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.

252081 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. #else
  68. #define JUCE_INTEL 1
  69. #endif
  70. #ifdef __LP64__
  71. #define JUCE_64BIT 1
  72. #else
  73. #define JUCE_32BIT 1
  74. #endif
  75. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  76. #error "Building for OSX 10.3 is no longer supported!"
  77. #endif
  78. #ifndef MAC_OS_X_VERSION_10_5
  79. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  80. #endif
  81. #endif
  82. #if JUCE_IPHONE
  83. #ifndef NDEBUG
  84. #define JUCE_DEBUG 1
  85. #endif
  86. #ifdef __LITTLE_ENDIAN__
  87. #define JUCE_LITTLE_ENDIAN 1
  88. #else
  89. #define JUCE_BIG_ENDIAN 1
  90. #endif
  91. #endif
  92. #if JUCE_LINUX
  93. #ifdef _DEBUG
  94. #define JUCE_DEBUG 1
  95. #endif
  96. // Allow override for big-endian Linux platforms
  97. #ifndef JUCE_BIG_ENDIAN
  98. #define JUCE_LITTLE_ENDIAN 1
  99. #endif
  100. #if defined (__LP64__) || defined (_LP64)
  101. #define JUCE_64BIT 1
  102. #else
  103. #define JUCE_32BIT 1
  104. #endif
  105. #define JUCE_INTEL 1
  106. #endif
  107. // Compiler type macros.
  108. #ifdef __GNUC__
  109. #define JUCE_GCC 1
  110. #elif defined (_MSC_VER)
  111. #define JUCE_MSVC 1
  112. #if _MSC_VER >= 1400
  113. #define JUCE_USE_INTRINSICS 1
  114. #endif
  115. #else
  116. #error unknown compiler
  117. #endif
  118. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  119. /*** End of inlined file: juce_TargetPlatform.h ***/
  120. // FORCE_AMALGAMATOR_INCLUDE
  121. /*** Start of inlined file: juce_Config.h ***/
  122. #ifndef __JUCE_CONFIG_JUCEHEADER__
  123. #define __JUCE_CONFIG_JUCEHEADER__
  124. #ifndef JUCE_NAMESPACE
  125. #define JUCE_NAMESPACE juce
  126. #endif
  127. #ifndef JUCE_FORCE_DEBUG
  128. //#define JUCE_FORCE_DEBUG 1
  129. #endif
  130. #ifndef JUCE_LOG_ASSERTIONS
  131. // #define JUCE_LOG_ASSERTIONS 1
  132. #endif
  133. #ifndef JUCE_ASIO
  134. #define JUCE_ASIO 1
  135. #endif
  136. #ifndef JUCE_WASAPI
  137. // #define JUCE_WASAPI 1
  138. #endif
  139. #ifndef JUCE_DIRECTSOUND
  140. #define JUCE_DIRECTSOUND 1
  141. #endif
  142. #ifndef JUCE_ALSA
  143. #define JUCE_ALSA 1
  144. #endif
  145. #ifndef JUCE_JACK
  146. #define JUCE_JACK 1
  147. #endif
  148. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  149. #define JUCE_QUICKTIME 1
  150. #endif
  151. #ifndef JUCE_OPENGL
  152. #define JUCE_OPENGL 1
  153. #endif
  154. #ifndef JUCE_USE_FLAC
  155. #define JUCE_USE_FLAC 1
  156. #endif
  157. #ifndef JUCE_USE_OGGVORBIS
  158. #define JUCE_USE_OGGVORBIS 1
  159. #endif
  160. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  161. #define JUCE_USE_CDBURNER 1
  162. #endif
  163. #ifndef JUCE_USE_CDREADER
  164. #define JUCE_USE_CDREADER 1
  165. #endif
  166. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  167. // #define JUCE_USE_CAMERA 1
  168. #endif
  169. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  170. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  171. #endif
  172. #ifndef JUCE_USE_XINERAMA
  173. #define JUCE_USE_XINERAMA 1
  174. #endif
  175. #ifndef JUCE_USE_XSHM
  176. #define JUCE_USE_XSHM 1
  177. #endif
  178. #ifndef JUCE_PLUGINHOST_VST
  179. // #define JUCE_PLUGINHOST_VST 1
  180. #endif
  181. #ifndef JUCE_PLUGINHOST_AU
  182. // #define JUCE_PLUGINHOST_AU 1
  183. #endif
  184. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  185. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  186. #endif
  187. #ifndef JUCE_WEB_BROWSER
  188. #define JUCE_WEB_BROWSER 1
  189. #endif
  190. #ifndef JUCE_SUPPORT_CARBON
  191. #define JUCE_SUPPORT_CARBON 1
  192. #endif
  193. #ifndef JUCE_INCLUDE_ZLIB_CODE
  194. #define JUCE_INCLUDE_ZLIB_CODE 1
  195. #endif
  196. #ifndef JUCE_INCLUDE_FLAC_CODE
  197. #define JUCE_INCLUDE_FLAC_CODE 1
  198. #endif
  199. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  200. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  201. #endif
  202. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  203. #define JUCE_INCLUDE_PNGLIB_CODE 1
  204. #endif
  205. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  206. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  207. #endif
  208. #ifndef JUCE_CHECK_MEMORY_LEAKS
  209. #define JUCE_CHECK_MEMORY_LEAKS 1
  210. #endif
  211. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  212. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  213. #endif
  214. #ifndef JUCE_STRINGS_ARE_UNICODE
  215. #define JUCE_STRINGS_ARE_UNICODE 1
  216. #endif
  217. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  218. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  219. #undef JUCE_QUICKTIME
  220. #define JUCE_QUICKTIME 0
  221. #undef JUCE_OPENGL
  222. #define JUCE_OPENGL 0
  223. #undef JUCE_USE_CDBURNER
  224. #define JUCE_USE_CDBURNER 0
  225. #undef JUCE_USE_CDREADER
  226. #define JUCE_USE_CDREADER 0
  227. #undef JUCE_WEB_BROWSER
  228. #define JUCE_WEB_BROWSER 0
  229. #undef JUCE_PLUGINHOST_AU
  230. #define JUCE_PLUGINHOST_AU 0
  231. #undef JUCE_PLUGINHOST_VST
  232. #define JUCE_PLUGINHOST_VST 0
  233. #endif
  234. #endif
  235. /*** End of inlined file: juce_Config.h ***/
  236. // FORCE_AMALGAMATOR_INCLUDE
  237. #ifndef JUCE_BUILD_CORE
  238. #define JUCE_BUILD_CORE 1
  239. #endif
  240. #ifndef JUCE_BUILD_MISC
  241. #define JUCE_BUILD_MISC 1
  242. #endif
  243. #ifndef JUCE_BUILD_GUI
  244. #define JUCE_BUILD_GUI 1
  245. #endif
  246. #ifndef JUCE_BUILD_NATIVE
  247. #define JUCE_BUILD_NATIVE 1
  248. #endif
  249. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  250. #undef JUCE_BUILD_MISC
  251. #undef JUCE_BUILD_GUI
  252. #endif
  253. //==============================================================================
  254. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE
  255. #if JUCE_WINDOWS
  256. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  257. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  258. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  259. #ifndef STRICT
  260. #define STRICT 1
  261. #endif
  262. #undef WIN32_LEAN_AND_MEAN
  263. #define WIN32_LEAN_AND_MEAN 1
  264. #ifdef _MSC_VER
  265. #pragma warning (push)
  266. #pragma warning (disable : 4100 4201 4514 4312 4995)
  267. #endif
  268. #define _WIN32_WINNT 0x0500
  269. #define _UNICODE 1
  270. #define UNICODE 1
  271. #ifndef _WIN32_IE
  272. #define _WIN32_IE 0x0400
  273. #endif
  274. #include <windows.h>
  275. #include <windowsx.h>
  276. #include <commdlg.h>
  277. #include <shellapi.h>
  278. #include <mmsystem.h>
  279. #include <vfw.h>
  280. #include <tchar.h>
  281. #include <stddef.h>
  282. #include <ctime>
  283. #include <wininet.h>
  284. #include <nb30.h>
  285. #include <iphlpapi.h>
  286. #include <mapi.h>
  287. #include <float.h>
  288. #include <process.h>
  289. #include <Exdisp.h>
  290. #include <exdispid.h>
  291. #include <shlobj.h>
  292. #if ! JUCE_MINGW
  293. #include <crtdbg.h>
  294. #include <comutil.h>
  295. #endif
  296. #if JUCE_OPENGL
  297. #include <gl/gl.h>
  298. #endif
  299. #undef PACKED
  300. #if JUCE_ASIO
  301. #include "iasiodrv.h"
  302. #endif
  303. #if JUCE_USE_CDBURNER
  304. #include <imapi.h>
  305. #include <imapierror.h>
  306. #endif
  307. #if JUCE_USE_CAMERA
  308. #include <dshow.h>
  309. #include <qedit.h>
  310. #endif
  311. #if JUCE_WASAPI
  312. #include <MMReg.h>
  313. #include <mmdeviceapi.h>
  314. #include <Audioclient.h>
  315. #include <Avrt.h>
  316. #include <functiondiscoverykeys.h>
  317. #endif
  318. #if JUCE_QUICKTIME
  319. #include <Movies.h>
  320. #include <QTML.h>
  321. #include <QuickTimeComponents.h>
  322. #include <MediaHandlers.h>
  323. #include <ImageCodec.h>
  324. #import <QTOLibrary.dll>
  325. #import <QTOControl.dll>
  326. #endif
  327. #ifdef _MSC_VER
  328. #pragma warning (pop)
  329. #endif
  330. template <class T>
  331. class ComSmartPtr
  332. {
  333. public:
  334. ComSmartPtr() throw() : p (0) {}
  335. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  336. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  337. ~ComSmartPtr() { if (p != 0) p->Release(); }
  338. operator T*() const throw() { return p; }
  339. T& operator*() const throw() { return *p; }
  340. T** operator&() throw() { return &p; }
  341. T* operator->() const throw() { return p; }
  342. T* operator= (T* const newP)
  343. {
  344. if (newP != 0)
  345. newP->AddRef();
  346. if (p != 0)
  347. p->Release();
  348. p = newP;
  349. return newP;
  350. }
  351. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  352. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  353. {
  354. #ifndef __MINGW32__
  355. operator= (0);
  356. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  357. #else
  358. return S_FALSE;
  359. #endif
  360. }
  361. T* p;
  362. };
  363. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  364. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  365. #elif JUCE_LINUX
  366. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  367. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  368. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  369. #include <sched.h>
  370. #include <pthread.h>
  371. #include <sys/time.h>
  372. #include <errno.h>
  373. #include <sys/stat.h>
  374. #include <sys/dir.h>
  375. #include <sys/ptrace.h>
  376. #include <sys/vfs.h>
  377. #include <sys/wait.h>
  378. #include <fnmatch.h>
  379. #include <utime.h>
  380. #include <pwd.h>
  381. #include <fcntl.h>
  382. #include <dlfcn.h>
  383. #include <netdb.h>
  384. #include <arpa/inet.h>
  385. #include <netinet/in.h>
  386. #include <sys/types.h>
  387. #include <sys/ioctl.h>
  388. #include <sys/socket.h>
  389. #include <linux/if.h>
  390. #include <sys/sysinfo.h>
  391. #include <sys/file.h>
  392. #include <signal.h>
  393. #include <ft2build.h>
  394. #include FT_FREETYPE_H
  395. #include <X11/Xlib.h>
  396. #include <X11/Xatom.h>
  397. #include <X11/Xresource.h>
  398. #include <X11/Xutil.h>
  399. #include <X11/Xmd.h>
  400. #include <X11/keysym.h>
  401. #include <X11/cursorfont.h>
  402. #if JUCE_USE_XINERAMA
  403. #include <X11/extensions/Xinerama.h>
  404. #endif
  405. #if JUCE_USE_XSHM
  406. #include <X11/extensions/XShm.h>
  407. #include <sys/shm.h>
  408. #include <sys/ipc.h>
  409. #endif
  410. #if JUCE_OPENGL
  411. #include <GL/glx.h>
  412. #endif
  413. #undef KeyPress
  414. #if JUCE_ALSA
  415. #include <alsa/asoundlib.h>
  416. #endif
  417. #if JUCE_JACK
  418. #include <jack/jack.h>
  419. //#include <jack/transport.h>
  420. #endif
  421. #undef SIZEOF
  422. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  423. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  424. #elif JUCE_MAC || JUCE_IPHONE
  425. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  426. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  427. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  428. #define USE_COREGRAPHICS_RENDERING 1
  429. #if JUCE_IPHONE
  430. #import <Foundation/Foundation.h>
  431. #import <UIKit/UIKit.h>
  432. #import <AudioToolbox/AudioToolbox.h>
  433. #import <AVFoundation/AVFoundation.h>
  434. #import <CoreData/CoreData.h>
  435. #import <MobileCoreServices/MobileCoreServices.h>
  436. #include <sys/fcntl.h>
  437. #else
  438. #import <Cocoa/Cocoa.h>
  439. #import <CoreAudio/HostTime.h>
  440. #import <CoreAudio/AudioHardware.h>
  441. #import <CoreMIDI/MIDIServices.h>
  442. #import <QTKit/QTKit.h>
  443. #import <WebKit/WebKit.h>
  444. #import <DiscRecording/DiscRecording.h>
  445. #import <IOKit/IOKitLib.h>
  446. #import <IOKit/IOCFPlugIn.h>
  447. #import <IOKit/hid/IOHIDLib.h>
  448. #import <IOKit/hid/IOHIDKeys.h>
  449. #import <IOKit/pwr_mgt/IOPMLib.h>
  450. #include <Carbon/Carbon.h>
  451. #include <sys/dir.h>
  452. #include <sys/socket.h>
  453. #endif
  454. #include <sys/sysctl.h>
  455. #include <sys/stat.h>
  456. #include <sys/param.h>
  457. #include <sys/mount.h>
  458. #include <fnmatch.h>
  459. #include <utime.h>
  460. #include <dlfcn.h>
  461. #include <ifaddrs.h>
  462. #include <net/if_dl.h>
  463. #include <mach/mach_time.h>
  464. #if MACOS_10_4_OR_EARLIER
  465. #include <GLUT/glut.h>
  466. #endif
  467. #if ! CGFLOAT_DEFINED
  468. #define CGFloat float
  469. #endif
  470. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  471. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  472. #else
  473. #error "Unknown platform!"
  474. #endif
  475. #endif
  476. //==============================================================================
  477. #define DONT_SET_USING_JUCE_NAMESPACE 1
  478. #undef max
  479. #undef min
  480. #define NO_DUMMY_DECL
  481. #if JUCE_BUILD_NATIVE
  482. #include "src/../juce_amalgamated.h"
  483. #endif
  484. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  485. #pragma warning (disable: 4309 4305)
  486. #endif
  487. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  488. BEGIN_JUCE_NAMESPACE
  489. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  490. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  491. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  492. class CarbonViewWrapperComponent : public Component,
  493. public ComponentMovementWatcher,
  494. public Timer
  495. {
  496. public:
  497. CarbonViewWrapperComponent()
  498. : ComponentMovementWatcher (this),
  499. wrapperWindow (0),
  500. embeddedView (0),
  501. recursiveResize (false)
  502. {
  503. }
  504. virtual ~CarbonViewWrapperComponent()
  505. {
  506. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  507. }
  508. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  509. virtual void removeView (HIViewRef embeddedView) = 0;
  510. virtual void mouseDown (int x, int y) {}
  511. virtual void paint() {}
  512. virtual bool getEmbeddedViewSize (int& w, int& h)
  513. {
  514. if (embeddedView == 0)
  515. return false;
  516. HIRect bounds;
  517. HIViewGetBounds (embeddedView, &bounds);
  518. w = jmax (1, roundToInt (bounds.size.width));
  519. h = jmax (1, roundToInt (bounds.size.height));
  520. return true;
  521. }
  522. void createWindow()
  523. {
  524. if (wrapperWindow == 0)
  525. {
  526. Rect r;
  527. r.left = getScreenX();
  528. r.top = getScreenY();
  529. r.right = r.left + getWidth();
  530. r.bottom = r.top + getHeight();
  531. CreateNewWindow (kDocumentWindowClass,
  532. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  533. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  534. &r, &wrapperWindow);
  535. jassert (wrapperWindow != 0);
  536. if (wrapperWindow == 0)
  537. return;
  538. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  539. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  540. [ownerWindow addChildWindow: carbonWindow
  541. ordered: NSWindowAbove];
  542. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  543. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  544. { kEventClassWindow, kEventWindowHandleDeactivate } };
  545. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  546. InstallWindowEventHandler (wrapperWindow, upp,
  547. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  548. windowEventTypes, this, &eventHandlerRef);
  549. setOurSizeToEmbeddedViewSize();
  550. setEmbeddedWindowToOurSize();
  551. creationTime = Time::getCurrentTime();
  552. }
  553. }
  554. void deleteWindow()
  555. {
  556. removeView (embeddedView);
  557. embeddedView = 0;
  558. if (wrapperWindow != 0)
  559. {
  560. RemoveEventHandler (eventHandlerRef);
  561. DisposeWindow (wrapperWindow);
  562. wrapperWindow = 0;
  563. }
  564. }
  565. void setOurSizeToEmbeddedViewSize()
  566. {
  567. int w, h;
  568. if (getEmbeddedViewSize (w, h))
  569. {
  570. if (w != getWidth() || h != getHeight())
  571. {
  572. startTimer (50);
  573. setSize (w, h);
  574. if (getParentComponent() != 0)
  575. getParentComponent()->setSize (w, h);
  576. }
  577. else
  578. {
  579. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  580. }
  581. }
  582. else
  583. {
  584. stopTimer();
  585. }
  586. }
  587. void setEmbeddedWindowToOurSize()
  588. {
  589. if (! recursiveResize)
  590. {
  591. recursiveResize = true;
  592. if (embeddedView != 0)
  593. {
  594. HIRect r;
  595. r.origin.x = 0;
  596. r.origin.y = 0;
  597. r.size.width = (float) getWidth();
  598. r.size.height = (float) getHeight();
  599. HIViewSetFrame (embeddedView, &r);
  600. }
  601. if (wrapperWindow != 0)
  602. {
  603. Rect wr;
  604. wr.left = getScreenX();
  605. wr.top = getScreenY();
  606. wr.right = wr.left + getWidth();
  607. wr.bottom = wr.top + getHeight();
  608. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  609. ShowWindow (wrapperWindow);
  610. }
  611. recursiveResize = false;
  612. }
  613. }
  614. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  615. {
  616. setEmbeddedWindowToOurSize();
  617. }
  618. void componentPeerChanged()
  619. {
  620. deleteWindow();
  621. createWindow();
  622. }
  623. void componentVisibilityChanged (Component&)
  624. {
  625. if (isShowing())
  626. createWindow();
  627. else
  628. deleteWindow();
  629. setEmbeddedWindowToOurSize();
  630. }
  631. static void recursiveHIViewRepaint (HIViewRef view)
  632. {
  633. HIViewSetNeedsDisplay (view, true);
  634. HIViewRef child = HIViewGetFirstSubview (view);
  635. while (child != 0)
  636. {
  637. recursiveHIViewRepaint (child);
  638. child = HIViewGetNextView (child);
  639. }
  640. }
  641. void timerCallback()
  642. {
  643. setOurSizeToEmbeddedViewSize();
  644. // To avoid strange overpainting problems when the UI is first opened, we'll
  645. // repaint it a few times during the first second that it's on-screen..
  646. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  647. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  648. }
  649. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  650. EventRef event)
  651. {
  652. switch (GetEventKind (event))
  653. {
  654. case kEventWindowHandleDeactivate:
  655. ActivateWindow (wrapperWindow, TRUE);
  656. break;
  657. case kEventWindowGetClickActivation:
  658. {
  659. getTopLevelComponent()->toFront (false);
  660. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  661. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  662. sizeof (ClickActivationResult), &howToHandleClick);
  663. HIViewSetNeedsDisplay (embeddedView, true);
  664. }
  665. break;
  666. }
  667. return noErr;
  668. }
  669. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  670. EventRef event, void* userData)
  671. {
  672. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  673. }
  674. protected:
  675. WindowRef wrapperWindow;
  676. HIViewRef embeddedView;
  677. bool recursiveResize;
  678. Time creationTime;
  679. EventHandlerRef eventHandlerRef;
  680. };
  681. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  682. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  683. END_JUCE_NAMESPACE
  684. #endif
  685. #define JUCE_AMALGAMATED_TEMPLATE 1
  686. //==============================================================================
  687. #if JUCE_BUILD_CORE
  688. /*** Start of inlined file: juce_FileLogger.cpp ***/
  689. BEGIN_JUCE_NAMESPACE
  690. FileLogger::FileLogger (const File& logFile_,
  691. const String& welcomeMessage,
  692. const int maxInitialFileSizeBytes)
  693. : logFile (logFile_)
  694. {
  695. if (maxInitialFileSizeBytes >= 0)
  696. trimFileSize (maxInitialFileSizeBytes);
  697. if (! logFile_.exists())
  698. {
  699. // do this so that the parent directories get created..
  700. logFile_.create();
  701. }
  702. logStream = logFile_.createOutputStream (256);
  703. jassert (logStream != 0);
  704. String welcome;
  705. welcome << "\r\n**********************************************************\r\n"
  706. << welcomeMessage
  707. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  708. << "\r\n";
  709. logMessage (welcome);
  710. }
  711. FileLogger::~FileLogger()
  712. {
  713. }
  714. void FileLogger::logMessage (const String& message)
  715. {
  716. if (logStream != 0)
  717. {
  718. Logger::outputDebugString (message);
  719. const ScopedLock sl (logLock);
  720. (*logStream) << message << T("\r\n");
  721. logStream->flush();
  722. }
  723. }
  724. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  725. {
  726. if (maxFileSizeBytes <= 0)
  727. {
  728. logFile.deleteFile();
  729. }
  730. else
  731. {
  732. const int64 fileSize = logFile.getSize();
  733. if (fileSize > maxFileSizeBytes)
  734. {
  735. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  736. jassert (in != 0);
  737. if (in != 0)
  738. {
  739. in->setPosition (fileSize - maxFileSizeBytes);
  740. String content;
  741. {
  742. MemoryBlock contentToSave;
  743. contentToSave.setSize (maxFileSizeBytes + 4);
  744. contentToSave.fillWith (0);
  745. in->read (contentToSave.getData(), maxFileSizeBytes);
  746. in = 0;
  747. content = contentToSave.toString();
  748. }
  749. int newStart = 0;
  750. while (newStart < fileSize
  751. && content[newStart] != '\n'
  752. && content[newStart] != '\r')
  753. ++newStart;
  754. logFile.deleteFile();
  755. logFile.appendText (content.substring (newStart), false, false);
  756. }
  757. }
  758. }
  759. }
  760. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  761. const String& logFileName,
  762. const String& welcomeMessage,
  763. const int maxInitialFileSizeBytes)
  764. {
  765. #if JUCE_MAC
  766. File logFile ("~/Library/Logs");
  767. logFile = logFile.getChildFile (logFileSubDirectoryName)
  768. .getChildFile (logFileName);
  769. #else
  770. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  771. if (logFile.isDirectory())
  772. {
  773. logFile = logFile.getChildFile (logFileSubDirectoryName)
  774. .getChildFile (logFileName);
  775. }
  776. #endif
  777. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  778. }
  779. END_JUCE_NAMESPACE
  780. /*** End of inlined file: juce_FileLogger.cpp ***/
  781. /*** Start of inlined file: juce_Logger.cpp ***/
  782. BEGIN_JUCE_NAMESPACE
  783. Logger::Logger()
  784. {
  785. }
  786. Logger::~Logger()
  787. {
  788. }
  789. static Logger* currentLogger = 0;
  790. void Logger::setCurrentLogger (Logger* const newLogger,
  791. const bool deleteOldLogger)
  792. {
  793. Logger* const oldLogger = currentLogger;
  794. currentLogger = newLogger;
  795. if (deleteOldLogger)
  796. delete oldLogger;
  797. }
  798. void Logger::writeToLog (const String& message)
  799. {
  800. if (currentLogger != 0)
  801. currentLogger->logMessage (message);
  802. else
  803. outputDebugString (message);
  804. }
  805. #if JUCE_LOG_ASSERTIONS
  806. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  807. {
  808. String m ("JUCE Assertion failure in ");
  809. m << filename << ", line " << lineNum;
  810. Logger::writeToLog (m);
  811. }
  812. #endif
  813. END_JUCE_NAMESPACE
  814. /*** End of inlined file: juce_Logger.cpp ***/
  815. /*** Start of inlined file: juce_Random.cpp ***/
  816. BEGIN_JUCE_NAMESPACE
  817. Random::Random (const int64 seedValue) throw()
  818. : seed (seedValue)
  819. {
  820. }
  821. Random::~Random() throw()
  822. {
  823. }
  824. void Random::setSeed (const int64 newSeed) throw()
  825. {
  826. seed = newSeed;
  827. }
  828. void Random::setSeedRandomly()
  829. {
  830. seed ^= (int64) (pointer_sized_int) this;
  831. seed ^= nextInt64() ^ Time::getMillisecondCounter();
  832. seed ^= nextInt64() ^ Time::getHighResolutionTicks();
  833. seed ^= nextInt64() ^ Time::getHighResolutionTicksPerSecond();
  834. seed ^= nextInt64() ^ Time::currentTimeMillis();
  835. }
  836. int Random::nextInt() throw()
  837. {
  838. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  839. return (int) (seed >> 16);
  840. }
  841. int Random::nextInt (const int maxValue) throw()
  842. {
  843. jassert (maxValue > 0);
  844. return (nextInt() & 0x7fffffff) % maxValue;
  845. }
  846. int64 Random::nextInt64() throw()
  847. {
  848. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  849. }
  850. bool Random::nextBool() throw()
  851. {
  852. return (nextInt() & 0x80000000) != 0;
  853. }
  854. float Random::nextFloat() throw()
  855. {
  856. return ((uint32) nextInt()) / (float) 0xffffffff;
  857. }
  858. double Random::nextDouble() throw()
  859. {
  860. return ((uint32) nextInt()) / (double) 0xffffffff;
  861. }
  862. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  863. {
  864. BitArray n;
  865. do
  866. {
  867. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  868. }
  869. while (n.compare (maximumValue) >= 0);
  870. return n;
  871. }
  872. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  873. {
  874. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  875. while ((startBit & 31) != 0 && numBits > 0)
  876. {
  877. arrayToChange.setBit (startBit++, nextBool());
  878. --numBits;
  879. }
  880. while (numBits >= 32)
  881. {
  882. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  883. startBit += 32;
  884. numBits -= 32;
  885. }
  886. while (--numBits >= 0)
  887. arrayToChange.setBit (startBit + numBits, nextBool());
  888. }
  889. Random& Random::getSystemRandom() throw()
  890. {
  891. static Random sysRand (1);
  892. return sysRand;
  893. }
  894. END_JUCE_NAMESPACE
  895. /*** End of inlined file: juce_Random.cpp ***/
  896. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  897. BEGIN_JUCE_NAMESPACE
  898. RelativeTime::RelativeTime (const double seconds_) throw()
  899. : seconds (seconds_)
  900. {
  901. }
  902. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  903. : seconds (other.seconds)
  904. {
  905. }
  906. RelativeTime::~RelativeTime() throw()
  907. {
  908. }
  909. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  910. {
  911. return RelativeTime (milliseconds * 0.001);
  912. }
  913. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  914. {
  915. return RelativeTime (milliseconds * 0.001);
  916. }
  917. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  918. {
  919. return RelativeTime (numberOfMinutes * 60.0);
  920. }
  921. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  922. {
  923. return RelativeTime (numberOfHours * (60.0 * 60.0));
  924. }
  925. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  926. {
  927. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  928. }
  929. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  930. {
  931. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  932. }
  933. int64 RelativeTime::inMilliseconds() const throw()
  934. {
  935. return (int64)(seconds * 1000.0);
  936. }
  937. double RelativeTime::inMinutes() const throw()
  938. {
  939. return seconds / 60.0;
  940. }
  941. double RelativeTime::inHours() const throw()
  942. {
  943. return seconds / (60.0 * 60.0);
  944. }
  945. double RelativeTime::inDays() const throw()
  946. {
  947. return seconds / (60.0 * 60.0 * 24.0);
  948. }
  949. double RelativeTime::inWeeks() const throw()
  950. {
  951. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  952. }
  953. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  954. {
  955. if (seconds < 0.001 && seconds > -0.001)
  956. return returnValueForZeroTime;
  957. String result;
  958. if (seconds < 0)
  959. result = T("-");
  960. int fieldsShown = 0;
  961. int n = abs ((int) inWeeks());
  962. if (n > 0)
  963. {
  964. result << n << ((n == 1) ? TRANS(" week ")
  965. : TRANS(" weeks "));
  966. ++fieldsShown;
  967. }
  968. n = abs ((int) inDays()) % 7;
  969. if (n > 0)
  970. {
  971. result << n << ((n == 1) ? TRANS(" day ")
  972. : TRANS(" days "));
  973. ++fieldsShown;
  974. }
  975. if (fieldsShown < 2)
  976. {
  977. n = abs ((int) inHours()) % 24;
  978. if (n > 0)
  979. {
  980. result << n << ((n == 1) ? TRANS(" hr ")
  981. : TRANS(" hrs "));
  982. ++fieldsShown;
  983. }
  984. if (fieldsShown < 2)
  985. {
  986. n = abs ((int) inMinutes()) % 60;
  987. if (n > 0)
  988. {
  989. result << n << ((n == 1) ? TRANS(" min ")
  990. : TRANS(" mins "));
  991. ++fieldsShown;
  992. }
  993. if (fieldsShown < 2)
  994. {
  995. n = abs ((int) inSeconds()) % 60;
  996. if (n > 0)
  997. {
  998. result << n << ((n == 1) ? TRANS(" sec ")
  999. : TRANS(" secs "));
  1000. ++fieldsShown;
  1001. }
  1002. if (fieldsShown < 1)
  1003. {
  1004. n = abs ((int) inMilliseconds()) % 1000;
  1005. if (n > 0)
  1006. {
  1007. result << n << TRANS(" ms");
  1008. ++fieldsShown;
  1009. }
  1010. }
  1011. }
  1012. }
  1013. }
  1014. return result.trimEnd();
  1015. }
  1016. const RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1017. {
  1018. seconds = other.seconds;
  1019. return *this;
  1020. }
  1021. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1022. {
  1023. return seconds == other.seconds;
  1024. }
  1025. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1026. {
  1027. return seconds != other.seconds;
  1028. }
  1029. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1030. {
  1031. return seconds > other.seconds;
  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. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1046. {
  1047. return RelativeTime (seconds + timeToAdd.seconds);
  1048. }
  1049. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1050. {
  1051. return RelativeTime (seconds - timeToSubtract.seconds);
  1052. }
  1053. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1054. {
  1055. return RelativeTime (seconds + secondsToAdd);
  1056. }
  1057. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1058. {
  1059. return RelativeTime (seconds - secondsToSubtract);
  1060. }
  1061. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1062. {
  1063. seconds += timeToAdd.seconds;
  1064. return *this;
  1065. }
  1066. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1067. {
  1068. seconds -= timeToSubtract.seconds;
  1069. return *this;
  1070. }
  1071. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1072. {
  1073. seconds += secondsToAdd;
  1074. return *this;
  1075. }
  1076. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1077. {
  1078. seconds -= secondsToSubtract;
  1079. return *this;
  1080. }
  1081. END_JUCE_NAMESPACE
  1082. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1083. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1084. BEGIN_JUCE_NAMESPACE
  1085. void juce_initialiseStrings();
  1086. const String SystemStats::getJUCEVersion() throw()
  1087. {
  1088. return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION);
  1089. }
  1090. static bool juceInitialisedNonGUI = false;
  1091. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1092. {
  1093. if (! juceInitialisedNonGUI)
  1094. {
  1095. #if JUCE_MAC || JUCE_IPHONE
  1096. const ScopedAutoReleasePool pool;
  1097. #endif
  1098. #ifdef JUCE_DEBUG
  1099. {
  1100. // Some simple test code to keep an eye on things and make sure these functions
  1101. // work ok on all platforms. Let me know if any of these assertions fail!
  1102. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1103. char a1[7];
  1104. jassert (numElementsInArray(a1) == 7);
  1105. int a2[3];
  1106. jassert (numElementsInArray(a2) == 3);
  1107. int n = 1;
  1108. Atomic::increment (n);
  1109. jassert (Atomic::incrementAndReturn (n) == 3);
  1110. Atomic::decrement (n);
  1111. jassert (Atomic::decrementAndReturn (n) == 1);
  1112. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1113. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1114. // Some quick stream tests..
  1115. int randomInt = Random::getSystemRandom().nextInt();
  1116. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1117. double randomDouble = Random::getSystemRandom().nextDouble();
  1118. String randomString;
  1119. for (int i = 50; --i >= 0;)
  1120. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1121. MemoryOutputStream mo;
  1122. mo.writeInt (randomInt);
  1123. mo.writeIntBigEndian (randomInt);
  1124. mo.writeCompressedInt (randomInt);
  1125. mo.writeString (randomString);
  1126. mo.writeInt64 (randomInt64);
  1127. mo.writeInt64BigEndian (randomInt64);
  1128. mo.writeDouble (randomDouble);
  1129. mo.writeDoubleBigEndian (randomDouble);
  1130. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1131. jassert (mi.readInt() == randomInt);
  1132. jassert (mi.readIntBigEndian() == randomInt);
  1133. jassert (mi.readCompressedInt() == randomInt);
  1134. jassert (mi.readString() == randomString);
  1135. jassert (mi.readInt64() == randomInt64);
  1136. jassert (mi.readInt64BigEndian() == randomInt64);
  1137. jassert (mi.readDouble() == randomDouble);
  1138. jassert (mi.readDoubleBigEndian() == randomDouble);
  1139. }
  1140. #endif
  1141. // Now the real initialisation..
  1142. juceInitialisedNonGUI = true;
  1143. DBG (SystemStats::getJUCEVersion());
  1144. juce_initialiseStrings();
  1145. SystemStats::initialiseStats();
  1146. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1147. }
  1148. }
  1149. #if JUCE_WINDOWS
  1150. // This is imported from the sockets code..
  1151. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1152. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1153. #endif
  1154. #if JUCE_DEBUG
  1155. extern void juce_CheckForDanglingStreams();
  1156. #endif
  1157. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1158. {
  1159. if (juceInitialisedNonGUI)
  1160. {
  1161. #if JUCE_MAC || JUCE_IPHONE
  1162. const ScopedAutoReleasePool pool;
  1163. #endif
  1164. #if JUCE_WINDOWS
  1165. // need to shut down sockets if they were used..
  1166. if (juce_CloseWin32SocketLib != 0)
  1167. (*juce_CloseWin32SocketLib)();
  1168. #endif
  1169. LocalisedStrings::setCurrentMappings (0);
  1170. Thread::stopAllThreads (3000);
  1171. #if JUCE_DEBUG
  1172. juce_CheckForDanglingStreams();
  1173. #endif
  1174. juceInitialisedNonGUI = false;
  1175. }
  1176. }
  1177. #ifdef JUCE_DLL
  1178. void* juce_Malloc (const int size)
  1179. {
  1180. return malloc (size);
  1181. }
  1182. void* juce_Calloc (const int size)
  1183. {
  1184. return calloc (1, size);
  1185. }
  1186. void* juce_Realloc (void* const block, const int size)
  1187. {
  1188. return realloc (block, size);
  1189. }
  1190. void juce_Free (void* const block)
  1191. {
  1192. free (block);
  1193. }
  1194. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1195. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1196. {
  1197. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1198. }
  1199. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1200. {
  1201. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1202. }
  1203. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1204. {
  1205. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1206. }
  1207. void juce_DebugFree (void* const block)
  1208. {
  1209. _free_dbg (block, _NORMAL_BLOCK);
  1210. }
  1211. #endif
  1212. #endif
  1213. END_JUCE_NAMESPACE
  1214. /*** End of inlined file: juce_SystemStats.cpp ***/
  1215. /*** Start of inlined file: juce_Time.cpp ***/
  1216. #ifdef _MSC_VER
  1217. #pragma warning (disable: 4514)
  1218. #pragma warning (push)
  1219. #endif
  1220. #ifndef JUCE_WINDOWS
  1221. #include <sys/time.h>
  1222. #else
  1223. #include <ctime>
  1224. #endif
  1225. #include <sys/timeb.h>
  1226. BEGIN_JUCE_NAMESPACE
  1227. #ifdef _MSC_VER
  1228. #pragma warning (pop)
  1229. #ifdef _INC_TIME_INL
  1230. #define USE_NEW_SECURE_TIME_FNS
  1231. #endif
  1232. #endif
  1233. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1234. {
  1235. const int64 seconds = millis / 1000;
  1236. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1237. {
  1238. // use extended maths for dates beyond 1970 to 2037..
  1239. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1240. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1241. const int days = (int) (jdm / literal64bit (86400));
  1242. const int a = 32044 + days;
  1243. const int b = (4 * a + 3) / 146097;
  1244. const int c = a - (b * 146097) / 4;
  1245. const int d = (4 * c + 3) / 1461;
  1246. const int e = c - (d * 1461) / 4;
  1247. const int m = (5 * e + 2) / 153;
  1248. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1249. result.tm_mon = m + 2 - 12 * (m / 10);
  1250. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1251. result.tm_wday = (days + 1) % 7;
  1252. result.tm_yday = -1;
  1253. int t = (int) (jdm % literal64bit (86400));
  1254. result.tm_hour = t / 3600;
  1255. t %= 3600;
  1256. result.tm_min = t / 60;
  1257. result.tm_sec = t % 60;
  1258. result.tm_isdst = -1;
  1259. }
  1260. else
  1261. {
  1262. time_t now = (time_t) (seconds);
  1263. #if JUCE_WINDOWS
  1264. #ifdef USE_NEW_SECURE_TIME_FNS
  1265. if (now >= 0 && now <= 0x793406fff)
  1266. localtime_s (&result, &now);
  1267. else
  1268. zeromem (&result, sizeof (result));
  1269. #else
  1270. result = *localtime (&now);
  1271. #endif
  1272. #else
  1273. // more thread-safe
  1274. localtime_r (&now, &result);
  1275. #endif
  1276. }
  1277. }
  1278. Time::Time() throw()
  1279. : millisSinceEpoch (0)
  1280. {
  1281. }
  1282. Time::Time (const Time& other) throw()
  1283. : millisSinceEpoch (other.millisSinceEpoch)
  1284. {
  1285. }
  1286. Time::Time (const int64 ms) throw()
  1287. : millisSinceEpoch (ms)
  1288. {
  1289. }
  1290. Time::Time (const int year,
  1291. const int month,
  1292. const int day,
  1293. const int hours,
  1294. const int minutes,
  1295. const int seconds,
  1296. const int milliseconds,
  1297. const bool useLocalTime) throw()
  1298. {
  1299. jassert (year > 100); // year must be a 4-digit version
  1300. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1301. {
  1302. // use extended maths for dates beyond 1970 to 2037..
  1303. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1304. : 0;
  1305. const int a = (13 - month) / 12;
  1306. const int y = year + 4800 - a;
  1307. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1308. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1309. - 32045;
  1310. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1311. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1312. + milliseconds;
  1313. }
  1314. else
  1315. {
  1316. struct tm t;
  1317. t.tm_year = year - 1900;
  1318. t.tm_mon = month;
  1319. t.tm_mday = day;
  1320. t.tm_hour = hours;
  1321. t.tm_min = minutes;
  1322. t.tm_sec = seconds;
  1323. t.tm_isdst = -1;
  1324. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1325. if (millisSinceEpoch < 0)
  1326. millisSinceEpoch = 0;
  1327. else
  1328. millisSinceEpoch += milliseconds;
  1329. }
  1330. }
  1331. Time::~Time() throw()
  1332. {
  1333. }
  1334. const Time& Time::operator= (const Time& other) throw()
  1335. {
  1336. millisSinceEpoch = other.millisSinceEpoch;
  1337. return *this;
  1338. }
  1339. int64 Time::currentTimeMillis() throw()
  1340. {
  1341. static uint32 lastCounterResult = 0xffffffff;
  1342. static int64 correction = 0;
  1343. const uint32 now = getMillisecondCounter();
  1344. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1345. if (now < lastCounterResult)
  1346. {
  1347. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1348. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1349. {
  1350. // get the time once using normal library calls, and store the difference needed to
  1351. // turn the millisecond counter into a real time.
  1352. #if JUCE_WINDOWS
  1353. struct _timeb t;
  1354. #ifdef USE_NEW_SECURE_TIME_FNS
  1355. _ftime_s (&t);
  1356. #else
  1357. _ftime (&t);
  1358. #endif
  1359. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1360. #else
  1361. struct timeval tv;
  1362. struct timezone tz;
  1363. gettimeofday (&tv, &tz);
  1364. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1365. #endif
  1366. }
  1367. }
  1368. lastCounterResult = now;
  1369. return correction + now;
  1370. }
  1371. uint32 juce_millisecondsSinceStartup() throw();
  1372. static uint32 lastMSCounterValue = 0;
  1373. uint32 Time::getMillisecondCounter() throw()
  1374. {
  1375. const uint32 now = juce_millisecondsSinceStartup();
  1376. if (now < lastMSCounterValue)
  1377. {
  1378. // in multi-threaded apps this might be called concurrently, so
  1379. // make sure that our last counter value only increases and doesn't
  1380. // go backwards..
  1381. if (now < lastMSCounterValue - 1000)
  1382. lastMSCounterValue = now;
  1383. }
  1384. else
  1385. {
  1386. lastMSCounterValue = now;
  1387. }
  1388. return now;
  1389. }
  1390. uint32 Time::getApproximateMillisecondCounter() throw()
  1391. {
  1392. jassert (lastMSCounterValue != 0);
  1393. return lastMSCounterValue;
  1394. }
  1395. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1396. {
  1397. for (;;)
  1398. {
  1399. const uint32 now = getMillisecondCounter();
  1400. if (now >= targetTime)
  1401. break;
  1402. const int toWait = targetTime - now;
  1403. if (toWait > 2)
  1404. {
  1405. Thread::sleep (jmin (20, toWait >> 1));
  1406. }
  1407. else
  1408. {
  1409. // xxx should consider using mutex_pause on the mac as it apparently
  1410. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1411. for (int i = 10; --i >= 0;)
  1412. Thread::yield();
  1413. }
  1414. }
  1415. }
  1416. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1417. {
  1418. return ticks / (double) getHighResolutionTicksPerSecond();
  1419. }
  1420. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1421. {
  1422. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1423. }
  1424. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1425. {
  1426. return Time (currentTimeMillis());
  1427. }
  1428. const String Time::toString (const bool includeDate,
  1429. const bool includeTime,
  1430. const bool includeSeconds,
  1431. const bool use24HourClock) const throw()
  1432. {
  1433. String result;
  1434. if (includeDate)
  1435. {
  1436. result << getDayOfMonth() << ' '
  1437. << getMonthName (true) << ' '
  1438. << getYear();
  1439. if (includeTime)
  1440. result << ' ';
  1441. }
  1442. if (includeTime)
  1443. {
  1444. if (includeSeconds)
  1445. {
  1446. result += String::formatted (T("%d:%02d:%02d "),
  1447. (use24HourClock) ? getHours()
  1448. : getHoursInAmPmFormat(),
  1449. getMinutes(),
  1450. getSeconds());
  1451. }
  1452. else
  1453. {
  1454. result += String::formatted (T("%d.%02d"),
  1455. (use24HourClock) ? getHours()
  1456. : getHoursInAmPmFormat(),
  1457. getMinutes());
  1458. }
  1459. if (! use24HourClock)
  1460. result << (isAfternoon() ? "pm" : "am");
  1461. }
  1462. return result.trimEnd();
  1463. }
  1464. const String Time::formatted (const tchar* const format) const throw()
  1465. {
  1466. String buffer;
  1467. int bufferSize = 128;
  1468. buffer.preallocateStorage (bufferSize);
  1469. struct tm t;
  1470. millisToLocal (millisSinceEpoch, t);
  1471. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1472. {
  1473. bufferSize += 128;
  1474. buffer.preallocateStorage (bufferSize);
  1475. }
  1476. return buffer;
  1477. }
  1478. int Time::getYear() const throw()
  1479. {
  1480. struct tm t;
  1481. millisToLocal (millisSinceEpoch, t);
  1482. return t.tm_year + 1900;
  1483. }
  1484. int Time::getMonth() const throw()
  1485. {
  1486. struct tm t;
  1487. millisToLocal (millisSinceEpoch, t);
  1488. return t.tm_mon;
  1489. }
  1490. int Time::getDayOfMonth() const throw()
  1491. {
  1492. struct tm t;
  1493. millisToLocal (millisSinceEpoch, t);
  1494. return t.tm_mday;
  1495. }
  1496. int Time::getDayOfWeek() const throw()
  1497. {
  1498. struct tm t;
  1499. millisToLocal (millisSinceEpoch, t);
  1500. return t.tm_wday;
  1501. }
  1502. int Time::getHours() const throw()
  1503. {
  1504. struct tm t;
  1505. millisToLocal (millisSinceEpoch, t);
  1506. return t.tm_hour;
  1507. }
  1508. int Time::getHoursInAmPmFormat() const throw()
  1509. {
  1510. const int hours = getHours();
  1511. if (hours == 0)
  1512. return 12;
  1513. else if (hours <= 12)
  1514. return hours;
  1515. else
  1516. return hours - 12;
  1517. }
  1518. bool Time::isAfternoon() const throw()
  1519. {
  1520. return getHours() >= 12;
  1521. }
  1522. static int extendedModulo (const int64 value, const int modulo) throw()
  1523. {
  1524. return (int) (value >= 0 ? (value % modulo)
  1525. : (value - ((value / modulo) + 1) * modulo));
  1526. }
  1527. int Time::getMinutes() const throw()
  1528. {
  1529. struct tm t;
  1530. millisToLocal (millisSinceEpoch, t);
  1531. return t.tm_min;
  1532. }
  1533. int Time::getSeconds() const throw()
  1534. {
  1535. return extendedModulo (millisSinceEpoch / 1000, 60);
  1536. }
  1537. int Time::getMilliseconds() const throw()
  1538. {
  1539. return extendedModulo (millisSinceEpoch, 1000);
  1540. }
  1541. bool Time::isDaylightSavingTime() const throw()
  1542. {
  1543. struct tm t;
  1544. millisToLocal (millisSinceEpoch, t);
  1545. return t.tm_isdst != 0;
  1546. }
  1547. const String Time::getTimeZone() const throw()
  1548. {
  1549. String zone[2];
  1550. #if JUCE_WINDOWS
  1551. _tzset();
  1552. #ifdef USE_NEW_SECURE_TIME_FNS
  1553. {
  1554. char name [128];
  1555. size_t length;
  1556. for (int i = 0; i < 2; ++i)
  1557. {
  1558. zeromem (name, sizeof (name));
  1559. _get_tzname (&length, name, 127, i);
  1560. zone[i] = name;
  1561. }
  1562. }
  1563. #else
  1564. const char** const zonePtr = (const char**) _tzname;
  1565. zone[0] = zonePtr[0];
  1566. zone[1] = zonePtr[1];
  1567. #endif
  1568. #else
  1569. tzset();
  1570. const char** const zonePtr = (const char**) tzname;
  1571. zone[0] = zonePtr[0];
  1572. zone[1] = zonePtr[1];
  1573. #endif
  1574. if (isDaylightSavingTime())
  1575. {
  1576. zone[0] = zone[1];
  1577. if (zone[0].length() > 3
  1578. && zone[0].containsIgnoreCase (T("daylight"))
  1579. && zone[0].contains (T("GMT")))
  1580. zone[0] = "BST";
  1581. }
  1582. return zone[0].substring (0, 3);
  1583. }
  1584. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1585. {
  1586. return getMonthName (getMonth(), threeLetterVersion);
  1587. }
  1588. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1589. {
  1590. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1591. }
  1592. const String Time::getMonthName (int monthNumber,
  1593. const bool threeLetterVersion) throw()
  1594. {
  1595. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1596. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1597. monthNumber %= 12;
  1598. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1599. : longMonthNames [monthNumber]);
  1600. }
  1601. const String Time::getWeekdayName (int day,
  1602. const bool threeLetterVersion) throw()
  1603. {
  1604. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1605. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1606. day %= 7;
  1607. return TRANS (threeLetterVersion ? shortDayNames [day]
  1608. : longDayNames [day]);
  1609. }
  1610. END_JUCE_NAMESPACE
  1611. /*** End of inlined file: juce_Time.cpp ***/
  1612. /*** Start of inlined file: juce_BitArray.cpp ***/
  1613. BEGIN_JUCE_NAMESPACE
  1614. BitArray::BitArray() throw()
  1615. : numValues (4),
  1616. highestBit (-1),
  1617. negative (false)
  1618. {
  1619. values.calloc (numValues + 1);
  1620. }
  1621. BitArray::BitArray (const int value) throw()
  1622. : numValues (4),
  1623. highestBit (31),
  1624. negative (value < 0)
  1625. {
  1626. values.calloc (numValues + 1);
  1627. values[0] = abs (value);
  1628. highestBit = getHighestBit();
  1629. }
  1630. BitArray::BitArray (int64 value) throw()
  1631. : numValues (4),
  1632. highestBit (63),
  1633. negative (value < 0)
  1634. {
  1635. values.calloc (numValues + 1);
  1636. if (value < 0)
  1637. value = -value;
  1638. values[0] = (unsigned int) value;
  1639. values[1] = (unsigned int) (value >> 32);
  1640. highestBit = getHighestBit();
  1641. }
  1642. BitArray::BitArray (const unsigned int value) throw()
  1643. : numValues (4),
  1644. highestBit (31),
  1645. negative (false)
  1646. {
  1647. values.calloc (numValues + 1);
  1648. values[0] = value;
  1649. highestBit = getHighestBit();
  1650. }
  1651. BitArray::BitArray (const BitArray& other) throw()
  1652. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1653. highestBit (other.getHighestBit()),
  1654. negative (other.negative)
  1655. {
  1656. values.malloc (numValues + 1);
  1657. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1658. }
  1659. BitArray::~BitArray() throw()
  1660. {
  1661. }
  1662. BitArray& BitArray::operator= (const BitArray& other) throw()
  1663. {
  1664. if (this != &other)
  1665. {
  1666. highestBit = other.getHighestBit();
  1667. numValues = jmax (4, (highestBit >> 5) + 1);
  1668. negative = other.negative;
  1669. values.malloc (numValues + 1);
  1670. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1671. }
  1672. return *this;
  1673. }
  1674. // result == 0 = the same
  1675. // result < 0 = this number is smaller
  1676. // result > 0 = this number is bigger
  1677. int BitArray::compare (const BitArray& other) const throw()
  1678. {
  1679. if (isNegative() == other.isNegative())
  1680. {
  1681. const int absComp = compareAbsolute (other);
  1682. return isNegative() ? -absComp : absComp;
  1683. }
  1684. else
  1685. {
  1686. return isNegative() ? -1 : 1;
  1687. }
  1688. }
  1689. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1690. {
  1691. const int h1 = getHighestBit();
  1692. const int h2 = other.getHighestBit();
  1693. if (h1 > h2)
  1694. return 1;
  1695. else if (h1 < h2)
  1696. return -1;
  1697. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1698. if (values[i] != other.values[i])
  1699. return (values[i] > other.values[i]) ? 1 : -1;
  1700. return 0;
  1701. }
  1702. bool BitArray::operator== (const BitArray& other) const throw()
  1703. {
  1704. return compare (other) == 0;
  1705. }
  1706. bool BitArray::operator!= (const BitArray& other) const throw()
  1707. {
  1708. return compare (other) != 0;
  1709. }
  1710. bool BitArray::operator[] (const int bit) const throw()
  1711. {
  1712. return bit >= 0 && bit <= highestBit
  1713. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1714. }
  1715. bool BitArray::isEmpty() const throw()
  1716. {
  1717. return getHighestBit() < 0;
  1718. }
  1719. void BitArray::clear() throw()
  1720. {
  1721. if (numValues > 16)
  1722. {
  1723. numValues = 4;
  1724. values.calloc (numValues + 1);
  1725. }
  1726. else
  1727. {
  1728. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1729. }
  1730. highestBit = -1;
  1731. negative = false;
  1732. }
  1733. void BitArray::setBit (const int bit) throw()
  1734. {
  1735. if (bit >= 0)
  1736. {
  1737. if (bit > highestBit)
  1738. {
  1739. ensureSize (bit >> 5);
  1740. highestBit = bit;
  1741. }
  1742. values [bit >> 5] |= (1 << (bit & 31));
  1743. }
  1744. }
  1745. void BitArray::setBit (const int bit,
  1746. const bool shouldBeSet) throw()
  1747. {
  1748. if (shouldBeSet)
  1749. setBit (bit);
  1750. else
  1751. clearBit (bit);
  1752. }
  1753. void BitArray::clearBit (const int bit) throw()
  1754. {
  1755. if (bit >= 0 && bit <= highestBit)
  1756. values [bit >> 5] &= ~(1 << (bit & 31));
  1757. }
  1758. void BitArray::setRange (int startBit,
  1759. int numBits,
  1760. const bool shouldBeSet) throw()
  1761. {
  1762. while (--numBits >= 0)
  1763. setBit (startBit++, shouldBeSet);
  1764. }
  1765. void BitArray::insertBit (const int bit,
  1766. const bool shouldBeSet) throw()
  1767. {
  1768. if (bit >= 0)
  1769. shiftBits (1, bit);
  1770. setBit (bit, shouldBeSet);
  1771. }
  1772. void BitArray::andWith (const BitArray& other) throw()
  1773. {
  1774. // this operation will only work with the absolute values
  1775. jassert (isNegative() == other.isNegative());
  1776. int n = numValues;
  1777. while (n > other.numValues)
  1778. values[--n] = 0;
  1779. while (--n >= 0)
  1780. values[n] &= other.values[n];
  1781. if (other.highestBit < highestBit)
  1782. highestBit = other.highestBit;
  1783. highestBit = getHighestBit();
  1784. }
  1785. void BitArray::orWith (const BitArray& other) throw()
  1786. {
  1787. if (other.highestBit < 0)
  1788. return;
  1789. // this operation will only work with the absolute values
  1790. jassert (isNegative() == other.isNegative());
  1791. ensureSize (other.highestBit >> 5);
  1792. int n = (other.highestBit >> 5) + 1;
  1793. while (--n >= 0)
  1794. values[n] |= other.values[n];
  1795. if (other.highestBit > highestBit)
  1796. highestBit = other.highestBit;
  1797. highestBit = getHighestBit();
  1798. }
  1799. void BitArray::xorWith (const BitArray& other) throw()
  1800. {
  1801. if (other.highestBit < 0)
  1802. return;
  1803. // this operation will only work with the absolute values
  1804. jassert (isNegative() == other.isNegative());
  1805. ensureSize (other.highestBit >> 5);
  1806. int n = (other.highestBit >> 5) + 1;
  1807. while (--n >= 0)
  1808. values[n] ^= other.values[n];
  1809. if (other.highestBit > highestBit)
  1810. highestBit = other.highestBit;
  1811. highestBit = getHighestBit();
  1812. }
  1813. void BitArray::add (const BitArray& other) throw()
  1814. {
  1815. if (other.isNegative())
  1816. {
  1817. BitArray o (other);
  1818. o.negate();
  1819. subtract (o);
  1820. return;
  1821. }
  1822. if (isNegative())
  1823. {
  1824. if (compareAbsolute (other) < 0)
  1825. {
  1826. BitArray temp (*this);
  1827. temp.negate();
  1828. *this = other;
  1829. subtract (temp);
  1830. }
  1831. else
  1832. {
  1833. negate();
  1834. subtract (other);
  1835. negate();
  1836. }
  1837. return;
  1838. }
  1839. if (other.highestBit > highestBit)
  1840. highestBit = other.highestBit;
  1841. ++highestBit;
  1842. const int numInts = (highestBit >> 5) + 1;
  1843. ensureSize (numInts);
  1844. int64 remainder = 0;
  1845. for (int i = 0; i <= numInts; ++i)
  1846. {
  1847. if (i < numValues)
  1848. remainder += values[i];
  1849. if (i < other.numValues)
  1850. remainder += other.values[i];
  1851. values[i] = (unsigned int) remainder;
  1852. remainder >>= 32;
  1853. }
  1854. jassert (remainder == 0);
  1855. highestBit = getHighestBit();
  1856. }
  1857. void BitArray::subtract (const BitArray& other) throw()
  1858. {
  1859. if (other.isNegative())
  1860. {
  1861. BitArray o (other);
  1862. o.negate();
  1863. add (o);
  1864. return;
  1865. }
  1866. if (! isNegative())
  1867. {
  1868. if (compareAbsolute (other) < 0)
  1869. {
  1870. BitArray temp (*this);
  1871. *this = other;
  1872. subtract (temp);
  1873. negate();
  1874. return;
  1875. }
  1876. }
  1877. else
  1878. {
  1879. negate();
  1880. add (other);
  1881. negate();
  1882. return;
  1883. }
  1884. const int numInts = (highestBit >> 5) + 1;
  1885. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1886. int64 amountToSubtract = 0;
  1887. for (int i = 0; i <= numInts; ++i)
  1888. {
  1889. if (i <= maxOtherInts)
  1890. amountToSubtract += (int64)other.values[i];
  1891. if (values[i] >= amountToSubtract)
  1892. {
  1893. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1894. amountToSubtract = 0;
  1895. }
  1896. else
  1897. {
  1898. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1899. values[i] = (unsigned int) n;
  1900. amountToSubtract = 1;
  1901. }
  1902. }
  1903. }
  1904. void BitArray::multiplyBy (const BitArray& other) throw()
  1905. {
  1906. BitArray total;
  1907. highestBit = getHighestBit();
  1908. const bool wasNegative = isNegative();
  1909. setNegative (false);
  1910. for (int i = 0; i <= highestBit; ++i)
  1911. {
  1912. if (operator[](i))
  1913. {
  1914. BitArray n (other);
  1915. n.setNegative (false);
  1916. n.shiftBits (i);
  1917. total.add (n);
  1918. }
  1919. }
  1920. *this = total;
  1921. negative = wasNegative ^ other.isNegative();
  1922. }
  1923. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1924. {
  1925. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1926. const int divHB = divisor.getHighestBit();
  1927. const int ourHB = getHighestBit();
  1928. if (divHB < 0 || ourHB < 0)
  1929. {
  1930. // division by zero
  1931. remainder.clear();
  1932. clear();
  1933. }
  1934. else
  1935. {
  1936. remainder = *this;
  1937. remainder.setNegative (false);
  1938. const bool wasNegative = isNegative();
  1939. clear();
  1940. BitArray temp (divisor);
  1941. temp.setNegative (false);
  1942. int leftShift = ourHB - divHB;
  1943. temp.shiftBits (leftShift);
  1944. while (leftShift >= 0)
  1945. {
  1946. if (remainder.compareAbsolute (temp) >= 0)
  1947. {
  1948. remainder.subtract (temp);
  1949. setBit (leftShift);
  1950. }
  1951. if (--leftShift >= 0)
  1952. temp.shiftBits (-1);
  1953. }
  1954. negative = wasNegative ^ divisor.isNegative();
  1955. remainder.setNegative (wasNegative);
  1956. }
  1957. }
  1958. void BitArray::modulo (const BitArray& divisor) throw()
  1959. {
  1960. BitArray remainder;
  1961. divideBy (divisor, remainder);
  1962. *this = remainder;
  1963. }
  1964. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1965. {
  1966. while (! m->isEmpty())
  1967. {
  1968. if (n->compareAbsolute (*m) > 0)
  1969. swapVariables (m, n);
  1970. m->subtract (*n);
  1971. }
  1972. return *n;
  1973. }
  1974. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1975. {
  1976. BitArray m (*this);
  1977. while (! n.isEmpty())
  1978. {
  1979. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  1980. return simpleGCD (&m, &n);
  1981. BitArray temp1 (m), temp2;
  1982. temp1.divideBy (n, temp2);
  1983. m = n;
  1984. n = temp2;
  1985. }
  1986. return m;
  1987. }
  1988. void BitArray::exponentModulo (const BitArray& exponent,
  1989. const BitArray& modulus) throw()
  1990. {
  1991. BitArray exp (exponent);
  1992. exp.modulo (modulus);
  1993. BitArray value (*this);
  1994. value.modulo (modulus);
  1995. clear();
  1996. setBit (0);
  1997. while (! exp.isEmpty())
  1998. {
  1999. if (exp [0])
  2000. {
  2001. multiplyBy (value);
  2002. this->modulo (modulus);
  2003. }
  2004. value.multiplyBy (value);
  2005. value.modulo (modulus);
  2006. exp.shiftBits (-1);
  2007. }
  2008. }
  2009. void BitArray::inverseModulo (const BitArray& modulus) throw()
  2010. {
  2011. const BitArray one (1);
  2012. if (modulus == one || modulus.isNegative())
  2013. {
  2014. clear();
  2015. return;
  2016. }
  2017. if (isNegative() || compareAbsolute (modulus) >= 0)
  2018. this->modulo (modulus);
  2019. if (*this == one)
  2020. return;
  2021. if (! (*this)[0])
  2022. {
  2023. // not invertible
  2024. clear();
  2025. return;
  2026. }
  2027. BitArray a1 (modulus);
  2028. BitArray a2 (*this);
  2029. BitArray b1 (modulus);
  2030. BitArray b2 (1);
  2031. while (a2 != one)
  2032. {
  2033. BitArray temp1, temp2, multiplier (a1);
  2034. multiplier.divideBy (a2, temp1);
  2035. temp1 = a2;
  2036. temp1.multiplyBy (multiplier);
  2037. temp2 = a1;
  2038. temp2.subtract (temp1);
  2039. a1 = a2;
  2040. a2 = temp2;
  2041. temp1 = b2;
  2042. temp1.multiplyBy (multiplier);
  2043. temp2 = b1;
  2044. temp2.subtract (temp1);
  2045. b1 = b2;
  2046. b2 = temp2;
  2047. }
  2048. while (b2.isNegative())
  2049. b2.add (modulus);
  2050. b2.modulo (modulus);
  2051. *this = b2;
  2052. }
  2053. void BitArray::shiftBits (int bits, const int startBit) throw()
  2054. {
  2055. if (highestBit < 0)
  2056. return;
  2057. if (startBit > 0)
  2058. {
  2059. if (bits < 0)
  2060. {
  2061. // right shift
  2062. for (int i = startBit; i <= highestBit; ++i)
  2063. setBit (i, operator[] (i - bits));
  2064. highestBit = getHighestBit();
  2065. }
  2066. else if (bits > 0)
  2067. {
  2068. // left shift
  2069. for (int i = highestBit + 1; --i >= startBit;)
  2070. setBit (i + bits, operator[] (i));
  2071. while (--bits >= 0)
  2072. clearBit (bits + startBit);
  2073. }
  2074. }
  2075. else
  2076. {
  2077. if (bits < 0)
  2078. {
  2079. // right shift
  2080. bits = -bits;
  2081. if (bits > highestBit)
  2082. {
  2083. clear();
  2084. }
  2085. else
  2086. {
  2087. const int wordsToMove = bits >> 5;
  2088. int top = 1 + (highestBit >> 5) - wordsToMove;
  2089. highestBit -= bits;
  2090. if (wordsToMove > 0)
  2091. {
  2092. int i;
  2093. for (i = 0; i < top; ++i)
  2094. values [i] = values [i + wordsToMove];
  2095. for (i = 0; i < wordsToMove; ++i)
  2096. values [top + i] = 0;
  2097. bits &= 31;
  2098. }
  2099. if (bits != 0)
  2100. {
  2101. const int invBits = 32 - bits;
  2102. --top;
  2103. for (int i = 0; i < top; ++i)
  2104. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2105. values[top] = (values[top] >> bits);
  2106. }
  2107. highestBit = getHighestBit();
  2108. }
  2109. }
  2110. else if (bits > 0)
  2111. {
  2112. // left shift
  2113. ensureSize (((highestBit + bits) >> 5) + 1);
  2114. const int wordsToMove = bits >> 5;
  2115. int top = 1 + (highestBit >> 5);
  2116. highestBit += bits;
  2117. if (wordsToMove > 0)
  2118. {
  2119. int i;
  2120. for (i = top; --i >= 0;)
  2121. values [i + wordsToMove] = values [i];
  2122. for (i = 0; i < wordsToMove; ++i)
  2123. values [i] = 0;
  2124. bits &= 31;
  2125. }
  2126. if (bits != 0)
  2127. {
  2128. const int invBits = 32 - bits;
  2129. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2130. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2131. values [wordsToMove] = values [wordsToMove] << bits;
  2132. }
  2133. highestBit = getHighestBit();
  2134. }
  2135. }
  2136. }
  2137. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2138. {
  2139. BitArray r;
  2140. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2141. r.ensureSize (numBits >> 5);
  2142. r.highestBit = numBits;
  2143. int i = 0;
  2144. while (numBits > 0)
  2145. {
  2146. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2147. numBits -= 32;
  2148. startBit += 32;
  2149. }
  2150. r.highestBit = r.getHighestBit();
  2151. return r;
  2152. }
  2153. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2154. {
  2155. if (numBits > 32)
  2156. {
  2157. jassertfalse // use getBitRange() if you need more than 32 bits..
  2158. numBits = 32;
  2159. }
  2160. numBits = jmin (numBits, highestBit + 1 - startBit);
  2161. if (numBits <= 0)
  2162. return 0;
  2163. const int pos = startBit >> 5;
  2164. const int offset = startBit & 31;
  2165. const int endSpace = 32 - numBits;
  2166. uint32 n = ((uint32) values [pos]) >> offset;
  2167. if (offset > endSpace)
  2168. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2169. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2170. }
  2171. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2172. {
  2173. if (numBits > 32)
  2174. {
  2175. jassertfalse
  2176. numBits = 32;
  2177. }
  2178. for (int i = 0; i < numBits; ++i)
  2179. {
  2180. setBit (startBit + i, (valueToSet & 1) != 0);
  2181. valueToSet >>= 1;
  2182. }
  2183. }
  2184. bool BitArray::isNegative() const throw()
  2185. {
  2186. return negative && ! isEmpty();
  2187. }
  2188. void BitArray::setNegative (const bool neg) throw()
  2189. {
  2190. negative = neg;
  2191. }
  2192. void BitArray::negate() throw()
  2193. {
  2194. negative = (! negative) && ! isEmpty();
  2195. }
  2196. int BitArray::countNumberOfSetBits() const throw()
  2197. {
  2198. int total = 0;
  2199. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2200. {
  2201. unsigned int n = values[i];
  2202. if (n == 0xffffffff)
  2203. {
  2204. total += 32;
  2205. }
  2206. else
  2207. {
  2208. while (n != 0)
  2209. {
  2210. total += (n & 1);
  2211. n >>= 1;
  2212. }
  2213. }
  2214. }
  2215. return total;
  2216. }
  2217. int BitArray::getHighestBit() const throw()
  2218. {
  2219. for (int i = highestBit + 1; --i >= 0;)
  2220. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2221. return i;
  2222. return -1;
  2223. }
  2224. int BitArray::findNextSetBit (int i) const throw()
  2225. {
  2226. for (; i <= highestBit; ++i)
  2227. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2228. return i;
  2229. return -1;
  2230. }
  2231. int BitArray::findNextClearBit (int i) const throw()
  2232. {
  2233. for (; i <= highestBit; ++i)
  2234. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2235. break;
  2236. return i;
  2237. }
  2238. void BitArray::ensureSize (const int numVals) throw()
  2239. {
  2240. if (numVals + 2 >= numValues)
  2241. {
  2242. int oldSize = numValues;
  2243. numValues = ((numVals + 2) * 3) / 2;
  2244. values.realloc (numValues + 1);
  2245. while (oldSize < numValues)
  2246. values [oldSize++] = 0;
  2247. }
  2248. }
  2249. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2250. {
  2251. String s;
  2252. BitArray v (*this);
  2253. if (base == 2 || base == 8 || base == 16)
  2254. {
  2255. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2256. static const tchar* const hexDigits = T("0123456789abcdef");
  2257. for (;;)
  2258. {
  2259. const int remainder = v.getBitRangeAsInt (0, bits);
  2260. v.shiftBits (-bits);
  2261. if (remainder == 0 && v.isEmpty())
  2262. break;
  2263. s = String::charToString (hexDigits [remainder]) + s;
  2264. }
  2265. }
  2266. else if (base == 10)
  2267. {
  2268. const BitArray ten (10);
  2269. BitArray remainder;
  2270. for (;;)
  2271. {
  2272. v.divideBy (ten, remainder);
  2273. if (remainder.isEmpty() && v.isEmpty())
  2274. break;
  2275. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2276. }
  2277. }
  2278. else
  2279. {
  2280. jassertfalse // can't do the specified base
  2281. return String::empty;
  2282. }
  2283. const int length = s.length();
  2284. if (length < minimumNumCharacters)
  2285. s = String::repeatedString (T("0"), minimumNumCharacters - length) + s;
  2286. return isNegative() ? T("-") + s : s;
  2287. }
  2288. void BitArray::parseString (const String& text,
  2289. const int base) throw()
  2290. {
  2291. clear();
  2292. const tchar* t = (const tchar*) text;
  2293. if (base == 2 || base == 8 || base == 16)
  2294. {
  2295. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2296. for (;;)
  2297. {
  2298. const tchar c = *t++;
  2299. const int digit = CharacterFunctions::getHexDigitValue (c);
  2300. if (((unsigned int) digit) < (unsigned int) base)
  2301. {
  2302. shiftBits (bits);
  2303. add (digit);
  2304. }
  2305. else if (c == 0)
  2306. {
  2307. break;
  2308. }
  2309. }
  2310. }
  2311. else if (base == 10)
  2312. {
  2313. const BitArray ten ((unsigned int) 10);
  2314. for (;;)
  2315. {
  2316. const tchar c = *t++;
  2317. if (c >= T('0') && c <= T('9'))
  2318. {
  2319. multiplyBy (ten);
  2320. add ((int) (c - T('0')));
  2321. }
  2322. else if (c == 0)
  2323. {
  2324. break;
  2325. }
  2326. }
  2327. }
  2328. setNegative (text.trimStart().startsWithChar (T('-')));
  2329. }
  2330. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2331. {
  2332. const int numBytes = (getHighestBit() + 8) >> 3;
  2333. MemoryBlock mb ((size_t) numBytes);
  2334. for (int i = 0; i < numBytes; ++i)
  2335. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2336. return mb;
  2337. }
  2338. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2339. {
  2340. clear();
  2341. for (int i = (int) data.getSize(); --i >= 0;)
  2342. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2343. }
  2344. END_JUCE_NAMESPACE
  2345. /*** End of inlined file: juce_BitArray.cpp ***/
  2346. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2347. BEGIN_JUCE_NAMESPACE
  2348. MemoryBlock::MemoryBlock() throw()
  2349. : size (0)
  2350. {
  2351. }
  2352. MemoryBlock::MemoryBlock (const size_t initialSize,
  2353. const bool initialiseToZero) throw()
  2354. {
  2355. if (initialSize > 0)
  2356. {
  2357. size = initialSize;
  2358. data.allocate (initialSize, initialiseToZero);
  2359. }
  2360. else
  2361. {
  2362. size = 0;
  2363. }
  2364. }
  2365. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2366. : size (other.size)
  2367. {
  2368. if (size > 0)
  2369. {
  2370. jassert (other.data != 0);
  2371. data.malloc (size);
  2372. memcpy (data, other.data, size);
  2373. }
  2374. }
  2375. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2376. const size_t sizeInBytes) throw()
  2377. : size (jmax ((size_t) 0, sizeInBytes))
  2378. {
  2379. jassert (sizeInBytes >= 0);
  2380. if (size > 0)
  2381. {
  2382. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2383. data.malloc (size);
  2384. if (dataToInitialiseFrom != 0)
  2385. memcpy (data, dataToInitialiseFrom, size);
  2386. }
  2387. }
  2388. MemoryBlock::~MemoryBlock() throw()
  2389. {
  2390. jassert (size >= 0); // should never happen
  2391. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2392. }
  2393. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2394. {
  2395. if (this != &other)
  2396. {
  2397. setSize (other.size, false);
  2398. memcpy (data, other.data, size);
  2399. }
  2400. return *this;
  2401. }
  2402. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2403. {
  2404. return matches (other.data, other.size);
  2405. }
  2406. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2407. {
  2408. return ! operator== (other);
  2409. }
  2410. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2411. {
  2412. return size == dataSize
  2413. && memcmp (data, dataToCompare, size) == 0;
  2414. }
  2415. // this will resize the block to this size
  2416. void MemoryBlock::setSize (const size_t newSize,
  2417. const bool initialiseToZero) throw()
  2418. {
  2419. if (size != newSize)
  2420. {
  2421. if (newSize <= 0)
  2422. {
  2423. data.free();
  2424. size = 0;
  2425. }
  2426. else
  2427. {
  2428. if (data != 0)
  2429. {
  2430. data.realloc (newSize);
  2431. if (initialiseToZero && (newSize > size))
  2432. zeromem (data + size, newSize - size);
  2433. }
  2434. else
  2435. {
  2436. data.allocate (newSize, initialiseToZero);
  2437. }
  2438. size = newSize;
  2439. }
  2440. }
  2441. }
  2442. void MemoryBlock::ensureSize (const size_t minimumSize,
  2443. const bool initialiseToZero) throw()
  2444. {
  2445. if (size < minimumSize)
  2446. setSize (minimumSize, initialiseToZero);
  2447. }
  2448. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2449. {
  2450. swapVariables (size, other.size);
  2451. data.swapWith (other.data);
  2452. }
  2453. void MemoryBlock::fillWith (const uint8 value) throw()
  2454. {
  2455. memset (data, (int) value, size);
  2456. }
  2457. void MemoryBlock::append (const void* const srcData,
  2458. const size_t numBytes) throw()
  2459. {
  2460. if (numBytes > 0)
  2461. {
  2462. const size_t oldSize = size;
  2463. setSize (size + numBytes);
  2464. memcpy (data + oldSize, srcData, numBytes);
  2465. }
  2466. }
  2467. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2468. {
  2469. const char* d = (const char*) src;
  2470. if (offset < 0)
  2471. {
  2472. d -= offset;
  2473. num -= offset;
  2474. offset = 0;
  2475. }
  2476. if (offset + num > size)
  2477. num = size - offset;
  2478. if (num > 0)
  2479. memcpy (data + offset, d, num);
  2480. }
  2481. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2482. {
  2483. char* d = (char*) dst;
  2484. if (offset < 0)
  2485. {
  2486. zeromem (d, -offset);
  2487. d -= offset;
  2488. num += offset;
  2489. offset = 0;
  2490. }
  2491. if (offset + num > size)
  2492. {
  2493. const size_t newNum = size - offset;
  2494. zeromem (d + newNum, num - newNum);
  2495. num = newNum;
  2496. }
  2497. if (num > 0)
  2498. memcpy (d, data + offset, num);
  2499. }
  2500. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2501. {
  2502. if (startByte < 0)
  2503. {
  2504. numBytesToRemove += startByte;
  2505. startByte = 0;
  2506. }
  2507. if (startByte + numBytesToRemove >= size)
  2508. {
  2509. setSize (startByte);
  2510. }
  2511. else if (numBytesToRemove > 0)
  2512. {
  2513. memmove (data + startByte,
  2514. data + startByte + numBytesToRemove,
  2515. size - (startByte + numBytesToRemove));
  2516. setSize (size - numBytesToRemove);
  2517. }
  2518. }
  2519. const String MemoryBlock::toString() const throw()
  2520. {
  2521. return String ((const char*) data, size);
  2522. }
  2523. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2524. {
  2525. int res = 0;
  2526. size_t byte = bitRangeStart >> 3;
  2527. int offsetInByte = bitRangeStart & 7;
  2528. size_t bitsSoFar = 0;
  2529. while (numBits > 0 && (size_t) byte < size)
  2530. {
  2531. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2532. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2533. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2534. bitsSoFar += bitsThisTime;
  2535. numBits -= bitsThisTime;
  2536. ++byte;
  2537. offsetInByte = 0;
  2538. }
  2539. return res;
  2540. }
  2541. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2542. {
  2543. size_t byte = bitRangeStart >> 3;
  2544. int offsetInByte = bitRangeStart & 7;
  2545. unsigned int mask = ~((((unsigned int)0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2546. while (numBits > 0 && (size_t) byte < size)
  2547. {
  2548. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2549. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int)0xffffffff) >> offsetInByte) << offsetInByte);
  2550. const unsigned int tempBits = bitsToSet << offsetInByte;
  2551. data[byte] = (char)((data[byte] & tempMask) | tempBits);
  2552. ++byte;
  2553. numBits -= bitsThisTime;
  2554. bitsToSet >>= bitsThisTime;
  2555. mask >>= bitsThisTime;
  2556. offsetInByte = 0;
  2557. }
  2558. }
  2559. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2560. {
  2561. ensureSize (hex.length() >> 1);
  2562. char* dest = data;
  2563. int i = 0;
  2564. for (;;)
  2565. {
  2566. int byte = 0;
  2567. for (int loop = 2; --loop >= 0;)
  2568. {
  2569. byte <<= 4;
  2570. for (;;)
  2571. {
  2572. const tchar c = hex [i++];
  2573. if (c >= T('0') && c <= T('9'))
  2574. {
  2575. byte |= c - T('0');
  2576. break;
  2577. }
  2578. else if (c >= T('a') && c <= T('z'))
  2579. {
  2580. byte |= c - (T('a') - 10);
  2581. break;
  2582. }
  2583. else if (c >= T('A') && c <= T('Z'))
  2584. {
  2585. byte |= c - (T('A') - 10);
  2586. break;
  2587. }
  2588. else if (c == 0)
  2589. {
  2590. setSize ((int) (dest - data));
  2591. return;
  2592. }
  2593. }
  2594. }
  2595. *dest++ = (char) byte;
  2596. }
  2597. }
  2598. static const char* const encodingTable
  2599. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2600. const String MemoryBlock::toBase64Encoding() const throw()
  2601. {
  2602. const size_t numChars = ((size << 3) + 5) / 6;
  2603. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2604. const int initialLen = destString.length();
  2605. destString.preallocateStorage (initialLen + 2 + numChars);
  2606. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2607. *d++ = T('.');
  2608. for (size_t i = 0; i < numChars; ++i)
  2609. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2610. *d++ = 0;
  2611. return destString;
  2612. }
  2613. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2614. {
  2615. const int startPos = s.indexOfChar (T('.')) + 1;
  2616. if (startPos <= 0)
  2617. return false;
  2618. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2619. setSize (numBytesNeeded, true);
  2620. const int numChars = s.length() - startPos;
  2621. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2622. int pos = 0;
  2623. for (int i = 0; i < numChars; ++i)
  2624. {
  2625. const char c = (char) srcChars[i];
  2626. for (int j = 0; j < 64; ++j)
  2627. {
  2628. if (encodingTable[j] == c)
  2629. {
  2630. setBitRange (pos, 6, j);
  2631. pos += 6;
  2632. break;
  2633. }
  2634. }
  2635. }
  2636. return true;
  2637. }
  2638. END_JUCE_NAMESPACE
  2639. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2640. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2641. BEGIN_JUCE_NAMESPACE
  2642. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2643. : properties (ignoreCaseOfKeyNames),
  2644. fallbackProperties (0),
  2645. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2646. {
  2647. }
  2648. PropertySet::PropertySet (const PropertySet& other) throw()
  2649. : properties (other.properties),
  2650. fallbackProperties (other.fallbackProperties),
  2651. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2652. {
  2653. }
  2654. const PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2655. {
  2656. properties = other.properties;
  2657. fallbackProperties = other.fallbackProperties;
  2658. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2659. propertyChanged();
  2660. return *this;
  2661. }
  2662. PropertySet::~PropertySet()
  2663. {
  2664. }
  2665. void PropertySet::clear()
  2666. {
  2667. const ScopedLock sl (lock);
  2668. if (properties.size() > 0)
  2669. {
  2670. properties.clear();
  2671. propertyChanged();
  2672. }
  2673. }
  2674. const String PropertySet::getValue (const String& keyName,
  2675. const String& defaultValue) const throw()
  2676. {
  2677. const ScopedLock sl (lock);
  2678. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2679. if (index >= 0)
  2680. return properties.getAllValues() [index];
  2681. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2682. : defaultValue;
  2683. }
  2684. int PropertySet::getIntValue (const String& keyName,
  2685. const int defaultValue) const throw()
  2686. {
  2687. const ScopedLock sl (lock);
  2688. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2689. if (index >= 0)
  2690. return properties.getAllValues() [index].getIntValue();
  2691. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2692. : defaultValue;
  2693. }
  2694. double PropertySet::getDoubleValue (const String& keyName,
  2695. const double defaultValue) const throw()
  2696. {
  2697. const ScopedLock sl (lock);
  2698. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2699. if (index >= 0)
  2700. return properties.getAllValues()[index].getDoubleValue();
  2701. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2702. : defaultValue;
  2703. }
  2704. bool PropertySet::getBoolValue (const String& keyName,
  2705. const bool defaultValue) const throw()
  2706. {
  2707. const ScopedLock sl (lock);
  2708. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2709. if (index >= 0)
  2710. return properties.getAllValues() [index].getIntValue() != 0;
  2711. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2712. : defaultValue;
  2713. }
  2714. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2715. {
  2716. XmlDocument doc (getValue (keyName));
  2717. return doc.getDocumentElement();
  2718. }
  2719. void PropertySet::setValue (const String& keyName,
  2720. const String& value) throw()
  2721. {
  2722. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2723. if (keyName.isNotEmpty())
  2724. {
  2725. const ScopedLock sl (lock);
  2726. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2727. if (index < 0 || properties.getAllValues() [index] != value)
  2728. {
  2729. properties.set (keyName, value);
  2730. propertyChanged();
  2731. }
  2732. }
  2733. }
  2734. void PropertySet::removeValue (const String& keyName) throw()
  2735. {
  2736. if (keyName.isNotEmpty())
  2737. {
  2738. const ScopedLock sl (lock);
  2739. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2740. if (index >= 0)
  2741. {
  2742. properties.remove (keyName);
  2743. propertyChanged();
  2744. }
  2745. }
  2746. }
  2747. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2748. {
  2749. setValue (keyName, String (value));
  2750. }
  2751. void PropertySet::setValue (const String& keyName, const int value) throw()
  2752. {
  2753. setValue (keyName, String (value));
  2754. }
  2755. void PropertySet::setValue (const String& keyName, const double value) throw()
  2756. {
  2757. setValue (keyName, String (value));
  2758. }
  2759. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2760. {
  2761. setValue (keyName, String ((value) ? T("1") : T("0")));
  2762. }
  2763. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2764. {
  2765. setValue (keyName, (xml == 0) ? String::empty
  2766. : xml->createDocument (String::empty, true));
  2767. }
  2768. bool PropertySet::containsKey (const String& keyName) const throw()
  2769. {
  2770. const ScopedLock sl (lock);
  2771. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2772. }
  2773. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2774. {
  2775. const ScopedLock sl (lock);
  2776. fallbackProperties = fallbackProperties_;
  2777. }
  2778. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2779. {
  2780. const ScopedLock sl (lock);
  2781. XmlElement* const xml = new XmlElement (nodeName);
  2782. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2783. {
  2784. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2785. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2786. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2787. }
  2788. return xml;
  2789. }
  2790. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2791. {
  2792. const ScopedLock sl (lock);
  2793. clear();
  2794. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2795. {
  2796. if (e->hasAttribute (T("name"))
  2797. && e->hasAttribute (T("val")))
  2798. {
  2799. properties.set (e->getStringAttribute (T("name")),
  2800. e->getStringAttribute (T("val")));
  2801. }
  2802. }
  2803. if (properties.size() > 0)
  2804. propertyChanged();
  2805. }
  2806. void PropertySet::propertyChanged()
  2807. {
  2808. }
  2809. END_JUCE_NAMESPACE
  2810. /*** End of inlined file: juce_PropertySet.cpp ***/
  2811. /*** Start of inlined file: juce_Variant.cpp ***/
  2812. BEGIN_JUCE_NAMESPACE
  2813. var::var() throw()
  2814. : type (voidType)
  2815. {
  2816. value.doubleValue = 0;
  2817. }
  2818. var::~var() throw()
  2819. {
  2820. if (type == stringType)
  2821. delete value.stringValue;
  2822. else if (type == objectType && value.objectValue != 0)
  2823. value.objectValue->decReferenceCount();
  2824. }
  2825. const var var::null;
  2826. var::var (const var& valueToCopy)
  2827. : type (valueToCopy.type),
  2828. value (valueToCopy.value)
  2829. {
  2830. if (type == stringType)
  2831. value.stringValue = new String (*(value.stringValue));
  2832. else if (type == objectType && value.objectValue != 0)
  2833. value.objectValue->incReferenceCount();
  2834. }
  2835. var::var (const int value_) throw()
  2836. : type (intType)
  2837. {
  2838. value.intValue = value_;
  2839. }
  2840. var::var (const bool value_) throw()
  2841. : type (boolType)
  2842. {
  2843. value.boolValue = value_;
  2844. }
  2845. var::var (const double value_) throw()
  2846. : type (doubleType)
  2847. {
  2848. value.doubleValue = value_;
  2849. }
  2850. var::var (const String& value_)
  2851. : type (stringType)
  2852. {
  2853. value.stringValue = new String (value_);
  2854. }
  2855. var::var (const char* const value_)
  2856. : type (stringType)
  2857. {
  2858. value.stringValue = new String (value_);
  2859. }
  2860. var::var (const juce_wchar* const value_)
  2861. : type (stringType)
  2862. {
  2863. value.stringValue = new String (value_);
  2864. }
  2865. var::var (DynamicObject* const object)
  2866. : type (objectType)
  2867. {
  2868. value.objectValue = object;
  2869. if (object != 0)
  2870. object->incReferenceCount();
  2871. }
  2872. var::var (MethodFunction method_) throw()
  2873. : type (methodType)
  2874. {
  2875. value.methodValue = method_;
  2876. }
  2877. void var::swapWith (var& other) throw()
  2878. {
  2879. swapVariables (type, other.type);
  2880. swapVariables (value, other.value);
  2881. }
  2882. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2883. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2884. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2885. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2886. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2887. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2888. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2889. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2890. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2891. var::operator int() const
  2892. {
  2893. switch (type)
  2894. {
  2895. case voidType: break;
  2896. case intType: return value.intValue;
  2897. case boolType: return value.boolValue ? 1 : 0;
  2898. case doubleType: return (int) value.doubleValue;
  2899. case stringType: return value.stringValue->getIntValue();
  2900. case objectType: break;
  2901. default: jassertfalse; break;
  2902. }
  2903. return 0;
  2904. }
  2905. var::operator bool() const
  2906. {
  2907. switch (type)
  2908. {
  2909. case voidType: break;
  2910. case intType: return value.intValue != 0;
  2911. case boolType: return value.boolValue;
  2912. case doubleType: return value.doubleValue != 0;
  2913. case stringType: return value.stringValue->getIntValue() != 0
  2914. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2915. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2916. case objectType: return value.objectValue != 0;
  2917. default: jassertfalse; break;
  2918. }
  2919. return false;
  2920. }
  2921. var::operator float() const
  2922. {
  2923. return (float) operator double();
  2924. }
  2925. var::operator double() const
  2926. {
  2927. switch (type)
  2928. {
  2929. case voidType: break;
  2930. case intType: return value.intValue;
  2931. case boolType: return value.boolValue ? 1.0 : 0.0;
  2932. case doubleType: return value.doubleValue;
  2933. case stringType: return value.stringValue->getDoubleValue();
  2934. case objectType: break;
  2935. default: jassertfalse; break;
  2936. }
  2937. return 0.0;
  2938. }
  2939. const String var::toString() const
  2940. {
  2941. switch (type)
  2942. {
  2943. case voidType: return String::empty;
  2944. case intType: return String (value.intValue);
  2945. case boolType: return value.boolValue ? T("1") : T("0");
  2946. case doubleType: return String (value.doubleValue);
  2947. case stringType: return *(value.stringValue);
  2948. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2949. case methodType: return "Method";
  2950. default: jassertfalse; break;
  2951. }
  2952. return String::empty;
  2953. }
  2954. var::operator const String() const
  2955. {
  2956. return toString();
  2957. }
  2958. DynamicObject* var::getObject() const
  2959. {
  2960. return type == objectType ? value.objectValue : 0;
  2961. }
  2962. bool var::operator== (const var& other) const throw()
  2963. {
  2964. switch (type)
  2965. {
  2966. case voidType: return other.isVoid();
  2967. case intType: return value.intValue == (int) other;
  2968. case boolType: return value.boolValue == (bool) other;
  2969. case doubleType: return value.doubleValue == (double) other;
  2970. case stringType: return (*(value.stringValue)) == other.toString();
  2971. case objectType: return value.objectValue == other.getObject();
  2972. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  2973. default: jassertfalse; break;
  2974. }
  2975. return false;
  2976. }
  2977. bool var::operator!= (const var& other) const throw()
  2978. {
  2979. return ! operator== (other);
  2980. }
  2981. void var::writeToStream (OutputStream& output) const
  2982. {
  2983. switch (type)
  2984. {
  2985. case voidType: output.writeCompressedInt (0); break;
  2986. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  2987. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  2988. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  2989. case stringType:
  2990. {
  2991. const int len = value.stringValue->copyToUTF8 (0);
  2992. output.writeCompressedInt (len + 1);
  2993. output.writeByte (5);
  2994. HeapBlock <uint8> temp (len);
  2995. value.stringValue->copyToUTF8 (temp);
  2996. output.write (temp, len);
  2997. break;
  2998. }
  2999. case objectType:
  3000. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3001. default: jassertfalse; break; // Is this a corrupted object?
  3002. }
  3003. }
  3004. const var var::readFromStream (InputStream& input)
  3005. {
  3006. const int numBytes = input.readCompressedInt();
  3007. if (numBytes > 0)
  3008. {
  3009. switch (input.readByte())
  3010. {
  3011. case 1: return var (input.readInt());
  3012. case 2: return var (true);
  3013. case 3: return var (false);
  3014. case 4: return var (input.readDouble());
  3015. case 5:
  3016. {
  3017. MemoryBlock mb;
  3018. input.readIntoMemoryBlock (mb, numBytes - 1);
  3019. return var (String::fromUTF8 ((const uint8*) mb.getData(), (int) mb.getSize()));
  3020. }
  3021. default: input.skipNextBytes (numBytes - 1); break;
  3022. }
  3023. }
  3024. return var::null;
  3025. }
  3026. const var var::operator[] (const var::identifier& propertyName) const
  3027. {
  3028. if (type == objectType && value.objectValue != 0)
  3029. return value.objectValue->getProperty (propertyName);
  3030. return var::null;
  3031. }
  3032. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3033. {
  3034. if (type == objectType && value.objectValue != 0)
  3035. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3036. return var::null;
  3037. }
  3038. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3039. {
  3040. if (isMethod())
  3041. {
  3042. DynamicObject* const target = targetObject.getObject();
  3043. if (target != 0)
  3044. return (target->*(value.methodValue)) (arguments, numArguments);
  3045. }
  3046. return var::null;
  3047. }
  3048. const var var::call (const var::identifier& method) const
  3049. {
  3050. return invoke (method, 0, 0);
  3051. }
  3052. const var var::call (const var::identifier& method, const var& arg1) const
  3053. {
  3054. return invoke (method, &arg1, 1);
  3055. }
  3056. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3057. {
  3058. var args[] = { arg1, arg2 };
  3059. return invoke (method, args, 2);
  3060. }
  3061. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3062. {
  3063. var args[] = { arg1, arg2, arg3 };
  3064. return invoke (method, args, 3);
  3065. }
  3066. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3067. {
  3068. var args[] = { arg1, arg2, arg3, arg4 };
  3069. return invoke (method, args, 4);
  3070. }
  3071. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3072. {
  3073. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3074. return invoke (method, args, 5);
  3075. }
  3076. var::identifier::identifier() throw()
  3077. : hashCode (0)
  3078. {
  3079. }
  3080. var::identifier::identifier (const String& name_)
  3081. : name (name_),
  3082. hashCode (name_.hashCode())
  3083. {
  3084. jassert (name_.isNotEmpty());
  3085. }
  3086. var::identifier::identifier (const char* const name_)
  3087. : name (name_),
  3088. hashCode (name.hashCode())
  3089. {
  3090. jassert (name.isNotEmpty());
  3091. }
  3092. var::identifier::~identifier()
  3093. {
  3094. }
  3095. END_JUCE_NAMESPACE
  3096. /*** End of inlined file: juce_Variant.cpp ***/
  3097. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3098. BEGIN_JUCE_NAMESPACE
  3099. NamedValueSet::NamedValue::NamedValue() throw()
  3100. {
  3101. }
  3102. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3103. : name (name_), value (value_)
  3104. {
  3105. }
  3106. NamedValueSet::NamedValueSet() throw()
  3107. {
  3108. }
  3109. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3110. : values (other.values)
  3111. {
  3112. }
  3113. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3114. {
  3115. values = other.values;
  3116. return *this;
  3117. }
  3118. NamedValueSet::~NamedValueSet()
  3119. {
  3120. }
  3121. int NamedValueSet::size() const throw()
  3122. {
  3123. return values.size();
  3124. }
  3125. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3126. {
  3127. for (int i = values.size(); --i >= 0;)
  3128. {
  3129. const NamedValue& v = values.getReference(i);
  3130. if (v.name == name)
  3131. return v.value;
  3132. }
  3133. return var::null;
  3134. }
  3135. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3136. {
  3137. const var* v = getItem (name);
  3138. return v != 0 ? *v : defaultReturnValue;
  3139. }
  3140. var* NamedValueSet::getItem (const var::identifier& name) const
  3141. {
  3142. for (int i = values.size(); --i >= 0;)
  3143. {
  3144. NamedValue& v = values.getReference(i);
  3145. if (v.name == name)
  3146. return &(v.value);
  3147. }
  3148. return 0;
  3149. }
  3150. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3151. {
  3152. for (int i = values.size(); --i >= 0;)
  3153. {
  3154. NamedValue& v = values.getReference(i);
  3155. if (v.name == name)
  3156. {
  3157. if (v.value == newValue)
  3158. return false;
  3159. v.value = newValue;
  3160. return true;
  3161. }
  3162. }
  3163. values.add (NamedValue (name, newValue));
  3164. return true;
  3165. }
  3166. bool NamedValueSet::contains (const var::identifier& name) const
  3167. {
  3168. return getItem (name) != 0;
  3169. }
  3170. bool NamedValueSet::remove (const var::identifier& name)
  3171. {
  3172. for (int i = values.size(); --i >= 0;)
  3173. {
  3174. if (values.getReference(i).name == name)
  3175. {
  3176. values.remove (i);
  3177. return true;
  3178. }
  3179. }
  3180. return false;
  3181. }
  3182. const var::identifier NamedValueSet::getName (int index) const
  3183. {
  3184. jassert (((unsigned int) index) < (unsigned int) values.size());
  3185. return values [index].name;
  3186. }
  3187. void NamedValueSet::clear()
  3188. {
  3189. values.clear();
  3190. }
  3191. END_JUCE_NAMESPACE
  3192. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3193. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3194. BEGIN_JUCE_NAMESPACE
  3195. DynamicObject::DynamicObject()
  3196. {
  3197. }
  3198. DynamicObject::~DynamicObject()
  3199. {
  3200. }
  3201. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3202. {
  3203. var* const v = properties.getItem (propertyName);
  3204. return v != 0 && ! v->isMethod();
  3205. }
  3206. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3207. {
  3208. return properties [propertyName];
  3209. }
  3210. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3211. {
  3212. properties.set (propertyName, newValue);
  3213. }
  3214. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3215. {
  3216. properties.remove (propertyName);
  3217. }
  3218. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3219. {
  3220. return getProperty (methodName).isMethod();
  3221. }
  3222. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3223. const var* parameters,
  3224. int numParameters)
  3225. {
  3226. return properties [methodName].invoke (var (this), parameters, numParameters);
  3227. }
  3228. void DynamicObject::setMethod (const var::identifier& name,
  3229. var::MethodFunction methodFunction)
  3230. {
  3231. properties.set (name, var (methodFunction));
  3232. }
  3233. void DynamicObject::clear()
  3234. {
  3235. properties.clear();
  3236. }
  3237. END_JUCE_NAMESPACE
  3238. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3239. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3240. BEGIN_JUCE_NAMESPACE
  3241. static const uint32 initialPValues [18] =
  3242. {
  3243. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3244. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3245. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3246. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3247. 0x9216d5d9, 0x8979fb1b
  3248. };
  3249. static const uint32 initialSValues [4 * 256] =
  3250. {
  3251. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3252. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3253. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3254. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3255. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3256. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3257. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3258. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3259. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3260. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3261. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3262. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3263. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3264. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3265. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3266. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3267. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3268. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3269. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3270. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3271. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3272. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3273. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3274. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3275. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3276. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3277. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3278. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3279. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3280. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3281. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3282. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3283. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3284. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3285. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3286. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3287. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3288. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3289. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3290. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3291. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3292. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3293. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3294. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3295. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3296. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3297. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3298. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3299. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3300. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3301. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3302. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3303. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3304. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3305. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3306. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3307. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3308. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3309. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3310. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3311. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3312. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3313. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3314. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3315. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3316. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3317. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3318. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3319. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3320. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3321. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3322. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3323. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3324. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3325. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3326. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3327. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3328. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3329. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3330. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3331. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3332. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3333. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3334. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3335. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3336. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3337. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3338. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3339. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3340. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3341. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3342. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3343. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3344. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3345. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3346. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3347. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3348. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3349. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3350. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3351. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3352. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3353. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3354. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3355. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3356. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3357. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3358. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3359. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3360. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3361. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3362. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3363. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3364. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3365. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3366. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3367. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3368. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3369. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3370. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3371. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3372. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3373. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3374. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3375. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3376. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3377. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3378. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3379. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3380. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3381. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3382. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3383. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3384. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3385. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3386. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3387. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3388. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3389. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3390. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3391. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3392. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3393. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3394. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3395. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3396. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3397. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3398. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3399. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3400. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3401. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3402. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3403. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3404. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3405. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3406. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3407. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3408. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3409. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3410. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3411. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3412. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3413. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3414. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3415. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3416. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3417. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3418. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3419. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3420. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3421. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3422. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3423. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3424. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3425. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3426. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3427. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3428. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3429. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3430. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3431. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3432. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3433. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3434. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3435. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3436. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3437. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3438. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3439. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3440. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3441. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3442. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3443. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3444. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3445. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3446. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3447. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3448. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3449. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3450. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3451. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3452. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3453. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3454. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3455. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3456. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3457. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3458. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3459. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3460. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3461. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3462. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3463. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3464. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3465. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3466. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3467. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3468. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3469. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3470. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3471. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3472. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3473. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3474. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3475. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3476. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3477. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3478. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3479. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3480. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3481. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3482. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3483. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3484. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3485. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3486. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3487. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3488. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3489. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3490. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3491. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3492. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3493. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3494. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3495. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3496. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3497. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3498. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3499. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3500. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3501. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3502. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3503. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3504. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3505. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3506. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3507. };
  3508. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3509. {
  3510. memcpy (p, initialPValues, sizeof (p));
  3511. int i, j;
  3512. for (i = 4; --i >= 0;)
  3513. {
  3514. s[i].malloc (256);
  3515. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3516. }
  3517. j = 0;
  3518. for (i = 0; i < 18; ++i)
  3519. {
  3520. uint32 d = 0;
  3521. for (int k = 0; k < 4; ++k)
  3522. {
  3523. d = (d << 8) | keyData[j];
  3524. if (++j >= keyBytes)
  3525. j = 0;
  3526. }
  3527. p[i] = initialPValues[i] ^ d;
  3528. }
  3529. uint32 l = 0, r = 0;
  3530. for (i = 0; i < 18; i += 2)
  3531. {
  3532. encrypt (l, r);
  3533. p[i] = l;
  3534. p[i + 1] = r;
  3535. }
  3536. for (i = 0; i < 4; ++i)
  3537. {
  3538. for (j = 0; j < 256; j += 2)
  3539. {
  3540. encrypt (l, r);
  3541. s[i][j] = l;
  3542. s[i][j + 1] = r;
  3543. }
  3544. }
  3545. }
  3546. BlowFish::BlowFish (const BlowFish& other)
  3547. {
  3548. for (int i = 4; --i >= 0;)
  3549. s[i].malloc (256);
  3550. operator= (other);
  3551. }
  3552. const BlowFish& BlowFish::operator= (const BlowFish& other)
  3553. {
  3554. memcpy (p, other.p, sizeof (p));
  3555. for (int i = 4; --i >= 0;)
  3556. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3557. return *this;
  3558. }
  3559. BlowFish::~BlowFish()
  3560. {
  3561. }
  3562. uint32 BlowFish::F (uint32 x) const
  3563. {
  3564. uint16 a, b, c, d;
  3565. uint32 y;
  3566. d = (uint16) (x & 0xff);
  3567. x >>= 8;
  3568. c = (uint16) (x & 0xff);
  3569. x >>= 8;
  3570. b = (uint16) (x & 0xff);
  3571. x >>= 8;
  3572. a = (uint16) (x & 0xff);
  3573. y = s[0][a] + s[1][b];
  3574. y = y ^ s[2][c];
  3575. y = y + s[3][d];
  3576. return y;
  3577. }
  3578. void BlowFish::encrypt (uint32& data1,
  3579. uint32& data2) const
  3580. {
  3581. uint32 l = data1;
  3582. uint32 r = data2;
  3583. for (int i = 0; i < 16; ++i)
  3584. {
  3585. l = l ^ p[i];
  3586. r = F (l) ^ r;
  3587. const uint32 temp = l;
  3588. l = r;
  3589. r = temp;
  3590. }
  3591. const uint32 temp = l;
  3592. l = r;
  3593. r = temp;
  3594. r = r ^ p[16];
  3595. l = l ^ p[17];
  3596. data1 = l;
  3597. data2 = r;
  3598. }
  3599. void BlowFish::decrypt (uint32& data1,
  3600. uint32& data2) const
  3601. {
  3602. uint32 l = data1;
  3603. uint32 r = data2;
  3604. for (int i = 17; i > 1; --i)
  3605. {
  3606. l =l ^ p[i];
  3607. r = F (l) ^ r;
  3608. const uint32 temp = l;
  3609. l = r;
  3610. r = temp;
  3611. }
  3612. const uint32 temp = l;
  3613. l = r;
  3614. r = temp;
  3615. r = r ^ p[1];
  3616. l = l ^ p[0];
  3617. data1 = l;
  3618. data2 = r;
  3619. }
  3620. END_JUCE_NAMESPACE
  3621. /*** End of inlined file: juce_BlowFish.cpp ***/
  3622. /*** Start of inlined file: juce_MD5.cpp ***/
  3623. BEGIN_JUCE_NAMESPACE
  3624. MD5::MD5()
  3625. {
  3626. zeromem (result, sizeof (result));
  3627. }
  3628. MD5::MD5 (const MD5& other)
  3629. {
  3630. memcpy (result, other.result, sizeof (result));
  3631. }
  3632. const MD5& MD5::operator= (const MD5& other)
  3633. {
  3634. memcpy (result, other.result, sizeof (result));
  3635. return *this;
  3636. }
  3637. MD5::MD5 (const MemoryBlock& data)
  3638. {
  3639. ProcessContext context;
  3640. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3641. context.finish (result);
  3642. }
  3643. MD5::MD5 (const char* data, const size_t numBytes)
  3644. {
  3645. ProcessContext context;
  3646. context.processBlock ((const uint8*) data, numBytes);
  3647. context.finish (result);
  3648. }
  3649. MD5::MD5 (const String& text)
  3650. {
  3651. ProcessContext context;
  3652. const int len = text.length();
  3653. const juce_wchar* const t = text;
  3654. for (int i = 0; i < len; ++i)
  3655. {
  3656. // force the string into integer-sized unicode characters, to try to make it
  3657. // get the same results on all platforms + compilers.
  3658. uint32 unicodeChar = (uint32) t[i];
  3659. ByteOrder::swapIfBigEndian (unicodeChar);
  3660. context.processBlock ((const uint8*) &unicodeChar,
  3661. sizeof (unicodeChar));
  3662. }
  3663. context.finish (result);
  3664. }
  3665. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3666. {
  3667. ProcessContext context;
  3668. if (numBytesToRead < 0)
  3669. numBytesToRead = std::numeric_limits<int64>::max();
  3670. while (numBytesToRead > 0)
  3671. {
  3672. char tempBuffer [512];
  3673. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3674. if (bytesRead <= 0)
  3675. break;
  3676. numBytesToRead -= bytesRead;
  3677. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3678. }
  3679. context.finish (result);
  3680. }
  3681. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3682. {
  3683. processStream (input, numBytesToRead);
  3684. }
  3685. MD5::MD5 (const File& file)
  3686. {
  3687. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3688. if (fin != 0)
  3689. processStream (*fin, -1);
  3690. else
  3691. zeromem (result, sizeof (result));
  3692. }
  3693. MD5::~MD5()
  3694. {
  3695. }
  3696. MD5::ProcessContext::ProcessContext()
  3697. {
  3698. state[0] = 0x67452301;
  3699. state[1] = 0xefcdab89;
  3700. state[2] = 0x98badcfe;
  3701. state[3] = 0x10325476;
  3702. count[0] = 0;
  3703. count[1] = 0;
  3704. }
  3705. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3706. {
  3707. int bufferPos = ((count[0] >> 3) & 0x3F);
  3708. count[0] += (uint32) (dataSize << 3);
  3709. if (count[0] < ((uint32) dataSize << 3))
  3710. count[1]++;
  3711. count[1] += (uint32) (dataSize >> 29);
  3712. const size_t spaceLeft = 64 - bufferPos;
  3713. size_t i = 0;
  3714. if (dataSize >= spaceLeft)
  3715. {
  3716. memcpy (buffer + bufferPos, data, spaceLeft);
  3717. transform (buffer);
  3718. i = spaceLeft;
  3719. while (i + 64 <= dataSize)
  3720. {
  3721. transform (data + i);
  3722. i += 64;
  3723. }
  3724. bufferPos = 0;
  3725. }
  3726. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3727. }
  3728. static void encode (uint8* const output,
  3729. const uint32* const input,
  3730. const int numBytes)
  3731. {
  3732. uint32* const o = (uint32*) output;
  3733. for (int i = 0; i < (numBytes >> 2); ++i)
  3734. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3735. }
  3736. static void decode (uint32* const output,
  3737. const uint8* const input,
  3738. const int numBytes)
  3739. {
  3740. for (int i = 0; i < (numBytes >> 2); ++i)
  3741. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3742. }
  3743. void MD5::ProcessContext::finish (uint8* const result)
  3744. {
  3745. unsigned char encodedLength[8];
  3746. encode (encodedLength, count, 8);
  3747. // Pad out to 56 mod 64.
  3748. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3749. const int paddingLength = (index < 56) ? (56 - index)
  3750. : (120 - index);
  3751. uint8 paddingBuffer [64];
  3752. zeromem (paddingBuffer, paddingLength);
  3753. paddingBuffer [0] = 0x80;
  3754. processBlock (paddingBuffer, paddingLength);
  3755. processBlock (encodedLength, 8);
  3756. encode (result, state, 16);
  3757. zeromem (buffer, sizeof (buffer));
  3758. }
  3759. #define S11 7
  3760. #define S12 12
  3761. #define S13 17
  3762. #define S14 22
  3763. #define S21 5
  3764. #define S22 9
  3765. #define S23 14
  3766. #define S24 20
  3767. #define S31 4
  3768. #define S32 11
  3769. #define S33 16
  3770. #define S34 23
  3771. #define S41 6
  3772. #define S42 10
  3773. #define S43 15
  3774. #define S44 21
  3775. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) { return (x & y) | (~x & z); }
  3776. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) { return (x & z) | (y & ~z); }
  3777. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) { return x ^ y ^ z; }
  3778. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) { return y ^ (x | ~z); }
  3779. static inline uint32 rotateLeft (const uint32 x, const uint32 n) { return (x << n) | (x >> (32 - n)); }
  3780. static inline void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3781. {
  3782. a += F (b, c, d) + x + ac;
  3783. a = rotateLeft (a, s) + b;
  3784. }
  3785. static inline void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3786. {
  3787. a += G (b, c, d) + x + ac;
  3788. a = rotateLeft (a, s) + b;
  3789. }
  3790. static inline void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3791. {
  3792. a += H (b, c, d) + x + ac;
  3793. a = rotateLeft (a, s) + b;
  3794. }
  3795. static inline void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3796. {
  3797. a += I (b, c, d) + x + ac;
  3798. a = rotateLeft (a, s) + b;
  3799. }
  3800. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3801. {
  3802. uint32 a = state[0];
  3803. uint32 b = state[1];
  3804. uint32 c = state[2];
  3805. uint32 d = state[3];
  3806. uint32 x[16];
  3807. decode (x, bufferToTransform, 64);
  3808. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3809. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3810. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3811. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3812. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3813. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3814. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3815. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3816. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3817. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3818. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3819. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3820. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3821. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3822. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3823. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3824. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3825. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3826. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3827. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3828. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3829. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3830. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3831. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3832. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3833. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3834. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3835. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3836. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3837. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3838. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3839. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3840. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3841. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3842. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3843. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3844. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3845. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3846. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3847. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3848. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3849. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3850. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3851. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3852. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3853. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3854. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3855. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3856. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3857. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3858. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3859. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3860. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3861. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3862. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3863. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3864. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3865. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3866. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3867. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3868. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3869. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3870. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3871. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3872. state[0] += a;
  3873. state[1] += b;
  3874. state[2] += c;
  3875. state[3] += d;
  3876. zeromem (x, sizeof (x));
  3877. }
  3878. const MemoryBlock MD5::getRawChecksumData() const
  3879. {
  3880. return MemoryBlock (result, 16);
  3881. }
  3882. const String MD5::toHexString() const
  3883. {
  3884. return String::toHexString (result, 16, 0);
  3885. }
  3886. bool MD5::operator== (const MD5& other) const
  3887. {
  3888. return memcmp (result, other.result, 16) == 0;
  3889. }
  3890. bool MD5::operator!= (const MD5& other) const
  3891. {
  3892. return ! operator== (other);
  3893. }
  3894. END_JUCE_NAMESPACE
  3895. /*** End of inlined file: juce_MD5.cpp ***/
  3896. /*** Start of inlined file: juce_Primes.cpp ***/
  3897. BEGIN_JUCE_NAMESPACE
  3898. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3899. {
  3900. result.setBit (numBits);
  3901. result.clearBit (numBits); // to enlarge the array
  3902. result.setBit (0);
  3903. int n = 2;
  3904. do
  3905. {
  3906. for (int i = n + n; i < numBits; i += n)
  3907. result.setBit (i);
  3908. n = result.findNextClearBit (n + 1);
  3909. }
  3910. while (n <= (numBits >> 1));
  3911. }
  3912. static void bigSieve (const BitArray& base,
  3913. const int numBits,
  3914. BitArray& result,
  3915. const BitArray& smallSieve,
  3916. const int smallSieveSize) throw()
  3917. {
  3918. jassert (! base[0]); // must be even!
  3919. result.setBit (numBits);
  3920. result.clearBit (numBits); // to enlarge the array
  3921. int index = smallSieve.findNextClearBit (0);
  3922. do
  3923. {
  3924. const int prime = (index << 1) + 1;
  3925. BitArray r (base);
  3926. BitArray remainder;
  3927. r.divideBy (prime, remainder);
  3928. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3929. if (r.isEmpty())
  3930. i += prime;
  3931. if ((i & 1) == 0)
  3932. i += prime;
  3933. i = (i - 1) >> 1;
  3934. while (i < numBits)
  3935. {
  3936. result.setBit (i);
  3937. i += prime;
  3938. }
  3939. index = smallSieve.findNextClearBit (index + 1);
  3940. }
  3941. while (index < smallSieveSize);
  3942. }
  3943. static bool findCandidate (const BitArray& base,
  3944. const BitArray& sieve,
  3945. const int numBits,
  3946. BitArray& result,
  3947. const int certainty) throw()
  3948. {
  3949. for (int i = 0; i < numBits; ++i)
  3950. {
  3951. if (! sieve[i])
  3952. {
  3953. result = base;
  3954. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3955. if (Primes::isProbablyPrime (result, certainty))
  3956. return true;
  3957. }
  3958. }
  3959. return false;
  3960. }
  3961. const BitArray Primes::createProbablePrime (const int bitLength,
  3962. const int certainty,
  3963. const int* randomSeeds,
  3964. int numRandomSeeds) throw()
  3965. {
  3966. int defaultSeeds [16];
  3967. if (numRandomSeeds <= 0)
  3968. {
  3969. randomSeeds = defaultSeeds;
  3970. numRandomSeeds = numElementsInArray (defaultSeeds);
  3971. Random r (0);
  3972. for (int j = 10; --j >= 0;)
  3973. {
  3974. r.setSeedRandomly();
  3975. for (int i = numRandomSeeds; --i >= 0;)
  3976. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3977. }
  3978. }
  3979. BitArray smallSieve;
  3980. const int smallSieveSize = 15000;
  3981. createSmallSieve (smallSieveSize, smallSieve);
  3982. BitArray p;
  3983. for (int i = numRandomSeeds; --i >= 0;)
  3984. {
  3985. BitArray p2;
  3986. Random r (randomSeeds[i]);
  3987. r.fillBitsRandomly (p2, 0, bitLength);
  3988. p.xorWith (p2);
  3989. }
  3990. p.setBit (bitLength - 1);
  3991. p.clearBit (0);
  3992. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3993. while (p.getHighestBit() < bitLength)
  3994. {
  3995. p.add (2 * searchLen);
  3996. BitArray sieve;
  3997. bigSieve (p, searchLen, sieve,
  3998. smallSieve, smallSieveSize);
  3999. BitArray candidate;
  4000. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  4001. return candidate;
  4002. }
  4003. jassertfalse
  4004. return BitArray();
  4005. }
  4006. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  4007. {
  4008. const BitArray one (1);
  4009. const BitArray two (2);
  4010. BitArray nMinusOne (n);
  4011. nMinusOne.subtract (one);
  4012. BitArray d (nMinusOne);
  4013. const int s = d.findNextSetBit (0);
  4014. d.shiftBits (-s);
  4015. BitArray smallPrimes;
  4016. int numBitsInSmallPrimes = 0;
  4017. for (;;)
  4018. {
  4019. numBitsInSmallPrimes += 256;
  4020. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  4021. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  4022. if (numPrimesFound > iterations + 1)
  4023. break;
  4024. }
  4025. int smallPrime = 2;
  4026. while (--iterations >= 0)
  4027. {
  4028. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  4029. BitArray r (smallPrime);
  4030. //r.createRandomNumber (nMinusOne);
  4031. r.exponentModulo (d, n);
  4032. if (! (r == one || r == nMinusOne))
  4033. {
  4034. for (int j = 0; j < s; ++j)
  4035. {
  4036. r.exponentModulo (two, n);
  4037. if (r == nMinusOne)
  4038. break;
  4039. }
  4040. if (r != nMinusOne)
  4041. return false;
  4042. }
  4043. }
  4044. return true;
  4045. }
  4046. bool Primes::isProbablyPrime (const BitArray& number,
  4047. const int certainty) throw()
  4048. {
  4049. if (! number[0])
  4050. return false;
  4051. if (number.getHighestBit() <= 10)
  4052. {
  4053. const int num = number.getBitRangeAsInt (0, 10);
  4054. for (int i = num / 2; --i > 1;)
  4055. if (num % i == 0)
  4056. return false;
  4057. return true;
  4058. }
  4059. else
  4060. {
  4061. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  4062. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  4063. return false;
  4064. return passesMillerRabin (number, certainty);
  4065. }
  4066. }
  4067. END_JUCE_NAMESPACE
  4068. /*** End of inlined file: juce_Primes.cpp ***/
  4069. /*** Start of inlined file: juce_RSAKey.cpp ***/
  4070. BEGIN_JUCE_NAMESPACE
  4071. RSAKey::RSAKey() throw()
  4072. {
  4073. }
  4074. RSAKey::RSAKey (const String& s) throw()
  4075. {
  4076. if (s.containsChar (T(',')))
  4077. {
  4078. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  4079. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  4080. }
  4081. else
  4082. {
  4083. // the string needs to be two hex numbers, comma-separated..
  4084. jassertfalse;
  4085. }
  4086. }
  4087. RSAKey::~RSAKey() throw()
  4088. {
  4089. }
  4090. const String RSAKey::toString() const throw()
  4091. {
  4092. return part1.toString (16) + T(",") + part2.toString (16);
  4093. }
  4094. bool RSAKey::applyToValue (BitArray& value) const throw()
  4095. {
  4096. if (part1.isEmpty() || part2.isEmpty()
  4097. || value.compare (0) <= 0)
  4098. {
  4099. jassertfalse // using an uninitialised key
  4100. value.clear();
  4101. return false;
  4102. }
  4103. BitArray result;
  4104. while (! value.isEmpty())
  4105. {
  4106. result.multiplyBy (part2);
  4107. BitArray remainder;
  4108. value.divideBy (part2, remainder);
  4109. remainder.exponentModulo (part1, part2);
  4110. result.add (remainder);
  4111. }
  4112. value = result;
  4113. return true;
  4114. }
  4115. static const BitArray findBestCommonDivisor (const BitArray& p,
  4116. const BitArray& q) throw()
  4117. {
  4118. const BitArray one (1);
  4119. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4120. // are fast to divide + multiply
  4121. for (int i = 2; i <= 65536; i *= 2)
  4122. {
  4123. const BitArray e (1 + i);
  4124. if (e.findGreatestCommonDivisor (p) == one
  4125. && e.findGreatestCommonDivisor (q) == one)
  4126. {
  4127. return e;
  4128. }
  4129. }
  4130. BitArray e (4);
  4131. while (! (e.findGreatestCommonDivisor (p) == one
  4132. && e.findGreatestCommonDivisor (q) == one))
  4133. {
  4134. e.add (one);
  4135. }
  4136. return e;
  4137. }
  4138. void RSAKey::createKeyPair (RSAKey& publicKey,
  4139. RSAKey& privateKey,
  4140. const int numBits,
  4141. const int* randomSeeds,
  4142. const int numRandomSeeds) throw()
  4143. {
  4144. jassert (numBits > 16); // not much point using less than this..
  4145. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4146. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4147. BitArray n (p);
  4148. n.multiplyBy (q); // n = pq
  4149. const BitArray one (1);
  4150. p.subtract (one);
  4151. q.subtract (one);
  4152. BitArray m (p);
  4153. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4154. const BitArray e (findBestCommonDivisor (p, q));
  4155. BitArray d (e);
  4156. d.inverseModulo (m);
  4157. publicKey.part1 = e;
  4158. publicKey.part2 = n;
  4159. privateKey.part1 = d;
  4160. privateKey.part2 = n;
  4161. }
  4162. END_JUCE_NAMESPACE
  4163. /*** End of inlined file: juce_RSAKey.cpp ***/
  4164. /*** Start of inlined file: juce_InputStream.cpp ***/
  4165. BEGIN_JUCE_NAMESPACE
  4166. char InputStream::readByte()
  4167. {
  4168. char temp = 0;
  4169. read (&temp, 1);
  4170. return temp;
  4171. }
  4172. bool InputStream::readBool()
  4173. {
  4174. return readByte() != 0;
  4175. }
  4176. short InputStream::readShort()
  4177. {
  4178. char temp [2];
  4179. if (read (temp, 2) == 2)
  4180. return (short) ByteOrder::littleEndianShort (temp);
  4181. else
  4182. return 0;
  4183. }
  4184. short InputStream::readShortBigEndian()
  4185. {
  4186. char temp [2];
  4187. if (read (temp, 2) == 2)
  4188. return (short) ByteOrder::bigEndianShort (temp);
  4189. else
  4190. return 0;
  4191. }
  4192. int InputStream::readInt()
  4193. {
  4194. char temp [4];
  4195. if (read (temp, 4) == 4)
  4196. return (int) ByteOrder::littleEndianInt (temp);
  4197. else
  4198. return 0;
  4199. }
  4200. int InputStream::readIntBigEndian()
  4201. {
  4202. char temp [4];
  4203. if (read (temp, 4) == 4)
  4204. return (int) ByteOrder::bigEndianInt (temp);
  4205. else
  4206. return 0;
  4207. }
  4208. int InputStream::readCompressedInt()
  4209. {
  4210. const unsigned char sizeByte = readByte();
  4211. if (sizeByte == 0)
  4212. return 0;
  4213. const int numBytes = (sizeByte & 0x7f);
  4214. if (numBytes > 4)
  4215. {
  4216. jassertfalse // trying to read corrupt data - this method must only be used
  4217. // to read data that was written by OutputStream::writeCompressedInt()
  4218. return 0;
  4219. }
  4220. char bytes[4] = { 0, 0, 0, 0 };
  4221. if (read (bytes, numBytes) != numBytes)
  4222. return 0;
  4223. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4224. return (sizeByte >> 7) ? -num : num;
  4225. }
  4226. int64 InputStream::readInt64()
  4227. {
  4228. char temp [8];
  4229. if (read (temp, 8) == 8)
  4230. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4231. else
  4232. return 0;
  4233. }
  4234. int64 InputStream::readInt64BigEndian()
  4235. {
  4236. char temp [8];
  4237. if (read (temp, 8) == 8)
  4238. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4239. else
  4240. return 0;
  4241. }
  4242. float InputStream::readFloat()
  4243. {
  4244. union { int asInt; float asFloat; } n;
  4245. n.asInt = readInt();
  4246. return n.asFloat;
  4247. }
  4248. float InputStream::readFloatBigEndian()
  4249. {
  4250. union { int asInt; float asFloat; } n;
  4251. n.asInt = readIntBigEndian();
  4252. return n.asFloat;
  4253. }
  4254. double InputStream::readDouble()
  4255. {
  4256. union { int64 asInt; double asDouble; } n;
  4257. n.asInt = readInt64();
  4258. return n.asDouble;
  4259. }
  4260. double InputStream::readDoubleBigEndian()
  4261. {
  4262. union { int64 asInt; double asDouble; } n;
  4263. n.asInt = readInt64BigEndian();
  4264. return n.asDouble;
  4265. }
  4266. const String InputStream::readString()
  4267. {
  4268. MemoryBlock buffer (256);
  4269. uint8* data = (uint8*) buffer.getData();
  4270. size_t i = 0;
  4271. while ((data[i] = readByte()) != 0)
  4272. {
  4273. if (++i >= buffer.getSize())
  4274. {
  4275. buffer.setSize (buffer.getSize() + 512);
  4276. data = (uint8*) buffer.getData();
  4277. }
  4278. }
  4279. return String::fromUTF8 (data, (int) i);
  4280. }
  4281. const String InputStream::readNextLine()
  4282. {
  4283. MemoryBlock buffer (256);
  4284. uint8* data = (uint8*) buffer.getData();
  4285. size_t i = 0;
  4286. while ((data[i] = readByte()) != 0)
  4287. {
  4288. if (data[i] == '\n')
  4289. break;
  4290. if (data[i] == '\r')
  4291. {
  4292. const int64 lastPos = getPosition();
  4293. if (readByte() != '\n')
  4294. setPosition (lastPos);
  4295. break;
  4296. }
  4297. if (++i >= buffer.getSize())
  4298. {
  4299. buffer.setSize (buffer.getSize() + 512);
  4300. data = (uint8*) buffer.getData();
  4301. }
  4302. }
  4303. return String::fromUTF8 (data, (int) i);
  4304. }
  4305. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4306. int numBytes)
  4307. {
  4308. const int64 totalLength = getTotalLength();
  4309. if (totalLength >= 0)
  4310. {
  4311. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4312. totalLength - getPosition());
  4313. if (numBytes < 0)
  4314. numBytes = totalBytesRemaining;
  4315. else if (numBytes > 0)
  4316. numBytes = jmin (numBytes, totalBytesRemaining);
  4317. else
  4318. return 0;
  4319. }
  4320. const size_t originalBlockSize = block.getSize();
  4321. int totalBytesRead = 0;
  4322. if (numBytes > 0)
  4323. {
  4324. // know how many bytes we want, so we can resize the block first..
  4325. block.setSize (originalBlockSize + numBytes, false);
  4326. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4327. }
  4328. else
  4329. {
  4330. // read until end of stram..
  4331. const int chunkSize = 32768;
  4332. for (;;)
  4333. {
  4334. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4335. const int bytesJustIn = read (((char*) block.getData())
  4336. + originalBlockSize
  4337. + totalBytesRead,
  4338. chunkSize);
  4339. if (bytesJustIn == 0)
  4340. break;
  4341. totalBytesRead += bytesJustIn;
  4342. }
  4343. }
  4344. // trim off any excess left at the end
  4345. block.setSize (originalBlockSize + totalBytesRead, false);
  4346. return totalBytesRead;
  4347. }
  4348. const String InputStream::readEntireStreamAsString()
  4349. {
  4350. MemoryBlock mb;
  4351. const int size = readIntoMemoryBlock (mb);
  4352. return String::createStringFromData ((const char*) mb.getData(), size);
  4353. }
  4354. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4355. {
  4356. if (numBytesToSkip > 0)
  4357. {
  4358. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4359. HeapBlock <char> temp (skipBufferSize);
  4360. while (numBytesToSkip > 0 && ! isExhausted())
  4361. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4362. }
  4363. }
  4364. END_JUCE_NAMESPACE
  4365. /*** End of inlined file: juce_InputStream.cpp ***/
  4366. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4367. BEGIN_JUCE_NAMESPACE
  4368. #if JUCE_DEBUG
  4369. static CriticalSection activeStreamLock;
  4370. static VoidArray activeStreams;
  4371. void juce_CheckForDanglingStreams()
  4372. {
  4373. /*
  4374. It's always a bad idea to leak any object, but if you're leaking output
  4375. streams, then there's a good chance that you're failing to flush a file
  4376. to disk properly, which could result in corrupted data and other similar
  4377. nastiness..
  4378. */
  4379. jassert (activeStreams.size() == 0);
  4380. };
  4381. #endif
  4382. OutputStream::OutputStream() throw()
  4383. {
  4384. #if JUCE_DEBUG
  4385. activeStreamLock.enter();
  4386. activeStreams.add (this);
  4387. activeStreamLock.exit();
  4388. #endif
  4389. }
  4390. OutputStream::~OutputStream()
  4391. {
  4392. #if JUCE_DEBUG
  4393. activeStreamLock.enter();
  4394. activeStreams.removeValue (this);
  4395. activeStreamLock.exit();
  4396. #endif
  4397. }
  4398. void OutputStream::writeBool (bool b)
  4399. {
  4400. writeByte ((b) ? (char) 1
  4401. : (char) 0);
  4402. }
  4403. void OutputStream::writeByte (char byte)
  4404. {
  4405. write (&byte, 1);
  4406. }
  4407. void OutputStream::writeShort (short value)
  4408. {
  4409. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4410. write (&v, 2);
  4411. }
  4412. void OutputStream::writeShortBigEndian (short value)
  4413. {
  4414. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4415. write (&v, 2);
  4416. }
  4417. void OutputStream::writeInt (int value)
  4418. {
  4419. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4420. write (&v, 4);
  4421. }
  4422. void OutputStream::writeIntBigEndian (int value)
  4423. {
  4424. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4425. write (&v, 4);
  4426. }
  4427. void OutputStream::writeCompressedInt (int value)
  4428. {
  4429. unsigned int un = (value < 0) ? (unsigned int) -value
  4430. : (unsigned int) value;
  4431. uint8 data[5];
  4432. int num = 0;
  4433. while (un > 0)
  4434. {
  4435. data[++num] = (uint8) un;
  4436. un >>= 8;
  4437. }
  4438. data[0] = (uint8) num;
  4439. if (value < 0)
  4440. data[0] |= 0x80;
  4441. write (data, num + 1);
  4442. }
  4443. void OutputStream::writeInt64 (int64 value)
  4444. {
  4445. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4446. write (&v, 8);
  4447. }
  4448. void OutputStream::writeInt64BigEndian (int64 value)
  4449. {
  4450. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4451. write (&v, 8);
  4452. }
  4453. void OutputStream::writeFloat (float value)
  4454. {
  4455. union { int asInt; float asFloat; } n;
  4456. n.asFloat = value;
  4457. writeInt (n.asInt);
  4458. }
  4459. void OutputStream::writeFloatBigEndian (float value)
  4460. {
  4461. union { int asInt; float asFloat; } n;
  4462. n.asFloat = value;
  4463. writeIntBigEndian (n.asInt);
  4464. }
  4465. void OutputStream::writeDouble (double value)
  4466. {
  4467. union { int64 asInt; double asDouble; } n;
  4468. n.asDouble = value;
  4469. writeInt64 (n.asInt);
  4470. }
  4471. void OutputStream::writeDoubleBigEndian (double value)
  4472. {
  4473. union { int64 asInt; double asDouble; } n;
  4474. n.asDouble = value;
  4475. writeInt64BigEndian (n.asInt);
  4476. }
  4477. void OutputStream::writeString (const String& text)
  4478. {
  4479. const int numBytes = text.copyToUTF8 (0);
  4480. HeapBlock <uint8> temp (numBytes);
  4481. text.copyToUTF8 (temp);
  4482. write (temp, numBytes); // (numBytes includes the terminating null).
  4483. }
  4484. void OutputStream::printf (const char* pf, ...)
  4485. {
  4486. unsigned int bufSize = 256;
  4487. HeapBlock <char> buf (bufSize);
  4488. for (;;)
  4489. {
  4490. va_list list;
  4491. va_start (list, pf);
  4492. const int num = CharacterFunctions::vprintf (buf, bufSize, pf, list);
  4493. va_end (list);
  4494. if (num > 0)
  4495. {
  4496. write (buf, num);
  4497. break;
  4498. }
  4499. else if (num == 0)
  4500. {
  4501. break;
  4502. }
  4503. bufSize += 256;
  4504. buf.malloc (bufSize);
  4505. }
  4506. }
  4507. OutputStream& OutputStream::operator<< (const int number)
  4508. {
  4509. const String s (number);
  4510. write ((const char*) s, s.length());
  4511. return *this;
  4512. }
  4513. OutputStream& OutputStream::operator<< (const double number)
  4514. {
  4515. const String s (number);
  4516. write ((const char*) s, s.length());
  4517. return *this;
  4518. }
  4519. OutputStream& OutputStream::operator<< (const char character)
  4520. {
  4521. writeByte (character);
  4522. return *this;
  4523. }
  4524. OutputStream& OutputStream::operator<< (const char* const text)
  4525. {
  4526. write (text, (int) strlen (text));
  4527. return *this;
  4528. }
  4529. OutputStream& OutputStream::operator<< (const juce_wchar* const text)
  4530. {
  4531. const String s (text);
  4532. write ((const char*) s, s.length());
  4533. return *this;
  4534. }
  4535. OutputStream& OutputStream::operator<< (const String& text)
  4536. {
  4537. write ((const char*) text,
  4538. text.length());
  4539. return *this;
  4540. }
  4541. void OutputStream::writeText (const String& text,
  4542. const bool asUnicode,
  4543. const bool writeUnicodeHeaderBytes)
  4544. {
  4545. if (asUnicode)
  4546. {
  4547. if (writeUnicodeHeaderBytes)
  4548. write ("\x0ff\x0fe", 2);
  4549. const juce_wchar* src = (const juce_wchar*) text;
  4550. bool lastCharWasReturn = false;
  4551. while (*src != 0)
  4552. {
  4553. if (*src == L'\n' && ! lastCharWasReturn)
  4554. writeShort ((short) L'\r');
  4555. lastCharWasReturn = (*src == L'\r');
  4556. writeShort ((short) *src++);
  4557. }
  4558. }
  4559. else
  4560. {
  4561. const char* src = (const char*) text;
  4562. const char* t = src;
  4563. for (;;)
  4564. {
  4565. if (*t == '\n')
  4566. {
  4567. if (t > src)
  4568. write (src, (int) (t - src));
  4569. write ("\r\n", 2);
  4570. src = t + 1;
  4571. }
  4572. else if (*t == '\r')
  4573. {
  4574. if (t[1] == '\n')
  4575. ++t;
  4576. }
  4577. else if (*t == 0)
  4578. {
  4579. if (t > src)
  4580. write (src, (int) (t - src));
  4581. break;
  4582. }
  4583. ++t;
  4584. }
  4585. }
  4586. }
  4587. int OutputStream::writeFromInputStream (InputStream& source,
  4588. int numBytesToWrite)
  4589. {
  4590. if (numBytesToWrite < 0)
  4591. numBytesToWrite = 0x7fffffff;
  4592. int numWritten = 0;
  4593. while (numBytesToWrite > 0 && ! source.isExhausted())
  4594. {
  4595. char buffer [8192];
  4596. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4597. if (num == 0)
  4598. break;
  4599. write (buffer, num);
  4600. numBytesToWrite -= num;
  4601. numWritten += num;
  4602. }
  4603. return numWritten;
  4604. }
  4605. END_JUCE_NAMESPACE
  4606. /*** End of inlined file: juce_OutputStream.cpp ***/
  4607. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4608. BEGIN_JUCE_NAMESPACE
  4609. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4610. bool* isDirectory, bool* isHidden, int64* fileSize,
  4611. Time* modTime, Time* creationTime, bool* isReadOnly);
  4612. bool juce_findFileNext (void* handle, String& resultFile,
  4613. bool* isDirectory, bool* isHidden, int64* fileSize,
  4614. Time* modTime, Time* creationTime, bool* isReadOnly);
  4615. void juce_findFileClose (void* handle);
  4616. DirectoryIterator::DirectoryIterator (const File& directory,
  4617. bool isRecursive,
  4618. const String& wc,
  4619. const int whatToLookFor_)
  4620. : wildCard (wc),
  4621. index (-1),
  4622. whatToLookFor (whatToLookFor_)
  4623. {
  4624. // you have to specify the type of files you're looking for!
  4625. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4626. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4627. String path (directory.getFullPathName());
  4628. if (! path.endsWithChar (File::separator))
  4629. path += File::separator;
  4630. String filename;
  4631. bool isDirectory, isHidden;
  4632. void* const handle = juce_findFileStart (path,
  4633. isRecursive ? T("*") : wc,
  4634. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4635. if (handle != 0)
  4636. {
  4637. do
  4638. {
  4639. if (! filename.containsOnly (T(".")))
  4640. {
  4641. bool addToList = false;
  4642. if (isDirectory)
  4643. {
  4644. if (isRecursive
  4645. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4646. || ! isHidden))
  4647. {
  4648. dirsFound.add (File (path + filename, 0));
  4649. }
  4650. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4651. }
  4652. else
  4653. {
  4654. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4655. }
  4656. // if it's recursive, we're not relying on the OS iterator
  4657. // to do the wildcard match, so do it now..
  4658. if (isRecursive && addToList)
  4659. addToList = filename.matchesWildcard (wc, true);
  4660. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4661. addToList = ! isHidden;
  4662. if (addToList)
  4663. filesFound.add (File (path + filename, 0));
  4664. }
  4665. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4666. juce_findFileClose (handle);
  4667. }
  4668. }
  4669. DirectoryIterator::~DirectoryIterator()
  4670. {
  4671. }
  4672. bool DirectoryIterator::next()
  4673. {
  4674. if (subIterator != 0)
  4675. {
  4676. if (subIterator->next())
  4677. return true;
  4678. subIterator = 0;
  4679. }
  4680. if (index >= filesFound.size() + dirsFound.size() - 1)
  4681. return false;
  4682. ++index;
  4683. if (index >= filesFound.size())
  4684. {
  4685. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4686. true, wildCard, whatToLookFor);
  4687. return next();
  4688. }
  4689. return true;
  4690. }
  4691. const File DirectoryIterator::getFile() const
  4692. {
  4693. if (subIterator != 0)
  4694. return subIterator->getFile();
  4695. return filesFound [index];
  4696. }
  4697. float DirectoryIterator::getEstimatedProgress() const
  4698. {
  4699. if (filesFound.size() + dirsFound.size() == 0)
  4700. {
  4701. return 0.0f;
  4702. }
  4703. else
  4704. {
  4705. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4706. : (float) index;
  4707. return detailedIndex / (filesFound.size() + dirsFound.size());
  4708. }
  4709. }
  4710. END_JUCE_NAMESPACE
  4711. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4712. /*** Start of inlined file: juce_File.cpp ***/
  4713. #ifdef _MSC_VER
  4714. #pragma warning (disable: 4514)
  4715. #pragma warning (push)
  4716. #endif
  4717. #if ! JUCE_WINDOWS
  4718. #include <pwd.h>
  4719. #endif
  4720. BEGIN_JUCE_NAMESPACE
  4721. #ifdef _MSC_VER
  4722. #pragma warning (pop)
  4723. #endif
  4724. void* juce_fileOpen (const String& path, bool forWriting);
  4725. void juce_fileClose (void* handle);
  4726. int juce_fileWrite (void* handle, const void* buffer, int size);
  4727. int64 juce_fileGetPosition (void* handle);
  4728. int64 juce_fileSetPosition (void* handle, int64 pos);
  4729. void juce_fileFlush (void* handle);
  4730. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4731. bool juce_isDirectory (const String& fileName);
  4732. int64 juce_getFileSize (const String& fileName);
  4733. bool juce_canWriteToFile (const String& fileName);
  4734. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4735. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4736. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4737. bool juce_deleteFile (const String& fileName);
  4738. bool juce_copyFile (const String& source, const String& dest);
  4739. bool juce_moveFile (const String& source, const String& dest);
  4740. // this must also create all paths involved in the directory.
  4741. void juce_createDirectory (const String& fileName);
  4742. bool juce_launchFile (const String& fileName, const String& parameters);
  4743. const StringArray juce_getFileSystemRoots();
  4744. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4745. // starts a directory search operation with a wildcard, returning a handle for
  4746. // use in calls to juce_findFileNext.
  4747. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4748. // the other pointers, if non-null, are set based on the properties of the file.
  4749. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4750. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4751. Time* creationTime, bool* isReadOnly);
  4752. // returns false when no more files are found
  4753. bool juce_findFileNext (void* handle, String& resultFile,
  4754. bool* isDirectory, bool* isHidden, int64* fileSize,
  4755. Time* modTime, Time* creationTime, bool* isReadOnly);
  4756. void juce_findFileClose (void* handle);
  4757. static const String juce_addTrailingSeparator (const String& path)
  4758. {
  4759. return path.endsWithChar (File::separator) ? path
  4760. : path + File::separator;
  4761. }
  4762. static const String parseAbsolutePath (String path)
  4763. {
  4764. if (path.isEmpty())
  4765. return String::empty;
  4766. #if JUCE_WINDOWS
  4767. // Windows..
  4768. path = path.replaceCharacter (T('/'), T('\\'));
  4769. if (path.startsWithChar (File::separator))
  4770. {
  4771. if (path[1] != File::separator)
  4772. {
  4773. jassertfalse // using a filename that starts with a slash is a bit dodgy on
  4774. // Windows, because it needs a drive letter, which in this case
  4775. // we'll take from the CWD.. but this is a bit of an assumption that
  4776. // could be wrong..
  4777. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4778. }
  4779. }
  4780. else if (path.indexOfChar (T(':')) < 0)
  4781. {
  4782. if (path.isEmpty())
  4783. return String::empty;
  4784. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4785. // we don't know what directory to put it in.
  4786. // Here we'll assume it's in the CWD, but this might not be what was
  4787. // intended..
  4788. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4789. }
  4790. #else
  4791. // Mac or Linux..
  4792. path = path.replaceCharacter (T('\\'), T('/'));
  4793. if (path.startsWithChar (T('~')))
  4794. {
  4795. const char* homeDir = 0;
  4796. if (path[1] == File::separator || path[1] == 0)
  4797. {
  4798. // expand a name of the form "~/abc"
  4799. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4800. + path.substring (1);
  4801. }
  4802. else
  4803. {
  4804. // expand a name of type "~dave/abc"
  4805. const String userName (path.substring (1)
  4806. .upToFirstOccurrenceOf (T("/"), false, false));
  4807. struct passwd* const pw = getpwnam (userName);
  4808. if (pw != 0)
  4809. {
  4810. String home (homeDir);
  4811. if (home.endsWithChar (File::separator))
  4812. home [home.length() - 1] = 0;
  4813. path = String (pw->pw_dir)
  4814. + path.substring (userName.length());
  4815. }
  4816. }
  4817. }
  4818. else if (! path.startsWithChar (File::separator))
  4819. {
  4820. while (path.startsWith (T("./")))
  4821. path = path.substring (2);
  4822. if (path.isEmpty())
  4823. return String::empty;
  4824. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4825. // we don't know what directory to put it in.
  4826. // Here we'll assume it's in the CWD, but this might not be what was
  4827. // intended..
  4828. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4829. }
  4830. #endif
  4831. int len = path.length();
  4832. while (--len > 0 && path [len] == File::separator)
  4833. path [len] = 0;
  4834. return path;
  4835. }
  4836. const File File::nonexistent;
  4837. File::File (const String& fullPathName)
  4838. : fullPath (parseAbsolutePath (fullPathName))
  4839. {
  4840. }
  4841. File::File (const String& path, int)
  4842. : fullPath (path)
  4843. {
  4844. }
  4845. const File File::createFileWithoutCheckingPath (const String& path)
  4846. {
  4847. return File (path, 0);
  4848. }
  4849. File::File (const File& other)
  4850. : fullPath (other.fullPath)
  4851. {
  4852. }
  4853. const File& File::operator= (const String& newPath)
  4854. {
  4855. fullPath = parseAbsolutePath (newPath);
  4856. return *this;
  4857. }
  4858. const File& File::operator= (const File& other)
  4859. {
  4860. fullPath = other.fullPath;
  4861. return *this;
  4862. }
  4863. #if JUCE_LINUX
  4864. #define NAMES_ARE_CASE_SENSITIVE 1
  4865. #endif
  4866. bool File::areFileNamesCaseSensitive()
  4867. {
  4868. #if NAMES_ARE_CASE_SENSITIVE
  4869. return true;
  4870. #else
  4871. return false;
  4872. #endif
  4873. }
  4874. bool File::operator== (const File& other) const
  4875. {
  4876. // case-insensitive on Windows, but not on linux.
  4877. #if NAMES_ARE_CASE_SENSITIVE
  4878. return fullPath == other.fullPath;
  4879. #else
  4880. return fullPath.equalsIgnoreCase (other.fullPath);
  4881. #endif
  4882. }
  4883. bool File::operator!= (const File& other) const
  4884. {
  4885. return ! operator== (other);
  4886. }
  4887. bool File::exists() const
  4888. {
  4889. return juce_fileExists (fullPath, false);
  4890. }
  4891. bool File::existsAsFile() const
  4892. {
  4893. return juce_fileExists (fullPath, true);
  4894. }
  4895. bool File::isDirectory() const
  4896. {
  4897. return juce_isDirectory (fullPath);
  4898. }
  4899. bool File::hasWriteAccess() const
  4900. {
  4901. if (exists())
  4902. return juce_canWriteToFile (fullPath);
  4903. #if ! JUCE_WINDOWS
  4904. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4905. return getParentDirectory().hasWriteAccess();
  4906. else
  4907. return false;
  4908. #else
  4909. // on windows, it seems that even read-only directories can still be written into,
  4910. // so checking the parent directory's permissions would return the wrong result..
  4911. else
  4912. return true;
  4913. #endif
  4914. }
  4915. bool File::setReadOnly (const bool shouldBeReadOnly,
  4916. const bool applyRecursively) const
  4917. {
  4918. bool worked = true;
  4919. if (applyRecursively && 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).setReadOnly (shouldBeReadOnly, true) && worked;
  4925. }
  4926. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4927. }
  4928. bool File::deleteFile() const
  4929. {
  4930. return (! exists())
  4931. || juce_deleteFile (fullPath);
  4932. }
  4933. bool File::deleteRecursively() const
  4934. {
  4935. bool worked = true;
  4936. if (isDirectory())
  4937. {
  4938. Array<File> subFiles;
  4939. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4940. for (int i = subFiles.size(); --i >= 0;)
  4941. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4942. }
  4943. return deleteFile() && worked;
  4944. }
  4945. bool File::moveFileTo (const File& newFile) const
  4946. {
  4947. if (newFile.fullPath == fullPath)
  4948. return true;
  4949. #if ! NAMES_ARE_CASE_SENSITIVE
  4950. if (*this != newFile)
  4951. #endif
  4952. if (! newFile.deleteFile())
  4953. return false;
  4954. return juce_moveFile (fullPath, newFile.fullPath);
  4955. }
  4956. bool File::copyFileTo (const File& newFile) const
  4957. {
  4958. if (*this == newFile)
  4959. return true;
  4960. if (! newFile.deleteFile())
  4961. return false;
  4962. return juce_copyFile (fullPath, newFile.fullPath);
  4963. }
  4964. bool File::copyDirectoryTo (const File& newDirectory) const
  4965. {
  4966. if (isDirectory() && newDirectory.createDirectory())
  4967. {
  4968. Array<File> subFiles;
  4969. findChildFiles (subFiles, File::findFiles, false);
  4970. int i;
  4971. for (i = 0; i < subFiles.size(); ++i)
  4972. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4973. return false;
  4974. subFiles.clear();
  4975. findChildFiles (subFiles, File::findDirectories, false);
  4976. for (i = 0; i < subFiles.size(); ++i)
  4977. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4978. return false;
  4979. return true;
  4980. }
  4981. return false;
  4982. }
  4983. const String File::getPathUpToLastSlash() const
  4984. {
  4985. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4986. if (lastSlash > 0)
  4987. return fullPath.substring (0, lastSlash);
  4988. else if (lastSlash == 0)
  4989. return separatorString;
  4990. else
  4991. return fullPath;
  4992. }
  4993. const File File::getParentDirectory() const
  4994. {
  4995. return File (getPathUpToLastSlash());
  4996. }
  4997. const String File::getFileName() const
  4998. {
  4999. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  5000. }
  5001. int File::hashCode() const
  5002. {
  5003. return fullPath.hashCode();
  5004. }
  5005. int64 File::hashCode64() const
  5006. {
  5007. return fullPath.hashCode64();
  5008. }
  5009. const String File::getFileNameWithoutExtension() const
  5010. {
  5011. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  5012. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  5013. if (lastDot > lastSlash)
  5014. return fullPath.substring (lastSlash, lastDot);
  5015. else
  5016. return fullPath.substring (lastSlash);
  5017. }
  5018. bool File::isAChildOf (const File& potentialParent) const
  5019. {
  5020. const String ourPath (getPathUpToLastSlash());
  5021. #if NAMES_ARE_CASE_SENSITIVE
  5022. if (potentialParent.fullPath == ourPath)
  5023. #else
  5024. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  5025. #endif
  5026. {
  5027. return true;
  5028. }
  5029. else if (potentialParent.fullPath.length() >= ourPath.length())
  5030. {
  5031. return false;
  5032. }
  5033. else
  5034. {
  5035. return getParentDirectory().isAChildOf (potentialParent);
  5036. }
  5037. }
  5038. bool File::isAbsolutePath (const String& path)
  5039. {
  5040. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  5041. #if JUCE_WINDOWS
  5042. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  5043. #else
  5044. || path.startsWithChar (T('~'));
  5045. #endif
  5046. }
  5047. const File File::getChildFile (String relativePath) const
  5048. {
  5049. if (isAbsolutePath (relativePath))
  5050. {
  5051. // the path is really absolute..
  5052. return File (relativePath);
  5053. }
  5054. else
  5055. {
  5056. // it's relative, so remove any ../ or ./ bits at the start.
  5057. String path (fullPath);
  5058. if (relativePath[0] == T('.'))
  5059. {
  5060. #if JUCE_WINDOWS
  5061. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  5062. #else
  5063. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  5064. #endif
  5065. while (relativePath[0] == T('.'))
  5066. {
  5067. if (relativePath[1] == T('.'))
  5068. {
  5069. if (relativePath [2] == 0 || relativePath[2] == separator)
  5070. {
  5071. const int lastSlash = path.lastIndexOfChar (separator);
  5072. if (lastSlash >= 0)
  5073. path = path.substring (0, lastSlash);
  5074. relativePath = relativePath.substring (3);
  5075. }
  5076. else
  5077. {
  5078. break;
  5079. }
  5080. }
  5081. else if (relativePath[1] == separator)
  5082. {
  5083. relativePath = relativePath.substring (2);
  5084. }
  5085. else
  5086. {
  5087. break;
  5088. }
  5089. }
  5090. }
  5091. return File (juce_addTrailingSeparator (path) + relativePath);
  5092. }
  5093. }
  5094. const File File::getSiblingFile (const String& fileName) const
  5095. {
  5096. return getParentDirectory().getChildFile (fileName);
  5097. }
  5098. int64 File::getSize() const
  5099. {
  5100. return juce_getFileSize (fullPath);
  5101. }
  5102. const String File::descriptionOfSizeInBytes (const int64 bytes)
  5103. {
  5104. if (bytes == 1)
  5105. {
  5106. return "1 byte";
  5107. }
  5108. else if (bytes < 1024)
  5109. {
  5110. return String ((int) bytes) + " bytes";
  5111. }
  5112. else if (bytes < 1024 * 1024)
  5113. {
  5114. return String (bytes / 1024.0, 1) + " KB";
  5115. }
  5116. else if (bytes < 1024 * 1024 * 1024)
  5117. {
  5118. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  5119. }
  5120. else
  5121. {
  5122. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  5123. }
  5124. }
  5125. bool File::create() const
  5126. {
  5127. if (! exists())
  5128. {
  5129. const File parentDir (getParentDirectory());
  5130. if (parentDir == *this || ! parentDir.createDirectory())
  5131. return false;
  5132. void* const fh = juce_fileOpen (fullPath, true);
  5133. if (fh == 0)
  5134. return false;
  5135. juce_fileClose (fh);
  5136. }
  5137. return true;
  5138. }
  5139. bool File::createDirectory() const
  5140. {
  5141. if (! isDirectory())
  5142. {
  5143. const File parentDir (getParentDirectory());
  5144. if (parentDir == *this || ! parentDir.createDirectory())
  5145. return false;
  5146. String dir (fullPath);
  5147. while (dir.endsWithChar (separator))
  5148. dir [dir.length() - 1] = 0;
  5149. juce_createDirectory (dir);
  5150. return isDirectory();
  5151. }
  5152. return true;
  5153. }
  5154. const Time File::getCreationTime() const
  5155. {
  5156. int64 m, a, c;
  5157. juce_getFileTimes (fullPath, m, a, c);
  5158. return Time (c);
  5159. }
  5160. bool File::setCreationTime (const Time& t) const
  5161. {
  5162. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5163. }
  5164. const Time File::getLastModificationTime() const
  5165. {
  5166. int64 m, a, c;
  5167. juce_getFileTimes (fullPath, m, a, c);
  5168. return Time (m);
  5169. }
  5170. bool File::setLastModificationTime (const Time& t) const
  5171. {
  5172. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5173. }
  5174. const Time File::getLastAccessTime() const
  5175. {
  5176. int64 m, a, c;
  5177. juce_getFileTimes (fullPath, m, a, c);
  5178. return Time (a);
  5179. }
  5180. bool File::setLastAccessTime (const Time& t) const
  5181. {
  5182. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5183. }
  5184. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5185. {
  5186. if (! existsAsFile())
  5187. return false;
  5188. FileInputStream in (*this);
  5189. return getSize() == in.readIntoMemoryBlock (destBlock);
  5190. }
  5191. const String File::loadFileAsString() const
  5192. {
  5193. if (! existsAsFile())
  5194. return String::empty;
  5195. FileInputStream in (*this);
  5196. return in.readEntireStreamAsString();
  5197. }
  5198. static inline bool fileTypeMatches (const int whatToLookFor,
  5199. const bool isDir,
  5200. const bool isHidden)
  5201. {
  5202. return (whatToLookFor & (isDir ? File::findDirectories
  5203. : File::findFiles)) != 0
  5204. && ((! isHidden)
  5205. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5206. }
  5207. int File::findChildFiles (Array<File>& results,
  5208. const int whatToLookFor,
  5209. const bool searchRecursively,
  5210. const String& wildCardPattern) const
  5211. {
  5212. // you have to specify the type of files you're looking for!
  5213. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5214. int total = 0;
  5215. // find child files or directories in this directory first..
  5216. if (isDirectory())
  5217. {
  5218. const String path (juce_addTrailingSeparator (fullPath));
  5219. String filename;
  5220. bool itemIsDirectory, itemIsHidden;
  5221. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5222. &itemIsDirectory, &itemIsHidden,
  5223. 0, 0, 0, 0);
  5224. if (handle != 0)
  5225. {
  5226. do
  5227. {
  5228. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5229. && ! filename.containsOnly (T(".")))
  5230. {
  5231. results.add (File (path + filename, 0));
  5232. ++total;
  5233. }
  5234. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5235. juce_findFileClose (handle);
  5236. }
  5237. }
  5238. else
  5239. {
  5240. // trying to search for files inside a non-directory?
  5241. //jassertfalse
  5242. }
  5243. // and recurse down if required.
  5244. if (searchRecursively)
  5245. {
  5246. Array<File> subDirectories;
  5247. findChildFiles (subDirectories, File::findDirectories, false);
  5248. for (int i = 0; i < subDirectories.size(); ++i)
  5249. {
  5250. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5251. true, wildCardPattern);
  5252. }
  5253. }
  5254. return total;
  5255. }
  5256. int File::getNumberOfChildFiles (const int whatToLookFor,
  5257. const String& wildCardPattern) const
  5258. {
  5259. // you have to specify the type of files you're looking for!
  5260. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5261. int count = 0;
  5262. if (isDirectory())
  5263. {
  5264. String filename;
  5265. bool itemIsDirectory, itemIsHidden;
  5266. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5267. &itemIsDirectory, &itemIsHidden,
  5268. 0, 0, 0, 0);
  5269. if (handle != 0)
  5270. {
  5271. do
  5272. {
  5273. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5274. && ! filename.containsOnly (T(".")))
  5275. {
  5276. ++count;
  5277. }
  5278. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5279. juce_findFileClose (handle);
  5280. }
  5281. }
  5282. else
  5283. {
  5284. // trying to search for files inside a non-directory?
  5285. jassertfalse
  5286. }
  5287. return count;
  5288. }
  5289. bool File::containsSubDirectories() const
  5290. {
  5291. bool result = false;
  5292. if (isDirectory())
  5293. {
  5294. String filename;
  5295. bool itemIsDirectory, itemIsHidden;
  5296. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5297. T("*"), filename,
  5298. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5299. if (handle != 0)
  5300. {
  5301. do
  5302. {
  5303. if (itemIsDirectory)
  5304. {
  5305. result = true;
  5306. break;
  5307. }
  5308. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5309. juce_findFileClose (handle);
  5310. }
  5311. }
  5312. return result;
  5313. }
  5314. const File File::getNonexistentChildFile (const String& prefix_,
  5315. const String& suffix,
  5316. bool putNumbersInBrackets) const
  5317. {
  5318. File f (getChildFile (prefix_ + suffix));
  5319. if (f.exists())
  5320. {
  5321. int num = 2;
  5322. String prefix (prefix_);
  5323. // remove any bracketed numbers that may already be on the end..
  5324. if (prefix.trim().endsWithChar (T(')')))
  5325. {
  5326. putNumbersInBrackets = true;
  5327. const int openBracks = prefix.lastIndexOfChar (T('('));
  5328. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5329. if (openBracks > 0
  5330. && closeBracks > openBracks
  5331. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5332. {
  5333. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5334. prefix = prefix.substring (0, openBracks);
  5335. }
  5336. }
  5337. // also use brackets if it ends in a digit.
  5338. putNumbersInBrackets = putNumbersInBrackets
  5339. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5340. do
  5341. {
  5342. if (putNumbersInBrackets)
  5343. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5344. else
  5345. f = getChildFile (prefix + String (num++) + suffix);
  5346. } while (f.exists());
  5347. }
  5348. return f;
  5349. }
  5350. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5351. {
  5352. if (exists())
  5353. {
  5354. return getParentDirectory()
  5355. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5356. getFileExtension(),
  5357. putNumbersInBrackets);
  5358. }
  5359. else
  5360. {
  5361. return *this;
  5362. }
  5363. }
  5364. const String File::getFileExtension() const
  5365. {
  5366. String ext;
  5367. if (! isDirectory())
  5368. {
  5369. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5370. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5371. ext = fullPath.substring (indexOfDot);
  5372. }
  5373. return ext;
  5374. }
  5375. bool File::hasFileExtension (const String& possibleSuffix) const
  5376. {
  5377. if (possibleSuffix.isEmpty())
  5378. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5379. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5380. if (semicolon >= 0)
  5381. {
  5382. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5383. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5384. }
  5385. else
  5386. {
  5387. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5388. {
  5389. if (possibleSuffix.startsWithChar (T('.')))
  5390. return true;
  5391. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5392. if (dotPos >= 0)
  5393. return fullPath [dotPos] == T('.');
  5394. }
  5395. }
  5396. return false;
  5397. }
  5398. const File File::withFileExtension (const String& newExtension) const
  5399. {
  5400. if (fullPath.isEmpty())
  5401. return File::nonexistent;
  5402. String filePart (getFileName());
  5403. int i = filePart.lastIndexOfChar (T('.'));
  5404. if (i < 0)
  5405. i = filePart.length();
  5406. String newExt (newExtension);
  5407. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5408. newExt = T(".") + newExt;
  5409. return getSiblingFile (filePart.substring (0, i) + newExt);
  5410. }
  5411. bool File::startAsProcess (const String& parameters) const
  5412. {
  5413. return exists()
  5414. && juce_launchFile (fullPath, parameters);
  5415. }
  5416. FileInputStream* File::createInputStream() const
  5417. {
  5418. if (existsAsFile())
  5419. return new FileInputStream (*this);
  5420. else
  5421. return 0;
  5422. }
  5423. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5424. {
  5425. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5426. if (out->failedToOpen())
  5427. return 0;
  5428. return out.release();
  5429. }
  5430. bool File::appendData (const void* const dataToAppend,
  5431. const int numberOfBytes) const
  5432. {
  5433. if (numberOfBytes > 0)
  5434. {
  5435. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5436. if (out == 0)
  5437. return false;
  5438. out->write (dataToAppend, numberOfBytes);
  5439. }
  5440. return true;
  5441. }
  5442. bool File::replaceWithData (const void* const dataToWrite,
  5443. const int numberOfBytes) const
  5444. {
  5445. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5446. if (numberOfBytes <= 0)
  5447. return deleteFile();
  5448. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5449. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5450. return tempFile.overwriteTargetFileWithTemporary();
  5451. }
  5452. bool File::appendText (const String& text,
  5453. const bool asUnicode,
  5454. const bool writeUnicodeHeaderBytes) const
  5455. {
  5456. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5457. if (out != 0)
  5458. {
  5459. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5460. return true;
  5461. }
  5462. return false;
  5463. }
  5464. bool File::replaceWithText (const String& textToWrite,
  5465. const bool asUnicode,
  5466. const bool writeUnicodeHeaderBytes) const
  5467. {
  5468. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5469. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5470. return tempFile.overwriteTargetFileWithTemporary();
  5471. }
  5472. const String File::createLegalPathName (const String& original)
  5473. {
  5474. String s (original);
  5475. String start;
  5476. if (s[1] == T(':'))
  5477. {
  5478. start = s.substring (0, 2);
  5479. s = s.substring (2);
  5480. }
  5481. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5482. .substring (0, 1024);
  5483. }
  5484. const String File::createLegalFileName (const String& original)
  5485. {
  5486. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5487. const int maxLength = 128; // only the length of the filename, not the whole path
  5488. const int len = s.length();
  5489. if (len > maxLength)
  5490. {
  5491. const int lastDot = s.lastIndexOfChar (T('.'));
  5492. if (lastDot > jmax (0, len - 12))
  5493. {
  5494. s = s.substring (0, maxLength - (len - lastDot))
  5495. + s.substring (lastDot);
  5496. }
  5497. else
  5498. {
  5499. s = s.substring (0, maxLength);
  5500. }
  5501. }
  5502. return s;
  5503. }
  5504. const String File::getRelativePathFrom (const File& dir) const
  5505. {
  5506. String thisPath (fullPath);
  5507. {
  5508. int len = thisPath.length();
  5509. while (--len >= 0 && thisPath [len] == File::separator)
  5510. thisPath [len] = 0;
  5511. }
  5512. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5513. : dir.fullPath));
  5514. const int len = jmin (thisPath.length(), dirPath.length());
  5515. int commonBitLength = 0;
  5516. for (int i = 0; i < len; ++i)
  5517. {
  5518. #if NAMES_ARE_CASE_SENSITIVE
  5519. if (thisPath[i] != dirPath[i])
  5520. #else
  5521. if (CharacterFunctions::toLowerCase (thisPath[i])
  5522. != CharacterFunctions::toLowerCase (dirPath[i]))
  5523. #endif
  5524. {
  5525. break;
  5526. }
  5527. ++commonBitLength;
  5528. }
  5529. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5530. --commonBitLength;
  5531. // if the only common bit is the root, then just return the full path..
  5532. if (commonBitLength <= 0
  5533. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5534. return fullPath;
  5535. thisPath = thisPath.substring (commonBitLength);
  5536. dirPath = dirPath.substring (commonBitLength);
  5537. while (dirPath.isNotEmpty())
  5538. {
  5539. #if JUCE_WINDOWS
  5540. thisPath = T("..\\") + thisPath;
  5541. #else
  5542. thisPath = T("../") + thisPath;
  5543. #endif
  5544. const int sep = dirPath.indexOfChar (separator);
  5545. if (sep >= 0)
  5546. dirPath = dirPath.substring (sep + 1);
  5547. else
  5548. dirPath = String::empty;
  5549. }
  5550. return thisPath;
  5551. }
  5552. void File::findFileSystemRoots (Array<File>& destArray)
  5553. {
  5554. const StringArray roots (juce_getFileSystemRoots());
  5555. for (int i = 0; i < roots.size(); ++i)
  5556. destArray.add (File (roots[i]));
  5557. }
  5558. const String File::getVolumeLabel() const
  5559. {
  5560. int serialNum;
  5561. return juce_getVolumeLabel (fullPath, serialNum);
  5562. }
  5563. int File::getVolumeSerialNumber() const
  5564. {
  5565. int serialNum;
  5566. juce_getVolumeLabel (fullPath, serialNum);
  5567. return serialNum;
  5568. }
  5569. const File File::createTempFile (const String& fileNameEnding)
  5570. {
  5571. const File tempFile (getSpecialLocation (tempDirectory)
  5572. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5573. .withFileExtension (fileNameEnding));
  5574. if (tempFile.exists())
  5575. return createTempFile (fileNameEnding);
  5576. else
  5577. return tempFile;
  5578. }
  5579. END_JUCE_NAMESPACE
  5580. /*** End of inlined file: juce_File.cpp ***/
  5581. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5582. BEGIN_JUCE_NAMESPACE
  5583. void* juce_fileOpen (const String& path, bool forWriting);
  5584. void juce_fileClose (void* handle);
  5585. int juce_fileRead (void* handle, void* buffer, int size);
  5586. int64 juce_fileSetPosition (void* handle, int64 pos);
  5587. FileInputStream::FileInputStream (const File& f)
  5588. : file (f),
  5589. currentPosition (0),
  5590. needToSeek (true)
  5591. {
  5592. totalSize = f.getSize();
  5593. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5594. }
  5595. FileInputStream::~FileInputStream()
  5596. {
  5597. juce_fileClose (fileHandle);
  5598. }
  5599. int64 FileInputStream::getTotalLength()
  5600. {
  5601. return totalSize;
  5602. }
  5603. int FileInputStream::read (void* buffer, int bytesToRead)
  5604. {
  5605. int num = 0;
  5606. if (needToSeek)
  5607. {
  5608. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5609. return 0;
  5610. needToSeek = false;
  5611. }
  5612. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5613. currentPosition += num;
  5614. return num;
  5615. }
  5616. bool FileInputStream::isExhausted()
  5617. {
  5618. return currentPosition >= totalSize;
  5619. }
  5620. int64 FileInputStream::getPosition()
  5621. {
  5622. return currentPosition;
  5623. }
  5624. bool FileInputStream::setPosition (int64 pos)
  5625. {
  5626. pos = jlimit ((int64) 0, totalSize, pos);
  5627. needToSeek |= (currentPosition != pos);
  5628. currentPosition = pos;
  5629. return true;
  5630. }
  5631. END_JUCE_NAMESPACE
  5632. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5633. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5634. BEGIN_JUCE_NAMESPACE
  5635. void* juce_fileOpen (const String& path, bool forWriting);
  5636. void juce_fileClose (void* handle);
  5637. int juce_fileWrite (void* handle, const void* buffer, int size);
  5638. void juce_fileFlush (void* handle);
  5639. int64 juce_fileGetPosition (void* handle);
  5640. int64 juce_fileSetPosition (void* handle, int64 pos);
  5641. FileOutputStream::FileOutputStream (const File& f,
  5642. const int bufferSize_)
  5643. : file (f),
  5644. bufferSize (bufferSize_),
  5645. bytesInBuffer (0)
  5646. {
  5647. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5648. if (fileHandle != 0)
  5649. {
  5650. currentPosition = juce_fileGetPosition (fileHandle);
  5651. if (currentPosition < 0)
  5652. {
  5653. jassertfalse
  5654. juce_fileClose (fileHandle);
  5655. fileHandle = 0;
  5656. }
  5657. }
  5658. buffer.malloc (jmax (bufferSize_, 16));
  5659. }
  5660. FileOutputStream::~FileOutputStream()
  5661. {
  5662. flush();
  5663. juce_fileClose (fileHandle);
  5664. }
  5665. int64 FileOutputStream::getPosition()
  5666. {
  5667. return currentPosition;
  5668. }
  5669. bool FileOutputStream::setPosition (int64 newPosition)
  5670. {
  5671. if (newPosition != currentPosition)
  5672. {
  5673. flush();
  5674. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5675. }
  5676. return newPosition == currentPosition;
  5677. }
  5678. void FileOutputStream::flush()
  5679. {
  5680. if (bytesInBuffer > 0)
  5681. {
  5682. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5683. bytesInBuffer = 0;
  5684. }
  5685. juce_fileFlush (fileHandle);
  5686. }
  5687. bool FileOutputStream::write (const void* const src, const int numBytes)
  5688. {
  5689. if (bytesInBuffer + numBytes < bufferSize)
  5690. {
  5691. memcpy (buffer + bytesInBuffer, src, numBytes);
  5692. bytesInBuffer += numBytes;
  5693. currentPosition += numBytes;
  5694. }
  5695. else
  5696. {
  5697. if (bytesInBuffer > 0)
  5698. {
  5699. // flush the reservoir
  5700. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5701. bytesInBuffer = 0;
  5702. if (! wroteOk)
  5703. return false;
  5704. }
  5705. if (numBytes < bufferSize)
  5706. {
  5707. memcpy (buffer + bytesInBuffer, src, numBytes);
  5708. bytesInBuffer += numBytes;
  5709. currentPosition += numBytes;
  5710. }
  5711. else
  5712. {
  5713. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5714. currentPosition += bytesWritten;
  5715. return bytesWritten == numBytes;
  5716. }
  5717. }
  5718. return true;
  5719. }
  5720. END_JUCE_NAMESPACE
  5721. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5722. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5723. BEGIN_JUCE_NAMESPACE
  5724. FileSearchPath::FileSearchPath()
  5725. {
  5726. }
  5727. FileSearchPath::FileSearchPath (const String& path)
  5728. {
  5729. init (path);
  5730. }
  5731. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5732. : directories (other.directories)
  5733. {
  5734. }
  5735. FileSearchPath::~FileSearchPath()
  5736. {
  5737. }
  5738. const FileSearchPath& FileSearchPath::operator= (const String& path)
  5739. {
  5740. init (path);
  5741. return *this;
  5742. }
  5743. void FileSearchPath::init (const String& path)
  5744. {
  5745. directories.clear();
  5746. directories.addTokens (path, T(";"), T("\""));
  5747. directories.trim();
  5748. directories.removeEmptyStrings();
  5749. for (int i = directories.size(); --i >= 0;)
  5750. directories.set (i, directories[i].unquoted());
  5751. }
  5752. int FileSearchPath::getNumPaths() const
  5753. {
  5754. return directories.size();
  5755. }
  5756. const File FileSearchPath::operator[] (const int index) const
  5757. {
  5758. return File (directories [index]);
  5759. }
  5760. const String FileSearchPath::toString() const
  5761. {
  5762. StringArray directories2 (directories);
  5763. for (int i = directories2.size(); --i >= 0;)
  5764. if (directories2[i].containsChar (T(';')))
  5765. directories2.set (i, directories2[i].quoted());
  5766. return directories2.joinIntoString (T(";"));
  5767. }
  5768. void FileSearchPath::add (const File& dir, const int insertIndex)
  5769. {
  5770. directories.insert (insertIndex, dir.getFullPathName());
  5771. }
  5772. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5773. {
  5774. for (int i = 0; i < directories.size(); ++i)
  5775. if (File (directories[i]) == dir)
  5776. return;
  5777. add (dir);
  5778. }
  5779. void FileSearchPath::remove (const int index)
  5780. {
  5781. directories.remove (index);
  5782. }
  5783. void FileSearchPath::addPath (const FileSearchPath& other)
  5784. {
  5785. for (int i = 0; i < other.getNumPaths(); ++i)
  5786. addIfNotAlreadyThere (other[i]);
  5787. }
  5788. void FileSearchPath::removeRedundantPaths()
  5789. {
  5790. for (int i = directories.size(); --i >= 0;)
  5791. {
  5792. const File d1 (directories[i]);
  5793. for (int j = directories.size(); --j >= 0;)
  5794. {
  5795. const File d2 (directories[j]);
  5796. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5797. {
  5798. directories.remove (i);
  5799. break;
  5800. }
  5801. }
  5802. }
  5803. }
  5804. void FileSearchPath::removeNonExistentPaths()
  5805. {
  5806. for (int i = directories.size(); --i >= 0;)
  5807. if (! File (directories[i]).isDirectory())
  5808. directories.remove (i);
  5809. }
  5810. int FileSearchPath::findChildFiles (Array<File>& results,
  5811. const int whatToLookFor,
  5812. const bool searchRecursively,
  5813. const String& wildCardPattern) const
  5814. {
  5815. int total = 0;
  5816. for (int i = 0; i < directories.size(); ++i)
  5817. total += operator[] (i).findChildFiles (results,
  5818. whatToLookFor,
  5819. searchRecursively,
  5820. wildCardPattern);
  5821. return total;
  5822. }
  5823. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5824. const bool checkRecursively) const
  5825. {
  5826. for (int i = directories.size(); --i >= 0;)
  5827. {
  5828. const File d (directories[i]);
  5829. if (checkRecursively)
  5830. {
  5831. if (fileToCheck.isAChildOf (d))
  5832. return true;
  5833. }
  5834. else
  5835. {
  5836. if (fileToCheck.getParentDirectory() == d)
  5837. return true;
  5838. }
  5839. }
  5840. return false;
  5841. }
  5842. END_JUCE_NAMESPACE
  5843. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5844. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5845. BEGIN_JUCE_NAMESPACE
  5846. NamedPipe::NamedPipe()
  5847. : internal (0)
  5848. {
  5849. }
  5850. NamedPipe::~NamedPipe()
  5851. {
  5852. close();
  5853. }
  5854. bool NamedPipe::openExisting (const String& pipeName)
  5855. {
  5856. currentPipeName = pipeName;
  5857. return openInternal (pipeName, false);
  5858. }
  5859. bool NamedPipe::createNewPipe (const String& pipeName)
  5860. {
  5861. currentPipeName = pipeName;
  5862. return openInternal (pipeName, true);
  5863. }
  5864. bool NamedPipe::isOpen() const
  5865. {
  5866. return internal != 0;
  5867. }
  5868. const String NamedPipe::getName() const
  5869. {
  5870. return currentPipeName;
  5871. }
  5872. // other methods for this class are implemented in the platform-specific files
  5873. END_JUCE_NAMESPACE
  5874. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5875. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5876. BEGIN_JUCE_NAMESPACE
  5877. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5878. {
  5879. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5880. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5881. suffix,
  5882. optionFlags);
  5883. }
  5884. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5885. : targetFile (targetFile_)
  5886. {
  5887. // If you use this constructor, you need to give it a valid target file!
  5888. jassert (targetFile != File::nonexistent);
  5889. createTempFile (targetFile.getParentDirectory(),
  5890. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5891. targetFile.getFileExtension(),
  5892. optionFlags);
  5893. }
  5894. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5895. const String& suffix, const int optionFlags)
  5896. {
  5897. if ((optionFlags & useHiddenFile) != 0)
  5898. name = T(".") + name;
  5899. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5900. }
  5901. TemporaryFile::~TemporaryFile()
  5902. {
  5903. // Have a few attempts at deleting the file before giving up..
  5904. for (int i = 5; --i >= 0;)
  5905. {
  5906. if (temporaryFile.deleteFile())
  5907. return;
  5908. Thread::sleep (50);
  5909. }
  5910. // Failed to delete our temporary file! Check that you've deleted all the
  5911. // file output streams that were using it!
  5912. jassertfalse;
  5913. }
  5914. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5915. {
  5916. // This method only works if you created this object with the constructor
  5917. // that takes a target file!
  5918. jassert (targetFile != File::nonexistent);
  5919. if (temporaryFile.exists())
  5920. {
  5921. // Have a few attempts at overwriting the file before giving up..
  5922. for (int i = 5; --i >= 0;)
  5923. {
  5924. if (temporaryFile.moveFileTo (targetFile))
  5925. return true;
  5926. Thread::sleep (100);
  5927. }
  5928. // Failed to overwrite the new file! Make sure you've not left any
  5929. // file streams hanging around when you call this method!
  5930. jassertfalse
  5931. }
  5932. else
  5933. {
  5934. // There's no temporary file to use. If your write failed, you should
  5935. // probably check, and not bother calling this method.
  5936. jassertfalse
  5937. }
  5938. return false;
  5939. }
  5940. END_JUCE_NAMESPACE
  5941. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5942. /*** Start of inlined file: juce_Socket.cpp ***/
  5943. #if JUCE_WINDOWS
  5944. #include <winsock2.h>
  5945. #ifdef _MSC_VER
  5946. #pragma warning (disable : 4127 4389 4018)
  5947. #endif
  5948. #else
  5949. #if JUCE_LINUX
  5950. #include <sys/types.h>
  5951. #include <sys/socket.h>
  5952. #include <sys/errno.h>
  5953. #include <unistd.h>
  5954. #include <netinet/in.h>
  5955. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5956. #include <CoreServices/CoreServices.h>
  5957. #endif
  5958. #include <fcntl.h>
  5959. #include <netdb.h>
  5960. #include <arpa/inet.h>
  5961. #include <netinet/tcp.h>
  5962. #endif
  5963. BEGIN_JUCE_NAMESPACE
  5964. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5965. typedef socklen_t juce_socklen_t;
  5966. #else
  5967. typedef int juce_socklen_t;
  5968. #endif
  5969. #if JUCE_WINDOWS
  5970. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5971. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5972. static void initWin32Sockets()
  5973. {
  5974. static CriticalSection lock;
  5975. const ScopedLock sl (lock);
  5976. if (juce_CloseWin32SocketLib == 0)
  5977. {
  5978. WSADATA wsaData;
  5979. const WORD wVersionRequested = MAKEWORD (1, 1);
  5980. WSAStartup (wVersionRequested, &wsaData);
  5981. juce_CloseWin32SocketLib = &WSACleanup;
  5982. }
  5983. }
  5984. #endif
  5985. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5986. {
  5987. const int sndBufSize = 65536;
  5988. const int rcvBufSize = 65536;
  5989. const int one = 1;
  5990. return handle > 0
  5991. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5992. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5993. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5994. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5995. }
  5996. static bool bindSocketToPort (const int handle, const int port) throw()
  5997. {
  5998. if (handle <= 0 || port <= 0)
  5999. return false;
  6000. struct sockaddr_in servTmpAddr;
  6001. zerostruct (servTmpAddr);
  6002. servTmpAddr.sin_family = PF_INET;
  6003. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6004. servTmpAddr.sin_port = htons ((uint16) port);
  6005. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  6006. }
  6007. static int readSocket (const int handle,
  6008. void* const destBuffer, const int maxBytesToRead,
  6009. bool volatile& connected,
  6010. const bool blockUntilSpecifiedAmountHasArrived) throw()
  6011. {
  6012. int bytesRead = 0;
  6013. while (bytesRead < maxBytesToRead)
  6014. {
  6015. int bytesThisTime;
  6016. #if JUCE_WINDOWS
  6017. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  6018. #else
  6019. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  6020. && errno == EINTR
  6021. && connected)
  6022. {
  6023. }
  6024. #endif
  6025. if (bytesThisTime <= 0 || ! connected)
  6026. {
  6027. if (bytesRead == 0)
  6028. bytesRead = -1;
  6029. break;
  6030. }
  6031. bytesRead += bytesThisTime;
  6032. if (! blockUntilSpecifiedAmountHasArrived)
  6033. break;
  6034. }
  6035. return bytesRead;
  6036. }
  6037. static int waitForReadiness (const int handle, const bool forReading,
  6038. const int timeoutMsecs) throw()
  6039. {
  6040. struct timeval timeout;
  6041. struct timeval* timeoutp;
  6042. if (timeoutMsecs >= 0)
  6043. {
  6044. timeout.tv_sec = timeoutMsecs / 1000;
  6045. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  6046. timeoutp = &timeout;
  6047. }
  6048. else
  6049. {
  6050. timeoutp = 0;
  6051. }
  6052. fd_set rset, wset;
  6053. FD_ZERO (&rset);
  6054. FD_SET (handle, &rset);
  6055. FD_ZERO (&wset);
  6056. FD_SET (handle, &wset);
  6057. fd_set* const prset = forReading ? &rset : 0;
  6058. fd_set* const pwset = forReading ? 0 : &wset;
  6059. #if JUCE_WINDOWS
  6060. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  6061. return -1;
  6062. #else
  6063. {
  6064. int result;
  6065. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  6066. && errno == EINTR)
  6067. {
  6068. }
  6069. if (result < 0)
  6070. return -1;
  6071. }
  6072. #endif
  6073. {
  6074. int opt;
  6075. juce_socklen_t len = sizeof (opt);
  6076. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  6077. || opt != 0)
  6078. return -1;
  6079. }
  6080. if ((forReading && FD_ISSET (handle, &rset))
  6081. || ((! forReading) && FD_ISSET (handle, &wset)))
  6082. return 1;
  6083. return 0;
  6084. }
  6085. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  6086. {
  6087. #if JUCE_WINDOWS
  6088. u_long nonBlocking = shouldBlock ? 0 : 1;
  6089. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  6090. return false;
  6091. #else
  6092. int socketFlags = fcntl (handle, F_GETFL, 0);
  6093. if (socketFlags == -1)
  6094. return false;
  6095. if (shouldBlock)
  6096. socketFlags &= ~O_NONBLOCK;
  6097. else
  6098. socketFlags |= O_NONBLOCK;
  6099. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  6100. return false;
  6101. #endif
  6102. return true;
  6103. }
  6104. static bool connectSocket (int volatile& handle,
  6105. const bool isDatagram,
  6106. void** serverAddress,
  6107. const String& hostName,
  6108. const int portNumber,
  6109. const int timeOutMillisecs) throw()
  6110. {
  6111. struct hostent* const hostEnt = gethostbyname (hostName);
  6112. if (hostEnt == 0)
  6113. return false;
  6114. struct in_addr targetAddress;
  6115. memcpy (&targetAddress.s_addr,
  6116. *(hostEnt->h_addr_list),
  6117. sizeof (targetAddress.s_addr));
  6118. struct sockaddr_in servTmpAddr;
  6119. zerostruct (servTmpAddr);
  6120. servTmpAddr.sin_family = PF_INET;
  6121. servTmpAddr.sin_addr = targetAddress;
  6122. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6123. if (handle < 0)
  6124. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  6125. if (handle < 0)
  6126. return false;
  6127. if (isDatagram)
  6128. {
  6129. *serverAddress = new struct sockaddr_in();
  6130. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6131. return true;
  6132. }
  6133. setSocketBlockingState (handle, false);
  6134. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6135. if (result < 0)
  6136. {
  6137. #if JUCE_WINDOWS
  6138. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6139. #else
  6140. if (errno == EINPROGRESS)
  6141. #endif
  6142. {
  6143. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6144. {
  6145. setSocketBlockingState (handle, true);
  6146. return false;
  6147. }
  6148. }
  6149. }
  6150. setSocketBlockingState (handle, true);
  6151. resetSocketOptions (handle, false, false);
  6152. return true;
  6153. }
  6154. StreamingSocket::StreamingSocket()
  6155. : portNumber (0),
  6156. handle (-1),
  6157. connected (false),
  6158. isListener (false)
  6159. {
  6160. #if JUCE_WINDOWS
  6161. initWin32Sockets();
  6162. #endif
  6163. }
  6164. StreamingSocket::StreamingSocket (const String& hostName_,
  6165. const int portNumber_,
  6166. const int handle_)
  6167. : hostName (hostName_),
  6168. portNumber (portNumber_),
  6169. handle (handle_),
  6170. connected (true),
  6171. isListener (false)
  6172. {
  6173. #if JUCE_WINDOWS
  6174. initWin32Sockets();
  6175. #endif
  6176. resetSocketOptions (handle_, false, false);
  6177. }
  6178. StreamingSocket::~StreamingSocket()
  6179. {
  6180. close();
  6181. }
  6182. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6183. {
  6184. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6185. : -1;
  6186. }
  6187. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6188. {
  6189. if (isListener || ! connected)
  6190. return -1;
  6191. #if JUCE_WINDOWS
  6192. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6193. #else
  6194. int result;
  6195. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6196. && errno == EINTR)
  6197. {
  6198. }
  6199. return result;
  6200. #endif
  6201. }
  6202. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6203. const int timeoutMsecs) const
  6204. {
  6205. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6206. : -1;
  6207. }
  6208. bool StreamingSocket::bindToPort (const int port)
  6209. {
  6210. return bindSocketToPort (handle, port);
  6211. }
  6212. bool StreamingSocket::connect (const String& remoteHostName,
  6213. const int remotePortNumber,
  6214. const int timeOutMillisecs)
  6215. {
  6216. if (isListener)
  6217. {
  6218. jassertfalse // a listener socket can't connect to another one!
  6219. return false;
  6220. }
  6221. if (connected)
  6222. close();
  6223. hostName = remoteHostName;
  6224. portNumber = remotePortNumber;
  6225. isListener = false;
  6226. connected = connectSocket (handle, false, 0, remoteHostName,
  6227. remotePortNumber, timeOutMillisecs);
  6228. if (! (connected && resetSocketOptions (handle, false, false)))
  6229. {
  6230. close();
  6231. return false;
  6232. }
  6233. return true;
  6234. }
  6235. void StreamingSocket::close()
  6236. {
  6237. #if JUCE_WINDOWS
  6238. closesocket (handle);
  6239. connected = false;
  6240. #else
  6241. if (connected)
  6242. {
  6243. connected = false;
  6244. if (isListener)
  6245. {
  6246. // need to do this to interrupt the accept() function..
  6247. StreamingSocket temp;
  6248. temp.connect ("localhost", portNumber, 1000);
  6249. }
  6250. }
  6251. ::close (handle);
  6252. #endif
  6253. hostName = String::empty;
  6254. portNumber = 0;
  6255. handle = -1;
  6256. isListener = false;
  6257. }
  6258. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6259. {
  6260. if (connected)
  6261. close();
  6262. hostName = "listener";
  6263. portNumber = newPortNumber;
  6264. isListener = true;
  6265. struct sockaddr_in servTmpAddr;
  6266. zerostruct (servTmpAddr);
  6267. servTmpAddr.sin_family = PF_INET;
  6268. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6269. if (localHostName.isNotEmpty())
  6270. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6271. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6272. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6273. if (handle < 0)
  6274. return false;
  6275. const int reuse = 1;
  6276. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6277. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6278. || listen (handle, SOMAXCONN) < 0)
  6279. {
  6280. close();
  6281. return false;
  6282. }
  6283. connected = true;
  6284. return true;
  6285. }
  6286. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6287. {
  6288. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6289. // prepare this socket as a listener.
  6290. if (connected && isListener)
  6291. {
  6292. struct sockaddr address;
  6293. juce_socklen_t len = sizeof (sockaddr);
  6294. const int newSocket = (int) accept (handle, &address, &len);
  6295. if (newSocket >= 0 && connected)
  6296. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6297. portNumber, newSocket);
  6298. }
  6299. return 0;
  6300. }
  6301. bool StreamingSocket::isLocal() const throw()
  6302. {
  6303. return hostName == T("127.0.0.1");
  6304. }
  6305. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6306. : portNumber (0),
  6307. handle (-1),
  6308. connected (true),
  6309. allowBroadcast (allowBroadcast_),
  6310. serverAddress (0)
  6311. {
  6312. #if JUCE_WINDOWS
  6313. initWin32Sockets();
  6314. #endif
  6315. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6316. bindToPort (localPortNumber);
  6317. }
  6318. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6319. const int handle_, const int localPortNumber)
  6320. : hostName (hostName_),
  6321. portNumber (portNumber_),
  6322. handle (handle_),
  6323. connected (true),
  6324. allowBroadcast (false),
  6325. serverAddress (0)
  6326. {
  6327. #if JUCE_WINDOWS
  6328. initWin32Sockets();
  6329. #endif
  6330. resetSocketOptions (handle_, true, allowBroadcast);
  6331. bindToPort (localPortNumber);
  6332. }
  6333. DatagramSocket::~DatagramSocket()
  6334. {
  6335. close();
  6336. delete ((struct sockaddr_in*) serverAddress);
  6337. serverAddress = 0;
  6338. }
  6339. void DatagramSocket::close()
  6340. {
  6341. #if JUCE_WINDOWS
  6342. closesocket (handle);
  6343. connected = false;
  6344. #else
  6345. connected = false;
  6346. ::close (handle);
  6347. #endif
  6348. hostName = String::empty;
  6349. portNumber = 0;
  6350. handle = -1;
  6351. }
  6352. bool DatagramSocket::bindToPort (const int port)
  6353. {
  6354. return bindSocketToPort (handle, port);
  6355. }
  6356. bool DatagramSocket::connect (const String& remoteHostName,
  6357. const int remotePortNumber,
  6358. const int timeOutMillisecs)
  6359. {
  6360. if (connected)
  6361. close();
  6362. hostName = remoteHostName;
  6363. portNumber = remotePortNumber;
  6364. connected = connectSocket (handle, true, &serverAddress,
  6365. remoteHostName, remotePortNumber,
  6366. timeOutMillisecs);
  6367. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6368. {
  6369. close();
  6370. return false;
  6371. }
  6372. return true;
  6373. }
  6374. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6375. {
  6376. struct sockaddr address;
  6377. juce_socklen_t len = sizeof (sockaddr);
  6378. while (waitUntilReady (true, -1) == 1)
  6379. {
  6380. char buf[1];
  6381. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6382. {
  6383. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6384. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6385. -1, -1);
  6386. }
  6387. }
  6388. return 0;
  6389. }
  6390. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6391. const int timeoutMsecs) const
  6392. {
  6393. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6394. : -1;
  6395. }
  6396. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6397. {
  6398. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6399. : -1;
  6400. }
  6401. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6402. {
  6403. // You need to call connect() first to set the server address..
  6404. jassert (serverAddress != 0 && connected);
  6405. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6406. numBytesToWrite, 0,
  6407. (const struct sockaddr*) serverAddress,
  6408. sizeof (struct sockaddr_in))
  6409. : -1;
  6410. }
  6411. bool DatagramSocket::isLocal() const throw()
  6412. {
  6413. return hostName == T("127.0.0.1");
  6414. }
  6415. END_JUCE_NAMESPACE
  6416. /*** End of inlined file: juce_Socket.cpp ***/
  6417. /*** Start of inlined file: juce_URL.cpp ***/
  6418. BEGIN_JUCE_NAMESPACE
  6419. URL::URL()
  6420. {
  6421. }
  6422. URL::URL (const String& url_)
  6423. : url (url_)
  6424. {
  6425. int i = url.indexOfChar (T('?'));
  6426. if (i >= 0)
  6427. {
  6428. do
  6429. {
  6430. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6431. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6432. if (equalsPos > i + 1)
  6433. {
  6434. if (nextAmp < 0)
  6435. {
  6436. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6437. removeEscapeChars (url.substring (equalsPos + 1)));
  6438. }
  6439. else if (nextAmp > 0 && equalsPos < nextAmp)
  6440. {
  6441. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6442. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6443. }
  6444. }
  6445. i = nextAmp;
  6446. }
  6447. while (i >= 0);
  6448. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6449. }
  6450. }
  6451. URL::URL (const URL& other)
  6452. : url (other.url),
  6453. postData (other.postData),
  6454. parameters (other.parameters),
  6455. filesToUpload (other.filesToUpload),
  6456. mimeTypes (other.mimeTypes)
  6457. {
  6458. }
  6459. const URL& URL::operator= (const URL& other)
  6460. {
  6461. url = other.url;
  6462. postData = other.postData;
  6463. parameters = other.parameters;
  6464. filesToUpload = other.filesToUpload;
  6465. mimeTypes = other.mimeTypes;
  6466. return *this;
  6467. }
  6468. URL::~URL()
  6469. {
  6470. }
  6471. static const String getMangledParameters (const StringPairArray& parameters)
  6472. {
  6473. String p;
  6474. for (int i = 0; i < parameters.size(); ++i)
  6475. {
  6476. if (i > 0)
  6477. p += T("&");
  6478. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6479. << T("=")
  6480. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6481. }
  6482. return p;
  6483. }
  6484. const String URL::toString (const bool includeGetParameters) const
  6485. {
  6486. if (includeGetParameters && parameters.size() > 0)
  6487. return url + T("?") + getMangledParameters (parameters);
  6488. else
  6489. return url;
  6490. }
  6491. bool URL::isWellFormed() const
  6492. {
  6493. //xxx TODO
  6494. return url.isNotEmpty();
  6495. }
  6496. static int findStartOfDomain (const String& url)
  6497. {
  6498. int i = 0;
  6499. while (CharacterFunctions::isLetterOrDigit (url[i])
  6500. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6501. ++i;
  6502. return url[i] == T(':') ? i + 1 : 0;
  6503. }
  6504. const String URL::getDomain() const
  6505. {
  6506. int start = findStartOfDomain (url);
  6507. while (url[start] == T('/'))
  6508. ++start;
  6509. const int end1 = url.indexOfChar (start, T('/'));
  6510. const int end2 = url.indexOfChar (start, T(':'));
  6511. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6512. : jmin (end1, end2);
  6513. return url.substring (start, end);
  6514. }
  6515. const String URL::getSubPath() const
  6516. {
  6517. int start = findStartOfDomain (url);
  6518. while (url[start] == T('/'))
  6519. ++start;
  6520. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6521. return startOfPath <= 0 ? String::empty
  6522. : url.substring (startOfPath);
  6523. }
  6524. const String URL::getScheme() const
  6525. {
  6526. return url.substring (0, findStartOfDomain (url) - 1);
  6527. }
  6528. const URL URL::withNewSubPath (const String& newPath) const
  6529. {
  6530. int start = findStartOfDomain (url);
  6531. while (url[start] == T('/'))
  6532. ++start;
  6533. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6534. URL u (*this);
  6535. if (startOfPath > 0)
  6536. u.url = url.substring (0, startOfPath);
  6537. if (! u.url.endsWithChar (T('/')))
  6538. u.url << '/';
  6539. if (newPath.startsWithChar (T('/')))
  6540. u.url << newPath.substring (1);
  6541. else
  6542. u.url << newPath;
  6543. return u;
  6544. }
  6545. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6546. {
  6547. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6548. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6549. return true;
  6550. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6551. || possibleURL.containsChar (T('@'))
  6552. || possibleURL.endsWithChar (T('.'))
  6553. || (! possibleURL.containsChar (T('.'))))
  6554. return false;
  6555. if (possibleURL.startsWithIgnoreCase (T("www."))
  6556. && possibleURL.substring (5).containsChar (T('.')))
  6557. return true;
  6558. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6559. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6560. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6561. return true;
  6562. return false;
  6563. }
  6564. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6565. {
  6566. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6567. return atSign > 0
  6568. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6569. && (! possibleEmailAddress.endsWithChar (T('.')));
  6570. }
  6571. void* juce_openInternetFile (const String& url,
  6572. const String& headers,
  6573. const MemoryBlock& optionalPostData,
  6574. const bool isPost,
  6575. URL::OpenStreamProgressCallback* callback,
  6576. void* callbackContext,
  6577. int timeOutMs);
  6578. void juce_closeInternetFile (void* handle);
  6579. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6580. int juce_seekInInternetFile (void* handle, int newPosition);
  6581. int64 juce_getInternetFileContentLength (void* handle);
  6582. class WebInputStream : public InputStream
  6583. {
  6584. public:
  6585. WebInputStream (const URL& url,
  6586. const bool isPost_,
  6587. URL::OpenStreamProgressCallback* const progressCallback_,
  6588. void* const progressCallbackContext_,
  6589. const String& extraHeaders,
  6590. int timeOutMs_)
  6591. : position (0),
  6592. finished (false),
  6593. isPost (isPost_),
  6594. progressCallback (progressCallback_),
  6595. progressCallbackContext (progressCallbackContext_),
  6596. timeOutMs (timeOutMs_)
  6597. {
  6598. server = url.toString (! isPost);
  6599. if (isPost_)
  6600. createHeadersAndPostData (url);
  6601. headers += extraHeaders;
  6602. if (! headers.endsWithChar (T('\n')))
  6603. headers << "\r\n";
  6604. handle = juce_openInternetFile (server, headers, postData, isPost,
  6605. progressCallback_, progressCallbackContext_,
  6606. timeOutMs);
  6607. }
  6608. ~WebInputStream()
  6609. {
  6610. juce_closeInternetFile (handle);
  6611. }
  6612. bool isError() const
  6613. {
  6614. return handle == 0;
  6615. }
  6616. int64 getTotalLength()
  6617. {
  6618. return juce_getInternetFileContentLength (handle);
  6619. }
  6620. bool isExhausted()
  6621. {
  6622. return finished;
  6623. }
  6624. int read (void* dest, int bytes)
  6625. {
  6626. if (finished || isError())
  6627. {
  6628. return 0;
  6629. }
  6630. else
  6631. {
  6632. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6633. position += bytesRead;
  6634. if (bytesRead == 0)
  6635. finished = true;
  6636. return bytesRead;
  6637. }
  6638. }
  6639. int64 getPosition()
  6640. {
  6641. return position;
  6642. }
  6643. bool setPosition (int64 wantedPos)
  6644. {
  6645. if (wantedPos != position)
  6646. {
  6647. finished = false;
  6648. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6649. if (actualPos == wantedPos)
  6650. {
  6651. position = wantedPos;
  6652. }
  6653. else
  6654. {
  6655. if (wantedPos < position)
  6656. {
  6657. juce_closeInternetFile (handle);
  6658. position = 0;
  6659. finished = false;
  6660. handle = juce_openInternetFile (server, headers, postData, isPost,
  6661. progressCallback, progressCallbackContext,
  6662. timeOutMs);
  6663. }
  6664. skipNextBytes (wantedPos - position);
  6665. }
  6666. }
  6667. return true;
  6668. }
  6669. juce_UseDebuggingNewOperator
  6670. private:
  6671. String server, headers;
  6672. MemoryBlock postData;
  6673. int64 position;
  6674. bool finished;
  6675. const bool isPost;
  6676. void* handle;
  6677. URL::OpenStreamProgressCallback* const progressCallback;
  6678. void* const progressCallbackContext;
  6679. const int timeOutMs;
  6680. void createHeadersAndPostData (const URL& url)
  6681. {
  6682. if (url.getFilesToUpload().size() > 0)
  6683. {
  6684. // need to upload some files, so do it as multi-part...
  6685. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6686. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6687. appendUTF8ToPostData ("--" + boundary);
  6688. int i;
  6689. for (i = 0; i < url.getParameters().size(); ++i)
  6690. {
  6691. String s;
  6692. s << "\r\nContent-Disposition: form-data; name=\""
  6693. << url.getParameters().getAllKeys() [i]
  6694. << "\"\r\n\r\n"
  6695. << url.getParameters().getAllValues() [i]
  6696. << "\r\n--"
  6697. << boundary;
  6698. appendUTF8ToPostData (s);
  6699. }
  6700. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6701. {
  6702. const File f (url.getFilesToUpload().getAllValues() [i]);
  6703. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6704. String s;
  6705. s << "\r\nContent-Disposition: form-data; name=\""
  6706. << paramName
  6707. << "\"; filename=\""
  6708. << f.getFileName()
  6709. << "\"\r\n";
  6710. const String mimeType (url.getMimeTypesOfUploadFiles()
  6711. .getValue (paramName, String::empty));
  6712. if (mimeType.isNotEmpty())
  6713. s << "Content-Type: " << mimeType << "\r\n";
  6714. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6715. appendUTF8ToPostData (s);
  6716. f.loadFileAsData (postData);
  6717. s = "\r\n--" + boundary;
  6718. appendUTF8ToPostData (s);
  6719. }
  6720. appendUTF8ToPostData ("--\r\n");
  6721. }
  6722. else
  6723. {
  6724. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6725. appendUTF8ToPostData (url.getPostData());
  6726. // just a short text attachment, so use simple url encoding..
  6727. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6728. + String ((unsigned int) postData.getSize())
  6729. + "\r\n";
  6730. }
  6731. }
  6732. void appendUTF8ToPostData (const String& text)
  6733. {
  6734. postData.append (text.toUTF8(),
  6735. (int) strlen (text.toUTF8()));
  6736. }
  6737. WebInputStream (const WebInputStream&);
  6738. const WebInputStream& operator= (const WebInputStream&);
  6739. };
  6740. InputStream* URL::createInputStream (const bool usePostCommand,
  6741. OpenStreamProgressCallback* const progressCallback,
  6742. void* const progressCallbackContext,
  6743. const String& extraHeaders,
  6744. const int timeOutMs) const
  6745. {
  6746. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6747. progressCallback, progressCallbackContext,
  6748. extraHeaders,
  6749. timeOutMs));
  6750. return wi->isError() ? 0 : wi.release();
  6751. }
  6752. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6753. const bool usePostCommand) const
  6754. {
  6755. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6756. if (in != 0)
  6757. {
  6758. in->readIntoMemoryBlock (destData, -1);
  6759. return true;
  6760. }
  6761. return false;
  6762. }
  6763. const String URL::readEntireTextStream (const bool usePostCommand) const
  6764. {
  6765. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6766. if (in != 0)
  6767. return in->readEntireStreamAsString();
  6768. return String::empty;
  6769. }
  6770. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6771. {
  6772. XmlDocument doc (readEntireTextStream (usePostCommand));
  6773. return doc.getDocumentElement();
  6774. }
  6775. const URL URL::withParameter (const String& parameterName,
  6776. const String& parameterValue) const
  6777. {
  6778. URL u (*this);
  6779. u.parameters.set (parameterName, parameterValue);
  6780. return u;
  6781. }
  6782. const URL URL::withFileToUpload (const String& parameterName,
  6783. const File& fileToUpload,
  6784. const String& mimeType) const
  6785. {
  6786. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6787. URL u (*this);
  6788. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6789. u.mimeTypes.set (parameterName, mimeType);
  6790. return u;
  6791. }
  6792. const URL URL::withPOSTData (const String& postData_) const
  6793. {
  6794. URL u (*this);
  6795. u.postData = postData_;
  6796. return u;
  6797. }
  6798. const StringPairArray& URL::getParameters() const
  6799. {
  6800. return parameters;
  6801. }
  6802. const StringPairArray& URL::getFilesToUpload() const
  6803. {
  6804. return filesToUpload;
  6805. }
  6806. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6807. {
  6808. return mimeTypes;
  6809. }
  6810. const String URL::removeEscapeChars (const String& s)
  6811. {
  6812. const int len = s.length();
  6813. HeapBlock <uint8> resultUTF8 (len * 4);
  6814. uint8* r = resultUTF8;
  6815. for (int i = 0; i < len; ++i)
  6816. {
  6817. char c = (char) s[i];
  6818. if (c == 0)
  6819. break;
  6820. if (c == '+')
  6821. {
  6822. c = ' ';
  6823. }
  6824. else if (c == '%')
  6825. {
  6826. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6827. i += 2;
  6828. }
  6829. *r++ = c;
  6830. }
  6831. return String::fromUTF8 (resultUTF8);
  6832. }
  6833. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6834. {
  6835. String result;
  6836. result.preallocateStorage (s.length() + 8);
  6837. const char* utf8 = s.toUTF8();
  6838. const char* legalChars = isParameter ? "_-.*!'()"
  6839. : "_-$.*!'(),";
  6840. while (*utf8 != 0)
  6841. {
  6842. const char c = *utf8++;
  6843. if (CharacterFunctions::isLetterOrDigit (c)
  6844. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6845. {
  6846. result << c;
  6847. }
  6848. else
  6849. {
  6850. const int v = (int) (uint8) c;
  6851. if (v < 0x10)
  6852. result << T("%0");
  6853. else
  6854. result << T('%');
  6855. result << String::toHexString (v);
  6856. }
  6857. }
  6858. return result;
  6859. }
  6860. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6861. bool URL::launchInDefaultBrowser() const
  6862. {
  6863. String u (toString (true));
  6864. if (u.contains (T("@")) && ! u.contains (T(":")))
  6865. u = "mailto:" + u;
  6866. return juce_launchFile (u, String::empty);
  6867. }
  6868. END_JUCE_NAMESPACE
  6869. /*** End of inlined file: juce_URL.cpp ***/
  6870. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6871. BEGIN_JUCE_NAMESPACE
  6872. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6873. const int bufferSize_,
  6874. const bool deleteSourceWhenDestroyed)
  6875. : source (source_),
  6876. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6877. bufferSize (jmax (256, bufferSize_)),
  6878. position (source_->getPosition()),
  6879. lastReadPos (0),
  6880. bufferOverlap (128)
  6881. {
  6882. const int sourceSize = (int) source_->getTotalLength();
  6883. if (sourceSize >= 0)
  6884. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6885. bufferStart = position;
  6886. buffer.malloc (bufferSize);
  6887. }
  6888. BufferedInputStream::~BufferedInputStream()
  6889. {
  6890. }
  6891. int64 BufferedInputStream::getTotalLength()
  6892. {
  6893. return source->getTotalLength();
  6894. }
  6895. int64 BufferedInputStream::getPosition()
  6896. {
  6897. return position;
  6898. }
  6899. bool BufferedInputStream::setPosition (int64 newPosition)
  6900. {
  6901. position = jmax ((int64) 0, newPosition);
  6902. return true;
  6903. }
  6904. bool BufferedInputStream::isExhausted()
  6905. {
  6906. return (position >= lastReadPos)
  6907. && source->isExhausted();
  6908. }
  6909. void BufferedInputStream::ensureBuffered()
  6910. {
  6911. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6912. if (position < bufferStart || position >= bufferEndOverlap)
  6913. {
  6914. int bytesRead;
  6915. if (position < lastReadPos
  6916. && position >= bufferEndOverlap
  6917. && position >= bufferStart)
  6918. {
  6919. const int bytesToKeep = (int) (lastReadPos - position);
  6920. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6921. bufferStart = position;
  6922. bytesRead = source->read (buffer + bytesToKeep,
  6923. bufferSize - bytesToKeep);
  6924. lastReadPos += bytesRead;
  6925. bytesRead += bytesToKeep;
  6926. }
  6927. else
  6928. {
  6929. bufferStart = position;
  6930. source->setPosition (bufferStart);
  6931. bytesRead = source->read (buffer, bufferSize);
  6932. lastReadPos = bufferStart + bytesRead;
  6933. }
  6934. while (bytesRead < bufferSize)
  6935. buffer [bytesRead++] = 0;
  6936. }
  6937. }
  6938. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6939. {
  6940. if (position >= bufferStart
  6941. && position + maxBytesToRead <= lastReadPos)
  6942. {
  6943. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6944. position += maxBytesToRead;
  6945. return maxBytesToRead;
  6946. }
  6947. else
  6948. {
  6949. if (position < bufferStart || position >= lastReadPos)
  6950. ensureBuffered();
  6951. int bytesRead = 0;
  6952. while (maxBytesToRead > 0)
  6953. {
  6954. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6955. if (bytesAvailable > 0)
  6956. {
  6957. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6958. maxBytesToRead -= bytesAvailable;
  6959. bytesRead += bytesAvailable;
  6960. position += bytesAvailable;
  6961. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6962. }
  6963. const int64 oldLastReadPos = lastReadPos;
  6964. ensureBuffered();
  6965. if (oldLastReadPos == lastReadPos)
  6966. break; // if ensureBuffered() failed to read any more data, bail out
  6967. if (isExhausted())
  6968. break;
  6969. }
  6970. return bytesRead;
  6971. }
  6972. }
  6973. const String BufferedInputStream::readString()
  6974. {
  6975. if (position >= bufferStart
  6976. && position < lastReadPos)
  6977. {
  6978. const int maxChars = (int) (lastReadPos - position);
  6979. const char* const src = buffer + (int) (position - bufferStart);
  6980. for (int i = 0; i < maxChars; ++i)
  6981. {
  6982. if (src[i] == 0)
  6983. {
  6984. position += i + 1;
  6985. return String::fromUTF8 ((const uint8*) src, i);
  6986. }
  6987. }
  6988. }
  6989. return InputStream::readString();
  6990. }
  6991. END_JUCE_NAMESPACE
  6992. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6993. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6994. BEGIN_JUCE_NAMESPACE
  6995. FileInputSource::FileInputSource (const File& file_)
  6996. : file (file_)
  6997. {
  6998. }
  6999. FileInputSource::~FileInputSource()
  7000. {
  7001. }
  7002. InputStream* FileInputSource::createInputStream()
  7003. {
  7004. return file.createInputStream();
  7005. }
  7006. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  7007. {
  7008. return file.getSiblingFile (relatedItemPath).createInputStream();
  7009. }
  7010. int64 FileInputSource::hashCode() const
  7011. {
  7012. return file.hashCode();
  7013. }
  7014. END_JUCE_NAMESPACE
  7015. /*** End of inlined file: juce_FileInputSource.cpp ***/
  7016. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  7017. BEGIN_JUCE_NAMESPACE
  7018. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  7019. const size_t sourceDataSize,
  7020. const bool keepInternalCopy)
  7021. : data ((const char*) sourceData),
  7022. dataSize (sourceDataSize),
  7023. position (0)
  7024. {
  7025. if (keepInternalCopy)
  7026. {
  7027. internalCopy.append (data, sourceDataSize);
  7028. data = (const char*) internalCopy.getData();
  7029. }
  7030. }
  7031. MemoryInputStream::~MemoryInputStream()
  7032. {
  7033. }
  7034. int64 MemoryInputStream::getTotalLength()
  7035. {
  7036. return dataSize;
  7037. }
  7038. int MemoryInputStream::read (void* buffer, int howMany)
  7039. {
  7040. jassert (howMany >= 0);
  7041. const int num = jmin (howMany, (int) (dataSize - position));
  7042. memcpy (buffer, data + position, num);
  7043. position += num;
  7044. return (int) num;
  7045. }
  7046. bool MemoryInputStream::isExhausted()
  7047. {
  7048. return (position >= dataSize);
  7049. }
  7050. bool MemoryInputStream::setPosition (int64 pos)
  7051. {
  7052. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  7053. return true;
  7054. }
  7055. int64 MemoryInputStream::getPosition()
  7056. {
  7057. return position;
  7058. }
  7059. END_JUCE_NAMESPACE
  7060. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  7061. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  7062. BEGIN_JUCE_NAMESPACE
  7063. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  7064. const size_t blockSizeToIncreaseBy,
  7065. MemoryBlock* const memoryBlockToWriteTo) throw()
  7066. : data (memoryBlockToWriteTo),
  7067. position (0),
  7068. size (0),
  7069. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  7070. {
  7071. if (data == 0)
  7072. dataToDelete = data = new MemoryBlock (initialSize);
  7073. else
  7074. data->setSize (initialSize, false);
  7075. }
  7076. MemoryOutputStream::~MemoryOutputStream() throw()
  7077. {
  7078. flush();
  7079. }
  7080. void MemoryOutputStream::flush()
  7081. {
  7082. if (dataToDelete == 0)
  7083. data->setSize (size, false);
  7084. }
  7085. void MemoryOutputStream::reset() throw()
  7086. {
  7087. position = 0;
  7088. size = 0;
  7089. }
  7090. bool MemoryOutputStream::write (const void* buffer, int howMany)
  7091. {
  7092. if (howMany > 0)
  7093. {
  7094. size_t storageNeeded = position + howMany;
  7095. if (storageNeeded >= data->getSize())
  7096. {
  7097. // if we need more space, increase the block by at least 10%..
  7098. storageNeeded += jmax (blockSize, storageNeeded / 10);
  7099. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  7100. data->ensureSize (storageNeeded);
  7101. }
  7102. data->copyFrom (buffer, (int) position, howMany);
  7103. position += howMany;
  7104. size = jmax (size, position);
  7105. }
  7106. return true;
  7107. }
  7108. const char* MemoryOutputStream::getData() const throw()
  7109. {
  7110. if (data->getSize() > size)
  7111. ((char*) data->getData()) [size] = 0;
  7112. return (const char*) data->getData();
  7113. }
  7114. size_t MemoryOutputStream::getDataSize() const throw()
  7115. {
  7116. return size;
  7117. }
  7118. int64 MemoryOutputStream::getPosition()
  7119. {
  7120. return position;
  7121. }
  7122. bool MemoryOutputStream::setPosition (int64 newPosition)
  7123. {
  7124. if (newPosition <= (int64) size)
  7125. {
  7126. // ok to seek backwards
  7127. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7128. return true;
  7129. }
  7130. else
  7131. {
  7132. // trying to make it bigger isn't a good thing to do..
  7133. return false;
  7134. }
  7135. }
  7136. END_JUCE_NAMESPACE
  7137. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  7138. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  7139. BEGIN_JUCE_NAMESPACE
  7140. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7141. const int64 startPositionInSourceStream_,
  7142. const int64 lengthOfSourceStream_,
  7143. const bool deleteSourceWhenDestroyed) throw()
  7144. : source (sourceStream),
  7145. startPositionInSourceStream (startPositionInSourceStream_),
  7146. lengthOfSourceStream (lengthOfSourceStream_)
  7147. {
  7148. if (deleteSourceWhenDestroyed)
  7149. sourceToDelete = source;
  7150. setPosition (0);
  7151. }
  7152. SubregionStream::~SubregionStream() throw()
  7153. {
  7154. }
  7155. int64 SubregionStream::getTotalLength()
  7156. {
  7157. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7158. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7159. : srcLen;
  7160. }
  7161. int64 SubregionStream::getPosition()
  7162. {
  7163. return source->getPosition() - startPositionInSourceStream;
  7164. }
  7165. bool SubregionStream::setPosition (int64 newPosition)
  7166. {
  7167. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7168. }
  7169. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7170. {
  7171. if (lengthOfSourceStream < 0)
  7172. {
  7173. return source->read (destBuffer, maxBytesToRead);
  7174. }
  7175. else
  7176. {
  7177. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7178. if (maxBytesToRead <= 0)
  7179. return 0;
  7180. return source->read (destBuffer, maxBytesToRead);
  7181. }
  7182. }
  7183. bool SubregionStream::isExhausted()
  7184. {
  7185. if (lengthOfSourceStream >= 0)
  7186. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7187. else
  7188. return source->isExhausted();
  7189. }
  7190. END_JUCE_NAMESPACE
  7191. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7192. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7193. BEGIN_JUCE_NAMESPACE
  7194. PerformanceCounter::PerformanceCounter (const String& name_,
  7195. int runsPerPrintout,
  7196. const File& loggingFile)
  7197. : name (name_),
  7198. numRuns (0),
  7199. runsPerPrint (runsPerPrintout),
  7200. totalTime (0),
  7201. outputFile (loggingFile)
  7202. {
  7203. if (outputFile != File::nonexistent)
  7204. {
  7205. String s ("**** Counter for \"");
  7206. s << name_ << "\" started at: "
  7207. << Time::getCurrentTime().toString (true, true)
  7208. << "\r\n";
  7209. outputFile.appendText (s, false, false);
  7210. }
  7211. }
  7212. PerformanceCounter::~PerformanceCounter()
  7213. {
  7214. printStatistics();
  7215. }
  7216. void PerformanceCounter::start()
  7217. {
  7218. started = Time::getHighResolutionTicks();
  7219. }
  7220. void PerformanceCounter::stop()
  7221. {
  7222. const int64 now = Time::getHighResolutionTicks();
  7223. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7224. if (++numRuns == runsPerPrint)
  7225. printStatistics();
  7226. }
  7227. void PerformanceCounter::printStatistics()
  7228. {
  7229. if (numRuns > 0)
  7230. {
  7231. String s ("Performance count for \"");
  7232. s << name << "\" - average over " << numRuns << " run(s) = ";
  7233. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7234. if (micros > 10000)
  7235. s << (micros/1000) << " millisecs";
  7236. else
  7237. s << micros << " microsecs";
  7238. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7239. Logger::outputDebugString (s);
  7240. s << "\r\n";
  7241. if (outputFile != File::nonexistent)
  7242. outputFile.appendText (s, false, false);
  7243. numRuns = 0;
  7244. totalTime = 0;
  7245. }
  7246. }
  7247. END_JUCE_NAMESPACE
  7248. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7249. /*** Start of inlined file: juce_Uuid.cpp ***/
  7250. BEGIN_JUCE_NAMESPACE
  7251. Uuid::Uuid()
  7252. {
  7253. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7254. // to make it very very unlikely that two UUIDs will ever be the same..
  7255. static int64 macAddresses[2];
  7256. static bool hasCheckedMacAddresses = false;
  7257. if (! hasCheckedMacAddresses)
  7258. {
  7259. hasCheckedMacAddresses = true;
  7260. SystemStats::getMACAddresses (macAddresses, 2);
  7261. }
  7262. value.asInt64[0] = macAddresses[0];
  7263. value.asInt64[1] = macAddresses[1];
  7264. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7265. // whose seed will carry over between calls to this method.
  7266. Random r (macAddresses[0] ^ macAddresses[1]
  7267. ^ Random::getSystemRandom().nextInt64());
  7268. for (int i = 4; --i >= 0;)
  7269. {
  7270. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7271. value.asInt[i] ^= r.nextInt();
  7272. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7273. }
  7274. }
  7275. Uuid::~Uuid() throw()
  7276. {
  7277. }
  7278. Uuid::Uuid (const Uuid& other)
  7279. : value (other.value)
  7280. {
  7281. }
  7282. Uuid& Uuid::operator= (const Uuid& other)
  7283. {
  7284. value = other.value;
  7285. return *this;
  7286. }
  7287. bool Uuid::operator== (const Uuid& other) const
  7288. {
  7289. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7290. }
  7291. bool Uuid::operator!= (const Uuid& other) const
  7292. {
  7293. return ! operator== (other);
  7294. }
  7295. bool Uuid::isNull() const throw()
  7296. {
  7297. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7298. }
  7299. const String Uuid::toString() const
  7300. {
  7301. return String::toHexString (value.asBytes, 16, 0);
  7302. }
  7303. Uuid::Uuid (const String& uuidString)
  7304. {
  7305. operator= (uuidString);
  7306. }
  7307. Uuid& Uuid::operator= (const String& uuidString)
  7308. {
  7309. int destIndex = 0;
  7310. int i = 0;
  7311. for (;;)
  7312. {
  7313. int byte = 0;
  7314. for (int loop = 2; --loop >= 0;)
  7315. {
  7316. byte <<= 4;
  7317. for (;;)
  7318. {
  7319. const tchar c = uuidString [i++];
  7320. if (c >= T('0') && c <= T('9'))
  7321. {
  7322. byte |= c - T('0');
  7323. break;
  7324. }
  7325. else if (c >= T('a') && c <= T('z'))
  7326. {
  7327. byte |= c - (T('a') - 10);
  7328. break;
  7329. }
  7330. else if (c >= T('A') && c <= T('Z'))
  7331. {
  7332. byte |= c - (T('A') - 10);
  7333. break;
  7334. }
  7335. else if (c == 0)
  7336. {
  7337. while (destIndex < 16)
  7338. value.asBytes [destIndex++] = 0;
  7339. return *this;
  7340. }
  7341. }
  7342. }
  7343. value.asBytes [destIndex++] = (uint8) byte;
  7344. }
  7345. }
  7346. Uuid::Uuid (const uint8* const rawData)
  7347. {
  7348. operator= (rawData);
  7349. }
  7350. Uuid& Uuid::operator= (const uint8* const rawData)
  7351. {
  7352. if (rawData != 0)
  7353. memcpy (value.asBytes, rawData, 16);
  7354. else
  7355. zeromem (value.asBytes, 16);
  7356. return *this;
  7357. }
  7358. END_JUCE_NAMESPACE
  7359. /*** End of inlined file: juce_Uuid.cpp ***/
  7360. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7361. BEGIN_JUCE_NAMESPACE
  7362. class ZipFile::ZipEntryInfo
  7363. {
  7364. public:
  7365. ZipFile::ZipEntry entry;
  7366. int streamOffset;
  7367. int compressedSize;
  7368. bool compressed;
  7369. };
  7370. class ZipFile::ZipInputStream : public InputStream
  7371. {
  7372. public:
  7373. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7374. : file (file_),
  7375. zipEntryInfo (zei),
  7376. pos (0),
  7377. headerSize (0),
  7378. inputStream (0)
  7379. {
  7380. inputStream = file_.inputStream;
  7381. if (file_.inputSource != 0)
  7382. {
  7383. inputStream = file.inputSource->createInputStream();
  7384. }
  7385. else
  7386. {
  7387. #ifdef JUCE_DEBUG
  7388. file_.numOpenStreams++;
  7389. #endif
  7390. }
  7391. char buffer [30];
  7392. if (inputStream != 0
  7393. && inputStream->setPosition (zei.streamOffset)
  7394. && inputStream->read (buffer, 30) == 30
  7395. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7396. {
  7397. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7398. + ByteOrder::littleEndianShort (buffer + 28);
  7399. }
  7400. }
  7401. ~ZipInputStream() throw()
  7402. {
  7403. #ifdef JUCE_DEBUG
  7404. if (inputStream != 0 && inputStream == file.inputStream)
  7405. file.numOpenStreams--;
  7406. #endif
  7407. if (inputStream != file.inputStream)
  7408. delete inputStream;
  7409. }
  7410. int64 getTotalLength() throw()
  7411. {
  7412. return zipEntryInfo.compressedSize;
  7413. }
  7414. int read (void* buffer, int howMany) throw()
  7415. {
  7416. if (headerSize <= 0)
  7417. return 0;
  7418. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7419. if (inputStream == 0)
  7420. return 0;
  7421. int num;
  7422. if (inputStream == file.inputStream)
  7423. {
  7424. const ScopedLock sl (file.lock);
  7425. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7426. num = inputStream->read (buffer, howMany);
  7427. }
  7428. else
  7429. {
  7430. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7431. num = inputStream->read (buffer, howMany);
  7432. }
  7433. pos += num;
  7434. return num;
  7435. }
  7436. bool isExhausted() throw()
  7437. {
  7438. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7439. }
  7440. int64 getPosition() throw()
  7441. {
  7442. return pos;
  7443. }
  7444. bool setPosition (int64 newPos) throw()
  7445. {
  7446. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7447. return true;
  7448. }
  7449. private:
  7450. ZipFile& file;
  7451. ZipEntryInfo zipEntryInfo;
  7452. int64 pos;
  7453. int headerSize;
  7454. InputStream* inputStream;
  7455. ZipInputStream (const ZipInputStream&);
  7456. const ZipInputStream& operator= (const ZipInputStream&);
  7457. };
  7458. ZipFile::ZipFile (InputStream* const source_,
  7459. const bool deleteStreamWhenDestroyed) throw()
  7460. : inputStream (source_)
  7461. #ifdef JUCE_DEBUG
  7462. , numOpenStreams (0)
  7463. #endif
  7464. {
  7465. if (deleteStreamWhenDestroyed)
  7466. streamToDelete = inputStream;
  7467. init();
  7468. }
  7469. ZipFile::ZipFile (const File& file)
  7470. : inputStream (0)
  7471. #ifdef JUCE_DEBUG
  7472. , numOpenStreams (0)
  7473. #endif
  7474. {
  7475. inputSource = new FileInputSource (file);
  7476. init();
  7477. }
  7478. ZipFile::ZipFile (InputSource* const inputSource_)
  7479. : inputStream (0),
  7480. inputSource (inputSource_)
  7481. #ifdef JUCE_DEBUG
  7482. , numOpenStreams (0)
  7483. #endif
  7484. {
  7485. init();
  7486. }
  7487. ZipFile::~ZipFile() throw()
  7488. {
  7489. #ifdef JUCE_DEBUG
  7490. entries.clear();
  7491. // If you hit this assertion, it means you've created a stream to read
  7492. // one of the items in the zipfile, but you've forgotten to delete that
  7493. // stream object before deleting the file.. Streams can't be kept open
  7494. // after the file is deleted because they need to share the input
  7495. // stream that the file uses to read itself.
  7496. jassert (numOpenStreams == 0);
  7497. #endif
  7498. }
  7499. int ZipFile::getNumEntries() const throw()
  7500. {
  7501. return entries.size();
  7502. }
  7503. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7504. {
  7505. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7506. return (zei != 0) ? &(zei->entry)
  7507. : 0;
  7508. }
  7509. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7510. {
  7511. for (int i = 0; i < entries.size(); ++i)
  7512. if (entries.getUnchecked (i)->entry.filename == fileName)
  7513. return i;
  7514. return -1;
  7515. }
  7516. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7517. {
  7518. return getEntry (getIndexOfFileName (fileName));
  7519. }
  7520. InputStream* ZipFile::createStreamForEntry (const int index)
  7521. {
  7522. ZipEntryInfo* const zei = entries[index];
  7523. InputStream* stream = 0;
  7524. if (zei != 0)
  7525. {
  7526. stream = new ZipInputStream (*this, *zei);
  7527. if (zei->compressed)
  7528. {
  7529. stream = new GZIPDecompressorInputStream (stream, true, true,
  7530. zei->entry.uncompressedSize);
  7531. // (much faster to unzip in big blocks using a buffer..)
  7532. stream = new BufferedInputStream (stream, 32768, true);
  7533. }
  7534. }
  7535. return stream;
  7536. }
  7537. class ZipFile::ZipFilenameComparator
  7538. {
  7539. public:
  7540. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7541. {
  7542. return first->entry.filename.compare (second->entry.filename);
  7543. }
  7544. };
  7545. void ZipFile::sortEntriesByFilename()
  7546. {
  7547. ZipFilenameComparator sorter;
  7548. entries.sort (sorter);
  7549. }
  7550. void ZipFile::init()
  7551. {
  7552. ScopedPointer <InputStream> toDelete;
  7553. InputStream* in = inputStream;
  7554. if (inputSource != 0)
  7555. {
  7556. in = inputSource->createInputStream();
  7557. toDelete = in;
  7558. }
  7559. if (in != 0)
  7560. {
  7561. int numEntries = 0;
  7562. int pos = findEndOfZipEntryTable (in, numEntries);
  7563. if (pos >= 0 && pos < in->getTotalLength())
  7564. {
  7565. const int size = (int) (in->getTotalLength() - pos);
  7566. in->setPosition (pos);
  7567. MemoryBlock headerData;
  7568. if (in->readIntoMemoryBlock (headerData, size) == size)
  7569. {
  7570. pos = 0;
  7571. for (int i = 0; i < numEntries; ++i)
  7572. {
  7573. if (pos + 46 > size)
  7574. break;
  7575. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7576. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7577. if (pos + 46 + fileNameLen > size)
  7578. break;
  7579. ZipEntryInfo* const zei = new ZipEntryInfo();
  7580. zei->entry.filename = String::fromUTF8 ((const uint8*) buffer + 46, fileNameLen);
  7581. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7582. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7583. const int year = 1980 + (date >> 9);
  7584. const int month = ((date >> 5) & 15) - 1;
  7585. const int day = date & 31;
  7586. const int hours = time >> 11;
  7587. const int minutes = (time >> 5) & 63;
  7588. const int seconds = (time & 31) << 1;
  7589. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7590. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7591. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7592. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7593. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7594. entries.add (zei);
  7595. pos += 46 + fileNameLen
  7596. + ByteOrder::littleEndianShort (buffer + 30)
  7597. + ByteOrder::littleEndianShort (buffer + 32);
  7598. }
  7599. }
  7600. }
  7601. }
  7602. }
  7603. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7604. {
  7605. BufferedInputStream in (input, 8192, false);
  7606. in.setPosition (in.getTotalLength());
  7607. int64 pos = in.getPosition();
  7608. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7609. char buffer [32];
  7610. zeromem (buffer, sizeof (buffer));
  7611. while (pos > lowestPos)
  7612. {
  7613. in.setPosition (pos - 22);
  7614. pos = in.getPosition();
  7615. memcpy (buffer + 22, buffer, 4);
  7616. if (in.read (buffer, 22) != 22)
  7617. return 0;
  7618. for (int i = 0; i < 22; ++i)
  7619. {
  7620. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7621. {
  7622. in.setPosition (pos + i);
  7623. in.read (buffer, 22);
  7624. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7625. return ByteOrder::littleEndianInt (buffer + 16);
  7626. }
  7627. }
  7628. }
  7629. return 0;
  7630. }
  7631. void ZipFile::uncompressTo (const File& targetDirectory,
  7632. const bool shouldOverwriteFiles)
  7633. {
  7634. for (int i = 0; i < entries.size(); ++i)
  7635. {
  7636. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7637. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7638. if (zei.filename.endsWithChar (T('/')))
  7639. {
  7640. targetFile.createDirectory(); // (entry is a directory, not a file)
  7641. }
  7642. else
  7643. {
  7644. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7645. if (in != 0)
  7646. {
  7647. if (shouldOverwriteFiles)
  7648. targetFile.deleteFile();
  7649. if ((! targetFile.exists())
  7650. && targetFile.getParentDirectory().createDirectory())
  7651. {
  7652. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7653. if (out != 0)
  7654. {
  7655. out->writeFromInputStream (*in, -1);
  7656. out = 0;
  7657. targetFile.setCreationTime (zei.fileTime);
  7658. targetFile.setLastModificationTime (zei.fileTime);
  7659. targetFile.setLastAccessTime (zei.fileTime);
  7660. }
  7661. }
  7662. }
  7663. }
  7664. }
  7665. }
  7666. END_JUCE_NAMESPACE
  7667. /*** End of inlined file: juce_ZipFile.cpp ***/
  7668. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7669. #ifdef _MSC_VER
  7670. #pragma warning (disable: 4514 4996)
  7671. #pragma warning (push)
  7672. #endif
  7673. #include <cwctype>
  7674. #include <cctype>
  7675. #include <ctime>
  7676. #ifdef _MSC_VER
  7677. #pragma warning (pop)
  7678. #endif
  7679. BEGIN_JUCE_NAMESPACE
  7680. int CharacterFunctions::length (const char* const s) throw()
  7681. {
  7682. return (int) strlen (s);
  7683. }
  7684. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7685. {
  7686. return (int) wcslen (s);
  7687. }
  7688. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7689. {
  7690. strncpy (dest, src, maxChars);
  7691. }
  7692. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7693. {
  7694. wcsncpy (dest, src, maxChars);
  7695. }
  7696. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7697. {
  7698. mbstowcs (dest, src, maxChars);
  7699. }
  7700. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7701. {
  7702. wcstombs (dest, src, maxChars);
  7703. }
  7704. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7705. {
  7706. return (int) wcstombs (0, src, 0);
  7707. }
  7708. void CharacterFunctions::append (char* dest, const char* src) throw()
  7709. {
  7710. strcat (dest, src);
  7711. }
  7712. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7713. {
  7714. wcscat (dest, src);
  7715. }
  7716. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7717. {
  7718. return strcmp (s1, s2);
  7719. }
  7720. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7721. {
  7722. jassert (s1 != 0 && s2 != 0);
  7723. return wcscmp (s1, s2);
  7724. }
  7725. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7726. {
  7727. jassert (s1 != 0 && s2 != 0);
  7728. return strncmp (s1, s2, maxChars);
  7729. }
  7730. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7731. {
  7732. jassert (s1 != 0 && s2 != 0);
  7733. return wcsncmp (s1, s2, maxChars);
  7734. }
  7735. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7736. {
  7737. jassert (s1 != 0 && s2 != 0);
  7738. #if JUCE_WIN32
  7739. return stricmp (s1, s2);
  7740. #else
  7741. return strcasecmp (s1, s2);
  7742. #endif
  7743. }
  7744. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7745. {
  7746. jassert (s1 != 0 && s2 != 0);
  7747. #if JUCE_WIN32
  7748. return _wcsicmp (s1, s2);
  7749. #else
  7750. for (;;)
  7751. {
  7752. if (*s1 != *s2)
  7753. {
  7754. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7755. if (diff != 0)
  7756. return diff < 0 ? -1 : 1;
  7757. }
  7758. else if (*s1 == 0)
  7759. break;
  7760. ++s1;
  7761. ++s2;
  7762. }
  7763. return 0;
  7764. #endif
  7765. }
  7766. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7767. {
  7768. jassert (s1 != 0 && s2 != 0);
  7769. #if JUCE_WIN32
  7770. return strnicmp (s1, s2, maxChars);
  7771. #else
  7772. return strncasecmp (s1, s2, maxChars);
  7773. #endif
  7774. }
  7775. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7776. {
  7777. jassert (s1 != 0 && s2 != 0);
  7778. #if JUCE_WIN32
  7779. return _wcsnicmp (s1, s2, maxChars);
  7780. #else
  7781. while (--maxChars >= 0)
  7782. {
  7783. if (*s1 != *s2)
  7784. {
  7785. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7786. if (diff != 0)
  7787. return diff < 0 ? -1 : 1;
  7788. }
  7789. else if (*s1 == 0)
  7790. break;
  7791. ++s1;
  7792. ++s2;
  7793. }
  7794. return 0;
  7795. #endif
  7796. }
  7797. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7798. {
  7799. return strstr (haystack, needle);
  7800. }
  7801. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7802. {
  7803. return wcsstr (haystack, needle);
  7804. }
  7805. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7806. {
  7807. if (haystack != 0)
  7808. {
  7809. int i = 0;
  7810. if (ignoreCase)
  7811. {
  7812. const char n1 = toLowerCase (needle);
  7813. const char n2 = toUpperCase (needle);
  7814. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7815. {
  7816. while (haystack[i] != 0)
  7817. {
  7818. if (haystack[i] == n1 || haystack[i] == n2)
  7819. return i;
  7820. ++i;
  7821. }
  7822. return -1;
  7823. }
  7824. jassert (n1 == needle);
  7825. }
  7826. while (haystack[i] != 0)
  7827. {
  7828. if (haystack[i] == needle)
  7829. return i;
  7830. ++i;
  7831. }
  7832. }
  7833. return -1;
  7834. }
  7835. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7836. {
  7837. if (haystack != 0)
  7838. {
  7839. int i = 0;
  7840. if (ignoreCase)
  7841. {
  7842. const juce_wchar n1 = toLowerCase (needle);
  7843. const juce_wchar n2 = toUpperCase (needle);
  7844. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7845. {
  7846. while (haystack[i] != 0)
  7847. {
  7848. if (haystack[i] == n1 || haystack[i] == n2)
  7849. return i;
  7850. ++i;
  7851. }
  7852. return -1;
  7853. }
  7854. jassert (n1 == needle);
  7855. }
  7856. while (haystack[i] != 0)
  7857. {
  7858. if (haystack[i] == needle)
  7859. return i;
  7860. ++i;
  7861. }
  7862. }
  7863. return -1;
  7864. }
  7865. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7866. {
  7867. jassert (haystack != 0);
  7868. int i = 0;
  7869. while (haystack[i] != 0)
  7870. {
  7871. if (haystack[i] == needle)
  7872. return i;
  7873. ++i;
  7874. }
  7875. return -1;
  7876. }
  7877. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7878. {
  7879. jassert (haystack != 0);
  7880. int i = 0;
  7881. while (haystack[i] != 0)
  7882. {
  7883. if (haystack[i] == needle)
  7884. return i;
  7885. ++i;
  7886. }
  7887. return -1;
  7888. }
  7889. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7890. {
  7891. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7892. }
  7893. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7894. {
  7895. if (allowedChars == 0)
  7896. return 0;
  7897. int i = 0;
  7898. for (;;)
  7899. {
  7900. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7901. break;
  7902. ++i;
  7903. }
  7904. return i;
  7905. }
  7906. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7907. {
  7908. return (int) strftime (dest, maxChars, format, tm);
  7909. }
  7910. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7911. {
  7912. return (int) wcsftime (dest, maxChars, format, tm);
  7913. }
  7914. int CharacterFunctions::getIntValue (const char* const s) throw()
  7915. {
  7916. return atoi (s);
  7917. }
  7918. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7919. {
  7920. #if JUCE_WIN32
  7921. return _wtoi (s);
  7922. #else
  7923. int v = 0;
  7924. while (isWhitespace (*s))
  7925. ++s;
  7926. const bool isNeg = *s == T('-');
  7927. if (isNeg)
  7928. ++s;
  7929. for (;;)
  7930. {
  7931. const wchar_t c = *s++;
  7932. if (c >= T('0') && c <= T('9'))
  7933. v = v * 10 + (int) (c - T('0'));
  7934. else
  7935. break;
  7936. }
  7937. return isNeg ? -v : v;
  7938. #endif
  7939. }
  7940. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7941. {
  7942. #if JUCE_LINUX
  7943. return atoll (s);
  7944. #elif defined (JUCE_WIN32)
  7945. return _atoi64 (s);
  7946. #else
  7947. int64 v = 0;
  7948. while (isWhitespace (*s))
  7949. ++s;
  7950. const bool isNeg = *s == T('-');
  7951. if (isNeg)
  7952. ++s;
  7953. for (;;)
  7954. {
  7955. const char c = *s++;
  7956. if (c >= '0' && c <= '9')
  7957. v = v * 10 + (int64) (c - '0');
  7958. else
  7959. break;
  7960. }
  7961. return isNeg ? -v : v;
  7962. #endif
  7963. }
  7964. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7965. {
  7966. #if JUCE_WIN32
  7967. return _wtoi64 (s);
  7968. #else
  7969. int64 v = 0;
  7970. while (isWhitespace (*s))
  7971. ++s;
  7972. const bool isNeg = *s == T('-');
  7973. if (isNeg)
  7974. ++s;
  7975. for (;;)
  7976. {
  7977. const juce_wchar c = *s++;
  7978. if (c >= T('0') && c <= T('9'))
  7979. v = v * 10 + (int64) (c - T('0'));
  7980. else
  7981. break;
  7982. }
  7983. return isNeg ? -v : v;
  7984. #endif
  7985. }
  7986. static double juce_mulexp10 (const double value, int exponent) throw()
  7987. {
  7988. if (exponent == 0)
  7989. return value;
  7990. if (value == 0)
  7991. return 0;
  7992. const bool negative = (exponent < 0);
  7993. if (negative)
  7994. exponent = -exponent;
  7995. double result = 1.0, power = 10.0;
  7996. for (int bit = 1; exponent != 0; bit <<= 1)
  7997. {
  7998. if ((exponent & bit) != 0)
  7999. {
  8000. exponent ^= bit;
  8001. result *= power;
  8002. if (exponent == 0)
  8003. break;
  8004. }
  8005. power *= power;
  8006. }
  8007. return negative ? (value / result) : (value * result);
  8008. }
  8009. template <class CharType>
  8010. double juce_atof (const CharType* const original) throw()
  8011. {
  8012. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  8013. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  8014. int exponent = 0, decPointIndex = 0, digit = 0;
  8015. int lastDigit = 0, numSignificantDigits = 0;
  8016. bool isNegative = false, digitsFound = false;
  8017. const int maxSignificantDigits = 15 + 2;
  8018. const CharType* s = original;
  8019. while (CharacterFunctions::isWhitespace (*s))
  8020. ++s;
  8021. switch (*s)
  8022. {
  8023. case '-': isNegative = true; // fall-through..
  8024. case '+': ++s;
  8025. }
  8026. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  8027. return atof (String (original)); // Let the c library deal with NAN and INF
  8028. for (;;)
  8029. {
  8030. if (CharacterFunctions::isDigit (*s))
  8031. {
  8032. lastDigit = digit;
  8033. digit = *s++ - '0';
  8034. digitsFound = true;
  8035. if (decPointIndex != 0)
  8036. exponentAdjustment[1]++;
  8037. if (numSignificantDigits == 0 && digit == 0)
  8038. continue;
  8039. if (++numSignificantDigits > maxSignificantDigits)
  8040. {
  8041. if (digit > 5)
  8042. ++accumulator [decPointIndex];
  8043. else if (digit == 5 && (lastDigit & 1) != 0)
  8044. ++accumulator [decPointIndex];
  8045. if (decPointIndex > 0)
  8046. exponentAdjustment[1]--;
  8047. else
  8048. exponentAdjustment[0]++;
  8049. while (CharacterFunctions::isDigit (*s))
  8050. {
  8051. ++s;
  8052. if (decPointIndex == 0)
  8053. exponentAdjustment[0]++;
  8054. }
  8055. }
  8056. else
  8057. {
  8058. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  8059. if (accumulator [decPointIndex] > maxAccumulatorValue)
  8060. {
  8061. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  8062. + accumulator [decPointIndex];
  8063. accumulator [decPointIndex] = 0;
  8064. exponentAccumulator [decPointIndex] = 0;
  8065. }
  8066. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  8067. exponentAccumulator [decPointIndex]++;
  8068. }
  8069. }
  8070. else if (decPointIndex == 0 && *s == '.')
  8071. {
  8072. ++s;
  8073. decPointIndex = 1;
  8074. if (numSignificantDigits > maxSignificantDigits)
  8075. {
  8076. while (CharacterFunctions::isDigit (*s))
  8077. ++s;
  8078. break;
  8079. }
  8080. }
  8081. else
  8082. {
  8083. break;
  8084. }
  8085. }
  8086. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  8087. if (decPointIndex != 0)
  8088. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  8089. if ((*s == 'e' || *s == 'E') && digitsFound)
  8090. {
  8091. bool negativeExponent = false;
  8092. switch (*++s)
  8093. {
  8094. case '-': negativeExponent = true; // fall-through..
  8095. case '+': ++s;
  8096. }
  8097. while (CharacterFunctions::isDigit (*s))
  8098. exponent = (exponent * 10) + (*s++ - '0');
  8099. if (negativeExponent)
  8100. exponent = -exponent;
  8101. }
  8102. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  8103. if (decPointIndex != 0)
  8104. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  8105. return isNegative ? -r : r;
  8106. }
  8107. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  8108. {
  8109. return juce_atof <char> (s);
  8110. }
  8111. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  8112. {
  8113. return juce_atof <juce_wchar> (s);
  8114. }
  8115. char CharacterFunctions::toUpperCase (const char character) throw()
  8116. {
  8117. return (char) toupper (character);
  8118. }
  8119. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  8120. {
  8121. return towupper (character);
  8122. }
  8123. void CharacterFunctions::toUpperCase (char* s) throw()
  8124. {
  8125. #if JUCE_WIN32
  8126. strupr (s);
  8127. #else
  8128. while (*s != 0)
  8129. {
  8130. *s = toUpperCase (*s);
  8131. ++s;
  8132. }
  8133. #endif
  8134. }
  8135. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8136. {
  8137. #if JUCE_WIN32
  8138. _wcsupr (s);
  8139. #else
  8140. while (*s != 0)
  8141. {
  8142. *s = toUpperCase (*s);
  8143. ++s;
  8144. }
  8145. #endif
  8146. }
  8147. bool CharacterFunctions::isUpperCase (const char character) throw()
  8148. {
  8149. return isupper (character) != 0;
  8150. }
  8151. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8152. {
  8153. #if JUCE_WIN32
  8154. return iswupper (character) != 0;
  8155. #else
  8156. return toLowerCase (character) != character;
  8157. #endif
  8158. }
  8159. char CharacterFunctions::toLowerCase (const char character) throw()
  8160. {
  8161. return (char) tolower (character);
  8162. }
  8163. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8164. {
  8165. return towlower (character);
  8166. }
  8167. void CharacterFunctions::toLowerCase (char* s) throw()
  8168. {
  8169. #if JUCE_WIN32
  8170. strlwr (s);
  8171. #else
  8172. while (*s != 0)
  8173. {
  8174. *s = toLowerCase (*s);
  8175. ++s;
  8176. }
  8177. #endif
  8178. }
  8179. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8180. {
  8181. #if JUCE_WIN32
  8182. _wcslwr (s);
  8183. #else
  8184. while (*s != 0)
  8185. {
  8186. *s = toLowerCase (*s);
  8187. ++s;
  8188. }
  8189. #endif
  8190. }
  8191. bool CharacterFunctions::isLowerCase (const char character) throw()
  8192. {
  8193. return islower (character) != 0;
  8194. }
  8195. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8196. {
  8197. #if JUCE_WIN32
  8198. return iswlower (character) != 0;
  8199. #else
  8200. return toUpperCase (character) != character;
  8201. #endif
  8202. }
  8203. bool CharacterFunctions::isWhitespace (const char character) throw()
  8204. {
  8205. return character == T(' ') || (character <= 13 && character >= 9);
  8206. }
  8207. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8208. {
  8209. return iswspace (character) != 0;
  8210. }
  8211. bool CharacterFunctions::isDigit (const char character) throw()
  8212. {
  8213. return (character >= '0' && character <= '9');
  8214. }
  8215. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8216. {
  8217. return iswdigit (character) != 0;
  8218. }
  8219. bool CharacterFunctions::isLetter (const char character) throw()
  8220. {
  8221. return (character >= 'a' && character <= 'z')
  8222. || (character >= 'A' && character <= 'Z');
  8223. }
  8224. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8225. {
  8226. return iswalpha (character) != 0;
  8227. }
  8228. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8229. {
  8230. return (character >= 'a' && character <= 'z')
  8231. || (character >= 'A' && character <= 'Z')
  8232. || (character >= '0' && character <= '9');
  8233. }
  8234. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8235. {
  8236. return iswalnum (character) != 0;
  8237. }
  8238. int CharacterFunctions::getHexDigitValue (const tchar digit) throw()
  8239. {
  8240. if (digit >= T('0') && digit <= T('9'))
  8241. return digit - T('0');
  8242. else if (digit >= T('a') && digit <= T('f'))
  8243. return digit - (T('a') - 10);
  8244. else if (digit >= T('A') && digit <= T('F'))
  8245. return digit - (T('A') - 10);
  8246. return -1;
  8247. }
  8248. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8249. {
  8250. va_list list;
  8251. va_start (list, format);
  8252. return vprintf (dest, maxLength, format, list);
  8253. }
  8254. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8255. {
  8256. va_list list;
  8257. va_start (list, format);
  8258. return vprintf (dest, maxLength, format, list);
  8259. }
  8260. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8261. {
  8262. #if JUCE_WIN32
  8263. return (int) _vsnprintf (dest, maxLength, format, args);
  8264. #else
  8265. return (int) vsnprintf (dest, maxLength, format, args);
  8266. #endif
  8267. }
  8268. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8269. {
  8270. #if defined (JUCE_WIN32)
  8271. return (int) _vsnwprintf (dest, maxLength, format, args);
  8272. #else
  8273. return (int) vswprintf (dest, maxLength, format, args);
  8274. #endif
  8275. }
  8276. END_JUCE_NAMESPACE
  8277. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8278. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8279. BEGIN_JUCE_NAMESPACE
  8280. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8281. {
  8282. loadFromText (fileContents);
  8283. }
  8284. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8285. {
  8286. loadFromText (fileToLoad.loadFileAsString());
  8287. }
  8288. LocalisedStrings::~LocalisedStrings()
  8289. {
  8290. }
  8291. const String LocalisedStrings::translate (const String& text) const
  8292. {
  8293. return translations.getValue (text, text);
  8294. }
  8295. static int findCloseQuote (const String& text, int startPos)
  8296. {
  8297. tchar lastChar = 0;
  8298. for (;;)
  8299. {
  8300. const tchar c = text [startPos];
  8301. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8302. break;
  8303. lastChar = c;
  8304. ++startPos;
  8305. }
  8306. return startPos;
  8307. }
  8308. static const String unescapeString (const String& s)
  8309. {
  8310. return s.replace (T("\\\""), T("\""))
  8311. .replace (T("\\\'"), T("\'"))
  8312. .replace (T("\\t"), T("\t"))
  8313. .replace (T("\\r"), T("\r"))
  8314. .replace (T("\\n"), T("\n"));
  8315. }
  8316. void LocalisedStrings::loadFromText (const String& fileContents)
  8317. {
  8318. StringArray lines;
  8319. lines.addLines (fileContents);
  8320. for (int i = 0; i < lines.size(); ++i)
  8321. {
  8322. String line (lines[i].trim());
  8323. if (line.startsWithChar (T('"')))
  8324. {
  8325. int closeQuote = findCloseQuote (line, 1);
  8326. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8327. if (originalText.isNotEmpty())
  8328. {
  8329. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8330. closeQuote = findCloseQuote (line, openingQuote + 1);
  8331. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8332. if (newText.isNotEmpty())
  8333. translations.set (originalText, newText);
  8334. }
  8335. }
  8336. else if (line.startsWithIgnoreCase (T("language:")))
  8337. {
  8338. languageName = line.substring (9).trim();
  8339. }
  8340. else if (line.startsWithIgnoreCase (T("countries:")))
  8341. {
  8342. countryCodes.addTokens (line.substring (10).trim(), true);
  8343. countryCodes.trim();
  8344. countryCodes.removeEmptyStrings();
  8345. }
  8346. }
  8347. }
  8348. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8349. {
  8350. translations.setIgnoresCase (shouldIgnoreCase);
  8351. }
  8352. static CriticalSection currentMappingsLock;
  8353. static LocalisedStrings* currentMappings = 0;
  8354. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8355. {
  8356. const ScopedLock sl (currentMappingsLock);
  8357. delete currentMappings;
  8358. currentMappings = newTranslations;
  8359. }
  8360. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8361. {
  8362. return currentMappings;
  8363. }
  8364. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8365. {
  8366. const ScopedLock sl (currentMappingsLock);
  8367. if (currentMappings != 0)
  8368. return currentMappings->translate (text);
  8369. return text;
  8370. }
  8371. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8372. {
  8373. return translateWithCurrentMappings (String (text));
  8374. }
  8375. END_JUCE_NAMESPACE
  8376. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8377. /*** Start of inlined file: juce_String.cpp ***/
  8378. #ifdef _MSC_VER
  8379. #pragma warning (disable: 4514)
  8380. #pragma warning (push)
  8381. #endif
  8382. #include <locale>
  8383. #if JUCE_MSVC
  8384. #include <float.h>
  8385. #endif
  8386. BEGIN_JUCE_NAMESPACE
  8387. #ifdef _MSC_VER
  8388. #pragma warning (pop)
  8389. #endif
  8390. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8391. static const int safeEmptyStringRefCount = 0x3fffffff;
  8392. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8393. static tchar decimalPoint = T('.');
  8394. void juce_initialiseStrings()
  8395. {
  8396. decimalPoint = String::fromUTF8 ((const uint8*) localeconv()->decimal_point) [0];
  8397. }
  8398. void String::createInternal (const int numChars) throw()
  8399. {
  8400. jassert (numChars > 0);
  8401. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8402. + numChars * sizeof (tchar));
  8403. text->refCount = 1;
  8404. text->allocatedNumChars = numChars;
  8405. text->text[0] = 0;
  8406. }
  8407. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8408. {
  8409. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8410. const int numChars = (int) (textEnd - t);
  8411. createInternal (numChars - 1);
  8412. memcpy (text->text, t, numChars * sizeof (tchar));
  8413. }
  8414. void String::appendInternal (const tchar* const newText,
  8415. const int numExtraChars) throw()
  8416. {
  8417. if (numExtraChars > 0)
  8418. {
  8419. const int oldLen = CharacterFunctions::length (text->text);
  8420. const int newTotalLen = oldLen + numExtraChars;
  8421. if (text->refCount > 1)
  8422. {
  8423. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8424. InternalRefCountedStringHolder* const newTextHolder
  8425. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8426. + newTotalLen * sizeof (tchar));
  8427. newTextHolder->refCount = 1;
  8428. newTextHolder->allocatedNumChars = newTotalLen;
  8429. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8430. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8431. InternalRefCountedStringHolder* const old = text;
  8432. text = newTextHolder;
  8433. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8434. juce_free (old);
  8435. }
  8436. else
  8437. {
  8438. // no other strings using it, so just expand it if needed..
  8439. if (newTotalLen > text->allocatedNumChars)
  8440. {
  8441. text = (InternalRefCountedStringHolder*)
  8442. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8443. + newTotalLen * sizeof (tchar));
  8444. text->allocatedNumChars = newTotalLen;
  8445. }
  8446. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8447. }
  8448. text->text [newTotalLen] = 0;
  8449. }
  8450. }
  8451. void String::dupeInternalIfMultiplyReferenced() throw()
  8452. {
  8453. if (text->refCount > 1)
  8454. {
  8455. InternalRefCountedStringHolder* const old = text;
  8456. const int len = old->allocatedNumChars;
  8457. InternalRefCountedStringHolder* const newTextHolder
  8458. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8459. + len * sizeof (tchar));
  8460. newTextHolder->refCount = 1;
  8461. newTextHolder->allocatedNumChars = len;
  8462. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8463. text = newTextHolder;
  8464. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8465. juce_free (old);
  8466. }
  8467. }
  8468. const String String::empty;
  8469. String::String() throw()
  8470. : text (&emptyString)
  8471. {
  8472. }
  8473. String::String (const String& other) throw()
  8474. : text (other.text)
  8475. {
  8476. Atomic::increment (text->refCount);
  8477. }
  8478. String::String (const int numChars,
  8479. const int /*dummyVariable*/) throw()
  8480. {
  8481. createInternal (numChars);
  8482. }
  8483. String::String (const char* const t) throw()
  8484. {
  8485. if (t != 0 && *t != 0)
  8486. {
  8487. const int len = CharacterFunctions::length (t);
  8488. createInternal (len);
  8489. #if JUCE_STRINGS_ARE_UNICODE
  8490. CharacterFunctions::copy (text->text, t, len + 1);
  8491. #else
  8492. memcpy (text->text, t, len + 1);
  8493. #endif
  8494. }
  8495. else
  8496. {
  8497. text = &emptyString;
  8498. emptyString.refCount = safeEmptyStringRefCount;
  8499. }
  8500. }
  8501. String::String (const juce_wchar* const t) throw()
  8502. {
  8503. if (t != 0 && *t != 0)
  8504. {
  8505. #if JUCE_STRINGS_ARE_UNICODE
  8506. const int len = CharacterFunctions::length (t);
  8507. createInternal (len);
  8508. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8509. #else
  8510. const int len = CharacterFunctions::bytesRequiredForCopy (t);
  8511. createInternal (len);
  8512. CharacterFunctions::copy (text->text, t, len + 1);
  8513. #endif
  8514. }
  8515. else
  8516. {
  8517. text = &emptyString;
  8518. emptyString.refCount = safeEmptyStringRefCount;
  8519. }
  8520. }
  8521. String::String (const char* const t,
  8522. const size_t maxChars) throw()
  8523. {
  8524. int i;
  8525. for (i = 0; (size_t) i < maxChars; ++i)
  8526. if (t[i] == 0)
  8527. break;
  8528. if (i > 0)
  8529. {
  8530. createInternal (i);
  8531. #if JUCE_STRINGS_ARE_UNICODE
  8532. CharacterFunctions::copy (text->text, t, i);
  8533. #else
  8534. memcpy (text->text, t, i);
  8535. #endif
  8536. text->text [i] = 0;
  8537. }
  8538. else
  8539. {
  8540. text = &emptyString;
  8541. emptyString.refCount = safeEmptyStringRefCount;
  8542. }
  8543. }
  8544. String::String (const juce_wchar* const t,
  8545. const size_t maxChars) throw()
  8546. {
  8547. int i;
  8548. for (i = 0; (size_t) i < maxChars; ++i)
  8549. if (t[i] == 0)
  8550. break;
  8551. if (i > 0)
  8552. {
  8553. createInternal (i);
  8554. #if JUCE_STRINGS_ARE_UNICODE
  8555. memcpy (text->text, t, i * sizeof (tchar));
  8556. #else
  8557. CharacterFunctions::copy (text->text, t, i);
  8558. #endif
  8559. text->text [i] = 0;
  8560. }
  8561. else
  8562. {
  8563. text = &emptyString;
  8564. emptyString.refCount = safeEmptyStringRefCount;
  8565. }
  8566. }
  8567. const String String::charToString (const tchar character) throw()
  8568. {
  8569. tchar temp[2];
  8570. temp[0] = character;
  8571. temp[1] = 0;
  8572. return String (temp);
  8573. }
  8574. // pass in a pointer to the END of a buffer..
  8575. static tchar* int64ToCharString (tchar* t, const int64 n) throw()
  8576. {
  8577. *--t = 0;
  8578. int64 v = (n >= 0) ? n : -n;
  8579. do
  8580. {
  8581. *--t = (tchar) (T('0') + (int) (v % 10));
  8582. v /= 10;
  8583. } while (v > 0);
  8584. if (n < 0)
  8585. *--t = T('-');
  8586. return t;
  8587. }
  8588. static tchar* intToCharString (tchar* t, const int n) throw()
  8589. {
  8590. if (n == (int) 0x80000000) // (would cause an overflow)
  8591. return int64ToCharString (t, n);
  8592. *--t = 0;
  8593. int v = abs (n);
  8594. do
  8595. {
  8596. *--t = (tchar) (T('0') + (v % 10));
  8597. v /= 10;
  8598. } while (v > 0);
  8599. if (n < 0)
  8600. *--t = T('-');
  8601. return t;
  8602. }
  8603. static tchar* uintToCharString (tchar* t, unsigned int v) throw()
  8604. {
  8605. *--t = 0;
  8606. do
  8607. {
  8608. *--t = (tchar) (T('0') + (v % 10));
  8609. v /= 10;
  8610. } while (v > 0);
  8611. return t;
  8612. }
  8613. String::String (const int number) throw()
  8614. {
  8615. tchar buffer [16];
  8616. tchar* const end = buffer + 16;
  8617. createInternal (intToCharString (end, number), end);
  8618. }
  8619. String::String (const unsigned int number) throw()
  8620. {
  8621. tchar buffer [16];
  8622. tchar* const end = buffer + 16;
  8623. createInternal (uintToCharString (end, number), end);
  8624. }
  8625. String::String (const short number) throw()
  8626. {
  8627. tchar buffer [16];
  8628. tchar* const end = buffer + 16;
  8629. createInternal (intToCharString (end, (int) number), end);
  8630. }
  8631. String::String (const unsigned short number) throw()
  8632. {
  8633. tchar buffer [16];
  8634. tchar* const end = buffer + 16;
  8635. createInternal (uintToCharString (end, (unsigned int) number), end);
  8636. }
  8637. String::String (const int64 number) throw()
  8638. {
  8639. tchar buffer [32];
  8640. tchar* const end = buffer + 32;
  8641. createInternal (int64ToCharString (end, number), end);
  8642. }
  8643. String::String (const uint64 number) throw()
  8644. {
  8645. tchar buffer [32];
  8646. tchar* const end = buffer + 32;
  8647. tchar* t = end;
  8648. *--t = 0;
  8649. int64 v = number;
  8650. do
  8651. {
  8652. *--t = (tchar) (T('0') + (int) (v % 10));
  8653. v /= 10;
  8654. } while (v > 0);
  8655. createInternal (t, end);
  8656. }
  8657. // a double-to-string routine that actually uses the number of dec. places you asked for
  8658. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8659. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8660. {
  8661. const int bufSize = 80;
  8662. tchar buffer [bufSize];
  8663. int len;
  8664. tchar* t;
  8665. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8666. {
  8667. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8668. t = buffer + bufSize;
  8669. *--t = (tchar) 0;
  8670. while (numDecPlaces >= 0 || v > 0)
  8671. {
  8672. if (numDecPlaces == 0)
  8673. *--t = decimalPoint;
  8674. *--t = (tchar) (T('0') + (v % 10));
  8675. v /= 10;
  8676. --numDecPlaces;
  8677. }
  8678. if (n < 0)
  8679. *--t = T('-');
  8680. len = (int) ((buffer + bufSize) - t);
  8681. }
  8682. else
  8683. {
  8684. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8685. t = buffer;
  8686. }
  8687. if (len > 1)
  8688. {
  8689. jassert (len < numElementsInArray (buffer));
  8690. createInternal (len - 1);
  8691. memcpy (text->text, t, len * sizeof (tchar));
  8692. }
  8693. else
  8694. {
  8695. jassert (*t == 0);
  8696. text = &emptyString;
  8697. emptyString.refCount = safeEmptyStringRefCount;
  8698. }
  8699. }
  8700. String::String (const float number,
  8701. const int numberOfDecimalPlaces) throw()
  8702. {
  8703. doubleToStringWithDecPlaces ((double) number,
  8704. numberOfDecimalPlaces);
  8705. }
  8706. String::String (const double number,
  8707. const int numberOfDecimalPlaces) throw()
  8708. {
  8709. doubleToStringWithDecPlaces (number,
  8710. numberOfDecimalPlaces);
  8711. }
  8712. String::~String() throw()
  8713. {
  8714. emptyString.refCount = safeEmptyStringRefCount;
  8715. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8716. juce_free (text);
  8717. }
  8718. void String::preallocateStorage (const size_t numChars) throw()
  8719. {
  8720. if (numChars > (size_t) text->allocatedNumChars)
  8721. {
  8722. dupeInternalIfMultiplyReferenced();
  8723. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8724. + numChars * sizeof (tchar));
  8725. text->allocatedNumChars = (int) numChars;
  8726. }
  8727. }
  8728. #if JUCE_STRINGS_ARE_UNICODE
  8729. String::operator const char*() const throw()
  8730. {
  8731. if (isEmpty())
  8732. {
  8733. return (const char*) emptyCharString;
  8734. }
  8735. else
  8736. {
  8737. String* const mutableThis = const_cast <String*> (this);
  8738. mutableThis->dupeInternalIfMultiplyReferenced();
  8739. int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1;
  8740. mutableThis->text = (InternalRefCountedStringHolder*)
  8741. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8742. + (len * sizeof (juce_wchar) + len));
  8743. char* otherCopy = (char*) (text->text + len);
  8744. --len;
  8745. CharacterFunctions::copy (otherCopy, text->text, len);
  8746. otherCopy [len] = 0;
  8747. return otherCopy;
  8748. }
  8749. }
  8750. #else
  8751. String::operator const juce_wchar*() const throw()
  8752. {
  8753. if (isEmpty())
  8754. {
  8755. return (const juce_wchar*) emptyCharString;
  8756. }
  8757. else
  8758. {
  8759. String* const mutableThis = const_cast <String*> (this);
  8760. mutableThis->dupeInternalIfMultiplyReferenced();
  8761. int len = CharacterFunctions::length (text->text) + 1;
  8762. mutableThis->text = (InternalRefCountedStringHolder*)
  8763. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8764. + (len * sizeof (juce_wchar) + len));
  8765. juce_wchar* otherCopy = (juce_wchar*) (text->text + len);
  8766. --len;
  8767. CharacterFunctions::copy (otherCopy, text->text, len);
  8768. otherCopy [len] = 0;
  8769. return otherCopy;
  8770. }
  8771. }
  8772. #endif
  8773. void String::copyToBuffer (char* const destBuffer,
  8774. const int bufferSizeBytes) const throw()
  8775. {
  8776. #if JUCE_STRINGS_ARE_UNICODE
  8777. const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text));
  8778. CharacterFunctions::copy (destBuffer, text->text, len);
  8779. #else
  8780. const int len = jmin (bufferSizeBytes, length());
  8781. memcpy (destBuffer, text->text, len * sizeof (tchar));
  8782. #endif
  8783. destBuffer [len] = 0;
  8784. }
  8785. void String::copyToBuffer (juce_wchar* const destBuffer,
  8786. const int maxCharsToCopy) const throw()
  8787. {
  8788. const int len = jmin (maxCharsToCopy, length());
  8789. #if JUCE_STRINGS_ARE_UNICODE
  8790. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  8791. #else
  8792. CharacterFunctions::copy (destBuffer, text->text, len);
  8793. #endif
  8794. destBuffer [len] = 0;
  8795. }
  8796. int String::length() const throw()
  8797. {
  8798. return CharacterFunctions::length (text->text);
  8799. }
  8800. int String::hashCode() const throw()
  8801. {
  8802. const tchar* t = text->text;
  8803. int result = 0;
  8804. while (*t != (tchar) 0)
  8805. result = 31 * result + *t++;
  8806. return result;
  8807. }
  8808. int64 String::hashCode64() const throw()
  8809. {
  8810. const tchar* t = text->text;
  8811. int64 result = 0;
  8812. while (*t != (tchar) 0)
  8813. result = 101 * result + *t++;
  8814. return result;
  8815. }
  8816. const String& String::operator= (const tchar* const otherText) throw()
  8817. {
  8818. operator= (String (otherText));
  8819. return *this;
  8820. }
  8821. const String& String::operator= (const String& other) throw()
  8822. {
  8823. if (this != &other)
  8824. {
  8825. InternalRefCountedStringHolder* newText = other.text;
  8826. Atomic::increment (newText->refCount);
  8827. InternalRefCountedStringHolder* oldText
  8828. = (InternalRefCountedStringHolder*) Atomic::swapPointers ((void* volatile*) &text, newText);
  8829. if (Atomic::decrementAndReturn (oldText->refCount) == 0)
  8830. juce_free (oldText);
  8831. }
  8832. return *this;
  8833. }
  8834. bool String::operator== (const String& other) const throw()
  8835. {
  8836. return text == other.text
  8837. || CharacterFunctions::compare (text->text, other.text->text) == 0;
  8838. }
  8839. bool String::operator== (const tchar* const t) const throw()
  8840. {
  8841. return t != 0 ? CharacterFunctions::compare (text->text, t) == 0
  8842. : isEmpty();
  8843. }
  8844. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8845. {
  8846. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8847. : isEmpty();
  8848. }
  8849. bool String::equalsIgnoreCase (const String& other) const throw()
  8850. {
  8851. return text == other.text
  8852. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8853. }
  8854. bool String::operator!= (const String& other) const throw()
  8855. {
  8856. return text != other.text
  8857. && CharacterFunctions::compare (text->text, other.text->text) != 0;
  8858. }
  8859. bool String::operator!= (const tchar* const t) const throw()
  8860. {
  8861. return t != 0 ? (CharacterFunctions::compare (text->text, t) != 0)
  8862. : isNotEmpty();
  8863. }
  8864. bool String::operator> (const String& other) const throw()
  8865. {
  8866. return compare (other) > 0;
  8867. }
  8868. bool String::operator< (const tchar* const other) const throw()
  8869. {
  8870. return compare (other) < 0;
  8871. }
  8872. bool String::operator>= (const String& other) const throw()
  8873. {
  8874. return compare (other) >= 0;
  8875. }
  8876. bool String::operator<= (const tchar* const other) const throw()
  8877. {
  8878. return compare (other) <= 0;
  8879. }
  8880. int String::compare (const tchar* const other) const throw()
  8881. {
  8882. return other != 0 ? CharacterFunctions::compare (text->text, other)
  8883. : isEmpty();
  8884. }
  8885. int String::compareIgnoreCase (const tchar* const other) const throw()
  8886. {
  8887. return other != 0 ? CharacterFunctions::compareIgnoreCase (text->text, other)
  8888. : isEmpty();
  8889. }
  8890. int String::compareLexicographically (const tchar* other) const throw()
  8891. {
  8892. if (other == 0)
  8893. return isEmpty();
  8894. const tchar* s1 = text->text;
  8895. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8896. ++s1;
  8897. while (*other != 0 && ! CharacterFunctions::isLetterOrDigit (*other))
  8898. ++other;
  8899. return CharacterFunctions::compareIgnoreCase (s1, other);
  8900. }
  8901. const String String::operator+ (const String& other) const throw()
  8902. {
  8903. if (*(other.text->text) == 0)
  8904. return *this;
  8905. if (isEmpty())
  8906. return other;
  8907. const int len = CharacterFunctions::length (text->text);
  8908. const int otherLen = CharacterFunctions::length (other.text->text);
  8909. String result (len + otherLen, (int) 0);
  8910. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8911. memcpy (result.text->text + len, other.text->text, otherLen * sizeof (tchar));
  8912. result.text->text [len + otherLen] = 0;
  8913. return result;
  8914. }
  8915. const String String::operator+ (const tchar* const textToAppend) const throw()
  8916. {
  8917. if (textToAppend == 0 || *textToAppend == 0)
  8918. return *this;
  8919. const int len = CharacterFunctions::length (text->text);
  8920. const int otherLen = CharacterFunctions::length (textToAppend);
  8921. String result (len + otherLen, (int) 0);
  8922. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8923. memcpy (result.text->text + len, textToAppend, otherLen * sizeof (tchar));
  8924. result.text->text [len + otherLen] = 0;
  8925. return result;
  8926. }
  8927. const String String::operator+ (const tchar characterToAppend) const throw()
  8928. {
  8929. if (characterToAppend == 0)
  8930. return *this;
  8931. const int len = CharacterFunctions::length (text->text);
  8932. String result ((int) (len + 1), (int) 0);
  8933. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8934. result.text->text[len] = characterToAppend;
  8935. result.text->text[len + 1] = 0;
  8936. return result;
  8937. }
  8938. const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1,
  8939. const String& string2) throw()
  8940. {
  8941. String s (string1);
  8942. s += string2;
  8943. return s;
  8944. }
  8945. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1,
  8946. const String& string2) throw()
  8947. {
  8948. String s (string1);
  8949. s += string2;
  8950. return s;
  8951. }
  8952. const String& String::operator+= (const tchar* const t) throw()
  8953. {
  8954. if (t != 0)
  8955. appendInternal (t, CharacterFunctions::length (t));
  8956. return *this;
  8957. }
  8958. const String& String::operator+= (const String& other) throw()
  8959. {
  8960. if (isEmpty())
  8961. operator= (other);
  8962. else
  8963. appendInternal (other.text->text,
  8964. CharacterFunctions::length (other.text->text));
  8965. return *this;
  8966. }
  8967. const String& String::operator+= (const char ch) throw()
  8968. {
  8969. char asString[2];
  8970. asString[0] = ch;
  8971. asString[1] = 0;
  8972. #if JUCE_STRINGS_ARE_UNICODE
  8973. operator+= (String (asString));
  8974. #else
  8975. appendInternal (asString, 1);
  8976. #endif
  8977. return *this;
  8978. }
  8979. const String& String::operator+= (const juce_wchar ch) throw()
  8980. {
  8981. juce_wchar asString[2];
  8982. asString[0] = ch;
  8983. asString[1] = 0;
  8984. #if JUCE_STRINGS_ARE_UNICODE
  8985. appendInternal (asString, 1);
  8986. #else
  8987. operator+= (String (asString));
  8988. #endif
  8989. return *this;
  8990. }
  8991. void String::append (const tchar* const other,
  8992. const int howMany) throw()
  8993. {
  8994. if (howMany > 0)
  8995. {
  8996. int i;
  8997. for (i = 0; i < howMany; ++i)
  8998. if (other[i] == 0)
  8999. break;
  9000. appendInternal (other, i);
  9001. }
  9002. }
  9003. String& String::operator<< (const int number) throw()
  9004. {
  9005. tchar buffer [64];
  9006. tchar* const end = buffer + 64;
  9007. const tchar* const t = intToCharString (end, number);
  9008. appendInternal (t, (int) (end - t) - 1);
  9009. return *this;
  9010. }
  9011. String& String::operator<< (const unsigned int number) throw()
  9012. {
  9013. tchar buffer [64];
  9014. tchar* const end = buffer + 64;
  9015. const tchar* const t = uintToCharString (end, number);
  9016. appendInternal (t, (int) (end - t) - 1);
  9017. return *this;
  9018. }
  9019. String& String::operator<< (const short number) throw()
  9020. {
  9021. tchar buffer [64];
  9022. tchar* const end = buffer + 64;
  9023. const tchar* const t = intToCharString (end, (int) number);
  9024. appendInternal (t, (int) (end - t) - 1);
  9025. return *this;
  9026. }
  9027. String& String::operator<< (const long number) throw()
  9028. {
  9029. return operator<< ((int) number);
  9030. }
  9031. String& String::operator<< (const unsigned long number) throw()
  9032. {
  9033. return operator<< ((unsigned int) number);
  9034. }
  9035. String& String::operator<< (const double number) throw()
  9036. {
  9037. operator+= (String (number));
  9038. return *this;
  9039. }
  9040. String& String::operator<< (const float number) throw()
  9041. {
  9042. operator+= (String (number));
  9043. return *this;
  9044. }
  9045. String& String::operator<< (const char character) throw()
  9046. {
  9047. operator+= (character);
  9048. return *this;
  9049. }
  9050. String& String::operator<< (const juce_wchar character) throw()
  9051. {
  9052. operator+= (character);
  9053. return *this;
  9054. }
  9055. String& String::operator<< (const char* const t) throw()
  9056. {
  9057. #if JUCE_STRINGS_ARE_UNICODE
  9058. operator+= (String (t));
  9059. #else
  9060. operator+= (t);
  9061. #endif
  9062. return *this;
  9063. }
  9064. String& String::operator<< (const juce_wchar* const t) throw()
  9065. {
  9066. #if JUCE_STRINGS_ARE_UNICODE
  9067. operator+= (t);
  9068. #else
  9069. operator+= (String (t));
  9070. #endif
  9071. return *this;
  9072. }
  9073. String& String::operator<< (const String& t) throw()
  9074. {
  9075. operator+= (t);
  9076. return *this;
  9077. }
  9078. int String::indexOfChar (const tchar character) const throw()
  9079. {
  9080. const tchar* t = text->text;
  9081. for (;;)
  9082. {
  9083. if (*t == character)
  9084. return (int) (t - text->text);
  9085. if (*t++ == 0)
  9086. return -1;
  9087. }
  9088. }
  9089. int String::lastIndexOfChar (const tchar character) const throw()
  9090. {
  9091. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9092. if (text->text[i] == character)
  9093. return i;
  9094. return -1;
  9095. }
  9096. int String::indexOf (const tchar* const t) const throw()
  9097. {
  9098. const tchar* const r = CharacterFunctions::find (text->text, t);
  9099. return (r == 0) ? -1
  9100. : (int) (r - text->text);
  9101. }
  9102. int String::indexOfChar (const int startIndex,
  9103. const tchar character) const throw()
  9104. {
  9105. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  9106. return -1;
  9107. const tchar* t = text->text + jmax (0, startIndex);
  9108. for (;;)
  9109. {
  9110. if (*t == character)
  9111. return (int) (t - text->text);
  9112. if (*t++ == 0)
  9113. return -1;
  9114. }
  9115. }
  9116. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9117. const int startIndex,
  9118. const bool ignoreCase) const throw()
  9119. {
  9120. if (charactersToLookFor == 0
  9121. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9122. return -1;
  9123. const tchar* t = text->text + jmax (0, startIndex);
  9124. while (*t != 0)
  9125. {
  9126. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9127. return (int) (t - text->text);
  9128. ++t;
  9129. }
  9130. return -1;
  9131. }
  9132. int String::indexOf (const int startIndex,
  9133. const tchar* const other) const throw()
  9134. {
  9135. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9136. return -1;
  9137. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9138. other);
  9139. return (found == 0) ? -1
  9140. : (int) (found - text->text);
  9141. }
  9142. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9143. {
  9144. if (other != 0 && *other != 0)
  9145. {
  9146. const int len = CharacterFunctions::length (other);
  9147. const int end = CharacterFunctions::length (text->text) - len;
  9148. for (int i = 0; i <= end; ++i)
  9149. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9150. return i;
  9151. }
  9152. return -1;
  9153. }
  9154. int String::indexOfIgnoreCase (const int startIndex,
  9155. const tchar* const other) const throw()
  9156. {
  9157. if (other != 0 && *other != 0)
  9158. {
  9159. const int len = CharacterFunctions::length (other);
  9160. const int end = length() - len;
  9161. for (int i = jmax (0, startIndex); i <= end; ++i)
  9162. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9163. return i;
  9164. }
  9165. return -1;
  9166. }
  9167. int String::lastIndexOf (const tchar* const other) const throw()
  9168. {
  9169. if (other != 0 && *other != 0)
  9170. {
  9171. const int len = CharacterFunctions::length (other);
  9172. int i = length() - len;
  9173. if (i >= 0)
  9174. {
  9175. const tchar* n = text->text + i;
  9176. while (i >= 0)
  9177. {
  9178. if (CharacterFunctions::compare (n--, other, len) == 0)
  9179. return i;
  9180. --i;
  9181. }
  9182. }
  9183. }
  9184. return -1;
  9185. }
  9186. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9187. {
  9188. if (other != 0 && *other != 0)
  9189. {
  9190. const int len = CharacterFunctions::length (other);
  9191. int i = length() - len;
  9192. if (i >= 0)
  9193. {
  9194. const tchar* n = text->text + i;
  9195. while (i >= 0)
  9196. {
  9197. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9198. return i;
  9199. --i;
  9200. }
  9201. }
  9202. }
  9203. return -1;
  9204. }
  9205. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9206. const bool ignoreCase) const throw()
  9207. {
  9208. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9209. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9210. return i;
  9211. return -1;
  9212. }
  9213. bool String::contains (const tchar* const other) const throw()
  9214. {
  9215. return indexOf (other) >= 0;
  9216. }
  9217. bool String::containsChar (const tchar character) const throw()
  9218. {
  9219. return indexOfChar (character) >= 0;
  9220. }
  9221. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9222. {
  9223. return indexOfIgnoreCase (t) >= 0;
  9224. }
  9225. int String::indexOfWholeWord (const tchar* const word) const throw()
  9226. {
  9227. if (word != 0 && *word != 0)
  9228. {
  9229. const int wordLen = CharacterFunctions::length (word);
  9230. const int end = length() - wordLen;
  9231. const tchar* t = text->text;
  9232. for (int i = 0; i <= end; ++i)
  9233. {
  9234. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9235. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9236. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9237. {
  9238. return i;
  9239. }
  9240. ++t;
  9241. }
  9242. }
  9243. return -1;
  9244. }
  9245. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9246. {
  9247. if (word != 0 && *word != 0)
  9248. {
  9249. const int wordLen = CharacterFunctions::length (word);
  9250. const int end = length() - wordLen;
  9251. const tchar* t = text->text;
  9252. for (int i = 0; i <= end; ++i)
  9253. {
  9254. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9255. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9256. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9257. {
  9258. return i;
  9259. }
  9260. ++t;
  9261. }
  9262. }
  9263. return -1;
  9264. }
  9265. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9266. {
  9267. return indexOfWholeWord (wordToLookFor) >= 0;
  9268. }
  9269. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9270. {
  9271. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9272. }
  9273. static int indexOfMatch (const tchar* const wildcard,
  9274. const tchar* const test,
  9275. const bool ignoreCase) throw()
  9276. {
  9277. int start = 0;
  9278. while (test [start] != 0)
  9279. {
  9280. int i = 0;
  9281. for (;;)
  9282. {
  9283. const tchar wc = wildcard [i];
  9284. const tchar c = test [i + start];
  9285. if (wc == c
  9286. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9287. || (wc == T('?') && c != 0))
  9288. {
  9289. if (wc == 0)
  9290. return start;
  9291. ++i;
  9292. }
  9293. else
  9294. {
  9295. if (wc == T('*') && (wildcard [i + 1] == 0
  9296. || indexOfMatch (wildcard + i + 1,
  9297. test + start + i,
  9298. ignoreCase) >= 0))
  9299. {
  9300. return start;
  9301. }
  9302. break;
  9303. }
  9304. }
  9305. ++start;
  9306. }
  9307. return -1;
  9308. }
  9309. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9310. {
  9311. int i = 0;
  9312. for (;;)
  9313. {
  9314. const tchar wc = wildcard [i];
  9315. const tchar c = text->text [i];
  9316. if (wc == c
  9317. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9318. || (wc == T('?') && c != 0))
  9319. {
  9320. if (wc == 0)
  9321. return true;
  9322. ++i;
  9323. }
  9324. else
  9325. {
  9326. return wc == T('*') && (wildcard [i + 1] == 0
  9327. || indexOfMatch (wildcard + i + 1,
  9328. text->text + i,
  9329. ignoreCase) >= 0);
  9330. }
  9331. }
  9332. }
  9333. void String::printf (const tchar* const pf, ...) throw()
  9334. {
  9335. va_list list;
  9336. va_start (list, pf);
  9337. vprintf (pf, list);
  9338. }
  9339. const String String::formatted (const tchar* const pf, ...) throw()
  9340. {
  9341. va_list list;
  9342. va_start (list, pf);
  9343. String result;
  9344. result.vprintf (pf, list);
  9345. return result;
  9346. }
  9347. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9348. {
  9349. int bufferSize = 256;
  9350. String result (bufferSize, 0);
  9351. do
  9352. {
  9353. #if JUCE_LINUX && JUCE_64BIT
  9354. va_list tempArgs;
  9355. va_copy (tempArgs, args);
  9356. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, tempArgs);
  9357. va_end (tempArgs);
  9358. #else
  9359. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, args);
  9360. #endif
  9361. if (num > 0)
  9362. {
  9363. *this = result;
  9364. break;
  9365. }
  9366. else if (num == 0)
  9367. {
  9368. *this = String::empty;
  9369. break;
  9370. }
  9371. bufferSize += 256;
  9372. result.preallocateStorage (bufferSize);
  9373. }
  9374. while (bufferSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9375. // returns -1 because of an error rather than because it needs more space.
  9376. }
  9377. const String String::repeatedString (const tchar* const stringToRepeat,
  9378. int numberOfTimesToRepeat) throw()
  9379. {
  9380. const int len = CharacterFunctions::length (stringToRepeat);
  9381. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9382. tchar* n = result.text->text;
  9383. n[0] = 0;
  9384. while (--numberOfTimesToRepeat >= 0)
  9385. {
  9386. CharacterFunctions::append (n, stringToRepeat);
  9387. n += len;
  9388. }
  9389. return result;
  9390. }
  9391. const String String::replaceSection (int index,
  9392. int numCharsToReplace,
  9393. const tchar* const stringToInsert) const throw()
  9394. {
  9395. if (index < 0)
  9396. {
  9397. // a negative index to replace from?
  9398. jassertfalse
  9399. index = 0;
  9400. }
  9401. if (numCharsToReplace < 0)
  9402. {
  9403. // replacing a negative number of characters?
  9404. numCharsToReplace = 0;
  9405. jassertfalse;
  9406. }
  9407. const int len = length();
  9408. if (index + numCharsToReplace > len)
  9409. {
  9410. if (index > len)
  9411. {
  9412. // replacing beyond the end of the string?
  9413. index = len;
  9414. jassertfalse
  9415. }
  9416. numCharsToReplace = len - index;
  9417. }
  9418. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9419. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9420. if (newTotalLen <= 0)
  9421. return String::empty;
  9422. String result (newTotalLen, (int) 0);
  9423. memcpy (result.text->text,
  9424. text->text,
  9425. index * sizeof (tchar));
  9426. if (newStringLen > 0)
  9427. memcpy (result.text->text + index,
  9428. stringToInsert,
  9429. newStringLen * sizeof (tchar));
  9430. const int endStringLen = newTotalLen - (index + newStringLen);
  9431. if (endStringLen > 0)
  9432. memcpy (result.text->text + (index + newStringLen),
  9433. text->text + (index + numCharsToReplace),
  9434. endStringLen * sizeof (tchar));
  9435. result.text->text [newTotalLen] = 0;
  9436. return result;
  9437. }
  9438. const String String::replace (const tchar* const stringToReplace,
  9439. const tchar* const stringToInsert,
  9440. const bool ignoreCase) const throw()
  9441. {
  9442. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9443. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9444. int i = 0;
  9445. String result (*this);
  9446. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9447. : result.indexOf (i, stringToReplace))) >= 0)
  9448. {
  9449. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9450. i += stringToInsertLen;
  9451. }
  9452. return result;
  9453. }
  9454. const String String::replaceCharacter (const tchar charToReplace,
  9455. const tchar charToInsert) const throw()
  9456. {
  9457. const int index = indexOfChar (charToReplace);
  9458. if (index < 0)
  9459. return *this;
  9460. String result (*this);
  9461. result.dupeInternalIfMultiplyReferenced();
  9462. tchar* t = result.text->text + index;
  9463. while (*t != 0)
  9464. {
  9465. if (*t == charToReplace)
  9466. *t = charToInsert;
  9467. ++t;
  9468. }
  9469. return result;
  9470. }
  9471. const String String::replaceCharacters (const String& charactersToReplace,
  9472. const tchar* const charactersToInsertInstead) const throw()
  9473. {
  9474. String result (*this);
  9475. result.dupeInternalIfMultiplyReferenced();
  9476. tchar* t = result.text->text;
  9477. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9478. // the two strings passed in are supposed to be the same length!
  9479. jassert (len2 == charactersToReplace.length());
  9480. while (*t != 0)
  9481. {
  9482. const int index = charactersToReplace.indexOfChar (*t);
  9483. if (((unsigned int) index) < (unsigned int) len2)
  9484. *t = charactersToInsertInstead [index];
  9485. ++t;
  9486. }
  9487. return result;
  9488. }
  9489. bool String::startsWith (const tchar* const other) const throw()
  9490. {
  9491. return other != 0
  9492. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9493. }
  9494. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9495. {
  9496. return other != 0
  9497. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9498. }
  9499. bool String::startsWithChar (const tchar character) const throw()
  9500. {
  9501. jassert (character != 0); // strings can't contain a null character!
  9502. return text->text[0] == character;
  9503. }
  9504. bool String::endsWithChar (const tchar character) const throw()
  9505. {
  9506. jassert (character != 0); // strings can't contain a null character!
  9507. return text->text[0] != 0
  9508. && text->text [length() - 1] == character;
  9509. }
  9510. bool String::endsWith (const tchar* const other) const throw()
  9511. {
  9512. if (other == 0)
  9513. return false;
  9514. const int thisLen = length();
  9515. const int otherLen = CharacterFunctions::length (other);
  9516. return thisLen >= otherLen
  9517. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9518. }
  9519. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9520. {
  9521. if (other == 0)
  9522. return false;
  9523. const int thisLen = length();
  9524. const int otherLen = CharacterFunctions::length (other);
  9525. return thisLen >= otherLen
  9526. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9527. }
  9528. const String String::toUpperCase() const throw()
  9529. {
  9530. String result (*this);
  9531. result.dupeInternalIfMultiplyReferenced();
  9532. CharacterFunctions::toUpperCase (result.text->text);
  9533. return result;
  9534. }
  9535. const String String::toLowerCase() const throw()
  9536. {
  9537. String result (*this);
  9538. result.dupeInternalIfMultiplyReferenced();
  9539. CharacterFunctions::toLowerCase (result.text->text);
  9540. return result;
  9541. }
  9542. tchar& String::operator[] (const int index) throw()
  9543. {
  9544. jassert (((unsigned int) index) <= (unsigned int) length());
  9545. dupeInternalIfMultiplyReferenced();
  9546. return text->text [index];
  9547. }
  9548. tchar String::getLastCharacter() const throw()
  9549. {
  9550. return (isEmpty()) ? ((tchar) 0)
  9551. : text->text [CharacterFunctions::length (text->text) - 1];
  9552. }
  9553. const String String::substring (int start, int end) const throw()
  9554. {
  9555. if (start < 0)
  9556. start = 0;
  9557. else if (end <= start)
  9558. return empty;
  9559. int len = 0;
  9560. const tchar* const t = text->text;
  9561. while (len <= end && t [len] != 0)
  9562. ++len;
  9563. if (end >= len)
  9564. {
  9565. if (start == 0)
  9566. return *this;
  9567. end = len;
  9568. }
  9569. return String (text->text + start,
  9570. end - start);
  9571. }
  9572. const String String::substring (const int start) const throw()
  9573. {
  9574. if (start <= 0)
  9575. return *this;
  9576. const int len = CharacterFunctions::length (text->text);
  9577. if (start >= len)
  9578. return empty;
  9579. else
  9580. return String (text->text + start,
  9581. len - start);
  9582. }
  9583. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9584. {
  9585. return String (text->text,
  9586. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9587. }
  9588. const String String::getLastCharacters (const int numCharacters) const throw()
  9589. {
  9590. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9591. }
  9592. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9593. const bool includeSubString,
  9594. const bool ignoreCase) const throw()
  9595. {
  9596. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9597. : indexOf (sub);
  9598. if (i < 0)
  9599. return empty;
  9600. else
  9601. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9602. }
  9603. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9604. const bool includeSubString,
  9605. const bool ignoreCase) const throw()
  9606. {
  9607. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9608. : lastIndexOf (sub);
  9609. if (i < 0)
  9610. return *this;
  9611. else
  9612. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9613. }
  9614. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9615. const bool includeSubString,
  9616. const bool ignoreCase) const throw()
  9617. {
  9618. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9619. : indexOf (sub);
  9620. if (i < 0)
  9621. return *this;
  9622. else
  9623. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9624. }
  9625. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9626. const bool includeSubString,
  9627. const bool ignoreCase) const throw()
  9628. {
  9629. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9630. : lastIndexOf (sub);
  9631. if (i < 0)
  9632. return *this;
  9633. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9634. }
  9635. bool String::isQuotedString() const throw()
  9636. {
  9637. const String trimmed (trimStart());
  9638. return trimmed[0] == T('"')
  9639. || trimmed[0] == T('\'');
  9640. }
  9641. const String String::unquoted() const throw()
  9642. {
  9643. String s (*this);
  9644. if (s[0] == T('"') || s[0] == T('\''))
  9645. s = s.substring (1);
  9646. const int lastCharIndex = s.length() - 1;
  9647. if (lastCharIndex >= 0
  9648. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9649. s [lastCharIndex] = 0;
  9650. return s;
  9651. }
  9652. const String String::quoted (const tchar quoteCharacter) const throw()
  9653. {
  9654. if (isEmpty())
  9655. return charToString (quoteCharacter) + quoteCharacter;
  9656. String t (*this);
  9657. if (! t.startsWithChar (quoteCharacter))
  9658. t = charToString (quoteCharacter) + t;
  9659. if (! t.endsWithChar (quoteCharacter))
  9660. t += quoteCharacter;
  9661. return t;
  9662. }
  9663. const String String::trim() const throw()
  9664. {
  9665. if (isEmpty())
  9666. return empty;
  9667. int start = 0;
  9668. while (CharacterFunctions::isWhitespace (text->text [start]))
  9669. ++start;
  9670. const int len = CharacterFunctions::length (text->text);
  9671. int end = len - 1;
  9672. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9673. --end;
  9674. ++end;
  9675. if (end <= start)
  9676. return empty;
  9677. else if (start > 0 || end < len)
  9678. return String (text->text + start, end - start);
  9679. else
  9680. return *this;
  9681. }
  9682. const String String::trimStart() const throw()
  9683. {
  9684. if (isEmpty())
  9685. return empty;
  9686. const tchar* t = text->text;
  9687. while (CharacterFunctions::isWhitespace (*t))
  9688. ++t;
  9689. if (t == text->text)
  9690. return *this;
  9691. else
  9692. return String (t);
  9693. }
  9694. const String String::trimEnd() const throw()
  9695. {
  9696. if (isEmpty())
  9697. return empty;
  9698. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9699. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9700. --endT;
  9701. return String (text->text, (int) (++endT - text->text));
  9702. }
  9703. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9704. {
  9705. jassert (charactersToTrim != 0);
  9706. if (isEmpty())
  9707. return empty;
  9708. const tchar* t = text->text;
  9709. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9710. ++t;
  9711. if (t == text->text)
  9712. return *this;
  9713. else
  9714. return String (t);
  9715. }
  9716. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9717. {
  9718. jassert (charactersToTrim != 0);
  9719. if (isEmpty())
  9720. return empty;
  9721. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9722. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9723. --endT;
  9724. return String (text->text, (int) (++endT - text->text));
  9725. }
  9726. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9727. {
  9728. jassert (charactersToRetain != 0);
  9729. if (isEmpty())
  9730. return empty;
  9731. String result (text->allocatedNumChars, (int) 0);
  9732. tchar* dst = result.text->text;
  9733. const tchar* src = text->text;
  9734. while (*src != 0)
  9735. {
  9736. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9737. *dst++ = *src;
  9738. ++src;
  9739. }
  9740. *dst = 0;
  9741. return result;
  9742. }
  9743. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9744. {
  9745. jassert (charactersToRemove != 0);
  9746. if (isEmpty())
  9747. return empty;
  9748. String result (text->allocatedNumChars, (int) 0);
  9749. tchar* dst = result.text->text;
  9750. const tchar* src = text->text;
  9751. while (*src != 0)
  9752. {
  9753. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9754. *dst++ = *src;
  9755. ++src;
  9756. }
  9757. *dst = 0;
  9758. return result;
  9759. }
  9760. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9761. {
  9762. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9763. }
  9764. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9765. {
  9766. jassert (charactersToStopAt != 0);
  9767. const tchar* const t = text->text;
  9768. int i = 0;
  9769. while (t[i] != 0)
  9770. {
  9771. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9772. return String (text->text, i);
  9773. ++i;
  9774. }
  9775. return empty;
  9776. }
  9777. bool String::containsOnly (const tchar* const chars) const throw()
  9778. {
  9779. jassert (chars != 0);
  9780. const tchar* t = text->text;
  9781. while (*t != 0)
  9782. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9783. return false;
  9784. return true;
  9785. }
  9786. bool String::containsAnyOf (const tchar* const chars) const throw()
  9787. {
  9788. jassert (chars != 0);
  9789. const tchar* t = text->text;
  9790. while (*t != 0)
  9791. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9792. return true;
  9793. return false;
  9794. }
  9795. bool String::containsNonWhitespaceChars() const throw()
  9796. {
  9797. const tchar* t = text->text;
  9798. while (*t != 0)
  9799. if (! CharacterFunctions::isWhitespace (*t++))
  9800. return true;
  9801. return false;
  9802. }
  9803. int String::getIntValue() const throw()
  9804. {
  9805. return CharacterFunctions::getIntValue (text->text);
  9806. }
  9807. int String::getTrailingIntValue() const throw()
  9808. {
  9809. int n = 0;
  9810. int mult = 1;
  9811. const tchar* t = text->text + length();
  9812. while (--t >= text->text)
  9813. {
  9814. const tchar c = *t;
  9815. if (! CharacterFunctions::isDigit (c))
  9816. {
  9817. if (c == T('-'))
  9818. n = -n;
  9819. break;
  9820. }
  9821. n += mult * (c - T('0'));
  9822. mult *= 10;
  9823. }
  9824. return n;
  9825. }
  9826. int64 String::getLargeIntValue() const throw()
  9827. {
  9828. return CharacterFunctions::getInt64Value (text->text);
  9829. }
  9830. float String::getFloatValue() const throw()
  9831. {
  9832. return (float) CharacterFunctions::getDoubleValue (text->text);
  9833. }
  9834. double String::getDoubleValue() const throw()
  9835. {
  9836. return CharacterFunctions::getDoubleValue (text->text);
  9837. }
  9838. static const tchar* const hexDigits = T("0123456789abcdef");
  9839. const String String::toHexString (const int number) throw()
  9840. {
  9841. tchar buffer[32];
  9842. tchar* const end = buffer + 32;
  9843. tchar* t = end;
  9844. *--t = 0;
  9845. unsigned int v = (unsigned int) number;
  9846. do
  9847. {
  9848. *--t = hexDigits [v & 15];
  9849. v >>= 4;
  9850. } while (v != 0);
  9851. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9852. }
  9853. const String String::toHexString (const int64 number) throw()
  9854. {
  9855. tchar buffer[32];
  9856. tchar* const end = buffer + 32;
  9857. tchar* t = end;
  9858. *--t = 0;
  9859. uint64 v = (uint64) number;
  9860. do
  9861. {
  9862. *--t = hexDigits [(int) (v & 15)];
  9863. v >>= 4;
  9864. } while (v != 0);
  9865. return String (t, (int) (((char*) end) - (char*) t));
  9866. }
  9867. const String String::toHexString (const short number) throw()
  9868. {
  9869. return toHexString ((int) (unsigned short) number);
  9870. }
  9871. const String String::toHexString (const unsigned char* data,
  9872. const int size,
  9873. const int groupSize) throw()
  9874. {
  9875. if (size <= 0)
  9876. return empty;
  9877. int numChars = (size * 2) + 2;
  9878. if (groupSize > 0)
  9879. numChars += size / groupSize;
  9880. String s (numChars, (int) 0);
  9881. tchar* d = s.text->text;
  9882. for (int i = 0; i < size; ++i)
  9883. {
  9884. *d++ = hexDigits [(*data) >> 4];
  9885. *d++ = hexDigits [(*data) & 0xf];
  9886. ++data;
  9887. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9888. *d++ = T(' ');
  9889. }
  9890. *d = 0;
  9891. return s;
  9892. }
  9893. int String::getHexValue32() const throw()
  9894. {
  9895. int result = 0;
  9896. const tchar* c = text->text;
  9897. for (;;)
  9898. {
  9899. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9900. if (hexValue >= 0)
  9901. result = (result << 4) | hexValue;
  9902. else if (*c == 0)
  9903. break;
  9904. ++c;
  9905. }
  9906. return result;
  9907. }
  9908. int64 String::getHexValue64() const throw()
  9909. {
  9910. int64 result = 0;
  9911. const tchar* c = text->text;
  9912. for (;;)
  9913. {
  9914. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9915. if (hexValue >= 0)
  9916. result = (result << 4) | hexValue;
  9917. else if (*c == 0)
  9918. break;
  9919. ++c;
  9920. }
  9921. return result;
  9922. }
  9923. const String String::createStringFromData (const void* const data_,
  9924. const int size) throw()
  9925. {
  9926. const char* const data = (const char*) data_;
  9927. if (size <= 0 || data == 0)
  9928. {
  9929. return empty;
  9930. }
  9931. else if (size < 2)
  9932. {
  9933. return charToString (data[0]);
  9934. }
  9935. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9936. || (data[0] == (char)-1 && data[1] == (char)-2))
  9937. {
  9938. // assume it's 16-bit unicode
  9939. const bool bigEndian = (data[0] == (char)-2);
  9940. const int numChars = size / 2 - 1;
  9941. String result;
  9942. result.preallocateStorage (numChars + 2);
  9943. const uint16* const src = (const uint16*) (data + 2);
  9944. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9945. if (bigEndian)
  9946. {
  9947. for (int i = 0; i < numChars; ++i)
  9948. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9949. }
  9950. else
  9951. {
  9952. for (int i = 0; i < numChars; ++i)
  9953. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9954. }
  9955. dst [numChars] = 0;
  9956. return result;
  9957. }
  9958. else
  9959. {
  9960. return String::fromUTF8 ((const uint8*) data, size);
  9961. }
  9962. }
  9963. const char* String::toUTF8() const throw()
  9964. {
  9965. if (isEmpty())
  9966. {
  9967. return (const char*) emptyCharString;
  9968. }
  9969. else
  9970. {
  9971. String* const mutableThis = const_cast <String*> (this);
  9972. mutableThis->dupeInternalIfMultiplyReferenced();
  9973. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9974. const int utf8BytesNeeded = copyToUTF8 (0);
  9975. mutableThis->text = (InternalRefCountedStringHolder*)
  9976. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9977. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9978. char* const otherCopy = (char*) (text->text + currentLen);
  9979. copyToUTF8 ((uint8*) otherCopy);
  9980. return otherCopy;
  9981. }
  9982. }
  9983. int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const throw()
  9984. {
  9985. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9986. #if JUCE_STRINGS_ARE_UNICODE
  9987. int num = 0, index = 0;
  9988. for (;;)
  9989. {
  9990. const uint32 c = (uint32) text->text [index++];
  9991. if (c >= 0x80)
  9992. {
  9993. int numExtraBytes = 1;
  9994. if (c >= 0x800)
  9995. {
  9996. ++numExtraBytes;
  9997. if (c >= 0x10000)
  9998. {
  9999. ++numExtraBytes;
  10000. if (c >= 0x200000)
  10001. {
  10002. ++numExtraBytes;
  10003. if (c >= 0x4000000)
  10004. ++numExtraBytes;
  10005. }
  10006. }
  10007. }
  10008. if (buffer != 0)
  10009. {
  10010. if (num + numExtraBytes >= maxBufferSizeBytes)
  10011. {
  10012. buffer [num++] = 0;
  10013. break;
  10014. }
  10015. else
  10016. {
  10017. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  10018. while (--numExtraBytes >= 0)
  10019. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  10020. }
  10021. }
  10022. else
  10023. {
  10024. num += numExtraBytes + 1;
  10025. }
  10026. }
  10027. else
  10028. {
  10029. if (buffer != 0)
  10030. {
  10031. if (num + 1 >= maxBufferSizeBytes)
  10032. {
  10033. buffer [num++] = 0;
  10034. break;
  10035. }
  10036. buffer [num] = (uint8) c;
  10037. }
  10038. ++num;
  10039. }
  10040. if (c == 0)
  10041. break;
  10042. }
  10043. return num;
  10044. #else
  10045. const int numBytes = jmin (maxBufferSizeBytes, length() + 1);
  10046. if (buffer != 0)
  10047. copyToBuffer ((char*) buffer, maxBufferSizeBytes);
  10048. return numBytes;
  10049. #endif
  10050. }
  10051. const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) throw()
  10052. {
  10053. if (buffer == 0)
  10054. return empty;
  10055. if (bufferSizeBytes < 0)
  10056. bufferSizeBytes = std::numeric_limits<int>::max();
  10057. size_t numBytes;
  10058. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  10059. if (buffer [numBytes] == 0)
  10060. break;
  10061. String result ((int) numBytes + 1, 0);
  10062. tchar* dest = result.text->text;
  10063. size_t i = 0;
  10064. while (i < numBytes)
  10065. {
  10066. const uint8 c = buffer [i++];
  10067. if ((c & 0x80) != 0)
  10068. {
  10069. int mask = 0x7f;
  10070. int bit = 0x40;
  10071. int numExtraValues = 0;
  10072. while (bit != 0 && (c & bit) != 0)
  10073. {
  10074. bit >>= 1;
  10075. mask >>= 1;
  10076. ++numExtraValues;
  10077. }
  10078. int n = (c & mask);
  10079. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  10080. {
  10081. const uint8 nextByte = buffer[i];
  10082. if ((nextByte & 0xc0) != 0x80)
  10083. break;
  10084. n <<= 6;
  10085. n |= (nextByte & 0x3f);
  10086. ++i;
  10087. }
  10088. *dest++ = (tchar) n;
  10089. }
  10090. else
  10091. {
  10092. *dest++ = (tchar) c;
  10093. }
  10094. }
  10095. *dest = 0;
  10096. return result;
  10097. }
  10098. String::Concatenator::Concatenator (String& stringToAppendTo)
  10099. : result (stringToAppendTo),
  10100. nextIndex (stringToAppendTo.length())
  10101. {
  10102. }
  10103. String::Concatenator::~Concatenator()
  10104. {
  10105. }
  10106. void String::Concatenator::append (const String& s)
  10107. {
  10108. const int len = s.length();
  10109. if (len > 0)
  10110. {
  10111. result.preallocateStorage (nextIndex + len);
  10112. s.copyToBuffer (const_cast <tchar*> ((const tchar*) result) + nextIndex, len);
  10113. nextIndex += len;
  10114. }
  10115. }
  10116. END_JUCE_NAMESPACE
  10117. /*** End of inlined file: juce_String.cpp ***/
  10118. /*** Start of inlined file: juce_StringArray.cpp ***/
  10119. BEGIN_JUCE_NAMESPACE
  10120. StringArray::StringArray() throw()
  10121. {
  10122. }
  10123. StringArray::StringArray (const StringArray& other)
  10124. : strings (other.strings)
  10125. {
  10126. }
  10127. StringArray::StringArray (const juce_wchar** const initialStrings,
  10128. const int numberOfStrings)
  10129. {
  10130. for (int i = 0; i < numberOfStrings; ++i)
  10131. add (initialStrings [i]);
  10132. }
  10133. StringArray::StringArray (const char** const initialStrings,
  10134. const int numberOfStrings)
  10135. {
  10136. for (int i = 0; i < numberOfStrings; ++i)
  10137. add (initialStrings [i]);
  10138. }
  10139. StringArray::StringArray (const juce_wchar** const initialStrings)
  10140. {
  10141. int i = 0;
  10142. while (initialStrings[i] != 0)
  10143. add (initialStrings [i++]);
  10144. }
  10145. StringArray::StringArray (const char** const initialStrings)
  10146. {
  10147. int i = 0;
  10148. while (initialStrings[i] != 0)
  10149. add (initialStrings [i++]);
  10150. }
  10151. const StringArray& StringArray::operator= (const StringArray& other)
  10152. {
  10153. strings = other.strings;
  10154. return *this;
  10155. }
  10156. StringArray::~StringArray()
  10157. {
  10158. }
  10159. bool StringArray::operator== (const StringArray& other) const
  10160. {
  10161. if (other.size() != size())
  10162. return false;
  10163. for (int i = size(); --i >= 0;)
  10164. if (other.strings.getReference(i) != strings.getReference(i))
  10165. return false;
  10166. return true;
  10167. }
  10168. bool StringArray::operator!= (const StringArray& other) const
  10169. {
  10170. return ! operator== (other);
  10171. }
  10172. void StringArray::clear()
  10173. {
  10174. strings.clear();
  10175. }
  10176. const String& StringArray::operator[] (const int index) const throw()
  10177. {
  10178. if (((unsigned int) index) < (unsigned int) strings.size())
  10179. return strings.getReference (index);
  10180. return String::empty;
  10181. }
  10182. void StringArray::add (const String& newString)
  10183. {
  10184. strings.add (newString);
  10185. }
  10186. void StringArray::insert (const int index, const String& newString)
  10187. {
  10188. strings.insert (index, newString);
  10189. }
  10190. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10191. {
  10192. if (! contains (newString, ignoreCase))
  10193. add (newString);
  10194. }
  10195. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10196. {
  10197. if (startIndex < 0)
  10198. {
  10199. jassertfalse
  10200. startIndex = 0;
  10201. }
  10202. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10203. numElementsToAdd = otherArray.size() - startIndex;
  10204. while (--numElementsToAdd >= 0)
  10205. strings.add (otherArray.strings.getReference (startIndex++));
  10206. }
  10207. void StringArray::set (const int index, const String& newString)
  10208. {
  10209. strings.set (index, newString);
  10210. }
  10211. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10212. {
  10213. if (ignoreCase)
  10214. {
  10215. for (int i = size(); --i >= 0;)
  10216. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10217. return true;
  10218. }
  10219. else
  10220. {
  10221. for (int i = size(); --i >= 0;)
  10222. if (stringToLookFor == strings.getReference(i))
  10223. return true;
  10224. }
  10225. return false;
  10226. }
  10227. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10228. {
  10229. if (i < 0)
  10230. i = 0;
  10231. const int numElements = size();
  10232. if (ignoreCase)
  10233. {
  10234. while (i < numElements)
  10235. {
  10236. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10237. return i;
  10238. ++i;
  10239. }
  10240. }
  10241. else
  10242. {
  10243. while (i < numElements)
  10244. {
  10245. if (stringToLookFor == strings.getReference (i))
  10246. return i;
  10247. ++i;
  10248. }
  10249. }
  10250. return -1;
  10251. }
  10252. void StringArray::remove (const int index)
  10253. {
  10254. strings.remove (index);
  10255. }
  10256. void StringArray::removeString (const String& stringToRemove,
  10257. const bool ignoreCase)
  10258. {
  10259. if (ignoreCase)
  10260. {
  10261. for (int i = size(); --i >= 0;)
  10262. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10263. strings.remove (i);
  10264. }
  10265. else
  10266. {
  10267. for (int i = size(); --i >= 0;)
  10268. if (stringToRemove == strings.getReference (i))
  10269. strings.remove (i);
  10270. }
  10271. }
  10272. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10273. {
  10274. if (removeWhitespaceStrings)
  10275. {
  10276. for (int i = size(); --i >= 0;)
  10277. if (! strings.getReference(i).containsNonWhitespaceChars())
  10278. strings.remove (i);
  10279. }
  10280. else
  10281. {
  10282. for (int i = size(); --i >= 0;)
  10283. if (strings.getReference(i).isEmpty())
  10284. strings.remove (i);
  10285. }
  10286. }
  10287. void StringArray::trim()
  10288. {
  10289. for (int i = size(); --i >= 0;)
  10290. {
  10291. String& s = strings.getReference(i);
  10292. s = s.trim();
  10293. }
  10294. }
  10295. class InternalStringArrayComparator_CaseSensitive
  10296. {
  10297. public:
  10298. static int compareElements (String& first, String& second) { return first.compare (second); }
  10299. };
  10300. class InternalStringArrayComparator_CaseInsensitive
  10301. {
  10302. public:
  10303. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10304. };
  10305. void StringArray::sort (const bool ignoreCase)
  10306. {
  10307. if (ignoreCase)
  10308. {
  10309. InternalStringArrayComparator_CaseInsensitive comp;
  10310. strings.sort (comp);
  10311. }
  10312. else
  10313. {
  10314. InternalStringArrayComparator_CaseSensitive comp;
  10315. strings.sort (comp);
  10316. }
  10317. }
  10318. void StringArray::move (const int currentIndex, int newIndex) throw()
  10319. {
  10320. strings.move (currentIndex, newIndex);
  10321. }
  10322. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10323. {
  10324. const int last = (numberToJoin < 0) ? size()
  10325. : jmin (size(), start + numberToJoin);
  10326. if (start < 0)
  10327. start = 0;
  10328. if (start >= last)
  10329. return String::empty;
  10330. if (start == last - 1)
  10331. return strings.getReference (start);
  10332. const int separatorLen = separator.length();
  10333. int charsNeeded = separatorLen * (last - start - 1);
  10334. for (int i = start; i < last; ++i)
  10335. charsNeeded += strings.getReference(i).length();
  10336. String result;
  10337. result.preallocateStorage (charsNeeded);
  10338. tchar* dest = (tchar*) (const tchar*) result;
  10339. while (start < last)
  10340. {
  10341. const String& s = strings.getReference (start);
  10342. const int len = s.length();
  10343. if (len > 0)
  10344. {
  10345. s.copyToBuffer (dest, len);
  10346. dest += len;
  10347. }
  10348. if (++start < last && separatorLen > 0)
  10349. {
  10350. separator.copyToBuffer (dest, separatorLen);
  10351. dest += separatorLen;
  10352. }
  10353. }
  10354. *dest = 0;
  10355. return result;
  10356. }
  10357. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10358. {
  10359. return addTokens (text,
  10360. T(" \n\r\t"),
  10361. preserveQuotedStrings ? T("\"") : 0);
  10362. }
  10363. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10364. {
  10365. int num = 0;
  10366. if (text != 0 && *text != 0)
  10367. {
  10368. if (breakCharacters == 0)
  10369. breakCharacters = T("");
  10370. if (quoteCharacters == 0)
  10371. quoteCharacters = T("");
  10372. bool insideQuotes = false;
  10373. tchar currentQuoteChar = 0;
  10374. int i = 0;
  10375. int tokenStart = 0;
  10376. for (;;)
  10377. {
  10378. const tchar c = text[i];
  10379. bool isBreak = (c == 0);
  10380. if (! (insideQuotes || isBreak))
  10381. {
  10382. const tchar* b = breakCharacters;
  10383. while (*b != 0)
  10384. {
  10385. if (*b++ == c)
  10386. {
  10387. isBreak = true;
  10388. break;
  10389. }
  10390. }
  10391. }
  10392. if (! isBreak)
  10393. {
  10394. bool isQuote = false;
  10395. const tchar* q = quoteCharacters;
  10396. while (*q != 0)
  10397. {
  10398. if (*q++ == c)
  10399. {
  10400. isQuote = true;
  10401. break;
  10402. }
  10403. }
  10404. if (isQuote)
  10405. {
  10406. if (insideQuotes)
  10407. {
  10408. // only break out of quotes-mode if we find a matching quote to the
  10409. // one that we opened with..
  10410. if (currentQuoteChar == c)
  10411. insideQuotes = false;
  10412. }
  10413. else
  10414. {
  10415. insideQuotes = true;
  10416. currentQuoteChar = c;
  10417. }
  10418. }
  10419. }
  10420. else
  10421. {
  10422. add (String (text + tokenStart, i - tokenStart));
  10423. ++num;
  10424. tokenStart = i + 1;
  10425. }
  10426. if (c == 0)
  10427. break;
  10428. ++i;
  10429. }
  10430. }
  10431. return num;
  10432. }
  10433. int StringArray::addLines (const tchar* text)
  10434. {
  10435. int numLines = 0;
  10436. if (text != 0)
  10437. {
  10438. while (*text != 0)
  10439. {
  10440. const tchar* const startOfLine = text;
  10441. while (*text != 0)
  10442. {
  10443. if (*text == T('\r'))
  10444. {
  10445. ++text;
  10446. if (*text == T('\n'))
  10447. ++text;
  10448. break;
  10449. }
  10450. if (*text == T('\n'))
  10451. {
  10452. ++text;
  10453. break;
  10454. }
  10455. ++text;
  10456. }
  10457. const tchar* endOfLine = text;
  10458. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10459. --endOfLine;
  10460. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10461. --endOfLine;
  10462. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10463. ++numLines;
  10464. }
  10465. }
  10466. return numLines;
  10467. }
  10468. void StringArray::removeDuplicates (const bool ignoreCase)
  10469. {
  10470. for (int i = 0; i < size() - 1; ++i)
  10471. {
  10472. const String s (strings.getReference(i));
  10473. int nextIndex = i + 1;
  10474. for (;;)
  10475. {
  10476. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10477. if (nextIndex < 0)
  10478. break;
  10479. strings.remove (nextIndex);
  10480. }
  10481. }
  10482. }
  10483. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10484. const bool appendNumberToFirstInstance,
  10485. const tchar* const preNumberString,
  10486. const tchar* const postNumberString)
  10487. {
  10488. for (int i = 0; i < size() - 1; ++i)
  10489. {
  10490. String& s = strings.getReference(i);
  10491. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10492. if (nextIndex >= 0)
  10493. {
  10494. const String original (s);
  10495. int number = 0;
  10496. if (appendNumberToFirstInstance)
  10497. s = original + preNumberString + String (++number) + postNumberString;
  10498. else
  10499. ++number;
  10500. while (nextIndex >= 0)
  10501. {
  10502. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10503. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10504. }
  10505. }
  10506. }
  10507. }
  10508. void StringArray::minimiseStorageOverheads()
  10509. {
  10510. strings.minimiseStorageOverheads();
  10511. }
  10512. END_JUCE_NAMESPACE
  10513. /*** End of inlined file: juce_StringArray.cpp ***/
  10514. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10515. BEGIN_JUCE_NAMESPACE
  10516. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10517. : ignoreCase (ignoreCase_)
  10518. {
  10519. }
  10520. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10521. : keys (other.keys),
  10522. values (other.values),
  10523. ignoreCase (other.ignoreCase)
  10524. {
  10525. }
  10526. StringPairArray::~StringPairArray() throw()
  10527. {
  10528. }
  10529. const StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10530. {
  10531. keys = other.keys;
  10532. values = other.values;
  10533. return *this;
  10534. }
  10535. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10536. {
  10537. for (int i = keys.size(); --i >= 0;)
  10538. if (other [keys[i]] != values[i])
  10539. return false;
  10540. return true;
  10541. }
  10542. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10543. {
  10544. return ! operator== (other);
  10545. }
  10546. const String& StringPairArray::operator[] (const String& key) const throw()
  10547. {
  10548. return values [keys.indexOf (key, ignoreCase)];
  10549. }
  10550. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10551. {
  10552. const int i = keys.indexOf (key, ignoreCase);
  10553. if (i >= 0)
  10554. return values[i];
  10555. return defaultReturnValue;
  10556. }
  10557. void StringPairArray::set (const String& key,
  10558. const String& value) throw()
  10559. {
  10560. const int i = keys.indexOf (key, ignoreCase);
  10561. if (i >= 0)
  10562. {
  10563. values.set (i, value);
  10564. }
  10565. else
  10566. {
  10567. keys.add (key);
  10568. values.add (value);
  10569. }
  10570. }
  10571. void StringPairArray::addArray (const StringPairArray& other)
  10572. {
  10573. for (int i = 0; i < other.size(); ++i)
  10574. set (other.keys[i], other.values[i]);
  10575. }
  10576. void StringPairArray::clear() throw()
  10577. {
  10578. keys.clear();
  10579. values.clear();
  10580. }
  10581. void StringPairArray::remove (const String& key) throw()
  10582. {
  10583. remove (keys.indexOf (key, ignoreCase));
  10584. }
  10585. void StringPairArray::remove (const int index) throw()
  10586. {
  10587. keys.remove (index);
  10588. values.remove (index);
  10589. }
  10590. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10591. {
  10592. ignoreCase = shouldIgnoreCase;
  10593. }
  10594. const String StringPairArray::getDescription() const
  10595. {
  10596. String s;
  10597. for (int i = 0; i < keys.size(); ++i)
  10598. {
  10599. s << keys[i] << T(" = ") << values[i];
  10600. if (i < keys.size())
  10601. s << T(", ");
  10602. }
  10603. return s;
  10604. }
  10605. void StringPairArray::minimiseStorageOverheads() throw()
  10606. {
  10607. keys.minimiseStorageOverheads();
  10608. values.minimiseStorageOverheads();
  10609. }
  10610. END_JUCE_NAMESPACE
  10611. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10612. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10613. BEGIN_JUCE_NAMESPACE
  10614. XmlDocument::XmlDocument (const String& documentText) throw()
  10615. : originalText (documentText),
  10616. ignoreEmptyTextElements (true)
  10617. {
  10618. }
  10619. XmlDocument::XmlDocument (const File& file)
  10620. {
  10621. inputSource = new FileInputSource (file);
  10622. }
  10623. XmlDocument::~XmlDocument() throw()
  10624. {
  10625. }
  10626. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10627. {
  10628. inputSource = newSource;
  10629. }
  10630. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10631. {
  10632. ignoreEmptyTextElements = shouldBeIgnored;
  10633. }
  10634. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10635. {
  10636. return CharacterFunctions::isLetterOrDigit (c)
  10637. || c == T('_')
  10638. || c == T('-')
  10639. || c == T(':')
  10640. || c == T('.');
  10641. }
  10642. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10643. {
  10644. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10645. : isXmlIdentifierCharSlow (c);
  10646. }
  10647. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10648. {
  10649. String textToParse (originalText);
  10650. if (textToParse.isEmpty() && inputSource != 0)
  10651. {
  10652. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10653. if (in != 0)
  10654. {
  10655. MemoryBlock data;
  10656. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10657. if (data.getSize() >= 2
  10658. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10659. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10660. {
  10661. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10662. }
  10663. else
  10664. {
  10665. textToParse = String::fromUTF8 ((const uint8*) data.getData(), (int) data.getSize());
  10666. }
  10667. if (! onlyReadOuterDocumentElement)
  10668. originalText = textToParse;
  10669. }
  10670. }
  10671. input = textToParse;
  10672. lastError = String::empty;
  10673. errorOccurred = false;
  10674. outOfData = false;
  10675. needToLoadDTD = true;
  10676. for (int i = 0; i < 128; ++i)
  10677. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10678. if (textToParse.isEmpty())
  10679. {
  10680. lastError = "not enough input";
  10681. }
  10682. else
  10683. {
  10684. skipHeader();
  10685. if (input != 0)
  10686. {
  10687. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10688. if (! errorOccurred)
  10689. return result.release();
  10690. }
  10691. else
  10692. {
  10693. lastError = "incorrect xml header";
  10694. }
  10695. }
  10696. return 0;
  10697. }
  10698. const String& XmlDocument::getLastParseError() const throw()
  10699. {
  10700. return lastError;
  10701. }
  10702. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10703. {
  10704. lastError = desc;
  10705. errorOccurred = ! carryOn;
  10706. }
  10707. const String XmlDocument::getFileContents (const String& filename) const
  10708. {
  10709. if (inputSource != 0)
  10710. {
  10711. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10712. if (in != 0)
  10713. return in->readEntireStreamAsString();
  10714. }
  10715. return String::empty;
  10716. }
  10717. tchar XmlDocument::readNextChar() throw()
  10718. {
  10719. if (*input != 0)
  10720. {
  10721. return *input++;
  10722. }
  10723. else
  10724. {
  10725. outOfData = true;
  10726. return 0;
  10727. }
  10728. }
  10729. int XmlDocument::findNextTokenLength() throw()
  10730. {
  10731. int len = 0;
  10732. tchar c = *input;
  10733. while (isXmlIdentifierChar (c))
  10734. c = input [++len];
  10735. return len;
  10736. }
  10737. void XmlDocument::skipHeader() throw()
  10738. {
  10739. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10740. if (found != 0)
  10741. {
  10742. input = found;
  10743. input = CharacterFunctions::find (input, T("?>"));
  10744. if (input == 0)
  10745. return;
  10746. input += 2;
  10747. }
  10748. skipNextWhiteSpace();
  10749. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10750. if (docType == 0)
  10751. return;
  10752. input = docType + 9;
  10753. int n = 1;
  10754. while (n > 0)
  10755. {
  10756. const tchar c = readNextChar();
  10757. if (outOfData)
  10758. return;
  10759. if (c == T('<'))
  10760. ++n;
  10761. else if (c == T('>'))
  10762. --n;
  10763. }
  10764. docType += 9;
  10765. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10766. }
  10767. void XmlDocument::skipNextWhiteSpace() throw()
  10768. {
  10769. for (;;)
  10770. {
  10771. tchar c = *input;
  10772. while (CharacterFunctions::isWhitespace (c))
  10773. c = *++input;
  10774. if (c == 0)
  10775. {
  10776. outOfData = true;
  10777. break;
  10778. }
  10779. else if (c == T('<'))
  10780. {
  10781. if (input[1] == T('!')
  10782. && input[2] == T('-')
  10783. && input[3] == T('-'))
  10784. {
  10785. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10786. if (closeComment == 0)
  10787. {
  10788. outOfData = true;
  10789. break;
  10790. }
  10791. input = closeComment + 3;
  10792. continue;
  10793. }
  10794. else if (input[1] == T('?'))
  10795. {
  10796. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10797. if (closeBracket == 0)
  10798. {
  10799. outOfData = true;
  10800. break;
  10801. }
  10802. input = closeBracket + 2;
  10803. continue;
  10804. }
  10805. }
  10806. break;
  10807. }
  10808. }
  10809. void XmlDocument::readQuotedString (String& result) throw()
  10810. {
  10811. const tchar quote = readNextChar();
  10812. while (! outOfData)
  10813. {
  10814. const tchar c = readNextChar();
  10815. if (c == quote)
  10816. break;
  10817. if (c == T('&'))
  10818. {
  10819. --input;
  10820. readEntity (result);
  10821. }
  10822. else
  10823. {
  10824. --input;
  10825. const tchar* const start = input;
  10826. for (;;)
  10827. {
  10828. const tchar character = *input;
  10829. if (character == quote)
  10830. {
  10831. result.append (start, (int) (input - start));
  10832. ++input;
  10833. return;
  10834. }
  10835. else if (character == T('&'))
  10836. {
  10837. result.append (start, (int) (input - start));
  10838. break;
  10839. }
  10840. else if (character == 0)
  10841. {
  10842. outOfData = true;
  10843. setLastError ("unmatched quotes", false);
  10844. break;
  10845. }
  10846. ++input;
  10847. }
  10848. }
  10849. }
  10850. }
  10851. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10852. {
  10853. XmlElement* node = 0;
  10854. skipNextWhiteSpace();
  10855. if (outOfData)
  10856. return 0;
  10857. input = CharacterFunctions::find (input, T("<"));
  10858. if (input != 0)
  10859. {
  10860. ++input;
  10861. int tagLen = findNextTokenLength();
  10862. if (tagLen == 0)
  10863. {
  10864. // no tag name - but allow for a gap after the '<' before giving an error
  10865. skipNextWhiteSpace();
  10866. tagLen = findNextTokenLength();
  10867. if (tagLen == 0)
  10868. {
  10869. setLastError ("tag name missing", false);
  10870. return node;
  10871. }
  10872. }
  10873. node = new XmlElement (String (input, tagLen));
  10874. input += tagLen;
  10875. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10876. // look for attributes
  10877. for (;;)
  10878. {
  10879. skipNextWhiteSpace();
  10880. const tchar c = *input;
  10881. // empty tag..
  10882. if (c == T('/') && input[1] == T('>'))
  10883. {
  10884. input += 2;
  10885. break;
  10886. }
  10887. // parse the guts of the element..
  10888. if (c == T('>'))
  10889. {
  10890. ++input;
  10891. skipNextWhiteSpace();
  10892. if (alsoParseSubElements)
  10893. readChildElements (node);
  10894. break;
  10895. }
  10896. // get an attribute..
  10897. if (isXmlIdentifierChar (c))
  10898. {
  10899. const int attNameLen = findNextTokenLength();
  10900. if (attNameLen > 0)
  10901. {
  10902. const tchar* attNameStart = input;
  10903. input += attNameLen;
  10904. skipNextWhiteSpace();
  10905. if (readNextChar() == T('='))
  10906. {
  10907. skipNextWhiteSpace();
  10908. const tchar nextChar = *input;
  10909. if (nextChar == T('"') || nextChar == T('\''))
  10910. {
  10911. XmlElement::XmlAttributeNode* const newAtt
  10912. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10913. String::empty);
  10914. readQuotedString (newAtt->value);
  10915. if (lastAttribute == 0)
  10916. node->attributes = newAtt;
  10917. else
  10918. lastAttribute->next = newAtt;
  10919. lastAttribute = newAtt;
  10920. continue;
  10921. }
  10922. }
  10923. }
  10924. }
  10925. else
  10926. {
  10927. if (! outOfData)
  10928. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10929. }
  10930. break;
  10931. }
  10932. }
  10933. return node;
  10934. }
  10935. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10936. {
  10937. XmlElement* lastChildNode = 0;
  10938. for (;;)
  10939. {
  10940. skipNextWhiteSpace();
  10941. if (outOfData)
  10942. {
  10943. setLastError ("unmatched tags", false);
  10944. break;
  10945. }
  10946. if (*input == T('<'))
  10947. {
  10948. if (input[1] == T('/'))
  10949. {
  10950. // our close tag..
  10951. input = CharacterFunctions::find (input, T(">"));
  10952. ++input;
  10953. break;
  10954. }
  10955. else if (input[1] == T('!')
  10956. && input[2] == T('[')
  10957. && input[3] == T('C')
  10958. && input[4] == T('D')
  10959. && input[5] == T('A')
  10960. && input[6] == T('T')
  10961. && input[7] == T('A')
  10962. && input[8] == T('['))
  10963. {
  10964. input += 9;
  10965. const tchar* const inputStart = input;
  10966. int len = 0;
  10967. for (;;)
  10968. {
  10969. if (*input == 0)
  10970. {
  10971. setLastError ("unterminated CDATA section", false);
  10972. outOfData = true;
  10973. break;
  10974. }
  10975. else if (input[0] == T(']')
  10976. && input[1] == T(']')
  10977. && input[2] == T('>'))
  10978. {
  10979. input += 3;
  10980. break;
  10981. }
  10982. ++input;
  10983. ++len;
  10984. }
  10985. XmlElement* const e = new XmlElement ((int) 0);
  10986. e->setText (String (inputStart, len));
  10987. if (lastChildNode != 0)
  10988. lastChildNode->nextElement = e;
  10989. else
  10990. parent->addChildElement (e);
  10991. lastChildNode = e;
  10992. }
  10993. else
  10994. {
  10995. // this is some other element, so parse and add it..
  10996. XmlElement* const n = readNextElement (true);
  10997. if (n != 0)
  10998. {
  10999. if (lastChildNode == 0)
  11000. parent->addChildElement (n);
  11001. else
  11002. lastChildNode->nextElement = n;
  11003. lastChildNode = n;
  11004. }
  11005. else
  11006. {
  11007. return;
  11008. }
  11009. }
  11010. }
  11011. else
  11012. {
  11013. // read character block..
  11014. XmlElement* const e = new XmlElement ((int)0);
  11015. if (lastChildNode != 0)
  11016. lastChildNode->nextElement = e;
  11017. else
  11018. parent->addChildElement (e);
  11019. lastChildNode = e;
  11020. String textElementContent;
  11021. for (;;)
  11022. {
  11023. const tchar c = *input;
  11024. if (c == T('<'))
  11025. break;
  11026. if (c == 0)
  11027. {
  11028. setLastError ("unmatched tags", false);
  11029. outOfData = true;
  11030. return;
  11031. }
  11032. if (c == T('&'))
  11033. {
  11034. String entity;
  11035. readEntity (entity);
  11036. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  11037. {
  11038. const tchar* const oldInput = input;
  11039. const bool oldOutOfData = outOfData;
  11040. input = (const tchar*) entity;
  11041. outOfData = false;
  11042. for (;;)
  11043. {
  11044. XmlElement* const n = readNextElement (true);
  11045. if (n == 0)
  11046. break;
  11047. if (lastChildNode == 0)
  11048. parent->addChildElement (n);
  11049. else
  11050. lastChildNode->nextElement = n;
  11051. lastChildNode = n;
  11052. }
  11053. input = oldInput;
  11054. outOfData = oldOutOfData;
  11055. }
  11056. else
  11057. {
  11058. textElementContent += entity;
  11059. }
  11060. }
  11061. else
  11062. {
  11063. const tchar* start = input;
  11064. int len = 0;
  11065. for (;;)
  11066. {
  11067. const tchar nextChar = *input;
  11068. if (nextChar == T('<') || nextChar == T('&'))
  11069. {
  11070. break;
  11071. }
  11072. else if (nextChar == 0)
  11073. {
  11074. setLastError ("unmatched tags", false);
  11075. outOfData = true;
  11076. return;
  11077. }
  11078. ++input;
  11079. ++len;
  11080. }
  11081. textElementContent.append (start, len);
  11082. }
  11083. }
  11084. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  11085. : textElementContent.isNotEmpty())
  11086. e->setText (textElementContent);
  11087. }
  11088. }
  11089. }
  11090. void XmlDocument::readEntity (String& result) throw()
  11091. {
  11092. // skip over the ampersand
  11093. ++input;
  11094. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  11095. {
  11096. input += 4;
  11097. result += T("&");
  11098. }
  11099. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  11100. {
  11101. input += 5;
  11102. result += T("\"");
  11103. }
  11104. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11105. {
  11106. input += 5;
  11107. result += T("\'");
  11108. }
  11109. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11110. {
  11111. input += 3;
  11112. result += T("<");
  11113. }
  11114. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11115. {
  11116. input += 3;
  11117. result += T(">");
  11118. }
  11119. else if (*input == T('#'))
  11120. {
  11121. int charCode = 0;
  11122. ++input;
  11123. if (*input == T('x') || *input == T('X'))
  11124. {
  11125. ++input;
  11126. int numChars = 0;
  11127. while (input[0] != T(';'))
  11128. {
  11129. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11130. if (hexValue < 0 || ++numChars > 8)
  11131. {
  11132. setLastError ("illegal escape sequence", true);
  11133. break;
  11134. }
  11135. charCode = (charCode << 4) | hexValue;
  11136. ++input;
  11137. }
  11138. ++input;
  11139. }
  11140. else if (input[0] >= T('0') && input[0] <= T('9'))
  11141. {
  11142. int numChars = 0;
  11143. while (input[0] != T(';'))
  11144. {
  11145. if (++numChars > 12)
  11146. {
  11147. setLastError ("illegal escape sequence", true);
  11148. break;
  11149. }
  11150. charCode = charCode * 10 + (input[0] - T('0'));
  11151. ++input;
  11152. }
  11153. ++input;
  11154. }
  11155. else
  11156. {
  11157. setLastError ("illegal escape sequence", true);
  11158. result += T("&");
  11159. return;
  11160. }
  11161. result << (tchar) charCode;
  11162. }
  11163. else
  11164. {
  11165. const tchar* const entityNameStart = input;
  11166. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11167. if (closingSemiColon == 0)
  11168. {
  11169. outOfData = true;
  11170. result += T("&");
  11171. }
  11172. else
  11173. {
  11174. input = closingSemiColon + 1;
  11175. result += expandExternalEntity (String (entityNameStart,
  11176. (int) (closingSemiColon - entityNameStart)));
  11177. }
  11178. }
  11179. }
  11180. const String XmlDocument::expandEntity (const String& ent)
  11181. {
  11182. if (ent.equalsIgnoreCase (T("amp")))
  11183. {
  11184. return T("&");
  11185. }
  11186. else if (ent.equalsIgnoreCase (T("quot")))
  11187. {
  11188. return T("\"");
  11189. }
  11190. else if (ent.equalsIgnoreCase (T("apos")))
  11191. {
  11192. return T("\'");
  11193. }
  11194. else if (ent.equalsIgnoreCase (T("lt")))
  11195. {
  11196. return T("<");
  11197. }
  11198. else if (ent.equalsIgnoreCase (T("gt")))
  11199. {
  11200. return T(">");
  11201. }
  11202. else if (ent[0] == T('#'))
  11203. {
  11204. if (ent[1] == T('x') || ent[1] == T('X'))
  11205. {
  11206. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11207. }
  11208. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11209. {
  11210. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11211. }
  11212. setLastError ("illegal escape sequence", false);
  11213. return T("&");
  11214. }
  11215. else
  11216. {
  11217. return expandExternalEntity (ent);
  11218. }
  11219. }
  11220. const String XmlDocument::expandExternalEntity (const String& entity)
  11221. {
  11222. if (needToLoadDTD)
  11223. {
  11224. if (dtdText.isNotEmpty())
  11225. {
  11226. while (dtdText.endsWithChar (T('>')))
  11227. dtdText = dtdText.dropLastCharacters (1);
  11228. tokenisedDTD.addTokens (dtdText, true);
  11229. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11230. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11231. {
  11232. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11233. tokenisedDTD.clear();
  11234. tokenisedDTD.addTokens (getFileContents (fn), true);
  11235. }
  11236. else
  11237. {
  11238. tokenisedDTD.clear();
  11239. const int openBracket = dtdText.indexOfChar (T('['));
  11240. if (openBracket > 0)
  11241. {
  11242. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11243. if (closeBracket > openBracket)
  11244. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11245. closeBracket), true);
  11246. }
  11247. }
  11248. for (int i = tokenisedDTD.size(); --i >= 0;)
  11249. {
  11250. if (tokenisedDTD[i].startsWithChar (T('%'))
  11251. && tokenisedDTD[i].endsWithChar (T(';')))
  11252. {
  11253. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11254. StringArray newToks;
  11255. newToks.addTokens (parsed, true);
  11256. tokenisedDTD.remove (i);
  11257. for (int j = newToks.size(); --j >= 0;)
  11258. tokenisedDTD.insert (i, newToks[j]);
  11259. }
  11260. }
  11261. }
  11262. needToLoadDTD = false;
  11263. }
  11264. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11265. {
  11266. if (tokenisedDTD[i] == entity)
  11267. {
  11268. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11269. {
  11270. String ent (tokenisedDTD [i + 1]);
  11271. while (ent.endsWithChar (T('>')))
  11272. ent = ent.dropLastCharacters (1);
  11273. ent = ent.trim().unquoted();
  11274. // check for sub-entities..
  11275. int ampersand = ent.indexOfChar (T('&'));
  11276. while (ampersand >= 0)
  11277. {
  11278. const int semiColon = ent.indexOf (i + 1, T(";"));
  11279. if (semiColon < 0)
  11280. {
  11281. setLastError ("entity without terminating semi-colon", false);
  11282. break;
  11283. }
  11284. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11285. ent = ent.substring (0, ampersand)
  11286. + resolved
  11287. + ent.substring (semiColon + 1);
  11288. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11289. }
  11290. return ent;
  11291. }
  11292. }
  11293. }
  11294. setLastError ("unknown entity", true);
  11295. return entity;
  11296. }
  11297. const String XmlDocument::getParameterEntity (const String& entity)
  11298. {
  11299. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11300. {
  11301. if (tokenisedDTD[i] == entity)
  11302. {
  11303. if (tokenisedDTD [i - 1] == T("%")
  11304. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11305. {
  11306. String ent (tokenisedDTD [i + 1]);
  11307. while (ent.endsWithChar (T('>')))
  11308. ent = ent.dropLastCharacters (1);
  11309. if (ent.equalsIgnoreCase (T("system")))
  11310. {
  11311. String filename (tokenisedDTD [i + 2]);
  11312. while (filename.endsWithChar (T('>')))
  11313. filename = filename.dropLastCharacters (1);
  11314. return getFileContents (filename);
  11315. }
  11316. else
  11317. {
  11318. return ent.trim().unquoted();
  11319. }
  11320. }
  11321. }
  11322. }
  11323. return entity;
  11324. }
  11325. END_JUCE_NAMESPACE
  11326. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11327. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11328. BEGIN_JUCE_NAMESPACE
  11329. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11330. : name (other.name),
  11331. value (other.value),
  11332. next (0)
  11333. {
  11334. }
  11335. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11336. const String& value_) throw()
  11337. : name (name_),
  11338. value (value_),
  11339. next (0)
  11340. {
  11341. }
  11342. XmlElement::XmlElement (const String& tagName_) throw()
  11343. : tagName (tagName_),
  11344. firstChildElement (0),
  11345. nextElement (0),
  11346. attributes (0)
  11347. {
  11348. // the tag name mustn't be empty, or it'll look like a text element!
  11349. jassert (tagName_.containsNonWhitespaceChars())
  11350. }
  11351. XmlElement::XmlElement (int /*dummy*/) throw()
  11352. : firstChildElement (0),
  11353. nextElement (0),
  11354. attributes (0)
  11355. {
  11356. }
  11357. XmlElement::XmlElement (const XmlElement& other) throw()
  11358. : tagName (other.tagName),
  11359. firstChildElement (0),
  11360. nextElement (0),
  11361. attributes (0)
  11362. {
  11363. copyChildrenAndAttributesFrom (other);
  11364. }
  11365. const XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11366. {
  11367. if (this != &other)
  11368. {
  11369. removeAllAttributes();
  11370. deleteAllChildElements();
  11371. tagName = other.tagName;
  11372. copyChildrenAndAttributesFrom (other);
  11373. }
  11374. return *this;
  11375. }
  11376. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11377. {
  11378. XmlElement* child = other.firstChildElement;
  11379. XmlElement* lastChild = 0;
  11380. while (child != 0)
  11381. {
  11382. XmlElement* const copiedChild = new XmlElement (*child);
  11383. if (lastChild != 0)
  11384. lastChild->nextElement = copiedChild;
  11385. else
  11386. firstChildElement = copiedChild;
  11387. lastChild = copiedChild;
  11388. child = child->nextElement;
  11389. }
  11390. const XmlAttributeNode* att = other.attributes;
  11391. XmlAttributeNode* lastAtt = 0;
  11392. while (att != 0)
  11393. {
  11394. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11395. if (lastAtt != 0)
  11396. lastAtt->next = newAtt;
  11397. else
  11398. attributes = newAtt;
  11399. lastAtt = newAtt;
  11400. att = att->next;
  11401. }
  11402. }
  11403. XmlElement::~XmlElement() throw()
  11404. {
  11405. XmlElement* child = firstChildElement;
  11406. while (child != 0)
  11407. {
  11408. XmlElement* const nextChild = child->nextElement;
  11409. delete child;
  11410. child = nextChild;
  11411. }
  11412. XmlAttributeNode* att = attributes;
  11413. while (att != 0)
  11414. {
  11415. XmlAttributeNode* const nextAtt = att->next;
  11416. delete att;
  11417. att = nextAtt;
  11418. }
  11419. }
  11420. static bool isLegalXmlChar (const juce_wchar character)
  11421. {
  11422. if ((character >= 'a' && character <= 'z')
  11423. || (character >= 'A' && character <= 'Z')
  11424. || (character >= '0' && character <= '9'))
  11425. return true;
  11426. const char* t = " .,;:-()_+=?!'#@[]/\\*%~{}";
  11427. do
  11428. {
  11429. if (((juce_wchar) (uint8) *t) == character)
  11430. return true;
  11431. }
  11432. while (*++t != 0);
  11433. return false;
  11434. }
  11435. static void escapeIllegalXmlChars (OutputStream& outputStream,
  11436. const String& text,
  11437. const bool changeNewLines) throw()
  11438. {
  11439. const juce_wchar* t = (const juce_wchar*) text;
  11440. for (;;)
  11441. {
  11442. const juce_wchar character = *t++;
  11443. if (character == 0)
  11444. {
  11445. break;
  11446. }
  11447. else if (isLegalXmlChar (character))
  11448. {
  11449. outputStream.writeByte ((char) character);
  11450. }
  11451. else
  11452. {
  11453. switch (character)
  11454. {
  11455. case '&':
  11456. outputStream.write ("&amp;", 5);
  11457. break;
  11458. case '"':
  11459. outputStream.write ("&quot;", 6);
  11460. break;
  11461. case '>':
  11462. outputStream.write ("&gt;", 4);
  11463. break;
  11464. case '<':
  11465. outputStream.write ("&lt;", 4);
  11466. break;
  11467. case '\n':
  11468. if (changeNewLines)
  11469. outputStream.write ("&#10;", 5);
  11470. else
  11471. outputStream.writeByte ((char) character);
  11472. break;
  11473. case '\r':
  11474. if (changeNewLines)
  11475. outputStream.write ("&#13;", 5);
  11476. else
  11477. outputStream.writeByte ((char) character);
  11478. break;
  11479. default:
  11480. {
  11481. String encoded (T("&#"));
  11482. encoded << String ((int) (unsigned int) character).trim()
  11483. << T(';');
  11484. outputStream.write ((const char*) encoded, encoded.length());
  11485. }
  11486. }
  11487. }
  11488. }
  11489. }
  11490. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11491. {
  11492. if (numSpaces > 0)
  11493. {
  11494. const char* const blanks = " ";
  11495. const int blankSize = (int) sizeof (blanks) - 1;
  11496. while (numSpaces > blankSize)
  11497. {
  11498. out.write (blanks, blankSize);
  11499. numSpaces -= blankSize;
  11500. }
  11501. out.write (blanks, numSpaces);
  11502. }
  11503. }
  11504. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11505. const int indentationLevel,
  11506. const int lineWrapLength) const throw()
  11507. {
  11508. writeSpaces (outputStream, indentationLevel);
  11509. if (! isTextElement())
  11510. {
  11511. outputStream.writeByte ('<');
  11512. const int nameLen = tagName.length();
  11513. outputStream.write ((const char*) tagName, nameLen);
  11514. const int attIndent = indentationLevel + nameLen + 1;
  11515. int lineLen = 0;
  11516. const XmlAttributeNode* att = attributes;
  11517. while (att != 0)
  11518. {
  11519. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11520. {
  11521. outputStream.write ("\r\n", 2);
  11522. writeSpaces (outputStream, attIndent);
  11523. lineLen = 0;
  11524. }
  11525. const int attNameLen = att->name.length();
  11526. outputStream.writeByte (' ');
  11527. outputStream.write ((const char*) (att->name), attNameLen);
  11528. outputStream.write ("=\"", 2);
  11529. escapeIllegalXmlChars (outputStream, att->value, true);
  11530. outputStream.writeByte ('"');
  11531. lineLen += 4 + attNameLen + att->value.length();
  11532. att = att->next;
  11533. }
  11534. if (firstChildElement != 0)
  11535. {
  11536. XmlElement* child = firstChildElement;
  11537. if (child->nextElement == 0 && child->isTextElement())
  11538. {
  11539. outputStream.writeByte ('>');
  11540. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11541. }
  11542. else
  11543. {
  11544. if (indentationLevel >= 0)
  11545. outputStream.write (">\r\n", 3);
  11546. else
  11547. outputStream.writeByte ('>');
  11548. bool lastWasTextNode = false;
  11549. while (child != 0)
  11550. {
  11551. if (child->isTextElement())
  11552. {
  11553. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11554. writeSpaces (outputStream, indentationLevel + 2);
  11555. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11556. lastWasTextNode = true;
  11557. }
  11558. else
  11559. {
  11560. if (indentationLevel >= 0)
  11561. {
  11562. if (lastWasTextNode)
  11563. outputStream.write ("\r\n", 2);
  11564. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11565. }
  11566. else
  11567. {
  11568. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11569. }
  11570. lastWasTextNode = false;
  11571. }
  11572. child = child->nextElement;
  11573. }
  11574. if (indentationLevel >= 0)
  11575. {
  11576. if (lastWasTextNode)
  11577. outputStream.write ("\r\n", 2);
  11578. writeSpaces (outputStream, indentationLevel);
  11579. }
  11580. }
  11581. outputStream.write ("</", 2);
  11582. outputStream.write ((const char*) tagName, nameLen);
  11583. if (indentationLevel >= 0)
  11584. outputStream.write (">\r\n", 3);
  11585. else
  11586. outputStream.writeByte ('>');
  11587. }
  11588. else
  11589. {
  11590. if (indentationLevel >= 0)
  11591. outputStream.write ("/>\r\n", 4);
  11592. else
  11593. outputStream.write ("/>", 2);
  11594. }
  11595. }
  11596. else
  11597. {
  11598. if (indentationLevel >= 0)
  11599. writeSpaces (outputStream, indentationLevel + 2);
  11600. escapeIllegalXmlChars (outputStream, getText(), false);
  11601. }
  11602. }
  11603. const String XmlElement::createDocument (const String& dtdToUse,
  11604. const bool allOnOneLine,
  11605. const bool includeXmlHeader,
  11606. const String& encodingType,
  11607. const int lineWrapLength) const throw()
  11608. {
  11609. MemoryOutputStream mem (2048, 4096);
  11610. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11611. return String (mem.getData(), mem.getDataSize());
  11612. }
  11613. void XmlElement::writeToStream (OutputStream& output,
  11614. const String& dtdToUse,
  11615. const bool allOnOneLine,
  11616. const bool includeXmlHeader,
  11617. const String& encodingType,
  11618. const int lineWrapLength) const throw()
  11619. {
  11620. if (includeXmlHeader)
  11621. {
  11622. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11623. if (allOnOneLine)
  11624. output << "\"?> ";
  11625. else
  11626. output << "\"?>\r\n\r\n";
  11627. }
  11628. if (dtdToUse.isNotEmpty())
  11629. {
  11630. output << dtdToUse;
  11631. if (allOnOneLine)
  11632. output << " ";
  11633. else
  11634. output << "\r\n";
  11635. }
  11636. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11637. }
  11638. bool XmlElement::writeToFile (const File& file,
  11639. const String& dtdToUse,
  11640. const String& encodingType,
  11641. const int lineWrapLength) const throw()
  11642. {
  11643. if (file.hasWriteAccess())
  11644. {
  11645. TemporaryFile tempFile (file);
  11646. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11647. if (out != 0)
  11648. {
  11649. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11650. out = 0;
  11651. return tempFile.overwriteTargetFileWithTemporary();
  11652. }
  11653. }
  11654. return false;
  11655. }
  11656. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11657. {
  11658. #ifdef JUCE_DEBUG
  11659. // if debugging, check that the case is actually the same, because
  11660. // valid xml is case-sensitive, and although this lets it pass, it's
  11661. // better not to..
  11662. if (tagName.equalsIgnoreCase (tagNameWanted))
  11663. {
  11664. jassert (tagName == tagNameWanted);
  11665. return true;
  11666. }
  11667. else
  11668. {
  11669. return false;
  11670. }
  11671. #else
  11672. return tagName.equalsIgnoreCase (tagNameWanted);
  11673. #endif
  11674. }
  11675. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11676. {
  11677. XmlElement* e = nextElement;
  11678. while (e != 0 && ! e->hasTagName (requiredTagName))
  11679. e = e->nextElement;
  11680. return e;
  11681. }
  11682. int XmlElement::getNumAttributes() const throw()
  11683. {
  11684. const XmlAttributeNode* att = attributes;
  11685. int count = 0;
  11686. while (att != 0)
  11687. {
  11688. att = att->next;
  11689. ++count;
  11690. }
  11691. return count;
  11692. }
  11693. const String& XmlElement::getAttributeName (const int index) const throw()
  11694. {
  11695. const XmlAttributeNode* att = attributes;
  11696. int count = 0;
  11697. while (att != 0)
  11698. {
  11699. if (count == index)
  11700. return att->name;
  11701. att = att->next;
  11702. ++count;
  11703. }
  11704. return String::empty;
  11705. }
  11706. const String& XmlElement::getAttributeValue (const int index) const throw()
  11707. {
  11708. const XmlAttributeNode* att = attributes;
  11709. int count = 0;
  11710. while (att != 0)
  11711. {
  11712. if (count == index)
  11713. return att->value;
  11714. att = att->next;
  11715. ++count;
  11716. }
  11717. return String::empty;
  11718. }
  11719. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11720. {
  11721. const XmlAttributeNode* att = attributes;
  11722. while (att != 0)
  11723. {
  11724. if (att->name.equalsIgnoreCase (attributeName))
  11725. return true;
  11726. att = att->next;
  11727. }
  11728. return false;
  11729. }
  11730. const String XmlElement::getStringAttribute (const String& attributeName,
  11731. const String& defaultReturnValue) const throw()
  11732. {
  11733. const XmlAttributeNode* att = attributes;
  11734. while (att != 0)
  11735. {
  11736. if (att->name.equalsIgnoreCase (attributeName))
  11737. return att->value;
  11738. att = att->next;
  11739. }
  11740. return defaultReturnValue;
  11741. }
  11742. int XmlElement::getIntAttribute (const String& attributeName,
  11743. const int defaultReturnValue) const throw()
  11744. {
  11745. const XmlAttributeNode* att = attributes;
  11746. while (att != 0)
  11747. {
  11748. if (att->name.equalsIgnoreCase (attributeName))
  11749. return att->value.getIntValue();
  11750. att = att->next;
  11751. }
  11752. return defaultReturnValue;
  11753. }
  11754. double XmlElement::getDoubleAttribute (const String& attributeName,
  11755. const double defaultReturnValue) const throw()
  11756. {
  11757. const XmlAttributeNode* att = attributes;
  11758. while (att != 0)
  11759. {
  11760. if (att->name.equalsIgnoreCase (attributeName))
  11761. return att->value.getDoubleValue();
  11762. att = att->next;
  11763. }
  11764. return defaultReturnValue;
  11765. }
  11766. bool XmlElement::getBoolAttribute (const String& attributeName,
  11767. const bool defaultReturnValue) const throw()
  11768. {
  11769. const XmlAttributeNode* att = attributes;
  11770. while (att != 0)
  11771. {
  11772. if (att->name.equalsIgnoreCase (attributeName))
  11773. {
  11774. tchar firstChar = att->value[0];
  11775. if (CharacterFunctions::isWhitespace (firstChar))
  11776. firstChar = att->value.trimStart() [0];
  11777. return firstChar == T('1')
  11778. || firstChar == T('t')
  11779. || firstChar == T('y')
  11780. || firstChar == T('T')
  11781. || firstChar == T('Y');
  11782. }
  11783. att = att->next;
  11784. }
  11785. return defaultReturnValue;
  11786. }
  11787. bool XmlElement::compareAttribute (const String& attributeName,
  11788. const String& stringToCompareAgainst,
  11789. const bool ignoreCase) const throw()
  11790. {
  11791. const XmlAttributeNode* att = attributes;
  11792. while (att != 0)
  11793. {
  11794. if (att->name.equalsIgnoreCase (attributeName))
  11795. {
  11796. if (ignoreCase)
  11797. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11798. else
  11799. return att->value == stringToCompareAgainst;
  11800. }
  11801. att = att->next;
  11802. }
  11803. return false;
  11804. }
  11805. void XmlElement::setAttribute (const String& attributeName,
  11806. const String& value) throw()
  11807. {
  11808. #ifdef JUCE_DEBUG
  11809. // check the identifier being passed in is legal..
  11810. const tchar* t = attributeName;
  11811. while (*t != 0)
  11812. {
  11813. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11814. || *t == T('_')
  11815. || *t == T('-')
  11816. || *t == T(':'));
  11817. ++t;
  11818. }
  11819. #endif
  11820. if (attributes == 0)
  11821. {
  11822. attributes = new XmlAttributeNode (attributeName, value);
  11823. }
  11824. else
  11825. {
  11826. XmlAttributeNode* att = attributes;
  11827. for (;;)
  11828. {
  11829. if (att->name.equalsIgnoreCase (attributeName))
  11830. {
  11831. att->value = value;
  11832. break;
  11833. }
  11834. else if (att->next == 0)
  11835. {
  11836. att->next = new XmlAttributeNode (attributeName, value);
  11837. break;
  11838. }
  11839. att = att->next;
  11840. }
  11841. }
  11842. }
  11843. void XmlElement::setAttribute (const String& attributeName,
  11844. const int number) throw()
  11845. {
  11846. setAttribute (attributeName, String (number));
  11847. }
  11848. void XmlElement::setAttribute (const String& attributeName,
  11849. const double number) throw()
  11850. {
  11851. setAttribute (attributeName, String (number));
  11852. }
  11853. void XmlElement::removeAttribute (const String& attributeName) throw()
  11854. {
  11855. XmlAttributeNode* att = attributes;
  11856. XmlAttributeNode* lastAtt = 0;
  11857. while (att != 0)
  11858. {
  11859. if (att->name.equalsIgnoreCase (attributeName))
  11860. {
  11861. if (lastAtt == 0)
  11862. attributes = att->next;
  11863. else
  11864. lastAtt->next = att->next;
  11865. delete att;
  11866. break;
  11867. }
  11868. lastAtt = att;
  11869. att = att->next;
  11870. }
  11871. }
  11872. void XmlElement::removeAllAttributes() throw()
  11873. {
  11874. while (attributes != 0)
  11875. {
  11876. XmlAttributeNode* const nextAtt = attributes->next;
  11877. delete attributes;
  11878. attributes = nextAtt;
  11879. }
  11880. }
  11881. int XmlElement::getNumChildElements() const throw()
  11882. {
  11883. int count = 0;
  11884. const XmlElement* child = firstChildElement;
  11885. while (child != 0)
  11886. {
  11887. ++count;
  11888. child = child->nextElement;
  11889. }
  11890. return count;
  11891. }
  11892. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11893. {
  11894. int count = 0;
  11895. XmlElement* child = firstChildElement;
  11896. while (child != 0 && count < index)
  11897. {
  11898. child = child->nextElement;
  11899. ++count;
  11900. }
  11901. return child;
  11902. }
  11903. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11904. {
  11905. XmlElement* child = firstChildElement;
  11906. while (child != 0)
  11907. {
  11908. if (child->hasTagName (childName))
  11909. break;
  11910. child = child->nextElement;
  11911. }
  11912. return child;
  11913. }
  11914. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11915. {
  11916. if (newNode != 0)
  11917. {
  11918. if (firstChildElement == 0)
  11919. {
  11920. firstChildElement = newNode;
  11921. }
  11922. else
  11923. {
  11924. XmlElement* child = firstChildElement;
  11925. while (child->nextElement != 0)
  11926. child = child->nextElement;
  11927. child->nextElement = newNode;
  11928. // if this is non-zero, then something's probably
  11929. // gone wrong..
  11930. jassert (newNode->nextElement == 0);
  11931. }
  11932. }
  11933. }
  11934. void XmlElement::insertChildElement (XmlElement* const newNode,
  11935. int indexToInsertAt) throw()
  11936. {
  11937. if (newNode != 0)
  11938. {
  11939. removeChildElement (newNode, false);
  11940. if (indexToInsertAt == 0)
  11941. {
  11942. newNode->nextElement = firstChildElement;
  11943. firstChildElement = newNode;
  11944. }
  11945. else
  11946. {
  11947. if (firstChildElement == 0)
  11948. {
  11949. firstChildElement = newNode;
  11950. }
  11951. else
  11952. {
  11953. if (indexToInsertAt < 0)
  11954. indexToInsertAt = std::numeric_limits<int>::max();
  11955. XmlElement* child = firstChildElement;
  11956. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11957. child = child->nextElement;
  11958. newNode->nextElement = child->nextElement;
  11959. child->nextElement = newNode;
  11960. }
  11961. }
  11962. }
  11963. }
  11964. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11965. {
  11966. XmlElement* const newElement = new XmlElement (tagName);
  11967. addChildElement (newElement);
  11968. return newElement;
  11969. }
  11970. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11971. XmlElement* const newNode) throw()
  11972. {
  11973. if (newNode != 0)
  11974. {
  11975. XmlElement* child = firstChildElement;
  11976. XmlElement* previousNode = 0;
  11977. while (child != 0)
  11978. {
  11979. if (child == currentChildElement)
  11980. {
  11981. if (child != newNode)
  11982. {
  11983. if (previousNode == 0)
  11984. firstChildElement = newNode;
  11985. else
  11986. previousNode->nextElement = newNode;
  11987. newNode->nextElement = child->nextElement;
  11988. delete child;
  11989. }
  11990. return true;
  11991. }
  11992. previousNode = child;
  11993. child = child->nextElement;
  11994. }
  11995. }
  11996. return false;
  11997. }
  11998. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11999. const bool shouldDeleteTheChild) throw()
  12000. {
  12001. if (childToRemove != 0)
  12002. {
  12003. if (firstChildElement == childToRemove)
  12004. {
  12005. firstChildElement = childToRemove->nextElement;
  12006. childToRemove->nextElement = 0;
  12007. }
  12008. else
  12009. {
  12010. XmlElement* child = firstChildElement;
  12011. XmlElement* last = 0;
  12012. while (child != 0)
  12013. {
  12014. if (child == childToRemove)
  12015. {
  12016. if (last == 0)
  12017. firstChildElement = child->nextElement;
  12018. else
  12019. last->nextElement = child->nextElement;
  12020. childToRemove->nextElement = 0;
  12021. break;
  12022. }
  12023. last = child;
  12024. child = child->nextElement;
  12025. }
  12026. }
  12027. if (shouldDeleteTheChild)
  12028. delete childToRemove;
  12029. }
  12030. }
  12031. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  12032. const bool ignoreOrderOfAttributes) const throw()
  12033. {
  12034. if (this != other)
  12035. {
  12036. if (other == 0 || tagName != other->tagName)
  12037. {
  12038. return false;
  12039. }
  12040. if (ignoreOrderOfAttributes)
  12041. {
  12042. int totalAtts = 0;
  12043. const XmlAttributeNode* att = attributes;
  12044. while (att != 0)
  12045. {
  12046. if (! other->compareAttribute (att->name, att->value))
  12047. return false;
  12048. att = att->next;
  12049. ++totalAtts;
  12050. }
  12051. if (totalAtts != other->getNumAttributes())
  12052. return false;
  12053. }
  12054. else
  12055. {
  12056. const XmlAttributeNode* thisAtt = attributes;
  12057. const XmlAttributeNode* otherAtt = other->attributes;
  12058. for (;;)
  12059. {
  12060. if (thisAtt == 0 || otherAtt == 0)
  12061. {
  12062. if (thisAtt == otherAtt) // both 0, so it's a match
  12063. break;
  12064. return false;
  12065. }
  12066. if (thisAtt->name != otherAtt->name
  12067. || thisAtt->value != otherAtt->value)
  12068. {
  12069. return false;
  12070. }
  12071. thisAtt = thisAtt->next;
  12072. otherAtt = otherAtt->next;
  12073. }
  12074. }
  12075. const XmlElement* thisChild = firstChildElement;
  12076. const XmlElement* otherChild = other->firstChildElement;
  12077. for (;;)
  12078. {
  12079. if (thisChild == 0 || otherChild == 0)
  12080. {
  12081. if (thisChild == otherChild) // both 0, so it's a match
  12082. break;
  12083. return false;
  12084. }
  12085. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  12086. return false;
  12087. thisChild = thisChild->nextElement;
  12088. otherChild = otherChild->nextElement;
  12089. }
  12090. }
  12091. return true;
  12092. }
  12093. void XmlElement::deleteAllChildElements() throw()
  12094. {
  12095. while (firstChildElement != 0)
  12096. {
  12097. XmlElement* const nextChild = firstChildElement->nextElement;
  12098. delete firstChildElement;
  12099. firstChildElement = nextChild;
  12100. }
  12101. }
  12102. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  12103. {
  12104. XmlElement* child = firstChildElement;
  12105. while (child != 0)
  12106. {
  12107. if (child->hasTagName (name))
  12108. {
  12109. XmlElement* const nextChild = child->nextElement;
  12110. removeChildElement (child, true);
  12111. child = nextChild;
  12112. }
  12113. else
  12114. {
  12115. child = child->nextElement;
  12116. }
  12117. }
  12118. }
  12119. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12120. {
  12121. const XmlElement* child = firstChildElement;
  12122. while (child != 0)
  12123. {
  12124. if (child == possibleChild)
  12125. return true;
  12126. child = child->nextElement;
  12127. }
  12128. return false;
  12129. }
  12130. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12131. {
  12132. if (this == elementToLookFor || elementToLookFor == 0)
  12133. return 0;
  12134. XmlElement* child = firstChildElement;
  12135. while (child != 0)
  12136. {
  12137. if (elementToLookFor == child)
  12138. return this;
  12139. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12140. if (found != 0)
  12141. return found;
  12142. child = child->nextElement;
  12143. }
  12144. return 0;
  12145. }
  12146. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12147. {
  12148. XmlElement* e = firstChildElement;
  12149. while (e != 0)
  12150. {
  12151. *elems++ = e;
  12152. e = e->nextElement;
  12153. }
  12154. }
  12155. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12156. {
  12157. XmlElement* e = firstChildElement = elems[0];
  12158. for (int i = 1; i < num; ++i)
  12159. {
  12160. e->nextElement = elems[i];
  12161. e = e->nextElement;
  12162. }
  12163. e->nextElement = 0;
  12164. }
  12165. bool XmlElement::isTextElement() const throw()
  12166. {
  12167. return tagName.isEmpty();
  12168. }
  12169. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12170. const String XmlElement::getText() const throw()
  12171. {
  12172. jassert (isTextElement()); // you're trying to get the text from an element that
  12173. // isn't actually a text element.. If this contains text sub-nodes, you
  12174. // probably want to use getAllSubText instead.
  12175. return getStringAttribute (juce_xmltextContentAttributeName);
  12176. }
  12177. void XmlElement::setText (const String& newText) throw()
  12178. {
  12179. if (isTextElement())
  12180. {
  12181. setAttribute (juce_xmltextContentAttributeName, newText);
  12182. }
  12183. else
  12184. {
  12185. jassertfalse // you can only change the text in a text element, not a normal one.
  12186. }
  12187. }
  12188. const String XmlElement::getAllSubText() const throw()
  12189. {
  12190. String result;
  12191. String::Concatenator concatenator (result);
  12192. const XmlElement* child = firstChildElement;
  12193. while (child != 0)
  12194. {
  12195. if (child->isTextElement())
  12196. concatenator.append (child->getText());
  12197. child = child->nextElement;
  12198. }
  12199. return result;
  12200. }
  12201. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  12202. const String& defaultReturnValue) const throw()
  12203. {
  12204. const XmlElement* const child = getChildByName (childTagName);
  12205. if (child != 0)
  12206. return child->getAllSubText();
  12207. return defaultReturnValue;
  12208. }
  12209. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12210. {
  12211. XmlElement* const e = new XmlElement ((int) 0);
  12212. e->setAttribute (juce_xmltextContentAttributeName, text);
  12213. return e;
  12214. }
  12215. void XmlElement::addTextElement (const String& text) throw()
  12216. {
  12217. addChildElement (createTextElement (text));
  12218. }
  12219. void XmlElement::deleteAllTextElements() throw()
  12220. {
  12221. XmlElement* child = firstChildElement;
  12222. while (child != 0)
  12223. {
  12224. XmlElement* const next = child->nextElement;
  12225. if (child->isTextElement())
  12226. removeChildElement (child, true);
  12227. child = next;
  12228. }
  12229. }
  12230. END_JUCE_NAMESPACE
  12231. /*** End of inlined file: juce_XmlElement.cpp ***/
  12232. /*** Start of inlined file: juce_InterProcessLock.cpp ***/
  12233. BEGIN_JUCE_NAMESPACE
  12234. // (implemented in the platform-specific code files)
  12235. END_JUCE_NAMESPACE
  12236. /*** End of inlined file: juce_InterProcessLock.cpp ***/
  12237. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  12238. BEGIN_JUCE_NAMESPACE
  12239. ReadWriteLock::ReadWriteLock() throw()
  12240. : numWaitingWriters (0),
  12241. numWriters (0),
  12242. writerThreadId (0)
  12243. {
  12244. }
  12245. ReadWriteLock::~ReadWriteLock() throw()
  12246. {
  12247. jassert (readerThreads.size() == 0);
  12248. jassert (numWriters == 0);
  12249. }
  12250. void ReadWriteLock::enterRead() const throw()
  12251. {
  12252. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12253. const ScopedLock sl (accessLock);
  12254. for (;;)
  12255. {
  12256. jassert (readerThreads.size() % 2 == 0);
  12257. int i;
  12258. for (i = 0; i < readerThreads.size(); i += 2)
  12259. if (readerThreads.getUnchecked(i) == threadId)
  12260. break;
  12261. if (i < readerThreads.size()
  12262. || numWriters + numWaitingWriters == 0
  12263. || (threadId == writerThreadId && numWriters > 0))
  12264. {
  12265. if (i < readerThreads.size())
  12266. {
  12267. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12268. }
  12269. else
  12270. {
  12271. readerThreads.add (threadId);
  12272. readerThreads.add ((Thread::ThreadID) 1);
  12273. }
  12274. return;
  12275. }
  12276. const ScopedUnlock ul (accessLock);
  12277. waitEvent.wait (100);
  12278. }
  12279. }
  12280. void ReadWriteLock::exitRead() const throw()
  12281. {
  12282. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12283. const ScopedLock sl (accessLock);
  12284. for (int i = 0; i < readerThreads.size(); i += 2)
  12285. {
  12286. if (readerThreads.getUnchecked(i) == threadId)
  12287. {
  12288. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12289. if (newCount == 0)
  12290. {
  12291. readerThreads.removeRange (i, 2);
  12292. waitEvent.signal();
  12293. }
  12294. else
  12295. {
  12296. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12297. }
  12298. return;
  12299. }
  12300. }
  12301. jassertfalse // unlocking a lock that wasn't locked..
  12302. }
  12303. void ReadWriteLock::enterWrite() const throw()
  12304. {
  12305. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12306. const ScopedLock sl (accessLock);
  12307. for (;;)
  12308. {
  12309. if (readerThreads.size() + numWriters == 0
  12310. || threadId == writerThreadId
  12311. || (readerThreads.size() == 2
  12312. && readerThreads.getUnchecked(0) == threadId))
  12313. {
  12314. writerThreadId = threadId;
  12315. ++numWriters;
  12316. break;
  12317. }
  12318. ++numWaitingWriters;
  12319. accessLock.exit();
  12320. waitEvent.wait (100);
  12321. accessLock.enter();
  12322. --numWaitingWriters;
  12323. }
  12324. }
  12325. bool ReadWriteLock::tryEnterWrite() const throw()
  12326. {
  12327. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12328. const ScopedLock sl (accessLock);
  12329. if (readerThreads.size() + numWriters == 0
  12330. || threadId == writerThreadId
  12331. || (readerThreads.size() == 2
  12332. && readerThreads.getUnchecked(0) == threadId))
  12333. {
  12334. writerThreadId = threadId;
  12335. ++numWriters;
  12336. return true;
  12337. }
  12338. return false;
  12339. }
  12340. void ReadWriteLock::exitWrite() const throw()
  12341. {
  12342. const ScopedLock sl (accessLock);
  12343. // check this thread actually had the lock..
  12344. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12345. if (--numWriters == 0)
  12346. {
  12347. writerThreadId = 0;
  12348. waitEvent.signal();
  12349. }
  12350. }
  12351. END_JUCE_NAMESPACE
  12352. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12353. /*** Start of inlined file: juce_Thread.cpp ***/
  12354. BEGIN_JUCE_NAMESPACE
  12355. // these functions are implemented in the platform-specific code.
  12356. void* juce_createThread (void* userData);
  12357. void juce_killThread (void* handle);
  12358. bool juce_setThreadPriority (void* handle, int priority);
  12359. void juce_setCurrentThreadName (const String& name);
  12360. #if JUCE_WIN32
  12361. void juce_CloseThreadHandle (void* handle);
  12362. #endif
  12363. static VoidArray runningThreads;
  12364. static CriticalSection runningThreadsLock;
  12365. void Thread::threadEntryPoint (Thread* const thread)
  12366. {
  12367. {
  12368. const ScopedLock sl (runningThreadsLock);
  12369. runningThreads.add (thread);
  12370. }
  12371. JUCE_TRY
  12372. {
  12373. thread->threadId_ = Thread::getCurrentThreadId();
  12374. if (thread->threadName_.isNotEmpty())
  12375. juce_setCurrentThreadName (thread->threadName_);
  12376. if (thread->startSuspensionEvent_.wait (10000))
  12377. {
  12378. if (thread->affinityMask_ != 0)
  12379. setCurrentThreadAffinityMask (thread->affinityMask_);
  12380. thread->run();
  12381. }
  12382. }
  12383. JUCE_CATCH_ALL_ASSERT
  12384. {
  12385. const ScopedLock sl (runningThreadsLock);
  12386. jassert (runningThreads.contains (thread));
  12387. runningThreads.removeValue (thread);
  12388. }
  12389. #if JUCE_WIN32
  12390. juce_CloseThreadHandle (thread->threadHandle_);
  12391. #endif
  12392. thread->threadHandle_ = 0;
  12393. thread->threadId_ = 0;
  12394. }
  12395. // used to wrap the incoming call from the platform-specific code
  12396. void JUCE_API juce_threadEntryPoint (void* userData)
  12397. {
  12398. Thread::threadEntryPoint ((Thread*) userData);
  12399. }
  12400. Thread::Thread (const String& threadName)
  12401. : threadName_ (threadName),
  12402. threadHandle_ (0),
  12403. threadPriority_ (5),
  12404. threadId_ (0),
  12405. affinityMask_ (0),
  12406. threadShouldExit_ (false)
  12407. {
  12408. }
  12409. Thread::~Thread()
  12410. {
  12411. stopThread (100);
  12412. }
  12413. void Thread::startThread()
  12414. {
  12415. const ScopedLock sl (startStopLock);
  12416. threadShouldExit_ = false;
  12417. if (threadHandle_ == 0)
  12418. {
  12419. threadHandle_ = juce_createThread ((void*) this);
  12420. juce_setThreadPriority (threadHandle_, threadPriority_);
  12421. startSuspensionEvent_.signal();
  12422. }
  12423. }
  12424. void Thread::startThread (const int priority)
  12425. {
  12426. const ScopedLock sl (startStopLock);
  12427. if (threadHandle_ == 0)
  12428. {
  12429. threadPriority_ = priority;
  12430. startThread();
  12431. }
  12432. else
  12433. {
  12434. setPriority (priority);
  12435. }
  12436. }
  12437. bool Thread::isThreadRunning() const
  12438. {
  12439. return threadHandle_ != 0;
  12440. }
  12441. void Thread::signalThreadShouldExit()
  12442. {
  12443. threadShouldExit_ = true;
  12444. }
  12445. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12446. {
  12447. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12448. jassert (getThreadId() != getCurrentThreadId());
  12449. const int sleepMsPerIteration = 5;
  12450. int count = timeOutMilliseconds / sleepMsPerIteration;
  12451. while (isThreadRunning())
  12452. {
  12453. if (timeOutMilliseconds > 0 && --count < 0)
  12454. return false;
  12455. sleep (sleepMsPerIteration);
  12456. }
  12457. return true;
  12458. }
  12459. void Thread::stopThread (const int timeOutMilliseconds)
  12460. {
  12461. // agh! You can't stop the thread that's calling this method! How on earth
  12462. // would that work??
  12463. jassert (getCurrentThreadId() != getThreadId());
  12464. const ScopedLock sl (startStopLock);
  12465. if (isThreadRunning())
  12466. {
  12467. signalThreadShouldExit();
  12468. notify();
  12469. if (timeOutMilliseconds != 0)
  12470. waitForThreadToExit (timeOutMilliseconds);
  12471. if (isThreadRunning())
  12472. {
  12473. // very bad karma if this point is reached, as
  12474. // there are bound to be locks and events left in
  12475. // silly states when a thread is killed by force..
  12476. jassertfalse
  12477. Logger::writeToLog ("!! killing thread by force !!");
  12478. juce_killThread (threadHandle_);
  12479. threadHandle_ = 0;
  12480. threadId_ = 0;
  12481. const ScopedLock sl2 (runningThreadsLock);
  12482. runningThreads.removeValue (this);
  12483. }
  12484. }
  12485. }
  12486. bool Thread::setPriority (const int priority)
  12487. {
  12488. const ScopedLock sl (startStopLock);
  12489. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12490. if (worked)
  12491. threadPriority_ = priority;
  12492. return worked;
  12493. }
  12494. bool Thread::setCurrentThreadPriority (const int priority)
  12495. {
  12496. return juce_setThreadPriority (0, priority);
  12497. }
  12498. void Thread::setAffinityMask (const uint32 affinityMask)
  12499. {
  12500. affinityMask_ = affinityMask;
  12501. }
  12502. bool Thread::wait (const int timeOutMilliseconds) const
  12503. {
  12504. return defaultEvent_.wait (timeOutMilliseconds);
  12505. }
  12506. void Thread::notify() const
  12507. {
  12508. defaultEvent_.signal();
  12509. }
  12510. int Thread::getNumRunningThreads()
  12511. {
  12512. return runningThreads.size();
  12513. }
  12514. Thread* Thread::getCurrentThread()
  12515. {
  12516. const ThreadID thisId = getCurrentThreadId();
  12517. const ScopedLock sl (runningThreadsLock);
  12518. for (int i = runningThreads.size(); --i >= 0;)
  12519. {
  12520. Thread* const t = (Thread*) runningThreads.getUnchecked(i);
  12521. if (t->threadId_ == thisId)
  12522. return t;
  12523. }
  12524. return 0;
  12525. }
  12526. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12527. {
  12528. {
  12529. const ScopedLock sl (runningThreadsLock);
  12530. for (int i = runningThreads.size(); --i >= 0;)
  12531. ((Thread*) runningThreads.getUnchecked(i))->signalThreadShouldExit();
  12532. }
  12533. for (;;)
  12534. {
  12535. runningThreadsLock.enter();
  12536. Thread* const t = (Thread*) runningThreads[0];
  12537. runningThreadsLock.exit();
  12538. if (t == 0)
  12539. break;
  12540. t->stopThread (timeOutMilliseconds);
  12541. }
  12542. }
  12543. END_JUCE_NAMESPACE
  12544. /*** End of inlined file: juce_Thread.cpp ***/
  12545. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12546. BEGIN_JUCE_NAMESPACE
  12547. ThreadPoolJob::ThreadPoolJob (const String& name)
  12548. : jobName (name),
  12549. pool (0),
  12550. shouldStop (false),
  12551. isActive (false),
  12552. shouldBeDeleted (false)
  12553. {
  12554. }
  12555. ThreadPoolJob::~ThreadPoolJob()
  12556. {
  12557. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12558. // to remove it first!
  12559. jassert (pool == 0 || ! pool->contains (this));
  12560. }
  12561. const String ThreadPoolJob::getJobName() const
  12562. {
  12563. return jobName;
  12564. }
  12565. void ThreadPoolJob::setJobName (const String& newName)
  12566. {
  12567. jobName = newName;
  12568. }
  12569. void ThreadPoolJob::signalJobShouldExit()
  12570. {
  12571. shouldStop = true;
  12572. }
  12573. class ThreadPool::ThreadPoolThread : public Thread
  12574. {
  12575. public:
  12576. ThreadPoolThread (ThreadPool& pool_)
  12577. : Thread (T("Pool")),
  12578. pool (pool_),
  12579. busy (false)
  12580. {
  12581. }
  12582. ~ThreadPoolThread()
  12583. {
  12584. }
  12585. void run()
  12586. {
  12587. while (! threadShouldExit())
  12588. {
  12589. if (! pool.runNextJob())
  12590. wait (500);
  12591. }
  12592. }
  12593. private:
  12594. ThreadPool& pool;
  12595. bool volatile busy;
  12596. ThreadPoolThread (const ThreadPoolThread&);
  12597. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12598. };
  12599. ThreadPool::ThreadPool (const int numThreads,
  12600. const bool startThreadsOnlyWhenNeeded,
  12601. const int stopThreadsWhenNotUsedTimeoutMs)
  12602. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12603. priority (5)
  12604. {
  12605. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12606. for (int i = jmax (1, numThreads); --i >= 0;)
  12607. threads.add (new ThreadPoolThread (*this));
  12608. if (! startThreadsOnlyWhenNeeded)
  12609. for (int i = threads.size(); --i >= 0;)
  12610. threads.getUnchecked(i)->startThread (priority);
  12611. }
  12612. ThreadPool::~ThreadPool()
  12613. {
  12614. removeAllJobs (true, 4000);
  12615. int i;
  12616. for (i = threads.size(); --i >= 0;)
  12617. threads.getUnchecked(i)->signalThreadShouldExit();
  12618. for (i = threads.size(); --i >= 0;)
  12619. threads.getUnchecked(i)->stopThread (500);
  12620. }
  12621. void ThreadPool::addJob (ThreadPoolJob* const job)
  12622. {
  12623. jassert (job != 0);
  12624. jassert (job->pool == 0);
  12625. if (job->pool == 0)
  12626. {
  12627. job->pool = this;
  12628. job->shouldStop = false;
  12629. job->isActive = false;
  12630. {
  12631. const ScopedLock sl (lock);
  12632. jobs.add (job);
  12633. int numRunning = 0;
  12634. for (int i = threads.size(); --i >= 0;)
  12635. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12636. ++numRunning;
  12637. if (numRunning < threads.size())
  12638. {
  12639. bool startedOne = false;
  12640. int n = 1000;
  12641. while (--n >= 0 && ! startedOne)
  12642. {
  12643. for (int i = threads.size(); --i >= 0;)
  12644. {
  12645. if (! threads.getUnchecked(i)->isThreadRunning())
  12646. {
  12647. threads.getUnchecked(i)->startThread (priority);
  12648. startedOne = true;
  12649. break;
  12650. }
  12651. }
  12652. if (! startedOne)
  12653. Thread::sleep (2);
  12654. }
  12655. }
  12656. }
  12657. for (int i = threads.size(); --i >= 0;)
  12658. threads.getUnchecked(i)->notify();
  12659. }
  12660. }
  12661. int ThreadPool::getNumJobs() const
  12662. {
  12663. return jobs.size();
  12664. }
  12665. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12666. {
  12667. const ScopedLock sl (lock);
  12668. return (ThreadPoolJob*) jobs [index];
  12669. }
  12670. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12671. {
  12672. const ScopedLock sl (lock);
  12673. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12674. }
  12675. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12676. {
  12677. const ScopedLock sl (lock);
  12678. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12679. }
  12680. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12681. const int timeOutMs) const
  12682. {
  12683. if (job != 0)
  12684. {
  12685. const uint32 start = Time::getMillisecondCounter();
  12686. while (contains (job))
  12687. {
  12688. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12689. return false;
  12690. jobFinishedSignal.wait (2);
  12691. }
  12692. }
  12693. return true;
  12694. }
  12695. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12696. const bool interruptIfRunning,
  12697. const int timeOutMs)
  12698. {
  12699. if (job != 0)
  12700. {
  12701. lock.enter();
  12702. if (jobs.contains (job))
  12703. {
  12704. if (job->isActive)
  12705. {
  12706. if (interruptIfRunning)
  12707. job->signalJobShouldExit();
  12708. lock.exit();
  12709. return waitForJobToFinish (job, timeOutMs);
  12710. }
  12711. else
  12712. {
  12713. jobs.removeValue (job);
  12714. }
  12715. }
  12716. lock.exit();
  12717. }
  12718. return true;
  12719. }
  12720. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12721. const int timeOutMs,
  12722. const bool deleteInactiveJobs,
  12723. ThreadPool::JobSelector* selectedJobsToRemove)
  12724. {
  12725. Array <ThreadPoolJob*> jobsToWaitFor;
  12726. {
  12727. const ScopedLock sl (lock);
  12728. for (int i = jobs.size(); --i >= 0;)
  12729. {
  12730. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12731. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12732. {
  12733. if (job->isActive)
  12734. {
  12735. jobsToWaitFor.add (job);
  12736. if (interruptRunningJobs)
  12737. job->signalJobShouldExit();
  12738. }
  12739. else
  12740. {
  12741. jobs.remove (i);
  12742. if (deleteInactiveJobs)
  12743. delete job;
  12744. }
  12745. }
  12746. }
  12747. }
  12748. const uint32 start = Time::getMillisecondCounter();
  12749. for (;;)
  12750. {
  12751. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12752. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12753. jobsToWaitFor.remove (i);
  12754. if (jobsToWaitFor.size() == 0)
  12755. break;
  12756. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12757. return false;
  12758. jobFinishedSignal.wait (20);
  12759. }
  12760. return true;
  12761. }
  12762. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12763. {
  12764. StringArray s;
  12765. const ScopedLock sl (lock);
  12766. for (int i = 0; i < jobs.size(); ++i)
  12767. {
  12768. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12769. if (job->isActive || ! onlyReturnActiveJobs)
  12770. s.add (job->getJobName());
  12771. }
  12772. return s;
  12773. }
  12774. bool ThreadPool::setThreadPriorities (const int newPriority)
  12775. {
  12776. bool ok = true;
  12777. if (priority != newPriority)
  12778. {
  12779. priority = newPriority;
  12780. for (int i = threads.size(); --i >= 0;)
  12781. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12782. ok = false;
  12783. }
  12784. return ok;
  12785. }
  12786. bool ThreadPool::runNextJob()
  12787. {
  12788. ThreadPoolJob* job = 0;
  12789. {
  12790. const ScopedLock sl (lock);
  12791. for (int i = 0; i < jobs.size(); ++i)
  12792. {
  12793. job = jobs[i];
  12794. if (job != 0 && ! (job->isActive || job->shouldStop))
  12795. break;
  12796. job = 0;
  12797. }
  12798. if (job != 0)
  12799. job->isActive = true;
  12800. }
  12801. if (job != 0)
  12802. {
  12803. JUCE_TRY
  12804. {
  12805. ThreadPoolJob::JobStatus result = job->runJob();
  12806. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12807. const ScopedLock sl (lock);
  12808. if (jobs.contains (job))
  12809. {
  12810. job->isActive = false;
  12811. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12812. {
  12813. job->pool = 0;
  12814. job->shouldStop = true;
  12815. jobs.removeValue (job);
  12816. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12817. delete job;
  12818. jobFinishedSignal.signal();
  12819. }
  12820. else
  12821. {
  12822. // move the job to the end of the queue if it wants another go
  12823. jobs.move (jobs.indexOf (job), -1);
  12824. }
  12825. }
  12826. }
  12827. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12828. catch (...)
  12829. {
  12830. const ScopedLock sl (lock);
  12831. jobs.removeValue (job);
  12832. }
  12833. #endif
  12834. }
  12835. else
  12836. {
  12837. if (threadStopTimeout > 0
  12838. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12839. {
  12840. const ScopedLock sl (lock);
  12841. if (jobs.size() == 0)
  12842. for (int i = threads.size(); --i >= 0;)
  12843. threads.getUnchecked(i)->signalThreadShouldExit();
  12844. }
  12845. else
  12846. {
  12847. return false;
  12848. }
  12849. }
  12850. return true;
  12851. }
  12852. END_JUCE_NAMESPACE
  12853. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12854. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12855. BEGIN_JUCE_NAMESPACE
  12856. TimeSliceThread::TimeSliceThread (const String& threadName)
  12857. : Thread (threadName),
  12858. index (0),
  12859. clientBeingCalled (0),
  12860. clientsChanged (false)
  12861. {
  12862. }
  12863. TimeSliceThread::~TimeSliceThread()
  12864. {
  12865. stopThread (2000);
  12866. }
  12867. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12868. {
  12869. const ScopedLock sl (listLock);
  12870. clients.addIfNotAlreadyThere (client);
  12871. clientsChanged = true;
  12872. notify();
  12873. }
  12874. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12875. {
  12876. const ScopedLock sl1 (listLock);
  12877. clientsChanged = true;
  12878. // if there's a chance we're in the middle of calling this client, we need to
  12879. // also lock the outer lock..
  12880. if (clientBeingCalled == client)
  12881. {
  12882. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12883. const ScopedLock sl2 (callbackLock);
  12884. const ScopedLock sl3 (listLock);
  12885. clients.removeValue (client);
  12886. }
  12887. else
  12888. {
  12889. clients.removeValue (client);
  12890. }
  12891. }
  12892. int TimeSliceThread::getNumClients() const
  12893. {
  12894. return clients.size();
  12895. }
  12896. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12897. {
  12898. const ScopedLock sl (listLock);
  12899. return clients [i];
  12900. }
  12901. void TimeSliceThread::run()
  12902. {
  12903. int numCallsSinceBusy = 0;
  12904. while (! threadShouldExit())
  12905. {
  12906. int timeToWait = 500;
  12907. {
  12908. const ScopedLock sl (callbackLock);
  12909. {
  12910. const ScopedLock sl2 (listLock);
  12911. if (clients.size() > 0)
  12912. {
  12913. index = (index + 1) % clients.size();
  12914. clientBeingCalled = clients [index];
  12915. }
  12916. else
  12917. {
  12918. index = 0;
  12919. clientBeingCalled = 0;
  12920. }
  12921. if (clientsChanged)
  12922. {
  12923. clientsChanged = false;
  12924. numCallsSinceBusy = 0;
  12925. }
  12926. }
  12927. if (clientBeingCalled != 0)
  12928. {
  12929. if (clientBeingCalled->useTimeSlice())
  12930. numCallsSinceBusy = 0;
  12931. else
  12932. ++numCallsSinceBusy;
  12933. if (numCallsSinceBusy >= clients.size())
  12934. timeToWait = 500;
  12935. else if (index == 0)
  12936. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12937. else
  12938. timeToWait = 0;
  12939. }
  12940. }
  12941. if (timeToWait > 0)
  12942. wait (timeToWait);
  12943. }
  12944. }
  12945. END_JUCE_NAMESPACE
  12946. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12947. #endif
  12948. #if JUCE_BUILD_MISC
  12949. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12950. BEGIN_JUCE_NAMESPACE
  12951. class ValueTreeSetPropertyAction : public UndoableAction
  12952. {
  12953. public:
  12954. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12955. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12956. : target (target_), name (name_), newValue (newValue_),
  12957. isAddingNewProperty (isAddingNewProperty_),
  12958. isDeletingProperty (isDeletingProperty_)
  12959. {
  12960. if (! isAddingNewProperty)
  12961. oldValue = target_->getProperty (name_);
  12962. }
  12963. ~ValueTreeSetPropertyAction() {}
  12964. bool perform()
  12965. {
  12966. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12967. if (isDeletingProperty)
  12968. target->removeProperty (name, 0);
  12969. else
  12970. target->setProperty (name, newValue, 0);
  12971. return true;
  12972. }
  12973. bool undo()
  12974. {
  12975. if (isAddingNewProperty)
  12976. target->removeProperty (name, 0);
  12977. else
  12978. target->setProperty (name, oldValue, 0);
  12979. return true;
  12980. }
  12981. int getSizeInUnits()
  12982. {
  12983. return (int) sizeof (*this); //xxx should be more accurate
  12984. }
  12985. private:
  12986. const ValueTree::SharedObjectPtr target;
  12987. const var::identifier name;
  12988. const var newValue;
  12989. var oldValue;
  12990. const bool isAddingNewProperty, isDeletingProperty;
  12991. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12992. const ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12993. };
  12994. class ValueTreeChildChangeAction : public UndoableAction
  12995. {
  12996. public:
  12997. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12998. const ValueTree::SharedObjectPtr& newChild_)
  12999. : target (target_),
  13000. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  13001. childIndex (childIndex_),
  13002. isDeleting (newChild_ == 0)
  13003. {
  13004. jassert (child != 0);
  13005. }
  13006. ~ValueTreeChildChangeAction() {}
  13007. bool perform()
  13008. {
  13009. if (isDeleting)
  13010. target->removeChild (childIndex, 0);
  13011. else
  13012. target->addChild (child, childIndex, 0);
  13013. return true;
  13014. }
  13015. bool undo()
  13016. {
  13017. if (isDeleting)
  13018. target->addChild (child, childIndex, 0);
  13019. else
  13020. target->removeChild (childIndex, 0);
  13021. return true;
  13022. }
  13023. int getSizeInUnits()
  13024. {
  13025. return (int) sizeof (*this); //xxx should be more accurate
  13026. }
  13027. private:
  13028. const ValueTree::SharedObjectPtr target, child;
  13029. const int childIndex;
  13030. const bool isDeleting;
  13031. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  13032. const ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  13033. };
  13034. ValueTree::SharedObject::SharedObject (const String& type_)
  13035. : type (type_), parent (0)
  13036. {
  13037. }
  13038. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  13039. : type (other.type), properties (other.properties), parent (0)
  13040. {
  13041. for (int i = 0; i < other.children.size(); ++i)
  13042. children.add (new SharedObject (*other.children.getUnchecked(i)));
  13043. }
  13044. ValueTree::SharedObject::~SharedObject()
  13045. {
  13046. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  13047. for (int i = children.size(); --i >= 0;)
  13048. {
  13049. const SharedObjectPtr c (children.getUnchecked(i));
  13050. c->parent = 0;
  13051. children.remove (i);
  13052. c->sendParentChangeMessage();
  13053. }
  13054. }
  13055. void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13056. {
  13057. for (int i = listeners.size(); --i >= 0;)
  13058. {
  13059. ValueTree::Listener* const l = listeners[i];
  13060. if (l != 0)
  13061. l->valueTreePropertyChanged (tree, property);
  13062. }
  13063. }
  13064. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13065. {
  13066. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13067. {
  13068. ValueTree* const v = valueTreesWithListeners[i];
  13069. if (v != 0)
  13070. v->deliverPropertyChangeMessage (tree, property);
  13071. }
  13072. }
  13073. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  13074. {
  13075. ValueTree tree (this);
  13076. ValueTree::SharedObject* t = this;
  13077. while (t != 0)
  13078. {
  13079. t->sendPropertyChangeMessage (tree, property);
  13080. t = t->parent;
  13081. }
  13082. }
  13083. void ValueTree::deliverChildChangeMessage (ValueTree& tree)
  13084. {
  13085. for (int i = listeners.size(); --i >= 0;)
  13086. {
  13087. ValueTree::Listener* const l = listeners[i];
  13088. if (l != 0)
  13089. l->valueTreeChildrenChanged (tree);
  13090. }
  13091. }
  13092. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13093. {
  13094. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13095. {
  13096. ValueTree* const v = valueTreesWithListeners[i];
  13097. if (v != 0)
  13098. v->deliverChildChangeMessage (tree);
  13099. }
  13100. }
  13101. void ValueTree::SharedObject::sendChildChangeMessage()
  13102. {
  13103. ValueTree tree (this);
  13104. ValueTree::SharedObject* t = this;
  13105. while (t != 0)
  13106. {
  13107. t->sendChildChangeMessage (tree);
  13108. t = t->parent;
  13109. }
  13110. }
  13111. void ValueTree::deliverParentChangeMessage (ValueTree& tree)
  13112. {
  13113. for (int i = listeners.size(); --i >= 0;)
  13114. {
  13115. ValueTree::Listener* const l = listeners[i];
  13116. if (l != 0)
  13117. l->valueTreeParentChanged (tree);
  13118. }
  13119. }
  13120. void ValueTree::SharedObject::sendParentChangeMessage()
  13121. {
  13122. ValueTree tree (this);
  13123. int i;
  13124. for (i = children.size(); --i >= 0;)
  13125. {
  13126. SharedObject* const t = children[i];
  13127. if (t != 0)
  13128. t->sendParentChangeMessage();
  13129. }
  13130. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13131. {
  13132. ValueTree* const v = valueTreesWithListeners[i];
  13133. if (v != 0)
  13134. v->deliverParentChangeMessage (tree);
  13135. }
  13136. }
  13137. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13138. {
  13139. return properties [name];
  13140. }
  13141. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13142. {
  13143. if (undoManager == 0)
  13144. {
  13145. if (properties.set (name, newValue))
  13146. sendPropertyChangeMessage (name);
  13147. }
  13148. else
  13149. {
  13150. var* const existingValue = properties.getItem (name);
  13151. if (existingValue != 0)
  13152. {
  13153. if (*existingValue != newValue)
  13154. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13155. }
  13156. else
  13157. {
  13158. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13159. }
  13160. }
  13161. }
  13162. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13163. {
  13164. return properties.contains (name);
  13165. }
  13166. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13167. {
  13168. if (undoManager == 0)
  13169. {
  13170. if (properties.remove (name))
  13171. sendPropertyChangeMessage (name);
  13172. }
  13173. else
  13174. {
  13175. if (properties.contains (name))
  13176. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  13177. }
  13178. }
  13179. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13180. {
  13181. if (undoManager == 0)
  13182. {
  13183. while (properties.size() > 0)
  13184. {
  13185. const var::identifier name (properties.getName (properties.size() - 1));
  13186. properties.remove (name);
  13187. sendPropertyChangeMessage (name);
  13188. }
  13189. }
  13190. else
  13191. {
  13192. for (int i = properties.size(); --i >= 0;)
  13193. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  13194. }
  13195. }
  13196. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13197. {
  13198. for (int i = 0; i < children.size(); ++i)
  13199. if (children.getUnchecked(i)->type == typeToMatch)
  13200. return (SharedObject*) children.getUnchecked(i);
  13201. return (SharedObject*) 0;
  13202. }
  13203. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13204. {
  13205. for (int i = 0; i < children.size(); ++i)
  13206. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13207. return (SharedObject*) children.getUnchecked(i);
  13208. return (SharedObject*) 0;
  13209. }
  13210. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13211. {
  13212. const SharedObject* p = parent;
  13213. while (p != 0)
  13214. {
  13215. if (p == possibleParent)
  13216. return true;
  13217. p = p->parent;
  13218. }
  13219. return false;
  13220. }
  13221. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13222. {
  13223. if (child != 0 && child->parent != this)
  13224. {
  13225. if (child != this && ! isAChildOf (child))
  13226. {
  13227. // You should always make sure that a child is removed from its previous parent before
  13228. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13229. // undomanager should be used when removing it from its current parent..
  13230. jassert (child->parent == 0);
  13231. if (child->parent != 0)
  13232. {
  13233. jassert (child->parent->children.indexOf (child) >= 0);
  13234. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13235. }
  13236. if (undoManager == 0)
  13237. {
  13238. children.insert (index, child);
  13239. child->parent = this;
  13240. sendChildChangeMessage();
  13241. child->sendParentChangeMessage();
  13242. }
  13243. else
  13244. {
  13245. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13246. }
  13247. }
  13248. else
  13249. {
  13250. // You're attempting to create a recursive loop! A node
  13251. // can't be a child of one of its own children!
  13252. jassertfalse
  13253. }
  13254. }
  13255. }
  13256. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13257. {
  13258. const SharedObjectPtr child (children [childIndex]);
  13259. if (child != 0)
  13260. {
  13261. if (undoManager == 0)
  13262. {
  13263. children.remove (childIndex);
  13264. child->parent = 0;
  13265. sendChildChangeMessage();
  13266. child->sendParentChangeMessage();
  13267. }
  13268. else
  13269. {
  13270. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13271. }
  13272. }
  13273. }
  13274. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13275. {
  13276. while (children.size() > 0)
  13277. removeChild (children.size() - 1, undoManager);
  13278. }
  13279. ValueTree::ValueTree (const String& type_)
  13280. : object (new ValueTree::SharedObject (type_))
  13281. {
  13282. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13283. }
  13284. ValueTree::ValueTree (SharedObject* const object_)
  13285. : object (object_)
  13286. {
  13287. }
  13288. ValueTree::ValueTree (const ValueTree& other)
  13289. : object (other.object)
  13290. {
  13291. }
  13292. const ValueTree& ValueTree::operator= (const ValueTree& other)
  13293. {
  13294. if (listeners.size() > 0)
  13295. {
  13296. if (object != 0)
  13297. object->valueTreesWithListeners.removeValue (this);
  13298. if (other.object != 0)
  13299. other.object->valueTreesWithListeners.add (this);
  13300. }
  13301. object = other.object;
  13302. return *this;
  13303. }
  13304. ValueTree::~ValueTree()
  13305. {
  13306. if (listeners.size() > 0 && object != 0)
  13307. object->valueTreesWithListeners.removeValue (this);
  13308. }
  13309. bool ValueTree::operator== (const ValueTree& other) const
  13310. {
  13311. return object == other.object;
  13312. }
  13313. bool ValueTree::operator!= (const ValueTree& other) const
  13314. {
  13315. return object != other.object;
  13316. }
  13317. ValueTree ValueTree::createCopy() const
  13318. {
  13319. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13320. }
  13321. bool ValueTree::hasType (const String& typeName) const
  13322. {
  13323. return object != 0 && object->type == typeName;
  13324. }
  13325. const String ValueTree::getType() const
  13326. {
  13327. return object != 0 ? object->type : String::empty;
  13328. }
  13329. ValueTree ValueTree::getParent() const
  13330. {
  13331. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13332. }
  13333. const var& ValueTree::operator[] (const var::identifier& name) const
  13334. {
  13335. return object == 0 ? var::null : object->getProperty (name);
  13336. }
  13337. const var& ValueTree::getProperty (const var::identifier& name) const
  13338. {
  13339. return object == 0 ? var::null : object->getProperty (name);
  13340. }
  13341. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13342. {
  13343. jassert (name.name.isNotEmpty());
  13344. if (object != 0 && name.name.isNotEmpty())
  13345. object->setProperty (name, newValue, undoManager);
  13346. }
  13347. bool ValueTree::hasProperty (const var::identifier& name) const
  13348. {
  13349. return object != 0 && object->hasProperty (name);
  13350. }
  13351. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13352. {
  13353. if (object != 0)
  13354. object->removeProperty (name, undoManager);
  13355. }
  13356. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13357. {
  13358. if (object != 0)
  13359. object->removeAllProperties (undoManager);
  13360. }
  13361. int ValueTree::getNumProperties() const
  13362. {
  13363. return object == 0 ? 0 : object->properties.size();
  13364. }
  13365. const var::identifier ValueTree::getPropertyName (int index) const
  13366. {
  13367. return (object == 0) ? var::identifier()
  13368. : object->properties.getName (index);
  13369. }
  13370. class ValueTreePropertyValueSource : public Value::ValueSource,
  13371. public ValueTree::Listener
  13372. {
  13373. public:
  13374. ValueTreePropertyValueSource (const ValueTree& tree_,
  13375. const var::identifier& property_,
  13376. UndoManager* const undoManager_)
  13377. : tree (tree_),
  13378. property (property_),
  13379. undoManager (undoManager_)
  13380. {
  13381. tree.addListener (this);
  13382. }
  13383. ~ValueTreePropertyValueSource()
  13384. {
  13385. tree.removeListener (this);
  13386. }
  13387. const var getValue() const
  13388. {
  13389. return tree [property];
  13390. }
  13391. void setValue (const var& newValue)
  13392. {
  13393. tree.setProperty (property, newValue, undoManager);
  13394. }
  13395. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13396. {
  13397. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13398. sendChangeMessage (false);
  13399. }
  13400. void valueTreeChildrenChanged (ValueTree&) {}
  13401. void valueTreeParentChanged (ValueTree&) {}
  13402. private:
  13403. ValueTree tree;
  13404. const var::identifier property;
  13405. UndoManager* const undoManager;
  13406. const ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13407. };
  13408. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13409. {
  13410. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13411. }
  13412. int ValueTree::getNumChildren() const
  13413. {
  13414. return object == 0 ? 0 : object->children.size();
  13415. }
  13416. ValueTree ValueTree::getChild (int index) const
  13417. {
  13418. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13419. }
  13420. ValueTree ValueTree::getChildWithName (const String& type) const
  13421. {
  13422. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13423. }
  13424. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13425. {
  13426. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13427. }
  13428. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13429. {
  13430. return object != 0 && object->isAChildOf (possibleParent.object);
  13431. }
  13432. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13433. {
  13434. if (object != 0)
  13435. object->addChild (child.object, index, undoManager);
  13436. }
  13437. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13438. {
  13439. if (object != 0)
  13440. object->removeChild (childIndex, undoManager);
  13441. }
  13442. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13443. {
  13444. if (object != 0)
  13445. object->removeChild (object->children.indexOf (child.object), undoManager);
  13446. }
  13447. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13448. {
  13449. if (object != 0)
  13450. object->removeAllChildren (undoManager);
  13451. }
  13452. void ValueTree::addListener (Listener* listener)
  13453. {
  13454. if (listener != 0)
  13455. {
  13456. if (listeners.size() == 0 && object != 0)
  13457. object->valueTreesWithListeners.add (this);
  13458. listeners.add (listener);
  13459. }
  13460. }
  13461. void ValueTree::removeListener (Listener* listener)
  13462. {
  13463. listeners.removeValue (listener);
  13464. if (listeners.size() == 0 && object != 0)
  13465. object->valueTreesWithListeners.removeValue (this);
  13466. }
  13467. XmlElement* ValueTree::SharedObject::createXml() const
  13468. {
  13469. XmlElement* xml = new XmlElement (type);
  13470. int i;
  13471. for (i = 0; i < properties.size(); ++i)
  13472. {
  13473. var::identifier name (properties.getName(i));
  13474. const var& v = properties [name];
  13475. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13476. xml->setAttribute (name.name, v.toString());
  13477. }
  13478. for (i = 0; i < children.size(); ++i)
  13479. xml->addChildElement (children.getUnchecked(i)->createXml());
  13480. return xml;
  13481. }
  13482. XmlElement* ValueTree::createXml() const
  13483. {
  13484. return object != 0 ? object->createXml() : 0;
  13485. }
  13486. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13487. {
  13488. ValueTree v (xml.getTagName());
  13489. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13490. for (int i = 0; i < numAtts; ++i)
  13491. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13492. forEachXmlChildElement (xml, e)
  13493. {
  13494. v.addChild (fromXml (*e), -1, 0);
  13495. }
  13496. return v;
  13497. }
  13498. void ValueTree::writeToStream (OutputStream& output)
  13499. {
  13500. output.writeString (getType());
  13501. const int numProps = getNumProperties();
  13502. output.writeCompressedInt (numProps);
  13503. int i;
  13504. for (i = 0; i < numProps; ++i)
  13505. {
  13506. const var::identifier name (getPropertyName(i));
  13507. output.writeString (name.name);
  13508. getProperty(name).writeToStream (output);
  13509. }
  13510. const int numChildren = getNumChildren();
  13511. output.writeCompressedInt (numChildren);
  13512. for (i = 0; i < numChildren; ++i)
  13513. getChild (i).writeToStream (output);
  13514. }
  13515. ValueTree ValueTree::readFromStream (InputStream& input)
  13516. {
  13517. String type (input.readString());
  13518. if (type.isEmpty())
  13519. return ValueTree ((SharedObject*) 0);
  13520. ValueTree v (type);
  13521. const int numProps = input.readCompressedInt();
  13522. if (numProps < 0)
  13523. {
  13524. jassertfalse // trying to read corrupted data!
  13525. return v;
  13526. }
  13527. int i;
  13528. for (i = 0; i < numProps; ++i)
  13529. {
  13530. const String name (input.readString());
  13531. jassert (name.isNotEmpty());
  13532. const var value (var::readFromStream (input));
  13533. v.setProperty (name, value, 0);
  13534. }
  13535. const int numChildren = input.readCompressedInt();
  13536. for (i = 0; i < numChildren; ++i)
  13537. v.addChild (readFromStream (input), -1, 0);
  13538. return v;
  13539. }
  13540. END_JUCE_NAMESPACE
  13541. /*** End of inlined file: juce_ValueTree.cpp ***/
  13542. /*** Start of inlined file: juce_Value.cpp ***/
  13543. BEGIN_JUCE_NAMESPACE
  13544. Value::ValueSource::ValueSource()
  13545. {
  13546. }
  13547. Value::ValueSource::~ValueSource()
  13548. {
  13549. }
  13550. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13551. {
  13552. if (synchronous)
  13553. {
  13554. for (int i = valuesWithListeners.size(); --i >= 0;)
  13555. {
  13556. Value* const v = valuesWithListeners[i];
  13557. if (v != 0)
  13558. v->callListeners();
  13559. }
  13560. }
  13561. else
  13562. {
  13563. triggerAsyncUpdate();
  13564. }
  13565. }
  13566. void Value::ValueSource::handleAsyncUpdate()
  13567. {
  13568. sendChangeMessage (true);
  13569. }
  13570. class SimpleValueSource : public Value::ValueSource
  13571. {
  13572. public:
  13573. SimpleValueSource()
  13574. {
  13575. }
  13576. SimpleValueSource (const var& initialValue)
  13577. : value (initialValue)
  13578. {
  13579. }
  13580. ~SimpleValueSource()
  13581. {
  13582. }
  13583. const var getValue() const
  13584. {
  13585. return value;
  13586. }
  13587. void setValue (const var& newValue)
  13588. {
  13589. if (newValue != value)
  13590. {
  13591. value = newValue;
  13592. sendChangeMessage (false);
  13593. }
  13594. }
  13595. private:
  13596. var value;
  13597. SimpleValueSource (const SimpleValueSource&);
  13598. const SimpleValueSource& operator= (const SimpleValueSource&);
  13599. };
  13600. Value::Value()
  13601. : value (new SimpleValueSource())
  13602. {
  13603. }
  13604. Value::Value (ValueSource* const value_)
  13605. : value (value_)
  13606. {
  13607. jassert (value_ != 0);
  13608. }
  13609. Value::Value (const var& initialValue)
  13610. : value (new SimpleValueSource (initialValue))
  13611. {
  13612. }
  13613. Value::Value (const Value& other)
  13614. : value (other.value)
  13615. {
  13616. }
  13617. const Value& Value::operator= (const Value& other)
  13618. {
  13619. value = other.value;
  13620. return *this;
  13621. }
  13622. Value::~Value()
  13623. {
  13624. if (listeners.size() > 0)
  13625. value->valuesWithListeners.removeValue (this);
  13626. }
  13627. const var Value::getValue() const
  13628. {
  13629. return value->getValue();
  13630. }
  13631. void Value::setValue (const var& newValue)
  13632. {
  13633. value->setValue (newValue);
  13634. }
  13635. const String Value::toString() const
  13636. {
  13637. return value->getValue().toString();
  13638. }
  13639. const Value& Value::operator= (const var& newValue)
  13640. {
  13641. value->setValue (newValue);
  13642. return *this;
  13643. }
  13644. void Value::referTo (const Value& valueToReferTo)
  13645. {
  13646. if (valueToReferTo.value != value)
  13647. {
  13648. if (listeners.size() > 0)
  13649. {
  13650. value->valuesWithListeners.removeValue (this);
  13651. valueToReferTo.value->valuesWithListeners.add (this);
  13652. }
  13653. value = valueToReferTo.value;
  13654. callListeners();
  13655. }
  13656. }
  13657. bool Value::refersToSameSourceAs (const Value& other) const
  13658. {
  13659. return value == other.value;
  13660. }
  13661. bool Value::operator== (const Value& other) const
  13662. {
  13663. return value == other.value || value->getValue() == other.getValue();
  13664. }
  13665. bool Value::operator!= (const Value& other) const
  13666. {
  13667. return value != other.value && value->getValue() != other.getValue();
  13668. }
  13669. void Value::addListener (Listener* const listener)
  13670. {
  13671. if (listener != 0)
  13672. {
  13673. if (listeners.size() == 0)
  13674. value->valuesWithListeners.add (this);
  13675. listeners.add (listener);
  13676. }
  13677. }
  13678. void Value::removeListener (Listener* const listener)
  13679. {
  13680. listeners.removeValue (listener);
  13681. if (listeners.size() == 0)
  13682. value->valuesWithListeners.removeValue (this);
  13683. }
  13684. void Value::callListeners()
  13685. {
  13686. Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback
  13687. for (int i = listeners.size(); --i >= 0;)
  13688. {
  13689. Listener* const l = listeners[i];
  13690. if (l != 0)
  13691. l->valueChanged (valueCopy);
  13692. }
  13693. }
  13694. END_JUCE_NAMESPACE
  13695. /*** End of inlined file: juce_Value.cpp ***/
  13696. /*** Start of inlined file: juce_Application.cpp ***/
  13697. #if JUCE_MSVC
  13698. #pragma warning (push)
  13699. #pragma warning (disable: 4245 4514 4100)
  13700. #include <crtdbg.h>
  13701. #pragma warning (pop)
  13702. #endif
  13703. BEGIN_JUCE_NAMESPACE
  13704. void juce_setCurrentThreadName (const String& name);
  13705. static JUCEApplication* appInstance = 0;
  13706. JUCEApplication::JUCEApplication()
  13707. : appReturnValue (0),
  13708. stillInitialising (true),
  13709. appLock (0)
  13710. {
  13711. }
  13712. JUCEApplication::~JUCEApplication()
  13713. {
  13714. if (appLock != 0)
  13715. {
  13716. appLock->exit();
  13717. delete appLock;
  13718. }
  13719. }
  13720. JUCEApplication* JUCEApplication::getInstance() throw()
  13721. {
  13722. return appInstance;
  13723. }
  13724. bool JUCEApplication::isInitialising() const throw()
  13725. {
  13726. return stillInitialising;
  13727. }
  13728. const String JUCEApplication::getApplicationVersion()
  13729. {
  13730. return String::empty;
  13731. }
  13732. bool JUCEApplication::moreThanOneInstanceAllowed()
  13733. {
  13734. return true;
  13735. }
  13736. void JUCEApplication::anotherInstanceStarted (const String&)
  13737. {
  13738. }
  13739. void JUCEApplication::systemRequestedQuit()
  13740. {
  13741. quit();
  13742. }
  13743. void JUCEApplication::quit()
  13744. {
  13745. MessageManager::getInstance()->stopDispatchLoop();
  13746. }
  13747. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13748. {
  13749. appReturnValue = newReturnValue;
  13750. }
  13751. void JUCEApplication::unhandledException (const std::exception*,
  13752. const String&,
  13753. const int)
  13754. {
  13755. jassertfalse
  13756. }
  13757. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13758. const char* const sourceFile,
  13759. const int lineNumber)
  13760. {
  13761. if (appInstance != 0)
  13762. appInstance->unhandledException (e, sourceFile, lineNumber);
  13763. }
  13764. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13765. {
  13766. return 0;
  13767. }
  13768. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13769. {
  13770. commands.add (StandardApplicationCommandIDs::quit);
  13771. }
  13772. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13773. {
  13774. if (commandID == StandardApplicationCommandIDs::quit)
  13775. {
  13776. result.setInfo (TRANS("Quit"),
  13777. TRANS("Quits the application"),
  13778. "Application",
  13779. 0);
  13780. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13781. }
  13782. }
  13783. bool JUCEApplication::perform (const InvocationInfo& info)
  13784. {
  13785. if (info.commandID == StandardApplicationCommandIDs::quit)
  13786. {
  13787. systemRequestedQuit();
  13788. return true;
  13789. }
  13790. return false;
  13791. }
  13792. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13793. {
  13794. if (! app->initialiseApp (commandLine))
  13795. return 0;
  13796. // now loop until a quit message is received..
  13797. JUCE_TRY
  13798. {
  13799. MessageManager::getInstance()->runDispatchLoop();
  13800. }
  13801. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13802. catch (const std::exception& e)
  13803. {
  13804. app->unhandledException (&e, __FILE__, __LINE__);
  13805. }
  13806. catch (...)
  13807. {
  13808. app->unhandledException (0, __FILE__, __LINE__);
  13809. }
  13810. #endif
  13811. return shutdownAppAndClearUp();
  13812. }
  13813. bool JUCEApplication::initialiseApp (String& commandLine)
  13814. {
  13815. jassert (appInstance == 0);
  13816. appInstance = this;
  13817. commandLineParameters = commandLine.trim();
  13818. commandLine = String::empty;
  13819. initialiseJuce_GUI();
  13820. #if ! JUCE_IPHONE
  13821. jassert (appLock == 0); // initialiseApp must only be called once!
  13822. if (! moreThanOneInstanceAllowed())
  13823. {
  13824. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13825. if (! appLock->enter(0))
  13826. {
  13827. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13828. delete appInstance;
  13829. appInstance = 0;
  13830. DBG ("Another instance is running - quitting...");
  13831. return false;
  13832. }
  13833. }
  13834. #endif
  13835. // let the app do its setting-up..
  13836. initialise (commandLineParameters);
  13837. // register for broadcast new app messages
  13838. MessageManager::getInstance()->registerBroadcastListener (this);
  13839. stillInitialising = false;
  13840. return true;
  13841. }
  13842. int JUCEApplication::shutdownAppAndClearUp()
  13843. {
  13844. jassert (appInstance != 0);
  13845. JUCEApplication* const app = appInstance;
  13846. int returnValue = 0;
  13847. MessageManager::getInstance()->deregisterBroadcastListener (app);
  13848. static bool reentrancyCheck = false;
  13849. if (! reentrancyCheck)
  13850. {
  13851. reentrancyCheck = true;
  13852. JUCE_TRY
  13853. {
  13854. // give the app a chance to clean up..
  13855. app->shutdown();
  13856. }
  13857. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13858. catch (const std::exception& e)
  13859. {
  13860. app->unhandledException (&e, __FILE__, __LINE__);
  13861. }
  13862. catch (...)
  13863. {
  13864. app->unhandledException (0, __FILE__, __LINE__);
  13865. }
  13866. #endif
  13867. JUCE_TRY
  13868. {
  13869. shutdownJuce_GUI();
  13870. returnValue = app->getApplicationReturnValue();
  13871. appInstance = 0;
  13872. delete app;
  13873. }
  13874. JUCE_CATCH_ALL_ASSERT
  13875. reentrancyCheck = false;
  13876. }
  13877. return returnValue;
  13878. }
  13879. #if JUCE_IPHONE
  13880. extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app);
  13881. #endif
  13882. #if ! JUCE_WINDOWS
  13883. extern const char* juce_Argv0;
  13884. #endif
  13885. int JUCEApplication::main (int argc, char* argv[],
  13886. JUCEApplication* const newApp)
  13887. {
  13888. #if ! JUCE_WINDOWS
  13889. juce_Argv0 = argv[0];
  13890. #endif
  13891. #if JUCE_IPHONE
  13892. const ScopedAutoReleasePool pool;
  13893. return juce_IPhoneMain (argc, argv, newApp);
  13894. #else
  13895. #if JUCE_MAC
  13896. const ScopedAutoReleasePool pool;
  13897. #endif
  13898. String cmd;
  13899. for (int i = 1; i < argc; ++i)
  13900. cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' ');
  13901. return JUCEApplication::main (cmd, newApp);
  13902. #endif
  13903. }
  13904. void JUCEApplication::actionListenerCallback (const String& message)
  13905. {
  13906. if (message.startsWith (getApplicationName() + "/"))
  13907. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13908. }
  13909. static bool juceInitialisedGUI = false;
  13910. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13911. {
  13912. if (! juceInitialisedGUI)
  13913. {
  13914. #if JUCE_MAC || JUCE_IPHONE
  13915. const ScopedAutoReleasePool pool;
  13916. #endif
  13917. juceInitialisedGUI = true;
  13918. initialiseJuce_NonGUI();
  13919. MessageManager::getInstance();
  13920. LookAndFeel::setDefaultLookAndFeel (0);
  13921. juce_setCurrentThreadName ("Juce Message Thread");
  13922. #if JUCE_WINDOWS && JUCE_DEBUG
  13923. // This section is just for catching people who mess up their project settings and
  13924. // turn RTTI off..
  13925. try
  13926. {
  13927. TextButton tb (String::empty);
  13928. Component* c = &tb;
  13929. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13930. c = dynamic_cast <Button*> (c);
  13931. }
  13932. catch (...)
  13933. {
  13934. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13935. // got as far as this catch statement, then why haven't you got exception catching
  13936. // turned on in the debugger???
  13937. jassertfalse
  13938. }
  13939. #endif
  13940. }
  13941. }
  13942. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13943. {
  13944. if (juceInitialisedGUI)
  13945. {
  13946. #if JUCE_MAC
  13947. const ScopedAutoReleasePool pool;
  13948. #endif
  13949. {
  13950. DeletedAtShutdown::deleteAll();
  13951. LookAndFeel::clearDefaultLookAndFeel();
  13952. }
  13953. delete MessageManager::getInstance();
  13954. shutdownJuce_NonGUI();
  13955. juceInitialisedGUI = false;
  13956. }
  13957. }
  13958. END_JUCE_NAMESPACE
  13959. /*** End of inlined file: juce_Application.cpp ***/
  13960. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13961. BEGIN_JUCE_NAMESPACE
  13962. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13963. : commandID (commandID_),
  13964. flags (0)
  13965. {
  13966. }
  13967. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13968. const String& description_,
  13969. const String& categoryName_,
  13970. const int flags_) throw()
  13971. {
  13972. shortName = shortName_;
  13973. description = description_;
  13974. categoryName = categoryName_;
  13975. flags = flags_;
  13976. }
  13977. void ApplicationCommandInfo::setActive (const bool b) throw()
  13978. {
  13979. if (b)
  13980. flags &= ~isDisabled;
  13981. else
  13982. flags |= isDisabled;
  13983. }
  13984. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13985. {
  13986. if (b)
  13987. flags |= isTicked;
  13988. else
  13989. flags &= ~isTicked;
  13990. }
  13991. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13992. {
  13993. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13994. }
  13995. END_JUCE_NAMESPACE
  13996. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13997. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13998. BEGIN_JUCE_NAMESPACE
  13999. ApplicationCommandManager::ApplicationCommandManager()
  14000. : firstTarget (0)
  14001. {
  14002. keyMappings = new KeyPressMappingSet (this);
  14003. Desktop::getInstance().addFocusChangeListener (this);
  14004. }
  14005. ApplicationCommandManager::~ApplicationCommandManager()
  14006. {
  14007. Desktop::getInstance().removeFocusChangeListener (this);
  14008. keyMappings = 0;
  14009. }
  14010. void ApplicationCommandManager::clearCommands()
  14011. {
  14012. commands.clear();
  14013. keyMappings->clearAllKeyPresses();
  14014. triggerAsyncUpdate();
  14015. }
  14016. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  14017. {
  14018. // zero isn't a valid command ID!
  14019. jassert (newCommand.commandID != 0);
  14020. // the name isn't optional!
  14021. jassert (newCommand.shortName.isNotEmpty());
  14022. if (getCommandForID (newCommand.commandID) == 0)
  14023. {
  14024. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  14025. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  14026. commands.add (newInfo);
  14027. keyMappings->resetToDefaultMapping (newCommand.commandID);
  14028. triggerAsyncUpdate();
  14029. }
  14030. else
  14031. {
  14032. // trying to re-register the same command with different parameters?
  14033. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  14034. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  14035. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  14036. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  14037. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  14038. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  14039. }
  14040. }
  14041. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  14042. {
  14043. if (target != 0)
  14044. {
  14045. Array <CommandID> commandIDs;
  14046. target->getAllCommands (commandIDs);
  14047. for (int i = 0; i < commandIDs.size(); ++i)
  14048. {
  14049. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  14050. target->getCommandInfo (info.commandID, info);
  14051. registerCommand (info);
  14052. }
  14053. }
  14054. }
  14055. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  14056. {
  14057. for (int i = commands.size(); --i >= 0;)
  14058. {
  14059. if (commands.getUnchecked (i)->commandID == commandID)
  14060. {
  14061. commands.remove (i);
  14062. triggerAsyncUpdate();
  14063. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  14064. for (int j = keys.size(); --j >= 0;)
  14065. keyMappings->removeKeyPress (keys.getReference (j));
  14066. }
  14067. }
  14068. }
  14069. void ApplicationCommandManager::commandStatusChanged()
  14070. {
  14071. triggerAsyncUpdate();
  14072. }
  14073. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14074. {
  14075. for (int i = commands.size(); --i >= 0;)
  14076. if (commands.getUnchecked(i)->commandID == commandID)
  14077. return commands.getUnchecked(i);
  14078. return 0;
  14079. }
  14080. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14081. {
  14082. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14083. return (ci != 0) ? ci->shortName : String::empty;
  14084. }
  14085. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14086. {
  14087. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14088. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14089. : String::empty;
  14090. }
  14091. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14092. {
  14093. StringArray s;
  14094. for (int i = 0; i < commands.size(); ++i)
  14095. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14096. return s;
  14097. }
  14098. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14099. {
  14100. Array <CommandID> results;
  14101. for (int i = 0; i < commands.size(); ++i)
  14102. if (commands.getUnchecked(i)->categoryName == categoryName)
  14103. results.add (commands.getUnchecked(i)->commandID);
  14104. return results;
  14105. }
  14106. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14107. {
  14108. ApplicationCommandTarget::InvocationInfo info (commandID);
  14109. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14110. return invoke (info, asynchronously);
  14111. }
  14112. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14113. {
  14114. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14115. // manager first..
  14116. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14117. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14118. if (target == 0)
  14119. return false;
  14120. ApplicationCommandInfo commandInfo (0);
  14121. target->getCommandInfo (info_.commandID, commandInfo);
  14122. ApplicationCommandTarget::InvocationInfo info (info_);
  14123. info.commandFlags = commandInfo.flags;
  14124. sendListenerInvokeCallback (info);
  14125. const bool ok = target->invoke (info, asynchronously);
  14126. commandStatusChanged();
  14127. return ok;
  14128. }
  14129. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14130. {
  14131. return firstTarget != 0 ? firstTarget
  14132. : findDefaultComponentTarget();
  14133. }
  14134. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14135. {
  14136. firstTarget = newTarget;
  14137. }
  14138. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14139. ApplicationCommandInfo& upToDateInfo)
  14140. {
  14141. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14142. if (target == 0)
  14143. target = JUCEApplication::getInstance();
  14144. if (target != 0)
  14145. target = target->getTargetForCommand (commandID);
  14146. if (target != 0)
  14147. target->getCommandInfo (commandID, upToDateInfo);
  14148. return target;
  14149. }
  14150. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14151. {
  14152. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14153. if (target == 0 && c != 0)
  14154. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14155. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14156. return target;
  14157. }
  14158. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14159. {
  14160. Component* c = Component::getCurrentlyFocusedComponent();
  14161. if (c == 0)
  14162. {
  14163. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14164. if (activeWindow != 0)
  14165. {
  14166. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14167. if (c == 0)
  14168. c = activeWindow;
  14169. }
  14170. }
  14171. if (c == 0 && Process::isForegroundProcess())
  14172. {
  14173. // getting a bit desperate now - try all desktop comps..
  14174. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14175. {
  14176. ApplicationCommandTarget* const target
  14177. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14178. ->getPeer()->getLastFocusedSubcomponent());
  14179. if (target != 0)
  14180. return target;
  14181. }
  14182. }
  14183. if (c != 0)
  14184. {
  14185. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14186. // if we're focused on a ResizableWindow, chances are that it's the content
  14187. // component that really should get the event. And if not, the event will
  14188. // still be passed up to the top level window anyway, so let's send it to the
  14189. // content comp.
  14190. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14191. c = resizableWindow->getContentComponent();
  14192. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14193. if (target != 0)
  14194. return target;
  14195. }
  14196. return JUCEApplication::getInstance();
  14197. }
  14198. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14199. {
  14200. jassert (listener != 0);
  14201. if (listener != 0)
  14202. listeners.add (listener);
  14203. }
  14204. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14205. {
  14206. listeners.removeValue (listener);
  14207. }
  14208. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const
  14209. {
  14210. for (int i = listeners.size(); --i >= 0;)
  14211. {
  14212. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info);
  14213. i = jmin (i, listeners.size());
  14214. }
  14215. }
  14216. void ApplicationCommandManager::handleAsyncUpdate()
  14217. {
  14218. for (int i = listeners.size(); --i >= 0;)
  14219. {
  14220. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged();
  14221. i = jmin (i, listeners.size());
  14222. }
  14223. }
  14224. void ApplicationCommandManager::globalFocusChanged (Component*)
  14225. {
  14226. commandStatusChanged();
  14227. }
  14228. END_JUCE_NAMESPACE
  14229. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  14230. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14231. BEGIN_JUCE_NAMESPACE
  14232. ApplicationCommandTarget::ApplicationCommandTarget()
  14233. {
  14234. }
  14235. ApplicationCommandTarget::~ApplicationCommandTarget()
  14236. {
  14237. messageInvoker = 0;
  14238. }
  14239. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14240. {
  14241. if (isCommandActive (info.commandID))
  14242. {
  14243. if (async)
  14244. {
  14245. if (messageInvoker == 0)
  14246. messageInvoker = new CommandTargetMessageInvoker (this);
  14247. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14248. return true;
  14249. }
  14250. else
  14251. {
  14252. const bool success = perform (info);
  14253. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14254. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14255. // returns the command's info.
  14256. return success;
  14257. }
  14258. }
  14259. return false;
  14260. }
  14261. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14262. {
  14263. Component* c = dynamic_cast <Component*> (this);
  14264. if (c != 0)
  14265. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14266. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14267. return 0;
  14268. }
  14269. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14270. {
  14271. ApplicationCommandTarget* target = this;
  14272. int depth = 0;
  14273. while (target != 0)
  14274. {
  14275. Array <CommandID> commandIDs;
  14276. target->getAllCommands (commandIDs);
  14277. if (commandIDs.contains (commandID))
  14278. return target;
  14279. target = target->getNextCommandTarget();
  14280. ++depth;
  14281. jassert (depth < 100); // could be a recursive command chain??
  14282. jassert (target != this); // definitely a recursive command chain!
  14283. if (depth > 100 || target == this)
  14284. break;
  14285. }
  14286. if (target == 0)
  14287. {
  14288. target = JUCEApplication::getInstance();
  14289. if (target != 0)
  14290. {
  14291. Array <CommandID> commandIDs;
  14292. target->getAllCommands (commandIDs);
  14293. if (commandIDs.contains (commandID))
  14294. return target;
  14295. }
  14296. }
  14297. return 0;
  14298. }
  14299. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14300. {
  14301. ApplicationCommandInfo info (commandID);
  14302. info.flags = ApplicationCommandInfo::isDisabled;
  14303. getCommandInfo (commandID, info);
  14304. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14305. }
  14306. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14307. {
  14308. ApplicationCommandTarget* target = this;
  14309. int depth = 0;
  14310. while (target != 0)
  14311. {
  14312. if (target->tryToInvoke (info, async))
  14313. return true;
  14314. target = target->getNextCommandTarget();
  14315. ++depth;
  14316. jassert (depth < 100); // could be a recursive command chain??
  14317. jassert (target != this); // definitely a recursive command chain!
  14318. if (depth > 100 || target == this)
  14319. break;
  14320. }
  14321. if (target == 0)
  14322. {
  14323. target = JUCEApplication::getInstance();
  14324. if (target != 0)
  14325. return target->tryToInvoke (info, async);
  14326. }
  14327. return false;
  14328. }
  14329. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14330. {
  14331. ApplicationCommandTarget::InvocationInfo info (commandID);
  14332. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14333. return invoke (info, asynchronously);
  14334. }
  14335. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14336. : commandID (commandID_),
  14337. commandFlags (0),
  14338. invocationMethod (direct),
  14339. originatingComponent (0),
  14340. isKeyDown (false),
  14341. millisecsSinceKeyPressed (0)
  14342. {
  14343. }
  14344. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14345. : owner (owner_)
  14346. {
  14347. }
  14348. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14349. {
  14350. }
  14351. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14352. {
  14353. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14354. owner->tryToInvoke (*info, false);
  14355. }
  14356. END_JUCE_NAMESPACE
  14357. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14358. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14359. BEGIN_JUCE_NAMESPACE
  14360. juce_ImplementSingleton (ApplicationProperties)
  14361. ApplicationProperties::ApplicationProperties() throw()
  14362. : msBeforeSaving (3000),
  14363. options (PropertiesFile::storeAsBinary),
  14364. commonSettingsAreReadOnly (0)
  14365. {
  14366. }
  14367. ApplicationProperties::~ApplicationProperties()
  14368. {
  14369. closeFiles();
  14370. clearSingletonInstance();
  14371. }
  14372. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14373. const String& fileNameSuffix,
  14374. const String& folderName_,
  14375. const int millisecondsBeforeSaving,
  14376. const int propertiesFileOptions) throw()
  14377. {
  14378. appName = applicationName;
  14379. fileSuffix = fileNameSuffix;
  14380. folderName = folderName_;
  14381. msBeforeSaving = millisecondsBeforeSaving;
  14382. options = propertiesFileOptions;
  14383. }
  14384. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14385. const bool testCommonSettings,
  14386. const bool showWarningDialogOnFailure)
  14387. {
  14388. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14389. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14390. if (! (userOk && commonOk))
  14391. {
  14392. if (showWarningDialogOnFailure)
  14393. {
  14394. String filenames;
  14395. if (userProps != 0 && ! userOk)
  14396. filenames << '\n' << userProps->getFile().getFullPathName();
  14397. if (commonProps != 0 && ! commonOk)
  14398. filenames << '\n' << commonProps->getFile().getFullPathName();
  14399. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14400. appName + TRANS(" - Unable to save settings"),
  14401. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14402. + appName + TRANS(" needs to be able to write to the following files:\n")
  14403. + filenames
  14404. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14405. }
  14406. return false;
  14407. }
  14408. return true;
  14409. }
  14410. void ApplicationProperties::openFiles() throw()
  14411. {
  14412. // You need to call setStorageParameters() before trying to get hold of the
  14413. // properties!
  14414. jassert (appName.isNotEmpty());
  14415. if (appName.isNotEmpty())
  14416. {
  14417. if (userProps == 0)
  14418. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14419. false, msBeforeSaving, options);
  14420. if (commonProps == 0)
  14421. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14422. true, msBeforeSaving, options);
  14423. userProps->setFallbackPropertySet (commonProps);
  14424. }
  14425. }
  14426. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14427. {
  14428. if (userProps == 0)
  14429. openFiles();
  14430. return userProps;
  14431. }
  14432. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14433. {
  14434. if (commonProps == 0)
  14435. openFiles();
  14436. if (returnUserPropsIfReadOnly)
  14437. {
  14438. if (commonSettingsAreReadOnly == 0)
  14439. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14440. if (commonSettingsAreReadOnly > 0)
  14441. return userProps;
  14442. }
  14443. return commonProps;
  14444. }
  14445. bool ApplicationProperties::saveIfNeeded()
  14446. {
  14447. return (userProps == 0 || userProps->saveIfNeeded())
  14448. && (commonProps == 0 || commonProps->saveIfNeeded());
  14449. }
  14450. void ApplicationProperties::closeFiles()
  14451. {
  14452. userProps = 0;
  14453. commonProps = 0;
  14454. }
  14455. END_JUCE_NAMESPACE
  14456. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14457. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14458. BEGIN_JUCE_NAMESPACE
  14459. static VoidArray objectsToDelete;
  14460. static CriticalSection lock;
  14461. DeletedAtShutdown::DeletedAtShutdown()
  14462. {
  14463. const ScopedLock sl (lock);
  14464. objectsToDelete.add (this);
  14465. }
  14466. DeletedAtShutdown::~DeletedAtShutdown()
  14467. {
  14468. const ScopedLock sl (lock);
  14469. objectsToDelete.removeValue (this);
  14470. }
  14471. void DeletedAtShutdown::deleteAll()
  14472. {
  14473. // make a local copy of the array, so it can't get into a loop if something
  14474. // creates another DeletedAtShutdown object during its destructor.
  14475. lock.enter();
  14476. const VoidArray localCopy (objectsToDelete);
  14477. lock.exit();
  14478. for (int i = localCopy.size(); --i >= 0;)
  14479. {
  14480. JUCE_TRY
  14481. {
  14482. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14483. // double-check that it's not already been deleted during another object's destructor.
  14484. {
  14485. const ScopedLock sl (lock);
  14486. if (! objectsToDelete.contains (deletee))
  14487. deletee = 0;
  14488. }
  14489. delete deletee;
  14490. }
  14491. JUCE_CATCH_EXCEPTION
  14492. }
  14493. // if no objects got re-created during shutdown, this should have been emptied by their
  14494. // destructors
  14495. jassert (objectsToDelete.size() == 0);
  14496. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14497. }
  14498. END_JUCE_NAMESPACE
  14499. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14500. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14501. BEGIN_JUCE_NAMESPACE
  14502. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14503. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14504. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14505. static const tchar* const propertyTagName = T("VALUE");
  14506. PropertiesFile::PropertiesFile (const File& f,
  14507. const int millisecondsBeforeSaving,
  14508. const int options_)
  14509. : PropertySet (ignoreCaseOfKeyNames),
  14510. file (f),
  14511. timerInterval (millisecondsBeforeSaving),
  14512. options (options_),
  14513. needsWriting (false)
  14514. {
  14515. // You need to correctly specify just one storage format for the file
  14516. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14517. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14518. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14519. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14520. if (fileStream != 0)
  14521. {
  14522. int magicNumber = fileStream->readInt();
  14523. if (magicNumber == propFileMagicNumberCompressed)
  14524. {
  14525. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14526. true);
  14527. magicNumber = propFileMagicNumber;
  14528. }
  14529. if (magicNumber == propFileMagicNumber)
  14530. {
  14531. BufferedInputStream in (fileStream.release(), 2048, true);
  14532. int numValues = in.readInt();
  14533. while (--numValues >= 0 && ! in.isExhausted())
  14534. {
  14535. const String key (in.readString());
  14536. const String value (in.readString());
  14537. jassert (key.isNotEmpty());
  14538. if (key.isNotEmpty())
  14539. getAllProperties().set (key, value);
  14540. }
  14541. }
  14542. else
  14543. {
  14544. // Not a binary props file - let's see if it's XML..
  14545. fileStream = 0;
  14546. XmlDocument parser (f);
  14547. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14548. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14549. {
  14550. doc = parser.getDocumentElement();
  14551. if (doc != 0)
  14552. {
  14553. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14554. {
  14555. const String name (e->getStringAttribute (T("name")));
  14556. if (name.isNotEmpty())
  14557. {
  14558. getAllProperties().set (name,
  14559. e->getFirstChildElement() != 0
  14560. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14561. : e->getStringAttribute (T("val")));
  14562. }
  14563. }
  14564. }
  14565. else
  14566. {
  14567. // must be a pretty broken XML file we're trying to parse here!
  14568. jassertfalse
  14569. }
  14570. }
  14571. }
  14572. }
  14573. }
  14574. PropertiesFile::~PropertiesFile()
  14575. {
  14576. saveIfNeeded();
  14577. }
  14578. bool PropertiesFile::saveIfNeeded()
  14579. {
  14580. const ScopedLock sl (getLock());
  14581. return (! needsWriting) || save();
  14582. }
  14583. bool PropertiesFile::needsToBeSaved() const
  14584. {
  14585. const ScopedLock sl (getLock());
  14586. return needsWriting;
  14587. }
  14588. bool PropertiesFile::save()
  14589. {
  14590. const ScopedLock sl (getLock());
  14591. stopTimer();
  14592. if (file == File::nonexistent
  14593. || file.isDirectory()
  14594. || ! file.getParentDirectory().createDirectory())
  14595. return false;
  14596. if ((options & storeAsXML) != 0)
  14597. {
  14598. XmlElement doc (propertyFileXmlTag);
  14599. for (int i = 0; i < getAllProperties().size(); ++i)
  14600. {
  14601. XmlElement* const e = doc.createNewChildElement (propertyTagName);
  14602. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14603. // if the value seems to contain xml, store it as such..
  14604. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14605. XmlElement* const childElement = xmlContent.getDocumentElement();
  14606. if (childElement != 0)
  14607. e->addChildElement (childElement);
  14608. else
  14609. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14610. }
  14611. return doc.writeToFile (file, String::empty);
  14612. }
  14613. else
  14614. {
  14615. TemporaryFile tempFile (file);
  14616. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14617. if (out != 0)
  14618. {
  14619. if ((options & storeAsCompressedBinary) != 0)
  14620. {
  14621. out->writeInt (propFileMagicNumberCompressed);
  14622. out->flush();
  14623. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14624. }
  14625. else
  14626. {
  14627. // have you set up the storage option flags correctly?
  14628. jassert ((options & storeAsBinary) != 0);
  14629. out->writeInt (propFileMagicNumber);
  14630. }
  14631. const int numProperties = getAllProperties().size();
  14632. out->writeInt (numProperties);
  14633. for (int i = 0; i < numProperties; ++i)
  14634. {
  14635. out->writeString (getAllProperties().getAllKeys() [i]);
  14636. out->writeString (getAllProperties().getAllValues() [i]);
  14637. }
  14638. out = 0;
  14639. if (tempFile.overwriteTargetFileWithTemporary())
  14640. {
  14641. needsWriting = false;
  14642. return true;
  14643. }
  14644. }
  14645. }
  14646. return false;
  14647. }
  14648. void PropertiesFile::timerCallback()
  14649. {
  14650. saveIfNeeded();
  14651. }
  14652. void PropertiesFile::propertyChanged()
  14653. {
  14654. sendChangeMessage (this);
  14655. needsWriting = true;
  14656. if (timerInterval > 0)
  14657. startTimer (timerInterval);
  14658. else if (timerInterval == 0)
  14659. saveIfNeeded();
  14660. }
  14661. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14662. const String& fileNameSuffix,
  14663. const String& folderName,
  14664. const bool commonToAllUsers)
  14665. {
  14666. // mustn't have illegal characters in this name..
  14667. jassert (applicationName == File::createLegalFileName (applicationName));
  14668. #if JUCE_MAC || JUCE_IPHONE
  14669. File dir (commonToAllUsers ? "/Library/Preferences"
  14670. : "~/Library/Preferences");
  14671. if (folderName.isNotEmpty())
  14672. dir = dir.getChildFile (folderName);
  14673. #endif
  14674. #ifdef JUCE_LINUX
  14675. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14676. + (folderName.isNotEmpty() ? folderName
  14677. : (T(".") + applicationName)));
  14678. #endif
  14679. #if JUCE_WIN32
  14680. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14681. : File::userApplicationDataDirectory));
  14682. if (dir == File::nonexistent)
  14683. return File::nonexistent;
  14684. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14685. : applicationName);
  14686. #endif
  14687. return dir.getChildFile (applicationName)
  14688. .withFileExtension (fileNameSuffix);
  14689. }
  14690. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14691. const String& fileNameSuffix,
  14692. const String& folderName,
  14693. const bool commonToAllUsers,
  14694. const int millisecondsBeforeSaving,
  14695. const int propertiesFileOptions)
  14696. {
  14697. const File file (getDefaultAppSettingsFile (applicationName,
  14698. fileNameSuffix,
  14699. folderName,
  14700. commonToAllUsers));
  14701. jassert (file != File::nonexistent);
  14702. if (file == File::nonexistent)
  14703. return 0;
  14704. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14705. }
  14706. END_JUCE_NAMESPACE
  14707. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14708. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14709. BEGIN_JUCE_NAMESPACE
  14710. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14711. const String& fileWildcard_,
  14712. const String& openFileDialogTitle_,
  14713. const String& saveFileDialogTitle_)
  14714. : changedSinceSave (false),
  14715. fileExtension (fileExtension_),
  14716. fileWildcard (fileWildcard_),
  14717. openFileDialogTitle (openFileDialogTitle_),
  14718. saveFileDialogTitle (saveFileDialogTitle_)
  14719. {
  14720. }
  14721. FileBasedDocument::~FileBasedDocument()
  14722. {
  14723. }
  14724. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14725. {
  14726. changedSinceSave = hasChanged;
  14727. }
  14728. void FileBasedDocument::changed()
  14729. {
  14730. changedSinceSave = true;
  14731. sendChangeMessage (this);
  14732. }
  14733. void FileBasedDocument::setFile (const File& newFile)
  14734. {
  14735. if (documentFile != newFile)
  14736. {
  14737. documentFile = newFile;
  14738. changedSinceSave = true;
  14739. }
  14740. }
  14741. bool FileBasedDocument::loadFrom (const File& newFile,
  14742. const bool showMessageOnFailure)
  14743. {
  14744. MouseCursor::showWaitCursor();
  14745. const File oldFile (documentFile);
  14746. documentFile = newFile;
  14747. String error;
  14748. if (newFile.existsAsFile())
  14749. {
  14750. error = loadDocument (newFile);
  14751. if (error.isEmpty())
  14752. {
  14753. setChangedFlag (false);
  14754. MouseCursor::hideWaitCursor();
  14755. setLastDocumentOpened (newFile);
  14756. return true;
  14757. }
  14758. }
  14759. else
  14760. {
  14761. error = "The file doesn't exist";
  14762. }
  14763. documentFile = oldFile;
  14764. MouseCursor::hideWaitCursor();
  14765. if (showMessageOnFailure)
  14766. {
  14767. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14768. TRANS("Failed to open file..."),
  14769. TRANS("There was an error while trying to load the file:\n\n")
  14770. + newFile.getFullPathName()
  14771. + T("\n\n")
  14772. + error);
  14773. }
  14774. return false;
  14775. }
  14776. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14777. {
  14778. FileChooser fc (openFileDialogTitle,
  14779. getLastDocumentOpened(),
  14780. fileWildcard);
  14781. if (fc.browseForFileToOpen())
  14782. return loadFrom (fc.getResult(), showMessageOnFailure);
  14783. return false;
  14784. }
  14785. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14786. const bool showMessageOnFailure)
  14787. {
  14788. return saveAs (documentFile,
  14789. false,
  14790. askUserForFileIfNotSpecified,
  14791. showMessageOnFailure);
  14792. }
  14793. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14794. const bool warnAboutOverwritingExistingFiles,
  14795. const bool askUserForFileIfNotSpecified,
  14796. const bool showMessageOnFailure)
  14797. {
  14798. if (newFile == File::nonexistent)
  14799. {
  14800. if (askUserForFileIfNotSpecified)
  14801. {
  14802. return saveAsInteractive (true);
  14803. }
  14804. else
  14805. {
  14806. // can't save to an unspecified file
  14807. jassertfalse
  14808. return failedToWriteToFile;
  14809. }
  14810. }
  14811. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14812. {
  14813. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14814. TRANS("File already exists"),
  14815. TRANS("There's already a file called:\n\n")
  14816. + newFile.getFullPathName()
  14817. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14818. TRANS("overwrite"),
  14819. TRANS("cancel")))
  14820. {
  14821. return userCancelledSave;
  14822. }
  14823. }
  14824. MouseCursor::showWaitCursor();
  14825. const File oldFile (documentFile);
  14826. documentFile = newFile;
  14827. String error (saveDocument (newFile));
  14828. if (error.isEmpty())
  14829. {
  14830. setChangedFlag (false);
  14831. MouseCursor::hideWaitCursor();
  14832. return savedOk;
  14833. }
  14834. documentFile = oldFile;
  14835. MouseCursor::hideWaitCursor();
  14836. if (showMessageOnFailure)
  14837. {
  14838. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14839. TRANS("Error writing to file..."),
  14840. TRANS("An error occurred while trying to save \"")
  14841. + getDocumentTitle()
  14842. + TRANS("\" to the file:\n\n")
  14843. + newFile.getFullPathName()
  14844. + T("\n\n")
  14845. + error);
  14846. }
  14847. return failedToWriteToFile;
  14848. }
  14849. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14850. {
  14851. if (! hasChangedSinceSaved())
  14852. return savedOk;
  14853. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14854. TRANS("Closing document..."),
  14855. TRANS("Do you want to save the changes to \"")
  14856. + getDocumentTitle() + T("\"?"),
  14857. TRANS("save"),
  14858. TRANS("discard changes"),
  14859. TRANS("cancel"));
  14860. if (r == 1)
  14861. {
  14862. // save changes
  14863. return save (true, true);
  14864. }
  14865. else if (r == 2)
  14866. {
  14867. // discard changes
  14868. return savedOk;
  14869. }
  14870. return userCancelledSave;
  14871. }
  14872. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14873. {
  14874. File f;
  14875. if (documentFile.existsAsFile())
  14876. f = documentFile;
  14877. else
  14878. f = getLastDocumentOpened();
  14879. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14880. if (legalFilename.isEmpty())
  14881. legalFilename = "unnamed";
  14882. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14883. f = f.getSiblingFile (legalFilename);
  14884. else
  14885. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14886. f = f.withFileExtension (fileExtension)
  14887. .getNonexistentSibling (true);
  14888. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14889. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14890. {
  14891. setLastDocumentOpened (fc.getResult());
  14892. File chosen (fc.getResult());
  14893. if (chosen.getFileExtension().isEmpty())
  14894. {
  14895. chosen = chosen.withFileExtension (fileExtension);
  14896. if (chosen.exists())
  14897. {
  14898. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14899. TRANS("File already exists"),
  14900. TRANS("There's already a file called:\n\n")
  14901. + chosen.getFullPathName()
  14902. + T("\n\nAre you sure you want to overwrite it?"),
  14903. TRANS("overwrite"),
  14904. TRANS("cancel")))
  14905. {
  14906. return userCancelledSave;
  14907. }
  14908. }
  14909. }
  14910. return saveAs (chosen, false, false, true);
  14911. }
  14912. return userCancelledSave;
  14913. }
  14914. END_JUCE_NAMESPACE
  14915. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14916. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14917. BEGIN_JUCE_NAMESPACE
  14918. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14919. : maxNumberOfItems (10)
  14920. {
  14921. }
  14922. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14923. {
  14924. }
  14925. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14926. {
  14927. maxNumberOfItems = jmax (1, newMaxNumber);
  14928. while (getNumFiles() > maxNumberOfItems)
  14929. files.remove (getNumFiles() - 1);
  14930. }
  14931. int RecentlyOpenedFilesList::getNumFiles() const
  14932. {
  14933. return files.size();
  14934. }
  14935. const File RecentlyOpenedFilesList::getFile (const int index) const
  14936. {
  14937. return File (files [index]);
  14938. }
  14939. void RecentlyOpenedFilesList::clear()
  14940. {
  14941. files.clear();
  14942. }
  14943. void RecentlyOpenedFilesList::addFile (const File& file)
  14944. {
  14945. const String path (file.getFullPathName());
  14946. files.removeString (path, true);
  14947. files.insert (0, path);
  14948. setMaxNumberOfItems (maxNumberOfItems);
  14949. }
  14950. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14951. {
  14952. for (int i = getNumFiles(); --i >= 0;)
  14953. if (! getFile(i).exists())
  14954. files.remove (i);
  14955. }
  14956. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14957. const int baseItemId,
  14958. const bool showFullPaths,
  14959. const bool dontAddNonExistentFiles,
  14960. const File** filesToAvoid)
  14961. {
  14962. int num = 0;
  14963. for (int i = 0; i < getNumFiles(); ++i)
  14964. {
  14965. const File f (getFile(i));
  14966. if ((! dontAddNonExistentFiles) || f.exists())
  14967. {
  14968. bool needsAvoiding = false;
  14969. if (filesToAvoid != 0)
  14970. {
  14971. const File** avoid = filesToAvoid;
  14972. while (*avoid != 0)
  14973. {
  14974. if (f == **avoid)
  14975. {
  14976. needsAvoiding = true;
  14977. break;
  14978. }
  14979. ++avoid;
  14980. }
  14981. }
  14982. if (! needsAvoiding)
  14983. {
  14984. menuToAddTo.addItem (baseItemId + i,
  14985. showFullPaths ? f.getFullPathName()
  14986. : f.getFileName());
  14987. ++num;
  14988. }
  14989. }
  14990. }
  14991. return num;
  14992. }
  14993. const String RecentlyOpenedFilesList::toString() const
  14994. {
  14995. return files.joinIntoString (T("\n"));
  14996. }
  14997. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14998. {
  14999. clear();
  15000. files.addLines (stringifiedVersion);
  15001. setMaxNumberOfItems (maxNumberOfItems);
  15002. }
  15003. END_JUCE_NAMESPACE
  15004. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  15005. /*** Start of inlined file: juce_UndoManager.cpp ***/
  15006. BEGIN_JUCE_NAMESPACE
  15007. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  15008. const int minimumTransactions)
  15009. : totalUnitsStored (0),
  15010. nextIndex (0),
  15011. newTransaction (true),
  15012. reentrancyCheck (false)
  15013. {
  15014. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  15015. minimumTransactions);
  15016. }
  15017. UndoManager::~UndoManager()
  15018. {
  15019. clearUndoHistory();
  15020. }
  15021. void UndoManager::clearUndoHistory()
  15022. {
  15023. transactions.clear();
  15024. transactionNames.clear();
  15025. totalUnitsStored = 0;
  15026. nextIndex = 0;
  15027. sendChangeMessage (this);
  15028. }
  15029. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  15030. {
  15031. return totalUnitsStored;
  15032. }
  15033. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  15034. const int minimumTransactions)
  15035. {
  15036. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  15037. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  15038. }
  15039. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  15040. {
  15041. if (command != 0)
  15042. {
  15043. if (actionName.isNotEmpty())
  15044. currentTransactionName = actionName;
  15045. if (reentrancyCheck)
  15046. {
  15047. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  15048. // undo() methods, or else these actions won't actually get done.
  15049. return false;
  15050. }
  15051. else
  15052. {
  15053. bool success = false;
  15054. JUCE_TRY
  15055. {
  15056. success = command->perform();
  15057. }
  15058. JUCE_CATCH_EXCEPTION
  15059. jassert (success);
  15060. if (success)
  15061. {
  15062. if (nextIndex > 0 && ! newTransaction)
  15063. {
  15064. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  15065. jassert (commandSet != 0);
  15066. if (commandSet == 0)
  15067. return false;
  15068. commandSet->add (command);
  15069. }
  15070. else
  15071. {
  15072. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15073. commandSet->add (command);
  15074. transactions.insert (nextIndex, commandSet);
  15075. transactionNames.insert (nextIndex, currentTransactionName);
  15076. ++nextIndex;
  15077. }
  15078. totalUnitsStored += command->getSizeInUnits();
  15079. newTransaction = false;
  15080. }
  15081. while (nextIndex < transactions.size())
  15082. {
  15083. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15084. for (int i = lastSet->size(); --i >= 0;)
  15085. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15086. transactions.removeLast();
  15087. transactionNames.remove (transactionNames.size() - 1);
  15088. }
  15089. while (nextIndex > 0
  15090. && totalUnitsStored > maxNumUnitsToKeep
  15091. && transactions.size() > minimumTransactionsToKeep)
  15092. {
  15093. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15094. for (int i = firstSet->size(); --i >= 0;)
  15095. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15096. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15097. transactions.remove (0);
  15098. transactionNames.remove (0);
  15099. --nextIndex;
  15100. }
  15101. sendChangeMessage (this);
  15102. return success;
  15103. }
  15104. }
  15105. return false;
  15106. }
  15107. void UndoManager::beginNewTransaction (const String& actionName)
  15108. {
  15109. newTransaction = true;
  15110. currentTransactionName = actionName;
  15111. }
  15112. void UndoManager::setCurrentTransactionName (const String& newName)
  15113. {
  15114. currentTransactionName = newName;
  15115. }
  15116. bool UndoManager::canUndo() const
  15117. {
  15118. return nextIndex > 0;
  15119. }
  15120. bool UndoManager::canRedo() const
  15121. {
  15122. return nextIndex < transactions.size();
  15123. }
  15124. const String UndoManager::getUndoDescription() const
  15125. {
  15126. return transactionNames [nextIndex - 1];
  15127. }
  15128. const String UndoManager::getRedoDescription() const
  15129. {
  15130. return transactionNames [nextIndex];
  15131. }
  15132. bool UndoManager::undo()
  15133. {
  15134. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15135. if (commandSet == 0)
  15136. return false;
  15137. reentrancyCheck = true;
  15138. bool failed = false;
  15139. for (int i = commandSet->size(); --i >= 0;)
  15140. {
  15141. if (! commandSet->getUnchecked(i)->undo())
  15142. {
  15143. jassertfalse
  15144. failed = true;
  15145. break;
  15146. }
  15147. }
  15148. reentrancyCheck = false;
  15149. if (failed)
  15150. {
  15151. clearUndoHistory();
  15152. }
  15153. else
  15154. {
  15155. --nextIndex;
  15156. }
  15157. beginNewTransaction();
  15158. sendChangeMessage (this);
  15159. return true;
  15160. }
  15161. bool UndoManager::redo()
  15162. {
  15163. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15164. if (commandSet == 0)
  15165. return false;
  15166. reentrancyCheck = true;
  15167. bool failed = false;
  15168. for (int i = 0; i < commandSet->size(); ++i)
  15169. {
  15170. if (! commandSet->getUnchecked(i)->perform())
  15171. {
  15172. jassertfalse
  15173. failed = true;
  15174. break;
  15175. }
  15176. }
  15177. reentrancyCheck = false;
  15178. if (failed)
  15179. {
  15180. clearUndoHistory();
  15181. }
  15182. else
  15183. {
  15184. ++nextIndex;
  15185. }
  15186. beginNewTransaction();
  15187. sendChangeMessage (this);
  15188. return true;
  15189. }
  15190. bool UndoManager::undoCurrentTransactionOnly()
  15191. {
  15192. return newTransaction ? false
  15193. : undo();
  15194. }
  15195. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15196. {
  15197. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15198. if (commandSet != 0 && ! newTransaction)
  15199. {
  15200. for (int i = 0; i < commandSet->size(); ++i)
  15201. actionsFound.add (commandSet->getUnchecked(i));
  15202. }
  15203. }
  15204. int UndoManager::getNumActionsInCurrentTransaction() const
  15205. {
  15206. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15207. if (commandSet != 0 && ! newTransaction)
  15208. return commandSet->size();
  15209. return 0;
  15210. }
  15211. END_JUCE_NAMESPACE
  15212. /*** End of inlined file: juce_UndoManager.cpp ***/
  15213. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  15214. BEGIN_JUCE_NAMESPACE
  15215. static const char* const aiffFormatName = "AIFF file";
  15216. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15217. class AiffAudioFormatReader : public AudioFormatReader
  15218. {
  15219. public:
  15220. int bytesPerFrame;
  15221. int64 dataChunkStart;
  15222. bool littleEndian;
  15223. AiffAudioFormatReader (InputStream* in)
  15224. : AudioFormatReader (in, TRANS (aiffFormatName))
  15225. {
  15226. if (input->readInt() == chunkName ("FORM"))
  15227. {
  15228. const int len = input->readIntBigEndian();
  15229. const int64 end = input->getPosition() + len;
  15230. const int nextType = input->readInt();
  15231. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15232. {
  15233. bool hasGotVer = false;
  15234. bool hasGotData = false;
  15235. bool hasGotType = false;
  15236. while (input->getPosition() < end)
  15237. {
  15238. const int type = input->readInt();
  15239. const uint32 length = (uint32) input->readIntBigEndian();
  15240. const int64 chunkEnd = input->getPosition() + length;
  15241. if (type == chunkName ("FVER"))
  15242. {
  15243. hasGotVer = true;
  15244. const int ver = input->readIntBigEndian();
  15245. if (ver != 0 && ver != (int)0xa2805140)
  15246. break;
  15247. }
  15248. else if (type == chunkName ("COMM"))
  15249. {
  15250. hasGotType = true;
  15251. numChannels = (unsigned int)input->readShortBigEndian();
  15252. lengthInSamples = input->readIntBigEndian();
  15253. bitsPerSample = input->readShortBigEndian();
  15254. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15255. unsigned char sampleRateBytes[10];
  15256. input->read (sampleRateBytes, 10);
  15257. const int byte0 = sampleRateBytes[0];
  15258. if ((byte0 & 0x80) != 0
  15259. || byte0 <= 0x3F || byte0 > 0x40
  15260. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15261. break;
  15262. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15263. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15264. sampleRate = (int) sampRate;
  15265. if (length <= 18)
  15266. {
  15267. // some types don't have a chunk large enough to include a compression
  15268. // type, so assume it's just big-endian pcm
  15269. littleEndian = false;
  15270. }
  15271. else
  15272. {
  15273. const int compType = input->readInt();
  15274. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15275. {
  15276. littleEndian = false;
  15277. }
  15278. else if (compType == chunkName ("sowt"))
  15279. {
  15280. littleEndian = true;
  15281. }
  15282. else
  15283. {
  15284. sampleRate = 0;
  15285. break;
  15286. }
  15287. }
  15288. }
  15289. else if (type == chunkName ("SSND"))
  15290. {
  15291. hasGotData = true;
  15292. const int offset = input->readIntBigEndian();
  15293. dataChunkStart = input->getPosition() + 4 + offset;
  15294. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15295. }
  15296. else if ((hasGotVer && hasGotData && hasGotType)
  15297. || chunkEnd < input->getPosition()
  15298. || input->isExhausted())
  15299. {
  15300. break;
  15301. }
  15302. input->setPosition (chunkEnd);
  15303. }
  15304. }
  15305. }
  15306. }
  15307. ~AiffAudioFormatReader()
  15308. {
  15309. }
  15310. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15311. int64 startSampleInFile, int numSamples)
  15312. {
  15313. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15314. if (samplesAvailable < numSamples)
  15315. {
  15316. for (int i = numDestChannels; --i >= 0;)
  15317. if (destSamples[i] != 0)
  15318. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15319. numSamples = (int) samplesAvailable;
  15320. }
  15321. if (numSamples <= 0)
  15322. return true;
  15323. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15324. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15325. char tempBuffer [tempBufSize];
  15326. while (numSamples > 0)
  15327. {
  15328. int* left = destSamples[0];
  15329. if (left != 0)
  15330. left += startOffsetInDestBuffer;
  15331. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15332. if (right != 0)
  15333. right += startOffsetInDestBuffer;
  15334. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15335. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15336. if (bytesRead < numThisTime * bytesPerFrame)
  15337. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15338. if (bitsPerSample == 16)
  15339. {
  15340. if (littleEndian)
  15341. {
  15342. const short* src = (const short*) tempBuffer;
  15343. if (numChannels > 1)
  15344. {
  15345. if (left == 0)
  15346. {
  15347. for (int i = numThisTime; --i >= 0;)
  15348. {
  15349. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15350. ++src;
  15351. }
  15352. }
  15353. else if (right == 0)
  15354. {
  15355. for (int i = numThisTime; --i >= 0;)
  15356. {
  15357. ++src;
  15358. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15359. }
  15360. }
  15361. else
  15362. {
  15363. for (int i = numThisTime; --i >= 0;)
  15364. {
  15365. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15366. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15367. }
  15368. }
  15369. }
  15370. else
  15371. {
  15372. for (int i = numThisTime; --i >= 0;)
  15373. {
  15374. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15375. }
  15376. }
  15377. }
  15378. else
  15379. {
  15380. const char* src = (const char*) tempBuffer;
  15381. if (numChannels > 1)
  15382. {
  15383. if (left == 0)
  15384. {
  15385. for (int i = numThisTime; --i >= 0;)
  15386. {
  15387. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15388. src += 4;
  15389. }
  15390. }
  15391. else if (right == 0)
  15392. {
  15393. for (int i = numThisTime; --i >= 0;)
  15394. {
  15395. src += 2;
  15396. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15397. src += 2;
  15398. }
  15399. }
  15400. else
  15401. {
  15402. for (int i = numThisTime; --i >= 0;)
  15403. {
  15404. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15405. src += 2;
  15406. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15407. src += 2;
  15408. }
  15409. }
  15410. }
  15411. else
  15412. {
  15413. for (int i = numThisTime; --i >= 0;)
  15414. {
  15415. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15416. src += 2;
  15417. }
  15418. }
  15419. }
  15420. }
  15421. else if (bitsPerSample == 24)
  15422. {
  15423. const char* src = (const char*)tempBuffer;
  15424. if (littleEndian)
  15425. {
  15426. if (numChannels > 1)
  15427. {
  15428. if (left == 0)
  15429. {
  15430. for (int i = numThisTime; --i >= 0;)
  15431. {
  15432. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15433. src += 6;
  15434. }
  15435. }
  15436. else if (right == 0)
  15437. {
  15438. for (int i = numThisTime; --i >= 0;)
  15439. {
  15440. src += 3;
  15441. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15442. src += 3;
  15443. }
  15444. }
  15445. else
  15446. {
  15447. for (int i = numThisTime; --i >= 0;)
  15448. {
  15449. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15450. src += 3;
  15451. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15452. src += 3;
  15453. }
  15454. }
  15455. }
  15456. else
  15457. {
  15458. for (int i = numThisTime; --i >= 0;)
  15459. {
  15460. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15461. src += 3;
  15462. }
  15463. }
  15464. }
  15465. else
  15466. {
  15467. if (numChannels > 1)
  15468. {
  15469. if (left == 0)
  15470. {
  15471. for (int i = numThisTime; --i >= 0;)
  15472. {
  15473. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15474. src += 6;
  15475. }
  15476. }
  15477. else if (right == 0)
  15478. {
  15479. for (int i = numThisTime; --i >= 0;)
  15480. {
  15481. src += 3;
  15482. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15483. src += 3;
  15484. }
  15485. }
  15486. else
  15487. {
  15488. for (int i = numThisTime; --i >= 0;)
  15489. {
  15490. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15491. src += 3;
  15492. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15493. src += 3;
  15494. }
  15495. }
  15496. }
  15497. else
  15498. {
  15499. for (int i = numThisTime; --i >= 0;)
  15500. {
  15501. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15502. src += 3;
  15503. }
  15504. }
  15505. }
  15506. }
  15507. else if (bitsPerSample == 32)
  15508. {
  15509. const unsigned int* src = (const unsigned int*) tempBuffer;
  15510. unsigned int* l = (unsigned int*) left;
  15511. unsigned int* r = (unsigned int*) right;
  15512. if (littleEndian)
  15513. {
  15514. if (numChannels > 1)
  15515. {
  15516. if (l == 0)
  15517. {
  15518. for (int i = numThisTime; --i >= 0;)
  15519. {
  15520. ++src;
  15521. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15522. }
  15523. }
  15524. else if (r == 0)
  15525. {
  15526. for (int i = numThisTime; --i >= 0;)
  15527. {
  15528. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15529. ++src;
  15530. }
  15531. }
  15532. else
  15533. {
  15534. for (int i = numThisTime; --i >= 0;)
  15535. {
  15536. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15537. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15538. }
  15539. }
  15540. }
  15541. else
  15542. {
  15543. for (int i = numThisTime; --i >= 0;)
  15544. {
  15545. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15546. }
  15547. }
  15548. }
  15549. else
  15550. {
  15551. if (numChannels > 1)
  15552. {
  15553. if (l == 0)
  15554. {
  15555. for (int i = numThisTime; --i >= 0;)
  15556. {
  15557. ++src;
  15558. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15559. }
  15560. }
  15561. else if (r == 0)
  15562. {
  15563. for (int i = numThisTime; --i >= 0;)
  15564. {
  15565. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15566. ++src;
  15567. }
  15568. }
  15569. else
  15570. {
  15571. for (int i = numThisTime; --i >= 0;)
  15572. {
  15573. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15574. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15575. }
  15576. }
  15577. }
  15578. else
  15579. {
  15580. for (int i = numThisTime; --i >= 0;)
  15581. {
  15582. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15583. }
  15584. }
  15585. }
  15586. left = (int*) l;
  15587. right = (int*) r;
  15588. }
  15589. else if (bitsPerSample == 8)
  15590. {
  15591. const char* src = (const char*) tempBuffer;
  15592. if (numChannels > 1)
  15593. {
  15594. if (left == 0)
  15595. {
  15596. for (int i = numThisTime; --i >= 0;)
  15597. {
  15598. *right++ = ((int) *src++) << 24;
  15599. ++src;
  15600. }
  15601. }
  15602. else if (right == 0)
  15603. {
  15604. for (int i = numThisTime; --i >= 0;)
  15605. {
  15606. ++src;
  15607. *left++ = ((int) *src++) << 24;
  15608. }
  15609. }
  15610. else
  15611. {
  15612. for (int i = numThisTime; --i >= 0;)
  15613. {
  15614. *left++ = ((int) *src++) << 24;
  15615. *right++ = ((int) *src++) << 24;
  15616. }
  15617. }
  15618. }
  15619. else
  15620. {
  15621. for (int i = numThisTime; --i >= 0;)
  15622. {
  15623. *left++ = ((int) *src++) << 24;
  15624. }
  15625. }
  15626. }
  15627. startOffsetInDestBuffer += numThisTime;
  15628. numSamples -= numThisTime;
  15629. }
  15630. if (numSamples > 0)
  15631. {
  15632. for (int i = numDestChannels; --i >= 0;)
  15633. if (destSamples[i] != 0)
  15634. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15635. sizeof (int) * numSamples);
  15636. }
  15637. return true;
  15638. }
  15639. juce_UseDebuggingNewOperator
  15640. private:
  15641. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15642. const AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15643. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15644. };
  15645. class AiffAudioFormatWriter : public AudioFormatWriter
  15646. {
  15647. MemoryBlock tempBlock;
  15648. uint32 lengthInSamples, bytesWritten;
  15649. int64 headerPosition;
  15650. bool writeFailed;
  15651. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15652. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15653. const AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15654. void writeHeader()
  15655. {
  15656. const bool couldSeekOk = output->setPosition (headerPosition);
  15657. (void) couldSeekOk;
  15658. // if this fails, you've given it an output stream that can't seek! It needs
  15659. // to be able to seek back to write the header
  15660. jassert (couldSeekOk);
  15661. const int headerLen = 54;
  15662. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15663. audioBytes += (audioBytes & 1);
  15664. output->writeInt (chunkName ("FORM"));
  15665. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15666. output->writeInt (chunkName ("AIFF"));
  15667. output->writeInt (chunkName ("COMM"));
  15668. output->writeIntBigEndian (18);
  15669. output->writeShortBigEndian ((short) numChannels);
  15670. output->writeIntBigEndian (lengthInSamples);
  15671. output->writeShortBigEndian ((short) bitsPerSample);
  15672. uint8 sampleRateBytes[10];
  15673. zeromem (sampleRateBytes, 10);
  15674. if (sampleRate <= 1)
  15675. {
  15676. sampleRateBytes[0] = 0x3f;
  15677. sampleRateBytes[1] = 0xff;
  15678. sampleRateBytes[2] = 0x80;
  15679. }
  15680. else
  15681. {
  15682. int mask = 0x40000000;
  15683. sampleRateBytes[0] = 0x40;
  15684. if (sampleRate >= mask)
  15685. {
  15686. jassertfalse
  15687. sampleRateBytes[1] = 0x1d;
  15688. }
  15689. else
  15690. {
  15691. int n = (int) sampleRate;
  15692. int i;
  15693. for (i = 0; i <= 32 ; ++i)
  15694. {
  15695. if ((n & mask) != 0)
  15696. break;
  15697. mask >>= 1;
  15698. }
  15699. n = n << (i + 1);
  15700. sampleRateBytes[1] = (uint8) (29 - i);
  15701. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15702. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15703. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15704. sampleRateBytes[5] = (uint8) (n & 0xff);
  15705. }
  15706. }
  15707. output->write (sampleRateBytes, 10);
  15708. output->writeInt (chunkName ("SSND"));
  15709. output->writeIntBigEndian (audioBytes + 8);
  15710. output->writeInt (0);
  15711. output->writeInt (0);
  15712. jassert (output->getPosition() == headerLen);
  15713. }
  15714. public:
  15715. AiffAudioFormatWriter (OutputStream* out,
  15716. const double sampleRate_,
  15717. const unsigned int chans,
  15718. const int bits)
  15719. : AudioFormatWriter (out,
  15720. TRANS (aiffFormatName),
  15721. sampleRate_,
  15722. chans,
  15723. bits),
  15724. lengthInSamples (0),
  15725. bytesWritten (0),
  15726. writeFailed (false)
  15727. {
  15728. headerPosition = out->getPosition();
  15729. writeHeader();
  15730. }
  15731. ~AiffAudioFormatWriter()
  15732. {
  15733. if ((bytesWritten & 1) != 0)
  15734. output->writeByte (0);
  15735. writeHeader();
  15736. }
  15737. bool write (const int** data, int numSamples)
  15738. {
  15739. if (writeFailed)
  15740. return false;
  15741. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15742. tempBlock.ensureSize (bytes, false);
  15743. char* buffer = (char*) tempBlock.getData();
  15744. const int* left = data[0];
  15745. const int* right = data[1];
  15746. if (right == 0)
  15747. right = left;
  15748. if (bitsPerSample == 16)
  15749. {
  15750. short* b = (short*) buffer;
  15751. if (numChannels > 1)
  15752. {
  15753. for (int i = numSamples; --i >= 0;)
  15754. {
  15755. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15756. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15757. }
  15758. }
  15759. else
  15760. {
  15761. for (int i = numSamples; --i >= 0;)
  15762. {
  15763. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15764. }
  15765. }
  15766. }
  15767. else if (bitsPerSample == 24)
  15768. {
  15769. char* b = (char*) buffer;
  15770. if (numChannels > 1)
  15771. {
  15772. for (int i = numSamples; --i >= 0;)
  15773. {
  15774. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15775. b += 3;
  15776. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15777. b += 3;
  15778. }
  15779. }
  15780. else
  15781. {
  15782. for (int i = numSamples; --i >= 0;)
  15783. {
  15784. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15785. b += 3;
  15786. }
  15787. }
  15788. }
  15789. else if (bitsPerSample == 32)
  15790. {
  15791. uint32* b = (uint32*) buffer;
  15792. if (numChannels > 1)
  15793. {
  15794. for (int i = numSamples; --i >= 0;)
  15795. {
  15796. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15797. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15798. }
  15799. }
  15800. else
  15801. {
  15802. for (int i = numSamples; --i >= 0;)
  15803. {
  15804. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15805. }
  15806. }
  15807. }
  15808. else if (bitsPerSample == 8)
  15809. {
  15810. char* b = (char*) buffer;
  15811. if (numChannels > 1)
  15812. {
  15813. for (int i = numSamples; --i >= 0;)
  15814. {
  15815. *b++ = (char) (*left++ >> 24);
  15816. *b++ = (char) (*right++ >> 24);
  15817. }
  15818. }
  15819. else
  15820. {
  15821. for (int i = numSamples; --i >= 0;)
  15822. {
  15823. *b++ = (char) (*left++ >> 24);
  15824. }
  15825. }
  15826. }
  15827. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15828. || ! output->write (buffer, bytes))
  15829. {
  15830. // failed to write to disk, so let's try writing the header.
  15831. // If it's just run out of disk space, then if it does manage
  15832. // to write the header, we'll still have a useable file..
  15833. writeHeader();
  15834. writeFailed = true;
  15835. return false;
  15836. }
  15837. else
  15838. {
  15839. bytesWritten += bytes;
  15840. lengthInSamples += numSamples;
  15841. return true;
  15842. }
  15843. }
  15844. juce_UseDebuggingNewOperator
  15845. };
  15846. AiffAudioFormat::AiffAudioFormat()
  15847. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15848. {
  15849. }
  15850. AiffAudioFormat::~AiffAudioFormat()
  15851. {
  15852. }
  15853. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15854. {
  15855. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15856. return Array <int> (rates);
  15857. }
  15858. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15859. {
  15860. const int depths[] = { 8, 16, 24, 0 };
  15861. return Array <int> (depths);
  15862. }
  15863. bool AiffAudioFormat::canDoStereo()
  15864. {
  15865. return true;
  15866. }
  15867. bool AiffAudioFormat::canDoMono()
  15868. {
  15869. return true;
  15870. }
  15871. #if JUCE_MAC
  15872. bool AiffAudioFormat::canHandleFile (const File& f)
  15873. {
  15874. if (AudioFormat::canHandleFile (f))
  15875. return true;
  15876. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15877. return type == 'AIFF' || type == 'AIFC'
  15878. || type == 'aiff' || type == 'aifc';
  15879. }
  15880. #endif
  15881. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15882. const bool deleteStreamIfOpeningFails)
  15883. {
  15884. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15885. if (w->sampleRate != 0)
  15886. return w.release();
  15887. if (! deleteStreamIfOpeningFails)
  15888. w->input = 0;
  15889. return 0;
  15890. }
  15891. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15892. double sampleRate,
  15893. unsigned int chans,
  15894. int bitsPerSample,
  15895. const StringPairArray& /*metadataValues*/,
  15896. int /*qualityOptionIndex*/)
  15897. {
  15898. if (getPossibleBitDepths().contains (bitsPerSample))
  15899. {
  15900. return new AiffAudioFormatWriter (out,
  15901. sampleRate,
  15902. chans,
  15903. bitsPerSample);
  15904. }
  15905. return 0;
  15906. }
  15907. END_JUCE_NAMESPACE
  15908. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15909. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15910. BEGIN_JUCE_NAMESPACE
  15911. #if JUCE_MAC && JUCE_USE_CDREADER
  15912. // Mac version doesn't need any native code because it's all done with files..
  15913. // Windows + Linux versions are in the platform-dependent code sections.
  15914. static void findCDs (Array<File>& cds)
  15915. {
  15916. File volumes ("/Volumes");
  15917. volumes.findChildFiles (cds, File::findDirectories, false);
  15918. for (int i = cds.size(); --i >= 0;)
  15919. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15920. cds.remove (i);
  15921. }
  15922. const StringArray AudioCDReader::getAvailableCDNames()
  15923. {
  15924. Array<File> cds;
  15925. findCDs (cds);
  15926. StringArray names;
  15927. for (int i = 0; i < cds.size(); ++i)
  15928. names.add (cds.getReference(i).getFileName());
  15929. return names;
  15930. }
  15931. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15932. {
  15933. Array<File> cds;
  15934. findCDs (cds);
  15935. if (cds[index] != File::nonexistent)
  15936. return new AudioCDReader (cds[index]);
  15937. else
  15938. return 0;
  15939. }
  15940. AudioCDReader::AudioCDReader (const File& volume)
  15941. : AudioFormatReader (0, "CD Audio"),
  15942. volumeDir (volume),
  15943. currentReaderTrack (-1),
  15944. reader (0)
  15945. {
  15946. sampleRate = 44100.0;
  15947. bitsPerSample = 16;
  15948. numChannels = 2;
  15949. usesFloatingPointData = false;
  15950. refreshTrackLengths();
  15951. }
  15952. AudioCDReader::~AudioCDReader()
  15953. {
  15954. }
  15955. static int getTrackNumber (const File& file)
  15956. {
  15957. return file.getFileName()
  15958. .initialSectionContainingOnly (T("0123456789"))
  15959. .getIntValue();
  15960. }
  15961. int AudioCDReader::compareElements (const File& first, const File& second)
  15962. {
  15963. const int firstTrack = getTrackNumber (first);
  15964. const int secondTrack = getTrackNumber (second);
  15965. jassert (firstTrack > 0 && secondTrack > 0);
  15966. return firstTrack - secondTrack;
  15967. }
  15968. void AudioCDReader::refreshTrackLengths()
  15969. {
  15970. tracks.clear();
  15971. trackStartSamples.clear();
  15972. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15973. tracks.sort (*this);
  15974. AiffAudioFormat format;
  15975. int sample = 0;
  15976. for (int i = 0; i < tracks.size(); ++i)
  15977. {
  15978. trackStartSamples.add (sample);
  15979. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15980. if (in != 0)
  15981. {
  15982. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15983. if (r != 0)
  15984. sample += (int) r->lengthInSamples;
  15985. }
  15986. }
  15987. trackStartSamples.add (sample);
  15988. lengthInSamples = sample;
  15989. }
  15990. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15991. int64 startSampleInFile, int numSamples)
  15992. {
  15993. while (numSamples > 0)
  15994. {
  15995. int track = -1;
  15996. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15997. {
  15998. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15999. {
  16000. track = i;
  16001. break;
  16002. }
  16003. }
  16004. if (track < 0)
  16005. return false;
  16006. if (track != currentReaderTrack)
  16007. {
  16008. reader = 0;
  16009. FileInputStream* const in = tracks [track].createInputStream();
  16010. if (in != 0)
  16011. {
  16012. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  16013. AiffAudioFormat format;
  16014. reader = format.createReaderFor (bin, true);
  16015. if (reader == 0)
  16016. currentReaderTrack = -1;
  16017. else
  16018. currentReaderTrack = track;
  16019. }
  16020. }
  16021. if (reader == 0)
  16022. return false;
  16023. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  16024. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  16025. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  16026. numSamples -= numAvailable;
  16027. startSampleInFile += numAvailable;
  16028. }
  16029. return true;
  16030. }
  16031. bool AudioCDReader::isCDStillPresent() const
  16032. {
  16033. return volumeDir.exists();
  16034. }
  16035. int AudioCDReader::getNumTracks() const
  16036. {
  16037. return tracks.size();
  16038. }
  16039. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  16040. {
  16041. return trackStartSamples [trackNum];
  16042. }
  16043. bool AudioCDReader::isTrackAudio (int trackNum) const
  16044. {
  16045. return tracks [trackNum] != File::nonexistent;
  16046. }
  16047. void AudioCDReader::enableIndexScanning (bool b)
  16048. {
  16049. // any way to do this on a Mac??
  16050. }
  16051. int AudioCDReader::getLastIndex() const
  16052. {
  16053. return 0;
  16054. }
  16055. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  16056. {
  16057. return Array <int>();
  16058. }
  16059. int AudioCDReader::getCDDBId()
  16060. {
  16061. return 0; //xxx
  16062. }
  16063. #endif
  16064. END_JUCE_NAMESPACE
  16065. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  16066. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  16067. BEGIN_JUCE_NAMESPACE
  16068. AudioFormatReader::AudioFormatReader (InputStream* const in,
  16069. const String& formatName_)
  16070. : sampleRate (0),
  16071. bitsPerSample (0),
  16072. lengthInSamples (0),
  16073. numChannels (0),
  16074. usesFloatingPointData (false),
  16075. input (in),
  16076. formatName (formatName_)
  16077. {
  16078. }
  16079. AudioFormatReader::~AudioFormatReader()
  16080. {
  16081. delete input;
  16082. }
  16083. bool AudioFormatReader::read (int** destSamples,
  16084. int numDestChannels,
  16085. int64 startSampleInSource,
  16086. int numSamplesToRead,
  16087. const bool fillLeftoverChannelsWithCopies)
  16088. {
  16089. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16090. int startOffsetInDestBuffer = 0;
  16091. if (startSampleInSource < 0)
  16092. {
  16093. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16094. for (int i = numDestChannels; --i >= 0;)
  16095. if (destSamples[i] != 0)
  16096. zeromem (destSamples[i], sizeof (int) * silence);
  16097. startOffsetInDestBuffer += silence;
  16098. numSamplesToRead -= silence;
  16099. startSampleInSource = 0;
  16100. }
  16101. if (numSamplesToRead <= 0)
  16102. return true;
  16103. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16104. startSampleInSource, numSamplesToRead))
  16105. return false;
  16106. if (numDestChannels > (int) numChannels)
  16107. {
  16108. if (fillLeftoverChannelsWithCopies)
  16109. {
  16110. int* lastFullChannel = destSamples[0];
  16111. for (int i = numDestChannels; --i > 0;)
  16112. {
  16113. if (destSamples[i] != 0)
  16114. {
  16115. lastFullChannel = destSamples[i];
  16116. break;
  16117. }
  16118. }
  16119. if (lastFullChannel != 0)
  16120. for (int i = numChannels; i < numDestChannels; ++i)
  16121. if (destSamples[i] != 0)
  16122. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16123. }
  16124. else
  16125. {
  16126. for (int i = numChannels; i < numDestChannels; ++i)
  16127. if (destSamples[i] != 0)
  16128. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16129. }
  16130. }
  16131. return true;
  16132. }
  16133. static void findMaxMin (const float* src, const int num,
  16134. float& maxVal, float& minVal)
  16135. {
  16136. float mn = src[0];
  16137. float mx = mn;
  16138. for (int i = 1; i < num; ++i)
  16139. {
  16140. const float s = src[i];
  16141. if (s > mx)
  16142. mx = s;
  16143. if (s < mn)
  16144. mn = s;
  16145. }
  16146. maxVal = mx;
  16147. minVal = mn;
  16148. }
  16149. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16150. int64 numSamples,
  16151. float& lowestLeft, float& highestLeft,
  16152. float& lowestRight, float& highestRight)
  16153. {
  16154. if (numSamples <= 0)
  16155. {
  16156. lowestLeft = 0;
  16157. lowestRight = 0;
  16158. highestLeft = 0;
  16159. highestRight = 0;
  16160. return;
  16161. }
  16162. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16163. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16164. int* tempBuffer[3];
  16165. tempBuffer[0] = (int*) tempSpace.getData();
  16166. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16167. tempBuffer[2] = 0;
  16168. if (usesFloatingPointData)
  16169. {
  16170. float lmin = 1.0e6f;
  16171. float lmax = -lmin;
  16172. float rmin = lmin;
  16173. float rmax = lmax;
  16174. while (numSamples > 0)
  16175. {
  16176. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16177. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16178. numSamples -= numToDo;
  16179. startSampleInFile += numToDo;
  16180. float bufmin, bufmax;
  16181. findMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16182. lmin = jmin (lmin, bufmin);
  16183. lmax = jmax (lmax, bufmax);
  16184. if (numChannels > 1)
  16185. {
  16186. findMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16187. rmin = jmin (rmin, bufmin);
  16188. rmax = jmax (rmax, bufmax);
  16189. }
  16190. }
  16191. if (numChannels <= 1)
  16192. {
  16193. rmax = lmax;
  16194. rmin = lmin;
  16195. }
  16196. lowestLeft = lmin;
  16197. highestLeft = lmax;
  16198. lowestRight = rmin;
  16199. highestRight = rmax;
  16200. }
  16201. else
  16202. {
  16203. int lmax = std::numeric_limits<int>::min();
  16204. int lmin = std::numeric_limits<int>::max();
  16205. int rmax = std::numeric_limits<int>::min();
  16206. int rmin = std::numeric_limits<int>::max();
  16207. while (numSamples > 0)
  16208. {
  16209. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16210. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16211. numSamples -= numToDo;
  16212. startSampleInFile += numToDo;
  16213. for (int j = numChannels; --j >= 0;)
  16214. {
  16215. int bufMax = std::numeric_limits<int>::min();
  16216. int bufMin = std::numeric_limits<int>::max();
  16217. const int* const b = tempBuffer[j];
  16218. for (int i = 0; i < numToDo; ++i)
  16219. {
  16220. const int samp = b[i];
  16221. if (samp < bufMin)
  16222. bufMin = samp;
  16223. if (samp > bufMax)
  16224. bufMax = samp;
  16225. }
  16226. if (j == 0)
  16227. {
  16228. lmax = jmax (lmax, bufMax);
  16229. lmin = jmin (lmin, bufMin);
  16230. }
  16231. else
  16232. {
  16233. rmax = jmax (rmax, bufMax);
  16234. rmin = jmin (rmin, bufMin);
  16235. }
  16236. }
  16237. }
  16238. if (numChannels <= 1)
  16239. {
  16240. rmax = lmax;
  16241. rmin = lmin;
  16242. }
  16243. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  16244. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  16245. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  16246. highestRight = rmax / (float) std::numeric_limits<int>::max();
  16247. }
  16248. }
  16249. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16250. int64 numSamplesToSearch,
  16251. const double magnitudeRangeMinimum,
  16252. const double magnitudeRangeMaximum,
  16253. const int minimumConsecutiveSamples)
  16254. {
  16255. if (numSamplesToSearch == 0)
  16256. return -1;
  16257. const int bufferSize = 4096;
  16258. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16259. int* tempBuffer[3];
  16260. tempBuffer[0] = (int*) tempSpace.getData();
  16261. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16262. tempBuffer[2] = 0;
  16263. int consecutive = 0;
  16264. int64 firstMatchPos = -1;
  16265. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16266. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16267. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16268. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16269. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16270. while (numSamplesToSearch != 0)
  16271. {
  16272. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16273. int64 bufferStart = startSample;
  16274. if (numSamplesToSearch < 0)
  16275. bufferStart -= numThisTime;
  16276. if (bufferStart >= (int) lengthInSamples)
  16277. break;
  16278. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16279. int num = numThisTime;
  16280. while (--num >= 0)
  16281. {
  16282. if (numSamplesToSearch < 0)
  16283. --startSample;
  16284. bool matches = false;
  16285. const int index = (int) (startSample - bufferStart);
  16286. if (usesFloatingPointData)
  16287. {
  16288. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16289. if (sample1 >= magnitudeRangeMinimum
  16290. && sample1 <= magnitudeRangeMaximum)
  16291. {
  16292. matches = true;
  16293. }
  16294. else if (numChannels > 1)
  16295. {
  16296. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16297. matches = (sample2 >= magnitudeRangeMinimum
  16298. && sample2 <= magnitudeRangeMaximum);
  16299. }
  16300. }
  16301. else
  16302. {
  16303. const int sample1 = abs (tempBuffer[0] [index]);
  16304. if (sample1 >= intMagnitudeRangeMinimum
  16305. && sample1 <= intMagnitudeRangeMaximum)
  16306. {
  16307. matches = true;
  16308. }
  16309. else if (numChannels > 1)
  16310. {
  16311. const int sample2 = abs (tempBuffer[1][index]);
  16312. matches = (sample2 >= intMagnitudeRangeMinimum
  16313. && sample2 <= intMagnitudeRangeMaximum);
  16314. }
  16315. }
  16316. if (matches)
  16317. {
  16318. if (firstMatchPos < 0)
  16319. firstMatchPos = startSample;
  16320. if (++consecutive >= minimumConsecutiveSamples)
  16321. {
  16322. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16323. return -1;
  16324. return firstMatchPos;
  16325. }
  16326. }
  16327. else
  16328. {
  16329. consecutive = 0;
  16330. firstMatchPos = -1;
  16331. }
  16332. if (numSamplesToSearch > 0)
  16333. ++startSample;
  16334. }
  16335. if (numSamplesToSearch > 0)
  16336. numSamplesToSearch -= numThisTime;
  16337. else
  16338. numSamplesToSearch += numThisTime;
  16339. }
  16340. return -1;
  16341. }
  16342. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16343. const String& formatName_,
  16344. const double rate,
  16345. const unsigned int numChannels_,
  16346. const unsigned int bitsPerSample_)
  16347. : sampleRate (rate),
  16348. numChannels (numChannels_),
  16349. bitsPerSample (bitsPerSample_),
  16350. usesFloatingPointData (false),
  16351. output (out),
  16352. formatName (formatName_)
  16353. {
  16354. }
  16355. AudioFormatWriter::~AudioFormatWriter()
  16356. {
  16357. delete output;
  16358. }
  16359. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16360. int64 startSample,
  16361. int64 numSamplesToRead)
  16362. {
  16363. const int bufferSize = 16384;
  16364. const int maxChans = 128;
  16365. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16366. int* buffers [maxChans];
  16367. for (int i = maxChans; --i >= 0;)
  16368. buffers[i] = 0;
  16369. if (numSamplesToRead < 0)
  16370. numSamplesToRead = reader.lengthInSamples;
  16371. while (numSamplesToRead > 0)
  16372. {
  16373. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16374. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16375. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16376. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16377. return false;
  16378. if (reader.usesFloatingPointData != isFloatingPoint())
  16379. {
  16380. int** bufferChan = buffers;
  16381. while (*bufferChan != 0)
  16382. {
  16383. int* b = *bufferChan++;
  16384. if (isFloatingPoint())
  16385. {
  16386. // int -> float
  16387. const double factor = 1.0 / std::numeric_limits<int>::max();
  16388. for (int i = 0; i < numToDo; ++i)
  16389. ((float*) b)[i] = (float) (factor * b[i]);
  16390. }
  16391. else
  16392. {
  16393. // float -> int
  16394. for (int i = 0; i < numToDo; ++i)
  16395. {
  16396. const double samp = *(const float*) b;
  16397. if (samp <= -1.0)
  16398. *b++ = std::numeric_limits<int>::min();
  16399. else if (samp >= 1.0)
  16400. *b++ = std::numeric_limits<int>::max();
  16401. else
  16402. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16403. }
  16404. }
  16405. }
  16406. }
  16407. if (! write ((const int**) buffers, numToDo))
  16408. return false;
  16409. numSamplesToRead -= numToDo;
  16410. startSample += numToDo;
  16411. }
  16412. return true;
  16413. }
  16414. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16415. int numSamplesToRead,
  16416. const int samplesPerBlock)
  16417. {
  16418. const int maxChans = 128;
  16419. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16420. int* buffers [maxChans];
  16421. while (numSamplesToRead > 0)
  16422. {
  16423. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16424. AudioSourceChannelInfo info;
  16425. info.buffer = &tempBuffer;
  16426. info.startSample = 0;
  16427. info.numSamples = numToDo;
  16428. info.clearActiveBufferRegion();
  16429. source.getNextAudioBlock (info);
  16430. int i;
  16431. for (i = maxChans; --i >= 0;)
  16432. buffers[i] = 0;
  16433. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16434. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16435. if (! isFloatingPoint())
  16436. {
  16437. int** bufferChan = buffers;
  16438. while (*bufferChan != 0)
  16439. {
  16440. int* b = *bufferChan++;
  16441. // float -> int
  16442. for (int j = numToDo; --j >= 0;)
  16443. {
  16444. const double samp = *(const float*) b;
  16445. if (samp <= -1.0)
  16446. *b++ = std::numeric_limits<int>::min();
  16447. else if (samp >= 1.0)
  16448. *b++ = std::numeric_limits<int>::max();
  16449. else
  16450. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16451. }
  16452. }
  16453. }
  16454. if (! write ((const int**) buffers, numToDo))
  16455. return false;
  16456. numSamplesToRead -= numToDo;
  16457. }
  16458. return true;
  16459. }
  16460. AudioFormat::AudioFormat (const String& name,
  16461. const tchar** const extensions)
  16462. : formatName (name),
  16463. fileExtensions (extensions)
  16464. {
  16465. }
  16466. AudioFormat::~AudioFormat()
  16467. {
  16468. }
  16469. const String& AudioFormat::getFormatName() const
  16470. {
  16471. return formatName;
  16472. }
  16473. const StringArray& AudioFormat::getFileExtensions() const
  16474. {
  16475. return fileExtensions;
  16476. }
  16477. bool AudioFormat::canHandleFile (const File& f)
  16478. {
  16479. for (int i = 0; i < fileExtensions.size(); ++i)
  16480. if (f.hasFileExtension (fileExtensions[i]))
  16481. return true;
  16482. return false;
  16483. }
  16484. bool AudioFormat::isCompressed()
  16485. {
  16486. return false;
  16487. }
  16488. const StringArray AudioFormat::getQualityOptions()
  16489. {
  16490. return StringArray();
  16491. }
  16492. END_JUCE_NAMESPACE
  16493. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16494. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16495. BEGIN_JUCE_NAMESPACE
  16496. AudioFormatManager::AudioFormatManager()
  16497. : defaultFormatIndex (0)
  16498. {
  16499. }
  16500. AudioFormatManager::~AudioFormatManager()
  16501. {
  16502. clearFormats();
  16503. clearSingletonInstance();
  16504. }
  16505. juce_ImplementSingleton (AudioFormatManager);
  16506. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16507. const bool makeThisTheDefaultFormat)
  16508. {
  16509. jassert (newFormat != 0);
  16510. if (newFormat != 0)
  16511. {
  16512. #ifdef JUCE_DEBUG
  16513. for (int i = getNumKnownFormats(); --i >= 0;)
  16514. {
  16515. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16516. {
  16517. jassertfalse // trying to add the same format twice!
  16518. }
  16519. }
  16520. #endif
  16521. if (makeThisTheDefaultFormat)
  16522. defaultFormatIndex = knownFormats.size();
  16523. knownFormats.add (newFormat);
  16524. }
  16525. }
  16526. void AudioFormatManager::registerBasicFormats()
  16527. {
  16528. #if JUCE_MAC
  16529. registerFormat (new AiffAudioFormat(), true);
  16530. registerFormat (new WavAudioFormat(), false);
  16531. #else
  16532. registerFormat (new WavAudioFormat(), true);
  16533. registerFormat (new AiffAudioFormat(), false);
  16534. #endif
  16535. #if JUCE_USE_FLAC
  16536. registerFormat (new FlacAudioFormat(), false);
  16537. #endif
  16538. #if JUCE_USE_OGGVORBIS
  16539. registerFormat (new OggVorbisAudioFormat(), false);
  16540. #endif
  16541. }
  16542. void AudioFormatManager::clearFormats()
  16543. {
  16544. for (int i = getNumKnownFormats(); --i >= 0;)
  16545. delete getKnownFormat(i);
  16546. knownFormats.clear();
  16547. defaultFormatIndex = 0;
  16548. }
  16549. int AudioFormatManager::getNumKnownFormats() const
  16550. {
  16551. return knownFormats.size();
  16552. }
  16553. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16554. {
  16555. return (AudioFormat*) knownFormats [index];
  16556. }
  16557. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16558. {
  16559. return getKnownFormat (defaultFormatIndex);
  16560. }
  16561. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16562. {
  16563. String e (fileExtension);
  16564. if (! e.startsWithChar (T('.')))
  16565. e = T(".") + e;
  16566. for (int i = 0; i < getNumKnownFormats(); ++i)
  16567. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16568. return getKnownFormat(i);
  16569. return 0;
  16570. }
  16571. const String AudioFormatManager::getWildcardForAllFormats() const
  16572. {
  16573. StringArray allExtensions;
  16574. int i;
  16575. for (i = 0; i < getNumKnownFormats(); ++i)
  16576. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16577. allExtensions.trim();
  16578. allExtensions.removeEmptyStrings();
  16579. String s;
  16580. for (i = 0; i < allExtensions.size(); ++i)
  16581. {
  16582. s << T('*');
  16583. if (! allExtensions[i].startsWithChar (T('.')))
  16584. s << T('.');
  16585. s << allExtensions[i];
  16586. if (i < allExtensions.size() - 1)
  16587. s << T(';');
  16588. }
  16589. return s;
  16590. }
  16591. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16592. {
  16593. // you need to actually register some formats before the manager can
  16594. // use them to open a file!
  16595. jassert (knownFormats.size() > 0);
  16596. for (int i = 0; i < getNumKnownFormats(); ++i)
  16597. {
  16598. AudioFormat* const af = getKnownFormat(i);
  16599. if (af->canHandleFile (file))
  16600. {
  16601. InputStream* const in = file.createInputStream();
  16602. if (in != 0)
  16603. {
  16604. AudioFormatReader* const r = af->createReaderFor (in, true);
  16605. if (r != 0)
  16606. return r;
  16607. }
  16608. }
  16609. }
  16610. return 0;
  16611. }
  16612. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16613. {
  16614. // you need to actually register some formats before the manager can
  16615. // use them to open a file!
  16616. jassert (knownFormats.size() > 0);
  16617. ScopedPointer <InputStream> in (audioFileStream);
  16618. if (in != 0)
  16619. {
  16620. const int64 originalStreamPos = in->getPosition();
  16621. for (int i = 0; i < getNumKnownFormats(); ++i)
  16622. {
  16623. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16624. if (r != 0)
  16625. {
  16626. in.release();
  16627. return r;
  16628. }
  16629. in->setPosition (originalStreamPos);
  16630. // the stream that is passed-in must be capable of being repositioned so
  16631. // that all the formats can have a go at opening it.
  16632. jassert (in->getPosition() == originalStreamPos);
  16633. }
  16634. }
  16635. return 0;
  16636. }
  16637. END_JUCE_NAMESPACE
  16638. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16639. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16640. BEGIN_JUCE_NAMESPACE
  16641. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16642. const int64 startSample_,
  16643. const int64 length_,
  16644. const bool deleteSourceWhenDeleted_)
  16645. : AudioFormatReader (0, source_->getFormatName()),
  16646. source (source_),
  16647. startSample (startSample_),
  16648. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16649. {
  16650. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16651. sampleRate = source->sampleRate;
  16652. bitsPerSample = source->bitsPerSample;
  16653. lengthInSamples = length;
  16654. numChannels = source->numChannels;
  16655. usesFloatingPointData = source->usesFloatingPointData;
  16656. }
  16657. AudioSubsectionReader::~AudioSubsectionReader()
  16658. {
  16659. if (deleteSourceWhenDeleted)
  16660. delete source;
  16661. }
  16662. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16663. int64 startSampleInFile, int numSamples)
  16664. {
  16665. if (startSampleInFile + numSamples > length)
  16666. {
  16667. for (int i = numDestChannels; --i >= 0;)
  16668. if (destSamples[i] != 0)
  16669. zeromem (destSamples[i], sizeof (int) * numSamples);
  16670. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16671. if (numSamples <= 0)
  16672. return true;
  16673. }
  16674. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16675. startSampleInFile + startSample, numSamples);
  16676. }
  16677. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16678. int64 numSamples,
  16679. float& lowestLeft,
  16680. float& highestLeft,
  16681. float& lowestRight,
  16682. float& highestRight)
  16683. {
  16684. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16685. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16686. source->readMaxLevels (startSampleInFile + startSample,
  16687. numSamples,
  16688. lowestLeft,
  16689. highestLeft,
  16690. lowestRight,
  16691. highestRight);
  16692. }
  16693. END_JUCE_NAMESPACE
  16694. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16695. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16696. BEGIN_JUCE_NAMESPACE
  16697. const int timeBeforeDeletingReader = 2000;
  16698. struct AudioThumbnailDataFormat
  16699. {
  16700. char thumbnailMagic[4];
  16701. int samplesPerThumbSample;
  16702. int64 totalSamples; // source samples
  16703. int64 numFinishedSamples; // source samples
  16704. int numThumbnailSamples;
  16705. int numChannels;
  16706. int sampleRate;
  16707. char future[16];
  16708. char data[1];
  16709. };
  16710. #if JUCE_BIG_ENDIAN
  16711. static void swap (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16712. static void swap (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16713. #endif
  16714. static void swapEndiannessIfNeeded (AudioThumbnailDataFormat* const d)
  16715. {
  16716. (void) d;
  16717. #if JUCE_BIG_ENDIAN
  16718. swap (d->samplesPerThumbSample);
  16719. swap (d->totalSamples);
  16720. swap (d->numFinishedSamples);
  16721. swap (d->numThumbnailSamples);
  16722. swap (d->numChannels);
  16723. swap (d->sampleRate);
  16724. #endif
  16725. }
  16726. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16727. AudioFormatManager& formatManagerToUse_,
  16728. AudioThumbnailCache& cacheToUse)
  16729. : formatManagerToUse (formatManagerToUse_),
  16730. cache (cacheToUse),
  16731. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16732. {
  16733. clear();
  16734. }
  16735. AudioThumbnail::~AudioThumbnail()
  16736. {
  16737. cache.removeThumbnail (this);
  16738. const ScopedLock sl (readerLock);
  16739. reader = 0;
  16740. }
  16741. void AudioThumbnail::setSource (InputSource* const newSource)
  16742. {
  16743. cache.removeThumbnail (this);
  16744. timerCallback(); // stops the timer and deletes the reader
  16745. source = newSource;
  16746. clear();
  16747. if (newSource != 0
  16748. && ! (cache.loadThumb (*this, newSource->hashCode())
  16749. && isFullyLoaded()))
  16750. {
  16751. {
  16752. const ScopedLock sl (readerLock);
  16753. reader = createReader();
  16754. }
  16755. if (reader != 0)
  16756. {
  16757. initialiseFromAudioFile (*reader);
  16758. cache.addThumbnail (this);
  16759. }
  16760. }
  16761. sendChangeMessage (this);
  16762. }
  16763. bool AudioThumbnail::useTimeSlice()
  16764. {
  16765. const ScopedLock sl (readerLock);
  16766. if (isFullyLoaded())
  16767. {
  16768. if (reader != 0)
  16769. startTimer (timeBeforeDeletingReader);
  16770. cache.removeThumbnail (this);
  16771. return false;
  16772. }
  16773. if (reader == 0)
  16774. reader = createReader();
  16775. if (reader != 0)
  16776. {
  16777. readNextBlockFromAudioFile (*reader);
  16778. stopTimer();
  16779. sendChangeMessage (this);
  16780. const bool justFinished = isFullyLoaded();
  16781. if (justFinished)
  16782. cache.storeThumb (*this, source->hashCode());
  16783. return ! justFinished;
  16784. }
  16785. return false;
  16786. }
  16787. AudioFormatReader* AudioThumbnail::createReader() const
  16788. {
  16789. if (source != 0)
  16790. {
  16791. InputStream* const audioFileStream = source->createInputStream();
  16792. if (audioFileStream != 0)
  16793. return formatManagerToUse.createReaderFor (audioFileStream);
  16794. }
  16795. return 0;
  16796. }
  16797. void AudioThumbnail::timerCallback()
  16798. {
  16799. stopTimer();
  16800. const ScopedLock sl (readerLock);
  16801. reader = 0;
  16802. }
  16803. void AudioThumbnail::clear()
  16804. {
  16805. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16806. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16807. d->thumbnailMagic[0] = 'j';
  16808. d->thumbnailMagic[1] = 'a';
  16809. d->thumbnailMagic[2] = 't';
  16810. d->thumbnailMagic[3] = 'm';
  16811. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16812. d->totalSamples = 0;
  16813. d->numFinishedSamples = 0;
  16814. d->numThumbnailSamples = 0;
  16815. d->numChannels = 0;
  16816. d->sampleRate = 0;
  16817. numSamplesCached = 0;
  16818. cacheNeedsRefilling = true;
  16819. }
  16820. void AudioThumbnail::loadFrom (InputStream& input)
  16821. {
  16822. const ScopedLock sl (readerLock);
  16823. data.setSize (0);
  16824. input.readIntoMemoryBlock (data);
  16825. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16826. swapEndiannessIfNeeded (d);
  16827. if (! (d->thumbnailMagic[0] == 'j'
  16828. && d->thumbnailMagic[1] == 'a'
  16829. && d->thumbnailMagic[2] == 't'
  16830. && d->thumbnailMagic[3] == 'm'))
  16831. {
  16832. clear();
  16833. }
  16834. numSamplesCached = 0;
  16835. cacheNeedsRefilling = true;
  16836. }
  16837. void AudioThumbnail::saveTo (OutputStream& output) const
  16838. {
  16839. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16840. swapEndiannessIfNeeded (d);
  16841. output.write (data.getData(), (int) data.getSize());
  16842. swapEndiannessIfNeeded (d);
  16843. }
  16844. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16845. {
  16846. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16847. d->totalSamples = fileReader.lengthInSamples;
  16848. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16849. d->numFinishedSamples = 0;
  16850. d->sampleRate = roundToInt (fileReader.sampleRate);
  16851. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16852. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16853. d = (AudioThumbnailDataFormat*) data.getData();
  16854. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16855. return d->totalSamples > 0;
  16856. }
  16857. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16858. {
  16859. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16860. if (d->numFinishedSamples < d->totalSamples)
  16861. {
  16862. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16863. generateSection (fileReader,
  16864. d->numFinishedSamples,
  16865. numToDo);
  16866. d->numFinishedSamples += numToDo;
  16867. }
  16868. cacheNeedsRefilling = true;
  16869. return (d->numFinishedSamples < d->totalSamples);
  16870. }
  16871. int AudioThumbnail::getNumChannels() const throw()
  16872. {
  16873. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16874. jassert (d != 0);
  16875. return d->numChannels;
  16876. }
  16877. double AudioThumbnail::getTotalLength() const throw()
  16878. {
  16879. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16880. jassert (d != 0);
  16881. if (d->sampleRate > 0)
  16882. return d->totalSamples / (double)d->sampleRate;
  16883. else
  16884. return 0.0;
  16885. }
  16886. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16887. int64 startSample,
  16888. int numSamples)
  16889. {
  16890. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16891. jassert (d != 0);
  16892. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16893. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16894. char* l = getChannelData (0);
  16895. char* r = getChannelData (1);
  16896. for (int i = firstDataPos; i < lastDataPos; ++i)
  16897. {
  16898. const int sourceStart = i * d->samplesPerThumbSample;
  16899. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16900. float lowestLeft, highestLeft, lowestRight, highestRight;
  16901. fileReader.readMaxLevels (sourceStart,
  16902. sourceEnd - sourceStart,
  16903. lowestLeft,
  16904. highestLeft,
  16905. lowestRight,
  16906. highestRight);
  16907. int n = i * 2;
  16908. if (r != 0)
  16909. {
  16910. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16911. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16912. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16913. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16914. }
  16915. else
  16916. {
  16917. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16918. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16919. }
  16920. }
  16921. }
  16922. char* AudioThumbnail::getChannelData (int channel) const
  16923. {
  16924. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16925. jassert (d != 0);
  16926. if (channel >= 0 && channel < d->numChannels)
  16927. return d->data + (channel * 2 * d->numThumbnailSamples);
  16928. return 0;
  16929. }
  16930. bool AudioThumbnail::isFullyLoaded() const throw()
  16931. {
  16932. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16933. jassert (d != 0);
  16934. return d->numFinishedSamples >= d->totalSamples;
  16935. }
  16936. void AudioThumbnail::refillCache (const int numSamples,
  16937. double startTime,
  16938. const double timePerPixel)
  16939. {
  16940. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16941. jassert (d != 0);
  16942. if (numSamples <= 0
  16943. || timePerPixel <= 0.0
  16944. || d->sampleRate <= 0)
  16945. {
  16946. numSamplesCached = 0;
  16947. cacheNeedsRefilling = true;
  16948. return;
  16949. }
  16950. if (numSamples == numSamplesCached
  16951. && numChannelsCached == d->numChannels
  16952. && startTime == cachedStart
  16953. && timePerPixel == cachedTimePerPixel
  16954. && ! cacheNeedsRefilling)
  16955. {
  16956. return;
  16957. }
  16958. numSamplesCached = numSamples;
  16959. numChannelsCached = d->numChannels;
  16960. cachedStart = startTime;
  16961. cachedTimePerPixel = timePerPixel;
  16962. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16963. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16964. const ScopedLock sl (readerLock);
  16965. cacheNeedsRefilling = false;
  16966. if (needExtraDetail && reader == 0)
  16967. reader = createReader();
  16968. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16969. {
  16970. startTimer (timeBeforeDeletingReader);
  16971. char* cacheData = (char*) cachedLevels.getData();
  16972. int sample = roundToInt (startTime * d->sampleRate);
  16973. for (int i = numSamples; --i >= 0;)
  16974. {
  16975. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16976. if (sample >= 0)
  16977. {
  16978. if (sample >= reader->lengthInSamples)
  16979. break;
  16980. float lmin, lmax, rmin, rmax;
  16981. reader->readMaxLevels (sample,
  16982. jmax (1, nextSample - sample),
  16983. lmin, lmax, rmin, rmax);
  16984. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16985. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16986. if (numChannelsCached > 1)
  16987. {
  16988. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16989. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16990. }
  16991. cacheData += 2 * numChannelsCached;
  16992. }
  16993. startTime += timePerPixel;
  16994. sample = nextSample;
  16995. }
  16996. }
  16997. else
  16998. {
  16999. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  17000. {
  17001. char* const channelData = getChannelData (channelNum);
  17002. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  17003. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  17004. startTime = cachedStart;
  17005. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  17006. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  17007. for (int i = numSamples; --i >= 0;)
  17008. {
  17009. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  17010. if (sample >= 0 && channelData != 0)
  17011. {
  17012. char mx = -128;
  17013. char mn = 127;
  17014. while (sample <= nextSample)
  17015. {
  17016. if (sample >= numFinished)
  17017. break;
  17018. const int n = sample << 1;
  17019. const char sampMin = channelData [n];
  17020. const char sampMax = channelData [n + 1];
  17021. if (sampMin < mn)
  17022. mn = sampMin;
  17023. if (sampMax > mx)
  17024. mx = sampMax;
  17025. ++sample;
  17026. }
  17027. if (mn <= mx)
  17028. {
  17029. cacheData[0] = mn;
  17030. cacheData[1] = mx;
  17031. }
  17032. else
  17033. {
  17034. cacheData[0] = 1;
  17035. cacheData[1] = 0;
  17036. }
  17037. }
  17038. else
  17039. {
  17040. cacheData[0] = 1;
  17041. cacheData[1] = 0;
  17042. }
  17043. cacheData += numChannelsCached * 2;
  17044. startTime += timePerPixel;
  17045. sample = nextSample;
  17046. }
  17047. }
  17048. }
  17049. }
  17050. void AudioThumbnail::drawChannel (Graphics& g,
  17051. int x, int y, int w, int h,
  17052. double startTime,
  17053. double endTime,
  17054. int channelNum,
  17055. const float verticalZoomFactor)
  17056. {
  17057. refillCache (w, startTime, (endTime - startTime) / w);
  17058. if (numSamplesCached >= w
  17059. && channelNum >= 0
  17060. && channelNum < numChannelsCached)
  17061. {
  17062. const float topY = (float) y;
  17063. const float bottomY = topY + h;
  17064. const float midY = topY + h * 0.5f;
  17065. const float vscale = verticalZoomFactor * h / 256.0f;
  17066. const Rectangle<int> clip (g.getClipBounds());
  17067. const int skipLeft = jlimit (0, w, clip.getX() - x);
  17068. w -= skipLeft;
  17069. x += skipLeft;
  17070. const char* cacheData = ((const char*) cachedLevels.getData())
  17071. + (channelNum << 1)
  17072. + skipLeft * (numChannelsCached << 1);
  17073. while (--w >= 0)
  17074. {
  17075. const char mn = cacheData[0];
  17076. const char mx = cacheData[1];
  17077. cacheData += numChannelsCached << 1;
  17078. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17079. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17080. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17081. ++x;
  17082. if (x >= clip.getRight())
  17083. break;
  17084. }
  17085. }
  17086. }
  17087. END_JUCE_NAMESPACE
  17088. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  17089. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  17090. BEGIN_JUCE_NAMESPACE
  17091. struct ThumbnailCacheEntry
  17092. {
  17093. int64 hash;
  17094. uint32 lastUsed;
  17095. MemoryBlock data;
  17096. juce_UseDebuggingNewOperator
  17097. };
  17098. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17099. : TimeSliceThread (T("thumb cache")),
  17100. maxNumThumbsToStore (maxNumThumbsToStore_)
  17101. {
  17102. startThread (2);
  17103. }
  17104. AudioThumbnailCache::~AudioThumbnailCache()
  17105. {
  17106. }
  17107. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17108. {
  17109. for (int i = thumbs.size(); --i >= 0;)
  17110. {
  17111. if (thumbs[i]->hash == hashCode)
  17112. {
  17113. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17114. thumbs[i]->data.getSize(),
  17115. false);
  17116. thumb.loadFrom (in);
  17117. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17118. return true;
  17119. }
  17120. }
  17121. return false;
  17122. }
  17123. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17124. const int64 hashCode)
  17125. {
  17126. MemoryOutputStream out;
  17127. thumb.saveTo (out);
  17128. ThumbnailCacheEntry* te = 0;
  17129. for (int i = thumbs.size(); --i >= 0;)
  17130. {
  17131. if (thumbs[i]->hash == hashCode)
  17132. {
  17133. te = thumbs[i];
  17134. break;
  17135. }
  17136. }
  17137. if (te == 0)
  17138. {
  17139. te = new ThumbnailCacheEntry();
  17140. te->hash = hashCode;
  17141. if (thumbs.size() < maxNumThumbsToStore)
  17142. {
  17143. thumbs.add (te);
  17144. }
  17145. else
  17146. {
  17147. int oldest = 0;
  17148. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17149. int i;
  17150. for (i = thumbs.size(); --i >= 0;)
  17151. if (thumbs[i]->lastUsed < oldestTime)
  17152. oldest = i;
  17153. thumbs.set (i, te);
  17154. }
  17155. }
  17156. te->lastUsed = Time::getMillisecondCounter();
  17157. te->data.setSize (0);
  17158. te->data.append (out.getData(), out.getDataSize());
  17159. }
  17160. void AudioThumbnailCache::clear()
  17161. {
  17162. thumbs.clear();
  17163. }
  17164. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17165. {
  17166. addTimeSliceClient (thumb);
  17167. }
  17168. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17169. {
  17170. removeTimeSliceClient (thumb);
  17171. }
  17172. END_JUCE_NAMESPACE
  17173. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  17174. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17175. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17176. #if ! JUCE_WINDOWS
  17177. #include <QuickTime/Movies.h>
  17178. #include <QuickTime/QTML.h>
  17179. #include <QuickTime/QuickTimeComponents.h>
  17180. #include <QuickTime/MediaHandlers.h>
  17181. #include <QuickTime/ImageCodec.h>
  17182. #else
  17183. #if JUCE_MSVC
  17184. #pragma warning (push)
  17185. #pragma warning (disable : 4100)
  17186. #endif
  17187. #include <Movies.h>
  17188. #include <QTML.h>
  17189. #include <QuickTimeComponents.h>
  17190. #include <MediaHandlers.h>
  17191. #include <ImageCodec.h>
  17192. #if JUCE_MSVC
  17193. #pragma warning (pop)
  17194. #endif
  17195. #endif
  17196. BEGIN_JUCE_NAMESPACE
  17197. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17198. static const char* const quickTimeFormatName = "QuickTime file";
  17199. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17200. class QTAudioReader : public AudioFormatReader
  17201. {
  17202. public:
  17203. QTAudioReader (InputStream* const input_, const int trackNum_)
  17204. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17205. ok (false),
  17206. movie (0),
  17207. trackNum (trackNum_),
  17208. lastSampleRead (0),
  17209. lastThreadId (0),
  17210. extractor (0),
  17211. dataHandle (0)
  17212. {
  17213. bufferList.calloc (256, 1);
  17214. #ifdef WIN32
  17215. if (InitializeQTML (0) != noErr)
  17216. return;
  17217. #endif
  17218. if (EnterMovies() != noErr)
  17219. return;
  17220. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17221. if (! opened)
  17222. return;
  17223. {
  17224. const int numTracks = GetMovieTrackCount (movie);
  17225. int trackCount = 0;
  17226. for (int i = 1; i <= numTracks; ++i)
  17227. {
  17228. track = GetMovieIndTrack (movie, i);
  17229. media = GetTrackMedia (track);
  17230. OSType mediaType;
  17231. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17232. if (mediaType == SoundMediaType
  17233. && trackCount++ == trackNum_)
  17234. {
  17235. ok = true;
  17236. break;
  17237. }
  17238. }
  17239. }
  17240. if (! ok)
  17241. return;
  17242. ok = false;
  17243. lengthInSamples = GetMediaDecodeDuration (media);
  17244. usesFloatingPointData = false;
  17245. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17246. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17247. / GetMediaTimeScale (media);
  17248. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17249. unsigned long output_layout_size;
  17250. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17251. kQTPropertyClass_MovieAudioExtraction_Audio,
  17252. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17253. 0, &output_layout_size, 0);
  17254. if (err != noErr)
  17255. return;
  17256. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17257. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17258. err = MovieAudioExtractionGetProperty (extractor,
  17259. kQTPropertyClass_MovieAudioExtraction_Audio,
  17260. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17261. output_layout_size, qt_audio_channel_layout, 0);
  17262. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17263. err = MovieAudioExtractionSetProperty (extractor,
  17264. kQTPropertyClass_MovieAudioExtraction_Audio,
  17265. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17266. output_layout_size,
  17267. qt_audio_channel_layout);
  17268. err = MovieAudioExtractionGetProperty (extractor,
  17269. kQTPropertyClass_MovieAudioExtraction_Audio,
  17270. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17271. sizeof (inputStreamDesc),
  17272. &inputStreamDesc, 0);
  17273. if (err != noErr)
  17274. return;
  17275. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17276. | kAudioFormatFlagIsPacked
  17277. | kAudioFormatFlagsNativeEndian;
  17278. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17279. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17280. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17281. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17282. err = MovieAudioExtractionSetProperty (extractor,
  17283. kQTPropertyClass_MovieAudioExtraction_Audio,
  17284. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17285. sizeof (inputStreamDesc),
  17286. &inputStreamDesc);
  17287. if (err != noErr)
  17288. return;
  17289. Boolean allChannelsDiscrete = false;
  17290. err = MovieAudioExtractionSetProperty (extractor,
  17291. kQTPropertyClass_MovieAudioExtraction_Movie,
  17292. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17293. sizeof (allChannelsDiscrete),
  17294. &allChannelsDiscrete);
  17295. if (err != noErr)
  17296. return;
  17297. bufferList->mNumberBuffers = 1;
  17298. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17299. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17300. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17301. sampleRate = inputStreamDesc.mSampleRate;
  17302. bitsPerSample = 16;
  17303. numChannels = inputStreamDesc.mChannelsPerFrame;
  17304. detachThread();
  17305. ok = true;
  17306. }
  17307. ~QTAudioReader()
  17308. {
  17309. if (dataHandle != 0)
  17310. DisposeHandle (dataHandle);
  17311. if (extractor != 0)
  17312. {
  17313. MovieAudioExtractionEnd (extractor);
  17314. extractor = 0;
  17315. }
  17316. checkThreadIsAttached();
  17317. DisposeMovie (movie);
  17318. juce_free (bufferList->mBuffers[0].mData);
  17319. #if JUCE_MAC
  17320. ExitMoviesOnThread ();
  17321. #endif
  17322. }
  17323. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17324. int64 startSampleInFile, int numSamples)
  17325. {
  17326. checkThreadIsAttached();
  17327. while (numSamples > 0)
  17328. {
  17329. if (! loadFrame ((int) startSampleInFile))
  17330. return false;
  17331. const int numToDo = jmin (numSamples, samplesPerFrame);
  17332. for (int j = numDestChannels; --j >= 0;)
  17333. {
  17334. if (destSamples[j] != 0)
  17335. {
  17336. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17337. for (int i = 0; i < numToDo; ++i)
  17338. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17339. }
  17340. }
  17341. startOffsetInDestBuffer += numToDo;
  17342. startSampleInFile += numToDo;
  17343. numSamples -= numToDo;
  17344. }
  17345. detachThread();
  17346. return true;
  17347. }
  17348. bool loadFrame (const int sampleNum)
  17349. {
  17350. if (lastSampleRead != sampleNum)
  17351. {
  17352. TimeRecord time;
  17353. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17354. time.base = 0;
  17355. time.value.hi = 0;
  17356. time.value.lo = (UInt32) sampleNum;
  17357. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17358. kQTPropertyClass_MovieAudioExtraction_Movie,
  17359. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17360. sizeof (time), &time);
  17361. if (err != noErr)
  17362. return false;
  17363. }
  17364. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17365. UInt32 outFlags = 0;
  17366. UInt32 actualNumSamples = samplesPerFrame;
  17367. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17368. bufferList, &outFlags);
  17369. lastSampleRead = sampleNum + samplesPerFrame;
  17370. return err == noErr;
  17371. }
  17372. juce_UseDebuggingNewOperator
  17373. bool ok;
  17374. private:
  17375. Movie movie;
  17376. Media media;
  17377. Track track;
  17378. const int trackNum;
  17379. double trackUnitsPerFrame;
  17380. int samplesPerFrame;
  17381. int lastSampleRead;
  17382. Thread::ThreadID lastThreadId;
  17383. MovieAudioExtractionRef extractor;
  17384. AudioStreamBasicDescription inputStreamDesc;
  17385. HeapBlock <AudioBufferList> bufferList;
  17386. Handle dataHandle;
  17387. void checkThreadIsAttached()
  17388. {
  17389. #if JUCE_MAC
  17390. if (Thread::getCurrentThreadId() != lastThreadId)
  17391. EnterMoviesOnThread (0);
  17392. AttachMovieToCurrentThread (movie);
  17393. #endif
  17394. }
  17395. void detachThread()
  17396. {
  17397. #if JUCE_MAC
  17398. DetachMovieFromCurrentThread (movie);
  17399. #endif
  17400. }
  17401. };
  17402. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17403. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17404. {
  17405. }
  17406. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17407. {
  17408. }
  17409. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17410. {
  17411. return Array<int>();
  17412. }
  17413. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17414. {
  17415. return Array<int>();
  17416. }
  17417. bool QuickTimeAudioFormat::canDoStereo()
  17418. {
  17419. return true;
  17420. }
  17421. bool QuickTimeAudioFormat::canDoMono()
  17422. {
  17423. return true;
  17424. }
  17425. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17426. const bool deleteStreamIfOpeningFails)
  17427. {
  17428. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17429. if (r->ok)
  17430. return r.release();
  17431. if (! deleteStreamIfOpeningFails)
  17432. r->input = 0;
  17433. return 0;
  17434. }
  17435. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17436. double /*sampleRateToUse*/,
  17437. unsigned int /*numberOfChannels*/,
  17438. int /*bitsPerSample*/,
  17439. const StringPairArray& /*metadataValues*/,
  17440. int /*qualityOptionIndex*/)
  17441. {
  17442. jassertfalse // not yet implemented!
  17443. return 0;
  17444. }
  17445. END_JUCE_NAMESPACE
  17446. #endif
  17447. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17448. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17449. BEGIN_JUCE_NAMESPACE
  17450. static const char* const wavFormatName = "WAV file";
  17451. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17452. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17453. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17454. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17455. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17456. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17457. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17458. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17459. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17460. const String& originator,
  17461. const String& originatorRef,
  17462. const Time& date,
  17463. const int64 timeReferenceSamples,
  17464. const String& codingHistory)
  17465. {
  17466. StringPairArray m;
  17467. m.set (bwavDescription, description);
  17468. m.set (bwavOriginator, originator);
  17469. m.set (bwavOriginatorRef, originatorRef);
  17470. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17471. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17472. m.set (bwavTimeReference, String (timeReferenceSamples));
  17473. m.set (bwavCodingHistory, codingHistory);
  17474. return m;
  17475. }
  17476. #if JUCE_MSVC
  17477. #pragma pack (push, 1)
  17478. #define PACKED
  17479. #elif JUCE_GCC
  17480. #define PACKED __attribute__((packed))
  17481. #else
  17482. #define PACKED
  17483. #endif
  17484. struct BWAVChunk
  17485. {
  17486. uint8 description [256];
  17487. uint8 originator [32];
  17488. uint8 originatorRef [32];
  17489. uint8 originationDate [10];
  17490. uint8 originationTime [8];
  17491. uint32 timeRefLow;
  17492. uint32 timeRefHigh;
  17493. uint16 version;
  17494. uint8 umid[64];
  17495. uint8 reserved[190];
  17496. uint8 codingHistory[1];
  17497. void copyTo (StringPairArray& values) const
  17498. {
  17499. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17500. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17501. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17502. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17503. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17504. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17505. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17506. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17507. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17508. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17509. }
  17510. static MemoryBlock createFrom (const StringPairArray& values)
  17511. {
  17512. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (0) - 1;
  17513. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17514. data.fillWith (0);
  17515. BWAVChunk* b = (BWAVChunk*) data.getData();
  17516. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17517. // as they get called in the right order..
  17518. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17519. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17520. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17521. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17522. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17523. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17524. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17525. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17526. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory);
  17527. if (b->description[0] != 0
  17528. || b->originator[0] != 0
  17529. || b->originationDate[0] != 0
  17530. || b->originationTime[0] != 0
  17531. || b->codingHistory[0] != 0
  17532. || time != 0)
  17533. {
  17534. return data;
  17535. }
  17536. return MemoryBlock();
  17537. }
  17538. } PACKED;
  17539. struct SMPLChunk
  17540. {
  17541. struct SampleLoop
  17542. {
  17543. uint32 identifier;
  17544. uint32 type;
  17545. uint32 start;
  17546. uint32 end;
  17547. uint32 fraction;
  17548. uint32 playCount;
  17549. } PACKED;
  17550. uint32 manufacturer;
  17551. uint32 product;
  17552. uint32 samplePeriod;
  17553. uint32 midiUnityNote;
  17554. uint32 midiPitchFraction;
  17555. uint32 smpteFormat;
  17556. uint32 smpteOffset;
  17557. uint32 numSampleLoops;
  17558. uint32 samplerData;
  17559. SampleLoop loops[1];
  17560. void copyTo (StringPairArray& values, const int totalSize) const
  17561. {
  17562. values.set (T("Manufacturer"), String (ByteOrder::swapIfBigEndian (manufacturer)));
  17563. values.set (T("Product"), String (ByteOrder::swapIfBigEndian (product)));
  17564. values.set (T("SamplePeriod"), String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17565. values.set (T("MidiUnityNote"), String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17566. values.set (T("MidiPitchFraction"), String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17567. values.set (T("SmpteFormat"), String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17568. values.set (T("SmpteOffset"), String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17569. values.set (T("NumSampleLoops"), String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17570. values.set (T("SamplerData"), String (ByteOrder::swapIfBigEndian (samplerData)));
  17571. for (uint32 i = 0; i < numSampleLoops; ++i)
  17572. {
  17573. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17574. break;
  17575. values.set (String::formatted (T("Loop%dIdentifier"), i), String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17576. values.set (String::formatted (T("Loop%dType"), i), String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17577. values.set (String::formatted (T("Loop%dStart"), i), String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17578. values.set (String::formatted (T("Loop%dEnd"), i), String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17579. values.set (String::formatted (T("Loop%dFraction"), i), String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17580. values.set (String::formatted (T("Loop%dPlayCount"), i), String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17581. }
  17582. }
  17583. } PACKED;
  17584. #if JUCE_MSVC
  17585. #pragma pack (pop)
  17586. #endif
  17587. #undef PACKED
  17588. class WavAudioFormatReader : public AudioFormatReader
  17589. {
  17590. int bytesPerFrame;
  17591. int64 dataChunkStart, dataLength;
  17592. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17593. WavAudioFormatReader (const WavAudioFormatReader&);
  17594. const WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17595. public:
  17596. int64 bwavChunkStart, bwavSize;
  17597. WavAudioFormatReader (InputStream* const in)
  17598. : AudioFormatReader (in, TRANS (wavFormatName)),
  17599. dataLength (0),
  17600. bwavChunkStart (0),
  17601. bwavSize (0)
  17602. {
  17603. if (input->readInt() == chunkName ("RIFF"))
  17604. {
  17605. const uint32 len = (uint32) input->readInt();
  17606. const int64 end = input->getPosition() + len;
  17607. bool hasGotType = false;
  17608. bool hasGotData = false;
  17609. if (input->readInt() == chunkName ("WAVE"))
  17610. {
  17611. while (input->getPosition() < end
  17612. && ! input->isExhausted())
  17613. {
  17614. const int chunkType = input->readInt();
  17615. uint32 length = (uint32) input->readInt();
  17616. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17617. if (chunkType == chunkName ("fmt "))
  17618. {
  17619. // read the format chunk
  17620. const short format = input->readShort();
  17621. const short numChans = input->readShort();
  17622. sampleRate = input->readInt();
  17623. const int bytesPerSec = input->readInt();
  17624. numChannels = numChans;
  17625. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17626. bitsPerSample = 8 * bytesPerFrame / numChans;
  17627. if (format == 3)
  17628. usesFloatingPointData = true;
  17629. else if (format != 1)
  17630. bytesPerFrame = 0;
  17631. hasGotType = true;
  17632. }
  17633. else if (chunkType == chunkName ("data"))
  17634. {
  17635. // get the data chunk's position
  17636. dataLength = length;
  17637. dataChunkStart = input->getPosition();
  17638. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17639. hasGotData = true;
  17640. }
  17641. else if (chunkType == chunkName ("bext"))
  17642. {
  17643. bwavChunkStart = input->getPosition();
  17644. bwavSize = length;
  17645. // Broadcast-wav extension chunk..
  17646. HeapBlock <BWAVChunk> bwav;
  17647. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17648. input->read (bwav, length);
  17649. bwav->copyTo (metadataValues);
  17650. }
  17651. else if (chunkType == chunkName ("smpl"))
  17652. {
  17653. HeapBlock <SMPLChunk> smpl;
  17654. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17655. input->read (smpl, length);
  17656. smpl->copyTo (metadataValues, length);
  17657. }
  17658. else if (chunkEnd <= input->getPosition())
  17659. {
  17660. break;
  17661. }
  17662. input->setPosition (chunkEnd);
  17663. }
  17664. }
  17665. }
  17666. }
  17667. ~WavAudioFormatReader()
  17668. {
  17669. }
  17670. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17671. int64 startSampleInFile, int numSamples)
  17672. {
  17673. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17674. if (samplesAvailable < numSamples)
  17675. {
  17676. for (int i = numDestChannels; --i >= 0;)
  17677. if (destSamples[i] != 0)
  17678. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17679. numSamples = (int) samplesAvailable;
  17680. }
  17681. if (numSamples <= 0)
  17682. return true;
  17683. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17684. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17685. char tempBuffer [tempBufSize];
  17686. while (numSamples > 0)
  17687. {
  17688. int* left = destSamples[0];
  17689. if (left != 0)
  17690. left += startOffsetInDestBuffer;
  17691. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17692. if (right != 0)
  17693. right += startOffsetInDestBuffer;
  17694. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17695. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17696. if (bytesRead < numThisTime * bytesPerFrame)
  17697. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17698. if (bitsPerSample == 16)
  17699. {
  17700. const short* src = (const short*) tempBuffer;
  17701. if (numChannels > 1)
  17702. {
  17703. if (left == 0)
  17704. {
  17705. for (int i = numThisTime; --i >= 0;)
  17706. {
  17707. ++src;
  17708. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17709. }
  17710. }
  17711. else if (right == 0)
  17712. {
  17713. for (int i = numThisTime; --i >= 0;)
  17714. {
  17715. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17716. ++src;
  17717. }
  17718. }
  17719. else
  17720. {
  17721. for (int i = numThisTime; --i >= 0;)
  17722. {
  17723. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17724. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17725. }
  17726. }
  17727. }
  17728. else
  17729. {
  17730. for (int i = numThisTime; --i >= 0;)
  17731. {
  17732. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17733. }
  17734. }
  17735. }
  17736. else if (bitsPerSample == 24)
  17737. {
  17738. const char* src = (const char*) tempBuffer;
  17739. if (numChannels > 1)
  17740. {
  17741. if (left == 0)
  17742. {
  17743. for (int i = numThisTime; --i >= 0;)
  17744. {
  17745. src += 3;
  17746. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17747. src += 3;
  17748. }
  17749. }
  17750. else if (right == 0)
  17751. {
  17752. for (int i = numThisTime; --i >= 0;)
  17753. {
  17754. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17755. src += 6;
  17756. }
  17757. }
  17758. else
  17759. {
  17760. for (int i = 0; i < numThisTime; ++i)
  17761. {
  17762. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17763. src += 3;
  17764. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17765. src += 3;
  17766. }
  17767. }
  17768. }
  17769. else
  17770. {
  17771. for (int i = 0; i < numThisTime; ++i)
  17772. {
  17773. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17774. src += 3;
  17775. }
  17776. }
  17777. }
  17778. else if (bitsPerSample == 32)
  17779. {
  17780. const unsigned int* src = (const unsigned int*) tempBuffer;
  17781. unsigned int* l = (unsigned int*) left;
  17782. unsigned int* r = (unsigned int*) right;
  17783. if (numChannels > 1)
  17784. {
  17785. if (l == 0)
  17786. {
  17787. for (int i = numThisTime; --i >= 0;)
  17788. {
  17789. ++src;
  17790. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17791. }
  17792. }
  17793. else if (r == 0)
  17794. {
  17795. for (int i = numThisTime; --i >= 0;)
  17796. {
  17797. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17798. ++src;
  17799. }
  17800. }
  17801. else
  17802. {
  17803. for (int i = numThisTime; --i >= 0;)
  17804. {
  17805. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17806. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17807. }
  17808. }
  17809. }
  17810. else
  17811. {
  17812. for (int i = numThisTime; --i >= 0;)
  17813. {
  17814. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17815. }
  17816. }
  17817. left = (int*)l;
  17818. right = (int*)r;
  17819. }
  17820. else if (bitsPerSample == 8)
  17821. {
  17822. const unsigned char* src = (const unsigned char*) tempBuffer;
  17823. if (numChannels > 1)
  17824. {
  17825. if (left == 0)
  17826. {
  17827. for (int i = numThisTime; --i >= 0;)
  17828. {
  17829. ++src;
  17830. *right++ = ((int) *src++ - 128) << 24;
  17831. }
  17832. }
  17833. else if (right == 0)
  17834. {
  17835. for (int i = numThisTime; --i >= 0;)
  17836. {
  17837. *left++ = ((int) *src++ - 128) << 24;
  17838. ++src;
  17839. }
  17840. }
  17841. else
  17842. {
  17843. for (int i = numThisTime; --i >= 0;)
  17844. {
  17845. *left++ = ((int) *src++ - 128) << 24;
  17846. *right++ = ((int) *src++ - 128) << 24;
  17847. }
  17848. }
  17849. }
  17850. else
  17851. {
  17852. for (int i = numThisTime; --i >= 0;)
  17853. {
  17854. *left++ = ((int)*src++ - 128) << 24;
  17855. }
  17856. }
  17857. }
  17858. startOffsetInDestBuffer += numThisTime;
  17859. numSamples -= numThisTime;
  17860. }
  17861. if (numSamples > 0)
  17862. {
  17863. for (int i = numDestChannels; --i >= 0;)
  17864. if (destSamples[i] != 0)
  17865. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17866. sizeof (int) * numSamples);
  17867. }
  17868. return true;
  17869. }
  17870. juce_UseDebuggingNewOperator
  17871. };
  17872. class WavAudioFormatWriter : public AudioFormatWriter
  17873. {
  17874. MemoryBlock tempBlock, bwavChunk;
  17875. uint32 lengthInSamples, bytesWritten;
  17876. int64 headerPosition;
  17877. bool writeFailed;
  17878. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17879. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17880. const WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17881. void writeHeader()
  17882. {
  17883. const bool seekedOk = output->setPosition (headerPosition);
  17884. (void) seekedOk;
  17885. // if this fails, you've given it an output stream that can't seek! It needs
  17886. // to be able to seek back to write the header
  17887. jassert (seekedOk);
  17888. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17889. output->writeInt (chunkName ("RIFF"));
  17890. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17891. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17892. output->writeInt (chunkName ("WAVE"));
  17893. output->writeInt (chunkName ("fmt "));
  17894. output->writeInt (16);
  17895. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17896. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17897. output->writeShort ((short) numChannels);
  17898. output->writeInt ((int) sampleRate);
  17899. output->writeInt (bytesPerFrame * (int) sampleRate);
  17900. output->writeShort ((short) bytesPerFrame);
  17901. output->writeShort ((short) bitsPerSample);
  17902. if (bwavChunk.getSize() > 0)
  17903. {
  17904. output->writeInt (chunkName ("bext"));
  17905. output->writeInt ((int) bwavChunk.getSize());
  17906. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17907. }
  17908. output->writeInt (chunkName ("data"));
  17909. output->writeInt (lengthInSamples * bytesPerFrame);
  17910. usesFloatingPointData = (bitsPerSample == 32);
  17911. }
  17912. public:
  17913. WavAudioFormatWriter (OutputStream* const out,
  17914. const double sampleRate_,
  17915. const unsigned int numChannels_,
  17916. const int bits,
  17917. const StringPairArray& metadataValues)
  17918. : AudioFormatWriter (out,
  17919. TRANS (wavFormatName),
  17920. sampleRate_,
  17921. numChannels_,
  17922. bits),
  17923. lengthInSamples (0),
  17924. bytesWritten (0),
  17925. writeFailed (false)
  17926. {
  17927. if (metadataValues.size() > 0)
  17928. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17929. headerPosition = out->getPosition();
  17930. writeHeader();
  17931. }
  17932. ~WavAudioFormatWriter()
  17933. {
  17934. writeHeader();
  17935. }
  17936. bool write (const int** data, int numSamples)
  17937. {
  17938. if (writeFailed)
  17939. return false;
  17940. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17941. tempBlock.ensureSize (bytes, false);
  17942. char* buffer = (char*) tempBlock.getData();
  17943. const int* left = data[0];
  17944. const int* right = data[1];
  17945. if (right == 0)
  17946. right = left;
  17947. if (bitsPerSample == 16)
  17948. {
  17949. short* b = (short*) buffer;
  17950. if (numChannels > 1)
  17951. {
  17952. for (int i = numSamples; --i >= 0;)
  17953. {
  17954. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17955. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17956. }
  17957. }
  17958. else
  17959. {
  17960. for (int i = numSamples; --i >= 0;)
  17961. {
  17962. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17963. }
  17964. }
  17965. }
  17966. else if (bitsPerSample == 24)
  17967. {
  17968. char* b = (char*) buffer;
  17969. if (numChannels > 1)
  17970. {
  17971. for (int i = numSamples; --i >= 0;)
  17972. {
  17973. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17974. b += 3;
  17975. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17976. b += 3;
  17977. }
  17978. }
  17979. else
  17980. {
  17981. for (int i = numSamples; --i >= 0;)
  17982. {
  17983. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17984. b += 3;
  17985. }
  17986. }
  17987. }
  17988. else if (bitsPerSample == 32)
  17989. {
  17990. unsigned int* b = (unsigned int*) buffer;
  17991. if (numChannels > 1)
  17992. {
  17993. for (int i = numSamples; --i >= 0;)
  17994. {
  17995. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17996. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17997. }
  17998. }
  17999. else
  18000. {
  18001. for (int i = numSamples; --i >= 0;)
  18002. {
  18003. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18004. }
  18005. }
  18006. }
  18007. else if (bitsPerSample == 8)
  18008. {
  18009. unsigned char* b = (unsigned char*) buffer;
  18010. if (numChannels > 1)
  18011. {
  18012. for (int i = numSamples; --i >= 0;)
  18013. {
  18014. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18015. *b++ = (unsigned char) (128 + (*right++ >> 24));
  18016. }
  18017. }
  18018. else
  18019. {
  18020. for (int i = numSamples; --i >= 0;)
  18021. {
  18022. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18023. }
  18024. }
  18025. }
  18026. if (bytesWritten + bytes >= (uint32) 0xfff00000
  18027. || ! output->write (buffer, bytes))
  18028. {
  18029. // failed to write to disk, so let's try writing the header.
  18030. // If it's just run out of disk space, then if it does manage
  18031. // to write the header, we'll still have a useable file..
  18032. writeHeader();
  18033. writeFailed = true;
  18034. return false;
  18035. }
  18036. else
  18037. {
  18038. bytesWritten += bytes;
  18039. lengthInSamples += numSamples;
  18040. return true;
  18041. }
  18042. }
  18043. juce_UseDebuggingNewOperator
  18044. };
  18045. WavAudioFormat::WavAudioFormat()
  18046. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  18047. {
  18048. }
  18049. WavAudioFormat::~WavAudioFormat()
  18050. {
  18051. }
  18052. const Array <int> WavAudioFormat::getPossibleSampleRates()
  18053. {
  18054. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  18055. return Array <int> (rates);
  18056. }
  18057. const Array <int> WavAudioFormat::getPossibleBitDepths()
  18058. {
  18059. const int depths[] = { 8, 16, 24, 32, 0 };
  18060. return Array <int> (depths);
  18061. }
  18062. bool WavAudioFormat::canDoStereo()
  18063. {
  18064. return true;
  18065. }
  18066. bool WavAudioFormat::canDoMono()
  18067. {
  18068. return true;
  18069. }
  18070. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18071. const bool deleteStreamIfOpeningFails)
  18072. {
  18073. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18074. if (r->sampleRate != 0)
  18075. return r.release();
  18076. if (! deleteStreamIfOpeningFails)
  18077. r->input = 0;
  18078. return 0;
  18079. }
  18080. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18081. double sampleRate,
  18082. unsigned int numChannels,
  18083. int bitsPerSample,
  18084. const StringPairArray& metadataValues,
  18085. int /*qualityOptionIndex*/)
  18086. {
  18087. if (getPossibleBitDepths().contains (bitsPerSample))
  18088. {
  18089. return new WavAudioFormatWriter (out,
  18090. sampleRate,
  18091. numChannels,
  18092. bitsPerSample,
  18093. metadataValues);
  18094. }
  18095. return 0;
  18096. }
  18097. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18098. {
  18099. TemporaryFile tempFile (file);
  18100. WavAudioFormat wav;
  18101. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18102. if (reader != 0)
  18103. {
  18104. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18105. if (outStream != 0)
  18106. {
  18107. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18108. reader->numChannels, reader->bitsPerSample,
  18109. metadata, 0));
  18110. if (writer != 0)
  18111. {
  18112. outStream.release();
  18113. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18114. writer = 0;
  18115. reader = 0;
  18116. return ok && tempFile.overwriteTargetFileWithTemporary();
  18117. }
  18118. }
  18119. }
  18120. return false;
  18121. }
  18122. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18123. {
  18124. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18125. if (reader != 0)
  18126. {
  18127. const int64 bwavPos = reader->bwavChunkStart;
  18128. const int64 bwavSize = reader->bwavSize;
  18129. reader = 0;
  18130. if (bwavSize > 0)
  18131. {
  18132. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18133. if (chunk.getSize() <= (size_t) bwavSize)
  18134. {
  18135. // the new one will fit in the space available, so write it directly..
  18136. const int64 oldSize = wavFile.getSize();
  18137. {
  18138. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18139. out->setPosition (bwavPos);
  18140. out->write (chunk.getData(), (int) chunk.getSize());
  18141. out->setPosition (oldSize);
  18142. }
  18143. jassert (wavFile.getSize() == oldSize);
  18144. return true;
  18145. }
  18146. }
  18147. }
  18148. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18149. }
  18150. END_JUCE_NAMESPACE
  18151. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18152. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18153. BEGIN_JUCE_NAMESPACE
  18154. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18155. const bool deleteReaderWhenThisIsDeleted)
  18156. : reader (reader_),
  18157. deleteReader (deleteReaderWhenThisIsDeleted),
  18158. nextPlayPos (0),
  18159. looping (false)
  18160. {
  18161. jassert (reader != 0);
  18162. }
  18163. AudioFormatReaderSource::~AudioFormatReaderSource()
  18164. {
  18165. releaseResources();
  18166. if (deleteReader)
  18167. delete reader;
  18168. }
  18169. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18170. {
  18171. nextPlayPos = newPosition;
  18172. }
  18173. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18174. {
  18175. looping = shouldLoop;
  18176. }
  18177. int AudioFormatReaderSource::getNextReadPosition() const
  18178. {
  18179. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18180. : nextPlayPos;
  18181. }
  18182. int AudioFormatReaderSource::getTotalLength() const
  18183. {
  18184. return (int) reader->lengthInSamples;
  18185. }
  18186. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18187. double /*sampleRate*/)
  18188. {
  18189. }
  18190. void AudioFormatReaderSource::releaseResources()
  18191. {
  18192. }
  18193. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18194. {
  18195. if (info.numSamples > 0)
  18196. {
  18197. const int start = nextPlayPos;
  18198. if (looping)
  18199. {
  18200. const int newStart = start % (int) reader->lengthInSamples;
  18201. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18202. if (newEnd > newStart)
  18203. {
  18204. info.buffer->readFromAudioReader (reader,
  18205. info.startSample,
  18206. newEnd - newStart,
  18207. newStart,
  18208. true, true);
  18209. }
  18210. else
  18211. {
  18212. const int endSamps = (int) reader->lengthInSamples - newStart;
  18213. info.buffer->readFromAudioReader (reader,
  18214. info.startSample,
  18215. endSamps,
  18216. newStart,
  18217. true, true);
  18218. info.buffer->readFromAudioReader (reader,
  18219. info.startSample + endSamps,
  18220. newEnd,
  18221. 0,
  18222. true, true);
  18223. }
  18224. nextPlayPos = newEnd;
  18225. }
  18226. else
  18227. {
  18228. info.buffer->readFromAudioReader (reader,
  18229. info.startSample,
  18230. info.numSamples,
  18231. start,
  18232. true, true);
  18233. nextPlayPos += info.numSamples;
  18234. }
  18235. }
  18236. }
  18237. END_JUCE_NAMESPACE
  18238. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18239. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18240. BEGIN_JUCE_NAMESPACE
  18241. AudioSourcePlayer::AudioSourcePlayer()
  18242. : source (0),
  18243. sampleRate (0),
  18244. bufferSize (0),
  18245. tempBuffer (2, 8),
  18246. lastGain (1.0f),
  18247. gain (1.0f)
  18248. {
  18249. }
  18250. AudioSourcePlayer::~AudioSourcePlayer()
  18251. {
  18252. setSource (0);
  18253. }
  18254. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18255. {
  18256. if (source != newSource)
  18257. {
  18258. AudioSource* const oldSource = source;
  18259. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18260. newSource->prepareToPlay (bufferSize, sampleRate);
  18261. {
  18262. const ScopedLock sl (readLock);
  18263. source = newSource;
  18264. }
  18265. if (oldSource != 0)
  18266. oldSource->releaseResources();
  18267. }
  18268. }
  18269. void AudioSourcePlayer::setGain (const float newGain) throw()
  18270. {
  18271. gain = newGain;
  18272. }
  18273. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18274. int totalNumInputChannels,
  18275. float** outputChannelData,
  18276. int totalNumOutputChannels,
  18277. int numSamples)
  18278. {
  18279. // these should have been prepared by audioDeviceAboutToStart()...
  18280. jassert (sampleRate > 0 && bufferSize > 0);
  18281. const ScopedLock sl (readLock);
  18282. if (source != 0)
  18283. {
  18284. AudioSourceChannelInfo info;
  18285. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18286. // messy stuff needed to compact the channels down into an array
  18287. // of non-zero pointers..
  18288. for (i = 0; i < totalNumInputChannels; ++i)
  18289. {
  18290. if (inputChannelData[i] != 0)
  18291. {
  18292. inputChans [numInputs++] = inputChannelData[i];
  18293. if (numInputs >= numElementsInArray (inputChans))
  18294. break;
  18295. }
  18296. }
  18297. for (i = 0; i < totalNumOutputChannels; ++i)
  18298. {
  18299. if (outputChannelData[i] != 0)
  18300. {
  18301. outputChans [numOutputs++] = outputChannelData[i];
  18302. if (numOutputs >= numElementsInArray (outputChans))
  18303. break;
  18304. }
  18305. }
  18306. if (numInputs > numOutputs)
  18307. {
  18308. // if there aren't enough output channels for the number of
  18309. // inputs, we need to create some temporary extra ones (can't
  18310. // use the input data in case it gets written to)
  18311. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18312. false, false, true);
  18313. for (i = 0; i < numOutputs; ++i)
  18314. {
  18315. channels[numActiveChans] = outputChans[i];
  18316. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18317. ++numActiveChans;
  18318. }
  18319. for (i = numOutputs; i < numInputs; ++i)
  18320. {
  18321. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18322. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18323. ++numActiveChans;
  18324. }
  18325. }
  18326. else
  18327. {
  18328. for (i = 0; i < numInputs; ++i)
  18329. {
  18330. channels[numActiveChans] = outputChans[i];
  18331. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18332. ++numActiveChans;
  18333. }
  18334. for (i = numInputs; i < numOutputs; ++i)
  18335. {
  18336. channels[numActiveChans] = outputChans[i];
  18337. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18338. ++numActiveChans;
  18339. }
  18340. }
  18341. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18342. info.buffer = &buffer;
  18343. info.startSample = 0;
  18344. info.numSamples = numSamples;
  18345. source->getNextAudioBlock (info);
  18346. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18347. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18348. lastGain = gain;
  18349. }
  18350. else
  18351. {
  18352. for (int i = 0; i < totalNumOutputChannels; ++i)
  18353. if (outputChannelData[i] != 0)
  18354. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18355. }
  18356. }
  18357. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18358. {
  18359. sampleRate = device->getCurrentSampleRate();
  18360. bufferSize = device->getCurrentBufferSizeSamples();
  18361. zeromem (channels, sizeof (channels));
  18362. if (source != 0)
  18363. source->prepareToPlay (bufferSize, sampleRate);
  18364. }
  18365. void AudioSourcePlayer::audioDeviceStopped()
  18366. {
  18367. if (source != 0)
  18368. source->releaseResources();
  18369. sampleRate = 0.0;
  18370. bufferSize = 0;
  18371. tempBuffer.setSize (2, 8);
  18372. }
  18373. END_JUCE_NAMESPACE
  18374. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18375. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18376. BEGIN_JUCE_NAMESPACE
  18377. AudioTransportSource::AudioTransportSource()
  18378. : source (0),
  18379. resamplerSource (0),
  18380. bufferingSource (0),
  18381. positionableSource (0),
  18382. masterSource (0),
  18383. gain (1.0f),
  18384. lastGain (1.0f),
  18385. playing (false),
  18386. stopped (true),
  18387. sampleRate (44100.0),
  18388. sourceSampleRate (0.0),
  18389. blockSize (128),
  18390. readAheadBufferSize (0),
  18391. isPrepared (false),
  18392. inputStreamEOF (false)
  18393. {
  18394. }
  18395. AudioTransportSource::~AudioTransportSource()
  18396. {
  18397. setSource (0);
  18398. releaseResources();
  18399. }
  18400. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18401. int readAheadBufferSize_,
  18402. double sourceSampleRateToCorrectFor)
  18403. {
  18404. if (source == newSource)
  18405. {
  18406. if (source == 0)
  18407. return;
  18408. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18409. }
  18410. readAheadBufferSize = readAheadBufferSize_;
  18411. sourceSampleRate = sourceSampleRateToCorrectFor;
  18412. ResamplingAudioSource* newResamplerSource = 0;
  18413. BufferingAudioSource* newBufferingSource = 0;
  18414. PositionableAudioSource* newPositionableSource = 0;
  18415. AudioSource* newMasterSource = 0;
  18416. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18417. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18418. AudioSource* oldMasterSource = masterSource;
  18419. if (newSource != 0)
  18420. {
  18421. newPositionableSource = newSource;
  18422. if (readAheadBufferSize_ > 0)
  18423. newPositionableSource = newBufferingSource
  18424. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18425. newPositionableSource->setNextReadPosition (0);
  18426. if (sourceSampleRateToCorrectFor != 0)
  18427. newMasterSource = newResamplerSource
  18428. = new ResamplingAudioSource (newPositionableSource, false);
  18429. else
  18430. newMasterSource = newPositionableSource;
  18431. if (isPrepared)
  18432. {
  18433. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18434. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18435. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18436. }
  18437. }
  18438. {
  18439. const ScopedLock sl (callbackLock);
  18440. source = newSource;
  18441. resamplerSource = newResamplerSource;
  18442. bufferingSource = newBufferingSource;
  18443. masterSource = newMasterSource;
  18444. positionableSource = newPositionableSource;
  18445. playing = false;
  18446. }
  18447. if (oldMasterSource != 0)
  18448. oldMasterSource->releaseResources();
  18449. }
  18450. void AudioTransportSource::start()
  18451. {
  18452. if ((! playing) && masterSource != 0)
  18453. {
  18454. callbackLock.enter();
  18455. playing = true;
  18456. stopped = false;
  18457. inputStreamEOF = false;
  18458. callbackLock.exit();
  18459. sendChangeMessage (this);
  18460. }
  18461. }
  18462. void AudioTransportSource::stop()
  18463. {
  18464. if (playing)
  18465. {
  18466. callbackLock.enter();
  18467. playing = false;
  18468. callbackLock.exit();
  18469. int n = 500;
  18470. while (--n >= 0 && ! stopped)
  18471. Thread::sleep (2);
  18472. sendChangeMessage (this);
  18473. }
  18474. }
  18475. void AudioTransportSource::setPosition (double newPosition)
  18476. {
  18477. if (sampleRate > 0.0)
  18478. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18479. }
  18480. double AudioTransportSource::getCurrentPosition() const
  18481. {
  18482. if (sampleRate > 0.0)
  18483. return getNextReadPosition() / sampleRate;
  18484. else
  18485. return 0.0;
  18486. }
  18487. void AudioTransportSource::setNextReadPosition (int newPosition)
  18488. {
  18489. if (positionableSource != 0)
  18490. {
  18491. if (sampleRate > 0 && sourceSampleRate > 0)
  18492. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18493. positionableSource->setNextReadPosition (newPosition);
  18494. }
  18495. }
  18496. int AudioTransportSource::getNextReadPosition() const
  18497. {
  18498. if (positionableSource != 0)
  18499. {
  18500. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18501. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18502. }
  18503. return 0;
  18504. }
  18505. int AudioTransportSource::getTotalLength() const
  18506. {
  18507. const ScopedLock sl (callbackLock);
  18508. if (positionableSource != 0)
  18509. {
  18510. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18511. return roundToInt (positionableSource->getTotalLength() * ratio);
  18512. }
  18513. return 0;
  18514. }
  18515. bool AudioTransportSource::isLooping() const
  18516. {
  18517. const ScopedLock sl (callbackLock);
  18518. return positionableSource != 0
  18519. && positionableSource->isLooping();
  18520. }
  18521. void AudioTransportSource::setGain (const float newGain) throw()
  18522. {
  18523. gain = newGain;
  18524. }
  18525. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18526. double sampleRate_)
  18527. {
  18528. const ScopedLock sl (callbackLock);
  18529. sampleRate = sampleRate_;
  18530. blockSize = samplesPerBlockExpected;
  18531. if (masterSource != 0)
  18532. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18533. if (resamplerSource != 0 && sourceSampleRate != 0)
  18534. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18535. isPrepared = true;
  18536. }
  18537. void AudioTransportSource::releaseResources()
  18538. {
  18539. const ScopedLock sl (callbackLock);
  18540. if (masterSource != 0)
  18541. masterSource->releaseResources();
  18542. isPrepared = false;
  18543. }
  18544. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18545. {
  18546. const ScopedLock sl (callbackLock);
  18547. inputStreamEOF = false;
  18548. if (masterSource != 0 && ! stopped)
  18549. {
  18550. masterSource->getNextAudioBlock (info);
  18551. if (! playing)
  18552. {
  18553. // just stopped playing, so fade out the last block..
  18554. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18555. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18556. if (info.numSamples > 256)
  18557. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18558. }
  18559. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18560. && ! positionableSource->isLooping())
  18561. {
  18562. playing = false;
  18563. inputStreamEOF = true;
  18564. sendChangeMessage (this);
  18565. }
  18566. stopped = ! playing;
  18567. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18568. {
  18569. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18570. lastGain, gain);
  18571. }
  18572. }
  18573. else
  18574. {
  18575. info.clearActiveBufferRegion();
  18576. stopped = true;
  18577. }
  18578. lastGain = gain;
  18579. }
  18580. END_JUCE_NAMESPACE
  18581. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18582. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18583. BEGIN_JUCE_NAMESPACE
  18584. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18585. public Thread,
  18586. private Timer
  18587. {
  18588. public:
  18589. SharedBufferingAudioSourceThread()
  18590. : Thread ("Audio Buffer")
  18591. {
  18592. }
  18593. ~SharedBufferingAudioSourceThread()
  18594. {
  18595. stopThread (10000);
  18596. clearSingletonInstance();
  18597. }
  18598. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18599. void addSource (BufferingAudioSource* source)
  18600. {
  18601. const ScopedLock sl (lock);
  18602. if (! sources.contains ((void*) source))
  18603. {
  18604. sources.add ((void*) source);
  18605. startThread();
  18606. stopTimer();
  18607. }
  18608. notify();
  18609. }
  18610. void removeSource (BufferingAudioSource* source)
  18611. {
  18612. const ScopedLock sl (lock);
  18613. sources.removeValue ((void*) source);
  18614. if (sources.size() == 0)
  18615. startTimer (5000);
  18616. }
  18617. private:
  18618. VoidArray sources;
  18619. CriticalSection lock;
  18620. void run()
  18621. {
  18622. while (! threadShouldExit())
  18623. {
  18624. bool busy = false;
  18625. for (int i = sources.size(); --i >= 0;)
  18626. {
  18627. if (threadShouldExit())
  18628. return;
  18629. const ScopedLock sl (lock);
  18630. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18631. if (b != 0 && b->readNextBufferChunk())
  18632. busy = true;
  18633. }
  18634. if (! busy)
  18635. wait (500);
  18636. }
  18637. }
  18638. void timerCallback()
  18639. {
  18640. stopTimer();
  18641. if (sources.size() == 0)
  18642. deleteInstance();
  18643. }
  18644. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18645. const SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18646. };
  18647. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18648. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18649. const bool deleteSourceWhenDeleted_,
  18650. int numberOfSamplesToBuffer_)
  18651. : source (source_),
  18652. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18653. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18654. buffer (2, 0),
  18655. bufferValidStart (0),
  18656. bufferValidEnd (0),
  18657. nextPlayPos (0),
  18658. wasSourceLooping (false)
  18659. {
  18660. jassert (source_ != 0);
  18661. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18662. // not using a larger buffer..
  18663. }
  18664. BufferingAudioSource::~BufferingAudioSource()
  18665. {
  18666. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18667. if (thread != 0)
  18668. thread->removeSource (this);
  18669. if (deleteSourceWhenDeleted)
  18670. delete source;
  18671. }
  18672. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18673. {
  18674. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18675. sampleRate = sampleRate_;
  18676. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18677. buffer.clear();
  18678. bufferValidStart = 0;
  18679. bufferValidEnd = 0;
  18680. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18681. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18682. buffer.getNumSamples() / 2))
  18683. {
  18684. SharedBufferingAudioSourceThread::getInstance()->notify();
  18685. Thread::sleep (5);
  18686. }
  18687. }
  18688. void BufferingAudioSource::releaseResources()
  18689. {
  18690. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18691. if (thread != 0)
  18692. thread->removeSource (this);
  18693. buffer.setSize (2, 0);
  18694. source->releaseResources();
  18695. }
  18696. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18697. {
  18698. const ScopedLock sl (bufferStartPosLock);
  18699. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18700. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18701. if (validStart == validEnd)
  18702. {
  18703. // total cache miss
  18704. info.clearActiveBufferRegion();
  18705. }
  18706. else
  18707. {
  18708. if (validStart > 0)
  18709. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18710. if (validEnd < info.numSamples)
  18711. info.buffer->clear (info.startSample + validEnd,
  18712. info.numSamples - validEnd); // partial cache miss at end
  18713. if (validStart < validEnd)
  18714. {
  18715. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18716. {
  18717. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18718. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18719. if (startBufferIndex < endBufferIndex)
  18720. {
  18721. info.buffer->copyFrom (chan, info.startSample + validStart,
  18722. buffer,
  18723. chan, startBufferIndex,
  18724. validEnd - validStart);
  18725. }
  18726. else
  18727. {
  18728. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18729. info.buffer->copyFrom (chan, info.startSample + validStart,
  18730. buffer,
  18731. chan, startBufferIndex,
  18732. initialSize);
  18733. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18734. buffer,
  18735. chan, 0,
  18736. (validEnd - validStart) - initialSize);
  18737. }
  18738. }
  18739. }
  18740. nextPlayPos += info.numSamples;
  18741. if (source->isLooping() && nextPlayPos > 0)
  18742. nextPlayPos %= source->getTotalLength();
  18743. }
  18744. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18745. if (thread != 0)
  18746. thread->notify();
  18747. }
  18748. int BufferingAudioSource::getNextReadPosition() const
  18749. {
  18750. return (source->isLooping() && nextPlayPos > 0)
  18751. ? nextPlayPos % source->getTotalLength()
  18752. : nextPlayPos;
  18753. }
  18754. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18755. {
  18756. const ScopedLock sl (bufferStartPosLock);
  18757. nextPlayPos = newPosition;
  18758. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18759. if (thread != 0)
  18760. thread->notify();
  18761. }
  18762. bool BufferingAudioSource::readNextBufferChunk()
  18763. {
  18764. bufferStartPosLock.enter();
  18765. if (wasSourceLooping != isLooping())
  18766. {
  18767. wasSourceLooping = isLooping();
  18768. bufferValidStart = 0;
  18769. bufferValidEnd = 0;
  18770. }
  18771. int newBVS = jmax (0, nextPlayPos);
  18772. int newBVE = newBVS + buffer.getNumSamples() - 4;
  18773. int sectionToReadStart = 0;
  18774. int sectionToReadEnd = 0;
  18775. const int maxChunkSize = 2048;
  18776. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18777. {
  18778. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18779. sectionToReadStart = newBVS;
  18780. sectionToReadEnd = newBVE;
  18781. bufferValidStart = 0;
  18782. bufferValidEnd = 0;
  18783. }
  18784. else if (abs (newBVS - bufferValidStart) > 512
  18785. || abs (newBVE - bufferValidEnd) > 512)
  18786. {
  18787. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18788. sectionToReadStart = bufferValidEnd;
  18789. sectionToReadEnd = newBVE;
  18790. bufferValidStart = newBVS;
  18791. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18792. }
  18793. bufferStartPosLock.exit();
  18794. if (sectionToReadStart != sectionToReadEnd)
  18795. {
  18796. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18797. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18798. if (bufferIndexStart < bufferIndexEnd)
  18799. {
  18800. readBufferSection (sectionToReadStart,
  18801. sectionToReadEnd - sectionToReadStart,
  18802. bufferIndexStart);
  18803. }
  18804. else
  18805. {
  18806. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18807. readBufferSection (sectionToReadStart,
  18808. initialSize,
  18809. bufferIndexStart);
  18810. readBufferSection (sectionToReadStart + initialSize,
  18811. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18812. 0);
  18813. }
  18814. const ScopedLock sl2 (bufferStartPosLock);
  18815. bufferValidStart = newBVS;
  18816. bufferValidEnd = newBVE;
  18817. return true;
  18818. }
  18819. else
  18820. {
  18821. return false;
  18822. }
  18823. }
  18824. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18825. {
  18826. if (source->getNextReadPosition() != start)
  18827. source->setNextReadPosition (start);
  18828. AudioSourceChannelInfo info;
  18829. info.buffer = &buffer;
  18830. info.startSample = bufferOffset;
  18831. info.numSamples = length;
  18832. source->getNextAudioBlock (info);
  18833. }
  18834. END_JUCE_NAMESPACE
  18835. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18836. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18837. BEGIN_JUCE_NAMESPACE
  18838. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18839. const bool deleteSourceWhenDeleted_)
  18840. : requiredNumberOfChannels (2),
  18841. source (source_),
  18842. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18843. buffer (2, 16)
  18844. {
  18845. remappedInfo.buffer = &buffer;
  18846. remappedInfo.startSample = 0;
  18847. }
  18848. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18849. {
  18850. if (deleteSourceWhenDeleted)
  18851. delete source;
  18852. }
  18853. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18854. {
  18855. const ScopedLock sl (lock);
  18856. requiredNumberOfChannels = requiredNumberOfChannels_;
  18857. }
  18858. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18859. {
  18860. const ScopedLock sl (lock);
  18861. remappedInputs.clear();
  18862. remappedOutputs.clear();
  18863. }
  18864. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18865. {
  18866. const ScopedLock sl (lock);
  18867. while (remappedInputs.size() < destIndex)
  18868. remappedInputs.add (-1);
  18869. remappedInputs.set (destIndex, sourceIndex);
  18870. }
  18871. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18872. {
  18873. const ScopedLock sl (lock);
  18874. while (remappedOutputs.size() < sourceIndex)
  18875. remappedOutputs.add (-1);
  18876. remappedOutputs.set (sourceIndex, destIndex);
  18877. }
  18878. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18879. {
  18880. const ScopedLock sl (lock);
  18881. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18882. return remappedInputs.getUnchecked (inputChannelIndex);
  18883. return -1;
  18884. }
  18885. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18886. {
  18887. const ScopedLock sl (lock);
  18888. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18889. return remappedOutputs .getUnchecked (outputChannelIndex);
  18890. return -1;
  18891. }
  18892. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18893. {
  18894. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18895. }
  18896. void ChannelRemappingAudioSource::releaseResources()
  18897. {
  18898. source->releaseResources();
  18899. }
  18900. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18901. {
  18902. const ScopedLock sl (lock);
  18903. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18904. const int numChans = bufferToFill.buffer->getNumChannels();
  18905. int i;
  18906. for (i = 0; i < buffer.getNumChannels(); ++i)
  18907. {
  18908. const int remappedChan = getRemappedInputChannel (i);
  18909. if (remappedChan >= 0 && remappedChan < numChans)
  18910. {
  18911. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18912. remappedChan,
  18913. bufferToFill.startSample,
  18914. bufferToFill.numSamples);
  18915. }
  18916. else
  18917. {
  18918. buffer.clear (i, 0, bufferToFill.numSamples);
  18919. }
  18920. }
  18921. remappedInfo.numSamples = bufferToFill.numSamples;
  18922. source->getNextAudioBlock (remappedInfo);
  18923. bufferToFill.clearActiveBufferRegion();
  18924. for (i = 0; i < requiredNumberOfChannels; ++i)
  18925. {
  18926. const int remappedChan = getRemappedOutputChannel (i);
  18927. if (remappedChan >= 0 && remappedChan < numChans)
  18928. {
  18929. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18930. buffer, i, 0, bufferToFill.numSamples);
  18931. }
  18932. }
  18933. }
  18934. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18935. {
  18936. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18937. String ins, outs;
  18938. int i;
  18939. const ScopedLock sl (lock);
  18940. for (i = 0; i < remappedInputs.size(); ++i)
  18941. ins << remappedInputs.getUnchecked(i) << T(' ');
  18942. for (i = 0; i < remappedOutputs.size(); ++i)
  18943. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18944. e->setAttribute (T("inputs"), ins.trimEnd());
  18945. e->setAttribute (T("outputs"), outs.trimEnd());
  18946. return e;
  18947. }
  18948. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18949. {
  18950. if (e.hasTagName (T("MAPPINGS")))
  18951. {
  18952. const ScopedLock sl (lock);
  18953. clearAllMappings();
  18954. StringArray ins, outs;
  18955. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18956. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18957. int i;
  18958. for (i = 0; i < ins.size(); ++i)
  18959. remappedInputs.add (ins[i].getIntValue());
  18960. for (i = 0; i < outs.size(); ++i)
  18961. remappedOutputs.add (outs[i].getIntValue());
  18962. }
  18963. }
  18964. END_JUCE_NAMESPACE
  18965. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18966. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18967. BEGIN_JUCE_NAMESPACE
  18968. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18969. const bool deleteInputWhenDeleted_)
  18970. : input (inputSource),
  18971. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18972. {
  18973. jassert (inputSource != 0);
  18974. for (int i = 2; --i >= 0;)
  18975. iirFilters.add (new IIRFilter());
  18976. }
  18977. IIRFilterAudioSource::~IIRFilterAudioSource()
  18978. {
  18979. if (deleteInputWhenDeleted)
  18980. delete input;
  18981. }
  18982. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18983. {
  18984. for (int i = iirFilters.size(); --i >= 0;)
  18985. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18986. }
  18987. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18988. {
  18989. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18990. for (int i = iirFilters.size(); --i >= 0;)
  18991. iirFilters.getUnchecked(i)->reset();
  18992. }
  18993. void IIRFilterAudioSource::releaseResources()
  18994. {
  18995. input->releaseResources();
  18996. }
  18997. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18998. {
  18999. input->getNextAudioBlock (bufferToFill);
  19000. const int numChannels = bufferToFill.buffer->getNumChannels();
  19001. while (numChannels > iirFilters.size())
  19002. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  19003. for (int i = 0; i < numChannels; ++i)
  19004. iirFilters.getUnchecked(i)
  19005. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  19006. bufferToFill.numSamples);
  19007. }
  19008. END_JUCE_NAMESPACE
  19009. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19010. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  19011. BEGIN_JUCE_NAMESPACE
  19012. MixerAudioSource::MixerAudioSource()
  19013. : tempBuffer (2, 0),
  19014. currentSampleRate (0.0),
  19015. bufferSizeExpected (0)
  19016. {
  19017. }
  19018. MixerAudioSource::~MixerAudioSource()
  19019. {
  19020. removeAllInputs();
  19021. }
  19022. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  19023. {
  19024. if (input != 0 && ! inputs.contains (input))
  19025. {
  19026. lock.enter();
  19027. double localRate = currentSampleRate;
  19028. int localBufferSize = bufferSizeExpected;
  19029. lock.exit();
  19030. if (localRate != 0.0)
  19031. input->prepareToPlay (localBufferSize, localRate);
  19032. const ScopedLock sl (lock);
  19033. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  19034. inputs.add (input);
  19035. }
  19036. }
  19037. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  19038. {
  19039. if (input != 0)
  19040. {
  19041. lock.enter();
  19042. const int index = inputs.indexOf ((void*) input);
  19043. if (index >= 0)
  19044. {
  19045. inputsToDelete.shiftBits (index, 1);
  19046. inputs.remove (index);
  19047. }
  19048. lock.exit();
  19049. if (index >= 0)
  19050. {
  19051. input->releaseResources();
  19052. if (deleteInput)
  19053. delete input;
  19054. }
  19055. }
  19056. }
  19057. void MixerAudioSource::removeAllInputs()
  19058. {
  19059. lock.enter();
  19060. VoidArray inputsCopy (inputs);
  19061. BitArray inputsToDeleteCopy (inputsToDelete);
  19062. inputs.clear();
  19063. lock.exit();
  19064. for (int i = inputsCopy.size(); --i >= 0;)
  19065. if (inputsToDeleteCopy[i])
  19066. delete (AudioSource*) inputsCopy[i];
  19067. }
  19068. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19069. {
  19070. tempBuffer.setSize (2, samplesPerBlockExpected);
  19071. const ScopedLock sl (lock);
  19072. currentSampleRate = sampleRate;
  19073. bufferSizeExpected = samplesPerBlockExpected;
  19074. for (int i = inputs.size(); --i >= 0;)
  19075. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19076. sampleRate);
  19077. }
  19078. void MixerAudioSource::releaseResources()
  19079. {
  19080. const ScopedLock sl (lock);
  19081. for (int i = inputs.size(); --i >= 0;)
  19082. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19083. tempBuffer.setSize (2, 0);
  19084. currentSampleRate = 0;
  19085. bufferSizeExpected = 0;
  19086. }
  19087. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19088. {
  19089. const ScopedLock sl (lock);
  19090. if (inputs.size() > 0)
  19091. {
  19092. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19093. if (inputs.size() > 1)
  19094. {
  19095. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19096. info.buffer->getNumSamples());
  19097. AudioSourceChannelInfo info2;
  19098. info2.buffer = &tempBuffer;
  19099. info2.numSamples = info.numSamples;
  19100. info2.startSample = 0;
  19101. for (int i = 1; i < inputs.size(); ++i)
  19102. {
  19103. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19104. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19105. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19106. }
  19107. }
  19108. }
  19109. else
  19110. {
  19111. info.clearActiveBufferRegion();
  19112. }
  19113. }
  19114. END_JUCE_NAMESPACE
  19115. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19116. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19117. BEGIN_JUCE_NAMESPACE
  19118. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19119. const bool deleteInputWhenDeleted_)
  19120. : input (inputSource),
  19121. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19122. ratio (1.0),
  19123. lastRatio (1.0),
  19124. buffer (2, 0),
  19125. sampsInBuffer (0)
  19126. {
  19127. jassert (input != 0);
  19128. }
  19129. ResamplingAudioSource::~ResamplingAudioSource()
  19130. {
  19131. if (deleteInputWhenDeleted)
  19132. delete input;
  19133. }
  19134. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19135. {
  19136. jassert (samplesInPerOutputSample > 0);
  19137. const ScopedLock sl (ratioLock);
  19138. ratio = jmax (0.0, samplesInPerOutputSample);
  19139. }
  19140. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19141. double sampleRate)
  19142. {
  19143. const ScopedLock sl (ratioLock);
  19144. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19145. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19146. buffer.clear();
  19147. sampsInBuffer = 0;
  19148. bufferPos = 0;
  19149. subSampleOffset = 0.0;
  19150. createLowPass (ratio);
  19151. resetFilters();
  19152. }
  19153. void ResamplingAudioSource::releaseResources()
  19154. {
  19155. input->releaseResources();
  19156. buffer.setSize (2, 0);
  19157. }
  19158. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19159. {
  19160. const ScopedLock sl (ratioLock);
  19161. if (lastRatio != ratio)
  19162. {
  19163. createLowPass (ratio);
  19164. lastRatio = ratio;
  19165. }
  19166. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19167. int bufferSize = buffer.getNumSamples();
  19168. if (bufferSize < sampsNeeded + 8)
  19169. {
  19170. bufferPos %= bufferSize;
  19171. bufferSize = sampsNeeded + 32;
  19172. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19173. }
  19174. bufferPos %= bufferSize;
  19175. int endOfBufferPos = bufferPos + sampsInBuffer;
  19176. while (sampsNeeded > sampsInBuffer)
  19177. {
  19178. endOfBufferPos %= bufferSize;
  19179. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19180. bufferSize - endOfBufferPos);
  19181. AudioSourceChannelInfo readInfo;
  19182. readInfo.buffer = &buffer;
  19183. readInfo.numSamples = numToDo;
  19184. readInfo.startSample = endOfBufferPos;
  19185. input->getNextAudioBlock (readInfo);
  19186. if (ratio > 1.0001)
  19187. {
  19188. // for down-sampling, pre-apply the filter..
  19189. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19190. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19191. }
  19192. sampsInBuffer += numToDo;
  19193. endOfBufferPos += numToDo;
  19194. }
  19195. float* dl = info.buffer->getSampleData (0, info.startSample);
  19196. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19197. const float* const bl = buffer.getSampleData (0, 0);
  19198. const float* const br = buffer.getSampleData (1, 0);
  19199. int nextPos = (bufferPos + 1) % bufferSize;
  19200. for (int m = info.numSamples; --m >= 0;)
  19201. {
  19202. const float alpha = (float) subSampleOffset;
  19203. const float invAlpha = 1.0f - alpha;
  19204. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19205. if (dr != 0)
  19206. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19207. subSampleOffset += ratio;
  19208. jassert (sampsInBuffer > 0);
  19209. while (subSampleOffset >= 1.0)
  19210. {
  19211. if (++bufferPos >= bufferSize)
  19212. bufferPos = 0;
  19213. --sampsInBuffer;
  19214. nextPos = (bufferPos + 1) % bufferSize;
  19215. subSampleOffset -= 1.0;
  19216. }
  19217. }
  19218. if (ratio < 0.9999)
  19219. {
  19220. // for up-sampling, apply the filter after transposing..
  19221. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19222. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19223. }
  19224. else if (ratio <= 1.0001)
  19225. {
  19226. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19227. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19228. {
  19229. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19230. FilterState& fs = filterStates[i];
  19231. if (info.numSamples > 1)
  19232. {
  19233. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19234. }
  19235. else
  19236. {
  19237. fs.y2 = fs.y1;
  19238. fs.x2 = fs.x1;
  19239. }
  19240. fs.y1 = fs.x1 = *endOfBuffer;
  19241. }
  19242. }
  19243. jassert (sampsInBuffer >= 0);
  19244. }
  19245. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19246. {
  19247. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19248. : 0.5 * frequencyRatio;
  19249. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19250. const double nSquared = n * n;
  19251. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19252. setFilterCoefficients (c1,
  19253. c1 * 2.0f,
  19254. c1,
  19255. 1.0,
  19256. c1 * 2.0 * (1.0 - nSquared),
  19257. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19258. }
  19259. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19260. {
  19261. const double a = 1.0 / c4;
  19262. c1 *= a;
  19263. c2 *= a;
  19264. c3 *= a;
  19265. c5 *= a;
  19266. c6 *= a;
  19267. coefficients[0] = c1;
  19268. coefficients[1] = c2;
  19269. coefficients[2] = c3;
  19270. coefficients[3] = c4;
  19271. coefficients[4] = c5;
  19272. coefficients[5] = c6;
  19273. }
  19274. void ResamplingAudioSource::resetFilters()
  19275. {
  19276. zeromem (filterStates, sizeof (filterStates));
  19277. }
  19278. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19279. {
  19280. while (--num >= 0)
  19281. {
  19282. const double in = *samples;
  19283. double out = coefficients[0] * in
  19284. + coefficients[1] * fs.x1
  19285. + coefficients[2] * fs.x2
  19286. - coefficients[4] * fs.y1
  19287. - coefficients[5] * fs.y2;
  19288. #if JUCE_INTEL
  19289. if (! (out < -1.0e-8 || out > 1.0e-8))
  19290. out = 0;
  19291. #endif
  19292. fs.x2 = fs.x1;
  19293. fs.x1 = in;
  19294. fs.y2 = fs.y1;
  19295. fs.y1 = out;
  19296. *samples++ = (float) out;
  19297. }
  19298. }
  19299. END_JUCE_NAMESPACE
  19300. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19301. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19302. BEGIN_JUCE_NAMESPACE
  19303. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19304. : frequency (1000.0),
  19305. sampleRate (44100.0),
  19306. currentPhase (0.0),
  19307. phasePerSample (0.0),
  19308. amplitude (0.5f)
  19309. {
  19310. }
  19311. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19312. {
  19313. }
  19314. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19315. {
  19316. amplitude = newAmplitude;
  19317. }
  19318. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19319. {
  19320. frequency = newFrequencyHz;
  19321. phasePerSample = 0.0;
  19322. }
  19323. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19324. double sampleRate_)
  19325. {
  19326. currentPhase = 0.0;
  19327. phasePerSample = 0.0;
  19328. sampleRate = sampleRate_;
  19329. }
  19330. void ToneGeneratorAudioSource::releaseResources()
  19331. {
  19332. }
  19333. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19334. {
  19335. if (phasePerSample == 0.0)
  19336. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19337. for (int i = 0; i < info.numSamples; ++i)
  19338. {
  19339. const float sample = amplitude * (float) sin (currentPhase);
  19340. currentPhase += phasePerSample;
  19341. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19342. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19343. }
  19344. }
  19345. END_JUCE_NAMESPACE
  19346. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19347. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19348. BEGIN_JUCE_NAMESPACE
  19349. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19350. : sampleRate (0),
  19351. bufferSize (0),
  19352. useDefaultInputChannels (true),
  19353. useDefaultOutputChannels (true)
  19354. {
  19355. }
  19356. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19357. {
  19358. return outputDeviceName == other.outputDeviceName
  19359. && inputDeviceName == other.inputDeviceName
  19360. && sampleRate == other.sampleRate
  19361. && bufferSize == other.bufferSize
  19362. && inputChannels == other.inputChannels
  19363. && useDefaultInputChannels == other.useDefaultInputChannels
  19364. && outputChannels == other.outputChannels
  19365. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19366. }
  19367. AudioDeviceManager::AudioDeviceManager()
  19368. : currentAudioDevice (0),
  19369. numInputChansNeeded (0),
  19370. numOutputChansNeeded (2),
  19371. listNeedsScanning (true),
  19372. useInputNames (false),
  19373. inputLevelMeasurementEnabledCount (0),
  19374. inputLevel (0),
  19375. tempBuffer (2, 2),
  19376. defaultMidiOutput (0),
  19377. cpuUsageMs (0),
  19378. timeToCpuScale (0)
  19379. {
  19380. callbackHandler.owner = this;
  19381. }
  19382. AudioDeviceManager::~AudioDeviceManager()
  19383. {
  19384. currentAudioDevice = 0;
  19385. defaultMidiOutput = 0;
  19386. }
  19387. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19388. {
  19389. if (availableDeviceTypes.size() == 0)
  19390. {
  19391. createAudioDeviceTypes (availableDeviceTypes);
  19392. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19393. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19394. if (availableDeviceTypes.size() > 0)
  19395. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19396. }
  19397. }
  19398. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19399. {
  19400. scanDevicesIfNeeded();
  19401. return availableDeviceTypes;
  19402. }
  19403. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19404. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19405. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19406. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19407. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19408. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19409. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19410. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19411. {
  19412. #if JUCE_WINDOWS
  19413. #if JUCE_WASAPI
  19414. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19415. list.add (juce_createAudioIODeviceType_WASAPI());
  19416. #endif
  19417. #if JUCE_DIRECTSOUND
  19418. list.add (juce_createAudioIODeviceType_DirectSound());
  19419. #endif
  19420. #if JUCE_ASIO
  19421. list.add (juce_createAudioIODeviceType_ASIO());
  19422. #endif
  19423. #endif
  19424. #if JUCE_MAC
  19425. list.add (juce_createAudioIODeviceType_CoreAudio());
  19426. #endif
  19427. #if JUCE_IPHONE
  19428. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19429. #endif
  19430. #if JUCE_LINUX && JUCE_ALSA
  19431. list.add (juce_createAudioIODeviceType_ALSA());
  19432. #endif
  19433. #if JUCE_LINUX && JUCE_JACK
  19434. list.add (juce_createAudioIODeviceType_JACK());
  19435. #endif
  19436. }
  19437. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19438. const int numOutputChannelsNeeded,
  19439. const XmlElement* const e,
  19440. const bool selectDefaultDeviceOnFailure,
  19441. const String& preferredDefaultDeviceName,
  19442. const AudioDeviceSetup* preferredSetupOptions)
  19443. {
  19444. scanDevicesIfNeeded();
  19445. numInputChansNeeded = numInputChannelsNeeded;
  19446. numOutputChansNeeded = numOutputChannelsNeeded;
  19447. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19448. {
  19449. lastExplicitSettings = new XmlElement (*e);
  19450. String error;
  19451. AudioDeviceSetup setup;
  19452. if (preferredSetupOptions != 0)
  19453. setup = *preferredSetupOptions;
  19454. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19455. {
  19456. setup.inputDeviceName = setup.outputDeviceName
  19457. = e->getStringAttribute (T("audioDeviceName"));
  19458. }
  19459. else
  19460. {
  19461. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19462. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19463. }
  19464. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19465. if (currentDeviceType.isEmpty())
  19466. {
  19467. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19468. if (type != 0)
  19469. currentDeviceType = type->getTypeName();
  19470. else if (availableDeviceTypes.size() > 0)
  19471. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19472. }
  19473. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19474. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19475. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19476. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19477. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19478. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19479. error = setAudioDeviceSetup (setup, true);
  19480. midiInsFromXml.clear();
  19481. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19482. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19483. const StringArray allMidiIns (MidiInput::getDevices());
  19484. for (int i = allMidiIns.size(); --i >= 0;)
  19485. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19486. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19487. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19488. false, preferredDefaultDeviceName);
  19489. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19490. return error;
  19491. }
  19492. else
  19493. {
  19494. AudioDeviceSetup setup;
  19495. if (preferredSetupOptions != 0)
  19496. {
  19497. setup = *preferredSetupOptions;
  19498. }
  19499. else if (preferredDefaultDeviceName.isNotEmpty())
  19500. {
  19501. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19502. {
  19503. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19504. StringArray outs (type->getDeviceNames (false));
  19505. int i;
  19506. for (i = 0; i < outs.size(); ++i)
  19507. {
  19508. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19509. {
  19510. setup.outputDeviceName = outs[i];
  19511. break;
  19512. }
  19513. }
  19514. StringArray ins (type->getDeviceNames (true));
  19515. for (i = 0; i < ins.size(); ++i)
  19516. {
  19517. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19518. {
  19519. setup.inputDeviceName = ins[i];
  19520. break;
  19521. }
  19522. }
  19523. }
  19524. }
  19525. insertDefaultDeviceNames (setup);
  19526. return setAudioDeviceSetup (setup, false);
  19527. }
  19528. }
  19529. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19530. {
  19531. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19532. if (type != 0)
  19533. {
  19534. if (setup.outputDeviceName.isEmpty())
  19535. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19536. if (setup.inputDeviceName.isEmpty())
  19537. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19538. }
  19539. }
  19540. XmlElement* AudioDeviceManager::createStateXml() const
  19541. {
  19542. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19543. }
  19544. void AudioDeviceManager::scanDevicesIfNeeded()
  19545. {
  19546. if (listNeedsScanning)
  19547. {
  19548. listNeedsScanning = false;
  19549. createDeviceTypesIfNeeded();
  19550. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19551. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19552. }
  19553. }
  19554. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19555. {
  19556. scanDevicesIfNeeded();
  19557. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19558. {
  19559. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19560. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19561. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19562. {
  19563. return type;
  19564. }
  19565. }
  19566. return 0;
  19567. }
  19568. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19569. {
  19570. setup = currentSetup;
  19571. }
  19572. void AudioDeviceManager::deleteCurrentDevice()
  19573. {
  19574. currentAudioDevice = 0;
  19575. currentSetup.inputDeviceName = String::empty;
  19576. currentSetup.outputDeviceName = String::empty;
  19577. }
  19578. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19579. const bool treatAsChosenDevice)
  19580. {
  19581. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19582. {
  19583. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19584. && currentDeviceType != type)
  19585. {
  19586. currentDeviceType = type;
  19587. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19588. insertDefaultDeviceNames (s);
  19589. setAudioDeviceSetup (s, treatAsChosenDevice);
  19590. sendChangeMessage (this);
  19591. break;
  19592. }
  19593. }
  19594. }
  19595. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19596. {
  19597. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19598. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19599. return availableDeviceTypes[i];
  19600. return availableDeviceTypes[0];
  19601. }
  19602. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19603. const bool treatAsChosenDevice)
  19604. {
  19605. jassert (&newSetup != &currentSetup); // this will have no effect
  19606. if (newSetup == currentSetup && currentAudioDevice != 0)
  19607. return String::empty;
  19608. if (! (newSetup == currentSetup))
  19609. sendChangeMessage (this);
  19610. stopDevice();
  19611. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19612. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19613. String error;
  19614. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19615. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19616. {
  19617. deleteCurrentDevice();
  19618. if (treatAsChosenDevice)
  19619. updateXml();
  19620. return String::empty;
  19621. }
  19622. if (currentSetup.inputDeviceName != newInputDeviceName
  19623. || currentSetup.outputDeviceName != newOutputDeviceName
  19624. || currentAudioDevice == 0)
  19625. {
  19626. deleteCurrentDevice();
  19627. scanDevicesIfNeeded();
  19628. if (newOutputDeviceName.isNotEmpty()
  19629. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19630. {
  19631. return "No such device: " + newOutputDeviceName;
  19632. }
  19633. if (newInputDeviceName.isNotEmpty()
  19634. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19635. {
  19636. return "No such device: " + newInputDeviceName;
  19637. }
  19638. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19639. if (currentAudioDevice == 0)
  19640. 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!";
  19641. else
  19642. error = currentAudioDevice->getLastError();
  19643. if (error.isNotEmpty())
  19644. {
  19645. deleteCurrentDevice();
  19646. return error;
  19647. }
  19648. if (newSetup.useDefaultInputChannels)
  19649. {
  19650. inputChannels.clear();
  19651. inputChannels.setRange (0, numInputChansNeeded, true);
  19652. }
  19653. if (newSetup.useDefaultOutputChannels)
  19654. {
  19655. outputChannels.clear();
  19656. outputChannels.setRange (0, numOutputChansNeeded, true);
  19657. }
  19658. if (newInputDeviceName.isEmpty())
  19659. inputChannels.clear();
  19660. if (newOutputDeviceName.isEmpty())
  19661. outputChannels.clear();
  19662. }
  19663. if (! newSetup.useDefaultInputChannels)
  19664. inputChannels = newSetup.inputChannels;
  19665. if (! newSetup.useDefaultOutputChannels)
  19666. outputChannels = newSetup.outputChannels;
  19667. currentSetup = newSetup;
  19668. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19669. error = currentAudioDevice->open (inputChannels,
  19670. outputChannels,
  19671. currentSetup.sampleRate,
  19672. currentSetup.bufferSize);
  19673. if (error.isEmpty())
  19674. {
  19675. currentDeviceType = currentAudioDevice->getTypeName();
  19676. currentAudioDevice->start (&callbackHandler);
  19677. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19678. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19679. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19680. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19681. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19682. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19683. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19684. if (treatAsChosenDevice)
  19685. updateXml();
  19686. }
  19687. else
  19688. {
  19689. deleteCurrentDevice();
  19690. }
  19691. return error;
  19692. }
  19693. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19694. {
  19695. jassert (currentAudioDevice != 0);
  19696. if (rate > 0)
  19697. {
  19698. bool ok = false;
  19699. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19700. {
  19701. const double sr = currentAudioDevice->getSampleRate (i);
  19702. if (sr == rate)
  19703. ok = true;
  19704. }
  19705. if (! ok)
  19706. rate = 0;
  19707. }
  19708. if (rate == 0)
  19709. {
  19710. double lowestAbove44 = 0.0;
  19711. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19712. {
  19713. const double sr = currentAudioDevice->getSampleRate (i);
  19714. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19715. lowestAbove44 = sr;
  19716. }
  19717. if (lowestAbove44 == 0.0)
  19718. rate = currentAudioDevice->getSampleRate (0);
  19719. else
  19720. rate = lowestAbove44;
  19721. }
  19722. return rate;
  19723. }
  19724. void AudioDeviceManager::stopDevice()
  19725. {
  19726. if (currentAudioDevice != 0)
  19727. currentAudioDevice->stop();
  19728. testSound = 0;
  19729. }
  19730. void AudioDeviceManager::closeAudioDevice()
  19731. {
  19732. stopDevice();
  19733. currentAudioDevice = 0;
  19734. }
  19735. void AudioDeviceManager::restartLastAudioDevice()
  19736. {
  19737. if (currentAudioDevice == 0)
  19738. {
  19739. if (currentSetup.inputDeviceName.isEmpty()
  19740. && currentSetup.outputDeviceName.isEmpty())
  19741. {
  19742. // This method will only reload the last device that was running
  19743. // before closeAudioDevice() was called - you need to actually open
  19744. // one first, with setAudioDevice().
  19745. jassertfalse
  19746. return;
  19747. }
  19748. AudioDeviceSetup s (currentSetup);
  19749. setAudioDeviceSetup (s, false);
  19750. }
  19751. }
  19752. void AudioDeviceManager::updateXml()
  19753. {
  19754. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19755. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19756. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19757. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19758. if (currentAudioDevice != 0)
  19759. {
  19760. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19761. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19762. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19763. if (! currentSetup.useDefaultInputChannels)
  19764. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19765. if (! currentSetup.useDefaultOutputChannels)
  19766. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19767. }
  19768. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19769. {
  19770. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19771. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19772. }
  19773. if (midiInsFromXml.size() > 0)
  19774. {
  19775. // Add any midi devices that have been enabled before, but which aren't currently
  19776. // open because the device has been disconnected.
  19777. const StringArray availableMidiDevices (MidiInput::getDevices());
  19778. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19779. {
  19780. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19781. {
  19782. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19783. m->setAttribute ("name", midiInsFromXml[i]);
  19784. }
  19785. }
  19786. }
  19787. if (defaultMidiOutputName.isNotEmpty())
  19788. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19789. }
  19790. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19791. {
  19792. {
  19793. const ScopedLock sl (audioCallbackLock);
  19794. if (callbacks.contains (newCallback))
  19795. return;
  19796. }
  19797. if (currentAudioDevice != 0 && newCallback != 0)
  19798. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19799. const ScopedLock sl (audioCallbackLock);
  19800. callbacks.add (newCallback);
  19801. }
  19802. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19803. {
  19804. if (callback != 0)
  19805. {
  19806. bool needsDeinitialising = currentAudioDevice != 0;
  19807. {
  19808. const ScopedLock sl (audioCallbackLock);
  19809. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19810. callbacks.removeValue (callback);
  19811. }
  19812. if (needsDeinitialising)
  19813. callback->audioDeviceStopped();
  19814. }
  19815. }
  19816. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19817. int numInputChannels,
  19818. float** outputChannelData,
  19819. int numOutputChannels,
  19820. int numSamples)
  19821. {
  19822. const ScopedLock sl (audioCallbackLock);
  19823. if (inputLevelMeasurementEnabledCount > 0)
  19824. {
  19825. for (int j = 0; j < numSamples; ++j)
  19826. {
  19827. float s = 0;
  19828. for (int i = 0; i < numInputChannels; ++i)
  19829. s += fabsf (inputChannelData[i][j]);
  19830. s /= numInputChannels;
  19831. const double decayFactor = 0.99992;
  19832. if (s > inputLevel)
  19833. inputLevel = s;
  19834. else if (inputLevel > 0.001f)
  19835. inputLevel *= decayFactor;
  19836. else
  19837. inputLevel = 0;
  19838. }
  19839. }
  19840. if (callbacks.size() > 0)
  19841. {
  19842. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19843. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19844. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19845. outputChannelData, numOutputChannels, numSamples);
  19846. float** const tempChans = tempBuffer.getArrayOfChannels();
  19847. for (int i = callbacks.size(); --i > 0;)
  19848. {
  19849. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19850. tempChans, numOutputChannels, numSamples);
  19851. for (int chan = 0; chan < numOutputChannels; ++chan)
  19852. {
  19853. const float* const src = tempChans [chan];
  19854. float* const dst = outputChannelData [chan];
  19855. if (src != 0 && dst != 0)
  19856. for (int j = 0; j < numSamples; ++j)
  19857. dst[j] += src[j];
  19858. }
  19859. }
  19860. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19861. const double filterAmount = 0.2;
  19862. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19863. }
  19864. else
  19865. {
  19866. for (int i = 0; i < numOutputChannels; ++i)
  19867. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19868. }
  19869. if (testSound != 0)
  19870. {
  19871. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19872. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19873. for (int i = 0; i < numOutputChannels; ++i)
  19874. for (int j = 0; j < numSamps; ++j)
  19875. outputChannelData [i][j] += src[j];
  19876. testSoundPosition += numSamps;
  19877. if (testSoundPosition >= testSound->getNumSamples())
  19878. testSound = 0;
  19879. }
  19880. }
  19881. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19882. {
  19883. cpuUsageMs = 0;
  19884. const double sampleRate = device->getCurrentSampleRate();
  19885. const int blockSize = device->getCurrentBufferSizeSamples();
  19886. if (sampleRate > 0.0 && blockSize > 0)
  19887. {
  19888. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19889. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19890. }
  19891. {
  19892. const ScopedLock sl (audioCallbackLock);
  19893. for (int i = callbacks.size(); --i >= 0;)
  19894. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19895. }
  19896. sendChangeMessage (this);
  19897. }
  19898. void AudioDeviceManager::audioDeviceStoppedInt()
  19899. {
  19900. cpuUsageMs = 0;
  19901. timeToCpuScale = 0;
  19902. sendChangeMessage (this);
  19903. const ScopedLock sl (audioCallbackLock);
  19904. for (int i = callbacks.size(); --i >= 0;)
  19905. callbacks.getUnchecked(i)->audioDeviceStopped();
  19906. }
  19907. double AudioDeviceManager::getCpuUsage() const
  19908. {
  19909. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19910. }
  19911. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19912. const bool enabled)
  19913. {
  19914. if (enabled != isMidiInputEnabled (name))
  19915. {
  19916. if (enabled)
  19917. {
  19918. const int index = MidiInput::getDevices().indexOf (name);
  19919. if (index >= 0)
  19920. {
  19921. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19922. if (min != 0)
  19923. {
  19924. enabledMidiInputs.add (min);
  19925. min->start();
  19926. }
  19927. }
  19928. }
  19929. else
  19930. {
  19931. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19932. if (enabledMidiInputs[i]->getName() == name)
  19933. enabledMidiInputs.remove (i);
  19934. }
  19935. updateXml();
  19936. sendChangeMessage (this);
  19937. }
  19938. }
  19939. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19940. {
  19941. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19942. if (enabledMidiInputs[i]->getName() == name)
  19943. return true;
  19944. return false;
  19945. }
  19946. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19947. MidiInputCallback* callback)
  19948. {
  19949. removeMidiInputCallback (name, callback);
  19950. if (name.isEmpty())
  19951. {
  19952. midiCallbacks.add (callback);
  19953. midiCallbackDevices.add (0);
  19954. }
  19955. else
  19956. {
  19957. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19958. {
  19959. if (enabledMidiInputs[i]->getName() == name)
  19960. {
  19961. const ScopedLock sl (midiCallbackLock);
  19962. midiCallbacks.add (callback);
  19963. midiCallbackDevices.add (enabledMidiInputs[i]);
  19964. break;
  19965. }
  19966. }
  19967. }
  19968. }
  19969. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19970. MidiInputCallback* /*callback*/)
  19971. {
  19972. const ScopedLock sl (midiCallbackLock);
  19973. for (int i = midiCallbacks.size(); --i >= 0;)
  19974. {
  19975. String devName;
  19976. if (midiCallbackDevices.getUnchecked(i) != 0)
  19977. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19978. if (devName == name)
  19979. {
  19980. midiCallbacks.remove (i);
  19981. midiCallbackDevices.remove (i);
  19982. }
  19983. }
  19984. }
  19985. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19986. const MidiMessage& message)
  19987. {
  19988. if (! message.isActiveSense())
  19989. {
  19990. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19991. const ScopedLock sl (midiCallbackLock);
  19992. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19993. {
  19994. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19995. if (md == source || (md == 0 && isDefaultSource))
  19996. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19997. }
  19998. }
  19999. }
  20000. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  20001. {
  20002. if (defaultMidiOutputName != deviceName)
  20003. {
  20004. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  20005. {
  20006. const ScopedLock sl (audioCallbackLock);
  20007. oldCallbacks = callbacks;
  20008. callbacks.clear();
  20009. }
  20010. if (currentAudioDevice != 0)
  20011. for (int i = oldCallbacks.size(); --i >= 0;)
  20012. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  20013. defaultMidiOutput = 0;
  20014. defaultMidiOutputName = deviceName;
  20015. if (deviceName.isNotEmpty())
  20016. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  20017. if (currentAudioDevice != 0)
  20018. for (int i = oldCallbacks.size(); --i >= 0;)
  20019. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  20020. {
  20021. const ScopedLock sl (audioCallbackLock);
  20022. callbacks = oldCallbacks;
  20023. }
  20024. updateXml();
  20025. sendChangeMessage (this);
  20026. }
  20027. }
  20028. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  20029. int numInputChannels,
  20030. float** outputChannelData,
  20031. int numOutputChannels,
  20032. int numSamples)
  20033. {
  20034. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  20035. }
  20036. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  20037. {
  20038. owner->audioDeviceAboutToStartInt (device);
  20039. }
  20040. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  20041. {
  20042. owner->audioDeviceStoppedInt();
  20043. }
  20044. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  20045. {
  20046. owner->handleIncomingMidiMessageInt (source, message);
  20047. }
  20048. void AudioDeviceManager::playTestSound()
  20049. {
  20050. {
  20051. audioCallbackLock.enter();
  20052. ScopedPointer <AudioSampleBuffer> oldSound (testSound);
  20053. audioCallbackLock.exit();
  20054. }
  20055. testSoundPosition = 0;
  20056. if (currentAudioDevice != 0)
  20057. {
  20058. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20059. const int soundLength = (int) sampleRate;
  20060. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20061. float* samples = newSound->getSampleData (0);
  20062. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20063. const float amplitude = 0.5f;
  20064. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20065. for (int i = 0; i < soundLength; ++i)
  20066. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20067. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20068. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20069. const ScopedLock sl (audioCallbackLock);
  20070. testSound = newSound;
  20071. }
  20072. }
  20073. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20074. {
  20075. const ScopedLock sl (audioCallbackLock);
  20076. if (enableMeasurement)
  20077. ++inputLevelMeasurementEnabledCount;
  20078. else
  20079. --inputLevelMeasurementEnabledCount;
  20080. inputLevel = 0;
  20081. }
  20082. double AudioDeviceManager::getCurrentInputLevel() const
  20083. {
  20084. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20085. return inputLevel;
  20086. }
  20087. END_JUCE_NAMESPACE
  20088. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20089. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20090. BEGIN_JUCE_NAMESPACE
  20091. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20092. : name (deviceName),
  20093. typeName (typeName_)
  20094. {
  20095. }
  20096. AudioIODevice::~AudioIODevice()
  20097. {
  20098. }
  20099. bool AudioIODevice::hasControlPanel() const
  20100. {
  20101. return false;
  20102. }
  20103. bool AudioIODevice::showControlPanel()
  20104. {
  20105. jassertfalse // this should only be called for devices which return true from
  20106. // their hasControlPanel() method.
  20107. return false;
  20108. }
  20109. END_JUCE_NAMESPACE
  20110. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20111. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20112. BEGIN_JUCE_NAMESPACE
  20113. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20114. : typeName (name)
  20115. {
  20116. }
  20117. AudioIODeviceType::~AudioIODeviceType()
  20118. {
  20119. }
  20120. END_JUCE_NAMESPACE
  20121. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20122. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20123. BEGIN_JUCE_NAMESPACE
  20124. MidiOutput::MidiOutput() throw()
  20125. : Thread ("midi out"),
  20126. internal (0),
  20127. firstMessage (0)
  20128. {
  20129. }
  20130. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20131. const int len,
  20132. const double sampleNumber) throw()
  20133. : message (data, len, sampleNumber)
  20134. {
  20135. }
  20136. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20137. const double millisecondCounterToStartAt,
  20138. double samplesPerSecondForBuffer) throw()
  20139. {
  20140. // You've got to call startBackgroundThread() for this to actually work..
  20141. jassert (isThreadRunning());
  20142. // this needs to be a value in the future - RTFM for this method!
  20143. jassert (millisecondCounterToStartAt > 0);
  20144. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20145. MidiBuffer::Iterator i (buffer);
  20146. const uint8* data;
  20147. int len, time;
  20148. while (i.getNextEvent (data, len, time))
  20149. {
  20150. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20151. PendingMessage* const m
  20152. = new PendingMessage (data, len, eventTime);
  20153. const ScopedLock sl (lock);
  20154. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20155. {
  20156. m->next = firstMessage;
  20157. firstMessage = m;
  20158. }
  20159. else
  20160. {
  20161. PendingMessage* mm = firstMessage;
  20162. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20163. mm = mm->next;
  20164. m->next = mm->next;
  20165. mm->next = m;
  20166. }
  20167. }
  20168. notify();
  20169. }
  20170. void MidiOutput::clearAllPendingMessages() throw()
  20171. {
  20172. const ScopedLock sl (lock);
  20173. while (firstMessage != 0)
  20174. {
  20175. PendingMessage* const m = firstMessage;
  20176. firstMessage = firstMessage->next;
  20177. delete m;
  20178. }
  20179. }
  20180. void MidiOutput::startBackgroundThread() throw()
  20181. {
  20182. startThread (9);
  20183. }
  20184. void MidiOutput::stopBackgroundThread() throw()
  20185. {
  20186. stopThread (5000);
  20187. }
  20188. void MidiOutput::run()
  20189. {
  20190. while (! threadShouldExit())
  20191. {
  20192. uint32 now = Time::getMillisecondCounter();
  20193. uint32 eventTime = 0;
  20194. uint32 timeToWait = 500;
  20195. lock.enter();
  20196. PendingMessage* message = firstMessage;
  20197. if (message != 0)
  20198. {
  20199. eventTime = roundToInt (message->message.getTimeStamp());
  20200. if (eventTime > now + 20)
  20201. {
  20202. timeToWait = eventTime - (now + 20);
  20203. message = 0;
  20204. }
  20205. else
  20206. {
  20207. firstMessage = message->next;
  20208. }
  20209. }
  20210. lock.exit();
  20211. if (message != 0)
  20212. {
  20213. if (eventTime > now)
  20214. {
  20215. Time::waitForMillisecondCounter (eventTime);
  20216. if (threadShouldExit())
  20217. break;
  20218. }
  20219. if (eventTime > now - 200)
  20220. sendMessageNow (message->message);
  20221. delete message;
  20222. }
  20223. else
  20224. {
  20225. jassert (timeToWait < 1000 * 30);
  20226. wait (timeToWait);
  20227. }
  20228. }
  20229. clearAllPendingMessages();
  20230. }
  20231. END_JUCE_NAMESPACE
  20232. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20233. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20234. BEGIN_JUCE_NAMESPACE
  20235. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20236. {
  20237. const double maxVal = (double) 0x7fff;
  20238. char* intData = (char*) dest;
  20239. if (dest != (void*) source || destBytesPerSample <= 4)
  20240. {
  20241. for (int i = 0; i < numSamples; ++i)
  20242. {
  20243. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20244. intData += destBytesPerSample;
  20245. }
  20246. }
  20247. else
  20248. {
  20249. intData += destBytesPerSample * numSamples;
  20250. for (int i = numSamples; --i >= 0;)
  20251. {
  20252. intData -= destBytesPerSample;
  20253. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20254. }
  20255. }
  20256. }
  20257. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20258. {
  20259. const double maxVal = (double) 0x7fff;
  20260. char* intData = (char*) dest;
  20261. if (dest != (void*) source || destBytesPerSample <= 4)
  20262. {
  20263. for (int i = 0; i < numSamples; ++i)
  20264. {
  20265. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20266. intData += destBytesPerSample;
  20267. }
  20268. }
  20269. else
  20270. {
  20271. intData += destBytesPerSample * numSamples;
  20272. for (int i = numSamples; --i >= 0;)
  20273. {
  20274. intData -= destBytesPerSample;
  20275. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20276. }
  20277. }
  20278. }
  20279. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20280. {
  20281. const double maxVal = (double) 0x7fffff;
  20282. char* intData = (char*) dest;
  20283. if (dest != (void*) source || destBytesPerSample <= 4)
  20284. {
  20285. for (int i = 0; i < numSamples; ++i)
  20286. {
  20287. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20288. intData += destBytesPerSample;
  20289. }
  20290. }
  20291. else
  20292. {
  20293. intData += destBytesPerSample * numSamples;
  20294. for (int i = numSamples; --i >= 0;)
  20295. {
  20296. intData -= destBytesPerSample;
  20297. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20298. }
  20299. }
  20300. }
  20301. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20302. {
  20303. const double maxVal = (double) 0x7fffff;
  20304. char* intData = (char*) dest;
  20305. if (dest != (void*) source || destBytesPerSample <= 4)
  20306. {
  20307. for (int i = 0; i < numSamples; ++i)
  20308. {
  20309. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20310. intData += destBytesPerSample;
  20311. }
  20312. }
  20313. else
  20314. {
  20315. intData += destBytesPerSample * numSamples;
  20316. for (int i = numSamples; --i >= 0;)
  20317. {
  20318. intData -= destBytesPerSample;
  20319. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20320. }
  20321. }
  20322. }
  20323. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20324. {
  20325. const double maxVal = (double) 0x7fffffff;
  20326. char* intData = (char*) dest;
  20327. if (dest != (void*) source || destBytesPerSample <= 4)
  20328. {
  20329. for (int i = 0; i < numSamples; ++i)
  20330. {
  20331. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20332. intData += destBytesPerSample;
  20333. }
  20334. }
  20335. else
  20336. {
  20337. intData += destBytesPerSample * numSamples;
  20338. for (int i = numSamples; --i >= 0;)
  20339. {
  20340. intData -= destBytesPerSample;
  20341. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20342. }
  20343. }
  20344. }
  20345. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20346. {
  20347. const double maxVal = (double) 0x7fffffff;
  20348. char* intData = (char*) dest;
  20349. if (dest != (void*) source || destBytesPerSample <= 4)
  20350. {
  20351. for (int i = 0; i < numSamples; ++i)
  20352. {
  20353. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20354. intData += destBytesPerSample;
  20355. }
  20356. }
  20357. else
  20358. {
  20359. intData += destBytesPerSample * numSamples;
  20360. for (int i = numSamples; --i >= 0;)
  20361. {
  20362. intData -= destBytesPerSample;
  20363. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20364. }
  20365. }
  20366. }
  20367. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20368. {
  20369. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20370. char* d = (char*) dest;
  20371. for (int i = 0; i < numSamples; ++i)
  20372. {
  20373. *(float*) d = source[i];
  20374. #if JUCE_BIG_ENDIAN
  20375. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20376. #endif
  20377. d += destBytesPerSample;
  20378. }
  20379. }
  20380. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20381. {
  20382. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20383. char* d = (char*) dest;
  20384. for (int i = 0; i < numSamples; ++i)
  20385. {
  20386. *(float*) d = source[i];
  20387. #if JUCE_LITTLE_ENDIAN
  20388. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20389. #endif
  20390. d += destBytesPerSample;
  20391. }
  20392. }
  20393. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20394. {
  20395. const float scale = 1.0f / 0x7fff;
  20396. const char* intData = (const char*) source;
  20397. if (source != (void*) dest || srcBytesPerSample >= 4)
  20398. {
  20399. for (int i = 0; i < numSamples; ++i)
  20400. {
  20401. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20402. intData += srcBytesPerSample;
  20403. }
  20404. }
  20405. else
  20406. {
  20407. intData += srcBytesPerSample * numSamples;
  20408. for (int i = numSamples; --i >= 0;)
  20409. {
  20410. intData -= srcBytesPerSample;
  20411. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20412. }
  20413. }
  20414. }
  20415. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20416. {
  20417. const float scale = 1.0f / 0x7fff;
  20418. const char* intData = (const char*) source;
  20419. if (source != (void*) dest || srcBytesPerSample >= 4)
  20420. {
  20421. for (int i = 0; i < numSamples; ++i)
  20422. {
  20423. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20424. intData += srcBytesPerSample;
  20425. }
  20426. }
  20427. else
  20428. {
  20429. intData += srcBytesPerSample * numSamples;
  20430. for (int i = numSamples; --i >= 0;)
  20431. {
  20432. intData -= srcBytesPerSample;
  20433. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20434. }
  20435. }
  20436. }
  20437. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20438. {
  20439. const float scale = 1.0f / 0x7fffff;
  20440. const char* intData = (const char*) source;
  20441. if (source != (void*) dest || srcBytesPerSample >= 4)
  20442. {
  20443. for (int i = 0; i < numSamples; ++i)
  20444. {
  20445. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20446. intData += srcBytesPerSample;
  20447. }
  20448. }
  20449. else
  20450. {
  20451. intData += srcBytesPerSample * numSamples;
  20452. for (int i = numSamples; --i >= 0;)
  20453. {
  20454. intData -= srcBytesPerSample;
  20455. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20456. }
  20457. }
  20458. }
  20459. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20460. {
  20461. const float scale = 1.0f / 0x7fffff;
  20462. const char* intData = (const char*) source;
  20463. if (source != (void*) dest || srcBytesPerSample >= 4)
  20464. {
  20465. for (int i = 0; i < numSamples; ++i)
  20466. {
  20467. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20468. intData += srcBytesPerSample;
  20469. }
  20470. }
  20471. else
  20472. {
  20473. intData += srcBytesPerSample * numSamples;
  20474. for (int i = numSamples; --i >= 0;)
  20475. {
  20476. intData -= srcBytesPerSample;
  20477. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20478. }
  20479. }
  20480. }
  20481. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20482. {
  20483. const float scale = 1.0f / 0x7fffffff;
  20484. const char* intData = (const char*) source;
  20485. if (source != (void*) dest || srcBytesPerSample >= 4)
  20486. {
  20487. for (int i = 0; i < numSamples; ++i)
  20488. {
  20489. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20490. intData += srcBytesPerSample;
  20491. }
  20492. }
  20493. else
  20494. {
  20495. intData += srcBytesPerSample * numSamples;
  20496. for (int i = numSamples; --i >= 0;)
  20497. {
  20498. intData -= srcBytesPerSample;
  20499. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20500. }
  20501. }
  20502. }
  20503. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20504. {
  20505. const float scale = 1.0f / 0x7fffffff;
  20506. const char* intData = (const char*) source;
  20507. if (source != (void*) dest || srcBytesPerSample >= 4)
  20508. {
  20509. for (int i = 0; i < numSamples; ++i)
  20510. {
  20511. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20512. intData += srcBytesPerSample;
  20513. }
  20514. }
  20515. else
  20516. {
  20517. intData += srcBytesPerSample * numSamples;
  20518. for (int i = numSamples; --i >= 0;)
  20519. {
  20520. intData -= srcBytesPerSample;
  20521. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20522. }
  20523. }
  20524. }
  20525. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20526. {
  20527. const char* s = (const char*) source;
  20528. for (int i = 0; i < numSamples; ++i)
  20529. {
  20530. dest[i] = *(float*)s;
  20531. #if JUCE_BIG_ENDIAN
  20532. uint32* const d = (uint32*) (dest + i);
  20533. *d = ByteOrder::swap (*d);
  20534. #endif
  20535. s += srcBytesPerSample;
  20536. }
  20537. }
  20538. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20539. {
  20540. const char* s = (const char*) source;
  20541. for (int i = 0; i < numSamples; ++i)
  20542. {
  20543. dest[i] = *(float*)s;
  20544. #if JUCE_LITTLE_ENDIAN
  20545. uint32* const d = (uint32*) (dest + i);
  20546. *d = ByteOrder::swap (*d);
  20547. #endif
  20548. s += srcBytesPerSample;
  20549. }
  20550. }
  20551. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20552. const float* const source,
  20553. void* const dest,
  20554. const int numSamples)
  20555. {
  20556. switch (destFormat)
  20557. {
  20558. case int16LE:
  20559. convertFloatToInt16LE (source, dest, numSamples);
  20560. break;
  20561. case int16BE:
  20562. convertFloatToInt16BE (source, dest, numSamples);
  20563. break;
  20564. case int24LE:
  20565. convertFloatToInt24LE (source, dest, numSamples);
  20566. break;
  20567. case int24BE:
  20568. convertFloatToInt24BE (source, dest, numSamples);
  20569. break;
  20570. case int32LE:
  20571. convertFloatToInt32LE (source, dest, numSamples);
  20572. break;
  20573. case int32BE:
  20574. convertFloatToInt32BE (source, dest, numSamples);
  20575. break;
  20576. case float32LE:
  20577. convertFloatToFloat32LE (source, dest, numSamples);
  20578. break;
  20579. case float32BE:
  20580. convertFloatToFloat32BE (source, dest, numSamples);
  20581. break;
  20582. default:
  20583. jassertfalse
  20584. break;
  20585. }
  20586. }
  20587. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20588. const void* const source,
  20589. float* const dest,
  20590. const int numSamples)
  20591. {
  20592. switch (sourceFormat)
  20593. {
  20594. case int16LE:
  20595. convertInt16LEToFloat (source, dest, numSamples);
  20596. break;
  20597. case int16BE:
  20598. convertInt16BEToFloat (source, dest, numSamples);
  20599. break;
  20600. case int24LE:
  20601. convertInt24LEToFloat (source, dest, numSamples);
  20602. break;
  20603. case int24BE:
  20604. convertInt24BEToFloat (source, dest, numSamples);
  20605. break;
  20606. case int32LE:
  20607. convertInt32LEToFloat (source, dest, numSamples);
  20608. break;
  20609. case int32BE:
  20610. convertInt32BEToFloat (source, dest, numSamples);
  20611. break;
  20612. case float32LE:
  20613. convertFloat32LEToFloat (source, dest, numSamples);
  20614. break;
  20615. case float32BE:
  20616. convertFloat32BEToFloat (source, dest, numSamples);
  20617. break;
  20618. default:
  20619. jassertfalse
  20620. break;
  20621. }
  20622. }
  20623. void AudioDataConverters::interleaveSamples (const float** const source,
  20624. float* const dest,
  20625. const int numSamples,
  20626. const int numChannels)
  20627. {
  20628. for (int chan = 0; chan < numChannels; ++chan)
  20629. {
  20630. int i = chan;
  20631. const float* src = source [chan];
  20632. for (int j = 0; j < numSamples; ++j)
  20633. {
  20634. dest [i] = src [j];
  20635. i += numChannels;
  20636. }
  20637. }
  20638. }
  20639. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20640. float** const dest,
  20641. const int numSamples,
  20642. const int numChannels)
  20643. {
  20644. for (int chan = 0; chan < numChannels; ++chan)
  20645. {
  20646. int i = chan;
  20647. float* dst = dest [chan];
  20648. for (int j = 0; j < numSamples; ++j)
  20649. {
  20650. dst [j] = source [i];
  20651. i += numChannels;
  20652. }
  20653. }
  20654. }
  20655. END_JUCE_NAMESPACE
  20656. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20657. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20658. BEGIN_JUCE_NAMESPACE
  20659. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20660. const int numSamples) throw()
  20661. : numChannels (numChannels_),
  20662. size (numSamples)
  20663. {
  20664. jassert (numSamples >= 0);
  20665. jassert (numChannels_ > 0);
  20666. allocateData();
  20667. }
  20668. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20669. : numChannels (other.numChannels),
  20670. size (other.size)
  20671. {
  20672. allocateData();
  20673. const size_t numBytes = size * sizeof (float);
  20674. for (int i = 0; i < numChannels; ++i)
  20675. memcpy (channels[i], other.channels[i], numBytes);
  20676. }
  20677. void AudioSampleBuffer::allocateData()
  20678. {
  20679. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20680. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20681. allocatedData.malloc (allocatedBytes);
  20682. channels = (float**) allocatedData;
  20683. float* chan = (float*) (allocatedData + channelListSize);
  20684. for (int i = 0; i < numChannels; ++i)
  20685. {
  20686. channels[i] = chan;
  20687. chan += size;
  20688. }
  20689. channels [numChannels] = 0;
  20690. }
  20691. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20692. const int numChannels_,
  20693. const int numSamples) throw()
  20694. : numChannels (numChannels_),
  20695. size (numSamples),
  20696. allocatedBytes (0)
  20697. {
  20698. jassert (numChannels_ > 0);
  20699. allocateChannels (dataToReferTo);
  20700. }
  20701. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20702. const int newNumChannels,
  20703. const int newNumSamples) throw()
  20704. {
  20705. jassert (newNumChannels > 0);
  20706. allocatedBytes = 0;
  20707. allocatedData.free();
  20708. numChannels = newNumChannels;
  20709. size = newNumSamples;
  20710. allocateChannels (dataToReferTo);
  20711. }
  20712. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20713. {
  20714. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20715. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20716. {
  20717. channels = (float**) preallocatedChannelSpace;
  20718. }
  20719. else
  20720. {
  20721. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20722. channels = (float**) allocatedData;
  20723. }
  20724. for (int i = 0; i < numChannels; ++i)
  20725. {
  20726. // you have to pass in the same number of valid pointers as numChannels
  20727. jassert (dataToReferTo[i] != 0);
  20728. channels[i] = dataToReferTo[i];
  20729. }
  20730. channels [numChannels] = 0;
  20731. }
  20732. const AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20733. {
  20734. if (this != &other)
  20735. {
  20736. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20737. const size_t numBytes = size * sizeof (float);
  20738. for (int i = 0; i < numChannels; ++i)
  20739. memcpy (channels[i], other.channels[i], numBytes);
  20740. }
  20741. return *this;
  20742. }
  20743. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20744. {
  20745. }
  20746. void AudioSampleBuffer::setSize (const int newNumChannels,
  20747. const int newNumSamples,
  20748. const bool keepExistingContent,
  20749. const bool clearExtraSpace,
  20750. const bool avoidReallocating) throw()
  20751. {
  20752. jassert (newNumChannels > 0);
  20753. if (newNumSamples != size || newNumChannels != numChannels)
  20754. {
  20755. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20756. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20757. if (keepExistingContent)
  20758. {
  20759. HeapBlock <char> newData;
  20760. newData.allocate (newTotalBytes, clearExtraSpace);
  20761. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20762. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20763. float** const newChannels = (float**) newData;
  20764. float* newChan = (float*) (newData + channelListSize);
  20765. for (int i = 0; i < numChansToCopy; ++i)
  20766. {
  20767. memcpy (newChan, channels[i], numBytesToCopy);
  20768. newChannels[i] = newChan;
  20769. newChan += newNumSamples;
  20770. }
  20771. allocatedData.swapWith (newData);
  20772. allocatedBytes = (int) newTotalBytes;
  20773. channels = (float**) allocatedData;
  20774. }
  20775. else
  20776. {
  20777. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20778. {
  20779. if (clearExtraSpace)
  20780. zeromem (allocatedData, newTotalBytes);
  20781. }
  20782. else
  20783. {
  20784. allocatedBytes = newTotalBytes;
  20785. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20786. channels = (float**) allocatedData;
  20787. }
  20788. float* chan = (float*) (allocatedData + channelListSize);
  20789. for (int i = 0; i < newNumChannels; ++i)
  20790. {
  20791. channels[i] = chan;
  20792. chan += newNumSamples;
  20793. }
  20794. }
  20795. channels [newNumChannels] = 0;
  20796. size = newNumSamples;
  20797. numChannels = newNumChannels;
  20798. }
  20799. }
  20800. void AudioSampleBuffer::clear() throw()
  20801. {
  20802. for (int i = 0; i < numChannels; ++i)
  20803. zeromem (channels[i], size * sizeof (float));
  20804. }
  20805. void AudioSampleBuffer::clear (const int startSample,
  20806. const int numSamples) throw()
  20807. {
  20808. jassert (startSample >= 0 && startSample + numSamples <= size);
  20809. for (int i = 0; i < numChannels; ++i)
  20810. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20811. }
  20812. void AudioSampleBuffer::clear (const int channel,
  20813. const int startSample,
  20814. const int numSamples) throw()
  20815. {
  20816. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20817. jassert (startSample >= 0 && startSample + numSamples <= size);
  20818. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20819. }
  20820. void AudioSampleBuffer::applyGain (const int channel,
  20821. const int startSample,
  20822. int numSamples,
  20823. const float gain) throw()
  20824. {
  20825. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20826. jassert (startSample >= 0 && startSample + numSamples <= size);
  20827. if (gain != 1.0f)
  20828. {
  20829. float* d = channels [channel] + startSample;
  20830. if (gain == 0.0f)
  20831. {
  20832. zeromem (d, sizeof (float) * numSamples);
  20833. }
  20834. else
  20835. {
  20836. while (--numSamples >= 0)
  20837. *d++ *= gain;
  20838. }
  20839. }
  20840. }
  20841. void AudioSampleBuffer::applyGainRamp (const int channel,
  20842. const int startSample,
  20843. int numSamples,
  20844. float startGain,
  20845. float endGain) throw()
  20846. {
  20847. if (startGain == endGain)
  20848. {
  20849. applyGain (channel, startSample, numSamples, startGain);
  20850. }
  20851. else
  20852. {
  20853. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20854. jassert (startSample >= 0 && startSample + numSamples <= size);
  20855. const float increment = (endGain - startGain) / numSamples;
  20856. float* d = channels [channel] + startSample;
  20857. while (--numSamples >= 0)
  20858. {
  20859. *d++ *= startGain;
  20860. startGain += increment;
  20861. }
  20862. }
  20863. }
  20864. void AudioSampleBuffer::applyGain (const int startSample,
  20865. const int numSamples,
  20866. const float gain) throw()
  20867. {
  20868. for (int i = 0; i < numChannels; ++i)
  20869. applyGain (i, startSample, numSamples, gain);
  20870. }
  20871. void AudioSampleBuffer::addFrom (const int destChannel,
  20872. const int destStartSample,
  20873. const AudioSampleBuffer& source,
  20874. const int sourceChannel,
  20875. const int sourceStartSample,
  20876. int numSamples,
  20877. const float gain) throw()
  20878. {
  20879. jassert (&source != this || sourceChannel != destChannel);
  20880. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20881. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20882. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20883. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20884. if (gain != 0.0f && numSamples > 0)
  20885. {
  20886. float* d = channels [destChannel] + destStartSample;
  20887. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20888. if (gain != 1.0f)
  20889. {
  20890. while (--numSamples >= 0)
  20891. *d++ += gain * *s++;
  20892. }
  20893. else
  20894. {
  20895. while (--numSamples >= 0)
  20896. *d++ += *s++;
  20897. }
  20898. }
  20899. }
  20900. void AudioSampleBuffer::addFrom (const int destChannel,
  20901. const int destStartSample,
  20902. const float* source,
  20903. int numSamples,
  20904. const float gain) throw()
  20905. {
  20906. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20907. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20908. jassert (source != 0);
  20909. if (gain != 0.0f && numSamples > 0)
  20910. {
  20911. float* d = channels [destChannel] + destStartSample;
  20912. if (gain != 1.0f)
  20913. {
  20914. while (--numSamples >= 0)
  20915. *d++ += gain * *source++;
  20916. }
  20917. else
  20918. {
  20919. while (--numSamples >= 0)
  20920. *d++ += *source++;
  20921. }
  20922. }
  20923. }
  20924. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20925. const int destStartSample,
  20926. const float* source,
  20927. int numSamples,
  20928. float startGain,
  20929. const float endGain) throw()
  20930. {
  20931. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20932. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20933. jassert (source != 0);
  20934. if (startGain == endGain)
  20935. {
  20936. addFrom (destChannel,
  20937. destStartSample,
  20938. source,
  20939. numSamples,
  20940. startGain);
  20941. }
  20942. else
  20943. {
  20944. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20945. {
  20946. const float increment = (endGain - startGain) / numSamples;
  20947. float* d = channels [destChannel] + destStartSample;
  20948. while (--numSamples >= 0)
  20949. {
  20950. *d++ += startGain * *source++;
  20951. startGain += increment;
  20952. }
  20953. }
  20954. }
  20955. }
  20956. void AudioSampleBuffer::copyFrom (const int destChannel,
  20957. const int destStartSample,
  20958. const AudioSampleBuffer& source,
  20959. const int sourceChannel,
  20960. const int sourceStartSample,
  20961. int numSamples) throw()
  20962. {
  20963. jassert (&source != this || sourceChannel != destChannel);
  20964. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20965. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20966. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20967. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20968. if (numSamples > 0)
  20969. {
  20970. memcpy (channels [destChannel] + destStartSample,
  20971. source.channels [sourceChannel] + sourceStartSample,
  20972. sizeof (float) * numSamples);
  20973. }
  20974. }
  20975. void AudioSampleBuffer::copyFrom (const int destChannel,
  20976. const int destStartSample,
  20977. const float* source,
  20978. int numSamples) throw()
  20979. {
  20980. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20981. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20982. jassert (source != 0);
  20983. if (numSamples > 0)
  20984. {
  20985. memcpy (channels [destChannel] + destStartSample,
  20986. source,
  20987. sizeof (float) * numSamples);
  20988. }
  20989. }
  20990. void AudioSampleBuffer::copyFrom (const int destChannel,
  20991. const int destStartSample,
  20992. const float* source,
  20993. int numSamples,
  20994. const float gain) throw()
  20995. {
  20996. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20997. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20998. jassert (source != 0);
  20999. if (numSamples > 0)
  21000. {
  21001. float* d = channels [destChannel] + destStartSample;
  21002. if (gain != 1.0f)
  21003. {
  21004. if (gain == 0)
  21005. {
  21006. zeromem (d, sizeof (float) * numSamples);
  21007. }
  21008. else
  21009. {
  21010. while (--numSamples >= 0)
  21011. *d++ = gain * *source++;
  21012. }
  21013. }
  21014. else
  21015. {
  21016. memcpy (d, source, sizeof (float) * numSamples);
  21017. }
  21018. }
  21019. }
  21020. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  21021. const int destStartSample,
  21022. const float* source,
  21023. int numSamples,
  21024. float startGain,
  21025. float endGain) throw()
  21026. {
  21027. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21028. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21029. jassert (source != 0);
  21030. if (startGain == endGain)
  21031. {
  21032. copyFrom (destChannel,
  21033. destStartSample,
  21034. source,
  21035. numSamples,
  21036. startGain);
  21037. }
  21038. else
  21039. {
  21040. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  21041. {
  21042. const float increment = (endGain - startGain) / numSamples;
  21043. float* d = channels [destChannel] + destStartSample;
  21044. while (--numSamples >= 0)
  21045. {
  21046. *d++ = startGain * *source++;
  21047. startGain += increment;
  21048. }
  21049. }
  21050. }
  21051. }
  21052. void AudioSampleBuffer::findMinMax (const int channel,
  21053. const int startSample,
  21054. int numSamples,
  21055. float& minVal,
  21056. float& maxVal) const throw()
  21057. {
  21058. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21059. jassert (startSample >= 0 && startSample + numSamples <= size);
  21060. if (numSamples <= 0)
  21061. {
  21062. minVal = 0.0f;
  21063. maxVal = 0.0f;
  21064. }
  21065. else
  21066. {
  21067. const float* d = channels [channel] + startSample;
  21068. float mn = *d++;
  21069. float mx = mn;
  21070. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21071. {
  21072. const float samp = *d++;
  21073. if (samp > mx)
  21074. mx = samp;
  21075. if (samp < mn)
  21076. mn = samp;
  21077. }
  21078. maxVal = mx;
  21079. minVal = mn;
  21080. }
  21081. }
  21082. float AudioSampleBuffer::getMagnitude (const int channel,
  21083. const int startSample,
  21084. const int numSamples) const throw()
  21085. {
  21086. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21087. jassert (startSample >= 0 && startSample + numSamples <= size);
  21088. float mn, mx;
  21089. findMinMax (channel, startSample, numSamples, mn, mx);
  21090. return jmax (mn, -mn, mx, -mx);
  21091. }
  21092. float AudioSampleBuffer::getMagnitude (const int startSample,
  21093. const int numSamples) const throw()
  21094. {
  21095. float mag = 0.0f;
  21096. for (int i = 0; i < numChannels; ++i)
  21097. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21098. return mag;
  21099. }
  21100. float AudioSampleBuffer::getRMSLevel (const int channel,
  21101. const int startSample,
  21102. const int numSamples) const throw()
  21103. {
  21104. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21105. jassert (startSample >= 0 && startSample + numSamples <= size);
  21106. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21107. return 0.0f;
  21108. const float* const data = channels [channel] + startSample;
  21109. double sum = 0.0;
  21110. for (int i = 0; i < numSamples; ++i)
  21111. {
  21112. const float sample = data [i];
  21113. sum += sample * sample;
  21114. }
  21115. return (float) sqrt (sum / numSamples);
  21116. }
  21117. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21118. const int startSample,
  21119. const int numSamples,
  21120. const int readerStartSample,
  21121. const bool useLeftChan,
  21122. const bool useRightChan) throw()
  21123. {
  21124. jassert (reader != 0);
  21125. jassert (startSample >= 0 && startSample + numSamples <= size);
  21126. if (numSamples > 0)
  21127. {
  21128. int* chans[3];
  21129. if (useLeftChan == useRightChan)
  21130. {
  21131. chans[0] = (int*) getSampleData (0, startSample);
  21132. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21133. }
  21134. else if (useLeftChan || (reader->numChannels == 1))
  21135. {
  21136. chans[0] = (int*) getSampleData (0, startSample);
  21137. chans[1] = 0;
  21138. }
  21139. else if (useRightChan)
  21140. {
  21141. chans[0] = 0;
  21142. chans[1] = (int*) getSampleData (0, startSample);
  21143. }
  21144. chans[2] = 0;
  21145. reader->read (chans, 2, readerStartSample, numSamples, true);
  21146. if (! reader->usesFloatingPointData)
  21147. {
  21148. for (int j = 0; j < 2; ++j)
  21149. {
  21150. float* const d = (float*) (chans[j]);
  21151. if (d != 0)
  21152. {
  21153. const float multiplier = 1.0f / 0x7fffffff;
  21154. for (int i = 0; i < numSamples; ++i)
  21155. d[i] = *(int*)(d + i) * multiplier;
  21156. }
  21157. }
  21158. }
  21159. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21160. {
  21161. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21162. memcpy (getSampleData (1, startSample),
  21163. getSampleData (0, startSample),
  21164. sizeof (float) * numSamples);
  21165. }
  21166. }
  21167. }
  21168. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21169. const int startSample,
  21170. const int numSamples) const throw()
  21171. {
  21172. jassert (startSample >= 0 && startSample + numSamples <= size);
  21173. if (numSamples > 0)
  21174. {
  21175. int* chans [3];
  21176. if (writer->isFloatingPoint())
  21177. {
  21178. chans[0] = (int*) getSampleData (0, startSample);
  21179. if (numChannels > 1)
  21180. chans[1] = (int*) getSampleData (1, startSample);
  21181. else
  21182. chans[1] = 0;
  21183. chans[2] = 0;
  21184. writer->write ((const int**) chans, numSamples);
  21185. }
  21186. else
  21187. {
  21188. HeapBlock <int> tempBuffer (numSamples * 2);
  21189. chans[0] = tempBuffer;
  21190. if (numChannels > 1)
  21191. chans[1] = chans[0] + numSamples;
  21192. else
  21193. chans[1] = 0;
  21194. chans[2] = 0;
  21195. for (int j = 0; j < 2; ++j)
  21196. {
  21197. int* const dest = chans[j];
  21198. if (dest != 0)
  21199. {
  21200. const float* const src = channels [j] + startSample;
  21201. for (int i = 0; i < numSamples; ++i)
  21202. {
  21203. const double samp = src[i];
  21204. if (samp <= -1.0)
  21205. dest[i] = std::numeric_limits<int>::min();
  21206. else if (samp >= 1.0)
  21207. dest[i] = std::numeric_limits<int>::max();
  21208. else
  21209. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21210. }
  21211. }
  21212. }
  21213. writer->write ((const int**) chans, numSamples);
  21214. }
  21215. }
  21216. }
  21217. END_JUCE_NAMESPACE
  21218. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21219. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21220. BEGIN_JUCE_NAMESPACE
  21221. IIRFilter::IIRFilter() throw()
  21222. : active (false)
  21223. {
  21224. reset();
  21225. }
  21226. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21227. : active (other.active)
  21228. {
  21229. const ScopedLock sl (other.processLock);
  21230. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21231. reset();
  21232. }
  21233. IIRFilter::~IIRFilter() throw()
  21234. {
  21235. }
  21236. void IIRFilter::reset() throw()
  21237. {
  21238. const ScopedLock sl (processLock);
  21239. x1 = 0;
  21240. x2 = 0;
  21241. y1 = 0;
  21242. y2 = 0;
  21243. }
  21244. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21245. {
  21246. float out = coefficients[0] * in
  21247. + coefficients[1] * x1
  21248. + coefficients[2] * x2
  21249. - coefficients[4] * y1
  21250. - coefficients[5] * y2;
  21251. #if JUCE_INTEL
  21252. if (! (out < -1.0e-8 || out > 1.0e-8))
  21253. out = 0;
  21254. #endif
  21255. x2 = x1;
  21256. x1 = in;
  21257. y2 = y1;
  21258. y1 = out;
  21259. return out;
  21260. }
  21261. void IIRFilter::processSamples (float* const samples,
  21262. const int numSamples) throw()
  21263. {
  21264. const ScopedLock sl (processLock);
  21265. if (active)
  21266. {
  21267. for (int i = 0; i < numSamples; ++i)
  21268. {
  21269. const float in = samples[i];
  21270. float out = coefficients[0] * in
  21271. + coefficients[1] * x1
  21272. + coefficients[2] * x2
  21273. - coefficients[4] * y1
  21274. - coefficients[5] * y2;
  21275. #if JUCE_INTEL
  21276. if (! (out < -1.0e-8 || out > 1.0e-8))
  21277. out = 0;
  21278. #endif
  21279. x2 = x1;
  21280. x1 = in;
  21281. y2 = y1;
  21282. y1 = out;
  21283. samples[i] = out;
  21284. }
  21285. }
  21286. }
  21287. void IIRFilter::makeLowPass (const double sampleRate,
  21288. const double frequency) throw()
  21289. {
  21290. jassert (sampleRate > 0);
  21291. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21292. const double nSquared = n * n;
  21293. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21294. setCoefficients (c1,
  21295. c1 * 2.0f,
  21296. c1,
  21297. 1.0,
  21298. c1 * 2.0 * (1.0 - nSquared),
  21299. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21300. }
  21301. void IIRFilter::makeHighPass (const double sampleRate,
  21302. const double frequency) throw()
  21303. {
  21304. const double n = tan (double_Pi * frequency / sampleRate);
  21305. const double nSquared = n * n;
  21306. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21307. setCoefficients (c1,
  21308. c1 * -2.0f,
  21309. c1,
  21310. 1.0,
  21311. c1 * 2.0 * (nSquared - 1.0),
  21312. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21313. }
  21314. void IIRFilter::makeLowShelf (const double sampleRate,
  21315. const double cutOffFrequency,
  21316. const double Q,
  21317. const float gainFactor) throw()
  21318. {
  21319. jassert (sampleRate > 0);
  21320. jassert (Q > 0);
  21321. const double A = jmax (0.0f, gainFactor);
  21322. const double aminus1 = A - 1.0;
  21323. const double aplus1 = A + 1.0;
  21324. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21325. const double coso = cos (omega);
  21326. const double beta = sin (omega) * sqrt (A) / Q;
  21327. const double aminus1TimesCoso = aminus1 * coso;
  21328. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21329. A * 2.0 * (aminus1 - aplus1 * coso),
  21330. A * (aplus1 - aminus1TimesCoso - beta),
  21331. aplus1 + aminus1TimesCoso + beta,
  21332. -2.0 * (aminus1 + aplus1 * coso),
  21333. aplus1 + aminus1TimesCoso - beta);
  21334. }
  21335. void IIRFilter::makeHighShelf (const double sampleRate,
  21336. const double cutOffFrequency,
  21337. const double Q,
  21338. const float gainFactor) throw()
  21339. {
  21340. jassert (sampleRate > 0);
  21341. jassert (Q > 0);
  21342. const double A = jmax (0.0f, gainFactor);
  21343. const double aminus1 = A - 1.0;
  21344. const double aplus1 = A + 1.0;
  21345. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21346. const double coso = cos (omega);
  21347. const double beta = sin (omega) * sqrt (A) / Q;
  21348. const double aminus1TimesCoso = aminus1 * coso;
  21349. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21350. A * -2.0 * (aminus1 + aplus1 * coso),
  21351. A * (aplus1 + aminus1TimesCoso - beta),
  21352. aplus1 - aminus1TimesCoso + beta,
  21353. 2.0 * (aminus1 - aplus1 * coso),
  21354. aplus1 - aminus1TimesCoso - beta);
  21355. }
  21356. void IIRFilter::makeBandPass (const double sampleRate,
  21357. const double centreFrequency,
  21358. const double Q,
  21359. const float gainFactor) throw()
  21360. {
  21361. jassert (sampleRate > 0);
  21362. jassert (Q > 0);
  21363. const double A = jmax (0.0f, gainFactor);
  21364. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21365. const double alpha = 0.5 * sin (omega) / Q;
  21366. const double c2 = -2.0 * cos (omega);
  21367. const double alphaTimesA = alpha * A;
  21368. const double alphaOverA = alpha / A;
  21369. setCoefficients (1.0 + alphaTimesA,
  21370. c2,
  21371. 1.0 - alphaTimesA,
  21372. 1.0 + alphaOverA,
  21373. c2,
  21374. 1.0 - alphaOverA);
  21375. }
  21376. void IIRFilter::makeInactive() throw()
  21377. {
  21378. const ScopedLock sl (processLock);
  21379. active = false;
  21380. }
  21381. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21382. {
  21383. const ScopedLock sl (processLock);
  21384. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21385. active = other.active;
  21386. }
  21387. void IIRFilter::setCoefficients (double c1,
  21388. double c2,
  21389. double c3,
  21390. double c4,
  21391. double c5,
  21392. double c6) throw()
  21393. {
  21394. const double a = 1.0 / c4;
  21395. c1 *= a;
  21396. c2 *= a;
  21397. c3 *= a;
  21398. c5 *= a;
  21399. c6 *= a;
  21400. const ScopedLock sl (processLock);
  21401. coefficients[0] = (float) c1;
  21402. coefficients[1] = (float) c2;
  21403. coefficients[2] = (float) c3;
  21404. coefficients[3] = (float) c4;
  21405. coefficients[4] = (float) c5;
  21406. coefficients[5] = (float) c6;
  21407. active = true;
  21408. }
  21409. END_JUCE_NAMESPACE
  21410. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21411. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21412. BEGIN_JUCE_NAMESPACE
  21413. MidiBuffer::MidiBuffer() throw()
  21414. : bytesUsed (0)
  21415. {
  21416. }
  21417. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21418. : bytesUsed (0)
  21419. {
  21420. addEvent (message, 0);
  21421. }
  21422. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21423. : data (other.data),
  21424. bytesUsed (other.bytesUsed)
  21425. {
  21426. }
  21427. const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21428. {
  21429. bytesUsed = other.bytesUsed;
  21430. data = other.data;
  21431. return *this;
  21432. }
  21433. void MidiBuffer::swap (MidiBuffer& other)
  21434. {
  21435. data.swapWith (other.data);
  21436. swapVariables <int> (bytesUsed, other.bytesUsed);
  21437. }
  21438. MidiBuffer::~MidiBuffer() throw()
  21439. {
  21440. }
  21441. void MidiBuffer::clear() throw()
  21442. {
  21443. bytesUsed = 0;
  21444. }
  21445. void MidiBuffer::clear (const int startSample,
  21446. const int numSamples) throw()
  21447. {
  21448. uint8* const start = findEventAfter (data, startSample - 1);
  21449. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21450. if (end > start)
  21451. {
  21452. const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData()));
  21453. if (bytesToMove > 0)
  21454. memmove (start, end, bytesToMove);
  21455. bytesUsed -= (int) (end - start);
  21456. }
  21457. }
  21458. void MidiBuffer::addEvent (const MidiMessage& m,
  21459. const int sampleNumber) throw()
  21460. {
  21461. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21462. }
  21463. static int findActualEventLength (const uint8* const data,
  21464. const int maxBytes) throw()
  21465. {
  21466. unsigned int byte = (unsigned int) *data;
  21467. int size = 0;
  21468. if (byte == 0xf0 || byte == 0xf7)
  21469. {
  21470. const uint8* d = data + 1;
  21471. while (d < data + maxBytes)
  21472. if (*d++ == 0xf7)
  21473. break;
  21474. size = (int) (d - data);
  21475. }
  21476. else if (byte == 0xff)
  21477. {
  21478. int n;
  21479. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21480. size = jmin (maxBytes, n + 2 + bytesLeft);
  21481. }
  21482. else if (byte >= 0x80)
  21483. {
  21484. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21485. }
  21486. return size;
  21487. }
  21488. void MidiBuffer::addEvent (const uint8* const newData,
  21489. const int maxBytes,
  21490. const int sampleNumber) throw()
  21491. {
  21492. const int numBytes = findActualEventLength (newData, maxBytes);
  21493. if (numBytes > 0)
  21494. {
  21495. int spaceNeeded = bytesUsed + numBytes + 6;
  21496. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21497. uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber);
  21498. const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData()));
  21499. if (bytesToMove > 0)
  21500. memmove (d + numBytes + 6,
  21501. d,
  21502. bytesToMove);
  21503. *(int*) d = sampleNumber;
  21504. d += 4;
  21505. *(uint16*) d = (uint16) numBytes;
  21506. d += 2;
  21507. memcpy (d, newData, numBytes);
  21508. bytesUsed += numBytes + 6;
  21509. }
  21510. }
  21511. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21512. const int startSample,
  21513. const int numSamples,
  21514. const int sampleDeltaToAdd) throw()
  21515. {
  21516. Iterator i (otherBuffer);
  21517. i.setNextSamplePosition (startSample);
  21518. const uint8* eventData;
  21519. int eventSize, position;
  21520. while (i.getNextEvent (eventData, eventSize, position)
  21521. && (position < startSample + numSamples || numSamples < 0))
  21522. {
  21523. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21524. }
  21525. }
  21526. bool MidiBuffer::isEmpty() const throw()
  21527. {
  21528. return bytesUsed == 0;
  21529. }
  21530. int MidiBuffer::getNumEvents() const throw()
  21531. {
  21532. int n = 0;
  21533. const uint8* d = (uint8*) data.getData();
  21534. const uint8* const end = d + bytesUsed;
  21535. while (d < end)
  21536. {
  21537. d += 4;
  21538. d += 2 + *(const uint16*) d;
  21539. ++n;
  21540. }
  21541. return n;
  21542. }
  21543. int MidiBuffer::getFirstEventTime() const throw()
  21544. {
  21545. return (bytesUsed > 0) ? *(const int*) data.getData() : 0;
  21546. }
  21547. int MidiBuffer::getLastEventTime() const throw()
  21548. {
  21549. if (bytesUsed == 0)
  21550. return 0;
  21551. const uint8* d = (uint8*) data.getData();
  21552. const uint8* const endData = d + bytesUsed;
  21553. for (;;)
  21554. {
  21555. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21556. if (nextOne >= endData)
  21557. return *(const int*) d;
  21558. d = nextOne;
  21559. }
  21560. }
  21561. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21562. {
  21563. const uint8* const endData = ((uint8*) data.getData()) + bytesUsed;
  21564. while (d < endData && *(int*) d <= samplePosition)
  21565. {
  21566. d += 4;
  21567. d += 2 + *(uint16*) d;
  21568. }
  21569. return d;
  21570. }
  21571. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21572. : buffer (buffer_),
  21573. data ((uint8*) buffer_.data.getData())
  21574. {
  21575. }
  21576. MidiBuffer::Iterator::~Iterator() throw()
  21577. {
  21578. }
  21579. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21580. {
  21581. data = buffer.data;
  21582. const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed;
  21583. while (data < dataEnd && *(int*) data < samplePosition)
  21584. {
  21585. data += 4;
  21586. data += 2 + *(uint16*) data;
  21587. }
  21588. }
  21589. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21590. int& numBytes,
  21591. int& samplePosition) throw()
  21592. {
  21593. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21594. return false;
  21595. samplePosition = *(int*) data;
  21596. data += 4;
  21597. numBytes = *(uint16*) data;
  21598. data += 2;
  21599. midiData = data;
  21600. data += numBytes;
  21601. return true;
  21602. }
  21603. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21604. int& samplePosition) throw()
  21605. {
  21606. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21607. return false;
  21608. samplePosition = *(int*) data;
  21609. data += 4;
  21610. const int numBytes = *(uint16*) data;
  21611. data += 2;
  21612. result = MidiMessage (data, numBytes, samplePosition);
  21613. data += numBytes;
  21614. return true;
  21615. }
  21616. END_JUCE_NAMESPACE
  21617. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21618. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21619. BEGIN_JUCE_NAMESPACE
  21620. struct TempoInfo
  21621. {
  21622. double bpm, timestamp;
  21623. };
  21624. struct TimeSigInfo
  21625. {
  21626. int numerator, denominator;
  21627. double timestamp;
  21628. };
  21629. MidiFile::MidiFile() throw()
  21630. : timeFormat ((short) (unsigned short) 0xe728)
  21631. {
  21632. }
  21633. MidiFile::~MidiFile() throw()
  21634. {
  21635. clear();
  21636. }
  21637. void MidiFile::clear() throw()
  21638. {
  21639. tracks.clear();
  21640. }
  21641. int MidiFile::getNumTracks() const throw()
  21642. {
  21643. return tracks.size();
  21644. }
  21645. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21646. {
  21647. return tracks [index];
  21648. }
  21649. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21650. {
  21651. tracks.add (new MidiMessageSequence (trackSequence));
  21652. }
  21653. short MidiFile::getTimeFormat() const throw()
  21654. {
  21655. return timeFormat;
  21656. }
  21657. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21658. {
  21659. timeFormat = (short)ticks;
  21660. }
  21661. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21662. const int subframeResolution) throw()
  21663. {
  21664. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21665. }
  21666. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21667. {
  21668. for (int i = tracks.size(); --i >= 0;)
  21669. {
  21670. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21671. for (int j = 0; j < numEvents; ++j)
  21672. {
  21673. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21674. if (m.isTempoMetaEvent())
  21675. tempoChangeEvents.addEvent (m);
  21676. }
  21677. }
  21678. }
  21679. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21680. {
  21681. for (int i = tracks.size(); --i >= 0;)
  21682. {
  21683. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21684. for (int j = 0; j < numEvents; ++j)
  21685. {
  21686. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21687. if (m.isTimeSignatureMetaEvent())
  21688. timeSigEvents.addEvent (m);
  21689. }
  21690. }
  21691. }
  21692. double MidiFile::getLastTimestamp() const
  21693. {
  21694. double t = 0.0;
  21695. for (int i = tracks.size(); --i >= 0;)
  21696. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21697. return t;
  21698. }
  21699. static bool parseMidiHeader (const char* &data,
  21700. short& timeFormat,
  21701. short& fileType,
  21702. short& numberOfTracks)
  21703. {
  21704. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21705. data += 4;
  21706. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21707. {
  21708. bool ok = false;
  21709. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21710. {
  21711. for (int i = 0; i < 8; ++i)
  21712. {
  21713. ch = ByteOrder::bigEndianInt (data);
  21714. data += 4;
  21715. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21716. {
  21717. ok = true;
  21718. break;
  21719. }
  21720. }
  21721. }
  21722. if (! ok)
  21723. return false;
  21724. }
  21725. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21726. data += 4;
  21727. fileType = (short) ByteOrder::bigEndianShort (data);
  21728. data += 2;
  21729. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21730. data += 2;
  21731. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21732. data += 2;
  21733. bytesRemaining -= 6;
  21734. data += bytesRemaining;
  21735. return true;
  21736. }
  21737. bool MidiFile::readFrom (InputStream& sourceStream)
  21738. {
  21739. clear();
  21740. MemoryBlock data;
  21741. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21742. // (put a sanity-check on the file size, as midi files are generally small)
  21743. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21744. {
  21745. size_t size = data.getSize();
  21746. const char* d = (char*) data.getData();
  21747. short fileType, expectedTracks;
  21748. if (size > 16 && parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21749. {
  21750. size -= (int) (d - (char*) data.getData());
  21751. int track = 0;
  21752. while (size > 0 && track < expectedTracks)
  21753. {
  21754. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21755. d += 4;
  21756. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21757. d += 4;
  21758. if (chunkSize <= 0)
  21759. break;
  21760. if (size < 0)
  21761. return false;
  21762. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21763. {
  21764. readNextTrack (d, chunkSize);
  21765. }
  21766. size -= chunkSize + 8;
  21767. d += chunkSize;
  21768. ++track;
  21769. }
  21770. return true;
  21771. }
  21772. }
  21773. return false;
  21774. }
  21775. // a comparator that puts all the note-offs before note-ons that have the same time
  21776. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21777. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21778. {
  21779. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21780. if (diff == 0)
  21781. {
  21782. if (first->message.isNoteOff() && second->message.isNoteOn())
  21783. return -1;
  21784. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21785. return 1;
  21786. else
  21787. return 0;
  21788. }
  21789. else
  21790. {
  21791. return (diff > 0) ? 1 : -1;
  21792. }
  21793. }
  21794. void MidiFile::readNextTrack (const char* data, int size)
  21795. {
  21796. double time = 0;
  21797. char lastStatusByte = 0;
  21798. MidiMessageSequence result;
  21799. while (size > 0)
  21800. {
  21801. int bytesUsed;
  21802. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21803. data += bytesUsed;
  21804. size -= bytesUsed;
  21805. time += delay;
  21806. int messSize = 0;
  21807. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21808. if (messSize <= 0)
  21809. break;
  21810. size -= messSize;
  21811. data += messSize;
  21812. result.addEvent (mm);
  21813. const char firstByte = *(mm.getRawData());
  21814. if ((firstByte & 0xf0) != 0xf0)
  21815. lastStatusByte = firstByte;
  21816. }
  21817. // use a sort that puts all the note-offs before note-ons that have the same time
  21818. result.list.sort (*this, true);
  21819. result.updateMatchedPairs();
  21820. addTrack (result);
  21821. }
  21822. static double convertTicksToSeconds (const double time,
  21823. const MidiMessageSequence& tempoEvents,
  21824. const int timeFormat)
  21825. {
  21826. if (timeFormat > 0)
  21827. {
  21828. int numer = 4, denom = 4;
  21829. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21830. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21831. double secsPerTick = 0.5 * tickLen;
  21832. const int numEvents = tempoEvents.getNumEvents();
  21833. for (int i = 0; i < numEvents; ++i)
  21834. {
  21835. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21836. if (time <= m.getTimeStamp())
  21837. break;
  21838. if (timeFormat > 0)
  21839. {
  21840. correctedTempoTime = correctedTempoTime
  21841. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21842. }
  21843. else
  21844. {
  21845. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21846. }
  21847. tempoTime = m.getTimeStamp();
  21848. if (m.isTempoMetaEvent())
  21849. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21850. else if (m.isTimeSignatureMetaEvent())
  21851. m.getTimeSignatureInfo (numer, denom);
  21852. while (i + 1 < numEvents)
  21853. {
  21854. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21855. if (m2.getTimeStamp() == tempoTime)
  21856. {
  21857. ++i;
  21858. if (m2.isTempoMetaEvent())
  21859. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21860. else if (m2.isTimeSignatureMetaEvent())
  21861. m2.getTimeSignatureInfo (numer, denom);
  21862. }
  21863. else
  21864. {
  21865. break;
  21866. }
  21867. }
  21868. }
  21869. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21870. }
  21871. else
  21872. {
  21873. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21874. }
  21875. }
  21876. void MidiFile::convertTimestampTicksToSeconds()
  21877. {
  21878. MidiMessageSequence tempoEvents;
  21879. findAllTempoEvents (tempoEvents);
  21880. findAllTimeSigEvents (tempoEvents);
  21881. for (int i = 0; i < tracks.size(); ++i)
  21882. {
  21883. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21884. for (int j = ms.getNumEvents(); --j >= 0;)
  21885. {
  21886. MidiMessage& m = ms.getEventPointer(j)->message;
  21887. m.setTimeStamp (convertTicksToSeconds (m.getTimeStamp(),
  21888. tempoEvents,
  21889. timeFormat));
  21890. }
  21891. }
  21892. }
  21893. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21894. {
  21895. unsigned int buffer = v & 0x7F;
  21896. while ((v >>= 7) != 0)
  21897. {
  21898. buffer <<= 8;
  21899. buffer |= ((v & 0x7F) | 0x80);
  21900. }
  21901. for (;;)
  21902. {
  21903. out.writeByte ((char) buffer);
  21904. if (buffer & 0x80)
  21905. buffer >>= 8;
  21906. else
  21907. break;
  21908. }
  21909. }
  21910. bool MidiFile::writeTo (OutputStream& out)
  21911. {
  21912. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21913. out.writeIntBigEndian (6);
  21914. out.writeShortBigEndian (1); // type
  21915. out.writeShortBigEndian ((short) tracks.size());
  21916. out.writeShortBigEndian (timeFormat);
  21917. for (int i = 0; i < tracks.size(); ++i)
  21918. writeTrack (out, i);
  21919. out.flush();
  21920. return true;
  21921. }
  21922. void MidiFile::writeTrack (OutputStream& mainOut,
  21923. const int trackNum)
  21924. {
  21925. MemoryOutputStream out;
  21926. const MidiMessageSequence& ms = *tracks[trackNum];
  21927. int lastTick = 0;
  21928. char lastStatusByte = 0;
  21929. for (int i = 0; i < ms.getNumEvents(); ++i)
  21930. {
  21931. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21932. const int tick = roundToInt (mm.getTimeStamp());
  21933. const int delta = jmax (0, tick - lastTick);
  21934. writeVariableLengthInt (out, delta);
  21935. lastTick = tick;
  21936. const char statusByte = *(mm.getRawData());
  21937. if ((statusByte == lastStatusByte)
  21938. && ((statusByte & 0xf0) != 0xf0)
  21939. && i > 0
  21940. && mm.getRawDataSize() > 1)
  21941. {
  21942. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21943. }
  21944. else
  21945. {
  21946. out.write (mm.getRawData(), mm.getRawDataSize());
  21947. }
  21948. lastStatusByte = statusByte;
  21949. }
  21950. out.writeByte (0);
  21951. const MidiMessage m (MidiMessage::endOfTrack());
  21952. out.write (m.getRawData(),
  21953. m.getRawDataSize());
  21954. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21955. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21956. mainOut.write (out.getData(), (int) out.getDataSize());
  21957. }
  21958. END_JUCE_NAMESPACE
  21959. /*** End of inlined file: juce_MidiFile.cpp ***/
  21960. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21961. BEGIN_JUCE_NAMESPACE
  21962. MidiKeyboardState::MidiKeyboardState()
  21963. {
  21964. zeromem (noteStates, sizeof (noteStates));
  21965. }
  21966. MidiKeyboardState::~MidiKeyboardState()
  21967. {
  21968. }
  21969. void MidiKeyboardState::reset()
  21970. {
  21971. const ScopedLock sl (lock);
  21972. zeromem (noteStates, sizeof (noteStates));
  21973. eventsToAdd.clear();
  21974. }
  21975. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21976. {
  21977. jassert (midiChannel >= 0 && midiChannel <= 16);
  21978. return ((unsigned int) n) < 128
  21979. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21980. }
  21981. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21982. {
  21983. return ((unsigned int) n) < 128
  21984. && (noteStates[n] & midiChannelMask) != 0;
  21985. }
  21986. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21987. {
  21988. jassert (midiChannel >= 0 && midiChannel <= 16);
  21989. jassert (((unsigned int) midiNoteNumber) < 128);
  21990. const ScopedLock sl (lock);
  21991. if (((unsigned int) midiNoteNumber) < 128)
  21992. {
  21993. const int timeNow = (int) Time::getMillisecondCounter();
  21994. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21995. eventsToAdd.clear (0, timeNow - 500);
  21996. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21997. }
  21998. }
  21999. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  22000. {
  22001. if (((unsigned int) midiNoteNumber) < 128)
  22002. {
  22003. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  22004. for (int i = listeners.size(); --i >= 0;)
  22005. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22006. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  22007. }
  22008. }
  22009. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  22010. {
  22011. const ScopedLock sl (lock);
  22012. if (isNoteOn (midiChannel, midiNoteNumber))
  22013. {
  22014. const int timeNow = (int) Time::getMillisecondCounter();
  22015. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  22016. eventsToAdd.clear (0, timeNow - 500);
  22017. noteOffInternal (midiChannel, midiNoteNumber);
  22018. }
  22019. }
  22020. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  22021. {
  22022. if (isNoteOn (midiChannel, midiNoteNumber))
  22023. {
  22024. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  22025. for (int i = listeners.size(); --i >= 0;)
  22026. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22027. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  22028. }
  22029. }
  22030. void MidiKeyboardState::allNotesOff (const int midiChannel)
  22031. {
  22032. const ScopedLock sl (lock);
  22033. if (midiChannel <= 0)
  22034. {
  22035. for (int i = 1; i <= 16; ++i)
  22036. allNotesOff (i);
  22037. }
  22038. else
  22039. {
  22040. for (int i = 0; i < 128; ++i)
  22041. noteOff (midiChannel, i);
  22042. }
  22043. }
  22044. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  22045. {
  22046. if (message.isNoteOn())
  22047. {
  22048. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  22049. }
  22050. else if (message.isNoteOff())
  22051. {
  22052. noteOffInternal (message.getChannel(), message.getNoteNumber());
  22053. }
  22054. else if (message.isAllNotesOff())
  22055. {
  22056. for (int i = 0; i < 128; ++i)
  22057. noteOffInternal (message.getChannel(), i);
  22058. }
  22059. }
  22060. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22061. const int startSample,
  22062. const int numSamples,
  22063. const bool injectIndirectEvents)
  22064. {
  22065. MidiBuffer::Iterator i (buffer);
  22066. MidiMessage message (0xf4, 0.0);
  22067. int time;
  22068. const ScopedLock sl (lock);
  22069. while (i.getNextEvent (message, time))
  22070. processNextMidiEvent (message);
  22071. if (injectIndirectEvents)
  22072. {
  22073. MidiBuffer::Iterator i2 (eventsToAdd);
  22074. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22075. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22076. while (i2.getNextEvent (message, time))
  22077. {
  22078. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22079. buffer.addEvent (message, startSample + pos);
  22080. }
  22081. }
  22082. eventsToAdd.clear();
  22083. }
  22084. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22085. {
  22086. const ScopedLock sl (lock);
  22087. listeners.addIfNotAlreadyThere (listener);
  22088. }
  22089. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22090. {
  22091. const ScopedLock sl (lock);
  22092. listeners.removeValue (listener);
  22093. }
  22094. END_JUCE_NAMESPACE
  22095. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22096. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22097. BEGIN_JUCE_NAMESPACE
  22098. int MidiMessage::readVariableLengthVal (const uint8* data,
  22099. int& numBytesUsed) throw()
  22100. {
  22101. numBytesUsed = 0;
  22102. int v = 0;
  22103. int i;
  22104. do
  22105. {
  22106. i = (int) *data++;
  22107. if (++numBytesUsed > 6)
  22108. break;
  22109. v = (v << 7) + (i & 0x7f);
  22110. } while (i & 0x80);
  22111. return v;
  22112. }
  22113. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22114. {
  22115. // this method only works for valid starting bytes of a short midi message
  22116. jassert (firstByte >= 0x80
  22117. && firstByte != 0xf0
  22118. && firstByte != 0xf7);
  22119. static const char messageLengths[] =
  22120. {
  22121. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22122. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22123. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22124. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22125. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22126. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22127. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22128. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22129. };
  22130. return messageLengths [firstByte & 0x7f];
  22131. }
  22132. MidiMessage::MidiMessage (const uint8* const d,
  22133. const int dataSize,
  22134. const double t) throw()
  22135. : timeStamp (t),
  22136. message (0),
  22137. size (dataSize)
  22138. {
  22139. jassert (dataSize > 0);
  22140. if (dataSize <= 4)
  22141. data = (uint8*) &message;
  22142. else
  22143. data = (uint8*) juce_malloc (dataSize);
  22144. memcpy (data, d, dataSize);
  22145. // check that the length matches the data..
  22146. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22147. }
  22148. MidiMessage::MidiMessage (const int byte1,
  22149. const double t) throw()
  22150. : timeStamp (t),
  22151. data ((uint8*) &message),
  22152. size (1)
  22153. {
  22154. data[0] = (uint8) byte1;
  22155. // check that the length matches the data..
  22156. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22157. }
  22158. MidiMessage::MidiMessage (const int byte1,
  22159. const int byte2,
  22160. const double t) throw()
  22161. : timeStamp (t),
  22162. data ((uint8*) &message),
  22163. size (2)
  22164. {
  22165. data[0] = (uint8) byte1;
  22166. data[1] = (uint8) byte2;
  22167. // check that the length matches the data..
  22168. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22169. }
  22170. MidiMessage::MidiMessage (const int byte1,
  22171. const int byte2,
  22172. const int byte3,
  22173. const double t) throw()
  22174. : timeStamp (t),
  22175. data ((uint8*) &message),
  22176. size (3)
  22177. {
  22178. data[0] = (uint8) byte1;
  22179. data[1] = (uint8) byte2;
  22180. data[2] = (uint8) byte3;
  22181. // check that the length matches the data..
  22182. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22183. }
  22184. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22185. : timeStamp (other.timeStamp),
  22186. message (other.message),
  22187. size (other.size)
  22188. {
  22189. if (other.data != (uint8*) &other.message)
  22190. {
  22191. data = (uint8*) juce_malloc (size);
  22192. memcpy (data, other.data, size);
  22193. }
  22194. else
  22195. {
  22196. data = (uint8*) &message;
  22197. }
  22198. }
  22199. MidiMessage::MidiMessage (const MidiMessage& other,
  22200. const double newTimeStamp) throw()
  22201. : timeStamp (newTimeStamp),
  22202. message (other.message),
  22203. size (other.size)
  22204. {
  22205. if (other.data != (uint8*) &other.message)
  22206. {
  22207. data = (uint8*) juce_malloc (size);
  22208. memcpy (data, other.data, size);
  22209. }
  22210. else
  22211. {
  22212. data = (uint8*) &message;
  22213. }
  22214. }
  22215. MidiMessage::MidiMessage (const uint8* src,
  22216. int sz,
  22217. int& numBytesUsed,
  22218. const uint8 lastStatusByte,
  22219. double t) throw()
  22220. : timeStamp (t),
  22221. data ((uint8*) &message),
  22222. message (0)
  22223. {
  22224. unsigned int byte = (unsigned int) *src;
  22225. if (byte < 0x80)
  22226. {
  22227. byte = (unsigned int) (uint8) lastStatusByte;
  22228. numBytesUsed = -1;
  22229. }
  22230. else
  22231. {
  22232. numBytesUsed = 0;
  22233. --sz;
  22234. ++src;
  22235. }
  22236. if (byte >= 0x80)
  22237. {
  22238. if (byte == 0xf0)
  22239. {
  22240. const uint8* d = (const uint8*) src;
  22241. while (d < src + sz)
  22242. {
  22243. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22244. {
  22245. if (*d == 0xf7) // include an 0xf7 if we hit one
  22246. ++d;
  22247. break;
  22248. }
  22249. ++d;
  22250. }
  22251. size = 1 + (int) (d - src);
  22252. data = (uint8*) juce_malloc (size);
  22253. *data = (uint8) byte;
  22254. memcpy (data + 1, src, size - 1);
  22255. }
  22256. else if (byte == 0xff)
  22257. {
  22258. int n;
  22259. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22260. size = jmin (sz + 1, n + 2 + bytesLeft);
  22261. data = (uint8*) juce_malloc (size);
  22262. *data = (uint8) byte;
  22263. memcpy (data + 1, src, size - 1);
  22264. }
  22265. else
  22266. {
  22267. size = getMessageLengthFromFirstByte ((uint8) byte);
  22268. *data = (uint8) byte;
  22269. if (size > 1)
  22270. {
  22271. data[1] = src[0];
  22272. if (size > 2)
  22273. data[2] = src[1];
  22274. }
  22275. }
  22276. numBytesUsed += size;
  22277. }
  22278. else
  22279. {
  22280. message = 0;
  22281. size = 0;
  22282. }
  22283. }
  22284. const MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22285. {
  22286. if (this != &other)
  22287. {
  22288. timeStamp = other.timeStamp;
  22289. size = other.size;
  22290. message = other.message;
  22291. if (data != (uint8*) &message)
  22292. juce_free (data);
  22293. if (other.data != (uint8*) &other.message)
  22294. {
  22295. data = (uint8*) juce_malloc (size);
  22296. memcpy (data, other.data, size);
  22297. }
  22298. else
  22299. {
  22300. data = (uint8*) &message;
  22301. }
  22302. }
  22303. return *this;
  22304. }
  22305. MidiMessage::~MidiMessage() throw()
  22306. {
  22307. if (data != (uint8*) &message)
  22308. juce_free (data);
  22309. }
  22310. int MidiMessage::getChannel() const throw()
  22311. {
  22312. if ((data[0] & 0xf0) != 0xf0)
  22313. return (data[0] & 0xf) + 1;
  22314. else
  22315. return 0;
  22316. }
  22317. bool MidiMessage::isForChannel (const int channel) const throw()
  22318. {
  22319. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22320. return ((data[0] & 0xf) == channel - 1)
  22321. && ((data[0] & 0xf0) != 0xf0);
  22322. }
  22323. void MidiMessage::setChannel (const int channel) throw()
  22324. {
  22325. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22326. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22327. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22328. | (uint8)(channel - 1));
  22329. }
  22330. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22331. {
  22332. return ((data[0] & 0xf0) == 0x90)
  22333. && (returnTrueForVelocity0 || data[2] != 0);
  22334. }
  22335. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22336. {
  22337. return ((data[0] & 0xf0) == 0x80)
  22338. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22339. }
  22340. bool MidiMessage::isNoteOnOrOff() const throw()
  22341. {
  22342. const int d = data[0] & 0xf0;
  22343. return (d == 0x90) || (d == 0x80);
  22344. }
  22345. int MidiMessage::getNoteNumber() const throw()
  22346. {
  22347. return data[1];
  22348. }
  22349. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22350. {
  22351. if (isNoteOnOrOff())
  22352. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22353. }
  22354. uint8 MidiMessage::getVelocity() const throw()
  22355. {
  22356. if (isNoteOnOrOff())
  22357. return data[2];
  22358. else
  22359. return 0;
  22360. }
  22361. float MidiMessage::getFloatVelocity() const throw()
  22362. {
  22363. return getVelocity() * (1.0f / 127.0f);
  22364. }
  22365. void MidiMessage::setVelocity (const float newVelocity) throw()
  22366. {
  22367. if (isNoteOnOrOff())
  22368. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22369. }
  22370. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22371. {
  22372. if (isNoteOnOrOff())
  22373. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22374. }
  22375. bool MidiMessage::isAftertouch() const throw()
  22376. {
  22377. return (data[0] & 0xf0) == 0xa0;
  22378. }
  22379. int MidiMessage::getAfterTouchValue() const throw()
  22380. {
  22381. return data[2];
  22382. }
  22383. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22384. const int noteNum,
  22385. const int aftertouchValue) throw()
  22386. {
  22387. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22388. jassert (((unsigned int) noteNum) <= 127);
  22389. jassert (((unsigned int) aftertouchValue) <= 127);
  22390. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22391. noteNum & 0x7f,
  22392. aftertouchValue & 0x7f);
  22393. }
  22394. bool MidiMessage::isChannelPressure() const throw()
  22395. {
  22396. return (data[0] & 0xf0) == 0xd0;
  22397. }
  22398. int MidiMessage::getChannelPressureValue() const throw()
  22399. {
  22400. jassert (isChannelPressure());
  22401. return data[1];
  22402. }
  22403. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22404. const int pressure) throw()
  22405. {
  22406. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22407. jassert (((unsigned int) pressure) <= 127);
  22408. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22409. pressure & 0x7f);
  22410. }
  22411. bool MidiMessage::isProgramChange() const throw()
  22412. {
  22413. return (data[0] & 0xf0) == 0xc0;
  22414. }
  22415. int MidiMessage::getProgramChangeNumber() const throw()
  22416. {
  22417. return data[1];
  22418. }
  22419. const MidiMessage MidiMessage::programChange (const int channel,
  22420. const int programNumber) throw()
  22421. {
  22422. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22423. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22424. programNumber & 0x7f);
  22425. }
  22426. bool MidiMessage::isPitchWheel() const throw()
  22427. {
  22428. return (data[0] & 0xf0) == 0xe0;
  22429. }
  22430. int MidiMessage::getPitchWheelValue() const throw()
  22431. {
  22432. return data[1] | (data[2] << 7);
  22433. }
  22434. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22435. const int position) throw()
  22436. {
  22437. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22438. jassert (((unsigned int) position) <= 0x3fff);
  22439. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22440. position & 127,
  22441. (position >> 7) & 127);
  22442. }
  22443. bool MidiMessage::isController() const throw()
  22444. {
  22445. return (data[0] & 0xf0) == 0xb0;
  22446. }
  22447. int MidiMessage::getControllerNumber() const throw()
  22448. {
  22449. jassert (isController());
  22450. return data[1];
  22451. }
  22452. int MidiMessage::getControllerValue() const throw()
  22453. {
  22454. jassert (isController());
  22455. return data[2];
  22456. }
  22457. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22458. const int controllerType,
  22459. const int value) throw()
  22460. {
  22461. // the channel must be between 1 and 16 inclusive
  22462. jassert (channel > 0 && channel <= 16);
  22463. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22464. controllerType & 127,
  22465. value & 127);
  22466. }
  22467. const MidiMessage MidiMessage::noteOn (const int channel,
  22468. const int noteNumber,
  22469. const float velocity) throw()
  22470. {
  22471. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22472. }
  22473. const MidiMessage MidiMessage::noteOn (const int channel,
  22474. const int noteNumber,
  22475. const uint8 velocity) throw()
  22476. {
  22477. jassert (channel > 0 && channel <= 16);
  22478. jassert (((unsigned int) noteNumber) <= 127);
  22479. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22480. noteNumber & 127,
  22481. jlimit (0, 127, roundToInt (velocity)));
  22482. }
  22483. const MidiMessage MidiMessage::noteOff (const int channel,
  22484. const int noteNumber) throw()
  22485. {
  22486. jassert (channel > 0 && channel <= 16);
  22487. jassert (((unsigned int) noteNumber) <= 127);
  22488. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22489. }
  22490. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22491. {
  22492. jassert (channel > 0 && channel <= 16);
  22493. return controllerEvent (channel, 123, 0);
  22494. }
  22495. bool MidiMessage::isAllNotesOff() const throw()
  22496. {
  22497. return (data[0] & 0xf0) == 0xb0
  22498. && data[1] == 123;
  22499. }
  22500. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22501. {
  22502. return controllerEvent (channel, 120, 0);
  22503. }
  22504. bool MidiMessage::isAllSoundOff() const throw()
  22505. {
  22506. return (data[0] & 0xf0) == 0xb0
  22507. && data[1] == 120;
  22508. }
  22509. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22510. {
  22511. return controllerEvent (channel, 121, 0);
  22512. }
  22513. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22514. {
  22515. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22516. uint8 buf[8];
  22517. buf[0] = 0xf0;
  22518. buf[1] = 0x7f;
  22519. buf[2] = 0x7f;
  22520. buf[3] = 0x04;
  22521. buf[4] = 0x01;
  22522. buf[5] = (uint8) (vol & 0x7f);
  22523. buf[6] = (uint8) (vol >> 7);
  22524. buf[7] = 0xf7;
  22525. return MidiMessage (buf, 8);
  22526. }
  22527. bool MidiMessage::isSysEx() const throw()
  22528. {
  22529. return *data == 0xf0;
  22530. }
  22531. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22532. const int dataSize) throw()
  22533. {
  22534. MemoryBlock mm (dataSize + 2);
  22535. uint8* const m = (uint8*) mm.getData();
  22536. m[0] = 0xf0;
  22537. memcpy (m + 1, sysexData, dataSize);
  22538. m[dataSize + 1] = 0xf7;
  22539. return MidiMessage (m, dataSize + 2);
  22540. }
  22541. const uint8* MidiMessage::getSysExData() const throw()
  22542. {
  22543. return (isSysEx()) ? getRawData() + 1
  22544. : 0;
  22545. }
  22546. int MidiMessage::getSysExDataSize() const throw()
  22547. {
  22548. return (isSysEx()) ? size - 2
  22549. : 0;
  22550. }
  22551. bool MidiMessage::isMetaEvent() const throw()
  22552. {
  22553. return *data == 0xff;
  22554. }
  22555. bool MidiMessage::isActiveSense() const throw()
  22556. {
  22557. return *data == 0xfe;
  22558. }
  22559. int MidiMessage::getMetaEventType() const throw()
  22560. {
  22561. if (*data != 0xff)
  22562. return -1;
  22563. else
  22564. return data[1];
  22565. }
  22566. int MidiMessage::getMetaEventLength() const throw()
  22567. {
  22568. if (*data == 0xff)
  22569. {
  22570. int n;
  22571. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22572. }
  22573. return 0;
  22574. }
  22575. const uint8* MidiMessage::getMetaEventData() const throw()
  22576. {
  22577. int n;
  22578. const uint8* d = data + 2;
  22579. readVariableLengthVal (d, n);
  22580. return d + n;
  22581. }
  22582. bool MidiMessage::isTrackMetaEvent() const throw()
  22583. {
  22584. return getMetaEventType() == 0;
  22585. }
  22586. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22587. {
  22588. return getMetaEventType() == 47;
  22589. }
  22590. bool MidiMessage::isTextMetaEvent() const throw()
  22591. {
  22592. const int t = getMetaEventType();
  22593. return t > 0 && t < 16;
  22594. }
  22595. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22596. {
  22597. return String ((const char*) getMetaEventData(),
  22598. getMetaEventLength());
  22599. }
  22600. bool MidiMessage::isTrackNameEvent() const throw()
  22601. {
  22602. return (data[1] == 3)
  22603. && (*data == 0xff);
  22604. }
  22605. bool MidiMessage::isTempoMetaEvent() const throw()
  22606. {
  22607. return (data[1] == 81)
  22608. && (*data == 0xff);
  22609. }
  22610. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22611. {
  22612. return (data[1] == 0x20)
  22613. && (*data == 0xff)
  22614. && (data[2] == 1);
  22615. }
  22616. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22617. {
  22618. return data[3] + 1;
  22619. }
  22620. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22621. {
  22622. if (! isTempoMetaEvent())
  22623. return 0.0;
  22624. const uint8* const d = getMetaEventData();
  22625. return (((unsigned int) d[0] << 16)
  22626. | ((unsigned int) d[1] << 8)
  22627. | d[2])
  22628. / 1000000.0;
  22629. }
  22630. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22631. {
  22632. if (timeFormat > 0)
  22633. {
  22634. if (! isTempoMetaEvent())
  22635. return 0.5 / timeFormat;
  22636. return getTempoSecondsPerQuarterNote() / timeFormat;
  22637. }
  22638. else
  22639. {
  22640. const int frameCode = (-timeFormat) >> 8;
  22641. double framesPerSecond;
  22642. switch (frameCode)
  22643. {
  22644. case 24: framesPerSecond = 24.0; break;
  22645. case 25: framesPerSecond = 25.0; break;
  22646. case 29: framesPerSecond = 29.97; break;
  22647. case 30: framesPerSecond = 30.0; break;
  22648. default: framesPerSecond = 30.0; break;
  22649. }
  22650. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22651. }
  22652. }
  22653. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22654. {
  22655. uint8 d[8];
  22656. d[0] = 0xff;
  22657. d[1] = 81;
  22658. d[2] = 3;
  22659. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22660. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22661. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22662. return MidiMessage (d, 6, 0.0);
  22663. }
  22664. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22665. {
  22666. return (data[1] == 0x58)
  22667. && (*data == (uint8) 0xff);
  22668. }
  22669. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22670. int& denominator) const throw()
  22671. {
  22672. if (isTimeSignatureMetaEvent())
  22673. {
  22674. const uint8* const d = getMetaEventData();
  22675. numerator = d[0];
  22676. denominator = 1 << d[1];
  22677. }
  22678. else
  22679. {
  22680. numerator = 4;
  22681. denominator = 4;
  22682. }
  22683. }
  22684. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22685. const int denominator) throw()
  22686. {
  22687. uint8 d[8];
  22688. d[0] = 0xff;
  22689. d[1] = 0x58;
  22690. d[2] = 0x04;
  22691. d[3] = (uint8) numerator;
  22692. int n = 1;
  22693. int powerOfTwo = 0;
  22694. while (n < denominator)
  22695. {
  22696. n <<= 1;
  22697. ++powerOfTwo;
  22698. }
  22699. d[4] = (uint8) powerOfTwo;
  22700. d[5] = 0x01;
  22701. d[6] = 96;
  22702. return MidiMessage (d, 7, 0.0);
  22703. }
  22704. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22705. {
  22706. uint8 d[8];
  22707. d[0] = 0xff;
  22708. d[1] = 0x20;
  22709. d[2] = 0x01;
  22710. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22711. return MidiMessage (d, 4, 0.0);
  22712. }
  22713. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22714. {
  22715. return getMetaEventType() == 89;
  22716. }
  22717. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22718. {
  22719. return (int) *getMetaEventData();
  22720. }
  22721. const MidiMessage MidiMessage::endOfTrack() throw()
  22722. {
  22723. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22724. }
  22725. bool MidiMessage::isSongPositionPointer() const throw()
  22726. {
  22727. return *data == 0xf2;
  22728. }
  22729. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22730. {
  22731. return data[1] | (data[2] << 7);
  22732. }
  22733. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22734. {
  22735. return MidiMessage (0xf2,
  22736. positionInMidiBeats & 127,
  22737. (positionInMidiBeats >> 7) & 127);
  22738. }
  22739. bool MidiMessage::isMidiStart() const throw()
  22740. {
  22741. return *data == 0xfa;
  22742. }
  22743. const MidiMessage MidiMessage::midiStart() throw()
  22744. {
  22745. return MidiMessage (0xfa);
  22746. }
  22747. bool MidiMessage::isMidiContinue() const throw()
  22748. {
  22749. return *data == 0xfb;
  22750. }
  22751. const MidiMessage MidiMessage::midiContinue() throw()
  22752. {
  22753. return MidiMessage (0xfb);
  22754. }
  22755. bool MidiMessage::isMidiStop() const throw()
  22756. {
  22757. return *data == 0xfc;
  22758. }
  22759. const MidiMessage MidiMessage::midiStop() throw()
  22760. {
  22761. return MidiMessage (0xfc);
  22762. }
  22763. bool MidiMessage::isMidiClock() const throw()
  22764. {
  22765. return *data == 0xf8;
  22766. }
  22767. const MidiMessage MidiMessage::midiClock() throw()
  22768. {
  22769. return MidiMessage (0xf8);
  22770. }
  22771. bool MidiMessage::isQuarterFrame() const throw()
  22772. {
  22773. return *data == 0xf1;
  22774. }
  22775. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22776. {
  22777. return ((int) data[1]) >> 4;
  22778. }
  22779. int MidiMessage::getQuarterFrameValue() const throw()
  22780. {
  22781. return ((int) data[1]) & 0x0f;
  22782. }
  22783. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22784. const int value) throw()
  22785. {
  22786. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22787. }
  22788. bool MidiMessage::isFullFrame() const throw()
  22789. {
  22790. return data[0] == 0xf0
  22791. && data[1] == 0x7f
  22792. && size >= 10
  22793. && data[3] == 0x01
  22794. && data[4] == 0x01;
  22795. }
  22796. void MidiMessage::getFullFrameParameters (int& hours,
  22797. int& minutes,
  22798. int& seconds,
  22799. int& frames,
  22800. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22801. {
  22802. jassert (isFullFrame());
  22803. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22804. hours = data[5] & 0x1f;
  22805. minutes = data[6];
  22806. seconds = data[7];
  22807. frames = data[8];
  22808. }
  22809. const MidiMessage MidiMessage::fullFrame (const int hours,
  22810. const int minutes,
  22811. const int seconds,
  22812. const int frames,
  22813. MidiMessage::SmpteTimecodeType timecodeType)
  22814. {
  22815. uint8 d[10];
  22816. d[0] = 0xf0;
  22817. d[1] = 0x7f;
  22818. d[2] = 0x7f;
  22819. d[3] = 0x01;
  22820. d[4] = 0x01;
  22821. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22822. d[6] = (uint8) minutes;
  22823. d[7] = (uint8) seconds;
  22824. d[8] = (uint8) frames;
  22825. d[9] = 0xf7;
  22826. return MidiMessage (d, 10, 0.0);
  22827. }
  22828. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22829. {
  22830. return data[0] == 0xf0
  22831. && data[1] == 0x7f
  22832. && data[3] == 0x06
  22833. && size > 5;
  22834. }
  22835. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22836. {
  22837. jassert (isMidiMachineControlMessage());
  22838. return (MidiMachineControlCommand) data[4];
  22839. }
  22840. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22841. {
  22842. uint8 d[6];
  22843. d[0] = 0xf0;
  22844. d[1] = 0x7f;
  22845. d[2] = 0x00;
  22846. d[3] = 0x06;
  22847. d[4] = (uint8) command;
  22848. d[5] = 0xf7;
  22849. return MidiMessage (d, 6, 0.0);
  22850. }
  22851. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22852. int& minutes,
  22853. int& seconds,
  22854. int& frames) const throw()
  22855. {
  22856. if (size >= 12
  22857. && data[0] == 0xf0
  22858. && data[1] == 0x7f
  22859. && data[3] == 0x06
  22860. && data[4] == 0x44
  22861. && data[5] == 0x06
  22862. && data[6] == 0x01)
  22863. {
  22864. hours = data[7] % 24; // (that some machines send out hours > 24)
  22865. minutes = data[8];
  22866. seconds = data[9];
  22867. frames = data[10];
  22868. return true;
  22869. }
  22870. return false;
  22871. }
  22872. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22873. int minutes,
  22874. int seconds,
  22875. int frames)
  22876. {
  22877. uint8 d[12];
  22878. d[0] = 0xf0;
  22879. d[1] = 0x7f;
  22880. d[2] = 0x00;
  22881. d[3] = 0x06;
  22882. d[4] = 0x44;
  22883. d[5] = 0x06;
  22884. d[6] = 0x01;
  22885. d[7] = (uint8) hours;
  22886. d[8] = (uint8) minutes;
  22887. d[9] = (uint8) seconds;
  22888. d[10] = (uint8) frames;
  22889. d[11] = 0xf7;
  22890. return MidiMessage (d, 12, 0.0);
  22891. }
  22892. const String MidiMessage::getMidiNoteName (int note,
  22893. bool useSharps,
  22894. bool includeOctaveNumber,
  22895. int octaveNumForMiddleC) throw()
  22896. {
  22897. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22898. "F", "F#", "G", "G#", "A",
  22899. "A#", "B" };
  22900. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22901. "F", "Gb", "G", "Ab", "A",
  22902. "Bb", "B" };
  22903. if (((unsigned int) note) < 128)
  22904. {
  22905. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22906. : flatNoteNames [note % 12]);
  22907. if (includeOctaveNumber)
  22908. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22909. else
  22910. return s;
  22911. }
  22912. return String::empty;
  22913. }
  22914. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22915. {
  22916. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22917. return 440.0 * pow (2.0, noteNumber / 12.0);
  22918. }
  22919. const String MidiMessage::getGMInstrumentName (int n) throw()
  22920. {
  22921. const char *names[] =
  22922. {
  22923. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22924. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22925. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22926. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22927. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22928. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22929. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22930. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22931. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22932. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22933. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22934. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22935. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22936. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22937. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22938. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22939. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22940. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22941. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22942. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22943. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22944. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22945. "Applause", "Gunshot"
  22946. };
  22947. return (((unsigned int) n) < 128) ? names[n]
  22948. : (const char*)0;
  22949. }
  22950. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22951. {
  22952. const char* names[] =
  22953. {
  22954. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22955. "Bass", "Strings", "Ensemble", "Brass",
  22956. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22957. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22958. };
  22959. return (((unsigned int) n) <= 15) ? names[n]
  22960. : (const char*)0;
  22961. }
  22962. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22963. {
  22964. const char* names[] =
  22965. {
  22966. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22967. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22968. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22969. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22970. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22971. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22972. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22973. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22974. "Mute Triangle", "Open Triangle"
  22975. };
  22976. return (n >= 35 && n <= 81) ? names [n - 35]
  22977. : (const char*)0;
  22978. }
  22979. const String MidiMessage::getControllerName (int n) throw()
  22980. {
  22981. const char* names[] =
  22982. {
  22983. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22984. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22985. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22986. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22987. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22988. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22989. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22990. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22991. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22992. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22993. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22994. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22995. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22996. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22997. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22998. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22999. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  23000. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  23001. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  23002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  23003. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  23004. "Poly Operation"
  23005. };
  23006. return (((unsigned int) n) < 128) ? names[n]
  23007. : (const char*)0;
  23008. }
  23009. END_JUCE_NAMESPACE
  23010. /*** End of inlined file: juce_MidiMessage.cpp ***/
  23011. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  23012. BEGIN_JUCE_NAMESPACE
  23013. MidiMessageCollector::MidiMessageCollector()
  23014. : lastCallbackTime (0),
  23015. sampleRate (44100.0001)
  23016. {
  23017. }
  23018. MidiMessageCollector::~MidiMessageCollector()
  23019. {
  23020. }
  23021. void MidiMessageCollector::reset (const double sampleRate_)
  23022. {
  23023. jassert (sampleRate_ > 0);
  23024. const ScopedLock sl (midiCallbackLock);
  23025. sampleRate = sampleRate_;
  23026. incomingMessages.clear();
  23027. lastCallbackTime = Time::getMillisecondCounterHiRes();
  23028. }
  23029. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  23030. {
  23031. // you need to call reset() to set the correct sample rate before using this object
  23032. jassert (sampleRate != 44100.0001);
  23033. // the messages that come in here need to be time-stamped correctly - see MidiInput
  23034. // for details of what the number should be.
  23035. jassert (message.getTimeStamp() != 0);
  23036. const ScopedLock sl (midiCallbackLock);
  23037. const int sampleNumber
  23038. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  23039. incomingMessages.addEvent (message, sampleNumber);
  23040. // if the messages don't get used for over a second, we'd better
  23041. // get rid of any old ones to avoid the queue getting too big
  23042. if (sampleNumber > sampleRate)
  23043. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  23044. }
  23045. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  23046. const int numSamples)
  23047. {
  23048. // you need to call reset() to set the correct sample rate before using this object
  23049. jassert (sampleRate != 44100.0001);
  23050. const double timeNow = Time::getMillisecondCounterHiRes();
  23051. const double msElapsed = timeNow - lastCallbackTime;
  23052. const ScopedLock sl (midiCallbackLock);
  23053. lastCallbackTime = timeNow;
  23054. if (! incomingMessages.isEmpty())
  23055. {
  23056. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23057. int startSample = 0;
  23058. int scale = 1 << 16;
  23059. const uint8* midiData;
  23060. int numBytes, samplePosition;
  23061. MidiBuffer::Iterator iter (incomingMessages);
  23062. if (numSourceSamples > numSamples)
  23063. {
  23064. // if our list of events is longer than the buffer we're being
  23065. // asked for, scale them down to squeeze them all in..
  23066. const int maxBlockLengthToUse = numSamples << 5;
  23067. if (numSourceSamples > maxBlockLengthToUse)
  23068. {
  23069. startSample = numSourceSamples - maxBlockLengthToUse;
  23070. numSourceSamples = maxBlockLengthToUse;
  23071. iter.setNextSamplePosition (startSample);
  23072. }
  23073. scale = (numSamples << 10) / numSourceSamples;
  23074. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23075. {
  23076. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23077. destBuffer.addEvent (midiData, numBytes,
  23078. jlimit (0, numSamples - 1, samplePosition));
  23079. }
  23080. }
  23081. else
  23082. {
  23083. // if our event list is shorter than the number we need, put them
  23084. // towards the end of the buffer
  23085. startSample = numSamples - numSourceSamples;
  23086. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23087. {
  23088. destBuffer.addEvent (midiData, numBytes,
  23089. jlimit (0, numSamples - 1, samplePosition + startSample));
  23090. }
  23091. }
  23092. incomingMessages.clear();
  23093. }
  23094. }
  23095. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23096. {
  23097. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23098. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23099. addMessageToQueue (m);
  23100. }
  23101. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23102. {
  23103. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23104. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23105. addMessageToQueue (m);
  23106. }
  23107. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23108. {
  23109. addMessageToQueue (message);
  23110. }
  23111. END_JUCE_NAMESPACE
  23112. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23113. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23114. BEGIN_JUCE_NAMESPACE
  23115. MidiMessageSequence::MidiMessageSequence()
  23116. {
  23117. }
  23118. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23119. {
  23120. list.ensureStorageAllocated (other.list.size());
  23121. for (int i = 0; i < other.list.size(); ++i)
  23122. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23123. }
  23124. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23125. {
  23126. MidiMessageSequence otherCopy (other);
  23127. swapWith (otherCopy);
  23128. return *this;
  23129. }
  23130. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23131. {
  23132. list.swapWithArray (other.list);
  23133. }
  23134. MidiMessageSequence::~MidiMessageSequence()
  23135. {
  23136. }
  23137. void MidiMessageSequence::clear()
  23138. {
  23139. list.clear();
  23140. }
  23141. int MidiMessageSequence::getNumEvents() const
  23142. {
  23143. return list.size();
  23144. }
  23145. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23146. {
  23147. return list [index];
  23148. }
  23149. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23150. {
  23151. const MidiEventHolder* const meh = list [index];
  23152. if (meh != 0 && meh->noteOffObject != 0)
  23153. return meh->noteOffObject->message.getTimeStamp();
  23154. else
  23155. return 0.0;
  23156. }
  23157. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23158. {
  23159. const MidiEventHolder* const meh = list [index];
  23160. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23161. }
  23162. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23163. {
  23164. return list.indexOf (event);
  23165. }
  23166. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23167. {
  23168. const int numEvents = list.size();
  23169. int i;
  23170. for (i = 0; i < numEvents; ++i)
  23171. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23172. break;
  23173. return i;
  23174. }
  23175. double MidiMessageSequence::getStartTime() const
  23176. {
  23177. if (list.size() > 0)
  23178. return list.getUnchecked(0)->message.getTimeStamp();
  23179. else
  23180. return 0;
  23181. }
  23182. double MidiMessageSequence::getEndTime() const
  23183. {
  23184. if (list.size() > 0)
  23185. return list.getLast()->message.getTimeStamp();
  23186. else
  23187. return 0;
  23188. }
  23189. double MidiMessageSequence::getEventTime (const int index) const
  23190. {
  23191. if (((unsigned int) index) < (unsigned int) list.size())
  23192. return list.getUnchecked (index)->message.getTimeStamp();
  23193. return 0.0;
  23194. }
  23195. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23196. double timeAdjustment)
  23197. {
  23198. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23199. timeAdjustment += newMessage.getTimeStamp();
  23200. newOne->message.setTimeStamp (timeAdjustment);
  23201. int i;
  23202. for (i = list.size(); --i >= 0;)
  23203. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23204. break;
  23205. list.insert (i + 1, newOne);
  23206. }
  23207. void MidiMessageSequence::deleteEvent (const int index,
  23208. const bool deleteMatchingNoteUp)
  23209. {
  23210. if (((unsigned int) index) < (unsigned int) list.size())
  23211. {
  23212. if (deleteMatchingNoteUp)
  23213. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23214. list.remove (index);
  23215. }
  23216. }
  23217. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23218. double timeAdjustment,
  23219. double firstAllowableTime,
  23220. double endOfAllowableDestTimes)
  23221. {
  23222. firstAllowableTime -= timeAdjustment;
  23223. endOfAllowableDestTimes -= timeAdjustment;
  23224. for (int i = 0; i < other.list.size(); ++i)
  23225. {
  23226. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23227. const double t = m.getTimeStamp();
  23228. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23229. {
  23230. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23231. newOne->message.setTimeStamp (timeAdjustment + t);
  23232. list.add (newOne);
  23233. }
  23234. }
  23235. sort();
  23236. }
  23237. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23238. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23239. {
  23240. const double diff = first->message.getTimeStamp()
  23241. - second->message.getTimeStamp();
  23242. return (diff > 0) - (diff < 0);
  23243. }
  23244. void MidiMessageSequence::sort()
  23245. {
  23246. list.sort (*this, true);
  23247. }
  23248. void MidiMessageSequence::updateMatchedPairs()
  23249. {
  23250. for (int i = 0; i < list.size(); ++i)
  23251. {
  23252. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23253. if (m1.isNoteOn())
  23254. {
  23255. list.getUnchecked(i)->noteOffObject = 0;
  23256. const int note = m1.getNoteNumber();
  23257. const int chan = m1.getChannel();
  23258. const int len = list.size();
  23259. for (int j = i + 1; j < len; ++j)
  23260. {
  23261. const MidiMessage& m = list.getUnchecked(j)->message;
  23262. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23263. {
  23264. if (m.isNoteOff())
  23265. {
  23266. list.getUnchecked(i)->noteOffObject = list[j];
  23267. break;
  23268. }
  23269. else if (m.isNoteOn())
  23270. {
  23271. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23272. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23273. list.getUnchecked(i)->noteOffObject = list[j];
  23274. break;
  23275. }
  23276. }
  23277. }
  23278. }
  23279. }
  23280. }
  23281. void MidiMessageSequence::addTimeToMessages (const double delta)
  23282. {
  23283. for (int i = list.size(); --i >= 0;)
  23284. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23285. + delta);
  23286. }
  23287. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23288. MidiMessageSequence& destSequence,
  23289. const bool alsoIncludeMetaEvents) const
  23290. {
  23291. for (int i = 0; i < list.size(); ++i)
  23292. {
  23293. const MidiMessage& mm = list.getUnchecked(i)->message;
  23294. if (mm.isForChannel (channelNumberToExtract)
  23295. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23296. {
  23297. destSequence.addEvent (mm);
  23298. }
  23299. }
  23300. }
  23301. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23302. {
  23303. for (int i = 0; i < list.size(); ++i)
  23304. {
  23305. const MidiMessage& mm = list.getUnchecked(i)->message;
  23306. if (mm.isSysEx())
  23307. destSequence.addEvent (mm);
  23308. }
  23309. }
  23310. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23311. {
  23312. for (int i = list.size(); --i >= 0;)
  23313. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23314. list.remove(i);
  23315. }
  23316. void MidiMessageSequence::deleteSysExMessages()
  23317. {
  23318. for (int i = list.size(); --i >= 0;)
  23319. if (list.getUnchecked(i)->message.isSysEx())
  23320. list.remove(i);
  23321. }
  23322. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23323. const double time,
  23324. OwnedArray<MidiMessage>& dest)
  23325. {
  23326. bool doneProg = false;
  23327. bool donePitchWheel = false;
  23328. Array <int> doneControllers;
  23329. doneControllers.ensureStorageAllocated (32);
  23330. for (int i = list.size(); --i >= 0;)
  23331. {
  23332. const MidiMessage& mm = list.getUnchecked(i)->message;
  23333. if (mm.isForChannel (channelNumber)
  23334. && mm.getTimeStamp() <= time)
  23335. {
  23336. if (mm.isProgramChange())
  23337. {
  23338. if (! doneProg)
  23339. {
  23340. dest.add (new MidiMessage (mm, 0.0));
  23341. doneProg = true;
  23342. }
  23343. }
  23344. else if (mm.isController())
  23345. {
  23346. if (! doneControllers.contains (mm.getControllerNumber()))
  23347. {
  23348. dest.add (new MidiMessage (mm, 0.0));
  23349. doneControllers.add (mm.getControllerNumber());
  23350. }
  23351. }
  23352. else if (mm.isPitchWheel())
  23353. {
  23354. if (! donePitchWheel)
  23355. {
  23356. dest.add (new MidiMessage (mm, 0.0));
  23357. donePitchWheel = true;
  23358. }
  23359. }
  23360. }
  23361. }
  23362. }
  23363. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23364. : message (message_),
  23365. noteOffObject (0)
  23366. {
  23367. }
  23368. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23369. {
  23370. }
  23371. END_JUCE_NAMESPACE
  23372. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23373. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23374. BEGIN_JUCE_NAMESPACE
  23375. AudioPluginFormat::AudioPluginFormat() throw()
  23376. {
  23377. }
  23378. AudioPluginFormat::~AudioPluginFormat()
  23379. {
  23380. }
  23381. END_JUCE_NAMESPACE
  23382. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23383. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23384. BEGIN_JUCE_NAMESPACE
  23385. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23386. {
  23387. }
  23388. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23389. {
  23390. clearSingletonInstance();
  23391. }
  23392. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23393. void AudioPluginFormatManager::addDefaultFormats()
  23394. {
  23395. #ifdef JUCE_DEBUG
  23396. // you should only call this method once!
  23397. for (int i = formats.size(); --i >= 0;)
  23398. {
  23399. #if JUCE_PLUGINHOST_VST
  23400. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23401. #endif
  23402. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23403. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23404. #endif
  23405. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23406. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23407. #endif
  23408. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23409. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23410. #endif
  23411. }
  23412. #endif
  23413. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23414. formats.add (new AudioUnitPluginFormat());
  23415. #endif
  23416. #if JUCE_PLUGINHOST_VST
  23417. formats.add (new VSTPluginFormat());
  23418. #endif
  23419. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23420. formats.add (new DirectXPluginFormat());
  23421. #endif
  23422. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23423. formats.add (new LADSPAPluginFormat());
  23424. #endif
  23425. }
  23426. int AudioPluginFormatManager::getNumFormats() throw()
  23427. {
  23428. return formats.size();
  23429. }
  23430. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23431. {
  23432. return formats [index];
  23433. }
  23434. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23435. {
  23436. formats.add (format);
  23437. }
  23438. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23439. String& errorMessage) const
  23440. {
  23441. AudioPluginInstance* result = 0;
  23442. for (int i = 0; i < formats.size(); ++i)
  23443. {
  23444. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23445. if (result != 0)
  23446. break;
  23447. }
  23448. if (result == 0)
  23449. {
  23450. if (! doesPluginStillExist (description))
  23451. errorMessage = TRANS ("This plug-in file no longer exists");
  23452. else
  23453. errorMessage = TRANS ("This plug-in failed to load correctly");
  23454. }
  23455. return result;
  23456. }
  23457. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23458. {
  23459. for (int i = 0; i < formats.size(); ++i)
  23460. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23461. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23462. return false;
  23463. }
  23464. END_JUCE_NAMESPACE
  23465. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23466. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23467. #define JUCE_PLUGIN_HOST 1
  23468. BEGIN_JUCE_NAMESPACE
  23469. AudioPluginInstance::AudioPluginInstance()
  23470. {
  23471. }
  23472. AudioPluginInstance::~AudioPluginInstance()
  23473. {
  23474. }
  23475. END_JUCE_NAMESPACE
  23476. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23477. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23478. BEGIN_JUCE_NAMESPACE
  23479. KnownPluginList::KnownPluginList()
  23480. {
  23481. }
  23482. KnownPluginList::~KnownPluginList()
  23483. {
  23484. }
  23485. void KnownPluginList::clear()
  23486. {
  23487. if (types.size() > 0)
  23488. {
  23489. types.clear();
  23490. sendChangeMessage (this);
  23491. }
  23492. }
  23493. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23494. {
  23495. for (int i = 0; i < types.size(); ++i)
  23496. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23497. return types.getUnchecked(i);
  23498. return 0;
  23499. }
  23500. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23501. {
  23502. for (int i = 0; i < types.size(); ++i)
  23503. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23504. return types.getUnchecked(i);
  23505. return 0;
  23506. }
  23507. bool KnownPluginList::addType (const PluginDescription& type)
  23508. {
  23509. for (int i = types.size(); --i >= 0;)
  23510. {
  23511. if (types.getUnchecked(i)->isDuplicateOf (type))
  23512. {
  23513. // strange - found a duplicate plugin with different info..
  23514. jassert (types.getUnchecked(i)->name == type.name);
  23515. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23516. *types.getUnchecked(i) = type;
  23517. return false;
  23518. }
  23519. }
  23520. types.add (new PluginDescription (type));
  23521. sendChangeMessage (this);
  23522. return true;
  23523. }
  23524. void KnownPluginList::removeType (const int index) throw()
  23525. {
  23526. types.remove (index);
  23527. sendChangeMessage (this);
  23528. }
  23529. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23530. {
  23531. if (fileOrIdentifier.startsWithChar (T('/'))
  23532. || fileOrIdentifier[1] == T(':'))
  23533. {
  23534. return File (fileOrIdentifier).getLastModificationTime();
  23535. }
  23536. return Time (0);
  23537. }
  23538. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23539. {
  23540. return t1 != t2 || t1 == Time (0);
  23541. }
  23542. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23543. {
  23544. if (getTypeForFile (fileOrIdentifier) == 0)
  23545. return false;
  23546. for (int i = types.size(); --i >= 0;)
  23547. {
  23548. const PluginDescription* const d = types.getUnchecked(i);
  23549. if (d->fileOrIdentifier == fileOrIdentifier
  23550. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23551. {
  23552. return false;
  23553. }
  23554. }
  23555. return true;
  23556. }
  23557. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23558. const bool dontRescanIfAlreadyInList,
  23559. OwnedArray <PluginDescription>& typesFound,
  23560. AudioPluginFormat& format)
  23561. {
  23562. bool addedOne = false;
  23563. if (dontRescanIfAlreadyInList
  23564. && getTypeForFile (fileOrIdentifier) != 0)
  23565. {
  23566. bool needsRescanning = false;
  23567. for (int i = types.size(); --i >= 0;)
  23568. {
  23569. const PluginDescription* const d = types.getUnchecked(i);
  23570. if (d->fileOrIdentifier == fileOrIdentifier)
  23571. {
  23572. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23573. needsRescanning = true;
  23574. else
  23575. typesFound.add (new PluginDescription (*d));
  23576. }
  23577. }
  23578. if (! needsRescanning)
  23579. return false;
  23580. }
  23581. OwnedArray <PluginDescription> found;
  23582. format.findAllTypesForFile (found, fileOrIdentifier);
  23583. for (int i = 0; i < found.size(); ++i)
  23584. {
  23585. PluginDescription* const desc = found.getUnchecked(i);
  23586. jassert (desc != 0);
  23587. if (addType (*desc))
  23588. addedOne = true;
  23589. typesFound.add (new PluginDescription (*desc));
  23590. }
  23591. return addedOne;
  23592. }
  23593. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23594. OwnedArray <PluginDescription>& typesFound)
  23595. {
  23596. for (int i = 0; i < files.size(); ++i)
  23597. {
  23598. bool loaded = false;
  23599. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23600. {
  23601. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23602. if (scanAndAddFile (files[i], true, typesFound, *format))
  23603. loaded = true;
  23604. }
  23605. if (! loaded)
  23606. {
  23607. const File f (files[i]);
  23608. if (f.isDirectory())
  23609. {
  23610. StringArray s;
  23611. {
  23612. Array<File> subFiles;
  23613. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23614. for (int j = 0; j < subFiles.size(); ++j)
  23615. s.add (subFiles.getReference(j).getFullPathName());
  23616. }
  23617. scanAndAddDragAndDroppedFiles (s, typesFound);
  23618. }
  23619. }
  23620. }
  23621. }
  23622. class PluginSorter
  23623. {
  23624. public:
  23625. KnownPluginList::SortMethod method;
  23626. PluginSorter() throw() {}
  23627. int compareElements (const PluginDescription* const first,
  23628. const PluginDescription* const second) const throw()
  23629. {
  23630. int diff = 0;
  23631. if (method == KnownPluginList::sortByCategory)
  23632. diff = first->category.compareLexicographically (second->category);
  23633. else if (method == KnownPluginList::sortByManufacturer)
  23634. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23635. else if (method == KnownPluginList::sortByFileSystemLocation)
  23636. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23637. .upToLastOccurrenceOf (T("/"), false, false)
  23638. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23639. .upToLastOccurrenceOf (T("/"), false, false));
  23640. if (diff == 0)
  23641. diff = first->name.compareLexicographically (second->name);
  23642. return diff;
  23643. }
  23644. };
  23645. void KnownPluginList::sort (const SortMethod method)
  23646. {
  23647. if (method != defaultOrder)
  23648. {
  23649. PluginSorter sorter;
  23650. sorter.method = method;
  23651. types.sort (sorter, true);
  23652. sendChangeMessage (this);
  23653. }
  23654. }
  23655. XmlElement* KnownPluginList::createXml() const
  23656. {
  23657. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23658. for (int i = 0; i < types.size(); ++i)
  23659. e->addChildElement (types.getUnchecked(i)->createXml());
  23660. return e;
  23661. }
  23662. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23663. {
  23664. clear();
  23665. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23666. {
  23667. forEachXmlChildElement (xml, e)
  23668. {
  23669. PluginDescription info;
  23670. if (info.loadFromXml (*e))
  23671. addType (info);
  23672. }
  23673. }
  23674. }
  23675. const int menuIdBase = 0x324503f4;
  23676. // This is used to turn a bunch of paths into a nested menu structure.
  23677. struct PluginFilesystemTree
  23678. {
  23679. private:
  23680. String folder;
  23681. OwnedArray <PluginFilesystemTree> subFolders;
  23682. Array <PluginDescription*> plugins;
  23683. void addPlugin (PluginDescription* const pd, const String& path)
  23684. {
  23685. if (path.isEmpty())
  23686. {
  23687. plugins.add (pd);
  23688. }
  23689. else
  23690. {
  23691. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23692. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23693. for (int i = subFolders.size(); --i >= 0;)
  23694. {
  23695. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23696. {
  23697. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23698. return;
  23699. }
  23700. }
  23701. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23702. newFolder->folder = firstSubFolder;
  23703. subFolders.add (newFolder);
  23704. newFolder->addPlugin (pd, remainingPath);
  23705. }
  23706. }
  23707. // removes any deeply nested folders that don't contain any actual plugins
  23708. void optimise()
  23709. {
  23710. for (int i = subFolders.size(); --i >= 0;)
  23711. {
  23712. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23713. sub->optimise();
  23714. if (sub->plugins.size() == 0)
  23715. {
  23716. for (int j = 0; j < sub->subFolders.size(); ++j)
  23717. subFolders.add (sub->subFolders.getUnchecked(j));
  23718. sub->subFolders.clear (false);
  23719. subFolders.remove (i);
  23720. }
  23721. }
  23722. }
  23723. public:
  23724. void buildTree (const Array <PluginDescription*>& allPlugins)
  23725. {
  23726. for (int i = 0; i < allPlugins.size(); ++i)
  23727. {
  23728. String path (allPlugins.getUnchecked(i)
  23729. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23730. .upToLastOccurrenceOf (T("/"), false, false));
  23731. if (path.substring (1, 2) == T(":"))
  23732. path = path.substring (2);
  23733. addPlugin (allPlugins.getUnchecked(i), path);
  23734. }
  23735. optimise();
  23736. }
  23737. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23738. {
  23739. int i;
  23740. for (i = 0; i < subFolders.size(); ++i)
  23741. {
  23742. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23743. PopupMenu subMenu;
  23744. sub->addToMenu (subMenu, allPlugins);
  23745. #if JUCE_MAC
  23746. // avoid the special AU formatting nonsense on Mac..
  23747. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23748. #else
  23749. m.addSubMenu (sub->folder, subMenu);
  23750. #endif
  23751. }
  23752. for (i = 0; i < plugins.size(); ++i)
  23753. {
  23754. PluginDescription* const plugin = plugins.getUnchecked(i);
  23755. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23756. plugin->name, true, false);
  23757. }
  23758. }
  23759. };
  23760. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23761. {
  23762. Array <PluginDescription*> sorted;
  23763. {
  23764. PluginSorter sorter;
  23765. sorter.method = sortMethod;
  23766. for (int i = 0; i < types.size(); ++i)
  23767. sorted.addSorted (sorter, types.getUnchecked(i));
  23768. }
  23769. if (sortMethod == sortByCategory
  23770. || sortMethod == sortByManufacturer)
  23771. {
  23772. String lastSubMenuName;
  23773. PopupMenu sub;
  23774. for (int i = 0; i < sorted.size(); ++i)
  23775. {
  23776. const PluginDescription* const pd = sorted.getUnchecked(i);
  23777. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23778. : pd->manufacturerName);
  23779. if (! thisSubMenuName.containsNonWhitespaceChars())
  23780. thisSubMenuName = T("Other");
  23781. if (thisSubMenuName != lastSubMenuName)
  23782. {
  23783. if (sub.getNumItems() > 0)
  23784. {
  23785. menu.addSubMenu (lastSubMenuName, sub);
  23786. sub.clear();
  23787. }
  23788. lastSubMenuName = thisSubMenuName;
  23789. }
  23790. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23791. }
  23792. if (sub.getNumItems() > 0)
  23793. menu.addSubMenu (lastSubMenuName, sub);
  23794. }
  23795. else if (sortMethod == sortByFileSystemLocation)
  23796. {
  23797. PluginFilesystemTree root;
  23798. root.buildTree (sorted);
  23799. root.addToMenu (menu, types);
  23800. }
  23801. else
  23802. {
  23803. for (int i = 0; i < sorted.size(); ++i)
  23804. {
  23805. const PluginDescription* const pd = sorted.getUnchecked(i);
  23806. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23807. }
  23808. }
  23809. }
  23810. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23811. {
  23812. const int i = menuResultCode - menuIdBase;
  23813. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23814. }
  23815. END_JUCE_NAMESPACE
  23816. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23817. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23818. BEGIN_JUCE_NAMESPACE
  23819. PluginDescription::PluginDescription() throw()
  23820. : uid (0),
  23821. isInstrument (false),
  23822. numInputChannels (0),
  23823. numOutputChannels (0)
  23824. {
  23825. }
  23826. PluginDescription::~PluginDescription() throw()
  23827. {
  23828. }
  23829. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23830. : name (other.name),
  23831. pluginFormatName (other.pluginFormatName),
  23832. category (other.category),
  23833. manufacturerName (other.manufacturerName),
  23834. version (other.version),
  23835. fileOrIdentifier (other.fileOrIdentifier),
  23836. lastFileModTime (other.lastFileModTime),
  23837. uid (other.uid),
  23838. isInstrument (other.isInstrument),
  23839. numInputChannels (other.numInputChannels),
  23840. numOutputChannels (other.numOutputChannels)
  23841. {
  23842. }
  23843. const PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23844. {
  23845. name = other.name;
  23846. pluginFormatName = other.pluginFormatName;
  23847. category = other.category;
  23848. manufacturerName = other.manufacturerName;
  23849. version = other.version;
  23850. fileOrIdentifier = other.fileOrIdentifier;
  23851. uid = other.uid;
  23852. isInstrument = other.isInstrument;
  23853. lastFileModTime = other.lastFileModTime;
  23854. numInputChannels = other.numInputChannels;
  23855. numOutputChannels = other.numOutputChannels;
  23856. return *this;
  23857. }
  23858. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23859. {
  23860. return fileOrIdentifier == other.fileOrIdentifier
  23861. && uid == other.uid;
  23862. }
  23863. const String PluginDescription::createIdentifierString() const throw()
  23864. {
  23865. return pluginFormatName
  23866. + T("-") + name
  23867. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23868. + T("-") + String::toHexString (uid);
  23869. }
  23870. XmlElement* PluginDescription::createXml() const
  23871. {
  23872. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23873. e->setAttribute (T("name"), name);
  23874. e->setAttribute (T("format"), pluginFormatName);
  23875. e->setAttribute (T("category"), category);
  23876. e->setAttribute (T("manufacturer"), manufacturerName);
  23877. e->setAttribute (T("version"), version);
  23878. e->setAttribute (T("file"), fileOrIdentifier);
  23879. e->setAttribute (T("uid"), String::toHexString (uid));
  23880. e->setAttribute (T("isInstrument"), isInstrument);
  23881. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23882. e->setAttribute (T("numInputs"), numInputChannels);
  23883. e->setAttribute (T("numOutputs"), numOutputChannels);
  23884. return e;
  23885. }
  23886. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23887. {
  23888. if (xml.hasTagName (T("PLUGIN")))
  23889. {
  23890. name = xml.getStringAttribute (T("name"));
  23891. pluginFormatName = xml.getStringAttribute (T("format"));
  23892. category = xml.getStringAttribute (T("category"));
  23893. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23894. version = xml.getStringAttribute (T("version"));
  23895. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23896. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23897. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23898. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23899. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23900. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23901. return true;
  23902. }
  23903. return false;
  23904. }
  23905. END_JUCE_NAMESPACE
  23906. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23907. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23908. BEGIN_JUCE_NAMESPACE
  23909. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23910. AudioPluginFormat& formatToLookFor,
  23911. FileSearchPath directoriesToSearch,
  23912. const bool recursive,
  23913. const File& deadMansPedalFile_)
  23914. : list (listToAddTo),
  23915. format (formatToLookFor),
  23916. deadMansPedalFile (deadMansPedalFile_),
  23917. nextIndex (0),
  23918. progress (0)
  23919. {
  23920. directoriesToSearch.removeRedundantPaths();
  23921. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23922. // If any plugins have crashed recently when being loaded, move them to the
  23923. // end of the list to give the others a chance to load correctly..
  23924. const StringArray crashedPlugins (getDeadMansPedalFile());
  23925. for (int i = 0; i < crashedPlugins.size(); ++i)
  23926. {
  23927. const String f = crashedPlugins[i];
  23928. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23929. if (f == filesOrIdentifiersToScan[j])
  23930. filesOrIdentifiersToScan.move (j, -1);
  23931. }
  23932. }
  23933. PluginDirectoryScanner::~PluginDirectoryScanner()
  23934. {
  23935. }
  23936. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23937. {
  23938. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23939. }
  23940. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23941. {
  23942. String file (filesOrIdentifiersToScan [nextIndex]);
  23943. if (file.isNotEmpty())
  23944. {
  23945. if (! list.isListingUpToDate (file))
  23946. {
  23947. OwnedArray <PluginDescription> typesFound;
  23948. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23949. StringArray crashedPlugins (getDeadMansPedalFile());
  23950. crashedPlugins.removeString (file);
  23951. crashedPlugins.add (file);
  23952. setDeadMansPedalFile (crashedPlugins);
  23953. list.scanAndAddFile (file,
  23954. dontRescanIfAlreadyInList,
  23955. typesFound,
  23956. format);
  23957. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23958. crashedPlugins.removeString (file);
  23959. setDeadMansPedalFile (crashedPlugins);
  23960. if (typesFound.size() == 0)
  23961. failedFiles.add (file);
  23962. }
  23963. ++nextIndex;
  23964. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23965. }
  23966. return nextIndex < filesOrIdentifiersToScan.size();
  23967. }
  23968. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23969. {
  23970. StringArray lines;
  23971. if (deadMansPedalFile != File::nonexistent)
  23972. {
  23973. lines.addLines (deadMansPedalFile.loadFileAsString());
  23974. lines.removeEmptyStrings();
  23975. }
  23976. return lines;
  23977. }
  23978. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23979. {
  23980. if (deadMansPedalFile != File::nonexistent)
  23981. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23982. }
  23983. END_JUCE_NAMESPACE
  23984. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23985. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23986. BEGIN_JUCE_NAMESPACE
  23987. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23988. const File& deadMansPedalFile_,
  23989. PropertiesFile* const propertiesToUse_)
  23990. : list (listToEdit),
  23991. deadMansPedalFile (deadMansPedalFile_),
  23992. propertiesToUse (propertiesToUse_)
  23993. {
  23994. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23995. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23996. optionsButton->addButtonListener (this);
  23997. optionsButton->setTriggeredOnMouseDown (true);
  23998. setSize (400, 600);
  23999. list.addChangeListener (this);
  24000. }
  24001. PluginListComponent::~PluginListComponent()
  24002. {
  24003. list.removeChangeListener (this);
  24004. deleteAllChildren();
  24005. }
  24006. void PluginListComponent::resized()
  24007. {
  24008. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  24009. optionsButton->changeWidthToFitText (24);
  24010. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  24011. }
  24012. void PluginListComponent::changeListenerCallback (void*)
  24013. {
  24014. listBox->updateContent();
  24015. listBox->repaint();
  24016. }
  24017. int PluginListComponent::getNumRows()
  24018. {
  24019. return list.getNumTypes();
  24020. }
  24021. void PluginListComponent::paintListBoxItem (int row,
  24022. Graphics& g,
  24023. int width, int height,
  24024. bool rowIsSelected)
  24025. {
  24026. if (rowIsSelected)
  24027. g.fillAll (findColour (TextEditor::highlightColourId));
  24028. const PluginDescription* const pd = list.getType (row);
  24029. if (pd != 0)
  24030. {
  24031. GlyphArrangement ga;
  24032. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  24033. g.setColour (Colours::black);
  24034. ga.draw (g);
  24035. float x, y, r, b;
  24036. ga.getBoundingBox (0, -1, x, y, r, b, false);
  24037. String desc;
  24038. desc << pd->pluginFormatName
  24039. << (pd->isInstrument ? " instrument" : " effect")
  24040. << " - "
  24041. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  24042. << " / "
  24043. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  24044. if (pd->manufacturerName.isNotEmpty())
  24045. desc << " - " << pd->manufacturerName;
  24046. if (pd->version.isNotEmpty())
  24047. desc << " - " << pd->version;
  24048. if (pd->category.isNotEmpty())
  24049. desc << " - category: '" << pd->category << '\'';
  24050. g.setColour (Colours::grey);
  24051. ga.clear();
  24052. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  24053. ga.draw (g);
  24054. }
  24055. }
  24056. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24057. {
  24058. list.removeType (lastRowSelected);
  24059. }
  24060. void PluginListComponent::buttonClicked (Button* b)
  24061. {
  24062. if (optionsButton == b)
  24063. {
  24064. PopupMenu menu;
  24065. menu.addItem (1, TRANS("Clear list"));
  24066. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24067. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24068. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24069. menu.addSeparator();
  24070. menu.addItem (2, TRANS("Sort alphabetically"));
  24071. menu.addItem (3, TRANS("Sort by category"));
  24072. menu.addItem (4, TRANS("Sort by manufacturer"));
  24073. menu.addSeparator();
  24074. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24075. {
  24076. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24077. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24078. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24079. }
  24080. const int r = menu.showAt (optionsButton);
  24081. if (r == 1)
  24082. {
  24083. list.clear();
  24084. }
  24085. else if (r == 2)
  24086. {
  24087. list.sort (KnownPluginList::sortAlphabetically);
  24088. }
  24089. else if (r == 3)
  24090. {
  24091. list.sort (KnownPluginList::sortByCategory);
  24092. }
  24093. else if (r == 4)
  24094. {
  24095. list.sort (KnownPluginList::sortByManufacturer);
  24096. }
  24097. else if (r == 5)
  24098. {
  24099. const SparseSet <int> selected (listBox->getSelectedRows());
  24100. for (int i = list.getNumTypes(); --i >= 0;)
  24101. if (selected.contains (i))
  24102. list.removeType (i);
  24103. }
  24104. else if (r == 6)
  24105. {
  24106. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24107. if (desc != 0)
  24108. {
  24109. if (File (desc->fileOrIdentifier).existsAsFile())
  24110. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24111. }
  24112. }
  24113. else if (r == 7)
  24114. {
  24115. for (int i = list.getNumTypes(); --i >= 0;)
  24116. {
  24117. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24118. {
  24119. list.removeType (i);
  24120. }
  24121. }
  24122. }
  24123. else if (r != 0)
  24124. {
  24125. typeToScan = r - 10;
  24126. startTimer (1);
  24127. }
  24128. }
  24129. }
  24130. void PluginListComponent::timerCallback()
  24131. {
  24132. stopTimer();
  24133. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24134. }
  24135. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24136. {
  24137. return true;
  24138. }
  24139. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24140. {
  24141. OwnedArray <PluginDescription> typesFound;
  24142. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24143. }
  24144. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24145. {
  24146. if (format == 0)
  24147. return;
  24148. FileSearchPath path (format->getDefaultLocationsToSearch());
  24149. if (propertiesToUse != 0)
  24150. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24151. {
  24152. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24153. FileSearchPathListComponent pathList;
  24154. pathList.setSize (500, 300);
  24155. pathList.setPath (path);
  24156. aw.addCustomComponent (&pathList);
  24157. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24158. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24159. if (aw.runModalLoop() == 0)
  24160. return;
  24161. path = pathList.getPath();
  24162. }
  24163. if (propertiesToUse != 0)
  24164. {
  24165. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24166. propertiesToUse->saveIfNeeded();
  24167. }
  24168. double progress = 0.0;
  24169. AlertWindow aw (TRANS("Scanning for plugins..."),
  24170. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24171. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24172. aw.addProgressBarComponent (progress);
  24173. aw.enterModalState();
  24174. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24175. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24176. for (;;)
  24177. {
  24178. aw.setMessage (TRANS("Testing:\n\n")
  24179. + scanner.getNextPluginFileThatWillBeScanned());
  24180. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24181. if (! scanner.scanNextFile (true))
  24182. break;
  24183. if (! aw.isCurrentlyModal())
  24184. break;
  24185. progress = scanner.getProgress();
  24186. }
  24187. if (scanner.getFailedFiles().size() > 0)
  24188. {
  24189. StringArray shortNames;
  24190. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24191. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24192. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24193. TRANS("Scan complete"),
  24194. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24195. + shortNames.joinIntoString (", "));
  24196. }
  24197. }
  24198. END_JUCE_NAMESPACE
  24199. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24200. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24201. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24202. #include <AudioUnit/AudioUnit.h>
  24203. #include <AudioUnit/AUCocoaUIView.h>
  24204. #include <CoreAudioKit/AUGenericView.h>
  24205. #if JUCE_SUPPORT_CARBON
  24206. #include <AudioToolbox/AudioUnitUtilities.h>
  24207. #include <AudioUnit/AudioUnitCarbonView.h>
  24208. #endif
  24209. BEGIN_JUCE_NAMESPACE
  24210. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24211. #endif
  24212. #if JUCE_MAC
  24213. // Change this to disable logging of various activities
  24214. #ifndef AU_LOGGING
  24215. #define AU_LOGGING 1
  24216. #endif
  24217. #if AU_LOGGING
  24218. #define log(a) Logger::writeToLog(a);
  24219. #else
  24220. #define log(a)
  24221. #endif
  24222. static int insideCallback = 0;
  24223. static const String osTypeToString (OSType type) throw()
  24224. {
  24225. char s[4];
  24226. s[0] = (char) (((uint32) type) >> 24);
  24227. s[1] = (char) (((uint32) type) >> 16);
  24228. s[2] = (char) (((uint32) type) >> 8);
  24229. s[3] = (char) ((uint32) type);
  24230. return String (s, 4);
  24231. }
  24232. static OSType stringToOSType (const String& s1) throw()
  24233. {
  24234. const String s (s1 + " ");
  24235. return (((OSType) (unsigned char) s[0]) << 24)
  24236. | (((OSType) (unsigned char) s[1]) << 16)
  24237. | (((OSType) (unsigned char) s[2]) << 8)
  24238. | ((OSType) (unsigned char) s[3]);
  24239. }
  24240. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24241. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24242. {
  24243. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24244. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24245. String s (auIdentifierPrefix);
  24246. if (desc.componentType == kAudioUnitType_MusicDevice)
  24247. s << "Synths/";
  24248. else if (desc.componentType == kAudioUnitType_MusicEffect
  24249. || desc.componentType == kAudioUnitType_Effect)
  24250. s << "Effects/";
  24251. else if (desc.componentType == kAudioUnitType_Generator)
  24252. s << "Generators/";
  24253. else if (desc.componentType == kAudioUnitType_Panner)
  24254. s << "Panners/";
  24255. s << osTypeToString (desc.componentType)
  24256. << T(",")
  24257. << osTypeToString (desc.componentSubType)
  24258. << T(",")
  24259. << osTypeToString (desc.componentManufacturer);
  24260. return s;
  24261. }
  24262. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24263. {
  24264. Handle componentNameHandle = NewHandle (sizeof (void*));
  24265. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24266. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24267. {
  24268. ComponentDescription desc;
  24269. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24270. {
  24271. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24272. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24273. if (nameString != 0 && nameString[0] != 0)
  24274. {
  24275. const String all ((const char*) nameString + 1, nameString[0]);
  24276. DBG ("name: "+ all);
  24277. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24278. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24279. }
  24280. if (infoString != 0 && infoString[0] != 0)
  24281. {
  24282. const String all ((const char*) infoString + 1, infoString[0]);
  24283. DBG ("info: " + all);
  24284. }
  24285. if (name.isEmpty())
  24286. name = "<Unknown>";
  24287. }
  24288. DisposeHandle (componentNameHandle);
  24289. DisposeHandle (componentInfoHandle);
  24290. }
  24291. }
  24292. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24293. String& name, String& version, String& manufacturer)
  24294. {
  24295. zerostruct (desc);
  24296. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24297. {
  24298. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24299. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24300. StringArray tokens;
  24301. tokens.addTokens (s, T(","), 0);
  24302. tokens.trim();
  24303. tokens.removeEmptyStrings();
  24304. if (tokens.size() == 3)
  24305. {
  24306. desc.componentType = stringToOSType (tokens[0]);
  24307. desc.componentSubType = stringToOSType (tokens[1]);
  24308. desc.componentManufacturer = stringToOSType (tokens[2]);
  24309. ComponentRecord* comp = FindNextComponent (0, &desc);
  24310. if (comp != 0)
  24311. {
  24312. getAUDetails (comp, name, manufacturer);
  24313. return true;
  24314. }
  24315. }
  24316. }
  24317. return false;
  24318. }
  24319. class AudioUnitPluginWindowCarbon;
  24320. class AudioUnitPluginWindowCocoa;
  24321. class AudioUnitPluginInstance : public AudioPluginInstance
  24322. {
  24323. public:
  24324. ~AudioUnitPluginInstance();
  24325. // AudioPluginInstance methods:
  24326. void fillInPluginDescription (PluginDescription& desc) const
  24327. {
  24328. desc.name = pluginName;
  24329. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24330. desc.uid = ((int) componentDesc.componentType)
  24331. ^ ((int) componentDesc.componentSubType)
  24332. ^ ((int) componentDesc.componentManufacturer);
  24333. desc.lastFileModTime = 0;
  24334. desc.pluginFormatName = "AudioUnit";
  24335. desc.category = getCategory();
  24336. desc.manufacturerName = manufacturer;
  24337. desc.version = version;
  24338. desc.numInputChannels = getNumInputChannels();
  24339. desc.numOutputChannels = getNumOutputChannels();
  24340. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24341. }
  24342. const String getName() const { return pluginName; }
  24343. bool acceptsMidi() const { return wantsMidiMessages; }
  24344. bool producesMidi() const { return false; }
  24345. // AudioProcessor methods:
  24346. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24347. void releaseResources();
  24348. void processBlock (AudioSampleBuffer& buffer,
  24349. MidiBuffer& midiMessages);
  24350. AudioProcessorEditor* createEditor();
  24351. const String getInputChannelName (const int index) const;
  24352. bool isInputChannelStereoPair (int index) const;
  24353. const String getOutputChannelName (const int index) const;
  24354. bool isOutputChannelStereoPair (int index) const;
  24355. int getNumParameters();
  24356. float getParameter (int index);
  24357. void setParameter (int index, float newValue);
  24358. const String getParameterName (int index);
  24359. const String getParameterText (int index);
  24360. bool isParameterAutomatable (int index) const;
  24361. int getNumPrograms();
  24362. int getCurrentProgram();
  24363. void setCurrentProgram (int index);
  24364. const String getProgramName (int index);
  24365. void changeProgramName (int index, const String& newName);
  24366. void getStateInformation (MemoryBlock& destData);
  24367. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24368. void setStateInformation (const void* data, int sizeInBytes);
  24369. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24370. juce_UseDebuggingNewOperator
  24371. private:
  24372. friend class AudioUnitPluginWindowCarbon;
  24373. friend class AudioUnitPluginWindowCocoa;
  24374. friend class AudioUnitPluginFormat;
  24375. ComponentDescription componentDesc;
  24376. String pluginName, manufacturer, version;
  24377. String fileOrIdentifier;
  24378. CriticalSection lock;
  24379. bool initialised, wantsMidiMessages, wasPlaying;
  24380. HeapBlock <AudioBufferList> outputBufferList;
  24381. AudioTimeStamp timeStamp;
  24382. AudioSampleBuffer* currentBuffer;
  24383. AudioUnit audioUnit;
  24384. Array <int> parameterIds;
  24385. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24386. void initialise();
  24387. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24388. const AudioTimeStamp* inTimeStamp,
  24389. UInt32 inBusNumber,
  24390. UInt32 inNumberFrames,
  24391. AudioBufferList* ioData) const;
  24392. static OSStatus renderGetInputCallback (void* inRefCon,
  24393. AudioUnitRenderActionFlags* ioActionFlags,
  24394. const AudioTimeStamp* inTimeStamp,
  24395. UInt32 inBusNumber,
  24396. UInt32 inNumberFrames,
  24397. AudioBufferList* ioData)
  24398. {
  24399. return ((AudioUnitPluginInstance*) inRefCon)
  24400. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24401. }
  24402. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24403. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24404. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24405. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24406. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24407. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24408. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24409. {
  24410. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24411. }
  24412. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24413. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24414. Float64* outCurrentMeasureDownBeat)
  24415. {
  24416. return ((AudioUnitPluginInstance*) inHostUserData)
  24417. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24418. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24419. }
  24420. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24421. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24422. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24423. {
  24424. return ((AudioUnitPluginInstance*) inHostUserData)
  24425. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24426. outCurrentSampleInTimeLine, outIsCycling,
  24427. outCycleStartBeat, outCycleEndBeat);
  24428. }
  24429. void getNumChannels (int& numIns, int& numOuts)
  24430. {
  24431. numIns = 0;
  24432. numOuts = 0;
  24433. AUChannelInfo supportedChannels [128];
  24434. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24435. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24436. 0, supportedChannels, &supportedChannelsSize) == noErr
  24437. && supportedChannelsSize > 0)
  24438. {
  24439. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24440. {
  24441. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24442. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24443. }
  24444. }
  24445. else
  24446. {
  24447. // (this really means the plugin will take any number of ins/outs as long
  24448. // as they are the same)
  24449. numIns = numOuts = 2;
  24450. }
  24451. }
  24452. const String getCategory() const;
  24453. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24454. };
  24455. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24456. : fileOrIdentifier (fileOrIdentifier),
  24457. initialised (false),
  24458. wantsMidiMessages (false),
  24459. audioUnit (0),
  24460. currentBuffer (0)
  24461. {
  24462. try
  24463. {
  24464. ++insideCallback;
  24465. log (T("Opening AU: ") + fileOrIdentifier);
  24466. if (getComponentDescFromFile (fileOrIdentifier))
  24467. {
  24468. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24469. if (comp != 0)
  24470. {
  24471. audioUnit = (AudioUnit) OpenComponent (comp);
  24472. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24473. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24474. }
  24475. }
  24476. --insideCallback;
  24477. }
  24478. catch (...)
  24479. {
  24480. --insideCallback;
  24481. }
  24482. }
  24483. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24484. {
  24485. {
  24486. const ScopedLock sl (lock);
  24487. jassert (insideCallback == 0);
  24488. if (audioUnit != 0)
  24489. {
  24490. AudioUnitUninitialize (audioUnit);
  24491. CloseComponent (audioUnit);
  24492. audioUnit = 0;
  24493. }
  24494. }
  24495. }
  24496. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24497. {
  24498. zerostruct (componentDesc);
  24499. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24500. return true;
  24501. const File file (fileOrIdentifier);
  24502. if (! file.hasFileExtension (T(".component")))
  24503. return false;
  24504. const char* const utf8 = fileOrIdentifier.toUTF8();
  24505. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24506. strlen (utf8), file.isDirectory());
  24507. if (url != 0)
  24508. {
  24509. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24510. CFRelease (url);
  24511. if (bundleRef != 0)
  24512. {
  24513. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24514. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24515. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24516. if (pluginName.isEmpty())
  24517. pluginName = file.getFileNameWithoutExtension();
  24518. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24519. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24520. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24521. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24522. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24523. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24524. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24525. UseResFile (resFileId);
  24526. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24527. {
  24528. Handle h = Get1IndResource ('thng', i);
  24529. if (h != 0)
  24530. {
  24531. HLock (h);
  24532. const uint32* const types = (const uint32*) *h;
  24533. if (types[0] == kAudioUnitType_MusicDevice
  24534. || types[0] == kAudioUnitType_MusicEffect
  24535. || types[0] == kAudioUnitType_Effect
  24536. || types[0] == kAudioUnitType_Generator
  24537. || types[0] == kAudioUnitType_Panner)
  24538. {
  24539. componentDesc.componentType = types[0];
  24540. componentDesc.componentSubType = types[1];
  24541. componentDesc.componentManufacturer = types[2];
  24542. break;
  24543. }
  24544. HUnlock (h);
  24545. ReleaseResource (h);
  24546. }
  24547. }
  24548. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24549. CFRelease (bundleRef);
  24550. }
  24551. }
  24552. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24553. }
  24554. void AudioUnitPluginInstance::initialise()
  24555. {
  24556. if (initialised || audioUnit == 0)
  24557. return;
  24558. log (T("Initialising AU: ") + pluginName);
  24559. parameterIds.clear();
  24560. {
  24561. UInt32 paramListSize = 0;
  24562. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24563. 0, 0, &paramListSize);
  24564. if (paramListSize > 0)
  24565. {
  24566. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24567. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24568. 0, &parameterIds.getReference(0), &paramListSize);
  24569. }
  24570. }
  24571. {
  24572. AURenderCallbackStruct info;
  24573. zerostruct (info);
  24574. info.inputProcRefCon = this;
  24575. info.inputProc = renderGetInputCallback;
  24576. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24577. 0, &info, sizeof (info));
  24578. }
  24579. {
  24580. HostCallbackInfo info;
  24581. zerostruct (info);
  24582. info.hostUserData = this;
  24583. info.beatAndTempoProc = getBeatAndTempoCallback;
  24584. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24585. info.transportStateProc = getTransportStateCallback;
  24586. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24587. 0, &info, sizeof (info));
  24588. }
  24589. int numIns, numOuts;
  24590. getNumChannels (numIns, numOuts);
  24591. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24592. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24593. setLatencySamples (0);
  24594. }
  24595. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24596. int samplesPerBlockExpected)
  24597. {
  24598. initialise();
  24599. if (initialised)
  24600. {
  24601. int numIns, numOuts;
  24602. getNumChannels (numIns, numOuts);
  24603. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24604. Float64 latencySecs = 0.0;
  24605. UInt32 latencySize = sizeof (latencySecs);
  24606. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24607. 0, &latencySecs, &latencySize);
  24608. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24609. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24610. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24611. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24612. AudioStreamBasicDescription stream;
  24613. zerostruct (stream);
  24614. stream.mSampleRate = sampleRate_;
  24615. stream.mFormatID = kAudioFormatLinearPCM;
  24616. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24617. stream.mFramesPerPacket = 1;
  24618. stream.mBytesPerPacket = 4;
  24619. stream.mBytesPerFrame = 4;
  24620. stream.mBitsPerChannel = 32;
  24621. stream.mChannelsPerFrame = numIns;
  24622. OSStatus err = AudioUnitSetProperty (audioUnit,
  24623. kAudioUnitProperty_StreamFormat,
  24624. kAudioUnitScope_Input,
  24625. 0, &stream, sizeof (stream));
  24626. stream.mChannelsPerFrame = numOuts;
  24627. err = AudioUnitSetProperty (audioUnit,
  24628. kAudioUnitProperty_StreamFormat,
  24629. kAudioUnitScope_Output,
  24630. 0, &stream, sizeof (stream));
  24631. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24632. outputBufferList->mNumberBuffers = numOuts;
  24633. for (int i = numOuts; --i >= 0;)
  24634. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24635. zerostruct (timeStamp);
  24636. timeStamp.mSampleTime = 0;
  24637. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24638. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24639. currentBuffer = 0;
  24640. wasPlaying = false;
  24641. }
  24642. }
  24643. void AudioUnitPluginInstance::releaseResources()
  24644. {
  24645. if (initialised)
  24646. {
  24647. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24648. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24649. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24650. outputBufferList.free();
  24651. currentBuffer = 0;
  24652. }
  24653. }
  24654. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24655. const AudioTimeStamp* inTimeStamp,
  24656. UInt32 inBusNumber,
  24657. UInt32 inNumberFrames,
  24658. AudioBufferList* ioData) const
  24659. {
  24660. if (inBusNumber == 0
  24661. && currentBuffer != 0)
  24662. {
  24663. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24664. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24665. {
  24666. if (i < currentBuffer->getNumChannels())
  24667. {
  24668. memcpy (ioData->mBuffers[i].mData,
  24669. currentBuffer->getSampleData (i, 0),
  24670. sizeof (float) * inNumberFrames);
  24671. }
  24672. else
  24673. {
  24674. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24675. }
  24676. }
  24677. }
  24678. return noErr;
  24679. }
  24680. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24681. MidiBuffer& midiMessages)
  24682. {
  24683. const int numSamples = buffer.getNumSamples();
  24684. if (initialised)
  24685. {
  24686. AudioUnitRenderActionFlags flags = 0;
  24687. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24688. for (int i = getNumOutputChannels(); --i >= 0;)
  24689. {
  24690. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24691. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24692. }
  24693. currentBuffer = &buffer;
  24694. if (wantsMidiMessages)
  24695. {
  24696. const uint8* midiEventData;
  24697. int midiEventSize, midiEventPosition;
  24698. MidiBuffer::Iterator i (midiMessages);
  24699. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24700. {
  24701. if (midiEventSize <= 3)
  24702. MusicDeviceMIDIEvent (audioUnit,
  24703. midiEventData[0], midiEventData[1], midiEventData[2],
  24704. midiEventPosition);
  24705. else
  24706. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24707. }
  24708. midiMessages.clear();
  24709. }
  24710. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24711. 0, numSamples, outputBufferList);
  24712. timeStamp.mSampleTime += numSamples;
  24713. }
  24714. else
  24715. {
  24716. // Not initialised, so just bypass..
  24717. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24718. buffer.clear (i, 0, buffer.getNumSamples());
  24719. }
  24720. }
  24721. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24722. {
  24723. AudioPlayHead* const ph = getPlayHead();
  24724. AudioPlayHead::CurrentPositionInfo result;
  24725. if (ph != 0 && ph->getCurrentPosition (result))
  24726. {
  24727. if (outCurrentBeat != 0)
  24728. *outCurrentBeat = result.ppqPosition;
  24729. if (outCurrentTempo != 0)
  24730. *outCurrentTempo = result.bpm;
  24731. }
  24732. else
  24733. {
  24734. if (outCurrentBeat != 0)
  24735. *outCurrentBeat = 0;
  24736. if (outCurrentTempo != 0)
  24737. *outCurrentTempo = 120.0;
  24738. }
  24739. return noErr;
  24740. }
  24741. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24742. Float32* outTimeSig_Numerator,
  24743. UInt32* outTimeSig_Denominator,
  24744. Float64* outCurrentMeasureDownBeat) const
  24745. {
  24746. AudioPlayHead* const ph = getPlayHead();
  24747. AudioPlayHead::CurrentPositionInfo result;
  24748. if (ph != 0 && ph->getCurrentPosition (result))
  24749. {
  24750. if (outTimeSig_Numerator != 0)
  24751. *outTimeSig_Numerator = result.timeSigNumerator;
  24752. if (outTimeSig_Denominator != 0)
  24753. *outTimeSig_Denominator = result.timeSigDenominator;
  24754. if (outDeltaSampleOffsetToNextBeat != 0)
  24755. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24756. if (outCurrentMeasureDownBeat != 0)
  24757. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24758. }
  24759. else
  24760. {
  24761. if (outDeltaSampleOffsetToNextBeat != 0)
  24762. *outDeltaSampleOffsetToNextBeat = 0;
  24763. if (outTimeSig_Numerator != 0)
  24764. *outTimeSig_Numerator = 4;
  24765. if (outTimeSig_Denominator != 0)
  24766. *outTimeSig_Denominator = 4;
  24767. if (outCurrentMeasureDownBeat != 0)
  24768. *outCurrentMeasureDownBeat = 0;
  24769. }
  24770. return noErr;
  24771. }
  24772. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24773. Boolean* outTransportStateChanged,
  24774. Float64* outCurrentSampleInTimeLine,
  24775. Boolean* outIsCycling,
  24776. Float64* outCycleStartBeat,
  24777. Float64* outCycleEndBeat)
  24778. {
  24779. AudioPlayHead* const ph = getPlayHead();
  24780. AudioPlayHead::CurrentPositionInfo result;
  24781. if (ph != 0 && ph->getCurrentPosition (result))
  24782. {
  24783. if (outIsPlaying != 0)
  24784. *outIsPlaying = result.isPlaying;
  24785. if (outTransportStateChanged != 0)
  24786. {
  24787. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24788. wasPlaying = result.isPlaying;
  24789. }
  24790. if (outCurrentSampleInTimeLine != 0)
  24791. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24792. if (outIsCycling != 0)
  24793. *outIsCycling = false;
  24794. if (outCycleStartBeat != 0)
  24795. *outCycleStartBeat = 0;
  24796. if (outCycleEndBeat != 0)
  24797. *outCycleEndBeat = 0;
  24798. }
  24799. else
  24800. {
  24801. if (outIsPlaying != 0)
  24802. *outIsPlaying = false;
  24803. if (outTransportStateChanged != 0)
  24804. *outTransportStateChanged = false;
  24805. if (outCurrentSampleInTimeLine != 0)
  24806. *outCurrentSampleInTimeLine = 0;
  24807. if (outIsCycling != 0)
  24808. *outIsCycling = false;
  24809. if (outCycleStartBeat != 0)
  24810. *outCycleStartBeat = 0;
  24811. if (outCycleEndBeat != 0)
  24812. *outCycleEndBeat = 0;
  24813. }
  24814. return noErr;
  24815. }
  24816. static VoidArray activeWindows;
  24817. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24818. {
  24819. public:
  24820. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24821. : AudioProcessorEditor (&plugin_),
  24822. plugin (plugin_),
  24823. wrapper (0)
  24824. {
  24825. addAndMakeVisible (wrapper = new NSViewComponent());
  24826. activeWindows.add (this);
  24827. setOpaque (true);
  24828. setVisible (true);
  24829. setSize (100, 100);
  24830. createView (createGenericViewIfNeeded);
  24831. }
  24832. ~AudioUnitPluginWindowCocoa()
  24833. {
  24834. const bool wasValid = isValid();
  24835. wrapper->setView (0);
  24836. activeWindows.removeValue (this);
  24837. if (wasValid)
  24838. plugin.editorBeingDeleted (this);
  24839. delete wrapper;
  24840. }
  24841. bool isValid() const { return wrapper->getView() != 0; }
  24842. void paint (Graphics& g)
  24843. {
  24844. g.fillAll (Colours::white);
  24845. }
  24846. void resized()
  24847. {
  24848. wrapper->setSize (getWidth(), getHeight());
  24849. }
  24850. private:
  24851. AudioUnitPluginInstance& plugin;
  24852. NSViewComponent* wrapper;
  24853. bool createView (const bool createGenericViewIfNeeded)
  24854. {
  24855. NSView* pluginView = 0;
  24856. UInt32 dataSize = 0;
  24857. Boolean isWritable = false;
  24858. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24859. 0, &dataSize, &isWritable) == noErr
  24860. && dataSize != 0
  24861. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24862. 0, &dataSize, &isWritable) == noErr)
  24863. {
  24864. HeapBlock <AudioUnitCocoaViewInfo> info;
  24865. info.calloc (dataSize, 1);
  24866. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24867. 0, info, &dataSize) == noErr)
  24868. {
  24869. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24870. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24871. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24872. Class viewClass = [viewBundle classNamed: viewClassName];
  24873. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24874. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24875. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24876. {
  24877. id factory = [[[viewClass alloc] init] autorelease];
  24878. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24879. withSize: NSMakeSize (getWidth(), getHeight())];
  24880. }
  24881. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24882. {
  24883. CFRelease (info->mCocoaAUViewClass[i]);
  24884. CFRelease (info->mCocoaAUViewBundleLocation);
  24885. }
  24886. }
  24887. }
  24888. if (createGenericViewIfNeeded && (pluginView == 0))
  24889. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24890. wrapper->setView (pluginView);
  24891. if (pluginView != 0)
  24892. setSize ([pluginView frame].size.width,
  24893. [pluginView frame].size.height);
  24894. return pluginView != 0;
  24895. }
  24896. };
  24897. #if JUCE_SUPPORT_CARBON
  24898. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24899. {
  24900. public:
  24901. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24902. : AudioProcessorEditor (&plugin_),
  24903. plugin (plugin_),
  24904. viewComponent (0)
  24905. {
  24906. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24907. activeWindows.add (this);
  24908. setOpaque (true);
  24909. setVisible (true);
  24910. setSize (400, 300);
  24911. ComponentDescription viewList [16];
  24912. UInt32 viewListSize = sizeof (viewList);
  24913. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24914. 0, &viewList, &viewListSize);
  24915. componentRecord = FindNextComponent (0, &viewList[0]);
  24916. }
  24917. ~AudioUnitPluginWindowCarbon()
  24918. {
  24919. deleteAndZero (innerWrapper);
  24920. activeWindows.removeValue (this);
  24921. if (isValid())
  24922. plugin.editorBeingDeleted (this);
  24923. }
  24924. bool isValid() const throw() { return componentRecord != 0; }
  24925. void paint (Graphics& g)
  24926. {
  24927. g.fillAll (Colours::black);
  24928. }
  24929. void resized()
  24930. {
  24931. innerWrapper->setSize (getWidth(), getHeight());
  24932. }
  24933. bool keyStateChanged (const bool)
  24934. {
  24935. return false;
  24936. }
  24937. bool keyPressed (const KeyPress&)
  24938. {
  24939. return false;
  24940. }
  24941. void broughtToFront()
  24942. {
  24943. activeWindows.removeValue (this);
  24944. activeWindows.add (this);
  24945. }
  24946. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24947. AudioUnitCarbonView getViewComponent()
  24948. {
  24949. if (viewComponent == 0 && componentRecord != 0)
  24950. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24951. return viewComponent;
  24952. }
  24953. void closeViewComponent()
  24954. {
  24955. if (viewComponent != 0)
  24956. {
  24957. CloseComponent (viewComponent);
  24958. viewComponent = 0;
  24959. }
  24960. }
  24961. juce_UseDebuggingNewOperator
  24962. private:
  24963. AudioUnitPluginInstance& plugin;
  24964. ComponentRecord* componentRecord;
  24965. AudioUnitCarbonView viewComponent;
  24966. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24967. {
  24968. public:
  24969. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24970. : owner (owner_)
  24971. {
  24972. }
  24973. ~InnerWrapperComponent()
  24974. {
  24975. deleteWindow();
  24976. }
  24977. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24978. {
  24979. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24980. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24981. if (viewComponent == 0)
  24982. return 0;
  24983. Float32Point pos = { 0, 0 };
  24984. Float32Point size = { 250, 200 };
  24985. HIViewRef pluginView = 0;
  24986. AudioUnitCarbonViewCreate (viewComponent,
  24987. owner->getAudioUnit(),
  24988. windowRef,
  24989. rootView,
  24990. &pos,
  24991. &size,
  24992. (ControlRef*) &pluginView);
  24993. return pluginView;
  24994. }
  24995. void removeView (HIViewRef)
  24996. {
  24997. log (T("Closing AU GUI: ") + owner->plugin.getName());
  24998. owner->closeViewComponent();
  24999. }
  25000. private:
  25001. AudioUnitPluginWindowCarbon* const owner;
  25002. };
  25003. friend class InnerWrapperComponent;
  25004. InnerWrapperComponent* innerWrapper;
  25005. };
  25006. #endif
  25007. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  25008. {
  25009. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  25010. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  25011. w = 0;
  25012. #if JUCE_SUPPORT_CARBON
  25013. if (w == 0)
  25014. {
  25015. w = new AudioUnitPluginWindowCarbon (*this);
  25016. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  25017. w = 0;
  25018. }
  25019. #endif
  25020. if (w == 0)
  25021. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  25022. return w.release();
  25023. }
  25024. const String AudioUnitPluginInstance::getCategory() const
  25025. {
  25026. const char* result = 0;
  25027. switch (componentDesc.componentType)
  25028. {
  25029. case kAudioUnitType_Effect:
  25030. case kAudioUnitType_MusicEffect:
  25031. result = "Effect";
  25032. break;
  25033. case kAudioUnitType_MusicDevice:
  25034. result = "Synth";
  25035. break;
  25036. case kAudioUnitType_Generator:
  25037. result = "Generator";
  25038. break;
  25039. case kAudioUnitType_Panner:
  25040. result = "Panner";
  25041. break;
  25042. default:
  25043. break;
  25044. }
  25045. return result;
  25046. }
  25047. int AudioUnitPluginInstance::getNumParameters()
  25048. {
  25049. return parameterIds.size();
  25050. }
  25051. float AudioUnitPluginInstance::getParameter (int index)
  25052. {
  25053. const ScopedLock sl (lock);
  25054. Float32 value = 0.0f;
  25055. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25056. {
  25057. AudioUnitGetParameter (audioUnit,
  25058. (UInt32) parameterIds.getUnchecked (index),
  25059. kAudioUnitScope_Global, 0,
  25060. &value);
  25061. }
  25062. return value;
  25063. }
  25064. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25065. {
  25066. const ScopedLock sl (lock);
  25067. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25068. {
  25069. AudioUnitSetParameter (audioUnit,
  25070. (UInt32) parameterIds.getUnchecked (index),
  25071. kAudioUnitScope_Global, 0,
  25072. newValue, 0);
  25073. }
  25074. }
  25075. const String AudioUnitPluginInstance::getParameterName (int index)
  25076. {
  25077. AudioUnitParameterInfo info;
  25078. zerostruct (info);
  25079. UInt32 sz = sizeof (info);
  25080. String name;
  25081. if (AudioUnitGetProperty (audioUnit,
  25082. kAudioUnitProperty_ParameterInfo,
  25083. kAudioUnitScope_Global,
  25084. parameterIds [index], &info, &sz) == noErr)
  25085. {
  25086. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25087. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25088. else
  25089. name = String (info.name, sizeof (info.name));
  25090. }
  25091. return name;
  25092. }
  25093. const String AudioUnitPluginInstance::getParameterText (int index)
  25094. {
  25095. return String (getParameter (index));
  25096. }
  25097. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25098. {
  25099. AudioUnitParameterInfo info;
  25100. UInt32 sz = sizeof (info);
  25101. if (AudioUnitGetProperty (audioUnit,
  25102. kAudioUnitProperty_ParameterInfo,
  25103. kAudioUnitScope_Global,
  25104. parameterIds [index], &info, &sz) == noErr)
  25105. {
  25106. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25107. }
  25108. return true;
  25109. }
  25110. int AudioUnitPluginInstance::getNumPrograms()
  25111. {
  25112. CFArrayRef presets;
  25113. UInt32 sz = sizeof (CFArrayRef);
  25114. int num = 0;
  25115. if (AudioUnitGetProperty (audioUnit,
  25116. kAudioUnitProperty_FactoryPresets,
  25117. kAudioUnitScope_Global,
  25118. 0, &presets, &sz) == noErr)
  25119. {
  25120. num = (int) CFArrayGetCount (presets);
  25121. CFRelease (presets);
  25122. }
  25123. return num;
  25124. }
  25125. int AudioUnitPluginInstance::getCurrentProgram()
  25126. {
  25127. AUPreset current;
  25128. current.presetNumber = 0;
  25129. UInt32 sz = sizeof (AUPreset);
  25130. AudioUnitGetProperty (audioUnit,
  25131. kAudioUnitProperty_FactoryPresets,
  25132. kAudioUnitScope_Global,
  25133. 0, &current, &sz);
  25134. return current.presetNumber;
  25135. }
  25136. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25137. {
  25138. AUPreset current;
  25139. current.presetNumber = newIndex;
  25140. current.presetName = 0;
  25141. AudioUnitSetProperty (audioUnit,
  25142. kAudioUnitProperty_FactoryPresets,
  25143. kAudioUnitScope_Global,
  25144. 0, &current, sizeof (AUPreset));
  25145. }
  25146. const String AudioUnitPluginInstance::getProgramName (int index)
  25147. {
  25148. String s;
  25149. CFArrayRef presets;
  25150. UInt32 sz = sizeof (CFArrayRef);
  25151. if (AudioUnitGetProperty (audioUnit,
  25152. kAudioUnitProperty_FactoryPresets,
  25153. kAudioUnitScope_Global,
  25154. 0, &presets, &sz) == noErr)
  25155. {
  25156. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25157. {
  25158. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25159. if (p != 0 && p->presetNumber == index)
  25160. {
  25161. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25162. break;
  25163. }
  25164. }
  25165. CFRelease (presets);
  25166. }
  25167. return s;
  25168. }
  25169. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25170. {
  25171. jassertfalse // xxx not implemented!
  25172. }
  25173. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25174. {
  25175. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25176. return T("Input ") + String (index + 1);
  25177. return String::empty;
  25178. }
  25179. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25180. {
  25181. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25182. return false;
  25183. return true;
  25184. }
  25185. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25186. {
  25187. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25188. return T("Output ") + String (index + 1);
  25189. return String::empty;
  25190. }
  25191. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25192. {
  25193. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25194. return false;
  25195. return true;
  25196. }
  25197. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25198. {
  25199. getCurrentProgramStateInformation (destData);
  25200. }
  25201. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25202. {
  25203. CFPropertyListRef propertyList = 0;
  25204. UInt32 sz = sizeof (CFPropertyListRef);
  25205. if (AudioUnitGetProperty (audioUnit,
  25206. kAudioUnitProperty_ClassInfo,
  25207. kAudioUnitScope_Global,
  25208. 0, &propertyList, &sz) == noErr)
  25209. {
  25210. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25211. CFWriteStreamOpen (stream);
  25212. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25213. CFWriteStreamClose (stream);
  25214. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25215. destData.setSize (bytesWritten);
  25216. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25217. CFRelease (data);
  25218. CFRelease (stream);
  25219. CFRelease (propertyList);
  25220. }
  25221. }
  25222. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25223. {
  25224. setCurrentProgramStateInformation (data, sizeInBytes);
  25225. }
  25226. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25227. {
  25228. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25229. (const UInt8*) data,
  25230. sizeInBytes,
  25231. kCFAllocatorNull);
  25232. CFReadStreamOpen (stream);
  25233. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25234. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25235. stream,
  25236. 0,
  25237. kCFPropertyListImmutable,
  25238. &format,
  25239. 0);
  25240. CFRelease (stream);
  25241. if (propertyList != 0)
  25242. AudioUnitSetProperty (audioUnit,
  25243. kAudioUnitProperty_ClassInfo,
  25244. kAudioUnitScope_Global,
  25245. 0, &propertyList, sizeof (propertyList));
  25246. }
  25247. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25248. {
  25249. }
  25250. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25251. {
  25252. }
  25253. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25254. const String& fileOrIdentifier)
  25255. {
  25256. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25257. return;
  25258. PluginDescription desc;
  25259. desc.fileOrIdentifier = fileOrIdentifier;
  25260. desc.uid = 0;
  25261. try
  25262. {
  25263. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25264. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25265. if (auInstance != 0)
  25266. {
  25267. auInstance->fillInPluginDescription (desc);
  25268. results.add (new PluginDescription (desc));
  25269. }
  25270. }
  25271. catch (...)
  25272. {
  25273. // crashed while loading...
  25274. }
  25275. }
  25276. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25277. {
  25278. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25279. {
  25280. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25281. if (result->audioUnit != 0)
  25282. {
  25283. result->initialise();
  25284. return result.release();
  25285. }
  25286. }
  25287. return 0;
  25288. }
  25289. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25290. const bool /*recursive*/)
  25291. {
  25292. StringArray result;
  25293. ComponentRecord* comp = 0;
  25294. ComponentDescription desc;
  25295. zerostruct (desc);
  25296. for (;;)
  25297. {
  25298. zerostruct (desc);
  25299. comp = FindNextComponent (comp, &desc);
  25300. if (comp == 0)
  25301. break;
  25302. GetComponentInfo (comp, &desc, 0, 0, 0);
  25303. if (desc.componentType == kAudioUnitType_MusicDevice
  25304. || desc.componentType == kAudioUnitType_MusicEffect
  25305. || desc.componentType == kAudioUnitType_Effect
  25306. || desc.componentType == kAudioUnitType_Generator
  25307. || desc.componentType == kAudioUnitType_Panner)
  25308. {
  25309. const String s (createAUPluginIdentifier (desc));
  25310. DBG (s);
  25311. result.add (s);
  25312. }
  25313. }
  25314. return result;
  25315. }
  25316. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25317. {
  25318. ComponentDescription desc;
  25319. String name, version, manufacturer;
  25320. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25321. return FindNextComponent (0, &desc) != 0;
  25322. const File f (fileOrIdentifier);
  25323. return f.hasFileExtension (T(".component"))
  25324. && f.isDirectory();
  25325. }
  25326. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25327. {
  25328. ComponentDescription desc;
  25329. String name, version, manufacturer;
  25330. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25331. if (name.isEmpty())
  25332. name = fileOrIdentifier;
  25333. return name;
  25334. }
  25335. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25336. {
  25337. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25338. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25339. else
  25340. return File (desc.fileOrIdentifier).exists();
  25341. }
  25342. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25343. {
  25344. return FileSearchPath ("/(Default AudioUnit locations)");
  25345. }
  25346. #endif
  25347. END_JUCE_NAMESPACE
  25348. #undef log
  25349. #endif
  25350. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25351. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25352. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25353. #define JUCE_MAC_VST_INCLUDED 1
  25354. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25355. #if JUCE_PLUGINHOST_VST
  25356. #if (defined (_WIN32) || defined (_WIN64))
  25357. #undef _WIN32_WINNT
  25358. #define _WIN32_WINNT 0x500
  25359. #undef STRICT
  25360. #define STRICT
  25361. #include <windows.h>
  25362. #include <float.h>
  25363. #pragma warning (disable : 4312 4355)
  25364. #elif defined (LINUX) || defined (__linux__)
  25365. #include <float.h>
  25366. #include <sys/time.h>
  25367. #include <X11/Xlib.h>
  25368. #include <X11/Xutil.h>
  25369. #include <X11/Xatom.h>
  25370. #undef Font
  25371. #undef KeyPress
  25372. #undef Drawable
  25373. #undef Time
  25374. #else
  25375. #ifndef JUCE_MAC_VST_INCLUDED
  25376. // On the mac, this file needs to be compiled indirectly, by using
  25377. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25378. #error
  25379. #endif
  25380. #include <Cocoa/Cocoa.h>
  25381. #include <Carbon/Carbon.h>
  25382. #endif
  25383. #if ! (JUCE_MAC && JUCE_64BIT)
  25384. BEGIN_JUCE_NAMESPACE
  25385. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25386. #endif
  25387. #undef PRAGMA_ALIGN_SUPPORTED
  25388. #define VST_FORCE_DEPRECATED 0
  25389. #ifdef _MSC_VER
  25390. #pragma warning (push)
  25391. #pragma warning (disable: 4996)
  25392. #endif
  25393. #include "pluginterfaces/vst2.x/aeffectx.h"
  25394. #ifdef _MSC_VER
  25395. #pragma warning (pop)
  25396. #endif
  25397. #if JUCE_LINUX
  25398. #define Font JUCE_NAMESPACE::Font
  25399. #define KeyPress JUCE_NAMESPACE::KeyPress
  25400. #define Drawable JUCE_NAMESPACE::Drawable
  25401. #define Time JUCE_NAMESPACE::Time
  25402. #endif
  25403. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25404. #ifdef __aeffect__
  25405. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25406. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25407. class VSTMidiEventList
  25408. {
  25409. public:
  25410. VSTMidiEventList()
  25411. : numEventsUsed (0), numEventsAllocated (0)
  25412. {
  25413. }
  25414. ~VSTMidiEventList()
  25415. {
  25416. freeEvents();
  25417. }
  25418. void clear()
  25419. {
  25420. numEventsUsed = 0;
  25421. if (events != 0)
  25422. events->numEvents = 0;
  25423. }
  25424. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25425. {
  25426. ensureSize (numEventsUsed + 1);
  25427. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25428. events->numEvents = ++numEventsUsed;
  25429. if (numBytes <= 4)
  25430. {
  25431. if (e->type == kVstSysExType)
  25432. {
  25433. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25434. e->type = kVstMidiType;
  25435. e->byteSize = sizeof (VstMidiEvent);
  25436. e->noteLength = 0;
  25437. e->noteOffset = 0;
  25438. e->detune = 0;
  25439. e->noteOffVelocity = 0;
  25440. }
  25441. e->deltaFrames = frameOffset;
  25442. memcpy (e->midiData, midiData, numBytes);
  25443. }
  25444. else
  25445. {
  25446. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25447. if (se->type == kVstSysExType)
  25448. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25449. else
  25450. se->sysexDump = (char*) juce_malloc (numBytes);
  25451. memcpy (se->sysexDump, midiData, numBytes);
  25452. se->type = kVstSysExType;
  25453. se->byteSize = sizeof (VstMidiSysexEvent);
  25454. se->deltaFrames = frameOffset;
  25455. se->flags = 0;
  25456. se->dumpBytes = numBytes;
  25457. se->resvd1 = 0;
  25458. se->resvd2 = 0;
  25459. }
  25460. }
  25461. // Handy method to pull the events out of an event buffer supplied by the host
  25462. // or plugin.
  25463. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25464. {
  25465. for (int i = 0; i < events->numEvents; ++i)
  25466. {
  25467. const VstEvent* const e = events->events[i];
  25468. if (e != 0)
  25469. {
  25470. if (e->type == kVstMidiType)
  25471. {
  25472. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25473. 4, e->deltaFrames);
  25474. }
  25475. else if (e->type == kVstSysExType)
  25476. {
  25477. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25478. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25479. e->deltaFrames);
  25480. }
  25481. }
  25482. }
  25483. }
  25484. void ensureSize (int numEventsNeeded)
  25485. {
  25486. if (numEventsNeeded > numEventsAllocated)
  25487. {
  25488. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25489. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25490. if (events == 0)
  25491. events.calloc (size, 1);
  25492. else
  25493. events.realloc (size, 1);
  25494. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25495. {
  25496. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25497. (int) sizeof (VstMidiSysexEvent)));
  25498. e->type = kVstMidiType;
  25499. e->byteSize = sizeof (VstMidiEvent);
  25500. events->events[i] = (VstEvent*) e;
  25501. }
  25502. numEventsAllocated = numEventsNeeded;
  25503. }
  25504. }
  25505. void freeEvents()
  25506. {
  25507. if (events != 0)
  25508. {
  25509. for (int i = numEventsAllocated; --i >= 0;)
  25510. {
  25511. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25512. if (e->type == kVstSysExType)
  25513. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25514. juce_free (e);
  25515. }
  25516. events.free();
  25517. numEventsUsed = 0;
  25518. numEventsAllocated = 0;
  25519. }
  25520. }
  25521. HeapBlock <VstEvents> events;
  25522. private:
  25523. int numEventsUsed, numEventsAllocated;
  25524. };
  25525. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25526. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25527. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25528. #if ! JUCE_WIN32
  25529. #define _fpreset()
  25530. #define _clearfp()
  25531. #endif
  25532. extern void juce_callAnyTimersSynchronously();
  25533. const int fxbVersionNum = 1;
  25534. struct fxProgram
  25535. {
  25536. long chunkMagic; // 'CcnK'
  25537. long byteSize; // of this chunk, excl. magic + byteSize
  25538. long fxMagic; // 'FxCk'
  25539. long version;
  25540. long fxID; // fx unique id
  25541. long fxVersion;
  25542. long numParams;
  25543. char prgName[28];
  25544. float params[1]; // variable no. of parameters
  25545. };
  25546. struct fxSet
  25547. {
  25548. long chunkMagic; // 'CcnK'
  25549. long byteSize; // of this chunk, excl. magic + byteSize
  25550. long fxMagic; // 'FxBk'
  25551. long version;
  25552. long fxID; // fx unique id
  25553. long fxVersion;
  25554. long numPrograms;
  25555. char future[128];
  25556. fxProgram programs[1]; // variable no. of programs
  25557. };
  25558. struct fxChunkSet
  25559. {
  25560. long chunkMagic; // 'CcnK'
  25561. long byteSize; // of this chunk, excl. magic + byteSize
  25562. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25563. long version;
  25564. long fxID; // fx unique id
  25565. long fxVersion;
  25566. long numPrograms;
  25567. char future[128];
  25568. long chunkSize;
  25569. char chunk[8]; // variable
  25570. };
  25571. struct fxProgramSet
  25572. {
  25573. long chunkMagic; // 'CcnK'
  25574. long byteSize; // of this chunk, excl. magic + byteSize
  25575. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25576. long version;
  25577. long fxID; // fx unique id
  25578. long fxVersion;
  25579. long numPrograms;
  25580. char name[28];
  25581. long chunkSize;
  25582. char chunk[8]; // variable
  25583. };
  25584. static long vst_swap (const long x) throw()
  25585. {
  25586. #ifdef JUCE_LITTLE_ENDIAN
  25587. return (long) ByteOrder::swap ((uint32) x);
  25588. #else
  25589. return x;
  25590. #endif
  25591. }
  25592. static float vst_swapFloat (const float x) throw()
  25593. {
  25594. #ifdef JUCE_LITTLE_ENDIAN
  25595. union { uint32 asInt; float asFloat; } n;
  25596. n.asFloat = x;
  25597. n.asInt = ByteOrder::swap (n.asInt);
  25598. return n.asFloat;
  25599. #else
  25600. return x;
  25601. #endif
  25602. }
  25603. typedef AEffect* (*MainCall) (audioMasterCallback);
  25604. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25605. static int shellUIDToCreate = 0;
  25606. static int insideVSTCallback = 0;
  25607. class VSTPluginWindow;
  25608. // Change this to disable logging of various VST activities
  25609. #ifndef VST_LOGGING
  25610. #define VST_LOGGING 1
  25611. #endif
  25612. #if VST_LOGGING
  25613. #define log(a) Logger::writeToLog(a);
  25614. #else
  25615. #define log(a)
  25616. #endif
  25617. #if JUCE_MAC && JUCE_PPC
  25618. static void* NewCFMFromMachO (void* const machofp) throw()
  25619. {
  25620. void* result = juce_malloc (8);
  25621. ((void**) result)[0] = machofp;
  25622. ((void**) result)[1] = result;
  25623. return result;
  25624. }
  25625. #endif
  25626. #if JUCE_LINUX
  25627. extern Display* display;
  25628. extern XContext improbableNumber;
  25629. typedef void (*EventProcPtr) (XEvent* ev);
  25630. static bool xErrorTriggered;
  25631. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25632. {
  25633. xErrorTriggered = true;
  25634. return 0;
  25635. }
  25636. static int getPropertyFromXWindow (Window handle, Atom atom)
  25637. {
  25638. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25639. xErrorTriggered = false;
  25640. int userSize;
  25641. unsigned long bytes, userCount;
  25642. unsigned char* data;
  25643. Atom userType;
  25644. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25645. &userType, &userSize, &userCount, &bytes, &data);
  25646. XSetErrorHandler (oldErrorHandler);
  25647. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25648. : 0;
  25649. }
  25650. static Window getChildWindow (Window windowToCheck)
  25651. {
  25652. Window rootWindow, parentWindow;
  25653. Window* childWindows;
  25654. unsigned int numChildren;
  25655. XQueryTree (display,
  25656. windowToCheck,
  25657. &rootWindow,
  25658. &parentWindow,
  25659. &childWindows,
  25660. &numChildren);
  25661. if (numChildren > 0)
  25662. return childWindows [0];
  25663. return 0;
  25664. }
  25665. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25666. {
  25667. if (e.mods.isLeftButtonDown())
  25668. {
  25669. ev.xbutton.button = Button1;
  25670. ev.xbutton.state |= Button1Mask;
  25671. }
  25672. else if (e.mods.isRightButtonDown())
  25673. {
  25674. ev.xbutton.button = Button3;
  25675. ev.xbutton.state |= Button3Mask;
  25676. }
  25677. else if (e.mods.isMiddleButtonDown())
  25678. {
  25679. ev.xbutton.button = Button2;
  25680. ev.xbutton.state |= Button2Mask;
  25681. }
  25682. }
  25683. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25684. {
  25685. if (e.mods.isLeftButtonDown())
  25686. ev.xmotion.state |= Button1Mask;
  25687. else if (e.mods.isRightButtonDown())
  25688. ev.xmotion.state |= Button3Mask;
  25689. else if (e.mods.isMiddleButtonDown())
  25690. ev.xmotion.state |= Button2Mask;
  25691. }
  25692. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25693. {
  25694. if (e.mods.isLeftButtonDown())
  25695. ev.xcrossing.state |= Button1Mask;
  25696. else if (e.mods.isRightButtonDown())
  25697. ev.xcrossing.state |= Button3Mask;
  25698. else if (e.mods.isMiddleButtonDown())
  25699. ev.xcrossing.state |= Button2Mask;
  25700. }
  25701. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25702. {
  25703. if (increment < 0)
  25704. {
  25705. ev.xbutton.button = Button5;
  25706. ev.xbutton.state |= Button5Mask;
  25707. }
  25708. else if (increment > 0)
  25709. {
  25710. ev.xbutton.button = Button4;
  25711. ev.xbutton.state |= Button4Mask;
  25712. }
  25713. }
  25714. #endif
  25715. static VoidArray activeModules;
  25716. class ModuleHandle : public ReferenceCountedObject
  25717. {
  25718. public:
  25719. File file;
  25720. MainCall moduleMain;
  25721. String pluginName;
  25722. static ModuleHandle* findOrCreateModule (const File& file)
  25723. {
  25724. for (int i = activeModules.size(); --i >= 0;)
  25725. {
  25726. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25727. if (module->file == file)
  25728. return module;
  25729. }
  25730. _fpreset(); // (doesn't do any harm)
  25731. ++insideVSTCallback;
  25732. shellUIDToCreate = 0;
  25733. log ("Attempting to load VST: " + file.getFullPathName());
  25734. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25735. if (! m->open())
  25736. m = 0;
  25737. --insideVSTCallback;
  25738. _fpreset(); // (doesn't do any harm)
  25739. return m.release();
  25740. }
  25741. ModuleHandle (const File& file_)
  25742. : file (file_),
  25743. moduleMain (0),
  25744. #if JUCE_WIN32 || JUCE_LINUX
  25745. hModule (0)
  25746. #elif JUCE_MAC
  25747. fragId (0),
  25748. resHandle (0),
  25749. bundleRef (0),
  25750. resFileId (0)
  25751. #endif
  25752. {
  25753. activeModules.add (this);
  25754. #if JUCE_WIN32 || JUCE_LINUX
  25755. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25756. #elif JUCE_MAC
  25757. FSRef ref;
  25758. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25759. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25760. #endif
  25761. }
  25762. ~ModuleHandle()
  25763. {
  25764. activeModules.removeValue (this);
  25765. close();
  25766. }
  25767. juce_UseDebuggingNewOperator
  25768. #if JUCE_WIN32 || JUCE_LINUX
  25769. void* hModule;
  25770. String fullParentDirectoryPathName;
  25771. bool open()
  25772. {
  25773. #if JUCE_WIN32
  25774. static bool timePeriodSet = false;
  25775. if (! timePeriodSet)
  25776. {
  25777. timePeriodSet = true;
  25778. timeBeginPeriod (2);
  25779. }
  25780. #endif
  25781. pluginName = file.getFileNameWithoutExtension();
  25782. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25783. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25784. if (moduleMain == 0)
  25785. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25786. return moduleMain != 0;
  25787. }
  25788. void close()
  25789. {
  25790. _fpreset(); // (doesn't do any harm)
  25791. PlatformUtilities::freeDynamicLibrary (hModule);
  25792. }
  25793. void closeEffect (AEffect* eff)
  25794. {
  25795. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25796. }
  25797. #else
  25798. CFragConnectionID fragId;
  25799. Handle resHandle;
  25800. CFBundleRef bundleRef;
  25801. FSSpec parentDirFSSpec;
  25802. short resFileId;
  25803. bool open()
  25804. {
  25805. bool ok = false;
  25806. const String filename (file.getFullPathName());
  25807. if (file.hasFileExtension (T(".vst")))
  25808. {
  25809. const char* const utf8 = filename.toUTF8();
  25810. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25811. strlen (utf8), file.isDirectory());
  25812. if (url != 0)
  25813. {
  25814. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25815. CFRelease (url);
  25816. if (bundleRef != 0)
  25817. {
  25818. if (CFBundleLoadExecutable (bundleRef))
  25819. {
  25820. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25821. if (moduleMain == 0)
  25822. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25823. if (moduleMain != 0)
  25824. {
  25825. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25826. if (name != 0)
  25827. {
  25828. if (CFGetTypeID (name) == CFStringGetTypeID())
  25829. {
  25830. char buffer[1024];
  25831. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25832. pluginName = buffer;
  25833. }
  25834. }
  25835. if (pluginName.isEmpty())
  25836. pluginName = file.getFileNameWithoutExtension();
  25837. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25838. ok = true;
  25839. }
  25840. }
  25841. if (! ok)
  25842. {
  25843. CFBundleUnloadExecutable (bundleRef);
  25844. CFRelease (bundleRef);
  25845. bundleRef = 0;
  25846. }
  25847. }
  25848. }
  25849. }
  25850. #if JUCE_PPC
  25851. else
  25852. {
  25853. FSRef fn;
  25854. if (FSPathMakeRef ((UInt8*) (const char*) filename, &fn, 0) == noErr)
  25855. {
  25856. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25857. if (resFileId != -1)
  25858. {
  25859. const int numEffs = Count1Resources ('aEff');
  25860. for (int i = 0; i < numEffs; ++i)
  25861. {
  25862. resHandle = Get1IndResource ('aEff', i + 1);
  25863. if (resHandle != 0)
  25864. {
  25865. OSType type;
  25866. Str255 name;
  25867. SInt16 id;
  25868. GetResInfo (resHandle, &id, &type, name);
  25869. pluginName = String ((const char*) name + 1, name[0]);
  25870. DetachResource (resHandle);
  25871. HLock (resHandle);
  25872. Ptr ptr;
  25873. Str255 errorText;
  25874. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25875. name, kPrivateCFragCopy,
  25876. &fragId, &ptr, errorText);
  25877. if (err == noErr)
  25878. {
  25879. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25880. ok = true;
  25881. }
  25882. else
  25883. {
  25884. HUnlock (resHandle);
  25885. }
  25886. break;
  25887. }
  25888. }
  25889. if (! ok)
  25890. CloseResFile (resFileId);
  25891. }
  25892. }
  25893. }
  25894. #endif
  25895. return ok;
  25896. }
  25897. void close()
  25898. {
  25899. #if JUCE_PPC
  25900. if (fragId != 0)
  25901. {
  25902. if (moduleMain != 0)
  25903. disposeMachOFromCFM ((void*) moduleMain);
  25904. CloseConnection (&fragId);
  25905. HUnlock (resHandle);
  25906. if (resFileId != 0)
  25907. CloseResFile (resFileId);
  25908. }
  25909. else
  25910. #endif
  25911. if (bundleRef != 0)
  25912. {
  25913. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25914. if (CFGetRetainCount (bundleRef) == 1)
  25915. CFBundleUnloadExecutable (bundleRef);
  25916. if (CFGetRetainCount (bundleRef) > 0)
  25917. CFRelease (bundleRef);
  25918. }
  25919. }
  25920. void closeEffect (AEffect* eff)
  25921. {
  25922. #if JUCE_PPC
  25923. if (fragId != 0)
  25924. {
  25925. VoidArray thingsToDelete;
  25926. thingsToDelete.add ((void*) eff->dispatcher);
  25927. thingsToDelete.add ((void*) eff->process);
  25928. thingsToDelete.add ((void*) eff->setParameter);
  25929. thingsToDelete.add ((void*) eff->getParameter);
  25930. thingsToDelete.add ((void*) eff->processReplacing);
  25931. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25932. for (int i = thingsToDelete.size(); --i >= 0;)
  25933. disposeMachOFromCFM (thingsToDelete[i]);
  25934. }
  25935. else
  25936. #endif
  25937. {
  25938. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25939. }
  25940. }
  25941. #if JUCE_PPC
  25942. static void* newMachOFromCFM (void* cfmfp)
  25943. {
  25944. if (cfmfp == 0)
  25945. return 0;
  25946. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25947. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25948. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25949. mfp[2] = 0x800c0000;
  25950. mfp[3] = 0x804c0004;
  25951. mfp[4] = 0x7c0903a6;
  25952. mfp[5] = 0x4e800420;
  25953. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25954. return mfp;
  25955. }
  25956. static void disposeMachOFromCFM (void* ptr)
  25957. {
  25958. juce_free (ptr);
  25959. }
  25960. void coerceAEffectFunctionCalls (AEffect* eff)
  25961. {
  25962. if (fragId != 0)
  25963. {
  25964. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25965. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25966. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25967. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25968. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25969. }
  25970. }
  25971. #endif
  25972. #endif
  25973. };
  25974. class VSTPluginInstance : public AudioPluginInstance,
  25975. private Timer,
  25976. private AsyncUpdater
  25977. {
  25978. public:
  25979. ~VSTPluginInstance();
  25980. // AudioPluginInstance methods:
  25981. void fillInPluginDescription (PluginDescription& desc) const
  25982. {
  25983. desc.name = name;
  25984. desc.fileOrIdentifier = module->file.getFullPathName();
  25985. desc.uid = getUID();
  25986. desc.lastFileModTime = module->file.getLastModificationTime();
  25987. desc.pluginFormatName = "VST";
  25988. desc.category = getCategory();
  25989. {
  25990. char buffer [kVstMaxVendorStrLen + 8];
  25991. zerostruct (buffer);
  25992. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25993. desc.manufacturerName = buffer;
  25994. }
  25995. desc.version = getVersion();
  25996. desc.numInputChannels = getNumInputChannels();
  25997. desc.numOutputChannels = getNumOutputChannels();
  25998. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25999. }
  26000. const String getName() const { return name; }
  26001. int getUID() const throw();
  26002. bool acceptsMidi() const { return wantsMidiMessages; }
  26003. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  26004. // AudioProcessor methods:
  26005. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  26006. void releaseResources();
  26007. void processBlock (AudioSampleBuffer& buffer,
  26008. MidiBuffer& midiMessages);
  26009. AudioProcessorEditor* createEditor();
  26010. const String getInputChannelName (const int index) const;
  26011. bool isInputChannelStereoPair (int index) const;
  26012. const String getOutputChannelName (const int index) const;
  26013. bool isOutputChannelStereoPair (int index) const;
  26014. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  26015. float getParameter (int index);
  26016. void setParameter (int index, float newValue);
  26017. const String getParameterName (int index);
  26018. const String getParameterText (int index);
  26019. bool isParameterAutomatable (int index) const;
  26020. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  26021. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  26022. void setCurrentProgram (int index);
  26023. const String getProgramName (int index);
  26024. void changeProgramName (int index, const String& newName);
  26025. void getStateInformation (MemoryBlock& destData);
  26026. void getCurrentProgramStateInformation (MemoryBlock& destData);
  26027. void setStateInformation (const void* data, int sizeInBytes);
  26028. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  26029. void timerCallback();
  26030. void handleAsyncUpdate();
  26031. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  26032. juce_UseDebuggingNewOperator
  26033. private:
  26034. friend class VSTPluginWindow;
  26035. friend class VSTPluginFormat;
  26036. AEffect* effect;
  26037. String name;
  26038. CriticalSection lock;
  26039. bool wantsMidiMessages, initialised, isPowerOn;
  26040. mutable StringArray programNames;
  26041. AudioSampleBuffer tempBuffer;
  26042. CriticalSection midiInLock;
  26043. MidiBuffer incomingMidi;
  26044. VSTMidiEventList midiEventsToSend;
  26045. VstTimeInfo vstHostTime;
  26046. HeapBlock <float*> channels;
  26047. ReferenceCountedObjectPtr <ModuleHandle> module;
  26048. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  26049. bool restoreProgramSettings (const fxProgram* const prog);
  26050. const String getCurrentProgramName();
  26051. void setParamsInProgramBlock (fxProgram* const prog) throw();
  26052. void updateStoredProgramNames();
  26053. void initialise();
  26054. void handleMidiFromPlugin (const VstEvents* const events);
  26055. void createTempParameterStore (MemoryBlock& dest);
  26056. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26057. const String getParameterLabel (int index) const;
  26058. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26059. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26060. void setChunkData (const char* data, int size, bool isPreset);
  26061. bool loadFromFXBFile (const void* data, int numBytes);
  26062. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26063. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26064. const String getVersion() const throw();
  26065. const String getCategory() const throw();
  26066. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26067. void setPower (const bool on);
  26068. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26069. };
  26070. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26071. : effect (0),
  26072. wantsMidiMessages (false),
  26073. initialised (false),
  26074. isPowerOn (false),
  26075. tempBuffer (1, 1),
  26076. module (module_)
  26077. {
  26078. try
  26079. {
  26080. _fpreset();
  26081. ++insideVSTCallback;
  26082. name = module->pluginName;
  26083. log (T("Creating VST instance: ") + name);
  26084. #if JUCE_MAC
  26085. if (module->resFileId != 0)
  26086. UseResFile (module->resFileId);
  26087. #if JUCE_PPC
  26088. if (module->fragId != 0)
  26089. {
  26090. static void* audioMasterCoerced = 0;
  26091. if (audioMasterCoerced == 0)
  26092. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26093. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26094. }
  26095. else
  26096. #endif
  26097. #endif
  26098. {
  26099. effect = module->moduleMain (&audioMaster);
  26100. }
  26101. --insideVSTCallback;
  26102. if (effect != 0 && effect->magic == kEffectMagic)
  26103. {
  26104. #if JUCE_PPC
  26105. module->coerceAEffectFunctionCalls (effect);
  26106. #endif
  26107. jassert (effect->resvd2 == 0);
  26108. jassert (effect->object != 0);
  26109. _fpreset(); // some dodgy plugs fuck around with this
  26110. }
  26111. else
  26112. {
  26113. effect = 0;
  26114. }
  26115. }
  26116. catch (...)
  26117. {
  26118. --insideVSTCallback;
  26119. }
  26120. }
  26121. VSTPluginInstance::~VSTPluginInstance()
  26122. {
  26123. {
  26124. const ScopedLock sl (lock);
  26125. jassert (insideVSTCallback == 0);
  26126. if (effect != 0 && effect->magic == kEffectMagic)
  26127. {
  26128. try
  26129. {
  26130. #if JUCE_MAC
  26131. if (module->resFileId != 0)
  26132. UseResFile (module->resFileId);
  26133. #endif
  26134. // Must delete any editors before deleting the plugin instance!
  26135. jassert (getActiveEditor() == 0);
  26136. _fpreset(); // some dodgy plugs fuck around with this
  26137. module->closeEffect (effect);
  26138. }
  26139. catch (...)
  26140. {}
  26141. }
  26142. module = 0;
  26143. effect = 0;
  26144. }
  26145. }
  26146. void VSTPluginInstance::initialise()
  26147. {
  26148. if (initialised || effect == 0)
  26149. return;
  26150. log (T("Initialising VST: ") + module->pluginName);
  26151. initialised = true;
  26152. dispatch (effIdentify, 0, 0, 0, 0);
  26153. // this code would ask the plugin for its name, but so few plugins
  26154. // actually bother implementing this correctly, that it's better to
  26155. // just ignore it and use the file name instead.
  26156. if (getSampleRate() > 0)
  26157. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26158. if (getBlockSize() > 0)
  26159. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26160. dispatch (effOpen, 0, 0, 0, 0);
  26161. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26162. getSampleRate(), getBlockSize());
  26163. if (getNumPrograms() > 1)
  26164. setCurrentProgram (0);
  26165. else
  26166. dispatch (effSetProgram, 0, 0, 0, 0);
  26167. int i;
  26168. for (i = effect->numInputs; --i >= 0;)
  26169. dispatch (effConnectInput, i, 1, 0, 0);
  26170. for (i = effect->numOutputs; --i >= 0;)
  26171. dispatch (effConnectOutput, i, 1, 0, 0);
  26172. updateStoredProgramNames();
  26173. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26174. setLatencySamples (effect->initialDelay);
  26175. }
  26176. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26177. int samplesPerBlockExpected)
  26178. {
  26179. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26180. sampleRate_, samplesPerBlockExpected);
  26181. setLatencySamples (effect->initialDelay);
  26182. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26183. vstHostTime.tempo = 120.0;
  26184. vstHostTime.timeSigNumerator = 4;
  26185. vstHostTime.timeSigDenominator = 4;
  26186. vstHostTime.sampleRate = sampleRate_;
  26187. vstHostTime.samplePos = 0;
  26188. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26189. initialise();
  26190. if (initialised)
  26191. {
  26192. wantsMidiMessages = wantsMidiMessages
  26193. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26194. if (wantsMidiMessages)
  26195. midiEventsToSend.ensureSize (256);
  26196. else
  26197. midiEventsToSend.freeEvents();
  26198. incomingMidi.clear();
  26199. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26200. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26201. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26202. if (! isPowerOn)
  26203. setPower (true);
  26204. // dodgy hack to force some plugins to initialise the sample rate..
  26205. if ((! hasEditor()) && getNumParameters() > 0)
  26206. {
  26207. const float old = getParameter (0);
  26208. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26209. setParameter (0, old);
  26210. }
  26211. dispatch (effStartProcess, 0, 0, 0, 0);
  26212. }
  26213. }
  26214. void VSTPluginInstance::releaseResources()
  26215. {
  26216. if (initialised)
  26217. {
  26218. dispatch (effStopProcess, 0, 0, 0, 0);
  26219. setPower (false);
  26220. }
  26221. tempBuffer.setSize (1, 1);
  26222. incomingMidi.clear();
  26223. midiEventsToSend.freeEvents();
  26224. channels.free();
  26225. }
  26226. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26227. MidiBuffer& midiMessages)
  26228. {
  26229. const int numSamples = buffer.getNumSamples();
  26230. if (initialised)
  26231. {
  26232. AudioPlayHead* playHead = getPlayHead();
  26233. if (playHead != 0)
  26234. {
  26235. AudioPlayHead::CurrentPositionInfo position;
  26236. playHead->getCurrentPosition (position);
  26237. vstHostTime.tempo = position.bpm;
  26238. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26239. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26240. vstHostTime.ppqPos = position.ppqPosition;
  26241. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26242. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26243. if (position.isPlaying)
  26244. vstHostTime.flags |= kVstTransportPlaying;
  26245. else
  26246. vstHostTime.flags &= ~kVstTransportPlaying;
  26247. }
  26248. #if JUCE_WIN32
  26249. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26250. #elif JUCE_LINUX
  26251. timeval micro;
  26252. gettimeofday (&micro, 0);
  26253. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26254. #elif JUCE_MAC
  26255. UnsignedWide micro;
  26256. Microseconds (&micro);
  26257. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26258. #endif
  26259. if (wantsMidiMessages)
  26260. {
  26261. midiEventsToSend.clear();
  26262. midiEventsToSend.ensureSize (1);
  26263. MidiBuffer::Iterator iter (midiMessages);
  26264. const uint8* midiData;
  26265. int numBytesOfMidiData, samplePosition;
  26266. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26267. {
  26268. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26269. jlimit (0, numSamples - 1, samplePosition));
  26270. }
  26271. try
  26272. {
  26273. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26274. }
  26275. catch (...)
  26276. {}
  26277. }
  26278. int i;
  26279. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26280. for (i = 0; i < maxChans; ++i)
  26281. channels[i] = buffer.getSampleData (i);
  26282. channels [maxChans] = 0;
  26283. _clearfp();
  26284. if ((effect->flags & effFlagsCanReplacing) != 0)
  26285. {
  26286. try
  26287. {
  26288. effect->processReplacing (effect, channels, channels, numSamples);
  26289. }
  26290. catch (...)
  26291. {}
  26292. }
  26293. else
  26294. {
  26295. tempBuffer.setSize (effect->numOutputs, numSamples);
  26296. tempBuffer.clear();
  26297. float* outs [64];
  26298. for (i = effect->numOutputs; --i >= 0;)
  26299. outs[i] = tempBuffer.getSampleData (i);
  26300. outs [effect->numOutputs] = 0;
  26301. try
  26302. {
  26303. effect->process (effect, channels, outs, numSamples);
  26304. }
  26305. catch (...)
  26306. {}
  26307. for (i = effect->numOutputs; --i >= 0;)
  26308. buffer.copyFrom (i, 0, outs[i], numSamples);
  26309. }
  26310. }
  26311. else
  26312. {
  26313. // Not initialised, so just bypass..
  26314. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26315. buffer.clear (i, 0, buffer.getNumSamples());
  26316. }
  26317. {
  26318. // copy any incoming midi..
  26319. const ScopedLock sl (midiInLock);
  26320. midiMessages = incomingMidi;
  26321. incomingMidi.clear();
  26322. }
  26323. }
  26324. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26325. {
  26326. if (events != 0)
  26327. {
  26328. const ScopedLock sl (midiInLock);
  26329. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26330. }
  26331. }
  26332. static Array <VSTPluginWindow*> activeVSTWindows;
  26333. class VSTPluginWindow : public AudioProcessorEditor,
  26334. #if ! JUCE_MAC
  26335. public ComponentMovementWatcher,
  26336. #endif
  26337. public Timer
  26338. {
  26339. public:
  26340. VSTPluginWindow (VSTPluginInstance& plugin_)
  26341. : AudioProcessorEditor (&plugin_),
  26342. #if ! JUCE_MAC
  26343. ComponentMovementWatcher (this),
  26344. #endif
  26345. plugin (plugin_),
  26346. isOpen (false),
  26347. wasShowing (false),
  26348. pluginRefusesToResize (false),
  26349. pluginWantsKeys (false),
  26350. alreadyInside (false),
  26351. recursiveResize (false)
  26352. {
  26353. #if JUCE_WIN32
  26354. sizeCheckCount = 0;
  26355. pluginHWND = 0;
  26356. #elif JUCE_LINUX
  26357. pluginWindow = None;
  26358. pluginProc = None;
  26359. #else
  26360. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26361. #endif
  26362. activeVSTWindows.add (this);
  26363. setSize (1, 1);
  26364. setOpaque (true);
  26365. setVisible (true);
  26366. }
  26367. ~VSTPluginWindow()
  26368. {
  26369. #if JUCE_MAC
  26370. innerWrapper = 0;
  26371. #else
  26372. closePluginWindow();
  26373. #endif
  26374. activeVSTWindows.removeValue (this);
  26375. plugin.editorBeingDeleted (this);
  26376. }
  26377. #if ! JUCE_MAC
  26378. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26379. {
  26380. if (recursiveResize)
  26381. return;
  26382. Component* const topComp = getTopLevelComponent();
  26383. if (topComp->getPeer() != 0)
  26384. {
  26385. int x = 0, y = 0;
  26386. relativePositionToOtherComponent (topComp, x, y);
  26387. recursiveResize = true;
  26388. #if JUCE_WIN32
  26389. if (pluginHWND != 0)
  26390. MoveWindow (pluginHWND, x, y, getWidth(), getHeight(), TRUE);
  26391. #elif JUCE_LINUX
  26392. if (pluginWindow != 0)
  26393. {
  26394. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26395. XMoveWindow (display, pluginWindow, x, y);
  26396. XMapRaised (display, pluginWindow);
  26397. }
  26398. #endif
  26399. recursiveResize = false;
  26400. }
  26401. }
  26402. void componentVisibilityChanged (Component&)
  26403. {
  26404. const bool isShowingNow = isShowing();
  26405. if (wasShowing != isShowingNow)
  26406. {
  26407. wasShowing = isShowingNow;
  26408. if (isShowingNow)
  26409. openPluginWindow();
  26410. else
  26411. closePluginWindow();
  26412. }
  26413. componentMovedOrResized (true, true);
  26414. }
  26415. void componentPeerChanged()
  26416. {
  26417. closePluginWindow();
  26418. openPluginWindow();
  26419. }
  26420. #endif
  26421. bool keyStateChanged (const bool)
  26422. {
  26423. return pluginWantsKeys;
  26424. }
  26425. bool keyPressed (const KeyPress&)
  26426. {
  26427. return pluginWantsKeys;
  26428. }
  26429. #if JUCE_MAC
  26430. void paint (Graphics& g)
  26431. {
  26432. g.fillAll (Colours::black);
  26433. }
  26434. #else
  26435. void paint (Graphics& g)
  26436. {
  26437. if (isOpen)
  26438. {
  26439. ComponentPeer* const peer = getPeer();
  26440. if (peer != 0)
  26441. {
  26442. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  26443. getScreenY() - peer->getScreenY(),
  26444. getWidth(), getHeight());
  26445. #if JUCE_LINUX
  26446. if (pluginWindow != 0)
  26447. {
  26448. const Rectangle<int> clip (g.getClipBounds());
  26449. XEvent ev;
  26450. zerostruct (ev);
  26451. ev.xexpose.type = Expose;
  26452. ev.xexpose.display = display;
  26453. ev.xexpose.window = pluginWindow;
  26454. ev.xexpose.x = clip.getX();
  26455. ev.xexpose.y = clip.getY();
  26456. ev.xexpose.width = clip.getWidth();
  26457. ev.xexpose.height = clip.getHeight();
  26458. sendEventToChild (&ev);
  26459. }
  26460. #endif
  26461. }
  26462. }
  26463. else
  26464. {
  26465. g.fillAll (Colours::black);
  26466. }
  26467. }
  26468. #endif
  26469. void timerCallback()
  26470. {
  26471. #if JUCE_WIN32
  26472. if (--sizeCheckCount <= 0)
  26473. {
  26474. sizeCheckCount = 10;
  26475. checkPluginWindowSize();
  26476. }
  26477. #endif
  26478. try
  26479. {
  26480. static bool reentrant = false;
  26481. if (! reentrant)
  26482. {
  26483. reentrant = true;
  26484. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26485. reentrant = false;
  26486. }
  26487. }
  26488. catch (...)
  26489. {}
  26490. }
  26491. void mouseDown (const MouseEvent& e)
  26492. {
  26493. #if JUCE_LINUX
  26494. if (pluginWindow == 0)
  26495. return;
  26496. toFront (true);
  26497. XEvent ev;
  26498. zerostruct (ev);
  26499. ev.xbutton.display = display;
  26500. ev.xbutton.type = ButtonPress;
  26501. ev.xbutton.window = pluginWindow;
  26502. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26503. ev.xbutton.time = CurrentTime;
  26504. ev.xbutton.x = e.x;
  26505. ev.xbutton.y = e.y;
  26506. ev.xbutton.x_root = e.getScreenX();
  26507. ev.xbutton.y_root = e.getScreenY();
  26508. translateJuceToXButtonModifiers (e, ev);
  26509. sendEventToChild (&ev);
  26510. #elif JUCE_WIN32
  26511. (void) e;
  26512. toFront (true);
  26513. #endif
  26514. }
  26515. void broughtToFront()
  26516. {
  26517. activeVSTWindows.removeValue (this);
  26518. activeVSTWindows.add (this);
  26519. #if JUCE_MAC
  26520. dispatch (effEditTop, 0, 0, 0, 0);
  26521. #endif
  26522. }
  26523. juce_UseDebuggingNewOperator
  26524. private:
  26525. VSTPluginInstance& plugin;
  26526. bool isOpen, wasShowing, recursiveResize;
  26527. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26528. #if JUCE_WIN32
  26529. HWND pluginHWND;
  26530. void* originalWndProc;
  26531. int sizeCheckCount;
  26532. #elif JUCE_LINUX
  26533. Window pluginWindow;
  26534. EventProcPtr pluginProc;
  26535. #endif
  26536. #if JUCE_MAC
  26537. void openPluginWindow (WindowRef parentWindow)
  26538. {
  26539. if (isOpen || parentWindow == 0)
  26540. return;
  26541. isOpen = true;
  26542. ERect* rect = 0;
  26543. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26544. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26545. // do this before and after like in the steinberg example
  26546. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26547. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26548. // Install keyboard hooks
  26549. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26550. // double-check it's not too tiny
  26551. int w = 250, h = 150;
  26552. if (rect != 0)
  26553. {
  26554. w = rect->right - rect->left;
  26555. h = rect->bottom - rect->top;
  26556. if (w == 0 || h == 0)
  26557. {
  26558. w = 250;
  26559. h = 150;
  26560. }
  26561. }
  26562. w = jmax (w, 32);
  26563. h = jmax (h, 32);
  26564. setSize (w, h);
  26565. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26566. repaint();
  26567. }
  26568. #else
  26569. void openPluginWindow()
  26570. {
  26571. if (isOpen || getWindowHandle() == 0)
  26572. return;
  26573. log (T("Opening VST UI: ") + plugin.name);
  26574. isOpen = true;
  26575. ERect* rect = 0;
  26576. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26577. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26578. // do this before and after like in the steinberg example
  26579. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26580. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26581. // Install keyboard hooks
  26582. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26583. #if JUCE_WIN32
  26584. originalWndProc = 0;
  26585. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26586. if (pluginHWND == 0)
  26587. {
  26588. isOpen = false;
  26589. setSize (300, 150);
  26590. return;
  26591. }
  26592. #pragma warning (push)
  26593. #pragma warning (disable: 4244)
  26594. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26595. if (! pluginWantsKeys)
  26596. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26597. #pragma warning (pop)
  26598. int w, h;
  26599. RECT r;
  26600. GetWindowRect (pluginHWND, &r);
  26601. w = r.right - r.left;
  26602. h = r.bottom - r.top;
  26603. if (rect != 0)
  26604. {
  26605. const int rw = rect->right - rect->left;
  26606. const int rh = rect->bottom - rect->top;
  26607. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26608. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26609. {
  26610. // very dodgy logic to decide which size is right.
  26611. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26612. {
  26613. SetWindowPos (pluginHWND, 0,
  26614. 0, 0, rw, rh,
  26615. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26616. GetWindowRect (pluginHWND, &r);
  26617. w = r.right - r.left;
  26618. h = r.bottom - r.top;
  26619. pluginRefusesToResize = (w != rw) || (h != rh);
  26620. w = rw;
  26621. h = rh;
  26622. }
  26623. }
  26624. }
  26625. #elif JUCE_LINUX
  26626. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26627. if (pluginWindow != 0)
  26628. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26629. XInternAtom (display, "_XEventProc", False));
  26630. int w = 250, h = 150;
  26631. if (rect != 0)
  26632. {
  26633. w = rect->right - rect->left;
  26634. h = rect->bottom - rect->top;
  26635. if (w == 0 || h == 0)
  26636. {
  26637. w = 250;
  26638. h = 150;
  26639. }
  26640. }
  26641. if (pluginWindow != 0)
  26642. XMapRaised (display, pluginWindow);
  26643. #endif
  26644. // double-check it's not too tiny
  26645. w = jmax (w, 32);
  26646. h = jmax (h, 32);
  26647. setSize (w, h);
  26648. #if JUCE_WIN32
  26649. checkPluginWindowSize();
  26650. #endif
  26651. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26652. repaint();
  26653. }
  26654. #endif
  26655. #if ! JUCE_MAC
  26656. void closePluginWindow()
  26657. {
  26658. if (isOpen)
  26659. {
  26660. log (T("Closing VST UI: ") + plugin.getName());
  26661. isOpen = false;
  26662. dispatch (effEditClose, 0, 0, 0, 0);
  26663. #if JUCE_WIN32
  26664. #pragma warning (push)
  26665. #pragma warning (disable: 4244)
  26666. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26667. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26668. #pragma warning (pop)
  26669. stopTimer();
  26670. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26671. DestroyWindow (pluginHWND);
  26672. pluginHWND = 0;
  26673. #elif JUCE_LINUX
  26674. stopTimer();
  26675. pluginWindow = 0;
  26676. pluginProc = 0;
  26677. #endif
  26678. }
  26679. }
  26680. #endif
  26681. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26682. {
  26683. return plugin.dispatch (opcode, index, value, ptr, opt);
  26684. }
  26685. #if JUCE_WIN32
  26686. void checkPluginWindowSize() throw()
  26687. {
  26688. RECT r;
  26689. GetWindowRect (pluginHWND, &r);
  26690. const int w = r.right - r.left;
  26691. const int h = r.bottom - r.top;
  26692. if (isShowing() && w > 0 && h > 0
  26693. && (w != getWidth() || h != getHeight())
  26694. && ! pluginRefusesToResize)
  26695. {
  26696. setSize (w, h);
  26697. sizeCheckCount = 0;
  26698. }
  26699. }
  26700. // hooks to get keyboard events from VST windows..
  26701. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26702. {
  26703. for (int i = activeVSTWindows.size(); --i >= 0;)
  26704. {
  26705. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26706. if (w->pluginHWND == hW)
  26707. {
  26708. if (message == WM_CHAR
  26709. || message == WM_KEYDOWN
  26710. || message == WM_SYSKEYDOWN
  26711. || message == WM_KEYUP
  26712. || message == WM_SYSKEYUP
  26713. || message == WM_APPCOMMAND)
  26714. {
  26715. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26716. message, wParam, lParam);
  26717. }
  26718. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26719. (HWND) w->pluginHWND,
  26720. message,
  26721. wParam,
  26722. lParam);
  26723. }
  26724. }
  26725. return DefWindowProc (hW, message, wParam, lParam);
  26726. }
  26727. #endif
  26728. #if JUCE_LINUX
  26729. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26730. void sendEventToChild (XEvent* event)
  26731. {
  26732. if (pluginProc != 0)
  26733. {
  26734. // if the plugin publishes an event procedure, pass the event directly..
  26735. pluginProc (event);
  26736. }
  26737. else if (pluginWindow != 0)
  26738. {
  26739. // if the plugin has a window, then send the event to the window so that
  26740. // its message thread will pick it up..
  26741. XSendEvent (display, pluginWindow, False, 0L, event);
  26742. XFlush (display);
  26743. }
  26744. }
  26745. void mouseEnter (const MouseEvent& e)
  26746. {
  26747. if (pluginWindow != 0)
  26748. {
  26749. XEvent ev;
  26750. zerostruct (ev);
  26751. ev.xcrossing.display = display;
  26752. ev.xcrossing.type = EnterNotify;
  26753. ev.xcrossing.window = pluginWindow;
  26754. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26755. ev.xcrossing.time = CurrentTime;
  26756. ev.xcrossing.x = e.x;
  26757. ev.xcrossing.y = e.y;
  26758. ev.xcrossing.x_root = e.getScreenX();
  26759. ev.xcrossing.y_root = e.getScreenY();
  26760. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26761. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26762. translateJuceToXCrossingModifiers (e, ev);
  26763. sendEventToChild (&ev);
  26764. }
  26765. }
  26766. void mouseExit (const MouseEvent& e)
  26767. {
  26768. if (pluginWindow != 0)
  26769. {
  26770. XEvent ev;
  26771. zerostruct (ev);
  26772. ev.xcrossing.display = display;
  26773. ev.xcrossing.type = LeaveNotify;
  26774. ev.xcrossing.window = pluginWindow;
  26775. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26776. ev.xcrossing.time = CurrentTime;
  26777. ev.xcrossing.x = e.x;
  26778. ev.xcrossing.y = e.y;
  26779. ev.xcrossing.x_root = e.getScreenX();
  26780. ev.xcrossing.y_root = e.getScreenY();
  26781. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26782. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26783. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26784. translateJuceToXCrossingModifiers (e, ev);
  26785. sendEventToChild (&ev);
  26786. }
  26787. }
  26788. void mouseMove (const MouseEvent& e)
  26789. {
  26790. if (pluginWindow != 0)
  26791. {
  26792. XEvent ev;
  26793. zerostruct (ev);
  26794. ev.xmotion.display = display;
  26795. ev.xmotion.type = MotionNotify;
  26796. ev.xmotion.window = pluginWindow;
  26797. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26798. ev.xmotion.time = CurrentTime;
  26799. ev.xmotion.is_hint = NotifyNormal;
  26800. ev.xmotion.x = e.x;
  26801. ev.xmotion.y = e.y;
  26802. ev.xmotion.x_root = e.getScreenX();
  26803. ev.xmotion.y_root = e.getScreenY();
  26804. sendEventToChild (&ev);
  26805. }
  26806. }
  26807. void mouseDrag (const MouseEvent& e)
  26808. {
  26809. if (pluginWindow != 0)
  26810. {
  26811. XEvent ev;
  26812. zerostruct (ev);
  26813. ev.xmotion.display = display;
  26814. ev.xmotion.type = MotionNotify;
  26815. ev.xmotion.window = pluginWindow;
  26816. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26817. ev.xmotion.time = CurrentTime;
  26818. ev.xmotion.x = e.x ;
  26819. ev.xmotion.y = e.y;
  26820. ev.xmotion.x_root = e.getScreenX();
  26821. ev.xmotion.y_root = e.getScreenY();
  26822. ev.xmotion.is_hint = NotifyNormal;
  26823. translateJuceToXMotionModifiers (e, ev);
  26824. sendEventToChild (&ev);
  26825. }
  26826. }
  26827. void mouseUp (const MouseEvent& e)
  26828. {
  26829. if (pluginWindow != 0)
  26830. {
  26831. XEvent ev;
  26832. zerostruct (ev);
  26833. ev.xbutton.display = display;
  26834. ev.xbutton.type = ButtonRelease;
  26835. ev.xbutton.window = pluginWindow;
  26836. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26837. ev.xbutton.time = CurrentTime;
  26838. ev.xbutton.x = e.x;
  26839. ev.xbutton.y = e.y;
  26840. ev.xbutton.x_root = e.getScreenX();
  26841. ev.xbutton.y_root = e.getScreenY();
  26842. translateJuceToXButtonModifiers (e, ev);
  26843. sendEventToChild (&ev);
  26844. }
  26845. }
  26846. void mouseWheelMove (const MouseEvent& e,
  26847. float incrementX,
  26848. float incrementY)
  26849. {
  26850. if (pluginWindow != 0)
  26851. {
  26852. XEvent ev;
  26853. zerostruct (ev);
  26854. ev.xbutton.display = display;
  26855. ev.xbutton.type = ButtonPress;
  26856. ev.xbutton.window = pluginWindow;
  26857. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26858. ev.xbutton.time = CurrentTime;
  26859. ev.xbutton.x = e.x;
  26860. ev.xbutton.y = e.y;
  26861. ev.xbutton.x_root = e.getScreenX();
  26862. ev.xbutton.y_root = e.getScreenY();
  26863. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26864. sendEventToChild (&ev);
  26865. // TODO - put a usleep here ?
  26866. ev.xbutton.type = ButtonRelease;
  26867. sendEventToChild (&ev);
  26868. }
  26869. }
  26870. #endif
  26871. #if JUCE_MAC
  26872. #if ! JUCE_SUPPORT_CARBON
  26873. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26874. #endif
  26875. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26876. {
  26877. public:
  26878. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26879. : owner (owner_),
  26880. alreadyInside (false)
  26881. {
  26882. }
  26883. ~InnerWrapperComponent()
  26884. {
  26885. deleteWindow();
  26886. }
  26887. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26888. {
  26889. owner->openPluginWindow (windowRef);
  26890. return 0;
  26891. }
  26892. void removeView (HIViewRef)
  26893. {
  26894. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26895. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26896. }
  26897. bool getEmbeddedViewSize (int& w, int& h)
  26898. {
  26899. ERect* rect = 0;
  26900. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26901. w = rect->right - rect->left;
  26902. h = rect->bottom - rect->top;
  26903. return true;
  26904. }
  26905. void mouseDown (int x, int y)
  26906. {
  26907. if (! alreadyInside)
  26908. {
  26909. alreadyInside = true;
  26910. getTopLevelComponent()->toFront (true);
  26911. owner->dispatch (effEditMouse, x, y, 0, 0);
  26912. alreadyInside = false;
  26913. }
  26914. else
  26915. {
  26916. PostEvent (::mouseDown, 0);
  26917. }
  26918. }
  26919. void paint()
  26920. {
  26921. ComponentPeer* const peer = getPeer();
  26922. if (peer != 0)
  26923. {
  26924. ERect r;
  26925. r.left = getScreenX() - peer->getScreenX();
  26926. r.right = r.left + getWidth();
  26927. r.top = getScreenY() - peer->getScreenY();
  26928. r.bottom = r.top + getHeight();
  26929. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26930. }
  26931. }
  26932. private:
  26933. VSTPluginWindow* const owner;
  26934. bool alreadyInside;
  26935. };
  26936. friend class InnerWrapperComponent;
  26937. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26938. void resized()
  26939. {
  26940. innerWrapper->setSize (getWidth(), getHeight());
  26941. }
  26942. #endif
  26943. };
  26944. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26945. {
  26946. if (hasEditor())
  26947. return new VSTPluginWindow (*this);
  26948. return 0;
  26949. }
  26950. void VSTPluginInstance::handleAsyncUpdate()
  26951. {
  26952. // indicates that something about the plugin has changed..
  26953. updateHostDisplay();
  26954. }
  26955. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26956. {
  26957. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26958. {
  26959. changeProgramName (getCurrentProgram(), prog->prgName);
  26960. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26961. setParameter (i, vst_swapFloat (prog->params[i]));
  26962. return true;
  26963. }
  26964. return false;
  26965. }
  26966. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26967. const int dataSize)
  26968. {
  26969. if (dataSize < 28)
  26970. return false;
  26971. const fxSet* const set = (const fxSet*) data;
  26972. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26973. || vst_swap (set->version) > fxbVersionNum)
  26974. return false;
  26975. if (vst_swap (set->fxMagic) == 'FxBk')
  26976. {
  26977. // bank of programs
  26978. if (vst_swap (set->numPrograms) >= 0)
  26979. {
  26980. const int oldProg = getCurrentProgram();
  26981. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26982. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26983. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26984. {
  26985. if (i != oldProg)
  26986. {
  26987. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26988. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26989. return false;
  26990. if (vst_swap (set->numPrograms) > 0)
  26991. setCurrentProgram (i);
  26992. if (! restoreProgramSettings (prog))
  26993. return false;
  26994. }
  26995. }
  26996. if (vst_swap (set->numPrograms) > 0)
  26997. setCurrentProgram (oldProg);
  26998. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26999. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27000. return false;
  27001. if (! restoreProgramSettings (prog))
  27002. return false;
  27003. }
  27004. }
  27005. else if (vst_swap (set->fxMagic) == 'FxCk')
  27006. {
  27007. // single program
  27008. const fxProgram* const prog = (const fxProgram*) data;
  27009. if (vst_swap (prog->chunkMagic) != 'CcnK')
  27010. return false;
  27011. changeProgramName (getCurrentProgram(), prog->prgName);
  27012. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27013. setParameter (i, vst_swapFloat (prog->params[i]));
  27014. }
  27015. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  27016. {
  27017. // non-preset chunk
  27018. const fxChunkSet* const cset = (const fxChunkSet*) data;
  27019. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  27020. return false;
  27021. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  27022. }
  27023. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  27024. {
  27025. // preset chunk
  27026. const fxProgramSet* const cset = (const fxProgramSet*) data;
  27027. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  27028. return false;
  27029. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  27030. changeProgramName (getCurrentProgram(), cset->name);
  27031. }
  27032. else
  27033. {
  27034. return false;
  27035. }
  27036. return true;
  27037. }
  27038. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  27039. {
  27040. const int numParams = getNumParameters();
  27041. prog->chunkMagic = vst_swap ('CcnK');
  27042. prog->byteSize = 0;
  27043. prog->fxMagic = vst_swap ('FxCk');
  27044. prog->version = vst_swap (fxbVersionNum);
  27045. prog->fxID = vst_swap (getUID());
  27046. prog->fxVersion = vst_swap (getVersionNumber());
  27047. prog->numParams = vst_swap (numParams);
  27048. getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1);
  27049. for (int i = 0; i < numParams; ++i)
  27050. prog->params[i] = vst_swapFloat (getParameter (i));
  27051. }
  27052. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  27053. {
  27054. const int numPrograms = getNumPrograms();
  27055. const int numParams = getNumParameters();
  27056. if (usesChunks())
  27057. {
  27058. if (isFXB)
  27059. {
  27060. MemoryBlock chunk;
  27061. getChunkData (chunk, false, maxSizeMB);
  27062. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27063. dest.setSize (totalLen, true);
  27064. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27065. set->chunkMagic = vst_swap ('CcnK');
  27066. set->byteSize = 0;
  27067. set->fxMagic = vst_swap ('FBCh');
  27068. set->version = vst_swap (fxbVersionNum);
  27069. set->fxID = vst_swap (getUID());
  27070. set->fxVersion = vst_swap (getVersionNumber());
  27071. set->numPrograms = vst_swap (numPrograms);
  27072. set->chunkSize = vst_swap ((long) chunk.getSize());
  27073. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27074. }
  27075. else
  27076. {
  27077. MemoryBlock chunk;
  27078. getChunkData (chunk, true, maxSizeMB);
  27079. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27080. dest.setSize (totalLen, true);
  27081. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27082. set->chunkMagic = vst_swap ('CcnK');
  27083. set->byteSize = 0;
  27084. set->fxMagic = vst_swap ('FPCh');
  27085. set->version = vst_swap (fxbVersionNum);
  27086. set->fxID = vst_swap (getUID());
  27087. set->fxVersion = vst_swap (getVersionNumber());
  27088. set->numPrograms = vst_swap (numPrograms);
  27089. set->chunkSize = vst_swap ((long) chunk.getSize());
  27090. getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1);
  27091. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27092. }
  27093. }
  27094. else
  27095. {
  27096. if (isFXB)
  27097. {
  27098. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27099. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27100. dest.setSize (len, true);
  27101. fxSet* const set = (fxSet*) dest.getData();
  27102. set->chunkMagic = vst_swap ('CcnK');
  27103. set->byteSize = 0;
  27104. set->fxMagic = vst_swap ('FxBk');
  27105. set->version = vst_swap (fxbVersionNum);
  27106. set->fxID = vst_swap (getUID());
  27107. set->fxVersion = vst_swap (getVersionNumber());
  27108. set->numPrograms = vst_swap (numPrograms);
  27109. const int oldProgram = getCurrentProgram();
  27110. MemoryBlock oldSettings;
  27111. createTempParameterStore (oldSettings);
  27112. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27113. for (int i = 0; i < numPrograms; ++i)
  27114. {
  27115. if (i != oldProgram)
  27116. {
  27117. setCurrentProgram (i);
  27118. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27119. }
  27120. }
  27121. setCurrentProgram (oldProgram);
  27122. restoreFromTempParameterStore (oldSettings);
  27123. }
  27124. else
  27125. {
  27126. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27127. dest.setSize (totalLen, true);
  27128. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27129. }
  27130. }
  27131. return true;
  27132. }
  27133. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27134. {
  27135. if (usesChunks())
  27136. {
  27137. void* data = 0;
  27138. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27139. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27140. {
  27141. mb.setSize (bytes);
  27142. mb.copyFrom (data, 0, bytes);
  27143. }
  27144. }
  27145. }
  27146. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27147. {
  27148. if (size > 0 && usesChunks())
  27149. {
  27150. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27151. if (! isPreset)
  27152. updateStoredProgramNames();
  27153. }
  27154. }
  27155. void VSTPluginInstance::timerCallback()
  27156. {
  27157. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27158. stopTimer();
  27159. }
  27160. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27161. {
  27162. const ScopedLock sl (lock);
  27163. ++insideVSTCallback;
  27164. int result = 0;
  27165. try
  27166. {
  27167. if (effect != 0)
  27168. {
  27169. #if JUCE_MAC
  27170. if (module->resFileId != 0)
  27171. UseResFile (module->resFileId);
  27172. CGrafPtr oldPort;
  27173. if (getActiveEditor() != 0)
  27174. {
  27175. int x = 0, y = 0;
  27176. getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), x, y);
  27177. GetPort (&oldPort);
  27178. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27179. SetOrigin (-x, -y);
  27180. }
  27181. #endif
  27182. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27183. #if JUCE_MAC
  27184. if (getActiveEditor() != 0)
  27185. SetPort (oldPort);
  27186. module->resFileId = CurResFile();
  27187. #endif
  27188. --insideVSTCallback;
  27189. return result;
  27190. }
  27191. }
  27192. catch (...)
  27193. {
  27194. //char s[512];
  27195. //sprintf (s, "dispatcher (%d, %d, %d, %x, %f)", opcode, index, value, (int)ptr, opt);
  27196. }
  27197. --insideVSTCallback;
  27198. return result;
  27199. }
  27200. // handles non plugin-specific callbacks..
  27201. static const int defaultVSTSampleRateValue = 16384;
  27202. static const int defaultVSTBlockSizeValue = 512;
  27203. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27204. {
  27205. (void) index;
  27206. (void) value;
  27207. (void) opt;
  27208. switch (opcode)
  27209. {
  27210. case audioMasterCanDo:
  27211. {
  27212. static const char* canDos[] = { "supplyIdle",
  27213. "sendVstEvents",
  27214. "sendVstMidiEvent",
  27215. "sendVstTimeInfo",
  27216. "receiveVstEvents",
  27217. "receiveVstMidiEvent",
  27218. "supportShell",
  27219. "shellCategory" };
  27220. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27221. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27222. return 1;
  27223. return 0;
  27224. }
  27225. case audioMasterVersion:
  27226. return 0x2400;
  27227. case audioMasterCurrentId:
  27228. return shellUIDToCreate;
  27229. case audioMasterGetNumAutomatableParameters:
  27230. return 0;
  27231. case audioMasterGetAutomationState:
  27232. return 1;
  27233. case audioMasterGetVendorVersion:
  27234. return 0x0101;
  27235. case audioMasterGetVendorString:
  27236. case audioMasterGetProductString:
  27237. {
  27238. String hostName ("Juce VST Host");
  27239. if (JUCEApplication::getInstance() != 0)
  27240. hostName = JUCEApplication::getInstance()->getApplicationName();
  27241. hostName.copyToBuffer ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27242. }
  27243. break;
  27244. case audioMasterGetSampleRate:
  27245. return (VstIntPtr) defaultVSTSampleRateValue;
  27246. case audioMasterGetBlockSize:
  27247. return (VstIntPtr) defaultVSTBlockSizeValue;
  27248. case audioMasterSetOutputSampleRate:
  27249. return 0;
  27250. default:
  27251. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27252. break;
  27253. }
  27254. return 0;
  27255. }
  27256. // handles callbacks for a specific plugin
  27257. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27258. {
  27259. switch (opcode)
  27260. {
  27261. case audioMasterAutomate:
  27262. sendParamChangeMessageToListeners (index, opt);
  27263. break;
  27264. case audioMasterProcessEvents:
  27265. handleMidiFromPlugin ((const VstEvents*) ptr);
  27266. break;
  27267. case audioMasterGetTime:
  27268. #ifdef _MSC_VER
  27269. #pragma warning (push)
  27270. #pragma warning (disable: 4311)
  27271. #endif
  27272. return (VstIntPtr) &vstHostTime;
  27273. #ifdef _MSC_VER
  27274. #pragma warning (pop)
  27275. #endif
  27276. break;
  27277. case audioMasterIdle:
  27278. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27279. {
  27280. ++insideVSTCallback;
  27281. #if JUCE_MAC
  27282. if (getActiveEditor() != 0)
  27283. dispatch (effEditIdle, 0, 0, 0, 0);
  27284. #endif
  27285. juce_callAnyTimersSynchronously();
  27286. handleUpdateNowIfNeeded();
  27287. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27288. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27289. --insideVSTCallback;
  27290. }
  27291. break;
  27292. case audioMasterUpdateDisplay:
  27293. triggerAsyncUpdate();
  27294. break;
  27295. case audioMasterTempoAt:
  27296. // returns (10000 * bpm)
  27297. break;
  27298. case audioMasterNeedIdle:
  27299. startTimer (50);
  27300. break;
  27301. case audioMasterSizeWindow:
  27302. if (getActiveEditor() != 0)
  27303. getActiveEditor()->setSize (index, value);
  27304. return 1;
  27305. case audioMasterGetSampleRate:
  27306. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27307. case audioMasterGetBlockSize:
  27308. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27309. case audioMasterWantMidi:
  27310. wantsMidiMessages = true;
  27311. break;
  27312. case audioMasterGetDirectory:
  27313. #if JUCE_MAC
  27314. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27315. #else
  27316. return (VstIntPtr) (pointer_sized_uint) (const char*) module->fullParentDirectoryPathName;
  27317. #endif
  27318. case audioMasterGetAutomationState:
  27319. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27320. break;
  27321. // none of these are handled (yet)..
  27322. case audioMasterBeginEdit:
  27323. case audioMasterEndEdit:
  27324. case audioMasterSetTime:
  27325. case audioMasterPinConnected:
  27326. case audioMasterGetParameterQuantization:
  27327. case audioMasterIOChanged:
  27328. case audioMasterGetInputLatency:
  27329. case audioMasterGetOutputLatency:
  27330. case audioMasterGetPreviousPlug:
  27331. case audioMasterGetNextPlug:
  27332. case audioMasterWillReplaceOrAccumulate:
  27333. case audioMasterGetCurrentProcessLevel:
  27334. case audioMasterOfflineStart:
  27335. case audioMasterOfflineRead:
  27336. case audioMasterOfflineWrite:
  27337. case audioMasterOfflineGetCurrentPass:
  27338. case audioMasterOfflineGetCurrentMetaPass:
  27339. case audioMasterVendorSpecific:
  27340. case audioMasterSetIcon:
  27341. case audioMasterGetLanguage:
  27342. case audioMasterOpenWindow:
  27343. case audioMasterCloseWindow:
  27344. break;
  27345. default:
  27346. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27347. }
  27348. return 0;
  27349. }
  27350. // entry point for all callbacks from the plugin
  27351. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27352. {
  27353. try
  27354. {
  27355. if (effect != 0 && effect->resvd2 != 0)
  27356. {
  27357. return ((VSTPluginInstance*)(effect->resvd2))
  27358. ->handleCallback (opcode, index, value, ptr, opt);
  27359. }
  27360. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27361. }
  27362. catch (...)
  27363. {
  27364. return 0;
  27365. }
  27366. }
  27367. const String VSTPluginInstance::getVersion() const throw()
  27368. {
  27369. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27370. String s;
  27371. if (v == 0 || v == -1)
  27372. v = getVersionNumber();
  27373. if (v != 0)
  27374. {
  27375. int versionBits[4];
  27376. int n = 0;
  27377. while (v != 0)
  27378. {
  27379. versionBits [n++] = (v & 0xff);
  27380. v >>= 8;
  27381. }
  27382. s << 'V';
  27383. while (n > 0)
  27384. {
  27385. s << versionBits [--n];
  27386. if (n > 0)
  27387. s << '.';
  27388. }
  27389. }
  27390. return s;
  27391. }
  27392. int VSTPluginInstance::getUID() const throw()
  27393. {
  27394. int uid = effect != 0 ? effect->uniqueID : 0;
  27395. if (uid == 0)
  27396. uid = module->file.hashCode();
  27397. return uid;
  27398. }
  27399. const String VSTPluginInstance::getCategory() const throw()
  27400. {
  27401. const char* result = 0;
  27402. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27403. {
  27404. case kPlugCategEffect:
  27405. result = "Effect";
  27406. break;
  27407. case kPlugCategSynth:
  27408. result = "Synth";
  27409. break;
  27410. case kPlugCategAnalysis:
  27411. result = "Anaylsis";
  27412. break;
  27413. case kPlugCategMastering:
  27414. result = "Mastering";
  27415. break;
  27416. case kPlugCategSpacializer:
  27417. result = "Spacial";
  27418. break;
  27419. case kPlugCategRoomFx:
  27420. result = "Reverb";
  27421. break;
  27422. case kPlugSurroundFx:
  27423. result = "Surround";
  27424. break;
  27425. case kPlugCategRestoration:
  27426. result = "Restoration";
  27427. break;
  27428. case kPlugCategGenerator:
  27429. result = "Tone generation";
  27430. break;
  27431. default:
  27432. break;
  27433. }
  27434. return result;
  27435. }
  27436. float VSTPluginInstance::getParameter (int index)
  27437. {
  27438. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27439. {
  27440. try
  27441. {
  27442. const ScopedLock sl (lock);
  27443. return effect->getParameter (effect, index);
  27444. }
  27445. catch (...)
  27446. {
  27447. }
  27448. }
  27449. return 0.0f;
  27450. }
  27451. void VSTPluginInstance::setParameter (int index, float newValue)
  27452. {
  27453. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27454. {
  27455. try
  27456. {
  27457. const ScopedLock sl (lock);
  27458. if (effect->getParameter (effect, index) != newValue)
  27459. effect->setParameter (effect, index, newValue);
  27460. }
  27461. catch (...)
  27462. {
  27463. }
  27464. }
  27465. }
  27466. const String VSTPluginInstance::getParameterName (int index)
  27467. {
  27468. if (effect != 0)
  27469. {
  27470. jassert (index >= 0 && index < effect->numParams);
  27471. char nm [256];
  27472. zerostruct (nm);
  27473. dispatch (effGetParamName, index, 0, nm, 0);
  27474. return String (nm).trim();
  27475. }
  27476. return String::empty;
  27477. }
  27478. const String VSTPluginInstance::getParameterLabel (int index) const
  27479. {
  27480. if (effect != 0)
  27481. {
  27482. jassert (index >= 0 && index < effect->numParams);
  27483. char nm [256];
  27484. zerostruct (nm);
  27485. dispatch (effGetParamLabel, index, 0, nm, 0);
  27486. return String (nm).trim();
  27487. }
  27488. return String::empty;
  27489. }
  27490. const String VSTPluginInstance::getParameterText (int index)
  27491. {
  27492. if (effect != 0)
  27493. {
  27494. jassert (index >= 0 && index < effect->numParams);
  27495. char nm [256];
  27496. zerostruct (nm);
  27497. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27498. return String (nm).trim();
  27499. }
  27500. return String::empty;
  27501. }
  27502. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27503. {
  27504. if (effect != 0)
  27505. {
  27506. jassert (index >= 0 && index < effect->numParams);
  27507. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27508. }
  27509. return false;
  27510. }
  27511. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27512. {
  27513. dest.setSize (64 + 4 * getNumParameters());
  27514. dest.fillWith (0);
  27515. getCurrentProgramName().copyToBuffer ((char*) dest.getData(), 63);
  27516. float* const p = (float*) (((char*) dest.getData()) + 64);
  27517. for (int i = 0; i < getNumParameters(); ++i)
  27518. p[i] = getParameter(i);
  27519. }
  27520. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27521. {
  27522. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27523. float* p = (float*) (((char*) m.getData()) + 64);
  27524. for (int i = 0; i < getNumParameters(); ++i)
  27525. setParameter (i, p[i]);
  27526. }
  27527. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27528. {
  27529. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27530. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27531. }
  27532. const String VSTPluginInstance::getProgramName (int index)
  27533. {
  27534. if (index == getCurrentProgram())
  27535. {
  27536. return getCurrentProgramName();
  27537. }
  27538. else if (effect != 0)
  27539. {
  27540. char nm [256];
  27541. zerostruct (nm);
  27542. if (dispatch (effGetProgramNameIndexed,
  27543. jlimit (0, getNumPrograms(), index),
  27544. -1, nm, 0) != 0)
  27545. {
  27546. return String (nm).trim();
  27547. }
  27548. }
  27549. return programNames [index];
  27550. }
  27551. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27552. {
  27553. if (index == getCurrentProgram())
  27554. {
  27555. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27556. dispatch (effSetProgramName, 0, 0, (void*) (const char*) newName.substring (0, 24), 0.0f);
  27557. }
  27558. else
  27559. {
  27560. jassertfalse // xxx not implemented!
  27561. }
  27562. }
  27563. void VSTPluginInstance::updateStoredProgramNames()
  27564. {
  27565. if (effect != 0 && getNumPrograms() > 0)
  27566. {
  27567. char nm [256];
  27568. zerostruct (nm);
  27569. // only do this if the plugin can't use indexed names..
  27570. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27571. {
  27572. const int oldProgram = getCurrentProgram();
  27573. MemoryBlock oldSettings;
  27574. createTempParameterStore (oldSettings);
  27575. for (int i = 0; i < getNumPrograms(); ++i)
  27576. {
  27577. setCurrentProgram (i);
  27578. getCurrentProgramName(); // (this updates the list)
  27579. }
  27580. setCurrentProgram (oldProgram);
  27581. restoreFromTempParameterStore (oldSettings);
  27582. }
  27583. }
  27584. }
  27585. const String VSTPluginInstance::getCurrentProgramName()
  27586. {
  27587. if (effect != 0)
  27588. {
  27589. char nm [256];
  27590. zerostruct (nm);
  27591. dispatch (effGetProgramName, 0, 0, nm, 0);
  27592. const int index = getCurrentProgram();
  27593. if (programNames[index].isEmpty())
  27594. {
  27595. while (programNames.size() < index)
  27596. programNames.add (String::empty);
  27597. programNames.set (index, String (nm).trim());
  27598. }
  27599. return String (nm).trim();
  27600. }
  27601. return String::empty;
  27602. }
  27603. const String VSTPluginInstance::getInputChannelName (const int index) const
  27604. {
  27605. if (index >= 0 && index < getNumInputChannels())
  27606. {
  27607. VstPinProperties pinProps;
  27608. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27609. return String (pinProps.label, sizeof (pinProps.label));
  27610. }
  27611. return String::empty;
  27612. }
  27613. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27614. {
  27615. if (index < 0 || index >= getNumInputChannels())
  27616. return false;
  27617. VstPinProperties pinProps;
  27618. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27619. return (pinProps.flags & kVstPinIsStereo) != 0;
  27620. return true;
  27621. }
  27622. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27623. {
  27624. if (index >= 0 && index < getNumOutputChannels())
  27625. {
  27626. VstPinProperties pinProps;
  27627. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27628. return String (pinProps.label, sizeof (pinProps.label));
  27629. }
  27630. return String::empty;
  27631. }
  27632. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27633. {
  27634. if (index < 0 || index >= getNumOutputChannels())
  27635. return false;
  27636. VstPinProperties pinProps;
  27637. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27638. return (pinProps.flags & kVstPinIsStereo) != 0;
  27639. return true;
  27640. }
  27641. void VSTPluginInstance::setPower (const bool on)
  27642. {
  27643. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27644. isPowerOn = on;
  27645. }
  27646. const int defaultMaxSizeMB = 64;
  27647. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27648. {
  27649. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27650. }
  27651. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27652. {
  27653. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27654. }
  27655. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27656. {
  27657. loadFromFXBFile (data, sizeInBytes);
  27658. }
  27659. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27660. {
  27661. loadFromFXBFile (data, sizeInBytes);
  27662. }
  27663. VSTPluginFormat::VSTPluginFormat()
  27664. {
  27665. }
  27666. VSTPluginFormat::~VSTPluginFormat()
  27667. {
  27668. }
  27669. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27670. const String& fileOrIdentifier)
  27671. {
  27672. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27673. return;
  27674. PluginDescription desc;
  27675. desc.fileOrIdentifier = fileOrIdentifier;
  27676. desc.uid = 0;
  27677. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27678. if (instance == 0)
  27679. return;
  27680. try
  27681. {
  27682. #if JUCE_MAC
  27683. if (instance->module->resFileId != 0)
  27684. UseResFile (instance->module->resFileId);
  27685. #endif
  27686. instance->fillInPluginDescription (desc);
  27687. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27688. if (category != kPlugCategShell)
  27689. {
  27690. // Normal plugin...
  27691. results.add (new PluginDescription (desc));
  27692. ++insideVSTCallback;
  27693. instance->dispatch (effOpen, 0, 0, 0, 0);
  27694. --insideVSTCallback;
  27695. }
  27696. else
  27697. {
  27698. // It's a shell plugin, so iterate all the subtypes...
  27699. char shellEffectName [64];
  27700. for (;;)
  27701. {
  27702. zerostruct (shellEffectName);
  27703. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27704. if (uid == 0)
  27705. {
  27706. break;
  27707. }
  27708. else
  27709. {
  27710. desc.uid = uid;
  27711. desc.name = shellEffectName;
  27712. bool alreadyThere = false;
  27713. for (int i = results.size(); --i >= 0;)
  27714. {
  27715. PluginDescription* const d = results.getUnchecked(i);
  27716. if (d->isDuplicateOf (desc))
  27717. {
  27718. alreadyThere = true;
  27719. break;
  27720. }
  27721. }
  27722. if (! alreadyThere)
  27723. results.add (new PluginDescription (desc));
  27724. }
  27725. }
  27726. }
  27727. }
  27728. catch (...)
  27729. {
  27730. // crashed while loading...
  27731. }
  27732. }
  27733. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27734. {
  27735. ScopedPointer <VSTPluginInstance> result;
  27736. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27737. {
  27738. File file (desc.fileOrIdentifier);
  27739. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27740. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27741. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27742. if (module != 0)
  27743. {
  27744. shellUIDToCreate = desc.uid;
  27745. result = new VSTPluginInstance (module);
  27746. if (result->effect != 0)
  27747. {
  27748. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27749. result->initialise();
  27750. }
  27751. else
  27752. {
  27753. result = 0;
  27754. }
  27755. }
  27756. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27757. }
  27758. return result.release();
  27759. }
  27760. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27761. {
  27762. const File f (fileOrIdentifier);
  27763. #if JUCE_MAC
  27764. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27765. return true;
  27766. #if JUCE_PPC
  27767. FSRef fileRef;
  27768. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27769. {
  27770. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27771. if (resFileId != -1)
  27772. {
  27773. const int numEffects = Count1Resources ('aEff');
  27774. CloseResFile (resFileId);
  27775. if (numEffects > 0)
  27776. return true;
  27777. }
  27778. }
  27779. #endif
  27780. return false;
  27781. #elif JUCE_WIN32
  27782. return f.existsAsFile()
  27783. && f.hasFileExtension (T(".dll"));
  27784. #elif JUCE_LINUX
  27785. return f.existsAsFile()
  27786. && f.hasFileExtension (T(".so"));
  27787. #endif
  27788. }
  27789. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27790. {
  27791. return fileOrIdentifier;
  27792. }
  27793. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27794. {
  27795. return File (desc.fileOrIdentifier).exists();
  27796. }
  27797. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27798. {
  27799. StringArray results;
  27800. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27801. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27802. return results;
  27803. }
  27804. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27805. {
  27806. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27807. // .component or .vst directories.
  27808. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27809. while (iter.next())
  27810. {
  27811. const File f (iter.getFile());
  27812. bool isPlugin = false;
  27813. if (fileMightContainThisPluginType (f.getFullPathName()))
  27814. {
  27815. isPlugin = true;
  27816. results.add (f.getFullPathName());
  27817. }
  27818. if (recursive && (! isPlugin) && f.isDirectory())
  27819. recursiveFileSearch (results, f, true);
  27820. }
  27821. }
  27822. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27823. {
  27824. #if JUCE_MAC
  27825. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27826. #elif JUCE_WIN32
  27827. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27828. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27829. #elif JUCE_LINUX
  27830. return FileSearchPath ("/usr/lib/vst");
  27831. #endif
  27832. }
  27833. END_JUCE_NAMESPACE
  27834. #endif
  27835. #undef log
  27836. #endif
  27837. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27838. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27839. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27840. BEGIN_JUCE_NAMESPACE
  27841. AudioProcessor::AudioProcessor()
  27842. : playHead (0),
  27843. activeEditor (0),
  27844. sampleRate (0),
  27845. blockSize (0),
  27846. numInputChannels (0),
  27847. numOutputChannels (0),
  27848. latencySamples (0),
  27849. suspended (false),
  27850. nonRealtime (false)
  27851. {
  27852. }
  27853. AudioProcessor::~AudioProcessor()
  27854. {
  27855. // ooh, nasty - the editor should have been deleted before the filter
  27856. // that it refers to is deleted..
  27857. jassert (activeEditor == 0);
  27858. #ifdef JUCE_DEBUG
  27859. // This will fail if you've called beginParameterChangeGesture() for one
  27860. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27861. jassert (changingParams.countNumberOfSetBits() == 0);
  27862. #endif
  27863. }
  27864. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27865. {
  27866. playHead = newPlayHead;
  27867. }
  27868. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27869. {
  27870. const ScopedLock sl (listenerLock);
  27871. listeners.addIfNotAlreadyThere (newListener);
  27872. }
  27873. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27874. {
  27875. const ScopedLock sl (listenerLock);
  27876. listeners.removeValue (listenerToRemove);
  27877. }
  27878. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27879. const int numOuts,
  27880. const double sampleRate_,
  27881. const int blockSize_) throw()
  27882. {
  27883. numInputChannels = numIns;
  27884. numOutputChannels = numOuts;
  27885. sampleRate = sampleRate_;
  27886. blockSize = blockSize_;
  27887. }
  27888. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27889. {
  27890. nonRealtime = nonRealtime_;
  27891. }
  27892. void AudioProcessor::setLatencySamples (const int newLatency)
  27893. {
  27894. if (latencySamples != newLatency)
  27895. {
  27896. latencySamples = newLatency;
  27897. updateHostDisplay();
  27898. }
  27899. }
  27900. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27901. const float newValue)
  27902. {
  27903. setParameter (parameterIndex, newValue);
  27904. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27905. }
  27906. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27907. {
  27908. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27909. for (int i = listeners.size(); --i >= 0;)
  27910. {
  27911. listenerLock.enter();
  27912. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27913. listenerLock.exit();
  27914. if (l != 0)
  27915. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27916. }
  27917. }
  27918. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27919. {
  27920. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27921. #ifdef JUCE_DEBUG
  27922. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27923. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27924. jassert (! changingParams [parameterIndex]);
  27925. changingParams.setBit (parameterIndex);
  27926. #endif
  27927. for (int i = listeners.size(); --i >= 0;)
  27928. {
  27929. listenerLock.enter();
  27930. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27931. listenerLock.exit();
  27932. if (l != 0)
  27933. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27934. }
  27935. }
  27936. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27937. {
  27938. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27939. #ifdef JUCE_DEBUG
  27940. // This means you've called endParameterChangeGesture without having previously called
  27941. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27942. // calls matched correctly.
  27943. jassert (changingParams [parameterIndex]);
  27944. changingParams.clearBit (parameterIndex);
  27945. #endif
  27946. for (int i = listeners.size(); --i >= 0;)
  27947. {
  27948. listenerLock.enter();
  27949. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27950. listenerLock.exit();
  27951. if (l != 0)
  27952. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27953. }
  27954. }
  27955. void AudioProcessor::updateHostDisplay()
  27956. {
  27957. for (int i = listeners.size(); --i >= 0;)
  27958. {
  27959. listenerLock.enter();
  27960. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27961. listenerLock.exit();
  27962. if (l != 0)
  27963. l->audioProcessorChanged (this);
  27964. }
  27965. }
  27966. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27967. {
  27968. return true;
  27969. }
  27970. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27971. {
  27972. return false;
  27973. }
  27974. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27975. {
  27976. const ScopedLock sl (callbackLock);
  27977. suspended = shouldBeSuspended;
  27978. }
  27979. void AudioProcessor::reset()
  27980. {
  27981. }
  27982. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27983. {
  27984. const ScopedLock sl (callbackLock);
  27985. jassert (activeEditor == editor);
  27986. if (activeEditor == editor)
  27987. activeEditor = 0;
  27988. }
  27989. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27990. {
  27991. if (activeEditor != 0)
  27992. return activeEditor;
  27993. AudioProcessorEditor* const ed = createEditor();
  27994. if (ed != 0)
  27995. {
  27996. // you must give your editor comp a size before returning it..
  27997. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27998. const ScopedLock sl (callbackLock);
  27999. activeEditor = ed;
  28000. }
  28001. return ed;
  28002. }
  28003. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  28004. {
  28005. getStateInformation (destData);
  28006. }
  28007. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  28008. {
  28009. setStateInformation (data, sizeInBytes);
  28010. }
  28011. // magic number to identify memory blocks that we've stored as XML
  28012. const uint32 magicXmlNumber = 0x21324356;
  28013. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  28014. JUCE_NAMESPACE::MemoryBlock& destData)
  28015. {
  28016. const String xmlString (xml.createDocument (String::empty, true, false));
  28017. const int stringLength = xmlString.length();
  28018. destData.setSize (stringLength + 10);
  28019. char* const d = (char*) destData.getData();
  28020. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  28021. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  28022. xmlString.copyToBuffer (d + 8, stringLength);
  28023. }
  28024. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  28025. const int sizeInBytes)
  28026. {
  28027. if (sizeInBytes > 8
  28028. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  28029. {
  28030. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  28031. if (stringLength > 0)
  28032. {
  28033. XmlDocument doc (String (((const char*) data) + 8,
  28034. jmin ((sizeInBytes - 8), stringLength)));
  28035. return doc.getDocumentElement();
  28036. }
  28037. }
  28038. return 0;
  28039. }
  28040. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  28041. {
  28042. }
  28043. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  28044. {
  28045. }
  28046. END_JUCE_NAMESPACE
  28047. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  28048. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  28049. BEGIN_JUCE_NAMESPACE
  28050. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  28051. : owner (owner_)
  28052. {
  28053. // the filter must be valid..
  28054. jassert (owner != 0);
  28055. }
  28056. AudioProcessorEditor::~AudioProcessorEditor()
  28057. {
  28058. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28059. // filter for some reason..
  28060. jassert (owner->getActiveEditor() != this);
  28061. }
  28062. END_JUCE_NAMESPACE
  28063. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  28064. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  28065. BEGIN_JUCE_NAMESPACE
  28066. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28067. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28068. : id (id_),
  28069. processor (processor_),
  28070. isPrepared (false)
  28071. {
  28072. jassert (processor_ != 0);
  28073. }
  28074. AudioProcessorGraph::Node::~Node()
  28075. {
  28076. delete processor;
  28077. }
  28078. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28079. AudioProcessorGraph* const graph)
  28080. {
  28081. if (! isPrepared)
  28082. {
  28083. isPrepared = true;
  28084. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28085. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28086. if (ioProc != 0)
  28087. ioProc->setParentGraph (graph);
  28088. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28089. processor->getNumOutputChannels(),
  28090. sampleRate, blockSize);
  28091. processor->prepareToPlay (sampleRate, blockSize);
  28092. }
  28093. }
  28094. void AudioProcessorGraph::Node::unprepare()
  28095. {
  28096. if (isPrepared)
  28097. {
  28098. isPrepared = false;
  28099. processor->releaseResources();
  28100. }
  28101. }
  28102. AudioProcessorGraph::AudioProcessorGraph()
  28103. : lastNodeId (0),
  28104. renderingBuffers (1, 1),
  28105. currentAudioOutputBuffer (1, 1)
  28106. {
  28107. }
  28108. AudioProcessorGraph::~AudioProcessorGraph()
  28109. {
  28110. clearRenderingSequence();
  28111. clear();
  28112. }
  28113. const String AudioProcessorGraph::getName() const
  28114. {
  28115. return "Audio Graph";
  28116. }
  28117. void AudioProcessorGraph::clear()
  28118. {
  28119. nodes.clear();
  28120. connections.clear();
  28121. triggerAsyncUpdate();
  28122. }
  28123. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28124. {
  28125. for (int i = nodes.size(); --i >= 0;)
  28126. if (nodes.getUnchecked(i)->id == nodeId)
  28127. return nodes.getUnchecked(i);
  28128. return 0;
  28129. }
  28130. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28131. uint32 nodeId)
  28132. {
  28133. if (newProcessor == 0)
  28134. {
  28135. jassertfalse
  28136. return 0;
  28137. }
  28138. if (nodeId == 0)
  28139. {
  28140. nodeId = ++lastNodeId;
  28141. }
  28142. else
  28143. {
  28144. // you can't add a node with an id that already exists in the graph..
  28145. jassert (getNodeForId (nodeId) == 0);
  28146. removeNode (nodeId);
  28147. }
  28148. lastNodeId = nodeId;
  28149. Node* const n = new Node (nodeId, newProcessor);
  28150. nodes.add (n);
  28151. triggerAsyncUpdate();
  28152. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28153. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28154. if (ioProc != 0)
  28155. ioProc->setParentGraph (this);
  28156. return n;
  28157. }
  28158. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28159. {
  28160. disconnectNode (nodeId);
  28161. for (int i = nodes.size(); --i >= 0;)
  28162. {
  28163. if (nodes.getUnchecked(i)->id == nodeId)
  28164. {
  28165. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28166. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28167. if (ioProc != 0)
  28168. ioProc->setParentGraph (0);
  28169. nodes.remove (i);
  28170. triggerAsyncUpdate();
  28171. return true;
  28172. }
  28173. }
  28174. return false;
  28175. }
  28176. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28177. const int sourceChannelIndex,
  28178. const uint32 destNodeId,
  28179. const int destChannelIndex) const
  28180. {
  28181. for (int i = connections.size(); --i >= 0;)
  28182. {
  28183. const Connection* const c = connections.getUnchecked(i);
  28184. if (c->sourceNodeId == sourceNodeId
  28185. && c->destNodeId == destNodeId
  28186. && c->sourceChannelIndex == sourceChannelIndex
  28187. && c->destChannelIndex == destChannelIndex)
  28188. {
  28189. return c;
  28190. }
  28191. }
  28192. return 0;
  28193. }
  28194. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28195. const uint32 possibleDestNodeId) const
  28196. {
  28197. for (int i = connections.size(); --i >= 0;)
  28198. {
  28199. const Connection* const c = connections.getUnchecked(i);
  28200. if (c->sourceNodeId == possibleSourceNodeId
  28201. && c->destNodeId == possibleDestNodeId)
  28202. {
  28203. return true;
  28204. }
  28205. }
  28206. return false;
  28207. }
  28208. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28209. const int sourceChannelIndex,
  28210. const uint32 destNodeId,
  28211. const int destChannelIndex) const
  28212. {
  28213. if (sourceChannelIndex < 0
  28214. || destChannelIndex < 0
  28215. || sourceNodeId == destNodeId
  28216. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28217. return false;
  28218. const Node* const source = getNodeForId (sourceNodeId);
  28219. if (source == 0
  28220. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28221. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28222. return false;
  28223. const Node* const dest = getNodeForId (destNodeId);
  28224. if (dest == 0
  28225. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28226. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28227. return false;
  28228. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28229. destNodeId, destChannelIndex) == 0;
  28230. }
  28231. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28232. const int sourceChannelIndex,
  28233. const uint32 destNodeId,
  28234. const int destChannelIndex)
  28235. {
  28236. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28237. return false;
  28238. Connection* const c = new Connection();
  28239. c->sourceNodeId = sourceNodeId;
  28240. c->sourceChannelIndex = sourceChannelIndex;
  28241. c->destNodeId = destNodeId;
  28242. c->destChannelIndex = destChannelIndex;
  28243. connections.add (c);
  28244. triggerAsyncUpdate();
  28245. return true;
  28246. }
  28247. void AudioProcessorGraph::removeConnection (const int index)
  28248. {
  28249. connections.remove (index);
  28250. triggerAsyncUpdate();
  28251. }
  28252. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28253. const uint32 destNodeId, const int destChannelIndex)
  28254. {
  28255. bool doneAnything = false;
  28256. for (int i = connections.size(); --i >= 0;)
  28257. {
  28258. const Connection* const c = connections.getUnchecked(i);
  28259. if (c->sourceNodeId == sourceNodeId
  28260. && c->destNodeId == destNodeId
  28261. && c->sourceChannelIndex == sourceChannelIndex
  28262. && c->destChannelIndex == destChannelIndex)
  28263. {
  28264. removeConnection (i);
  28265. doneAnything = true;
  28266. triggerAsyncUpdate();
  28267. }
  28268. }
  28269. return doneAnything;
  28270. }
  28271. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28272. {
  28273. bool doneAnything = false;
  28274. for (int i = connections.size(); --i >= 0;)
  28275. {
  28276. const Connection* const c = connections.getUnchecked(i);
  28277. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28278. {
  28279. removeConnection (i);
  28280. doneAnything = true;
  28281. triggerAsyncUpdate();
  28282. }
  28283. }
  28284. return doneAnything;
  28285. }
  28286. bool AudioProcessorGraph::removeIllegalConnections()
  28287. {
  28288. bool doneAnything = false;
  28289. for (int i = connections.size(); --i >= 0;)
  28290. {
  28291. const Connection* const c = connections.getUnchecked(i);
  28292. const Node* const source = getNodeForId (c->sourceNodeId);
  28293. const Node* const dest = getNodeForId (c->destNodeId);
  28294. if (source == 0 || dest == 0
  28295. || (c->sourceChannelIndex != midiChannelIndex
  28296. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28297. || (c->sourceChannelIndex == midiChannelIndex
  28298. && ! source->processor->producesMidi())
  28299. || (c->destChannelIndex != midiChannelIndex
  28300. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28301. || (c->destChannelIndex == midiChannelIndex
  28302. && ! dest->processor->acceptsMidi()))
  28303. {
  28304. removeConnection (i);
  28305. doneAnything = true;
  28306. triggerAsyncUpdate();
  28307. }
  28308. }
  28309. return doneAnything;
  28310. }
  28311. namespace GraphRenderingOps
  28312. {
  28313. class AudioGraphRenderingOp
  28314. {
  28315. public:
  28316. AudioGraphRenderingOp() {}
  28317. virtual ~AudioGraphRenderingOp() {}
  28318. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28319. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28320. const int numSamples) = 0;
  28321. juce_UseDebuggingNewOperator
  28322. };
  28323. class ClearChannelOp : public AudioGraphRenderingOp
  28324. {
  28325. public:
  28326. ClearChannelOp (const int channelNum_)
  28327. : channelNum (channelNum_)
  28328. {}
  28329. ~ClearChannelOp() {}
  28330. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28331. {
  28332. sharedBufferChans.clear (channelNum, 0, numSamples);
  28333. }
  28334. private:
  28335. const int channelNum;
  28336. ClearChannelOp (const ClearChannelOp&);
  28337. const ClearChannelOp& operator= (const ClearChannelOp&);
  28338. };
  28339. class CopyChannelOp : public AudioGraphRenderingOp
  28340. {
  28341. public:
  28342. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28343. : srcChannelNum (srcChannelNum_),
  28344. dstChannelNum (dstChannelNum_)
  28345. {}
  28346. ~CopyChannelOp() {}
  28347. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28348. {
  28349. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28350. }
  28351. private:
  28352. const int srcChannelNum, dstChannelNum;
  28353. CopyChannelOp (const CopyChannelOp&);
  28354. const CopyChannelOp& operator= (const CopyChannelOp&);
  28355. };
  28356. class AddChannelOp : public AudioGraphRenderingOp
  28357. {
  28358. public:
  28359. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28360. : srcChannelNum (srcChannelNum_),
  28361. dstChannelNum (dstChannelNum_)
  28362. {}
  28363. ~AddChannelOp() {}
  28364. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28365. {
  28366. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28367. }
  28368. private:
  28369. const int srcChannelNum, dstChannelNum;
  28370. AddChannelOp (const AddChannelOp&);
  28371. const AddChannelOp& operator= (const AddChannelOp&);
  28372. };
  28373. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28374. {
  28375. public:
  28376. ClearMidiBufferOp (const int bufferNum_)
  28377. : bufferNum (bufferNum_)
  28378. {}
  28379. ~ClearMidiBufferOp() {}
  28380. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28381. {
  28382. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28383. }
  28384. private:
  28385. const int bufferNum;
  28386. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28387. const ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28388. };
  28389. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28390. {
  28391. public:
  28392. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28393. : srcBufferNum (srcBufferNum_),
  28394. dstBufferNum (dstBufferNum_)
  28395. {}
  28396. ~CopyMidiBufferOp() {}
  28397. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28398. {
  28399. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28400. }
  28401. private:
  28402. const int srcBufferNum, dstBufferNum;
  28403. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28404. const CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28405. };
  28406. class AddMidiBufferOp : public AudioGraphRenderingOp
  28407. {
  28408. public:
  28409. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28410. : srcBufferNum (srcBufferNum_),
  28411. dstBufferNum (dstBufferNum_)
  28412. {}
  28413. ~AddMidiBufferOp() {}
  28414. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28415. {
  28416. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28417. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28418. }
  28419. private:
  28420. const int srcBufferNum, dstBufferNum;
  28421. AddMidiBufferOp (const AddMidiBufferOp&);
  28422. const AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28423. };
  28424. class ProcessBufferOp : public AudioGraphRenderingOp
  28425. {
  28426. public:
  28427. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28428. const Array <int>& audioChannelsToUse_,
  28429. const int totalChans_,
  28430. const int midiBufferToUse_)
  28431. : node (node_),
  28432. processor (node_->processor),
  28433. audioChannelsToUse (audioChannelsToUse_),
  28434. totalChans (jmax (1, totalChans_)),
  28435. midiBufferToUse (midiBufferToUse_)
  28436. {
  28437. channels.calloc (totalChans);
  28438. while (audioChannelsToUse.size() < totalChans)
  28439. audioChannelsToUse.add (0);
  28440. }
  28441. ~ProcessBufferOp()
  28442. {
  28443. }
  28444. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28445. {
  28446. for (int i = totalChans; --i >= 0;)
  28447. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28448. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28449. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28450. }
  28451. const AudioProcessorGraph::Node::Ptr node;
  28452. AudioProcessor* const processor;
  28453. private:
  28454. Array <int> audioChannelsToUse;
  28455. HeapBlock <float*> channels;
  28456. int totalChans;
  28457. int midiBufferToUse;
  28458. ProcessBufferOp (const ProcessBufferOp&);
  28459. const ProcessBufferOp& operator= (const ProcessBufferOp&);
  28460. };
  28461. class RenderingOpSequenceCalculator
  28462. {
  28463. public:
  28464. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28465. const VoidArray& orderedNodes_,
  28466. VoidArray& renderingOps)
  28467. : graph (graph_),
  28468. orderedNodes (orderedNodes_)
  28469. {
  28470. nodeIds.add (-2); // first buffer is read-only zeros
  28471. channels.add (0);
  28472. midiNodeIds.add (-2);
  28473. for (int i = 0; i < orderedNodes.size(); ++i)
  28474. {
  28475. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28476. renderingOps, i);
  28477. markAnyUnusedBuffersAsFree (i);
  28478. }
  28479. }
  28480. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28481. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28482. juce_UseDebuggingNewOperator
  28483. private:
  28484. AudioProcessorGraph& graph;
  28485. const VoidArray& orderedNodes;
  28486. Array <int> nodeIds, channels, midiNodeIds;
  28487. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28488. VoidArray& renderingOps,
  28489. const int ourRenderingIndex)
  28490. {
  28491. const int numIns = node->processor->getNumInputChannels();
  28492. const int numOuts = node->processor->getNumOutputChannels();
  28493. const int totalChans = jmax (numIns, numOuts);
  28494. Array <int> audioChannelsToUse;
  28495. int midiBufferToUse = -1;
  28496. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28497. {
  28498. // get a list of all the inputs to this node
  28499. Array <int> sourceNodes, sourceOutputChans;
  28500. for (int i = graph.getNumConnections(); --i >= 0;)
  28501. {
  28502. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28503. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28504. {
  28505. sourceNodes.add (c->sourceNodeId);
  28506. sourceOutputChans.add (c->sourceChannelIndex);
  28507. }
  28508. }
  28509. int bufIndex = -1;
  28510. if (sourceNodes.size() == 0)
  28511. {
  28512. // unconnected input channel
  28513. if (inputChan >= numOuts)
  28514. {
  28515. bufIndex = getReadOnlyEmptyBuffer();
  28516. jassert (bufIndex >= 0);
  28517. }
  28518. else
  28519. {
  28520. bufIndex = getFreeBuffer (false);
  28521. renderingOps.add (new ClearChannelOp (bufIndex));
  28522. }
  28523. }
  28524. else if (sourceNodes.size() == 1)
  28525. {
  28526. // channel with a straightforward single input..
  28527. const int srcNode = sourceNodes.getUnchecked(0);
  28528. const int srcChan = sourceOutputChans.getUnchecked(0);
  28529. bufIndex = getBufferContaining (srcNode, srcChan);
  28530. if (bufIndex < 0)
  28531. {
  28532. // if not found, this is probably a feedback loop
  28533. bufIndex = getReadOnlyEmptyBuffer();
  28534. jassert (bufIndex >= 0);
  28535. }
  28536. if (inputChan < numOuts
  28537. && isBufferNeededLater (ourRenderingIndex,
  28538. inputChan,
  28539. srcNode, srcChan))
  28540. {
  28541. // can't mess up this channel because it's needed later by another node, so we
  28542. // need to use a copy of it..
  28543. const int newFreeBuffer = getFreeBuffer (false);
  28544. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28545. bufIndex = newFreeBuffer;
  28546. }
  28547. }
  28548. else
  28549. {
  28550. // channel with a mix of several inputs..
  28551. // try to find a re-usable channel from our inputs..
  28552. int reusableInputIndex = -1;
  28553. for (int i = 0; i < sourceNodes.size(); ++i)
  28554. {
  28555. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28556. sourceOutputChans.getUnchecked(i));
  28557. if (sourceBufIndex >= 0
  28558. && ! isBufferNeededLater (ourRenderingIndex,
  28559. inputChan,
  28560. sourceNodes.getUnchecked(i),
  28561. sourceOutputChans.getUnchecked(i)))
  28562. {
  28563. // we've found one of our input chans that can be re-used..
  28564. reusableInputIndex = i;
  28565. bufIndex = sourceBufIndex;
  28566. break;
  28567. }
  28568. }
  28569. if (reusableInputIndex < 0)
  28570. {
  28571. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28572. bufIndex = getFreeBuffer (false);
  28573. jassert (bufIndex != 0);
  28574. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28575. sourceOutputChans.getUnchecked (0));
  28576. if (srcIndex < 0)
  28577. {
  28578. // if not found, this is probably a feedback loop
  28579. renderingOps.add (new ClearChannelOp (bufIndex));
  28580. }
  28581. else
  28582. {
  28583. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28584. }
  28585. reusableInputIndex = 0;
  28586. }
  28587. for (int j = 0; j < sourceNodes.size(); ++j)
  28588. {
  28589. if (j != reusableInputIndex)
  28590. {
  28591. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28592. sourceOutputChans.getUnchecked(j));
  28593. if (srcIndex >= 0)
  28594. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28595. }
  28596. }
  28597. }
  28598. jassert (bufIndex >= 0);
  28599. audioChannelsToUse.add (bufIndex);
  28600. if (inputChan < numOuts)
  28601. markBufferAsContaining (bufIndex, node->id, inputChan);
  28602. }
  28603. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28604. {
  28605. const int bufIndex = getFreeBuffer (false);
  28606. jassert (bufIndex != 0);
  28607. audioChannelsToUse.add (bufIndex);
  28608. markBufferAsContaining (bufIndex, node->id, outputChan);
  28609. }
  28610. // Now the same thing for midi..
  28611. Array <int> midiSourceNodes;
  28612. for (int i = graph.getNumConnections(); --i >= 0;)
  28613. {
  28614. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28615. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28616. midiSourceNodes.add (c->sourceNodeId);
  28617. }
  28618. if (midiSourceNodes.size() == 0)
  28619. {
  28620. // No midi inputs..
  28621. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28622. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28623. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28624. }
  28625. else if (midiSourceNodes.size() == 1)
  28626. {
  28627. // One midi input..
  28628. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28629. AudioProcessorGraph::midiChannelIndex);
  28630. if (midiBufferToUse >= 0)
  28631. {
  28632. if (isBufferNeededLater (ourRenderingIndex,
  28633. AudioProcessorGraph::midiChannelIndex,
  28634. midiSourceNodes.getUnchecked(0),
  28635. AudioProcessorGraph::midiChannelIndex))
  28636. {
  28637. // can't mess up this channel because it's needed later by another node, so we
  28638. // need to use a copy of it..
  28639. const int newFreeBuffer = getFreeBuffer (true);
  28640. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28641. midiBufferToUse = newFreeBuffer;
  28642. }
  28643. }
  28644. else
  28645. {
  28646. // probably a feedback loop, so just use an empty one..
  28647. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28648. }
  28649. }
  28650. else
  28651. {
  28652. // More than one midi input being mixed..
  28653. int reusableInputIndex = -1;
  28654. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28655. {
  28656. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28657. AudioProcessorGraph::midiChannelIndex);
  28658. if (sourceBufIndex >= 0
  28659. && ! isBufferNeededLater (ourRenderingIndex,
  28660. AudioProcessorGraph::midiChannelIndex,
  28661. midiSourceNodes.getUnchecked(i),
  28662. AudioProcessorGraph::midiChannelIndex))
  28663. {
  28664. // we've found one of our input buffers that can be re-used..
  28665. reusableInputIndex = i;
  28666. midiBufferToUse = sourceBufIndex;
  28667. break;
  28668. }
  28669. }
  28670. if (reusableInputIndex < 0)
  28671. {
  28672. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28673. midiBufferToUse = getFreeBuffer (true);
  28674. jassert (midiBufferToUse >= 0);
  28675. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28676. AudioProcessorGraph::midiChannelIndex);
  28677. if (srcIndex >= 0)
  28678. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28679. else
  28680. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28681. reusableInputIndex = 0;
  28682. }
  28683. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28684. {
  28685. if (j != reusableInputIndex)
  28686. {
  28687. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28688. AudioProcessorGraph::midiChannelIndex);
  28689. if (srcIndex >= 0)
  28690. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28691. }
  28692. }
  28693. }
  28694. if (node->processor->producesMidi())
  28695. markBufferAsContaining (midiBufferToUse, node->id,
  28696. AudioProcessorGraph::midiChannelIndex);
  28697. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28698. totalChans, midiBufferToUse));
  28699. }
  28700. int getFreeBuffer (const bool forMidi)
  28701. {
  28702. if (forMidi)
  28703. {
  28704. for (int i = 1; i < midiNodeIds.size(); ++i)
  28705. if (midiNodeIds.getUnchecked(i) < 0)
  28706. return i;
  28707. midiNodeIds.add (-1);
  28708. return midiNodeIds.size() - 1;
  28709. }
  28710. else
  28711. {
  28712. for (int i = 1; i < nodeIds.size(); ++i)
  28713. if (nodeIds.getUnchecked(i) < 0)
  28714. return i;
  28715. nodeIds.add (-1);
  28716. channels.add (0);
  28717. return nodeIds.size() - 1;
  28718. }
  28719. }
  28720. int getReadOnlyEmptyBuffer() const
  28721. {
  28722. return 0;
  28723. }
  28724. int getBufferContaining (const int nodeId, const int outputChannel) const
  28725. {
  28726. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28727. {
  28728. for (int i = midiNodeIds.size(); --i >= 0;)
  28729. if (midiNodeIds.getUnchecked(i) == nodeId)
  28730. return i;
  28731. }
  28732. else
  28733. {
  28734. for (int i = nodeIds.size(); --i >= 0;)
  28735. if (nodeIds.getUnchecked(i) == nodeId
  28736. && channels.getUnchecked(i) == outputChannel)
  28737. return i;
  28738. }
  28739. return -1;
  28740. }
  28741. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28742. {
  28743. int i;
  28744. for (i = 0; i < nodeIds.size(); ++i)
  28745. {
  28746. if (nodeIds.getUnchecked(i) >= 0
  28747. && ! isBufferNeededLater (stepIndex, -1,
  28748. nodeIds.getUnchecked(i),
  28749. channels.getUnchecked(i)))
  28750. {
  28751. nodeIds.set (i, -1);
  28752. }
  28753. }
  28754. for (i = 0; i < midiNodeIds.size(); ++i)
  28755. {
  28756. if (midiNodeIds.getUnchecked(i) >= 0
  28757. && ! isBufferNeededLater (stepIndex, -1,
  28758. midiNodeIds.getUnchecked(i),
  28759. AudioProcessorGraph::midiChannelIndex))
  28760. {
  28761. midiNodeIds.set (i, -1);
  28762. }
  28763. }
  28764. }
  28765. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28766. int inputChannelOfIndexToIgnore,
  28767. const int nodeId,
  28768. const int outputChanIndex) const
  28769. {
  28770. while (stepIndexToSearchFrom < orderedNodes.size())
  28771. {
  28772. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28773. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28774. {
  28775. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28776. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28777. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28778. return true;
  28779. }
  28780. else
  28781. {
  28782. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28783. if (i != inputChannelOfIndexToIgnore
  28784. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28785. node->id, i) != 0)
  28786. return true;
  28787. }
  28788. inputChannelOfIndexToIgnore = -1;
  28789. ++stepIndexToSearchFrom;
  28790. }
  28791. return false;
  28792. }
  28793. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28794. {
  28795. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28796. {
  28797. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28798. midiNodeIds.set (bufferNum, nodeId);
  28799. }
  28800. else
  28801. {
  28802. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28803. nodeIds.set (bufferNum, nodeId);
  28804. channels.set (bufferNum, outputIndex);
  28805. }
  28806. }
  28807. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28808. const RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28809. };
  28810. }
  28811. void AudioProcessorGraph::clearRenderingSequence()
  28812. {
  28813. const ScopedLock sl (renderLock);
  28814. for (int i = renderingOps.size(); --i >= 0;)
  28815. {
  28816. GraphRenderingOps::AudioGraphRenderingOp* const r
  28817. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28818. renderingOps.remove (i);
  28819. delete r;
  28820. }
  28821. }
  28822. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28823. const uint32 possibleDestinationId,
  28824. const int recursionCheck) const
  28825. {
  28826. if (recursionCheck > 0)
  28827. {
  28828. for (int i = connections.size(); --i >= 0;)
  28829. {
  28830. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28831. if (c->destNodeId == possibleDestinationId
  28832. && (c->sourceNodeId == possibleInputId
  28833. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28834. return true;
  28835. }
  28836. }
  28837. return false;
  28838. }
  28839. void AudioProcessorGraph::buildRenderingSequence()
  28840. {
  28841. VoidArray newRenderingOps;
  28842. int numRenderingBuffersNeeded = 2;
  28843. int numMidiBuffersNeeded = 1;
  28844. {
  28845. MessageManagerLock mml;
  28846. VoidArray orderedNodes;
  28847. int i;
  28848. for (i = 0; i < nodes.size(); ++i)
  28849. {
  28850. Node* const node = nodes.getUnchecked(i);
  28851. node->prepare (getSampleRate(), getBlockSize(), this);
  28852. int j = 0;
  28853. for (; j < orderedNodes.size(); ++j)
  28854. if (isAnInputTo (node->id,
  28855. ((Node*) orderedNodes.getUnchecked (j))->id,
  28856. nodes.size() + 1))
  28857. break;
  28858. orderedNodes.insert (j, node);
  28859. }
  28860. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28861. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28862. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28863. }
  28864. VoidArray oldRenderingOps (renderingOps);
  28865. {
  28866. // swap over to the new rendering sequence..
  28867. const ScopedLock sl (renderLock);
  28868. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28869. renderingBuffers.clear();
  28870. for (int i = midiBuffers.size(); --i >= 0;)
  28871. midiBuffers.getUnchecked(i)->clear();
  28872. while (midiBuffers.size() < numMidiBuffersNeeded)
  28873. midiBuffers.add (new MidiBuffer());
  28874. renderingOps = newRenderingOps;
  28875. }
  28876. for (int i = oldRenderingOps.size(); --i >= 0;)
  28877. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28878. }
  28879. void AudioProcessorGraph::handleAsyncUpdate()
  28880. {
  28881. buildRenderingSequence();
  28882. }
  28883. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28884. {
  28885. currentAudioInputBuffer = 0;
  28886. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28887. currentMidiInputBuffer = 0;
  28888. currentMidiOutputBuffer.clear();
  28889. clearRenderingSequence();
  28890. buildRenderingSequence();
  28891. }
  28892. void AudioProcessorGraph::releaseResources()
  28893. {
  28894. for (int i = 0; i < nodes.size(); ++i)
  28895. nodes.getUnchecked(i)->unprepare();
  28896. renderingBuffers.setSize (1, 1);
  28897. midiBuffers.clear();
  28898. currentAudioInputBuffer = 0;
  28899. currentAudioOutputBuffer.setSize (1, 1);
  28900. currentMidiInputBuffer = 0;
  28901. currentMidiOutputBuffer.clear();
  28902. }
  28903. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28904. {
  28905. const int numSamples = buffer.getNumSamples();
  28906. const ScopedLock sl (renderLock);
  28907. currentAudioInputBuffer = &buffer;
  28908. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28909. currentAudioOutputBuffer.clear();
  28910. currentMidiInputBuffer = &midiMessages;
  28911. currentMidiOutputBuffer.clear();
  28912. int i;
  28913. for (i = 0; i < renderingOps.size(); ++i)
  28914. {
  28915. GraphRenderingOps::AudioGraphRenderingOp* const op
  28916. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28917. op->perform (renderingBuffers, midiBuffers, numSamples);
  28918. }
  28919. for (i = 0; i < buffer.getNumChannels(); ++i)
  28920. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28921. midiMessages.clear();
  28922. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28923. }
  28924. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28925. {
  28926. return "Input " + String (channelIndex + 1);
  28927. }
  28928. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28929. {
  28930. return "Output " + String (channelIndex + 1);
  28931. }
  28932. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28933. {
  28934. return true;
  28935. }
  28936. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28937. {
  28938. return true;
  28939. }
  28940. bool AudioProcessorGraph::acceptsMidi() const
  28941. {
  28942. return true;
  28943. }
  28944. bool AudioProcessorGraph::producesMidi() const
  28945. {
  28946. return true;
  28947. }
  28948. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28949. {
  28950. }
  28951. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28952. {
  28953. }
  28954. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28955. : type (type_),
  28956. graph (0)
  28957. {
  28958. }
  28959. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28960. {
  28961. }
  28962. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28963. {
  28964. switch (type)
  28965. {
  28966. case audioOutputNode:
  28967. return "Audio Output";
  28968. case audioInputNode:
  28969. return "Audio Input";
  28970. case midiOutputNode:
  28971. return "Midi Output";
  28972. case midiInputNode:
  28973. return "Midi Input";
  28974. default:
  28975. break;
  28976. }
  28977. return String::empty;
  28978. }
  28979. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28980. {
  28981. d.name = getName();
  28982. d.uid = d.name.hashCode();
  28983. d.category = "I/O devices";
  28984. d.pluginFormatName = "Internal";
  28985. d.manufacturerName = "Raw Material Software";
  28986. d.version = "1.0";
  28987. d.isInstrument = false;
  28988. d.numInputChannels = getNumInputChannels();
  28989. if (type == audioOutputNode && graph != 0)
  28990. d.numInputChannels = graph->getNumInputChannels();
  28991. d.numOutputChannels = getNumOutputChannels();
  28992. if (type == audioInputNode && graph != 0)
  28993. d.numOutputChannels = graph->getNumOutputChannels();
  28994. }
  28995. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28996. {
  28997. jassert (graph != 0);
  28998. }
  28999. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  29000. {
  29001. }
  29002. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  29003. MidiBuffer& midiMessages)
  29004. {
  29005. jassert (graph != 0);
  29006. switch (type)
  29007. {
  29008. case audioOutputNode:
  29009. {
  29010. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  29011. buffer.getNumChannels()); --i >= 0;)
  29012. {
  29013. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  29014. }
  29015. break;
  29016. }
  29017. case audioInputNode:
  29018. {
  29019. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  29020. buffer.getNumChannels()); --i >= 0;)
  29021. {
  29022. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  29023. }
  29024. break;
  29025. }
  29026. case midiOutputNode:
  29027. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  29028. break;
  29029. case midiInputNode:
  29030. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  29031. break;
  29032. default:
  29033. break;
  29034. }
  29035. }
  29036. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  29037. {
  29038. return type == midiOutputNode;
  29039. }
  29040. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  29041. {
  29042. return type == midiInputNode;
  29043. }
  29044. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  29045. {
  29046. switch (type)
  29047. {
  29048. case audioOutputNode:
  29049. return "Output " + String (channelIndex + 1);
  29050. case midiOutputNode:
  29051. return "Midi Output";
  29052. default:
  29053. break;
  29054. }
  29055. return String::empty;
  29056. }
  29057. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29058. {
  29059. switch (type)
  29060. {
  29061. case audioInputNode:
  29062. return "Input " + String (channelIndex + 1);
  29063. case midiInputNode:
  29064. return "Midi Input";
  29065. default:
  29066. break;
  29067. }
  29068. return String::empty;
  29069. }
  29070. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29071. {
  29072. return type == audioInputNode || type == audioOutputNode;
  29073. }
  29074. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29075. {
  29076. return isInputChannelStereoPair (index);
  29077. }
  29078. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29079. {
  29080. return type == audioInputNode || type == midiInputNode;
  29081. }
  29082. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29083. {
  29084. return type == audioOutputNode || type == midiOutputNode;
  29085. }
  29086. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29087. {
  29088. return 0;
  29089. }
  29090. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29091. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29092. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29093. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29094. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29095. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29096. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29097. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29098. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29099. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29100. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29101. {
  29102. }
  29103. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29104. {
  29105. }
  29106. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29107. {
  29108. graph = newGraph;
  29109. if (graph != 0)
  29110. {
  29111. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29112. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29113. getSampleRate(),
  29114. getBlockSize());
  29115. updateHostDisplay();
  29116. }
  29117. }
  29118. END_JUCE_NAMESPACE
  29119. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29120. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29121. BEGIN_JUCE_NAMESPACE
  29122. AudioProcessorPlayer::AudioProcessorPlayer()
  29123. : processor (0),
  29124. sampleRate (0),
  29125. blockSize (0),
  29126. isPrepared (false),
  29127. numInputChans (0),
  29128. numOutputChans (0),
  29129. tempBuffer (1, 1)
  29130. {
  29131. }
  29132. AudioProcessorPlayer::~AudioProcessorPlayer()
  29133. {
  29134. setProcessor (0);
  29135. }
  29136. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29137. {
  29138. if (processor != processorToPlay)
  29139. {
  29140. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29141. {
  29142. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29143. sampleRate, blockSize);
  29144. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29145. }
  29146. lock.enter();
  29147. AudioProcessor* const oldOne = isPrepared ? processor : 0;
  29148. processor = processorToPlay;
  29149. isPrepared = true;
  29150. lock.exit();
  29151. if (oldOne != 0)
  29152. oldOne->releaseResources();
  29153. }
  29154. }
  29155. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29156. int numInputChannels,
  29157. float** outputChannelData,
  29158. int numOutputChannels,
  29159. int numSamples)
  29160. {
  29161. // these should have been prepared by audioDeviceAboutToStart()...
  29162. jassert (sampleRate > 0 && blockSize > 0);
  29163. incomingMidi.clear();
  29164. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29165. int i, totalNumChans = 0;
  29166. if (numInputChannels > numOutputChannels)
  29167. {
  29168. // if there aren't enough output channels for the number of
  29169. // inputs, we need to create some temporary extra ones (can't
  29170. // use the input data in case it gets written to)
  29171. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29172. false, false, true);
  29173. for (i = 0; i < numOutputChannels; ++i)
  29174. {
  29175. channels[totalNumChans] = outputChannelData[i];
  29176. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29177. ++totalNumChans;
  29178. }
  29179. for (i = numOutputChannels; i < numInputChannels; ++i)
  29180. {
  29181. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29182. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29183. ++totalNumChans;
  29184. }
  29185. }
  29186. else
  29187. {
  29188. for (i = 0; i < numInputChannels; ++i)
  29189. {
  29190. channels[totalNumChans] = outputChannelData[i];
  29191. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29192. ++totalNumChans;
  29193. }
  29194. for (i = numInputChannels; i < numOutputChannels; ++i)
  29195. {
  29196. channels[totalNumChans] = outputChannelData[i];
  29197. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29198. ++totalNumChans;
  29199. }
  29200. }
  29201. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29202. const ScopedLock sl (lock);
  29203. if (processor != 0)
  29204. processor->processBlock (buffer, incomingMidi);
  29205. }
  29206. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29207. {
  29208. const ScopedLock sl (lock);
  29209. sampleRate = device->getCurrentSampleRate();
  29210. blockSize = device->getCurrentBufferSizeSamples();
  29211. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29212. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29213. messageCollector.reset (sampleRate);
  29214. zeromem (channels, sizeof (channels));
  29215. if (processor != 0)
  29216. {
  29217. if (isPrepared)
  29218. processor->releaseResources();
  29219. AudioProcessor* const oldProcessor = processor;
  29220. setProcessor (0);
  29221. setProcessor (oldProcessor);
  29222. }
  29223. }
  29224. void AudioProcessorPlayer::audioDeviceStopped()
  29225. {
  29226. const ScopedLock sl (lock);
  29227. if (processor != 0 && isPrepared)
  29228. processor->releaseResources();
  29229. sampleRate = 0.0;
  29230. blockSize = 0;
  29231. isPrepared = false;
  29232. tempBuffer.setSize (1, 1);
  29233. }
  29234. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29235. {
  29236. messageCollector.addMessageToQueue (message);
  29237. }
  29238. END_JUCE_NAMESPACE
  29239. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29240. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29241. BEGIN_JUCE_NAMESPACE
  29242. class ProcessorParameterPropertyComp : public PropertyComponent,
  29243. public AudioProcessorListener,
  29244. public AsyncUpdater
  29245. {
  29246. public:
  29247. ProcessorParameterPropertyComp (const String& name,
  29248. AudioProcessor* const owner_,
  29249. const int index_)
  29250. : PropertyComponent (name),
  29251. owner (owner_),
  29252. index (index_)
  29253. {
  29254. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29255. owner_->addListener (this);
  29256. }
  29257. ~ProcessorParameterPropertyComp()
  29258. {
  29259. owner->removeListener (this);
  29260. deleteAllChildren();
  29261. }
  29262. void refresh()
  29263. {
  29264. slider->setValue (owner->getParameter (index), false);
  29265. }
  29266. void audioProcessorChanged (AudioProcessor*) {}
  29267. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29268. {
  29269. if (parameterIndex == index)
  29270. triggerAsyncUpdate();
  29271. }
  29272. void handleAsyncUpdate()
  29273. {
  29274. refresh();
  29275. }
  29276. juce_UseDebuggingNewOperator
  29277. private:
  29278. AudioProcessor* const owner;
  29279. const int index;
  29280. Slider* slider;
  29281. class ParamSlider : public Slider
  29282. {
  29283. public:
  29284. ParamSlider (AudioProcessor* const owner_, const int index_)
  29285. : Slider (String::empty),
  29286. owner (owner_),
  29287. index (index_)
  29288. {
  29289. setRange (0.0, 1.0, 0.0);
  29290. setSliderStyle (Slider::LinearBar);
  29291. setTextBoxIsEditable (false);
  29292. setScrollWheelEnabled (false);
  29293. }
  29294. ~ParamSlider()
  29295. {
  29296. }
  29297. void valueChanged()
  29298. {
  29299. const float newVal = (float) getValue();
  29300. if (owner->getParameter (index) != newVal)
  29301. owner->setParameter (index, newVal);
  29302. }
  29303. const String getTextFromValue (double /*value*/)
  29304. {
  29305. return owner->getParameterText (index);
  29306. }
  29307. juce_UseDebuggingNewOperator
  29308. private:
  29309. AudioProcessor* const owner;
  29310. const int index;
  29311. ParamSlider (const ParamSlider&);
  29312. const ParamSlider& operator= (const ParamSlider&);
  29313. };
  29314. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29315. const ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29316. };
  29317. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29318. : AudioProcessorEditor (owner_)
  29319. {
  29320. setOpaque (true);
  29321. addAndMakeVisible (panel = new PropertyPanel());
  29322. Array <PropertyComponent*> params;
  29323. const int numParams = owner_->getNumParameters();
  29324. int totalHeight = 0;
  29325. for (int i = 0; i < numParams; ++i)
  29326. {
  29327. String name (owner_->getParameterName (i));
  29328. if (name.trim().isEmpty())
  29329. name = "Unnamed";
  29330. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29331. params.add (pc);
  29332. totalHeight += pc->getPreferredHeight();
  29333. }
  29334. panel->addProperties (params);
  29335. setSize (400, jlimit (25, 400, totalHeight));
  29336. }
  29337. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29338. {
  29339. deleteAllChildren();
  29340. }
  29341. void GenericAudioProcessorEditor::paint (Graphics& g)
  29342. {
  29343. g.fillAll (Colours::white);
  29344. }
  29345. void GenericAudioProcessorEditor::resized()
  29346. {
  29347. panel->setSize (getWidth(), getHeight());
  29348. }
  29349. END_JUCE_NAMESPACE
  29350. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29351. /*** Start of inlined file: juce_Sampler.cpp ***/
  29352. BEGIN_JUCE_NAMESPACE
  29353. SamplerSound::SamplerSound (const String& name_,
  29354. AudioFormatReader& source,
  29355. const BitArray& midiNotes_,
  29356. const int midiNoteForNormalPitch,
  29357. const double attackTimeSecs,
  29358. const double releaseTimeSecs,
  29359. const double maxSampleLengthSeconds)
  29360. : name (name_),
  29361. midiNotes (midiNotes_),
  29362. midiRootNote (midiNoteForNormalPitch)
  29363. {
  29364. sourceSampleRate = source.sampleRate;
  29365. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29366. {
  29367. length = 0;
  29368. attackSamples = 0;
  29369. releaseSamples = 0;
  29370. }
  29371. else
  29372. {
  29373. length = jmin ((int) source.lengthInSamples,
  29374. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29375. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29376. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29377. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29378. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29379. }
  29380. }
  29381. SamplerSound::~SamplerSound()
  29382. {
  29383. }
  29384. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29385. {
  29386. return midiNotes [midiNoteNumber];
  29387. }
  29388. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29389. {
  29390. return true;
  29391. }
  29392. SamplerVoice::SamplerVoice()
  29393. : pitchRatio (0.0),
  29394. sourceSamplePosition (0.0),
  29395. lgain (0.0f),
  29396. rgain (0.0f),
  29397. isInAttack (false),
  29398. isInRelease (false)
  29399. {
  29400. }
  29401. SamplerVoice::~SamplerVoice()
  29402. {
  29403. }
  29404. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29405. {
  29406. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29407. }
  29408. void SamplerVoice::startNote (const int midiNoteNumber,
  29409. const float velocity,
  29410. SynthesiserSound* s,
  29411. const int /*currentPitchWheelPosition*/)
  29412. {
  29413. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29414. jassert (sound != 0); // this object can only play SamplerSounds!
  29415. if (sound != 0)
  29416. {
  29417. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29418. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29419. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29420. sourceSamplePosition = 0.0;
  29421. lgain = velocity;
  29422. rgain = velocity;
  29423. isInAttack = (sound->attackSamples > 0);
  29424. isInRelease = false;
  29425. if (isInAttack)
  29426. {
  29427. attackReleaseLevel = 0.0f;
  29428. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29429. }
  29430. else
  29431. {
  29432. attackReleaseLevel = 1.0f;
  29433. attackDelta = 0.0f;
  29434. }
  29435. if (sound->releaseSamples > 0)
  29436. {
  29437. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29438. }
  29439. else
  29440. {
  29441. releaseDelta = 0.0f;
  29442. }
  29443. }
  29444. }
  29445. void SamplerVoice::stopNote (const bool allowTailOff)
  29446. {
  29447. if (allowTailOff)
  29448. {
  29449. isInAttack = false;
  29450. isInRelease = true;
  29451. }
  29452. else
  29453. {
  29454. clearCurrentNote();
  29455. }
  29456. }
  29457. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29458. {
  29459. }
  29460. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29461. const int /*newValue*/)
  29462. {
  29463. }
  29464. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29465. {
  29466. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29467. if (playingSound != 0)
  29468. {
  29469. const float* const inL = playingSound->data->getSampleData (0, 0);
  29470. const float* const inR = playingSound->data->getNumChannels() > 1
  29471. ? playingSound->data->getSampleData (1, 0) : 0;
  29472. float* outL = outputBuffer.getSampleData (0, startSample);
  29473. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29474. while (--numSamples >= 0)
  29475. {
  29476. const int pos = (int) sourceSamplePosition;
  29477. const float alpha = (float) (sourceSamplePosition - pos);
  29478. const float invAlpha = 1.0f - alpha;
  29479. // just using a very simple linear interpolation here..
  29480. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29481. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29482. : l;
  29483. l *= lgain;
  29484. r *= rgain;
  29485. if (isInAttack)
  29486. {
  29487. l *= attackReleaseLevel;
  29488. r *= attackReleaseLevel;
  29489. attackReleaseLevel += attackDelta;
  29490. if (attackReleaseLevel >= 1.0f)
  29491. {
  29492. attackReleaseLevel = 1.0f;
  29493. isInAttack = false;
  29494. }
  29495. }
  29496. else if (isInRelease)
  29497. {
  29498. l *= attackReleaseLevel;
  29499. r *= attackReleaseLevel;
  29500. attackReleaseLevel += releaseDelta;
  29501. if (attackReleaseLevel <= 0.0f)
  29502. {
  29503. stopNote (false);
  29504. break;
  29505. }
  29506. }
  29507. if (outR != 0)
  29508. {
  29509. *outL++ += l;
  29510. *outR++ += r;
  29511. }
  29512. else
  29513. {
  29514. *outL++ += (l + r) * 0.5f;
  29515. }
  29516. sourceSamplePosition += pitchRatio;
  29517. if (sourceSamplePosition > playingSound->length)
  29518. {
  29519. stopNote (false);
  29520. break;
  29521. }
  29522. }
  29523. }
  29524. }
  29525. END_JUCE_NAMESPACE
  29526. /*** End of inlined file: juce_Sampler.cpp ***/
  29527. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29528. BEGIN_JUCE_NAMESPACE
  29529. SynthesiserSound::SynthesiserSound()
  29530. {
  29531. }
  29532. SynthesiserSound::~SynthesiserSound()
  29533. {
  29534. }
  29535. SynthesiserVoice::SynthesiserVoice()
  29536. : currentSampleRate (44100.0),
  29537. currentlyPlayingNote (-1),
  29538. noteOnTime (0),
  29539. currentlyPlayingSound (0)
  29540. {
  29541. }
  29542. SynthesiserVoice::~SynthesiserVoice()
  29543. {
  29544. }
  29545. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29546. {
  29547. return currentlyPlayingSound != 0
  29548. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29549. }
  29550. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29551. {
  29552. currentSampleRate = newRate;
  29553. }
  29554. void SynthesiserVoice::clearCurrentNote()
  29555. {
  29556. currentlyPlayingNote = -1;
  29557. currentlyPlayingSound = 0;
  29558. }
  29559. Synthesiser::Synthesiser()
  29560. : sampleRate (0),
  29561. lastNoteOnCounter (0),
  29562. shouldStealNotes (true)
  29563. {
  29564. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29565. lastPitchWheelValues[i] = 0x2000;
  29566. }
  29567. Synthesiser::~Synthesiser()
  29568. {
  29569. }
  29570. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29571. {
  29572. const ScopedLock sl (lock);
  29573. return voices [index];
  29574. }
  29575. void Synthesiser::clearVoices()
  29576. {
  29577. const ScopedLock sl (lock);
  29578. voices.clear();
  29579. }
  29580. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29581. {
  29582. const ScopedLock sl (lock);
  29583. voices.add (newVoice);
  29584. }
  29585. void Synthesiser::removeVoice (const int index)
  29586. {
  29587. const ScopedLock sl (lock);
  29588. voices.remove (index);
  29589. }
  29590. void Synthesiser::clearSounds()
  29591. {
  29592. const ScopedLock sl (lock);
  29593. sounds.clear();
  29594. }
  29595. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29596. {
  29597. const ScopedLock sl (lock);
  29598. sounds.add (newSound);
  29599. }
  29600. void Synthesiser::removeSound (const int index)
  29601. {
  29602. const ScopedLock sl (lock);
  29603. sounds.remove (index);
  29604. }
  29605. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29606. {
  29607. shouldStealNotes = shouldStealNotes_;
  29608. }
  29609. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29610. {
  29611. if (sampleRate != newRate)
  29612. {
  29613. const ScopedLock sl (lock);
  29614. allNotesOff (0, false);
  29615. sampleRate = newRate;
  29616. for (int i = voices.size(); --i >= 0;)
  29617. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29618. }
  29619. }
  29620. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29621. const MidiBuffer& midiData,
  29622. int startSample,
  29623. int numSamples)
  29624. {
  29625. // must set the sample rate before using this!
  29626. jassert (sampleRate != 0);
  29627. const ScopedLock sl (lock);
  29628. MidiBuffer::Iterator midiIterator (midiData);
  29629. midiIterator.setNextSamplePosition (startSample);
  29630. MidiMessage m (0xf4, 0.0);
  29631. while (numSamples > 0)
  29632. {
  29633. int midiEventPos;
  29634. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29635. && midiEventPos < startSample + numSamples;
  29636. const int numThisTime = useEvent ? midiEventPos - startSample
  29637. : numSamples;
  29638. if (numThisTime > 0)
  29639. {
  29640. for (int i = voices.size(); --i >= 0;)
  29641. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29642. }
  29643. if (useEvent)
  29644. {
  29645. if (m.isNoteOn())
  29646. {
  29647. const int channel = m.getChannel();
  29648. noteOn (channel,
  29649. m.getNoteNumber(),
  29650. m.getFloatVelocity());
  29651. }
  29652. else if (m.isNoteOff())
  29653. {
  29654. noteOff (m.getChannel(),
  29655. m.getNoteNumber(),
  29656. true);
  29657. }
  29658. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29659. {
  29660. allNotesOff (m.getChannel(), true);
  29661. }
  29662. else if (m.isPitchWheel())
  29663. {
  29664. const int channel = m.getChannel();
  29665. const int wheelPos = m.getPitchWheelValue();
  29666. lastPitchWheelValues [channel - 1] = wheelPos;
  29667. handlePitchWheel (channel, wheelPos);
  29668. }
  29669. else if (m.isController())
  29670. {
  29671. handleController (m.getChannel(),
  29672. m.getControllerNumber(),
  29673. m.getControllerValue());
  29674. }
  29675. }
  29676. startSample += numThisTime;
  29677. numSamples -= numThisTime;
  29678. }
  29679. }
  29680. void Synthesiser::noteOn (const int midiChannel,
  29681. const int midiNoteNumber,
  29682. const float velocity)
  29683. {
  29684. const ScopedLock sl (lock);
  29685. for (int i = sounds.size(); --i >= 0;)
  29686. {
  29687. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29688. if (sound->appliesToNote (midiNoteNumber)
  29689. && sound->appliesToChannel (midiChannel))
  29690. {
  29691. startVoice (findFreeVoice (sound, shouldStealNotes),
  29692. sound, midiChannel, midiNoteNumber, velocity);
  29693. }
  29694. }
  29695. }
  29696. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29697. SynthesiserSound* const sound,
  29698. const int midiChannel,
  29699. const int midiNoteNumber,
  29700. const float velocity)
  29701. {
  29702. if (voice != 0 && sound != 0)
  29703. {
  29704. if (voice->currentlyPlayingSound != 0)
  29705. voice->stopNote (false);
  29706. voice->startNote (midiNoteNumber,
  29707. velocity,
  29708. sound,
  29709. lastPitchWheelValues [midiChannel - 1]);
  29710. voice->currentlyPlayingNote = midiNoteNumber;
  29711. voice->noteOnTime = ++lastNoteOnCounter;
  29712. voice->currentlyPlayingSound = sound;
  29713. }
  29714. }
  29715. void Synthesiser::noteOff (const int midiChannel,
  29716. const int midiNoteNumber,
  29717. const bool allowTailOff)
  29718. {
  29719. const ScopedLock sl (lock);
  29720. for (int i = voices.size(); --i >= 0;)
  29721. {
  29722. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29723. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29724. {
  29725. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29726. if (sound != 0
  29727. && sound->appliesToNote (midiNoteNumber)
  29728. && sound->appliesToChannel (midiChannel))
  29729. {
  29730. voice->stopNote (allowTailOff);
  29731. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29732. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29733. }
  29734. }
  29735. }
  29736. }
  29737. void Synthesiser::allNotesOff (const int midiChannel,
  29738. const bool allowTailOff)
  29739. {
  29740. const ScopedLock sl (lock);
  29741. for (int i = voices.size(); --i >= 0;)
  29742. {
  29743. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29744. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29745. voice->stopNote (allowTailOff);
  29746. }
  29747. }
  29748. void Synthesiser::handlePitchWheel (const int midiChannel,
  29749. const int wheelValue)
  29750. {
  29751. const ScopedLock sl (lock);
  29752. for (int i = voices.size(); --i >= 0;)
  29753. {
  29754. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29755. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29756. {
  29757. voice->pitchWheelMoved (wheelValue);
  29758. }
  29759. }
  29760. }
  29761. void Synthesiser::handleController (const int midiChannel,
  29762. const int controllerNumber,
  29763. const int controllerValue)
  29764. {
  29765. const ScopedLock sl (lock);
  29766. for (int i = voices.size(); --i >= 0;)
  29767. {
  29768. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29769. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29770. voice->controllerMoved (controllerNumber, controllerValue);
  29771. }
  29772. }
  29773. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29774. const bool stealIfNoneAvailable) const
  29775. {
  29776. const ScopedLock sl (lock);
  29777. for (int i = voices.size(); --i >= 0;)
  29778. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29779. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29780. return voices.getUnchecked (i);
  29781. if (stealIfNoneAvailable)
  29782. {
  29783. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29784. SynthesiserVoice* oldest = 0;
  29785. for (int i = voices.size(); --i >= 0;)
  29786. {
  29787. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29788. if (voice->canPlaySound (soundToPlay)
  29789. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29790. oldest = voice;
  29791. }
  29792. jassert (oldest != 0);
  29793. return oldest;
  29794. }
  29795. return 0;
  29796. }
  29797. END_JUCE_NAMESPACE
  29798. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29799. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29800. BEGIN_JUCE_NAMESPACE
  29801. ActionBroadcaster::ActionBroadcaster() throw()
  29802. {
  29803. // are you trying to create this object before or after juce has been intialised??
  29804. jassert (MessageManager::instance != 0);
  29805. }
  29806. ActionBroadcaster::~ActionBroadcaster()
  29807. {
  29808. // all event-based objects must be deleted BEFORE juce is shut down!
  29809. jassert (MessageManager::instance != 0);
  29810. }
  29811. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29812. {
  29813. actionListenerList.addActionListener (listener);
  29814. }
  29815. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29816. {
  29817. jassert (actionListenerList.isValidMessageListener());
  29818. if (actionListenerList.isValidMessageListener())
  29819. actionListenerList.removeActionListener (listener);
  29820. }
  29821. void ActionBroadcaster::removeAllActionListeners()
  29822. {
  29823. actionListenerList.removeAllActionListeners();
  29824. }
  29825. void ActionBroadcaster::sendActionMessage (const String& message) const
  29826. {
  29827. actionListenerList.sendActionMessage (message);
  29828. }
  29829. END_JUCE_NAMESPACE
  29830. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29831. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29832. BEGIN_JUCE_NAMESPACE
  29833. // special message of our own with a string in it
  29834. class ActionMessage : public Message
  29835. {
  29836. public:
  29837. const String message;
  29838. ActionMessage (const String& messageText,
  29839. void* const listener_) throw()
  29840. : message (messageText)
  29841. {
  29842. pointerParameter = listener_;
  29843. }
  29844. ~ActionMessage() throw()
  29845. {
  29846. }
  29847. private:
  29848. ActionMessage (const ActionMessage&);
  29849. const ActionMessage& operator= (const ActionMessage&);
  29850. };
  29851. ActionListenerList::ActionListenerList() throw()
  29852. {
  29853. }
  29854. ActionListenerList::~ActionListenerList() throw()
  29855. {
  29856. }
  29857. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29858. {
  29859. const ScopedLock sl (actionListenerLock_);
  29860. jassert (listener != 0);
  29861. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29862. if (listener != 0)
  29863. actionListeners_.add (listener);
  29864. }
  29865. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29866. {
  29867. const ScopedLock sl (actionListenerLock_);
  29868. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29869. actionListeners_.removeValue (listener);
  29870. }
  29871. void ActionListenerList::removeAllActionListeners() throw()
  29872. {
  29873. const ScopedLock sl (actionListenerLock_);
  29874. actionListeners_.clear();
  29875. }
  29876. void ActionListenerList::sendActionMessage (const String& message) const
  29877. {
  29878. const ScopedLock sl (actionListenerLock_);
  29879. for (int i = actionListeners_.size(); --i >= 0;)
  29880. {
  29881. postMessage (new ActionMessage (message,
  29882. (ActionListener*) actionListeners_.getUnchecked(i)));
  29883. }
  29884. }
  29885. void ActionListenerList::handleMessage (const Message& message)
  29886. {
  29887. const ActionMessage& am = (const ActionMessage&) message;
  29888. if (actionListeners_.contains (am.pointerParameter))
  29889. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29890. }
  29891. END_JUCE_NAMESPACE
  29892. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29893. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29894. BEGIN_JUCE_NAMESPACE
  29895. AsyncUpdater::AsyncUpdater() throw()
  29896. : asyncMessagePending (false)
  29897. {
  29898. internalAsyncHandler.owner = this;
  29899. }
  29900. AsyncUpdater::~AsyncUpdater()
  29901. {
  29902. }
  29903. void AsyncUpdater::triggerAsyncUpdate() throw()
  29904. {
  29905. if (! asyncMessagePending)
  29906. {
  29907. asyncMessagePending = true;
  29908. internalAsyncHandler.postMessage (new Message());
  29909. }
  29910. }
  29911. void AsyncUpdater::cancelPendingUpdate() throw()
  29912. {
  29913. asyncMessagePending = false;
  29914. }
  29915. void AsyncUpdater::handleUpdateNowIfNeeded()
  29916. {
  29917. if (asyncMessagePending)
  29918. {
  29919. asyncMessagePending = false;
  29920. handleAsyncUpdate();
  29921. }
  29922. }
  29923. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29924. {
  29925. owner->handleUpdateNowIfNeeded();
  29926. }
  29927. END_JUCE_NAMESPACE
  29928. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29929. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29930. BEGIN_JUCE_NAMESPACE
  29931. ChangeBroadcaster::ChangeBroadcaster() throw()
  29932. {
  29933. // are you trying to create this object before or after juce has been intialised??
  29934. jassert (MessageManager::instance != 0);
  29935. }
  29936. ChangeBroadcaster::~ChangeBroadcaster()
  29937. {
  29938. // all event-based objects must be deleted BEFORE juce is shut down!
  29939. jassert (MessageManager::instance != 0);
  29940. }
  29941. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29942. {
  29943. changeListenerList.addChangeListener (listener);
  29944. }
  29945. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29946. {
  29947. jassert (changeListenerList.isValidMessageListener());
  29948. if (changeListenerList.isValidMessageListener())
  29949. changeListenerList.removeChangeListener (listener);
  29950. }
  29951. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29952. {
  29953. changeListenerList.removeAllChangeListeners();
  29954. }
  29955. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29956. {
  29957. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29958. }
  29959. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29960. {
  29961. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29962. }
  29963. void ChangeBroadcaster::dispatchPendingMessages()
  29964. {
  29965. changeListenerList.dispatchPendingMessages();
  29966. }
  29967. END_JUCE_NAMESPACE
  29968. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29969. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29970. BEGIN_JUCE_NAMESPACE
  29971. ChangeListenerList::ChangeListenerList() throw()
  29972. : lastChangedObject (0),
  29973. messagePending (false)
  29974. {
  29975. }
  29976. ChangeListenerList::~ChangeListenerList() throw()
  29977. {
  29978. }
  29979. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29980. {
  29981. const ScopedLock sl (lock);
  29982. jassert (listener != 0);
  29983. if (listener != 0)
  29984. listeners.add (listener);
  29985. }
  29986. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29987. {
  29988. const ScopedLock sl (lock);
  29989. listeners.removeValue (listener);
  29990. }
  29991. void ChangeListenerList::removeAllChangeListeners() throw()
  29992. {
  29993. const ScopedLock sl (lock);
  29994. listeners.clear();
  29995. }
  29996. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29997. {
  29998. const ScopedLock sl (lock);
  29999. if ((! messagePending) && (listeners.size() > 0))
  30000. {
  30001. lastChangedObject = objectThatHasChanged;
  30002. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  30003. messagePending = true;
  30004. }
  30005. }
  30006. void ChangeListenerList::handleMessage (const Message& message)
  30007. {
  30008. sendSynchronousChangeMessage (message.pointerParameter);
  30009. }
  30010. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  30011. {
  30012. const ScopedLock sl (lock);
  30013. messagePending = false;
  30014. for (int i = listeners.size(); --i >= 0;)
  30015. {
  30016. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  30017. {
  30018. const ScopedUnlock tempUnlocker (lock);
  30019. l->changeListenerCallback (objectThatHasChanged);
  30020. }
  30021. i = jmin (i, listeners.size());
  30022. }
  30023. }
  30024. void ChangeListenerList::dispatchPendingMessages()
  30025. {
  30026. if (messagePending)
  30027. sendSynchronousChangeMessage (lastChangedObject);
  30028. }
  30029. END_JUCE_NAMESPACE
  30030. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  30031. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  30032. BEGIN_JUCE_NAMESPACE
  30033. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  30034. const uint32 magicMessageHeaderNumber)
  30035. : Thread ("Juce IPC connection"),
  30036. callbackConnectionState (false),
  30037. useMessageThread (callbacksOnMessageThread),
  30038. magicMessageHeader (magicMessageHeaderNumber),
  30039. pipeReceiveMessageTimeout (-1)
  30040. {
  30041. }
  30042. InterprocessConnection::~InterprocessConnection()
  30043. {
  30044. callbackConnectionState = false;
  30045. disconnect();
  30046. }
  30047. bool InterprocessConnection::connectToSocket (const String& hostName,
  30048. const int portNumber,
  30049. const int timeOutMillisecs)
  30050. {
  30051. disconnect();
  30052. const ScopedLock sl (pipeAndSocketLock);
  30053. socket = new StreamingSocket();
  30054. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  30055. {
  30056. connectionMadeInt();
  30057. startThread();
  30058. return true;
  30059. }
  30060. else
  30061. {
  30062. socket = 0;
  30063. return false;
  30064. }
  30065. }
  30066. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30067. const int pipeReceiveMessageTimeoutMs)
  30068. {
  30069. disconnect();
  30070. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30071. if (newPipe->openExisting (pipeName))
  30072. {
  30073. const ScopedLock sl (pipeAndSocketLock);
  30074. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30075. initialiseWithPipe (newPipe.release());
  30076. return true;
  30077. }
  30078. return false;
  30079. }
  30080. bool InterprocessConnection::createPipe (const String& pipeName,
  30081. const int pipeReceiveMessageTimeoutMs)
  30082. {
  30083. disconnect();
  30084. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30085. if (newPipe->createNewPipe (pipeName))
  30086. {
  30087. const ScopedLock sl (pipeAndSocketLock);
  30088. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30089. initialiseWithPipe (newPipe.release());
  30090. return true;
  30091. }
  30092. return false;
  30093. }
  30094. void InterprocessConnection::disconnect()
  30095. {
  30096. if (socket != 0)
  30097. socket->close();
  30098. if (pipe != 0)
  30099. {
  30100. pipe->cancelPendingReads();
  30101. pipe->close();
  30102. }
  30103. stopThread (4000);
  30104. {
  30105. const ScopedLock sl (pipeAndSocketLock);
  30106. socket = 0;
  30107. pipe = 0;
  30108. }
  30109. connectionLostInt();
  30110. }
  30111. bool InterprocessConnection::isConnected() const
  30112. {
  30113. const ScopedLock sl (pipeAndSocketLock);
  30114. return ((socket != 0 && socket->isConnected())
  30115. || (pipe != 0 && pipe->isOpen()))
  30116. && isThreadRunning();
  30117. }
  30118. const String InterprocessConnection::getConnectedHostName() const
  30119. {
  30120. if (pipe != 0)
  30121. {
  30122. return "localhost";
  30123. }
  30124. else if (socket != 0)
  30125. {
  30126. if (! socket->isLocal())
  30127. return socket->getHostName();
  30128. return "localhost";
  30129. }
  30130. return String::empty;
  30131. }
  30132. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30133. {
  30134. uint32 messageHeader[2];
  30135. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30136. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30137. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30138. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30139. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30140. size_t bytesWritten = 0;
  30141. const ScopedLock sl (pipeAndSocketLock);
  30142. if (socket != 0)
  30143. {
  30144. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30145. }
  30146. else if (pipe != 0)
  30147. {
  30148. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30149. }
  30150. if (bytesWritten < 0)
  30151. {
  30152. // error..
  30153. return false;
  30154. }
  30155. return (bytesWritten == messageData.getSize());
  30156. }
  30157. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30158. {
  30159. jassert (socket == 0);
  30160. socket = socket_;
  30161. connectionMadeInt();
  30162. startThread();
  30163. }
  30164. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30165. {
  30166. jassert (pipe == 0);
  30167. pipe = pipe_;
  30168. connectionMadeInt();
  30169. startThread();
  30170. }
  30171. const int messageMagicNumber = 0xb734128b;
  30172. void InterprocessConnection::handleMessage (const Message& message)
  30173. {
  30174. if (message.intParameter1 == messageMagicNumber)
  30175. {
  30176. switch (message.intParameter2)
  30177. {
  30178. case 0:
  30179. {
  30180. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30181. messageReceived (*data);
  30182. break;
  30183. }
  30184. case 1:
  30185. connectionMade();
  30186. break;
  30187. case 2:
  30188. connectionLost();
  30189. break;
  30190. }
  30191. }
  30192. }
  30193. void InterprocessConnection::connectionMadeInt()
  30194. {
  30195. if (! callbackConnectionState)
  30196. {
  30197. callbackConnectionState = true;
  30198. if (useMessageThread)
  30199. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30200. else
  30201. connectionMade();
  30202. }
  30203. }
  30204. void InterprocessConnection::connectionLostInt()
  30205. {
  30206. if (callbackConnectionState)
  30207. {
  30208. callbackConnectionState = false;
  30209. if (useMessageThread)
  30210. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30211. else
  30212. connectionLost();
  30213. }
  30214. }
  30215. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30216. {
  30217. jassert (callbackConnectionState);
  30218. if (useMessageThread)
  30219. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30220. else
  30221. messageReceived (data);
  30222. }
  30223. bool InterprocessConnection::readNextMessageInt()
  30224. {
  30225. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30226. uint32 messageHeader[2];
  30227. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30228. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30229. if (bytes == sizeof (messageHeader)
  30230. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30231. {
  30232. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30233. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30234. {
  30235. MemoryBlock messageData (bytesInMessage, true);
  30236. int bytesRead = 0;
  30237. while (bytesRead < bytesInMessage)
  30238. {
  30239. if (threadShouldExit())
  30240. return false;
  30241. const int numThisTime = jmin (bytesInMessage, 65536);
  30242. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30243. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30244. pipeReceiveMessageTimeout);
  30245. if (bytesIn <= 0)
  30246. break;
  30247. bytesRead += bytesIn;
  30248. }
  30249. if (bytesRead >= 0)
  30250. deliverDataInt (messageData);
  30251. }
  30252. }
  30253. else if (bytes < 0)
  30254. {
  30255. {
  30256. const ScopedLock sl (pipeAndSocketLock);
  30257. socket = 0;
  30258. }
  30259. connectionLostInt();
  30260. return false;
  30261. }
  30262. return true;
  30263. }
  30264. void InterprocessConnection::run()
  30265. {
  30266. while (! threadShouldExit())
  30267. {
  30268. if (socket != 0)
  30269. {
  30270. const int ready = socket->waitUntilReady (true, 0);
  30271. if (ready < 0)
  30272. {
  30273. {
  30274. const ScopedLock sl (pipeAndSocketLock);
  30275. socket = 0;
  30276. }
  30277. connectionLostInt();
  30278. break;
  30279. }
  30280. else if (ready > 0)
  30281. {
  30282. if (! readNextMessageInt())
  30283. break;
  30284. }
  30285. else
  30286. {
  30287. Thread::sleep (2);
  30288. }
  30289. }
  30290. else if (pipe != 0)
  30291. {
  30292. if (! pipe->isOpen())
  30293. {
  30294. {
  30295. const ScopedLock sl (pipeAndSocketLock);
  30296. pipe = 0;
  30297. }
  30298. connectionLostInt();
  30299. break;
  30300. }
  30301. else
  30302. {
  30303. if (! readNextMessageInt())
  30304. break;
  30305. }
  30306. }
  30307. else
  30308. {
  30309. break;
  30310. }
  30311. }
  30312. }
  30313. END_JUCE_NAMESPACE
  30314. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30315. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30316. BEGIN_JUCE_NAMESPACE
  30317. InterprocessConnectionServer::InterprocessConnectionServer()
  30318. : Thread ("Juce IPC server")
  30319. {
  30320. }
  30321. InterprocessConnectionServer::~InterprocessConnectionServer()
  30322. {
  30323. stop();
  30324. }
  30325. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30326. {
  30327. stop();
  30328. socket = new StreamingSocket();
  30329. if (socket->createListener (portNumber))
  30330. {
  30331. startThread();
  30332. return true;
  30333. }
  30334. socket = 0;
  30335. return false;
  30336. }
  30337. void InterprocessConnectionServer::stop()
  30338. {
  30339. signalThreadShouldExit();
  30340. if (socket != 0)
  30341. socket->close();
  30342. stopThread (4000);
  30343. socket = 0;
  30344. }
  30345. void InterprocessConnectionServer::run()
  30346. {
  30347. while ((! threadShouldExit()) && socket != 0)
  30348. {
  30349. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30350. if (clientSocket != 0)
  30351. {
  30352. InterprocessConnection* newConnection = createConnectionObject();
  30353. if (newConnection != 0)
  30354. newConnection->initialiseWithSocket (clientSocket.release());
  30355. }
  30356. }
  30357. }
  30358. END_JUCE_NAMESPACE
  30359. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30360. /*** Start of inlined file: juce_Message.cpp ***/
  30361. BEGIN_JUCE_NAMESPACE
  30362. Message::Message() throw()
  30363. {
  30364. }
  30365. Message::~Message() throw()
  30366. {
  30367. }
  30368. Message::Message (const int intParameter1_,
  30369. const int intParameter2_,
  30370. const int intParameter3_,
  30371. void* const pointerParameter_) throw()
  30372. : intParameter1 (intParameter1_),
  30373. intParameter2 (intParameter2_),
  30374. intParameter3 (intParameter3_),
  30375. pointerParameter (pointerParameter_)
  30376. {
  30377. }
  30378. END_JUCE_NAMESPACE
  30379. /*** End of inlined file: juce_Message.cpp ***/
  30380. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30381. BEGIN_JUCE_NAMESPACE
  30382. MessageListener::MessageListener() throw()
  30383. {
  30384. // are you trying to create a messagelistener before or after juce has been intialised??
  30385. jassert (MessageManager::instance != 0);
  30386. if (MessageManager::instance != 0)
  30387. MessageManager::instance->messageListeners.add (this);
  30388. }
  30389. MessageListener::~MessageListener()
  30390. {
  30391. if (MessageManager::instance != 0)
  30392. MessageManager::instance->messageListeners.removeValue (this);
  30393. }
  30394. void MessageListener::postMessage (Message* const message) const throw()
  30395. {
  30396. message->messageRecipient = const_cast <MessageListener*> (this);
  30397. if (MessageManager::instance == 0)
  30398. MessageManager::getInstance();
  30399. MessageManager::instance->postMessageToQueue (message);
  30400. }
  30401. bool MessageListener::isValidMessageListener() const throw()
  30402. {
  30403. return (MessageManager::instance != 0)
  30404. && MessageManager::instance->messageListeners.contains (this);
  30405. }
  30406. END_JUCE_NAMESPACE
  30407. /*** End of inlined file: juce_MessageListener.cpp ***/
  30408. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30409. BEGIN_JUCE_NAMESPACE
  30410. // platform-specific functions..
  30411. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30412. bool juce_postMessageToSystemQueue (void* message);
  30413. MessageManager* MessageManager::instance = 0;
  30414. static const int quitMessageId = 0xfffff321;
  30415. MessageManager::MessageManager() throw()
  30416. : quitMessagePosted (false),
  30417. quitMessageReceived (false),
  30418. threadWithLock (0)
  30419. {
  30420. messageThreadId = Thread::getCurrentThreadId();
  30421. }
  30422. MessageManager::~MessageManager() throw()
  30423. {
  30424. broadcastListeners = 0;
  30425. doPlatformSpecificShutdown();
  30426. jassert (instance == this);
  30427. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30428. }
  30429. MessageManager* MessageManager::getInstance() throw()
  30430. {
  30431. if (instance == 0)
  30432. {
  30433. instance = new MessageManager();
  30434. doPlatformSpecificInitialisation();
  30435. }
  30436. return instance;
  30437. }
  30438. void MessageManager::postMessageToQueue (Message* const message)
  30439. {
  30440. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30441. delete message;
  30442. }
  30443. CallbackMessage::CallbackMessage() throw() {}
  30444. CallbackMessage::~CallbackMessage() throw() {}
  30445. void CallbackMessage::post()
  30446. {
  30447. if (MessageManager::instance != 0)
  30448. MessageManager::instance->postCallbackMessage (this);
  30449. }
  30450. void MessageManager::postCallbackMessage (Message* const message)
  30451. {
  30452. message->messageRecipient = 0;
  30453. postMessageToQueue (message);
  30454. }
  30455. // not for public use..
  30456. void MessageManager::deliverMessage (void* message)
  30457. {
  30458. const ScopedPointer <Message> m ((Message*) message);
  30459. MessageListener* const recipient = m->messageRecipient;
  30460. JUCE_TRY
  30461. {
  30462. if (messageListeners.contains (recipient))
  30463. {
  30464. recipient->handleMessage (*m);
  30465. }
  30466. else if (recipient == 0)
  30467. {
  30468. if (m->intParameter1 == quitMessageId)
  30469. {
  30470. quitMessageReceived = true;
  30471. }
  30472. else
  30473. {
  30474. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30475. if (cm != 0)
  30476. cm->messageCallback();
  30477. }
  30478. }
  30479. }
  30480. JUCE_CATCH_EXCEPTION
  30481. }
  30482. #if ! (JUCE_MAC || JUCE_IPHONE)
  30483. void MessageManager::runDispatchLoop()
  30484. {
  30485. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30486. runDispatchLoopUntil (-1);
  30487. }
  30488. void MessageManager::stopDispatchLoop()
  30489. {
  30490. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30491. m->messageRecipient = 0;
  30492. postMessageToQueue (m);
  30493. quitMessagePosted = true;
  30494. }
  30495. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30496. {
  30497. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30498. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30499. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30500. && ! quitMessageReceived)
  30501. {
  30502. JUCE_TRY
  30503. {
  30504. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30505. {
  30506. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30507. if (msToWait > 0)
  30508. Thread::sleep (jmin (5, msToWait));
  30509. }
  30510. }
  30511. JUCE_CATCH_EXCEPTION
  30512. }
  30513. return ! quitMessageReceived;
  30514. }
  30515. #endif
  30516. void MessageManager::deliverBroadcastMessage (const String& value)
  30517. {
  30518. if (broadcastListeners != 0)
  30519. broadcastListeners->sendActionMessage (value);
  30520. }
  30521. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30522. {
  30523. if (broadcastListeners == 0)
  30524. broadcastListeners = new ActionListenerList();
  30525. broadcastListeners->addActionListener (listener);
  30526. }
  30527. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30528. {
  30529. if (broadcastListeners != 0)
  30530. broadcastListeners->removeActionListener (listener);
  30531. }
  30532. bool MessageManager::isThisTheMessageThread() const throw()
  30533. {
  30534. return Thread::getCurrentThreadId() == messageThreadId;
  30535. }
  30536. void MessageManager::setCurrentMessageThread (const Thread::ThreadID threadId) throw()
  30537. {
  30538. messageThreadId = threadId;
  30539. }
  30540. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30541. {
  30542. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30543. return thisThread == messageThreadId || thisThread == threadWithLock;
  30544. }
  30545. class SharedLockingEvents : public ReferenceCountedObject
  30546. {
  30547. public:
  30548. SharedLockingEvents() throw() {}
  30549. ~SharedLockingEvents() {}
  30550. WaitableEvent lockedEvent, releaseEvent;
  30551. };
  30552. class MMLockMessage : public CallbackMessage
  30553. {
  30554. public:
  30555. MMLockMessage (SharedLockingEvents* const events_) throw()
  30556. : events (events_)
  30557. {}
  30558. ~MMLockMessage() throw() {}
  30559. ReferenceCountedObjectPtr <SharedLockingEvents> events;
  30560. void messageCallback()
  30561. {
  30562. events->lockedEvent.signal();
  30563. events->releaseEvent.wait();
  30564. }
  30565. juce_UseDebuggingNewOperator
  30566. MMLockMessage (const MMLockMessage&);
  30567. const MMLockMessage& operator= (const MMLockMessage&);
  30568. };
  30569. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30570. : locked (false),
  30571. needsUnlocking (false)
  30572. {
  30573. init (threadToCheck, 0);
  30574. }
  30575. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30576. : locked (false),
  30577. needsUnlocking (false)
  30578. {
  30579. init (0, jobToCheckForExitSignal);
  30580. }
  30581. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30582. {
  30583. if (MessageManager::instance != 0)
  30584. {
  30585. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30586. {
  30587. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30588. }
  30589. else
  30590. {
  30591. if (threadToCheck == 0 && job == 0)
  30592. {
  30593. MessageManager::instance->lockingLock.enter();
  30594. }
  30595. else
  30596. {
  30597. while (! MessageManager::instance->lockingLock.tryEnter())
  30598. {
  30599. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30600. || (job != 0 && job->shouldExit()))
  30601. return;
  30602. Thread::sleep (1);
  30603. }
  30604. }
  30605. SharedLockingEvents* const events = new SharedLockingEvents();
  30606. sharedEvents = events;
  30607. events->incReferenceCount();
  30608. (new MMLockMessage (events))->post();
  30609. while (! events->lockedEvent.wait (50))
  30610. {
  30611. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30612. || (job != 0 && job->shouldExit()))
  30613. {
  30614. events->releaseEvent.signal();
  30615. events->decReferenceCount();
  30616. MessageManager::instance->lockingLock.exit();
  30617. return;
  30618. }
  30619. }
  30620. jassert (MessageManager::instance->threadWithLock == 0);
  30621. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30622. locked = true;
  30623. needsUnlocking = true;
  30624. }
  30625. }
  30626. }
  30627. MessageManagerLock::~MessageManagerLock() throw()
  30628. {
  30629. if (needsUnlocking && MessageManager::instance != 0)
  30630. {
  30631. jassert (MessageManager::instance->currentThreadHasLockedMessageManager());
  30632. ((SharedLockingEvents*) sharedEvents)->releaseEvent.signal();
  30633. ((SharedLockingEvents*) sharedEvents)->decReferenceCount();
  30634. MessageManager::instance->threadWithLock = 0;
  30635. MessageManager::instance->lockingLock.exit();
  30636. }
  30637. }
  30638. END_JUCE_NAMESPACE
  30639. /*** End of inlined file: juce_MessageManager.cpp ***/
  30640. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30641. BEGIN_JUCE_NAMESPACE
  30642. class MultiTimer::MultiTimerCallback : public Timer
  30643. {
  30644. public:
  30645. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30646. : timerId (timerId_),
  30647. owner (owner_)
  30648. {
  30649. }
  30650. ~MultiTimerCallback()
  30651. {
  30652. }
  30653. void timerCallback()
  30654. {
  30655. owner.timerCallback (timerId);
  30656. }
  30657. const int timerId;
  30658. private:
  30659. MultiTimer& owner;
  30660. };
  30661. MultiTimer::MultiTimer() throw()
  30662. {
  30663. }
  30664. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30665. {
  30666. }
  30667. MultiTimer::~MultiTimer()
  30668. {
  30669. const ScopedLock sl (timerListLock);
  30670. timers.clear();
  30671. }
  30672. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30673. {
  30674. const ScopedLock sl (timerListLock);
  30675. for (int i = timers.size(); --i >= 0;)
  30676. {
  30677. MultiTimerCallback* const t = timers.getUnchecked(i);
  30678. if (t->timerId == timerId)
  30679. {
  30680. t->startTimer (intervalInMilliseconds);
  30681. return;
  30682. }
  30683. }
  30684. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30685. timers.add (newTimer);
  30686. newTimer->startTimer (intervalInMilliseconds);
  30687. }
  30688. void MultiTimer::stopTimer (const int timerId) throw()
  30689. {
  30690. const ScopedLock sl (timerListLock);
  30691. for (int i = timers.size(); --i >= 0;)
  30692. {
  30693. MultiTimerCallback* const t = timers.getUnchecked(i);
  30694. if (t->timerId == timerId)
  30695. t->stopTimer();
  30696. }
  30697. }
  30698. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30699. {
  30700. const ScopedLock sl (timerListLock);
  30701. for (int i = timers.size(); --i >= 0;)
  30702. {
  30703. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30704. if (t->timerId == timerId)
  30705. return t->isTimerRunning();
  30706. }
  30707. return false;
  30708. }
  30709. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30710. {
  30711. const ScopedLock sl (timerListLock);
  30712. for (int i = timers.size(); --i >= 0;)
  30713. {
  30714. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30715. if (t->timerId == timerId)
  30716. return t->getTimerInterval();
  30717. }
  30718. return 0;
  30719. }
  30720. END_JUCE_NAMESPACE
  30721. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30722. /*** Start of inlined file: juce_Timer.cpp ***/
  30723. BEGIN_JUCE_NAMESPACE
  30724. class InternalTimerThread : private Thread,
  30725. private MessageListener,
  30726. private DeletedAtShutdown,
  30727. private AsyncUpdater
  30728. {
  30729. public:
  30730. InternalTimerThread()
  30731. : Thread ("Juce Timer"),
  30732. firstTimer (0),
  30733. callbackNeeded (false)
  30734. {
  30735. triggerAsyncUpdate();
  30736. }
  30737. ~InternalTimerThread() throw()
  30738. {
  30739. stopThread (4000);
  30740. jassert (instance == this || instance == 0);
  30741. if (instance == this)
  30742. instance = 0;
  30743. }
  30744. void run()
  30745. {
  30746. uint32 lastTime = Time::getMillisecondCounter();
  30747. while (! threadShouldExit())
  30748. {
  30749. const uint32 now = Time::getMillisecondCounter();
  30750. if (now <= lastTime)
  30751. {
  30752. wait (2);
  30753. continue;
  30754. }
  30755. const int elapsed = now - lastTime;
  30756. lastTime = now;
  30757. lock.enter();
  30758. decrementAllCounters (elapsed);
  30759. const int timeUntilFirstTimer = (firstTimer != 0) ? firstTimer->countdownMs
  30760. : 1000;
  30761. lock.exit();
  30762. if (timeUntilFirstTimer <= 0)
  30763. {
  30764. if (callbackNeeded.set (true))
  30765. {
  30766. postMessage (new Message());
  30767. const uint32 messageDeliveryTimeout = now + 2000;
  30768. while (callbackNeeded.get())
  30769. {
  30770. wait (4);
  30771. if (threadShouldExit())
  30772. return;
  30773. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30774. break;
  30775. }
  30776. }
  30777. }
  30778. else
  30779. {
  30780. // don't wait for too long because running this loop also helps keep the
  30781. // Time::getApproximateMillisecondTimer value stay up-to-date
  30782. wait (jlimit (1, 50, timeUntilFirstTimer));
  30783. }
  30784. }
  30785. }
  30786. void handleMessage (const Message&)
  30787. {
  30788. const ScopedLock sl (lock);
  30789. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30790. {
  30791. Timer* const t = firstTimer;
  30792. t->countdownMs = t->periodMs;
  30793. removeTimer (t);
  30794. addTimer (t);
  30795. const ScopedUnlock ul (lock);
  30796. JUCE_TRY
  30797. {
  30798. t->timerCallback();
  30799. }
  30800. JUCE_CATCH_EXCEPTION
  30801. }
  30802. callbackNeeded.set (false);
  30803. }
  30804. static void callAnyTimersSynchronously()
  30805. {
  30806. if (InternalTimerThread::instance != 0)
  30807. {
  30808. const Message m;
  30809. InternalTimerThread::instance->handleMessage (m);
  30810. }
  30811. }
  30812. static inline void add (Timer* const tim) throw()
  30813. {
  30814. if (instance == 0)
  30815. instance = new InternalTimerThread();
  30816. const ScopedLock sl (instance->lock);
  30817. instance->addTimer (tim);
  30818. }
  30819. static inline void remove (Timer* const tim) throw()
  30820. {
  30821. if (instance != 0)
  30822. {
  30823. const ScopedLock sl (instance->lock);
  30824. instance->removeTimer (tim);
  30825. }
  30826. }
  30827. static inline void resetCounter (Timer* const tim,
  30828. const int newCounter) throw()
  30829. {
  30830. if (instance != 0)
  30831. {
  30832. tim->countdownMs = newCounter;
  30833. tim->periodMs = newCounter;
  30834. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30835. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30836. {
  30837. const ScopedLock sl (instance->lock);
  30838. instance->removeTimer (tim);
  30839. instance->addTimer (tim);
  30840. }
  30841. }
  30842. }
  30843. private:
  30844. friend class Timer;
  30845. static InternalTimerThread* instance;
  30846. static CriticalSection lock;
  30847. Timer* volatile firstTimer;
  30848. class AtomicBool
  30849. {
  30850. public:
  30851. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30852. ~AtomicBool() throw() {}
  30853. bool get() const throw() { return value != 0; }
  30854. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30855. private:
  30856. int32 value;
  30857. AtomicBool (const AtomicBool&);
  30858. AtomicBool& operator= (const AtomicBool&);
  30859. };
  30860. AtomicBool callbackNeeded;
  30861. void addTimer (Timer* const t) throw()
  30862. {
  30863. #ifdef JUCE_DEBUG
  30864. Timer* tt = firstTimer;
  30865. while (tt != 0)
  30866. {
  30867. // trying to add a timer that's already here - shouldn't get to this point,
  30868. // so if you get this assertion, let me know!
  30869. jassert (tt != t);
  30870. tt = tt->next;
  30871. }
  30872. jassert (t->previous == 0 && t->next == 0);
  30873. #endif
  30874. Timer* i = firstTimer;
  30875. if (i == 0 || i->countdownMs > t->countdownMs)
  30876. {
  30877. t->next = firstTimer;
  30878. firstTimer = t;
  30879. }
  30880. else
  30881. {
  30882. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30883. i = i->next;
  30884. jassert (i != 0);
  30885. t->next = i->next;
  30886. t->previous = i;
  30887. i->next = t;
  30888. }
  30889. if (t->next != 0)
  30890. t->next->previous = t;
  30891. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30892. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30893. notify();
  30894. }
  30895. void removeTimer (Timer* const t) throw()
  30896. {
  30897. #ifdef JUCE_DEBUG
  30898. Timer* tt = firstTimer;
  30899. bool found = false;
  30900. while (tt != 0)
  30901. {
  30902. if (tt == t)
  30903. {
  30904. found = true;
  30905. break;
  30906. }
  30907. tt = tt->next;
  30908. }
  30909. // trying to remove a timer that's not here - shouldn't get to this point,
  30910. // so if you get this assertion, let me know!
  30911. jassert (found);
  30912. #endif
  30913. if (t->previous != 0)
  30914. {
  30915. jassert (firstTimer != t);
  30916. t->previous->next = t->next;
  30917. }
  30918. else
  30919. {
  30920. jassert (firstTimer == t);
  30921. firstTimer = t->next;
  30922. }
  30923. if (t->next != 0)
  30924. t->next->previous = t->previous;
  30925. t->next = 0;
  30926. t->previous = 0;
  30927. }
  30928. void decrementAllCounters (const int numMillisecs) const
  30929. {
  30930. Timer* t = firstTimer;
  30931. while (t != 0)
  30932. {
  30933. t->countdownMs -= numMillisecs;
  30934. t = t->next;
  30935. }
  30936. }
  30937. void handleAsyncUpdate()
  30938. {
  30939. startThread (7);
  30940. }
  30941. InternalTimerThread (const InternalTimerThread&);
  30942. InternalTimerThread& operator= (const InternalTimerThread&);
  30943. };
  30944. InternalTimerThread* InternalTimerThread::instance = 0;
  30945. CriticalSection InternalTimerThread::lock;
  30946. void juce_callAnyTimersSynchronously()
  30947. {
  30948. InternalTimerThread::callAnyTimersSynchronously();
  30949. }
  30950. #ifdef JUCE_DEBUG
  30951. static SortedSet <Timer*> activeTimers;
  30952. #endif
  30953. Timer::Timer() throw()
  30954. : countdownMs (0),
  30955. periodMs (0),
  30956. previous (0),
  30957. next (0)
  30958. {
  30959. #ifdef JUCE_DEBUG
  30960. activeTimers.add (this);
  30961. #endif
  30962. }
  30963. Timer::Timer (const Timer&) throw()
  30964. : countdownMs (0),
  30965. periodMs (0),
  30966. previous (0),
  30967. next (0)
  30968. {
  30969. #ifdef JUCE_DEBUG
  30970. activeTimers.add (this);
  30971. #endif
  30972. }
  30973. Timer::~Timer()
  30974. {
  30975. stopTimer();
  30976. #ifdef JUCE_DEBUG
  30977. activeTimers.removeValue (this);
  30978. #endif
  30979. }
  30980. void Timer::startTimer (const int interval) throw()
  30981. {
  30982. const ScopedLock sl (InternalTimerThread::lock);
  30983. #ifdef JUCE_DEBUG
  30984. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30985. jassert (activeTimers.contains (this));
  30986. #endif
  30987. if (periodMs == 0)
  30988. {
  30989. countdownMs = interval;
  30990. periodMs = jmax (1, interval);
  30991. InternalTimerThread::add (this);
  30992. }
  30993. else
  30994. {
  30995. InternalTimerThread::resetCounter (this, interval);
  30996. }
  30997. }
  30998. void Timer::stopTimer() throw()
  30999. {
  31000. const ScopedLock sl (InternalTimerThread::lock);
  31001. #ifdef JUCE_DEBUG
  31002. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31003. jassert (activeTimers.contains (this));
  31004. #endif
  31005. if (periodMs > 0)
  31006. {
  31007. InternalTimerThread::remove (this);
  31008. periodMs = 0;
  31009. }
  31010. }
  31011. END_JUCE_NAMESPACE
  31012. /*** End of inlined file: juce_Timer.cpp ***/
  31013. #endif
  31014. #if JUCE_BUILD_GUI
  31015. /*** Start of inlined file: juce_Component.cpp ***/
  31016. BEGIN_JUCE_NAMESPACE
  31017. Component* Component::componentUnderMouse = 0;
  31018. Component* Component::currentlyFocusedComponent = 0;
  31019. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  31020. static Array <int> modalReturnValues;
  31021. static const int customCommandMessage = 0x7fff0001;
  31022. static const int exitModalStateMessage = 0x7fff0002;
  31023. static int unboundedMouseOffsetX = 0;
  31024. static int unboundedMouseOffsetY = 0;
  31025. static bool isUnboundedMouseModeOn = false;
  31026. static bool isCursorVisibleUntilOffscreen;
  31027. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31028. static uint32 nextComponentUID = 0;
  31029. Component::Component() throw()
  31030. : parentComponent_ (0),
  31031. componentUID (++nextComponentUID),
  31032. numDeepMouseListeners (0),
  31033. lookAndFeel_ (0),
  31034. effect_ (0),
  31035. bufferedImage_ (0),
  31036. mouseListeners_ (0),
  31037. keyListeners_ (0),
  31038. componentListeners_ (0),
  31039. componentFlags_ (0)
  31040. {
  31041. }
  31042. Component::Component (const String& name) throw()
  31043. : componentName_ (name),
  31044. parentComponent_ (0),
  31045. componentUID (++nextComponentUID),
  31046. numDeepMouseListeners (0),
  31047. lookAndFeel_ (0),
  31048. effect_ (0),
  31049. bufferedImage_ (0),
  31050. mouseListeners_ (0),
  31051. keyListeners_ (0),
  31052. componentListeners_ (0),
  31053. componentFlags_ (0)
  31054. {
  31055. }
  31056. Component::~Component()
  31057. {
  31058. if (parentComponent_ != 0)
  31059. {
  31060. parentComponent_->removeChildComponent (this);
  31061. }
  31062. else if ((currentlyFocusedComponent == this)
  31063. || isParentOf (currentlyFocusedComponent))
  31064. {
  31065. giveAwayFocus();
  31066. }
  31067. if (componentUnderMouse == this)
  31068. componentUnderMouse = 0;
  31069. if (flags.hasHeavyweightPeerFlag)
  31070. removeFromDesktop();
  31071. modalComponentStack.removeValue (this);
  31072. for (int i = childComponentList_.size(); --i >= 0;)
  31073. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31074. delete bufferedImage_;
  31075. delete mouseListeners_;
  31076. delete keyListeners_;
  31077. delete componentListeners_;
  31078. }
  31079. void Component::setName (const String& name)
  31080. {
  31081. // if component methods are being called from threads other than the message
  31082. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31083. checkMessageManagerIsLocked
  31084. if (componentName_ != name)
  31085. {
  31086. componentName_ = name;
  31087. if (flags.hasHeavyweightPeerFlag)
  31088. {
  31089. ComponentPeer* const peer = getPeer();
  31090. jassert (peer != 0);
  31091. if (peer != 0)
  31092. peer->setTitle (name);
  31093. }
  31094. if (componentListeners_ != 0)
  31095. {
  31096. const ComponentDeletionWatcher deletionChecker (this);
  31097. for (int i = componentListeners_->size(); --i >= 0;)
  31098. {
  31099. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31100. ->componentNameChanged (*this);
  31101. if (deletionChecker.hasBeenDeleted())
  31102. return;
  31103. i = jmin (i, componentListeners_->size());
  31104. }
  31105. }
  31106. }
  31107. }
  31108. void Component::setVisible (bool shouldBeVisible)
  31109. {
  31110. if (flags.visibleFlag != shouldBeVisible)
  31111. {
  31112. // if component methods are being called from threads other than the message
  31113. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31114. checkMessageManagerIsLocked
  31115. const ComponentDeletionWatcher deletionChecker (this);
  31116. flags.visibleFlag = shouldBeVisible;
  31117. internalRepaint (0, 0, getWidth(), getHeight());
  31118. sendFakeMouseMove();
  31119. if (! shouldBeVisible)
  31120. {
  31121. if (currentlyFocusedComponent == this
  31122. || isParentOf (currentlyFocusedComponent))
  31123. {
  31124. if (parentComponent_ != 0)
  31125. parentComponent_->grabKeyboardFocus();
  31126. else
  31127. giveAwayFocus();
  31128. }
  31129. }
  31130. sendVisibilityChangeMessage();
  31131. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31132. {
  31133. ComponentPeer* const peer = getPeer();
  31134. jassert (peer != 0);
  31135. if (peer != 0)
  31136. {
  31137. peer->setVisible (shouldBeVisible);
  31138. internalHierarchyChanged();
  31139. }
  31140. }
  31141. }
  31142. }
  31143. void Component::visibilityChanged()
  31144. {
  31145. }
  31146. void Component::sendVisibilityChangeMessage()
  31147. {
  31148. const ComponentDeletionWatcher deletionChecker (this);
  31149. visibilityChanged();
  31150. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31151. {
  31152. for (int i = componentListeners_->size(); --i >= 0;)
  31153. {
  31154. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31155. ->componentVisibilityChanged (*this);
  31156. if (deletionChecker.hasBeenDeleted())
  31157. return;
  31158. i = jmin (i, componentListeners_->size());
  31159. }
  31160. }
  31161. }
  31162. bool Component::isShowing() const throw()
  31163. {
  31164. if (flags.visibleFlag)
  31165. {
  31166. if (parentComponent_ != 0)
  31167. {
  31168. return parentComponent_->isShowing();
  31169. }
  31170. else
  31171. {
  31172. const ComponentPeer* const peer = getPeer();
  31173. return peer != 0 && ! peer->isMinimised();
  31174. }
  31175. }
  31176. return false;
  31177. }
  31178. class FadeOutProxyComponent : public Component,
  31179. public Timer
  31180. {
  31181. public:
  31182. FadeOutProxyComponent (Component* comp,
  31183. const int fadeLengthMs,
  31184. const int deltaXToMove,
  31185. const int deltaYToMove,
  31186. const float scaleFactorAtEnd)
  31187. : lastTime (0),
  31188. alpha (1.0f),
  31189. scale (1.0f)
  31190. {
  31191. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31192. setBounds (comp->getBounds());
  31193. comp->getParentComponent()->addAndMakeVisible (this);
  31194. toBehind (comp);
  31195. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31196. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31197. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31198. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31199. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31200. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31201. setInterceptsMouseClicks (false, false);
  31202. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31203. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31204. }
  31205. ~FadeOutProxyComponent()
  31206. {
  31207. delete image;
  31208. }
  31209. void paint (Graphics& g)
  31210. {
  31211. g.setOpacity (alpha);
  31212. g.drawImage (image,
  31213. 0, 0, getWidth(), getHeight(),
  31214. 0, 0, image->getWidth(), image->getHeight());
  31215. }
  31216. void timerCallback()
  31217. {
  31218. const uint32 now = Time::getMillisecondCounter();
  31219. if (lastTime == 0)
  31220. lastTime = now;
  31221. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31222. lastTime = now;
  31223. alpha += alphaChangePerMs * msPassed;
  31224. if (alpha > 0)
  31225. {
  31226. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31227. {
  31228. centreX += xChangePerMs * msPassed;
  31229. centreY += yChangePerMs * msPassed;
  31230. scale += scaleChangePerMs * msPassed;
  31231. const int w = roundToInt (image->getWidth() * scale);
  31232. const int h = roundToInt (image->getHeight() * scale);
  31233. setBounds (roundToInt (centreX) - w / 2,
  31234. roundToInt (centreY) - h / 2,
  31235. w, h);
  31236. }
  31237. repaint();
  31238. }
  31239. else
  31240. {
  31241. delete this;
  31242. }
  31243. }
  31244. juce_UseDebuggingNewOperator
  31245. private:
  31246. Image* image;
  31247. uint32 lastTime;
  31248. float alpha, alphaChangePerMs;
  31249. float centreX, xChangePerMs;
  31250. float centreY, yChangePerMs;
  31251. float scale, scaleChangePerMs;
  31252. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31253. const FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31254. };
  31255. void Component::fadeOutComponent (const int millisecondsToFade,
  31256. const int deltaXToMove,
  31257. const int deltaYToMove,
  31258. const float scaleFactorAtEnd)
  31259. {
  31260. //xxx won't work for comps without parents
  31261. if (isShowing() && millisecondsToFade > 0)
  31262. new FadeOutProxyComponent (this, millisecondsToFade,
  31263. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31264. setVisible (false);
  31265. }
  31266. bool Component::isValidComponent() const throw()
  31267. {
  31268. return (this != 0) && isValidMessageListener();
  31269. }
  31270. void* Component::getWindowHandle() const throw()
  31271. {
  31272. const ComponentPeer* const peer = getPeer();
  31273. if (peer != 0)
  31274. return peer->getNativeHandle();
  31275. return 0;
  31276. }
  31277. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31278. {
  31279. // if component methods are being called from threads other than the message
  31280. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31281. checkMessageManagerIsLocked
  31282. if (isOpaque())
  31283. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31284. else
  31285. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31286. int currentStyleFlags = 0;
  31287. // don't use getPeer(), so that we only get the peer that's specifically
  31288. // for this comp, and not for one of its parents.
  31289. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31290. if (peer != 0)
  31291. currentStyleFlags = peer->getStyleFlags();
  31292. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31293. {
  31294. const ComponentDeletionWatcher deletionChecker (this);
  31295. #if JUCE_LINUX
  31296. // it's wise to give the component a non-zero size before
  31297. // putting it on the desktop, as X windows get confused by this, and
  31298. // a (1, 1) minimum size is enforced here.
  31299. setSize (jmax (1, getWidth()),
  31300. jmax (1, getHeight()));
  31301. #endif
  31302. int x = 0, y = 0;
  31303. relativePositionToGlobal (x, y);
  31304. bool wasFullscreen = false;
  31305. bool wasMinimised = false;
  31306. ComponentBoundsConstrainer* currentConstainer = 0;
  31307. Rectangle<int> oldNonFullScreenBounds;
  31308. if (peer != 0)
  31309. {
  31310. wasFullscreen = peer->isFullScreen();
  31311. wasMinimised = peer->isMinimised();
  31312. currentConstainer = peer->getConstrainer();
  31313. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31314. removeFromDesktop();
  31315. setTopLeftPosition (x, y);
  31316. }
  31317. if (parentComponent_ != 0)
  31318. parentComponent_->removeChildComponent (this);
  31319. if (! deletionChecker.hasBeenDeleted())
  31320. {
  31321. flags.hasHeavyweightPeerFlag = true;
  31322. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31323. Desktop::getInstance().addDesktopComponent (this);
  31324. bounds_.setPosition (x, y);
  31325. peer->setBounds (x, y, getWidth(), getHeight(), false);
  31326. peer->setVisible (isVisible());
  31327. if (wasFullscreen)
  31328. {
  31329. peer->setFullScreen (true);
  31330. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31331. }
  31332. if (wasMinimised)
  31333. peer->setMinimised (true);
  31334. if (isAlwaysOnTop())
  31335. peer->setAlwaysOnTop (true);
  31336. peer->setConstrainer (currentConstainer);
  31337. repaint();
  31338. }
  31339. internalHierarchyChanged();
  31340. }
  31341. }
  31342. void Component::removeFromDesktop()
  31343. {
  31344. // if component methods are being called from threads other than the message
  31345. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31346. checkMessageManagerIsLocked
  31347. if (flags.hasHeavyweightPeerFlag)
  31348. {
  31349. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31350. flags.hasHeavyweightPeerFlag = false;
  31351. jassert (peer != 0);
  31352. delete peer;
  31353. Desktop::getInstance().removeDesktopComponent (this);
  31354. }
  31355. }
  31356. bool Component::isOnDesktop() const throw()
  31357. {
  31358. return flags.hasHeavyweightPeerFlag;
  31359. }
  31360. void Component::userTriedToCloseWindow()
  31361. {
  31362. /* This means that the user's trying to get rid of your window with the 'close window' system
  31363. menu option (on windows) or possibly the task manager - you should really handle this
  31364. and delete or hide your component in an appropriate way.
  31365. If you want to ignore the event and don't want to trigger this assertion, just override
  31366. this method and do nothing.
  31367. */
  31368. jassertfalse
  31369. }
  31370. void Component::minimisationStateChanged (bool)
  31371. {
  31372. }
  31373. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31374. {
  31375. if (shouldBeOpaque != flags.opaqueFlag)
  31376. {
  31377. flags.opaqueFlag = shouldBeOpaque;
  31378. if (flags.hasHeavyweightPeerFlag)
  31379. {
  31380. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31381. if (peer != 0)
  31382. {
  31383. // to make it recreate the heavyweight window
  31384. addToDesktop (peer->getStyleFlags());
  31385. }
  31386. }
  31387. repaint();
  31388. }
  31389. }
  31390. bool Component::isOpaque() const throw()
  31391. {
  31392. return flags.opaqueFlag;
  31393. }
  31394. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31395. {
  31396. if (shouldBeBuffered != flags.bufferToImageFlag)
  31397. {
  31398. deleteAndZero (bufferedImage_);
  31399. flags.bufferToImageFlag = shouldBeBuffered;
  31400. }
  31401. }
  31402. void Component::toFront (const bool setAsForeground)
  31403. {
  31404. // if component methods are being called from threads other than the message
  31405. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31406. checkMessageManagerIsLocked
  31407. if (flags.hasHeavyweightPeerFlag)
  31408. {
  31409. ComponentPeer* const peer = getPeer();
  31410. if (peer != 0)
  31411. {
  31412. peer->toFront (setAsForeground);
  31413. if (setAsForeground && ! hasKeyboardFocus (true))
  31414. grabKeyboardFocus();
  31415. }
  31416. }
  31417. else if (parentComponent_ != 0)
  31418. {
  31419. if (parentComponent_->childComponentList_.getLast() != this)
  31420. {
  31421. const int index = parentComponent_->childComponentList_.indexOf (this);
  31422. if (index >= 0)
  31423. {
  31424. int insertIndex = -1;
  31425. if (! flags.alwaysOnTopFlag)
  31426. {
  31427. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31428. while (insertIndex > 0
  31429. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31430. {
  31431. --insertIndex;
  31432. }
  31433. }
  31434. if (index != insertIndex)
  31435. {
  31436. parentComponent_->childComponentList_.move (index, insertIndex);
  31437. sendFakeMouseMove();
  31438. repaintParent();
  31439. }
  31440. }
  31441. }
  31442. if (setAsForeground)
  31443. {
  31444. internalBroughtToFront();
  31445. grabKeyboardFocus();
  31446. }
  31447. }
  31448. }
  31449. void Component::toBehind (Component* const other)
  31450. {
  31451. if (other != 0)
  31452. {
  31453. // the two components must belong to the same parent..
  31454. jassert (parentComponent_ == other->parentComponent_);
  31455. if (parentComponent_ != 0)
  31456. {
  31457. const int index = parentComponent_->childComponentList_.indexOf (this);
  31458. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31459. if (index >= 0
  31460. && otherIndex >= 0
  31461. && index != otherIndex - 1
  31462. && other != this)
  31463. {
  31464. if (index < otherIndex)
  31465. --otherIndex;
  31466. parentComponent_->childComponentList_.move (index, otherIndex);
  31467. sendFakeMouseMove();
  31468. repaintParent();
  31469. }
  31470. }
  31471. else if (isOnDesktop())
  31472. {
  31473. jassert (other->isOnDesktop());
  31474. if (other->isOnDesktop())
  31475. {
  31476. ComponentPeer* const us = getPeer();
  31477. ComponentPeer* const them = other->getPeer();
  31478. jassert (us != 0 && them != 0);
  31479. if (us != 0 && them != 0)
  31480. us->toBehind (them);
  31481. }
  31482. }
  31483. }
  31484. }
  31485. void Component::toBack()
  31486. {
  31487. if (isOnDesktop())
  31488. {
  31489. jassertfalse //xxx need to add this to native window
  31490. }
  31491. else if (parentComponent_ != 0
  31492. && parentComponent_->childComponentList_.getFirst() != this)
  31493. {
  31494. const int index = parentComponent_->childComponentList_.indexOf (this);
  31495. if (index > 0)
  31496. {
  31497. int insertIndex = 0;
  31498. if (flags.alwaysOnTopFlag)
  31499. {
  31500. while (insertIndex < parentComponent_->childComponentList_.size()
  31501. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31502. {
  31503. ++insertIndex;
  31504. }
  31505. }
  31506. if (index != insertIndex)
  31507. {
  31508. parentComponent_->childComponentList_.move (index, insertIndex);
  31509. sendFakeMouseMove();
  31510. repaintParent();
  31511. }
  31512. }
  31513. }
  31514. }
  31515. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31516. {
  31517. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31518. {
  31519. flags.alwaysOnTopFlag = shouldStayOnTop;
  31520. if (isOnDesktop())
  31521. {
  31522. ComponentPeer* const peer = getPeer();
  31523. jassert (peer != 0);
  31524. if (peer != 0)
  31525. {
  31526. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31527. {
  31528. // some kinds of peer can't change their always-on-top status, so
  31529. // for these, we'll need to create a new window
  31530. const int oldFlags = peer->getStyleFlags();
  31531. removeFromDesktop();
  31532. addToDesktop (oldFlags);
  31533. }
  31534. }
  31535. }
  31536. if (shouldStayOnTop)
  31537. toFront (false);
  31538. internalHierarchyChanged();
  31539. }
  31540. }
  31541. bool Component::isAlwaysOnTop() const throw()
  31542. {
  31543. return flags.alwaysOnTopFlag;
  31544. }
  31545. int Component::proportionOfWidth (const float proportion) const throw()
  31546. {
  31547. return roundToInt (proportion * bounds_.getWidth());
  31548. }
  31549. int Component::proportionOfHeight (const float proportion) const throw()
  31550. {
  31551. return roundToInt (proportion * bounds_.getHeight());
  31552. }
  31553. int Component::getParentWidth() const throw()
  31554. {
  31555. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31556. : getParentMonitorArea().getWidth();
  31557. }
  31558. int Component::getParentHeight() const throw()
  31559. {
  31560. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31561. : getParentMonitorArea().getHeight();
  31562. }
  31563. int Component::getScreenX() const throw()
  31564. {
  31565. return (parentComponent_ != 0) ? parentComponent_->getScreenX() + getX()
  31566. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenX()
  31567. : getX());
  31568. }
  31569. int Component::getScreenY() const throw()
  31570. {
  31571. return (parentComponent_ != 0) ? parentComponent_->getScreenY() + getY()
  31572. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenY()
  31573. : getY());
  31574. }
  31575. void Component::relativePositionToGlobal (int& x, int& y) const throw()
  31576. {
  31577. const Component* c = this;
  31578. do
  31579. {
  31580. if (c->flags.hasHeavyweightPeerFlag)
  31581. {
  31582. c->getPeer()->relativePositionToGlobal (x, y);
  31583. break;
  31584. }
  31585. x += c->getX();
  31586. y += c->getY();
  31587. c = c->parentComponent_;
  31588. }
  31589. while (c != 0);
  31590. }
  31591. void Component::globalPositionToRelative (int& x, int& y) const throw()
  31592. {
  31593. if (flags.hasHeavyweightPeerFlag)
  31594. {
  31595. getPeer()->globalPositionToRelative (x, y);
  31596. }
  31597. else
  31598. {
  31599. if (parentComponent_ != 0)
  31600. parentComponent_->globalPositionToRelative (x, y);
  31601. x -= getX();
  31602. y -= getY();
  31603. }
  31604. }
  31605. void Component::relativePositionToOtherComponent (const Component* const targetComponent, int& x, int& y) const throw()
  31606. {
  31607. if (targetComponent != 0)
  31608. {
  31609. const Component* c = this;
  31610. do
  31611. {
  31612. if (c == targetComponent)
  31613. return;
  31614. if (c->flags.hasHeavyweightPeerFlag)
  31615. {
  31616. c->getPeer()->relativePositionToGlobal (x, y);
  31617. break;
  31618. }
  31619. x += c->getX();
  31620. y += c->getY();
  31621. c = c->parentComponent_;
  31622. }
  31623. while (c != 0);
  31624. targetComponent->globalPositionToRelative (x, y);
  31625. }
  31626. }
  31627. void Component::setBounds (int x, int y, int w, int h)
  31628. {
  31629. // if component methods are being called from threads other than the message
  31630. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31631. checkMessageManagerIsLocked
  31632. if (w < 0) w = 0;
  31633. if (h < 0) h = 0;
  31634. const bool wasResized = (getWidth() != w || getHeight() != h);
  31635. const bool wasMoved = (getX() != x || getY() != y);
  31636. #ifdef JUCE_DEBUG
  31637. // It's a very bad idea to try to resize a window during its paint() method!
  31638. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31639. #endif
  31640. if (wasMoved || wasResized)
  31641. {
  31642. if (flags.visibleFlag)
  31643. {
  31644. // send a fake mouse move to trigger enter/exit messages if needed..
  31645. sendFakeMouseMove();
  31646. if (! flags.hasHeavyweightPeerFlag)
  31647. repaintParent();
  31648. }
  31649. bounds_.setBounds (x, y, w, h);
  31650. if (wasResized)
  31651. repaint();
  31652. else if (! flags.hasHeavyweightPeerFlag)
  31653. repaintParent();
  31654. if (flags.hasHeavyweightPeerFlag)
  31655. {
  31656. ComponentPeer* const peer = getPeer();
  31657. if (peer != 0)
  31658. {
  31659. if (wasMoved && wasResized)
  31660. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31661. else if (wasMoved)
  31662. peer->setPosition (getX(), getY());
  31663. else if (wasResized)
  31664. peer->setSize (getWidth(), getHeight());
  31665. }
  31666. }
  31667. sendMovedResizedMessages (wasMoved, wasResized);
  31668. }
  31669. }
  31670. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31671. {
  31672. JUCE_TRY
  31673. {
  31674. if (wasMoved)
  31675. moved();
  31676. if (wasResized)
  31677. {
  31678. resized();
  31679. for (int i = childComponentList_.size(); --i >= 0;)
  31680. {
  31681. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31682. i = jmin (i, childComponentList_.size());
  31683. }
  31684. }
  31685. if (parentComponent_ != 0)
  31686. parentComponent_->childBoundsChanged (this);
  31687. if (componentListeners_ != 0)
  31688. {
  31689. const ComponentDeletionWatcher deletionChecker (this);
  31690. for (int i = componentListeners_->size(); --i >= 0;)
  31691. {
  31692. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31693. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31694. if (deletionChecker.hasBeenDeleted())
  31695. return;
  31696. i = jmin (i, componentListeners_->size());
  31697. }
  31698. }
  31699. }
  31700. JUCE_CATCH_EXCEPTION
  31701. }
  31702. void Component::setSize (const int w, const int h)
  31703. {
  31704. setBounds (getX(), getY(), w, h);
  31705. }
  31706. void Component::setTopLeftPosition (const int x, const int y)
  31707. {
  31708. setBounds (x, y, getWidth(), getHeight());
  31709. }
  31710. void Component::setTopRightPosition (const int x, const int y)
  31711. {
  31712. setTopLeftPosition (x - getWidth(), y);
  31713. }
  31714. void Component::setBounds (const Rectangle<int>& r)
  31715. {
  31716. setBounds (r.getX(),
  31717. r.getY(),
  31718. r.getWidth(),
  31719. r.getHeight());
  31720. }
  31721. void Component::setBoundsRelative (const float x, const float y,
  31722. const float w, const float h)
  31723. {
  31724. const int pw = getParentWidth();
  31725. const int ph = getParentHeight();
  31726. setBounds (roundToInt (x * pw),
  31727. roundToInt (y * ph),
  31728. roundToInt (w * pw),
  31729. roundToInt (h * ph));
  31730. }
  31731. void Component::setCentrePosition (const int x, const int y)
  31732. {
  31733. setTopLeftPosition (x - getWidth() / 2,
  31734. y - getHeight() / 2);
  31735. }
  31736. void Component::setCentreRelative (const float x, const float y)
  31737. {
  31738. setCentrePosition (roundToInt (getParentWidth() * x),
  31739. roundToInt (getParentHeight() * y));
  31740. }
  31741. void Component::centreWithSize (const int width, const int height)
  31742. {
  31743. setBounds ((getParentWidth() - width) / 2,
  31744. (getParentHeight() - height) / 2,
  31745. width,
  31746. height);
  31747. }
  31748. void Component::setBoundsInset (const BorderSize& borders)
  31749. {
  31750. setBounds (borders.getLeft(),
  31751. borders.getTop(),
  31752. getParentWidth() - (borders.getLeftAndRight()),
  31753. getParentHeight() - (borders.getTopAndBottom()));
  31754. }
  31755. void Component::setBoundsToFit (int x, int y, int width, int height,
  31756. const Justification& justification,
  31757. const bool onlyReduceInSize)
  31758. {
  31759. // it's no good calling this method unless both the component and
  31760. // target rectangle have a finite size.
  31761. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31762. if (getWidth() > 0 && getHeight() > 0
  31763. && width > 0 && height > 0)
  31764. {
  31765. int newW, newH;
  31766. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31767. {
  31768. newW = getWidth();
  31769. newH = getHeight();
  31770. }
  31771. else
  31772. {
  31773. const double imageRatio = getHeight() / (double) getWidth();
  31774. const double targetRatio = height / (double) width;
  31775. if (imageRatio <= targetRatio)
  31776. {
  31777. newW = width;
  31778. newH = jmin (height, roundToInt (newW * imageRatio));
  31779. }
  31780. else
  31781. {
  31782. newH = height;
  31783. newW = jmin (width, roundToInt (newH / imageRatio));
  31784. }
  31785. }
  31786. if (newW > 0 && newH > 0)
  31787. {
  31788. int newX, newY;
  31789. justification.applyToRectangle (newX, newY, newW, newH,
  31790. x, y, width, height);
  31791. setBounds (newX, newY, newW, newH);
  31792. }
  31793. }
  31794. }
  31795. bool Component::hitTest (int x, int y)
  31796. {
  31797. if (! flags.ignoresMouseClicksFlag)
  31798. return true;
  31799. if (flags.allowChildMouseClicksFlag)
  31800. {
  31801. for (int i = getNumChildComponents(); --i >= 0;)
  31802. {
  31803. Component* const c = getChildComponent (i);
  31804. if (c->isVisible()
  31805. && c->bounds_.contains (x, y)
  31806. && c->hitTest (x - c->getX(),
  31807. y - c->getY()))
  31808. {
  31809. return true;
  31810. }
  31811. }
  31812. }
  31813. return false;
  31814. }
  31815. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31816. const bool allowClicksOnChildComponents) throw()
  31817. {
  31818. flags.ignoresMouseClicksFlag = ! allowClicks;
  31819. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31820. }
  31821. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31822. bool& allowsClicksOnChildComponents) const throw()
  31823. {
  31824. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31825. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31826. }
  31827. bool Component::contains (const int x, const int y)
  31828. {
  31829. if (((unsigned int) x) < (unsigned int) getWidth()
  31830. && ((unsigned int) y) < (unsigned int) getHeight()
  31831. && hitTest (x, y))
  31832. {
  31833. if (parentComponent_ != 0)
  31834. {
  31835. return parentComponent_->contains (x + getX(),
  31836. y + getY());
  31837. }
  31838. else if (flags.hasHeavyweightPeerFlag)
  31839. {
  31840. const ComponentPeer* const peer = getPeer();
  31841. if (peer != 0)
  31842. return peer->contains (x, y, true);
  31843. }
  31844. }
  31845. return false;
  31846. }
  31847. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31848. {
  31849. if (! contains (x, y))
  31850. return false;
  31851. Component* p = this;
  31852. while (p->parentComponent_ != 0)
  31853. {
  31854. x += p->getX();
  31855. y += p->getY();
  31856. p = p->parentComponent_;
  31857. }
  31858. const Component* const c = p->getComponentAt (x, y);
  31859. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31860. }
  31861. Component* Component::getComponentAt (const int x, const int y)
  31862. {
  31863. if (flags.visibleFlag
  31864. && ((unsigned int) x) < (unsigned int) getWidth()
  31865. && ((unsigned int) y) < (unsigned int) getHeight()
  31866. && hitTest (x, y))
  31867. {
  31868. for (int i = childComponentList_.size(); --i >= 0;)
  31869. {
  31870. Component* const child = childComponentList_.getUnchecked(i);
  31871. Component* const c = child->getComponentAt (x - child->getX(),
  31872. y - child->getY());
  31873. if (c != 0)
  31874. return c;
  31875. }
  31876. return this;
  31877. }
  31878. return 0;
  31879. }
  31880. void Component::addChildComponent (Component* const child, int zOrder)
  31881. {
  31882. // if component methods are being called from threads other than the message
  31883. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31884. checkMessageManagerIsLocked
  31885. if (child != 0 && child->parentComponent_ != this)
  31886. {
  31887. if (child->parentComponent_ != 0)
  31888. child->parentComponent_->removeChildComponent (child);
  31889. else
  31890. child->removeFromDesktop();
  31891. child->parentComponent_ = this;
  31892. if (child->isVisible())
  31893. child->repaintParent();
  31894. if (! child->isAlwaysOnTop())
  31895. {
  31896. if (zOrder < 0 || zOrder > childComponentList_.size())
  31897. zOrder = childComponentList_.size();
  31898. while (zOrder > 0)
  31899. {
  31900. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31901. break;
  31902. --zOrder;
  31903. }
  31904. }
  31905. childComponentList_.insert (zOrder, child);
  31906. child->internalHierarchyChanged();
  31907. internalChildrenChanged();
  31908. }
  31909. }
  31910. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31911. {
  31912. if (child != 0)
  31913. {
  31914. child->setVisible (true);
  31915. addChildComponent (child, zOrder);
  31916. }
  31917. }
  31918. void Component::removeChildComponent (Component* const child)
  31919. {
  31920. removeChildComponent (childComponentList_.indexOf (child));
  31921. }
  31922. Component* Component::removeChildComponent (const int index)
  31923. {
  31924. // if component methods are being called from threads other than the message
  31925. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31926. checkMessageManagerIsLocked
  31927. Component* const child = childComponentList_ [index];
  31928. if (child != 0)
  31929. {
  31930. sendFakeMouseMove();
  31931. child->repaintParent();
  31932. childComponentList_.remove (index);
  31933. child->parentComponent_ = 0;
  31934. JUCE_TRY
  31935. {
  31936. if ((currentlyFocusedComponent == child)
  31937. || child->isParentOf (currentlyFocusedComponent))
  31938. {
  31939. // get rid first to force the grabKeyboardFocus to change to us.
  31940. giveAwayFocus();
  31941. grabKeyboardFocus();
  31942. }
  31943. }
  31944. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31945. catch (const std::exception& e)
  31946. {
  31947. currentlyFocusedComponent = 0;
  31948. Desktop::getInstance().triggerFocusCallback();
  31949. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31950. }
  31951. catch (...)
  31952. {
  31953. currentlyFocusedComponent = 0;
  31954. Desktop::getInstance().triggerFocusCallback();
  31955. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31956. }
  31957. #endif
  31958. child->internalHierarchyChanged();
  31959. internalChildrenChanged();
  31960. }
  31961. return child;
  31962. }
  31963. void Component::removeAllChildren()
  31964. {
  31965. for (int i = childComponentList_.size(); --i >= 0;)
  31966. removeChildComponent (i);
  31967. }
  31968. void Component::deleteAllChildren()
  31969. {
  31970. for (int i = childComponentList_.size(); --i >= 0;)
  31971. delete (removeChildComponent (i));
  31972. }
  31973. int Component::getNumChildComponents() const throw()
  31974. {
  31975. return childComponentList_.size();
  31976. }
  31977. Component* Component::getChildComponent (const int index) const throw()
  31978. {
  31979. return childComponentList_ [index];
  31980. }
  31981. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31982. {
  31983. return childComponentList_.indexOf (const_cast <Component*> (child));
  31984. }
  31985. Component* Component::getTopLevelComponent() const throw()
  31986. {
  31987. const Component* comp = this;
  31988. while (comp->parentComponent_ != 0)
  31989. comp = comp->parentComponent_;
  31990. return (Component*) comp;
  31991. }
  31992. bool Component::isParentOf (const Component* possibleChild) const throw()
  31993. {
  31994. while (possibleChild->isValidComponent())
  31995. {
  31996. possibleChild = possibleChild->parentComponent_;
  31997. if (possibleChild == this)
  31998. return true;
  31999. }
  32000. return false;
  32001. }
  32002. void Component::parentHierarchyChanged()
  32003. {
  32004. }
  32005. void Component::childrenChanged()
  32006. {
  32007. }
  32008. void Component::internalChildrenChanged()
  32009. {
  32010. const ComponentDeletionWatcher deletionChecker (this);
  32011. const bool hasListeners = componentListeners_ != 0;
  32012. childrenChanged();
  32013. if (hasListeners)
  32014. {
  32015. if (deletionChecker.hasBeenDeleted())
  32016. return;
  32017. for (int i = componentListeners_->size(); --i >= 0;)
  32018. {
  32019. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32020. ->componentChildrenChanged (*this);
  32021. if (deletionChecker.hasBeenDeleted())
  32022. return;
  32023. i = jmin (i, componentListeners_->size());
  32024. }
  32025. }
  32026. }
  32027. void Component::internalHierarchyChanged()
  32028. {
  32029. parentHierarchyChanged();
  32030. const ComponentDeletionWatcher deletionChecker (this);
  32031. if (componentListeners_ != 0)
  32032. {
  32033. for (int i = componentListeners_->size(); --i >= 0;)
  32034. {
  32035. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32036. ->componentParentHierarchyChanged (*this);
  32037. if (deletionChecker.hasBeenDeleted())
  32038. return;
  32039. i = jmin (i, componentListeners_->size());
  32040. }
  32041. }
  32042. for (int i = childComponentList_.size(); --i >= 0;)
  32043. {
  32044. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32045. // you really shouldn't delete the parent component during a callback telling you
  32046. // that it's changed..
  32047. jassert (! deletionChecker.hasBeenDeleted());
  32048. if (deletionChecker.hasBeenDeleted())
  32049. return;
  32050. i = jmin (i, childComponentList_.size());
  32051. }
  32052. }
  32053. void* Component::runModalLoopCallback (void* userData)
  32054. {
  32055. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32056. }
  32057. int Component::runModalLoop()
  32058. {
  32059. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32060. {
  32061. // use a callback so this can be called from non-gui threads
  32062. return (int) (pointer_sized_int)
  32063. MessageManager::getInstance()
  32064. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32065. }
  32066. Component* const prevFocused = getCurrentlyFocusedComponent();
  32067. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32068. if (prevFocused != 0)
  32069. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32070. if (! isCurrentlyModal())
  32071. enterModalState();
  32072. JUCE_TRY
  32073. {
  32074. while (flags.currentlyModalFlag && flags.visibleFlag)
  32075. {
  32076. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32077. break;
  32078. // check whether this component was deleted during the last message
  32079. if (! isValidMessageListener())
  32080. break;
  32081. }
  32082. }
  32083. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32084. catch (const std::exception& e)
  32085. {
  32086. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32087. return 0;
  32088. }
  32089. catch (...)
  32090. {
  32091. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32092. return 0;
  32093. }
  32094. #endif
  32095. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32096. int returnValue = 0;
  32097. if (modalIndex >= 0)
  32098. {
  32099. modalComponentReturnValueKeys.remove (modalIndex);
  32100. returnValue = modalReturnValues.remove (modalIndex);
  32101. }
  32102. modalComponentStack.removeValue (this);
  32103. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32104. prevFocused->grabKeyboardFocus();
  32105. return returnValue;
  32106. }
  32107. void Component::enterModalState (const bool takeKeyboardFocus_)
  32108. {
  32109. // if component methods are being called from threads other than the message
  32110. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32111. checkMessageManagerIsLocked
  32112. // Check for an attempt to make a component modal when it already is!
  32113. // This can cause nasty problems..
  32114. jassert (! flags.currentlyModalFlag);
  32115. if (! isCurrentlyModal())
  32116. {
  32117. modalComponentStack.add (this);
  32118. modalComponentReturnValueKeys.add (this);
  32119. modalReturnValues.add (0);
  32120. flags.currentlyModalFlag = true;
  32121. setVisible (true);
  32122. if (takeKeyboardFocus_)
  32123. grabKeyboardFocus();
  32124. }
  32125. }
  32126. void Component::exitModalState (const int returnValue)
  32127. {
  32128. if (isCurrentlyModal())
  32129. {
  32130. if (MessageManager::getInstance()->isThisTheMessageThread())
  32131. {
  32132. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32133. if (modalIndex >= 0)
  32134. {
  32135. modalReturnValues.set (modalIndex, returnValue);
  32136. }
  32137. else
  32138. {
  32139. modalComponentReturnValueKeys.add (this);
  32140. modalReturnValues.add (returnValue);
  32141. }
  32142. modalComponentStack.removeValue (this);
  32143. flags.currentlyModalFlag = false;
  32144. bringModalComponentToFront();
  32145. }
  32146. else
  32147. {
  32148. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32149. }
  32150. }
  32151. }
  32152. bool Component::isCurrentlyModal() const throw()
  32153. {
  32154. return flags.currentlyModalFlag
  32155. && getCurrentlyModalComponent() == this;
  32156. }
  32157. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32158. {
  32159. Component* const mc = getCurrentlyModalComponent();
  32160. return mc != 0
  32161. && mc != this
  32162. && (! mc->isParentOf (this))
  32163. && ! mc->canModalEventBeSentToComponent (this);
  32164. }
  32165. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32166. {
  32167. return modalComponentStack.size();
  32168. }
  32169. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32170. {
  32171. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32172. return c->isValidComponent() ? c : 0;
  32173. }
  32174. void Component::bringModalComponentToFront()
  32175. {
  32176. ComponentPeer* lastOne = 0;
  32177. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32178. {
  32179. Component* const c = getCurrentlyModalComponent (i);
  32180. if (c == 0)
  32181. break;
  32182. ComponentPeer* peer = c->getPeer();
  32183. if (peer != 0 && peer != lastOne)
  32184. {
  32185. if (lastOne == 0)
  32186. {
  32187. peer->toFront (true);
  32188. peer->grabFocus();
  32189. }
  32190. else
  32191. peer->toBehind (lastOne);
  32192. lastOne = peer;
  32193. }
  32194. }
  32195. }
  32196. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32197. {
  32198. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32199. }
  32200. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32201. {
  32202. return flags.bringToFrontOnClickFlag;
  32203. }
  32204. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32205. {
  32206. cursor_ = cursor;
  32207. if (flags.visibleFlag)
  32208. {
  32209. int mx, my;
  32210. getMouseXYRelative (mx, my);
  32211. if (flags.draggingFlag || reallyContains (mx, my, false))
  32212. {
  32213. internalUpdateMouseCursor (false);
  32214. }
  32215. }
  32216. }
  32217. const MouseCursor Component::getMouseCursor()
  32218. {
  32219. return cursor_;
  32220. }
  32221. void Component::updateMouseCursor() const throw()
  32222. {
  32223. sendFakeMouseMove();
  32224. }
  32225. void Component::internalUpdateMouseCursor (bool forcedUpdate) throw()
  32226. {
  32227. ComponentPeer* const peer = getPeer();
  32228. if (peer != 0)
  32229. {
  32230. MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this));
  32231. if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0
  32232. || unboundedMouseOffsetY != 0
  32233. || ! isCursorVisibleUntilOffscreen))
  32234. {
  32235. mc = MouseCursor::NoCursor;
  32236. forcedUpdate = true;
  32237. }
  32238. static void* currentCursorHandle = 0;
  32239. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32240. {
  32241. currentCursorHandle = mc.getHandle();
  32242. mc.showInWindow (peer);
  32243. }
  32244. }
  32245. }
  32246. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32247. {
  32248. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32249. }
  32250. void Component::repaintParent() throw()
  32251. {
  32252. if (flags.visibleFlag)
  32253. internalRepaint (0, 0, getWidth(), getHeight());
  32254. }
  32255. void Component::repaint() throw()
  32256. {
  32257. repaint (0, 0, getWidth(), getHeight());
  32258. }
  32259. void Component::repaint (const int x, const int y,
  32260. const int w, const int h) throw()
  32261. {
  32262. deleteAndZero (bufferedImage_);
  32263. if (flags.visibleFlag)
  32264. internalRepaint (x, y, w, h);
  32265. }
  32266. void Component::internalRepaint (int x, int y, int w, int h)
  32267. {
  32268. // if component methods are being called from threads other than the message
  32269. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32270. checkMessageManagerIsLocked
  32271. if (x < 0)
  32272. {
  32273. w += x;
  32274. x = 0;
  32275. }
  32276. if (x + w > getWidth())
  32277. w = getWidth() - x;
  32278. if (w > 0)
  32279. {
  32280. if (y < 0)
  32281. {
  32282. h += y;
  32283. y = 0;
  32284. }
  32285. if (y + h > getHeight())
  32286. h = getHeight() - y;
  32287. if (h > 0)
  32288. {
  32289. if (parentComponent_ != 0)
  32290. {
  32291. x += getX();
  32292. y += getY();
  32293. if (parentComponent_->flags.visibleFlag)
  32294. parentComponent_->internalRepaint (x, y, w, h);
  32295. }
  32296. else if (flags.hasHeavyweightPeerFlag)
  32297. {
  32298. ComponentPeer* const peer = getPeer();
  32299. if (peer != 0)
  32300. peer->repaint (x, y, w, h);
  32301. }
  32302. }
  32303. }
  32304. }
  32305. void Component::paintEntireComponent (Graphics& originalContext)
  32306. {
  32307. jassert (! originalContext.isClipEmpty());
  32308. #ifdef JUCE_DEBUG
  32309. flags.isInsidePaintCall = true;
  32310. #endif
  32311. Graphics* g = &originalContext;
  32312. Image* effectImage = 0;
  32313. if (effect_ != 0)
  32314. {
  32315. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32316. getWidth(), getHeight(),
  32317. ! flags.opaqueFlag);
  32318. g = new Graphics (*effectImage);
  32319. }
  32320. g->saveState();
  32321. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32322. if (! g->isClipEmpty())
  32323. {
  32324. if (bufferedImage_ != 0)
  32325. {
  32326. g->setColour (Colours::black);
  32327. g->drawImageAt (bufferedImage_, 0, 0);
  32328. }
  32329. else
  32330. {
  32331. if (flags.bufferToImageFlag)
  32332. {
  32333. if (bufferedImage_ == 0)
  32334. {
  32335. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32336. getWidth(), getHeight(), ! flags.opaqueFlag);
  32337. Graphics imG (*bufferedImage_);
  32338. paint (imG);
  32339. }
  32340. g->setColour (Colours::black);
  32341. g->drawImageAt (bufferedImage_, 0, 0);
  32342. }
  32343. else
  32344. {
  32345. paint (*g);
  32346. g->resetToDefaultState();
  32347. }
  32348. }
  32349. }
  32350. g->restoreState();
  32351. for (int i = 0; i < childComponentList_.size(); ++i)
  32352. {
  32353. Component* const child = childComponentList_.getUnchecked (i);
  32354. if (child->isVisible())
  32355. {
  32356. g->saveState();
  32357. if (g->reduceClipRegion (child->getX(), child->getY(),
  32358. child->getWidth(), child->getHeight()))
  32359. {
  32360. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32361. {
  32362. const Component* const sibling = childComponentList_.getUnchecked (j);
  32363. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32364. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32365. sibling->getWidth(), sibling->getHeight());
  32366. }
  32367. if (! g->isClipEmpty())
  32368. {
  32369. g->setOrigin (child->getX(), child->getY());
  32370. child->paintEntireComponent (*g);
  32371. }
  32372. }
  32373. g->restoreState();
  32374. }
  32375. }
  32376. JUCE_TRY
  32377. {
  32378. g->saveState();
  32379. paintOverChildren (*g);
  32380. g->restoreState();
  32381. }
  32382. JUCE_CATCH_EXCEPTION
  32383. if (effect_ != 0)
  32384. {
  32385. delete g;
  32386. effect_->applyEffect (*effectImage, originalContext);
  32387. delete effectImage;
  32388. }
  32389. #ifdef JUCE_DEBUG
  32390. flags.isInsidePaintCall = false;
  32391. #endif
  32392. }
  32393. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32394. const bool clipImageToComponentBounds)
  32395. {
  32396. Rectangle<int> r (areaToGrab);
  32397. if (clipImageToComponentBounds)
  32398. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32399. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32400. jmax (1, r.getWidth()),
  32401. jmax (1, r.getHeight()),
  32402. true);
  32403. Graphics imageContext (*componentImage);
  32404. imageContext.setOrigin (-r.getX(),
  32405. -r.getY());
  32406. paintEntireComponent (imageContext);
  32407. return componentImage;
  32408. }
  32409. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32410. {
  32411. if (effect_ != effect)
  32412. {
  32413. effect_ = effect;
  32414. repaint();
  32415. }
  32416. }
  32417. LookAndFeel& Component::getLookAndFeel() const throw()
  32418. {
  32419. const Component* c = this;
  32420. do
  32421. {
  32422. if (c->lookAndFeel_ != 0)
  32423. return *(c->lookAndFeel_);
  32424. c = c->parentComponent_;
  32425. }
  32426. while (c != 0);
  32427. return LookAndFeel::getDefaultLookAndFeel();
  32428. }
  32429. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32430. {
  32431. if (lookAndFeel_ != newLookAndFeel)
  32432. {
  32433. lookAndFeel_ = newLookAndFeel;
  32434. sendLookAndFeelChange();
  32435. }
  32436. }
  32437. void Component::lookAndFeelChanged()
  32438. {
  32439. }
  32440. void Component::sendLookAndFeelChange()
  32441. {
  32442. repaint();
  32443. lookAndFeelChanged();
  32444. // (it's not a great idea to do anything that would delete this component
  32445. // during the lookAndFeelChanged() callback)
  32446. jassert (isValidComponent());
  32447. const ComponentDeletionWatcher deletionChecker (this);
  32448. for (int i = childComponentList_.size(); --i >= 0;)
  32449. {
  32450. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32451. if (deletionChecker.hasBeenDeleted())
  32452. return;
  32453. i = jmin (i, childComponentList_.size());
  32454. }
  32455. }
  32456. static const var::identifier getColourPropertyId (const int colourId)
  32457. {
  32458. String s;
  32459. s.preallocateStorage (18);
  32460. s << T("jcclr_") << colourId;
  32461. return s;
  32462. }
  32463. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32464. {
  32465. var* v = properties.getItem (getColourPropertyId (colourId));
  32466. if (v != 0)
  32467. return Colour ((int) *v);
  32468. if (inheritFromParent && parentComponent_ != 0)
  32469. return parentComponent_->findColour (colourId, true);
  32470. return getLookAndFeel().findColour (colourId);
  32471. }
  32472. bool Component::isColourSpecified (const int colourId) const throw()
  32473. {
  32474. return properties.contains (getColourPropertyId (colourId));
  32475. }
  32476. void Component::removeColour (const int colourId)
  32477. {
  32478. if (properties.remove (getColourPropertyId (colourId)))
  32479. colourChanged();
  32480. }
  32481. void Component::setColour (const int colourId, const Colour& colour)
  32482. {
  32483. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32484. colourChanged();
  32485. }
  32486. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32487. {
  32488. bool changed = false;
  32489. for (int i = properties.size(); --i >= 0;)
  32490. {
  32491. const var::identifier name (properties.getName(i));
  32492. if (name.name.startsWith (T("jcclr_")))
  32493. if (target.properties.set (name, properties [name]))
  32494. changed = true;
  32495. }
  32496. if (changed)
  32497. target.colourChanged();
  32498. }
  32499. void Component::colourChanged()
  32500. {
  32501. }
  32502. const Rectangle<int> Component::getUnclippedArea() const
  32503. {
  32504. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32505. Component* p = parentComponent_;
  32506. int px = getX();
  32507. int py = getY();
  32508. while (p != 0)
  32509. {
  32510. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32511. return Rectangle<int>();
  32512. px += p->getX();
  32513. py += p->getY();
  32514. p = p->parentComponent_;
  32515. }
  32516. return Rectangle<int> (x, y, w, h);
  32517. }
  32518. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32519. const int deltaX, const int deltaY) const throw()
  32520. {
  32521. for (int i = childComponentList_.size(); --i >= 0;)
  32522. {
  32523. const Component* const c = childComponentList_.getUnchecked(i);
  32524. if (c->isVisible())
  32525. {
  32526. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32527. if (! newClip.isEmpty())
  32528. {
  32529. if (c->isOpaque())
  32530. {
  32531. g.excludeClipRegion (deltaX + newClip.getX(),
  32532. deltaY + newClip.getY(),
  32533. newClip.getWidth(),
  32534. newClip.getHeight());
  32535. }
  32536. else
  32537. {
  32538. newClip.translate (-c->getX(), -c->getY());
  32539. c->clipObscuredRegions (g, newClip,
  32540. c->getX() + deltaX,
  32541. c->getY() + deltaY);
  32542. }
  32543. }
  32544. }
  32545. }
  32546. }
  32547. void Component::getVisibleArea (RectangleList& result,
  32548. const bool includeSiblings) const
  32549. {
  32550. result.clear();
  32551. const Rectangle<int> unclipped (getUnclippedArea());
  32552. if (! unclipped.isEmpty())
  32553. {
  32554. result.add (unclipped);
  32555. if (includeSiblings)
  32556. {
  32557. const Component* const c = getTopLevelComponent();
  32558. int x = 0, y = 0;
  32559. c->relativePositionToOtherComponent (this, x, y);
  32560. c->subtractObscuredRegions (result, x, y,
  32561. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32562. this);
  32563. }
  32564. subtractObscuredRegions (result, 0, 0, unclipped, 0);
  32565. result.consolidate();
  32566. }
  32567. }
  32568. void Component::subtractObscuredRegions (RectangleList& result,
  32569. const int deltaX,
  32570. const int deltaY,
  32571. const Rectangle<int>& clipRect,
  32572. const Component* const compToAvoid) const throw()
  32573. {
  32574. for (int i = childComponentList_.size(); --i >= 0;)
  32575. {
  32576. const Component* const c = childComponentList_.getUnchecked(i);
  32577. if (c != compToAvoid && c->isVisible())
  32578. {
  32579. if (c->isOpaque())
  32580. {
  32581. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32582. childBounds.translate (deltaX, deltaY);
  32583. result.subtract (childBounds);
  32584. }
  32585. else
  32586. {
  32587. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32588. newClip.translate (-c->getX(), -c->getY());
  32589. c->subtractObscuredRegions (result,
  32590. c->getX() + deltaX,
  32591. c->getY() + deltaY,
  32592. newClip,
  32593. compToAvoid);
  32594. }
  32595. }
  32596. }
  32597. }
  32598. void Component::mouseEnter (const MouseEvent&)
  32599. {
  32600. // base class does nothing
  32601. }
  32602. void Component::mouseExit (const MouseEvent&)
  32603. {
  32604. // base class does nothing
  32605. }
  32606. void Component::mouseDown (const MouseEvent&)
  32607. {
  32608. // base class does nothing
  32609. }
  32610. void Component::mouseUp (const MouseEvent&)
  32611. {
  32612. // base class does nothing
  32613. }
  32614. void Component::mouseDrag (const MouseEvent&)
  32615. {
  32616. // base class does nothing
  32617. }
  32618. void Component::mouseMove (const MouseEvent&)
  32619. {
  32620. // base class does nothing
  32621. }
  32622. void Component::mouseDoubleClick (const MouseEvent&)
  32623. {
  32624. // base class does nothing
  32625. }
  32626. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32627. {
  32628. // the base class just passes this event up to its parent..
  32629. if (parentComponent_ != 0)
  32630. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32631. wheelIncrementX, wheelIncrementY);
  32632. }
  32633. void Component::resized()
  32634. {
  32635. // base class does nothing
  32636. }
  32637. void Component::moved()
  32638. {
  32639. // base class does nothing
  32640. }
  32641. void Component::childBoundsChanged (Component*)
  32642. {
  32643. // base class does nothing
  32644. }
  32645. void Component::parentSizeChanged()
  32646. {
  32647. // base class does nothing
  32648. }
  32649. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32650. {
  32651. if (componentListeners_ == 0)
  32652. componentListeners_ = new VoidArray();
  32653. componentListeners_->addIfNotAlreadyThere (newListener);
  32654. }
  32655. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32656. {
  32657. jassert (isValidComponent());
  32658. if (componentListeners_ != 0)
  32659. componentListeners_->removeValue (listenerToRemove);
  32660. }
  32661. void Component::inputAttemptWhenModal()
  32662. {
  32663. bringModalComponentToFront();
  32664. getLookAndFeel().playAlertSound();
  32665. }
  32666. bool Component::canModalEventBeSentToComponent (const Component*)
  32667. {
  32668. return false;
  32669. }
  32670. void Component::internalModalInputAttempt()
  32671. {
  32672. Component* const current = getCurrentlyModalComponent();
  32673. if (current != 0)
  32674. current->inputAttemptWhenModal();
  32675. }
  32676. void Component::paint (Graphics&)
  32677. {
  32678. // all painting is done in the subclasses
  32679. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32680. }
  32681. void Component::paintOverChildren (Graphics&)
  32682. {
  32683. // all painting is done in the subclasses
  32684. }
  32685. void Component::handleMessage (const Message& message)
  32686. {
  32687. if (message.intParameter1 == exitModalStateMessage)
  32688. {
  32689. exitModalState (message.intParameter2);
  32690. }
  32691. else if (message.intParameter1 == customCommandMessage)
  32692. {
  32693. handleCommandMessage (message.intParameter2);
  32694. }
  32695. }
  32696. void Component::postCommandMessage (const int commandId) throw()
  32697. {
  32698. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32699. }
  32700. void Component::handleCommandMessage (int)
  32701. {
  32702. // used by subclasses
  32703. }
  32704. void Component::addMouseListener (MouseListener* const newListener,
  32705. const bool wantsEventsForAllNestedChildComponents) throw()
  32706. {
  32707. // if component methods are being called from threads other than the message
  32708. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32709. checkMessageManagerIsLocked
  32710. if (mouseListeners_ == 0)
  32711. mouseListeners_ = new VoidArray();
  32712. if (! mouseListeners_->contains (newListener))
  32713. {
  32714. if (wantsEventsForAllNestedChildComponents)
  32715. {
  32716. mouseListeners_->insert (0, newListener);
  32717. ++numDeepMouseListeners;
  32718. }
  32719. else
  32720. {
  32721. mouseListeners_->add (newListener);
  32722. }
  32723. }
  32724. }
  32725. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32726. {
  32727. // if component methods are being called from threads other than the message
  32728. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32729. checkMessageManagerIsLocked
  32730. if (mouseListeners_ != 0)
  32731. {
  32732. const int index = mouseListeners_->indexOf (listenerToRemove);
  32733. if (index >= 0)
  32734. {
  32735. if (index < numDeepMouseListeners)
  32736. --numDeepMouseListeners;
  32737. mouseListeners_->remove (index);
  32738. }
  32739. }
  32740. }
  32741. void Component::internalMouseEnter (int x, int y, int64 time)
  32742. {
  32743. if (isCurrentlyBlockedByAnotherModalComponent())
  32744. {
  32745. // if something else is modal, always just show a normal mouse cursor
  32746. if (componentUnderMouse == this)
  32747. {
  32748. ComponentPeer* const peer = getPeer();
  32749. if (peer != 0)
  32750. {
  32751. MouseCursor mc (MouseCursor::NormalCursor);
  32752. mc.showInWindow (peer);
  32753. }
  32754. }
  32755. return;
  32756. }
  32757. if (isValidComponent() && ! flags.mouseInsideFlag)
  32758. {
  32759. flags.mouseInsideFlag = true;
  32760. flags.mouseOverFlag = true;
  32761. flags.draggingFlag = false;
  32762. const ComponentDeletionWatcher deletionChecker (this);
  32763. if (flags.repaintOnMouseActivityFlag)
  32764. repaint();
  32765. const MouseEvent me (x, y,
  32766. ModifierKeys::getCurrentModifiers(),
  32767. this,
  32768. Time (time),
  32769. x, y,
  32770. Time (time),
  32771. 0, false);
  32772. mouseEnter (me);
  32773. if (deletionChecker.hasBeenDeleted())
  32774. return;
  32775. Desktop::getInstance().resetTimer();
  32776. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32777. {
  32778. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32779. if (deletionChecker.hasBeenDeleted())
  32780. return;
  32781. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32782. }
  32783. if (mouseListeners_ != 0)
  32784. {
  32785. for (int i = mouseListeners_->size(); --i >= 0;)
  32786. {
  32787. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32788. if (deletionChecker.hasBeenDeleted())
  32789. return;
  32790. i = jmin (i, mouseListeners_->size());
  32791. }
  32792. }
  32793. const Component* p = parentComponent_;
  32794. while (p != 0)
  32795. {
  32796. const ComponentDeletionWatcher parentDeletionChecker (p);
  32797. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32798. {
  32799. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32800. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32801. return;
  32802. i = jmin (i, p->numDeepMouseListeners);
  32803. }
  32804. p = p->parentComponent_;
  32805. }
  32806. }
  32807. if (componentUnderMouse == this)
  32808. internalUpdateMouseCursor (true);
  32809. }
  32810. void Component::internalMouseExit (int x, int y, int64 time)
  32811. {
  32812. const ComponentDeletionWatcher deletionChecker (this);
  32813. if (flags.draggingFlag)
  32814. {
  32815. internalMouseUp (ModifierKeys::getCurrentModifiers().getRawFlags(), x, y, time);
  32816. if (deletionChecker.hasBeenDeleted())
  32817. return;
  32818. }
  32819. enableUnboundedMouseMovement (false);
  32820. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32821. {
  32822. flags.mouseInsideFlag = false;
  32823. flags.mouseOverFlag = false;
  32824. flags.draggingFlag = false;
  32825. if (flags.repaintOnMouseActivityFlag)
  32826. repaint();
  32827. const MouseEvent me (x, y,
  32828. ModifierKeys::getCurrentModifiers(),
  32829. this,
  32830. Time (time),
  32831. x, y,
  32832. Time (time),
  32833. 0, false);
  32834. mouseExit (me);
  32835. if (deletionChecker.hasBeenDeleted())
  32836. return;
  32837. Desktop::getInstance().resetTimer();
  32838. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32839. {
  32840. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32841. if (deletionChecker.hasBeenDeleted())
  32842. return;
  32843. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32844. }
  32845. if (mouseListeners_ != 0)
  32846. {
  32847. for (int i = mouseListeners_->size(); --i >= 0;)
  32848. {
  32849. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32850. if (deletionChecker.hasBeenDeleted())
  32851. return;
  32852. i = jmin (i, mouseListeners_->size());
  32853. }
  32854. }
  32855. const Component* p = parentComponent_;
  32856. while (p != 0)
  32857. {
  32858. const ComponentDeletionWatcher parentDeletionChecker (p);
  32859. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32860. {
  32861. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32862. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32863. return;
  32864. i = jmin (i, p->numDeepMouseListeners);
  32865. }
  32866. p = p->parentComponent_;
  32867. }
  32868. }
  32869. }
  32870. class InternalDragRepeater : public Timer
  32871. {
  32872. public:
  32873. InternalDragRepeater() {}
  32874. ~InternalDragRepeater() {}
  32875. void timerCallback()
  32876. {
  32877. Component* const c = Component::getComponentUnderMouse();
  32878. if (c != 0 && c->isMouseButtonDown())
  32879. {
  32880. int x, y;
  32881. c->getMouseXYRelative (x, y);
  32882. // the offsets have been added on, so must be taken off before calling the
  32883. // drag.. otherwise they'll be added twice
  32884. x -= unboundedMouseOffsetX;
  32885. y -= unboundedMouseOffsetY;
  32886. c->internalMouseDrag (x, y, Time::currentTimeMillis());
  32887. }
  32888. }
  32889. juce_UseDebuggingNewOperator
  32890. private:
  32891. InternalDragRepeater (const InternalDragRepeater&);
  32892. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32893. };
  32894. static InternalDragRepeater* dragRepeater = 0;
  32895. void Component::beginDragAutoRepeat (const int interval)
  32896. {
  32897. if (interval > 0)
  32898. {
  32899. if (dragRepeater == 0)
  32900. dragRepeater = new InternalDragRepeater();
  32901. if (dragRepeater->getTimerInterval() != interval)
  32902. dragRepeater->startTimer (interval);
  32903. }
  32904. else
  32905. {
  32906. deleteAndZero (dragRepeater);
  32907. }
  32908. }
  32909. void Component::internalMouseDown (const int x, const int y, const int64 time)
  32910. {
  32911. Desktop& desktop = Desktop::getInstance();
  32912. int gx = x, gy = y;
  32913. relativePositionToGlobal (gx, gy);
  32914. desktop.registerMouseDown (Point<int> (gx, gy), time, this);
  32915. const ComponentDeletionWatcher deletionChecker (this);
  32916. if (isCurrentlyBlockedByAnotherModalComponent())
  32917. {
  32918. internalModalInputAttempt();
  32919. if (deletionChecker.hasBeenDeleted())
  32920. return;
  32921. // If processing the input attempt has exited the modal loop, we'll allow the event
  32922. // to be delivered..
  32923. if (isCurrentlyBlockedByAnotherModalComponent())
  32924. {
  32925. // allow blocked mouse-events to go to global listeners..
  32926. const MouseEvent me (x, y,
  32927. ModifierKeys::getCurrentModifiers(),
  32928. this,
  32929. Time (time),
  32930. x, y,
  32931. desktop.getLastMouseDownTime(),
  32932. desktop.getNumberOfMultipleClicks(),
  32933. false);
  32934. desktop.resetTimer();
  32935. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  32936. {
  32937. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  32938. if (deletionChecker.hasBeenDeleted())
  32939. return;
  32940. i = jmin (i, desktop.mouseListeners.size());
  32941. }
  32942. return;
  32943. }
  32944. }
  32945. {
  32946. Component* c = this;
  32947. while (c != 0)
  32948. {
  32949. if (c->isBroughtToFrontOnMouseClick())
  32950. {
  32951. c->toFront (true);
  32952. if (deletionChecker.hasBeenDeleted())
  32953. return;
  32954. }
  32955. c = c->parentComponent_;
  32956. }
  32957. }
  32958. if (! flags.dontFocusOnMouseClickFlag)
  32959. grabFocusInternal (focusChangedByMouseClick);
  32960. if (! deletionChecker.hasBeenDeleted())
  32961. {
  32962. flags.draggingFlag = true;
  32963. flags.mouseOverFlag = true;
  32964. if (flags.repaintOnMouseActivityFlag)
  32965. repaint();
  32966. const MouseEvent me (x, y,
  32967. ModifierKeys::getCurrentModifiers(),
  32968. this,
  32969. desktop.getLastMouseDownTime(),
  32970. x, y,
  32971. desktop.getLastMouseDownTime(),
  32972. desktop.getNumberOfMultipleClicks(),
  32973. false);
  32974. mouseDown (me);
  32975. if (deletionChecker.hasBeenDeleted())
  32976. return;
  32977. desktop.resetTimer();
  32978. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  32979. {
  32980. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  32981. if (deletionChecker.hasBeenDeleted())
  32982. return;
  32983. i = jmin (i, desktop.mouseListeners.size());
  32984. }
  32985. if (mouseListeners_ != 0)
  32986. {
  32987. for (int i = mouseListeners_->size(); --i >= 0;)
  32988. {
  32989. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32990. if (deletionChecker.hasBeenDeleted())
  32991. return;
  32992. i = jmin (i, mouseListeners_->size());
  32993. }
  32994. }
  32995. const Component* p = parentComponent_;
  32996. while (p != 0)
  32997. {
  32998. const ComponentDeletionWatcher parentDeletionChecker (p);
  32999. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33000. {
  33001. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  33002. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33003. return;
  33004. i = jmin (i, p->numDeepMouseListeners);
  33005. }
  33006. p = p->parentComponent_;
  33007. }
  33008. }
  33009. }
  33010. void Component::internalMouseUp (const int oldModifiers, int x, int y, const int64 time)
  33011. {
  33012. if (isValidComponent() && flags.draggingFlag)
  33013. {
  33014. Desktop& desktop = Desktop::getInstance();
  33015. flags.draggingFlag = false;
  33016. deleteAndZero (dragRepeater);
  33017. x += unboundedMouseOffsetX;
  33018. y += unboundedMouseOffsetY;
  33019. int gx = x, gy = y;
  33020. relativePositionToGlobal (gx, gy);
  33021. desktop.registerMouseDrag (Point<int> (gx, gy));
  33022. const ComponentDeletionWatcher deletionChecker (this);
  33023. if (flags.repaintOnMouseActivityFlag)
  33024. repaint();
  33025. int mdx, mdy;
  33026. Desktop::getLastMouseDownPosition (mdx, mdy);
  33027. globalPositionToRelative (mdx, mdy);
  33028. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33029. const MouseEvent me (x, y,
  33030. oldModifiers,
  33031. this,
  33032. Time (time),
  33033. mdx, mdy,
  33034. lastMouseDownTime,
  33035. desktop.getNumberOfMultipleClicks(),
  33036. desktop.mouseMovedSignificantlySincePressed
  33037. || time > lastMouseDownTime.toMilliseconds() + 300);
  33038. mouseUp (me);
  33039. if (deletionChecker.hasBeenDeleted())
  33040. return;
  33041. desktop.resetTimer();
  33042. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33043. {
  33044. ((MouseListener*) desktop.mouseListeners[i])->mouseUp (me);
  33045. if (deletionChecker.hasBeenDeleted())
  33046. return;
  33047. i = jmin (i, desktop.mouseListeners.size());
  33048. }
  33049. if (mouseListeners_ != 0)
  33050. {
  33051. for (int i = mouseListeners_->size(); --i >= 0;)
  33052. {
  33053. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33054. if (deletionChecker.hasBeenDeleted())
  33055. return;
  33056. i = jmin (i, mouseListeners_->size());
  33057. }
  33058. }
  33059. {
  33060. const Component* p = parentComponent_;
  33061. while (p != 0)
  33062. {
  33063. const ComponentDeletionWatcher parentDeletionChecker (p);
  33064. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33065. {
  33066. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33067. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33068. return;
  33069. i = jmin (i, p->numDeepMouseListeners);
  33070. }
  33071. p = p->parentComponent_;
  33072. }
  33073. }
  33074. // check for double-click
  33075. if (me.getNumberOfClicks() >= 2)
  33076. {
  33077. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33078. mouseDoubleClick (me);
  33079. int i;
  33080. for (i = desktop.mouseListeners.size(); --i >= 0;)
  33081. {
  33082. ((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me);
  33083. if (deletionChecker.hasBeenDeleted())
  33084. return;
  33085. i = jmin (i, desktop.mouseListeners.size());
  33086. }
  33087. for (i = numListeners; --i >= 0;)
  33088. {
  33089. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33090. return;
  33091. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33092. if (ml != 0)
  33093. ml->mouseDoubleClick (me);
  33094. }
  33095. if (deletionChecker.hasBeenDeleted())
  33096. return;
  33097. const Component* p = parentComponent_;
  33098. while (p != 0)
  33099. {
  33100. const ComponentDeletionWatcher parentDeletionChecker (p);
  33101. for (i = p->numDeepMouseListeners; --i >= 0;)
  33102. {
  33103. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33104. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33105. return;
  33106. i = jmin (i, p->numDeepMouseListeners);
  33107. }
  33108. p = p->parentComponent_;
  33109. }
  33110. }
  33111. }
  33112. enableUnboundedMouseMovement (false);
  33113. }
  33114. void Component::internalMouseDrag (int x, int y, const int64 time)
  33115. {
  33116. if (isValidComponent() && flags.draggingFlag)
  33117. {
  33118. Desktop& desktop = Desktop::getInstance();
  33119. flags.mouseOverFlag = reallyContains (x, y, false);
  33120. x += unboundedMouseOffsetX;
  33121. y += unboundedMouseOffsetY;
  33122. int gx = x, gy = y;
  33123. relativePositionToGlobal (gx, gy);
  33124. desktop.registerMouseDrag (Point<int> (gx, gy));
  33125. const ComponentDeletionWatcher deletionChecker (this);
  33126. int mdx, mdy;
  33127. Desktop::getLastMouseDownPosition (mdx, mdy);
  33128. globalPositionToRelative (mdx, mdy);
  33129. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33130. const MouseEvent me (x, y,
  33131. ModifierKeys::getCurrentModifiers(),
  33132. this,
  33133. Time (time),
  33134. mdx, mdy,
  33135. lastMouseDownTime,
  33136. desktop.getNumberOfMultipleClicks(),
  33137. desktop.mouseMovedSignificantlySincePressed
  33138. || time > lastMouseDownTime.toMilliseconds() + 300);
  33139. mouseDrag (me);
  33140. if (deletionChecker.hasBeenDeleted())
  33141. return;
  33142. desktop.resetTimer();
  33143. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33144. {
  33145. ((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me);
  33146. if (deletionChecker.hasBeenDeleted())
  33147. return;
  33148. i = jmin (i, desktop.mouseListeners.size());
  33149. }
  33150. if (mouseListeners_ != 0)
  33151. {
  33152. for (int i = mouseListeners_->size(); --i >= 0;)
  33153. {
  33154. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33155. if (deletionChecker.hasBeenDeleted())
  33156. return;
  33157. i = jmin (i, mouseListeners_->size());
  33158. }
  33159. }
  33160. const Component* p = parentComponent_;
  33161. while (p != 0)
  33162. {
  33163. const ComponentDeletionWatcher parentDeletionChecker (p);
  33164. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33165. {
  33166. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33167. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33168. return;
  33169. i = jmin (i, p->numDeepMouseListeners);
  33170. }
  33171. p = p->parentComponent_;
  33172. }
  33173. if (this == componentUnderMouse)
  33174. {
  33175. if (isUnboundedMouseModeOn)
  33176. {
  33177. Rectangle<int> screenArea (getParentMonitorArea().expanded (-2, -2));
  33178. int mx, my;
  33179. Desktop::getMousePosition (mx, my);
  33180. if (! screenArea.contains (mx, my))
  33181. {
  33182. int deltaX = 0, deltaY = 0;
  33183. if (mx <= screenArea.getX() || mx >= screenArea.getRight())
  33184. deltaX = getScreenX() + getWidth() / 2 - mx;
  33185. if (my <= screenArea.getY() || my >= screenArea.getBottom())
  33186. deltaY = getScreenY() + getHeight() / 2 - my;
  33187. unboundedMouseOffsetX -= deltaX;
  33188. unboundedMouseOffsetY -= deltaY;
  33189. Desktop::setMousePosition (mx + deltaX,
  33190. my + deltaY);
  33191. }
  33192. else if (isCursorVisibleUntilOffscreen
  33193. && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0)
  33194. && screenArea.contains (mx + unboundedMouseOffsetX,
  33195. my + unboundedMouseOffsetY))
  33196. {
  33197. mx += unboundedMouseOffsetX;
  33198. my += unboundedMouseOffsetY;
  33199. unboundedMouseOffsetX = 0;
  33200. unboundedMouseOffsetY = 0;
  33201. Desktop::setMousePosition (mx, my);
  33202. }
  33203. }
  33204. internalUpdateMouseCursor (false);
  33205. }
  33206. }
  33207. }
  33208. void Component::internalMouseMove (const int x, const int y, const int64 time)
  33209. {
  33210. const ComponentDeletionWatcher deletionChecker (this);
  33211. if (isValidComponent())
  33212. {
  33213. Desktop& desktop = Desktop::getInstance();
  33214. const MouseEvent me (x, y,
  33215. ModifierKeys::getCurrentModifiers(),
  33216. this,
  33217. Time (time),
  33218. x, y,
  33219. Time (time),
  33220. 0, false);
  33221. if (isCurrentlyBlockedByAnotherModalComponent())
  33222. {
  33223. // allow blocked mouse-events to go to global listeners..
  33224. desktop.sendMouseMove();
  33225. }
  33226. else
  33227. {
  33228. if (this == componentUnderMouse)
  33229. internalUpdateMouseCursor (false);
  33230. flags.mouseOverFlag = true;
  33231. mouseMove (me);
  33232. if (deletionChecker.hasBeenDeleted())
  33233. return;
  33234. desktop.resetTimer();
  33235. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33236. {
  33237. ((MouseListener*) desktop.mouseListeners[i])->mouseMove (me);
  33238. if (deletionChecker.hasBeenDeleted())
  33239. return;
  33240. i = jmin (i, desktop.mouseListeners.size());
  33241. }
  33242. if (mouseListeners_ != 0)
  33243. {
  33244. for (int i = mouseListeners_->size(); --i >= 0;)
  33245. {
  33246. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33247. if (deletionChecker.hasBeenDeleted())
  33248. return;
  33249. i = jmin (i, mouseListeners_->size());
  33250. }
  33251. }
  33252. const Component* p = parentComponent_;
  33253. while (p != 0)
  33254. {
  33255. const ComponentDeletionWatcher parentDeletionChecker (p);
  33256. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33257. {
  33258. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33259. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33260. return;
  33261. i = jmin (i, p->numDeepMouseListeners);
  33262. }
  33263. p = p->parentComponent_;
  33264. }
  33265. }
  33266. }
  33267. }
  33268. void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time)
  33269. {
  33270. Desktop& desktop = Desktop::getInstance();
  33271. const ComponentDeletionWatcher deletionChecker (this);
  33272. const float wheelIncrementX = intAmountX * (1.0f / 256.0f);
  33273. const float wheelIncrementY = intAmountY * (1.0f / 256.0f);
  33274. int mx, my;
  33275. getMouseXYRelative (mx, my);
  33276. const MouseEvent me (mx, my,
  33277. ModifierKeys::getCurrentModifiers(),
  33278. this,
  33279. Time (time),
  33280. mx, my,
  33281. Time (time),
  33282. 0, false);
  33283. if (isCurrentlyBlockedByAnotherModalComponent())
  33284. {
  33285. // allow blocked mouse-events to go to global listeners..
  33286. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33287. {
  33288. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33289. if (deletionChecker.hasBeenDeleted())
  33290. return;
  33291. i = jmin (i, desktop.mouseListeners.size());
  33292. }
  33293. }
  33294. else
  33295. {
  33296. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33297. if (deletionChecker.hasBeenDeleted())
  33298. return;
  33299. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33300. {
  33301. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33302. if (deletionChecker.hasBeenDeleted())
  33303. return;
  33304. i = jmin (i, desktop.mouseListeners.size());
  33305. }
  33306. if (mouseListeners_ != 0)
  33307. {
  33308. for (int i = mouseListeners_->size(); --i >= 0;)
  33309. {
  33310. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33311. if (deletionChecker.hasBeenDeleted())
  33312. return;
  33313. i = jmin (i, mouseListeners_->size());
  33314. }
  33315. }
  33316. const Component* p = parentComponent_;
  33317. while (p != 0)
  33318. {
  33319. const ComponentDeletionWatcher parentDeletionChecker (p);
  33320. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33321. {
  33322. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33323. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33324. return;
  33325. i = jmin (i, p->numDeepMouseListeners);
  33326. }
  33327. p = p->parentComponent_;
  33328. }
  33329. sendFakeMouseMove();
  33330. }
  33331. }
  33332. void Component::sendFakeMouseMove() const
  33333. {
  33334. ComponentPeer* const peer = getPeer();
  33335. if (peer != 0)
  33336. peer->sendFakeMouseMove();
  33337. }
  33338. void Component::broughtToFront()
  33339. {
  33340. }
  33341. void Component::internalBroughtToFront()
  33342. {
  33343. if (isValidComponent())
  33344. {
  33345. if (flags.hasHeavyweightPeerFlag)
  33346. Desktop::getInstance().componentBroughtToFront (this);
  33347. const ComponentDeletionWatcher deletionChecker (this);
  33348. broughtToFront();
  33349. if (deletionChecker.hasBeenDeleted())
  33350. return;
  33351. if (componentListeners_ != 0)
  33352. {
  33353. for (int i = componentListeners_->size(); --i >= 0;)
  33354. {
  33355. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33356. ->componentBroughtToFront (*this);
  33357. if (deletionChecker.hasBeenDeleted())
  33358. return;
  33359. i = jmin (i, componentListeners_->size());
  33360. }
  33361. }
  33362. // when brought to the front and there's a modal component blocking this one,
  33363. // we need to bring the modal one to the front instead..
  33364. Component* const cm = getCurrentlyModalComponent();
  33365. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33366. bringModalComponentToFront();
  33367. }
  33368. }
  33369. void Component::focusGained (FocusChangeType)
  33370. {
  33371. // base class does nothing
  33372. }
  33373. void Component::internalFocusGain (const FocusChangeType cause)
  33374. {
  33375. const ComponentDeletionWatcher deletionChecker (this);
  33376. focusGained (cause);
  33377. if (! deletionChecker.hasBeenDeleted())
  33378. internalChildFocusChange (cause);
  33379. }
  33380. void Component::focusLost (FocusChangeType)
  33381. {
  33382. // base class does nothing
  33383. }
  33384. void Component::internalFocusLoss (const FocusChangeType cause)
  33385. {
  33386. const ComponentDeletionWatcher deletionChecker (this);
  33387. focusLost (focusChangedDirectly);
  33388. if (! deletionChecker.hasBeenDeleted())
  33389. internalChildFocusChange (cause);
  33390. }
  33391. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33392. {
  33393. // base class does nothing
  33394. }
  33395. void Component::internalChildFocusChange (FocusChangeType cause)
  33396. {
  33397. const bool childIsNowFocused = hasKeyboardFocus (true);
  33398. if (flags.childCompFocusedFlag != childIsNowFocused)
  33399. {
  33400. flags.childCompFocusedFlag = childIsNowFocused;
  33401. const ComponentDeletionWatcher deletionChecker (this);
  33402. focusOfChildComponentChanged (cause);
  33403. if (deletionChecker.hasBeenDeleted())
  33404. return;
  33405. }
  33406. if (parentComponent_ != 0)
  33407. parentComponent_->internalChildFocusChange (cause);
  33408. }
  33409. bool Component::isEnabled() const throw()
  33410. {
  33411. return (! flags.isDisabledFlag)
  33412. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33413. }
  33414. void Component::setEnabled (const bool shouldBeEnabled)
  33415. {
  33416. if (flags.isDisabledFlag == shouldBeEnabled)
  33417. {
  33418. flags.isDisabledFlag = ! shouldBeEnabled;
  33419. // if any parent components are disabled, setting our flag won't make a difference,
  33420. // so no need to send a change message
  33421. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33422. sendEnablementChangeMessage();
  33423. }
  33424. }
  33425. void Component::sendEnablementChangeMessage()
  33426. {
  33427. const ComponentDeletionWatcher deletionChecker (this);
  33428. enablementChanged();
  33429. if (deletionChecker.hasBeenDeleted())
  33430. return;
  33431. for (int i = getNumChildComponents(); --i >= 0;)
  33432. {
  33433. Component* const c = getChildComponent (i);
  33434. if (c != 0)
  33435. {
  33436. c->sendEnablementChangeMessage();
  33437. if (deletionChecker.hasBeenDeleted())
  33438. return;
  33439. }
  33440. }
  33441. }
  33442. void Component::enablementChanged()
  33443. {
  33444. }
  33445. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33446. {
  33447. flags.wantsFocusFlag = wantsFocus;
  33448. }
  33449. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33450. {
  33451. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33452. }
  33453. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33454. {
  33455. return ! flags.dontFocusOnMouseClickFlag;
  33456. }
  33457. bool Component::getWantsKeyboardFocus() const throw()
  33458. {
  33459. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33460. }
  33461. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33462. {
  33463. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33464. }
  33465. bool Component::isFocusContainer() const throw()
  33466. {
  33467. return flags.isFocusContainerFlag;
  33468. }
  33469. int Component::getExplicitFocusOrder() const throw()
  33470. {
  33471. return properties ["_jexfo"];
  33472. }
  33473. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33474. {
  33475. properties.set ("_jexfo", newFocusOrderIndex);
  33476. }
  33477. KeyboardFocusTraverser* Component::createFocusTraverser()
  33478. {
  33479. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33480. return new KeyboardFocusTraverser();
  33481. return parentComponent_->createFocusTraverser();
  33482. }
  33483. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33484. {
  33485. // give the focus to this component
  33486. if (currentlyFocusedComponent != this)
  33487. {
  33488. JUCE_TRY
  33489. {
  33490. // get the focus onto our desktop window
  33491. ComponentPeer* const peer = getPeer();
  33492. if (peer != 0)
  33493. {
  33494. const ComponentDeletionWatcher deletionChecker (this);
  33495. peer->grabFocus();
  33496. if (peer->isFocused() && currentlyFocusedComponent != this)
  33497. {
  33498. Component* const componentLosingFocus = currentlyFocusedComponent;
  33499. currentlyFocusedComponent = this;
  33500. Desktop::getInstance().triggerFocusCallback();
  33501. // call this after setting currentlyFocusedComponent so that the one that's
  33502. // losing it has a chance to see where focus is going
  33503. if (componentLosingFocus->isValidComponent())
  33504. componentLosingFocus->internalFocusLoss (cause);
  33505. if (currentlyFocusedComponent == this)
  33506. {
  33507. focusGained (cause);
  33508. if (! deletionChecker.hasBeenDeleted())
  33509. internalChildFocusChange (cause);
  33510. }
  33511. }
  33512. }
  33513. }
  33514. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33515. catch (const std::exception& e)
  33516. {
  33517. currentlyFocusedComponent = 0;
  33518. Desktop::getInstance().triggerFocusCallback();
  33519. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33520. }
  33521. catch (...)
  33522. {
  33523. currentlyFocusedComponent = 0;
  33524. Desktop::getInstance().triggerFocusCallback();
  33525. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33526. }
  33527. #endif
  33528. }
  33529. }
  33530. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33531. {
  33532. if (isShowing())
  33533. {
  33534. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33535. {
  33536. takeKeyboardFocus (cause);
  33537. }
  33538. else
  33539. {
  33540. if (isParentOf (currentlyFocusedComponent)
  33541. && currentlyFocusedComponent->isShowing())
  33542. {
  33543. // do nothing if the focused component is actually a child of ours..
  33544. }
  33545. else
  33546. {
  33547. // find the default child component..
  33548. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33549. if (traverser != 0)
  33550. {
  33551. Component* const defaultComp = traverser->getDefaultComponent (this);
  33552. traverser = 0;
  33553. if (defaultComp != 0)
  33554. {
  33555. defaultComp->grabFocusInternal (cause, false);
  33556. return;
  33557. }
  33558. }
  33559. if (canTryParent && parentComponent_ != 0)
  33560. {
  33561. // if no children want it and we're allowed to try our parent comp,
  33562. // then pass up to parent, which will try our siblings.
  33563. parentComponent_->grabFocusInternal (cause, true);
  33564. }
  33565. }
  33566. }
  33567. }
  33568. }
  33569. void Component::grabKeyboardFocus()
  33570. {
  33571. // if component methods are being called from threads other than the message
  33572. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33573. checkMessageManagerIsLocked
  33574. grabFocusInternal (focusChangedDirectly);
  33575. }
  33576. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33577. {
  33578. // if component methods are being called from threads other than the message
  33579. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33580. checkMessageManagerIsLocked
  33581. if (parentComponent_ != 0)
  33582. {
  33583. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33584. if (traverser != 0)
  33585. {
  33586. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33587. : traverser->getPreviousComponent (this);
  33588. traverser = 0;
  33589. if (nextComp != 0)
  33590. {
  33591. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33592. {
  33593. const ComponentDeletionWatcher deletionChecker (nextComp);
  33594. internalModalInputAttempt();
  33595. if (deletionChecker.hasBeenDeleted()
  33596. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33597. return;
  33598. }
  33599. nextComp->grabFocusInternal (focusChangedByTabKey);
  33600. return;
  33601. }
  33602. }
  33603. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33604. }
  33605. }
  33606. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33607. {
  33608. return (currentlyFocusedComponent == this)
  33609. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33610. }
  33611. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33612. {
  33613. return currentlyFocusedComponent;
  33614. }
  33615. void Component::giveAwayFocus()
  33616. {
  33617. // use a copy so we can clear the value before the call
  33618. Component* const componentLosingFocus = currentlyFocusedComponent;
  33619. currentlyFocusedComponent = 0;
  33620. Desktop::getInstance().triggerFocusCallback();
  33621. if (componentLosingFocus->isValidComponent())
  33622. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33623. }
  33624. bool Component::isMouseOver() const throw()
  33625. {
  33626. return flags.mouseOverFlag;
  33627. }
  33628. bool Component::isMouseButtonDown() const throw()
  33629. {
  33630. return flags.draggingFlag;
  33631. }
  33632. bool Component::isMouseOverOrDragging() const throw()
  33633. {
  33634. return flags.mouseOverFlag || flags.draggingFlag;
  33635. }
  33636. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33637. {
  33638. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33639. }
  33640. void Component::getMouseXYRelative (int& mx, int& my) const throw()
  33641. {
  33642. Desktop::getMousePosition (mx, my);
  33643. globalPositionToRelative (mx, my);
  33644. mx += unboundedMouseOffsetX;
  33645. my += unboundedMouseOffsetY;
  33646. }
  33647. void Component::enableUnboundedMouseMovement (bool enable,
  33648. bool keepCursorVisibleUntilOffscreen) throw()
  33649. {
  33650. enable = enable && isMouseButtonDown();
  33651. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33652. if (enable != isUnboundedMouseModeOn)
  33653. {
  33654. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33655. || unboundedMouseOffsetX != 0
  33656. || unboundedMouseOffsetY != 0))
  33657. {
  33658. // when released, return the mouse to within the component's bounds
  33659. int mx, my;
  33660. getMouseXYRelative (mx, my);
  33661. mx = jlimit (0, getWidth(), mx);
  33662. my = jlimit (0, getHeight(), my);
  33663. relativePositionToGlobal (mx, my);
  33664. Desktop::setMousePosition (mx, my);
  33665. }
  33666. isUnboundedMouseModeOn = enable;
  33667. unboundedMouseOffsetX = 0;
  33668. unboundedMouseOffsetY = 0;
  33669. internalUpdateMouseCursor (true);
  33670. }
  33671. }
  33672. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33673. {
  33674. return componentUnderMouse;
  33675. }
  33676. const Rectangle<int> Component::getParentMonitorArea() const throw()
  33677. {
  33678. int centreX = getWidth() / 2;
  33679. int centreY = getHeight() / 2;
  33680. relativePositionToGlobal (centreX, centreY);
  33681. return Desktop::getInstance().getMonitorAreaContaining (centreX, centreY);
  33682. }
  33683. void Component::addKeyListener (KeyListener* const newListener) throw()
  33684. {
  33685. if (keyListeners_ == 0)
  33686. keyListeners_ = new VoidArray();
  33687. keyListeners_->addIfNotAlreadyThere (newListener);
  33688. }
  33689. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33690. {
  33691. if (keyListeners_ != 0)
  33692. keyListeners_->removeValue (listenerToRemove);
  33693. }
  33694. bool Component::keyPressed (const KeyPress&)
  33695. {
  33696. return false;
  33697. }
  33698. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33699. {
  33700. return false;
  33701. }
  33702. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33703. {
  33704. if (parentComponent_ != 0)
  33705. parentComponent_->modifierKeysChanged (modifiers);
  33706. }
  33707. void Component::internalModifierKeysChanged()
  33708. {
  33709. sendFakeMouseMove();
  33710. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33711. }
  33712. ComponentPeer* Component::getPeer() const throw()
  33713. {
  33714. if (flags.hasHeavyweightPeerFlag)
  33715. return ComponentPeer::getPeerFor (this);
  33716. else if (parentComponent_ != 0)
  33717. return parentComponent_->getPeer();
  33718. else
  33719. return 0;
  33720. }
  33721. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33722. : componentToWatch (componentToWatch_),
  33723. componentUID (componentToWatch_->getComponentUID())
  33724. {
  33725. // not possible to check on an already-deleted object..
  33726. jassert (componentToWatch_->isValidComponent());
  33727. }
  33728. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33729. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33730. {
  33731. return ! (componentToWatch->isValidComponent()
  33732. && componentToWatch->getComponentUID() == componentUID);
  33733. }
  33734. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33735. {
  33736. return hasBeenDeleted() ? 0 : componentToWatch;
  33737. }
  33738. END_JUCE_NAMESPACE
  33739. /*** End of inlined file: juce_Component.cpp ***/
  33740. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33741. BEGIN_JUCE_NAMESPACE
  33742. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33743. {
  33744. }
  33745. void ComponentListener::componentBroughtToFront (Component&)
  33746. {
  33747. }
  33748. void ComponentListener::componentVisibilityChanged (Component&)
  33749. {
  33750. }
  33751. void ComponentListener::componentChildrenChanged (Component&)
  33752. {
  33753. }
  33754. void ComponentListener::componentParentHierarchyChanged (Component&)
  33755. {
  33756. }
  33757. void ComponentListener::componentNameChanged (Component&)
  33758. {
  33759. }
  33760. END_JUCE_NAMESPACE
  33761. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33762. /*** Start of inlined file: juce_Desktop.cpp ***/
  33763. BEGIN_JUCE_NAMESPACE
  33764. Desktop::Desktop() throw()
  33765. : lastFakeMouseMoveX (0),
  33766. lastFakeMouseMoveY (0),
  33767. mouseClickCounter (0),
  33768. mouseMovedSignificantlySincePressed (false),
  33769. kioskModeComponent (0)
  33770. {
  33771. zerostruct (mouseDowns);
  33772. refreshMonitorSizes();
  33773. }
  33774. Desktop::~Desktop() throw()
  33775. {
  33776. jassert (instance == this);
  33777. instance = 0;
  33778. // doh! If you don't delete all your windows before exiting, you're going to
  33779. // be leaking memory!
  33780. jassert (desktopComponents.size() == 0);
  33781. }
  33782. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33783. {
  33784. if (instance == 0)
  33785. instance = new Desktop();
  33786. return *instance;
  33787. }
  33788. Desktop* Desktop::instance = 0;
  33789. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33790. const bool clipToWorkArea);
  33791. void Desktop::refreshMonitorSizes() throw()
  33792. {
  33793. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33794. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33795. monitorCoordsClipped.clear();
  33796. monitorCoordsUnclipped.clear();
  33797. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33798. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33799. jassert (monitorCoordsClipped.size() > 0
  33800. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33801. if (oldClipped != monitorCoordsClipped
  33802. || oldUnclipped != monitorCoordsUnclipped)
  33803. {
  33804. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33805. {
  33806. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33807. if (p != 0)
  33808. p->handleScreenSizeChange();
  33809. }
  33810. }
  33811. }
  33812. int Desktop::getNumDisplayMonitors() const throw()
  33813. {
  33814. return monitorCoordsClipped.size();
  33815. }
  33816. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33817. {
  33818. return clippedToWorkArea ? monitorCoordsClipped [index]
  33819. : monitorCoordsUnclipped [index];
  33820. }
  33821. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33822. {
  33823. RectangleList rl;
  33824. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33825. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33826. return rl;
  33827. }
  33828. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33829. {
  33830. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33831. }
  33832. const Rectangle<int> Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw()
  33833. {
  33834. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33835. double bestDistance = 1.0e10;
  33836. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33837. {
  33838. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33839. if (rect.contains (cx, cy))
  33840. return rect;
  33841. const double distance = juce_hypot ((double) (rect.getCentreX() - cx),
  33842. (double) (rect.getCentreY() - cy));
  33843. if (distance < bestDistance)
  33844. {
  33845. bestDistance = distance;
  33846. best = rect;
  33847. }
  33848. }
  33849. return best;
  33850. }
  33851. int Desktop::getNumComponents() const throw()
  33852. {
  33853. return desktopComponents.size();
  33854. }
  33855. Component* Desktop::getComponent (const int index) const throw()
  33856. {
  33857. return desktopComponents [index];
  33858. }
  33859. Component* Desktop::findComponentAt (const int screenX,
  33860. const int screenY) const
  33861. {
  33862. for (int i = desktopComponents.size(); --i >= 0;)
  33863. {
  33864. Component* const c = desktopComponents.getUnchecked(i);
  33865. int x = screenX, y = screenY;
  33866. c->globalPositionToRelative (x, y);
  33867. if (c->contains (x, y))
  33868. return c->getComponentAt (x, y);
  33869. }
  33870. return 0;
  33871. }
  33872. void Desktop::addDesktopComponent (Component* const c) throw()
  33873. {
  33874. jassert (c != 0);
  33875. jassert (! desktopComponents.contains (c));
  33876. desktopComponents.addIfNotAlreadyThere (c);
  33877. }
  33878. void Desktop::removeDesktopComponent (Component* const c) throw()
  33879. {
  33880. desktopComponents.removeValue (c);
  33881. }
  33882. void Desktop::componentBroughtToFront (Component* const c) throw()
  33883. {
  33884. const int index = desktopComponents.indexOf (c);
  33885. jassert (index >= 0);
  33886. if (index >= 0)
  33887. {
  33888. int newIndex = -1;
  33889. if (! c->isAlwaysOnTop())
  33890. {
  33891. newIndex = desktopComponents.size();
  33892. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33893. --newIndex;
  33894. --newIndex;
  33895. }
  33896. desktopComponents.move (index, newIndex);
  33897. }
  33898. }
  33899. void Desktop::getLastMouseDownPosition (int& x, int& y) throw()
  33900. {
  33901. const Desktop& d = getInstance();
  33902. x = d.mouseDowns[0].position.getX();
  33903. y = d.mouseDowns[0].position.getY();
  33904. }
  33905. int Desktop::getMouseButtonClickCounter() throw()
  33906. {
  33907. return getInstance().mouseClickCounter;
  33908. }
  33909. void Desktop::incrementMouseClickCounter() throw()
  33910. {
  33911. ++mouseClickCounter;
  33912. }
  33913. const Time Desktop::getLastMouseDownTime() const throw()
  33914. {
  33915. return Time (mouseDowns[0].time);
  33916. }
  33917. void Desktop::registerMouseDown (const Point<int>& position, int64 time, Component* component) throw()
  33918. {
  33919. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  33920. mouseDowns[i] = mouseDowns[i - 1];
  33921. mouseDowns[0].position = position;
  33922. mouseDowns[0].time = time;
  33923. mouseDowns[0].component = component;
  33924. mouseMovedSignificantlySincePressed = false;
  33925. }
  33926. void Desktop::registerMouseDrag (const Point<int>& position) throw()
  33927. {
  33928. mouseMovedSignificantlySincePressed
  33929. = mouseMovedSignificantlySincePressed
  33930. || abs (mouseDowns[0].position.getX() - position.getX()) >= 4
  33931. || abs (mouseDowns[0].position.getY() - position.getY()) >= 4;
  33932. }
  33933. int Desktop::getNumberOfMultipleClicks() const throw()
  33934. {
  33935. int numClicks = 0;
  33936. if (mouseDowns[0].time != 0)
  33937. {
  33938. if (! mouseMovedSignificantlySincePressed)
  33939. ++numClicks;
  33940. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  33941. {
  33942. if (mouseDowns[0].time - mouseDowns[i].time
  33943. < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  33944. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  33945. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  33946. && mouseDowns[0].component == mouseDowns[i].component)
  33947. {
  33948. ++numClicks;
  33949. }
  33950. else
  33951. {
  33952. break;
  33953. }
  33954. }
  33955. }
  33956. return numClicks;
  33957. }
  33958. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  33959. {
  33960. jassert (listener != 0);
  33961. if (listener != 0)
  33962. {
  33963. mouseListeners.add (listener);
  33964. resetTimer();
  33965. }
  33966. }
  33967. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  33968. {
  33969. mouseListeners.removeValue (listener);
  33970. resetTimer();
  33971. }
  33972. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  33973. {
  33974. jassert (listener != 0);
  33975. if (listener != 0)
  33976. focusListeners.add (listener);
  33977. }
  33978. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  33979. {
  33980. focusListeners.removeValue (listener);
  33981. }
  33982. void Desktop::triggerFocusCallback() throw()
  33983. {
  33984. triggerAsyncUpdate();
  33985. }
  33986. void Desktop::handleAsyncUpdate()
  33987. {
  33988. for (int i = focusListeners.size(); --i >= 0;)
  33989. {
  33990. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  33991. i = jmin (i, focusListeners.size());
  33992. }
  33993. }
  33994. void Desktop::timerCallback()
  33995. {
  33996. int x, y;
  33997. getMousePosition (x, y);
  33998. if (lastFakeMouseMoveX != x || lastFakeMouseMoveY != y)
  33999. sendMouseMove();
  34000. }
  34001. void Desktop::sendMouseMove()
  34002. {
  34003. if (mouseListeners.size() > 0)
  34004. {
  34005. startTimer (20);
  34006. int x, y;
  34007. getMousePosition (x, y);
  34008. lastFakeMouseMoveX = x;
  34009. lastFakeMouseMoveY = y;
  34010. Component* const target = findComponentAt (x, y);
  34011. if (target != 0)
  34012. {
  34013. target->globalPositionToRelative (x, y);
  34014. ComponentDeletionWatcher deletionChecker (target);
  34015. const MouseEvent me (x, y,
  34016. ModifierKeys::getCurrentModifiers(),
  34017. target,
  34018. Time::getCurrentTime(),
  34019. x, y,
  34020. Time::getCurrentTime(),
  34021. 0, false);
  34022. for (int i = mouseListeners.size(); --i >= 0;)
  34023. {
  34024. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  34025. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  34026. else
  34027. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  34028. if (deletionChecker.hasBeenDeleted())
  34029. return;
  34030. i = jmin (i, mouseListeners.size());
  34031. }
  34032. }
  34033. }
  34034. }
  34035. void Desktop::resetTimer() throw()
  34036. {
  34037. if (mouseListeners.size() == 0)
  34038. stopTimer();
  34039. else
  34040. startTimer (100);
  34041. getMousePosition (lastFakeMouseMoveX, lastFakeMouseMoveY);
  34042. }
  34043. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  34044. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  34045. {
  34046. if (kioskModeComponent != componentToUse)
  34047. {
  34048. // agh! Don't delete a component without first stopping it being the kiosk comp
  34049. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  34050. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  34051. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  34052. if (kioskModeComponent->isValidComponent())
  34053. {
  34054. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  34055. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  34056. }
  34057. kioskModeComponent = componentToUse;
  34058. if (kioskModeComponent != 0)
  34059. {
  34060. jassert (kioskModeComponent->isValidComponent());
  34061. // Only components that are already on the desktop can be put into kiosk mode!
  34062. jassert (kioskModeComponent->isOnDesktop());
  34063. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  34064. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  34065. }
  34066. }
  34067. }
  34068. END_JUCE_NAMESPACE
  34069. /*** End of inlined file: juce_Desktop.cpp ***/
  34070. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  34071. BEGIN_JUCE_NAMESPACE
  34072. ArrowButton::ArrowButton (const String& name,
  34073. float arrowDirectionInRadians,
  34074. const Colour& arrowColour)
  34075. : Button (name),
  34076. colour (arrowColour)
  34077. {
  34078. path.lineTo (0.0f, 1.0f);
  34079. path.lineTo (1.0f, 0.5f);
  34080. path.closeSubPath();
  34081. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  34082. 0.5f, 0.5f));
  34083. setComponentEffect (&shadow);
  34084. buttonStateChanged();
  34085. }
  34086. ArrowButton::~ArrowButton()
  34087. {
  34088. }
  34089. void ArrowButton::paintButton (Graphics& g,
  34090. bool /*isMouseOverButton*/,
  34091. bool /*isButtonDown*/)
  34092. {
  34093. g.setColour (colour);
  34094. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34095. (float) offset,
  34096. (float) (getWidth() - 3),
  34097. (float) (getHeight() - 3),
  34098. false));
  34099. }
  34100. void ArrowButton::buttonStateChanged()
  34101. {
  34102. offset = (isDown()) ? 1 : 0;
  34103. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34104. 0.3f, -1, 0);
  34105. }
  34106. END_JUCE_NAMESPACE
  34107. /*** End of inlined file: juce_ArrowButton.cpp ***/
  34108. /*** Start of inlined file: juce_Button.cpp ***/
  34109. BEGIN_JUCE_NAMESPACE
  34110. class Button::RepeatTimer : public Timer
  34111. {
  34112. public:
  34113. RepeatTimer (Button& owner_) : owner (owner_) {}
  34114. void timerCallback() { owner.repeatTimerCallback(); }
  34115. juce_UseDebuggingNewOperator
  34116. private:
  34117. Button& owner;
  34118. RepeatTimer (const RepeatTimer&);
  34119. RepeatTimer& operator= (const RepeatTimer&);
  34120. };
  34121. Button::Button (const String& name)
  34122. : Component (name),
  34123. keySource (0),
  34124. text (name),
  34125. buttonPressTime (0),
  34126. lastTimeCallbackTime (0),
  34127. commandManagerToUse (0),
  34128. autoRepeatDelay (-1),
  34129. autoRepeatSpeed (0),
  34130. autoRepeatMinimumDelay (-1),
  34131. radioGroupId (0),
  34132. commandID (0),
  34133. connectedEdgeFlags (0),
  34134. buttonState (buttonNormal),
  34135. lastToggleState (false),
  34136. clickTogglesState (false),
  34137. needsToRelease (false),
  34138. needsRepainting (false),
  34139. isKeyDown (false),
  34140. triggerOnMouseDown (false),
  34141. generateTooltip (false)
  34142. {
  34143. setWantsKeyboardFocus (true);
  34144. isOn.addListener (this);
  34145. }
  34146. Button::~Button()
  34147. {
  34148. isOn.removeListener (this);
  34149. if (commandManagerToUse != 0)
  34150. commandManagerToUse->removeListener (this);
  34151. repeatTimer = 0;
  34152. clearShortcuts();
  34153. }
  34154. void Button::setButtonText (const String& newText)
  34155. {
  34156. if (text != newText)
  34157. {
  34158. text = newText;
  34159. repaint();
  34160. }
  34161. }
  34162. void Button::setTooltip (const String& newTooltip)
  34163. {
  34164. SettableTooltipClient::setTooltip (newTooltip);
  34165. generateTooltip = false;
  34166. }
  34167. const String Button::getTooltip()
  34168. {
  34169. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34170. {
  34171. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34172. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34173. for (int i = 0; i < keyPresses.size(); ++i)
  34174. {
  34175. const String key (keyPresses.getReference(i).getTextDescription());
  34176. tt << " [";
  34177. if (key.length() == 1)
  34178. tt << TRANS("shortcut") << ": '" << key << "']";
  34179. else
  34180. tt << key << ']';
  34181. }
  34182. return tt;
  34183. }
  34184. return SettableTooltipClient::getTooltip();
  34185. }
  34186. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  34187. {
  34188. if (connectedEdgeFlags != connectedEdgeFlags_)
  34189. {
  34190. connectedEdgeFlags = connectedEdgeFlags_;
  34191. repaint();
  34192. }
  34193. }
  34194. void Button::setToggleState (const bool shouldBeOn,
  34195. const bool sendChangeNotification)
  34196. {
  34197. if (shouldBeOn != lastToggleState)
  34198. {
  34199. const ComponentDeletionWatcher deletionWatcher (this);
  34200. isOn = shouldBeOn;
  34201. lastToggleState = shouldBeOn;
  34202. repaint();
  34203. if (sendChangeNotification)
  34204. sendClickMessage (ModifierKeys());
  34205. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34206. turnOffOtherButtonsInGroup (sendChangeNotification);
  34207. }
  34208. }
  34209. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34210. {
  34211. clickTogglesState = shouldToggle;
  34212. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34213. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34214. // it is that this button represents, and the button will update its state to reflect this
  34215. // in the applicationCommandListChanged() method.
  34216. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34217. }
  34218. bool Button::getClickingTogglesState() const throw()
  34219. {
  34220. return clickTogglesState;
  34221. }
  34222. void Button::valueChanged (Value& value)
  34223. {
  34224. if (value.refersToSameSourceAs (isOn))
  34225. setToggleState (isOn.getValue(), true);
  34226. }
  34227. void Button::setRadioGroupId (const int newGroupId)
  34228. {
  34229. if (radioGroupId != newGroupId)
  34230. {
  34231. radioGroupId = newGroupId;
  34232. if (lastToggleState)
  34233. turnOffOtherButtonsInGroup (true);
  34234. }
  34235. }
  34236. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34237. {
  34238. Component* const p = getParentComponent();
  34239. if (p != 0 && radioGroupId != 0)
  34240. {
  34241. const ComponentDeletionWatcher deletionWatcher (this);
  34242. for (int i = p->getNumChildComponents(); --i >= 0;)
  34243. {
  34244. Component* const c = p->getChildComponent (i);
  34245. if (c != this)
  34246. {
  34247. Button* const b = dynamic_cast <Button*> (c);
  34248. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34249. {
  34250. b->setToggleState (false, sendChangeNotification);
  34251. if (deletionWatcher.hasBeenDeleted())
  34252. return;
  34253. }
  34254. }
  34255. }
  34256. }
  34257. }
  34258. void Button::enablementChanged()
  34259. {
  34260. updateState (0);
  34261. repaint();
  34262. }
  34263. Button::ButtonState Button::updateState (const MouseEvent* const e)
  34264. {
  34265. ButtonState state = buttonNormal;
  34266. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34267. {
  34268. int mx, my;
  34269. if (e == 0)
  34270. {
  34271. getMouseXYRelative (mx, my);
  34272. }
  34273. else
  34274. {
  34275. const MouseEvent e2 (e->getEventRelativeTo (this));
  34276. mx = e2.x;
  34277. my = e2.y;
  34278. }
  34279. const bool over = reallyContains (mx, my, true);
  34280. const bool down = isMouseButtonDown();
  34281. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34282. state = buttonDown;
  34283. else if (over)
  34284. state = buttonOver;
  34285. }
  34286. setState (state);
  34287. return state;
  34288. }
  34289. void Button::setState (const ButtonState newState)
  34290. {
  34291. if (buttonState != newState)
  34292. {
  34293. buttonState = newState;
  34294. repaint();
  34295. if (buttonState == buttonDown)
  34296. {
  34297. buttonPressTime = Time::getApproximateMillisecondCounter();
  34298. lastTimeCallbackTime = buttonPressTime;
  34299. }
  34300. sendStateMessage();
  34301. }
  34302. }
  34303. bool Button::isDown() const throw()
  34304. {
  34305. return buttonState == buttonDown;
  34306. }
  34307. bool Button::isOver() const throw()
  34308. {
  34309. return buttonState != buttonNormal;
  34310. }
  34311. void Button::buttonStateChanged()
  34312. {
  34313. }
  34314. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34315. {
  34316. const uint32 now = Time::getApproximateMillisecondCounter();
  34317. return now > buttonPressTime ? now - buttonPressTime : 0;
  34318. }
  34319. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34320. {
  34321. triggerOnMouseDown = isTriggeredOnMouseDown;
  34322. }
  34323. void Button::clicked()
  34324. {
  34325. }
  34326. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34327. {
  34328. clicked();
  34329. }
  34330. static const int clickMessageId = 0x2f3f4f99;
  34331. void Button::triggerClick()
  34332. {
  34333. postCommandMessage (clickMessageId);
  34334. }
  34335. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34336. {
  34337. if (clickTogglesState)
  34338. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34339. sendClickMessage (modifiers);
  34340. }
  34341. void Button::flashButtonState()
  34342. {
  34343. if (isEnabled())
  34344. {
  34345. needsToRelease = true;
  34346. setState (buttonDown);
  34347. getRepeatTimer().startTimer (100);
  34348. }
  34349. }
  34350. void Button::handleCommandMessage (int commandId)
  34351. {
  34352. if (commandId == clickMessageId)
  34353. {
  34354. if (isEnabled())
  34355. {
  34356. flashButtonState();
  34357. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34358. }
  34359. }
  34360. else
  34361. {
  34362. Component::handleCommandMessage (commandId);
  34363. }
  34364. }
  34365. void Button::addButtonListener (ButtonListener* const newListener)
  34366. {
  34367. jassert (newListener != 0);
  34368. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34369. if (newListener != 0)
  34370. buttonListeners.add (newListener);
  34371. }
  34372. void Button::removeButtonListener (ButtonListener* const listener)
  34373. {
  34374. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34375. buttonListeners.removeValue (listener);
  34376. }
  34377. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34378. {
  34379. const ComponentDeletionWatcher cdw (this);
  34380. if (commandManagerToUse != 0 && commandID != 0)
  34381. {
  34382. ApplicationCommandTarget::InvocationInfo info (commandID);
  34383. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34384. info.originatingComponent = this;
  34385. commandManagerToUse->invoke (info, true);
  34386. }
  34387. clicked (modifiers);
  34388. if (! cdw.hasBeenDeleted())
  34389. {
  34390. for (int i = buttonListeners.size(); --i >= 0;)
  34391. {
  34392. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34393. if (bl != 0)
  34394. {
  34395. bl->buttonClicked (this);
  34396. if (cdw.hasBeenDeleted())
  34397. return;
  34398. }
  34399. }
  34400. }
  34401. }
  34402. void Button::sendStateMessage()
  34403. {
  34404. const ComponentDeletionWatcher cdw (this);
  34405. buttonStateChanged();
  34406. if (cdw.hasBeenDeleted())
  34407. return;
  34408. for (int i = buttonListeners.size(); --i >= 0;)
  34409. {
  34410. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34411. if (bl != 0)
  34412. {
  34413. bl->buttonStateChanged (this);
  34414. if (cdw.hasBeenDeleted())
  34415. return;
  34416. }
  34417. }
  34418. }
  34419. void Button::paint (Graphics& g)
  34420. {
  34421. if (needsToRelease && isEnabled())
  34422. {
  34423. needsToRelease = false;
  34424. needsRepainting = true;
  34425. }
  34426. paintButton (g, isOver(), isDown());
  34427. }
  34428. void Button::mouseEnter (const MouseEvent& e)
  34429. {
  34430. updateState (&e);
  34431. }
  34432. void Button::mouseExit (const MouseEvent& e)
  34433. {
  34434. updateState (&e);
  34435. }
  34436. void Button::mouseDown (const MouseEvent& e)
  34437. {
  34438. updateState (&e);
  34439. if (isDown())
  34440. {
  34441. if (autoRepeatDelay >= 0)
  34442. getRepeatTimer().startTimer (autoRepeatDelay);
  34443. if (triggerOnMouseDown)
  34444. internalClickCallback (e.mods);
  34445. }
  34446. }
  34447. void Button::mouseUp (const MouseEvent& e)
  34448. {
  34449. const bool wasDown = isDown();
  34450. updateState (&e);
  34451. if (wasDown && isOver() && ! triggerOnMouseDown)
  34452. internalClickCallback (e.mods);
  34453. }
  34454. void Button::mouseDrag (const MouseEvent& e)
  34455. {
  34456. const ButtonState oldState = buttonState;
  34457. updateState (&e);
  34458. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34459. getRepeatTimer().startTimer (autoRepeatSpeed);
  34460. }
  34461. void Button::focusGained (FocusChangeType)
  34462. {
  34463. updateState (0);
  34464. repaint();
  34465. }
  34466. void Button::focusLost (FocusChangeType)
  34467. {
  34468. updateState (0);
  34469. repaint();
  34470. }
  34471. void Button::setVisible (bool shouldBeVisible)
  34472. {
  34473. if (shouldBeVisible != isVisible())
  34474. {
  34475. Component::setVisible (shouldBeVisible);
  34476. if (! shouldBeVisible)
  34477. needsToRelease = false;
  34478. updateState (0);
  34479. }
  34480. else
  34481. {
  34482. Component::setVisible (shouldBeVisible);
  34483. }
  34484. }
  34485. void Button::parentHierarchyChanged()
  34486. {
  34487. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34488. if (newKeySource != keySource)
  34489. {
  34490. if (keySource->isValidComponent())
  34491. keySource->removeKeyListener (this);
  34492. keySource = newKeySource;
  34493. if (keySource->isValidComponent())
  34494. keySource->addKeyListener (this);
  34495. }
  34496. }
  34497. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34498. const int commandID_,
  34499. const bool generateTooltip_)
  34500. {
  34501. commandID = commandID_;
  34502. generateTooltip = generateTooltip_;
  34503. if (commandManagerToUse != commandManagerToUse_)
  34504. {
  34505. if (commandManagerToUse != 0)
  34506. commandManagerToUse->removeListener (this);
  34507. commandManagerToUse = commandManagerToUse_;
  34508. if (commandManagerToUse != 0)
  34509. commandManagerToUse->addListener (this);
  34510. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34511. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34512. // it is that this button represents, and the button will update its state to reflect this
  34513. // in the applicationCommandListChanged() method.
  34514. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34515. }
  34516. if (commandManagerToUse != 0)
  34517. applicationCommandListChanged();
  34518. else
  34519. setEnabled (true);
  34520. }
  34521. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34522. {
  34523. if (info.commandID == commandID
  34524. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34525. {
  34526. flashButtonState();
  34527. }
  34528. }
  34529. void Button::applicationCommandListChanged()
  34530. {
  34531. if (commandManagerToUse != 0)
  34532. {
  34533. ApplicationCommandInfo info (0);
  34534. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34535. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34536. if (target != 0)
  34537. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34538. }
  34539. }
  34540. void Button::addShortcut (const KeyPress& key)
  34541. {
  34542. if (key.isValid())
  34543. {
  34544. jassert (! isRegisteredForShortcut (key)); // already registered!
  34545. shortcuts.add (key);
  34546. parentHierarchyChanged();
  34547. }
  34548. }
  34549. void Button::clearShortcuts()
  34550. {
  34551. shortcuts.clear();
  34552. parentHierarchyChanged();
  34553. }
  34554. bool Button::isShortcutPressed() const
  34555. {
  34556. if (! isCurrentlyBlockedByAnotherModalComponent())
  34557. {
  34558. for (int i = shortcuts.size(); --i >= 0;)
  34559. if (shortcuts.getReference(i).isCurrentlyDown())
  34560. return true;
  34561. }
  34562. return false;
  34563. }
  34564. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34565. {
  34566. for (int i = shortcuts.size(); --i >= 0;)
  34567. if (key == shortcuts.getReference(i))
  34568. return true;
  34569. return false;
  34570. }
  34571. bool Button::keyStateChanged (const bool, Component*)
  34572. {
  34573. if (! isEnabled())
  34574. return false;
  34575. const bool wasDown = isKeyDown;
  34576. isKeyDown = isShortcutPressed();
  34577. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34578. getRepeatTimer().startTimer (autoRepeatDelay);
  34579. updateState (0);
  34580. if (isEnabled() && wasDown && ! isKeyDown)
  34581. {
  34582. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34583. // (return immediately - this button may now have been deleted)
  34584. return true;
  34585. }
  34586. return wasDown || isKeyDown;
  34587. }
  34588. bool Button::keyPressed (const KeyPress&, Component*)
  34589. {
  34590. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34591. return isShortcutPressed();
  34592. }
  34593. bool Button::keyPressed (const KeyPress& key)
  34594. {
  34595. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34596. {
  34597. triggerClick();
  34598. return true;
  34599. }
  34600. return false;
  34601. }
  34602. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34603. const int repeatMillisecs,
  34604. const int minimumDelayInMillisecs) throw()
  34605. {
  34606. autoRepeatDelay = initialDelayMillisecs;
  34607. autoRepeatSpeed = repeatMillisecs;
  34608. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34609. }
  34610. void Button::repeatTimerCallback()
  34611. {
  34612. if (needsRepainting)
  34613. {
  34614. getRepeatTimer().stopTimer();
  34615. updateState (0);
  34616. needsRepainting = false;
  34617. }
  34618. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34619. {
  34620. int repeatSpeed = autoRepeatSpeed;
  34621. if (autoRepeatMinimumDelay >= 0)
  34622. {
  34623. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34624. timeHeldDown *= timeHeldDown;
  34625. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34626. }
  34627. repeatSpeed = jmax (1, repeatSpeed);
  34628. getRepeatTimer().startTimer (repeatSpeed);
  34629. const uint32 now = Time::getApproximateMillisecondCounter();
  34630. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34631. lastTimeCallbackTime = now;
  34632. const ComponentDeletionWatcher cdw (this);
  34633. for (int i = numTimesToCallback; --i >= 0;)
  34634. {
  34635. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34636. if (cdw.hasBeenDeleted() || ! isDown())
  34637. return;
  34638. }
  34639. }
  34640. else if (! needsToRelease)
  34641. {
  34642. getRepeatTimer().stopTimer();
  34643. }
  34644. }
  34645. Button::RepeatTimer& Button::getRepeatTimer()
  34646. {
  34647. if (repeatTimer == 0)
  34648. repeatTimer = new RepeatTimer (*this);
  34649. return *repeatTimer;
  34650. }
  34651. END_JUCE_NAMESPACE
  34652. /*** End of inlined file: juce_Button.cpp ***/
  34653. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34654. BEGIN_JUCE_NAMESPACE
  34655. DrawableButton::DrawableButton (const String& name,
  34656. const DrawableButton::ButtonStyle buttonStyle)
  34657. : Button (name),
  34658. style (buttonStyle),
  34659. edgeIndent (3)
  34660. {
  34661. if (buttonStyle == ImageOnButtonBackground)
  34662. {
  34663. backgroundOff = Colour (0xffbbbbff);
  34664. backgroundOn = Colour (0xff3333ff);
  34665. }
  34666. else
  34667. {
  34668. backgroundOff = Colours::transparentBlack;
  34669. backgroundOn = Colour (0xaabbbbff);
  34670. }
  34671. }
  34672. DrawableButton::~DrawableButton()
  34673. {
  34674. deleteImages();
  34675. }
  34676. void DrawableButton::deleteImages()
  34677. {
  34678. }
  34679. void DrawableButton::setImages (const Drawable* normal,
  34680. const Drawable* over,
  34681. const Drawable* down,
  34682. const Drawable* disabled,
  34683. const Drawable* normalOn,
  34684. const Drawable* overOn,
  34685. const Drawable* downOn,
  34686. const Drawable* disabledOn)
  34687. {
  34688. deleteImages();
  34689. jassert (normal != 0); // you really need to give it at least a normal image..
  34690. if (normal != 0)
  34691. normalImage = normal->createCopy();
  34692. if (over != 0)
  34693. overImage = over->createCopy();
  34694. if (down != 0)
  34695. downImage = down->createCopy();
  34696. if (disabled != 0)
  34697. disabledImage = disabled->createCopy();
  34698. if (normalOn != 0)
  34699. normalImageOn = normalOn->createCopy();
  34700. if (overOn != 0)
  34701. overImageOn = overOn->createCopy();
  34702. if (downOn != 0)
  34703. downImageOn = downOn->createCopy();
  34704. if (disabledOn != 0)
  34705. disabledImageOn = disabledOn->createCopy();
  34706. repaint();
  34707. }
  34708. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34709. {
  34710. if (style != newStyle)
  34711. {
  34712. style = newStyle;
  34713. repaint();
  34714. }
  34715. }
  34716. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34717. const Colour& toggledOnColour)
  34718. {
  34719. if (backgroundOff != toggledOffColour
  34720. || backgroundOn != toggledOnColour)
  34721. {
  34722. backgroundOff = toggledOffColour;
  34723. backgroundOn = toggledOnColour;
  34724. repaint();
  34725. }
  34726. }
  34727. const Colour& DrawableButton::getBackgroundColour() const throw()
  34728. {
  34729. return getToggleState() ? backgroundOn
  34730. : backgroundOff;
  34731. }
  34732. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34733. {
  34734. edgeIndent = numPixelsIndent;
  34735. repaint();
  34736. }
  34737. void DrawableButton::paintButton (Graphics& g,
  34738. bool isMouseOverButton,
  34739. bool isButtonDown)
  34740. {
  34741. Rectangle<int> imageSpace;
  34742. if (style == ImageOnButtonBackground)
  34743. {
  34744. const int insetX = getWidth() / 4;
  34745. const int insetY = getHeight() / 4;
  34746. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34747. getLookAndFeel().drawButtonBackground (g, *this,
  34748. getBackgroundColour(),
  34749. isMouseOverButton,
  34750. isButtonDown);
  34751. }
  34752. else
  34753. {
  34754. g.fillAll (getBackgroundColour());
  34755. const int textH = (style == ImageAboveTextLabel)
  34756. ? jmin (16, proportionOfHeight (0.25f))
  34757. : 0;
  34758. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34759. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34760. imageSpace.setBounds (indentX, indentY,
  34761. getWidth() - indentX * 2,
  34762. getHeight() - indentY * 2 - textH);
  34763. if (textH > 0)
  34764. {
  34765. g.setFont ((float) textH);
  34766. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34767. g.drawFittedText (getButtonText(),
  34768. 2, getHeight() - textH - 1,
  34769. getWidth() - 4, textH,
  34770. Justification::centred, 1);
  34771. }
  34772. }
  34773. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34774. g.setOpacity (1.0f);
  34775. const Drawable* imageToDraw = 0;
  34776. if (isEnabled())
  34777. {
  34778. imageToDraw = getCurrentImage();
  34779. }
  34780. else
  34781. {
  34782. imageToDraw = getToggleState() ? disabledImageOn
  34783. : disabledImage;
  34784. if (imageToDraw == 0)
  34785. {
  34786. g.setOpacity (0.4f);
  34787. imageToDraw = getNormalImage();
  34788. }
  34789. }
  34790. if (imageToDraw != 0)
  34791. {
  34792. if (style == ImageRaw)
  34793. {
  34794. imageToDraw->draw (g, 1.0f);
  34795. }
  34796. else
  34797. {
  34798. imageToDraw->drawWithin (g,
  34799. imageSpace.getX(),
  34800. imageSpace.getY(),
  34801. imageSpace.getWidth(),
  34802. imageSpace.getHeight(),
  34803. RectanglePlacement::centred,
  34804. 1.0f);
  34805. }
  34806. }
  34807. }
  34808. const Drawable* DrawableButton::getCurrentImage() const throw()
  34809. {
  34810. if (isDown())
  34811. return getDownImage();
  34812. if (isOver())
  34813. return getOverImage();
  34814. return getNormalImage();
  34815. }
  34816. const Drawable* DrawableButton::getNormalImage() const throw()
  34817. {
  34818. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34819. : normalImage;
  34820. }
  34821. const Drawable* DrawableButton::getOverImage() const throw()
  34822. {
  34823. const Drawable* d = normalImage;
  34824. if (getToggleState())
  34825. {
  34826. if (overImageOn != 0)
  34827. d = overImageOn;
  34828. else if (normalImageOn != 0)
  34829. d = normalImageOn;
  34830. else if (overImage != 0)
  34831. d = overImage;
  34832. }
  34833. else
  34834. {
  34835. if (overImage != 0)
  34836. d = overImage;
  34837. }
  34838. return d;
  34839. }
  34840. const Drawable* DrawableButton::getDownImage() const throw()
  34841. {
  34842. const Drawable* d = normalImage;
  34843. if (getToggleState())
  34844. {
  34845. if (downImageOn != 0)
  34846. d = downImageOn;
  34847. else if (overImageOn != 0)
  34848. d = overImageOn;
  34849. else if (normalImageOn != 0)
  34850. d = normalImageOn;
  34851. else if (downImage != 0)
  34852. d = downImage;
  34853. else
  34854. d = getOverImage();
  34855. }
  34856. else
  34857. {
  34858. if (downImage != 0)
  34859. d = downImage;
  34860. else
  34861. d = getOverImage();
  34862. }
  34863. return d;
  34864. }
  34865. END_JUCE_NAMESPACE
  34866. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34867. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34868. BEGIN_JUCE_NAMESPACE
  34869. HyperlinkButton::HyperlinkButton (const String& linkText,
  34870. const URL& linkURL)
  34871. : Button (linkText),
  34872. url (linkURL),
  34873. font (14.0f, Font::underlined),
  34874. resizeFont (true),
  34875. justification (Justification::centred)
  34876. {
  34877. setMouseCursor (MouseCursor::PointingHandCursor);
  34878. setTooltip (linkURL.toString (false));
  34879. }
  34880. HyperlinkButton::~HyperlinkButton()
  34881. {
  34882. }
  34883. void HyperlinkButton::setFont (const Font& newFont,
  34884. const bool resizeToMatchComponentHeight,
  34885. const Justification& justificationType)
  34886. {
  34887. font = newFont;
  34888. resizeFont = resizeToMatchComponentHeight;
  34889. justification = justificationType;
  34890. repaint();
  34891. }
  34892. void HyperlinkButton::setURL (const URL& newURL) throw()
  34893. {
  34894. url = newURL;
  34895. setTooltip (newURL.toString (false));
  34896. }
  34897. const Font HyperlinkButton::getFontToUse() const
  34898. {
  34899. Font f (font);
  34900. if (resizeFont)
  34901. f.setHeight (getHeight() * 0.7f);
  34902. return f;
  34903. }
  34904. void HyperlinkButton::changeWidthToFitText()
  34905. {
  34906. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34907. }
  34908. void HyperlinkButton::colourChanged()
  34909. {
  34910. repaint();
  34911. }
  34912. void HyperlinkButton::clicked()
  34913. {
  34914. if (url.isWellFormed())
  34915. url.launchInDefaultBrowser();
  34916. }
  34917. void HyperlinkButton::paintButton (Graphics& g,
  34918. bool isMouseOverButton,
  34919. bool isButtonDown)
  34920. {
  34921. const Colour textColour (findColour (textColourId));
  34922. if (isEnabled())
  34923. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34924. : textColour);
  34925. else
  34926. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34927. g.setFont (getFontToUse());
  34928. g.drawText (getButtonText(),
  34929. 2, 0, getWidth() - 2, getHeight(),
  34930. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34931. true);
  34932. }
  34933. END_JUCE_NAMESPACE
  34934. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34935. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34936. BEGIN_JUCE_NAMESPACE
  34937. ImageButton::ImageButton (const String& text_)
  34938. : Button (text_),
  34939. scaleImageToFit (true),
  34940. preserveProportions (true),
  34941. alphaThreshold (0),
  34942. imageX (0),
  34943. imageY (0),
  34944. imageW (0),
  34945. imageH (0),
  34946. normalImage (0),
  34947. overImage (0),
  34948. downImage (0)
  34949. {
  34950. }
  34951. ImageButton::~ImageButton()
  34952. {
  34953. deleteImages();
  34954. }
  34955. void ImageButton::deleteImages()
  34956. {
  34957. ImageCache::releaseOrDelete (normalImage);
  34958. ImageCache::releaseOrDelete (overImage);
  34959. ImageCache::releaseOrDelete (downImage);
  34960. }
  34961. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34962. const bool rescaleImagesWhenButtonSizeChanges,
  34963. const bool preserveImageProportions,
  34964. Image* const normalImage_,
  34965. const float imageOpacityWhenNormal,
  34966. const Colour& overlayColourWhenNormal,
  34967. Image* const overImage_,
  34968. const float imageOpacityWhenOver,
  34969. const Colour& overlayColourWhenOver,
  34970. Image* const downImage_,
  34971. const float imageOpacityWhenDown,
  34972. const Colour& overlayColourWhenDown,
  34973. const float hitTestAlphaThreshold)
  34974. {
  34975. deleteImages();
  34976. normalImage = normalImage_;
  34977. overImage = overImage_;
  34978. downImage = downImage_;
  34979. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34980. {
  34981. imageW = normalImage->getWidth();
  34982. imageH = normalImage->getHeight();
  34983. setSize (imageW, imageH);
  34984. }
  34985. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34986. preserveProportions = preserveImageProportions;
  34987. normalOpacity = imageOpacityWhenNormal;
  34988. normalOverlay = overlayColourWhenNormal;
  34989. overOpacity = imageOpacityWhenOver;
  34990. overOverlay = overlayColourWhenOver;
  34991. downOpacity = imageOpacityWhenDown;
  34992. downOverlay = overlayColourWhenDown;
  34993. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34994. repaint();
  34995. }
  34996. Image* ImageButton::getCurrentImage() const
  34997. {
  34998. if (isDown() || getToggleState())
  34999. return getDownImage();
  35000. if (isOver())
  35001. return getOverImage();
  35002. return getNormalImage();
  35003. }
  35004. Image* ImageButton::getNormalImage() const throw()
  35005. {
  35006. return normalImage;
  35007. }
  35008. Image* ImageButton::getOverImage() const throw()
  35009. {
  35010. return (overImage != 0) ? overImage
  35011. : normalImage;
  35012. }
  35013. Image* ImageButton::getDownImage() const throw()
  35014. {
  35015. return (downImage != 0) ? downImage
  35016. : getOverImage();
  35017. }
  35018. void ImageButton::paintButton (Graphics& g,
  35019. bool isMouseOverButton,
  35020. bool isButtonDown)
  35021. {
  35022. if (! isEnabled())
  35023. {
  35024. isMouseOverButton = false;
  35025. isButtonDown = false;
  35026. }
  35027. Image* const im = getCurrentImage();
  35028. if (im != 0)
  35029. {
  35030. const int iw = im->getWidth();
  35031. const int ih = im->getHeight();
  35032. imageW = getWidth();
  35033. imageH = getHeight();
  35034. imageX = (imageW - iw) >> 1;
  35035. imageY = (imageH - ih) >> 1;
  35036. if (scaleImageToFit)
  35037. {
  35038. if (preserveProportions)
  35039. {
  35040. int newW, newH;
  35041. const float imRatio = ih / (float)iw;
  35042. const float destRatio = imageH / (float)imageW;
  35043. if (imRatio > destRatio)
  35044. {
  35045. newW = roundToInt (imageH / imRatio);
  35046. newH = imageH;
  35047. }
  35048. else
  35049. {
  35050. newW = imageW;
  35051. newH = roundToInt (imageW * imRatio);
  35052. }
  35053. imageX = (imageW - newW) / 2;
  35054. imageY = (imageH - newH) / 2;
  35055. imageW = newW;
  35056. imageH = newH;
  35057. }
  35058. else
  35059. {
  35060. imageX = 0;
  35061. imageY = 0;
  35062. }
  35063. }
  35064. if (! scaleImageToFit)
  35065. {
  35066. imageW = iw;
  35067. imageH = ih;
  35068. }
  35069. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  35070. isButtonDown ? downOverlay
  35071. : (isMouseOverButton ? overOverlay
  35072. : normalOverlay),
  35073. isButtonDown ? downOpacity
  35074. : (isMouseOverButton ? overOpacity
  35075. : normalOpacity),
  35076. *this);
  35077. }
  35078. }
  35079. bool ImageButton::hitTest (int x, int y)
  35080. {
  35081. if (alphaThreshold == 0)
  35082. return true;
  35083. Image* const im = getCurrentImage();
  35084. return im == 0
  35085. || (imageW > 0 && imageH > 0
  35086. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  35087. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  35088. }
  35089. END_JUCE_NAMESPACE
  35090. /*** End of inlined file: juce_ImageButton.cpp ***/
  35091. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  35092. BEGIN_JUCE_NAMESPACE
  35093. ShapeButton::ShapeButton (const String& text_,
  35094. const Colour& normalColour_,
  35095. const Colour& overColour_,
  35096. const Colour& downColour_)
  35097. : Button (text_),
  35098. normalColour (normalColour_),
  35099. overColour (overColour_),
  35100. downColour (downColour_),
  35101. maintainShapeProportions (false),
  35102. outlineWidth (0.0f)
  35103. {
  35104. }
  35105. ShapeButton::~ShapeButton()
  35106. {
  35107. }
  35108. void ShapeButton::setColours (const Colour& newNormalColour,
  35109. const Colour& newOverColour,
  35110. const Colour& newDownColour)
  35111. {
  35112. normalColour = newNormalColour;
  35113. overColour = newOverColour;
  35114. downColour = newDownColour;
  35115. }
  35116. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35117. const float newOutlineWidth)
  35118. {
  35119. outlineColour = newOutlineColour;
  35120. outlineWidth = newOutlineWidth;
  35121. }
  35122. void ShapeButton::setShape (const Path& newShape,
  35123. const bool resizeNowToFitThisShape,
  35124. const bool maintainShapeProportions_,
  35125. const bool hasShadow)
  35126. {
  35127. shape = newShape;
  35128. maintainShapeProportions = maintainShapeProportions_;
  35129. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35130. setComponentEffect ((hasShadow) ? &shadow : 0);
  35131. if (resizeNowToFitThisShape)
  35132. {
  35133. Rectangle<float> bounds (shape.getBounds());
  35134. if (hasShadow)
  35135. bounds.expand (4.0f, 4.0f);
  35136. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  35137. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  35138. 1 + (int) (bounds.getHeight() + outlineWidth));
  35139. }
  35140. }
  35141. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35142. {
  35143. if (! isEnabled())
  35144. {
  35145. isMouseOverButton = false;
  35146. isButtonDown = false;
  35147. }
  35148. g.setColour ((isButtonDown) ? downColour
  35149. : (isMouseOverButton) ? overColour
  35150. : normalColour);
  35151. int w = getWidth();
  35152. int h = getHeight();
  35153. if (getComponentEffect() != 0)
  35154. {
  35155. w -= 4;
  35156. h -= 4;
  35157. }
  35158. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35159. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35160. w - offset - outlineWidth,
  35161. h - offset - outlineWidth,
  35162. maintainShapeProportions));
  35163. g.fillPath (shape, trans);
  35164. if (outlineWidth > 0.0f)
  35165. {
  35166. g.setColour (outlineColour);
  35167. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35168. }
  35169. }
  35170. END_JUCE_NAMESPACE
  35171. /*** End of inlined file: juce_ShapeButton.cpp ***/
  35172. /*** Start of inlined file: juce_TextButton.cpp ***/
  35173. BEGIN_JUCE_NAMESPACE
  35174. TextButton::TextButton (const String& name,
  35175. const String& toolTip)
  35176. : Button (name)
  35177. {
  35178. setTooltip (toolTip);
  35179. }
  35180. TextButton::~TextButton()
  35181. {
  35182. }
  35183. void TextButton::paintButton (Graphics& g,
  35184. bool isMouseOverButton,
  35185. bool isButtonDown)
  35186. {
  35187. getLookAndFeel().drawButtonBackground (g, *this,
  35188. findColour (getToggleState() ? buttonOnColourId
  35189. : buttonColourId),
  35190. isMouseOverButton,
  35191. isButtonDown);
  35192. getLookAndFeel().drawButtonText (g, *this,
  35193. isMouseOverButton,
  35194. isButtonDown);
  35195. }
  35196. void TextButton::colourChanged()
  35197. {
  35198. repaint();
  35199. }
  35200. const Font TextButton::getFont()
  35201. {
  35202. return Font (jmin (15.0f, getHeight() * 0.6f));
  35203. }
  35204. void TextButton::changeWidthToFitText (const int newHeight)
  35205. {
  35206. if (newHeight >= 0)
  35207. setSize (jmax (1, getWidth()), newHeight);
  35208. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35209. getHeight());
  35210. }
  35211. END_JUCE_NAMESPACE
  35212. /*** End of inlined file: juce_TextButton.cpp ***/
  35213. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  35214. BEGIN_JUCE_NAMESPACE
  35215. ToggleButton::ToggleButton (const String& buttonText)
  35216. : Button (buttonText)
  35217. {
  35218. setClickingTogglesState (true);
  35219. }
  35220. ToggleButton::~ToggleButton()
  35221. {
  35222. }
  35223. void ToggleButton::paintButton (Graphics& g,
  35224. bool isMouseOverButton,
  35225. bool isButtonDown)
  35226. {
  35227. getLookAndFeel().drawToggleButton (g, *this,
  35228. isMouseOverButton,
  35229. isButtonDown);
  35230. }
  35231. void ToggleButton::changeWidthToFitText()
  35232. {
  35233. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35234. }
  35235. void ToggleButton::colourChanged()
  35236. {
  35237. repaint();
  35238. }
  35239. END_JUCE_NAMESPACE
  35240. /*** End of inlined file: juce_ToggleButton.cpp ***/
  35241. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  35242. BEGIN_JUCE_NAMESPACE
  35243. ToolbarButton::ToolbarButton (const int itemId_,
  35244. const String& buttonText,
  35245. Drawable* const normalImage_,
  35246. Drawable* const toggledOnImage_)
  35247. : ToolbarItemComponent (itemId_, buttonText, true),
  35248. normalImage (normalImage_),
  35249. toggledOnImage (toggledOnImage_)
  35250. {
  35251. }
  35252. ToolbarButton::~ToolbarButton()
  35253. {
  35254. }
  35255. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35256. bool /*isToolbarVertical*/,
  35257. int& preferredSize,
  35258. int& minSize, int& maxSize)
  35259. {
  35260. preferredSize = minSize = maxSize = toolbarDepth;
  35261. return true;
  35262. }
  35263. void ToolbarButton::paintButtonArea (Graphics& g,
  35264. int width, int height,
  35265. bool /*isMouseOver*/,
  35266. bool /*isMouseDown*/)
  35267. {
  35268. Drawable* d = normalImage;
  35269. if (getToggleState() && toggledOnImage != 0)
  35270. d = toggledOnImage;
  35271. if (! isEnabled())
  35272. {
  35273. Image im (Image::ARGB, width, height, true);
  35274. Graphics g2 (im);
  35275. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35276. im.desaturate();
  35277. g.drawImageAt (&im, 0, 0);
  35278. }
  35279. else
  35280. {
  35281. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35282. }
  35283. }
  35284. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  35285. {
  35286. }
  35287. END_JUCE_NAMESPACE
  35288. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  35289. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  35290. BEGIN_JUCE_NAMESPACE
  35291. class CodeDocumentLine
  35292. {
  35293. public:
  35294. CodeDocumentLine (const tchar* const line_,
  35295. const int lineLength_,
  35296. const int numNewLineChars,
  35297. const int lineStartInFile_)
  35298. : line (line_, lineLength_),
  35299. lineStartInFile (lineStartInFile_),
  35300. lineLength (lineLength_),
  35301. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  35302. {
  35303. }
  35304. ~CodeDocumentLine()
  35305. {
  35306. }
  35307. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  35308. {
  35309. const tchar* const t = (const tchar*) text;
  35310. int pos = 0;
  35311. while (t [pos] != 0)
  35312. {
  35313. const int startOfLine = pos;
  35314. int numNewLineChars = 0;
  35315. while (t[pos] != 0)
  35316. {
  35317. if (t[pos] == T('\r'))
  35318. {
  35319. ++numNewLineChars;
  35320. ++pos;
  35321. if (t[pos] == T('\n'))
  35322. {
  35323. ++numNewLineChars;
  35324. ++pos;
  35325. }
  35326. break;
  35327. }
  35328. if (t[pos] == T('\n'))
  35329. {
  35330. ++numNewLineChars;
  35331. ++pos;
  35332. break;
  35333. }
  35334. ++pos;
  35335. }
  35336. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  35337. numNewLineChars, startOfLine));
  35338. }
  35339. jassert (pos == text.length());
  35340. }
  35341. bool endsWithLineBreak() const throw()
  35342. {
  35343. return lineLengthWithoutNewLines != lineLength;
  35344. }
  35345. void updateLength() throw()
  35346. {
  35347. lineLengthWithoutNewLines = lineLength = line.length();
  35348. while (lineLengthWithoutNewLines > 0
  35349. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35350. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35351. {
  35352. --lineLengthWithoutNewLines;
  35353. }
  35354. }
  35355. String line;
  35356. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35357. };
  35358. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  35359. : document (document_),
  35360. currentLine (document_->lines[0]),
  35361. line (0),
  35362. position (0)
  35363. {
  35364. }
  35365. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35366. : document (other.document),
  35367. currentLine (other.currentLine),
  35368. line (other.line),
  35369. position (other.position)
  35370. {
  35371. }
  35372. const CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35373. {
  35374. document = other.document;
  35375. currentLine = other.currentLine;
  35376. line = other.line;
  35377. position = other.position;
  35378. return *this;
  35379. }
  35380. CodeDocument::Iterator::~Iterator() throw()
  35381. {
  35382. }
  35383. juce_wchar CodeDocument::Iterator::nextChar()
  35384. {
  35385. if (currentLine == 0)
  35386. return 0;
  35387. jassert (currentLine == document->lines.getUnchecked (line));
  35388. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35389. skip();
  35390. return result;
  35391. }
  35392. void CodeDocument::Iterator::skip()
  35393. {
  35394. if (currentLine != 0)
  35395. {
  35396. jassert (currentLine == document->lines.getUnchecked (line));
  35397. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35398. {
  35399. ++line;
  35400. currentLine = document->lines [line];
  35401. }
  35402. }
  35403. }
  35404. void CodeDocument::Iterator::skipToEndOfLine()
  35405. {
  35406. if (currentLine != 0)
  35407. {
  35408. jassert (currentLine == document->lines.getUnchecked (line));
  35409. ++line;
  35410. currentLine = document->lines [line];
  35411. if (currentLine != 0)
  35412. position = currentLine->lineStartInFile;
  35413. }
  35414. }
  35415. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35416. {
  35417. if (currentLine == 0)
  35418. return 0;
  35419. jassert (currentLine == document->lines.getUnchecked (line));
  35420. return currentLine->line [position - currentLine->lineStartInFile];
  35421. }
  35422. void CodeDocument::Iterator::skipWhitespace()
  35423. {
  35424. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35425. skip();
  35426. }
  35427. bool CodeDocument::Iterator::isEOF() const throw()
  35428. {
  35429. return currentLine == 0;
  35430. }
  35431. CodeDocument::Position::Position() throw()
  35432. : owner (0), characterPos (0), line (0),
  35433. indexInLine (0), positionMaintained (false)
  35434. {
  35435. }
  35436. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35437. const int line_, const int indexInLine_) throw()
  35438. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35439. characterPos (0), line (line_),
  35440. indexInLine (indexInLine_), positionMaintained (false)
  35441. {
  35442. setLineAndIndex (line_, indexInLine_);
  35443. }
  35444. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35445. const int characterPos_) throw()
  35446. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35447. positionMaintained (false)
  35448. {
  35449. setPosition (characterPos_);
  35450. }
  35451. CodeDocument::Position::Position (const Position& other) throw()
  35452. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35453. indexInLine (other.indexInLine), positionMaintained (false)
  35454. {
  35455. jassert (*this == other);
  35456. }
  35457. CodeDocument::Position::~Position() throw()
  35458. {
  35459. setPositionMaintained (false);
  35460. }
  35461. const CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35462. {
  35463. if (this != &other)
  35464. {
  35465. const bool wasPositionMaintained = positionMaintained;
  35466. if (owner != other.owner)
  35467. setPositionMaintained (false);
  35468. owner = other.owner;
  35469. line = other.line;
  35470. indexInLine = other.indexInLine;
  35471. characterPos = other.characterPos;
  35472. setPositionMaintained (wasPositionMaintained);
  35473. jassert (*this == other);
  35474. }
  35475. return *this;
  35476. }
  35477. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35478. {
  35479. jassert ((characterPos == other.characterPos)
  35480. == (line == other.line && indexInLine == other.indexInLine));
  35481. return characterPos == other.characterPos
  35482. && line == other.line
  35483. && indexInLine == other.indexInLine
  35484. && owner == other.owner;
  35485. }
  35486. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35487. {
  35488. return ! operator== (other);
  35489. }
  35490. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35491. {
  35492. jassert (owner != 0);
  35493. if (owner->lines.size() == 0)
  35494. {
  35495. line = 0;
  35496. indexInLine = 0;
  35497. characterPos = 0;
  35498. }
  35499. else
  35500. {
  35501. if (newLine >= owner->lines.size())
  35502. {
  35503. line = owner->lines.size() - 1;
  35504. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35505. jassert (l != 0);
  35506. indexInLine = l->lineLengthWithoutNewLines;
  35507. characterPos = l->lineStartInFile + indexInLine;
  35508. }
  35509. else
  35510. {
  35511. line = jmax (0, newLine);
  35512. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35513. jassert (l != 0);
  35514. if (l->lineLengthWithoutNewLines > 0)
  35515. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35516. else
  35517. indexInLine = 0;
  35518. characterPos = l->lineStartInFile + indexInLine;
  35519. }
  35520. }
  35521. }
  35522. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35523. {
  35524. jassert (owner != 0);
  35525. line = 0;
  35526. indexInLine = 0;
  35527. characterPos = 0;
  35528. if (newPosition > 0)
  35529. {
  35530. int lineStart = 0;
  35531. int lineEnd = owner->lines.size();
  35532. for (;;)
  35533. {
  35534. if (lineEnd - lineStart < 4)
  35535. {
  35536. for (int i = lineStart; i < lineEnd; ++i)
  35537. {
  35538. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35539. int index = newPosition - l->lineStartInFile;
  35540. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35541. {
  35542. line = i;
  35543. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35544. characterPos = l->lineStartInFile + indexInLine;
  35545. }
  35546. }
  35547. break;
  35548. }
  35549. else
  35550. {
  35551. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35552. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35553. if (newPosition >= mid->lineStartInFile)
  35554. lineStart = midIndex;
  35555. else
  35556. lineEnd = midIndex;
  35557. }
  35558. }
  35559. }
  35560. }
  35561. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35562. {
  35563. jassert (owner != 0);
  35564. if (characterDelta == 1)
  35565. {
  35566. setPosition (getPosition());
  35567. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35568. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35569. if (indexInLine + characterDelta < l->lineLength
  35570. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35571. ++characterDelta;
  35572. }
  35573. setPosition (characterPos + characterDelta);
  35574. }
  35575. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35576. {
  35577. CodeDocument::Position p (*this);
  35578. p.moveBy (characterDelta);
  35579. return p;
  35580. }
  35581. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35582. {
  35583. CodeDocument::Position p (*this);
  35584. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35585. return p;
  35586. }
  35587. const tchar CodeDocument::Position::getCharacter() const throw()
  35588. {
  35589. const CodeDocumentLine* const l = owner->lines [line];
  35590. return l == 0 ? 0 : l->line [getIndexInLine()];
  35591. }
  35592. const String CodeDocument::Position::getLineText() const throw()
  35593. {
  35594. const CodeDocumentLine* const l = owner->lines [line];
  35595. return l == 0 ? String::empty : l->line;
  35596. }
  35597. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35598. {
  35599. if (isMaintained != positionMaintained)
  35600. {
  35601. positionMaintained = isMaintained;
  35602. if (owner != 0)
  35603. {
  35604. if (isMaintained)
  35605. {
  35606. jassert (! owner->positionsToMaintain.contains (this));
  35607. owner->positionsToMaintain.add (this);
  35608. }
  35609. else
  35610. {
  35611. jassert (owner->positionsToMaintain.contains (this));
  35612. owner->positionsToMaintain.removeValue (this);
  35613. }
  35614. }
  35615. }
  35616. }
  35617. CodeDocument::CodeDocument()
  35618. : undoManager (std::numeric_limits<int>::max(), 10000),
  35619. currentActionIndex (0),
  35620. indexOfSavedState (-1),
  35621. maximumLineLength (-1),
  35622. newLineChars ("\r\n")
  35623. {
  35624. }
  35625. CodeDocument::~CodeDocument()
  35626. {
  35627. }
  35628. const String CodeDocument::getAllContent() const throw()
  35629. {
  35630. return getTextBetween (Position (this, 0),
  35631. Position (this, lines.size(), 0));
  35632. }
  35633. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35634. {
  35635. if (end.getPosition() <= start.getPosition())
  35636. return String::empty;
  35637. const int startLine = start.getLineNumber();
  35638. const int endLine = end.getLineNumber();
  35639. if (startLine == endLine)
  35640. {
  35641. CodeDocumentLine* const line = lines [startLine];
  35642. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35643. }
  35644. String result;
  35645. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35646. String::Concatenator concatenator (result);
  35647. const int maxLine = jmin (lines.size() - 1, endLine);
  35648. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35649. {
  35650. const CodeDocumentLine* line = lines.getUnchecked(i);
  35651. int len = line->lineLength;
  35652. if (i == startLine)
  35653. {
  35654. const int index = start.getIndexInLine();
  35655. concatenator.append (line->line.substring (index, len));
  35656. }
  35657. else if (i == endLine)
  35658. {
  35659. len = end.getIndexInLine();
  35660. concatenator.append (line->line.substring (0, len));
  35661. }
  35662. else
  35663. {
  35664. concatenator.append (line->line);
  35665. }
  35666. }
  35667. return result;
  35668. }
  35669. int CodeDocument::getNumCharacters() const throw()
  35670. {
  35671. const CodeDocumentLine* const lastLine = lines.getLast();
  35672. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35673. }
  35674. const String CodeDocument::getLine (const int lineIndex) const throw()
  35675. {
  35676. const CodeDocumentLine* const line = lines [lineIndex];
  35677. return (line == 0) ? String::empty : line->line;
  35678. }
  35679. int CodeDocument::getMaximumLineLength() throw()
  35680. {
  35681. if (maximumLineLength < 0)
  35682. {
  35683. maximumLineLength = 0;
  35684. for (int i = lines.size(); --i >= 0;)
  35685. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35686. }
  35687. return maximumLineLength;
  35688. }
  35689. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35690. {
  35691. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35692. }
  35693. void CodeDocument::insertText (const Position& position, const String& text)
  35694. {
  35695. insert (text, position.getPosition(), true);
  35696. }
  35697. void CodeDocument::replaceAllContent (const String& newContent)
  35698. {
  35699. remove (0, getNumCharacters(), true);
  35700. insert (newContent, 0, true);
  35701. }
  35702. bool CodeDocument::loadFromStream (InputStream& stream)
  35703. {
  35704. replaceAllContent (stream.readEntireStreamAsString());
  35705. setSavePoint();
  35706. clearUndoHistory();
  35707. return true;
  35708. }
  35709. bool CodeDocument::writeToStream (OutputStream& stream)
  35710. {
  35711. for (int i = 0; i < lines.size(); ++i)
  35712. {
  35713. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35714. const char* utf8 = temp.toUTF8();
  35715. if (! stream.write (utf8, (int) strlen (utf8)))
  35716. return false;
  35717. }
  35718. return true;
  35719. }
  35720. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35721. {
  35722. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35723. newLineChars = newLine;
  35724. }
  35725. void CodeDocument::newTransaction()
  35726. {
  35727. undoManager.beginNewTransaction (String::empty);
  35728. }
  35729. void CodeDocument::undo()
  35730. {
  35731. newTransaction();
  35732. undoManager.undo();
  35733. }
  35734. void CodeDocument::redo()
  35735. {
  35736. undoManager.redo();
  35737. }
  35738. void CodeDocument::clearUndoHistory()
  35739. {
  35740. undoManager.clearUndoHistory();
  35741. }
  35742. void CodeDocument::setSavePoint() throw()
  35743. {
  35744. indexOfSavedState = currentActionIndex;
  35745. }
  35746. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35747. {
  35748. return currentActionIndex != indexOfSavedState;
  35749. }
  35750. static int getCodeCharacterCategory (const tchar character) throw()
  35751. {
  35752. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35753. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35754. }
  35755. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35756. {
  35757. Position p (position);
  35758. const int maxDistance = 256;
  35759. int i = 0;
  35760. while (i < maxDistance
  35761. && CharacterFunctions::isWhitespace (p.getCharacter())
  35762. && (i == 0 || (p.getCharacter() != T('\n')
  35763. && p.getCharacter() != T('\r'))))
  35764. {
  35765. ++i;
  35766. p.moveBy (1);
  35767. }
  35768. if (i == 0)
  35769. {
  35770. const int type = getCodeCharacterCategory (p.getCharacter());
  35771. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35772. {
  35773. ++i;
  35774. p.moveBy (1);
  35775. }
  35776. while (i < maxDistance
  35777. && CharacterFunctions::isWhitespace (p.getCharacter())
  35778. && (i == 0 || (p.getCharacter() != T('\n')
  35779. && p.getCharacter() != T('\r'))))
  35780. {
  35781. ++i;
  35782. p.moveBy (1);
  35783. }
  35784. }
  35785. return p;
  35786. }
  35787. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35788. {
  35789. Position p (position);
  35790. const int maxDistance = 256;
  35791. int i = 0;
  35792. bool stoppedAtLineStart = false;
  35793. while (i < maxDistance)
  35794. {
  35795. const tchar c = p.movedBy (-1).getCharacter();
  35796. if (c == T('\r') || c == T('\n'))
  35797. {
  35798. stoppedAtLineStart = true;
  35799. if (i > 0)
  35800. break;
  35801. }
  35802. if (! CharacterFunctions::isWhitespace (c))
  35803. break;
  35804. p.moveBy (-1);
  35805. ++i;
  35806. }
  35807. if (i < maxDistance && ! stoppedAtLineStart)
  35808. {
  35809. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35810. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35811. {
  35812. p.moveBy (-1);
  35813. ++i;
  35814. }
  35815. }
  35816. return p;
  35817. }
  35818. void CodeDocument::checkLastLineStatus()
  35819. {
  35820. while (lines.size() > 0
  35821. && lines.getLast()->lineLength == 0
  35822. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35823. {
  35824. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35825. lines.removeLast();
  35826. }
  35827. const CodeDocumentLine* const lastLine = lines.getLast();
  35828. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35829. {
  35830. // check that there's an empty line at the end if the preceding one ends in a newline..
  35831. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35832. }
  35833. }
  35834. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35835. {
  35836. listeners.addIfNotAlreadyThere (listener);
  35837. }
  35838. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35839. {
  35840. listeners.removeValue (listener);
  35841. }
  35842. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35843. {
  35844. const Position startPos (this, startLine, 0);
  35845. const Position endPos (this, endLine, 0);
  35846. for (int i = listeners.size(); --i >= 0;)
  35847. {
  35848. Listener* const l = (Listener*) listeners[i];
  35849. if (l != 0)
  35850. l->codeDocumentChanged (startPos, endPos);
  35851. }
  35852. }
  35853. class CodeDocumentInsertAction : public UndoableAction
  35854. {
  35855. CodeDocument& owner;
  35856. const String text;
  35857. int insertPos;
  35858. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35859. const CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35860. public:
  35861. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35862. : owner (owner_),
  35863. text (text_),
  35864. insertPos (insertPos_)
  35865. {
  35866. }
  35867. ~CodeDocumentInsertAction() {}
  35868. bool perform()
  35869. {
  35870. owner.currentActionIndex++;
  35871. owner.insert (text, insertPos, false);
  35872. return true;
  35873. }
  35874. bool undo()
  35875. {
  35876. owner.currentActionIndex--;
  35877. owner.remove (insertPos, insertPos + text.length(), false);
  35878. return true;
  35879. }
  35880. int getSizeInUnits() { return text.length() + 32; }
  35881. };
  35882. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35883. {
  35884. if (text.isEmpty())
  35885. return;
  35886. if (undoable)
  35887. {
  35888. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35889. }
  35890. else
  35891. {
  35892. Position pos (this, insertPos);
  35893. const int firstAffectedLine = pos.getLineNumber();
  35894. int lastAffectedLine = firstAffectedLine + 1;
  35895. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35896. String textInsideOriginalLine (text);
  35897. if (firstLine != 0)
  35898. {
  35899. const int index = pos.getIndexInLine();
  35900. textInsideOriginalLine = firstLine->line.substring (0, index)
  35901. + textInsideOriginalLine
  35902. + firstLine->line.substring (index);
  35903. }
  35904. maximumLineLength = -1;
  35905. Array <CodeDocumentLine*> newLines;
  35906. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35907. jassert (newLines.size() > 0);
  35908. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35909. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35910. lines.set (firstAffectedLine, newFirstLine);
  35911. if (newLines.size() > 1)
  35912. {
  35913. for (int i = 1; i < newLines.size(); ++i)
  35914. {
  35915. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35916. lines.insert (firstAffectedLine + i, l);
  35917. }
  35918. lastAffectedLine = lines.size();
  35919. }
  35920. int i, lineStart = newFirstLine->lineStartInFile;
  35921. for (i = firstAffectedLine; i < lines.size(); ++i)
  35922. {
  35923. CodeDocumentLine* const l = lines.getUnchecked (i);
  35924. l->lineStartInFile = lineStart;
  35925. lineStart += l->lineLength;
  35926. }
  35927. checkLastLineStatus();
  35928. const int newTextLength = text.length();
  35929. for (i = 0; i < positionsToMaintain.size(); ++i)
  35930. {
  35931. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35932. if (p->getPosition() >= insertPos)
  35933. p->setPosition (p->getPosition() + newTextLength);
  35934. }
  35935. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35936. }
  35937. }
  35938. class CodeDocumentDeleteAction : public UndoableAction
  35939. {
  35940. CodeDocument& owner;
  35941. int startPos, endPos;
  35942. String removedText;
  35943. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35944. const CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35945. public:
  35946. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35947. : owner (owner_),
  35948. startPos (startPos_),
  35949. endPos (endPos_)
  35950. {
  35951. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35952. CodeDocument::Position (&owner, endPos));
  35953. }
  35954. ~CodeDocumentDeleteAction() {}
  35955. bool perform()
  35956. {
  35957. owner.currentActionIndex++;
  35958. owner.remove (startPos, endPos, false);
  35959. return true;
  35960. }
  35961. bool undo()
  35962. {
  35963. owner.currentActionIndex--;
  35964. owner.insert (removedText, startPos, false);
  35965. return true;
  35966. }
  35967. int getSizeInUnits() { return removedText.length() + 32; }
  35968. };
  35969. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35970. {
  35971. if (endPos <= startPos)
  35972. return;
  35973. if (undoable)
  35974. {
  35975. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35976. }
  35977. else
  35978. {
  35979. Position startPosition (this, startPos);
  35980. Position endPosition (this, endPos);
  35981. maximumLineLength = -1;
  35982. const int firstAffectedLine = startPosition.getLineNumber();
  35983. const int endLine = endPosition.getLineNumber();
  35984. int lastAffectedLine = firstAffectedLine + 1;
  35985. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35986. if (firstAffectedLine == endLine)
  35987. {
  35988. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35989. + firstLine->line.substring (endPosition.getIndexInLine());
  35990. firstLine->updateLength();
  35991. }
  35992. else
  35993. {
  35994. lastAffectedLine = lines.size();
  35995. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35996. jassert (lastLine != 0);
  35997. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35998. + lastLine->line.substring (endPosition.getIndexInLine());
  35999. firstLine->updateLength();
  36000. int numLinesToRemove = endLine - firstAffectedLine;
  36001. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  36002. }
  36003. int i;
  36004. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  36005. {
  36006. CodeDocumentLine* const l = lines.getUnchecked (i);
  36007. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  36008. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  36009. }
  36010. checkLastLineStatus();
  36011. const int totalChars = getNumCharacters();
  36012. for (i = 0; i < positionsToMaintain.size(); ++i)
  36013. {
  36014. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  36015. if (p->getPosition() > startPosition.getPosition())
  36016. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  36017. if (p->getPosition() > totalChars)
  36018. p->setPosition (totalChars);
  36019. }
  36020. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  36021. }
  36022. }
  36023. END_JUCE_NAMESPACE
  36024. /*** End of inlined file: juce_CodeDocument.cpp ***/
  36025. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  36026. BEGIN_JUCE_NAMESPACE
  36027. class CaretComponent : public Component,
  36028. public Timer
  36029. {
  36030. public:
  36031. CaretComponent()
  36032. {
  36033. setAlwaysOnTop (true);
  36034. setInterceptsMouseClicks (false, false);
  36035. }
  36036. ~CaretComponent()
  36037. {
  36038. }
  36039. void paint (Graphics& g)
  36040. {
  36041. if (getParentComponent()->hasKeyboardFocus (true))
  36042. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  36043. }
  36044. void timerCallback()
  36045. {
  36046. setVisible (! isVisible());
  36047. }
  36048. void updatePosition (CodeEditorComponent& owner)
  36049. {
  36050. startTimer (400);
  36051. setVisible (true);
  36052. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  36053. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  36054. }
  36055. };
  36056. class CodeEditorComponent::CodeEditorLine
  36057. {
  36058. public:
  36059. CodeEditorLine() throw()
  36060. {
  36061. }
  36062. ~CodeEditorLine() throw()
  36063. {
  36064. }
  36065. bool update (CodeDocument& document, int lineNum,
  36066. CodeDocument::Iterator& source,
  36067. CodeTokeniser* analyser, const int spacesPerTab,
  36068. const CodeDocument::Position& selectionStart,
  36069. const CodeDocument::Position& selectionEnd)
  36070. {
  36071. Array <SyntaxToken> newTokens;
  36072. newTokens.ensureStorageAllocated (8);
  36073. if (analyser == 0)
  36074. {
  36075. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  36076. }
  36077. else if (lineNum < document.getNumLines())
  36078. {
  36079. const CodeDocument::Position pos (&document, lineNum, 0);
  36080. createTokens (pos.getPosition(), pos.getLineText(),
  36081. source, analyser, newTokens);
  36082. }
  36083. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36084. int newHighlightStart = 0;
  36085. int newHighlightEnd = 0;
  36086. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36087. {
  36088. const String line (document.getLine (lineNum));
  36089. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36090. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36091. line, spacesPerTab);
  36092. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36093. line, spacesPerTab);
  36094. }
  36095. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36096. {
  36097. highlightColumnStart = newHighlightStart;
  36098. highlightColumnEnd = newHighlightEnd;
  36099. }
  36100. else
  36101. {
  36102. if (tokens.size() == newTokens.size())
  36103. {
  36104. bool allTheSame = true;
  36105. for (int i = newTokens.size(); --i >= 0;)
  36106. {
  36107. if (tokens.getReference(i) != newTokens.getReference(i))
  36108. {
  36109. allTheSame = false;
  36110. break;
  36111. }
  36112. }
  36113. if (allTheSame)
  36114. return false;
  36115. }
  36116. }
  36117. tokens.swapWithArray (newTokens);
  36118. return true;
  36119. }
  36120. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36121. float x, const int y, const int baselineOffset, const int lineHeight,
  36122. const Colour& highlightColour) const throw()
  36123. {
  36124. if (highlightColumnStart < highlightColumnEnd)
  36125. {
  36126. g.setColour (highlightColour);
  36127. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36128. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36129. }
  36130. int lastType = std::numeric_limits<int>::min();
  36131. for (int i = 0; i < tokens.size(); ++i)
  36132. {
  36133. SyntaxToken& token = tokens.getReference(i);
  36134. if (lastType != token.tokenType)
  36135. {
  36136. lastType = token.tokenType;
  36137. g.setColour (owner.getColourForTokenType (lastType));
  36138. }
  36139. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  36140. if (i < tokens.size() - 1)
  36141. {
  36142. if (token.width < 0)
  36143. token.width = font.getStringWidthFloat (token.text);
  36144. x += token.width;
  36145. }
  36146. }
  36147. }
  36148. private:
  36149. struct SyntaxToken
  36150. {
  36151. String text;
  36152. int tokenType;
  36153. float width;
  36154. SyntaxToken (const String& text_, const int type) throw()
  36155. : text (text_), tokenType (type), width (-1.0f)
  36156. {
  36157. }
  36158. bool operator!= (const SyntaxToken& other) const throw()
  36159. {
  36160. return text != other.text || tokenType != other.tokenType;
  36161. }
  36162. };
  36163. Array <SyntaxToken> tokens;
  36164. int highlightColumnStart, highlightColumnEnd;
  36165. static void createTokens (int startPosition, const String& lineText,
  36166. CodeDocument::Iterator& source,
  36167. CodeTokeniser* analyser,
  36168. Array <SyntaxToken>& newTokens)
  36169. {
  36170. CodeDocument::Iterator lastIterator (source);
  36171. const int lineLength = lineText.length();
  36172. for (;;)
  36173. {
  36174. int tokenType = analyser->readNextToken (source);
  36175. int tokenStart = lastIterator.getPosition();
  36176. int tokenEnd = source.getPosition();
  36177. if (tokenEnd <= tokenStart)
  36178. break;
  36179. tokenEnd -= startPosition;
  36180. if (tokenEnd > 0)
  36181. {
  36182. tokenStart -= startPosition;
  36183. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36184. tokenType));
  36185. if (tokenEnd >= lineLength)
  36186. break;
  36187. }
  36188. lastIterator = source;
  36189. }
  36190. source = lastIterator;
  36191. }
  36192. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36193. {
  36194. int x = 0;
  36195. for (int i = 0; i < tokens.size(); ++i)
  36196. {
  36197. SyntaxToken& t = tokens.getReference(i);
  36198. for (;;)
  36199. {
  36200. int tabPos = t.text.indexOfChar (T('\t'));
  36201. if (tabPos < 0)
  36202. break;
  36203. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36204. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36205. }
  36206. x += t.text.length();
  36207. }
  36208. }
  36209. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36210. {
  36211. jassert (index <= line.length());
  36212. int col = 0;
  36213. for (int i = 0; i < index; ++i)
  36214. {
  36215. if (line[i] != T('\t'))
  36216. ++col;
  36217. else
  36218. col += spacesPerTab - (col % spacesPerTab);
  36219. }
  36220. return col;
  36221. }
  36222. };
  36223. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36224. CodeTokeniser* const codeTokeniser_)
  36225. : document (document_),
  36226. firstLineOnScreen (0),
  36227. gutter (5),
  36228. spacesPerTab (4),
  36229. lineHeight (0),
  36230. linesOnScreen (0),
  36231. columnsOnScreen (0),
  36232. scrollbarThickness (16),
  36233. columnToTryToMaintain (-1),
  36234. useSpacesForTabs (false),
  36235. xOffset (0),
  36236. codeTokeniser (codeTokeniser_)
  36237. {
  36238. caretPos = CodeDocument::Position (&document_, 0, 0);
  36239. caretPos.setPositionMaintained (true);
  36240. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36241. selectionStart.setPositionMaintained (true);
  36242. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36243. selectionEnd.setPositionMaintained (true);
  36244. setOpaque (true);
  36245. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36246. setWantsKeyboardFocus (true);
  36247. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36248. verticalScrollBar->setSingleStepSize (1.0);
  36249. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36250. horizontalScrollBar->setSingleStepSize (1.0);
  36251. addAndMakeVisible (caret = new CaretComponent());
  36252. Font f (12.0f);
  36253. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36254. setFont (f);
  36255. resetToDefaultColours();
  36256. verticalScrollBar->addListener (this);
  36257. horizontalScrollBar->addListener (this);
  36258. document.addListener (this);
  36259. }
  36260. CodeEditorComponent::~CodeEditorComponent()
  36261. {
  36262. document.removeListener (this);
  36263. deleteAllChildren();
  36264. }
  36265. void CodeEditorComponent::loadContent (const String& newContent)
  36266. {
  36267. clearCachedIterators (0);
  36268. document.replaceAllContent (newContent);
  36269. document.clearUndoHistory();
  36270. document.setSavePoint();
  36271. caretPos.setPosition (0);
  36272. selectionStart.setPosition (0);
  36273. selectionEnd.setPosition (0);
  36274. scrollToLine (0);
  36275. }
  36276. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36277. const CodeDocument::Position& affectedTextEnd)
  36278. {
  36279. clearCachedIterators (affectedTextStart.getLineNumber());
  36280. triggerAsyncUpdate();
  36281. ((CaretComponent*) caret)->updatePosition (*this);
  36282. columnToTryToMaintain = -1;
  36283. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36284. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36285. deselectAll();
  36286. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36287. || caretPos.getPosition() < affectedTextStart.getPosition())
  36288. moveCaretTo (affectedTextStart, false);
  36289. updateScrollBars();
  36290. }
  36291. void CodeEditorComponent::resized()
  36292. {
  36293. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36294. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36295. lines.clear();
  36296. rebuildLineTokens();
  36297. ((CaretComponent*) caret)->updatePosition (*this);
  36298. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36299. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36300. updateScrollBars();
  36301. }
  36302. void CodeEditorComponent::paint (Graphics& g)
  36303. {
  36304. handleUpdateNowIfNeeded();
  36305. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36306. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36307. g.setFont (font);
  36308. const int baselineOffset = (int) font.getAscent();
  36309. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36310. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36311. const Rectangle<int> clip (g.getClipBounds());
  36312. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36313. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36314. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36315. {
  36316. lines.getUnchecked(j)->draw (*this, g, font,
  36317. (float) (gutter - xOffset * charWidth),
  36318. lineHeight * j, baselineOffset, lineHeight,
  36319. highlightColour);
  36320. }
  36321. }
  36322. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36323. {
  36324. if (scrollbarThickness != thickness)
  36325. {
  36326. scrollbarThickness = thickness;
  36327. resized();
  36328. }
  36329. }
  36330. void CodeEditorComponent::handleAsyncUpdate()
  36331. {
  36332. rebuildLineTokens();
  36333. }
  36334. void CodeEditorComponent::rebuildLineTokens()
  36335. {
  36336. cancelPendingUpdate();
  36337. const int numNeeded = linesOnScreen + 1;
  36338. int minLineToRepaint = numNeeded;
  36339. int maxLineToRepaint = 0;
  36340. if (numNeeded != lines.size())
  36341. {
  36342. lines.clear();
  36343. for (int i = numNeeded; --i >= 0;)
  36344. lines.add (new CodeEditorLine());
  36345. minLineToRepaint = 0;
  36346. maxLineToRepaint = numNeeded;
  36347. }
  36348. jassert (numNeeded == lines.size());
  36349. CodeDocument::Iterator source (&document);
  36350. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36351. for (int i = 0; i < numNeeded; ++i)
  36352. {
  36353. CodeEditorLine* const line = lines.getUnchecked(i);
  36354. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36355. selectionStart, selectionEnd))
  36356. {
  36357. minLineToRepaint = jmin (minLineToRepaint, i);
  36358. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36359. }
  36360. }
  36361. if (minLineToRepaint <= maxLineToRepaint)
  36362. {
  36363. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36364. verticalScrollBar->getX() - gutter,
  36365. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36366. }
  36367. }
  36368. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36369. {
  36370. caretPos = newPos;
  36371. columnToTryToMaintain = -1;
  36372. if (highlighting)
  36373. {
  36374. if (dragType == notDragging)
  36375. {
  36376. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36377. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36378. dragType = draggingSelectionStart;
  36379. else
  36380. dragType = draggingSelectionEnd;
  36381. }
  36382. if (dragType == draggingSelectionStart)
  36383. {
  36384. selectionStart = caretPos;
  36385. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36386. {
  36387. const CodeDocument::Position temp (selectionStart);
  36388. selectionStart = selectionEnd;
  36389. selectionEnd = temp;
  36390. dragType = draggingSelectionEnd;
  36391. }
  36392. }
  36393. else
  36394. {
  36395. selectionEnd = caretPos;
  36396. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36397. {
  36398. const CodeDocument::Position temp (selectionStart);
  36399. selectionStart = selectionEnd;
  36400. selectionEnd = temp;
  36401. dragType = draggingSelectionStart;
  36402. }
  36403. }
  36404. triggerAsyncUpdate();
  36405. }
  36406. else
  36407. {
  36408. deselectAll();
  36409. }
  36410. ((CaretComponent*) caret)->updatePosition (*this);
  36411. scrollToKeepCaretOnScreen();
  36412. updateScrollBars();
  36413. }
  36414. void CodeEditorComponent::deselectAll()
  36415. {
  36416. if (selectionStart != selectionEnd)
  36417. triggerAsyncUpdate();
  36418. selectionStart = caretPos;
  36419. selectionEnd = caretPos;
  36420. }
  36421. void CodeEditorComponent::updateScrollBars()
  36422. {
  36423. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36424. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36425. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36426. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36427. }
  36428. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36429. {
  36430. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36431. newFirstLineOnScreen);
  36432. if (newFirstLineOnScreen != firstLineOnScreen)
  36433. {
  36434. firstLineOnScreen = newFirstLineOnScreen;
  36435. ((CaretComponent*) caret)->updatePosition (*this);
  36436. updateCachedIterators (firstLineOnScreen);
  36437. triggerAsyncUpdate();
  36438. }
  36439. }
  36440. void CodeEditorComponent::scrollToColumnInternal (double column)
  36441. {
  36442. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36443. if (xOffset != newOffset)
  36444. {
  36445. xOffset = newOffset;
  36446. ((CaretComponent*) caret)->updatePosition (*this);
  36447. repaint();
  36448. }
  36449. }
  36450. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36451. {
  36452. scrollToLineInternal (newFirstLineOnScreen);
  36453. updateScrollBars();
  36454. }
  36455. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36456. {
  36457. scrollToColumnInternal (newFirstColumnOnScreen);
  36458. updateScrollBars();
  36459. }
  36460. void CodeEditorComponent::scrollBy (int deltaLines)
  36461. {
  36462. scrollToLine (firstLineOnScreen + deltaLines);
  36463. }
  36464. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36465. {
  36466. if (caretPos.getLineNumber() < firstLineOnScreen)
  36467. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36468. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36469. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36470. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36471. if (column >= xOffset + columnsOnScreen - 1)
  36472. scrollToColumn (column + 1 - columnsOnScreen);
  36473. else if (column < xOffset)
  36474. scrollToColumn (column);
  36475. }
  36476. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36477. {
  36478. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36479. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36480. roundToInt (charWidth),
  36481. lineHeight);
  36482. }
  36483. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36484. {
  36485. const int line = y / lineHeight + firstLineOnScreen;
  36486. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36487. const int index = columnToIndex (line, column);
  36488. return CodeDocument::Position (&document, line, index);
  36489. }
  36490. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36491. {
  36492. document.deleteSection (selectionStart, selectionEnd);
  36493. if (newText.isNotEmpty())
  36494. document.insertText (caretPos, newText);
  36495. scrollToKeepCaretOnScreen();
  36496. }
  36497. void CodeEditorComponent::insertTabAtCaret()
  36498. {
  36499. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36500. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36501. {
  36502. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36503. }
  36504. if (useSpacesForTabs)
  36505. {
  36506. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36507. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36508. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36509. }
  36510. else
  36511. {
  36512. insertTextAtCaret (T("\t"));
  36513. }
  36514. }
  36515. void CodeEditorComponent::cut()
  36516. {
  36517. insertTextAtCaret (String::empty);
  36518. }
  36519. void CodeEditorComponent::copy()
  36520. {
  36521. newTransaction();
  36522. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36523. if (selection.isNotEmpty())
  36524. SystemClipboard::copyTextToClipboard (selection);
  36525. }
  36526. void CodeEditorComponent::copyThenCut()
  36527. {
  36528. copy();
  36529. cut();
  36530. newTransaction();
  36531. }
  36532. void CodeEditorComponent::paste()
  36533. {
  36534. newTransaction();
  36535. const String clip (SystemClipboard::getTextFromClipboard());
  36536. if (clip.isNotEmpty())
  36537. insertTextAtCaret (clip);
  36538. newTransaction();
  36539. }
  36540. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36541. {
  36542. newTransaction();
  36543. if (moveInWholeWordSteps)
  36544. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36545. else
  36546. moveCaretTo (caretPos.movedBy (-1), selecting);
  36547. }
  36548. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36549. {
  36550. newTransaction();
  36551. if (moveInWholeWordSteps)
  36552. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36553. else
  36554. moveCaretTo (caretPos.movedBy (1), selecting);
  36555. }
  36556. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36557. {
  36558. CodeDocument::Position pos (caretPos);
  36559. const int newLineNum = pos.getLineNumber() + delta;
  36560. if (columnToTryToMaintain < 0)
  36561. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36562. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36563. const int colToMaintain = columnToTryToMaintain;
  36564. moveCaretTo (pos, selecting);
  36565. columnToTryToMaintain = colToMaintain;
  36566. }
  36567. void CodeEditorComponent::cursorDown (const bool selecting)
  36568. {
  36569. newTransaction();
  36570. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36571. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36572. else
  36573. moveLineDelta (1, selecting);
  36574. }
  36575. void CodeEditorComponent::cursorUp (const bool selecting)
  36576. {
  36577. newTransaction();
  36578. if (caretPos.getLineNumber() == 0)
  36579. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36580. else
  36581. moveLineDelta (-1, selecting);
  36582. }
  36583. void CodeEditorComponent::pageDown (const bool selecting)
  36584. {
  36585. newTransaction();
  36586. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36587. moveLineDelta (linesOnScreen, selecting);
  36588. }
  36589. void CodeEditorComponent::pageUp (const bool selecting)
  36590. {
  36591. newTransaction();
  36592. scrollBy (-linesOnScreen);
  36593. moveLineDelta (-linesOnScreen, selecting);
  36594. }
  36595. void CodeEditorComponent::scrollUp()
  36596. {
  36597. newTransaction();
  36598. scrollBy (1);
  36599. if (caretPos.getLineNumber() < firstLineOnScreen)
  36600. moveLineDelta (1, false);
  36601. }
  36602. void CodeEditorComponent::scrollDown()
  36603. {
  36604. newTransaction();
  36605. scrollBy (-1);
  36606. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36607. moveLineDelta (-1, false);
  36608. }
  36609. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36610. {
  36611. newTransaction();
  36612. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36613. }
  36614. static int findFirstNonWhitespaceChar (const String& line) throw()
  36615. {
  36616. const int len = line.length();
  36617. for (int i = 0; i < len; ++i)
  36618. if (! CharacterFunctions::isWhitespace (line [i]))
  36619. return i;
  36620. return 0;
  36621. }
  36622. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36623. {
  36624. newTransaction();
  36625. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36626. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36627. index = 0;
  36628. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36629. }
  36630. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36631. {
  36632. newTransaction();
  36633. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36634. }
  36635. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36636. {
  36637. newTransaction();
  36638. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36639. }
  36640. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36641. {
  36642. if (moveInWholeWordSteps)
  36643. {
  36644. cut(); // in case something is already highlighted
  36645. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36646. }
  36647. else
  36648. {
  36649. if (selectionStart == selectionEnd)
  36650. selectionStart.moveBy (-1);
  36651. }
  36652. cut();
  36653. }
  36654. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36655. {
  36656. if (moveInWholeWordSteps)
  36657. {
  36658. cut(); // in case something is already highlighted
  36659. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36660. }
  36661. else
  36662. {
  36663. if (selectionStart == selectionEnd)
  36664. selectionEnd.moveBy (1);
  36665. else
  36666. newTransaction();
  36667. }
  36668. cut();
  36669. }
  36670. void CodeEditorComponent::selectAll()
  36671. {
  36672. newTransaction();
  36673. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36674. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36675. }
  36676. void CodeEditorComponent::undo()
  36677. {
  36678. document.undo();
  36679. scrollToKeepCaretOnScreen();
  36680. }
  36681. void CodeEditorComponent::redo()
  36682. {
  36683. document.redo();
  36684. scrollToKeepCaretOnScreen();
  36685. }
  36686. void CodeEditorComponent::newTransaction()
  36687. {
  36688. document.newTransaction();
  36689. startTimer (600);
  36690. }
  36691. void CodeEditorComponent::timerCallback()
  36692. {
  36693. newTransaction();
  36694. }
  36695. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36696. {
  36697. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36698. const bool shiftDown = key.getModifiers().isShiftDown();
  36699. if (key.isKeyCode (KeyPress::leftKey))
  36700. {
  36701. cursorLeft (moveInWholeWordSteps, shiftDown);
  36702. }
  36703. else if (key.isKeyCode (KeyPress::rightKey))
  36704. {
  36705. cursorRight (moveInWholeWordSteps, shiftDown);
  36706. }
  36707. else if (key.isKeyCode (KeyPress::upKey))
  36708. {
  36709. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36710. scrollDown();
  36711. #if JUCE_MAC
  36712. else if (key.getModifiers().isCommandDown())
  36713. goToStartOfDocument (shiftDown);
  36714. #endif
  36715. else
  36716. cursorUp (shiftDown);
  36717. }
  36718. else if (key.isKeyCode (KeyPress::downKey))
  36719. {
  36720. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36721. scrollUp();
  36722. #if JUCE_MAC
  36723. else if (key.getModifiers().isCommandDown())
  36724. goToEndOfDocument (shiftDown);
  36725. #endif
  36726. else
  36727. cursorDown (shiftDown);
  36728. }
  36729. else if (key.isKeyCode (KeyPress::pageDownKey))
  36730. {
  36731. pageDown (shiftDown);
  36732. }
  36733. else if (key.isKeyCode (KeyPress::pageUpKey))
  36734. {
  36735. pageUp (shiftDown);
  36736. }
  36737. else if (key.isKeyCode (KeyPress::homeKey))
  36738. {
  36739. if (moveInWholeWordSteps)
  36740. goToStartOfDocument (shiftDown);
  36741. else
  36742. goToStartOfLine (shiftDown);
  36743. }
  36744. else if (key.isKeyCode (KeyPress::endKey))
  36745. {
  36746. if (moveInWholeWordSteps)
  36747. goToEndOfDocument (shiftDown);
  36748. else
  36749. goToEndOfLine (shiftDown);
  36750. }
  36751. else if (key.isKeyCode (KeyPress::backspaceKey))
  36752. {
  36753. backspace (moveInWholeWordSteps);
  36754. }
  36755. else if (key.isKeyCode (KeyPress::deleteKey))
  36756. {
  36757. deleteForward (moveInWholeWordSteps);
  36758. }
  36759. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36760. {
  36761. copy();
  36762. }
  36763. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36764. {
  36765. copyThenCut();
  36766. }
  36767. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36768. {
  36769. paste();
  36770. }
  36771. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36772. {
  36773. undo();
  36774. }
  36775. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36776. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36777. {
  36778. redo();
  36779. }
  36780. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36781. {
  36782. selectAll();
  36783. }
  36784. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36785. {
  36786. insertTabAtCaret();
  36787. }
  36788. else if (key == KeyPress::returnKey)
  36789. {
  36790. newTransaction();
  36791. insertTextAtCaret (document.getNewLineCharacters());
  36792. }
  36793. else if (key.isKeyCode (KeyPress::escapeKey))
  36794. {
  36795. newTransaction();
  36796. }
  36797. else if (key.getTextCharacter() >= ' ')
  36798. {
  36799. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36800. }
  36801. else
  36802. {
  36803. return false;
  36804. }
  36805. return true;
  36806. }
  36807. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36808. {
  36809. newTransaction();
  36810. dragType = notDragging;
  36811. if (! e.mods.isPopupMenu())
  36812. {
  36813. beginDragAutoRepeat (100);
  36814. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36815. }
  36816. else
  36817. {
  36818. }
  36819. }
  36820. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36821. {
  36822. if (! e.mods.isPopupMenu())
  36823. moveCaretTo (getPositionAt (e.x, e.y), true);
  36824. }
  36825. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36826. {
  36827. newTransaction();
  36828. beginDragAutoRepeat (0);
  36829. dragType = notDragging;
  36830. }
  36831. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36832. {
  36833. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36834. CodeDocument::Position tokenEnd (tokenStart);
  36835. if (e.getNumberOfClicks() > 2)
  36836. {
  36837. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36838. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36839. }
  36840. else
  36841. {
  36842. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36843. tokenEnd.moveBy (1);
  36844. tokenStart = tokenEnd;
  36845. while (tokenStart.getIndexInLine() > 0
  36846. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36847. tokenStart.moveBy (-1);
  36848. }
  36849. moveCaretTo (tokenEnd, false);
  36850. moveCaretTo (tokenStart, true);
  36851. }
  36852. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36853. {
  36854. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36855. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36856. }
  36857. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36858. {
  36859. if (scrollBarThatHasMoved == verticalScrollBar)
  36860. scrollToLineInternal ((int) newRangeStart);
  36861. else
  36862. scrollToColumnInternal (newRangeStart);
  36863. }
  36864. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36865. {
  36866. useSpacesForTabs = insertSpaces;
  36867. if (spacesPerTab != numSpaces)
  36868. {
  36869. spacesPerTab = numSpaces;
  36870. triggerAsyncUpdate();
  36871. }
  36872. }
  36873. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36874. {
  36875. const String line (document.getLine (lineNum));
  36876. jassert (index <= line.length());
  36877. int col = 0;
  36878. for (int i = 0; i < index; ++i)
  36879. {
  36880. if (line[i] != T('\t'))
  36881. ++col;
  36882. else
  36883. col += getTabSize() - (col % getTabSize());
  36884. }
  36885. return col;
  36886. }
  36887. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36888. {
  36889. const String line (document.getLine (lineNum));
  36890. const int lineLength = line.length();
  36891. int i, col = 0;
  36892. for (i = 0; i < lineLength; ++i)
  36893. {
  36894. if (line[i] != T('\t'))
  36895. ++col;
  36896. else
  36897. col += getTabSize() - (col % getTabSize());
  36898. if (col > column)
  36899. break;
  36900. }
  36901. return i;
  36902. }
  36903. void CodeEditorComponent::setFont (const Font& newFont)
  36904. {
  36905. font = newFont;
  36906. charWidth = font.getStringWidthFloat (T("0"));
  36907. lineHeight = roundToInt (font.getHeight());
  36908. resized();
  36909. }
  36910. void CodeEditorComponent::resetToDefaultColours()
  36911. {
  36912. coloursForTokenCategories.clear();
  36913. if (codeTokeniser != 0)
  36914. {
  36915. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36916. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36917. }
  36918. }
  36919. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36920. {
  36921. jassert (tokenType < 256);
  36922. while (coloursForTokenCategories.size() < tokenType)
  36923. coloursForTokenCategories.add (Colours::black);
  36924. coloursForTokenCategories.set (tokenType, colour);
  36925. repaint();
  36926. }
  36927. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36928. {
  36929. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36930. return findColour (CodeEditorComponent::defaultTextColourId);
  36931. return coloursForTokenCategories.getReference (tokenType);
  36932. }
  36933. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36934. {
  36935. int i;
  36936. for (i = cachedIterators.size(); --i >= 0;)
  36937. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36938. break;
  36939. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36940. }
  36941. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36942. {
  36943. const int maxNumCachedPositions = 5000;
  36944. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36945. if (cachedIterators.size() == 0)
  36946. cachedIterators.add (new CodeDocument::Iterator (&document));
  36947. if (codeTokeniser == 0)
  36948. return;
  36949. for (;;)
  36950. {
  36951. CodeDocument::Iterator* last = cachedIterators.getLast();
  36952. if (last->getLine() >= maxLineNum)
  36953. break;
  36954. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36955. cachedIterators.add (t);
  36956. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36957. for (;;)
  36958. {
  36959. codeTokeniser->readNextToken (*t);
  36960. if (t->getLine() >= targetLine)
  36961. break;
  36962. if (t->isEOF())
  36963. return;
  36964. }
  36965. }
  36966. }
  36967. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36968. {
  36969. if (codeTokeniser == 0)
  36970. return;
  36971. for (int i = cachedIterators.size(); --i >= 0;)
  36972. {
  36973. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36974. if (t->getPosition() <= position)
  36975. {
  36976. source = *t;
  36977. break;
  36978. }
  36979. }
  36980. while (source.getPosition() < position)
  36981. {
  36982. const CodeDocument::Iterator original (source);
  36983. codeTokeniser->readNextToken (source);
  36984. if (source.getPosition() > position || source.isEOF())
  36985. {
  36986. source = original;
  36987. break;
  36988. }
  36989. }
  36990. }
  36991. END_JUCE_NAMESPACE
  36992. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36993. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36994. BEGIN_JUCE_NAMESPACE
  36995. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36996. {
  36997. }
  36998. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36999. {
  37000. }
  37001. namespace CppTokeniser
  37002. {
  37003. static bool isIdentifierStart (const tchar c) throw()
  37004. {
  37005. return CharacterFunctions::isLetter (c)
  37006. || c == T('_') || c == T('@');
  37007. }
  37008. static bool isIdentifierBody (const tchar c) throw()
  37009. {
  37010. return CharacterFunctions::isLetter (c)
  37011. || CharacterFunctions::isDigit (c)
  37012. || c == T('_') || c == T('@');
  37013. }
  37014. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  37015. {
  37016. static const tchar* keywords2Char[] =
  37017. { T("if"), T("do"), T("or"), 0 };
  37018. static const tchar* keywords3Char[] =
  37019. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  37020. static const tchar* keywords4Char[] =
  37021. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  37022. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  37023. static const tchar* keywords5Char[] =
  37024. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  37025. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  37026. static const tchar* keywords6Char[] =
  37027. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  37028. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  37029. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  37030. static const tchar* keywordsOther[] =
  37031. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  37032. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  37033. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  37034. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  37035. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  37036. int tokenLength = 0;
  37037. tchar possibleIdentifier [19];
  37038. while (isIdentifierBody (source.peekNextChar()))
  37039. {
  37040. const tchar c = source.nextChar();
  37041. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  37042. possibleIdentifier [tokenLength] = c;
  37043. ++tokenLength;
  37044. }
  37045. if (tokenLength > 1 && tokenLength <= 16)
  37046. {
  37047. possibleIdentifier [tokenLength] = 0;
  37048. const tchar** k;
  37049. switch (tokenLength)
  37050. {
  37051. case 2: k = keywords2Char; break;
  37052. case 3: k = keywords3Char; break;
  37053. case 4: k = keywords4Char; break;
  37054. case 5: k = keywords5Char; break;
  37055. case 6: k = keywords6Char; break;
  37056. default: k = keywordsOther; break;
  37057. }
  37058. int i = 0;
  37059. while (k[i] != 0)
  37060. {
  37061. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  37062. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  37063. ++i;
  37064. }
  37065. }
  37066. return CPlusPlusCodeTokeniser::tokenType_identifier;
  37067. }
  37068. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  37069. {
  37070. const juce_wchar c = source.peekNextChar();
  37071. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37072. source.skip();
  37073. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37074. return false;
  37075. return true;
  37076. }
  37077. static bool isHexDigit (const juce_wchar c) throw()
  37078. {
  37079. return (c >= '0' && c <= '9')
  37080. || (c >= 'a' && c <= 'f')
  37081. || (c >= 'A' && c <= 'F');
  37082. }
  37083. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37084. {
  37085. if (source.nextChar() != '0')
  37086. return false;
  37087. juce_wchar c = source.nextChar();
  37088. if (c != 'x' && c != 'X')
  37089. return false;
  37090. int numDigits = 0;
  37091. while (isHexDigit (source.peekNextChar()))
  37092. {
  37093. ++numDigits;
  37094. source.skip();
  37095. }
  37096. if (numDigits == 0)
  37097. return false;
  37098. return skipNumberSuffix (source);
  37099. }
  37100. static bool isOctalDigit (const juce_wchar c) throw()
  37101. {
  37102. return c >= '0' && c <= '7';
  37103. }
  37104. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37105. {
  37106. if (source.nextChar() != '0')
  37107. return false;
  37108. if (! isOctalDigit (source.nextChar()))
  37109. return false;
  37110. while (isOctalDigit (source.peekNextChar()))
  37111. source.skip();
  37112. return skipNumberSuffix (source);
  37113. }
  37114. static bool isDecimalDigit (const juce_wchar c) throw()
  37115. {
  37116. return c >= '0' && c <= '9';
  37117. }
  37118. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37119. {
  37120. int numChars = 0;
  37121. while (isDecimalDigit (source.peekNextChar()))
  37122. {
  37123. ++numChars;
  37124. source.skip();
  37125. }
  37126. if (numChars == 0)
  37127. return false;
  37128. return skipNumberSuffix (source);
  37129. }
  37130. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37131. {
  37132. int numDigits = 0;
  37133. while (isDecimalDigit (source.peekNextChar()))
  37134. {
  37135. source.skip();
  37136. ++numDigits;
  37137. }
  37138. const bool hasPoint = (source.peekNextChar() == '.');
  37139. if (hasPoint)
  37140. {
  37141. source.skip();
  37142. while (isDecimalDigit (source.peekNextChar()))
  37143. {
  37144. source.skip();
  37145. ++numDigits;
  37146. }
  37147. }
  37148. if (numDigits == 0)
  37149. return false;
  37150. juce_wchar c = source.peekNextChar();
  37151. const bool hasExponent = (c == 'e' || c == 'E');
  37152. if (hasExponent)
  37153. {
  37154. source.skip();
  37155. c = source.peekNextChar();
  37156. if (c == '+' || c == '-')
  37157. source.skip();
  37158. int numExpDigits = 0;
  37159. while (isDecimalDigit (source.peekNextChar()))
  37160. {
  37161. source.skip();
  37162. ++numExpDigits;
  37163. }
  37164. if (numExpDigits == 0)
  37165. return false;
  37166. }
  37167. c = source.peekNextChar();
  37168. if (c == 'f' || c == 'F')
  37169. source.skip();
  37170. else if (! (hasExponent || hasPoint))
  37171. return false;
  37172. return true;
  37173. }
  37174. static int parseNumber (CodeDocument::Iterator& source)
  37175. {
  37176. const CodeDocument::Iterator original (source);
  37177. if (parseFloatLiteral (source))
  37178. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37179. source = original;
  37180. if (parseHexLiteral (source))
  37181. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37182. source = original;
  37183. if (parseOctalLiteral (source))
  37184. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37185. source = original;
  37186. if (parseDecimalLiteral (source))
  37187. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37188. source = original;
  37189. source.skip();
  37190. return CPlusPlusCodeTokeniser::tokenType_error;
  37191. }
  37192. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37193. {
  37194. const juce_wchar quote = source.nextChar();
  37195. for (;;)
  37196. {
  37197. const juce_wchar c = source.nextChar();
  37198. if (c == quote || c == 0)
  37199. break;
  37200. if (c == '\\')
  37201. source.skip();
  37202. }
  37203. }
  37204. static void skipComment (CodeDocument::Iterator& source) throw()
  37205. {
  37206. bool lastWasStar = false;
  37207. for (;;)
  37208. {
  37209. const juce_wchar c = source.nextChar();
  37210. if (c == 0 || (c == T('/') && lastWasStar))
  37211. break;
  37212. lastWasStar = (c == '*');
  37213. }
  37214. }
  37215. }
  37216. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37217. {
  37218. int result = tokenType_error;
  37219. source.skipWhitespace();
  37220. tchar firstChar = source.peekNextChar();
  37221. switch (firstChar)
  37222. {
  37223. case 0:
  37224. source.skip();
  37225. break;
  37226. case T('0'):
  37227. case T('1'):
  37228. case T('2'):
  37229. case T('3'):
  37230. case T('4'):
  37231. case T('5'):
  37232. case T('6'):
  37233. case T('7'):
  37234. case T('8'):
  37235. case T('9'):
  37236. result = CppTokeniser::parseNumber (source);
  37237. break;
  37238. case T('.'):
  37239. result = CppTokeniser::parseNumber (source);
  37240. if (result == tokenType_error)
  37241. result = tokenType_punctuation;
  37242. break;
  37243. case T(','):
  37244. case T(';'):
  37245. case T(':'):
  37246. source.skip();
  37247. result = tokenType_punctuation;
  37248. break;
  37249. case T('('):
  37250. case T(')'):
  37251. case T('{'):
  37252. case T('}'):
  37253. case T('['):
  37254. case T(']'):
  37255. source.skip();
  37256. result = tokenType_bracket;
  37257. break;
  37258. case T('"'):
  37259. case T('\''):
  37260. CppTokeniser::skipQuotedString (source);
  37261. result = tokenType_stringLiteral;
  37262. break;
  37263. case T('+'):
  37264. result = tokenType_operator;
  37265. source.skip();
  37266. if (source.peekNextChar() == T('+'))
  37267. source.skip();
  37268. else if (source.peekNextChar() == T('='))
  37269. source.skip();
  37270. break;
  37271. case T('-'):
  37272. source.skip();
  37273. result = CppTokeniser::parseNumber (source);
  37274. if (result == tokenType_error)
  37275. {
  37276. result = tokenType_operator;
  37277. if (source.peekNextChar() == T('-'))
  37278. source.skip();
  37279. else if (source.peekNextChar() == T('='))
  37280. source.skip();
  37281. }
  37282. break;
  37283. case T('*'):
  37284. case T('%'):
  37285. case T('='):
  37286. case T('!'):
  37287. result = tokenType_operator;
  37288. source.skip();
  37289. if (source.peekNextChar() == T('='))
  37290. source.skip();
  37291. break;
  37292. case T('/'):
  37293. result = tokenType_operator;
  37294. source.skip();
  37295. if (source.peekNextChar() == T('='))
  37296. {
  37297. source.skip();
  37298. }
  37299. else if (source.peekNextChar() == T('/'))
  37300. {
  37301. result = tokenType_comment;
  37302. source.skipToEndOfLine();
  37303. }
  37304. else if (source.peekNextChar() == T('*'))
  37305. {
  37306. source.skip();
  37307. result = tokenType_comment;
  37308. CppTokeniser::skipComment (source);
  37309. }
  37310. break;
  37311. case T('?'):
  37312. case T('~'):
  37313. source.skip();
  37314. result = tokenType_operator;
  37315. break;
  37316. case T('<'):
  37317. source.skip();
  37318. result = tokenType_operator;
  37319. if (source.peekNextChar() == T('='))
  37320. {
  37321. source.skip();
  37322. }
  37323. else if (source.peekNextChar() == T('<'))
  37324. {
  37325. source.skip();
  37326. if (source.peekNextChar() == T('='))
  37327. source.skip();
  37328. }
  37329. break;
  37330. case T('>'):
  37331. source.skip();
  37332. result = tokenType_operator;
  37333. if (source.peekNextChar() == T('='))
  37334. {
  37335. source.skip();
  37336. }
  37337. else if (source.peekNextChar() == T('<'))
  37338. {
  37339. source.skip();
  37340. if (source.peekNextChar() == T('='))
  37341. source.skip();
  37342. }
  37343. break;
  37344. case T('|'):
  37345. source.skip();
  37346. result = tokenType_operator;
  37347. if (source.peekNextChar() == T('='))
  37348. {
  37349. source.skip();
  37350. }
  37351. else if (source.peekNextChar() == T('|'))
  37352. {
  37353. source.skip();
  37354. if (source.peekNextChar() == T('='))
  37355. source.skip();
  37356. }
  37357. break;
  37358. case T('&'):
  37359. source.skip();
  37360. result = tokenType_operator;
  37361. if (source.peekNextChar() == T('='))
  37362. {
  37363. source.skip();
  37364. }
  37365. else if (source.peekNextChar() == T('&'))
  37366. {
  37367. source.skip();
  37368. if (source.peekNextChar() == T('='))
  37369. source.skip();
  37370. }
  37371. break;
  37372. case T('^'):
  37373. source.skip();
  37374. result = tokenType_operator;
  37375. if (source.peekNextChar() == T('='))
  37376. {
  37377. source.skip();
  37378. }
  37379. else if (source.peekNextChar() == T('^'))
  37380. {
  37381. source.skip();
  37382. if (source.peekNextChar() == T('='))
  37383. source.skip();
  37384. }
  37385. break;
  37386. case T('#'):
  37387. result = tokenType_preprocessor;
  37388. source.skipToEndOfLine();
  37389. break;
  37390. default:
  37391. if (CppTokeniser::isIdentifierStart (firstChar))
  37392. result = CppTokeniser::parseIdentifier (source);
  37393. else
  37394. source.skip();
  37395. break;
  37396. }
  37397. //jassert (result != tokenType_unknown);
  37398. return result;
  37399. }
  37400. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37401. {
  37402. StringArray s;
  37403. s.add ("Error");
  37404. s.add ("Comment");
  37405. s.add ("C++ keyword");
  37406. s.add ("Identifier");
  37407. s.add ("Integer literal");
  37408. s.add ("Float literal");
  37409. s.add ("String literal");
  37410. s.add ("Operator");
  37411. s.add ("Bracket");
  37412. s.add ("Punctuation");
  37413. s.add ("Preprocessor line");
  37414. return s;
  37415. }
  37416. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37417. {
  37418. const uint32 colours[] =
  37419. {
  37420. 0xffcc0000, // error
  37421. 0xff00aa00, // comment
  37422. 0xff0000cc, // keyword
  37423. 0xff000000, // identifier
  37424. 0xff880000, // int literal
  37425. 0xff885500, // float literal
  37426. 0xff990099, // string literal
  37427. 0xff225500, // operator
  37428. 0xff000055, // bracket
  37429. 0xff004400, // punctuation
  37430. 0xff660000 // preprocessor
  37431. };
  37432. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37433. return Colour (colours [tokenType]);
  37434. return Colours::black;
  37435. }
  37436. END_JUCE_NAMESPACE
  37437. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37438. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37439. BEGIN_JUCE_NAMESPACE
  37440. ComboBox::ComboBox (const String& name)
  37441. : Component (name),
  37442. lastCurrentId (0),
  37443. isButtonDown (false),
  37444. separatorPending (false),
  37445. menuActive (false),
  37446. label (0)
  37447. {
  37448. noChoicesMessage = TRANS("(no choices)");
  37449. setRepaintsOnMouseActivity (true);
  37450. lookAndFeelChanged();
  37451. currentId.addListener (this);
  37452. }
  37453. ComboBox::~ComboBox()
  37454. {
  37455. currentId.removeListener (this);
  37456. if (menuActive)
  37457. PopupMenu::dismissAllActiveMenus();
  37458. deleteAllChildren();
  37459. }
  37460. void ComboBox::setEditableText (const bool isEditable)
  37461. {
  37462. label->setEditable (isEditable, isEditable, false);
  37463. setWantsKeyboardFocus (! isEditable);
  37464. resized();
  37465. }
  37466. bool ComboBox::isTextEditable() const throw()
  37467. {
  37468. return label->isEditable();
  37469. }
  37470. void ComboBox::setJustificationType (const Justification& justification) throw()
  37471. {
  37472. label->setJustificationType (justification);
  37473. }
  37474. const Justification ComboBox::getJustificationType() const throw()
  37475. {
  37476. return label->getJustificationType();
  37477. }
  37478. void ComboBox::setTooltip (const String& newTooltip)
  37479. {
  37480. SettableTooltipClient::setTooltip (newTooltip);
  37481. label->setTooltip (newTooltip);
  37482. }
  37483. void ComboBox::addItem (const String& newItemText,
  37484. const int newItemId) throw()
  37485. {
  37486. // you can't add empty strings to the list..
  37487. jassert (newItemText.isNotEmpty());
  37488. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37489. jassert (newItemId != 0);
  37490. // you shouldn't use duplicate item IDs!
  37491. jassert (getItemForId (newItemId) == 0);
  37492. if (newItemText.isNotEmpty() && newItemId != 0)
  37493. {
  37494. if (separatorPending)
  37495. {
  37496. separatorPending = false;
  37497. ItemInfo* const item = new ItemInfo();
  37498. item->itemId = 0;
  37499. item->isEnabled = false;
  37500. item->isHeading = false;
  37501. items.add (item);
  37502. }
  37503. ItemInfo* const item = new ItemInfo();
  37504. item->name = newItemText;
  37505. item->itemId = newItemId;
  37506. item->isEnabled = true;
  37507. item->isHeading = false;
  37508. items.add (item);
  37509. }
  37510. }
  37511. void ComboBox::addSeparator() throw()
  37512. {
  37513. separatorPending = (items.size() > 0);
  37514. }
  37515. void ComboBox::addSectionHeading (const String& headingName) throw()
  37516. {
  37517. // you can't add empty strings to the list..
  37518. jassert (headingName.isNotEmpty());
  37519. if (headingName.isNotEmpty())
  37520. {
  37521. if (separatorPending)
  37522. {
  37523. separatorPending = false;
  37524. ItemInfo* const item = new ItemInfo();
  37525. item->itemId = 0;
  37526. item->isEnabled = false;
  37527. item->isHeading = false;
  37528. items.add (item);
  37529. }
  37530. ItemInfo* const item = new ItemInfo();
  37531. item->name = headingName;
  37532. item->itemId = 0;
  37533. item->isEnabled = true;
  37534. item->isHeading = true;
  37535. items.add (item);
  37536. }
  37537. }
  37538. void ComboBox::setItemEnabled (const int itemId,
  37539. const bool shouldBeEnabled) throw()
  37540. {
  37541. ItemInfo* const item = getItemForId (itemId);
  37542. if (item != 0)
  37543. item->isEnabled = shouldBeEnabled;
  37544. }
  37545. void ComboBox::changeItemText (const int itemId,
  37546. const String& newText) throw()
  37547. {
  37548. ItemInfo* const item = getItemForId (itemId);
  37549. jassert (item != 0);
  37550. if (item != 0)
  37551. item->name = newText;
  37552. }
  37553. void ComboBox::clear (const bool dontSendChangeMessage)
  37554. {
  37555. items.clear();
  37556. separatorPending = false;
  37557. if (! label->isEditable())
  37558. setSelectedItemIndex (-1, dontSendChangeMessage);
  37559. }
  37560. bool ComboBox::ItemInfo::isSeparator() const throw()
  37561. {
  37562. return name.isEmpty();
  37563. }
  37564. bool ComboBox::ItemInfo::isRealItem() const throw()
  37565. {
  37566. return ! (isHeading || name.isEmpty());
  37567. }
  37568. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37569. {
  37570. if (itemId != 0)
  37571. {
  37572. for (int i = items.size(); --i >= 0;)
  37573. if (items.getUnchecked(i)->itemId == itemId)
  37574. return items.getUnchecked(i);
  37575. }
  37576. return 0;
  37577. }
  37578. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37579. {
  37580. int n = 0;
  37581. for (int i = 0; i < items.size(); ++i)
  37582. {
  37583. ItemInfo* const item = items.getUnchecked(i);
  37584. if (item->isRealItem())
  37585. if (n++ == index)
  37586. return item;
  37587. }
  37588. return 0;
  37589. }
  37590. int ComboBox::getNumItems() const throw()
  37591. {
  37592. int n = 0;
  37593. for (int i = items.size(); --i >= 0;)
  37594. if (items.getUnchecked(i)->isRealItem())
  37595. ++n;
  37596. return n;
  37597. }
  37598. const String ComboBox::getItemText (const int index) const throw()
  37599. {
  37600. const ItemInfo* const item = getItemForIndex (index);
  37601. if (item != 0)
  37602. return item->name;
  37603. return String::empty;
  37604. }
  37605. int ComboBox::getItemId (const int index) const throw()
  37606. {
  37607. const ItemInfo* const item = getItemForIndex (index);
  37608. return (item != 0) ? item->itemId : 0;
  37609. }
  37610. int ComboBox::indexOfItemId (const int itemId) const throw()
  37611. {
  37612. int n = 0;
  37613. for (int i = 0; i < items.size(); ++i)
  37614. {
  37615. const ItemInfo* const item = items.getUnchecked(i);
  37616. if (item->isRealItem())
  37617. {
  37618. if (item->itemId == itemId)
  37619. return n;
  37620. ++n;
  37621. }
  37622. }
  37623. return -1;
  37624. }
  37625. int ComboBox::getSelectedItemIndex() const throw()
  37626. {
  37627. int index = indexOfItemId (currentId.getValue());
  37628. if (getText() != getItemText (index))
  37629. index = -1;
  37630. return index;
  37631. }
  37632. void ComboBox::setSelectedItemIndex (const int index,
  37633. const bool dontSendChangeMessage) throw()
  37634. {
  37635. setSelectedId (getItemId (index), dontSendChangeMessage);
  37636. }
  37637. int ComboBox::getSelectedId() const throw()
  37638. {
  37639. const ItemInfo* const item = getItemForId (currentId.getValue());
  37640. return (item != 0 && getText() == item->name)
  37641. ? item->itemId
  37642. : 0;
  37643. }
  37644. void ComboBox::setSelectedId (const int newItemId,
  37645. const bool dontSendChangeMessage) throw()
  37646. {
  37647. const ItemInfo* const item = getItemForId (newItemId);
  37648. const String newItemText (item != 0 ? item->name : String::empty);
  37649. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37650. {
  37651. if (! dontSendChangeMessage)
  37652. triggerAsyncUpdate();
  37653. label->setText (newItemText, false);
  37654. lastCurrentId = newItemId;
  37655. currentId = newItemId;
  37656. repaint(); // for the benefit of the 'none selected' text
  37657. }
  37658. }
  37659. void ComboBox::valueChanged (Value&)
  37660. {
  37661. if (lastCurrentId != (int) currentId.getValue())
  37662. setSelectedId (currentId.getValue(), false);
  37663. }
  37664. const String ComboBox::getText() const throw()
  37665. {
  37666. return label->getText();
  37667. }
  37668. void ComboBox::setText (const String& newText,
  37669. const bool dontSendChangeMessage) throw()
  37670. {
  37671. for (int i = items.size(); --i >= 0;)
  37672. {
  37673. const ItemInfo* const item = items.getUnchecked(i);
  37674. if (item->isRealItem()
  37675. && item->name == newText)
  37676. {
  37677. setSelectedId (item->itemId, dontSendChangeMessage);
  37678. return;
  37679. }
  37680. }
  37681. lastCurrentId = 0;
  37682. currentId = 0;
  37683. if (label->getText() != newText)
  37684. {
  37685. label->setText (newText, false);
  37686. if (! dontSendChangeMessage)
  37687. triggerAsyncUpdate();
  37688. }
  37689. repaint();
  37690. }
  37691. void ComboBox::showEditor()
  37692. {
  37693. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37694. label->showEditor();
  37695. }
  37696. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37697. {
  37698. textWhenNothingSelected = newMessage;
  37699. repaint();
  37700. }
  37701. const String ComboBox::getTextWhenNothingSelected() const throw()
  37702. {
  37703. return textWhenNothingSelected;
  37704. }
  37705. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37706. {
  37707. noChoicesMessage = newMessage;
  37708. }
  37709. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37710. {
  37711. return noChoicesMessage;
  37712. }
  37713. void ComboBox::paint (Graphics& g)
  37714. {
  37715. getLookAndFeel().drawComboBox (g,
  37716. getWidth(),
  37717. getHeight(),
  37718. isButtonDown,
  37719. label->getRight(),
  37720. 0,
  37721. getWidth() - label->getRight(),
  37722. getHeight(),
  37723. *this);
  37724. if (textWhenNothingSelected.isNotEmpty()
  37725. && label->getText().isEmpty()
  37726. && ! label->isBeingEdited())
  37727. {
  37728. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37729. g.setFont (label->getFont());
  37730. g.drawFittedText (textWhenNothingSelected,
  37731. label->getX() + 2, label->getY() + 1,
  37732. label->getWidth() - 4, label->getHeight() - 2,
  37733. label->getJustificationType(),
  37734. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37735. }
  37736. }
  37737. void ComboBox::resized()
  37738. {
  37739. if (getHeight() > 0 && getWidth() > 0)
  37740. getLookAndFeel().positionComboBoxText (*this, *label);
  37741. }
  37742. void ComboBox::enablementChanged()
  37743. {
  37744. repaint();
  37745. }
  37746. void ComboBox::lookAndFeelChanged()
  37747. {
  37748. repaint();
  37749. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37750. if (label != 0)
  37751. {
  37752. newLabel->setEditable (label->isEditable());
  37753. newLabel->setJustificationType (label->getJustificationType());
  37754. newLabel->setTooltip (label->getTooltip());
  37755. newLabel->setText (label->getText(), false);
  37756. }
  37757. delete label;
  37758. label = newLabel;
  37759. addAndMakeVisible (newLabel);
  37760. newLabel->addListener (this);
  37761. newLabel->addMouseListener (this, false);
  37762. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37763. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37764. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37765. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37766. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37767. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37768. resized();
  37769. }
  37770. void ComboBox::colourChanged()
  37771. {
  37772. lookAndFeelChanged();
  37773. }
  37774. bool ComboBox::keyPressed (const KeyPress& key)
  37775. {
  37776. bool used = false;
  37777. if (key.isKeyCode (KeyPress::upKey)
  37778. || key.isKeyCode (KeyPress::leftKey))
  37779. {
  37780. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37781. used = true;
  37782. }
  37783. else if (key.isKeyCode (KeyPress::downKey)
  37784. || key.isKeyCode (KeyPress::rightKey))
  37785. {
  37786. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37787. used = true;
  37788. }
  37789. else if (key.isKeyCode (KeyPress::returnKey))
  37790. {
  37791. showPopup();
  37792. used = true;
  37793. }
  37794. return used;
  37795. }
  37796. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37797. {
  37798. // only forward key events that aren't used by this component
  37799. return isKeyDown
  37800. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37801. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37802. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37803. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37804. }
  37805. void ComboBox::focusGained (FocusChangeType)
  37806. {
  37807. repaint();
  37808. }
  37809. void ComboBox::focusLost (FocusChangeType)
  37810. {
  37811. repaint();
  37812. }
  37813. void ComboBox::labelTextChanged (Label*)
  37814. {
  37815. triggerAsyncUpdate();
  37816. }
  37817. void ComboBox::showPopup()
  37818. {
  37819. if (! menuActive)
  37820. {
  37821. const int selectedId = getSelectedId();
  37822. ComponentDeletionWatcher deletionWatcher (this);
  37823. PopupMenu menu;
  37824. menu.setLookAndFeel (&getLookAndFeel());
  37825. for (int i = 0; i < items.size(); ++i)
  37826. {
  37827. const ItemInfo* const item = items.getUnchecked(i);
  37828. if (item->isSeparator())
  37829. menu.addSeparator();
  37830. else if (item->isHeading)
  37831. menu.addSectionHeader (item->name);
  37832. else
  37833. menu.addItem (item->itemId, item->name,
  37834. item->isEnabled, item->itemId == selectedId);
  37835. }
  37836. if (items.size() == 0)
  37837. menu.addItem (1, noChoicesMessage, false);
  37838. const int itemHeight = jlimit (12, 24, getHeight());
  37839. menuActive = true;
  37840. const int resultId = menu.showAt (this, selectedId,
  37841. getWidth(), 1, itemHeight);
  37842. if (deletionWatcher.hasBeenDeleted())
  37843. return;
  37844. menuActive = false;
  37845. if (resultId != 0)
  37846. setSelectedId (resultId);
  37847. }
  37848. }
  37849. void ComboBox::mouseDown (const MouseEvent& e)
  37850. {
  37851. beginDragAutoRepeat (300);
  37852. isButtonDown = isEnabled();
  37853. if (isButtonDown
  37854. && (e.eventComponent == this || ! label->isEditable()))
  37855. {
  37856. showPopup();
  37857. }
  37858. }
  37859. void ComboBox::mouseDrag (const MouseEvent& e)
  37860. {
  37861. beginDragAutoRepeat (50);
  37862. if (isButtonDown && ! e.mouseWasClicked())
  37863. showPopup();
  37864. }
  37865. void ComboBox::mouseUp (const MouseEvent& e2)
  37866. {
  37867. if (isButtonDown)
  37868. {
  37869. isButtonDown = false;
  37870. repaint();
  37871. const MouseEvent e (e2.getEventRelativeTo (this));
  37872. if (reallyContains (e.x, e.y, true)
  37873. && (e2.eventComponent == this || ! label->isEditable()))
  37874. {
  37875. showPopup();
  37876. }
  37877. }
  37878. }
  37879. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37880. {
  37881. jassert (listener != 0);
  37882. if (listener != 0)
  37883. listeners.add (listener);
  37884. }
  37885. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37886. {
  37887. listeners.removeValue (listener);
  37888. }
  37889. void ComboBox::handleAsyncUpdate()
  37890. {
  37891. for (int i = listeners.size(); --i >= 0;)
  37892. {
  37893. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37894. i = jmin (i, listeners.size());
  37895. }
  37896. }
  37897. END_JUCE_NAMESPACE
  37898. /*** End of inlined file: juce_ComboBox.cpp ***/
  37899. /*** Start of inlined file: juce_Label.cpp ***/
  37900. BEGIN_JUCE_NAMESPACE
  37901. Label::Label (const String& componentName,
  37902. const String& labelText)
  37903. : Component (componentName),
  37904. textValue (labelText),
  37905. lastTextValue (labelText),
  37906. font (15.0f),
  37907. justification (Justification::centredLeft),
  37908. ownerComponent (0),
  37909. horizontalBorderSize (5),
  37910. verticalBorderSize (1),
  37911. minimumHorizontalScale (0.7f),
  37912. editSingleClick (false),
  37913. editDoubleClick (false),
  37914. lossOfFocusDiscardsChanges (false)
  37915. {
  37916. setColour (TextEditor::textColourId, Colours::black);
  37917. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37918. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37919. textValue.addListener (this);
  37920. }
  37921. Label::~Label()
  37922. {
  37923. textValue.removeListener (this);
  37924. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37925. ownerComponent->removeComponentListener (this);
  37926. editor = 0;
  37927. }
  37928. void Label::setText (const String& newText,
  37929. const bool broadcastChangeMessage)
  37930. {
  37931. hideEditor (true);
  37932. if (lastTextValue != newText)
  37933. {
  37934. lastTextValue = newText;
  37935. textValue = newText;
  37936. repaint();
  37937. textWasChanged();
  37938. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37939. componentMovedOrResized (*ownerComponent, true, true);
  37940. if (broadcastChangeMessage)
  37941. callChangeListeners();
  37942. }
  37943. }
  37944. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37945. {
  37946. return (returnActiveEditorContents && isBeingEdited())
  37947. ? editor->getText()
  37948. : textValue.toString();
  37949. }
  37950. void Label::valueChanged (Value&)
  37951. {
  37952. if (lastTextValue != textValue.toString())
  37953. setText (textValue.toString(), true);
  37954. }
  37955. void Label::setFont (const Font& newFont) throw()
  37956. {
  37957. font = newFont;
  37958. repaint();
  37959. }
  37960. const Font& Label::getFont() const throw()
  37961. {
  37962. return font;
  37963. }
  37964. void Label::setEditable (const bool editOnSingleClick,
  37965. const bool editOnDoubleClick,
  37966. const bool lossOfFocusDiscardsChanges_) throw()
  37967. {
  37968. editSingleClick = editOnSingleClick;
  37969. editDoubleClick = editOnDoubleClick;
  37970. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37971. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37972. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37973. }
  37974. void Label::setJustificationType (const Justification& justification_) throw()
  37975. {
  37976. justification = justification_;
  37977. repaint();
  37978. }
  37979. void Label::setBorderSize (int h, int v)
  37980. {
  37981. horizontalBorderSize = h;
  37982. verticalBorderSize = v;
  37983. repaint();
  37984. }
  37985. void Label::attachToComponent (Component* owner,
  37986. const bool onLeft)
  37987. {
  37988. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37989. ownerComponent->removeComponentListener (this);
  37990. deletionWatcher = 0;
  37991. ownerComponent = owner;
  37992. leftOfOwnerComp = onLeft;
  37993. if (ownerComponent != 0)
  37994. {
  37995. deletionWatcher = new ComponentDeletionWatcher (owner);
  37996. setVisible (owner->isVisible());
  37997. ownerComponent->addComponentListener (this);
  37998. componentParentHierarchyChanged (*ownerComponent);
  37999. componentMovedOrResized (*ownerComponent, true, true);
  38000. }
  38001. }
  38002. void Label::componentMovedOrResized (Component& component,
  38003. bool /*wasMoved*/,
  38004. bool /*wasResized*/)
  38005. {
  38006. if (leftOfOwnerComp)
  38007. {
  38008. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  38009. component.getHeight());
  38010. setTopRightPosition (component.getX(), component.getY());
  38011. }
  38012. else
  38013. {
  38014. setSize (component.getWidth(),
  38015. 8 + roundToInt (getFont().getHeight()));
  38016. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  38017. }
  38018. }
  38019. void Label::componentParentHierarchyChanged (Component& component)
  38020. {
  38021. if (component.getParentComponent() != 0)
  38022. component.getParentComponent()->addChildComponent (this);
  38023. }
  38024. void Label::componentVisibilityChanged (Component& component)
  38025. {
  38026. setVisible (component.isVisible());
  38027. }
  38028. void Label::textWasEdited()
  38029. {
  38030. }
  38031. void Label::textWasChanged()
  38032. {
  38033. }
  38034. void Label::showEditor()
  38035. {
  38036. if (editor == 0)
  38037. {
  38038. addAndMakeVisible (editor = createEditorComponent());
  38039. editor->setText (getText(), false);
  38040. editor->addListener (this);
  38041. editor->grabKeyboardFocus();
  38042. editor->setHighlightedRegion (0, textValue.toString().length());
  38043. editor->addListener (this);
  38044. resized();
  38045. repaint();
  38046. editorShown (editor);
  38047. enterModalState();
  38048. editor->grabKeyboardFocus();
  38049. }
  38050. }
  38051. void Label::editorShown (TextEditor* /*editorComponent*/)
  38052. {
  38053. }
  38054. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  38055. {
  38056. }
  38057. bool Label::updateFromTextEditorContents()
  38058. {
  38059. jassert (editor != 0);
  38060. const String newText (editor->getText());
  38061. if (textValue.toString() != newText)
  38062. {
  38063. lastTextValue = newText;
  38064. textValue = newText;
  38065. repaint();
  38066. textWasChanged();
  38067. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38068. componentMovedOrResized (*ownerComponent, true, true);
  38069. return true;
  38070. }
  38071. return false;
  38072. }
  38073. void Label::hideEditor (const bool discardCurrentEditorContents)
  38074. {
  38075. if (editor != 0)
  38076. {
  38077. editorAboutToBeHidden (editor);
  38078. const bool changed = (! discardCurrentEditorContents)
  38079. && updateFromTextEditorContents();
  38080. editor = 0;
  38081. repaint();
  38082. if (changed)
  38083. textWasEdited();
  38084. exitModalState (0);
  38085. if (changed && isValidComponent())
  38086. callChangeListeners();
  38087. }
  38088. }
  38089. void Label::inputAttemptWhenModal()
  38090. {
  38091. if (editor != 0)
  38092. {
  38093. if (lossOfFocusDiscardsChanges)
  38094. textEditorEscapeKeyPressed (*editor);
  38095. else
  38096. textEditorReturnKeyPressed (*editor);
  38097. }
  38098. }
  38099. bool Label::isBeingEdited() const throw()
  38100. {
  38101. return editor != 0;
  38102. }
  38103. TextEditor* Label::createEditorComponent()
  38104. {
  38105. TextEditor* const ed = new TextEditor (getName());
  38106. ed->setFont (font);
  38107. // copy these colours from our own settings..
  38108. const int cols[] = { TextEditor::backgroundColourId,
  38109. TextEditor::textColourId,
  38110. TextEditor::highlightColourId,
  38111. TextEditor::highlightedTextColourId,
  38112. TextEditor::caretColourId,
  38113. TextEditor::outlineColourId,
  38114. TextEditor::focusedOutlineColourId,
  38115. TextEditor::shadowColourId };
  38116. for (int i = 0; i < numElementsInArray (cols); ++i)
  38117. ed->setColour (cols[i], findColour (cols[i]));
  38118. return ed;
  38119. }
  38120. void Label::paint (Graphics& g)
  38121. {
  38122. getLookAndFeel().drawLabel (g, *this);
  38123. }
  38124. void Label::mouseUp (const MouseEvent& e)
  38125. {
  38126. if (editSingleClick
  38127. && e.mouseWasClicked()
  38128. && contains (e.x, e.y)
  38129. && ! e.mods.isPopupMenu())
  38130. {
  38131. showEditor();
  38132. }
  38133. }
  38134. void Label::mouseDoubleClick (const MouseEvent& e)
  38135. {
  38136. if (editDoubleClick && ! e.mods.isPopupMenu())
  38137. showEditor();
  38138. }
  38139. void Label::resized()
  38140. {
  38141. if (editor != 0)
  38142. editor->setBoundsInset (BorderSize (0));
  38143. }
  38144. void Label::focusGained (FocusChangeType cause)
  38145. {
  38146. if (editSingleClick && cause == focusChangedByTabKey)
  38147. showEditor();
  38148. }
  38149. void Label::enablementChanged()
  38150. {
  38151. repaint();
  38152. }
  38153. void Label::colourChanged()
  38154. {
  38155. repaint();
  38156. }
  38157. void Label::setMinimumHorizontalScale (const float newScale)
  38158. {
  38159. if (minimumHorizontalScale != newScale)
  38160. {
  38161. minimumHorizontalScale = newScale;
  38162. repaint();
  38163. }
  38164. }
  38165. // We'll use a custom focus traverser here to make sure focus goes from the
  38166. // text editor to another component rather than back to the label itself.
  38167. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38168. {
  38169. public:
  38170. LabelKeyboardFocusTraverser() {}
  38171. Component* getNextComponent (Component* current)
  38172. {
  38173. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38174. ? current->getParentComponent() : current);
  38175. }
  38176. Component* getPreviousComponent (Component* current)
  38177. {
  38178. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38179. ? current->getParentComponent() : current);
  38180. }
  38181. };
  38182. KeyboardFocusTraverser* Label::createFocusTraverser()
  38183. {
  38184. return new LabelKeyboardFocusTraverser();
  38185. }
  38186. void Label::addListener (LabelListener* const listener) throw()
  38187. {
  38188. jassert (listener != 0);
  38189. if (listener != 0)
  38190. listeners.add (listener);
  38191. }
  38192. void Label::removeListener (LabelListener* const listener) throw()
  38193. {
  38194. listeners.removeValue (listener);
  38195. }
  38196. void Label::callChangeListeners()
  38197. {
  38198. for (int i = listeners.size(); --i >= 0;)
  38199. {
  38200. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38201. i = jmin (i, listeners.size());
  38202. }
  38203. }
  38204. void Label::textEditorTextChanged (TextEditor& ed)
  38205. {
  38206. if (editor != 0)
  38207. {
  38208. jassert (&ed == editor);
  38209. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38210. {
  38211. if (lossOfFocusDiscardsChanges)
  38212. textEditorEscapeKeyPressed (ed);
  38213. else
  38214. textEditorReturnKeyPressed (ed);
  38215. }
  38216. }
  38217. }
  38218. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38219. {
  38220. if (editor != 0)
  38221. {
  38222. jassert (&ed == editor);
  38223. (void) ed;
  38224. const bool changed = updateFromTextEditorContents();
  38225. hideEditor (true);
  38226. if (changed)
  38227. {
  38228. textWasEdited();
  38229. if (isValidComponent())
  38230. callChangeListeners();
  38231. }
  38232. }
  38233. }
  38234. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38235. {
  38236. if (editor != 0)
  38237. {
  38238. jassert (&ed == editor);
  38239. (void) ed;
  38240. editor->setText (textValue.toString(), false);
  38241. hideEditor (true);
  38242. }
  38243. }
  38244. void Label::textEditorFocusLost (TextEditor& ed)
  38245. {
  38246. textEditorTextChanged (ed);
  38247. }
  38248. END_JUCE_NAMESPACE
  38249. /*** End of inlined file: juce_Label.cpp ***/
  38250. /*** Start of inlined file: juce_ListBox.cpp ***/
  38251. BEGIN_JUCE_NAMESPACE
  38252. class ListBoxRowComponent : public Component,
  38253. public TooltipClient
  38254. {
  38255. public:
  38256. ListBoxRowComponent (ListBox& owner_)
  38257. : owner (owner_),
  38258. row (-1),
  38259. selected (false),
  38260. isDragging (false)
  38261. {
  38262. }
  38263. ~ListBoxRowComponent()
  38264. {
  38265. deleteAllChildren();
  38266. }
  38267. void paint (Graphics& g)
  38268. {
  38269. if (owner.getModel() != 0)
  38270. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38271. }
  38272. void update (const int row_, const bool selected_)
  38273. {
  38274. if (row != row_ || selected != selected_)
  38275. {
  38276. repaint();
  38277. row = row_;
  38278. selected = selected_;
  38279. }
  38280. if (owner.getModel() != 0)
  38281. {
  38282. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38283. if (customComp != 0)
  38284. {
  38285. addAndMakeVisible (customComp);
  38286. customComp->setBounds (0, 0, getWidth(), getHeight());
  38287. for (int i = getNumChildComponents(); --i >= 0;)
  38288. if (getChildComponent (i) != customComp)
  38289. delete getChildComponent (i);
  38290. }
  38291. else
  38292. {
  38293. deleteAllChildren();
  38294. }
  38295. }
  38296. }
  38297. void mouseDown (const MouseEvent& e)
  38298. {
  38299. isDragging = false;
  38300. selectRowOnMouseUp = false;
  38301. if (isEnabled())
  38302. {
  38303. if (! selected)
  38304. {
  38305. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38306. if (owner.getModel() != 0)
  38307. owner.getModel()->listBoxItemClicked (row, e);
  38308. }
  38309. else
  38310. {
  38311. selectRowOnMouseUp = true;
  38312. }
  38313. }
  38314. }
  38315. void mouseUp (const MouseEvent& e)
  38316. {
  38317. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38318. {
  38319. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38320. if (owner.getModel() != 0)
  38321. owner.getModel()->listBoxItemClicked (row, e);
  38322. }
  38323. }
  38324. void mouseDoubleClick (const MouseEvent& e)
  38325. {
  38326. if (owner.getModel() != 0 && isEnabled())
  38327. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38328. }
  38329. void mouseDrag (const MouseEvent& e)
  38330. {
  38331. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38332. {
  38333. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38334. if (selectedRows.size() > 0)
  38335. {
  38336. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38337. if (dragDescription.isNotEmpty())
  38338. {
  38339. isDragging = true;
  38340. owner.startDragAndDrop (e, dragDescription);
  38341. }
  38342. }
  38343. }
  38344. }
  38345. void resized()
  38346. {
  38347. if (getNumChildComponents() > 0)
  38348. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38349. }
  38350. const String getTooltip()
  38351. {
  38352. if (owner.getModel() != 0)
  38353. return owner.getModel()->getTooltipForRow (row);
  38354. return String::empty;
  38355. }
  38356. juce_UseDebuggingNewOperator
  38357. bool neededFlag;
  38358. private:
  38359. ListBox& owner;
  38360. int row;
  38361. bool selected, isDragging, selectRowOnMouseUp;
  38362. ListBoxRowComponent (const ListBoxRowComponent&);
  38363. const ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38364. };
  38365. class ListViewport : public Viewport
  38366. {
  38367. public:
  38368. int firstIndex, firstWholeIndex, lastWholeIndex;
  38369. bool hasUpdated;
  38370. ListViewport (ListBox& owner_)
  38371. : owner (owner_)
  38372. {
  38373. setWantsKeyboardFocus (false);
  38374. setViewedComponent (new Component());
  38375. getViewedComponent()->addMouseListener (this, false);
  38376. getViewedComponent()->setWantsKeyboardFocus (false);
  38377. }
  38378. ~ListViewport()
  38379. {
  38380. getViewedComponent()->removeMouseListener (this);
  38381. getViewedComponent()->deleteAllChildren();
  38382. }
  38383. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38384. {
  38385. return (ListBoxRowComponent*) getViewedComponent()
  38386. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38387. }
  38388. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38389. {
  38390. const int index = getIndexOfChildComponent (rowComponent);
  38391. const int num = getViewedComponent()->getNumChildComponents();
  38392. for (int i = num; --i >= 0;)
  38393. if (((firstIndex + i) % jmax (1, num)) == index)
  38394. return firstIndex + i;
  38395. return -1;
  38396. }
  38397. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38398. {
  38399. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38400. ? getComponentForRow (row) : 0;
  38401. }
  38402. void visibleAreaChanged (int, int, int, int)
  38403. {
  38404. updateVisibleArea (true);
  38405. if (owner.getModel() != 0)
  38406. owner.getModel()->listWasScrolled();
  38407. }
  38408. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38409. {
  38410. hasUpdated = false;
  38411. const int newX = getViewedComponent()->getX();
  38412. int newY = getViewedComponent()->getY();
  38413. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38414. const int newH = owner.totalItems * owner.getRowHeight();
  38415. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38416. newY = getMaximumVisibleHeight() - newH;
  38417. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38418. if (makeSureItUpdatesContent && ! hasUpdated)
  38419. updateContents();
  38420. }
  38421. void updateContents()
  38422. {
  38423. hasUpdated = true;
  38424. const int rowHeight = owner.getRowHeight();
  38425. if (rowHeight > 0)
  38426. {
  38427. const int y = getViewPositionY();
  38428. const int w = getViewedComponent()->getWidth();
  38429. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38430. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38431. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38432. jassert (numNeeded >= 0);
  38433. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38434. {
  38435. Component* const rowToRemove
  38436. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38437. delete rowToRemove;
  38438. }
  38439. firstIndex = y / rowHeight;
  38440. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38441. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38442. for (int i = 0; i < numNeeded; ++i)
  38443. {
  38444. const int row = i + firstIndex;
  38445. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38446. if (rowComp != 0)
  38447. {
  38448. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38449. rowComp->update (row, owner.isRowSelected (row));
  38450. }
  38451. }
  38452. }
  38453. if (owner.headerComponent != 0)
  38454. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38455. owner.outlineThickness,
  38456. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38457. getViewedComponent()->getWidth()),
  38458. owner.headerComponent->getHeight());
  38459. }
  38460. void paint (Graphics& g)
  38461. {
  38462. if (isOpaque())
  38463. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38464. }
  38465. bool keyPressed (const KeyPress& key)
  38466. {
  38467. if (key.isKeyCode (KeyPress::upKey)
  38468. || key.isKeyCode (KeyPress::downKey)
  38469. || key.isKeyCode (KeyPress::pageUpKey)
  38470. || key.isKeyCode (KeyPress::pageDownKey)
  38471. || key.isKeyCode (KeyPress::homeKey)
  38472. || key.isKeyCode (KeyPress::endKey))
  38473. {
  38474. // we want to avoid these keypresses going to the viewport, and instead allow
  38475. // them to pass up to our listbox..
  38476. return false;
  38477. }
  38478. return Viewport::keyPressed (key);
  38479. }
  38480. juce_UseDebuggingNewOperator
  38481. private:
  38482. ListBox& owner;
  38483. ListViewport (const ListViewport&);
  38484. const ListViewport& operator= (const ListViewport&);
  38485. };
  38486. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38487. : Component (name),
  38488. model (model_),
  38489. headerComponent (0),
  38490. totalItems (0),
  38491. rowHeight (22),
  38492. minimumRowWidth (0),
  38493. outlineThickness (0),
  38494. lastRowSelected (-1),
  38495. mouseMoveSelects (false),
  38496. multipleSelection (false),
  38497. hasDoneInitialUpdate (false)
  38498. {
  38499. addAndMakeVisible (viewport = new ListViewport (*this));
  38500. setWantsKeyboardFocus (true);
  38501. colourChanged();
  38502. }
  38503. ListBox::~ListBox()
  38504. {
  38505. deleteAllChildren();
  38506. }
  38507. void ListBox::setModel (ListBoxModel* const newModel)
  38508. {
  38509. if (model != newModel)
  38510. {
  38511. model = newModel;
  38512. updateContent();
  38513. }
  38514. }
  38515. void ListBox::setMultipleSelectionEnabled (bool b)
  38516. {
  38517. multipleSelection = b;
  38518. }
  38519. void ListBox::setMouseMoveSelectsRows (bool b)
  38520. {
  38521. mouseMoveSelects = b;
  38522. if (b)
  38523. addMouseListener (this, true);
  38524. }
  38525. void ListBox::paint (Graphics& g)
  38526. {
  38527. if (! hasDoneInitialUpdate)
  38528. updateContent();
  38529. g.fillAll (findColour (backgroundColourId));
  38530. }
  38531. void ListBox::paintOverChildren (Graphics& g)
  38532. {
  38533. if (outlineThickness > 0)
  38534. {
  38535. g.setColour (findColour (outlineColourId));
  38536. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38537. }
  38538. }
  38539. void ListBox::resized()
  38540. {
  38541. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38542. outlineThickness,
  38543. outlineThickness,
  38544. outlineThickness));
  38545. viewport->setSingleStepSizes (20, getRowHeight());
  38546. viewport->updateVisibleArea (false);
  38547. }
  38548. void ListBox::visibilityChanged()
  38549. {
  38550. viewport->updateVisibleArea (true);
  38551. }
  38552. Viewport* ListBox::getViewport() const throw()
  38553. {
  38554. return viewport;
  38555. }
  38556. void ListBox::updateContent()
  38557. {
  38558. hasDoneInitialUpdate = true;
  38559. totalItems = (model != 0) ? model->getNumRows() : 0;
  38560. bool selectionChanged = false;
  38561. if (selected [selected.size() - 1] >= totalItems)
  38562. {
  38563. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38564. lastRowSelected = getSelectedRow (0);
  38565. selectionChanged = true;
  38566. }
  38567. viewport->updateVisibleArea (isVisible());
  38568. viewport->resized();
  38569. if (selectionChanged && model != 0)
  38570. model->selectedRowsChanged (lastRowSelected);
  38571. }
  38572. void ListBox::selectRow (const int row,
  38573. bool dontScroll,
  38574. bool deselectOthersFirst)
  38575. {
  38576. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38577. }
  38578. void ListBox::selectRowInternal (const int row,
  38579. bool dontScroll,
  38580. bool deselectOthersFirst,
  38581. bool isMouseClick)
  38582. {
  38583. if (! multipleSelection)
  38584. deselectOthersFirst = true;
  38585. if ((! isRowSelected (row))
  38586. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38587. {
  38588. if (((unsigned int) row) < (unsigned int) totalItems)
  38589. {
  38590. if (deselectOthersFirst)
  38591. selected.clear();
  38592. selected.addRange (row, 1);
  38593. if (getHeight() == 0 || getWidth() == 0)
  38594. dontScroll = true;
  38595. viewport->hasUpdated = false;
  38596. if (row < viewport->firstWholeIndex && ! dontScroll)
  38597. {
  38598. viewport->setViewPosition (viewport->getViewPositionX(),
  38599. row * getRowHeight());
  38600. }
  38601. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38602. {
  38603. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38604. if (row >= lastRowSelected + rowsOnScreen
  38605. && rowsOnScreen < totalItems - 1
  38606. && ! isMouseClick)
  38607. {
  38608. viewport->setViewPosition (viewport->getViewPositionX(),
  38609. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38610. * getRowHeight());
  38611. }
  38612. else
  38613. {
  38614. viewport->setViewPosition (viewport->getViewPositionX(),
  38615. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38616. }
  38617. }
  38618. if (! viewport->hasUpdated)
  38619. viewport->updateContents();
  38620. lastRowSelected = row;
  38621. model->selectedRowsChanged (row);
  38622. }
  38623. else
  38624. {
  38625. if (deselectOthersFirst)
  38626. deselectAllRows();
  38627. }
  38628. }
  38629. }
  38630. void ListBox::deselectRow (const int row)
  38631. {
  38632. if (selected.contains (row))
  38633. {
  38634. selected.removeRange (row, 1);
  38635. if (row == lastRowSelected)
  38636. lastRowSelected = getSelectedRow (0);
  38637. viewport->updateContents();
  38638. model->selectedRowsChanged (lastRowSelected);
  38639. }
  38640. }
  38641. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38642. const bool sendNotificationEventToModel)
  38643. {
  38644. selected = setOfRowsToBeSelected;
  38645. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38646. if (! isRowSelected (lastRowSelected))
  38647. lastRowSelected = getSelectedRow (0);
  38648. viewport->updateContents();
  38649. if ((model != 0) && sendNotificationEventToModel)
  38650. model->selectedRowsChanged (lastRowSelected);
  38651. }
  38652. const SparseSet<int> ListBox::getSelectedRows() const
  38653. {
  38654. return selected;
  38655. }
  38656. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38657. {
  38658. if (multipleSelection && (firstRow != lastRow))
  38659. {
  38660. const int numRows = totalItems - 1;
  38661. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38662. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38663. selected.addRange (jmin (firstRow, lastRow),
  38664. abs (firstRow - lastRow) + 1);
  38665. selected.removeRange (lastRow, 1);
  38666. }
  38667. selectRowInternal (lastRow, false, false, true);
  38668. }
  38669. void ListBox::flipRowSelection (const int row)
  38670. {
  38671. if (isRowSelected (row))
  38672. deselectRow (row);
  38673. else
  38674. selectRowInternal (row, false, false, true);
  38675. }
  38676. void ListBox::deselectAllRows()
  38677. {
  38678. if (! selected.isEmpty())
  38679. {
  38680. selected.clear();
  38681. lastRowSelected = -1;
  38682. viewport->updateContents();
  38683. if (model != 0)
  38684. model->selectedRowsChanged (lastRowSelected);
  38685. }
  38686. }
  38687. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38688. const ModifierKeys& mods)
  38689. {
  38690. if (multipleSelection && mods.isCommandDown())
  38691. {
  38692. flipRowSelection (row);
  38693. }
  38694. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38695. {
  38696. selectRangeOfRows (lastRowSelected, row);
  38697. }
  38698. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38699. {
  38700. selectRowInternal (row, false, true, true);
  38701. }
  38702. }
  38703. int ListBox::getNumSelectedRows() const
  38704. {
  38705. return selected.size();
  38706. }
  38707. int ListBox::getSelectedRow (const int index) const
  38708. {
  38709. return (((unsigned int) index) < (unsigned int) selected.size())
  38710. ? selected [index] : -1;
  38711. }
  38712. bool ListBox::isRowSelected (const int row) const
  38713. {
  38714. return selected.contains (row);
  38715. }
  38716. int ListBox::getLastRowSelected() const
  38717. {
  38718. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38719. }
  38720. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38721. {
  38722. if (((unsigned int) x) < (unsigned int) getWidth())
  38723. {
  38724. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38725. if (((unsigned int) row) < (unsigned int) totalItems)
  38726. return row;
  38727. }
  38728. return -1;
  38729. }
  38730. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38731. {
  38732. if (((unsigned int) x) < (unsigned int) getWidth())
  38733. {
  38734. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38735. return jlimit (0, totalItems, row);
  38736. }
  38737. return -1;
  38738. }
  38739. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38740. {
  38741. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38742. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38743. }
  38744. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38745. {
  38746. return viewport->getRowNumberOfComponent (rowComponent);
  38747. }
  38748. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38749. const bool relativeToComponentTopLeft) const throw()
  38750. {
  38751. const int rowHeight = getRowHeight();
  38752. int y = viewport->getY() + rowHeight * rowNumber;
  38753. if (relativeToComponentTopLeft)
  38754. y -= viewport->getViewPositionY();
  38755. return Rectangle<int> (viewport->getX(), y,
  38756. viewport->getViewedComponent()->getWidth(), rowHeight);
  38757. }
  38758. void ListBox::setVerticalPosition (const double proportion)
  38759. {
  38760. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38761. viewport->setViewPosition (viewport->getViewPositionX(),
  38762. jmax (0, roundToInt (proportion * offscreen)));
  38763. }
  38764. double ListBox::getVerticalPosition() const
  38765. {
  38766. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38767. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38768. : 0;
  38769. }
  38770. int ListBox::getVisibleRowWidth() const throw()
  38771. {
  38772. return viewport->getViewWidth();
  38773. }
  38774. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38775. {
  38776. if (row < viewport->firstWholeIndex)
  38777. {
  38778. viewport->setViewPosition (viewport->getViewPositionX(),
  38779. row * getRowHeight());
  38780. }
  38781. else if (row >= viewport->lastWholeIndex)
  38782. {
  38783. viewport->setViewPosition (viewport->getViewPositionX(),
  38784. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38785. }
  38786. }
  38787. bool ListBox::keyPressed (const KeyPress& key)
  38788. {
  38789. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38790. const bool multiple = multipleSelection
  38791. && (lastRowSelected >= 0)
  38792. && (key.getModifiers().isShiftDown()
  38793. || key.getModifiers().isCtrlDown()
  38794. || key.getModifiers().isCommandDown());
  38795. if (key.isKeyCode (KeyPress::upKey))
  38796. {
  38797. if (multiple)
  38798. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38799. else
  38800. selectRow (jmax (0, lastRowSelected - 1));
  38801. }
  38802. else if (key.isKeyCode (KeyPress::returnKey)
  38803. && isRowSelected (lastRowSelected))
  38804. {
  38805. if (model != 0)
  38806. model->returnKeyPressed (lastRowSelected);
  38807. }
  38808. else if (key.isKeyCode (KeyPress::pageUpKey))
  38809. {
  38810. if (multiple)
  38811. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38812. else
  38813. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38814. }
  38815. else if (key.isKeyCode (KeyPress::pageDownKey))
  38816. {
  38817. if (multiple)
  38818. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38819. else
  38820. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38821. }
  38822. else if (key.isKeyCode (KeyPress::homeKey))
  38823. {
  38824. if (multiple && key.getModifiers().isShiftDown())
  38825. selectRangeOfRows (lastRowSelected, 0);
  38826. else
  38827. selectRow (0);
  38828. }
  38829. else if (key.isKeyCode (KeyPress::endKey))
  38830. {
  38831. if (multiple && key.getModifiers().isShiftDown())
  38832. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38833. else
  38834. selectRow (totalItems - 1);
  38835. }
  38836. else if (key.isKeyCode (KeyPress::downKey))
  38837. {
  38838. if (multiple)
  38839. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38840. else
  38841. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38842. }
  38843. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38844. && isRowSelected (lastRowSelected))
  38845. {
  38846. if (model != 0)
  38847. model->deleteKeyPressed (lastRowSelected);
  38848. }
  38849. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38850. {
  38851. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38852. }
  38853. else
  38854. {
  38855. return false;
  38856. }
  38857. return true;
  38858. }
  38859. bool ListBox::keyStateChanged (const bool isKeyDown)
  38860. {
  38861. return isKeyDown
  38862. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38863. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38864. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38865. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38866. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38867. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38868. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38869. }
  38870. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38871. {
  38872. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38873. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38874. }
  38875. void ListBox::mouseMove (const MouseEvent& e)
  38876. {
  38877. if (mouseMoveSelects)
  38878. {
  38879. const MouseEvent e2 (e.getEventRelativeTo (this));
  38880. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38881. lastMouseX = e2.x;
  38882. lastMouseY = e2.y;
  38883. }
  38884. }
  38885. void ListBox::mouseExit (const MouseEvent& e)
  38886. {
  38887. mouseMove (e);
  38888. }
  38889. void ListBox::mouseUp (const MouseEvent& e)
  38890. {
  38891. if (e.mouseWasClicked() && model != 0)
  38892. model->backgroundClicked();
  38893. }
  38894. void ListBox::setRowHeight (const int newHeight)
  38895. {
  38896. rowHeight = jmax (1, newHeight);
  38897. viewport->setSingleStepSizes (20, rowHeight);
  38898. updateContent();
  38899. }
  38900. int ListBox::getNumRowsOnScreen() const throw()
  38901. {
  38902. return viewport->getMaximumVisibleHeight() / rowHeight;
  38903. }
  38904. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38905. {
  38906. minimumRowWidth = newMinimumWidth;
  38907. updateContent();
  38908. }
  38909. int ListBox::getVisibleContentWidth() const throw()
  38910. {
  38911. return viewport->getMaximumVisibleWidth();
  38912. }
  38913. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38914. {
  38915. return viewport->getVerticalScrollBar();
  38916. }
  38917. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38918. {
  38919. return viewport->getHorizontalScrollBar();
  38920. }
  38921. void ListBox::colourChanged()
  38922. {
  38923. setOpaque (findColour (backgroundColourId).isOpaque());
  38924. viewport->setOpaque (isOpaque());
  38925. repaint();
  38926. }
  38927. void ListBox::setOutlineThickness (const int outlineThickness_)
  38928. {
  38929. outlineThickness = outlineThickness_;
  38930. resized();
  38931. }
  38932. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38933. {
  38934. if (headerComponent != newHeaderComponent)
  38935. {
  38936. delete headerComponent;
  38937. headerComponent = newHeaderComponent;
  38938. addAndMakeVisible (newHeaderComponent);
  38939. ListBox::resized();
  38940. }
  38941. }
  38942. void ListBox::repaintRow (const int rowNumber) throw()
  38943. {
  38944. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38945. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38946. }
  38947. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38948. {
  38949. Rectangle<int> imageArea;
  38950. const int firstRow = getRowContainingPosition (0, 0);
  38951. int i;
  38952. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38953. {
  38954. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38955. if (rowComp != 0 && isRowSelected (firstRow + i))
  38956. {
  38957. int x = 0, y = 0;
  38958. rowComp->relativePositionToOtherComponent (this, x, y);
  38959. const Rectangle<int> rowRect (x, y, rowComp->getWidth(), rowComp->getHeight());
  38960. if (imageArea.isEmpty())
  38961. imageArea = rowRect;
  38962. else
  38963. imageArea = imageArea.getUnion (rowRect);
  38964. }
  38965. }
  38966. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38967. imageX = imageArea.getX();
  38968. imageY = imageArea.getY();
  38969. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38970. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38971. {
  38972. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38973. if (rowComp != 0 && isRowSelected (firstRow + i))
  38974. {
  38975. int x = 0, y = 0;
  38976. rowComp->relativePositionToOtherComponent (this, x, y);
  38977. Graphics g (*snapshot);
  38978. g.setOrigin (x - imageX, y - imageY);
  38979. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38980. rowComp->paintEntireComponent (g);
  38981. }
  38982. }
  38983. return snapshot;
  38984. }
  38985. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38986. {
  38987. DragAndDropContainer* const dragContainer
  38988. = DragAndDropContainer::findParentDragContainerFor (this);
  38989. if (dragContainer != 0)
  38990. {
  38991. int x, y;
  38992. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38993. dragImage->multiplyAllAlphas (0.6f);
  38994. MouseEvent e2 (e.getEventRelativeTo (this));
  38995. const Point<int> p (x - e2.x, y - e2.y);
  38996. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38997. }
  38998. else
  38999. {
  39000. // to be able to do a drag-and-drop operation, the listbox needs to
  39001. // be inside a component which is also a DragAndDropContainer.
  39002. jassertfalse
  39003. }
  39004. }
  39005. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  39006. {
  39007. (void) existingComponentToUpdate;
  39008. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  39009. return 0;
  39010. }
  39011. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  39012. {
  39013. }
  39014. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  39015. {
  39016. }
  39017. void ListBoxModel::backgroundClicked()
  39018. {
  39019. }
  39020. void ListBoxModel::selectedRowsChanged (int)
  39021. {
  39022. }
  39023. void ListBoxModel::deleteKeyPressed (int)
  39024. {
  39025. }
  39026. void ListBoxModel::returnKeyPressed (int)
  39027. {
  39028. }
  39029. void ListBoxModel::listWasScrolled()
  39030. {
  39031. }
  39032. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  39033. {
  39034. return String::empty;
  39035. }
  39036. const String ListBoxModel::getTooltipForRow (int)
  39037. {
  39038. return String::empty;
  39039. }
  39040. END_JUCE_NAMESPACE
  39041. /*** End of inlined file: juce_ListBox.cpp ***/
  39042. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  39043. BEGIN_JUCE_NAMESPACE
  39044. ProgressBar::ProgressBar (double& progress_)
  39045. : progress (progress_),
  39046. displayPercentage (true),
  39047. lastCallbackTime (0)
  39048. {
  39049. currentValue = jlimit (0.0, 1.0, progress);
  39050. }
  39051. ProgressBar::~ProgressBar()
  39052. {
  39053. }
  39054. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  39055. {
  39056. displayPercentage = shouldDisplayPercentage;
  39057. repaint();
  39058. }
  39059. void ProgressBar::setTextToDisplay (const String& text)
  39060. {
  39061. displayPercentage = false;
  39062. displayedMessage = text;
  39063. }
  39064. void ProgressBar::lookAndFeelChanged()
  39065. {
  39066. setOpaque (findColour (backgroundColourId).isOpaque());
  39067. }
  39068. void ProgressBar::colourChanged()
  39069. {
  39070. lookAndFeelChanged();
  39071. }
  39072. void ProgressBar::paint (Graphics& g)
  39073. {
  39074. String text;
  39075. if (displayPercentage)
  39076. {
  39077. if (currentValue >= 0 && currentValue <= 1.0)
  39078. text << roundToInt (currentValue * 100.0) << T("%");
  39079. }
  39080. else
  39081. {
  39082. text = displayedMessage;
  39083. }
  39084. getLookAndFeel().drawProgressBar (g, *this,
  39085. getWidth(), getHeight(),
  39086. currentValue, text);
  39087. }
  39088. void ProgressBar::visibilityChanged()
  39089. {
  39090. if (isVisible())
  39091. startTimer (30);
  39092. else
  39093. stopTimer();
  39094. }
  39095. void ProgressBar::timerCallback()
  39096. {
  39097. double newProgress = progress;
  39098. const uint32 now = Time::getMillisecondCounter();
  39099. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39100. lastCallbackTime = now;
  39101. if (currentValue != newProgress
  39102. || newProgress < 0 || newProgress >= 1.0
  39103. || currentMessage != displayedMessage)
  39104. {
  39105. if (currentValue < newProgress
  39106. && newProgress >= 0 && newProgress < 1.0
  39107. && currentValue >= 0 && currentValue < 1.0)
  39108. {
  39109. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39110. newProgress);
  39111. }
  39112. currentValue = newProgress;
  39113. currentMessage = displayedMessage;
  39114. repaint();
  39115. }
  39116. }
  39117. END_JUCE_NAMESPACE
  39118. /*** End of inlined file: juce_ProgressBar.cpp ***/
  39119. /*** Start of inlined file: juce_Slider.cpp ***/
  39120. BEGIN_JUCE_NAMESPACE
  39121. class SliderPopupDisplayComponent : public BubbleComponent
  39122. {
  39123. public:
  39124. SliderPopupDisplayComponent (Slider* const owner_)
  39125. : owner (owner_),
  39126. font (15.0f, Font::bold)
  39127. {
  39128. setAlwaysOnTop (true);
  39129. }
  39130. ~SliderPopupDisplayComponent()
  39131. {
  39132. }
  39133. void paintContent (Graphics& g, int w, int h)
  39134. {
  39135. g.setFont (font);
  39136. g.setColour (Colours::black);
  39137. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39138. }
  39139. void getContentSize (int& w, int& h)
  39140. {
  39141. w = font.getStringWidth (text) + 18;
  39142. h = (int) (font.getHeight() * 1.6f);
  39143. }
  39144. void updatePosition (const String& newText)
  39145. {
  39146. if (text != newText)
  39147. {
  39148. text = newText;
  39149. repaint();
  39150. }
  39151. BubbleComponent::setPosition (owner);
  39152. }
  39153. juce_UseDebuggingNewOperator
  39154. private:
  39155. Slider* owner;
  39156. Font font;
  39157. String text;
  39158. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39159. const SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39160. };
  39161. Slider::Slider (const String& name)
  39162. : Component (name),
  39163. lastCurrentValue (0),
  39164. lastValueMin (0),
  39165. lastValueMax (0),
  39166. minimum (0),
  39167. maximum (10),
  39168. interval (0),
  39169. skewFactor (1.0),
  39170. velocityModeSensitivity (1.0),
  39171. velocityModeOffset (0.0),
  39172. velocityModeThreshold (1),
  39173. rotaryStart (float_Pi * 1.2f),
  39174. rotaryEnd (float_Pi * 2.8f),
  39175. numDecimalPlaces (7),
  39176. sliderRegionStart (0),
  39177. sliderRegionSize (1),
  39178. sliderBeingDragged (-1),
  39179. pixelsForFullDragExtent (250),
  39180. style (LinearHorizontal),
  39181. textBoxPos (TextBoxLeft),
  39182. textBoxWidth (80),
  39183. textBoxHeight (20),
  39184. incDecButtonMode (incDecButtonsNotDraggable),
  39185. editableText (true),
  39186. doubleClickToValue (false),
  39187. isVelocityBased (false),
  39188. userKeyOverridesVelocity (true),
  39189. rotaryStop (true),
  39190. incDecButtonsSideBySide (false),
  39191. sendChangeOnlyOnRelease (false),
  39192. popupDisplayEnabled (false),
  39193. menuEnabled (false),
  39194. menuShown (false),
  39195. scrollWheelEnabled (true),
  39196. snapsToMousePos (true),
  39197. valueBox (0),
  39198. incButton (0),
  39199. decButton (0),
  39200. popupDisplay (0),
  39201. parentForPopupDisplay (0)
  39202. {
  39203. setWantsKeyboardFocus (false);
  39204. setRepaintsOnMouseActivity (true);
  39205. lookAndFeelChanged();
  39206. updateText();
  39207. currentValue.addListener (this);
  39208. valueMin.addListener (this);
  39209. valueMax.addListener (this);
  39210. }
  39211. Slider::~Slider()
  39212. {
  39213. currentValue.removeListener (this);
  39214. valueMin.removeListener (this);
  39215. valueMax.removeListener (this);
  39216. popupDisplay = 0;
  39217. deleteAllChildren();
  39218. }
  39219. void Slider::handleAsyncUpdate()
  39220. {
  39221. cancelPendingUpdate();
  39222. for (int i = listeners.size(); --i >= 0;)
  39223. {
  39224. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39225. i = jmin (i, listeners.size());
  39226. }
  39227. }
  39228. void Slider::sendDragStart()
  39229. {
  39230. startedDragging();
  39231. for (int i = listeners.size(); --i >= 0;)
  39232. {
  39233. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39234. i = jmin (i, listeners.size());
  39235. }
  39236. }
  39237. void Slider::sendDragEnd()
  39238. {
  39239. stoppedDragging();
  39240. sliderBeingDragged = -1;
  39241. for (int i = listeners.size(); --i >= 0;)
  39242. {
  39243. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39244. i = jmin (i, listeners.size());
  39245. }
  39246. }
  39247. void Slider::addListener (SliderListener* const listener)
  39248. {
  39249. jassert (listener != 0);
  39250. if (listener != 0)
  39251. listeners.add (listener);
  39252. }
  39253. void Slider::removeListener (SliderListener* const listener)
  39254. {
  39255. listeners.removeValue (listener);
  39256. }
  39257. void Slider::setSliderStyle (const SliderStyle newStyle)
  39258. {
  39259. if (style != newStyle)
  39260. {
  39261. style = newStyle;
  39262. repaint();
  39263. lookAndFeelChanged();
  39264. }
  39265. }
  39266. void Slider::setRotaryParameters (const float startAngleRadians,
  39267. const float endAngleRadians,
  39268. const bool stopAtEnd)
  39269. {
  39270. // make sure the values are sensible..
  39271. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39272. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39273. jassert (rotaryStart < rotaryEnd);
  39274. rotaryStart = startAngleRadians;
  39275. rotaryEnd = endAngleRadians;
  39276. rotaryStop = stopAtEnd;
  39277. }
  39278. void Slider::setVelocityBasedMode (const bool velBased)
  39279. {
  39280. isVelocityBased = velBased;
  39281. }
  39282. void Slider::setVelocityModeParameters (const double sensitivity,
  39283. const int threshold,
  39284. const double offset,
  39285. const bool userCanPressKeyToSwapMode)
  39286. {
  39287. jassert (threshold >= 0);
  39288. jassert (sensitivity > 0);
  39289. jassert (offset >= 0);
  39290. velocityModeSensitivity = sensitivity;
  39291. velocityModeOffset = offset;
  39292. velocityModeThreshold = threshold;
  39293. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39294. }
  39295. void Slider::setSkewFactor (const double factor)
  39296. {
  39297. skewFactor = factor;
  39298. }
  39299. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39300. {
  39301. if (maximum > minimum)
  39302. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39303. / (maximum - minimum));
  39304. }
  39305. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39306. {
  39307. jassert (distanceForFullScaleDrag > 0);
  39308. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39309. }
  39310. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39311. {
  39312. if (incDecButtonMode != mode)
  39313. {
  39314. incDecButtonMode = mode;
  39315. lookAndFeelChanged();
  39316. }
  39317. }
  39318. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39319. const bool isReadOnly,
  39320. const int textEntryBoxWidth,
  39321. const int textEntryBoxHeight)
  39322. {
  39323. textBoxPos = newPosition;
  39324. editableText = ! isReadOnly;
  39325. textBoxWidth = textEntryBoxWidth;
  39326. textBoxHeight = textEntryBoxHeight;
  39327. repaint();
  39328. lookAndFeelChanged();
  39329. }
  39330. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39331. {
  39332. editableText = shouldBeEditable;
  39333. if (valueBox != 0)
  39334. valueBox->setEditable (shouldBeEditable && isEnabled());
  39335. }
  39336. void Slider::showTextBox()
  39337. {
  39338. jassert (editableText); // this should probably be avoided in read-only sliders.
  39339. if (valueBox != 0)
  39340. valueBox->showEditor();
  39341. }
  39342. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39343. {
  39344. if (valueBox != 0)
  39345. {
  39346. valueBox->hideEditor (discardCurrentEditorContents);
  39347. if (discardCurrentEditorContents)
  39348. updateText();
  39349. }
  39350. }
  39351. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39352. {
  39353. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39354. }
  39355. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39356. {
  39357. snapsToMousePos = shouldSnapToMouse;
  39358. }
  39359. void Slider::setPopupDisplayEnabled (const bool enabled,
  39360. Component* const parentComponentToUse)
  39361. {
  39362. popupDisplayEnabled = enabled;
  39363. parentForPopupDisplay = parentComponentToUse;
  39364. }
  39365. void Slider::colourChanged()
  39366. {
  39367. lookAndFeelChanged();
  39368. }
  39369. void Slider::lookAndFeelChanged()
  39370. {
  39371. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39372. : getTextFromValue (currentValue.getValue()));
  39373. deleteAllChildren();
  39374. valueBox = 0;
  39375. LookAndFeel& lf = getLookAndFeel();
  39376. if (textBoxPos != NoTextBox)
  39377. {
  39378. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39379. valueBox->setWantsKeyboardFocus (false);
  39380. valueBox->setText (previousTextBoxContent, false);
  39381. valueBox->setEditable (editableText && isEnabled());
  39382. valueBox->addListener (this);
  39383. if (style == LinearBar)
  39384. valueBox->addMouseListener (this, false);
  39385. valueBox->setTooltip (getTooltip());
  39386. }
  39387. if (style == IncDecButtons)
  39388. {
  39389. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39390. incButton->addButtonListener (this);
  39391. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39392. decButton->addButtonListener (this);
  39393. if (incDecButtonMode != incDecButtonsNotDraggable)
  39394. {
  39395. incButton->addMouseListener (this, false);
  39396. decButton->addMouseListener (this, false);
  39397. }
  39398. else
  39399. {
  39400. incButton->setRepeatSpeed (300, 100, 20);
  39401. incButton->addMouseListener (decButton, false);
  39402. decButton->setRepeatSpeed (300, 100, 20);
  39403. decButton->addMouseListener (incButton, false);
  39404. }
  39405. incButton->setTooltip (getTooltip());
  39406. decButton->setTooltip (getTooltip());
  39407. }
  39408. setComponentEffect (lf.getSliderEffect());
  39409. resized();
  39410. repaint();
  39411. }
  39412. void Slider::setRange (const double newMin,
  39413. const double newMax,
  39414. const double newInt)
  39415. {
  39416. if (minimum != newMin
  39417. || maximum != newMax
  39418. || interval != newInt)
  39419. {
  39420. minimum = newMin;
  39421. maximum = newMax;
  39422. interval = newInt;
  39423. // figure out the number of DPs needed to display all values at this
  39424. // interval setting.
  39425. numDecimalPlaces = 7;
  39426. if (newInt != 0)
  39427. {
  39428. int v = abs ((int) (newInt * 10000000));
  39429. while ((v % 10) == 0)
  39430. {
  39431. --numDecimalPlaces;
  39432. v /= 10;
  39433. }
  39434. }
  39435. // keep the current values inside the new range..
  39436. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39437. {
  39438. setValue (getValue(), false, false);
  39439. }
  39440. else
  39441. {
  39442. setMinValue (getMinValue(), false, false);
  39443. setMaxValue (getMaxValue(), false, false);
  39444. }
  39445. updateText();
  39446. }
  39447. }
  39448. void Slider::triggerChangeMessage (const bool synchronous)
  39449. {
  39450. if (synchronous)
  39451. handleAsyncUpdate();
  39452. else
  39453. triggerAsyncUpdate();
  39454. valueChanged();
  39455. }
  39456. void Slider::valueChanged (Value& value)
  39457. {
  39458. if (value.refersToSameSourceAs (currentValue))
  39459. {
  39460. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39461. setValue (currentValue.getValue(), false, false);
  39462. }
  39463. else if (value.refersToSameSourceAs (valueMin))
  39464. setMinValue (valueMin.getValue(), false, false, true);
  39465. else if (value.refersToSameSourceAs (valueMax))
  39466. setMaxValue (valueMax.getValue(), false, false, true);
  39467. }
  39468. double Slider::getValue() const
  39469. {
  39470. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39471. // methods to get the two values.
  39472. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39473. return currentValue.getValue();
  39474. }
  39475. void Slider::setValue (double newValue,
  39476. const bool sendUpdateMessage,
  39477. const bool sendMessageSynchronously)
  39478. {
  39479. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39480. // methods to set the two values.
  39481. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39482. newValue = constrainedValue (newValue);
  39483. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39484. {
  39485. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39486. newValue = jlimit ((double) valueMin.getValue(),
  39487. (double) valueMax.getValue(),
  39488. newValue);
  39489. }
  39490. if (newValue != lastCurrentValue)
  39491. {
  39492. if (valueBox != 0)
  39493. valueBox->hideEditor (true);
  39494. lastCurrentValue = newValue;
  39495. currentValue = newValue;
  39496. updateText();
  39497. repaint();
  39498. if (popupDisplay != 0)
  39499. {
  39500. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39501. popupDisplay->repaint();
  39502. }
  39503. if (sendUpdateMessage)
  39504. triggerChangeMessage (sendMessageSynchronously);
  39505. }
  39506. }
  39507. double Slider::getMinValue() const
  39508. {
  39509. // The minimum value only applies to sliders that are in two- or three-value mode.
  39510. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39511. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39512. return valueMin.getValue();
  39513. }
  39514. double Slider::getMaxValue() const
  39515. {
  39516. // The maximum value only applies to sliders that are in two- or three-value mode.
  39517. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39518. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39519. return valueMax.getValue();
  39520. }
  39521. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39522. {
  39523. // The minimum value only applies to sliders that are in two- or three-value mode.
  39524. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39525. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39526. newValue = constrainedValue (newValue);
  39527. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39528. {
  39529. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39530. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39531. newValue = jmin ((double) valueMax.getValue(), newValue);
  39532. }
  39533. else
  39534. {
  39535. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39536. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39537. newValue = jmin (lastCurrentValue, newValue);
  39538. }
  39539. if (lastValueMin != newValue)
  39540. {
  39541. lastValueMin = newValue;
  39542. valueMin = newValue;
  39543. repaint();
  39544. if (popupDisplay != 0)
  39545. {
  39546. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39547. popupDisplay->repaint();
  39548. }
  39549. if (sendUpdateMessage)
  39550. triggerChangeMessage (sendMessageSynchronously);
  39551. }
  39552. }
  39553. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39554. {
  39555. // The maximum value only applies to sliders that are in two- or three-value mode.
  39556. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39557. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39558. newValue = constrainedValue (newValue);
  39559. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39560. {
  39561. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39562. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39563. newValue = jmax ((double) valueMin.getValue(), newValue);
  39564. }
  39565. else
  39566. {
  39567. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39568. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39569. newValue = jmax (lastCurrentValue, newValue);
  39570. }
  39571. if (lastValueMax != newValue)
  39572. {
  39573. lastValueMax = newValue;
  39574. valueMax = newValue;
  39575. repaint();
  39576. if (popupDisplay != 0)
  39577. {
  39578. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39579. popupDisplay->repaint();
  39580. }
  39581. if (sendUpdateMessage)
  39582. triggerChangeMessage (sendMessageSynchronously);
  39583. }
  39584. }
  39585. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39586. const double valueToSetOnDoubleClick)
  39587. {
  39588. doubleClickToValue = isDoubleClickEnabled;
  39589. doubleClickReturnValue = valueToSetOnDoubleClick;
  39590. }
  39591. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39592. {
  39593. isEnabled_ = doubleClickToValue;
  39594. return doubleClickReturnValue;
  39595. }
  39596. void Slider::updateText()
  39597. {
  39598. if (valueBox != 0)
  39599. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39600. }
  39601. void Slider::setTextValueSuffix (const String& suffix)
  39602. {
  39603. if (textSuffix != suffix)
  39604. {
  39605. textSuffix = suffix;
  39606. updateText();
  39607. }
  39608. }
  39609. const String Slider::getTextFromValue (double v)
  39610. {
  39611. if (numDecimalPlaces > 0)
  39612. return String (v, numDecimalPlaces) + textSuffix;
  39613. else
  39614. return String (roundToInt (v)) + textSuffix;
  39615. }
  39616. double Slider::getValueFromText (const String& text)
  39617. {
  39618. String t (text.trimStart());
  39619. if (t.endsWith (textSuffix))
  39620. t = t.substring (0, t.length() - textSuffix.length());
  39621. while (t.startsWithChar (T('+')))
  39622. t = t.substring (1).trimStart();
  39623. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39624. .getDoubleValue();
  39625. }
  39626. double Slider::proportionOfLengthToValue (double proportion)
  39627. {
  39628. if (skewFactor != 1.0 && proportion > 0.0)
  39629. proportion = exp (log (proportion) / skewFactor);
  39630. return minimum + (maximum - minimum) * proportion;
  39631. }
  39632. double Slider::valueToProportionOfLength (double value)
  39633. {
  39634. const double n = (value - minimum) / (maximum - minimum);
  39635. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39636. }
  39637. double Slider::snapValue (double attemptedValue, const bool)
  39638. {
  39639. return attemptedValue;
  39640. }
  39641. void Slider::startedDragging()
  39642. {
  39643. }
  39644. void Slider::stoppedDragging()
  39645. {
  39646. }
  39647. void Slider::valueChanged()
  39648. {
  39649. }
  39650. void Slider::enablementChanged()
  39651. {
  39652. repaint();
  39653. }
  39654. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39655. {
  39656. menuEnabled = menuEnabled_;
  39657. }
  39658. void Slider::setScrollWheelEnabled (const bool enabled)
  39659. {
  39660. scrollWheelEnabled = enabled;
  39661. }
  39662. void Slider::labelTextChanged (Label* label)
  39663. {
  39664. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39665. if (newValue != (double) currentValue.getValue())
  39666. {
  39667. sendDragStart();
  39668. setValue (newValue, true, true);
  39669. sendDragEnd();
  39670. }
  39671. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39672. }
  39673. void Slider::buttonClicked (Button* button)
  39674. {
  39675. if (style == IncDecButtons)
  39676. {
  39677. sendDragStart();
  39678. if (button == incButton)
  39679. setValue (snapValue (getValue() + interval, false), true, true);
  39680. else if (button == decButton)
  39681. setValue (snapValue (getValue() - interval, false), true, true);
  39682. sendDragEnd();
  39683. }
  39684. }
  39685. double Slider::constrainedValue (double value) const
  39686. {
  39687. if (interval > 0)
  39688. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39689. if (value <= minimum || maximum <= minimum)
  39690. value = minimum;
  39691. else if (value >= maximum)
  39692. value = maximum;
  39693. return value;
  39694. }
  39695. float Slider::getLinearSliderPos (const double value)
  39696. {
  39697. double sliderPosProportional;
  39698. if (maximum > minimum)
  39699. {
  39700. if (value < minimum)
  39701. {
  39702. sliderPosProportional = 0.0;
  39703. }
  39704. else if (value > maximum)
  39705. {
  39706. sliderPosProportional = 1.0;
  39707. }
  39708. else
  39709. {
  39710. sliderPosProportional = valueToProportionOfLength (value);
  39711. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39712. }
  39713. }
  39714. else
  39715. {
  39716. sliderPosProportional = 0.5;
  39717. }
  39718. if (isVertical() || style == IncDecButtons)
  39719. sliderPosProportional = 1.0 - sliderPosProportional;
  39720. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39721. }
  39722. bool Slider::isHorizontal() const
  39723. {
  39724. return style == LinearHorizontal
  39725. || style == LinearBar
  39726. || style == TwoValueHorizontal
  39727. || style == ThreeValueHorizontal;
  39728. }
  39729. bool Slider::isVertical() const
  39730. {
  39731. return style == LinearVertical
  39732. || style == TwoValueVertical
  39733. || style == ThreeValueVertical;
  39734. }
  39735. bool Slider::incDecDragDirectionIsHorizontal() const
  39736. {
  39737. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39738. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39739. }
  39740. float Slider::getPositionOfValue (const double value)
  39741. {
  39742. if (isHorizontal() || isVertical())
  39743. {
  39744. return getLinearSliderPos (value);
  39745. }
  39746. else
  39747. {
  39748. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39749. return 0.0f;
  39750. }
  39751. }
  39752. void Slider::paint (Graphics& g)
  39753. {
  39754. if (style != IncDecButtons)
  39755. {
  39756. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39757. {
  39758. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39759. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39760. getLookAndFeel().drawRotarySlider (g,
  39761. sliderRect.getX(),
  39762. sliderRect.getY(),
  39763. sliderRect.getWidth(),
  39764. sliderRect.getHeight(),
  39765. sliderPos,
  39766. rotaryStart, rotaryEnd,
  39767. *this);
  39768. }
  39769. else
  39770. {
  39771. getLookAndFeel().drawLinearSlider (g,
  39772. sliderRect.getX(),
  39773. sliderRect.getY(),
  39774. sliderRect.getWidth(),
  39775. sliderRect.getHeight(),
  39776. getLinearSliderPos (lastCurrentValue),
  39777. getLinearSliderPos (lastValueMin),
  39778. getLinearSliderPos (lastValueMax),
  39779. style,
  39780. *this);
  39781. }
  39782. if (style == LinearBar && valueBox == 0)
  39783. {
  39784. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39785. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39786. }
  39787. }
  39788. }
  39789. void Slider::resized()
  39790. {
  39791. int minXSpace = 0;
  39792. int minYSpace = 0;
  39793. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39794. minXSpace = 30;
  39795. else
  39796. minYSpace = 15;
  39797. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39798. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39799. if (style == LinearBar)
  39800. {
  39801. if (valueBox != 0)
  39802. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39803. }
  39804. else
  39805. {
  39806. if (textBoxPos == NoTextBox)
  39807. {
  39808. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39809. }
  39810. else if (textBoxPos == TextBoxLeft)
  39811. {
  39812. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39813. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39814. }
  39815. else if (textBoxPos == TextBoxRight)
  39816. {
  39817. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39818. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39819. }
  39820. else if (textBoxPos == TextBoxAbove)
  39821. {
  39822. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39823. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39824. }
  39825. else if (textBoxPos == TextBoxBelow)
  39826. {
  39827. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39828. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39829. }
  39830. }
  39831. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39832. if (style == LinearBar)
  39833. {
  39834. const int barIndent = 1;
  39835. sliderRegionStart = barIndent;
  39836. sliderRegionSize = getWidth() - barIndent * 2;
  39837. sliderRect.setBounds (sliderRegionStart, barIndent,
  39838. sliderRegionSize, getHeight() - barIndent * 2);
  39839. }
  39840. else if (isHorizontal())
  39841. {
  39842. sliderRegionStart = sliderRect.getX() + indent;
  39843. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39844. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39845. sliderRegionSize, sliderRect.getHeight());
  39846. }
  39847. else if (isVertical())
  39848. {
  39849. sliderRegionStart = sliderRect.getY() + indent;
  39850. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39851. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39852. sliderRect.getWidth(), sliderRegionSize);
  39853. }
  39854. else
  39855. {
  39856. sliderRegionStart = 0;
  39857. sliderRegionSize = 100;
  39858. }
  39859. if (style == IncDecButtons)
  39860. {
  39861. Rectangle<int> buttonRect (sliderRect);
  39862. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39863. buttonRect.expand (-2, 0);
  39864. else
  39865. buttonRect.expand (0, -2);
  39866. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39867. if (incDecButtonsSideBySide)
  39868. {
  39869. decButton->setBounds (buttonRect.getX(),
  39870. buttonRect.getY(),
  39871. buttonRect.getWidth() / 2,
  39872. buttonRect.getHeight());
  39873. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39874. incButton->setBounds (buttonRect.getCentreX(),
  39875. buttonRect.getY(),
  39876. buttonRect.getWidth() / 2,
  39877. buttonRect.getHeight());
  39878. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39879. }
  39880. else
  39881. {
  39882. incButton->setBounds (buttonRect.getX(),
  39883. buttonRect.getY(),
  39884. buttonRect.getWidth(),
  39885. buttonRect.getHeight() / 2);
  39886. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39887. decButton->setBounds (buttonRect.getX(),
  39888. buttonRect.getCentreY(),
  39889. buttonRect.getWidth(),
  39890. buttonRect.getHeight() / 2);
  39891. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39892. }
  39893. }
  39894. }
  39895. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39896. {
  39897. repaint();
  39898. }
  39899. void Slider::mouseDown (const MouseEvent& e)
  39900. {
  39901. mouseWasHidden = false;
  39902. incDecDragged = false;
  39903. mouseXWhenLastDragged = e.x;
  39904. mouseYWhenLastDragged = e.y;
  39905. mouseDragStartX = e.getMouseDownX();
  39906. mouseDragStartY = e.getMouseDownY();
  39907. if (isEnabled())
  39908. {
  39909. if (e.mods.isPopupMenu() && menuEnabled)
  39910. {
  39911. menuShown = true;
  39912. PopupMenu m;
  39913. m.setLookAndFeel (&getLookAndFeel());
  39914. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39915. m.addSeparator();
  39916. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39917. {
  39918. PopupMenu rotaryMenu;
  39919. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39920. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39921. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39922. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39923. }
  39924. const int r = m.show();
  39925. if (r == 1)
  39926. {
  39927. setVelocityBasedMode (! isVelocityBased);
  39928. }
  39929. else if (r == 2)
  39930. {
  39931. setSliderStyle (Rotary);
  39932. }
  39933. else if (r == 3)
  39934. {
  39935. setSliderStyle (RotaryHorizontalDrag);
  39936. }
  39937. else if (r == 4)
  39938. {
  39939. setSliderStyle (RotaryVerticalDrag);
  39940. }
  39941. }
  39942. else if (maximum > minimum)
  39943. {
  39944. menuShown = false;
  39945. if (valueBox != 0)
  39946. valueBox->hideEditor (true);
  39947. sliderBeingDragged = 0;
  39948. if (style == TwoValueHorizontal
  39949. || style == TwoValueVertical
  39950. || style == ThreeValueHorizontal
  39951. || style == ThreeValueVertical)
  39952. {
  39953. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39954. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39955. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39956. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39957. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39958. {
  39959. if (maxPosDistance <= minPosDistance)
  39960. sliderBeingDragged = 2;
  39961. else
  39962. sliderBeingDragged = 1;
  39963. }
  39964. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39965. {
  39966. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39967. sliderBeingDragged = 1;
  39968. else if (normalPosDistance >= maxPosDistance)
  39969. sliderBeingDragged = 2;
  39970. }
  39971. }
  39972. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39973. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39974. * valueToProportionOfLength (currentValue.getValue());
  39975. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39976. : ((sliderBeingDragged == 1) ? valueMin
  39977. : currentValue)).getValue();
  39978. valueOnMouseDown = valueWhenLastDragged;
  39979. if (popupDisplayEnabled)
  39980. {
  39981. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39982. popupDisplay = popup;
  39983. if (parentForPopupDisplay != 0)
  39984. {
  39985. parentForPopupDisplay->addChildComponent (popup);
  39986. }
  39987. else
  39988. {
  39989. popup->addToDesktop (0);
  39990. }
  39991. popup->setVisible (true);
  39992. }
  39993. sendDragStart();
  39994. mouseDrag (e);
  39995. }
  39996. }
  39997. }
  39998. void Slider::mouseUp (const MouseEvent&)
  39999. {
  40000. if (isEnabled()
  40001. && (! menuShown)
  40002. && (maximum > minimum)
  40003. && (style != IncDecButtons || incDecDragged))
  40004. {
  40005. restoreMouseIfHidden();
  40006. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  40007. triggerChangeMessage (false);
  40008. sendDragEnd();
  40009. popupDisplay = 0;
  40010. if (style == IncDecButtons)
  40011. {
  40012. incButton->setState (Button::buttonNormal);
  40013. decButton->setState (Button::buttonNormal);
  40014. }
  40015. }
  40016. }
  40017. void Slider::restoreMouseIfHidden()
  40018. {
  40019. if (mouseWasHidden)
  40020. {
  40021. mouseWasHidden = false;
  40022. Component* c = Component::getComponentUnderMouse();
  40023. if (c == 0)
  40024. c = this;
  40025. c->enableUnboundedMouseMovement (false);
  40026. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  40027. : ((sliderBeingDragged == 1) ? getMinValue()
  40028. : (double) currentValue.getValue());
  40029. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  40030. {
  40031. int x, y, downX, downY;
  40032. Desktop::getMousePosition (x, y);
  40033. Desktop::getLastMouseDownPosition (downX, downY);
  40034. if (style == RotaryHorizontalDrag)
  40035. {
  40036. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  40037. x = roundToInt (pixelsForFullDragExtent * posDiff + downX);
  40038. y = downY;
  40039. }
  40040. else
  40041. {
  40042. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  40043. x = downX;
  40044. y = roundToInt (pixelsForFullDragExtent * posDiff + downY);
  40045. }
  40046. Desktop::setMousePosition (x, y);
  40047. }
  40048. else
  40049. {
  40050. const int pixelPos = (int) getLinearSliderPos (pos);
  40051. int x = isHorizontal() ? pixelPos : (getWidth() / 2);
  40052. int y = isVertical() ? pixelPos : (getHeight() / 2);
  40053. relativePositionToGlobal (x, y);
  40054. Desktop::setMousePosition (x, y);
  40055. }
  40056. }
  40057. }
  40058. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  40059. {
  40060. if (isEnabled()
  40061. && style != IncDecButtons
  40062. && style != Rotary
  40063. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  40064. {
  40065. restoreMouseIfHidden();
  40066. }
  40067. }
  40068. static double smallestAngleBetween (double a1, double a2)
  40069. {
  40070. return jmin (fabs (a1 - a2),
  40071. fabs (a1 + double_Pi * 2.0 - a2),
  40072. fabs (a2 + double_Pi * 2.0 - a1));
  40073. }
  40074. void Slider::mouseDrag (const MouseEvent& e)
  40075. {
  40076. if (isEnabled()
  40077. && (! menuShown)
  40078. && (maximum > minimum))
  40079. {
  40080. if (style == Rotary)
  40081. {
  40082. int dx = e.x - sliderRect.getCentreX();
  40083. int dy = e.y - sliderRect.getCentreY();
  40084. if (dx * dx + dy * dy > 25)
  40085. {
  40086. double angle = atan2 ((double) dx, (double) -dy);
  40087. while (angle < 0.0)
  40088. angle += double_Pi * 2.0;
  40089. if (rotaryStop && ! e.mouseWasClicked())
  40090. {
  40091. if (fabs (angle - lastAngle) > double_Pi)
  40092. {
  40093. if (angle >= lastAngle)
  40094. angle -= double_Pi * 2.0;
  40095. else
  40096. angle += double_Pi * 2.0;
  40097. }
  40098. if (angle >= lastAngle)
  40099. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40100. else
  40101. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40102. }
  40103. else
  40104. {
  40105. while (angle < rotaryStart)
  40106. angle += double_Pi * 2.0;
  40107. if (angle > rotaryEnd)
  40108. {
  40109. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40110. angle = rotaryStart;
  40111. else
  40112. angle = rotaryEnd;
  40113. }
  40114. }
  40115. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40116. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40117. lastAngle = angle;
  40118. }
  40119. }
  40120. else
  40121. {
  40122. if (style == LinearBar && e.mouseWasClicked()
  40123. && valueBox != 0 && valueBox->isEditable())
  40124. return;
  40125. if (style == IncDecButtons && ! incDecDragged)
  40126. {
  40127. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40128. return;
  40129. incDecDragged = true;
  40130. mouseDragStartX = e.x;
  40131. mouseDragStartY = e.y;
  40132. }
  40133. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40134. : false))
  40135. || ((maximum - minimum) / sliderRegionSize < interval))
  40136. {
  40137. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40138. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40139. if (style == RotaryHorizontalDrag
  40140. || style == RotaryVerticalDrag
  40141. || style == IncDecButtons
  40142. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40143. && ! snapsToMousePos))
  40144. {
  40145. const int mouseDiff = (style == RotaryHorizontalDrag
  40146. || style == LinearHorizontal
  40147. || style == LinearBar
  40148. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40149. ? e.x - mouseDragStartX
  40150. : mouseDragStartY - e.y;
  40151. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40152. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40153. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40154. if (style == IncDecButtons)
  40155. {
  40156. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40157. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40158. }
  40159. }
  40160. else
  40161. {
  40162. if (isVertical())
  40163. scaledMousePos = 1.0 - scaledMousePos;
  40164. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40165. }
  40166. }
  40167. else
  40168. {
  40169. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40170. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40171. ? e.x - mouseXWhenLastDragged
  40172. : e.y - mouseYWhenLastDragged;
  40173. const double maxSpeed = jmax (200, sliderRegionSize);
  40174. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40175. if (speed != 0)
  40176. {
  40177. speed = 0.2 * velocityModeSensitivity
  40178. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40179. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40180. / maxSpeed))));
  40181. if (mouseDiff < 0)
  40182. speed = -speed;
  40183. if (isVertical() || style == RotaryVerticalDrag
  40184. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40185. speed = -speed;
  40186. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40187. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40188. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40189. mouseWasHidden = true;
  40190. }
  40191. }
  40192. }
  40193. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40194. if (sliderBeingDragged == 0)
  40195. {
  40196. setValue (snapValue (valueWhenLastDragged, true),
  40197. ! sendChangeOnlyOnRelease, true);
  40198. }
  40199. else if (sliderBeingDragged == 1)
  40200. {
  40201. setMinValue (snapValue (valueWhenLastDragged, true),
  40202. ! sendChangeOnlyOnRelease, false, true);
  40203. if (e.mods.isShiftDown())
  40204. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40205. else
  40206. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40207. }
  40208. else
  40209. {
  40210. jassert (sliderBeingDragged == 2);
  40211. setMaxValue (snapValue (valueWhenLastDragged, true),
  40212. ! sendChangeOnlyOnRelease, false, true);
  40213. if (e.mods.isShiftDown())
  40214. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40215. else
  40216. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40217. }
  40218. mouseXWhenLastDragged = e.x;
  40219. mouseYWhenLastDragged = e.y;
  40220. }
  40221. }
  40222. void Slider::mouseDoubleClick (const MouseEvent&)
  40223. {
  40224. if (doubleClickToValue
  40225. && isEnabled()
  40226. && style != IncDecButtons
  40227. && minimum <= doubleClickReturnValue
  40228. && maximum >= doubleClickReturnValue)
  40229. {
  40230. sendDragStart();
  40231. setValue (doubleClickReturnValue, true, true);
  40232. sendDragEnd();
  40233. }
  40234. }
  40235. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40236. {
  40237. if (scrollWheelEnabled && isEnabled()
  40238. && style != TwoValueHorizontal
  40239. && style != TwoValueVertical)
  40240. {
  40241. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40242. {
  40243. if (valueBox != 0)
  40244. valueBox->hideEditor (false);
  40245. const double value = (double) currentValue.getValue();
  40246. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40247. const double currentPos = valueToProportionOfLength (value);
  40248. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40249. double delta = (newValue != value)
  40250. ? jmax (fabs (newValue - value), interval) : 0;
  40251. if (value > newValue)
  40252. delta = -delta;
  40253. sendDragStart();
  40254. setValue (snapValue (value + delta, false), true, true);
  40255. sendDragEnd();
  40256. }
  40257. }
  40258. else
  40259. {
  40260. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40261. }
  40262. }
  40263. void SliderListener::sliderDragStarted (Slider*)
  40264. {
  40265. }
  40266. void SliderListener::sliderDragEnded (Slider*)
  40267. {
  40268. }
  40269. END_JUCE_NAMESPACE
  40270. /*** End of inlined file: juce_Slider.cpp ***/
  40271. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  40272. BEGIN_JUCE_NAMESPACE
  40273. class DragOverlayComp : public Component
  40274. {
  40275. public:
  40276. DragOverlayComp (Image* const image_)
  40277. : image (image_)
  40278. {
  40279. image->multiplyAllAlphas (0.8f);
  40280. setAlwaysOnTop (true);
  40281. }
  40282. ~DragOverlayComp()
  40283. {
  40284. }
  40285. void paint (Graphics& g)
  40286. {
  40287. g.drawImageAt (image, 0, 0);
  40288. }
  40289. private:
  40290. ScopedPointer <Image> image;
  40291. DragOverlayComp (const DragOverlayComp&);
  40292. const DragOverlayComp& operator= (const DragOverlayComp&);
  40293. };
  40294. TableHeaderComponent::TableHeaderComponent()
  40295. : columnsChanged (false),
  40296. columnsResized (false),
  40297. sortChanged (false),
  40298. menuActive (true),
  40299. stretchToFit (false),
  40300. columnIdBeingResized (0),
  40301. columnIdBeingDragged (0),
  40302. columnIdUnderMouse (0),
  40303. lastDeliberateWidth (0)
  40304. {
  40305. }
  40306. TableHeaderComponent::~TableHeaderComponent()
  40307. {
  40308. dragOverlayComp = 0;
  40309. }
  40310. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40311. {
  40312. menuActive = hasMenu;
  40313. }
  40314. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40315. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40316. {
  40317. if (onlyCountVisibleColumns)
  40318. {
  40319. int num = 0;
  40320. for (int i = columns.size(); --i >= 0;)
  40321. if (columns.getUnchecked(i)->isVisible())
  40322. ++num;
  40323. return num;
  40324. }
  40325. else
  40326. {
  40327. return columns.size();
  40328. }
  40329. }
  40330. const String TableHeaderComponent::getColumnName (const int columnId) const
  40331. {
  40332. const ColumnInfo* const ci = getInfoForId (columnId);
  40333. return ci != 0 ? ci->name : String::empty;
  40334. }
  40335. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40336. {
  40337. ColumnInfo* const ci = getInfoForId (columnId);
  40338. if (ci != 0 && ci->name != newName)
  40339. {
  40340. ci->name = newName;
  40341. sendColumnsChanged();
  40342. }
  40343. }
  40344. void TableHeaderComponent::addColumn (const String& columnName,
  40345. const int columnId,
  40346. const int width,
  40347. const int minimumWidth,
  40348. const int maximumWidth,
  40349. const int propertyFlags,
  40350. const int insertIndex)
  40351. {
  40352. // can't have a duplicate or null ID!
  40353. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40354. jassert (width > 0);
  40355. ColumnInfo* const ci = new ColumnInfo();
  40356. ci->name = columnName;
  40357. ci->id = columnId;
  40358. ci->width = width;
  40359. ci->lastDeliberateWidth = width;
  40360. ci->minimumWidth = minimumWidth;
  40361. ci->maximumWidth = maximumWidth;
  40362. if (ci->maximumWidth < 0)
  40363. ci->maximumWidth = std::numeric_limits<int>::max();
  40364. jassert (ci->maximumWidth >= ci->minimumWidth);
  40365. ci->propertyFlags = propertyFlags;
  40366. columns.insert (insertIndex, ci);
  40367. sendColumnsChanged();
  40368. }
  40369. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40370. {
  40371. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40372. if (index >= 0)
  40373. {
  40374. columns.remove (index);
  40375. sortChanged = true;
  40376. sendColumnsChanged();
  40377. }
  40378. }
  40379. void TableHeaderComponent::removeAllColumns()
  40380. {
  40381. if (columns.size() > 0)
  40382. {
  40383. columns.clear();
  40384. sendColumnsChanged();
  40385. }
  40386. }
  40387. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40388. {
  40389. const int currentIndex = getIndexOfColumnId (columnId, false);
  40390. newIndex = visibleIndexToTotalIndex (newIndex);
  40391. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40392. {
  40393. columns.move (currentIndex, newIndex);
  40394. sendColumnsChanged();
  40395. }
  40396. }
  40397. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40398. {
  40399. const ColumnInfo* const ci = getInfoForId (columnId);
  40400. return ci != 0 ? ci->width : 0;
  40401. }
  40402. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40403. {
  40404. ColumnInfo* const ci = getInfoForId (columnId);
  40405. if (ci != 0 && ci->width != newWidth)
  40406. {
  40407. const int numColumns = getNumColumns (true);
  40408. ci->lastDeliberateWidth = ci->width
  40409. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40410. if (stretchToFit)
  40411. {
  40412. const int index = getIndexOfColumnId (columnId, true) + 1;
  40413. if (((unsigned int) index) < (unsigned int) numColumns)
  40414. {
  40415. const int x = getColumnPosition (index).getX();
  40416. if (lastDeliberateWidth == 0)
  40417. lastDeliberateWidth = getTotalWidth();
  40418. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40419. }
  40420. }
  40421. repaint();
  40422. columnsResized = true;
  40423. triggerAsyncUpdate();
  40424. }
  40425. }
  40426. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40427. {
  40428. int n = 0;
  40429. for (int i = 0; i < columns.size(); ++i)
  40430. {
  40431. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40432. {
  40433. if (columns.getUnchecked(i)->id == columnId)
  40434. return n;
  40435. ++n;
  40436. }
  40437. }
  40438. return -1;
  40439. }
  40440. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40441. {
  40442. if (onlyCountVisibleColumns)
  40443. index = visibleIndexToTotalIndex (index);
  40444. const ColumnInfo* const ci = columns [index];
  40445. return (ci != 0) ? ci->id : 0;
  40446. }
  40447. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40448. {
  40449. int x = 0, width = 0, n = 0;
  40450. for (int i = 0; i < columns.size(); ++i)
  40451. {
  40452. x += width;
  40453. if (columns.getUnchecked(i)->isVisible())
  40454. {
  40455. width = columns.getUnchecked(i)->width;
  40456. if (n++ == index)
  40457. break;
  40458. }
  40459. else
  40460. {
  40461. width = 0;
  40462. }
  40463. }
  40464. return Rectangle<int> (x, 0, width, getHeight());
  40465. }
  40466. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40467. {
  40468. if (xToFind >= 0)
  40469. {
  40470. int x = 0;
  40471. for (int i = 0; i < columns.size(); ++i)
  40472. {
  40473. const ColumnInfo* const ci = columns.getUnchecked(i);
  40474. if (ci->isVisible())
  40475. {
  40476. x += ci->width;
  40477. if (xToFind < x)
  40478. return ci->id;
  40479. }
  40480. }
  40481. }
  40482. return 0;
  40483. }
  40484. int TableHeaderComponent::getTotalWidth() const
  40485. {
  40486. int w = 0;
  40487. for (int i = columns.size(); --i >= 0;)
  40488. if (columns.getUnchecked(i)->isVisible())
  40489. w += columns.getUnchecked(i)->width;
  40490. return w;
  40491. }
  40492. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40493. {
  40494. stretchToFit = shouldStretchToFit;
  40495. lastDeliberateWidth = getTotalWidth();
  40496. resized();
  40497. }
  40498. bool TableHeaderComponent::isStretchToFitActive() const
  40499. {
  40500. return stretchToFit;
  40501. }
  40502. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40503. {
  40504. if (stretchToFit && getWidth() > 0
  40505. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40506. {
  40507. lastDeliberateWidth = targetTotalWidth;
  40508. resizeColumnsToFit (0, targetTotalWidth);
  40509. }
  40510. }
  40511. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40512. {
  40513. targetTotalWidth = jmax (targetTotalWidth, 0);
  40514. StretchableObjectResizer sor;
  40515. int i;
  40516. for (i = firstColumnIndex; i < columns.size(); ++i)
  40517. {
  40518. ColumnInfo* const ci = columns.getUnchecked(i);
  40519. if (ci->isVisible())
  40520. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40521. }
  40522. sor.resizeToFit (targetTotalWidth);
  40523. int visIndex = 0;
  40524. for (i = firstColumnIndex; i < columns.size(); ++i)
  40525. {
  40526. ColumnInfo* const ci = columns.getUnchecked(i);
  40527. if (ci->isVisible())
  40528. {
  40529. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40530. (int) floor (sor.getItemSize (visIndex++)));
  40531. if (newWidth != ci->width)
  40532. {
  40533. ci->width = newWidth;
  40534. repaint();
  40535. columnsResized = true;
  40536. triggerAsyncUpdate();
  40537. }
  40538. }
  40539. }
  40540. }
  40541. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40542. {
  40543. ColumnInfo* const ci = getInfoForId (columnId);
  40544. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40545. {
  40546. if (shouldBeVisible)
  40547. ci->propertyFlags |= visible;
  40548. else
  40549. ci->propertyFlags &= ~visible;
  40550. sendColumnsChanged();
  40551. resized();
  40552. }
  40553. }
  40554. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40555. {
  40556. const ColumnInfo* const ci = getInfoForId (columnId);
  40557. return ci != 0 && ci->isVisible();
  40558. }
  40559. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40560. {
  40561. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40562. {
  40563. for (int i = columns.size(); --i >= 0;)
  40564. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40565. ColumnInfo* const ci = getInfoForId (columnId);
  40566. if (ci != 0)
  40567. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40568. reSortTable();
  40569. }
  40570. }
  40571. int TableHeaderComponent::getSortColumnId() const
  40572. {
  40573. for (int i = columns.size(); --i >= 0;)
  40574. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40575. return columns.getUnchecked(i)->id;
  40576. return 0;
  40577. }
  40578. bool TableHeaderComponent::isSortedForwards() const
  40579. {
  40580. for (int i = columns.size(); --i >= 0;)
  40581. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40582. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40583. return true;
  40584. }
  40585. void TableHeaderComponent::reSortTable()
  40586. {
  40587. sortChanged = true;
  40588. repaint();
  40589. triggerAsyncUpdate();
  40590. }
  40591. const String TableHeaderComponent::toString() const
  40592. {
  40593. String s;
  40594. XmlElement doc ("TABLELAYOUT");
  40595. doc.setAttribute ("sortedCol", getSortColumnId());
  40596. doc.setAttribute ("sortForwards", isSortedForwards());
  40597. for (int i = 0; i < columns.size(); ++i)
  40598. {
  40599. const ColumnInfo* const ci = columns.getUnchecked (i);
  40600. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40601. e->setAttribute ("id", ci->id);
  40602. e->setAttribute ("visible", ci->isVisible());
  40603. e->setAttribute ("width", ci->width);
  40604. }
  40605. return doc.createDocument (String::empty, true, false);
  40606. }
  40607. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40608. {
  40609. XmlDocument doc (storedVersion);
  40610. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40611. int index = 0;
  40612. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40613. {
  40614. forEachXmlChildElement (*storedXml, col)
  40615. {
  40616. const int tabId = col->getIntAttribute ("id");
  40617. ColumnInfo* const ci = getInfoForId (tabId);
  40618. if (ci != 0)
  40619. {
  40620. columns.move (columns.indexOf (ci), index);
  40621. ci->width = col->getIntAttribute ("width");
  40622. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40623. }
  40624. ++index;
  40625. }
  40626. columnsResized = true;
  40627. sendColumnsChanged();
  40628. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40629. storedXml->getBoolAttribute ("sortForwards", true));
  40630. }
  40631. }
  40632. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40633. {
  40634. listeners.addIfNotAlreadyThere (newListener);
  40635. }
  40636. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40637. {
  40638. listeners.removeValue (listenerToRemove);
  40639. }
  40640. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40641. {
  40642. const ColumnInfo* const ci = getInfoForId (columnId);
  40643. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40644. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40645. }
  40646. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40647. {
  40648. for (int i = 0; i < columns.size(); ++i)
  40649. {
  40650. const ColumnInfo* const ci = columns.getUnchecked(i);
  40651. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40652. menu.addItem (ci->id, ci->name,
  40653. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40654. isColumnVisible (ci->id));
  40655. }
  40656. }
  40657. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40658. {
  40659. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40660. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40661. }
  40662. void TableHeaderComponent::paint (Graphics& g)
  40663. {
  40664. LookAndFeel& lf = getLookAndFeel();
  40665. lf.drawTableHeaderBackground (g, *this);
  40666. const Rectangle<int> clip (g.getClipBounds());
  40667. int x = 0;
  40668. for (int i = 0; i < columns.size(); ++i)
  40669. {
  40670. const ColumnInfo* const ci = columns.getUnchecked(i);
  40671. if (ci->isVisible())
  40672. {
  40673. if (x + ci->width > clip.getX()
  40674. && (ci->id != columnIdBeingDragged
  40675. || dragOverlayComp == 0
  40676. || ! dragOverlayComp->isVisible()))
  40677. {
  40678. g.saveState();
  40679. g.setOrigin (x, 0);
  40680. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40681. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40682. ci->id == columnIdUnderMouse,
  40683. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40684. ci->propertyFlags);
  40685. g.restoreState();
  40686. }
  40687. x += ci->width;
  40688. if (x >= clip.getRight())
  40689. break;
  40690. }
  40691. }
  40692. }
  40693. void TableHeaderComponent::resized()
  40694. {
  40695. }
  40696. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40697. {
  40698. updateColumnUnderMouse (e.x, e.y);
  40699. }
  40700. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40701. {
  40702. updateColumnUnderMouse (e.x, e.y);
  40703. }
  40704. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40705. {
  40706. updateColumnUnderMouse (e.x, e.y);
  40707. }
  40708. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40709. {
  40710. repaint();
  40711. columnIdBeingResized = 0;
  40712. columnIdBeingDragged = 0;
  40713. if (columnIdUnderMouse != 0)
  40714. {
  40715. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40716. if (e.mods.isPopupMenu())
  40717. columnClicked (columnIdUnderMouse, e.mods);
  40718. }
  40719. if (menuActive && e.mods.isPopupMenu())
  40720. showColumnChooserMenu (columnIdUnderMouse);
  40721. }
  40722. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40723. {
  40724. if (columnIdBeingResized == 0
  40725. && columnIdBeingDragged == 0
  40726. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40727. {
  40728. dragOverlayComp = 0;
  40729. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40730. if (columnIdBeingResized != 0)
  40731. {
  40732. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40733. initialColumnWidth = ci->width;
  40734. }
  40735. else
  40736. {
  40737. beginDrag (e);
  40738. }
  40739. }
  40740. if (columnIdBeingResized != 0)
  40741. {
  40742. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40743. if (ci != 0)
  40744. {
  40745. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40746. initialColumnWidth + e.getDistanceFromDragStartX());
  40747. if (stretchToFit)
  40748. {
  40749. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40750. int minWidthOnRight = 0;
  40751. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40752. if (columns.getUnchecked (i)->isVisible())
  40753. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40754. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40755. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40756. }
  40757. setColumnWidth (columnIdBeingResized, w);
  40758. }
  40759. }
  40760. else if (columnIdBeingDragged != 0)
  40761. {
  40762. if (e.y >= -50 && e.y < getHeight() + 50)
  40763. {
  40764. if (dragOverlayComp != 0)
  40765. {
  40766. dragOverlayComp->setVisible (true);
  40767. dragOverlayComp->setBounds (jlimit (0,
  40768. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40769. e.x - draggingColumnOffset),
  40770. 0,
  40771. dragOverlayComp->getWidth(),
  40772. getHeight());
  40773. for (int i = columns.size(); --i >= 0;)
  40774. {
  40775. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40776. int newIndex = currentIndex;
  40777. if (newIndex > 0)
  40778. {
  40779. // if the previous column isn't draggable, we can't move our column
  40780. // past it, because that'd change the undraggable column's position..
  40781. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40782. if ((previous->propertyFlags & draggable) != 0)
  40783. {
  40784. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40785. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40786. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40787. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40788. {
  40789. --newIndex;
  40790. }
  40791. }
  40792. }
  40793. if (newIndex < columns.size() - 1)
  40794. {
  40795. // if the next column isn't draggable, we can't move our column
  40796. // past it, because that'd change the undraggable column's position..
  40797. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40798. if ((nextCol->propertyFlags & draggable) != 0)
  40799. {
  40800. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40801. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40802. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40803. > abs (dragOverlayComp->getRight() - rightOfNext))
  40804. {
  40805. ++newIndex;
  40806. }
  40807. }
  40808. }
  40809. if (newIndex != currentIndex)
  40810. moveColumn (columnIdBeingDragged, newIndex);
  40811. else
  40812. break;
  40813. }
  40814. }
  40815. }
  40816. else
  40817. {
  40818. endDrag (draggingColumnOriginalIndex);
  40819. }
  40820. }
  40821. }
  40822. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40823. {
  40824. if (columnIdBeingDragged == 0)
  40825. {
  40826. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40827. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40828. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40829. {
  40830. columnIdBeingDragged = 0;
  40831. }
  40832. else
  40833. {
  40834. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40835. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40836. const int temp = columnIdBeingDragged;
  40837. columnIdBeingDragged = 0;
  40838. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40839. columnIdBeingDragged = temp;
  40840. dragOverlayComp->setBounds (columnRect);
  40841. for (int i = listeners.size(); --i >= 0;)
  40842. {
  40843. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40844. i = jmin (i, listeners.size() - 1);
  40845. }
  40846. }
  40847. }
  40848. }
  40849. void TableHeaderComponent::endDrag (const int finalIndex)
  40850. {
  40851. if (columnIdBeingDragged != 0)
  40852. {
  40853. moveColumn (columnIdBeingDragged, finalIndex);
  40854. columnIdBeingDragged = 0;
  40855. repaint();
  40856. for (int i = listeners.size(); --i >= 0;)
  40857. {
  40858. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40859. i = jmin (i, listeners.size() - 1);
  40860. }
  40861. }
  40862. }
  40863. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40864. {
  40865. mouseDrag (e);
  40866. for (int i = columns.size(); --i >= 0;)
  40867. if (columns.getUnchecked (i)->isVisible())
  40868. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40869. columnIdBeingResized = 0;
  40870. repaint();
  40871. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40872. updateColumnUnderMouse (e.x, e.y);
  40873. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40874. columnClicked (columnIdUnderMouse, e.mods);
  40875. dragOverlayComp = 0;
  40876. }
  40877. const MouseCursor TableHeaderComponent::getMouseCursor()
  40878. {
  40879. int x, y;
  40880. getMouseXYRelative (x, y);
  40881. if (columnIdBeingResized != 0 || (getResizeDraggerAt (x) != 0 && ! isMouseButtonDown()))
  40882. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40883. return Component::getMouseCursor();
  40884. }
  40885. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40886. {
  40887. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40888. }
  40889. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40890. {
  40891. for (int i = columns.size(); --i >= 0;)
  40892. if (columns.getUnchecked(i)->id == id)
  40893. return columns.getUnchecked(i);
  40894. return 0;
  40895. }
  40896. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40897. {
  40898. int n = 0;
  40899. for (int i = 0; i < columns.size(); ++i)
  40900. {
  40901. if (columns.getUnchecked(i)->isVisible())
  40902. {
  40903. if (n == visibleIndex)
  40904. return i;
  40905. ++n;
  40906. }
  40907. }
  40908. return -1;
  40909. }
  40910. void TableHeaderComponent::sendColumnsChanged()
  40911. {
  40912. if (stretchToFit && lastDeliberateWidth > 0)
  40913. resizeAllColumnsToFit (lastDeliberateWidth);
  40914. repaint();
  40915. columnsChanged = true;
  40916. triggerAsyncUpdate();
  40917. }
  40918. void TableHeaderComponent::handleAsyncUpdate()
  40919. {
  40920. const bool changed = columnsChanged || sortChanged;
  40921. const bool sized = columnsResized || changed;
  40922. const bool sorted = sortChanged;
  40923. columnsChanged = false;
  40924. columnsResized = false;
  40925. sortChanged = false;
  40926. if (sorted)
  40927. {
  40928. for (int i = listeners.size(); --i >= 0;)
  40929. {
  40930. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40931. i = jmin (i, listeners.size() - 1);
  40932. }
  40933. }
  40934. if (changed)
  40935. {
  40936. for (int i = listeners.size(); --i >= 0;)
  40937. {
  40938. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40939. i = jmin (i, listeners.size() - 1);
  40940. }
  40941. }
  40942. if (sized)
  40943. {
  40944. for (int i = listeners.size(); --i >= 0;)
  40945. {
  40946. listeners.getUnchecked(i)->tableColumnsResized (this);
  40947. i = jmin (i, listeners.size() - 1);
  40948. }
  40949. }
  40950. }
  40951. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40952. {
  40953. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40954. {
  40955. const int draggableDistance = 3;
  40956. int x = 0;
  40957. for (int i = 0; i < columns.size(); ++i)
  40958. {
  40959. const ColumnInfo* const ci = columns.getUnchecked(i);
  40960. if (ci->isVisible())
  40961. {
  40962. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40963. && (ci->propertyFlags & resizable) != 0)
  40964. return ci->id;
  40965. x += ci->width;
  40966. }
  40967. }
  40968. }
  40969. return 0;
  40970. }
  40971. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40972. {
  40973. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40974. ? getColumnIdAtX (x) : 0;
  40975. if (newCol != columnIdUnderMouse)
  40976. {
  40977. columnIdUnderMouse = newCol;
  40978. repaint();
  40979. }
  40980. }
  40981. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40982. {
  40983. PopupMenu m;
  40984. addMenuItems (m, columnIdClicked);
  40985. if (m.getNumItems() > 0)
  40986. {
  40987. m.setLookAndFeel (&getLookAndFeel());
  40988. const int result = m.show();
  40989. if (result != 0)
  40990. reactToMenuItem (result, columnIdClicked);
  40991. }
  40992. }
  40993. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40994. {
  40995. }
  40996. END_JUCE_NAMESPACE
  40997. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40998. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40999. BEGIN_JUCE_NAMESPACE
  41000. static const char* const tableColumnPropertyTag = "_tableColumnID";
  41001. class TableListRowComp : public Component,
  41002. public TooltipClient
  41003. {
  41004. public:
  41005. TableListRowComp (TableListBox& owner_)
  41006. : owner (owner_),
  41007. row (-1),
  41008. isSelected (false)
  41009. {
  41010. }
  41011. ~TableListRowComp()
  41012. {
  41013. deleteAllChildren();
  41014. }
  41015. void paint (Graphics& g)
  41016. {
  41017. TableListBoxModel* const model = owner.getModel();
  41018. if (model != 0)
  41019. {
  41020. const TableHeaderComponent* const header = owner.getHeader();
  41021. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  41022. const int numColumns = header->getNumColumns (true);
  41023. for (int i = 0; i < numColumns; ++i)
  41024. {
  41025. if (! columnsWithComponents [i])
  41026. {
  41027. const int columnId = header->getColumnIdOfIndex (i, true);
  41028. Rectangle<int> columnRect (header->getColumnPosition (i));
  41029. columnRect.setSize (columnRect.getWidth(), getHeight());
  41030. g.saveState();
  41031. g.reduceClipRegion (columnRect);
  41032. g.setOrigin (columnRect.getX(), 0);
  41033. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  41034. g.restoreState();
  41035. }
  41036. }
  41037. }
  41038. }
  41039. void update (const int newRow, const bool isNowSelected)
  41040. {
  41041. if (newRow != row || isNowSelected != isSelected)
  41042. {
  41043. row = newRow;
  41044. isSelected = isNowSelected;
  41045. repaint();
  41046. }
  41047. if (row < owner.getNumRows())
  41048. {
  41049. jassert (row >= 0);
  41050. const var::identifier tagPropertyName ("_tableLastUseNum");
  41051. const int newTag = Random::getSystemRandom().nextInt();
  41052. const TableHeaderComponent* const header = owner.getHeader();
  41053. const int numColumns = header->getNumColumns (true);
  41054. int i;
  41055. columnsWithComponents.clear();
  41056. if (owner.getModel() != 0)
  41057. {
  41058. for (i = 0; i < numColumns; ++i)
  41059. {
  41060. const int columnId = header->getColumnIdOfIndex (i, true);
  41061. Component* const newComp
  41062. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  41063. findChildComponentForColumn (columnId));
  41064. if (newComp != 0)
  41065. {
  41066. addAndMakeVisible (newComp);
  41067. newComp->getProperties().set (tagPropertyName, newTag);
  41068. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  41069. const Rectangle<int> columnRect (header->getColumnPosition (i));
  41070. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41071. columnsWithComponents.setBit (i);
  41072. }
  41073. }
  41074. }
  41075. for (i = getNumChildComponents(); --i >= 0;)
  41076. {
  41077. Component* const c = getChildComponent (i);
  41078. if ((int) c->getProperties() [tagPropertyName] != newTag)
  41079. delete c;
  41080. }
  41081. }
  41082. else
  41083. {
  41084. columnsWithComponents.clear();
  41085. deleteAllChildren();
  41086. }
  41087. }
  41088. void resized()
  41089. {
  41090. for (int i = getNumChildComponents(); --i >= 0;)
  41091. {
  41092. Component* const c = getChildComponent (i);
  41093. const int columnId = c->getProperties() [tableColumnPropertyTag];
  41094. if (columnId != 0)
  41095. {
  41096. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41097. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41098. }
  41099. }
  41100. }
  41101. void mouseDown (const MouseEvent& e)
  41102. {
  41103. isDragging = false;
  41104. selectRowOnMouseUp = false;
  41105. if (isEnabled())
  41106. {
  41107. if (! isSelected)
  41108. {
  41109. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41110. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41111. if (columnId != 0 && owner.getModel() != 0)
  41112. owner.getModel()->cellClicked (row, columnId, e);
  41113. }
  41114. else
  41115. {
  41116. selectRowOnMouseUp = true;
  41117. }
  41118. }
  41119. }
  41120. void mouseDrag (const MouseEvent& e)
  41121. {
  41122. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41123. {
  41124. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41125. if (selectedRows.size() > 0)
  41126. {
  41127. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41128. if (dragDescription.isNotEmpty())
  41129. {
  41130. isDragging = true;
  41131. owner.startDragAndDrop (e, dragDescription);
  41132. }
  41133. }
  41134. }
  41135. }
  41136. void mouseUp (const MouseEvent& e)
  41137. {
  41138. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41139. {
  41140. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41141. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41142. if (columnId != 0 && owner.getModel() != 0)
  41143. owner.getModel()->cellClicked (row, columnId, e);
  41144. }
  41145. }
  41146. void mouseDoubleClick (const MouseEvent& e)
  41147. {
  41148. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41149. if (columnId != 0 && owner.getModel() != 0)
  41150. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41151. }
  41152. const String getTooltip()
  41153. {
  41154. int x, y;
  41155. getMouseXYRelative (x, y);
  41156. const int columnId = owner.getHeader()->getColumnIdAtX (x);
  41157. if (columnId != 0 && owner.getModel() != 0)
  41158. return owner.getModel()->getCellTooltip (row, columnId);
  41159. return String::empty;
  41160. }
  41161. juce_UseDebuggingNewOperator
  41162. private:
  41163. TableListBox& owner;
  41164. int row;
  41165. bool isSelected, isDragging, selectRowOnMouseUp;
  41166. BitArray columnsWithComponents;
  41167. Component* findChildComponentForColumn (const int columnId) const
  41168. {
  41169. for (int i = getNumChildComponents(); --i >= 0;)
  41170. {
  41171. Component* const c = getChildComponent (i);
  41172. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  41173. return c;
  41174. }
  41175. return 0;
  41176. }
  41177. TableListRowComp (const TableListRowComp&);
  41178. const TableListRowComp& operator= (const TableListRowComp&);
  41179. };
  41180. class TableListBoxHeader : public TableHeaderComponent
  41181. {
  41182. public:
  41183. TableListBoxHeader (TableListBox& owner_)
  41184. : owner (owner_)
  41185. {
  41186. }
  41187. ~TableListBoxHeader()
  41188. {
  41189. }
  41190. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41191. {
  41192. if (owner.isAutoSizeMenuOptionShown())
  41193. {
  41194. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41195. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41196. menu.addSeparator();
  41197. }
  41198. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41199. }
  41200. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41201. {
  41202. if (menuReturnId == 0xf836743)
  41203. {
  41204. owner.autoSizeColumn (columnIdClicked);
  41205. }
  41206. else if (menuReturnId == 0xf836744)
  41207. {
  41208. owner.autoSizeAllColumns();
  41209. }
  41210. else
  41211. {
  41212. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41213. }
  41214. }
  41215. juce_UseDebuggingNewOperator
  41216. private:
  41217. TableListBox& owner;
  41218. TableListBoxHeader (const TableListBoxHeader&);
  41219. const TableListBoxHeader& operator= (const TableListBoxHeader&);
  41220. };
  41221. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41222. : ListBox (name, 0),
  41223. model (model_),
  41224. autoSizeOptionsShown (true)
  41225. {
  41226. ListBox::model = this;
  41227. header = new TableListBoxHeader (*this);
  41228. header->setSize (100, 28);
  41229. header->addListener (this);
  41230. setHeaderComponent (header);
  41231. }
  41232. TableListBox::~TableListBox()
  41233. {
  41234. deleteAllChildren();
  41235. }
  41236. void TableListBox::setModel (TableListBoxModel* const newModel)
  41237. {
  41238. if (model != newModel)
  41239. {
  41240. model = newModel;
  41241. updateContent();
  41242. }
  41243. }
  41244. int TableListBox::getHeaderHeight() const
  41245. {
  41246. return header->getHeight();
  41247. }
  41248. void TableListBox::setHeaderHeight (const int newHeight)
  41249. {
  41250. header->setSize (header->getWidth(), newHeight);
  41251. resized();
  41252. }
  41253. void TableListBox::autoSizeColumn (const int columnId)
  41254. {
  41255. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41256. if (width > 0)
  41257. header->setColumnWidth (columnId, width);
  41258. }
  41259. void TableListBox::autoSizeAllColumns()
  41260. {
  41261. for (int i = 0; i < header->getNumColumns (true); ++i)
  41262. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41263. }
  41264. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41265. {
  41266. autoSizeOptionsShown = shouldBeShown;
  41267. }
  41268. bool TableListBox::isAutoSizeMenuOptionShown() const
  41269. {
  41270. return autoSizeOptionsShown;
  41271. }
  41272. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  41273. const int rowNumber,
  41274. const bool relativeToComponentTopLeft) const
  41275. {
  41276. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41277. if (relativeToComponentTopLeft)
  41278. headerCell.translate (header->getX(), 0);
  41279. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41280. return Rectangle<int> (headerCell.getX(), row.getY(),
  41281. headerCell.getWidth(), row.getHeight());
  41282. }
  41283. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41284. {
  41285. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41286. if (scrollbar != 0)
  41287. {
  41288. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41289. double x = scrollbar->getCurrentRangeStart();
  41290. const double w = scrollbar->getCurrentRangeSize();
  41291. if (pos.getX() < x)
  41292. x = pos.getX();
  41293. else if (pos.getRight() > x + w)
  41294. x += jmax (0.0, pos.getRight() - (x + w));
  41295. scrollbar->setCurrentRangeStart (x);
  41296. }
  41297. }
  41298. int TableListBox::getNumRows()
  41299. {
  41300. return model != 0 ? model->getNumRows() : 0;
  41301. }
  41302. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41303. {
  41304. }
  41305. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41306. {
  41307. if (existingComponentToUpdate == 0)
  41308. existingComponentToUpdate = new TableListRowComp (*this);
  41309. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41310. return existingComponentToUpdate;
  41311. }
  41312. void TableListBox::selectedRowsChanged (int row)
  41313. {
  41314. if (model != 0)
  41315. model->selectedRowsChanged (row);
  41316. }
  41317. void TableListBox::deleteKeyPressed (int row)
  41318. {
  41319. if (model != 0)
  41320. model->deleteKeyPressed (row);
  41321. }
  41322. void TableListBox::returnKeyPressed (int row)
  41323. {
  41324. if (model != 0)
  41325. model->returnKeyPressed (row);
  41326. }
  41327. void TableListBox::backgroundClicked()
  41328. {
  41329. if (model != 0)
  41330. model->backgroundClicked();
  41331. }
  41332. void TableListBox::listWasScrolled()
  41333. {
  41334. if (model != 0)
  41335. model->listWasScrolled();
  41336. }
  41337. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41338. {
  41339. setMinimumContentWidth (header->getTotalWidth());
  41340. repaint();
  41341. updateColumnComponents();
  41342. }
  41343. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41344. {
  41345. setMinimumContentWidth (header->getTotalWidth());
  41346. repaint();
  41347. updateColumnComponents();
  41348. }
  41349. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41350. {
  41351. if (model != 0)
  41352. model->sortOrderChanged (header->getSortColumnId(),
  41353. header->isSortedForwards());
  41354. }
  41355. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41356. {
  41357. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41358. repaint();
  41359. }
  41360. void TableListBox::resized()
  41361. {
  41362. ListBox::resized();
  41363. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41364. setMinimumContentWidth (header->getTotalWidth());
  41365. }
  41366. void TableListBox::updateColumnComponents() const
  41367. {
  41368. const int firstRow = getRowContainingPosition (0, 0);
  41369. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41370. {
  41371. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41372. if (rowComp != 0)
  41373. rowComp->resized();
  41374. }
  41375. }
  41376. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41377. {
  41378. }
  41379. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41380. {
  41381. }
  41382. void TableListBoxModel::backgroundClicked()
  41383. {
  41384. }
  41385. void TableListBoxModel::sortOrderChanged (int, const bool)
  41386. {
  41387. }
  41388. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41389. {
  41390. return 0;
  41391. }
  41392. void TableListBoxModel::selectedRowsChanged (int)
  41393. {
  41394. }
  41395. void TableListBoxModel::deleteKeyPressed (int)
  41396. {
  41397. }
  41398. void TableListBoxModel::returnKeyPressed (int)
  41399. {
  41400. }
  41401. void TableListBoxModel::listWasScrolled()
  41402. {
  41403. }
  41404. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41405. {
  41406. return String::empty;
  41407. }
  41408. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41409. {
  41410. return String::empty;
  41411. }
  41412. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41413. {
  41414. (void) existingComponentToUpdate;
  41415. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41416. return 0;
  41417. }
  41418. END_JUCE_NAMESPACE
  41419. /*** End of inlined file: juce_TableListBox.cpp ***/
  41420. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41421. BEGIN_JUCE_NAMESPACE
  41422. // a word or space that can't be broken down any further
  41423. struct TextAtom
  41424. {
  41425. String atomText;
  41426. float width;
  41427. uint16 numChars;
  41428. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41429. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41430. const String getText (const tchar passwordCharacter) const
  41431. {
  41432. if (passwordCharacter == 0)
  41433. return atomText;
  41434. else
  41435. return String::repeatedString (String::charToString (passwordCharacter),
  41436. atomText.length());
  41437. }
  41438. const String getTrimmedText (const tchar passwordCharacter) const
  41439. {
  41440. if (passwordCharacter == 0)
  41441. return atomText.substring (0, numChars);
  41442. else if (isNewLine())
  41443. return String::empty;
  41444. else
  41445. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41446. }
  41447. };
  41448. // a run of text with a single font and colour
  41449. class UniformTextSection
  41450. {
  41451. public:
  41452. UniformTextSection (const String& text,
  41453. const Font& font_,
  41454. const Colour& colour_,
  41455. const tchar passwordCharacter)
  41456. : font (font_),
  41457. colour (colour_)
  41458. {
  41459. initialiseAtoms (text, passwordCharacter);
  41460. }
  41461. UniformTextSection (const UniformTextSection& other)
  41462. : font (other.font),
  41463. colour (other.colour)
  41464. {
  41465. atoms.ensureStorageAllocated (other.atoms.size());
  41466. for (int i = 0; i < other.atoms.size(); ++i)
  41467. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41468. }
  41469. ~UniformTextSection()
  41470. {
  41471. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41472. }
  41473. void clear()
  41474. {
  41475. for (int i = atoms.size(); --i >= 0;)
  41476. delete getAtom(i);
  41477. atoms.clear();
  41478. }
  41479. int getNumAtoms() const
  41480. {
  41481. return atoms.size();
  41482. }
  41483. TextAtom* getAtom (const int index) const
  41484. {
  41485. return (TextAtom*) atoms.getUnchecked (index);
  41486. }
  41487. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41488. {
  41489. if (other.atoms.size() > 0)
  41490. {
  41491. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41492. int i = 0;
  41493. if (lastAtom != 0)
  41494. {
  41495. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41496. {
  41497. TextAtom* const first = other.getAtom(0);
  41498. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41499. {
  41500. lastAtom->atomText += first->atomText;
  41501. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41502. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41503. delete first;
  41504. ++i;
  41505. }
  41506. }
  41507. }
  41508. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41509. while (i < other.atoms.size())
  41510. {
  41511. atoms.add (other.getAtom(i));
  41512. ++i;
  41513. }
  41514. }
  41515. }
  41516. UniformTextSection* split (const int indexToBreakAt,
  41517. const tchar passwordCharacter)
  41518. {
  41519. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41520. font, colour,
  41521. passwordCharacter);
  41522. int index = 0;
  41523. for (int i = 0; i < atoms.size(); ++i)
  41524. {
  41525. TextAtom* const atom = getAtom(i);
  41526. const int nextIndex = index + atom->numChars;
  41527. if (index == indexToBreakAt)
  41528. {
  41529. int j;
  41530. for (j = i; j < atoms.size(); ++j)
  41531. section2->atoms.add (getAtom (j));
  41532. for (j = atoms.size(); --j >= i;)
  41533. atoms.remove (j);
  41534. break;
  41535. }
  41536. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41537. {
  41538. TextAtom* const secondAtom = new TextAtom();
  41539. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41540. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41541. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41542. section2->atoms.add (secondAtom);
  41543. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41544. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41545. atom->numChars = (uint16) (indexToBreakAt - index);
  41546. int j;
  41547. for (j = i + 1; j < atoms.size(); ++j)
  41548. section2->atoms.add (getAtom (j));
  41549. for (j = atoms.size(); --j > i;)
  41550. atoms.remove (j);
  41551. break;
  41552. }
  41553. index = nextIndex;
  41554. }
  41555. return section2;
  41556. }
  41557. void appendAllText (String::Concatenator& concatenator) const
  41558. {
  41559. for (int i = 0; i < atoms.size(); ++i)
  41560. concatenator.append (getAtom(i)->atomText);
  41561. }
  41562. void appendSubstring (String::Concatenator& concatenator,
  41563. const int startCharacter,
  41564. const int endCharacter) const
  41565. {
  41566. int index = 0;
  41567. for (int i = 0; i < atoms.size(); ++i)
  41568. {
  41569. const TextAtom* const atom = getAtom (i);
  41570. const int nextIndex = index + atom->numChars;
  41571. if (startCharacter < nextIndex)
  41572. {
  41573. if (endCharacter <= index)
  41574. break;
  41575. const int start = jmax (0, startCharacter - index);
  41576. const int end = jmin (endCharacter - index, (int) atom->numChars);
  41577. if (start < end)
  41578. concatenator.append (atom->atomText.substring (start, end));
  41579. }
  41580. index = nextIndex;
  41581. }
  41582. }
  41583. int getTotalLength() const
  41584. {
  41585. int total = 0;
  41586. for (int i = atoms.size(); --i >= 0;)
  41587. total += getAtom(i)->numChars;
  41588. return total;
  41589. }
  41590. void setFont (const Font& newFont,
  41591. const tchar passwordCharacter)
  41592. {
  41593. if (font != newFont)
  41594. {
  41595. font = newFont;
  41596. for (int i = atoms.size(); --i >= 0;)
  41597. {
  41598. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41599. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41600. }
  41601. }
  41602. }
  41603. juce_UseDebuggingNewOperator
  41604. Font font;
  41605. Colour colour;
  41606. private:
  41607. VoidArray atoms;
  41608. void initialiseAtoms (const String& textToParse,
  41609. const tchar passwordCharacter)
  41610. {
  41611. int i = 0;
  41612. const int len = textToParse.length();
  41613. const tchar* const text = (const tchar*) textToParse;
  41614. while (i < len)
  41615. {
  41616. int start = i;
  41617. // create a whitespace atom unless it starts with non-ws
  41618. if (CharacterFunctions::isWhitespace (text[i])
  41619. && text[i] != T('\r')
  41620. && text[i] != T('\n'))
  41621. {
  41622. while (i < len
  41623. && CharacterFunctions::isWhitespace (text[i])
  41624. && text[i] != T('\r')
  41625. && text[i] != T('\n'))
  41626. {
  41627. ++i;
  41628. }
  41629. }
  41630. else
  41631. {
  41632. if (text[i] == T('\r'))
  41633. {
  41634. ++i;
  41635. if ((i < len) && (text[i] == T('\n')))
  41636. {
  41637. ++start;
  41638. ++i;
  41639. }
  41640. }
  41641. else if (text[i] == T('\n'))
  41642. {
  41643. ++i;
  41644. }
  41645. else
  41646. {
  41647. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41648. ++i;
  41649. }
  41650. }
  41651. TextAtom* const atom = new TextAtom();
  41652. atom->atomText = String (text + start, i - start);
  41653. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41654. atom->numChars = (uint16) (i - start);
  41655. atoms.add (atom);
  41656. }
  41657. }
  41658. const UniformTextSection& operator= (const UniformTextSection& other);
  41659. };
  41660. class TextEditorIterator
  41661. {
  41662. public:
  41663. TextEditorIterator (const VoidArray& sections_,
  41664. const float wordWrapWidth_,
  41665. const tchar passwordCharacter_)
  41666. : indexInText (0),
  41667. lineY (0),
  41668. lineHeight (0),
  41669. maxDescent (0),
  41670. atomX (0),
  41671. atomRight (0),
  41672. atom (0),
  41673. currentSection (0),
  41674. sections (sections_),
  41675. sectionIndex (0),
  41676. atomIndex (0),
  41677. wordWrapWidth (wordWrapWidth_),
  41678. passwordCharacter (passwordCharacter_)
  41679. {
  41680. jassert (wordWrapWidth_ > 0);
  41681. if (sections.size() > 0)
  41682. {
  41683. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41684. if (currentSection != 0)
  41685. beginNewLine();
  41686. }
  41687. }
  41688. TextEditorIterator (const TextEditorIterator& other)
  41689. : indexInText (other.indexInText),
  41690. lineY (other.lineY),
  41691. lineHeight (other.lineHeight),
  41692. maxDescent (other.maxDescent),
  41693. atomX (other.atomX),
  41694. atomRight (other.atomRight),
  41695. atom (other.atom),
  41696. currentSection (other.currentSection),
  41697. sections (other.sections),
  41698. sectionIndex (other.sectionIndex),
  41699. atomIndex (other.atomIndex),
  41700. wordWrapWidth (other.wordWrapWidth),
  41701. passwordCharacter (other.passwordCharacter),
  41702. tempAtom (other.tempAtom)
  41703. {
  41704. }
  41705. ~TextEditorIterator()
  41706. {
  41707. }
  41708. bool next()
  41709. {
  41710. if (atom == &tempAtom)
  41711. {
  41712. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41713. if (numRemaining > 0)
  41714. {
  41715. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41716. atomX = 0;
  41717. if (tempAtom.numChars > 0)
  41718. lineY += lineHeight;
  41719. indexInText += tempAtom.numChars;
  41720. GlyphArrangement g;
  41721. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41722. int split;
  41723. for (split = 0; split < g.getNumGlyphs(); ++split)
  41724. if (shouldWrap (g.getGlyph (split).getRight()))
  41725. break;
  41726. if (split > 0 && split <= numRemaining)
  41727. {
  41728. tempAtom.numChars = (uint16) split;
  41729. tempAtom.width = g.getGlyph (split - 1).getRight();
  41730. atomRight = atomX + tempAtom.width;
  41731. return true;
  41732. }
  41733. }
  41734. }
  41735. bool forceNewLine = false;
  41736. if (sectionIndex >= sections.size())
  41737. {
  41738. moveToEndOfLastAtom();
  41739. return false;
  41740. }
  41741. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41742. {
  41743. if (atomIndex >= currentSection->getNumAtoms())
  41744. {
  41745. if (++sectionIndex >= sections.size())
  41746. {
  41747. moveToEndOfLastAtom();
  41748. return false;
  41749. }
  41750. atomIndex = 0;
  41751. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41752. }
  41753. else
  41754. {
  41755. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41756. if (! lastAtom->isWhitespace())
  41757. {
  41758. // handle the case where the last atom in a section is actually part of the same
  41759. // word as the first atom of the next section...
  41760. float right = atomRight + lastAtom->width;
  41761. float lineHeight2 = lineHeight;
  41762. float maxDescent2 = maxDescent;
  41763. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41764. {
  41765. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41766. if (s->getNumAtoms() == 0)
  41767. break;
  41768. const TextAtom* const nextAtom = s->getAtom (0);
  41769. if (nextAtom->isWhitespace())
  41770. break;
  41771. right += nextAtom->width;
  41772. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41773. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41774. if (shouldWrap (right))
  41775. {
  41776. lineHeight = lineHeight2;
  41777. maxDescent = maxDescent2;
  41778. forceNewLine = true;
  41779. break;
  41780. }
  41781. if (s->getNumAtoms() > 1)
  41782. break;
  41783. }
  41784. }
  41785. }
  41786. }
  41787. if (atom != 0)
  41788. {
  41789. atomX = atomRight;
  41790. indexInText += atom->numChars;
  41791. if (atom->isNewLine())
  41792. beginNewLine();
  41793. }
  41794. atom = currentSection->getAtom (atomIndex);
  41795. atomRight = atomX + atom->width;
  41796. ++atomIndex;
  41797. if (shouldWrap (atomRight) || forceNewLine)
  41798. {
  41799. if (atom->isWhitespace())
  41800. {
  41801. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41802. atomRight = jmin (atomRight, wordWrapWidth);
  41803. }
  41804. else
  41805. {
  41806. atomRight = atom->width;
  41807. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41808. {
  41809. tempAtom = *atom;
  41810. tempAtom.width = 0;
  41811. tempAtom.numChars = 0;
  41812. atom = &tempAtom;
  41813. if (atomX > 0)
  41814. beginNewLine();
  41815. return next();
  41816. }
  41817. beginNewLine();
  41818. return true;
  41819. }
  41820. }
  41821. return true;
  41822. }
  41823. void beginNewLine()
  41824. {
  41825. atomX = 0;
  41826. lineY += lineHeight;
  41827. int tempSectionIndex = sectionIndex;
  41828. int tempAtomIndex = atomIndex;
  41829. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41830. lineHeight = section->font.getHeight();
  41831. maxDescent = section->font.getDescent();
  41832. float x = (atom != 0) ? atom->width : 0;
  41833. while (! shouldWrap (x))
  41834. {
  41835. if (tempSectionIndex >= sections.size())
  41836. break;
  41837. bool checkSize = false;
  41838. if (tempAtomIndex >= section->getNumAtoms())
  41839. {
  41840. if (++tempSectionIndex >= sections.size())
  41841. break;
  41842. tempAtomIndex = 0;
  41843. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41844. checkSize = true;
  41845. }
  41846. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41847. if (nextAtom == 0)
  41848. break;
  41849. x += nextAtom->width;
  41850. if (shouldWrap (x) || nextAtom->isNewLine())
  41851. break;
  41852. if (checkSize)
  41853. {
  41854. lineHeight = jmax (lineHeight, section->font.getHeight());
  41855. maxDescent = jmax (maxDescent, section->font.getDescent());
  41856. }
  41857. ++tempAtomIndex;
  41858. }
  41859. }
  41860. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41861. {
  41862. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41863. {
  41864. if (lastSection != currentSection)
  41865. {
  41866. lastSection = currentSection;
  41867. g.setColour (currentSection->colour);
  41868. g.setFont (currentSection->font);
  41869. }
  41870. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41871. GlyphArrangement ga;
  41872. ga.addLineOfText (currentSection->font,
  41873. atom->getTrimmedText (passwordCharacter),
  41874. atomX,
  41875. (float) roundToInt (lineY + lineHeight - maxDescent));
  41876. ga.draw (g);
  41877. }
  41878. }
  41879. void drawSelection (Graphics& g,
  41880. const int selectionStart,
  41881. const int selectionEnd) const
  41882. {
  41883. const int startX = roundToInt (indexToX (selectionStart));
  41884. const int endX = roundToInt (indexToX (selectionEnd));
  41885. const int y = roundToInt (lineY);
  41886. const int nextY = roundToInt (lineY + lineHeight);
  41887. g.fillRect (startX, y, endX - startX, nextY - y);
  41888. }
  41889. void drawSelectedText (Graphics& g,
  41890. const int selectionStart,
  41891. const int selectionEnd,
  41892. const Colour& selectedTextColour) const
  41893. {
  41894. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41895. {
  41896. GlyphArrangement ga;
  41897. ga.addLineOfText (currentSection->font,
  41898. atom->getTrimmedText (passwordCharacter),
  41899. atomX,
  41900. (float) roundToInt (lineY + lineHeight - maxDescent));
  41901. if (selectionEnd < indexInText + atom->numChars)
  41902. {
  41903. GlyphArrangement ga2 (ga);
  41904. ga2.removeRangeOfGlyphs (0, selectionEnd - indexInText);
  41905. ga.removeRangeOfGlyphs (selectionEnd - indexInText, -1);
  41906. g.setColour (currentSection->colour);
  41907. ga2.draw (g);
  41908. }
  41909. if (selectionStart > indexInText)
  41910. {
  41911. GlyphArrangement ga2 (ga);
  41912. ga2.removeRangeOfGlyphs (selectionStart - indexInText, -1);
  41913. ga.removeRangeOfGlyphs (0, selectionStart - indexInText);
  41914. g.setColour (currentSection->colour);
  41915. ga2.draw (g);
  41916. }
  41917. g.setColour (selectedTextColour);
  41918. ga.draw (g);
  41919. }
  41920. }
  41921. float indexToX (const int indexToFind) const
  41922. {
  41923. if (indexToFind <= indexInText)
  41924. return atomX;
  41925. if (indexToFind >= indexInText + atom->numChars)
  41926. return atomRight;
  41927. GlyphArrangement g;
  41928. g.addLineOfText (currentSection->font,
  41929. atom->getText (passwordCharacter),
  41930. atomX, 0.0f);
  41931. if (indexToFind - indexInText >= g.getNumGlyphs())
  41932. return atomRight;
  41933. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41934. }
  41935. int xToIndex (const float xToFind) const
  41936. {
  41937. if (xToFind <= atomX || atom->isNewLine())
  41938. return indexInText;
  41939. if (xToFind >= atomRight)
  41940. return indexInText + atom->numChars;
  41941. GlyphArrangement g;
  41942. g.addLineOfText (currentSection->font,
  41943. atom->getText (passwordCharacter),
  41944. atomX, 0.0f);
  41945. int j;
  41946. for (j = 0; j < g.getNumGlyphs(); ++j)
  41947. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41948. break;
  41949. return indexInText + j;
  41950. }
  41951. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41952. {
  41953. while (next())
  41954. {
  41955. if (indexInText + atom->numChars > index)
  41956. {
  41957. cx = indexToX (index);
  41958. cy = lineY;
  41959. lineHeight_ = lineHeight;
  41960. return true;
  41961. }
  41962. }
  41963. cx = atomX;
  41964. cy = lineY;
  41965. lineHeight_ = lineHeight;
  41966. return false;
  41967. }
  41968. juce_UseDebuggingNewOperator
  41969. int indexInText;
  41970. float lineY, lineHeight, maxDescent;
  41971. float atomX, atomRight;
  41972. const TextAtom* atom;
  41973. const UniformTextSection* currentSection;
  41974. private:
  41975. const VoidArray& sections;
  41976. int sectionIndex, atomIndex;
  41977. const float wordWrapWidth;
  41978. const tchar passwordCharacter;
  41979. TextAtom tempAtom;
  41980. const TextEditorIterator& operator= (const TextEditorIterator&);
  41981. void moveToEndOfLastAtom()
  41982. {
  41983. if (atom != 0)
  41984. {
  41985. atomX = atomRight;
  41986. if (atom->isNewLine())
  41987. {
  41988. atomX = 0.0f;
  41989. lineY += lineHeight;
  41990. }
  41991. }
  41992. }
  41993. bool shouldWrap (const float x) const
  41994. {
  41995. return (x - 0.0001f) >= wordWrapWidth;
  41996. }
  41997. };
  41998. class TextEditorInsertAction : public UndoableAction
  41999. {
  42000. TextEditor& owner;
  42001. const String text;
  42002. const int insertIndex, oldCaretPos, newCaretPos;
  42003. const Font font;
  42004. const Colour colour;
  42005. TextEditorInsertAction (const TextEditorInsertAction&);
  42006. const TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  42007. public:
  42008. TextEditorInsertAction (TextEditor& owner_,
  42009. const String& text_,
  42010. const int insertIndex_,
  42011. const Font& font_,
  42012. const Colour& colour_,
  42013. const int oldCaretPos_,
  42014. const int newCaretPos_)
  42015. : owner (owner_),
  42016. text (text_),
  42017. insertIndex (insertIndex_),
  42018. oldCaretPos (oldCaretPos_),
  42019. newCaretPos (newCaretPos_),
  42020. font (font_),
  42021. colour (colour_)
  42022. {
  42023. }
  42024. ~TextEditorInsertAction()
  42025. {
  42026. }
  42027. bool perform()
  42028. {
  42029. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  42030. return true;
  42031. }
  42032. bool undo()
  42033. {
  42034. owner.remove (insertIndex, insertIndex + text.length(), 0, oldCaretPos);
  42035. return true;
  42036. }
  42037. int getSizeInUnits()
  42038. {
  42039. return text.length() + 16;
  42040. }
  42041. };
  42042. class TextEditorRemoveAction : public UndoableAction
  42043. {
  42044. TextEditor& owner;
  42045. const int startIndex, endIndex, oldCaretPos, newCaretPos;
  42046. VoidArray removedSections;
  42047. TextEditorRemoveAction (const TextEditorRemoveAction&);
  42048. const TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  42049. public:
  42050. TextEditorRemoveAction (TextEditor& owner_,
  42051. const int startIndex_,
  42052. const int endIndex_,
  42053. const int oldCaretPos_,
  42054. const int newCaretPos_,
  42055. const VoidArray& removedSections_)
  42056. : owner (owner_),
  42057. startIndex (startIndex_),
  42058. endIndex (endIndex_),
  42059. oldCaretPos (oldCaretPos_),
  42060. newCaretPos (newCaretPos_),
  42061. removedSections (removedSections_)
  42062. {
  42063. }
  42064. ~TextEditorRemoveAction()
  42065. {
  42066. for (int i = removedSections.size(); --i >= 0;)
  42067. {
  42068. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42069. section->clear();
  42070. delete section;
  42071. }
  42072. }
  42073. bool perform()
  42074. {
  42075. owner.remove (startIndex, endIndex, 0, newCaretPos);
  42076. return true;
  42077. }
  42078. bool undo()
  42079. {
  42080. owner.reinsert (startIndex, removedSections);
  42081. owner.moveCursorTo (oldCaretPos, false);
  42082. return true;
  42083. }
  42084. int getSizeInUnits()
  42085. {
  42086. int n = 0;
  42087. for (int i = removedSections.size(); --i >= 0;)
  42088. {
  42089. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42090. n += section->getTotalLength();
  42091. }
  42092. return n + 16;
  42093. }
  42094. };
  42095. class TextHolderComponent : public Component,
  42096. public Timer,
  42097. public Value::Listener
  42098. {
  42099. TextEditor& owner;
  42100. TextHolderComponent (const TextHolderComponent&);
  42101. const TextHolderComponent& operator= (const TextHolderComponent&);
  42102. public:
  42103. TextHolderComponent (TextEditor& owner_)
  42104. : owner (owner_)
  42105. {
  42106. setWantsKeyboardFocus (false);
  42107. setInterceptsMouseClicks (false, true);
  42108. owner.getTextValue().addListener (this);
  42109. }
  42110. ~TextHolderComponent()
  42111. {
  42112. owner.getTextValue().removeListener (this);
  42113. }
  42114. void paint (Graphics& g)
  42115. {
  42116. owner.drawContent (g);
  42117. }
  42118. void timerCallback()
  42119. {
  42120. owner.timerCallbackInt();
  42121. }
  42122. const MouseCursor getMouseCursor()
  42123. {
  42124. return owner.getMouseCursor();
  42125. }
  42126. void valueChanged (Value&)
  42127. {
  42128. owner.textWasChangedByValue();
  42129. }
  42130. };
  42131. class TextEditorViewport : public Viewport
  42132. {
  42133. TextEditor* const owner;
  42134. float lastWordWrapWidth;
  42135. TextEditorViewport (const TextEditorViewport&);
  42136. const TextEditorViewport& operator= (const TextEditorViewport&);
  42137. public:
  42138. TextEditorViewport (TextEditor* const owner_)
  42139. : owner (owner_),
  42140. lastWordWrapWidth (0)
  42141. {
  42142. }
  42143. ~TextEditorViewport()
  42144. {
  42145. }
  42146. void visibleAreaChanged (int, int, int, int)
  42147. {
  42148. const float wordWrapWidth = owner->getWordWrapWidth();
  42149. if (wordWrapWidth != lastWordWrapWidth)
  42150. {
  42151. lastWordWrapWidth = wordWrapWidth;
  42152. owner->updateTextHolderSize();
  42153. }
  42154. }
  42155. };
  42156. namespace TextEditorDefs
  42157. {
  42158. const int flashSpeedIntervalMs = 380;
  42159. const int textChangeMessageId = 0x10003001;
  42160. const int returnKeyMessageId = 0x10003002;
  42161. const int escapeKeyMessageId = 0x10003003;
  42162. const int focusLossMessageId = 0x10003004;
  42163. const int maxActionsPerTransaction = 100;
  42164. }
  42165. TextEditor::TextEditor (const String& name,
  42166. const tchar passwordCharacter_)
  42167. : Component (name),
  42168. borderSize (1, 1, 1, 3),
  42169. readOnly (false),
  42170. multiline (false),
  42171. wordWrap (false),
  42172. returnKeyStartsNewLine (false),
  42173. caretVisible (true),
  42174. popupMenuEnabled (true),
  42175. selectAllTextWhenFocused (false),
  42176. scrollbarVisible (true),
  42177. wasFocused (false),
  42178. caretFlashState (true),
  42179. keepCursorOnScreen (true),
  42180. tabKeyUsed (false),
  42181. menuActive (false),
  42182. valueTextNeedsUpdating (false),
  42183. cursorX (0),
  42184. cursorY (0),
  42185. cursorHeight (0),
  42186. maxTextLength (0),
  42187. selectionStart (0),
  42188. selectionEnd (0),
  42189. leftIndent (4),
  42190. topIndent (4),
  42191. lastTransactionTime (0),
  42192. currentFont (14.0f),
  42193. totalNumChars (0),
  42194. caretPosition (0),
  42195. passwordCharacter (passwordCharacter_),
  42196. dragType (notDragging)
  42197. {
  42198. setOpaque (true);
  42199. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42200. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42201. viewport->setWantsKeyboardFocus (false);
  42202. viewport->setScrollBarsShown (false, false);
  42203. setMouseCursor (MouseCursor::IBeamCursor);
  42204. setWantsKeyboardFocus (true);
  42205. }
  42206. TextEditor::~TextEditor()
  42207. {
  42208. textValue.referTo (Value());
  42209. clearInternal (0);
  42210. viewport = 0;
  42211. textHolder = 0;
  42212. }
  42213. void TextEditor::newTransaction()
  42214. {
  42215. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42216. undoManager.beginNewTransaction();
  42217. }
  42218. void TextEditor::doUndoRedo (const bool isRedo)
  42219. {
  42220. if (! isReadOnly())
  42221. {
  42222. if ((isRedo) ? undoManager.redo()
  42223. : undoManager.undo())
  42224. {
  42225. scrollToMakeSureCursorIsVisible();
  42226. repaint();
  42227. textChanged();
  42228. }
  42229. }
  42230. }
  42231. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42232. const bool shouldWordWrap)
  42233. {
  42234. multiline = shouldBeMultiLine;
  42235. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42236. setScrollbarsShown (scrollbarVisible);
  42237. viewport->setViewPosition (0, 0);
  42238. resized();
  42239. scrollToMakeSureCursorIsVisible();
  42240. }
  42241. bool TextEditor::isMultiLine() const
  42242. {
  42243. return multiline;
  42244. }
  42245. void TextEditor::setScrollbarsShown (bool enabled)
  42246. {
  42247. scrollbarVisible = enabled;
  42248. enabled = enabled && isMultiLine();
  42249. viewport->setScrollBarsShown (enabled, enabled);
  42250. }
  42251. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42252. {
  42253. readOnly = shouldBeReadOnly;
  42254. enablementChanged();
  42255. }
  42256. bool TextEditor::isReadOnly() const
  42257. {
  42258. return readOnly || ! isEnabled();
  42259. }
  42260. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42261. {
  42262. returnKeyStartsNewLine = shouldStartNewLine;
  42263. }
  42264. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42265. {
  42266. tabKeyUsed = shouldTabKeyBeUsed;
  42267. }
  42268. void TextEditor::setPopupMenuEnabled (const bool b)
  42269. {
  42270. popupMenuEnabled = b;
  42271. }
  42272. void TextEditor::setSelectAllWhenFocused (const bool b)
  42273. {
  42274. selectAllTextWhenFocused = b;
  42275. }
  42276. const Font TextEditor::getFont() const
  42277. {
  42278. return currentFont;
  42279. }
  42280. void TextEditor::setFont (const Font& newFont)
  42281. {
  42282. currentFont = newFont;
  42283. scrollToMakeSureCursorIsVisible();
  42284. }
  42285. void TextEditor::applyFontToAllText (const Font& newFont)
  42286. {
  42287. currentFont = newFont;
  42288. const Colour overallColour (findColour (textColourId));
  42289. for (int i = sections.size(); --i >= 0;)
  42290. {
  42291. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42292. uts->setFont (newFont, passwordCharacter);
  42293. uts->colour = overallColour;
  42294. }
  42295. coalesceSimilarSections();
  42296. updateTextHolderSize();
  42297. scrollToMakeSureCursorIsVisible();
  42298. repaint();
  42299. }
  42300. void TextEditor::colourChanged()
  42301. {
  42302. setOpaque (findColour (backgroundColourId).isOpaque());
  42303. repaint();
  42304. }
  42305. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42306. {
  42307. caretVisible = shouldCaretBeVisible;
  42308. if (shouldCaretBeVisible)
  42309. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42310. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42311. : MouseCursor::NormalCursor);
  42312. }
  42313. void TextEditor::setInputRestrictions (const int maxLen,
  42314. const String& chars)
  42315. {
  42316. maxTextLength = jmax (0, maxLen);
  42317. allowedCharacters = chars;
  42318. }
  42319. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42320. {
  42321. textToShowWhenEmpty = text;
  42322. colourForTextWhenEmpty = colourToUse;
  42323. }
  42324. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42325. {
  42326. if (passwordCharacter != newPasswordCharacter)
  42327. {
  42328. passwordCharacter = newPasswordCharacter;
  42329. resized();
  42330. repaint();
  42331. }
  42332. }
  42333. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42334. {
  42335. viewport->setScrollBarThickness (newThicknessPixels);
  42336. }
  42337. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42338. {
  42339. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42340. }
  42341. void TextEditor::clear()
  42342. {
  42343. clearInternal (0);
  42344. updateTextHolderSize();
  42345. undoManager.clearUndoHistory();
  42346. }
  42347. void TextEditor::setText (const String& newText,
  42348. const bool sendTextChangeMessage)
  42349. {
  42350. const int newLength = newText.length();
  42351. if (newLength != getTotalNumChars() || getText() != newText)
  42352. {
  42353. const int oldCursorPos = caretPosition;
  42354. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42355. clearInternal (0);
  42356. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42357. // if you're adding text with line-feeds to a single-line text editor, it
  42358. // ain't gonna look right!
  42359. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42360. if (cursorWasAtEnd && ! isMultiLine())
  42361. moveCursorTo (getTotalNumChars(), false);
  42362. else
  42363. moveCursorTo (oldCursorPos, false);
  42364. if (sendTextChangeMessage)
  42365. textChanged();
  42366. repaint();
  42367. }
  42368. updateTextHolderSize();
  42369. scrollToMakeSureCursorIsVisible();
  42370. undoManager.clearUndoHistory();
  42371. }
  42372. Value& TextEditor::getTextValue()
  42373. {
  42374. if (valueTextNeedsUpdating)
  42375. {
  42376. valueTextNeedsUpdating = false;
  42377. textValue = getText();
  42378. }
  42379. return textValue;
  42380. }
  42381. void TextEditor::textWasChangedByValue()
  42382. {
  42383. if (textValue.getValueSource().getReferenceCount() > 1)
  42384. setText (textValue.getValue());
  42385. }
  42386. void TextEditor::textChanged()
  42387. {
  42388. updateTextHolderSize();
  42389. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42390. if (textValue.getValueSource().getReferenceCount() > 1)
  42391. {
  42392. valueTextNeedsUpdating = false;
  42393. textValue = getText();
  42394. }
  42395. }
  42396. void TextEditor::returnPressed()
  42397. {
  42398. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42399. }
  42400. void TextEditor::escapePressed()
  42401. {
  42402. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42403. }
  42404. void TextEditor::addListener (TextEditorListener* const newListener)
  42405. {
  42406. jassert (newListener != 0)
  42407. if (newListener != 0)
  42408. listeners.add (newListener);
  42409. }
  42410. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42411. {
  42412. listeners.removeValue (listenerToRemove);
  42413. }
  42414. void TextEditor::timerCallbackInt()
  42415. {
  42416. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42417. if (caretFlashState != newState)
  42418. {
  42419. caretFlashState = newState;
  42420. if (caretFlashState)
  42421. wasFocused = true;
  42422. if (caretVisible
  42423. && hasKeyboardFocus (false)
  42424. && ! isReadOnly())
  42425. {
  42426. repaintCaret();
  42427. }
  42428. }
  42429. const unsigned int now = Time::getApproximateMillisecondCounter();
  42430. if (now > lastTransactionTime + 200)
  42431. newTransaction();
  42432. }
  42433. void TextEditor::repaintCaret()
  42434. {
  42435. if (! findColour (caretColourId).isTransparent())
  42436. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42437. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42438. 4,
  42439. roundToInt (cursorHeight) + 2);
  42440. }
  42441. void TextEditor::repaintText (int textStartIndex, int textEndIndex)
  42442. {
  42443. if (textStartIndex > textEndIndex && textEndIndex > 0)
  42444. swapVariables (textStartIndex, textEndIndex);
  42445. float x = 0, y = 0, lh = currentFont.getHeight();
  42446. const float wordWrapWidth = getWordWrapWidth();
  42447. if (wordWrapWidth > 0)
  42448. {
  42449. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42450. i.getCharPosition (textStartIndex, x, y, lh);
  42451. const int y1 = (int) y;
  42452. int y2;
  42453. if (textEndIndex >= 0)
  42454. {
  42455. i.getCharPosition (textEndIndex, x, y, lh);
  42456. y2 = (int) (y + lh * 2.0f);
  42457. }
  42458. else
  42459. {
  42460. y2 = textHolder->getHeight();
  42461. }
  42462. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42463. }
  42464. }
  42465. void TextEditor::moveCaret (int newCaretPos)
  42466. {
  42467. if (newCaretPos < 0)
  42468. newCaretPos = 0;
  42469. else if (newCaretPos > getTotalNumChars())
  42470. newCaretPos = getTotalNumChars();
  42471. if (newCaretPos != getCaretPosition())
  42472. {
  42473. repaintCaret();
  42474. caretFlashState = true;
  42475. caretPosition = newCaretPos;
  42476. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42477. scrollToMakeSureCursorIsVisible();
  42478. repaintCaret();
  42479. }
  42480. }
  42481. void TextEditor::setCaretPosition (const int newIndex)
  42482. {
  42483. moveCursorTo (newIndex, false);
  42484. }
  42485. int TextEditor::getCaretPosition() const
  42486. {
  42487. return caretPosition;
  42488. }
  42489. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42490. const int desiredCaretY)
  42491. {
  42492. updateCaretPosition();
  42493. int vx = roundToInt (cursorX) - desiredCaretX;
  42494. int vy = roundToInt (cursorY) - desiredCaretY;
  42495. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42496. {
  42497. vx += desiredCaretX - proportionOfWidth (0.2f);
  42498. }
  42499. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42500. {
  42501. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42502. }
  42503. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42504. if (! isMultiLine())
  42505. {
  42506. vy = viewport->getViewPositionY();
  42507. }
  42508. else
  42509. {
  42510. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42511. const int curH = roundToInt (cursorHeight);
  42512. if (desiredCaretY < 0)
  42513. {
  42514. vy = jmax (0, desiredCaretY + vy);
  42515. }
  42516. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42517. {
  42518. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42519. }
  42520. }
  42521. viewport->setViewPosition (vx, vy);
  42522. }
  42523. const Rectangle<int> TextEditor::getCaretRectangle()
  42524. {
  42525. updateCaretPosition();
  42526. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42527. roundToInt (cursorY) - viewport->getY(),
  42528. 1, roundToInt (cursorHeight));
  42529. }
  42530. float TextEditor::getWordWrapWidth() const
  42531. {
  42532. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42533. : 1.0e10f;
  42534. }
  42535. void TextEditor::updateTextHolderSize()
  42536. {
  42537. const float wordWrapWidth = getWordWrapWidth();
  42538. if (wordWrapWidth > 0)
  42539. {
  42540. float maxWidth = 0.0f;
  42541. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42542. while (i.next())
  42543. maxWidth = jmax (maxWidth, i.atomRight);
  42544. const int w = leftIndent + roundToInt (maxWidth);
  42545. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42546. currentFont.getHeight()));
  42547. textHolder->setSize (w + 1, h + 1);
  42548. }
  42549. }
  42550. int TextEditor::getTextWidth() const
  42551. {
  42552. return textHolder->getWidth();
  42553. }
  42554. int TextEditor::getTextHeight() const
  42555. {
  42556. return textHolder->getHeight();
  42557. }
  42558. void TextEditor::setIndents (const int newLeftIndent,
  42559. const int newTopIndent)
  42560. {
  42561. leftIndent = newLeftIndent;
  42562. topIndent = newTopIndent;
  42563. }
  42564. void TextEditor::setBorder (const BorderSize& border)
  42565. {
  42566. borderSize = border;
  42567. resized();
  42568. }
  42569. const BorderSize TextEditor::getBorder() const
  42570. {
  42571. return borderSize;
  42572. }
  42573. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42574. {
  42575. keepCursorOnScreen = shouldScrollToShowCursor;
  42576. }
  42577. void TextEditor::updateCaretPosition()
  42578. {
  42579. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42580. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42581. }
  42582. void TextEditor::scrollToMakeSureCursorIsVisible()
  42583. {
  42584. updateCaretPosition();
  42585. if (keepCursorOnScreen)
  42586. {
  42587. int x = viewport->getViewPositionX();
  42588. int y = viewport->getViewPositionY();
  42589. const int relativeCursorX = roundToInt (cursorX) - x;
  42590. const int relativeCursorY = roundToInt (cursorY) - y;
  42591. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42592. {
  42593. x += relativeCursorX - proportionOfWidth (0.2f);
  42594. }
  42595. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42596. {
  42597. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42598. }
  42599. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42600. if (! isMultiLine())
  42601. {
  42602. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42603. }
  42604. else
  42605. {
  42606. const int curH = roundToInt (cursorHeight);
  42607. if (relativeCursorY < 0)
  42608. {
  42609. y = jmax (0, relativeCursorY + y);
  42610. }
  42611. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42612. {
  42613. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42614. }
  42615. }
  42616. viewport->setViewPosition (x, y);
  42617. }
  42618. }
  42619. void TextEditor::moveCursorTo (const int newPosition,
  42620. const bool isSelecting)
  42621. {
  42622. if (isSelecting)
  42623. {
  42624. moveCaret (newPosition);
  42625. const int oldSelStart = selectionStart;
  42626. const int oldSelEnd = selectionEnd;
  42627. if (dragType == notDragging)
  42628. {
  42629. if (abs (getCaretPosition() - selectionStart) < abs (getCaretPosition() - selectionEnd))
  42630. dragType = draggingSelectionStart;
  42631. else
  42632. dragType = draggingSelectionEnd;
  42633. }
  42634. if (dragType == draggingSelectionStart)
  42635. {
  42636. selectionStart = getCaretPosition();
  42637. if (selectionEnd < selectionStart)
  42638. {
  42639. swapVariables (selectionStart, selectionEnd);
  42640. dragType = draggingSelectionEnd;
  42641. }
  42642. }
  42643. else
  42644. {
  42645. selectionEnd = getCaretPosition();
  42646. if (selectionEnd < selectionStart)
  42647. {
  42648. swapVariables (selectionStart, selectionEnd);
  42649. dragType = draggingSelectionStart;
  42650. }
  42651. }
  42652. jassert (selectionStart <= selectionEnd);
  42653. jassert (oldSelStart <= oldSelEnd);
  42654. repaintText (jmin (oldSelStart, selectionStart),
  42655. jmax (oldSelEnd, selectionEnd));
  42656. }
  42657. else
  42658. {
  42659. dragType = notDragging;
  42660. if (selectionEnd > selectionStart)
  42661. repaintText (selectionStart, selectionEnd);
  42662. moveCaret (newPosition);
  42663. selectionStart = getCaretPosition();
  42664. selectionEnd = getCaretPosition();
  42665. }
  42666. }
  42667. int TextEditor::getTextIndexAt (const int x,
  42668. const int y)
  42669. {
  42670. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42671. (float) (y + viewport->getViewPositionY() - topIndent));
  42672. }
  42673. void TextEditor::insertTextAtCursor (String newText)
  42674. {
  42675. if (allowedCharacters.isNotEmpty())
  42676. newText = newText.retainCharacters (allowedCharacters);
  42677. if (! isMultiLine())
  42678. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42679. else
  42680. newText = newText.replace (T("\r\n"), T("\n"));
  42681. const int newCaretPos = selectionStart + newText.length();
  42682. const int insertIndex = selectionStart;
  42683. remove (selectionStart, selectionEnd,
  42684. &undoManager,
  42685. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42686. if (maxTextLength > 0)
  42687. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42688. if (newText.isNotEmpty())
  42689. insert (newText,
  42690. insertIndex,
  42691. currentFont,
  42692. findColour (textColourId),
  42693. &undoManager,
  42694. newCaretPos);
  42695. textChanged();
  42696. }
  42697. void TextEditor::setHighlightedRegion (int startPos, int numChars)
  42698. {
  42699. moveCursorTo (startPos, false);
  42700. moveCursorTo (startPos + numChars, true);
  42701. }
  42702. void TextEditor::copy()
  42703. {
  42704. if (passwordCharacter == 0)
  42705. {
  42706. const String selection (getTextSubstring (selectionStart, selectionEnd));
  42707. if (selection.isNotEmpty())
  42708. SystemClipboard::copyTextToClipboard (selection);
  42709. }
  42710. }
  42711. void TextEditor::paste()
  42712. {
  42713. if (! isReadOnly())
  42714. {
  42715. const String clip (SystemClipboard::getTextFromClipboard());
  42716. if (clip.isNotEmpty())
  42717. insertTextAtCursor (clip);
  42718. }
  42719. }
  42720. void TextEditor::cut()
  42721. {
  42722. if (! isReadOnly())
  42723. {
  42724. moveCaret (selectionEnd);
  42725. insertTextAtCursor (String::empty);
  42726. }
  42727. }
  42728. void TextEditor::drawContent (Graphics& g)
  42729. {
  42730. const float wordWrapWidth = getWordWrapWidth();
  42731. if (wordWrapWidth > 0)
  42732. {
  42733. g.setOrigin (leftIndent, topIndent);
  42734. const Rectangle<int> clip (g.getClipBounds());
  42735. Colour selectedTextColour;
  42736. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42737. while (i.lineY + 200.0 < clip.getY() && i.next())
  42738. {}
  42739. if (selectionStart < selectionEnd)
  42740. {
  42741. g.setColour (findColour (highlightColourId)
  42742. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42743. selectedTextColour = findColour (highlightedTextColourId);
  42744. TextEditorIterator i2 (i);
  42745. while (i2.next() && i2.lineY < clip.getBottom())
  42746. {
  42747. if (i2.lineY + i2.lineHeight >= clip.getY()
  42748. && selectionEnd >= i2.indexInText
  42749. && selectionStart <= i2.indexInText + i2.atom->numChars)
  42750. {
  42751. i2.drawSelection (g, selectionStart, selectionEnd);
  42752. }
  42753. }
  42754. }
  42755. const UniformTextSection* lastSection = 0;
  42756. while (i.next() && i.lineY < clip.getBottom())
  42757. {
  42758. if (i.lineY + i.lineHeight >= clip.getY())
  42759. {
  42760. if (selectionEnd >= i.indexInText
  42761. && selectionStart <= i.indexInText + i.atom->numChars)
  42762. {
  42763. i.drawSelectedText (g, selectionStart, selectionEnd, selectedTextColour);
  42764. lastSection = 0;
  42765. }
  42766. else
  42767. {
  42768. i.draw (g, lastSection);
  42769. }
  42770. }
  42771. }
  42772. }
  42773. }
  42774. void TextEditor::paint (Graphics& g)
  42775. {
  42776. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42777. }
  42778. void TextEditor::paintOverChildren (Graphics& g)
  42779. {
  42780. if (caretFlashState
  42781. && hasKeyboardFocus (false)
  42782. && caretVisible
  42783. && ! isReadOnly())
  42784. {
  42785. g.setColour (findColour (caretColourId));
  42786. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42787. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42788. 2.0f, cursorHeight);
  42789. }
  42790. if (textToShowWhenEmpty.isNotEmpty()
  42791. && (! hasKeyboardFocus (false))
  42792. && getTotalNumChars() == 0)
  42793. {
  42794. g.setColour (colourForTextWhenEmpty);
  42795. g.setFont (getFont());
  42796. if (isMultiLine())
  42797. {
  42798. g.drawText (textToShowWhenEmpty,
  42799. 0, 0, getWidth(), getHeight(),
  42800. Justification::centred, true);
  42801. }
  42802. else
  42803. {
  42804. g.drawText (textToShowWhenEmpty,
  42805. leftIndent, topIndent,
  42806. viewport->getWidth() - leftIndent,
  42807. viewport->getHeight() - topIndent,
  42808. Justification::centredLeft, true);
  42809. }
  42810. }
  42811. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42812. }
  42813. void TextEditor::mouseDown (const MouseEvent& e)
  42814. {
  42815. beginDragAutoRepeat (100);
  42816. newTransaction();
  42817. if (wasFocused || ! selectAllTextWhenFocused)
  42818. {
  42819. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42820. {
  42821. moveCursorTo (getTextIndexAt (e.x, e.y),
  42822. e.mods.isShiftDown());
  42823. }
  42824. else
  42825. {
  42826. PopupMenu m;
  42827. m.setLookAndFeel (&getLookAndFeel());
  42828. addPopupMenuItems (m, &e);
  42829. menuActive = true;
  42830. const int result = m.show();
  42831. menuActive = false;
  42832. if (result != 0)
  42833. performPopupMenuAction (result);
  42834. }
  42835. }
  42836. }
  42837. void TextEditor::mouseDrag (const MouseEvent& e)
  42838. {
  42839. if (wasFocused || ! selectAllTextWhenFocused)
  42840. {
  42841. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42842. {
  42843. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42844. }
  42845. }
  42846. }
  42847. void TextEditor::mouseUp (const MouseEvent& e)
  42848. {
  42849. newTransaction();
  42850. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42851. if (wasFocused || ! selectAllTextWhenFocused)
  42852. {
  42853. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42854. {
  42855. moveCaret (getTextIndexAt (e.x, e.y));
  42856. }
  42857. }
  42858. wasFocused = true;
  42859. }
  42860. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42861. {
  42862. int tokenEnd = getTextIndexAt (e.x, e.y);
  42863. int tokenStart = tokenEnd;
  42864. if (e.getNumberOfClicks() > 3)
  42865. {
  42866. tokenStart = 0;
  42867. tokenEnd = getTotalNumChars();
  42868. }
  42869. else
  42870. {
  42871. const String t (getText());
  42872. const int totalLength = getTotalNumChars();
  42873. while (tokenEnd < totalLength)
  42874. {
  42875. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42876. ++tokenEnd;
  42877. else
  42878. break;
  42879. }
  42880. tokenStart = tokenEnd;
  42881. while (tokenStart > 0)
  42882. {
  42883. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42884. --tokenStart;
  42885. else
  42886. break;
  42887. }
  42888. if (e.getNumberOfClicks() > 2)
  42889. {
  42890. while (tokenEnd < totalLength)
  42891. {
  42892. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42893. ++tokenEnd;
  42894. else
  42895. break;
  42896. }
  42897. while (tokenStart > 0)
  42898. {
  42899. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42900. --tokenStart;
  42901. else
  42902. break;
  42903. }
  42904. }
  42905. }
  42906. moveCursorTo (tokenEnd, false);
  42907. moveCursorTo (tokenStart, true);
  42908. }
  42909. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42910. {
  42911. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42912. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42913. }
  42914. bool TextEditor::keyPressed (const KeyPress& key)
  42915. {
  42916. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42917. return false;
  42918. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42919. if (key.isKeyCode (KeyPress::leftKey)
  42920. || key.isKeyCode (KeyPress::upKey))
  42921. {
  42922. newTransaction();
  42923. int newPos;
  42924. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42925. newPos = indexAtPosition (cursorX, cursorY - 1);
  42926. else if (moveInWholeWordSteps)
  42927. newPos = findWordBreakBefore (getCaretPosition());
  42928. else
  42929. newPos = getCaretPosition() - 1;
  42930. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42931. }
  42932. else if (key.isKeyCode (KeyPress::rightKey)
  42933. || key.isKeyCode (KeyPress::downKey))
  42934. {
  42935. newTransaction();
  42936. int newPos;
  42937. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42938. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42939. else if (moveInWholeWordSteps)
  42940. newPos = findWordBreakAfter (getCaretPosition());
  42941. else
  42942. newPos = getCaretPosition() + 1;
  42943. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42944. }
  42945. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42946. {
  42947. newTransaction();
  42948. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42949. key.getModifiers().isShiftDown());
  42950. }
  42951. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42952. {
  42953. newTransaction();
  42954. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42955. key.getModifiers().isShiftDown());
  42956. }
  42957. else if (key.isKeyCode (KeyPress::homeKey))
  42958. {
  42959. newTransaction();
  42960. if (isMultiLine() && ! moveInWholeWordSteps)
  42961. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42962. key.getModifiers().isShiftDown());
  42963. else
  42964. moveCursorTo (0, key.getModifiers().isShiftDown());
  42965. }
  42966. else if (key.isKeyCode (KeyPress::endKey))
  42967. {
  42968. newTransaction();
  42969. if (isMultiLine() && ! moveInWholeWordSteps)
  42970. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42971. key.getModifiers().isShiftDown());
  42972. else
  42973. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42974. }
  42975. else if (key.isKeyCode (KeyPress::backspaceKey))
  42976. {
  42977. if (moveInWholeWordSteps)
  42978. {
  42979. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42980. }
  42981. else
  42982. {
  42983. if (selectionStart == selectionEnd && selectionStart > 0)
  42984. --selectionStart;
  42985. }
  42986. cut();
  42987. }
  42988. else if (key.isKeyCode (KeyPress::deleteKey))
  42989. {
  42990. if (key.getModifiers().isShiftDown())
  42991. copy();
  42992. if (selectionStart == selectionEnd
  42993. && selectionEnd < getTotalNumChars())
  42994. {
  42995. ++selectionEnd;
  42996. }
  42997. cut();
  42998. }
  42999. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  43000. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  43001. {
  43002. newTransaction();
  43003. copy();
  43004. }
  43005. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  43006. {
  43007. newTransaction();
  43008. copy();
  43009. cut();
  43010. }
  43011. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  43012. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  43013. {
  43014. newTransaction();
  43015. paste();
  43016. }
  43017. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  43018. {
  43019. newTransaction();
  43020. doUndoRedo (false);
  43021. }
  43022. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  43023. {
  43024. newTransaction();
  43025. doUndoRedo (true);
  43026. }
  43027. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  43028. {
  43029. newTransaction();
  43030. moveCursorTo (getTotalNumChars(), false);
  43031. moveCursorTo (0, true);
  43032. }
  43033. else if (key == KeyPress::returnKey)
  43034. {
  43035. newTransaction();
  43036. if (returnKeyStartsNewLine)
  43037. insertTextAtCursor (T("\n"));
  43038. else
  43039. returnPressed();
  43040. }
  43041. else if (key.isKeyCode (KeyPress::escapeKey))
  43042. {
  43043. newTransaction();
  43044. moveCursorTo (getCaretPosition(), false);
  43045. escapePressed();
  43046. }
  43047. else if (key.getTextCharacter() >= ' '
  43048. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  43049. {
  43050. insertTextAtCursor (String::charToString (key.getTextCharacter()));
  43051. lastTransactionTime = Time::getApproximateMillisecondCounter();
  43052. }
  43053. else
  43054. {
  43055. return false;
  43056. }
  43057. return true;
  43058. }
  43059. bool TextEditor::keyStateChanged (const bool isKeyDown)
  43060. {
  43061. if (! isKeyDown)
  43062. return false;
  43063. #if JUCE_WIN32
  43064. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  43065. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  43066. #endif
  43067. // (overridden to avoid forwarding key events to the parent)
  43068. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  43069. }
  43070. const int baseMenuItemID = 0x7fff0000;
  43071. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  43072. {
  43073. const bool writable = ! isReadOnly();
  43074. if (passwordCharacter == 0)
  43075. {
  43076. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  43077. m.addItem (baseMenuItemID + 2, TRANS("copy"), selectionStart < selectionEnd);
  43078. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  43079. }
  43080. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  43081. m.addSeparator();
  43082. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  43083. m.addSeparator();
  43084. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  43085. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  43086. }
  43087. void TextEditor::performPopupMenuAction (const int menuItemID)
  43088. {
  43089. switch (menuItemID)
  43090. {
  43091. case baseMenuItemID + 1:
  43092. copy();
  43093. cut();
  43094. break;
  43095. case baseMenuItemID + 2:
  43096. copy();
  43097. break;
  43098. case baseMenuItemID + 3:
  43099. paste();
  43100. break;
  43101. case baseMenuItemID + 4:
  43102. cut();
  43103. break;
  43104. case baseMenuItemID + 5:
  43105. moveCursorTo (getTotalNumChars(), false);
  43106. moveCursorTo (0, true);
  43107. break;
  43108. case baseMenuItemID + 6:
  43109. doUndoRedo (false);
  43110. break;
  43111. case baseMenuItemID + 7:
  43112. doUndoRedo (true);
  43113. break;
  43114. default:
  43115. break;
  43116. }
  43117. }
  43118. void TextEditor::focusGained (FocusChangeType)
  43119. {
  43120. newTransaction();
  43121. caretFlashState = true;
  43122. if (selectAllTextWhenFocused)
  43123. {
  43124. moveCursorTo (0, false);
  43125. moveCursorTo (getTotalNumChars(), true);
  43126. }
  43127. repaint();
  43128. if (caretVisible)
  43129. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43130. ComponentPeer* const peer = getPeer();
  43131. if (peer != 0 && ! isReadOnly())
  43132. peer->textInputRequired (getScreenX() - peer->getScreenX(),
  43133. getScreenY() - peer->getScreenY());
  43134. }
  43135. void TextEditor::focusLost (FocusChangeType)
  43136. {
  43137. newTransaction();
  43138. wasFocused = false;
  43139. textHolder->stopTimer();
  43140. caretFlashState = false;
  43141. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43142. repaint();
  43143. }
  43144. void TextEditor::resized()
  43145. {
  43146. viewport->setBoundsInset (borderSize);
  43147. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43148. updateTextHolderSize();
  43149. if (! isMultiLine())
  43150. {
  43151. scrollToMakeSureCursorIsVisible();
  43152. }
  43153. else
  43154. {
  43155. updateCaretPosition();
  43156. }
  43157. }
  43158. void TextEditor::handleCommandMessage (const int commandId)
  43159. {
  43160. const ComponentDeletionWatcher deletionChecker (this);
  43161. for (int i = listeners.size(); --i >= 0;)
  43162. {
  43163. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43164. if (tl != 0)
  43165. {
  43166. switch (commandId)
  43167. {
  43168. case TextEditorDefs::textChangeMessageId:
  43169. tl->textEditorTextChanged (*this);
  43170. break;
  43171. case TextEditorDefs::returnKeyMessageId:
  43172. tl->textEditorReturnKeyPressed (*this);
  43173. break;
  43174. case TextEditorDefs::escapeKeyMessageId:
  43175. tl->textEditorEscapeKeyPressed (*this);
  43176. break;
  43177. case TextEditorDefs::focusLossMessageId:
  43178. tl->textEditorFocusLost (*this);
  43179. break;
  43180. default:
  43181. jassertfalse
  43182. break;
  43183. }
  43184. if (i > 0 && deletionChecker.hasBeenDeleted())
  43185. return;
  43186. }
  43187. }
  43188. }
  43189. void TextEditor::enablementChanged()
  43190. {
  43191. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43192. : MouseCursor::IBeamCursor));
  43193. repaint();
  43194. }
  43195. void TextEditor::clearInternal (UndoManager* const um)
  43196. {
  43197. remove (0, getTotalNumChars(), um, caretPosition);
  43198. }
  43199. void TextEditor::insert (const String& text,
  43200. const int insertIndex,
  43201. const Font& font,
  43202. const Colour& colour,
  43203. UndoManager* const um,
  43204. const int caretPositionToMoveTo)
  43205. {
  43206. if (text.isNotEmpty())
  43207. {
  43208. if (um != 0)
  43209. {
  43210. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43211. newTransaction();
  43212. um->perform (new TextEditorInsertAction (*this,
  43213. text,
  43214. insertIndex,
  43215. font,
  43216. colour,
  43217. caretPosition,
  43218. caretPositionToMoveTo));
  43219. }
  43220. else
  43221. {
  43222. repaintText (insertIndex, -1); // must do this before and after changing the data, in case
  43223. // a line gets moved due to word wrap
  43224. int index = 0;
  43225. int nextIndex = 0;
  43226. for (int i = 0; i < sections.size(); ++i)
  43227. {
  43228. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43229. if (insertIndex == index)
  43230. {
  43231. sections.insert (i, new UniformTextSection (text,
  43232. font, colour,
  43233. passwordCharacter));
  43234. break;
  43235. }
  43236. else if (insertIndex > index && insertIndex < nextIndex)
  43237. {
  43238. splitSection (i, insertIndex - index);
  43239. sections.insert (i + 1, new UniformTextSection (text,
  43240. font, colour,
  43241. passwordCharacter));
  43242. break;
  43243. }
  43244. index = nextIndex;
  43245. }
  43246. if (nextIndex == insertIndex)
  43247. sections.add (new UniformTextSection (text,
  43248. font, colour,
  43249. passwordCharacter));
  43250. coalesceSimilarSections();
  43251. totalNumChars = -1;
  43252. valueTextNeedsUpdating = true;
  43253. moveCursorTo (caretPositionToMoveTo, false);
  43254. repaintText (insertIndex, -1);
  43255. }
  43256. }
  43257. }
  43258. void TextEditor::reinsert (const int insertIndex,
  43259. const VoidArray& sectionsToInsert)
  43260. {
  43261. int index = 0;
  43262. int nextIndex = 0;
  43263. for (int i = 0; i < sections.size(); ++i)
  43264. {
  43265. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43266. if (insertIndex == index)
  43267. {
  43268. for (int j = sectionsToInsert.size(); --j >= 0;)
  43269. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43270. break;
  43271. }
  43272. else if (insertIndex > index && insertIndex < nextIndex)
  43273. {
  43274. splitSection (i, insertIndex - index);
  43275. for (int j = sectionsToInsert.size(); --j >= 0;)
  43276. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43277. break;
  43278. }
  43279. index = nextIndex;
  43280. }
  43281. if (nextIndex == insertIndex)
  43282. {
  43283. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43284. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43285. }
  43286. coalesceSimilarSections();
  43287. totalNumChars = -1;
  43288. valueTextNeedsUpdating = true;
  43289. }
  43290. void TextEditor::remove (const int startIndex,
  43291. int endIndex,
  43292. UndoManager* const um,
  43293. const int caretPositionToMoveTo)
  43294. {
  43295. if (endIndex > startIndex)
  43296. {
  43297. int index = 0;
  43298. for (int i = 0; i < sections.size(); ++i)
  43299. {
  43300. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43301. if (startIndex > index && startIndex < nextIndex)
  43302. {
  43303. splitSection (i, startIndex - index);
  43304. --i;
  43305. }
  43306. else if (endIndex > index && endIndex < nextIndex)
  43307. {
  43308. splitSection (i, endIndex - index);
  43309. --i;
  43310. }
  43311. else
  43312. {
  43313. index = nextIndex;
  43314. if (index > endIndex)
  43315. break;
  43316. }
  43317. }
  43318. index = 0;
  43319. if (um != 0)
  43320. {
  43321. VoidArray removedSections;
  43322. for (int i = 0; i < sections.size(); ++i)
  43323. {
  43324. if (endIndex <= startIndex)
  43325. break;
  43326. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43327. const int nextIndex = index + section->getTotalLength();
  43328. if (startIndex <= index && endIndex >= nextIndex)
  43329. removedSections.add (new UniformTextSection (*section));
  43330. index = nextIndex;
  43331. }
  43332. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43333. newTransaction();
  43334. um->perform (new TextEditorRemoveAction (*this,
  43335. startIndex,
  43336. endIndex,
  43337. caretPosition,
  43338. caretPositionToMoveTo,
  43339. removedSections));
  43340. }
  43341. else
  43342. {
  43343. for (int i = 0; i < sections.size(); ++i)
  43344. {
  43345. if (endIndex <= startIndex)
  43346. break;
  43347. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43348. const int nextIndex = index + section->getTotalLength();
  43349. if (startIndex <= index && endIndex >= nextIndex)
  43350. {
  43351. sections.remove(i);
  43352. endIndex -= (nextIndex - index);
  43353. section->clear();
  43354. delete section;
  43355. --i;
  43356. }
  43357. else
  43358. {
  43359. index = nextIndex;
  43360. }
  43361. }
  43362. coalesceSimilarSections();
  43363. totalNumChars = -1;
  43364. valueTextNeedsUpdating = true;
  43365. moveCursorTo (caretPositionToMoveTo, false);
  43366. repaintText (startIndex, -1);
  43367. }
  43368. }
  43369. }
  43370. const String TextEditor::getText() const
  43371. {
  43372. String t;
  43373. t.preallocateStorage (getTotalNumChars());
  43374. String::Concatenator concatenator (t);
  43375. for (int i = 0; i < sections.size(); ++i)
  43376. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43377. return t;
  43378. }
  43379. const String TextEditor::getTextSubstring (const int startCharacter, const int endCharacter) const
  43380. {
  43381. String t;
  43382. if (endCharacter > startCharacter)
  43383. {
  43384. t.preallocateStorage (jmin (getTotalNumChars(), endCharacter - startCharacter));
  43385. String::Concatenator concatenator (t);
  43386. int index = 0;
  43387. for (int i = 0; i < sections.size(); ++i)
  43388. {
  43389. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43390. const int nextIndex = index + s->getTotalLength();
  43391. if (startCharacter < nextIndex)
  43392. {
  43393. if (endCharacter <= index)
  43394. break;
  43395. s->appendSubstring (concatenator,
  43396. startCharacter - index,
  43397. endCharacter - index);
  43398. }
  43399. index = nextIndex;
  43400. }
  43401. }
  43402. return t;
  43403. }
  43404. const String TextEditor::getHighlightedText() const
  43405. {
  43406. return getTextSubstring (selectionStart, selectionEnd);
  43407. }
  43408. int TextEditor::getTotalNumChars() const
  43409. {
  43410. if (totalNumChars < 0)
  43411. {
  43412. totalNumChars = 0;
  43413. for (int i = sections.size(); --i >= 0;)
  43414. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43415. }
  43416. return totalNumChars;
  43417. }
  43418. bool TextEditor::isEmpty() const
  43419. {
  43420. return getTotalNumChars() == 0;
  43421. }
  43422. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43423. {
  43424. const float wordWrapWidth = getWordWrapWidth();
  43425. if (wordWrapWidth > 0 && sections.size() > 0)
  43426. {
  43427. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43428. i.getCharPosition (index, cx, cy, lineHeight);
  43429. }
  43430. else
  43431. {
  43432. cx = cy = 0;
  43433. lineHeight = currentFont.getHeight();
  43434. }
  43435. }
  43436. int TextEditor::indexAtPosition (const float x, const float y)
  43437. {
  43438. const float wordWrapWidth = getWordWrapWidth();
  43439. if (wordWrapWidth > 0)
  43440. {
  43441. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43442. while (i.next())
  43443. {
  43444. if (i.lineY + i.lineHeight > y)
  43445. {
  43446. if (i.lineY > y)
  43447. return jmax (0, i.indexInText - 1);
  43448. if (i.atomX >= x)
  43449. return i.indexInText;
  43450. if (x < i.atomRight)
  43451. return i.xToIndex (x);
  43452. }
  43453. }
  43454. }
  43455. return getTotalNumChars();
  43456. }
  43457. static int getCharacterCategory (const tchar character)
  43458. {
  43459. return CharacterFunctions::isLetterOrDigit (character)
  43460. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43461. }
  43462. int TextEditor::findWordBreakAfter (const int position) const
  43463. {
  43464. const String t (getTextSubstring (position, position + 512));
  43465. const int totalLength = t.length();
  43466. int i = 0;
  43467. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43468. ++i;
  43469. const int type = getCharacterCategory (t[i]);
  43470. while (i < totalLength && type == getCharacterCategory (t[i]))
  43471. ++i;
  43472. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43473. ++i;
  43474. return position + i;
  43475. }
  43476. int TextEditor::findWordBreakBefore (const int position) const
  43477. {
  43478. if (position <= 0)
  43479. return 0;
  43480. const int startOfBuffer = jmax (0, position - 512);
  43481. const String t (getTextSubstring (startOfBuffer, position));
  43482. int i = position - startOfBuffer;
  43483. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43484. --i;
  43485. if (i > 0)
  43486. {
  43487. const int type = getCharacterCategory (t [i - 1]);
  43488. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43489. --i;
  43490. }
  43491. jassert (startOfBuffer + i >= 0);
  43492. return startOfBuffer + i;
  43493. }
  43494. void TextEditor::splitSection (const int sectionIndex,
  43495. const int charToSplitAt)
  43496. {
  43497. jassert (sections[sectionIndex] != 0);
  43498. sections.insert (sectionIndex + 1,
  43499. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43500. ->split (charToSplitAt, passwordCharacter));
  43501. }
  43502. void TextEditor::coalesceSimilarSections()
  43503. {
  43504. for (int i = 0; i < sections.size() - 1; ++i)
  43505. {
  43506. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43507. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43508. if (s1->font == s2->font
  43509. && s1->colour == s2->colour)
  43510. {
  43511. s1->append (*s2, passwordCharacter);
  43512. sections.remove (i + 1);
  43513. delete s2;
  43514. --i;
  43515. }
  43516. }
  43517. }
  43518. END_JUCE_NAMESPACE
  43519. /*** End of inlined file: juce_TextEditor.cpp ***/
  43520. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43521. BEGIN_JUCE_NAMESPACE
  43522. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43523. class ToolbarSpacerComp : public ToolbarItemComponent
  43524. {
  43525. public:
  43526. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43527. : ToolbarItemComponent (itemId_, String::empty, false),
  43528. fixedSize (fixedSize_),
  43529. drawBar (drawBar_)
  43530. {
  43531. }
  43532. ~ToolbarSpacerComp()
  43533. {
  43534. }
  43535. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43536. int& preferredSize, int& minSize, int& maxSize)
  43537. {
  43538. if (fixedSize <= 0)
  43539. {
  43540. preferredSize = toolbarThickness * 2;
  43541. minSize = 4;
  43542. maxSize = 32768;
  43543. }
  43544. else
  43545. {
  43546. maxSize = roundToInt (toolbarThickness * fixedSize);
  43547. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43548. preferredSize = maxSize;
  43549. if (getEditingMode() == editableOnPalette)
  43550. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43551. }
  43552. return true;
  43553. }
  43554. void paintButtonArea (Graphics&, int, int, bool, bool)
  43555. {
  43556. }
  43557. void contentAreaChanged (const Rectangle<int>&)
  43558. {
  43559. }
  43560. int getResizeOrder() const throw()
  43561. {
  43562. return fixedSize <= 0 ? 0 : 1;
  43563. }
  43564. void paint (Graphics& g)
  43565. {
  43566. const int w = getWidth();
  43567. const int h = getHeight();
  43568. if (drawBar)
  43569. {
  43570. g.setColour (findColour (Toolbar::separatorColourId, true));
  43571. const float thickness = 0.2f;
  43572. if (isToolbarVertical())
  43573. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43574. else
  43575. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43576. }
  43577. if (getEditingMode() != normalMode && ! drawBar)
  43578. {
  43579. g.setColour (findColour (Toolbar::separatorColourId, true));
  43580. const int indentX = jmin (2, (w - 3) / 2);
  43581. const int indentY = jmin (2, (h - 3) / 2);
  43582. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43583. if (fixedSize <= 0)
  43584. {
  43585. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43586. if (isToolbarVertical())
  43587. {
  43588. x1 = w * 0.5f;
  43589. y1 = h * 0.4f;
  43590. x2 = x1;
  43591. y2 = indentX * 2.0f;
  43592. x3 = x1;
  43593. y3 = h * 0.6f;
  43594. x4 = x1;
  43595. y4 = h - y2;
  43596. hw = w * 0.15f;
  43597. hl = w * 0.2f;
  43598. }
  43599. else
  43600. {
  43601. x1 = w * 0.4f;
  43602. y1 = h * 0.5f;
  43603. x2 = indentX * 2.0f;
  43604. y2 = y1;
  43605. x3 = w * 0.6f;
  43606. y3 = y1;
  43607. x4 = w - x2;
  43608. y4 = y1;
  43609. hw = h * 0.15f;
  43610. hl = h * 0.2f;
  43611. }
  43612. Path p;
  43613. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43614. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43615. g.fillPath (p);
  43616. }
  43617. }
  43618. }
  43619. juce_UseDebuggingNewOperator
  43620. private:
  43621. const float fixedSize;
  43622. const bool drawBar;
  43623. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43624. const ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43625. };
  43626. class MissingItemsComponent : public PopupMenuCustomComponent
  43627. {
  43628. public:
  43629. MissingItemsComponent (Toolbar& owner_, const int height_)
  43630. : PopupMenuCustomComponent (true),
  43631. owner (owner_),
  43632. height (height_)
  43633. {
  43634. for (int i = owner_.items.size(); --i >= 0;)
  43635. {
  43636. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43637. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43638. {
  43639. oldIndexes.insert (0, i);
  43640. addAndMakeVisible (tc, 0);
  43641. }
  43642. }
  43643. layout (400);
  43644. }
  43645. ~MissingItemsComponent()
  43646. {
  43647. // deleting the toolbar while its menu it open??
  43648. jassert (owner.isValidComponent());
  43649. for (int i = 0; i < getNumChildComponents(); ++i)
  43650. {
  43651. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43652. if (tc != 0)
  43653. {
  43654. tc->setVisible (false);
  43655. const int index = oldIndexes.remove (i);
  43656. owner.addChildComponent (tc, index);
  43657. --i;
  43658. }
  43659. }
  43660. owner.resized();
  43661. }
  43662. void layout (const int preferredWidth)
  43663. {
  43664. const int indent = 8;
  43665. int x = indent;
  43666. int y = indent;
  43667. int maxX = 0;
  43668. for (int i = 0; i < getNumChildComponents(); ++i)
  43669. {
  43670. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43671. if (tc != 0)
  43672. {
  43673. int preferredSize = 1, minSize = 1, maxSize = 1;
  43674. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43675. {
  43676. if (x + preferredSize > preferredWidth && x > indent)
  43677. {
  43678. x = indent;
  43679. y += height;
  43680. }
  43681. tc->setBounds (x, y, preferredSize, height);
  43682. x += preferredSize;
  43683. maxX = jmax (maxX, x);
  43684. }
  43685. }
  43686. }
  43687. setSize (maxX + 8, y + height + 8);
  43688. }
  43689. void getIdealSize (int& idealWidth, int& idealHeight)
  43690. {
  43691. idealWidth = getWidth();
  43692. idealHeight = getHeight();
  43693. }
  43694. juce_UseDebuggingNewOperator
  43695. private:
  43696. Toolbar& owner;
  43697. const int height;
  43698. Array <int> oldIndexes;
  43699. MissingItemsComponent (const MissingItemsComponent&);
  43700. const MissingItemsComponent& operator= (const MissingItemsComponent&);
  43701. };
  43702. Toolbar::Toolbar()
  43703. : vertical (false),
  43704. isEditingActive (false),
  43705. toolbarStyle (Toolbar::iconsOnly)
  43706. {
  43707. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43708. missingItemsButton->setAlwaysOnTop (true);
  43709. missingItemsButton->addButtonListener (this);
  43710. }
  43711. Toolbar::~Toolbar()
  43712. {
  43713. animator.cancelAllAnimations (true);
  43714. deleteAllChildren();
  43715. }
  43716. void Toolbar::setVertical (const bool shouldBeVertical)
  43717. {
  43718. if (vertical != shouldBeVertical)
  43719. {
  43720. vertical = shouldBeVertical;
  43721. resized();
  43722. }
  43723. }
  43724. void Toolbar::clear()
  43725. {
  43726. for (int i = items.size(); --i >= 0;)
  43727. {
  43728. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43729. items.remove (i);
  43730. delete tc;
  43731. }
  43732. resized();
  43733. }
  43734. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43735. {
  43736. if (itemId == ToolbarItemFactory::separatorBarId)
  43737. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43738. else if (itemId == ToolbarItemFactory::spacerId)
  43739. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43740. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43741. return new ToolbarSpacerComp (itemId, 0, false);
  43742. return factory.createItem (itemId);
  43743. }
  43744. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43745. const int itemId,
  43746. const int insertIndex)
  43747. {
  43748. // An ID can't be zero - this might indicate a mistake somewhere?
  43749. jassert (itemId != 0);
  43750. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43751. if (tc != 0)
  43752. {
  43753. #ifdef JUCE_DEBUG
  43754. Array <int> allowedIds;
  43755. factory.getAllToolbarItemIds (allowedIds);
  43756. // If your factory can create an item for a given ID, it must also return
  43757. // that ID from its getAllToolbarItemIds() method!
  43758. jassert (allowedIds.contains (itemId));
  43759. #endif
  43760. items.insert (insertIndex, tc);
  43761. addAndMakeVisible (tc, insertIndex);
  43762. }
  43763. }
  43764. void Toolbar::addItem (ToolbarItemFactory& factory,
  43765. const int itemId,
  43766. const int insertIndex)
  43767. {
  43768. addItemInternal (factory, itemId, insertIndex);
  43769. resized();
  43770. }
  43771. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43772. {
  43773. Array <int> ids;
  43774. factoryToUse.getDefaultItemSet (ids);
  43775. clear();
  43776. for (int i = 0; i < ids.size(); ++i)
  43777. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43778. resized();
  43779. }
  43780. void Toolbar::removeToolbarItem (const int itemIndex)
  43781. {
  43782. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43783. if (tc != 0)
  43784. {
  43785. items.removeValue (tc);
  43786. delete tc;
  43787. resized();
  43788. }
  43789. }
  43790. int Toolbar::getNumItems() const throw()
  43791. {
  43792. return items.size();
  43793. }
  43794. int Toolbar::getItemId (const int itemIndex) const throw()
  43795. {
  43796. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43797. return tc != 0 ? tc->getItemId() : 0;
  43798. }
  43799. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43800. {
  43801. return items [itemIndex];
  43802. }
  43803. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43804. {
  43805. for (;;)
  43806. {
  43807. index += delta;
  43808. ToolbarItemComponent* const tc = getItemComponent (index);
  43809. if (tc == 0)
  43810. break;
  43811. if (tc->isActive)
  43812. return tc;
  43813. }
  43814. return 0;
  43815. }
  43816. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43817. {
  43818. if (toolbarStyle != newStyle)
  43819. {
  43820. toolbarStyle = newStyle;
  43821. updateAllItemPositions (false);
  43822. }
  43823. }
  43824. const String Toolbar::toString() const
  43825. {
  43826. String s (T("TB:"));
  43827. for (int i = 0; i < getNumItems(); ++i)
  43828. s << getItemId(i) << T(' ');
  43829. return s.trimEnd();
  43830. }
  43831. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43832. const String& savedVersion)
  43833. {
  43834. if (! savedVersion.startsWith (T("TB:")))
  43835. return false;
  43836. StringArray tokens;
  43837. tokens.addTokens (savedVersion.substring (3), false);
  43838. clear();
  43839. for (int i = 0; i < tokens.size(); ++i)
  43840. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43841. resized();
  43842. return true;
  43843. }
  43844. void Toolbar::paint (Graphics& g)
  43845. {
  43846. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43847. }
  43848. int Toolbar::getThickness() const throw()
  43849. {
  43850. return vertical ? getWidth() : getHeight();
  43851. }
  43852. int Toolbar::getLength() const throw()
  43853. {
  43854. return vertical ? getHeight() : getWidth();
  43855. }
  43856. void Toolbar::setEditingActive (const bool active)
  43857. {
  43858. if (isEditingActive != active)
  43859. {
  43860. isEditingActive = active;
  43861. updateAllItemPositions (false);
  43862. }
  43863. }
  43864. void Toolbar::resized()
  43865. {
  43866. updateAllItemPositions (false);
  43867. }
  43868. void Toolbar::updateAllItemPositions (const bool animate)
  43869. {
  43870. if (getWidth() > 0 && getHeight() > 0)
  43871. {
  43872. StretchableObjectResizer resizer;
  43873. int i;
  43874. for (i = 0; i < items.size(); ++i)
  43875. {
  43876. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43877. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43878. : ToolbarItemComponent::normalMode);
  43879. tc->setStyle (toolbarStyle);
  43880. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43881. int preferredSize = 1, minSize = 1, maxSize = 1;
  43882. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43883. preferredSize, minSize, maxSize))
  43884. {
  43885. tc->isActive = true;
  43886. resizer.addItem (preferredSize, minSize, maxSize,
  43887. spacer != 0 ? spacer->getResizeOrder() : 2);
  43888. }
  43889. else
  43890. {
  43891. tc->isActive = false;
  43892. tc->setVisible (false);
  43893. }
  43894. }
  43895. resizer.resizeToFit (getLength());
  43896. int totalLength = 0;
  43897. for (i = 0; i < resizer.getNumItems(); ++i)
  43898. totalLength += (int) resizer.getItemSize (i);
  43899. const bool itemsOffTheEnd = totalLength > getLength();
  43900. const int extrasButtonSize = getThickness() / 2;
  43901. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43902. missingItemsButton->setVisible (itemsOffTheEnd);
  43903. missingItemsButton->setEnabled (! isEditingActive);
  43904. if (vertical)
  43905. missingItemsButton->setCentrePosition (getWidth() / 2,
  43906. getHeight() - 4 - extrasButtonSize / 2);
  43907. else
  43908. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43909. getHeight() / 2);
  43910. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43911. : missingItemsButton->getX()) - 4
  43912. : getLength();
  43913. int pos = 0, activeIndex = 0;
  43914. for (i = 0; i < items.size(); ++i)
  43915. {
  43916. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43917. if (tc->isActive)
  43918. {
  43919. const int size = (int) resizer.getItemSize (activeIndex++);
  43920. Rectangle<int> newBounds;
  43921. if (vertical)
  43922. newBounds.setBounds (0, pos, getWidth(), size);
  43923. else
  43924. newBounds.setBounds (pos, 0, size, getHeight());
  43925. if (animate)
  43926. {
  43927. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43928. }
  43929. else
  43930. {
  43931. animator.cancelAnimation (tc, false);
  43932. tc->setBounds (newBounds);
  43933. }
  43934. pos += size;
  43935. tc->setVisible (pos <= maxLength
  43936. && ((! tc->isBeingDragged)
  43937. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43938. }
  43939. }
  43940. }
  43941. }
  43942. void Toolbar::buttonClicked (Button*)
  43943. {
  43944. jassert (missingItemsButton->isShowing());
  43945. if (missingItemsButton->isShowing())
  43946. {
  43947. PopupMenu m;
  43948. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43949. m.showAt (missingItemsButton);
  43950. }
  43951. }
  43952. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43953. Component* /*sourceComponent*/)
  43954. {
  43955. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43956. }
  43957. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43958. {
  43959. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43960. if (tc != 0)
  43961. {
  43962. if (getNumItems() == 0)
  43963. {
  43964. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43965. {
  43966. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43967. if (palette != 0)
  43968. palette->replaceComponent (tc);
  43969. }
  43970. else
  43971. {
  43972. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43973. }
  43974. items.add (tc);
  43975. addChildComponent (tc);
  43976. updateAllItemPositions (false);
  43977. }
  43978. else
  43979. {
  43980. for (int i = getNumItems(); --i >= 0;)
  43981. {
  43982. int currentIndex = getIndexOfChildComponent (tc);
  43983. if (currentIndex < 0)
  43984. {
  43985. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43986. {
  43987. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43988. if (palette != 0)
  43989. palette->replaceComponent (tc);
  43990. }
  43991. else
  43992. {
  43993. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43994. }
  43995. items.add (tc);
  43996. addChildComponent (tc);
  43997. currentIndex = getIndexOfChildComponent (tc);
  43998. updateAllItemPositions (true);
  43999. }
  44000. int newIndex = currentIndex;
  44001. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  44002. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  44003. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  44004. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  44005. if (prev != 0)
  44006. {
  44007. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  44008. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  44009. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  44010. {
  44011. newIndex = getIndexOfChildComponent (prev);
  44012. }
  44013. }
  44014. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  44015. if (next != 0)
  44016. {
  44017. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  44018. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  44019. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  44020. {
  44021. newIndex = getIndexOfChildComponent (next) + 1;
  44022. }
  44023. }
  44024. if (newIndex != currentIndex)
  44025. {
  44026. items.removeValue (tc);
  44027. removeChildComponent (tc);
  44028. addChildComponent (tc, newIndex);
  44029. items.insert (newIndex, tc);
  44030. updateAllItemPositions (true);
  44031. }
  44032. else
  44033. {
  44034. break;
  44035. }
  44036. }
  44037. }
  44038. }
  44039. }
  44040. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  44041. {
  44042. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44043. if (tc != 0)
  44044. {
  44045. if (isParentOf (tc))
  44046. {
  44047. items.removeValue (tc);
  44048. removeChildComponent (tc);
  44049. updateAllItemPositions (true);
  44050. }
  44051. }
  44052. }
  44053. void Toolbar::itemDropped (const String&, Component*, int, int)
  44054. {
  44055. }
  44056. void Toolbar::mouseDown (const MouseEvent& e)
  44057. {
  44058. if (e.mods.isPopupMenu())
  44059. {
  44060. }
  44061. }
  44062. class ToolbarCustomisationDialog : public DialogWindow
  44063. {
  44064. public:
  44065. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  44066. Toolbar* const toolbar_,
  44067. const int optionFlags)
  44068. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  44069. toolbar (toolbar_)
  44070. {
  44071. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  44072. setResizable (true, true);
  44073. setResizeLimits (400, 300, 1500, 1000);
  44074. positionNearBar();
  44075. }
  44076. ~ToolbarCustomisationDialog()
  44077. {
  44078. setContentComponent (0, true);
  44079. }
  44080. void closeButtonPressed()
  44081. {
  44082. setVisible (false);
  44083. }
  44084. bool canModalEventBeSentToComponent (const Component* comp)
  44085. {
  44086. return toolbar->isParentOf (comp);
  44087. }
  44088. void positionNearBar()
  44089. {
  44090. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  44091. const int tbx = toolbar->getScreenX();
  44092. const int tby = toolbar->getScreenY();
  44093. const int gap = 8;
  44094. int x, y;
  44095. if (toolbar->isVertical())
  44096. {
  44097. y = tby;
  44098. if (tbx > screenSize.getCentreX())
  44099. x = tbx - getWidth() - gap;
  44100. else
  44101. x = tbx + toolbar->getWidth() + gap;
  44102. }
  44103. else
  44104. {
  44105. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  44106. if (tby > screenSize.getCentreY())
  44107. y = tby - getHeight() - gap;
  44108. else
  44109. y = tby + toolbar->getHeight() + gap;
  44110. }
  44111. setTopLeftPosition (x, y);
  44112. }
  44113. private:
  44114. Toolbar* const toolbar;
  44115. class CustomiserPanel : public Component,
  44116. private ComboBoxListener,
  44117. private ButtonListener
  44118. {
  44119. public:
  44120. CustomiserPanel (ToolbarItemFactory& factory_,
  44121. Toolbar* const toolbar_,
  44122. const int optionFlags)
  44123. : factory (factory_),
  44124. toolbar (toolbar_),
  44125. styleBox (0),
  44126. defaultButton (0)
  44127. {
  44128. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44129. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44130. | Toolbar::allowIconsWithTextChoice
  44131. | Toolbar::allowTextOnlyChoice)) != 0)
  44132. {
  44133. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44134. styleBox->setEditableText (false);
  44135. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44136. styleBox->addItem (TRANS("Show icons only"), 1);
  44137. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44138. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44139. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44140. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44141. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44142. styleBox->setSelectedId (1);
  44143. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44144. styleBox->setSelectedId (2);
  44145. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44146. styleBox->setSelectedId (3);
  44147. styleBox->addListener (this);
  44148. }
  44149. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44150. {
  44151. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44152. defaultButton->addButtonListener (this);
  44153. }
  44154. addAndMakeVisible (instructions = new Label (String::empty,
  44155. 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.")));
  44156. instructions->setFont (Font (13.0f));
  44157. setSize (500, 300);
  44158. }
  44159. ~CustomiserPanel()
  44160. {
  44161. deleteAllChildren();
  44162. }
  44163. void comboBoxChanged (ComboBox*)
  44164. {
  44165. if (styleBox->getSelectedId() == 1)
  44166. toolbar->setStyle (Toolbar::iconsOnly);
  44167. else if (styleBox->getSelectedId() == 2)
  44168. toolbar->setStyle (Toolbar::iconsWithText);
  44169. else if (styleBox->getSelectedId() == 3)
  44170. toolbar->setStyle (Toolbar::textOnly);
  44171. palette->resized(); // to make it update the styles
  44172. }
  44173. void buttonClicked (Button*)
  44174. {
  44175. toolbar->addDefaultItems (factory);
  44176. }
  44177. void paint (Graphics& g)
  44178. {
  44179. Colour background;
  44180. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44181. if (dw != 0)
  44182. background = dw->getBackgroundColour();
  44183. g.setColour (background.contrasting().withAlpha (0.3f));
  44184. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44185. }
  44186. void resized()
  44187. {
  44188. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44189. if (styleBox != 0)
  44190. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44191. if (defaultButton != 0)
  44192. {
  44193. defaultButton->changeWidthToFitText (22);
  44194. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44195. }
  44196. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44197. }
  44198. private:
  44199. ToolbarItemFactory& factory;
  44200. Toolbar* const toolbar;
  44201. Label* instructions;
  44202. ToolbarItemPalette* palette;
  44203. ComboBox* styleBox;
  44204. TextButton* defaultButton;
  44205. };
  44206. };
  44207. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44208. {
  44209. setEditingActive (true);
  44210. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44211. dw.runModalLoop();
  44212. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44213. setEditingActive (false);
  44214. }
  44215. END_JUCE_NAMESPACE
  44216. /*** End of inlined file: juce_Toolbar.cpp ***/
  44217. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  44218. BEGIN_JUCE_NAMESPACE
  44219. ToolbarItemFactory::ToolbarItemFactory()
  44220. {
  44221. }
  44222. ToolbarItemFactory::~ToolbarItemFactory()
  44223. {
  44224. }
  44225. class ItemDragAndDropOverlayComponent : public Component
  44226. {
  44227. public:
  44228. ItemDragAndDropOverlayComponent()
  44229. : isDragging (false)
  44230. {
  44231. setAlwaysOnTop (true);
  44232. setRepaintsOnMouseActivity (true);
  44233. setMouseCursor (MouseCursor::DraggingHandCursor);
  44234. }
  44235. ~ItemDragAndDropOverlayComponent()
  44236. {
  44237. }
  44238. void paint (Graphics& g)
  44239. {
  44240. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44241. if (isMouseOverOrDragging()
  44242. && tc != 0
  44243. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44244. {
  44245. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44246. g.drawRect (0, 0, getWidth(), getHeight(),
  44247. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44248. }
  44249. }
  44250. void mouseDown (const MouseEvent& e)
  44251. {
  44252. isDragging = false;
  44253. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44254. if (tc != 0)
  44255. {
  44256. tc->dragOffsetX = e.x;
  44257. tc->dragOffsetY = e.y;
  44258. }
  44259. }
  44260. void mouseDrag (const MouseEvent& e)
  44261. {
  44262. if (! (isDragging || e.mouseWasClicked()))
  44263. {
  44264. isDragging = true;
  44265. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44266. if (dnd != 0)
  44267. {
  44268. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44269. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44270. if (tc != 0)
  44271. {
  44272. tc->isBeingDragged = true;
  44273. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44274. tc->setVisible (false);
  44275. }
  44276. }
  44277. }
  44278. }
  44279. void mouseUp (const MouseEvent&)
  44280. {
  44281. isDragging = false;
  44282. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44283. if (tc != 0)
  44284. {
  44285. tc->isBeingDragged = false;
  44286. Toolbar* const tb = tc->getToolbar();
  44287. if (tb != 0)
  44288. tb->updateAllItemPositions (true);
  44289. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44290. delete tc;
  44291. }
  44292. }
  44293. void parentSizeChanged()
  44294. {
  44295. setBounds (0, 0, getParentWidth(), getParentHeight());
  44296. }
  44297. juce_UseDebuggingNewOperator
  44298. private:
  44299. bool isDragging;
  44300. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44301. const ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44302. };
  44303. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44304. const String& labelText,
  44305. const bool isBeingUsedAsAButton_)
  44306. : Button (labelText),
  44307. itemId (itemId_),
  44308. mode (normalMode),
  44309. toolbarStyle (Toolbar::iconsOnly),
  44310. dragOffsetX (0),
  44311. dragOffsetY (0),
  44312. isActive (true),
  44313. isBeingDragged (false),
  44314. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44315. {
  44316. // Your item ID can't be 0!
  44317. jassert (itemId_ != 0);
  44318. }
  44319. ToolbarItemComponent::~ToolbarItemComponent()
  44320. {
  44321. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44322. overlayComp = 0;
  44323. }
  44324. Toolbar* ToolbarItemComponent::getToolbar() const
  44325. {
  44326. return dynamic_cast <Toolbar*> (getParentComponent());
  44327. }
  44328. bool ToolbarItemComponent::isToolbarVertical() const
  44329. {
  44330. const Toolbar* const t = getToolbar();
  44331. return t != 0 && t->isVertical();
  44332. }
  44333. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44334. {
  44335. if (toolbarStyle != newStyle)
  44336. {
  44337. toolbarStyle = newStyle;
  44338. repaint();
  44339. resized();
  44340. }
  44341. }
  44342. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44343. {
  44344. if (isBeingUsedAsAButton)
  44345. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44346. isMouseOver, isMouseDown, *this);
  44347. if (toolbarStyle != Toolbar::iconsOnly)
  44348. {
  44349. const int indent = contentArea.getX();
  44350. int y = indent;
  44351. int h = getHeight() - indent * 2;
  44352. if (toolbarStyle == Toolbar::iconsWithText)
  44353. {
  44354. y = contentArea.getBottom() + indent / 2;
  44355. h -= contentArea.getHeight();
  44356. }
  44357. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44358. getButtonText(), *this);
  44359. }
  44360. if (! contentArea.isEmpty())
  44361. {
  44362. g.saveState();
  44363. g.setOrigin (contentArea.getX(), contentArea.getY());
  44364. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44365. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44366. g.restoreState();
  44367. }
  44368. }
  44369. void ToolbarItemComponent::resized()
  44370. {
  44371. if (toolbarStyle != Toolbar::textOnly)
  44372. {
  44373. const int indent = jmin (proportionOfWidth (0.08f),
  44374. proportionOfHeight (0.08f));
  44375. contentArea = Rectangle<int> (indent, indent,
  44376. getWidth() - indent * 2,
  44377. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44378. : (getHeight() - indent * 2));
  44379. }
  44380. else
  44381. {
  44382. contentArea = Rectangle<int>();
  44383. }
  44384. contentAreaChanged (contentArea);
  44385. }
  44386. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44387. {
  44388. if (mode != newMode)
  44389. {
  44390. mode = newMode;
  44391. repaint();
  44392. if (mode == normalMode)
  44393. {
  44394. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44395. overlayComp = 0;
  44396. }
  44397. else if (overlayComp == 0)
  44398. {
  44399. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44400. overlayComp->parentSizeChanged();
  44401. }
  44402. resized();
  44403. }
  44404. }
  44405. END_JUCE_NAMESPACE
  44406. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  44407. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  44408. BEGIN_JUCE_NAMESPACE
  44409. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44410. Toolbar* const toolbar_)
  44411. : factory (factory_),
  44412. toolbar (toolbar_)
  44413. {
  44414. Component* const itemHolder = new Component();
  44415. Array <int> allIds;
  44416. factory_.getAllToolbarItemIds (allIds);
  44417. for (int i = 0; i < allIds.size(); ++i)
  44418. {
  44419. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44420. jassert (tc != 0);
  44421. if (tc != 0)
  44422. {
  44423. itemHolder->addAndMakeVisible (tc);
  44424. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44425. }
  44426. }
  44427. viewport = new Viewport();
  44428. viewport->setViewedComponent (itemHolder);
  44429. addAndMakeVisible (viewport);
  44430. }
  44431. ToolbarItemPalette::~ToolbarItemPalette()
  44432. {
  44433. viewport->getViewedComponent()->deleteAllChildren();
  44434. deleteAllChildren();
  44435. }
  44436. void ToolbarItemPalette::resized()
  44437. {
  44438. viewport->setBoundsInset (BorderSize (1));
  44439. Component* const itemHolder = viewport->getViewedComponent();
  44440. const int indent = 8;
  44441. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44442. const int height = toolbar->getThickness();
  44443. int x = indent;
  44444. int y = indent;
  44445. int maxX = 0;
  44446. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44447. {
  44448. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44449. if (tc != 0)
  44450. {
  44451. tc->setStyle (toolbar->getStyle());
  44452. int preferredSize = 1, minSize = 1, maxSize = 1;
  44453. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44454. {
  44455. if (x + preferredSize > preferredWidth && x > indent)
  44456. {
  44457. x = indent;
  44458. y += height;
  44459. }
  44460. tc->setBounds (x, y, preferredSize, height);
  44461. x += preferredSize + 8;
  44462. maxX = jmax (maxX, x);
  44463. }
  44464. }
  44465. }
  44466. itemHolder->setSize (maxX, y + height + 8);
  44467. }
  44468. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44469. {
  44470. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44471. jassert (tc != 0);
  44472. if (tc != 0)
  44473. {
  44474. tc->setBounds (comp->getBounds());
  44475. tc->setStyle (toolbar->getStyle());
  44476. tc->setEditingMode (comp->getEditingMode());
  44477. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44478. }
  44479. }
  44480. END_JUCE_NAMESPACE
  44481. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44482. /*** Start of inlined file: juce_TreeView.cpp ***/
  44483. BEGIN_JUCE_NAMESPACE
  44484. class TreeViewContentComponent : public Component,
  44485. public TooltipClient
  44486. {
  44487. public:
  44488. TreeViewContentComponent (TreeView* const owner_)
  44489. : owner (owner_),
  44490. buttonUnderMouse (0),
  44491. isDragging (false)
  44492. {
  44493. }
  44494. ~TreeViewContentComponent()
  44495. {
  44496. deleteAllChildren();
  44497. }
  44498. void mouseDown (const MouseEvent& e)
  44499. {
  44500. updateButtonUnderMouse (e);
  44501. isDragging = false;
  44502. needSelectionOnMouseUp = false;
  44503. Rectangle<int> pos;
  44504. TreeViewItem* const item = findItemAt (e.y, pos);
  44505. if (item == 0)
  44506. return;
  44507. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44508. // as selection clicks)
  44509. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44510. {
  44511. if (e.x >= pos.getX() - owner->getIndentSize())
  44512. item->setOpen (! item->isOpen());
  44513. // (clicks to the left of an open/close button are ignored)
  44514. }
  44515. else
  44516. {
  44517. // mouse-down inside the body of the item..
  44518. if (! owner->isMultiSelectEnabled())
  44519. item->setSelected (true, true);
  44520. else if (item->isSelected())
  44521. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44522. else
  44523. selectBasedOnModifiers (item, e.mods);
  44524. MouseEvent e2 (e);
  44525. e2.x -= pos.getX();
  44526. e2.y -= pos.getY();
  44527. if (e2.x >= 0)
  44528. item->itemClicked (e2);
  44529. }
  44530. }
  44531. void mouseUp (const MouseEvent& e)
  44532. {
  44533. updateButtonUnderMouse (e);
  44534. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44535. {
  44536. Rectangle<int> pos;
  44537. TreeViewItem* const item = findItemAt (e.y, pos);
  44538. if (item != 0)
  44539. selectBasedOnModifiers (item, e.mods);
  44540. }
  44541. }
  44542. void mouseDoubleClick (const MouseEvent& e)
  44543. {
  44544. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44545. {
  44546. Rectangle<int> pos;
  44547. TreeViewItem* const item = findItemAt (e.y, pos);
  44548. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44549. {
  44550. MouseEvent e2 (e);
  44551. e2.x -= pos.getX();
  44552. e2.y -= pos.getY();
  44553. item->itemDoubleClicked (e2);
  44554. }
  44555. }
  44556. }
  44557. void mouseDrag (const MouseEvent& e)
  44558. {
  44559. if (isEnabled()
  44560. && ! (isDragging || e.mouseWasClicked()
  44561. || e.getDistanceFromDragStart() < 5
  44562. || e.mods.isPopupMenu()))
  44563. {
  44564. isDragging = true;
  44565. Rectangle<int> pos;
  44566. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44567. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44568. {
  44569. const String dragDescription (item->getDragSourceDescription());
  44570. if (dragDescription.isNotEmpty())
  44571. {
  44572. DragAndDropContainer* const dragContainer
  44573. = DragAndDropContainer::findParentDragContainerFor (this);
  44574. if (dragContainer != 0)
  44575. {
  44576. pos.setSize (pos.getWidth(), item->itemHeight);
  44577. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44578. dragImage->multiplyAllAlphas (0.6f);
  44579. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44580. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44581. }
  44582. else
  44583. {
  44584. // to be able to do a drag-and-drop operation, the treeview needs to
  44585. // be inside a component which is also a DragAndDropContainer.
  44586. jassertfalse
  44587. }
  44588. }
  44589. }
  44590. }
  44591. }
  44592. void mouseMove (const MouseEvent& e)
  44593. {
  44594. updateButtonUnderMouse (e);
  44595. }
  44596. void mouseExit (const MouseEvent& e)
  44597. {
  44598. updateButtonUnderMouse (e);
  44599. }
  44600. void paint (Graphics& g);
  44601. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44602. void updateComponents()
  44603. {
  44604. const int visibleTop = -getY();
  44605. const int visibleBottom = visibleTop + getParentHeight();
  44606. BitArray itemsToKeep;
  44607. TreeViewItem* item = owner->rootItem;
  44608. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44609. while (item != 0 && y < visibleBottom)
  44610. {
  44611. y += item->itemHeight;
  44612. if (y >= visibleTop)
  44613. {
  44614. const int index = rowComponentIds.indexOf (item->uid);
  44615. if (index < 0)
  44616. {
  44617. Component* const comp = item->createItemComponent();
  44618. if (comp != 0)
  44619. {
  44620. addAndMakeVisible (comp);
  44621. itemsToKeep.setBit (rowComponentItems.size());
  44622. rowComponentItems.add (item);
  44623. rowComponentIds.add (item->uid);
  44624. rowComponents.add (comp);
  44625. }
  44626. }
  44627. else
  44628. {
  44629. itemsToKeep.setBit (index);
  44630. }
  44631. }
  44632. item = item->getNextVisibleItem (true);
  44633. }
  44634. for (int i = rowComponentItems.size(); --i >= 0;)
  44635. {
  44636. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44637. bool keep = false;
  44638. if (isParentOf (comp))
  44639. {
  44640. if (itemsToKeep[i])
  44641. {
  44642. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44643. Rectangle<int> pos (item->getItemPosition (false));
  44644. pos.setSize (pos.getWidth(), item->itemHeight);
  44645. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44646. {
  44647. keep = true;
  44648. comp->setBounds (pos);
  44649. }
  44650. }
  44651. if ((! keep)
  44652. && Component::isMouseButtonDownAnywhere()
  44653. && (comp == Component::getComponentUnderMouse()
  44654. || comp->isParentOf (Component::getComponentUnderMouse())))
  44655. {
  44656. keep = true;
  44657. comp->setSize (0, 0);
  44658. }
  44659. }
  44660. if (! keep)
  44661. {
  44662. delete comp;
  44663. rowComponents.remove (i);
  44664. rowComponentIds.remove (i);
  44665. rowComponentItems.remove (i);
  44666. }
  44667. }
  44668. }
  44669. void updateButtonUnderMouse (const MouseEvent& e)
  44670. {
  44671. TreeViewItem* newItem = 0;
  44672. if (owner->openCloseButtonsVisible)
  44673. {
  44674. Rectangle<int> pos;
  44675. TreeViewItem* item = findItemAt (e.y, pos);
  44676. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44677. {
  44678. newItem = item;
  44679. if (! newItem->mightContainSubItems())
  44680. newItem = 0;
  44681. }
  44682. }
  44683. if (buttonUnderMouse != newItem)
  44684. {
  44685. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44686. {
  44687. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44688. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44689. }
  44690. buttonUnderMouse = newItem;
  44691. if (buttonUnderMouse != 0)
  44692. {
  44693. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44694. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44695. }
  44696. }
  44697. }
  44698. bool isMouseOverButton (TreeViewItem* item) const throw()
  44699. {
  44700. return item == buttonUnderMouse;
  44701. }
  44702. void resized()
  44703. {
  44704. owner->itemsChanged();
  44705. }
  44706. const String getTooltip()
  44707. {
  44708. int x, y;
  44709. getMouseXYRelative (x, y);
  44710. Rectangle<int> pos;
  44711. TreeViewItem* const item = findItemAt (y, pos);
  44712. if (item != 0)
  44713. return item->getTooltip();
  44714. return owner->getTooltip();
  44715. }
  44716. juce_UseDebuggingNewOperator
  44717. private:
  44718. TreeView* const owner;
  44719. VoidArray rowComponentItems;
  44720. Array <int> rowComponentIds;
  44721. VoidArray rowComponents;
  44722. TreeViewItem* buttonUnderMouse;
  44723. bool isDragging, needSelectionOnMouseUp;
  44724. TreeViewContentComponent (const TreeViewContentComponent&);
  44725. const TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44726. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44727. {
  44728. TreeViewItem* firstSelected = 0;
  44729. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44730. {
  44731. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44732. jassert (lastSelected != 0);
  44733. int rowStart = firstSelected->getRowNumberInTree();
  44734. int rowEnd = lastSelected->getRowNumberInTree();
  44735. if (rowStart > rowEnd)
  44736. swapVariables (rowStart, rowEnd);
  44737. int ourRow = item->getRowNumberInTree();
  44738. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44739. if (ourRow > otherEnd)
  44740. swapVariables (ourRow, otherEnd);
  44741. for (int i = ourRow; i <= otherEnd; ++i)
  44742. owner->getItemOnRow (i)->setSelected (true, false);
  44743. }
  44744. else
  44745. {
  44746. const bool cmd = modifiers.isCommandDown();
  44747. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44748. }
  44749. }
  44750. bool containsItem (TreeViewItem* const item) const
  44751. {
  44752. for (int i = rowComponentItems.size(); --i >= 0;)
  44753. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44754. return true;
  44755. return false;
  44756. }
  44757. };
  44758. class TreeViewport : public Viewport
  44759. {
  44760. public:
  44761. TreeViewport() throw() {}
  44762. ~TreeViewport() throw() {}
  44763. void updateComponents()
  44764. {
  44765. if (getViewedComponent() != 0)
  44766. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44767. repaint();
  44768. }
  44769. void visibleAreaChanged (int, int, int, int)
  44770. {
  44771. updateComponents();
  44772. }
  44773. juce_UseDebuggingNewOperator
  44774. private:
  44775. TreeViewport (const TreeViewport&);
  44776. const TreeViewport& operator= (const TreeViewport&);
  44777. };
  44778. TreeView::TreeView (const String& componentName)
  44779. : Component (componentName),
  44780. rootItem (0),
  44781. dragInsertPointHighlight (0),
  44782. dragTargetGroupHighlight (0),
  44783. indentSize (24),
  44784. defaultOpenness (false),
  44785. needsRecalculating (true),
  44786. rootItemVisible (true),
  44787. multiSelectEnabled (false),
  44788. openCloseButtonsVisible (true)
  44789. {
  44790. addAndMakeVisible (viewport = new TreeViewport());
  44791. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44792. viewport->setWantsKeyboardFocus (false);
  44793. setWantsKeyboardFocus (true);
  44794. }
  44795. TreeView::~TreeView()
  44796. {
  44797. if (rootItem != 0)
  44798. rootItem->setOwnerView (0);
  44799. deleteAllChildren();
  44800. }
  44801. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44802. {
  44803. if (rootItem != newRootItem)
  44804. {
  44805. if (newRootItem != 0)
  44806. {
  44807. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44808. if (newRootItem->ownerView != 0)
  44809. newRootItem->ownerView->setRootItem (0);
  44810. }
  44811. if (rootItem != 0)
  44812. rootItem->setOwnerView (0);
  44813. rootItem = newRootItem;
  44814. if (newRootItem != 0)
  44815. newRootItem->setOwnerView (this);
  44816. needsRecalculating = true;
  44817. handleAsyncUpdate();
  44818. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44819. {
  44820. rootItem->setOpen (false); // force a re-open
  44821. rootItem->setOpen (true);
  44822. }
  44823. }
  44824. }
  44825. void TreeView::deleteRootItem()
  44826. {
  44827. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44828. setRootItem (0);
  44829. }
  44830. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44831. {
  44832. rootItemVisible = shouldBeVisible;
  44833. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44834. {
  44835. rootItem->setOpen (false); // force a re-open
  44836. rootItem->setOpen (true);
  44837. }
  44838. itemsChanged();
  44839. }
  44840. void TreeView::colourChanged()
  44841. {
  44842. setOpaque (findColour (backgroundColourId).isOpaque());
  44843. repaint();
  44844. }
  44845. void TreeView::setIndentSize (const int newIndentSize)
  44846. {
  44847. if (indentSize != newIndentSize)
  44848. {
  44849. indentSize = newIndentSize;
  44850. resized();
  44851. }
  44852. }
  44853. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44854. {
  44855. if (defaultOpenness != isOpenByDefault)
  44856. {
  44857. defaultOpenness = isOpenByDefault;
  44858. itemsChanged();
  44859. }
  44860. }
  44861. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44862. {
  44863. multiSelectEnabled = canMultiSelect;
  44864. }
  44865. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44866. {
  44867. if (openCloseButtonsVisible != shouldBeVisible)
  44868. {
  44869. openCloseButtonsVisible = shouldBeVisible;
  44870. itemsChanged();
  44871. }
  44872. }
  44873. void TreeView::clearSelectedItems()
  44874. {
  44875. if (rootItem != 0)
  44876. rootItem->deselectAllRecursively();
  44877. }
  44878. int TreeView::getNumSelectedItems() const throw()
  44879. {
  44880. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44881. }
  44882. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44883. {
  44884. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44885. }
  44886. int TreeView::getNumRowsInTree() const
  44887. {
  44888. if (rootItem != 0)
  44889. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44890. return 0;
  44891. }
  44892. TreeViewItem* TreeView::getItemOnRow (int index) const
  44893. {
  44894. if (! rootItemVisible)
  44895. ++index;
  44896. if (rootItem != 0 && index >= 0)
  44897. return rootItem->getItemOnRow (index);
  44898. return 0;
  44899. }
  44900. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44901. {
  44902. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44903. int x;
  44904. relativePositionToOtherComponent (tc, x, y);
  44905. Rectangle<int> pos;
  44906. return tc->findItemAt (y, pos);
  44907. }
  44908. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44909. {
  44910. if (rootItem == 0)
  44911. return 0;
  44912. return rootItem->findItemFromIdentifierString (identifierString);
  44913. }
  44914. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44915. {
  44916. XmlElement* e = 0;
  44917. if (rootItem != 0)
  44918. {
  44919. e = rootItem->getOpennessState();
  44920. if (e != 0 && alsoIncludeScrollPosition)
  44921. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44922. }
  44923. return e;
  44924. }
  44925. void TreeView::restoreOpennessState (const XmlElement& newState)
  44926. {
  44927. if (rootItem != 0)
  44928. {
  44929. rootItem->restoreOpennessState (newState);
  44930. if (newState.hasAttribute (T("scrollPos")))
  44931. viewport->setViewPosition (viewport->getViewPositionX(),
  44932. newState.getIntAttribute (T("scrollPos")));
  44933. }
  44934. }
  44935. void TreeView::paint (Graphics& g)
  44936. {
  44937. g.fillAll (findColour (backgroundColourId));
  44938. }
  44939. void TreeView::resized()
  44940. {
  44941. viewport->setBounds (0, 0, getWidth(), getHeight());
  44942. itemsChanged();
  44943. handleAsyncUpdate();
  44944. }
  44945. void TreeView::enablementChanged()
  44946. {
  44947. repaint();
  44948. }
  44949. void TreeView::moveSelectedRow (int delta)
  44950. {
  44951. if (delta == 0)
  44952. return;
  44953. int rowSelected = 0;
  44954. TreeViewItem* const firstSelected = getSelectedItem (0);
  44955. if (firstSelected != 0)
  44956. rowSelected = firstSelected->getRowNumberInTree();
  44957. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44958. for (;;)
  44959. {
  44960. TreeViewItem* item = getItemOnRow (rowSelected);
  44961. if (item != 0)
  44962. {
  44963. if (! item->canBeSelected())
  44964. {
  44965. // if the row we want to highlight doesn't allow it, try skipping
  44966. // to the next item..
  44967. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44968. rowSelected + (delta < 0 ? -1 : 1));
  44969. if (rowSelected != nextRowToTry)
  44970. {
  44971. rowSelected = nextRowToTry;
  44972. continue;
  44973. }
  44974. else
  44975. {
  44976. break;
  44977. }
  44978. }
  44979. item->setSelected (true, true);
  44980. scrollToKeepItemVisible (item);
  44981. }
  44982. break;
  44983. }
  44984. }
  44985. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44986. {
  44987. if (item != 0 && item->ownerView == this)
  44988. {
  44989. handleAsyncUpdate();
  44990. item = item->getDeepestOpenParentItem();
  44991. int y = item->y;
  44992. int viewTop = viewport->getViewPositionY();
  44993. if (y < viewTop)
  44994. {
  44995. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44996. }
  44997. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44998. {
  44999. viewport->setViewPosition (viewport->getViewPositionX(),
  45000. (y + item->itemHeight) - viewport->getViewHeight());
  45001. }
  45002. }
  45003. }
  45004. bool TreeView::keyPressed (const KeyPress& key)
  45005. {
  45006. if (key.isKeyCode (KeyPress::upKey))
  45007. {
  45008. moveSelectedRow (-1);
  45009. }
  45010. else if (key.isKeyCode (KeyPress::downKey))
  45011. {
  45012. moveSelectedRow (1);
  45013. }
  45014. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  45015. {
  45016. if (rootItem != 0)
  45017. {
  45018. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  45019. if (key.isKeyCode (KeyPress::pageUpKey))
  45020. rowsOnScreen = -rowsOnScreen;
  45021. moveSelectedRow (rowsOnScreen);
  45022. }
  45023. }
  45024. else if (key.isKeyCode (KeyPress::homeKey))
  45025. {
  45026. moveSelectedRow (-0x3fffffff);
  45027. }
  45028. else if (key.isKeyCode (KeyPress::endKey))
  45029. {
  45030. moveSelectedRow (0x3fffffff);
  45031. }
  45032. else if (key.isKeyCode (KeyPress::returnKey))
  45033. {
  45034. TreeViewItem* const firstSelected = getSelectedItem (0);
  45035. if (firstSelected != 0)
  45036. firstSelected->setOpen (! firstSelected->isOpen());
  45037. }
  45038. else if (key.isKeyCode (KeyPress::leftKey))
  45039. {
  45040. TreeViewItem* const firstSelected = getSelectedItem (0);
  45041. if (firstSelected != 0)
  45042. {
  45043. if (firstSelected->isOpen())
  45044. {
  45045. firstSelected->setOpen (false);
  45046. }
  45047. else
  45048. {
  45049. TreeViewItem* parent = firstSelected->parentItem;
  45050. if ((! rootItemVisible) && parent == rootItem)
  45051. parent = 0;
  45052. if (parent != 0)
  45053. {
  45054. parent->setSelected (true, true);
  45055. scrollToKeepItemVisible (parent);
  45056. }
  45057. }
  45058. }
  45059. }
  45060. else if (key.isKeyCode (KeyPress::rightKey))
  45061. {
  45062. TreeViewItem* const firstSelected = getSelectedItem (0);
  45063. if (firstSelected != 0)
  45064. {
  45065. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  45066. moveSelectedRow (1);
  45067. else
  45068. firstSelected->setOpen (true);
  45069. }
  45070. }
  45071. else
  45072. {
  45073. return false;
  45074. }
  45075. return true;
  45076. }
  45077. void TreeView::itemsChanged() throw()
  45078. {
  45079. needsRecalculating = true;
  45080. repaint();
  45081. triggerAsyncUpdate();
  45082. }
  45083. void TreeView::handleAsyncUpdate()
  45084. {
  45085. if (needsRecalculating)
  45086. {
  45087. needsRecalculating = false;
  45088. const ScopedLock sl (nodeAlterationLock);
  45089. if (rootItem != 0)
  45090. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  45091. ((TreeViewport*) viewport)->updateComponents();
  45092. if (rootItem != 0)
  45093. {
  45094. viewport->getViewedComponent()
  45095. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  45096. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  45097. }
  45098. else
  45099. {
  45100. viewport->getViewedComponent()->setSize (0, 0);
  45101. }
  45102. }
  45103. }
  45104. class TreeViewDragInsertPointHighlight : public Component
  45105. {
  45106. public:
  45107. TreeViewDragInsertPointHighlight()
  45108. : lastItem (0)
  45109. {
  45110. setSize (100, 12);
  45111. setAlwaysOnTop (true);
  45112. setInterceptsMouseClicks (false, false);
  45113. }
  45114. ~TreeViewDragInsertPointHighlight() {}
  45115. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  45116. {
  45117. lastItem = item;
  45118. lastIndex = insertIndex;
  45119. const int offset = getHeight() / 2;
  45120. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  45121. }
  45122. void paint (Graphics& g)
  45123. {
  45124. Path p;
  45125. const float h = (float) getHeight();
  45126. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45127. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45128. p.lineTo ((float) getWidth(), h / 2.0f);
  45129. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45130. g.strokePath (p, PathStrokeType (2.0f));
  45131. }
  45132. TreeViewItem* lastItem;
  45133. int lastIndex;
  45134. };
  45135. class TreeViewDragTargetGroupHighlight : public Component
  45136. {
  45137. public:
  45138. TreeViewDragTargetGroupHighlight()
  45139. {
  45140. setAlwaysOnTop (true);
  45141. setInterceptsMouseClicks (false, false);
  45142. }
  45143. ~TreeViewDragTargetGroupHighlight() {}
  45144. void setTargetPosition (TreeViewItem* const item) throw()
  45145. {
  45146. Rectangle<int> r (item->getItemPosition (true));
  45147. r.setHeight (item->getItemHeight());
  45148. setBounds (r);
  45149. }
  45150. void paint (Graphics& g)
  45151. {
  45152. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45153. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45154. }
  45155. };
  45156. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45157. {
  45158. beginDragAutoRepeat (1000 / 30);
  45159. if (dragInsertPointHighlight == 0)
  45160. {
  45161. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45162. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45163. }
  45164. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45165. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45166. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45167. ->setTargetPosition (item);
  45168. }
  45169. void TreeView::hideDragHighlight() throw()
  45170. {
  45171. deleteAndZero (dragInsertPointHighlight);
  45172. deleteAndZero (dragTargetGroupHighlight);
  45173. }
  45174. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45175. const StringArray& files, const String& sourceDescription,
  45176. Component* sourceComponent) const throw()
  45177. {
  45178. insertIndex = 0;
  45179. TreeViewItem* item = getItemAt (y);
  45180. if (item == 0)
  45181. return 0;
  45182. Rectangle<int> itemPos (item->getItemPosition (true));
  45183. insertIndex = item->getIndexInParent();
  45184. const int oldY = y;
  45185. y = itemPos.getY();
  45186. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45187. {
  45188. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45189. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45190. {
  45191. // Check if we're trying to drag into an empty group item..
  45192. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45193. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45194. {
  45195. insertIndex = 0;
  45196. x = itemPos.getX() + getIndentSize();
  45197. y = itemPos.getBottom();
  45198. return item;
  45199. }
  45200. }
  45201. }
  45202. if (oldY > itemPos.getCentreY())
  45203. {
  45204. y += item->getItemHeight();
  45205. while (item->isLastOfSiblings() && item->parentItem != 0
  45206. && item->parentItem->parentItem != 0)
  45207. {
  45208. if (x > itemPos.getX())
  45209. break;
  45210. item = item->parentItem;
  45211. itemPos = item->getItemPosition (true);
  45212. insertIndex = item->getIndexInParent();
  45213. }
  45214. ++insertIndex;
  45215. }
  45216. x = itemPos.getX();
  45217. return item->parentItem;
  45218. }
  45219. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45220. {
  45221. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45222. int insertIndex;
  45223. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45224. if (item != 0)
  45225. {
  45226. if (scrolled || dragInsertPointHighlight == 0
  45227. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45228. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45229. {
  45230. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45231. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45232. showDragHighlight (item, insertIndex, x, y);
  45233. else
  45234. hideDragHighlight();
  45235. }
  45236. }
  45237. else
  45238. {
  45239. hideDragHighlight();
  45240. }
  45241. }
  45242. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45243. {
  45244. hideDragHighlight();
  45245. int insertIndex;
  45246. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45247. if (item != 0)
  45248. {
  45249. if (files.size() > 0)
  45250. {
  45251. if (item->isInterestedInFileDrag (files))
  45252. item->filesDropped (files, insertIndex);
  45253. }
  45254. else
  45255. {
  45256. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45257. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45258. }
  45259. }
  45260. }
  45261. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45262. {
  45263. return true;
  45264. }
  45265. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45266. {
  45267. fileDragMove (files, x, y);
  45268. }
  45269. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45270. {
  45271. handleDrag (files, String::empty, 0, x, y);
  45272. }
  45273. void TreeView::fileDragExit (const StringArray&)
  45274. {
  45275. hideDragHighlight();
  45276. }
  45277. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45278. {
  45279. handleDrop (files, String::empty, 0, x, y);
  45280. }
  45281. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45282. {
  45283. return true;
  45284. }
  45285. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45286. {
  45287. itemDragMove (sourceDescription, sourceComponent, x, y);
  45288. }
  45289. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45290. {
  45291. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45292. }
  45293. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45294. {
  45295. hideDragHighlight();
  45296. }
  45297. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45298. {
  45299. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45300. }
  45301. void TreeViewContentComponent::paint (Graphics& g)
  45302. {
  45303. if (owner->rootItem != 0)
  45304. {
  45305. owner->handleAsyncUpdate();
  45306. if (! owner->rootItemVisible)
  45307. g.setOrigin (0, -owner->rootItem->itemHeight);
  45308. owner->rootItem->paintRecursively (g, getWidth());
  45309. }
  45310. }
  45311. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  45312. {
  45313. if (owner->rootItem != 0)
  45314. {
  45315. owner->handleAsyncUpdate();
  45316. if (! owner->rootItemVisible)
  45317. y += owner->rootItem->itemHeight;
  45318. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45319. if (ti != 0)
  45320. itemPosition = ti->getItemPosition (false);
  45321. return ti;
  45322. }
  45323. return 0;
  45324. }
  45325. enum TreeViewOpenness
  45326. {
  45327. opennessDefault = 0,
  45328. opennessClosed = 1,
  45329. opennessOpen = 2
  45330. };
  45331. TreeViewItem::TreeViewItem()
  45332. : ownerView (0),
  45333. parentItem (0),
  45334. y (0),
  45335. itemHeight (0),
  45336. totalHeight (0),
  45337. selected (false),
  45338. redrawNeeded (true),
  45339. drawLinesInside (true),
  45340. drawsInLeftMargin (false),
  45341. openness (opennessDefault)
  45342. {
  45343. static int nextUID = 0;
  45344. uid = nextUID++;
  45345. }
  45346. TreeViewItem::~TreeViewItem()
  45347. {
  45348. }
  45349. const String TreeViewItem::getUniqueName() const
  45350. {
  45351. return String::empty;
  45352. }
  45353. void TreeViewItem::itemOpennessChanged (bool)
  45354. {
  45355. }
  45356. int TreeViewItem::getNumSubItems() const throw()
  45357. {
  45358. return subItems.size();
  45359. }
  45360. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45361. {
  45362. return subItems [index];
  45363. }
  45364. void TreeViewItem::clearSubItems()
  45365. {
  45366. if (subItems.size() > 0)
  45367. {
  45368. if (ownerView != 0)
  45369. {
  45370. const ScopedLock sl (ownerView->nodeAlterationLock);
  45371. subItems.clear();
  45372. treeHasChanged();
  45373. }
  45374. else
  45375. {
  45376. subItems.clear();
  45377. }
  45378. }
  45379. }
  45380. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45381. {
  45382. if (newItem != 0)
  45383. {
  45384. newItem->parentItem = this;
  45385. newItem->setOwnerView (ownerView);
  45386. newItem->y = 0;
  45387. newItem->itemHeight = newItem->getItemHeight();
  45388. newItem->totalHeight = 0;
  45389. newItem->itemWidth = newItem->getItemWidth();
  45390. newItem->totalWidth = 0;
  45391. if (ownerView != 0)
  45392. {
  45393. const ScopedLock sl (ownerView->nodeAlterationLock);
  45394. subItems.insert (insertPosition, newItem);
  45395. treeHasChanged();
  45396. if (newItem->isOpen())
  45397. newItem->itemOpennessChanged (true);
  45398. }
  45399. else
  45400. {
  45401. subItems.insert (insertPosition, newItem);
  45402. if (newItem->isOpen())
  45403. newItem->itemOpennessChanged (true);
  45404. }
  45405. }
  45406. }
  45407. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45408. {
  45409. if (ownerView != 0)
  45410. ownerView->nodeAlterationLock.enter();
  45411. if (((unsigned int) index) < (unsigned int) subItems.size())
  45412. {
  45413. subItems.remove (index, deleteItem);
  45414. treeHasChanged();
  45415. }
  45416. if (ownerView != 0)
  45417. ownerView->nodeAlterationLock.exit();
  45418. }
  45419. bool TreeViewItem::isOpen() const throw()
  45420. {
  45421. if (openness == opennessDefault)
  45422. return ownerView != 0 && ownerView->defaultOpenness;
  45423. else
  45424. return openness == opennessOpen;
  45425. }
  45426. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45427. {
  45428. if (isOpen() != shouldBeOpen)
  45429. {
  45430. openness = shouldBeOpen ? opennessOpen
  45431. : opennessClosed;
  45432. treeHasChanged();
  45433. itemOpennessChanged (isOpen());
  45434. }
  45435. }
  45436. bool TreeViewItem::isSelected() const throw()
  45437. {
  45438. return selected;
  45439. }
  45440. void TreeViewItem::deselectAllRecursively()
  45441. {
  45442. setSelected (false, false);
  45443. for (int i = 0; i < subItems.size(); ++i)
  45444. subItems.getUnchecked(i)->deselectAllRecursively();
  45445. }
  45446. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45447. const bool deselectOtherItemsFirst)
  45448. {
  45449. if (shouldBeSelected && ! canBeSelected())
  45450. return;
  45451. if (deselectOtherItemsFirst)
  45452. getTopLevelItem()->deselectAllRecursively();
  45453. if (shouldBeSelected != selected)
  45454. {
  45455. selected = shouldBeSelected;
  45456. if (ownerView != 0)
  45457. ownerView->repaint();
  45458. itemSelectionChanged (shouldBeSelected);
  45459. }
  45460. }
  45461. void TreeViewItem::paintItem (Graphics&, int, int)
  45462. {
  45463. }
  45464. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45465. {
  45466. ownerView->getLookAndFeel()
  45467. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45468. }
  45469. void TreeViewItem::itemClicked (const MouseEvent&)
  45470. {
  45471. }
  45472. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45473. {
  45474. if (mightContainSubItems())
  45475. setOpen (! isOpen());
  45476. }
  45477. void TreeViewItem::itemSelectionChanged (bool)
  45478. {
  45479. }
  45480. const String TreeViewItem::getTooltip()
  45481. {
  45482. return String::empty;
  45483. }
  45484. const String TreeViewItem::getDragSourceDescription()
  45485. {
  45486. return String::empty;
  45487. }
  45488. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45489. {
  45490. return false;
  45491. }
  45492. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45493. {
  45494. }
  45495. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45496. {
  45497. return false;
  45498. }
  45499. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45500. {
  45501. }
  45502. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45503. {
  45504. const int indentX = getIndentX();
  45505. int width = itemWidth;
  45506. if (ownerView != 0 && width < 0)
  45507. width = ownerView->viewport->getViewWidth() - indentX;
  45508. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45509. if (relativeToTreeViewTopLeft)
  45510. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45511. r.getY() - ownerView->viewport->getViewPositionY());
  45512. return r;
  45513. }
  45514. void TreeViewItem::treeHasChanged() const throw()
  45515. {
  45516. if (ownerView != 0)
  45517. ownerView->itemsChanged();
  45518. }
  45519. void TreeViewItem::repaintItem() const
  45520. {
  45521. if (ownerView != 0 && areAllParentsOpen())
  45522. {
  45523. const Rectangle<int> r (getItemPosition (true));
  45524. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45525. }
  45526. }
  45527. bool TreeViewItem::areAllParentsOpen() const throw()
  45528. {
  45529. return parentItem == 0
  45530. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45531. }
  45532. void TreeViewItem::updatePositions (int newY)
  45533. {
  45534. y = newY;
  45535. itemHeight = getItemHeight();
  45536. totalHeight = itemHeight;
  45537. itemWidth = getItemWidth();
  45538. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45539. if (isOpen())
  45540. {
  45541. newY += totalHeight;
  45542. for (int i = 0; i < subItems.size(); ++i)
  45543. {
  45544. TreeViewItem* const ti = subItems.getUnchecked(i);
  45545. ti->updatePositions (newY);
  45546. newY += ti->totalHeight;
  45547. totalHeight += ti->totalHeight;
  45548. totalWidth = jmax (totalWidth, ti->totalWidth);
  45549. }
  45550. }
  45551. }
  45552. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45553. {
  45554. TreeViewItem* result = this;
  45555. TreeViewItem* item = this;
  45556. while (item->parentItem != 0)
  45557. {
  45558. item = item->parentItem;
  45559. if (! item->isOpen())
  45560. result = item;
  45561. }
  45562. return result;
  45563. }
  45564. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45565. {
  45566. ownerView = newOwner;
  45567. for (int i = subItems.size(); --i >= 0;)
  45568. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45569. }
  45570. int TreeViewItem::getIndentX() const throw()
  45571. {
  45572. const int indentWidth = ownerView->getIndentSize();
  45573. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45574. if (! ownerView->openCloseButtonsVisible)
  45575. x -= indentWidth;
  45576. TreeViewItem* p = parentItem;
  45577. while (p != 0)
  45578. {
  45579. x += indentWidth;
  45580. p = p->parentItem;
  45581. }
  45582. return x;
  45583. }
  45584. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45585. {
  45586. drawsInLeftMargin = canDrawInLeftMargin;
  45587. }
  45588. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45589. {
  45590. jassert (ownerView != 0);
  45591. if (ownerView == 0)
  45592. return;
  45593. const int indent = getIndentX();
  45594. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45595. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45596. const float halfH = itemHeight * 0.5f;
  45597. int depth = 0;
  45598. TreeViewItem* p = parentItem;
  45599. while (p != 0)
  45600. {
  45601. ++depth;
  45602. p = p->parentItem;
  45603. }
  45604. if (! ownerView->rootItemVisible)
  45605. --depth;
  45606. const int indentWidth = ownerView->getIndentSize();
  45607. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45608. {
  45609. float x = (depth + 0.5f) * indentWidth;
  45610. if (depth >= 0)
  45611. {
  45612. if (parentItem != 0 && parentItem->drawLinesInside)
  45613. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45614. if ((parentItem != 0 && parentItem->drawLinesInside)
  45615. || (parentItem == 0 && drawLinesInside))
  45616. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45617. }
  45618. p = parentItem;
  45619. int d = depth;
  45620. while (p != 0 && --d >= 0)
  45621. {
  45622. x -= (float) indentWidth;
  45623. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45624. && ! p->isLastOfSiblings())
  45625. {
  45626. g.drawLine (x, 0, x, (float) itemHeight);
  45627. }
  45628. p = p->parentItem;
  45629. }
  45630. if (mightContainSubItems())
  45631. {
  45632. g.saveState();
  45633. g.setOrigin (depth * indentWidth, 0);
  45634. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45635. paintOpenCloseButton (g, indentWidth, itemHeight,
  45636. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45637. ->isMouseOverButton (this));
  45638. g.restoreState();
  45639. }
  45640. }
  45641. {
  45642. g.saveState();
  45643. g.setOrigin (indent, 0);
  45644. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45645. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45646. paintItem (g, itemW, itemHeight);
  45647. g.restoreState();
  45648. }
  45649. if (isOpen())
  45650. {
  45651. const Rectangle<int> clip (g.getClipBounds());
  45652. for (int i = 0; i < subItems.size(); ++i)
  45653. {
  45654. TreeViewItem* const ti = subItems.getUnchecked(i);
  45655. const int relY = ti->y - y;
  45656. if (relY >= clip.getBottom())
  45657. break;
  45658. if (relY + ti->totalHeight >= clip.getY())
  45659. {
  45660. g.saveState();
  45661. g.setOrigin (0, relY);
  45662. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45663. ti->paintRecursively (g, width);
  45664. g.restoreState();
  45665. }
  45666. }
  45667. }
  45668. }
  45669. bool TreeViewItem::isLastOfSiblings() const throw()
  45670. {
  45671. return parentItem == 0
  45672. || parentItem->subItems.getLast() == this;
  45673. }
  45674. int TreeViewItem::getIndexInParent() const throw()
  45675. {
  45676. if (parentItem == 0)
  45677. return 0;
  45678. return parentItem->subItems.indexOf (this);
  45679. }
  45680. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45681. {
  45682. return (parentItem == 0) ? this
  45683. : parentItem->getTopLevelItem();
  45684. }
  45685. int TreeViewItem::getNumRows() const throw()
  45686. {
  45687. int num = 1;
  45688. if (isOpen())
  45689. {
  45690. for (int i = subItems.size(); --i >= 0;)
  45691. num += subItems.getUnchecked(i)->getNumRows();
  45692. }
  45693. return num;
  45694. }
  45695. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45696. {
  45697. if (index == 0)
  45698. return this;
  45699. if (index > 0 && isOpen())
  45700. {
  45701. --index;
  45702. for (int i = 0; i < subItems.size(); ++i)
  45703. {
  45704. TreeViewItem* const item = subItems.getUnchecked(i);
  45705. if (index == 0)
  45706. return item;
  45707. const int numRows = item->getNumRows();
  45708. if (numRows > index)
  45709. return item->getItemOnRow (index);
  45710. index -= numRows;
  45711. }
  45712. }
  45713. return 0;
  45714. }
  45715. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45716. {
  45717. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45718. {
  45719. const int h = itemHeight;
  45720. if (targetY < h)
  45721. return this;
  45722. if (isOpen())
  45723. {
  45724. targetY -= h;
  45725. for (int i = 0; i < subItems.size(); ++i)
  45726. {
  45727. TreeViewItem* const ti = subItems.getUnchecked(i);
  45728. if (targetY < ti->totalHeight)
  45729. return ti->findItemRecursively (targetY);
  45730. targetY -= ti->totalHeight;
  45731. }
  45732. }
  45733. }
  45734. return 0;
  45735. }
  45736. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45737. {
  45738. int total = 0;
  45739. if (isSelected())
  45740. ++total;
  45741. for (int i = subItems.size(); --i >= 0;)
  45742. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45743. return total;
  45744. }
  45745. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45746. {
  45747. if (isSelected())
  45748. {
  45749. if (index == 0)
  45750. return this;
  45751. --index;
  45752. }
  45753. if (index >= 0)
  45754. {
  45755. for (int i = 0; i < subItems.size(); ++i)
  45756. {
  45757. TreeViewItem* const item = subItems.getUnchecked(i);
  45758. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45759. if (found != 0)
  45760. return found;
  45761. index -= item->countSelectedItemsRecursively();
  45762. }
  45763. }
  45764. return 0;
  45765. }
  45766. int TreeViewItem::getRowNumberInTree() const throw()
  45767. {
  45768. if (parentItem != 0 && ownerView != 0)
  45769. {
  45770. int n = 1 + parentItem->getRowNumberInTree();
  45771. int ourIndex = parentItem->subItems.indexOf (this);
  45772. jassert (ourIndex >= 0);
  45773. while (--ourIndex >= 0)
  45774. n += parentItem->subItems [ourIndex]->getNumRows();
  45775. if (parentItem->parentItem == 0
  45776. && ! ownerView->rootItemVisible)
  45777. --n;
  45778. return n;
  45779. }
  45780. else
  45781. {
  45782. return 0;
  45783. }
  45784. }
  45785. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45786. {
  45787. drawLinesInside = drawLines;
  45788. }
  45789. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45790. {
  45791. if (recurse && isOpen() && subItems.size() > 0)
  45792. return subItems [0];
  45793. if (parentItem != 0)
  45794. {
  45795. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45796. if (nextIndex >= parentItem->subItems.size())
  45797. return parentItem->getNextVisibleItem (false);
  45798. return parentItem->subItems [nextIndex];
  45799. }
  45800. return 0;
  45801. }
  45802. const String TreeViewItem::getItemIdentifierString() const
  45803. {
  45804. String s;
  45805. if (parentItem != 0)
  45806. s = parentItem->getItemIdentifierString();
  45807. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45808. }
  45809. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45810. {
  45811. const String uid (getUniqueName());
  45812. if (uid == identifierString)
  45813. return this;
  45814. if (identifierString.startsWith (uid + T("/")))
  45815. {
  45816. const String remainingPath (identifierString.substring (uid.length() + 1));
  45817. bool wasOpen = isOpen();
  45818. setOpen (true);
  45819. for (int i = subItems.size(); --i >= 0;)
  45820. {
  45821. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45822. if (item != 0)
  45823. return item;
  45824. }
  45825. setOpen (wasOpen);
  45826. }
  45827. return 0;
  45828. }
  45829. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45830. {
  45831. if (e.hasTagName (T("CLOSED")))
  45832. {
  45833. setOpen (false);
  45834. }
  45835. else if (e.hasTagName (T("OPEN")))
  45836. {
  45837. setOpen (true);
  45838. forEachXmlChildElement (e, n)
  45839. {
  45840. const String id (n->getStringAttribute (T("id")));
  45841. for (int i = 0; i < subItems.size(); ++i)
  45842. {
  45843. TreeViewItem* const ti = subItems.getUnchecked(i);
  45844. if (ti->getUniqueName() == id)
  45845. {
  45846. ti->restoreOpennessState (*n);
  45847. break;
  45848. }
  45849. }
  45850. }
  45851. }
  45852. }
  45853. XmlElement* TreeViewItem::getOpennessState() const throw()
  45854. {
  45855. const String name (getUniqueName());
  45856. if (name.isNotEmpty())
  45857. {
  45858. XmlElement* e;
  45859. if (isOpen())
  45860. {
  45861. e = new XmlElement (T("OPEN"));
  45862. for (int i = 0; i < subItems.size(); ++i)
  45863. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45864. }
  45865. else
  45866. {
  45867. e = new XmlElement (T("CLOSED"));
  45868. }
  45869. e->setAttribute (T("id"), name);
  45870. return e;
  45871. }
  45872. else
  45873. {
  45874. // trying to save the openness for an element that has no name - this won't
  45875. // work because it needs the names to identify what to open.
  45876. jassertfalse
  45877. }
  45878. return 0;
  45879. }
  45880. END_JUCE_NAMESPACE
  45881. /*** End of inlined file: juce_TreeView.cpp ***/
  45882. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45883. BEGIN_JUCE_NAMESPACE
  45884. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45885. : fileList (listToShow)
  45886. {
  45887. }
  45888. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45889. {
  45890. }
  45891. FileBrowserListener::~FileBrowserListener()
  45892. {
  45893. }
  45894. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45895. {
  45896. jassert (listener != 0);
  45897. if (listener != 0)
  45898. listeners.add (listener);
  45899. }
  45900. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45901. {
  45902. listeners.removeValue (listener);
  45903. }
  45904. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45905. {
  45906. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45907. for (int i = listeners.size(); --i >= 0;)
  45908. {
  45909. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45910. if (deletionWatcher.hasBeenDeleted())
  45911. return;
  45912. i = jmin (i, listeners.size() - 1);
  45913. }
  45914. }
  45915. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45916. {
  45917. if (fileList.getDirectory().exists())
  45918. {
  45919. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45920. for (int i = listeners.size(); --i >= 0;)
  45921. {
  45922. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45923. if (deletionWatcher.hasBeenDeleted())
  45924. return;
  45925. i = jmin (i, listeners.size() - 1);
  45926. }
  45927. }
  45928. }
  45929. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45930. {
  45931. if (fileList.getDirectory().exists())
  45932. {
  45933. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45934. for (int i = listeners.size(); --i >= 0;)
  45935. {
  45936. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45937. if (deletionWatcher.hasBeenDeleted())
  45938. return;
  45939. i = jmin (i, listeners.size() - 1);
  45940. }
  45941. }
  45942. }
  45943. END_JUCE_NAMESPACE
  45944. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45945. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45946. BEGIN_JUCE_NAMESPACE
  45947. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45948. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45949. Time* creationTime, bool* isReadOnly);
  45950. bool juce_findFileNext (void* handle, String& resultFile,
  45951. bool* isDirectory, bool* isHidden, int64* fileSize,
  45952. Time* modTime, Time* creationTime, bool* isReadOnly);
  45953. void juce_findFileClose (void* handle);
  45954. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45955. TimeSliceThread& thread_)
  45956. : fileFilter (fileFilter_),
  45957. thread (thread_),
  45958. includeDirectories (false),
  45959. includeFiles (false),
  45960. ignoreHiddenFiles (true),
  45961. fileFindHandle (0),
  45962. shouldStop (true)
  45963. {
  45964. }
  45965. DirectoryContentsList::~DirectoryContentsList()
  45966. {
  45967. clear();
  45968. }
  45969. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45970. {
  45971. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45972. }
  45973. const File& DirectoryContentsList::getDirectory() const
  45974. {
  45975. return root;
  45976. }
  45977. void DirectoryContentsList::setDirectory (const File& directory,
  45978. const bool includeDirectories_,
  45979. const bool includeFiles_)
  45980. {
  45981. if (directory != root
  45982. || includeDirectories != includeDirectories_
  45983. || includeFiles != includeFiles_)
  45984. {
  45985. clear();
  45986. root = directory;
  45987. includeDirectories = includeDirectories_;
  45988. includeFiles = includeFiles_;
  45989. refresh();
  45990. }
  45991. }
  45992. void DirectoryContentsList::clear()
  45993. {
  45994. shouldStop = true;
  45995. thread.removeTimeSliceClient (this);
  45996. if (fileFindHandle != 0)
  45997. {
  45998. juce_findFileClose (fileFindHandle);
  45999. fileFindHandle = 0;
  46000. }
  46001. if (files.size() > 0)
  46002. {
  46003. files.clear();
  46004. changed();
  46005. }
  46006. }
  46007. void DirectoryContentsList::refresh()
  46008. {
  46009. clear();
  46010. if (root.isDirectory())
  46011. {
  46012. String fileFound;
  46013. bool fileFoundIsDir, isHidden, isReadOnly;
  46014. int64 fileSize;
  46015. Time modTime, creationTime;
  46016. String path (root.getFullPathName());
  46017. if (! path.endsWithChar (File::separator))
  46018. path += File::separator;
  46019. jassert (fileFindHandle == 0);
  46020. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  46021. &fileFoundIsDir,
  46022. &isHidden,
  46023. &fileSize,
  46024. &modTime,
  46025. &creationTime,
  46026. &isReadOnly);
  46027. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  46028. {
  46029. if (addFile (fileFound, fileFoundIsDir, isHidden,
  46030. fileSize, modTime, creationTime, isReadOnly))
  46031. {
  46032. changed();
  46033. }
  46034. }
  46035. shouldStop = false;
  46036. thread.addTimeSliceClient (this);
  46037. }
  46038. }
  46039. int DirectoryContentsList::getNumFiles() const
  46040. {
  46041. return files.size();
  46042. }
  46043. bool DirectoryContentsList::getFileInfo (const int index,
  46044. FileInfo& result) const
  46045. {
  46046. const ScopedLock sl (fileListLock);
  46047. const FileInfo* const info = files [index];
  46048. if (info != 0)
  46049. {
  46050. result = *info;
  46051. return true;
  46052. }
  46053. return false;
  46054. }
  46055. const File DirectoryContentsList::getFile (const int index) const
  46056. {
  46057. const ScopedLock sl (fileListLock);
  46058. const FileInfo* const info = files [index];
  46059. if (info != 0)
  46060. return root.getChildFile (info->filename);
  46061. return File::nonexistent;
  46062. }
  46063. bool DirectoryContentsList::isStillLoading() const
  46064. {
  46065. return fileFindHandle != 0;
  46066. }
  46067. void DirectoryContentsList::changed()
  46068. {
  46069. sendChangeMessage (this);
  46070. }
  46071. bool DirectoryContentsList::useTimeSlice()
  46072. {
  46073. const uint32 startTime = Time::getApproximateMillisecondCounter();
  46074. bool hasChanged = false;
  46075. for (int i = 100; --i >= 0;)
  46076. {
  46077. if (! checkNextFile (hasChanged))
  46078. {
  46079. if (hasChanged)
  46080. changed();
  46081. return false;
  46082. }
  46083. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  46084. break;
  46085. }
  46086. if (hasChanged)
  46087. changed();
  46088. return true;
  46089. }
  46090. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  46091. {
  46092. if (fileFindHandle != 0)
  46093. {
  46094. String fileFound;
  46095. bool fileFoundIsDir, isHidden, isReadOnly;
  46096. int64 fileSize;
  46097. Time modTime, creationTime;
  46098. if (juce_findFileNext (fileFindHandle, fileFound,
  46099. &fileFoundIsDir, &isHidden,
  46100. &fileSize,
  46101. &modTime,
  46102. &creationTime,
  46103. &isReadOnly))
  46104. {
  46105. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  46106. modTime, creationTime, isReadOnly))
  46107. {
  46108. hasChanged = true;
  46109. }
  46110. return true;
  46111. }
  46112. else
  46113. {
  46114. juce_findFileClose (fileFindHandle);
  46115. fileFindHandle = 0;
  46116. }
  46117. }
  46118. return false;
  46119. }
  46120. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46121. const DirectoryContentsList::FileInfo* const second)
  46122. {
  46123. #if JUCE_WINDOWS
  46124. if (first->isDirectory != second->isDirectory)
  46125. return first->isDirectory ? -1 : 1;
  46126. #endif
  46127. return first->filename.compareIgnoreCase (second->filename);
  46128. }
  46129. bool DirectoryContentsList::addFile (const String& filename,
  46130. const bool isDir,
  46131. const bool isHidden,
  46132. const int64 fileSize,
  46133. const Time& modTime,
  46134. const Time& creationTime,
  46135. const bool isReadOnly)
  46136. {
  46137. if (filename == T("..")
  46138. || filename == T(".")
  46139. || (ignoreHiddenFiles && isHidden))
  46140. return false;
  46141. const File file (root.getChildFile (filename));
  46142. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46143. && (fileFilter == 0
  46144. || ((! isDir) && fileFilter->isFileSuitable (file))
  46145. || (isDir && fileFilter->isDirectorySuitable (file))))
  46146. {
  46147. ScopedPointer <FileInfo> info (new FileInfo());
  46148. info->filename = filename;
  46149. info->fileSize = fileSize;
  46150. info->modificationTime = modTime;
  46151. info->creationTime = creationTime;
  46152. info->isDirectory = isDir;
  46153. info->isReadOnly = isReadOnly;
  46154. const ScopedLock sl (fileListLock);
  46155. for (int i = files.size(); --i >= 0;)
  46156. if (files.getUnchecked(i)->filename == info->filename)
  46157. return false;
  46158. files.addSorted (*this, info.release());
  46159. return true;
  46160. }
  46161. return false;
  46162. }
  46163. END_JUCE_NAMESPACE
  46164. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  46165. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  46166. BEGIN_JUCE_NAMESPACE
  46167. FileBrowserComponent::FileBrowserComponent (int flags_,
  46168. const File& initialFileOrDirectory,
  46169. const FileFilter* fileFilter_,
  46170. FilePreviewComponent* previewComp_)
  46171. : FileFilter (String::empty),
  46172. fileFilter (fileFilter_),
  46173. flags (flags_),
  46174. previewComp (previewComp_),
  46175. thread ("Juce FileBrowser")
  46176. {
  46177. // You need to specify one or other of the open/save flags..
  46178. jassert ((flags & (saveMode | openMode)) != 0);
  46179. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46180. // You need to specify at least one of these flags..
  46181. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46182. String filename;
  46183. if (initialFileOrDirectory == File::nonexistent)
  46184. {
  46185. currentRoot = File::getCurrentWorkingDirectory();
  46186. }
  46187. else if (initialFileOrDirectory.isDirectory())
  46188. {
  46189. currentRoot = initialFileOrDirectory;
  46190. }
  46191. else
  46192. {
  46193. chosenFiles.add (initialFileOrDirectory);
  46194. currentRoot = initialFileOrDirectory.getParentDirectory();
  46195. filename = initialFileOrDirectory.getFileName();
  46196. }
  46197. fileList = new DirectoryContentsList (this, thread);
  46198. if ((flags & useTreeView) != 0)
  46199. {
  46200. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46201. if ((flags & canSelectMultipleItems) != 0)
  46202. tree->setMultiSelectEnabled (true);
  46203. addAndMakeVisible (tree);
  46204. fileListComponent = tree;
  46205. }
  46206. else
  46207. {
  46208. FileListComponent* const list = new FileListComponent (*fileList);
  46209. list->setOutlineThickness (1);
  46210. if ((flags & canSelectMultipleItems) != 0)
  46211. list->setMultipleSelectionEnabled (true);
  46212. addAndMakeVisible (list);
  46213. fileListComponent = list;
  46214. }
  46215. fileListComponent->addListener (this);
  46216. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46217. currentPathBox->setEditableText (true);
  46218. StringArray rootNames, rootPaths;
  46219. const BitArray separators (getRoots (rootNames, rootPaths));
  46220. for (int i = 0; i < rootNames.size(); ++i)
  46221. {
  46222. if (separators [i])
  46223. currentPathBox->addSeparator();
  46224. currentPathBox->addItem (rootNames[i], i + 1);
  46225. }
  46226. currentPathBox->addSeparator();
  46227. currentPathBox->addListener (this);
  46228. addAndMakeVisible (filenameBox = new TextEditor());
  46229. filenameBox->setMultiLine (false);
  46230. filenameBox->setSelectAllWhenFocused (true);
  46231. filenameBox->setText (filename, false);
  46232. filenameBox->addListener (this);
  46233. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46234. Label* label = new Label ("f", TRANS("file:"));
  46235. addAndMakeVisible (label);
  46236. label->attachToComponent (filenameBox, true);
  46237. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46238. goUpButton->addButtonListener (this);
  46239. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46240. if (previewComp != 0)
  46241. addAndMakeVisible (previewComp);
  46242. setRoot (currentRoot);
  46243. thread.startThread (4);
  46244. }
  46245. FileBrowserComponent::~FileBrowserComponent()
  46246. {
  46247. if (previewComp != 0)
  46248. removeChildComponent (previewComp);
  46249. deleteAllChildren();
  46250. fileList = 0;
  46251. thread.stopThread (10000);
  46252. }
  46253. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46254. {
  46255. jassert (newListener != 0)
  46256. if (newListener != 0)
  46257. listeners.add (newListener);
  46258. }
  46259. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46260. {
  46261. listeners.removeValue (listener);
  46262. }
  46263. bool FileBrowserComponent::isSaveMode() const throw()
  46264. {
  46265. return (flags & saveMode) != 0;
  46266. }
  46267. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46268. {
  46269. if (chosenFiles.size() == 0 && currentFileIsValid())
  46270. return 1;
  46271. return chosenFiles.size();
  46272. }
  46273. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46274. {
  46275. if (! filenameBox->isReadOnly())
  46276. return currentRoot.getChildFile (filenameBox->getText());
  46277. else
  46278. return chosenFiles[index];
  46279. }
  46280. bool FileBrowserComponent::currentFileIsValid() const
  46281. {
  46282. if (isSaveMode())
  46283. return ! getSelectedFile (0).isDirectory();
  46284. else
  46285. return getSelectedFile (0).exists();
  46286. }
  46287. const File FileBrowserComponent::getHighlightedFile() const throw()
  46288. {
  46289. return fileListComponent->getSelectedFile (0);
  46290. }
  46291. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46292. {
  46293. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46294. : false;
  46295. }
  46296. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46297. {
  46298. return true;
  46299. }
  46300. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46301. {
  46302. if (f.isDirectory())
  46303. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46304. return (flags & canSelectFiles) != 0 && f.exists()
  46305. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46306. }
  46307. const File FileBrowserComponent::getRoot() const
  46308. {
  46309. return currentRoot;
  46310. }
  46311. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46312. {
  46313. if (currentRoot != newRootDirectory)
  46314. {
  46315. fileListComponent->scrollToTop();
  46316. String path (newRootDirectory.getFullPathName());
  46317. if (path.isEmpty())
  46318. path += File::separator;
  46319. StringArray rootNames, rootPaths;
  46320. getRoots (rootNames, rootPaths);
  46321. if (! rootPaths.contains (path, true))
  46322. {
  46323. bool alreadyListed = false;
  46324. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46325. {
  46326. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46327. {
  46328. alreadyListed = true;
  46329. break;
  46330. }
  46331. }
  46332. if (! alreadyListed)
  46333. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46334. }
  46335. }
  46336. currentRoot = newRootDirectory;
  46337. fileList->setDirectory (currentRoot, true, true);
  46338. String currentRootName (currentRoot.getFullPathName());
  46339. if (currentRootName.isEmpty())
  46340. currentRootName += File::separator;
  46341. currentPathBox->setText (currentRootName, true);
  46342. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46343. && currentRoot.getParentDirectory() != currentRoot);
  46344. }
  46345. void FileBrowserComponent::goUp()
  46346. {
  46347. setRoot (getRoot().getParentDirectory());
  46348. }
  46349. void FileBrowserComponent::refresh()
  46350. {
  46351. fileList->refresh();
  46352. }
  46353. const String FileBrowserComponent::getActionVerb() const
  46354. {
  46355. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46356. }
  46357. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46358. {
  46359. return previewComp;
  46360. }
  46361. void FileBrowserComponent::resized()
  46362. {
  46363. getLookAndFeel()
  46364. .layoutFileBrowserComponent (*this, fileListComponent,
  46365. previewComp, currentPathBox,
  46366. filenameBox, goUpButton);
  46367. }
  46368. void FileBrowserComponent::sendListenerChangeMessage()
  46369. {
  46370. ComponentDeletionWatcher deletionWatcher (this);
  46371. if (previewComp != 0)
  46372. previewComp->selectedFileChanged (getSelectedFile (0));
  46373. jassert (! deletionWatcher.hasBeenDeleted());
  46374. for (int i = listeners.size(); --i >= 0;)
  46375. {
  46376. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46377. if (deletionWatcher.hasBeenDeleted())
  46378. return;
  46379. i = jmin (i, listeners.size() - 1);
  46380. }
  46381. }
  46382. void FileBrowserComponent::selectionChanged()
  46383. {
  46384. StringArray newFilenames;
  46385. bool resetChosenFiles = true;
  46386. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46387. {
  46388. const File f (fileListComponent->getSelectedFile (i));
  46389. if (isFileOrDirSuitable (f))
  46390. {
  46391. if (resetChosenFiles)
  46392. {
  46393. chosenFiles.clear();
  46394. resetChosenFiles = false;
  46395. }
  46396. chosenFiles.add (f);
  46397. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46398. }
  46399. }
  46400. if (newFilenames.size() > 0)
  46401. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46402. sendListenerChangeMessage();
  46403. }
  46404. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46405. {
  46406. ComponentDeletionWatcher deletionWatcher (this);
  46407. for (int i = listeners.size(); --i >= 0;)
  46408. {
  46409. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46410. if (deletionWatcher.hasBeenDeleted())
  46411. return;
  46412. i = jmin (i, listeners.size() - 1);
  46413. }
  46414. }
  46415. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46416. {
  46417. if (f.isDirectory())
  46418. {
  46419. setRoot (f);
  46420. }
  46421. else
  46422. {
  46423. ComponentDeletionWatcher deletionWatcher (this);
  46424. for (int i = listeners.size(); --i >= 0;)
  46425. {
  46426. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46427. if (deletionWatcher.hasBeenDeleted())
  46428. return;
  46429. i = jmin (i, listeners.size() - 1);
  46430. }
  46431. }
  46432. }
  46433. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46434. {
  46435. #if JUCE_LINUX || JUCE_WINDOWS
  46436. if (key.getModifiers().isCommandDown()
  46437. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46438. {
  46439. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46440. fileList->refresh();
  46441. return true;
  46442. }
  46443. #endif
  46444. return false;
  46445. }
  46446. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46447. {
  46448. sendListenerChangeMessage();
  46449. }
  46450. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46451. {
  46452. if (filenameBox->getText().containsChar (File::separator))
  46453. {
  46454. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46455. if (f.isDirectory())
  46456. {
  46457. setRoot (f);
  46458. chosenFiles.clear();
  46459. filenameBox->setText (String::empty);
  46460. }
  46461. else
  46462. {
  46463. setRoot (f.getParentDirectory());
  46464. chosenFiles.clear();
  46465. chosenFiles.add (f);
  46466. filenameBox->setText (f.getFileName());
  46467. }
  46468. }
  46469. else
  46470. {
  46471. fileDoubleClicked (getSelectedFile (0));
  46472. }
  46473. }
  46474. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46475. {
  46476. }
  46477. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46478. {
  46479. if (! isSaveMode())
  46480. selectionChanged();
  46481. }
  46482. void FileBrowserComponent::buttonClicked (Button*)
  46483. {
  46484. goUp();
  46485. }
  46486. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46487. {
  46488. const String newText (currentPathBox->getText().trim().unquoted());
  46489. if (newText.isNotEmpty())
  46490. {
  46491. const int index = currentPathBox->getSelectedId() - 1;
  46492. StringArray rootNames, rootPaths;
  46493. getRoots (rootNames, rootPaths);
  46494. if (rootPaths [index].isNotEmpty())
  46495. {
  46496. setRoot (File (rootPaths [index]));
  46497. }
  46498. else
  46499. {
  46500. File f (newText);
  46501. for (;;)
  46502. {
  46503. if (f.isDirectory())
  46504. {
  46505. setRoot (f);
  46506. break;
  46507. }
  46508. if (f.getParentDirectory() == f)
  46509. break;
  46510. f = f.getParentDirectory();
  46511. }
  46512. }
  46513. }
  46514. }
  46515. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46516. {
  46517. BitArray separators;
  46518. #if JUCE_WINDOWS
  46519. Array<File> roots;
  46520. File::findFileSystemRoots (roots);
  46521. rootPaths.clear();
  46522. for (int i = 0; i < roots.size(); ++i)
  46523. {
  46524. const File& drive = roots.getReference(i);
  46525. String name (drive.getFullPathName());
  46526. rootPaths.add (name);
  46527. if (drive.isOnHardDisk())
  46528. {
  46529. String volume (drive.getVolumeLabel());
  46530. if (volume.isEmpty())
  46531. volume = TRANS("Hard Drive");
  46532. name << " [" << drive.getVolumeLabel() << ']';
  46533. }
  46534. else if (drive.isOnCDRomDrive())
  46535. {
  46536. name << TRANS(" [CD/DVD drive]");
  46537. }
  46538. rootNames.add (name);
  46539. }
  46540. separators.setBit (rootPaths.size());
  46541. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46542. rootNames.add ("Documents");
  46543. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46544. rootNames.add ("Desktop");
  46545. #endif
  46546. #if JUCE_MAC
  46547. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46548. rootNames.add ("Home folder");
  46549. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46550. rootNames.add ("Documents");
  46551. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46552. rootNames.add ("Desktop");
  46553. separators.setBit (rootPaths.size());
  46554. Array <File> volumes;
  46555. File vol ("/Volumes");
  46556. vol.findChildFiles (volumes, File::findDirectories, false);
  46557. for (int i = 0; i < volumes.size(); ++i)
  46558. {
  46559. const File& volume = volumes.getReference(i);
  46560. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46561. {
  46562. rootPaths.add (volume.getFullPathName());
  46563. rootNames.add (volume.getFileName());
  46564. }
  46565. }
  46566. #endif
  46567. #if JUCE_LINUX
  46568. rootPaths.add ("/");
  46569. rootNames.add ("/");
  46570. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46571. rootNames.add ("Home folder");
  46572. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46573. rootNames.add ("Desktop");
  46574. #endif
  46575. return separators;
  46576. }
  46577. END_JUCE_NAMESPACE
  46578. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46579. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46580. BEGIN_JUCE_NAMESPACE
  46581. FileChooser::FileChooser (const String& chooserBoxTitle,
  46582. const File& currentFileOrDirectory,
  46583. const String& fileFilters,
  46584. const bool useNativeDialogBox_)
  46585. : title (chooserBoxTitle),
  46586. filters (fileFilters),
  46587. startingFile (currentFileOrDirectory),
  46588. useNativeDialogBox (useNativeDialogBox_)
  46589. {
  46590. #if JUCE_LINUX
  46591. useNativeDialogBox = false;
  46592. #endif
  46593. if (! fileFilters.containsNonWhitespaceChars())
  46594. filters = T("*");
  46595. }
  46596. FileChooser::~FileChooser()
  46597. {
  46598. }
  46599. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46600. {
  46601. return showDialog (false, true, false, false, false, previewComponent);
  46602. }
  46603. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46604. {
  46605. return showDialog (false, true, false, false, true, previewComponent);
  46606. }
  46607. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46608. {
  46609. return showDialog (true, true, false, false, true, previewComponent);
  46610. }
  46611. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46612. {
  46613. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46614. }
  46615. bool FileChooser::browseForDirectory()
  46616. {
  46617. return showDialog (true, false, false, false, false, 0);
  46618. }
  46619. const File FileChooser::getResult() const
  46620. {
  46621. // if you've used a multiple-file select, you should use the getResults() method
  46622. // to retrieve all the files that were chosen.
  46623. jassert (results.size() <= 1);
  46624. return results.getFirst();
  46625. }
  46626. const Array<File>& FileChooser::getResults() const
  46627. {
  46628. return results;
  46629. }
  46630. bool FileChooser::showDialog (const bool selectsDirectories,
  46631. const bool selectsFiles,
  46632. const bool isSave,
  46633. const bool warnAboutOverwritingExistingFiles,
  46634. const bool selectMultipleFiles,
  46635. FilePreviewComponent* const previewComponent)
  46636. {
  46637. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46638. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46639. if (currentlyFocused != 0)
  46640. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46641. results.clear();
  46642. // the preview component needs to be the right size before you pass it in here..
  46643. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46644. && previewComponent->getHeight() > 10));
  46645. #if JUCE_WINDOWS
  46646. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46647. #elif JUCE_MAC
  46648. if (useNativeDialogBox && (previewComponent == 0))
  46649. #else
  46650. if (false)
  46651. #endif
  46652. {
  46653. showPlatformDialog (results, title, startingFile, filters,
  46654. selectsDirectories, selectsFiles, isSave,
  46655. warnAboutOverwritingExistingFiles,
  46656. selectMultipleFiles,
  46657. previewComponent);
  46658. }
  46659. else
  46660. {
  46661. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46662. selectsDirectories ? "*" : String::empty,
  46663. String::empty);
  46664. int flags = isSave ? FileBrowserComponent::saveMode
  46665. : FileBrowserComponent::openMode;
  46666. if (selectsFiles)
  46667. flags |= FileBrowserComponent::canSelectFiles;
  46668. if (selectsDirectories)
  46669. flags |= FileBrowserComponent::canSelectDirectories;
  46670. if (selectMultipleFiles)
  46671. flags |= FileBrowserComponent::canSelectMultipleItems;
  46672. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46673. FileChooserDialogBox box (title, String::empty,
  46674. browserComponent,
  46675. warnAboutOverwritingExistingFiles,
  46676. browserComponent.findColour (AlertWindow::backgroundColourId));
  46677. if (box.show())
  46678. {
  46679. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46680. results.add (browserComponent.getSelectedFile (i));
  46681. }
  46682. }
  46683. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46684. currentlyFocused->grabKeyboardFocus();
  46685. return results.size() > 0;
  46686. }
  46687. FilePreviewComponent::FilePreviewComponent()
  46688. {
  46689. }
  46690. FilePreviewComponent::~FilePreviewComponent()
  46691. {
  46692. }
  46693. END_JUCE_NAMESPACE
  46694. /*** End of inlined file: juce_FileChooser.cpp ***/
  46695. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46696. BEGIN_JUCE_NAMESPACE
  46697. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46698. const String& instructions,
  46699. FileBrowserComponent& chooserComponent,
  46700. const bool warnAboutOverwritingExistingFiles_,
  46701. const Colour& backgroundColour)
  46702. : ResizableWindow (name, backgroundColour, true),
  46703. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46704. {
  46705. content = new ContentComponent();
  46706. content->setName (name);
  46707. content->instructions = instructions;
  46708. content->chooserComponent = &chooserComponent;
  46709. content->addAndMakeVisible (&chooserComponent);
  46710. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46711. content->addAndMakeVisible (content->okButton);
  46712. content->okButton->addButtonListener (this);
  46713. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46714. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46715. content->cancelButton = new TextButton (TRANS("Cancel"));
  46716. content->addAndMakeVisible (content->cancelButton);
  46717. content->cancelButton->addButtonListener (this);
  46718. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46719. setContentComponent (content);
  46720. setResizable (true, true);
  46721. setResizeLimits (300, 300, 1200, 1000);
  46722. content->chooserComponent->addListener (this);
  46723. }
  46724. FileChooserDialogBox::~FileChooserDialogBox()
  46725. {
  46726. content->chooserComponent->removeListener (this);
  46727. }
  46728. bool FileChooserDialogBox::show (int w, int h)
  46729. {
  46730. if (w <= 0)
  46731. {
  46732. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46733. if (previewComp != 0)
  46734. w = 400 + previewComp->getWidth();
  46735. else
  46736. w = 600;
  46737. }
  46738. if (h <= 0)
  46739. h = 500;
  46740. centreWithSize (w, h);
  46741. const bool ok = (runModalLoop() != 0);
  46742. setVisible (false);
  46743. return ok;
  46744. }
  46745. void FileChooserDialogBox::buttonClicked (Button* button)
  46746. {
  46747. if (button == content->okButton)
  46748. {
  46749. if (warnAboutOverwritingExistingFiles
  46750. && content->chooserComponent->isSaveMode()
  46751. && content->chooserComponent->getSelectedFile(0).exists())
  46752. {
  46753. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46754. TRANS("File already exists"),
  46755. TRANS("There's already a file called:\n\n")
  46756. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46757. + T("\n\nAre you sure you want to overwrite it?"),
  46758. TRANS("overwrite"),
  46759. TRANS("cancel")))
  46760. {
  46761. return;
  46762. }
  46763. }
  46764. exitModalState (1);
  46765. }
  46766. else if (button == content->cancelButton)
  46767. closeButtonPressed();
  46768. }
  46769. void FileChooserDialogBox::closeButtonPressed()
  46770. {
  46771. setVisible (false);
  46772. }
  46773. void FileChooserDialogBox::selectionChanged()
  46774. {
  46775. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46776. }
  46777. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46778. {
  46779. }
  46780. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46781. {
  46782. selectionChanged();
  46783. content->okButton->triggerClick();
  46784. }
  46785. FileChooserDialogBox::ContentComponent::ContentComponent()
  46786. {
  46787. setInterceptsMouseClicks (false, true);
  46788. }
  46789. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46790. {
  46791. delete okButton;
  46792. delete cancelButton;
  46793. }
  46794. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46795. {
  46796. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46797. text.draw (g);
  46798. }
  46799. void FileChooserDialogBox::ContentComponent::resized()
  46800. {
  46801. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46802. float left, top, right, bottom;
  46803. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46804. const int y = roundToInt (bottom) + 10;
  46805. const int buttonHeight = 26;
  46806. const int buttonY = getHeight() - buttonHeight - 8;
  46807. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46808. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46809. proportionOfWidth (0.2f), buttonHeight);
  46810. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46811. proportionOfWidth (0.2f), buttonHeight);
  46812. }
  46813. END_JUCE_NAMESPACE
  46814. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46815. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46816. BEGIN_JUCE_NAMESPACE
  46817. FileFilter::FileFilter (const String& filterDescription)
  46818. : description (filterDescription)
  46819. {
  46820. }
  46821. FileFilter::~FileFilter()
  46822. {
  46823. }
  46824. const String& FileFilter::getDescription() const throw()
  46825. {
  46826. return description;
  46827. }
  46828. END_JUCE_NAMESPACE
  46829. /*** End of inlined file: juce_FileFilter.cpp ***/
  46830. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46831. BEGIN_JUCE_NAMESPACE
  46832. Image* juce_createIconForFile (const File& file);
  46833. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46834. : ListBox (String::empty, 0),
  46835. DirectoryContentsDisplayComponent (listToShow)
  46836. {
  46837. setModel (this);
  46838. fileList.addChangeListener (this);
  46839. }
  46840. FileListComponent::~FileListComponent()
  46841. {
  46842. fileList.removeChangeListener (this);
  46843. deleteAllChildren();
  46844. }
  46845. int FileListComponent::getNumSelectedFiles() const
  46846. {
  46847. return getNumSelectedRows();
  46848. }
  46849. const File FileListComponent::getSelectedFile (int index) const
  46850. {
  46851. return fileList.getFile (getSelectedRow (index));
  46852. }
  46853. void FileListComponent::scrollToTop()
  46854. {
  46855. getVerticalScrollBar()->setCurrentRangeStart (0);
  46856. }
  46857. void FileListComponent::changeListenerCallback (void*)
  46858. {
  46859. updateContent();
  46860. if (lastDirectory != fileList.getDirectory())
  46861. {
  46862. lastDirectory = fileList.getDirectory();
  46863. deselectAllRows();
  46864. }
  46865. }
  46866. class FileListItemComponent : public Component,
  46867. public TimeSliceClient,
  46868. public AsyncUpdater
  46869. {
  46870. public:
  46871. FileListItemComponent (FileListComponent& owner_,
  46872. TimeSliceThread& thread_) throw()
  46873. : owner (owner_),
  46874. thread (thread_),
  46875. icon (0)
  46876. {
  46877. }
  46878. ~FileListItemComponent() throw()
  46879. {
  46880. thread.removeTimeSliceClient (this);
  46881. clearIcon();
  46882. }
  46883. void paint (Graphics& g)
  46884. {
  46885. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46886. file.getFileName(),
  46887. icon,
  46888. fileSize, modTime,
  46889. isDirectory, highlighted,
  46890. index);
  46891. }
  46892. void mouseDown (const MouseEvent& e)
  46893. {
  46894. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46895. owner.sendMouseClickMessage (file, e);
  46896. }
  46897. void mouseDoubleClick (const MouseEvent&)
  46898. {
  46899. owner.sendDoubleClickMessage (file);
  46900. }
  46901. void update (const File& root,
  46902. const DirectoryContentsList::FileInfo* const fileInfo,
  46903. const int index_,
  46904. const bool highlighted_) throw()
  46905. {
  46906. thread.removeTimeSliceClient (this);
  46907. if (highlighted_ != highlighted
  46908. || index_ != index)
  46909. {
  46910. index = index_;
  46911. highlighted = highlighted_;
  46912. repaint();
  46913. }
  46914. File newFile;
  46915. String newFileSize;
  46916. String newModTime;
  46917. if (fileInfo != 0)
  46918. {
  46919. newFile = root.getChildFile (fileInfo->filename);
  46920. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46921. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46922. }
  46923. if (newFile != file
  46924. || fileSize != newFileSize
  46925. || modTime != newModTime)
  46926. {
  46927. file = newFile;
  46928. fileSize = newFileSize;
  46929. modTime = newModTime;
  46930. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46931. repaint();
  46932. clearIcon();
  46933. }
  46934. if (file != File::nonexistent
  46935. && icon == 0 && ! isDirectory)
  46936. {
  46937. updateIcon (true);
  46938. if (icon == 0)
  46939. thread.addTimeSliceClient (this);
  46940. }
  46941. }
  46942. bool useTimeSlice()
  46943. {
  46944. updateIcon (false);
  46945. return false;
  46946. }
  46947. void handleAsyncUpdate()
  46948. {
  46949. repaint();
  46950. }
  46951. juce_UseDebuggingNewOperator
  46952. private:
  46953. FileListComponent& owner;
  46954. TimeSliceThread& thread;
  46955. bool highlighted;
  46956. int index;
  46957. File file;
  46958. String fileSize;
  46959. String modTime;
  46960. Image* icon;
  46961. bool isDirectory;
  46962. void clearIcon() throw()
  46963. {
  46964. ImageCache::release (icon);
  46965. icon = 0;
  46966. }
  46967. void updateIcon (const bool onlyUpdateIfCached) throw()
  46968. {
  46969. if (icon == 0)
  46970. {
  46971. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46972. Image* im = ImageCache::getFromHashCode (hashCode);
  46973. if (im == 0 && ! onlyUpdateIfCached)
  46974. {
  46975. im = juce_createIconForFile (file);
  46976. if (im != 0)
  46977. ImageCache::addImageToCache (im, hashCode);
  46978. }
  46979. if (im != 0)
  46980. {
  46981. icon = im;
  46982. triggerAsyncUpdate();
  46983. }
  46984. }
  46985. }
  46986. };
  46987. int FileListComponent::getNumRows()
  46988. {
  46989. return fileList.getNumFiles();
  46990. }
  46991. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46992. {
  46993. }
  46994. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46995. {
  46996. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46997. if (comp == 0)
  46998. {
  46999. delete existingComponentToUpdate;
  47000. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  47001. }
  47002. DirectoryContentsList::FileInfo fileInfo;
  47003. if (fileList.getFileInfo (row, fileInfo))
  47004. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  47005. else
  47006. comp->update (fileList.getDirectory(), 0, row, isSelected);
  47007. return comp;
  47008. }
  47009. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  47010. {
  47011. sendSelectionChangeMessage();
  47012. }
  47013. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  47014. {
  47015. }
  47016. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  47017. {
  47018. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  47019. }
  47020. END_JUCE_NAMESPACE
  47021. /*** End of inlined file: juce_FileListComponent.cpp ***/
  47022. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  47023. BEGIN_JUCE_NAMESPACE
  47024. FilenameComponent::FilenameComponent (const String& name,
  47025. const File& currentFile,
  47026. const bool canEditFilename,
  47027. const bool isDirectory,
  47028. const bool isForSaving,
  47029. const String& fileBrowserWildcard,
  47030. const String& enforcedSuffix_,
  47031. const String& textWhenNothingSelected)
  47032. : Component (name),
  47033. maxRecentFiles (30),
  47034. isDir (isDirectory),
  47035. isSaving (isForSaving),
  47036. isFileDragOver (false),
  47037. wildcard (fileBrowserWildcard),
  47038. enforcedSuffix (enforcedSuffix_)
  47039. {
  47040. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  47041. filenameBox->setEditableText (canEditFilename);
  47042. filenameBox->addListener (this);
  47043. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  47044. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  47045. browseButton = 0;
  47046. setBrowseButtonText (T("..."));
  47047. setCurrentFile (currentFile, true);
  47048. }
  47049. FilenameComponent::~FilenameComponent()
  47050. {
  47051. deleteAllChildren();
  47052. }
  47053. void FilenameComponent::paintOverChildren (Graphics& g)
  47054. {
  47055. if (isFileDragOver)
  47056. {
  47057. g.setColour (Colours::red.withAlpha (0.2f));
  47058. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  47059. }
  47060. }
  47061. void FilenameComponent::resized()
  47062. {
  47063. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  47064. }
  47065. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  47066. {
  47067. browseButtonText = newBrowseButtonText;
  47068. lookAndFeelChanged();
  47069. }
  47070. void FilenameComponent::lookAndFeelChanged()
  47071. {
  47072. deleteAndZero (browseButton);
  47073. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  47074. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  47075. resized();
  47076. browseButton->addButtonListener (this);
  47077. }
  47078. void FilenameComponent::setTooltip (const String& newTooltip)
  47079. {
  47080. SettableTooltipClient::setTooltip (newTooltip);
  47081. filenameBox->setTooltip (newTooltip);
  47082. }
  47083. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47084. {
  47085. defaultBrowseFile = newDefaultDirectory;
  47086. }
  47087. void FilenameComponent::buttonClicked (Button*)
  47088. {
  47089. FileChooser fc (TRANS("Choose a new file"),
  47090. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  47091. : getCurrentFile(),
  47092. wildcard);
  47093. if (isDir ? fc.browseForDirectory()
  47094. : (isSaving ? fc.browseForFileToSave (false)
  47095. : fc.browseForFileToOpen()))
  47096. {
  47097. setCurrentFile (fc.getResult(), true);
  47098. }
  47099. }
  47100. void FilenameComponent::comboBoxChanged (ComboBox*)
  47101. {
  47102. setCurrentFile (getCurrentFile(), true);
  47103. }
  47104. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  47105. {
  47106. return true;
  47107. }
  47108. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  47109. {
  47110. isFileDragOver = false;
  47111. repaint();
  47112. const File f (filenames[0]);
  47113. if (f.exists() && (f.isDirectory() == isDir))
  47114. setCurrentFile (f, true);
  47115. }
  47116. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  47117. {
  47118. isFileDragOver = true;
  47119. repaint();
  47120. }
  47121. void FilenameComponent::fileDragExit (const StringArray&)
  47122. {
  47123. isFileDragOver = false;
  47124. repaint();
  47125. }
  47126. const File FilenameComponent::getCurrentFile() const
  47127. {
  47128. File f (filenameBox->getText());
  47129. if (enforcedSuffix.isNotEmpty())
  47130. f = f.withFileExtension (enforcedSuffix);
  47131. return f;
  47132. }
  47133. void FilenameComponent::setCurrentFile (File newFile,
  47134. const bool addToRecentlyUsedList,
  47135. const bool sendChangeNotification)
  47136. {
  47137. if (enforcedSuffix.isNotEmpty())
  47138. newFile = newFile.withFileExtension (enforcedSuffix);
  47139. if (newFile.getFullPathName() != lastFilename)
  47140. {
  47141. lastFilename = newFile.getFullPathName();
  47142. if (addToRecentlyUsedList)
  47143. addRecentlyUsedFile (newFile);
  47144. filenameBox->setText (lastFilename, true);
  47145. if (sendChangeNotification)
  47146. triggerAsyncUpdate();
  47147. }
  47148. }
  47149. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47150. {
  47151. filenameBox->setEditableText (shouldBeEditable);
  47152. }
  47153. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47154. {
  47155. StringArray names;
  47156. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47157. names.add (filenameBox->getItemText (i));
  47158. return names;
  47159. }
  47160. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47161. {
  47162. if (filenames != getRecentlyUsedFilenames())
  47163. {
  47164. filenameBox->clear();
  47165. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47166. filenameBox->addItem (filenames[i], i + 1);
  47167. }
  47168. }
  47169. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47170. {
  47171. maxRecentFiles = jmax (1, newMaximum);
  47172. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47173. }
  47174. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47175. {
  47176. StringArray files (getRecentlyUsedFilenames());
  47177. if (file.getFullPathName().isNotEmpty())
  47178. {
  47179. files.removeString (file.getFullPathName(), true);
  47180. files.insert (0, file.getFullPathName());
  47181. setRecentlyUsedFilenames (files);
  47182. }
  47183. }
  47184. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47185. {
  47186. jassert (listener != 0);
  47187. if (listener != 0)
  47188. listeners.add (listener);
  47189. }
  47190. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47191. {
  47192. listeners.removeValue (listener);
  47193. }
  47194. void FilenameComponent::handleAsyncUpdate()
  47195. {
  47196. for (int i = listeners.size(); --i >= 0;)
  47197. {
  47198. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47199. i = jmin (i, listeners.size());
  47200. }
  47201. }
  47202. END_JUCE_NAMESPACE
  47203. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  47204. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47205. BEGIN_JUCE_NAMESPACE
  47206. FileSearchPathListComponent::FileSearchPathListComponent()
  47207. {
  47208. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47209. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47210. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47211. listBox->setOutlineThickness (1);
  47212. addAndMakeVisible (addButton = new TextButton ("+"));
  47213. addButton->addButtonListener (this);
  47214. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47215. addAndMakeVisible (removeButton = new TextButton ("-"));
  47216. removeButton->addButtonListener (this);
  47217. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47218. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47219. changeButton->addButtonListener (this);
  47220. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47221. upButton->addButtonListener (this);
  47222. {
  47223. Path arrowPath;
  47224. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47225. DrawablePath arrowImage;
  47226. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47227. arrowImage.setPath (arrowPath);
  47228. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47229. }
  47230. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47231. downButton->addButtonListener (this);
  47232. {
  47233. Path arrowPath;
  47234. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47235. DrawablePath arrowImage;
  47236. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47237. arrowImage.setPath (arrowPath);
  47238. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47239. }
  47240. updateButtons();
  47241. }
  47242. FileSearchPathListComponent::~FileSearchPathListComponent()
  47243. {
  47244. deleteAllChildren();
  47245. }
  47246. void FileSearchPathListComponent::updateButtons() throw()
  47247. {
  47248. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47249. removeButton->setEnabled (anythingSelected);
  47250. changeButton->setEnabled (anythingSelected);
  47251. upButton->setEnabled (anythingSelected);
  47252. downButton->setEnabled (anythingSelected);
  47253. }
  47254. void FileSearchPathListComponent::changed() throw()
  47255. {
  47256. listBox->updateContent();
  47257. listBox->repaint();
  47258. updateButtons();
  47259. }
  47260. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47261. {
  47262. if (newPath.toString() != path.toString())
  47263. {
  47264. path = newPath;
  47265. changed();
  47266. }
  47267. }
  47268. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47269. {
  47270. defaultBrowseTarget = newDefaultDirectory;
  47271. }
  47272. int FileSearchPathListComponent::getNumRows()
  47273. {
  47274. return path.getNumPaths();
  47275. }
  47276. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47277. {
  47278. if (rowIsSelected)
  47279. g.fillAll (findColour (TextEditor::highlightColourId));
  47280. g.setColour (findColour (ListBox::textColourId));
  47281. Font f (height * 0.7f);
  47282. f.setHorizontalScale (0.9f);
  47283. g.setFont (f);
  47284. g.drawText (path [rowNumber].getFullPathName(),
  47285. 4, 0, width - 6, height,
  47286. Justification::centredLeft, true);
  47287. }
  47288. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47289. {
  47290. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47291. {
  47292. path.remove (row);
  47293. changed();
  47294. }
  47295. }
  47296. void FileSearchPathListComponent::returnKeyPressed (int row)
  47297. {
  47298. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47299. if (chooser.browseForDirectory())
  47300. {
  47301. path.remove (row);
  47302. path.add (chooser.getResult(), row);
  47303. changed();
  47304. }
  47305. }
  47306. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47307. {
  47308. returnKeyPressed (row);
  47309. }
  47310. void FileSearchPathListComponent::selectedRowsChanged (int)
  47311. {
  47312. updateButtons();
  47313. }
  47314. void FileSearchPathListComponent::paint (Graphics& g)
  47315. {
  47316. g.fillAll (findColour (backgroundColourId));
  47317. }
  47318. void FileSearchPathListComponent::resized()
  47319. {
  47320. const int buttonH = 22;
  47321. const int buttonY = getHeight() - buttonH - 4;
  47322. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47323. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47324. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47325. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47326. downButton->setSize (buttonH * 2, buttonH);
  47327. upButton->setSize (buttonH * 2, buttonH);
  47328. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47329. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47330. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47331. }
  47332. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47333. {
  47334. return true;
  47335. }
  47336. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47337. {
  47338. for (int i = filenames.size(); --i >= 0;)
  47339. {
  47340. const File f (filenames[i]);
  47341. if (f.isDirectory())
  47342. {
  47343. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47344. path.add (f, row);
  47345. changed();
  47346. }
  47347. }
  47348. }
  47349. void FileSearchPathListComponent::buttonClicked (Button* button)
  47350. {
  47351. const int currentRow = listBox->getSelectedRow();
  47352. if (button == removeButton)
  47353. {
  47354. deleteKeyPressed (currentRow);
  47355. }
  47356. else if (button == addButton)
  47357. {
  47358. File start (defaultBrowseTarget);
  47359. if (start == File::nonexistent)
  47360. start = path [0];
  47361. if (start == File::nonexistent)
  47362. start = File::getCurrentWorkingDirectory();
  47363. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47364. if (chooser.browseForDirectory())
  47365. {
  47366. path.add (chooser.getResult(), currentRow);
  47367. }
  47368. }
  47369. else if (button == changeButton)
  47370. {
  47371. returnKeyPressed (currentRow);
  47372. }
  47373. else if (button == upButton)
  47374. {
  47375. if (currentRow > 0 && currentRow < path.getNumPaths())
  47376. {
  47377. const File f (path[currentRow]);
  47378. path.remove (currentRow);
  47379. path.add (f, currentRow - 1);
  47380. listBox->selectRow (currentRow - 1);
  47381. }
  47382. }
  47383. else if (button == downButton)
  47384. {
  47385. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47386. {
  47387. const File f (path[currentRow]);
  47388. path.remove (currentRow);
  47389. path.add (f, currentRow + 1);
  47390. listBox->selectRow (currentRow + 1);
  47391. }
  47392. }
  47393. changed();
  47394. }
  47395. END_JUCE_NAMESPACE
  47396. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47397. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  47398. BEGIN_JUCE_NAMESPACE
  47399. Image* juce_createIconForFile (const File& file);
  47400. class FileListTreeItem : public TreeViewItem,
  47401. public TimeSliceClient,
  47402. public AsyncUpdater,
  47403. public ChangeListener
  47404. {
  47405. public:
  47406. FileListTreeItem (FileTreeComponent& owner_,
  47407. DirectoryContentsList* const parentContentsList_,
  47408. const int indexInContentsList_,
  47409. const File& file_,
  47410. TimeSliceThread& thread_) throw()
  47411. : file (file_),
  47412. owner (owner_),
  47413. parentContentsList (parentContentsList_),
  47414. indexInContentsList (indexInContentsList_),
  47415. subContentsList (0),
  47416. canDeleteSubContentsList (false),
  47417. thread (thread_),
  47418. icon (0)
  47419. {
  47420. DirectoryContentsList::FileInfo fileInfo;
  47421. if (parentContentsList_ != 0
  47422. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47423. {
  47424. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47425. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47426. isDirectory = fileInfo.isDirectory;
  47427. }
  47428. else
  47429. {
  47430. isDirectory = true;
  47431. }
  47432. }
  47433. ~FileListTreeItem() throw()
  47434. {
  47435. thread.removeTimeSliceClient (this);
  47436. clearSubItems();
  47437. ImageCache::release (icon);
  47438. if (canDeleteSubContentsList)
  47439. delete subContentsList;
  47440. }
  47441. bool mightContainSubItems() { return isDirectory; }
  47442. const String getUniqueName() const { return file.getFullPathName(); }
  47443. int getItemHeight() const { return 22; }
  47444. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47445. void itemOpennessChanged (bool isNowOpen)
  47446. {
  47447. if (isNowOpen)
  47448. {
  47449. clearSubItems();
  47450. isDirectory = file.isDirectory();
  47451. if (isDirectory)
  47452. {
  47453. if (subContentsList == 0)
  47454. {
  47455. jassert (parentContentsList != 0);
  47456. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47457. l->setDirectory (file, true, true);
  47458. setSubContentsList (l);
  47459. canDeleteSubContentsList = true;
  47460. }
  47461. changeListenerCallback (0);
  47462. }
  47463. }
  47464. }
  47465. void setSubContentsList (DirectoryContentsList* newList) throw()
  47466. {
  47467. jassert (subContentsList == 0);
  47468. subContentsList = newList;
  47469. newList->addChangeListener (this);
  47470. }
  47471. void changeListenerCallback (void*)
  47472. {
  47473. clearSubItems();
  47474. if (isOpen() && subContentsList != 0)
  47475. {
  47476. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47477. {
  47478. FileListTreeItem* const item
  47479. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47480. addSubItem (item);
  47481. }
  47482. }
  47483. }
  47484. void paintItem (Graphics& g, int width, int height)
  47485. {
  47486. if (file != File::nonexistent)
  47487. {
  47488. updateIcon (true);
  47489. if (icon == 0)
  47490. thread.addTimeSliceClient (this);
  47491. }
  47492. owner.getLookAndFeel()
  47493. .drawFileBrowserRow (g, width, height,
  47494. file.getFileName(),
  47495. icon,
  47496. fileSize, modTime,
  47497. isDirectory, isSelected(),
  47498. indexInContentsList);
  47499. }
  47500. void itemClicked (const MouseEvent& e)
  47501. {
  47502. owner.sendMouseClickMessage (file, e);
  47503. }
  47504. void itemDoubleClicked (const MouseEvent& e)
  47505. {
  47506. TreeViewItem::itemDoubleClicked (e);
  47507. owner.sendDoubleClickMessage (file);
  47508. }
  47509. void itemSelectionChanged (bool)
  47510. {
  47511. owner.sendSelectionChangeMessage();
  47512. }
  47513. bool useTimeSlice()
  47514. {
  47515. updateIcon (false);
  47516. thread.removeTimeSliceClient (this);
  47517. return false;
  47518. }
  47519. void handleAsyncUpdate()
  47520. {
  47521. owner.repaint();
  47522. }
  47523. const File file;
  47524. juce_UseDebuggingNewOperator
  47525. private:
  47526. FileTreeComponent& owner;
  47527. DirectoryContentsList* parentContentsList;
  47528. int indexInContentsList;
  47529. DirectoryContentsList* subContentsList;
  47530. bool isDirectory, canDeleteSubContentsList;
  47531. TimeSliceThread& thread;
  47532. Image* icon;
  47533. String fileSize;
  47534. String modTime;
  47535. void updateIcon (const bool onlyUpdateIfCached) throw()
  47536. {
  47537. if (icon == 0)
  47538. {
  47539. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47540. Image* im = ImageCache::getFromHashCode (hashCode);
  47541. if (im == 0 && ! onlyUpdateIfCached)
  47542. {
  47543. im = juce_createIconForFile (file);
  47544. if (im != 0)
  47545. ImageCache::addImageToCache (im, hashCode);
  47546. }
  47547. if (im != 0)
  47548. {
  47549. icon = im;
  47550. triggerAsyncUpdate();
  47551. }
  47552. }
  47553. }
  47554. };
  47555. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47556. : DirectoryContentsDisplayComponent (listToShow)
  47557. {
  47558. FileListTreeItem* const root
  47559. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47560. listToShow.getTimeSliceThread());
  47561. root->setSubContentsList (&listToShow);
  47562. setRootItemVisible (false);
  47563. setRootItem (root);
  47564. }
  47565. FileTreeComponent::~FileTreeComponent()
  47566. {
  47567. deleteRootItem();
  47568. }
  47569. const File FileTreeComponent::getSelectedFile (const int index) const
  47570. {
  47571. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47572. if (item != 0)
  47573. return item->file;
  47574. return File::nonexistent;
  47575. }
  47576. void FileTreeComponent::scrollToTop()
  47577. {
  47578. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47579. }
  47580. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47581. {
  47582. dragAndDropDescription = description;
  47583. }
  47584. END_JUCE_NAMESPACE
  47585. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47586. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47587. BEGIN_JUCE_NAMESPACE
  47588. ImagePreviewComponent::ImagePreviewComponent()
  47589. {
  47590. }
  47591. ImagePreviewComponent::~ImagePreviewComponent()
  47592. {
  47593. }
  47594. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47595. {
  47596. const int availableW = proportionOfWidth (0.97f);
  47597. const int availableH = getHeight() - 13 * 4;
  47598. const double scale = jmin (1.0,
  47599. availableW / (double) w,
  47600. availableH / (double) h);
  47601. w = roundToInt (scale * w);
  47602. h = roundToInt (scale * h);
  47603. }
  47604. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47605. {
  47606. if (fileToLoad != file)
  47607. {
  47608. fileToLoad = file;
  47609. startTimer (100);
  47610. }
  47611. }
  47612. void ImagePreviewComponent::timerCallback()
  47613. {
  47614. stopTimer();
  47615. currentThumbnail = 0;
  47616. currentDetails = String::empty;
  47617. repaint();
  47618. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47619. if (in != 0)
  47620. {
  47621. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47622. if (format != 0)
  47623. {
  47624. currentThumbnail = format->decodeImage (*in);
  47625. if (currentThumbnail != 0)
  47626. {
  47627. int w = currentThumbnail->getWidth();
  47628. int h = currentThumbnail->getHeight();
  47629. currentDetails
  47630. << fileToLoad.getFileName() << "\n"
  47631. << format->getFormatName() << "\n"
  47632. << w << " x " << h << " pixels\n"
  47633. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47634. getThumbSize (w, h);
  47635. currentThumbnail = currentThumbnail->createCopy (w, h);
  47636. }
  47637. }
  47638. }
  47639. }
  47640. void ImagePreviewComponent::paint (Graphics& g)
  47641. {
  47642. if (currentThumbnail != 0)
  47643. {
  47644. g.setFont (13.0f);
  47645. int w = currentThumbnail->getWidth();
  47646. int h = currentThumbnail->getHeight();
  47647. getThumbSize (w, h);
  47648. const int numLines = 4;
  47649. const int totalH = 13 * numLines + h + 4;
  47650. const int y = (getHeight() - totalH) / 2;
  47651. g.drawImageWithin (currentThumbnail,
  47652. (getWidth() - w) / 2, y, w, h,
  47653. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47654. false);
  47655. g.drawFittedText (currentDetails,
  47656. 0, y + h + 4, getWidth(), 100,
  47657. Justification::centredTop, numLines);
  47658. }
  47659. }
  47660. END_JUCE_NAMESPACE
  47661. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47662. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47663. BEGIN_JUCE_NAMESPACE
  47664. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47665. const String& directoryWildcardPatterns,
  47666. const String& description_)
  47667. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47668. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47669. {
  47670. parse (fileWildcardPatterns, fileWildcards);
  47671. parse (directoryWildcardPatterns, directoryWildcards);
  47672. }
  47673. WildcardFileFilter::~WildcardFileFilter()
  47674. {
  47675. }
  47676. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47677. {
  47678. return match (file, fileWildcards);
  47679. }
  47680. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47681. {
  47682. return match (file, directoryWildcards);
  47683. }
  47684. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47685. {
  47686. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47687. result.trim();
  47688. result.removeEmptyStrings();
  47689. // special case for *.*, because people use it to mean "any file", but it
  47690. // would actually ignore files with no extension.
  47691. for (int i = result.size(); --i >= 0;)
  47692. if (result[i] == T("*.*"))
  47693. result.set (i, T("*"));
  47694. }
  47695. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47696. {
  47697. const String filename (file.getFileName());
  47698. for (int i = wildcards.size(); --i >= 0;)
  47699. if (filename.matchesWildcard (wildcards[i], true))
  47700. return true;
  47701. return false;
  47702. }
  47703. END_JUCE_NAMESPACE
  47704. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47705. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47706. BEGIN_JUCE_NAMESPACE
  47707. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47708. {
  47709. }
  47710. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47711. {
  47712. }
  47713. // This will sort a set of components, so that they are ordered in terms of
  47714. // left-to-right and then top-to-bottom.
  47715. class ScreenPositionComparator
  47716. {
  47717. public:
  47718. ScreenPositionComparator() {}
  47719. static int compareElements (const Component* const first, const Component* const second) throw()
  47720. {
  47721. int explicitOrder1 = first->getExplicitFocusOrder();
  47722. if (explicitOrder1 <= 0)
  47723. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47724. int explicitOrder2 = second->getExplicitFocusOrder();
  47725. if (explicitOrder2 <= 0)
  47726. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47727. if (explicitOrder1 != explicitOrder2)
  47728. return explicitOrder1 - explicitOrder2;
  47729. const int diff = first->getY() - second->getY();
  47730. return (diff == 0) ? first->getX() - second->getX()
  47731. : diff;
  47732. }
  47733. };
  47734. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47735. {
  47736. if (parent->getNumChildComponents() > 0)
  47737. {
  47738. Array <Component*> localComps;
  47739. ScreenPositionComparator comparator;
  47740. int i;
  47741. for (i = parent->getNumChildComponents(); --i >= 0;)
  47742. {
  47743. Component* const c = parent->getChildComponent (i);
  47744. if (c->isVisible() && c->isEnabled())
  47745. localComps.addSorted (comparator, c);
  47746. }
  47747. for (i = 0; i < localComps.size(); ++i)
  47748. {
  47749. Component* const c = localComps.getUnchecked (i);
  47750. if (c->getWantsKeyboardFocus())
  47751. comps.add (c);
  47752. if (! c->isFocusContainer())
  47753. findAllFocusableComponents (c, comps);
  47754. }
  47755. }
  47756. }
  47757. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47758. {
  47759. Component* focusContainer = current->getParentComponent();
  47760. if (focusContainer != 0)
  47761. {
  47762. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47763. focusContainer = focusContainer->getParentComponent();
  47764. if (focusContainer != 0)
  47765. {
  47766. Array <Component*> comps;
  47767. findAllFocusableComponents (focusContainer, comps);
  47768. if (comps.size() > 0)
  47769. {
  47770. const int index = comps.indexOf (current);
  47771. return comps [(index + comps.size() + delta) % comps.size()];
  47772. }
  47773. }
  47774. }
  47775. return 0;
  47776. }
  47777. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47778. {
  47779. return getIncrementedComponent (current, 1);
  47780. }
  47781. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47782. {
  47783. return getIncrementedComponent (current, -1);
  47784. }
  47785. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47786. {
  47787. Array <Component*> comps;
  47788. if (parentComponent != 0)
  47789. findAllFocusableComponents (parentComponent, comps);
  47790. return comps.getFirst();
  47791. }
  47792. END_JUCE_NAMESPACE
  47793. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47794. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47795. BEGIN_JUCE_NAMESPACE
  47796. bool KeyListener::keyStateChanged (const bool, Component*)
  47797. {
  47798. return false;
  47799. }
  47800. END_JUCE_NAMESPACE
  47801. /*** End of inlined file: juce_KeyListener.cpp ***/
  47802. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47803. BEGIN_JUCE_NAMESPACE
  47804. // N.B. these two includes are put here deliberately to avoid problems with
  47805. // old GCCs failing on long include paths
  47806. const int maxKeys = 3;
  47807. class KeyMappingChangeButton : public Button
  47808. {
  47809. public:
  47810. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47811. const CommandID commandID_,
  47812. const String& keyName,
  47813. const int keyNum_)
  47814. : Button (keyName),
  47815. owner (owner_),
  47816. commandID (commandID_),
  47817. keyNum (keyNum_)
  47818. {
  47819. setWantsKeyboardFocus (false);
  47820. setTriggeredOnMouseDown (keyNum >= 0);
  47821. if (keyNum_ < 0)
  47822. setTooltip (TRANS("adds a new key-mapping"));
  47823. else
  47824. setTooltip (TRANS("click to change this key-mapping"));
  47825. }
  47826. ~KeyMappingChangeButton()
  47827. {
  47828. }
  47829. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47830. {
  47831. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47832. keyNum >= 0 ? getName() : String::empty);
  47833. }
  47834. void clicked()
  47835. {
  47836. if (keyNum >= 0)
  47837. {
  47838. // existing key clicked..
  47839. PopupMenu m;
  47840. m.addItem (1, TRANS("change this key-mapping"));
  47841. m.addSeparator();
  47842. m.addItem (2, TRANS("remove this key-mapping"));
  47843. const int res = m.show();
  47844. if (res == 1)
  47845. {
  47846. owner->assignNewKey (commandID, keyNum);
  47847. }
  47848. else if (res == 2)
  47849. {
  47850. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47851. }
  47852. }
  47853. else
  47854. {
  47855. // + button pressed..
  47856. owner->assignNewKey (commandID, -1);
  47857. }
  47858. }
  47859. void fitToContent (const int h) throw()
  47860. {
  47861. if (keyNum < 0)
  47862. {
  47863. setSize (h, h);
  47864. }
  47865. else
  47866. {
  47867. Font f (h * 0.6f);
  47868. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47869. }
  47870. }
  47871. juce_UseDebuggingNewOperator
  47872. private:
  47873. KeyMappingEditorComponent* const owner;
  47874. const CommandID commandID;
  47875. const int keyNum;
  47876. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47877. const KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47878. };
  47879. class KeyMappingItemComponent : public Component
  47880. {
  47881. public:
  47882. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47883. const CommandID commandID_)
  47884. : owner (owner_),
  47885. commandID (commandID_)
  47886. {
  47887. setInterceptsMouseClicks (false, true);
  47888. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47889. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47890. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47891. {
  47892. KeyMappingChangeButton* const kb
  47893. = new KeyMappingChangeButton (owner_, commandID,
  47894. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47895. kb->setEnabled (! isReadOnly);
  47896. addAndMakeVisible (kb);
  47897. }
  47898. KeyMappingChangeButton* const kb
  47899. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47900. addChildComponent (kb);
  47901. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47902. }
  47903. ~KeyMappingItemComponent()
  47904. {
  47905. deleteAllChildren();
  47906. }
  47907. void paint (Graphics& g)
  47908. {
  47909. g.setFont (getHeight() * 0.7f);
  47910. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47911. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47912. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47913. Justification::centredLeft, true);
  47914. }
  47915. void resized()
  47916. {
  47917. int x = getWidth() - 4;
  47918. for (int i = getNumChildComponents(); --i >= 0;)
  47919. {
  47920. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47921. kb->fitToContent (getHeight() - 2);
  47922. kb->setTopRightPosition (x, 1);
  47923. x -= kb->getWidth() + 5;
  47924. }
  47925. }
  47926. juce_UseDebuggingNewOperator
  47927. private:
  47928. KeyMappingEditorComponent* const owner;
  47929. const CommandID commandID;
  47930. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47931. const KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47932. };
  47933. class KeyMappingTreeViewItem : public TreeViewItem
  47934. {
  47935. public:
  47936. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47937. const CommandID commandID_)
  47938. : owner (owner_),
  47939. commandID (commandID_)
  47940. {
  47941. }
  47942. ~KeyMappingTreeViewItem()
  47943. {
  47944. }
  47945. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47946. bool mightContainSubItems() { return false; }
  47947. int getItemHeight() const { return 20; }
  47948. Component* createItemComponent()
  47949. {
  47950. return new KeyMappingItemComponent (owner, commandID);
  47951. }
  47952. juce_UseDebuggingNewOperator
  47953. private:
  47954. KeyMappingEditorComponent* const owner;
  47955. const CommandID commandID;
  47956. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47957. const KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47958. };
  47959. class KeyCategoryTreeViewItem : public TreeViewItem
  47960. {
  47961. public:
  47962. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47963. const String& name)
  47964. : owner (owner_),
  47965. categoryName (name)
  47966. {
  47967. }
  47968. ~KeyCategoryTreeViewItem()
  47969. {
  47970. }
  47971. const String getUniqueName() const { return categoryName + "_cat"; }
  47972. bool mightContainSubItems() { return true; }
  47973. int getItemHeight() const { return 28; }
  47974. void paintItem (Graphics& g, int width, int height)
  47975. {
  47976. g.setFont (height * 0.6f, Font::bold);
  47977. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47978. g.drawText (categoryName,
  47979. 2, 0, width - 2, height,
  47980. Justification::centredLeft, true);
  47981. }
  47982. void itemOpennessChanged (bool isNowOpen)
  47983. {
  47984. if (isNowOpen)
  47985. {
  47986. if (getNumSubItems() == 0)
  47987. {
  47988. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47989. for (int i = 0; i < commands.size(); ++i)
  47990. {
  47991. if (owner->shouldCommandBeIncluded (commands[i]))
  47992. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47993. }
  47994. }
  47995. }
  47996. else
  47997. {
  47998. clearSubItems();
  47999. }
  48000. }
  48001. juce_UseDebuggingNewOperator
  48002. private:
  48003. KeyMappingEditorComponent* owner;
  48004. String categoryName;
  48005. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  48006. const KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  48007. };
  48008. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  48009. const bool showResetToDefaultButton)
  48010. : mappings (mappingManager)
  48011. {
  48012. jassert (mappingManager != 0); // can't be null!
  48013. mappingManager->addChangeListener (this);
  48014. setLinesDrawnForSubItems (false);
  48015. resetButton = 0;
  48016. if (showResetToDefaultButton)
  48017. {
  48018. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  48019. resetButton->addButtonListener (this);
  48020. }
  48021. addAndMakeVisible (tree = new TreeView());
  48022. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  48023. tree->setRootItemVisible (false);
  48024. tree->setDefaultOpenness (true);
  48025. tree->setRootItem (this);
  48026. }
  48027. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  48028. {
  48029. mappings->removeChangeListener (this);
  48030. deleteAllChildren();
  48031. }
  48032. bool KeyMappingEditorComponent::mightContainSubItems()
  48033. {
  48034. return true;
  48035. }
  48036. const String KeyMappingEditorComponent::getUniqueName() const
  48037. {
  48038. return T("keys");
  48039. }
  48040. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  48041. const Colour& textColour)
  48042. {
  48043. setColour (backgroundColourId, mainBackground);
  48044. setColour (textColourId, textColour);
  48045. tree->setColour (TreeView::backgroundColourId, mainBackground);
  48046. }
  48047. void KeyMappingEditorComponent::parentHierarchyChanged()
  48048. {
  48049. changeListenerCallback (0);
  48050. }
  48051. void KeyMappingEditorComponent::resized()
  48052. {
  48053. int h = getHeight();
  48054. if (resetButton != 0)
  48055. {
  48056. const int buttonHeight = 20;
  48057. h -= buttonHeight + 8;
  48058. int x = getWidth() - 8;
  48059. const int y = h + 6;
  48060. resetButton->changeWidthToFitText (buttonHeight);
  48061. resetButton->setTopRightPosition (x, y);
  48062. }
  48063. tree->setBounds (0, 0, getWidth(), h);
  48064. }
  48065. void KeyMappingEditorComponent::buttonClicked (Button* button)
  48066. {
  48067. if (button == resetButton)
  48068. {
  48069. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  48070. TRANS("Reset to defaults"),
  48071. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  48072. TRANS("Reset")))
  48073. {
  48074. mappings->resetToDefaultMappings();
  48075. }
  48076. }
  48077. }
  48078. void KeyMappingEditorComponent::changeListenerCallback (void*)
  48079. {
  48080. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  48081. clearSubItems();
  48082. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  48083. for (int i = 0; i < categories.size(); ++i)
  48084. {
  48085. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  48086. int count = 0;
  48087. for (int j = 0; j < commands.size(); ++j)
  48088. if (shouldCommandBeIncluded (commands[j]))
  48089. ++count;
  48090. if (count > 0)
  48091. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  48092. }
  48093. if (openness != 0)
  48094. tree->restoreOpennessState (*openness);
  48095. }
  48096. class KeyEntryWindow : public AlertWindow
  48097. {
  48098. public:
  48099. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  48100. : AlertWindow (TRANS("New key-mapping"),
  48101. TRANS("Please press a key combination now..."),
  48102. AlertWindow::NoIcon),
  48103. owner (owner_)
  48104. {
  48105. addButton (TRANS("ok"), 1);
  48106. addButton (TRANS("cancel"), 0);
  48107. // (avoid return + escape keys getting processed by the buttons..)
  48108. for (int i = getNumChildComponents(); --i >= 0;)
  48109. getChildComponent (i)->setWantsKeyboardFocus (false);
  48110. setWantsKeyboardFocus (true);
  48111. grabKeyboardFocus();
  48112. }
  48113. ~KeyEntryWindow()
  48114. {
  48115. }
  48116. bool keyPressed (const KeyPress& key)
  48117. {
  48118. lastPress = key;
  48119. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48120. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48121. if (previousCommand != 0)
  48122. {
  48123. message << "\n\n"
  48124. << TRANS("(Currently assigned to \"")
  48125. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48126. << "\")";
  48127. }
  48128. setMessage (message);
  48129. return true;
  48130. }
  48131. bool keyStateChanged (const bool)
  48132. {
  48133. return true;
  48134. }
  48135. KeyPress lastPress;
  48136. juce_UseDebuggingNewOperator
  48137. private:
  48138. KeyMappingEditorComponent* owner;
  48139. KeyEntryWindow (const KeyEntryWindow&);
  48140. const KeyEntryWindow& operator= (const KeyEntryWindow&);
  48141. };
  48142. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48143. {
  48144. KeyEntryWindow entryWindow (this);
  48145. if (entryWindow.runModalLoop() != 0)
  48146. {
  48147. entryWindow.setVisible (false);
  48148. if (entryWindow.lastPress.isValid())
  48149. {
  48150. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48151. if (previousCommand != 0)
  48152. {
  48153. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48154. TRANS("Change key-mapping"),
  48155. TRANS("This key is already assigned to the command \"")
  48156. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48157. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48158. TRANS("re-assign"),
  48159. TRANS("cancel")))
  48160. {
  48161. return;
  48162. }
  48163. }
  48164. mappings->removeKeyPress (entryWindow.lastPress);
  48165. if (index >= 0)
  48166. mappings->removeKeyPress (commandID, index);
  48167. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48168. }
  48169. }
  48170. }
  48171. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48172. {
  48173. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48174. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48175. }
  48176. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48177. {
  48178. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48179. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48180. }
  48181. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48182. {
  48183. return key.getTextDescription();
  48184. }
  48185. END_JUCE_NAMESPACE
  48186. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  48187. /*** Start of inlined file: juce_KeyPress.cpp ***/
  48188. BEGIN_JUCE_NAMESPACE
  48189. KeyPress::KeyPress() throw()
  48190. : keyCode (0),
  48191. mods (0),
  48192. textCharacter (0)
  48193. {
  48194. }
  48195. KeyPress::KeyPress (const int keyCode_,
  48196. const ModifierKeys& mods_,
  48197. const juce_wchar textCharacter_) throw()
  48198. : keyCode (keyCode_),
  48199. mods (mods_),
  48200. textCharacter (textCharacter_)
  48201. {
  48202. }
  48203. KeyPress::KeyPress (const int keyCode_) throw()
  48204. : keyCode (keyCode_),
  48205. textCharacter (0)
  48206. {
  48207. }
  48208. KeyPress::KeyPress (const KeyPress& other) throw()
  48209. : keyCode (other.keyCode),
  48210. mods (other.mods),
  48211. textCharacter (other.textCharacter)
  48212. {
  48213. }
  48214. const KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48215. {
  48216. keyCode = other.keyCode;
  48217. mods = other.mods;
  48218. textCharacter = other.textCharacter;
  48219. return *this;
  48220. }
  48221. bool KeyPress::operator== (const KeyPress& other) const throw()
  48222. {
  48223. return mods.getRawFlags() == other.mods.getRawFlags()
  48224. && (textCharacter == other.textCharacter
  48225. || textCharacter == 0
  48226. || other.textCharacter == 0)
  48227. && (keyCode == other.keyCode
  48228. || (keyCode < 256
  48229. && other.keyCode < 256
  48230. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48231. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48232. }
  48233. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48234. {
  48235. return ! operator== (other);
  48236. }
  48237. bool KeyPress::isCurrentlyDown() const throw()
  48238. {
  48239. return isKeyCurrentlyDown (keyCode)
  48240. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48241. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48242. }
  48243. struct KeyNameAndCode
  48244. {
  48245. const char* name;
  48246. int code;
  48247. };
  48248. static const KeyNameAndCode keyNameTranslations[] =
  48249. {
  48250. { "spacebar", KeyPress::spaceKey },
  48251. { "return", KeyPress::returnKey },
  48252. { "escape", KeyPress::escapeKey },
  48253. { "backspace", KeyPress::backspaceKey },
  48254. { "cursor left", KeyPress::leftKey },
  48255. { "cursor right", KeyPress::rightKey },
  48256. { "cursor up", KeyPress::upKey },
  48257. { "cursor down", KeyPress::downKey },
  48258. { "page up", KeyPress::pageUpKey },
  48259. { "page down", KeyPress::pageDownKey },
  48260. { "home", KeyPress::homeKey },
  48261. { "end", KeyPress::endKey },
  48262. { "delete", KeyPress::deleteKey },
  48263. { "insert", KeyPress::insertKey },
  48264. { "tab", KeyPress::tabKey },
  48265. { "play", KeyPress::playKey },
  48266. { "stop", KeyPress::stopKey },
  48267. { "fast forward", KeyPress::fastForwardKey },
  48268. { "rewind", KeyPress::rewindKey }
  48269. };
  48270. static const tchar* const numberPadPrefix = T("numpad ");
  48271. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48272. {
  48273. int modifiers = 0;
  48274. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48275. || desc.containsWholeWordIgnoreCase (T("control"))
  48276. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48277. modifiers |= ModifierKeys::ctrlModifier;
  48278. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48279. || desc.containsWholeWordIgnoreCase (T("shft")))
  48280. modifiers |= ModifierKeys::shiftModifier;
  48281. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48282. || desc.containsWholeWordIgnoreCase (T("option")))
  48283. modifiers |= ModifierKeys::altModifier;
  48284. if (desc.containsWholeWordIgnoreCase (T("command"))
  48285. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48286. modifiers |= ModifierKeys::commandModifier;
  48287. int key = 0;
  48288. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48289. {
  48290. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48291. {
  48292. key = keyNameTranslations[i].code;
  48293. break;
  48294. }
  48295. }
  48296. if (key == 0)
  48297. {
  48298. // see if it's a numpad key..
  48299. if (desc.containsIgnoreCase (numberPadPrefix))
  48300. {
  48301. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48302. if (lastChar >= T('0') && lastChar <= T('9'))
  48303. key = numberPad0 + lastChar - T('0');
  48304. else if (lastChar == T('+'))
  48305. key = numberPadAdd;
  48306. else if (lastChar == T('-'))
  48307. key = numberPadSubtract;
  48308. else if (lastChar == T('*'))
  48309. key = numberPadMultiply;
  48310. else if (lastChar == T('/'))
  48311. key = numberPadDivide;
  48312. else if (lastChar == T('.'))
  48313. key = numberPadDecimalPoint;
  48314. else if (lastChar == T('='))
  48315. key = numberPadEquals;
  48316. else if (desc.endsWith (T("separator")))
  48317. key = numberPadSeparator;
  48318. else if (desc.endsWith (T("delete")))
  48319. key = numberPadDelete;
  48320. }
  48321. if (key == 0)
  48322. {
  48323. // see if it's a function key..
  48324. for (int i = 1; i <= 12; ++i)
  48325. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48326. key = F1Key + i - 1;
  48327. if (key == 0)
  48328. {
  48329. // give up and use the hex code..
  48330. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48331. .toLowerCase()
  48332. .retainCharacters (T("0123456789abcdef"))
  48333. .getHexValue32();
  48334. if (hexCode > 0)
  48335. key = hexCode;
  48336. else
  48337. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48338. }
  48339. }
  48340. }
  48341. return KeyPress (key, ModifierKeys (modifiers), 0);
  48342. }
  48343. const String KeyPress::getTextDescription() const throw()
  48344. {
  48345. String desc;
  48346. if (keyCode > 0)
  48347. {
  48348. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48349. // want to store it as being a slash, not shift+whatever.
  48350. if (textCharacter == T('/'))
  48351. return "/";
  48352. if (mods.isCtrlDown())
  48353. desc << "ctrl + ";
  48354. if (mods.isShiftDown())
  48355. desc << "shift + ";
  48356. #if JUCE_MAC
  48357. // only do this on the mac, because on Windows ctrl and command are the same,
  48358. // and this would get confusing
  48359. if (mods.isCommandDown())
  48360. desc << "command + ";
  48361. if (mods.isAltDown())
  48362. desc << "option + ";
  48363. #else
  48364. if (mods.isAltDown())
  48365. desc << "alt + ";
  48366. #endif
  48367. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48368. if (keyCode == keyNameTranslations[i].code)
  48369. return desc + keyNameTranslations[i].name;
  48370. if (keyCode >= F1Key && keyCode <= F16Key)
  48371. desc << 'F' << (1 + keyCode - F1Key);
  48372. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48373. desc << numberPadPrefix << (keyCode - numberPad0);
  48374. else if (keyCode >= 33 && keyCode < 176)
  48375. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48376. else if (keyCode == numberPadAdd)
  48377. desc << numberPadPrefix << '+';
  48378. else if (keyCode == numberPadSubtract)
  48379. desc << numberPadPrefix << '-';
  48380. else if (keyCode == numberPadMultiply)
  48381. desc << numberPadPrefix << '*';
  48382. else if (keyCode == numberPadDivide)
  48383. desc << numberPadPrefix << '/';
  48384. else if (keyCode == numberPadSeparator)
  48385. desc << numberPadPrefix << "separator";
  48386. else if (keyCode == numberPadDecimalPoint)
  48387. desc << numberPadPrefix << '.';
  48388. else if (keyCode == numberPadDelete)
  48389. desc << numberPadPrefix << "delete";
  48390. else
  48391. desc << '#' << String::toHexString (keyCode);
  48392. }
  48393. return desc;
  48394. }
  48395. END_JUCE_NAMESPACE
  48396. /*** End of inlined file: juce_KeyPress.cpp ***/
  48397. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  48398. BEGIN_JUCE_NAMESPACE
  48399. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48400. : commandManager (commandManager_)
  48401. {
  48402. // A manager is needed to get the descriptions of commands, and will be called when
  48403. // a command is invoked. So you can't leave this null..
  48404. jassert (commandManager_ != 0);
  48405. Desktop::getInstance().addFocusChangeListener (this);
  48406. }
  48407. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48408. : commandManager (other.commandManager)
  48409. {
  48410. Desktop::getInstance().addFocusChangeListener (this);
  48411. }
  48412. KeyPressMappingSet::~KeyPressMappingSet()
  48413. {
  48414. Desktop::getInstance().removeFocusChangeListener (this);
  48415. }
  48416. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48417. {
  48418. for (int i = 0; i < mappings.size(); ++i)
  48419. if (mappings.getUnchecked(i)->commandID == commandID)
  48420. return mappings.getUnchecked (i)->keypresses;
  48421. return Array <KeyPress> ();
  48422. }
  48423. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48424. const KeyPress& newKeyPress,
  48425. int insertIndex) throw()
  48426. {
  48427. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48428. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48429. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48430. && ! newKeyPress.getModifiers().isShiftDown()));
  48431. if (findCommandForKeyPress (newKeyPress) != commandID)
  48432. {
  48433. removeKeyPress (newKeyPress);
  48434. if (newKeyPress.isValid())
  48435. {
  48436. for (int i = mappings.size(); --i >= 0;)
  48437. {
  48438. if (mappings.getUnchecked(i)->commandID == commandID)
  48439. {
  48440. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48441. sendChangeMessage (this);
  48442. return;
  48443. }
  48444. }
  48445. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48446. if (ci != 0)
  48447. {
  48448. CommandMapping* const cm = new CommandMapping();
  48449. cm->commandID = commandID;
  48450. cm->keypresses.add (newKeyPress);
  48451. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48452. mappings.add (cm);
  48453. sendChangeMessage (this);
  48454. }
  48455. }
  48456. }
  48457. }
  48458. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48459. {
  48460. mappings.clear();
  48461. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48462. {
  48463. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48464. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48465. {
  48466. addKeyPress (ci->commandID,
  48467. ci->defaultKeypresses.getReference (j));
  48468. }
  48469. }
  48470. sendChangeMessage (this);
  48471. }
  48472. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48473. {
  48474. clearAllKeyPresses (commandID);
  48475. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48476. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48477. {
  48478. addKeyPress (ci->commandID,
  48479. ci->defaultKeypresses.getReference (j));
  48480. }
  48481. }
  48482. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48483. {
  48484. if (mappings.size() > 0)
  48485. {
  48486. sendChangeMessage (this);
  48487. mappings.clear();
  48488. }
  48489. }
  48490. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48491. {
  48492. for (int i = mappings.size(); --i >= 0;)
  48493. {
  48494. if (mappings.getUnchecked(i)->commandID == commandID)
  48495. {
  48496. mappings.remove (i);
  48497. sendChangeMessage (this);
  48498. }
  48499. }
  48500. }
  48501. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48502. {
  48503. if (keypress.isValid())
  48504. {
  48505. for (int i = mappings.size(); --i >= 0;)
  48506. {
  48507. CommandMapping* const cm = mappings.getUnchecked(i);
  48508. for (int j = cm->keypresses.size(); --j >= 0;)
  48509. {
  48510. if (keypress == cm->keypresses [j])
  48511. {
  48512. cm->keypresses.remove (j);
  48513. sendChangeMessage (this);
  48514. }
  48515. }
  48516. }
  48517. }
  48518. }
  48519. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48520. const int keyPressIndex) throw()
  48521. {
  48522. for (int i = mappings.size(); --i >= 0;)
  48523. {
  48524. if (mappings.getUnchecked(i)->commandID == commandID)
  48525. {
  48526. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48527. sendChangeMessage (this);
  48528. break;
  48529. }
  48530. }
  48531. }
  48532. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48533. {
  48534. for (int i = 0; i < mappings.size(); ++i)
  48535. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48536. return mappings.getUnchecked(i)->commandID;
  48537. return 0;
  48538. }
  48539. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48540. const KeyPress& keyPress) const throw()
  48541. {
  48542. for (int i = mappings.size(); --i >= 0;)
  48543. if (mappings.getUnchecked(i)->commandID == commandID)
  48544. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48545. return false;
  48546. }
  48547. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48548. const KeyPress& key,
  48549. const bool isKeyDown,
  48550. const int millisecsSinceKeyPressed,
  48551. Component* const originatingComponent) const
  48552. {
  48553. ApplicationCommandTarget::InvocationInfo info (commandID);
  48554. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48555. info.isKeyDown = isKeyDown;
  48556. info.keyPress = key;
  48557. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48558. info.originatingComponent = originatingComponent;
  48559. commandManager->invoke (info, false);
  48560. }
  48561. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48562. {
  48563. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48564. {
  48565. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48566. {
  48567. // if the XML was created as a set of differences from the default mappings,
  48568. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48569. resetToDefaultMappings();
  48570. }
  48571. else
  48572. {
  48573. // if the XML was created calling createXml (false), then we need to clear all
  48574. // the keys and treat the xml as describing the entire set of mappings.
  48575. clearAllKeyPresses();
  48576. }
  48577. forEachXmlChildElement (xmlVersion, map)
  48578. {
  48579. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48580. if (commandId != 0)
  48581. {
  48582. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48583. if (map->hasTagName (T("MAPPING")))
  48584. {
  48585. addKeyPress (commandId, key);
  48586. }
  48587. else if (map->hasTagName (T("UNMAPPING")))
  48588. {
  48589. if (containsMapping (commandId, key))
  48590. removeKeyPress (key);
  48591. }
  48592. }
  48593. }
  48594. return true;
  48595. }
  48596. return false;
  48597. }
  48598. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48599. {
  48600. ScopedPointer <KeyPressMappingSet> defaultSet;
  48601. if (saveDifferencesFromDefaultSet)
  48602. {
  48603. defaultSet = new KeyPressMappingSet (commandManager);
  48604. defaultSet->resetToDefaultMappings();
  48605. }
  48606. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48607. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48608. int i;
  48609. for (i = 0; i < mappings.size(); ++i)
  48610. {
  48611. const CommandMapping* const cm = mappings.getUnchecked(i);
  48612. for (int j = 0; j < cm->keypresses.size(); ++j)
  48613. {
  48614. if (defaultSet == 0
  48615. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48616. {
  48617. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48618. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48619. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48620. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48621. }
  48622. }
  48623. }
  48624. if (defaultSet != 0)
  48625. {
  48626. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48627. {
  48628. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48629. for (int j = 0; j < cm->keypresses.size(); ++j)
  48630. {
  48631. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48632. {
  48633. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48634. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48635. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48636. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48637. }
  48638. }
  48639. }
  48640. }
  48641. return doc;
  48642. }
  48643. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48644. Component* originatingComponent)
  48645. {
  48646. bool used = false;
  48647. const CommandID commandID = findCommandForKeyPress (key);
  48648. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48649. if (ci != 0
  48650. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48651. {
  48652. ApplicationCommandInfo info (0);
  48653. if (commandManager->getTargetForCommand (commandID, info) != 0
  48654. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48655. {
  48656. invokeCommand (commandID, key, true, 0, originatingComponent);
  48657. used = true;
  48658. }
  48659. else
  48660. {
  48661. if (originatingComponent != 0)
  48662. originatingComponent->getLookAndFeel().playAlertSound();
  48663. }
  48664. }
  48665. return used;
  48666. }
  48667. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48668. {
  48669. bool used = false;
  48670. const uint32 now = Time::getMillisecondCounter();
  48671. for (int i = mappings.size(); --i >= 0;)
  48672. {
  48673. CommandMapping* const cm = mappings.getUnchecked(i);
  48674. if (cm->wantsKeyUpDownCallbacks)
  48675. {
  48676. for (int j = cm->keypresses.size(); --j >= 0;)
  48677. {
  48678. const KeyPress key (cm->keypresses.getReference (j));
  48679. const bool isDown = key.isCurrentlyDown();
  48680. int keyPressEntryIndex = 0;
  48681. bool wasDown = false;
  48682. for (int k = keysDown.size(); --k >= 0;)
  48683. {
  48684. if (key == keysDown.getUnchecked(k)->key)
  48685. {
  48686. keyPressEntryIndex = k;
  48687. wasDown = true;
  48688. used = true;
  48689. break;
  48690. }
  48691. }
  48692. if (isDown != wasDown)
  48693. {
  48694. int millisecs = 0;
  48695. if (isDown)
  48696. {
  48697. KeyPressTime* const k = new KeyPressTime();
  48698. k->key = key;
  48699. k->timeWhenPressed = now;
  48700. keysDown.add (k);
  48701. }
  48702. else
  48703. {
  48704. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48705. if (now > pressTime)
  48706. millisecs = now - pressTime;
  48707. keysDown.remove (keyPressEntryIndex);
  48708. }
  48709. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48710. used = true;
  48711. }
  48712. }
  48713. }
  48714. }
  48715. return used;
  48716. }
  48717. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48718. {
  48719. if (focusedComponent != 0)
  48720. focusedComponent->keyStateChanged (false);
  48721. }
  48722. END_JUCE_NAMESPACE
  48723. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48724. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48725. BEGIN_JUCE_NAMESPACE
  48726. ModifierKeys::ModifierKeys (const int flags_) throw()
  48727. : flags (flags_)
  48728. {
  48729. }
  48730. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48731. : flags (other.flags)
  48732. {
  48733. }
  48734. const ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48735. {
  48736. flags = other.flags;
  48737. return *this;
  48738. }
  48739. int ModifierKeys::currentModifierFlags = 0;
  48740. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48741. {
  48742. return ModifierKeys (currentModifierFlags);
  48743. }
  48744. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48745. {
  48746. int num = 0;
  48747. if (isLeftButtonDown()) ++num;
  48748. if (isRightButtonDown()) ++num;
  48749. if (isMiddleButtonDown()) ++num;
  48750. return num;
  48751. }
  48752. END_JUCE_NAMESPACE
  48753. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48754. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48755. BEGIN_JUCE_NAMESPACE
  48756. struct AnimationTask
  48757. {
  48758. AnimationTask (Component* const comp)
  48759. : component (comp),
  48760. watcher (comp)
  48761. {
  48762. }
  48763. Component* component;
  48764. ComponentDeletionWatcher watcher;
  48765. Rectangle<int> destination;
  48766. int msElapsed, msTotal;
  48767. double startSpeed, midSpeed, endSpeed, lastProgress;
  48768. double left, top, right, bottom;
  48769. bool useTimeslice (const int elapsed)
  48770. {
  48771. if (watcher.hasBeenDeleted())
  48772. return false;
  48773. msElapsed += elapsed;
  48774. double newProgress = msElapsed / (double) msTotal;
  48775. if (newProgress >= 0 && newProgress < 1.0)
  48776. {
  48777. newProgress = timeToDistance (newProgress);
  48778. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48779. jassert (newProgress >= lastProgress);
  48780. lastProgress = newProgress;
  48781. left += (destination.getX() - left) * delta;
  48782. top += (destination.getY() - top) * delta;
  48783. right += (destination.getRight() - right) * delta;
  48784. bottom += (destination.getBottom() - bottom) * delta;
  48785. if (delta < 1.0)
  48786. {
  48787. const Rectangle<int> newBounds (roundToInt (left),
  48788. roundToInt (top),
  48789. roundToInt (right - left),
  48790. roundToInt (bottom - top));
  48791. if (newBounds != destination)
  48792. {
  48793. component->setBounds (newBounds);
  48794. return true;
  48795. }
  48796. }
  48797. }
  48798. component->setBounds (destination);
  48799. return false;
  48800. }
  48801. void moveToFinalDestination()
  48802. {
  48803. if (! watcher.hasBeenDeleted())
  48804. component->setBounds (destination);
  48805. }
  48806. private:
  48807. inline double timeToDistance (const double time) const
  48808. {
  48809. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48810. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48811. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48812. }
  48813. };
  48814. ComponentAnimator::ComponentAnimator()
  48815. : lastTime (0)
  48816. {
  48817. }
  48818. ComponentAnimator::~ComponentAnimator()
  48819. {
  48820. cancelAllAnimations (false);
  48821. jassert (tasks.size() == 0);
  48822. }
  48823. void* ComponentAnimator::findTaskFor (Component* const component) const
  48824. {
  48825. for (int i = tasks.size(); --i >= 0;)
  48826. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48827. return tasks.getUnchecked(i);
  48828. return 0;
  48829. }
  48830. void ComponentAnimator::animateComponent (Component* const component,
  48831. const Rectangle<int>& finalPosition,
  48832. const int millisecondsToSpendMoving,
  48833. const double startSpeed,
  48834. const double endSpeed)
  48835. {
  48836. if (component != 0)
  48837. {
  48838. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48839. if (at == 0)
  48840. {
  48841. at = new AnimationTask (component);
  48842. tasks.add (at);
  48843. sendChangeMessage (this);
  48844. }
  48845. at->msElapsed = 0;
  48846. at->lastProgress = 0;
  48847. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48848. at->destination = finalPosition;
  48849. // the speeds must be 0 or greater!
  48850. jassert (startSpeed >= 0 && endSpeed >= 0)
  48851. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48852. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48853. at->midSpeed = invTotalDistance;
  48854. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48855. at->left = component->getX();
  48856. at->top = component->getY();
  48857. at->right = component->getRight();
  48858. at->bottom = component->getBottom();
  48859. if (! isTimerRunning())
  48860. {
  48861. lastTime = Time::getMillisecondCounter();
  48862. startTimer (1000 / 50);
  48863. }
  48864. }
  48865. }
  48866. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48867. {
  48868. for (int i = tasks.size(); --i >= 0;)
  48869. {
  48870. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48871. if (moveComponentsToTheirFinalPositions)
  48872. at->moveToFinalDestination();
  48873. delete at;
  48874. tasks.remove (i);
  48875. sendChangeMessage (this);
  48876. }
  48877. }
  48878. void ComponentAnimator::cancelAnimation (Component* const component,
  48879. const bool moveComponentToItsFinalPosition)
  48880. {
  48881. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48882. if (at != 0)
  48883. {
  48884. if (moveComponentToItsFinalPosition)
  48885. at->moveToFinalDestination();
  48886. tasks.removeValue (at);
  48887. delete at;
  48888. sendChangeMessage (this);
  48889. }
  48890. }
  48891. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48892. {
  48893. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48894. if (at != 0)
  48895. return at->destination;
  48896. else if (component != 0)
  48897. return component->getBounds();
  48898. return Rectangle<int>();
  48899. }
  48900. bool ComponentAnimator::isAnimating (Component* component) const
  48901. {
  48902. return findTaskFor (component) != 0;
  48903. }
  48904. void ComponentAnimator::timerCallback()
  48905. {
  48906. const uint32 timeNow = Time::getMillisecondCounter();
  48907. if (lastTime == 0 || lastTime == timeNow)
  48908. lastTime = timeNow;
  48909. const int elapsed = timeNow - lastTime;
  48910. for (int i = tasks.size(); --i >= 0;)
  48911. {
  48912. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48913. if (! at->useTimeslice (elapsed))
  48914. {
  48915. tasks.remove (i);
  48916. delete at;
  48917. sendChangeMessage (this);
  48918. }
  48919. }
  48920. lastTime = timeNow;
  48921. if (tasks.size() == 0)
  48922. stopTimer();
  48923. }
  48924. END_JUCE_NAMESPACE
  48925. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48926. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48927. BEGIN_JUCE_NAMESPACE
  48928. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48929. : minW (0),
  48930. maxW (0x3fffffff),
  48931. minH (0),
  48932. maxH (0x3fffffff),
  48933. minOffTop (0),
  48934. minOffLeft (0),
  48935. minOffBottom (0),
  48936. minOffRight (0),
  48937. aspectRatio (0.0)
  48938. {
  48939. }
  48940. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48941. {
  48942. }
  48943. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48944. {
  48945. minW = minimumWidth;
  48946. }
  48947. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48948. {
  48949. maxW = maximumWidth;
  48950. }
  48951. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48952. {
  48953. minH = minimumHeight;
  48954. }
  48955. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48956. {
  48957. maxH = maximumHeight;
  48958. }
  48959. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48960. {
  48961. jassert (maxW >= minimumWidth);
  48962. jassert (maxH >= minimumHeight);
  48963. jassert (minimumWidth > 0 && minimumHeight > 0);
  48964. minW = minimumWidth;
  48965. minH = minimumHeight;
  48966. if (minW > maxW)
  48967. maxW = minW;
  48968. if (minH > maxH)
  48969. maxH = minH;
  48970. }
  48971. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48972. {
  48973. jassert (maximumWidth >= minW);
  48974. jassert (maximumHeight >= minH);
  48975. jassert (maximumWidth > 0 && maximumHeight > 0);
  48976. maxW = jmax (minW, maximumWidth);
  48977. maxH = jmax (minH, maximumHeight);
  48978. }
  48979. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48980. const int minimumHeight,
  48981. const int maximumWidth,
  48982. const int maximumHeight) throw()
  48983. {
  48984. jassert (maximumWidth >= minimumWidth);
  48985. jassert (maximumHeight >= minimumHeight);
  48986. jassert (maximumWidth > 0 && maximumHeight > 0);
  48987. jassert (minimumWidth > 0 && minimumHeight > 0);
  48988. minW = jmax (0, minimumWidth);
  48989. minH = jmax (0, minimumHeight);
  48990. maxW = jmax (minW, maximumWidth);
  48991. maxH = jmax (minH, maximumHeight);
  48992. }
  48993. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48994. const int minimumWhenOffTheLeft,
  48995. const int minimumWhenOffTheBottom,
  48996. const int minimumWhenOffTheRight) throw()
  48997. {
  48998. minOffTop = minimumWhenOffTheTop;
  48999. minOffLeft = minimumWhenOffTheLeft;
  49000. minOffBottom = minimumWhenOffTheBottom;
  49001. minOffRight = minimumWhenOffTheRight;
  49002. }
  49003. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  49004. {
  49005. aspectRatio = jmax (0.0, widthOverHeight);
  49006. }
  49007. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  49008. {
  49009. return aspectRatio;
  49010. }
  49011. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  49012. int x, int y, int w, int h,
  49013. const bool isStretchingTop,
  49014. const bool isStretchingLeft,
  49015. const bool isStretchingBottom,
  49016. const bool isStretchingRight)
  49017. {
  49018. jassert (component != 0);
  49019. Rectangle<int> limits;
  49020. Component* const p = component->getParentComponent();
  49021. if (p == 0)
  49022. limits = Desktop::getInstance().getAllMonitorDisplayAreas().getBounds();
  49023. else
  49024. limits.setSize (p->getWidth(), p->getHeight());
  49025. if (component->isOnDesktop())
  49026. {
  49027. ComponentPeer* const peer = component->getPeer();
  49028. const BorderSize border (peer->getFrameSize());
  49029. x -= border.getLeft();
  49030. y -= border.getTop();
  49031. w += border.getLeftAndRight();
  49032. h += border.getTopAndBottom();
  49033. checkBounds (x, y, w, h,
  49034. border.addedTo (component->getBounds()), limits,
  49035. isStretchingTop, isStretchingLeft,
  49036. isStretchingBottom, isStretchingRight);
  49037. x += border.getLeft();
  49038. y += border.getTop();
  49039. w -= border.getLeftAndRight();
  49040. h -= border.getTopAndBottom();
  49041. }
  49042. else
  49043. {
  49044. checkBounds (x, y, w, h,
  49045. component->getBounds(), limits,
  49046. isStretchingTop, isStretchingLeft,
  49047. isStretchingBottom, isStretchingRight);
  49048. }
  49049. applyBoundsToComponent (component, x, y, w, h);
  49050. }
  49051. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  49052. {
  49053. setBoundsForComponent (component,
  49054. component->getX(), component->getY(),
  49055. component->getWidth(), component->getHeight(),
  49056. false, false, false, false);
  49057. }
  49058. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  49059. int x, int y, int w, int h)
  49060. {
  49061. component->setBounds (x, y, w, h);
  49062. }
  49063. void ComponentBoundsConstrainer::resizeStart()
  49064. {
  49065. }
  49066. void ComponentBoundsConstrainer::resizeEnd()
  49067. {
  49068. }
  49069. void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h,
  49070. const Rectangle<int>& old,
  49071. const Rectangle<int>& limits,
  49072. const bool isStretchingTop,
  49073. const bool isStretchingLeft,
  49074. const bool isStretchingBottom,
  49075. const bool isStretchingRight)
  49076. {
  49077. // constrain the size if it's being stretched..
  49078. if (isStretchingLeft)
  49079. {
  49080. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  49081. w = old.getRight() - x;
  49082. }
  49083. if (isStretchingRight)
  49084. {
  49085. w = jlimit (minW, maxW, w);
  49086. }
  49087. if (isStretchingTop)
  49088. {
  49089. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  49090. h = old.getBottom() - y;
  49091. }
  49092. if (isStretchingBottom)
  49093. {
  49094. h = jlimit (minH, maxH, h);
  49095. }
  49096. // constrain the aspect ratio if one has been specified..
  49097. if (aspectRatio > 0.0 && w > 0 && h > 0)
  49098. {
  49099. bool adjustWidth;
  49100. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49101. {
  49102. adjustWidth = true;
  49103. }
  49104. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49105. {
  49106. adjustWidth = false;
  49107. }
  49108. else
  49109. {
  49110. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  49111. const double newRatio = fabs (w / (double) h);
  49112. adjustWidth = (oldRatio > newRatio);
  49113. }
  49114. if (adjustWidth)
  49115. {
  49116. w = roundToInt (h * aspectRatio);
  49117. if (w > maxW || w < minW)
  49118. {
  49119. w = jlimit (minW, maxW, w);
  49120. h = roundToInt (w / aspectRatio);
  49121. }
  49122. }
  49123. else
  49124. {
  49125. h = roundToInt (w / aspectRatio);
  49126. if (h > maxH || h < minH)
  49127. {
  49128. h = jlimit (minH, maxH, h);
  49129. w = roundToInt (h * aspectRatio);
  49130. }
  49131. }
  49132. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49133. {
  49134. x = old.getX() + (old.getWidth() - w) / 2;
  49135. }
  49136. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49137. {
  49138. y = old.getY() + (old.getHeight() - h) / 2;
  49139. }
  49140. else
  49141. {
  49142. if (isStretchingLeft)
  49143. x = old.getRight() - w;
  49144. if (isStretchingTop)
  49145. y = old.getBottom() - h;
  49146. }
  49147. }
  49148. // ...and constrain the position if limits have been set for that.
  49149. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49150. {
  49151. if (minOffTop > 0)
  49152. {
  49153. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49154. if (y < limit)
  49155. {
  49156. if (isStretchingTop)
  49157. h -= (limit - y);
  49158. y = limit;
  49159. }
  49160. }
  49161. if (minOffLeft > 0)
  49162. {
  49163. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49164. if (x < limit)
  49165. {
  49166. if (isStretchingLeft)
  49167. w -= (limit - x);
  49168. x = limit;
  49169. }
  49170. }
  49171. if (minOffBottom > 0)
  49172. {
  49173. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49174. if (y > limit)
  49175. {
  49176. if (isStretchingBottom)
  49177. h += (limit - y);
  49178. else
  49179. y = limit;
  49180. }
  49181. }
  49182. if (minOffRight > 0)
  49183. {
  49184. const int limit = limits.getRight() - jmin (minOffRight, w);
  49185. if (x > limit)
  49186. {
  49187. if (isStretchingRight)
  49188. w += (limit - x);
  49189. else
  49190. x = limit;
  49191. }
  49192. }
  49193. }
  49194. jassert (w >= 0 && h >= 0);
  49195. }
  49196. END_JUCE_NAMESPACE
  49197. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  49198. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49199. BEGIN_JUCE_NAMESPACE
  49200. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49201. : component (component_),
  49202. lastPeer (0),
  49203. reentrant (false)
  49204. {
  49205. jassert (component != 0); // can't use this with a null pointer..
  49206. #ifdef JUCE_DEBUG
  49207. deletionWatcher = new ComponentDeletionWatcher (component_);
  49208. #endif
  49209. component->addComponentListener (this);
  49210. registerWithParentComps();
  49211. }
  49212. ComponentMovementWatcher::~ComponentMovementWatcher()
  49213. {
  49214. component->removeComponentListener (this);
  49215. unregister();
  49216. }
  49217. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49218. {
  49219. #ifdef JUCE_DEBUG
  49220. // agh! don't delete the target component without deleting this object first!
  49221. jassert (! deletionWatcher->hasBeenDeleted());
  49222. #endif
  49223. if (! reentrant)
  49224. {
  49225. reentrant = true;
  49226. ComponentPeer* const peer = component->getPeer();
  49227. if (peer != lastPeer)
  49228. {
  49229. ComponentDeletionWatcher watcher (component);
  49230. componentPeerChanged();
  49231. if (watcher.hasBeenDeleted())
  49232. return;
  49233. lastPeer = peer;
  49234. }
  49235. unregister();
  49236. registerWithParentComps();
  49237. reentrant = false;
  49238. componentMovedOrResized (*component, true, true);
  49239. }
  49240. }
  49241. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49242. {
  49243. #ifdef JUCE_DEBUG
  49244. // agh! don't delete the target component without deleting this object first!
  49245. jassert (! deletionWatcher->hasBeenDeleted());
  49246. #endif
  49247. if (wasMoved)
  49248. {
  49249. int x = 0, y = 0;
  49250. component->relativePositionToOtherComponent (component->getTopLevelComponent(), x, y);
  49251. wasMoved = (lastX != x || lastY != y);
  49252. lastX = x;
  49253. lastY = y;
  49254. }
  49255. wasResized = (lastWidth != component->getWidth() || lastHeight != component->getHeight());
  49256. lastWidth = component->getWidth();
  49257. lastHeight = component->getHeight();
  49258. if (wasMoved || wasResized)
  49259. componentMovedOrResized (wasMoved, wasResized);
  49260. }
  49261. void ComponentMovementWatcher::registerWithParentComps() throw()
  49262. {
  49263. Component* p = component->getParentComponent();
  49264. while (p != 0)
  49265. {
  49266. p->addComponentListener (this);
  49267. registeredParentComps.add (p);
  49268. p = p->getParentComponent();
  49269. }
  49270. }
  49271. void ComponentMovementWatcher::unregister() throw()
  49272. {
  49273. for (int i = registeredParentComps.size(); --i >= 0;)
  49274. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49275. registeredParentComps.clear();
  49276. }
  49277. END_JUCE_NAMESPACE
  49278. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49279. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  49280. BEGIN_JUCE_NAMESPACE
  49281. GroupComponent::GroupComponent (const String& componentName,
  49282. const String& labelText)
  49283. : Component (componentName),
  49284. text (labelText),
  49285. justification (Justification::left)
  49286. {
  49287. setInterceptsMouseClicks (false, true);
  49288. }
  49289. GroupComponent::~GroupComponent()
  49290. {
  49291. }
  49292. void GroupComponent::setText (const String& newText) throw()
  49293. {
  49294. if (text != newText)
  49295. {
  49296. text = newText;
  49297. repaint();
  49298. }
  49299. }
  49300. const String GroupComponent::getText() const throw()
  49301. {
  49302. return text;
  49303. }
  49304. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49305. {
  49306. if (justification.getFlags() != newJustification.getFlags())
  49307. {
  49308. justification = newJustification;
  49309. repaint();
  49310. }
  49311. }
  49312. void GroupComponent::paint (Graphics& g)
  49313. {
  49314. getLookAndFeel()
  49315. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49316. text, justification,
  49317. *this);
  49318. }
  49319. void GroupComponent::enablementChanged()
  49320. {
  49321. repaint();
  49322. }
  49323. void GroupComponent::colourChanged()
  49324. {
  49325. repaint();
  49326. }
  49327. END_JUCE_NAMESPACE
  49328. /*** End of inlined file: juce_GroupComponent.cpp ***/
  49329. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  49330. BEGIN_JUCE_NAMESPACE
  49331. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49332. : DocumentWindow (String::empty, backgroundColour,
  49333. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49334. {
  49335. }
  49336. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49337. {
  49338. }
  49339. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49340. {
  49341. MultiDocumentPanel* const owner = getOwner();
  49342. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49343. if (owner != 0)
  49344. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49345. }
  49346. void MultiDocumentPanelWindow::closeButtonPressed()
  49347. {
  49348. MultiDocumentPanel* const owner = getOwner();
  49349. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49350. if (owner != 0)
  49351. owner->closeDocument (getContentComponent(), true);
  49352. }
  49353. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49354. {
  49355. DocumentWindow::activeWindowStatusChanged();
  49356. updateOrder();
  49357. }
  49358. void MultiDocumentPanelWindow::broughtToFront()
  49359. {
  49360. DocumentWindow::broughtToFront();
  49361. updateOrder();
  49362. }
  49363. void MultiDocumentPanelWindow::updateOrder()
  49364. {
  49365. MultiDocumentPanel* const owner = getOwner();
  49366. if (owner != 0)
  49367. owner->updateOrder();
  49368. }
  49369. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49370. {
  49371. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49372. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49373. }
  49374. class MDITabbedComponentInternal : public TabbedComponent
  49375. {
  49376. public:
  49377. MDITabbedComponentInternal()
  49378. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49379. {
  49380. }
  49381. ~MDITabbedComponentInternal()
  49382. {
  49383. }
  49384. void currentTabChanged (const int, const String&)
  49385. {
  49386. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49387. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49388. if (owner != 0)
  49389. owner->updateOrder();
  49390. }
  49391. };
  49392. MultiDocumentPanel::MultiDocumentPanel()
  49393. : mode (MaximisedWindowsWithTabs),
  49394. tabComponent (0),
  49395. backgroundColour (Colours::lightblue),
  49396. maximumNumDocuments (0),
  49397. numDocsBeforeTabsUsed (0)
  49398. {
  49399. setOpaque (true);
  49400. }
  49401. MultiDocumentPanel::~MultiDocumentPanel()
  49402. {
  49403. closeAllDocuments (false);
  49404. }
  49405. static bool shouldDeleteComp (Component* const c)
  49406. {
  49407. return c->getProperties() ["mdiDocumentDelete_"];
  49408. }
  49409. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49410. {
  49411. while (components.size() > 0)
  49412. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49413. return false;
  49414. return true;
  49415. }
  49416. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49417. {
  49418. return new MultiDocumentPanelWindow (backgroundColour);
  49419. }
  49420. void MultiDocumentPanel::addWindow (Component* component)
  49421. {
  49422. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49423. dw->setResizable (true, false);
  49424. dw->setContentComponent (component, false, true);
  49425. dw->setName (component->getName());
  49426. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  49427. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  49428. int x = 4;
  49429. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49430. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49431. x += 16;
  49432. dw->setTopLeftPosition (x, x);
  49433. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  49434. if (pos.toString().isNotEmpty())
  49435. dw->restoreWindowStateFromString (pos.toString());
  49436. addAndMakeVisible (dw);
  49437. dw->toFront (true);
  49438. }
  49439. bool MultiDocumentPanel::addDocument (Component* const component,
  49440. const Colour& docColour,
  49441. const bool deleteWhenRemoved)
  49442. {
  49443. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49444. // with a frame-within-a-frame! Just pass in the bare content component.
  49445. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49446. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49447. return false;
  49448. components.add (component);
  49449. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  49450. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  49451. component->addComponentListener (this);
  49452. if (mode == FloatingWindows)
  49453. {
  49454. if (isFullscreenWhenOneDocument())
  49455. {
  49456. if (components.size() == 1)
  49457. {
  49458. addAndMakeVisible (component);
  49459. }
  49460. else
  49461. {
  49462. if (components.size() == 2)
  49463. addWindow (components.getFirst());
  49464. addWindow (component);
  49465. }
  49466. }
  49467. else
  49468. {
  49469. addWindow (component);
  49470. }
  49471. }
  49472. else
  49473. {
  49474. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49475. {
  49476. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49477. Array <Component*> temp (components);
  49478. for (int i = 0; i < temp.size(); ++i)
  49479. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49480. resized();
  49481. }
  49482. else
  49483. {
  49484. if (tabComponent != 0)
  49485. tabComponent->addTab (component->getName(), docColour, component, false);
  49486. else
  49487. addAndMakeVisible (component);
  49488. }
  49489. setActiveDocument (component);
  49490. }
  49491. resized();
  49492. activeDocumentChanged();
  49493. return true;
  49494. }
  49495. bool MultiDocumentPanel::closeDocument (Component* component,
  49496. const bool checkItsOkToCloseFirst)
  49497. {
  49498. if (components.contains (component))
  49499. {
  49500. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49501. return false;
  49502. component->removeComponentListener (this);
  49503. const bool shouldDelete = shouldDeleteComp (component);
  49504. component->getProperties().remove ("mdiDocumentDelete_");
  49505. component->getProperties().remove ("mdiDocumentBkg_");
  49506. if (mode == FloatingWindows)
  49507. {
  49508. for (int i = getNumChildComponents(); --i >= 0;)
  49509. {
  49510. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49511. if (dw != 0 && dw->getContentComponent() == component)
  49512. {
  49513. dw->setContentComponent (0, false);
  49514. delete dw;
  49515. break;
  49516. }
  49517. }
  49518. if (shouldDelete)
  49519. delete component;
  49520. components.removeValue (component);
  49521. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49522. {
  49523. for (int i = getNumChildComponents(); --i >= 0;)
  49524. {
  49525. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49526. if (dw != 0)
  49527. {
  49528. dw->setContentComponent (0, false);
  49529. delete dw;
  49530. }
  49531. }
  49532. addAndMakeVisible (components.getFirst());
  49533. }
  49534. }
  49535. else
  49536. {
  49537. jassert (components.indexOf (component) >= 0);
  49538. if (tabComponent != 0)
  49539. {
  49540. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49541. if (tabComponent->getTabContentComponent (i) == component)
  49542. tabComponent->removeTab (i);
  49543. }
  49544. else
  49545. {
  49546. removeChildComponent (component);
  49547. }
  49548. if (shouldDelete)
  49549. delete component;
  49550. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49551. deleteAndZero (tabComponent);
  49552. components.removeValue (component);
  49553. if (components.size() > 0 && tabComponent == 0)
  49554. addAndMakeVisible (components.getFirst());
  49555. }
  49556. resized();
  49557. activeDocumentChanged();
  49558. }
  49559. else
  49560. {
  49561. jassertfalse
  49562. }
  49563. return true;
  49564. }
  49565. int MultiDocumentPanel::getNumDocuments() const throw()
  49566. {
  49567. return components.size();
  49568. }
  49569. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49570. {
  49571. return components [index];
  49572. }
  49573. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49574. {
  49575. if (mode == FloatingWindows)
  49576. {
  49577. for (int i = getNumChildComponents(); --i >= 0;)
  49578. {
  49579. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49580. if (dw != 0 && dw->isActiveWindow())
  49581. return dw->getContentComponent();
  49582. }
  49583. }
  49584. return components.getLast();
  49585. }
  49586. void MultiDocumentPanel::setActiveDocument (Component* component)
  49587. {
  49588. if (mode == FloatingWindows)
  49589. {
  49590. component = getContainerComp (component);
  49591. if (component != 0)
  49592. component->toFront (true);
  49593. }
  49594. else if (tabComponent != 0)
  49595. {
  49596. jassert (components.indexOf (component) >= 0);
  49597. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49598. {
  49599. if (tabComponent->getTabContentComponent (i) == component)
  49600. {
  49601. tabComponent->setCurrentTabIndex (i);
  49602. break;
  49603. }
  49604. }
  49605. }
  49606. else
  49607. {
  49608. component->grabKeyboardFocus();
  49609. }
  49610. }
  49611. void MultiDocumentPanel::activeDocumentChanged()
  49612. {
  49613. }
  49614. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49615. {
  49616. maximumNumDocuments = newNumber;
  49617. }
  49618. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49619. {
  49620. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49621. }
  49622. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49623. {
  49624. return numDocsBeforeTabsUsed != 0;
  49625. }
  49626. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49627. {
  49628. if (mode != newLayoutMode)
  49629. {
  49630. mode = newLayoutMode;
  49631. if (mode == FloatingWindows)
  49632. {
  49633. deleteAndZero (tabComponent);
  49634. }
  49635. else
  49636. {
  49637. for (int i = getNumChildComponents(); --i >= 0;)
  49638. {
  49639. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49640. if (dw != 0)
  49641. {
  49642. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49643. dw->setContentComponent (0, false);
  49644. delete dw;
  49645. }
  49646. }
  49647. }
  49648. resized();
  49649. const Array <Component*> tempComps (components);
  49650. components.clear();
  49651. for (int i = 0; i < tempComps.size(); ++i)
  49652. {
  49653. Component* const c = tempComps.getUnchecked(i);
  49654. addDocument (c,
  49655. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49656. shouldDeleteComp (c));
  49657. }
  49658. }
  49659. }
  49660. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49661. {
  49662. if (backgroundColour != newBackgroundColour)
  49663. {
  49664. backgroundColour = newBackgroundColour;
  49665. setOpaque (newBackgroundColour.isOpaque());
  49666. repaint();
  49667. }
  49668. }
  49669. void MultiDocumentPanel::paint (Graphics& g)
  49670. {
  49671. g.fillAll (backgroundColour);
  49672. }
  49673. void MultiDocumentPanel::resized()
  49674. {
  49675. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49676. {
  49677. for (int i = getNumChildComponents(); --i >= 0;)
  49678. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49679. }
  49680. setWantsKeyboardFocus (components.size() == 0);
  49681. }
  49682. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49683. {
  49684. if (mode == FloatingWindows)
  49685. {
  49686. for (int i = 0; i < getNumChildComponents(); ++i)
  49687. {
  49688. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49689. if (dw != 0 && dw->getContentComponent() == c)
  49690. {
  49691. c = dw;
  49692. break;
  49693. }
  49694. }
  49695. }
  49696. return c;
  49697. }
  49698. void MultiDocumentPanel::componentNameChanged (Component&)
  49699. {
  49700. if (mode == FloatingWindows)
  49701. {
  49702. for (int i = 0; i < getNumChildComponents(); ++i)
  49703. {
  49704. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49705. if (dw != 0)
  49706. dw->setName (dw->getContentComponent()->getName());
  49707. }
  49708. }
  49709. else if (tabComponent != 0)
  49710. {
  49711. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49712. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49713. }
  49714. }
  49715. void MultiDocumentPanel::updateOrder()
  49716. {
  49717. const Array <Component*> oldList (components);
  49718. if (mode == FloatingWindows)
  49719. {
  49720. components.clear();
  49721. for (int i = 0; i < getNumChildComponents(); ++i)
  49722. {
  49723. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49724. if (dw != 0)
  49725. components.add (dw->getContentComponent());
  49726. }
  49727. }
  49728. else
  49729. {
  49730. if (tabComponent != 0)
  49731. {
  49732. Component* const current = tabComponent->getCurrentContentComponent();
  49733. if (current != 0)
  49734. {
  49735. components.removeValue (current);
  49736. components.add (current);
  49737. }
  49738. }
  49739. }
  49740. if (components != oldList)
  49741. activeDocumentChanged();
  49742. }
  49743. END_JUCE_NAMESPACE
  49744. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49745. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49746. BEGIN_JUCE_NAMESPACE
  49747. const int zoneL = 1;
  49748. const int zoneR = 2;
  49749. const int zoneT = 4;
  49750. const int zoneB = 8;
  49751. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49752. ComponentBoundsConstrainer* const constrainer_)
  49753. : component (componentToResize),
  49754. constrainer (constrainer_),
  49755. borderSize (5),
  49756. mouseZone (0)
  49757. {
  49758. }
  49759. ResizableBorderComponent::~ResizableBorderComponent()
  49760. {
  49761. }
  49762. void ResizableBorderComponent::paint (Graphics& g)
  49763. {
  49764. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49765. }
  49766. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49767. {
  49768. updateMouseZone (e);
  49769. }
  49770. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49771. {
  49772. updateMouseZone (e);
  49773. }
  49774. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49775. {
  49776. if (component->isValidComponent())
  49777. {
  49778. updateMouseZone (e);
  49779. originalX = component->getX();
  49780. originalY = component->getY();
  49781. originalW = component->getWidth();
  49782. originalH = component->getHeight();
  49783. if (constrainer != 0)
  49784. constrainer->resizeStart();
  49785. }
  49786. else
  49787. {
  49788. jassertfalse
  49789. }
  49790. }
  49791. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49792. {
  49793. if (! component->isValidComponent())
  49794. {
  49795. jassertfalse
  49796. return;
  49797. }
  49798. int x = originalX;
  49799. int y = originalY;
  49800. int w = originalW;
  49801. int h = originalH;
  49802. const int dx = e.getDistanceFromDragStartX();
  49803. const int dy = e.getDistanceFromDragStartY();
  49804. if ((mouseZone & zoneL) != 0)
  49805. {
  49806. x += dx;
  49807. w -= dx;
  49808. }
  49809. if ((mouseZone & zoneT) != 0)
  49810. {
  49811. y += dy;
  49812. h -= dy;
  49813. }
  49814. if ((mouseZone & zoneR) != 0)
  49815. w += dx;
  49816. if ((mouseZone & zoneB) != 0)
  49817. h += dy;
  49818. if (constrainer != 0)
  49819. constrainer->setBoundsForComponent (component,
  49820. x, y, w, h,
  49821. (mouseZone & zoneT) != 0,
  49822. (mouseZone & zoneL) != 0,
  49823. (mouseZone & zoneB) != 0,
  49824. (mouseZone & zoneR) != 0);
  49825. else
  49826. component->setBounds (x, y, w, h);
  49827. }
  49828. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49829. {
  49830. if (constrainer != 0)
  49831. constrainer->resizeEnd();
  49832. }
  49833. bool ResizableBorderComponent::hitTest (int x, int y)
  49834. {
  49835. return x < borderSize.getLeft()
  49836. || x >= getWidth() - borderSize.getRight()
  49837. || y < borderSize.getTop()
  49838. || y >= getHeight() - borderSize.getBottom();
  49839. }
  49840. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49841. {
  49842. if (borderSize != newBorderSize)
  49843. {
  49844. borderSize = newBorderSize;
  49845. repaint();
  49846. }
  49847. }
  49848. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49849. {
  49850. return borderSize;
  49851. }
  49852. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49853. {
  49854. int newZone = 0;
  49855. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49856. {
  49857. if (e.x < jmax (borderSize.getLeft(),
  49858. proportionOfWidth (0.1f),
  49859. jmin (10, proportionOfWidth (0.33f))))
  49860. newZone |= zoneL;
  49861. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49862. proportionOfWidth (0.9f),
  49863. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49864. newZone |= zoneR;
  49865. if (e.y < jmax (borderSize.getTop(),
  49866. proportionOfHeight (0.1f),
  49867. jmin (10, proportionOfHeight (0.33f))))
  49868. newZone |= zoneT;
  49869. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49870. proportionOfHeight (0.9f),
  49871. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49872. newZone |= zoneB;
  49873. }
  49874. if (mouseZone != newZone)
  49875. {
  49876. mouseZone = newZone;
  49877. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49878. switch (newZone)
  49879. {
  49880. case (zoneL | zoneT):
  49881. mc = MouseCursor::TopLeftCornerResizeCursor;
  49882. break;
  49883. case zoneT:
  49884. mc = MouseCursor::TopEdgeResizeCursor;
  49885. break;
  49886. case (zoneR | zoneT):
  49887. mc = MouseCursor::TopRightCornerResizeCursor;
  49888. break;
  49889. case zoneL:
  49890. mc = MouseCursor::LeftEdgeResizeCursor;
  49891. break;
  49892. case zoneR:
  49893. mc = MouseCursor::RightEdgeResizeCursor;
  49894. break;
  49895. case (zoneL | zoneB):
  49896. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49897. break;
  49898. case zoneB:
  49899. mc = MouseCursor::BottomEdgeResizeCursor;
  49900. break;
  49901. case (zoneR | zoneB):
  49902. mc = MouseCursor::BottomRightCornerResizeCursor;
  49903. break;
  49904. default:
  49905. break;
  49906. }
  49907. setMouseCursor (mc);
  49908. }
  49909. }
  49910. END_JUCE_NAMESPACE
  49911. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49912. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49913. BEGIN_JUCE_NAMESPACE
  49914. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49915. ComponentBoundsConstrainer* const constrainer_)
  49916. : component (componentToResize),
  49917. constrainer (constrainer_)
  49918. {
  49919. setRepaintsOnMouseActivity (true);
  49920. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49921. }
  49922. ResizableCornerComponent::~ResizableCornerComponent()
  49923. {
  49924. }
  49925. void ResizableCornerComponent::paint (Graphics& g)
  49926. {
  49927. getLookAndFeel()
  49928. .drawCornerResizer (g, getWidth(), getHeight(),
  49929. isMouseOverOrDragging(),
  49930. isMouseButtonDown());
  49931. }
  49932. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49933. {
  49934. if (component->isValidComponent())
  49935. {
  49936. originalX = component->getX();
  49937. originalY = component->getY();
  49938. originalW = component->getWidth();
  49939. originalH = component->getHeight();
  49940. if (constrainer != 0)
  49941. constrainer->resizeStart();
  49942. }
  49943. else
  49944. {
  49945. jassertfalse
  49946. }
  49947. }
  49948. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49949. {
  49950. if (! component->isValidComponent())
  49951. {
  49952. jassertfalse
  49953. return;
  49954. }
  49955. int x = originalX;
  49956. int y = originalY;
  49957. int w = originalW + e.getDistanceFromDragStartX();
  49958. int h = originalH + e.getDistanceFromDragStartY();
  49959. if (constrainer != 0)
  49960. constrainer->setBoundsForComponent (component, x, y, w, h,
  49961. false, false, true, true);
  49962. else
  49963. component->setBounds (x, y, w, h);
  49964. }
  49965. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49966. {
  49967. if (constrainer != 0)
  49968. constrainer->resizeStart();
  49969. }
  49970. bool ResizableCornerComponent::hitTest (int x, int y)
  49971. {
  49972. if (getWidth() <= 0)
  49973. return false;
  49974. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49975. return y >= yAtX - getHeight() / 4;
  49976. }
  49977. END_JUCE_NAMESPACE
  49978. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49979. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49980. BEGIN_JUCE_NAMESPACE
  49981. class ScrollbarButton : public Button
  49982. {
  49983. public:
  49984. int direction;
  49985. ScrollbarButton (const int direction_,
  49986. ScrollBar& owner_) throw()
  49987. : Button (String::empty),
  49988. direction (direction_),
  49989. owner (owner_)
  49990. {
  49991. setWantsKeyboardFocus (false);
  49992. }
  49993. ~ScrollbarButton()
  49994. {
  49995. }
  49996. void paintButton (Graphics& g,
  49997. bool isMouseOver,
  49998. bool isMouseDown)
  49999. {
  50000. getLookAndFeel()
  50001. .drawScrollbarButton (g, owner,
  50002. getWidth(), getHeight(),
  50003. direction,
  50004. owner.isVertical(),
  50005. isMouseOver, isMouseDown);
  50006. }
  50007. void clicked()
  50008. {
  50009. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  50010. }
  50011. juce_UseDebuggingNewOperator
  50012. private:
  50013. ScrollBar& owner;
  50014. ScrollbarButton (const ScrollbarButton&);
  50015. const ScrollbarButton& operator= (const ScrollbarButton&);
  50016. };
  50017. ScrollBar::ScrollBar (const bool vertical_,
  50018. const bool buttonsAreVisible)
  50019. : minimum (0.0),
  50020. maximum (1.0),
  50021. rangeStart (0.0),
  50022. rangeSize (0.1),
  50023. singleStepSize (0.1),
  50024. thumbAreaStart (0),
  50025. thumbAreaSize (0),
  50026. thumbStart (0),
  50027. thumbSize (0),
  50028. initialDelayInMillisecs (100),
  50029. repeatDelayInMillisecs (50),
  50030. minimumDelayInMillisecs (10),
  50031. vertical (vertical_),
  50032. isDraggingThumb (false),
  50033. alwaysVisible (false),
  50034. upButton (0),
  50035. downButton (0)
  50036. {
  50037. setButtonVisibility (buttonsAreVisible);
  50038. setRepaintsOnMouseActivity (true);
  50039. setFocusContainer (true);
  50040. }
  50041. ScrollBar::~ScrollBar()
  50042. {
  50043. deleteAllChildren();
  50044. }
  50045. void ScrollBar::setRangeLimits (const double newMinimum,
  50046. const double newMaximum) throw()
  50047. {
  50048. minimum = newMinimum;
  50049. maximum = newMaximum;
  50050. jassert (maximum >= minimum); // these can't be the wrong way round!
  50051. setCurrentRangeStart (rangeStart);
  50052. updateThumbPosition();
  50053. }
  50054. void ScrollBar::setCurrentRange (double newStart,
  50055. double newSize) throw()
  50056. {
  50057. newSize = jlimit (0.0, maximum - minimum, newSize);
  50058. newStart = jlimit (minimum, maximum - newSize, newStart);
  50059. if (rangeStart != newStart
  50060. || rangeSize != newSize)
  50061. {
  50062. rangeStart = newStart;
  50063. rangeSize = newSize;
  50064. updateThumbPosition();
  50065. triggerAsyncUpdate();
  50066. }
  50067. }
  50068. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  50069. {
  50070. setCurrentRange (newStart, rangeSize);
  50071. }
  50072. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  50073. {
  50074. singleStepSize = newSingleStepSize;
  50075. }
  50076. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  50077. {
  50078. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  50079. }
  50080. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  50081. {
  50082. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  50083. }
  50084. void ScrollBar::scrollToTop() throw()
  50085. {
  50086. setCurrentRangeStart (minimum);
  50087. }
  50088. void ScrollBar::scrollToBottom() throw()
  50089. {
  50090. setCurrentRangeStart (maximum - rangeSize);
  50091. }
  50092. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  50093. const int repeatDelayInMillisecs_,
  50094. const int minimumDelayInMillisecs_) throw()
  50095. {
  50096. initialDelayInMillisecs = initialDelayInMillisecs_;
  50097. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  50098. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  50099. if (upButton != 0)
  50100. {
  50101. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50102. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50103. }
  50104. }
  50105. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  50106. {
  50107. jassert (listener != 0);
  50108. if (listener != 0)
  50109. listeners.add (listener);
  50110. }
  50111. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  50112. {
  50113. listeners.removeValue (listener);
  50114. }
  50115. void ScrollBar::handleAsyncUpdate()
  50116. {
  50117. const double value = getCurrentRangeStart();
  50118. for (int i = listeners.size(); --i >= 0;)
  50119. {
  50120. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  50121. i = jmin (i, listeners.size());
  50122. }
  50123. }
  50124. void ScrollBar::updateThumbPosition() throw()
  50125. {
  50126. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50127. : thumbAreaSize);
  50128. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50129. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50130. if (newThumbSize > thumbAreaSize)
  50131. newThumbSize = thumbAreaSize;
  50132. int newThumbStart = thumbAreaStart;
  50133. if (maximum - minimum > rangeSize)
  50134. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50135. / ((maximum - minimum) - rangeSize));
  50136. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50137. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50138. {
  50139. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50140. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50141. if (vertical)
  50142. repaint (0, repaintStart, getWidth(), repaintSize);
  50143. else
  50144. repaint (repaintStart, 0, repaintSize, getHeight());
  50145. thumbStart = newThumbStart;
  50146. thumbSize = newThumbSize;
  50147. }
  50148. }
  50149. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50150. {
  50151. if (vertical != shouldBeVertical)
  50152. {
  50153. vertical = shouldBeVertical;
  50154. if (upButton != 0)
  50155. {
  50156. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50157. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50158. }
  50159. updateThumbPosition();
  50160. }
  50161. }
  50162. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50163. {
  50164. deleteAndZero (upButton);
  50165. deleteAndZero (downButton);
  50166. if (buttonsAreVisible)
  50167. {
  50168. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50169. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50170. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50171. }
  50172. updateThumbPosition();
  50173. }
  50174. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50175. {
  50176. alwaysVisible = ! shouldHideWhenFullRange;
  50177. updateThumbPosition();
  50178. }
  50179. void ScrollBar::paint (Graphics& g)
  50180. {
  50181. if (thumbAreaSize > 0)
  50182. {
  50183. LookAndFeel& lf = getLookAndFeel();
  50184. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50185. ? thumbSize : 0;
  50186. if (vertical)
  50187. {
  50188. lf.drawScrollbar (g, *this,
  50189. 0, thumbAreaStart,
  50190. getWidth(), thumbAreaSize,
  50191. vertical,
  50192. thumbStart, thumb,
  50193. isMouseOver(), isMouseButtonDown());
  50194. }
  50195. else
  50196. {
  50197. lf.drawScrollbar (g, *this,
  50198. thumbAreaStart, 0,
  50199. thumbAreaSize, getHeight(),
  50200. vertical,
  50201. thumbStart, thumb,
  50202. isMouseOver(), isMouseButtonDown());
  50203. }
  50204. }
  50205. }
  50206. void ScrollBar::lookAndFeelChanged()
  50207. {
  50208. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50209. }
  50210. void ScrollBar::resized()
  50211. {
  50212. const int length = ((vertical) ? getHeight() : getWidth());
  50213. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50214. : 0;
  50215. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50216. {
  50217. thumbAreaStart = length >> 1;
  50218. thumbAreaSize = 0;
  50219. }
  50220. else
  50221. {
  50222. thumbAreaStart = buttonSize;
  50223. thumbAreaSize = length - (buttonSize << 1);
  50224. }
  50225. if (upButton != 0)
  50226. {
  50227. if (vertical)
  50228. {
  50229. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50230. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50231. }
  50232. else
  50233. {
  50234. upButton->setBounds (0, 0, buttonSize, getHeight());
  50235. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50236. }
  50237. }
  50238. updateThumbPosition();
  50239. }
  50240. void ScrollBar::mouseDown (const MouseEvent& e)
  50241. {
  50242. isDraggingThumb = false;
  50243. lastMousePos = vertical ? e.y : e.x;
  50244. dragStartMousePos = lastMousePos;
  50245. dragStartRange = rangeStart;
  50246. if (dragStartMousePos < thumbStart)
  50247. {
  50248. moveScrollbarInPages (-1);
  50249. startTimer (400);
  50250. }
  50251. else if (dragStartMousePos >= thumbStart + thumbSize)
  50252. {
  50253. moveScrollbarInPages (1);
  50254. startTimer (400);
  50255. }
  50256. else
  50257. {
  50258. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50259. && (thumbAreaSize > thumbSize);
  50260. }
  50261. }
  50262. void ScrollBar::mouseDrag (const MouseEvent& e)
  50263. {
  50264. if (isDraggingThumb)
  50265. {
  50266. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50267. setCurrentRangeStart (dragStartRange
  50268. + deltaPixels * ((maximum - minimum) - rangeSize)
  50269. / (thumbAreaSize - thumbSize));
  50270. }
  50271. else
  50272. {
  50273. lastMousePos = (vertical) ? e.y : e.x;
  50274. }
  50275. }
  50276. void ScrollBar::mouseUp (const MouseEvent&)
  50277. {
  50278. isDraggingThumb = false;
  50279. stopTimer();
  50280. repaint();
  50281. }
  50282. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50283. float wheelIncrementX,
  50284. float wheelIncrementY)
  50285. {
  50286. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50287. if (increment < 0)
  50288. increment = jmin (increment * 10.0f, -1.0f);
  50289. else if (increment > 0)
  50290. increment = jmax (increment * 10.0f, 1.0f);
  50291. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50292. }
  50293. void ScrollBar::timerCallback()
  50294. {
  50295. if (isMouseButtonDown())
  50296. {
  50297. startTimer (40);
  50298. if (lastMousePos < thumbStart)
  50299. setCurrentRangeStart (rangeStart - rangeSize);
  50300. else if (lastMousePos > thumbStart + thumbSize)
  50301. setCurrentRangeStart (rangeStart + rangeSize);
  50302. }
  50303. else
  50304. {
  50305. stopTimer();
  50306. }
  50307. }
  50308. bool ScrollBar::keyPressed (const KeyPress& key)
  50309. {
  50310. if (! isVisible())
  50311. return false;
  50312. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50313. moveScrollbarInSteps (-1);
  50314. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50315. moveScrollbarInSteps (1);
  50316. else if (key.isKeyCode (KeyPress::pageUpKey))
  50317. moveScrollbarInPages (-1);
  50318. else if (key.isKeyCode (KeyPress::pageDownKey))
  50319. moveScrollbarInPages (1);
  50320. else if (key.isKeyCode (KeyPress::homeKey))
  50321. scrollToTop();
  50322. else if (key.isKeyCode (KeyPress::endKey))
  50323. scrollToBottom();
  50324. else
  50325. return false;
  50326. return true;
  50327. }
  50328. END_JUCE_NAMESPACE
  50329. /*** End of inlined file: juce_ScrollBar.cpp ***/
  50330. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  50331. BEGIN_JUCE_NAMESPACE
  50332. StretchableLayoutManager::StretchableLayoutManager()
  50333. : totalSize (0)
  50334. {
  50335. }
  50336. StretchableLayoutManager::~StretchableLayoutManager()
  50337. {
  50338. }
  50339. void StretchableLayoutManager::clearAllItems()
  50340. {
  50341. items.clear();
  50342. totalSize = 0;
  50343. }
  50344. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50345. const double minimumSize,
  50346. const double maximumSize,
  50347. const double preferredSize)
  50348. {
  50349. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50350. if (layout == 0)
  50351. {
  50352. layout = new ItemLayoutProperties();
  50353. layout->itemIndex = itemIndex;
  50354. int i;
  50355. for (i = 0; i < items.size(); ++i)
  50356. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50357. break;
  50358. items.insert (i, layout);
  50359. }
  50360. layout->minSize = minimumSize;
  50361. layout->maxSize = maximumSize;
  50362. layout->preferredSize = preferredSize;
  50363. layout->currentSize = 0;
  50364. }
  50365. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50366. double& minimumSize,
  50367. double& maximumSize,
  50368. double& preferredSize) const
  50369. {
  50370. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50371. if (layout != 0)
  50372. {
  50373. minimumSize = layout->minSize;
  50374. maximumSize = layout->maxSize;
  50375. preferredSize = layout->preferredSize;
  50376. return true;
  50377. }
  50378. return false;
  50379. }
  50380. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50381. {
  50382. totalSize = newTotalSize;
  50383. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50384. }
  50385. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50386. {
  50387. int pos = 0;
  50388. for (int i = 0; i < itemIndex; ++i)
  50389. {
  50390. const ItemLayoutProperties* const layout = getInfoFor (i);
  50391. if (layout != 0)
  50392. pos += layout->currentSize;
  50393. }
  50394. return pos;
  50395. }
  50396. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50397. {
  50398. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50399. if (layout != 0)
  50400. return layout->currentSize;
  50401. return 0;
  50402. }
  50403. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50404. {
  50405. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50406. if (layout != 0)
  50407. return -layout->currentSize / (double) totalSize;
  50408. return 0;
  50409. }
  50410. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50411. int newPosition)
  50412. {
  50413. for (int i = items.size(); --i >= 0;)
  50414. {
  50415. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50416. if (layout->itemIndex == itemIndex)
  50417. {
  50418. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50419. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50420. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50421. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50422. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50423. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50424. endPos += layout->currentSize;
  50425. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50426. updatePrefSizesToMatchCurrentPositions();
  50427. break;
  50428. }
  50429. }
  50430. }
  50431. void StretchableLayoutManager::layOutComponents (Component** const components,
  50432. int numComponents,
  50433. int x, int y, int w, int h,
  50434. const bool vertically,
  50435. const bool resizeOtherDimension)
  50436. {
  50437. setTotalSize (vertically ? h : w);
  50438. int pos = vertically ? y : x;
  50439. for (int i = 0; i < numComponents; ++i)
  50440. {
  50441. const ItemLayoutProperties* const layout = getInfoFor (i);
  50442. if (layout != 0)
  50443. {
  50444. Component* const c = components[i];
  50445. if (c != 0)
  50446. {
  50447. if (i == numComponents - 1)
  50448. {
  50449. // if it's the last item, crop it to exactly fit the available space..
  50450. if (resizeOtherDimension)
  50451. {
  50452. if (vertically)
  50453. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50454. else
  50455. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50456. }
  50457. else
  50458. {
  50459. if (vertically)
  50460. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50461. else
  50462. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50463. }
  50464. }
  50465. else
  50466. {
  50467. if (resizeOtherDimension)
  50468. {
  50469. if (vertically)
  50470. c->setBounds (x, pos, w, layout->currentSize);
  50471. else
  50472. c->setBounds (pos, y, layout->currentSize, h);
  50473. }
  50474. else
  50475. {
  50476. if (vertically)
  50477. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50478. else
  50479. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50480. }
  50481. }
  50482. }
  50483. pos += layout->currentSize;
  50484. }
  50485. }
  50486. }
  50487. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50488. {
  50489. for (int i = items.size(); --i >= 0;)
  50490. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50491. return items.getUnchecked(i);
  50492. return 0;
  50493. }
  50494. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50495. const int endIndex,
  50496. const int availableSpace,
  50497. int startPos)
  50498. {
  50499. // calculate the total sizes
  50500. int i;
  50501. double totalIdealSize = 0.0;
  50502. int totalMinimums = 0;
  50503. for (i = startIndex; i < endIndex; ++i)
  50504. {
  50505. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50506. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50507. totalMinimums += layout->currentSize;
  50508. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50509. }
  50510. if (totalIdealSize <= 0)
  50511. totalIdealSize = 1.0;
  50512. // now calc the best sizes..
  50513. int extraSpace = availableSpace - totalMinimums;
  50514. while (extraSpace > 0)
  50515. {
  50516. int numWantingMoreSpace = 0;
  50517. int numHavingTakenExtraSpace = 0;
  50518. // first figure out how many comps want a slice of the extra space..
  50519. for (i = startIndex; i < endIndex; ++i)
  50520. {
  50521. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50522. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50523. const int bestSize = jlimit (layout->currentSize,
  50524. jmax (layout->currentSize,
  50525. sizeToRealSize (layout->maxSize, totalSize)),
  50526. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50527. if (bestSize > layout->currentSize)
  50528. ++numWantingMoreSpace;
  50529. }
  50530. // ..share out the extra space..
  50531. for (i = startIndex; i < endIndex; ++i)
  50532. {
  50533. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50534. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50535. int bestSize = jlimit (layout->currentSize,
  50536. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50537. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50538. const int extraWanted = bestSize - layout->currentSize;
  50539. if (extraWanted > 0)
  50540. {
  50541. const int extraAllowed = jmin (extraWanted,
  50542. extraSpace / jmax (1, numWantingMoreSpace));
  50543. if (extraAllowed > 0)
  50544. {
  50545. ++numHavingTakenExtraSpace;
  50546. --numWantingMoreSpace;
  50547. layout->currentSize += extraAllowed;
  50548. extraSpace -= extraAllowed;
  50549. }
  50550. }
  50551. }
  50552. if (numHavingTakenExtraSpace <= 0)
  50553. break;
  50554. }
  50555. // ..and calculate the end position
  50556. for (i = startIndex; i < endIndex; ++i)
  50557. {
  50558. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50559. startPos += layout->currentSize;
  50560. }
  50561. return startPos;
  50562. }
  50563. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50564. const int endIndex) const
  50565. {
  50566. int totalMinimums = 0;
  50567. for (int i = startIndex; i < endIndex; ++i)
  50568. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50569. return totalMinimums;
  50570. }
  50571. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50572. {
  50573. int totalMaximums = 0;
  50574. for (int i = startIndex; i < endIndex; ++i)
  50575. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50576. return totalMaximums;
  50577. }
  50578. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50579. {
  50580. for (int i = 0; i < items.size(); ++i)
  50581. {
  50582. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50583. layout->preferredSize
  50584. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50585. : getItemCurrentAbsoluteSize (i);
  50586. }
  50587. }
  50588. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50589. {
  50590. if (size < 0)
  50591. size *= -totalSpace;
  50592. return roundToInt (size);
  50593. }
  50594. END_JUCE_NAMESPACE
  50595. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50596. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50597. BEGIN_JUCE_NAMESPACE
  50598. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50599. const int itemIndex_,
  50600. const bool isVertical_)
  50601. : layout (layout_),
  50602. itemIndex (itemIndex_),
  50603. isVertical (isVertical_)
  50604. {
  50605. setRepaintsOnMouseActivity (true);
  50606. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50607. : MouseCursor::UpDownResizeCursor));
  50608. }
  50609. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50610. {
  50611. }
  50612. void StretchableLayoutResizerBar::paint (Graphics& g)
  50613. {
  50614. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50615. getWidth(), getHeight(),
  50616. isVertical,
  50617. isMouseOver(),
  50618. isMouseButtonDown());
  50619. }
  50620. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50621. {
  50622. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50623. }
  50624. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50625. {
  50626. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50627. : e.getDistanceFromDragStartY());
  50628. layout->setItemPosition (itemIndex, desiredPos);
  50629. hasBeenMoved();
  50630. }
  50631. void StretchableLayoutResizerBar::hasBeenMoved()
  50632. {
  50633. if (getParentComponent() != 0)
  50634. getParentComponent()->resized();
  50635. }
  50636. END_JUCE_NAMESPACE
  50637. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50638. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50639. BEGIN_JUCE_NAMESPACE
  50640. StretchableObjectResizer::StretchableObjectResizer()
  50641. {
  50642. }
  50643. StretchableObjectResizer::~StretchableObjectResizer()
  50644. {
  50645. }
  50646. void StretchableObjectResizer::addItem (const double size,
  50647. const double minSize, const double maxSize,
  50648. const int order)
  50649. {
  50650. // the order must be >= 0 but less than the maximum integer value.
  50651. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50652. Item* const item = new Item();
  50653. item->size = size;
  50654. item->minSize = minSize;
  50655. item->maxSize = maxSize;
  50656. item->order = order;
  50657. items.add (item);
  50658. }
  50659. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50660. {
  50661. const Item* const it = items [index];
  50662. return it != 0 ? it->size : 0;
  50663. }
  50664. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50665. {
  50666. int order = 0;
  50667. for (;;)
  50668. {
  50669. double currentSize = 0;
  50670. double minSize = 0;
  50671. double maxSize = 0;
  50672. int nextHighestOrder = std::numeric_limits<int>::max();
  50673. for (int i = 0; i < items.size(); ++i)
  50674. {
  50675. const Item* const it = items.getUnchecked(i);
  50676. currentSize += it->size;
  50677. if (it->order <= order)
  50678. {
  50679. minSize += it->minSize;
  50680. maxSize += it->maxSize;
  50681. }
  50682. else
  50683. {
  50684. minSize += it->size;
  50685. maxSize += it->size;
  50686. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50687. }
  50688. }
  50689. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50690. if (thisIterationTarget >= currentSize)
  50691. {
  50692. const double availableExtraSpace = maxSize - currentSize;
  50693. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50694. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50695. for (int i = 0; i < items.size(); ++i)
  50696. {
  50697. Item* const it = items.getUnchecked(i);
  50698. if (it->order <= order)
  50699. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50700. }
  50701. }
  50702. else
  50703. {
  50704. const double amountOfSlack = currentSize - minSize;
  50705. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50706. const double scale = targetAmountOfSlack / amountOfSlack;
  50707. for (int i = 0; i < items.size(); ++i)
  50708. {
  50709. Item* const it = items.getUnchecked(i);
  50710. if (it->order <= order)
  50711. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50712. }
  50713. }
  50714. if (nextHighestOrder < std::numeric_limits<int>::max())
  50715. order = nextHighestOrder;
  50716. else
  50717. break;
  50718. }
  50719. }
  50720. END_JUCE_NAMESPACE
  50721. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50722. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50723. BEGIN_JUCE_NAMESPACE
  50724. TabBarButton::TabBarButton (const String& name,
  50725. TabbedButtonBar* const owner_,
  50726. const int index)
  50727. : Button (name),
  50728. owner (owner_),
  50729. tabIndex (index),
  50730. overlapPixels (0)
  50731. {
  50732. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50733. setComponentEffect (&shadow);
  50734. setWantsKeyboardFocus (false);
  50735. }
  50736. TabBarButton::~TabBarButton()
  50737. {
  50738. }
  50739. void TabBarButton::paintButton (Graphics& g,
  50740. bool isMouseOverButton,
  50741. bool isButtonDown)
  50742. {
  50743. int x, y, w, h;
  50744. getActiveArea (x, y, w, h);
  50745. g.setOrigin (x, y);
  50746. getLookAndFeel()
  50747. .drawTabButton (g, w, h,
  50748. owner->getTabBackgroundColour (tabIndex),
  50749. tabIndex, getButtonText(), *this,
  50750. owner->getOrientation(),
  50751. isMouseOverButton, isButtonDown,
  50752. getToggleState());
  50753. }
  50754. void TabBarButton::clicked (const ModifierKeys& mods)
  50755. {
  50756. if (mods.isPopupMenu())
  50757. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50758. else
  50759. owner->setCurrentTabIndex (tabIndex);
  50760. }
  50761. bool TabBarButton::hitTest (int mx, int my)
  50762. {
  50763. int x, y, w, h;
  50764. getActiveArea (x, y, w, h);
  50765. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50766. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50767. {
  50768. if (((unsigned int) mx) < (unsigned int) getWidth()
  50769. && my >= y + overlapPixels
  50770. && my < y + h - overlapPixels)
  50771. return true;
  50772. }
  50773. else
  50774. {
  50775. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50776. && ((unsigned int) my) < (unsigned int) getHeight())
  50777. return true;
  50778. }
  50779. Path p;
  50780. getLookAndFeel()
  50781. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50782. owner->getOrientation(),
  50783. false, false, getToggleState());
  50784. return p.contains ((float) (mx - x),
  50785. (float) (my - y));
  50786. }
  50787. int TabBarButton::getBestTabLength (const int depth)
  50788. {
  50789. return jlimit (depth * 2,
  50790. depth * 7,
  50791. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50792. }
  50793. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50794. {
  50795. x = 0;
  50796. y = 0;
  50797. int r = getWidth();
  50798. int b = getHeight();
  50799. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50800. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50801. r -= spaceAroundImage;
  50802. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50803. x += spaceAroundImage;
  50804. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50805. y += spaceAroundImage;
  50806. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50807. b -= spaceAroundImage;
  50808. w = r - x;
  50809. h = b - y;
  50810. }
  50811. class TabAreaBehindFrontButtonComponent : public Component
  50812. {
  50813. public:
  50814. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50815. : owner (owner_)
  50816. {
  50817. setInterceptsMouseClicks (false, false);
  50818. }
  50819. ~TabAreaBehindFrontButtonComponent()
  50820. {
  50821. }
  50822. void paint (Graphics& g)
  50823. {
  50824. getLookAndFeel()
  50825. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50826. *owner, owner->getOrientation());
  50827. }
  50828. void enablementChanged()
  50829. {
  50830. repaint();
  50831. }
  50832. private:
  50833. TabbedButtonBar* const owner;
  50834. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50835. const TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50836. };
  50837. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50838. : orientation (orientation_),
  50839. currentTabIndex (-1),
  50840. extraTabsButton (0)
  50841. {
  50842. setInterceptsMouseClicks (false, true);
  50843. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50844. setFocusContainer (true);
  50845. }
  50846. TabbedButtonBar::~TabbedButtonBar()
  50847. {
  50848. deleteAllChildren();
  50849. }
  50850. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50851. {
  50852. orientation = newOrientation;
  50853. for (int i = getNumChildComponents(); --i >= 0;)
  50854. getChildComponent (i)->resized();
  50855. resized();
  50856. }
  50857. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50858. {
  50859. return new TabBarButton (name, this, index);
  50860. }
  50861. void TabbedButtonBar::clearTabs()
  50862. {
  50863. tabs.clear();
  50864. tabColours.clear();
  50865. currentTabIndex = -1;
  50866. deleteAndZero (extraTabsButton);
  50867. removeChildComponent (behindFrontTab);
  50868. deleteAllChildren();
  50869. addChildComponent (behindFrontTab);
  50870. setCurrentTabIndex (-1);
  50871. }
  50872. void TabbedButtonBar::addTab (const String& tabName,
  50873. const Colour& tabBackgroundColour,
  50874. int insertIndex)
  50875. {
  50876. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50877. if (tabName.isNotEmpty())
  50878. {
  50879. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50880. insertIndex = tabs.size();
  50881. for (int i = tabs.size(); --i >= insertIndex;)
  50882. {
  50883. TabBarButton* const tb = getTabButton (i);
  50884. if (tb != 0)
  50885. tb->tabIndex++;
  50886. }
  50887. tabs.insert (insertIndex, tabName);
  50888. tabColours.insert (insertIndex, tabBackgroundColour);
  50889. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50890. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50891. addAndMakeVisible (tb, insertIndex);
  50892. resized();
  50893. if (currentTabIndex < 0)
  50894. setCurrentTabIndex (0);
  50895. }
  50896. }
  50897. void TabbedButtonBar::setTabName (const int tabIndex,
  50898. const String& newName)
  50899. {
  50900. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50901. && tabs[tabIndex] != newName)
  50902. {
  50903. tabs.set (tabIndex, newName);
  50904. TabBarButton* const tb = getTabButton (tabIndex);
  50905. if (tb != 0)
  50906. tb->setButtonText (newName);
  50907. resized();
  50908. }
  50909. }
  50910. void TabbedButtonBar::removeTab (const int tabIndex)
  50911. {
  50912. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50913. {
  50914. const int oldTabIndex = currentTabIndex;
  50915. if (currentTabIndex == tabIndex)
  50916. currentTabIndex = -1;
  50917. tabs.remove (tabIndex);
  50918. tabColours.remove (tabIndex);
  50919. delete getTabButton (tabIndex);
  50920. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50921. {
  50922. TabBarButton* const tb = getTabButton (i);
  50923. if (tb != 0)
  50924. tb->tabIndex--;
  50925. }
  50926. resized();
  50927. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50928. }
  50929. }
  50930. void TabbedButtonBar::moveTab (const int currentIndex,
  50931. const int newIndex)
  50932. {
  50933. tabs.move (currentIndex, newIndex);
  50934. tabColours.move (currentIndex, newIndex);
  50935. resized();
  50936. }
  50937. int TabbedButtonBar::getNumTabs() const
  50938. {
  50939. return tabs.size();
  50940. }
  50941. const StringArray TabbedButtonBar::getTabNames() const
  50942. {
  50943. return tabs;
  50944. }
  50945. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50946. {
  50947. if (currentTabIndex != newIndex)
  50948. {
  50949. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50950. newIndex = -1;
  50951. currentTabIndex = newIndex;
  50952. for (int i = 0; i < getNumChildComponents(); ++i)
  50953. {
  50954. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50955. if (tb != 0)
  50956. tb->setToggleState (tb->tabIndex == newIndex, false);
  50957. }
  50958. resized();
  50959. if (sendChangeMessage_)
  50960. sendChangeMessage (this);
  50961. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50962. }
  50963. }
  50964. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50965. {
  50966. for (int i = getNumChildComponents(); --i >= 0;)
  50967. {
  50968. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50969. if (tb != 0 && tb->tabIndex == index)
  50970. return tb;
  50971. }
  50972. return 0;
  50973. }
  50974. void TabbedButtonBar::lookAndFeelChanged()
  50975. {
  50976. deleteAndZero (extraTabsButton);
  50977. resized();
  50978. }
  50979. void TabbedButtonBar::resized()
  50980. {
  50981. const double minimumScale = 0.7;
  50982. int depth = getWidth();
  50983. int length = getHeight();
  50984. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50985. swapVariables (depth, length);
  50986. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50987. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50988. int i, totalLength = overlap;
  50989. int numVisibleButtons = tabs.size();
  50990. for (i = 0; i < getNumChildComponents(); ++i)
  50991. {
  50992. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50993. if (tb != 0)
  50994. {
  50995. totalLength += tb->getBestTabLength (depth) - overlap;
  50996. tb->overlapPixels = overlap / 2;
  50997. }
  50998. }
  50999. double scale = 1.0;
  51000. if (totalLength > length)
  51001. scale = jmax (minimumScale, length / (double) totalLength);
  51002. const bool isTooBig = totalLength * scale > length;
  51003. int tabsButtonPos = 0;
  51004. if (isTooBig)
  51005. {
  51006. if (extraTabsButton == 0)
  51007. {
  51008. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  51009. extraTabsButton->addButtonListener (this);
  51010. extraTabsButton->setAlwaysOnTop (true);
  51011. extraTabsButton->setTriggeredOnMouseDown (true);
  51012. }
  51013. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  51014. extraTabsButton->setSize (buttonSize, buttonSize);
  51015. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51016. {
  51017. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  51018. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  51019. }
  51020. else
  51021. {
  51022. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  51023. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  51024. }
  51025. totalLength = 0;
  51026. for (i = 0; i < tabs.size(); ++i)
  51027. {
  51028. TabBarButton* const tb = getTabButton (i);
  51029. if (tb != 0)
  51030. {
  51031. const int newLength = totalLength + tb->getBestTabLength (depth);
  51032. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  51033. {
  51034. totalLength += overlap;
  51035. break;
  51036. }
  51037. numVisibleButtons = i + 1;
  51038. totalLength = newLength - overlap;
  51039. }
  51040. }
  51041. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  51042. }
  51043. else
  51044. {
  51045. deleteAndZero (extraTabsButton);
  51046. }
  51047. int pos = 0;
  51048. TabBarButton* frontTab = 0;
  51049. for (i = 0; i < tabs.size(); ++i)
  51050. {
  51051. TabBarButton* const tb = getTabButton (i);
  51052. if (tb != 0)
  51053. {
  51054. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  51055. if (i < numVisibleButtons)
  51056. {
  51057. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51058. tb->setBounds (pos, 0, bestLength, getHeight());
  51059. else
  51060. tb->setBounds (0, pos, getWidth(), bestLength);
  51061. tb->toBack();
  51062. if (tb->tabIndex == currentTabIndex)
  51063. frontTab = tb;
  51064. tb->setVisible (true);
  51065. }
  51066. else
  51067. {
  51068. tb->setVisible (false);
  51069. }
  51070. pos += bestLength - overlap;
  51071. }
  51072. }
  51073. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  51074. if (frontTab != 0)
  51075. {
  51076. frontTab->toFront (false);
  51077. behindFrontTab->toBehind (frontTab);
  51078. }
  51079. }
  51080. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  51081. {
  51082. return tabColours [tabIndex];
  51083. }
  51084. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51085. {
  51086. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  51087. && tabColours [tabIndex] != newColour)
  51088. {
  51089. tabColours.set (tabIndex, newColour);
  51090. repaint();
  51091. }
  51092. }
  51093. void TabbedButtonBar::buttonClicked (Button* button)
  51094. {
  51095. if (extraTabsButton == button)
  51096. {
  51097. PopupMenu m;
  51098. for (int i = 0; i < tabs.size(); ++i)
  51099. {
  51100. TabBarButton* const tb = getTabButton (i);
  51101. if (tb != 0 && ! tb->isVisible())
  51102. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  51103. }
  51104. const int res = m.showAt (extraTabsButton);
  51105. if (res != 0)
  51106. setCurrentTabIndex (res - 1);
  51107. }
  51108. }
  51109. void TabbedButtonBar::currentTabChanged (const int, const String&)
  51110. {
  51111. }
  51112. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  51113. {
  51114. }
  51115. END_JUCE_NAMESPACE
  51116. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  51117. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  51118. BEGIN_JUCE_NAMESPACE
  51119. class TabCompButtonBar : public TabbedButtonBar
  51120. {
  51121. public:
  51122. TabCompButtonBar (TabbedComponent* const owner_,
  51123. const TabbedButtonBar::Orientation orientation)
  51124. : TabbedButtonBar (orientation),
  51125. owner (owner_)
  51126. {
  51127. }
  51128. ~TabCompButtonBar()
  51129. {
  51130. }
  51131. void currentTabChanged (const int newCurrentTabIndex,
  51132. const String& newTabName)
  51133. {
  51134. owner->changeCallback (newCurrentTabIndex, newTabName);
  51135. }
  51136. void popupMenuClickOnTab (const int tabIndex,
  51137. const String& tabName)
  51138. {
  51139. owner->popupMenuClickOnTab (tabIndex, tabName);
  51140. }
  51141. const Colour getTabBackgroundColour (const int tabIndex)
  51142. {
  51143. return owner->tabs->getTabBackgroundColour (tabIndex);
  51144. }
  51145. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51146. {
  51147. return owner->createTabButton (tabName, tabIndex);
  51148. }
  51149. juce_UseDebuggingNewOperator
  51150. private:
  51151. TabbedComponent* const owner;
  51152. TabCompButtonBar (const TabCompButtonBar&);
  51153. const TabCompButtonBar& operator= (const TabCompButtonBar&);
  51154. };
  51155. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51156. : panelComponent (0),
  51157. tabDepth (30),
  51158. outlineThickness (1),
  51159. edgeIndent (0)
  51160. {
  51161. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51162. }
  51163. TabbedComponent::~TabbedComponent()
  51164. {
  51165. clearTabs();
  51166. delete tabs;
  51167. }
  51168. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51169. {
  51170. tabs->setOrientation (orientation);
  51171. resized();
  51172. }
  51173. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51174. {
  51175. return tabs->getOrientation();
  51176. }
  51177. void TabbedComponent::setTabBarDepth (const int newDepth)
  51178. {
  51179. if (tabDepth != newDepth)
  51180. {
  51181. tabDepth = newDepth;
  51182. resized();
  51183. }
  51184. }
  51185. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51186. {
  51187. return new TabBarButton (tabName, tabs, tabIndex);
  51188. }
  51189. void TabbedComponent::clearTabs()
  51190. {
  51191. if (panelComponent != 0)
  51192. {
  51193. panelComponent->setVisible (false);
  51194. removeChildComponent (panelComponent);
  51195. panelComponent = 0;
  51196. }
  51197. tabs->clearTabs();
  51198. for (int i = contentComponents.size(); --i >= 0;)
  51199. {
  51200. Component* const c = contentComponents.getUnchecked(i);
  51201. // be careful not to delete these components until they've been removed from the tab component
  51202. jassert (c == 0 || c->isValidComponent());
  51203. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51204. delete c;
  51205. }
  51206. contentComponents.clear();
  51207. }
  51208. void TabbedComponent::addTab (const String& tabName,
  51209. const Colour& tabBackgroundColour,
  51210. Component* const contentComponent,
  51211. const bool deleteComponentWhenNotNeeded,
  51212. const int insertIndex)
  51213. {
  51214. contentComponents.insert (insertIndex, contentComponent);
  51215. if (contentComponent != 0)
  51216. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  51217. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51218. }
  51219. void TabbedComponent::setTabName (const int tabIndex,
  51220. const String& newName)
  51221. {
  51222. tabs->setTabName (tabIndex, newName);
  51223. }
  51224. void TabbedComponent::removeTab (const int tabIndex)
  51225. {
  51226. Component* const c = contentComponents [tabIndex];
  51227. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51228. {
  51229. if (c == panelComponent)
  51230. panelComponent = 0;
  51231. delete c;
  51232. }
  51233. contentComponents.remove (tabIndex);
  51234. tabs->removeTab (tabIndex);
  51235. }
  51236. int TabbedComponent::getNumTabs() const
  51237. {
  51238. return tabs->getNumTabs();
  51239. }
  51240. const StringArray TabbedComponent::getTabNames() const
  51241. {
  51242. return tabs->getTabNames();
  51243. }
  51244. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51245. {
  51246. return contentComponents [tabIndex];
  51247. }
  51248. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51249. {
  51250. return tabs->getTabBackgroundColour (tabIndex);
  51251. }
  51252. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51253. {
  51254. tabs->setTabBackgroundColour (tabIndex, newColour);
  51255. if (getCurrentTabIndex() == tabIndex)
  51256. repaint();
  51257. }
  51258. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51259. {
  51260. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51261. }
  51262. int TabbedComponent::getCurrentTabIndex() const
  51263. {
  51264. return tabs->getCurrentTabIndex();
  51265. }
  51266. const String& TabbedComponent::getCurrentTabName() const
  51267. {
  51268. return tabs->getCurrentTabName();
  51269. }
  51270. void TabbedComponent::setOutline (int thickness)
  51271. {
  51272. outlineThickness = thickness;
  51273. repaint();
  51274. }
  51275. void TabbedComponent::setIndent (const int indentThickness)
  51276. {
  51277. edgeIndent = indentThickness;
  51278. }
  51279. void TabbedComponent::paint (Graphics& g)
  51280. {
  51281. g.fillAll (findColour (backgroundColourId));
  51282. const TabbedButtonBar::Orientation o = getOrientation();
  51283. int x = 0;
  51284. int y = 0;
  51285. int r = getWidth();
  51286. int b = getHeight();
  51287. if (o == TabbedButtonBar::TabsAtTop)
  51288. y += tabDepth;
  51289. else if (o == TabbedButtonBar::TabsAtBottom)
  51290. b -= tabDepth;
  51291. else if (o == TabbedButtonBar::TabsAtLeft)
  51292. x += tabDepth;
  51293. else if (o == TabbedButtonBar::TabsAtRight)
  51294. r -= tabDepth;
  51295. g.reduceClipRegion (x, y, r - x, b - y);
  51296. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51297. if (outlineThickness > 0)
  51298. {
  51299. if (o == TabbedButtonBar::TabsAtTop)
  51300. --y;
  51301. else if (o == TabbedButtonBar::TabsAtBottom)
  51302. ++b;
  51303. else if (o == TabbedButtonBar::TabsAtLeft)
  51304. --x;
  51305. else if (o == TabbedButtonBar::TabsAtRight)
  51306. ++r;
  51307. g.setColour (findColour (outlineColourId));
  51308. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51309. }
  51310. }
  51311. void TabbedComponent::resized()
  51312. {
  51313. const TabbedButtonBar::Orientation o = getOrientation();
  51314. const int indent = edgeIndent + outlineThickness;
  51315. BorderSize indents (indent);
  51316. if (o == TabbedButtonBar::TabsAtTop)
  51317. {
  51318. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51319. indents.setTop (tabDepth + edgeIndent);
  51320. }
  51321. else if (o == TabbedButtonBar::TabsAtBottom)
  51322. {
  51323. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51324. indents.setBottom (tabDepth + edgeIndent);
  51325. }
  51326. else if (o == TabbedButtonBar::TabsAtLeft)
  51327. {
  51328. tabs->setBounds (0, 0, tabDepth, getHeight());
  51329. indents.setLeft (tabDepth + edgeIndent);
  51330. }
  51331. else if (o == TabbedButtonBar::TabsAtRight)
  51332. {
  51333. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51334. indents.setRight (tabDepth + edgeIndent);
  51335. }
  51336. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  51337. for (int i = contentComponents.size(); --i >= 0;)
  51338. if (contentComponents.getUnchecked (i) != 0)
  51339. contentComponents.getUnchecked (i)->setBounds (bounds);
  51340. }
  51341. void TabbedComponent::lookAndFeelChanged()
  51342. {
  51343. for (int i = contentComponents.size(); --i >= 0;)
  51344. if (contentComponents.getUnchecked (i) != 0)
  51345. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51346. }
  51347. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51348. const String& newTabName)
  51349. {
  51350. if (panelComponent != 0)
  51351. {
  51352. panelComponent->setVisible (false);
  51353. removeChildComponent (panelComponent);
  51354. panelComponent = 0;
  51355. }
  51356. if (getCurrentTabIndex() >= 0)
  51357. {
  51358. panelComponent = contentComponents [getCurrentTabIndex()];
  51359. if (panelComponent != 0)
  51360. {
  51361. // do these ops as two stages instead of addAndMakeVisible() so that the
  51362. // component has always got a parent when it gets the visibilityChanged() callback
  51363. addChildComponent (panelComponent);
  51364. panelComponent->setVisible (true);
  51365. panelComponent->toFront (true);
  51366. }
  51367. repaint();
  51368. }
  51369. resized();
  51370. currentTabChanged (newCurrentTabIndex, newTabName);
  51371. }
  51372. void TabbedComponent::currentTabChanged (const int, const String&)
  51373. {
  51374. }
  51375. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51376. {
  51377. }
  51378. END_JUCE_NAMESPACE
  51379. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  51380. /*** Start of inlined file: juce_Viewport.cpp ***/
  51381. BEGIN_JUCE_NAMESPACE
  51382. Viewport::Viewport (const String& componentName)
  51383. : Component (componentName),
  51384. contentComp (0),
  51385. lastVX (0),
  51386. lastVY (0),
  51387. lastVW (0),
  51388. lastVH (0),
  51389. scrollBarThickness (0),
  51390. singleStepX (16),
  51391. singleStepY (16),
  51392. showHScrollbar (true),
  51393. showVScrollbar (true)
  51394. {
  51395. // content holder is used to clip the contents so they don't overlap the scrollbars
  51396. addAndMakeVisible (contentHolder = new Component());
  51397. contentHolder->setInterceptsMouseClicks (false, true);
  51398. verticalScrollBar = new ScrollBar (true);
  51399. horizontalScrollBar = new ScrollBar (false);
  51400. addChildComponent (verticalScrollBar);
  51401. addChildComponent (horizontalScrollBar);
  51402. verticalScrollBar->addListener (this);
  51403. horizontalScrollBar->addListener (this);
  51404. setInterceptsMouseClicks (false, true);
  51405. setWantsKeyboardFocus (true);
  51406. }
  51407. Viewport::~Viewport()
  51408. {
  51409. contentHolder->deleteAllChildren();
  51410. deleteAllChildren();
  51411. }
  51412. void Viewport::visibleAreaChanged (int, int, int, int)
  51413. {
  51414. }
  51415. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51416. {
  51417. if (contentComp != newViewedComponent)
  51418. {
  51419. if (contentComp->isValidComponent())
  51420. {
  51421. Component* const oldComp = contentComp;
  51422. contentComp = 0;
  51423. delete oldComp;
  51424. }
  51425. contentComp = newViewedComponent;
  51426. if (contentComp != 0)
  51427. {
  51428. contentComp->setTopLeftPosition (0, 0);
  51429. contentHolder->addAndMakeVisible (contentComp);
  51430. contentComp->addComponentListener (this);
  51431. }
  51432. updateVisibleRegion();
  51433. }
  51434. }
  51435. int Viewport::getMaximumVisibleWidth() const throw()
  51436. {
  51437. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51438. }
  51439. int Viewport::getMaximumVisibleHeight() const throw()
  51440. {
  51441. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51442. }
  51443. void Viewport::setViewPosition (const int xPixelsOffset,
  51444. const int yPixelsOffset)
  51445. {
  51446. if (contentComp != 0)
  51447. contentComp->setTopLeftPosition (-xPixelsOffset,
  51448. -yPixelsOffset);
  51449. }
  51450. void Viewport::setViewPositionProportionately (const double x,
  51451. const double y)
  51452. {
  51453. if (contentComp != 0)
  51454. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51455. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51456. }
  51457. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51458. {
  51459. if (contentComp != 0)
  51460. {
  51461. int dx = 0, dy = 0;
  51462. if (mouseX < activeBorderThickness)
  51463. dx = activeBorderThickness - mouseX;
  51464. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51465. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51466. if (dx < 0)
  51467. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51468. else
  51469. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51470. if (mouseY < activeBorderThickness)
  51471. dy = activeBorderThickness - mouseY;
  51472. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51473. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51474. if (dy < 0)
  51475. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51476. else
  51477. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51478. if (dx != 0 || dy != 0)
  51479. {
  51480. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51481. contentComp->getY() + dy);
  51482. return true;
  51483. }
  51484. }
  51485. return false;
  51486. }
  51487. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51488. {
  51489. updateVisibleRegion();
  51490. }
  51491. void Viewport::resized()
  51492. {
  51493. updateVisibleRegion();
  51494. }
  51495. void Viewport::updateVisibleRegion()
  51496. {
  51497. if (contentComp != 0)
  51498. {
  51499. const int newVX = -contentComp->getX();
  51500. const int newVY = -contentComp->getY();
  51501. if (newVX == 0 && newVY == 0
  51502. && contentComp->getWidth() <= getWidth()
  51503. && contentComp->getHeight() <= getHeight())
  51504. {
  51505. horizontalScrollBar->setVisible (false);
  51506. verticalScrollBar->setVisible (false);
  51507. }
  51508. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51509. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51510. horizontalScrollBar->setSingleStepSize (singleStepX);
  51511. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51512. horizontalScrollBar->setVisible (false);
  51513. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51514. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51515. verticalScrollBar->setSingleStepSize (singleStepY);
  51516. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51517. verticalScrollBar->setVisible (false);
  51518. if (verticalScrollBar->isVisible())
  51519. {
  51520. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51521. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51522. verticalScrollBar
  51523. ->setBounds (getMaximumVisibleWidth(), 0,
  51524. getScrollBarThickness(), getMaximumVisibleHeight());
  51525. }
  51526. if (horizontalScrollBar->isVisible())
  51527. {
  51528. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51529. horizontalScrollBar
  51530. ->setBounds (0, getMaximumVisibleHeight(),
  51531. getMaximumVisibleWidth(), getScrollBarThickness());
  51532. }
  51533. contentHolder->setSize (getMaximumVisibleWidth(),
  51534. getMaximumVisibleHeight());
  51535. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51536. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51537. if (newVX != lastVX
  51538. || newVY != lastVY
  51539. || newVW != lastVW
  51540. || newVH != lastVH)
  51541. {
  51542. lastVX = newVX;
  51543. lastVY = newVY;
  51544. lastVW = newVW;
  51545. lastVH = newVH;
  51546. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51547. }
  51548. horizontalScrollBar->handleUpdateNowIfNeeded();
  51549. verticalScrollBar->handleUpdateNowIfNeeded();
  51550. }
  51551. else
  51552. {
  51553. horizontalScrollBar->setVisible (false);
  51554. verticalScrollBar->setVisible (false);
  51555. }
  51556. }
  51557. void Viewport::setSingleStepSizes (const int stepX,
  51558. const int stepY)
  51559. {
  51560. singleStepX = stepX;
  51561. singleStepY = stepY;
  51562. updateVisibleRegion();
  51563. }
  51564. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51565. const bool showHorizontalScrollbarIfNeeded)
  51566. {
  51567. showVScrollbar = showVerticalScrollbarIfNeeded;
  51568. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51569. updateVisibleRegion();
  51570. }
  51571. void Viewport::setScrollBarThickness (const int thickness)
  51572. {
  51573. scrollBarThickness = thickness;
  51574. updateVisibleRegion();
  51575. }
  51576. int Viewport::getScrollBarThickness() const throw()
  51577. {
  51578. return (scrollBarThickness > 0) ? scrollBarThickness
  51579. : getLookAndFeel().getDefaultScrollbarWidth();
  51580. }
  51581. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51582. {
  51583. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51584. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51585. }
  51586. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51587. {
  51588. if (scrollBarThatHasMoved == horizontalScrollBar)
  51589. {
  51590. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51591. }
  51592. else if (scrollBarThatHasMoved == verticalScrollBar)
  51593. {
  51594. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51595. }
  51596. }
  51597. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51598. {
  51599. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51600. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51601. }
  51602. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51603. {
  51604. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51605. {
  51606. const bool hasVertBar = verticalScrollBar->isVisible();
  51607. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51608. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51609. {
  51610. if (wheelIncrementX == 0 && ! hasVertBar)
  51611. wheelIncrementX = wheelIncrementY;
  51612. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51613. wheelIncrementX, wheelIncrementY);
  51614. return true;
  51615. }
  51616. else if (hasVertBar && wheelIncrementY != 0)
  51617. {
  51618. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51619. wheelIncrementX, wheelIncrementY);
  51620. return true;
  51621. }
  51622. }
  51623. return false;
  51624. }
  51625. bool Viewport::keyPressed (const KeyPress& key)
  51626. {
  51627. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51628. || key.isKeyCode (KeyPress::downKey)
  51629. || key.isKeyCode (KeyPress::pageUpKey)
  51630. || key.isKeyCode (KeyPress::pageDownKey)
  51631. || key.isKeyCode (KeyPress::homeKey)
  51632. || key.isKeyCode (KeyPress::endKey);
  51633. if (verticalScrollBar->isVisible() && isUpDownKey)
  51634. return verticalScrollBar->keyPressed (key);
  51635. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51636. || key.isKeyCode (KeyPress::rightKey);
  51637. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51638. return horizontalScrollBar->keyPressed (key);
  51639. return false;
  51640. }
  51641. END_JUCE_NAMESPACE
  51642. /*** End of inlined file: juce_Viewport.cpp ***/
  51643. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51644. BEGIN_JUCE_NAMESPACE
  51645. static const Colour createBaseColour (const Colour& buttonColour,
  51646. const bool hasKeyboardFocus,
  51647. const bool isMouseOverButton,
  51648. const bool isButtonDown) throw()
  51649. {
  51650. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51651. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51652. if (isButtonDown)
  51653. return baseColour.contrasting (0.2f);
  51654. else if (isMouseOverButton)
  51655. return baseColour.contrasting (0.1f);
  51656. return baseColour;
  51657. }
  51658. static String defaultSansName, defaultSerifName, defaultFixedName;
  51659. void clearUpDefaultFontNames() throw()
  51660. {
  51661. defaultSansName = String::empty;
  51662. defaultSerifName = String::empty;
  51663. defaultFixedName = String::empty;
  51664. }
  51665. LookAndFeel::LookAndFeel()
  51666. {
  51667. /* if this fails it means you're trying to create a LookAndFeel object before
  51668. the static Colours have been initialised. That ain't gonna work. It probably
  51669. means that you're using a static LookAndFeel object and that your compiler has
  51670. decided to intialise it before the Colours class.
  51671. */
  51672. jassert (Colours::white == Colour (0xffffffff));
  51673. // set up the standard set of colours..
  51674. const int textButtonColour = 0xffbbbbff;
  51675. const int textHighlightColour = 0x401111ee;
  51676. const int standardOutlineColour = 0xb2808080;
  51677. static const int standardColours[] =
  51678. {
  51679. TextButton::buttonColourId, textButtonColour,
  51680. TextButton::buttonOnColourId, 0xff4444ff,
  51681. TextButton::textColourOnId, 0xff000000,
  51682. TextButton::textColourOffId, 0xff000000,
  51683. ComboBox::buttonColourId, 0xffbbbbff,
  51684. ComboBox::outlineColourId, standardOutlineColour,
  51685. ToggleButton::textColourId, 0xff000000,
  51686. TextEditor::backgroundColourId, 0xffffffff,
  51687. TextEditor::textColourId, 0xff000000,
  51688. TextEditor::highlightColourId, textHighlightColour,
  51689. TextEditor::highlightedTextColourId, 0xff000000,
  51690. TextEditor::caretColourId, 0xff000000,
  51691. TextEditor::outlineColourId, 0x00000000,
  51692. TextEditor::focusedOutlineColourId, textButtonColour,
  51693. TextEditor::shadowColourId, 0x38000000,
  51694. Label::backgroundColourId, 0x00000000,
  51695. Label::textColourId, 0xff000000,
  51696. Label::outlineColourId, 0x00000000,
  51697. ScrollBar::backgroundColourId, 0x00000000,
  51698. ScrollBar::thumbColourId, 0xffffffff,
  51699. ScrollBar::trackColourId, 0xffffffff,
  51700. TreeView::linesColourId, 0x4c000000,
  51701. TreeView::backgroundColourId, 0x00000000,
  51702. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51703. PopupMenu::backgroundColourId, 0xffffffff,
  51704. PopupMenu::textColourId, 0xff000000,
  51705. PopupMenu::headerTextColourId, 0xff000000,
  51706. PopupMenu::highlightedTextColourId, 0xffffffff,
  51707. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51708. ComboBox::textColourId, 0xff000000,
  51709. ComboBox::backgroundColourId, 0xffffffff,
  51710. ComboBox::arrowColourId, 0x99000000,
  51711. ListBox::backgroundColourId, 0xffffffff,
  51712. ListBox::outlineColourId, standardOutlineColour,
  51713. ListBox::textColourId, 0xff000000,
  51714. Slider::backgroundColourId, 0x00000000,
  51715. Slider::thumbColourId, textButtonColour,
  51716. Slider::trackColourId, 0x7fffffff,
  51717. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51718. Slider::rotarySliderOutlineColourId, 0x66000000,
  51719. Slider::textBoxTextColourId, 0xff000000,
  51720. Slider::textBoxBackgroundColourId, 0xffffffff,
  51721. Slider::textBoxHighlightColourId, textHighlightColour,
  51722. Slider::textBoxOutlineColourId, standardOutlineColour,
  51723. ResizableWindow::backgroundColourId, 0xff777777,
  51724. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51725. AlertWindow::backgroundColourId, 0xffededed,
  51726. AlertWindow::textColourId, 0xff000000,
  51727. AlertWindow::outlineColourId, 0xff666666,
  51728. ProgressBar::backgroundColourId, 0xffeeeeee,
  51729. ProgressBar::foregroundColourId, 0xffaaaaee,
  51730. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51731. TooltipWindow::textColourId, 0xff000000,
  51732. TooltipWindow::outlineColourId, 0x4c000000,
  51733. TabbedComponent::backgroundColourId, 0x00000000,
  51734. TabbedComponent::outlineColourId, 0xff777777,
  51735. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51736. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51737. Toolbar::backgroundColourId, 0xfff6f8f9,
  51738. Toolbar::separatorColourId, 0x4c000000,
  51739. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51740. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51741. Toolbar::labelTextColourId, 0xff000000,
  51742. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51743. HyperlinkButton::textColourId, 0xcc1111ee,
  51744. GroupComponent::outlineColourId, 0x66000000,
  51745. GroupComponent::textColourId, 0xff000000,
  51746. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51747. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51748. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51749. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51750. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51751. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51752. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51753. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51754. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51755. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51756. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51757. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51758. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51759. CodeEditorComponent::caretColourId, 0xff000000,
  51760. CodeEditorComponent::highlightColourId, textHighlightColour,
  51761. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51762. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51763. ColourSelector::labelTextColourId, 0xff000000,
  51764. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51765. KeyMappingEditorComponent::textColourId, 0xff000000,
  51766. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51767. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51768. };
  51769. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51770. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51771. if (defaultSansName.isEmpty())
  51772. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51773. defaultSans = defaultSansName;
  51774. defaultSerif = defaultSerifName;
  51775. defaultFixed = defaultFixedName;
  51776. }
  51777. LookAndFeel::~LookAndFeel()
  51778. {
  51779. }
  51780. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51781. {
  51782. const int index = colourIds.indexOf (colourId);
  51783. if (index >= 0)
  51784. return colours [index];
  51785. jassertfalse
  51786. return Colours::black;
  51787. }
  51788. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51789. {
  51790. const int index = colourIds.indexOf (colourId);
  51791. if (index >= 0)
  51792. colours.set (index, colour);
  51793. colourIds.add (colourId);
  51794. colours.add (colour);
  51795. }
  51796. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51797. {
  51798. return colourIds.contains (colourId);
  51799. }
  51800. static LookAndFeel* defaultLF = 0;
  51801. static LookAndFeel* currentDefaultLF = 0;
  51802. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51803. {
  51804. // if this happens, your app hasn't initialised itself properly.. if you're
  51805. // trying to hack your own main() function, have a look at
  51806. // JUCEApplication::initialiseForGUI()
  51807. jassert (currentDefaultLF != 0);
  51808. return *currentDefaultLF;
  51809. }
  51810. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51811. {
  51812. if (newDefaultLookAndFeel == 0)
  51813. {
  51814. if (defaultLF == 0)
  51815. defaultLF = new LookAndFeel();
  51816. newDefaultLookAndFeel = defaultLF;
  51817. }
  51818. currentDefaultLF = newDefaultLookAndFeel;
  51819. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51820. {
  51821. Component* const c = Desktop::getInstance().getComponent (i);
  51822. if (c != 0)
  51823. c->sendLookAndFeelChange();
  51824. }
  51825. }
  51826. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51827. {
  51828. if (currentDefaultLF == defaultLF)
  51829. currentDefaultLF = 0;
  51830. deleteAndZero (defaultLF);
  51831. }
  51832. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51833. {
  51834. String faceName (font.getTypefaceName());
  51835. if (faceName == Font::getDefaultSansSerifFontName())
  51836. faceName = defaultSans;
  51837. else if (faceName == Font::getDefaultSerifFontName())
  51838. faceName = defaultSerif;
  51839. else if (faceName == Font::getDefaultMonospacedFontName())
  51840. faceName = defaultFixed;
  51841. Font f (font);
  51842. f.setTypefaceName (faceName);
  51843. return Typeface::createSystemTypefaceFor (f);
  51844. }
  51845. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51846. {
  51847. defaultSans = newName;
  51848. }
  51849. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51850. {
  51851. return component.getMouseCursor();
  51852. }
  51853. void LookAndFeel::drawButtonBackground (Graphics& g,
  51854. Button& button,
  51855. const Colour& backgroundColour,
  51856. bool isMouseOverButton,
  51857. bool isButtonDown)
  51858. {
  51859. const int width = button.getWidth();
  51860. const int height = button.getHeight();
  51861. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51862. const float halfThickness = outlineThickness * 0.5f;
  51863. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51864. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51865. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51866. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51867. const Colour baseColour (createBaseColour (backgroundColour,
  51868. button.hasKeyboardFocus (true),
  51869. isMouseOverButton, isButtonDown)
  51870. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51871. drawGlassLozenge (g,
  51872. indentL,
  51873. indentT,
  51874. width - indentL - indentR,
  51875. height - indentT - indentB,
  51876. baseColour, outlineThickness, -1.0f,
  51877. button.isConnectedOnLeft(),
  51878. button.isConnectedOnRight(),
  51879. button.isConnectedOnTop(),
  51880. button.isConnectedOnBottom());
  51881. }
  51882. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51883. {
  51884. return button.getFont();
  51885. }
  51886. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51887. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51888. {
  51889. Font font (getFontForTextButton (button));
  51890. g.setFont (font);
  51891. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51892. : TextButton::textColourOffId)
  51893. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51894. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51895. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51896. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51897. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51898. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51899. g.drawFittedText (button.getButtonText(),
  51900. leftIndent,
  51901. yIndent,
  51902. button.getWidth() - leftIndent - rightIndent,
  51903. button.getHeight() - yIndent * 2,
  51904. Justification::centred, 2);
  51905. }
  51906. void LookAndFeel::drawTickBox (Graphics& g,
  51907. Component& component,
  51908. float x, float y, float w, float h,
  51909. const bool ticked,
  51910. const bool isEnabled,
  51911. const bool isMouseOverButton,
  51912. const bool isButtonDown)
  51913. {
  51914. const float boxSize = w * 0.7f;
  51915. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51916. createBaseColour (component.findColour (TextButton::buttonColourId)
  51917. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51918. true,
  51919. isMouseOverButton,
  51920. isButtonDown),
  51921. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51922. if (ticked)
  51923. {
  51924. Path tick;
  51925. tick.startNewSubPath (1.5f, 3.0f);
  51926. tick.lineTo (3.0f, 6.0f);
  51927. tick.lineTo (6.0f, 0.0f);
  51928. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51929. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51930. .translated (x, y));
  51931. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51932. }
  51933. }
  51934. void LookAndFeel::drawToggleButton (Graphics& g,
  51935. ToggleButton& button,
  51936. bool isMouseOverButton,
  51937. bool isButtonDown)
  51938. {
  51939. if (button.hasKeyboardFocus (true))
  51940. {
  51941. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51942. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51943. }
  51944. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51945. const float tickWidth = fontSize * 1.1f;
  51946. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51947. tickWidth, tickWidth,
  51948. button.getToggleState(),
  51949. button.isEnabled(),
  51950. isMouseOverButton,
  51951. isButtonDown);
  51952. g.setColour (button.findColour (ToggleButton::textColourId));
  51953. g.setFont (fontSize);
  51954. if (! button.isEnabled())
  51955. g.setOpacity (0.5f);
  51956. const int textX = (int) tickWidth + 5;
  51957. g.drawFittedText (button.getButtonText(),
  51958. textX, 0,
  51959. button.getWidth() - textX - 2, button.getHeight(),
  51960. Justification::centredLeft, 10);
  51961. }
  51962. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51963. {
  51964. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51965. const int tickWidth = jmin (24, button.getHeight());
  51966. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51967. button.getHeight());
  51968. }
  51969. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51970. const String& message,
  51971. const String& button1,
  51972. const String& button2,
  51973. const String& button3,
  51974. AlertWindow::AlertIconType iconType,
  51975. int numButtons,
  51976. Component* associatedComponent)
  51977. {
  51978. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51979. if (numButtons == 1)
  51980. {
  51981. aw->addButton (button1, 0,
  51982. KeyPress (KeyPress::escapeKey, 0, 0),
  51983. KeyPress (KeyPress::returnKey, 0, 0));
  51984. }
  51985. else
  51986. {
  51987. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51988. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51989. if (button1ShortCut == button2ShortCut)
  51990. button2ShortCut = KeyPress();
  51991. if (numButtons == 2)
  51992. {
  51993. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51994. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51995. }
  51996. else if (numButtons == 3)
  51997. {
  51998. aw->addButton (button1, 1, button1ShortCut);
  51999. aw->addButton (button2, 2, button2ShortCut);
  52000. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  52001. }
  52002. }
  52003. return aw;
  52004. }
  52005. void LookAndFeel::drawAlertBox (Graphics& g,
  52006. AlertWindow& alert,
  52007. const Rectangle<int>& textArea,
  52008. TextLayout& textLayout)
  52009. {
  52010. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  52011. int iconSpaceUsed = 0;
  52012. Justification alignment (Justification::horizontallyCentred);
  52013. const int iconWidth = 80;
  52014. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  52015. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  52016. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  52017. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  52018. iconSize, iconSize);
  52019. if (alert.getAlertType() != AlertWindow::NoIcon)
  52020. {
  52021. Path icon;
  52022. uint32 colour;
  52023. char character;
  52024. if (alert.getAlertType() == AlertWindow::WarningIcon)
  52025. {
  52026. colour = 0x55ff5555;
  52027. character = '!';
  52028. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  52029. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  52030. (float) iconRect.getX(), (float) iconRect.getBottom());
  52031. icon = icon.createPathWithRoundedCorners (5.0f);
  52032. }
  52033. else
  52034. {
  52035. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  52036. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  52037. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  52038. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  52039. }
  52040. GlyphArrangement ga;
  52041. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  52042. String::charToString (character),
  52043. (float) iconRect.getX(), (float) iconRect.getY(),
  52044. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  52045. Justification::centred, false);
  52046. ga.createPath (icon);
  52047. icon.setUsingNonZeroWinding (false);
  52048. g.setColour (Colour (colour));
  52049. g.fillPath (icon);
  52050. iconSpaceUsed = iconWidth;
  52051. alignment = Justification::left;
  52052. }
  52053. g.setColour (alert.findColour (AlertWindow::textColourId));
  52054. textLayout.drawWithin (g,
  52055. textArea.getX() + iconSpaceUsed, textArea.getY(),
  52056. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  52057. alignment.getFlags() | Justification::top);
  52058. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  52059. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  52060. }
  52061. int LookAndFeel::getAlertBoxWindowFlags()
  52062. {
  52063. return ComponentPeer::windowAppearsOnTaskbar
  52064. | ComponentPeer::windowHasDropShadow;
  52065. }
  52066. int LookAndFeel::getAlertWindowButtonHeight()
  52067. {
  52068. return 28;
  52069. }
  52070. const Font LookAndFeel::getAlertWindowFont()
  52071. {
  52072. return Font (12.0f);
  52073. }
  52074. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  52075. int width, int height,
  52076. double progress, const String& textToShow)
  52077. {
  52078. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  52079. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  52080. g.fillAll (background);
  52081. if (progress >= 0.0f && progress < 1.0f)
  52082. {
  52083. drawGlassLozenge (g, 1.0f, 1.0f,
  52084. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  52085. (float) (height - 2),
  52086. foreground,
  52087. 0.5f, 0.0f,
  52088. true, true, true, true);
  52089. }
  52090. else
  52091. {
  52092. // spinning bar..
  52093. g.setColour (foreground);
  52094. const int stripeWidth = height * 2;
  52095. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  52096. Path p;
  52097. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  52098. p.addQuadrilateral (x, 0.0f,
  52099. x + stripeWidth * 0.5f, 0.0f,
  52100. x, (float) height,
  52101. x - stripeWidth * 0.5f, (float) height);
  52102. Image im (Image::ARGB, width, height, true);
  52103. {
  52104. Graphics g2 (im);
  52105. drawGlassLozenge (g2, 1.0f, 1.0f,
  52106. (float) (width - 2),
  52107. (float) (height - 2),
  52108. foreground,
  52109. 0.5f, 0.0f,
  52110. true, true, true, true);
  52111. }
  52112. g.setTiledImageFill (im, 0, 0, 0.85f);
  52113. g.fillPath (p);
  52114. }
  52115. if (textToShow.isNotEmpty())
  52116. {
  52117. g.setColour (Colour::contrasting (background, foreground));
  52118. g.setFont (height * 0.6f);
  52119. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  52120. }
  52121. }
  52122. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  52123. {
  52124. const float radius = jmin (w, h) * 0.4f;
  52125. const float thickness = radius * 0.15f;
  52126. Path p;
  52127. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52128. radius * 0.6f, thickness,
  52129. thickness * 0.5f);
  52130. const float cx = x + w * 0.5f;
  52131. const float cy = y + h * 0.5f;
  52132. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52133. for (int i = 0; i < 12; ++i)
  52134. {
  52135. const int n = (i + 12 - animationIndex) % 12;
  52136. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52137. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52138. .translated (cx, cy));
  52139. }
  52140. }
  52141. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52142. ScrollBar& scrollbar,
  52143. int width, int height,
  52144. int buttonDirection,
  52145. bool /*isScrollbarVertical*/,
  52146. bool /*isMouseOverButton*/,
  52147. bool isButtonDown)
  52148. {
  52149. Path p;
  52150. if (buttonDirection == 0)
  52151. p.addTriangle (width * 0.5f, height * 0.2f,
  52152. width * 0.1f, height * 0.7f,
  52153. width * 0.9f, height * 0.7f);
  52154. else if (buttonDirection == 1)
  52155. p.addTriangle (width * 0.8f, height * 0.5f,
  52156. width * 0.3f, height * 0.1f,
  52157. width * 0.3f, height * 0.9f);
  52158. else if (buttonDirection == 2)
  52159. p.addTriangle (width * 0.5f, height * 0.8f,
  52160. width * 0.1f, height * 0.3f,
  52161. width * 0.9f, height * 0.3f);
  52162. else if (buttonDirection == 3)
  52163. p.addTriangle (width * 0.2f, height * 0.5f,
  52164. width * 0.7f, height * 0.1f,
  52165. width * 0.7f, height * 0.9f);
  52166. if (isButtonDown)
  52167. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52168. else
  52169. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52170. g.fillPath (p);
  52171. g.setColour (Colour (0x80000000));
  52172. g.strokePath (p, PathStrokeType (0.5f));
  52173. }
  52174. void LookAndFeel::drawScrollbar (Graphics& g,
  52175. ScrollBar& scrollbar,
  52176. int x, int y,
  52177. int width, int height,
  52178. bool isScrollbarVertical,
  52179. int thumbStartPosition,
  52180. int thumbSize,
  52181. bool /*isMouseOver*/,
  52182. bool /*isMouseDown*/)
  52183. {
  52184. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52185. Path slotPath, thumbPath;
  52186. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52187. const float slotIndentx2 = slotIndent * 2.0f;
  52188. const float thumbIndent = slotIndent + 1.0f;
  52189. const float thumbIndentx2 = thumbIndent * 2.0f;
  52190. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52191. if (isScrollbarVertical)
  52192. {
  52193. slotPath.addRoundedRectangle (x + slotIndent,
  52194. y + slotIndent,
  52195. width - slotIndentx2,
  52196. height - slotIndentx2,
  52197. (width - slotIndentx2) * 0.5f);
  52198. if (thumbSize > 0)
  52199. thumbPath.addRoundedRectangle (x + thumbIndent,
  52200. thumbStartPosition + thumbIndent,
  52201. width - thumbIndentx2,
  52202. thumbSize - thumbIndentx2,
  52203. (width - thumbIndentx2) * 0.5f);
  52204. gx1 = (float) x;
  52205. gx2 = x + width * 0.7f;
  52206. }
  52207. else
  52208. {
  52209. slotPath.addRoundedRectangle (x + slotIndent,
  52210. y + slotIndent,
  52211. width - slotIndentx2,
  52212. height - slotIndentx2,
  52213. (height - slotIndentx2) * 0.5f);
  52214. if (thumbSize > 0)
  52215. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52216. y + thumbIndent,
  52217. thumbSize - thumbIndentx2,
  52218. height - thumbIndentx2,
  52219. (height - thumbIndentx2) * 0.5f);
  52220. gy1 = (float) y;
  52221. gy2 = y + height * 0.7f;
  52222. }
  52223. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52224. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52225. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52226. g.fillPath (slotPath);
  52227. if (isScrollbarVertical)
  52228. {
  52229. gx1 = x + width * 0.6f;
  52230. gx2 = (float) x + width;
  52231. }
  52232. else
  52233. {
  52234. gy1 = y + height * 0.6f;
  52235. gy2 = (float) y + height;
  52236. }
  52237. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52238. Colour (0x19000000), gx2, gy2, false));
  52239. g.fillPath (slotPath);
  52240. g.setColour (thumbColour);
  52241. g.fillPath (thumbPath);
  52242. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52243. Colours::transparentBlack, gx2, gy2, false));
  52244. g.saveState();
  52245. if (isScrollbarVertical)
  52246. g.reduceClipRegion (x + width / 2, y, width, height);
  52247. else
  52248. g.reduceClipRegion (x, y + height / 2, width, height);
  52249. g.fillPath (thumbPath);
  52250. g.restoreState();
  52251. g.setColour (Colour (0x4c000000));
  52252. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52253. }
  52254. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52255. {
  52256. return 0;
  52257. }
  52258. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52259. {
  52260. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52261. }
  52262. int LookAndFeel::getDefaultScrollbarWidth()
  52263. {
  52264. return 18;
  52265. }
  52266. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52267. {
  52268. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52269. : scrollbar.getHeight());
  52270. }
  52271. const Path LookAndFeel::getTickShape (const float height)
  52272. {
  52273. static const unsigned char tickShapeData[] =
  52274. {
  52275. 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,
  52276. 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,
  52277. 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,
  52278. 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,
  52279. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52280. };
  52281. Path p;
  52282. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52283. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52284. return p;
  52285. }
  52286. const Path LookAndFeel::getCrossShape (const float height)
  52287. {
  52288. static const unsigned char crossShapeData[] =
  52289. {
  52290. 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,
  52291. 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,
  52292. 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,
  52293. 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,
  52294. 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,
  52295. 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,
  52296. 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
  52297. };
  52298. Path p;
  52299. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52300. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52301. return p;
  52302. }
  52303. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52304. {
  52305. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52306. x += (w - boxSize) >> 1;
  52307. y += (h - boxSize) >> 1;
  52308. w = boxSize;
  52309. h = boxSize;
  52310. g.setColour (Colour (0xe5ffffff));
  52311. g.fillRect (x, y, w, h);
  52312. g.setColour (Colour (0x80000000));
  52313. g.drawRect (x, y, w, h);
  52314. const float size = boxSize / 2 + 1.0f;
  52315. const float centre = (float) (boxSize / 2);
  52316. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52317. if (isPlus)
  52318. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52319. }
  52320. void LookAndFeel::drawBubble (Graphics& g,
  52321. float tipX, float tipY,
  52322. float boxX, float boxY,
  52323. float boxW, float boxH)
  52324. {
  52325. int side = 0;
  52326. if (tipX < boxX)
  52327. side = 1;
  52328. else if (tipX > boxX + boxW)
  52329. side = 3;
  52330. else if (tipY > boxY + boxH)
  52331. side = 2;
  52332. const float indent = 2.0f;
  52333. Path p;
  52334. p.addBubble (boxX + indent,
  52335. boxY + indent,
  52336. boxW - indent * 2.0f,
  52337. boxH - indent * 2.0f,
  52338. 5.0f,
  52339. tipX, tipY,
  52340. side,
  52341. 0.5f,
  52342. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52343. //xxx need to take comp as param for colour
  52344. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52345. g.fillPath (p);
  52346. //xxx as above
  52347. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52348. g.strokePath (p, PathStrokeType (1.33f));
  52349. }
  52350. const Font LookAndFeel::getPopupMenuFont()
  52351. {
  52352. return Font (17.0f);
  52353. }
  52354. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52355. const bool isSeparator,
  52356. int standardMenuItemHeight,
  52357. int& idealWidth,
  52358. int& idealHeight)
  52359. {
  52360. if (isSeparator)
  52361. {
  52362. idealWidth = 50;
  52363. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52364. }
  52365. else
  52366. {
  52367. Font font (getPopupMenuFont());
  52368. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52369. font.setHeight (standardMenuItemHeight / 1.3f);
  52370. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52371. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52372. }
  52373. }
  52374. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52375. {
  52376. const Colour background (findColour (PopupMenu::backgroundColourId));
  52377. g.fillAll (background);
  52378. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52379. for (int i = 0; i < height; i += 3)
  52380. g.fillRect (0, i, width, 1);
  52381. #if ! JUCE_MAC
  52382. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52383. g.drawRect (0, 0, width, height);
  52384. #endif
  52385. }
  52386. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52387. int width, int height,
  52388. bool isScrollUpArrow)
  52389. {
  52390. const Colour background (findColour (PopupMenu::backgroundColourId));
  52391. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52392. background.withAlpha (0.0f),
  52393. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52394. false));
  52395. g.fillRect (1, 1, width - 2, height - 2);
  52396. const float hw = width * 0.5f;
  52397. const float arrowW = height * 0.3f;
  52398. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52399. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52400. Path p;
  52401. p.addTriangle (hw - arrowW, y1,
  52402. hw + arrowW, y1,
  52403. hw, y2);
  52404. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52405. g.fillPath (p);
  52406. }
  52407. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52408. int width, int height,
  52409. const bool isSeparator,
  52410. const bool isActive,
  52411. const bool isHighlighted,
  52412. const bool isTicked,
  52413. const bool hasSubMenu,
  52414. const String& text,
  52415. const String& shortcutKeyText,
  52416. Image* image,
  52417. const Colour* const textColourToUse)
  52418. {
  52419. const float halfH = height * 0.5f;
  52420. if (isSeparator)
  52421. {
  52422. const float separatorIndent = 5.5f;
  52423. g.setColour (Colour (0x33000000));
  52424. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52425. g.setColour (Colour (0x66ffffff));
  52426. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52427. }
  52428. else
  52429. {
  52430. Colour textColour (findColour (PopupMenu::textColourId));
  52431. if (textColourToUse != 0)
  52432. textColour = *textColourToUse;
  52433. if (isHighlighted)
  52434. {
  52435. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52436. g.fillRect (1, 1, width - 2, height - 2);
  52437. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52438. }
  52439. else
  52440. {
  52441. g.setColour (textColour);
  52442. }
  52443. if (! isActive)
  52444. g.setOpacity (0.3f);
  52445. Font font (getPopupMenuFont());
  52446. if (font.getHeight() > height / 1.3f)
  52447. font.setHeight (height / 1.3f);
  52448. g.setFont (font);
  52449. const int leftBorder = (height * 5) / 4;
  52450. const int rightBorder = 4;
  52451. if (image != 0)
  52452. {
  52453. g.drawImageWithin (image,
  52454. 2, 1, leftBorder - 4, height - 2,
  52455. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52456. }
  52457. else if (isTicked)
  52458. {
  52459. const Path tick (getTickShape (1.0f));
  52460. const float th = font.getAscent();
  52461. const float ty = halfH - th * 0.5f;
  52462. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52463. th, true));
  52464. }
  52465. g.drawFittedText (text,
  52466. leftBorder, 0,
  52467. width - (leftBorder + rightBorder), height,
  52468. Justification::centredLeft, 1);
  52469. if (shortcutKeyText.isNotEmpty())
  52470. {
  52471. Font f2 (font);
  52472. f2.setHeight (f2.getHeight() * 0.75f);
  52473. f2.setHorizontalScale (0.95f);
  52474. g.setFont (f2);
  52475. g.drawText (shortcutKeyText,
  52476. leftBorder,
  52477. 0,
  52478. width - (leftBorder + rightBorder + 4),
  52479. height,
  52480. Justification::centredRight,
  52481. true);
  52482. }
  52483. if (hasSubMenu)
  52484. {
  52485. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52486. const float x = width - height * 0.6f;
  52487. Path p;
  52488. p.addTriangle (x, halfH - arrowH * 0.5f,
  52489. x, halfH + arrowH * 0.5f,
  52490. x + arrowH * 0.6f, halfH);
  52491. g.fillPath (p);
  52492. }
  52493. }
  52494. }
  52495. int LookAndFeel::getMenuWindowFlags()
  52496. {
  52497. return ComponentPeer::windowHasDropShadow;
  52498. }
  52499. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52500. bool, MenuBarComponent& menuBar)
  52501. {
  52502. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52503. if (menuBar.isEnabled())
  52504. {
  52505. drawShinyButtonShape (g,
  52506. -4.0f, 0.0f,
  52507. width + 8.0f, (float) height,
  52508. 0.0f,
  52509. baseColour,
  52510. 0.4f,
  52511. true, true, true, true);
  52512. }
  52513. else
  52514. {
  52515. g.fillAll (baseColour);
  52516. }
  52517. }
  52518. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52519. {
  52520. return Font (menuBar.getHeight() * 0.7f);
  52521. }
  52522. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52523. {
  52524. return getMenuBarFont (menuBar, itemIndex, itemText)
  52525. .getStringWidth (itemText) + menuBar.getHeight();
  52526. }
  52527. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52528. int width, int height,
  52529. int itemIndex,
  52530. const String& itemText,
  52531. bool isMouseOverItem,
  52532. bool isMenuOpen,
  52533. bool /*isMouseOverBar*/,
  52534. MenuBarComponent& menuBar)
  52535. {
  52536. if (! menuBar.isEnabled())
  52537. {
  52538. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52539. .withMultipliedAlpha (0.5f));
  52540. }
  52541. else if (isMenuOpen || isMouseOverItem)
  52542. {
  52543. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52544. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52545. }
  52546. else
  52547. {
  52548. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52549. }
  52550. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52551. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52552. }
  52553. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52554. TextEditor& textEditor)
  52555. {
  52556. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52557. }
  52558. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52559. {
  52560. if (textEditor.isEnabled())
  52561. {
  52562. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52563. {
  52564. const int border = 2;
  52565. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52566. g.drawRect (0, 0, width, height, border);
  52567. g.setOpacity (1.0f);
  52568. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52569. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52570. }
  52571. else
  52572. {
  52573. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52574. g.drawRect (0, 0, width, height);
  52575. g.setOpacity (1.0f);
  52576. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52577. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52578. }
  52579. }
  52580. }
  52581. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52582. const bool isButtonDown,
  52583. int buttonX, int buttonY,
  52584. int buttonW, int buttonH,
  52585. ComboBox& box)
  52586. {
  52587. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52588. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52589. {
  52590. g.setColour (box.findColour (TextButton::buttonColourId));
  52591. g.drawRect (0, 0, width, height, 2);
  52592. }
  52593. else
  52594. {
  52595. g.setColour (box.findColour (ComboBox::outlineColourId));
  52596. g.drawRect (0, 0, width, height);
  52597. }
  52598. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52599. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52600. box.hasKeyboardFocus (true),
  52601. false, isButtonDown)
  52602. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52603. drawGlassLozenge (g,
  52604. buttonX + outlineThickness, buttonY + outlineThickness,
  52605. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52606. baseColour, outlineThickness, -1.0f,
  52607. true, true, true, true);
  52608. if (box.isEnabled())
  52609. {
  52610. const float arrowX = 0.3f;
  52611. const float arrowH = 0.2f;
  52612. Path p;
  52613. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52614. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52615. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52616. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52617. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52618. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52619. g.setColour (box.findColour (ComboBox::arrowColourId));
  52620. g.fillPath (p);
  52621. }
  52622. }
  52623. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52624. {
  52625. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52626. }
  52627. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52628. {
  52629. return new Label (String::empty, String::empty);
  52630. }
  52631. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52632. {
  52633. label.setBounds (1, 1,
  52634. box.getWidth() + 3 - box.getHeight(),
  52635. box.getHeight() - 2);
  52636. label.setFont (getComboBoxFont (box));
  52637. }
  52638. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52639. {
  52640. g.fillAll (label.findColour (Label::backgroundColourId));
  52641. if (! label.isBeingEdited())
  52642. {
  52643. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52644. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52645. g.setFont (label.getFont());
  52646. g.drawFittedText (label.getText(),
  52647. label.getHorizontalBorderSize(),
  52648. label.getVerticalBorderSize(),
  52649. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52650. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52651. label.getJustificationType(),
  52652. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52653. label.getMinimumHorizontalScale());
  52654. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52655. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52656. }
  52657. else if (label.isEnabled())
  52658. {
  52659. g.setColour (label.findColour (Label::outlineColourId));
  52660. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52661. }
  52662. }
  52663. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52664. int x, int y,
  52665. int width, int height,
  52666. float /*sliderPos*/,
  52667. float /*minSliderPos*/,
  52668. float /*maxSliderPos*/,
  52669. const Slider::SliderStyle /*style*/,
  52670. Slider& slider)
  52671. {
  52672. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52673. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52674. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52675. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52676. Path indent;
  52677. if (slider.isHorizontal())
  52678. {
  52679. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52680. const float ih = sliderRadius;
  52681. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52682. gradCol2, 0.0f, iy + ih, false));
  52683. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52684. width + sliderRadius, ih,
  52685. 5.0f);
  52686. g.fillPath (indent);
  52687. }
  52688. else
  52689. {
  52690. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52691. const float iw = sliderRadius;
  52692. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52693. gradCol2, ix + iw, 0.0f, false));
  52694. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52695. iw, height + sliderRadius,
  52696. 5.0f);
  52697. g.fillPath (indent);
  52698. }
  52699. g.setColour (Colour (0x4c000000));
  52700. g.strokePath (indent, PathStrokeType (0.5f));
  52701. }
  52702. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52703. int x, int y,
  52704. int width, int height,
  52705. float sliderPos,
  52706. float minSliderPos,
  52707. float maxSliderPos,
  52708. const Slider::SliderStyle style,
  52709. Slider& slider)
  52710. {
  52711. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52712. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52713. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52714. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52715. slider.isMouseButtonDown() && slider.isEnabled()));
  52716. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52717. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52718. {
  52719. float kx, ky;
  52720. if (style == Slider::LinearVertical)
  52721. {
  52722. kx = x + width * 0.5f;
  52723. ky = sliderPos;
  52724. }
  52725. else
  52726. {
  52727. kx = sliderPos;
  52728. ky = y + height * 0.5f;
  52729. }
  52730. drawGlassSphere (g,
  52731. kx - sliderRadius,
  52732. ky - sliderRadius,
  52733. sliderRadius * 2.0f,
  52734. knobColour, outlineThickness);
  52735. }
  52736. else
  52737. {
  52738. if (style == Slider::ThreeValueVertical)
  52739. {
  52740. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52741. sliderPos - sliderRadius,
  52742. sliderRadius * 2.0f,
  52743. knobColour, outlineThickness);
  52744. }
  52745. else if (style == Slider::ThreeValueHorizontal)
  52746. {
  52747. drawGlassSphere (g,sliderPos - sliderRadius,
  52748. y + height * 0.5f - sliderRadius,
  52749. sliderRadius * 2.0f,
  52750. knobColour, outlineThickness);
  52751. }
  52752. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52753. {
  52754. const float sr = jmin (sliderRadius, width * 0.4f);
  52755. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52756. minSliderPos - sliderRadius,
  52757. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52758. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52759. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52760. }
  52761. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52762. {
  52763. const float sr = jmin (sliderRadius, height * 0.4f);
  52764. drawGlassPointer (g, minSliderPos - sr,
  52765. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52766. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52767. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52768. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52769. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52770. }
  52771. }
  52772. }
  52773. void LookAndFeel::drawLinearSlider (Graphics& g,
  52774. int x, int y,
  52775. int width, int height,
  52776. float sliderPos,
  52777. float minSliderPos,
  52778. float maxSliderPos,
  52779. const Slider::SliderStyle style,
  52780. Slider& slider)
  52781. {
  52782. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52783. if (style == Slider::LinearBar)
  52784. {
  52785. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52786. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52787. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52788. false,
  52789. isMouseOver,
  52790. isMouseOver || slider.isMouseButtonDown()));
  52791. drawShinyButtonShape (g,
  52792. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52793. baseColour,
  52794. slider.isEnabled() ? 0.9f : 0.3f,
  52795. true, true, true, true);
  52796. }
  52797. else
  52798. {
  52799. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52800. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52801. }
  52802. }
  52803. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52804. {
  52805. return jmin (7,
  52806. slider.getHeight() / 2,
  52807. slider.getWidth() / 2) + 2;
  52808. }
  52809. void LookAndFeel::drawRotarySlider (Graphics& g,
  52810. int x, int y,
  52811. int width, int height,
  52812. float sliderPos,
  52813. const float rotaryStartAngle,
  52814. const float rotaryEndAngle,
  52815. Slider& slider)
  52816. {
  52817. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52818. const float centreX = x + width * 0.5f;
  52819. const float centreY = y + height * 0.5f;
  52820. const float rx = centreX - radius;
  52821. const float ry = centreY - radius;
  52822. const float rw = radius * 2.0f;
  52823. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52824. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52825. if (radius > 12.0f)
  52826. {
  52827. if (slider.isEnabled())
  52828. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52829. else
  52830. g.setColour (Colour (0x80808080));
  52831. const float thickness = 0.7f;
  52832. {
  52833. Path filledArc;
  52834. filledArc.addPieSegment (rx, ry, rw, rw,
  52835. rotaryStartAngle,
  52836. angle,
  52837. thickness);
  52838. g.fillPath (filledArc);
  52839. }
  52840. if (thickness > 0)
  52841. {
  52842. const float innerRadius = radius * 0.2f;
  52843. Path p;
  52844. p.addTriangle (-innerRadius, 0.0f,
  52845. 0.0f, -radius * thickness * 1.1f,
  52846. innerRadius, 0.0f);
  52847. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52848. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52849. }
  52850. if (slider.isEnabled())
  52851. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52852. else
  52853. g.setColour (Colour (0x80808080));
  52854. Path outlineArc;
  52855. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52856. outlineArc.closeSubPath();
  52857. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52858. }
  52859. else
  52860. {
  52861. if (slider.isEnabled())
  52862. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52863. else
  52864. g.setColour (Colour (0x80808080));
  52865. Path p;
  52866. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52867. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52868. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52869. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52870. }
  52871. }
  52872. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52873. {
  52874. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52875. }
  52876. class SliderLabelComp : public Label
  52877. {
  52878. public:
  52879. SliderLabelComp() : Label (String::empty, String::empty) {}
  52880. ~SliderLabelComp() {}
  52881. void mouseWheelMove (const MouseEvent&, float, float) {}
  52882. };
  52883. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52884. {
  52885. Label* const l = new SliderLabelComp();
  52886. l->setJustificationType (Justification::centred);
  52887. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52888. l->setColour (Label::backgroundColourId,
  52889. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52890. : slider.findColour (Slider::textBoxBackgroundColourId));
  52891. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52892. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52893. l->setColour (TextEditor::backgroundColourId,
  52894. slider.findColour (Slider::textBoxBackgroundColourId)
  52895. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52896. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52897. return l;
  52898. }
  52899. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52900. {
  52901. return 0;
  52902. }
  52903. static const TextLayout layoutTooltipText (const String& text) throw()
  52904. {
  52905. const float tooltipFontSize = 12.0f;
  52906. const int maxToolTipWidth = 400;
  52907. const Font f (tooltipFontSize, Font::bold);
  52908. TextLayout tl (text, f);
  52909. tl.layout (maxToolTipWidth, Justification::left, true);
  52910. return tl;
  52911. }
  52912. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52913. {
  52914. const TextLayout tl (layoutTooltipText (tipText));
  52915. width = tl.getWidth() + 14;
  52916. height = tl.getHeight() + 6;
  52917. }
  52918. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52919. {
  52920. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52921. const Colour textCol (findColour (TooltipWindow::textColourId));
  52922. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52923. g.setColour (findColour (TooltipWindow::outlineColourId));
  52924. g.drawRect (0, 0, width, height, 1);
  52925. #endif
  52926. const TextLayout tl (layoutTooltipText (text));
  52927. g.setColour (findColour (TooltipWindow::textColourId));
  52928. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52929. }
  52930. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52931. {
  52932. return new TextButton (text, TRANS("click to browse for a different file"));
  52933. }
  52934. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52935. ComboBox* filenameBox,
  52936. Button* browseButton)
  52937. {
  52938. browseButton->setSize (80, filenameComp.getHeight());
  52939. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52940. if (tb != 0)
  52941. tb->changeWidthToFitText();
  52942. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52943. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52944. }
  52945. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52946. int imageX, int imageY, int imageW, int imageH,
  52947. const Colour& overlayColour,
  52948. float imageOpacity,
  52949. ImageButton& button)
  52950. {
  52951. if (! button.isEnabled())
  52952. imageOpacity *= 0.3f;
  52953. if (! overlayColour.isOpaque())
  52954. {
  52955. g.setOpacity (imageOpacity);
  52956. g.drawImage (image, imageX, imageY, imageW, imageH,
  52957. 0, 0, image->getWidth(), image->getHeight(), false);
  52958. }
  52959. if (! overlayColour.isTransparent())
  52960. {
  52961. g.setColour (overlayColour);
  52962. g.drawImage (image, imageX, imageY, imageW, imageH,
  52963. 0, 0, image->getWidth(), image->getHeight(), true);
  52964. }
  52965. }
  52966. void LookAndFeel::drawCornerResizer (Graphics& g,
  52967. int w, int h,
  52968. bool /*isMouseOver*/,
  52969. bool /*isMouseDragging*/)
  52970. {
  52971. const float lineThickness = jmin (w, h) * 0.075f;
  52972. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52973. {
  52974. g.setColour (Colours::lightgrey);
  52975. g.drawLine (w * i,
  52976. h + 1.0f,
  52977. w + 1.0f,
  52978. h * i,
  52979. lineThickness);
  52980. g.setColour (Colours::darkgrey);
  52981. g.drawLine (w * i + lineThickness,
  52982. h + 1.0f,
  52983. w + 1.0f,
  52984. h * i + lineThickness,
  52985. lineThickness);
  52986. }
  52987. }
  52988. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52989. const BorderSize& /*borders*/)
  52990. {
  52991. }
  52992. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52993. const BorderSize& /*border*/, ResizableWindow& window)
  52994. {
  52995. g.fillAll (window.getBackgroundColour());
  52996. }
  52997. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52998. const BorderSize& border, ResizableWindow&)
  52999. {
  53000. g.setColour (Colour (0x80000000));
  53001. g.drawRect (0, 0, w, h);
  53002. g.setColour (Colour (0x19000000));
  53003. g.drawRect (border.getLeft() - 1,
  53004. border.getTop() - 1,
  53005. w + 2 - border.getLeftAndRight(),
  53006. h + 2 - border.getTopAndBottom());
  53007. }
  53008. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  53009. Graphics& g, int w, int h,
  53010. int titleSpaceX, int titleSpaceW,
  53011. const Image* icon,
  53012. bool drawTitleTextOnLeft)
  53013. {
  53014. const bool isActive = window.isActiveWindow();
  53015. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  53016. 0.0f, 0.0f,
  53017. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  53018. 0.0f, (float) h, false));
  53019. g.fillAll();
  53020. Font font (h * 0.65f, Font::bold);
  53021. g.setFont (font);
  53022. int textW = font.getStringWidth (window.getName());
  53023. int iconW = 0;
  53024. int iconH = 0;
  53025. if (icon != 0)
  53026. {
  53027. iconH = (int) font.getHeight();
  53028. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  53029. }
  53030. textW = jmin (titleSpaceW, textW + iconW);
  53031. int textX = drawTitleTextOnLeft ? titleSpaceX
  53032. : jmax (titleSpaceX, (w - textW) / 2);
  53033. if (textX + textW > titleSpaceX + titleSpaceW)
  53034. textX = titleSpaceX + titleSpaceW - textW;
  53035. if (icon != 0)
  53036. {
  53037. g.setOpacity (isActive ? 1.0f : 0.6f);
  53038. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  53039. RectanglePlacement::centred, false);
  53040. textX += iconW;
  53041. textW -= iconW;
  53042. }
  53043. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  53044. g.setColour (findColour (DocumentWindow::textColourId));
  53045. else
  53046. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  53047. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  53048. }
  53049. class GlassWindowButton : public Button
  53050. {
  53051. public:
  53052. GlassWindowButton (const String& name, const Colour& col,
  53053. const Path& normalShape_,
  53054. const Path& toggledShape_) throw()
  53055. : Button (name),
  53056. colour (col),
  53057. normalShape (normalShape_),
  53058. toggledShape (toggledShape_)
  53059. {
  53060. }
  53061. ~GlassWindowButton()
  53062. {
  53063. }
  53064. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  53065. {
  53066. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  53067. if (! isEnabled())
  53068. alpha *= 0.5f;
  53069. float x = 0, y = 0, diam;
  53070. if (getWidth() < getHeight())
  53071. {
  53072. diam = (float) getWidth();
  53073. y = (getHeight() - getWidth()) * 0.5f;
  53074. }
  53075. else
  53076. {
  53077. diam = (float) getHeight();
  53078. y = (getWidth() - getHeight()) * 0.5f;
  53079. }
  53080. x += diam * 0.05f;
  53081. y += diam * 0.05f;
  53082. diam *= 0.9f;
  53083. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  53084. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  53085. g.fillEllipse (x, y, diam, diam);
  53086. x += 2.0f;
  53087. y += 2.0f;
  53088. diam -= 4.0f;
  53089. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  53090. Path& p = getToggleState() ? toggledShape : normalShape;
  53091. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  53092. diam * 0.4f, diam * 0.4f, true));
  53093. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  53094. g.fillPath (p, t);
  53095. }
  53096. juce_UseDebuggingNewOperator
  53097. private:
  53098. Colour colour;
  53099. Path normalShape, toggledShape;
  53100. GlassWindowButton (const GlassWindowButton&);
  53101. const GlassWindowButton& operator= (const GlassWindowButton&);
  53102. };
  53103. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  53104. {
  53105. Path shape;
  53106. const float crossThickness = 0.25f;
  53107. if (buttonType == DocumentWindow::closeButton)
  53108. {
  53109. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  53110. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  53111. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  53112. }
  53113. else if (buttonType == DocumentWindow::minimiseButton)
  53114. {
  53115. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53116. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  53117. }
  53118. else if (buttonType == DocumentWindow::maximiseButton)
  53119. {
  53120. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  53121. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53122. Path fullscreenShape;
  53123. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  53124. fullscreenShape.lineTo (0.0f, 100.0f);
  53125. fullscreenShape.lineTo (0.0f, 0.0f);
  53126. fullscreenShape.lineTo (100.0f, 0.0f);
  53127. fullscreenShape.lineTo (100.0f, 45.0f);
  53128. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53129. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53130. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53131. }
  53132. jassertfalse
  53133. return 0;
  53134. }
  53135. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53136. int titleBarX,
  53137. int titleBarY,
  53138. int titleBarW,
  53139. int titleBarH,
  53140. Button* minimiseButton,
  53141. Button* maximiseButton,
  53142. Button* closeButton,
  53143. bool positionTitleBarButtonsOnLeft)
  53144. {
  53145. const int buttonW = titleBarH - titleBarH / 8;
  53146. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53147. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53148. if (closeButton != 0)
  53149. {
  53150. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53151. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53152. }
  53153. if (positionTitleBarButtonsOnLeft)
  53154. swapVariables (minimiseButton, maximiseButton);
  53155. if (maximiseButton != 0)
  53156. {
  53157. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53158. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53159. }
  53160. if (minimiseButton != 0)
  53161. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53162. }
  53163. int LookAndFeel::getDefaultMenuBarHeight()
  53164. {
  53165. return 24;
  53166. }
  53167. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53168. {
  53169. return new DropShadower (0.4f, 1, 5, 10);
  53170. }
  53171. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53172. int w, int h,
  53173. bool /*isVerticalBar*/,
  53174. bool isMouseOver,
  53175. bool isMouseDragging)
  53176. {
  53177. float alpha = 0.5f;
  53178. if (isMouseOver || isMouseDragging)
  53179. {
  53180. g.fillAll (Colour (0x190000ff));
  53181. alpha = 1.0f;
  53182. }
  53183. const float cx = w * 0.5f;
  53184. const float cy = h * 0.5f;
  53185. const float cr = jmin (w, h) * 0.4f;
  53186. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53187. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53188. true));
  53189. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53190. }
  53191. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53192. const String& text,
  53193. const Justification& position,
  53194. GroupComponent& group)
  53195. {
  53196. const float textH = 15.0f;
  53197. const float indent = 3.0f;
  53198. const float textEdgeGap = 4.0f;
  53199. float cs = 5.0f;
  53200. Font f (textH);
  53201. Path p;
  53202. float x = indent;
  53203. float y = f.getAscent() - 3.0f;
  53204. float w = jmax (0.0f, width - x * 2.0f);
  53205. float h = jmax (0.0f, height - y - indent);
  53206. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53207. const float cs2 = 2.0f * cs;
  53208. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53209. float textX = cs + textEdgeGap;
  53210. if (position.testFlags (Justification::horizontallyCentred))
  53211. textX = cs + (w - cs2 - textW) * 0.5f;
  53212. else if (position.testFlags (Justification::right))
  53213. textX = w - cs - textW - textEdgeGap;
  53214. p.startNewSubPath (x + textX + textW, y);
  53215. p.lineTo (x + w - cs, y);
  53216. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53217. p.lineTo (x + w, y + h - cs);
  53218. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53219. p.lineTo (x + cs, y + h);
  53220. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53221. p.lineTo (x, y + cs);
  53222. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53223. p.lineTo (x + textX, y);
  53224. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53225. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53226. .withMultipliedAlpha (alpha));
  53227. g.strokePath (p, PathStrokeType (2.0f));
  53228. g.setColour (group.findColour (GroupComponent::textColourId)
  53229. .withMultipliedAlpha (alpha));
  53230. g.setFont (f);
  53231. g.drawText (text,
  53232. roundToInt (x + textX), 0,
  53233. roundToInt (textW),
  53234. roundToInt (textH),
  53235. Justification::centred, true);
  53236. }
  53237. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53238. {
  53239. return 1 + tabDepth / 3;
  53240. }
  53241. int LookAndFeel::getTabButtonSpaceAroundImage()
  53242. {
  53243. return 4;
  53244. }
  53245. void LookAndFeel::createTabButtonShape (Path& p,
  53246. int width, int height,
  53247. int /*tabIndex*/,
  53248. const String& /*text*/,
  53249. Button& /*button*/,
  53250. TabbedButtonBar::Orientation orientation,
  53251. const bool /*isMouseOver*/,
  53252. const bool /*isMouseDown*/,
  53253. const bool /*isFrontTab*/)
  53254. {
  53255. const float w = (float) width;
  53256. const float h = (float) height;
  53257. float length = w;
  53258. float depth = h;
  53259. if (orientation == TabbedButtonBar::TabsAtLeft
  53260. || orientation == TabbedButtonBar::TabsAtRight)
  53261. {
  53262. swapVariables (length, depth);
  53263. }
  53264. const float indent = (float) getTabButtonOverlap ((int) depth);
  53265. const float overhang = 4.0f;
  53266. if (orientation == TabbedButtonBar::TabsAtLeft)
  53267. {
  53268. p.startNewSubPath (w, 0.0f);
  53269. p.lineTo (0.0f, indent);
  53270. p.lineTo (0.0f, h - indent);
  53271. p.lineTo (w, h);
  53272. p.lineTo (w + overhang, h + overhang);
  53273. p.lineTo (w + overhang, -overhang);
  53274. }
  53275. else if (orientation == TabbedButtonBar::TabsAtRight)
  53276. {
  53277. p.startNewSubPath (0.0f, 0.0f);
  53278. p.lineTo (w, indent);
  53279. p.lineTo (w, h - indent);
  53280. p.lineTo (0.0f, h);
  53281. p.lineTo (-overhang, h + overhang);
  53282. p.lineTo (-overhang, -overhang);
  53283. }
  53284. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53285. {
  53286. p.startNewSubPath (0.0f, 0.0f);
  53287. p.lineTo (indent, h);
  53288. p.lineTo (w - indent, h);
  53289. p.lineTo (w, 0.0f);
  53290. p.lineTo (w + overhang, -overhang);
  53291. p.lineTo (-overhang, -overhang);
  53292. }
  53293. else
  53294. {
  53295. p.startNewSubPath (0.0f, h);
  53296. p.lineTo (indent, 0.0f);
  53297. p.lineTo (w - indent, 0.0f);
  53298. p.lineTo (w, h);
  53299. p.lineTo (w + overhang, h + overhang);
  53300. p.lineTo (-overhang, h + overhang);
  53301. }
  53302. p.closeSubPath();
  53303. p = p.createPathWithRoundedCorners (3.0f);
  53304. }
  53305. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53306. const Path& path,
  53307. const Colour& preferredColour,
  53308. int /*tabIndex*/,
  53309. const String& /*text*/,
  53310. Button& button,
  53311. TabbedButtonBar::Orientation /*orientation*/,
  53312. const bool /*isMouseOver*/,
  53313. const bool /*isMouseDown*/,
  53314. const bool isFrontTab)
  53315. {
  53316. g.setColour (isFrontTab ? preferredColour
  53317. : preferredColour.withMultipliedAlpha (0.9f));
  53318. g.fillPath (path);
  53319. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53320. : TabbedButtonBar::tabOutlineColourId, false)
  53321. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53322. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53323. }
  53324. void LookAndFeel::drawTabButtonText (Graphics& g,
  53325. int x, int y, int w, int h,
  53326. const Colour& preferredBackgroundColour,
  53327. int /*tabIndex*/,
  53328. const String& text,
  53329. Button& button,
  53330. TabbedButtonBar::Orientation orientation,
  53331. const bool isMouseOver,
  53332. const bool isMouseDown,
  53333. const bool isFrontTab)
  53334. {
  53335. int length = w;
  53336. int depth = h;
  53337. if (orientation == TabbedButtonBar::TabsAtLeft
  53338. || orientation == TabbedButtonBar::TabsAtRight)
  53339. {
  53340. swapVariables (length, depth);
  53341. }
  53342. Font font (depth * 0.6f);
  53343. font.setUnderline (button.hasKeyboardFocus (false));
  53344. GlyphArrangement textLayout;
  53345. textLayout.addFittedText (font, text.trim(),
  53346. 0.0f, 0.0f, (float) length, (float) depth,
  53347. Justification::centred,
  53348. jmax (1, depth / 12));
  53349. AffineTransform transform;
  53350. if (orientation == TabbedButtonBar::TabsAtLeft)
  53351. {
  53352. transform = transform.rotated (float_Pi * -0.5f)
  53353. .translated ((float) x, (float) (y + h));
  53354. }
  53355. else if (orientation == TabbedButtonBar::TabsAtRight)
  53356. {
  53357. transform = transform.rotated (float_Pi * 0.5f)
  53358. .translated ((float) (x + w), (float) y);
  53359. }
  53360. else
  53361. {
  53362. transform = transform.translated ((float) x, (float) y);
  53363. }
  53364. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53365. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53366. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53367. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53368. else
  53369. g.setColour (preferredBackgroundColour.contrasting());
  53370. if (! (isMouseOver || isMouseDown))
  53371. g.setOpacity (0.8f);
  53372. if (! button.isEnabled())
  53373. g.setOpacity (0.3f);
  53374. textLayout.draw (g, transform);
  53375. }
  53376. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53377. const String& text,
  53378. int tabDepth,
  53379. Button&)
  53380. {
  53381. Font f (tabDepth * 0.6f);
  53382. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53383. }
  53384. void LookAndFeel::drawTabButton (Graphics& g,
  53385. int w, int h,
  53386. const Colour& preferredColour,
  53387. int tabIndex,
  53388. const String& text,
  53389. Button& button,
  53390. TabbedButtonBar::Orientation orientation,
  53391. const bool isMouseOver,
  53392. const bool isMouseDown,
  53393. const bool isFrontTab)
  53394. {
  53395. int length = w;
  53396. int depth = h;
  53397. if (orientation == TabbedButtonBar::TabsAtLeft
  53398. || orientation == TabbedButtonBar::TabsAtRight)
  53399. {
  53400. swapVariables (length, depth);
  53401. }
  53402. Path tabShape;
  53403. createTabButtonShape (tabShape, w, h,
  53404. tabIndex, text, button, orientation,
  53405. isMouseOver, isMouseDown, isFrontTab);
  53406. fillTabButtonShape (g, tabShape, preferredColour,
  53407. tabIndex, text, button, orientation,
  53408. isMouseOver, isMouseDown, isFrontTab);
  53409. const int indent = getTabButtonOverlap (depth);
  53410. int x = 0, y = 0;
  53411. if (orientation == TabbedButtonBar::TabsAtLeft
  53412. || orientation == TabbedButtonBar::TabsAtRight)
  53413. {
  53414. y += indent;
  53415. h -= indent * 2;
  53416. }
  53417. else
  53418. {
  53419. x += indent;
  53420. w -= indent * 2;
  53421. }
  53422. drawTabButtonText (g, x, y, w, h, preferredColour,
  53423. tabIndex, text, button, orientation,
  53424. isMouseOver, isMouseDown, isFrontTab);
  53425. }
  53426. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53427. int w, int h,
  53428. TabbedButtonBar& tabBar,
  53429. TabbedButtonBar::Orientation orientation)
  53430. {
  53431. const float shadowSize = 0.2f;
  53432. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53433. Rectangle<int> shadowRect;
  53434. if (orientation == TabbedButtonBar::TabsAtLeft)
  53435. {
  53436. x1 = (float) w;
  53437. x2 = w * (1.0f - shadowSize);
  53438. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53439. }
  53440. else if (orientation == TabbedButtonBar::TabsAtRight)
  53441. {
  53442. x2 = w * shadowSize;
  53443. shadowRect.setBounds (0, 0, (int) x2, h);
  53444. }
  53445. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53446. {
  53447. y2 = h * shadowSize;
  53448. shadowRect.setBounds (0, 0, w, (int) y2);
  53449. }
  53450. else
  53451. {
  53452. y1 = (float) h;
  53453. y2 = h * (1.0f - shadowSize);
  53454. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53455. }
  53456. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53457. Colours::transparentBlack, x2, y2, false));
  53458. shadowRect.expand (2, 2);
  53459. g.fillRect (shadowRect);
  53460. g.setColour (Colour (0x80000000));
  53461. if (orientation == TabbedButtonBar::TabsAtLeft)
  53462. {
  53463. g.fillRect (w - 1, 0, 1, h);
  53464. }
  53465. else if (orientation == TabbedButtonBar::TabsAtRight)
  53466. {
  53467. g.fillRect (0, 0, 1, h);
  53468. }
  53469. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53470. {
  53471. g.fillRect (0, 0, w, 1);
  53472. }
  53473. else
  53474. {
  53475. g.fillRect (0, h - 1, w, 1);
  53476. }
  53477. }
  53478. Button* LookAndFeel::createTabBarExtrasButton()
  53479. {
  53480. const float thickness = 7.0f;
  53481. const float indent = 22.0f;
  53482. Path p;
  53483. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53484. DrawablePath ellipse;
  53485. ellipse.setPath (p);
  53486. ellipse.setFill (Colour (0x99ffffff));
  53487. p.clear();
  53488. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53489. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53490. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53491. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53492. p.setUsingNonZeroWinding (false);
  53493. DrawablePath dp;
  53494. dp.setPath (p);
  53495. dp.setFill (Colour (0x59000000));
  53496. DrawableComposite normalImage;
  53497. normalImage.insertDrawable (ellipse);
  53498. normalImage.insertDrawable (dp);
  53499. dp.setFill (Colour (0xcc000000));
  53500. DrawableComposite overImage;
  53501. overImage.insertDrawable (ellipse);
  53502. overImage.insertDrawable (dp);
  53503. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53504. db->setImages (&normalImage, &overImage, 0);
  53505. return db;
  53506. }
  53507. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53508. {
  53509. g.fillAll (Colours::white);
  53510. const int w = header.getWidth();
  53511. const int h = header.getHeight();
  53512. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53513. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53514. false));
  53515. g.fillRect (0, h / 2, w, h);
  53516. g.setColour (Colour (0x33000000));
  53517. g.fillRect (0, h - 1, w, 1);
  53518. for (int i = header.getNumColumns (true); --i >= 0;)
  53519. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53520. }
  53521. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53522. int width, int height,
  53523. bool isMouseOver, bool isMouseDown,
  53524. int columnFlags)
  53525. {
  53526. if (isMouseDown)
  53527. g.fillAll (Colour (0x8899aadd));
  53528. else if (isMouseOver)
  53529. g.fillAll (Colour (0x5599aadd));
  53530. int rightOfText = width - 4;
  53531. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53532. {
  53533. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53534. const float bottom = height - top;
  53535. const float w = height * 0.5f;
  53536. const float x = rightOfText - (w * 1.25f);
  53537. rightOfText = (int) x;
  53538. Path sortArrow;
  53539. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53540. g.setColour (Colour (0x99000000));
  53541. g.fillPath (sortArrow);
  53542. }
  53543. g.setColour (Colours::black);
  53544. g.setFont (height * 0.5f, Font::bold);
  53545. const int textX = 4;
  53546. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53547. }
  53548. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53549. {
  53550. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53551. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53552. background.darker (0.1f),
  53553. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53554. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53555. false));
  53556. g.fillAll();
  53557. }
  53558. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53559. {
  53560. return createTabBarExtrasButton();
  53561. }
  53562. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53563. bool isMouseOver, bool isMouseDown,
  53564. ToolbarItemComponent& component)
  53565. {
  53566. if (isMouseDown)
  53567. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53568. else if (isMouseOver)
  53569. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53570. }
  53571. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53572. const String& text, ToolbarItemComponent& component)
  53573. {
  53574. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53575. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53576. const float fontHeight = jmin (14.0f, height * 0.85f);
  53577. g.setFont (fontHeight);
  53578. g.drawFittedText (text,
  53579. x, y, width, height,
  53580. Justification::centred,
  53581. jmax (1, height / (int) fontHeight));
  53582. }
  53583. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53584. bool isOpen, int width, int height)
  53585. {
  53586. const int buttonSize = (height * 3) / 4;
  53587. const int buttonIndent = (height - buttonSize) / 2;
  53588. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53589. const int textX = buttonIndent * 2 + buttonSize + 2;
  53590. g.setColour (Colours::black);
  53591. g.setFont (height * 0.7f, Font::bold);
  53592. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53593. }
  53594. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53595. PropertyComponent&)
  53596. {
  53597. g.setColour (Colour (0x66ffffff));
  53598. g.fillRect (0, 0, width, height - 1);
  53599. }
  53600. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53601. PropertyComponent& component)
  53602. {
  53603. g.setColour (Colours::black);
  53604. if (! component.isEnabled())
  53605. g.setOpacity (0.6f);
  53606. g.setFont (jmin (height, 24) * 0.65f);
  53607. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53608. g.drawFittedText (component.getName(),
  53609. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53610. Justification::centredLeft, 2);
  53611. }
  53612. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53613. {
  53614. return Rectangle<int> (component.getWidth() / 3, 1,
  53615. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53616. }
  53617. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53618. const String& instructions,
  53619. GlyphArrangement& text,
  53620. int width)
  53621. {
  53622. text.clear();
  53623. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53624. 8.0f, 22.0f, width - 16.0f,
  53625. Justification::centred);
  53626. text.addJustifiedText (Font (14.0f), instructions,
  53627. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53628. Justification::centred);
  53629. }
  53630. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53631. const String& filename, Image* icon,
  53632. const String& fileSizeDescription,
  53633. const String& fileTimeDescription,
  53634. const bool isDirectory,
  53635. const bool isItemSelected,
  53636. const int /*itemIndex*/)
  53637. {
  53638. if (isItemSelected)
  53639. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53640. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53641. g.setFont (height * 0.7f);
  53642. Image* im = icon;
  53643. Image* toRelease = 0;
  53644. if (im == 0)
  53645. {
  53646. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53647. : getDefaultDocumentFileImage());
  53648. }
  53649. const int x = 32;
  53650. if (im != 0)
  53651. {
  53652. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53653. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53654. false);
  53655. ImageCache::release (toRelease);
  53656. }
  53657. if (width > 450 && ! isDirectory)
  53658. {
  53659. const int sizeX = roundToInt (width * 0.7f);
  53660. const int dateX = roundToInt (width * 0.8f);
  53661. g.drawFittedText (filename,
  53662. x, 0, sizeX - x, height,
  53663. Justification::centredLeft, 1);
  53664. g.setFont (height * 0.5f);
  53665. g.setColour (Colours::darkgrey);
  53666. if (! isDirectory)
  53667. {
  53668. g.drawFittedText (fileSizeDescription,
  53669. sizeX, 0, dateX - sizeX - 8, height,
  53670. Justification::centredRight, 1);
  53671. g.drawFittedText (fileTimeDescription,
  53672. dateX, 0, width - 8 - dateX, height,
  53673. Justification::centredRight, 1);
  53674. }
  53675. }
  53676. else
  53677. {
  53678. g.drawFittedText (filename,
  53679. x, 0, width - x, height,
  53680. Justification::centredLeft, 1);
  53681. }
  53682. }
  53683. Button* LookAndFeel::createFileBrowserGoUpButton()
  53684. {
  53685. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53686. Path arrowPath;
  53687. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53688. DrawablePath arrowImage;
  53689. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53690. arrowImage.setPath (arrowPath);
  53691. goUpButton->setImages (&arrowImage);
  53692. return goUpButton;
  53693. }
  53694. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53695. DirectoryContentsDisplayComponent* fileListComponent,
  53696. FilePreviewComponent* previewComp,
  53697. ComboBox* currentPathBox,
  53698. TextEditor* filenameBox,
  53699. Button* goUpButton)
  53700. {
  53701. const int x = 8;
  53702. int w = browserComp.getWidth() - x - x;
  53703. if (previewComp != 0)
  53704. {
  53705. const int previewWidth = w / 3;
  53706. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53707. w -= previewWidth + 4;
  53708. }
  53709. int y = 4;
  53710. const int controlsHeight = 22;
  53711. const int bottomSectionHeight = controlsHeight + 8;
  53712. const int upButtonWidth = 50;
  53713. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53714. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53715. y += controlsHeight + 4;
  53716. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53717. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53718. y = listAsComp->getBottom() + 4;
  53719. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53720. }
  53721. Image* LookAndFeel::getDefaultFolderImage()
  53722. {
  53723. 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,
  53724. 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,
  53725. 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,
  53726. 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,
  53727. 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,
  53728. 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,
  53729. 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,
  53730. 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,
  53731. 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,
  53732. 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,
  53733. 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,
  53734. 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,
  53735. 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,
  53736. 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,
  53737. 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,
  53738. 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,
  53739. 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,
  53740. 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,
  53741. 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,
  53742. 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,
  53743. 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,
  53744. 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,
  53745. 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,
  53746. 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,
  53747. 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,
  53748. 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,
  53749. 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,
  53750. 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,
  53751. 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,
  53752. 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,
  53753. 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,
  53754. 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,
  53755. 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,
  53756. 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,
  53757. 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,
  53758. 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,
  53759. 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,
  53760. 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,
  53761. 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,
  53762. 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,
  53763. 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,
  53764. 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,
  53765. 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,
  53766. 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};
  53767. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53768. }
  53769. Image* LookAndFeel::getDefaultDocumentFileImage()
  53770. {
  53771. 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,
  53772. 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,
  53773. 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,
  53774. 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,
  53775. 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,
  53776. 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,
  53777. 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,
  53778. 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,
  53779. 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,
  53780. 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,
  53781. 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,
  53782. 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,
  53783. 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,
  53784. 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,
  53785. 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,
  53786. 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,
  53787. 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,
  53788. 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,
  53789. 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,
  53790. 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,
  53791. 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,
  53792. 174,66,96,130,0,0};
  53793. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53794. }
  53795. void LookAndFeel::playAlertSound()
  53796. {
  53797. PlatformUtilities::beep();
  53798. }
  53799. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53800. {
  53801. g.setColour (Colours::white.withAlpha (0.7f));
  53802. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53803. g.setColour (Colours::black.withAlpha (0.2f));
  53804. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53805. const int totalBlocks = 7;
  53806. const int numBlocks = roundToInt (totalBlocks * level);
  53807. const float w = (width - 6.0f) / (float) totalBlocks;
  53808. for (int i = 0; i < totalBlocks; ++i)
  53809. {
  53810. if (i >= numBlocks)
  53811. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53812. else
  53813. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53814. : Colours::red);
  53815. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53816. }
  53817. }
  53818. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53819. {
  53820. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53821. if (keyDescription.isNotEmpty())
  53822. {
  53823. if (button.isEnabled())
  53824. {
  53825. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53826. g.fillAll (textColour.withAlpha (alpha));
  53827. g.setOpacity (0.3f);
  53828. g.drawBevel (0, 0, width, height, 2);
  53829. }
  53830. g.setColour (textColour);
  53831. g.setFont (height * 0.6f);
  53832. g.drawFittedText (keyDescription,
  53833. 3, 0, width - 6, height,
  53834. Justification::centred, 1);
  53835. }
  53836. else
  53837. {
  53838. const float thickness = 7.0f;
  53839. const float indent = 22.0f;
  53840. Path p;
  53841. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53842. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53843. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53844. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53845. p.setUsingNonZeroWinding (false);
  53846. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53847. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53848. }
  53849. if (button.hasKeyboardFocus (false))
  53850. {
  53851. g.setColour (textColour.withAlpha (0.4f));
  53852. g.drawRect (0, 0, width, height);
  53853. }
  53854. }
  53855. static void createRoundedPath (Path& p,
  53856. const float x, const float y,
  53857. const float w, const float h,
  53858. const float cs,
  53859. const bool curveTopLeft, const bool curveTopRight,
  53860. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53861. {
  53862. const float cs2 = 2.0f * cs;
  53863. if (curveTopLeft)
  53864. {
  53865. p.startNewSubPath (x, y + cs);
  53866. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53867. }
  53868. else
  53869. {
  53870. p.startNewSubPath (x, y);
  53871. }
  53872. if (curveTopRight)
  53873. {
  53874. p.lineTo (x + w - cs, y);
  53875. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53876. }
  53877. else
  53878. {
  53879. p.lineTo (x + w, y);
  53880. }
  53881. if (curveBottomRight)
  53882. {
  53883. p.lineTo (x + w, y + h - cs);
  53884. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53885. }
  53886. else
  53887. {
  53888. p.lineTo (x + w, y + h);
  53889. }
  53890. if (curveBottomLeft)
  53891. {
  53892. p.lineTo (x + cs, y + h);
  53893. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53894. }
  53895. else
  53896. {
  53897. p.lineTo (x, y + h);
  53898. }
  53899. p.closeSubPath();
  53900. }
  53901. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53902. float x, float y, float w, float h,
  53903. float maxCornerSize,
  53904. const Colour& baseColour,
  53905. const float strokeWidth,
  53906. const bool flatOnLeft,
  53907. const bool flatOnRight,
  53908. const bool flatOnTop,
  53909. const bool flatOnBottom) throw()
  53910. {
  53911. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53912. return;
  53913. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53914. Path outline;
  53915. createRoundedPath (outline, x, y, w, h, cs,
  53916. ! (flatOnLeft || flatOnTop),
  53917. ! (flatOnRight || flatOnTop),
  53918. ! (flatOnLeft || flatOnBottom),
  53919. ! (flatOnRight || flatOnBottom));
  53920. ColourGradient cg (baseColour, 0.0f, y,
  53921. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53922. false);
  53923. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53924. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53925. g.setGradientFill (cg);
  53926. g.fillPath (outline);
  53927. g.setColour (Colour (0x80000000));
  53928. g.strokePath (outline, PathStrokeType (strokeWidth));
  53929. }
  53930. void LookAndFeel::drawGlassSphere (Graphics& g,
  53931. const float x, const float y,
  53932. const float diameter,
  53933. const Colour& colour,
  53934. const float outlineThickness) throw()
  53935. {
  53936. if (diameter <= outlineThickness)
  53937. return;
  53938. Path p;
  53939. p.addEllipse (x, y, diameter, diameter);
  53940. {
  53941. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53942. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53943. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53944. g.setGradientFill (cg);
  53945. g.fillPath (p);
  53946. }
  53947. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53948. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53949. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53950. ColourGradient cg (Colours::transparentBlack,
  53951. x + diameter * 0.5f, y + diameter * 0.5f,
  53952. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53953. x, y + diameter * 0.5f, true);
  53954. cg.addColour (0.7, Colours::transparentBlack);
  53955. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53956. g.setGradientFill (cg);
  53957. g.fillPath (p);
  53958. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53959. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53960. }
  53961. void LookAndFeel::drawGlassPointer (Graphics& g,
  53962. const float x, const float y,
  53963. const float diameter,
  53964. const Colour& colour, const float outlineThickness,
  53965. const int direction) throw()
  53966. {
  53967. if (diameter <= outlineThickness)
  53968. return;
  53969. Path p;
  53970. p.startNewSubPath (x + diameter * 0.5f, y);
  53971. p.lineTo (x + diameter, y + diameter * 0.6f);
  53972. p.lineTo (x + diameter, y + diameter);
  53973. p.lineTo (x, y + diameter);
  53974. p.lineTo (x, y + diameter * 0.6f);
  53975. p.closeSubPath();
  53976. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53977. {
  53978. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53979. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53980. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53981. g.setGradientFill (cg);
  53982. g.fillPath (p);
  53983. }
  53984. ColourGradient cg (Colours::transparentBlack,
  53985. x + diameter * 0.5f, y + diameter * 0.5f,
  53986. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53987. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53988. cg.addColour (0.5, Colours::transparentBlack);
  53989. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53990. g.setGradientFill (cg);
  53991. g.fillPath (p);
  53992. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53993. g.strokePath (p, PathStrokeType (outlineThickness));
  53994. }
  53995. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53996. const float x, const float y,
  53997. const float width, const float height,
  53998. const Colour& colour,
  53999. const float outlineThickness,
  54000. const float cornerSize,
  54001. const bool flatOnLeft,
  54002. const bool flatOnRight,
  54003. const bool flatOnTop,
  54004. const bool flatOnBottom) throw()
  54005. {
  54006. if (width <= outlineThickness || height <= outlineThickness)
  54007. return;
  54008. const int intX = (int) x;
  54009. const int intY = (int) y;
  54010. const int intW = (int) width;
  54011. const int intH = (int) height;
  54012. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  54013. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  54014. const int intEdge = (int) edgeBlurRadius;
  54015. Path outline;
  54016. createRoundedPath (outline, x, y, width, height, cs,
  54017. ! (flatOnLeft || flatOnTop),
  54018. ! (flatOnRight || flatOnTop),
  54019. ! (flatOnLeft || flatOnBottom),
  54020. ! (flatOnRight || flatOnBottom));
  54021. {
  54022. ColourGradient cg (colour.darker (0.2f), 0, y,
  54023. colour.darker (0.2f), 0, y + height, false);
  54024. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  54025. cg.addColour (0.4, colour);
  54026. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  54027. g.setGradientFill (cg);
  54028. g.fillPath (outline);
  54029. }
  54030. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  54031. colour.darker (0.2f), x, y + height * 0.5f, true);
  54032. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  54033. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  54034. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  54035. {
  54036. g.saveState();
  54037. g.setGradientFill (cg);
  54038. g.reduceClipRegion (intX, intY, intEdge, intH);
  54039. g.fillPath (outline);
  54040. g.restoreState();
  54041. }
  54042. if (! (flatOnRight || flatOnTop || flatOnBottom))
  54043. {
  54044. cg.x1 = x + width - edgeBlurRadius;
  54045. cg.x2 = x + width;
  54046. g.saveState();
  54047. g.setGradientFill (cg);
  54048. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  54049. g.fillPath (outline);
  54050. g.restoreState();
  54051. }
  54052. {
  54053. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  54054. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  54055. Path highlight;
  54056. createRoundedPath (highlight,
  54057. x + leftIndent,
  54058. y + cs * 0.1f,
  54059. width - (leftIndent + rightIndent),
  54060. height * 0.4f, cs * 0.4f,
  54061. ! (flatOnLeft || flatOnTop),
  54062. ! (flatOnRight || flatOnTop),
  54063. ! (flatOnLeft || flatOnBottom),
  54064. ! (flatOnRight || flatOnBottom));
  54065. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  54066. Colours::transparentWhite, 0, y + height * 0.4f, false));
  54067. g.fillPath (highlight);
  54068. }
  54069. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  54070. g.strokePath (outline, PathStrokeType (outlineThickness));
  54071. }
  54072. END_JUCE_NAMESPACE
  54073. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  54074. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54075. BEGIN_JUCE_NAMESPACE
  54076. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  54077. {
  54078. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  54079. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  54080. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  54081. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  54082. setColour (Slider::thumbColourId, Colours::white);
  54083. setColour (Slider::trackColourId, Colour (0x7f000000));
  54084. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  54085. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  54086. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  54087. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  54088. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  54089. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  54090. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  54091. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  54092. }
  54093. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  54094. {
  54095. }
  54096. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  54097. Button& button,
  54098. const Colour& backgroundColour,
  54099. bool isMouseOverButton,
  54100. bool isButtonDown)
  54101. {
  54102. const int width = button.getWidth();
  54103. const int height = button.getHeight();
  54104. const float indent = 2.0f;
  54105. const int cornerSize = jmin (roundToInt (width * 0.4f),
  54106. roundToInt (height * 0.4f));
  54107. Path p;
  54108. p.addRoundedRectangle (indent, indent,
  54109. width - indent * 2.0f,
  54110. height - indent * 2.0f,
  54111. (float) cornerSize);
  54112. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  54113. if (isMouseOverButton)
  54114. {
  54115. if (isButtonDown)
  54116. bc = bc.brighter();
  54117. else if (bc.getBrightness() > 0.5f)
  54118. bc = bc.darker (0.1f);
  54119. else
  54120. bc = bc.brighter (0.1f);
  54121. }
  54122. g.setColour (bc);
  54123. g.fillPath (p);
  54124. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54125. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54126. }
  54127. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54128. Component& /*component*/,
  54129. int x, int y, int w, int h,
  54130. const bool ticked,
  54131. const bool isEnabled,
  54132. const bool /*isMouseOverButton*/,
  54133. const bool isButtonDown)
  54134. {
  54135. Path box;
  54136. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54137. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54138. : Colours::lightgrey.withAlpha (0.1f));
  54139. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  54140. .translated ((float) x, (float) y));
  54141. g.fillPath (box, trans);
  54142. g.setColour (Colours::black.withAlpha (0.6f));
  54143. g.strokePath (box, PathStrokeType (0.9f), trans);
  54144. if (ticked)
  54145. {
  54146. Path tick;
  54147. tick.startNewSubPath (1.5f, 3.0f);
  54148. tick.lineTo (3.0f, 6.0f);
  54149. tick.lineTo (6.0f, 0.0f);
  54150. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54151. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54152. }
  54153. }
  54154. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54155. ToggleButton& button,
  54156. bool isMouseOverButton,
  54157. bool isButtonDown)
  54158. {
  54159. if (button.hasKeyboardFocus (true))
  54160. {
  54161. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54162. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54163. }
  54164. const int tickWidth = jmin (20, button.getHeight() - 4);
  54165. drawTickBox (g, button, 4, (button.getHeight() - tickWidth) / 2,
  54166. tickWidth, tickWidth,
  54167. button.getToggleState(),
  54168. button.isEnabled(),
  54169. isMouseOverButton,
  54170. isButtonDown);
  54171. g.setColour (button.findColour (ToggleButton::textColourId));
  54172. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54173. if (! button.isEnabled())
  54174. g.setOpacity (0.5f);
  54175. const int textX = tickWidth + 5;
  54176. g.drawFittedText (button.getButtonText(),
  54177. textX, 4,
  54178. button.getWidth() - textX - 2, button.getHeight() - 8,
  54179. Justification::centredLeft, 10);
  54180. }
  54181. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54182. int width, int height,
  54183. double progress, const String& textToShow)
  54184. {
  54185. if (progress < 0 || progress >= 1.0)
  54186. {
  54187. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54188. }
  54189. else
  54190. {
  54191. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54192. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54193. g.fillAll (background);
  54194. g.setColour (foreground);
  54195. g.fillRect (1, 1,
  54196. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54197. height - 2);
  54198. if (textToShow.isNotEmpty())
  54199. {
  54200. g.setColour (Colour::contrasting (background, foreground));
  54201. g.setFont (height * 0.6f);
  54202. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54203. }
  54204. }
  54205. }
  54206. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54207. ScrollBar& bar,
  54208. int width, int height,
  54209. int buttonDirection,
  54210. bool isScrollbarVertical,
  54211. bool isMouseOverButton,
  54212. bool isButtonDown)
  54213. {
  54214. if (isScrollbarVertical)
  54215. width -= 2;
  54216. else
  54217. height -= 2;
  54218. Path p;
  54219. if (buttonDirection == 0)
  54220. p.addTriangle (width * 0.5f, height * 0.2f,
  54221. width * 0.1f, height * 0.7f,
  54222. width * 0.9f, height * 0.7f);
  54223. else if (buttonDirection == 1)
  54224. p.addTriangle (width * 0.8f, height * 0.5f,
  54225. width * 0.3f, height * 0.1f,
  54226. width * 0.3f, height * 0.9f);
  54227. else if (buttonDirection == 2)
  54228. p.addTriangle (width * 0.5f, height * 0.8f,
  54229. width * 0.1f, height * 0.3f,
  54230. width * 0.9f, height * 0.3f);
  54231. else if (buttonDirection == 3)
  54232. p.addTriangle (width * 0.2f, height * 0.5f,
  54233. width * 0.7f, height * 0.1f,
  54234. width * 0.7f, height * 0.9f);
  54235. if (isButtonDown)
  54236. g.setColour (Colours::white);
  54237. else if (isMouseOverButton)
  54238. g.setColour (Colours::white.withAlpha (0.7f));
  54239. else
  54240. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54241. g.fillPath (p);
  54242. g.setColour (Colours::black.withAlpha (0.5f));
  54243. g.strokePath (p, PathStrokeType (0.5f));
  54244. }
  54245. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54246. ScrollBar& bar,
  54247. int x, int y,
  54248. int width, int height,
  54249. bool isScrollbarVertical,
  54250. int thumbStartPosition,
  54251. int thumbSize,
  54252. bool isMouseOver,
  54253. bool isMouseDown)
  54254. {
  54255. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54256. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54257. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54258. if (thumbSize > 0.0f)
  54259. {
  54260. Rectangle<int> thumb;
  54261. if (isScrollbarVertical)
  54262. {
  54263. width -= 2;
  54264. g.fillRect (x + roundToInt (width * 0.35f), y,
  54265. roundToInt (width * 0.3f), height);
  54266. thumb.setBounds (x + 1, thumbStartPosition,
  54267. width - 2, thumbSize);
  54268. }
  54269. else
  54270. {
  54271. height -= 2;
  54272. g.fillRect (x, y + roundToInt (height * 0.35f),
  54273. width, roundToInt (height * 0.3f));
  54274. thumb.setBounds (thumbStartPosition, y + 1,
  54275. thumbSize, height - 2);
  54276. }
  54277. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54278. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54279. g.fillRect (thumb);
  54280. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54281. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54282. if (thumbSize > 16)
  54283. {
  54284. for (int i = 3; --i >= 0;)
  54285. {
  54286. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54287. g.setColour (Colours::black.withAlpha (0.15f));
  54288. if (isScrollbarVertical)
  54289. {
  54290. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54291. g.setColour (Colours::white.withAlpha (0.15f));
  54292. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54293. }
  54294. else
  54295. {
  54296. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54297. g.setColour (Colours::white.withAlpha (0.15f));
  54298. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54299. }
  54300. }
  54301. }
  54302. }
  54303. }
  54304. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54305. {
  54306. return &scrollbarShadow;
  54307. }
  54308. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54309. {
  54310. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54311. g.setColour (Colours::black.withAlpha (0.6f));
  54312. g.drawRect (0, 0, width, height);
  54313. }
  54314. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54315. bool, MenuBarComponent& menuBar)
  54316. {
  54317. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54318. }
  54319. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54320. {
  54321. if (textEditor.isEnabled())
  54322. {
  54323. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54324. g.drawRect (0, 0, width, height);
  54325. }
  54326. }
  54327. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54328. const bool isButtonDown,
  54329. int buttonX, int buttonY,
  54330. int buttonW, int buttonH,
  54331. ComboBox& box)
  54332. {
  54333. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54334. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54335. : ComboBox::backgroundColourId));
  54336. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54337. g.setColour (box.findColour (ComboBox::outlineColourId));
  54338. g.drawRect (0, 0, width, height);
  54339. const float arrowX = 0.2f;
  54340. const float arrowH = 0.3f;
  54341. if (box.isEnabled())
  54342. {
  54343. Path p;
  54344. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54345. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54346. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54347. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54348. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54349. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54350. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54351. : ComboBox::buttonColourId));
  54352. g.fillPath (p);
  54353. }
  54354. }
  54355. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54356. {
  54357. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54358. f.setHorizontalScale (0.9f);
  54359. return f;
  54360. }
  54361. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54362. {
  54363. Path p;
  54364. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54365. g.setColour (fill);
  54366. g.fillPath (p);
  54367. g.setColour (outline);
  54368. g.strokePath (p, PathStrokeType (0.3f));
  54369. }
  54370. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54371. int x, int y,
  54372. int w, int h,
  54373. float sliderPos,
  54374. float minSliderPos,
  54375. float maxSliderPos,
  54376. const Slider::SliderStyle style,
  54377. Slider& slider)
  54378. {
  54379. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54380. if (style == Slider::LinearBar)
  54381. {
  54382. g.setColour (slider.findColour (Slider::thumbColourId));
  54383. g.fillRect (x, y, (int) sliderPos - x, h);
  54384. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54385. g.drawRect (x, y, (int) sliderPos - x, h);
  54386. }
  54387. else
  54388. {
  54389. g.setColour (slider.findColour (Slider::trackColourId)
  54390. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54391. if (slider.isHorizontal())
  54392. {
  54393. g.fillRect (x, y + roundToInt (h * 0.6f),
  54394. w, roundToInt (h * 0.2f));
  54395. }
  54396. else
  54397. {
  54398. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54399. jmin (4, roundToInt (w * 0.2f)), h);
  54400. }
  54401. float alpha = 0.35f;
  54402. if (slider.isEnabled())
  54403. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54404. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54405. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54406. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54407. {
  54408. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54409. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54410. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54411. fill, outline);
  54412. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54413. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54414. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54415. fill, outline);
  54416. }
  54417. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54418. {
  54419. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54420. minSliderPos - 7.0f, y + h * 0.9f ,
  54421. minSliderPos, y + h * 0.9f,
  54422. fill, outline);
  54423. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54424. maxSliderPos, y + h * 0.9f,
  54425. maxSliderPos + 7.0f, y + h * 0.9f,
  54426. fill, outline);
  54427. }
  54428. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54429. {
  54430. drawTriangle (g, sliderPos, y + h * 0.9f,
  54431. sliderPos - 7.0f, y + h * 0.2f,
  54432. sliderPos + 7.0f, y + h * 0.2f,
  54433. fill, outline);
  54434. }
  54435. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54436. {
  54437. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54438. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54439. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54440. fill, outline);
  54441. }
  54442. }
  54443. }
  54444. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54445. {
  54446. if (isIncrement)
  54447. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54448. else
  54449. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54450. }
  54451. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54452. {
  54453. return &scrollbarShadow;
  54454. }
  54455. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54456. {
  54457. return 8;
  54458. }
  54459. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54460. int w, int h,
  54461. bool isMouseOver,
  54462. bool isMouseDragging)
  54463. {
  54464. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54465. : Colours::darkgrey);
  54466. const float lineThickness = jmin (w, h) * 0.1f;
  54467. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54468. {
  54469. g.drawLine (w * i,
  54470. h + 1.0f,
  54471. w + 1.0f,
  54472. h * i,
  54473. lineThickness);
  54474. }
  54475. }
  54476. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54477. {
  54478. Path shape;
  54479. if (buttonType == DocumentWindow::closeButton)
  54480. {
  54481. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54482. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54483. ShapeButton* const b = new ShapeButton ("close",
  54484. Colour (0x7fff3333),
  54485. Colour (0xd7ff3333),
  54486. Colour (0xf7ff3333));
  54487. b->setShape (shape, true, true, true);
  54488. return b;
  54489. }
  54490. else if (buttonType == DocumentWindow::minimiseButton)
  54491. {
  54492. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54493. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54494. DrawablePath dp;
  54495. dp.setPath (shape);
  54496. dp.setFill (Colours::black.withAlpha (0.3f));
  54497. b->setImages (&dp);
  54498. return b;
  54499. }
  54500. else if (buttonType == DocumentWindow::maximiseButton)
  54501. {
  54502. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54503. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54504. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54505. DrawablePath dp;
  54506. dp.setPath (shape);
  54507. dp.setFill (Colours::black.withAlpha (0.3f));
  54508. b->setImages (&dp);
  54509. return b;
  54510. }
  54511. jassertfalse
  54512. return 0;
  54513. }
  54514. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54515. int titleBarX,
  54516. int titleBarY,
  54517. int titleBarW,
  54518. int titleBarH,
  54519. Button* minimiseButton,
  54520. Button* maximiseButton,
  54521. Button* closeButton,
  54522. bool positionTitleBarButtonsOnLeft)
  54523. {
  54524. titleBarY += titleBarH / 8;
  54525. titleBarH -= titleBarH / 4;
  54526. const int buttonW = titleBarH;
  54527. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54528. : titleBarX + titleBarW - buttonW - 4;
  54529. if (closeButton != 0)
  54530. {
  54531. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54532. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54533. : -(buttonW + buttonW / 5);
  54534. }
  54535. if (positionTitleBarButtonsOnLeft)
  54536. swapVariables (minimiseButton, maximiseButton);
  54537. if (maximiseButton != 0)
  54538. {
  54539. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54540. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54541. }
  54542. if (minimiseButton != 0)
  54543. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54544. }
  54545. END_JUCE_NAMESPACE
  54546. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54547. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54548. BEGIN_JUCE_NAMESPACE
  54549. class DummyMenuComponent : public Component
  54550. {
  54551. DummyMenuComponent (const DummyMenuComponent&);
  54552. const DummyMenuComponent& operator= (const DummyMenuComponent&);
  54553. public:
  54554. DummyMenuComponent() {}
  54555. ~DummyMenuComponent() {}
  54556. void inputAttemptWhenModal()
  54557. {
  54558. exitModalState (0);
  54559. }
  54560. };
  54561. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54562. : model (0),
  54563. itemUnderMouse (-1),
  54564. currentPopupIndex (-1),
  54565. indexToShowAgain (-1),
  54566. lastMouseX (0),
  54567. lastMouseY (0),
  54568. inModalState (false)
  54569. {
  54570. setRepaintsOnMouseActivity (true);
  54571. setWantsKeyboardFocus (false);
  54572. setMouseClickGrabsKeyboardFocus (false);
  54573. setModel (model_);
  54574. }
  54575. MenuBarComponent::~MenuBarComponent()
  54576. {
  54577. setModel (0);
  54578. Desktop::getInstance().removeGlobalMouseListener (this);
  54579. currentPopup = 0;
  54580. }
  54581. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54582. {
  54583. if (model != newModel)
  54584. {
  54585. if (model != 0)
  54586. model->removeListener (this);
  54587. model = newModel;
  54588. if (model != 0)
  54589. model->addListener (this);
  54590. repaint();
  54591. menuBarItemsChanged (0);
  54592. }
  54593. }
  54594. void MenuBarComponent::paint (Graphics& g)
  54595. {
  54596. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54597. getLookAndFeel().drawMenuBarBackground (g,
  54598. getWidth(),
  54599. getHeight(),
  54600. isMouseOverBar,
  54601. *this);
  54602. if (model != 0)
  54603. {
  54604. for (int i = 0; i < menuNames.size(); ++i)
  54605. {
  54606. g.saveState();
  54607. g.setOrigin (xPositions [i], 0);
  54608. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54609. getLookAndFeel().drawMenuBarItem (g,
  54610. xPositions[i + 1] - xPositions[i],
  54611. getHeight(),
  54612. i,
  54613. menuNames[i],
  54614. i == itemUnderMouse,
  54615. i == currentPopupIndex,
  54616. isMouseOverBar,
  54617. *this);
  54618. g.restoreState();
  54619. }
  54620. }
  54621. }
  54622. void MenuBarComponent::resized()
  54623. {
  54624. xPositions.clear();
  54625. int x = 2;
  54626. xPositions.add (x);
  54627. for (int i = 0; i < menuNames.size(); ++i)
  54628. {
  54629. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54630. xPositions.add (x);
  54631. }
  54632. }
  54633. int MenuBarComponent::getItemAt (const int x, const int y)
  54634. {
  54635. for (int i = 0; i < xPositions.size(); ++i)
  54636. if (x >= xPositions[i] && x < xPositions[i + 1])
  54637. return reallyContains (x, y, true) ? i : -1;
  54638. return -1;
  54639. }
  54640. void MenuBarComponent::repaintMenuItem (int index)
  54641. {
  54642. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54643. {
  54644. const int x1 = xPositions [index];
  54645. const int x2 = xPositions [index + 1];
  54646. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54647. }
  54648. }
  54649. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54650. {
  54651. const int newItem = getItemAt (x, y);
  54652. if (itemUnderMouse != newItem)
  54653. {
  54654. repaintMenuItem (itemUnderMouse);
  54655. itemUnderMouse = newItem;
  54656. repaintMenuItem (itemUnderMouse);
  54657. }
  54658. }
  54659. void MenuBarComponent::hideCurrentMenu()
  54660. {
  54661. currentPopup = 0;
  54662. repaint();
  54663. }
  54664. void MenuBarComponent::showMenu (int index)
  54665. {
  54666. if (index != currentPopupIndex)
  54667. {
  54668. if (inModalState)
  54669. {
  54670. hideCurrentMenu();
  54671. indexToShowAgain = index;
  54672. return;
  54673. }
  54674. indexToShowAgain = -1;
  54675. currentPopupIndex = -1;
  54676. itemUnderMouse = index;
  54677. currentPopup = 0;
  54678. menuBarItemsChanged (0);
  54679. Component* const prevFocused = getCurrentlyFocusedComponent();
  54680. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54681. if (prevFocused != 0)
  54682. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54683. ComponentDeletionWatcher deletionChecker (this);
  54684. enterModalState (false);
  54685. inModalState = true;
  54686. int result = 0;
  54687. ApplicationCommandManager* managerOfChosenCommand = 0;
  54688. Desktop::getInstance().addGlobalMouseListener (this);
  54689. for (;;)
  54690. {
  54691. const int x = getScreenX() + xPositions [itemUnderMouse];
  54692. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54693. currentPopupIndex = itemUnderMouse;
  54694. indexToShowAgain = -1;
  54695. repaint();
  54696. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54697. {
  54698. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54699. menuNames [itemUnderMouse]));
  54700. if (m.lookAndFeel == 0)
  54701. m.setLookAndFeel (&getLookAndFeel());
  54702. currentPopup = m.createMenuComponent (x, getScreenY(),
  54703. w, getHeight(),
  54704. 0, w, 0, 0,
  54705. true, this,
  54706. &managerOfChosenCommand,
  54707. this);
  54708. }
  54709. if (currentPopup == 0)
  54710. {
  54711. currentPopup = new DummyMenuComponent();
  54712. addAndMakeVisible (currentPopup);
  54713. }
  54714. currentPopup->enterModalState (false);
  54715. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54716. // be stuck behind other comps that are already modal..
  54717. result = currentPopup->runModalLoop();
  54718. if (deletionChecker.hasBeenDeleted())
  54719. return;
  54720. const int lastPopupIndex = currentPopupIndex;
  54721. currentPopup = 0;
  54722. currentPopupIndex = -1;
  54723. if (result != 0)
  54724. {
  54725. topLevelIndexClicked = lastPopupIndex;
  54726. break;
  54727. }
  54728. else if (indexToShowAgain >= 0)
  54729. {
  54730. menuBarItemsChanged (0);
  54731. repaint();
  54732. itemUnderMouse = indexToShowAgain;
  54733. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54734. break;
  54735. }
  54736. else
  54737. {
  54738. break;
  54739. }
  54740. }
  54741. Desktop::getInstance().removeGlobalMouseListener (this);
  54742. inModalState = false;
  54743. exitModalState (0);
  54744. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54745. prevFocused->grabKeyboardFocus();
  54746. int mx, my;
  54747. getMouseXYRelative (mx, my);
  54748. updateItemUnderMouse (mx, my);
  54749. repaint();
  54750. if (result != 0)
  54751. {
  54752. if (managerOfChosenCommand != 0)
  54753. {
  54754. ApplicationCommandTarget::InvocationInfo info (result);
  54755. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54756. managerOfChosenCommand->invoke (info, true);
  54757. }
  54758. postCommandMessage (result);
  54759. }
  54760. }
  54761. }
  54762. void MenuBarComponent::handleCommandMessage (int commandId)
  54763. {
  54764. if (model != 0)
  54765. model->menuItemSelected (commandId, topLevelIndexClicked);
  54766. }
  54767. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54768. {
  54769. if (e.eventComponent == this)
  54770. updateItemUnderMouse (e.x, e.y);
  54771. }
  54772. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54773. {
  54774. if (e.eventComponent == this)
  54775. updateItemUnderMouse (e.x, e.y);
  54776. }
  54777. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54778. {
  54779. const MouseEvent e2 (e.getEventRelativeTo (this));
  54780. if (currentPopupIndex < 0)
  54781. {
  54782. updateItemUnderMouse (e2.x, e2.y);
  54783. currentPopupIndex = -2;
  54784. showMenu (itemUnderMouse);
  54785. }
  54786. }
  54787. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54788. {
  54789. const MouseEvent e2 (e.getEventRelativeTo (this));
  54790. const int item = getItemAt (e2.x, e2.y);
  54791. if (item >= 0)
  54792. showMenu (item);
  54793. }
  54794. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54795. {
  54796. const MouseEvent e2 (e.getEventRelativeTo (this));
  54797. updateItemUnderMouse (e2.x, e2.y);
  54798. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54799. hideCurrentMenu();
  54800. }
  54801. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54802. {
  54803. const MouseEvent e2 (e.getEventRelativeTo (this));
  54804. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54805. {
  54806. if (currentPopupIndex >= 0)
  54807. {
  54808. const int item = getItemAt (e2.x, e2.y);
  54809. if (item >= 0)
  54810. showMenu (item);
  54811. }
  54812. else
  54813. {
  54814. updateItemUnderMouse (e2.x, e2.y);
  54815. }
  54816. lastMouseX = e2.x;
  54817. lastMouseY = e2.y;
  54818. }
  54819. }
  54820. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54821. {
  54822. bool used = false;
  54823. const int numMenus = menuNames.size();
  54824. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54825. if (key.isKeyCode (KeyPress::leftKey))
  54826. {
  54827. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54828. used = true;
  54829. }
  54830. else if (key.isKeyCode (KeyPress::rightKey))
  54831. {
  54832. showMenu ((currentIndex + 1) % numMenus);
  54833. used = true;
  54834. }
  54835. return used;
  54836. }
  54837. void MenuBarComponent::inputAttemptWhenModal()
  54838. {
  54839. hideCurrentMenu();
  54840. }
  54841. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54842. {
  54843. StringArray newNames;
  54844. if (model != 0)
  54845. newNames = model->getMenuBarNames();
  54846. if (newNames != menuNames)
  54847. {
  54848. menuNames = newNames;
  54849. repaint();
  54850. resized();
  54851. }
  54852. }
  54853. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54854. const ApplicationCommandTarget::InvocationInfo& info)
  54855. {
  54856. if (model == 0
  54857. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54858. return;
  54859. for (int i = 0; i < menuNames.size(); ++i)
  54860. {
  54861. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54862. if (menu.containsCommandItem (info.commandID))
  54863. {
  54864. itemUnderMouse = i;
  54865. repaintMenuItem (i);
  54866. startTimer (200);
  54867. break;
  54868. }
  54869. }
  54870. }
  54871. void MenuBarComponent::timerCallback()
  54872. {
  54873. stopTimer();
  54874. int mx, my;
  54875. getMouseXYRelative (mx, my);
  54876. updateItemUnderMouse (mx, my);
  54877. }
  54878. END_JUCE_NAMESPACE
  54879. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54880. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54881. BEGIN_JUCE_NAMESPACE
  54882. MenuBarModel::MenuBarModel() throw()
  54883. : manager (0)
  54884. {
  54885. }
  54886. MenuBarModel::~MenuBarModel()
  54887. {
  54888. setApplicationCommandManagerToWatch (0);
  54889. }
  54890. void MenuBarModel::menuItemsChanged()
  54891. {
  54892. triggerAsyncUpdate();
  54893. }
  54894. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54895. {
  54896. if (manager != newManager)
  54897. {
  54898. if (manager != 0)
  54899. manager->removeListener (this);
  54900. manager = newManager;
  54901. if (manager != 0)
  54902. manager->addListener (this);
  54903. }
  54904. }
  54905. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54906. {
  54907. jassert (newListener != 0);
  54908. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54909. if (newListener != 0)
  54910. listeners.add (newListener);
  54911. }
  54912. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54913. {
  54914. // Trying to remove a listener that isn't on the list!
  54915. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54916. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54917. jassert (listeners.contains (listenerToRemove));
  54918. listeners.removeValue (listenerToRemove);
  54919. }
  54920. void MenuBarModel::handleAsyncUpdate()
  54921. {
  54922. for (int i = listeners.size(); --i >= 0;)
  54923. {
  54924. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54925. i = jmin (i, listeners.size());
  54926. }
  54927. }
  54928. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54929. {
  54930. for (int i = listeners.size(); --i >= 0;)
  54931. {
  54932. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54933. i = jmin (i, listeners.size());
  54934. }
  54935. }
  54936. void MenuBarModel::applicationCommandListChanged()
  54937. {
  54938. menuItemsChanged();
  54939. }
  54940. END_JUCE_NAMESPACE
  54941. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54942. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54943. BEGIN_JUCE_NAMESPACE
  54944. class PopupMenu::Item
  54945. {
  54946. public:
  54947. Item()
  54948. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54949. usesColour (false), customComp (0), commandManager (0)
  54950. {
  54951. }
  54952. Item (const int itemId_,
  54953. const String& text_,
  54954. const bool active_,
  54955. const bool isTicked_,
  54956. const Image* im,
  54957. const Colour& textColour_,
  54958. const bool usesColour_,
  54959. PopupMenuCustomComponent* const customComp_,
  54960. const PopupMenu* const subMenu_,
  54961. ApplicationCommandManager* const commandManager_)
  54962. : itemId (itemId_), text (text_), textColour (textColour_),
  54963. active (active_), isSeparator (false), isTicked (isTicked_),
  54964. usesColour (usesColour_), customComp (customComp_),
  54965. commandManager (commandManager_)
  54966. {
  54967. if (subMenu_ != 0)
  54968. subMenu = new PopupMenu (*subMenu_);
  54969. if (im != 0)
  54970. image = im->createCopy();
  54971. if (commandManager_ != 0 && itemId_ != 0)
  54972. {
  54973. String shortcutKey;
  54974. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54975. ->getKeyPressesAssignedToCommand (itemId_));
  54976. for (int i = 0; i < keyPresses.size(); ++i)
  54977. {
  54978. const String key (keyPresses.getReference(i).getTextDescription());
  54979. if (shortcutKey.isNotEmpty())
  54980. shortcutKey << ", ";
  54981. if (key.length() == 1)
  54982. shortcutKey << "shortcut: '" << key << '\'';
  54983. else
  54984. shortcutKey << key;
  54985. }
  54986. shortcutKey = shortcutKey.trim();
  54987. if (shortcutKey.isNotEmpty())
  54988. text << "<end>" << shortcutKey;
  54989. }
  54990. }
  54991. Item (const Item& other)
  54992. : itemId (other.itemId),
  54993. text (other.text),
  54994. textColour (other.textColour),
  54995. active (other.active),
  54996. isSeparator (other.isSeparator),
  54997. isTicked (other.isTicked),
  54998. usesColour (other.usesColour),
  54999. customComp (other.customComp),
  55000. commandManager (other.commandManager)
  55001. {
  55002. if (other.subMenu != 0)
  55003. subMenu = new PopupMenu (*(other.subMenu));
  55004. if (other.image != 0)
  55005. image = other.image->createCopy();
  55006. }
  55007. ~Item()
  55008. {
  55009. customComp = 0;
  55010. }
  55011. bool canBeTriggered() const throw()
  55012. {
  55013. return active && ! (isSeparator || (subMenu != 0));
  55014. }
  55015. bool hasActiveSubMenu() const throw()
  55016. {
  55017. return active && (subMenu != 0);
  55018. }
  55019. const int itemId;
  55020. String text;
  55021. const Colour textColour;
  55022. const bool active, isSeparator, isTicked, usesColour;
  55023. ScopedPointer <Image> image;
  55024. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  55025. ScopedPointer <PopupMenu> subMenu;
  55026. ApplicationCommandManager* const commandManager;
  55027. juce_UseDebuggingNewOperator
  55028. private:
  55029. Item& operator= (const Item&);
  55030. };
  55031. class PopupMenu::ItemComponent : public Component
  55032. {
  55033. public:
  55034. ItemComponent (const PopupMenu::Item& itemInfo_)
  55035. : itemInfo (itemInfo_),
  55036. isHighlighted (false)
  55037. {
  55038. if (itemInfo.customComp != 0)
  55039. addAndMakeVisible (itemInfo.customComp);
  55040. }
  55041. ~ItemComponent()
  55042. {
  55043. if (itemInfo.customComp != 0)
  55044. removeChildComponent (itemInfo.customComp);
  55045. }
  55046. void getIdealSize (int& idealWidth,
  55047. int& idealHeight,
  55048. const int standardItemHeight)
  55049. {
  55050. if (itemInfo.customComp != 0)
  55051. {
  55052. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  55053. }
  55054. else
  55055. {
  55056. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  55057. itemInfo.isSeparator,
  55058. standardItemHeight,
  55059. idealWidth,
  55060. idealHeight);
  55061. }
  55062. }
  55063. void paint (Graphics& g)
  55064. {
  55065. if (itemInfo.customComp == 0)
  55066. {
  55067. String mainText (itemInfo.text);
  55068. String endText;
  55069. const int endIndex = mainText.indexOf (T("<end>"));
  55070. if (endIndex >= 0)
  55071. {
  55072. endText = mainText.substring (endIndex + 5).trim();
  55073. mainText = mainText.substring (0, endIndex);
  55074. }
  55075. getLookAndFeel()
  55076. .drawPopupMenuItem (g, getWidth(), getHeight(),
  55077. itemInfo.isSeparator,
  55078. itemInfo.active,
  55079. isHighlighted,
  55080. itemInfo.isTicked,
  55081. itemInfo.subMenu != 0,
  55082. mainText, endText,
  55083. itemInfo.image,
  55084. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  55085. }
  55086. }
  55087. void resized()
  55088. {
  55089. if (getNumChildComponents() > 0)
  55090. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  55091. }
  55092. void setHighlighted (bool shouldBeHighlighted)
  55093. {
  55094. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  55095. if (isHighlighted != shouldBeHighlighted)
  55096. {
  55097. isHighlighted = shouldBeHighlighted;
  55098. if (itemInfo.customComp != 0)
  55099. {
  55100. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  55101. itemInfo.customComp->repaint();
  55102. }
  55103. repaint();
  55104. }
  55105. }
  55106. PopupMenu::Item itemInfo;
  55107. juce_UseDebuggingNewOperator
  55108. private:
  55109. bool isHighlighted;
  55110. ItemComponent (const ItemComponent&);
  55111. ItemComponent& operator= (const ItemComponent&);
  55112. };
  55113. namespace PopupMenuSettings
  55114. {
  55115. static const int scrollZone = 24;
  55116. static const int borderSize = 2;
  55117. static const int timerInterval = 50;
  55118. static const int dismissCommandId = 0x6287345f;
  55119. }
  55120. class PopupMenu::Window : public Component,
  55121. private Timer
  55122. {
  55123. public:
  55124. Window()
  55125. : Component (T("menu")),
  55126. owner (0),
  55127. currentChild (0),
  55128. activeSubMenu (0),
  55129. menuBarComponent (0),
  55130. managerOfChosenCommand (0),
  55131. componentAttachedTo (0),
  55132. lastMouseX (0),
  55133. lastMouseY (0),
  55134. minimumWidth (0),
  55135. maximumNumColumns (7),
  55136. standardItemHeight (0),
  55137. isOver (false),
  55138. hasBeenOver (false),
  55139. isDown (false),
  55140. needsToScroll (false),
  55141. hideOnExit (false),
  55142. disableMouseMoves (false),
  55143. hasAnyJuceCompHadFocus (false),
  55144. numColumns (0),
  55145. contentHeight (0),
  55146. childYOffset (0),
  55147. timeEnteredCurrentChildComp (0),
  55148. scrollAcceleration (1.0)
  55149. {
  55150. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55151. setWantsKeyboardFocus (true);
  55152. setMouseClickGrabsKeyboardFocus (false);
  55153. setOpaque (true);
  55154. setAlwaysOnTop (true);
  55155. Desktop::getInstance().addGlobalMouseListener (this);
  55156. getActiveWindows().add (this);
  55157. }
  55158. ~Window()
  55159. {
  55160. getActiveWindows().removeValue (this);
  55161. Desktop::getInstance().removeGlobalMouseListener (this);
  55162. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55163. activeSubMenu = 0;
  55164. deleteAllChildren();
  55165. attachedCompWatcher = 0;
  55166. }
  55167. static Window* create (const PopupMenu& menu,
  55168. const bool dismissOnMouseUp,
  55169. Window* const owner_,
  55170. const int minX, const int maxX,
  55171. const int minY, const int maxY,
  55172. const int minimumWidth,
  55173. const int maximumNumColumns,
  55174. const int standardItemHeight,
  55175. const bool alignToRectangle,
  55176. const int itemIdThatMustBeVisible,
  55177. Component* const menuBarComponent,
  55178. ApplicationCommandManager** managerOfChosenCommand,
  55179. Component* const componentAttachedTo)
  55180. {
  55181. if (menu.items.size() > 0)
  55182. {
  55183. int totalItems = 0;
  55184. ScopedPointer <Window> mw (new Window());
  55185. mw->setLookAndFeel (menu.lookAndFeel);
  55186. mw->setWantsKeyboardFocus (false);
  55187. mw->minimumWidth = minimumWidth;
  55188. mw->maximumNumColumns = maximumNumColumns;
  55189. mw->standardItemHeight = standardItemHeight;
  55190. mw->dismissOnMouseUp = dismissOnMouseUp;
  55191. for (int i = 0; i < menu.items.size(); ++i)
  55192. {
  55193. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  55194. mw->addItem (*item);
  55195. ++totalItems;
  55196. }
  55197. if (totalItems > 0)
  55198. {
  55199. mw->owner = owner_;
  55200. mw->menuBarComponent = menuBarComponent;
  55201. mw->managerOfChosenCommand = managerOfChosenCommand;
  55202. mw->componentAttachedTo = componentAttachedTo;
  55203. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55204. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55205. mw->setTopLeftPosition (mw->windowPos.getX(),
  55206. mw->windowPos.getY());
  55207. mw->updateYPositions();
  55208. if (itemIdThatMustBeVisible != 0)
  55209. {
  55210. const int y = minY - mw->windowPos.getY();
  55211. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55212. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55213. }
  55214. mw->resizeToBestWindowPos();
  55215. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55216. | mw->getLookAndFeel().getMenuWindowFlags());
  55217. return mw.release();
  55218. }
  55219. }
  55220. return 0;
  55221. }
  55222. void paint (Graphics& g)
  55223. {
  55224. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55225. }
  55226. void paintOverChildren (Graphics& g)
  55227. {
  55228. if (isScrolling())
  55229. {
  55230. LookAndFeel& lf = getLookAndFeel();
  55231. if (isScrollZoneActive (false))
  55232. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  55233. if (isScrollZoneActive (true))
  55234. {
  55235. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  55236. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  55237. }
  55238. }
  55239. }
  55240. bool isScrollZoneActive (bool bottomOne) const
  55241. {
  55242. return isScrolling()
  55243. && (bottomOne
  55244. ? childYOffset < contentHeight - windowPos.getHeight()
  55245. : childYOffset > 0);
  55246. }
  55247. void addItem (const PopupMenu::Item& item)
  55248. {
  55249. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  55250. addAndMakeVisible (mic);
  55251. int itemW = 80;
  55252. int itemH = 16;
  55253. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55254. mic->setSize (itemW, jlimit (2, 600, itemH));
  55255. mic->addMouseListener (this, false);
  55256. }
  55257. // hide this and all sub-comps
  55258. void hide (const PopupMenu::Item* const item)
  55259. {
  55260. if (isVisible())
  55261. {
  55262. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55263. activeSubMenu = 0;
  55264. currentChild = 0;
  55265. exitModalState (item != 0 ? item->itemId : 0);
  55266. setVisible (false);
  55267. if (item != 0
  55268. && item->commandManager != 0
  55269. && item->itemId != 0)
  55270. {
  55271. *managerOfChosenCommand = item->commandManager;
  55272. }
  55273. }
  55274. }
  55275. void dismissMenu (const PopupMenu::Item* const item)
  55276. {
  55277. if (owner != 0)
  55278. {
  55279. owner->dismissMenu (item);
  55280. }
  55281. else
  55282. {
  55283. if (item != 0)
  55284. {
  55285. // need a copy of this on the stack as the one passed in will get deleted during this call
  55286. const PopupMenu::Item mi (*item);
  55287. hide (&mi);
  55288. }
  55289. else
  55290. {
  55291. hide (0);
  55292. }
  55293. }
  55294. }
  55295. void mouseMove (const MouseEvent&)
  55296. {
  55297. timerCallback();
  55298. }
  55299. void mouseDown (const MouseEvent&)
  55300. {
  55301. timerCallback();
  55302. }
  55303. void mouseDrag (const MouseEvent&)
  55304. {
  55305. timerCallback();
  55306. }
  55307. void mouseUp (const MouseEvent&)
  55308. {
  55309. timerCallback();
  55310. }
  55311. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55312. {
  55313. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  55314. lastMouseX = -1;
  55315. }
  55316. bool keyPressed (const KeyPress& key)
  55317. {
  55318. if (key.isKeyCode (KeyPress::downKey))
  55319. {
  55320. selectNextItem (1);
  55321. }
  55322. else if (key.isKeyCode (KeyPress::upKey))
  55323. {
  55324. selectNextItem (-1);
  55325. }
  55326. else if (key.isKeyCode (KeyPress::leftKey))
  55327. {
  55328. Window* parentWindow = owner;
  55329. if (parentWindow != 0)
  55330. {
  55331. PopupMenu::ItemComponent* currentChildOfParent
  55332. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55333. hide (0);
  55334. if (parentWindow->isValidComponent())
  55335. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55336. disableTimerUntilMouseMoves();
  55337. }
  55338. else if (menuBarComponent != 0)
  55339. {
  55340. menuBarComponent->keyPressed (key);
  55341. }
  55342. }
  55343. else if (key.isKeyCode (KeyPress::rightKey))
  55344. {
  55345. disableTimerUntilMouseMoves();
  55346. if (showSubMenuFor (currentChild))
  55347. {
  55348. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55349. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55350. activeSubMenu->selectNextItem (1);
  55351. }
  55352. else if (menuBarComponent != 0)
  55353. {
  55354. menuBarComponent->keyPressed (key);
  55355. }
  55356. }
  55357. else if (key.isKeyCode (KeyPress::returnKey))
  55358. {
  55359. triggerCurrentlyHighlightedItem();
  55360. }
  55361. else if (key.isKeyCode (KeyPress::escapeKey))
  55362. {
  55363. dismissMenu (0);
  55364. }
  55365. else
  55366. {
  55367. return false;
  55368. }
  55369. return true;
  55370. }
  55371. void inputAttemptWhenModal()
  55372. {
  55373. timerCallback();
  55374. if (! isOverAnyMenu())
  55375. {
  55376. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55377. {
  55378. // we want to dismiss the menu, but if we do it synchronously, then
  55379. // the mouse-click will be allowed to pass through. That's good, except
  55380. // when the user clicks on the button that orginally popped the menu up,
  55381. // as they'll expect the menu to go away, and in fact it'll just
  55382. // come back. So only dismiss synchronously if they're not on the original
  55383. // comp that we're attached to.
  55384. int mx, my;
  55385. componentAttachedTo->getMouseXYRelative (mx, my);
  55386. if (componentAttachedTo->reallyContains (mx, my, true))
  55387. {
  55388. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  55389. return;
  55390. }
  55391. }
  55392. dismissMenu (0);
  55393. }
  55394. }
  55395. void handleCommandMessage (int commandId)
  55396. {
  55397. Component::handleCommandMessage (commandId);
  55398. if (commandId == PopupMenuSettings::dismissCommandId)
  55399. dismissMenu (0);
  55400. }
  55401. void timerCallback()
  55402. {
  55403. if (! isVisible())
  55404. return;
  55405. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55406. {
  55407. dismissMenu (0);
  55408. return;
  55409. }
  55410. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  55411. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55412. return;
  55413. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  55414. // move rather than a real timer callback
  55415. int mx, my;
  55416. Desktop::getMousePosition (mx, my);
  55417. int x = mx, y = my;
  55418. globalPositionToRelative (x, y);
  55419. const uint32 now = Time::getMillisecondCounter();
  55420. if (now > timeEnteredCurrentChildComp + 100
  55421. && reallyContains (x, y, true)
  55422. && currentChild->isValidComponent()
  55423. && (! disableMouseMoves)
  55424. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55425. {
  55426. showSubMenuFor (currentChild);
  55427. }
  55428. if (mx != lastMouseX || my != lastMouseY || now > lastMouseMoveTime + 350)
  55429. {
  55430. highlightItemUnderMouse (mx, my, x, y);
  55431. }
  55432. bool overScrollArea = false;
  55433. if (isScrolling()
  55434. && (isOver || (isDown && ((unsigned int) x) < (unsigned int) getWidth()))
  55435. && ((isScrollZoneActive (false) && y < PopupMenuSettings::scrollZone)
  55436. || (isScrollZoneActive (true) && y > getHeight() - PopupMenuSettings::scrollZone)))
  55437. {
  55438. if (now > lastScroll + 20)
  55439. {
  55440. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55441. int amount = 0;
  55442. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55443. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55444. alterChildYPos (y < PopupMenuSettings::scrollZone ? -amount : amount);
  55445. lastScroll = now;
  55446. }
  55447. overScrollArea = true;
  55448. lastMouseX = -1; // trigger a mouse-move
  55449. }
  55450. else
  55451. {
  55452. scrollAcceleration = 1.0;
  55453. }
  55454. const bool wasDown = isDown;
  55455. bool isOverAny = isOverAnyMenu();
  55456. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55457. {
  55458. activeSubMenu->updateMouseOverStatus (mx, my);
  55459. isOverAny = isOverAnyMenu();
  55460. }
  55461. if (hideOnExit && hasBeenOver && ! isOverAny)
  55462. {
  55463. hide (0);
  55464. }
  55465. else
  55466. {
  55467. isDown = hasBeenOver
  55468. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55469. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55470. bool anyFocused = Process::isForegroundProcess();
  55471. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55472. {
  55473. // because no component at all may have focus, our test here will
  55474. // only be triggered when something has focus and then loses it.
  55475. anyFocused = ! hasAnyJuceCompHadFocus;
  55476. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55477. {
  55478. if (ComponentPeer::getPeer (i)->isFocused())
  55479. {
  55480. anyFocused = true;
  55481. hasAnyJuceCompHadFocus = true;
  55482. break;
  55483. }
  55484. }
  55485. }
  55486. if (! anyFocused)
  55487. {
  55488. if (now > lastFocused + 10)
  55489. {
  55490. wasHiddenBecauseOfAppChange() = true;
  55491. dismissMenu (0);
  55492. return; // may have been deleted by the previous call..
  55493. }
  55494. }
  55495. else if (wasDown && now > menuCreationTime + 250
  55496. && ! (isDown || overScrollArea))
  55497. {
  55498. isOver = reallyContains (x, y, true);
  55499. if (isOver)
  55500. {
  55501. triggerCurrentlyHighlightedItem();
  55502. }
  55503. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55504. {
  55505. dismissMenu (0);
  55506. }
  55507. return; // may have been deleted by the previous calls..
  55508. }
  55509. else
  55510. {
  55511. lastFocused = now;
  55512. }
  55513. }
  55514. }
  55515. static Array<Window*>& getActiveWindows()
  55516. {
  55517. static Array<Window*> activeMenuWindows;
  55518. return activeMenuWindows;
  55519. }
  55520. static bool& wasHiddenBecauseOfAppChange() throw()
  55521. {
  55522. static bool b = false;
  55523. return b;
  55524. }
  55525. juce_UseDebuggingNewOperator
  55526. private:
  55527. Window* owner;
  55528. PopupMenu::ItemComponent* currentChild;
  55529. ScopedPointer <Window> activeSubMenu;
  55530. Component* menuBarComponent;
  55531. ApplicationCommandManager** managerOfChosenCommand;
  55532. Component* componentAttachedTo;
  55533. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55534. Rectangle<int> windowPos;
  55535. int lastMouseX, lastMouseY;
  55536. int minimumWidth, maximumNumColumns, standardItemHeight;
  55537. bool isOver, hasBeenOver, isDown, needsToScroll;
  55538. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55539. int numColumns, contentHeight, childYOffset;
  55540. Array <int> columnWidths;
  55541. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55542. double scrollAcceleration;
  55543. bool overlaps (const Rectangle<int>& r) const
  55544. {
  55545. return r.intersects (getBounds())
  55546. || (owner != 0 && owner->overlaps (r));
  55547. }
  55548. bool isOverAnyMenu() const
  55549. {
  55550. return (owner != 0) ? owner->isOverAnyMenu()
  55551. : isOverChildren();
  55552. }
  55553. bool isOverChildren() const
  55554. {
  55555. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55556. return isVisible()
  55557. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55558. }
  55559. void updateMouseOverStatus (const int mx, const int my)
  55560. {
  55561. int rx = mx, ry = my;
  55562. globalPositionToRelative (rx, ry);
  55563. isOver = reallyContains (rx, ry, true);
  55564. if (activeSubMenu != 0)
  55565. activeSubMenu->updateMouseOverStatus (mx, my);
  55566. }
  55567. bool treeContains (const Window* const window) const throw()
  55568. {
  55569. const Window* mw = this;
  55570. while (mw->owner != 0)
  55571. mw = mw->owner;
  55572. while (mw != 0)
  55573. {
  55574. if (mw == window)
  55575. return true;
  55576. mw = mw->activeSubMenu;
  55577. }
  55578. return false;
  55579. }
  55580. void calculateWindowPos (const int minX, const int maxX,
  55581. const int minY, const int maxY,
  55582. const bool alignToRectangle)
  55583. {
  55584. const Rectangle<int> mon (Desktop::getInstance()
  55585. .getMonitorAreaContaining ((minX + maxX) / 2,
  55586. (minY + maxY) / 2,
  55587. #if JUCE_MAC
  55588. true));
  55589. #else
  55590. false)); // on windows, don't stop the menu overlapping the taskbar
  55591. #endif
  55592. int x, y, widthToUse, heightToUse;
  55593. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55594. if (alignToRectangle)
  55595. {
  55596. x = minX;
  55597. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55598. const int spaceOver = minY - mon.getY();
  55599. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55600. y = maxY;
  55601. else
  55602. y = minY - heightToUse;
  55603. }
  55604. else
  55605. {
  55606. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55607. if (owner != 0)
  55608. {
  55609. if (owner->owner != 0)
  55610. {
  55611. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55612. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55613. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55614. tendTowardsRight = true;
  55615. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55616. tendTowardsRight = false;
  55617. }
  55618. else if (maxX + widthToUse < mon.getRight() - 32)
  55619. {
  55620. tendTowardsRight = true;
  55621. }
  55622. }
  55623. const int biggestSpace = jmax (mon.getRight() - maxX,
  55624. minX - mon.getX()) - 32;
  55625. if (biggestSpace < widthToUse)
  55626. {
  55627. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55628. if (numColumns > 1)
  55629. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55630. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55631. }
  55632. if (tendTowardsRight)
  55633. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55634. else
  55635. x = jmax (mon.getX() + 4, minX - widthToUse);
  55636. y = minY;
  55637. if ((minY + maxY) / 2 > mon.getCentreY())
  55638. y = jmax (mon.getY(), maxY - heightToUse);
  55639. }
  55640. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55641. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55642. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55643. // sets this flag if it's big enough to obscure any of its parent menus
  55644. hideOnExit = (owner != 0)
  55645. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55646. }
  55647. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55648. {
  55649. numColumns = 0;
  55650. contentHeight = 0;
  55651. const int maxMenuH = getParentHeight() - 24;
  55652. int totalW;
  55653. do
  55654. {
  55655. ++numColumns;
  55656. totalW = workOutBestSize (maxMenuW);
  55657. if (totalW > maxMenuW)
  55658. {
  55659. numColumns = jmax (1, numColumns - 1);
  55660. totalW = workOutBestSize (maxMenuW); // to update col widths
  55661. break;
  55662. }
  55663. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55664. {
  55665. break;
  55666. }
  55667. } while (numColumns < maximumNumColumns);
  55668. const int actualH = jmin (contentHeight, maxMenuH);
  55669. needsToScroll = contentHeight > actualH;
  55670. width = updateYPositions();
  55671. height = actualH + PopupMenuSettings::borderSize * 2;
  55672. }
  55673. int workOutBestSize (const int maxMenuW)
  55674. {
  55675. int totalW = 0;
  55676. contentHeight = 0;
  55677. int childNum = 0;
  55678. for (int col = 0; col < numColumns; ++col)
  55679. {
  55680. int i, colW = 50, colH = 0;
  55681. const int numChildren = jmin (getNumChildComponents() - childNum,
  55682. (getNumChildComponents() + numColumns - 1) / numColumns);
  55683. for (i = numChildren; --i >= 0;)
  55684. {
  55685. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55686. colH += getChildComponent (childNum + i)->getHeight();
  55687. }
  55688. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55689. columnWidths.set (col, colW);
  55690. totalW += colW;
  55691. contentHeight = jmax (contentHeight, colH);
  55692. childNum += numChildren;
  55693. }
  55694. if (totalW < minimumWidth)
  55695. {
  55696. totalW = minimumWidth;
  55697. for (int col = 0; col < numColumns; ++col)
  55698. columnWidths.set (0, totalW / numColumns);
  55699. }
  55700. return totalW;
  55701. }
  55702. void ensureItemIsVisible (const int itemId, int wantedY)
  55703. {
  55704. jassert (itemId != 0)
  55705. for (int i = getNumChildComponents(); --i >= 0;)
  55706. {
  55707. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55708. if (m != 0
  55709. && m->itemInfo.itemId == itemId
  55710. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55711. {
  55712. const int currentY = m->getY();
  55713. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55714. {
  55715. if (wantedY < 0)
  55716. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55717. jmax (PopupMenuSettings::scrollZone,
  55718. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55719. currentY);
  55720. const Rectangle<int> mon (Desktop::getInstance()
  55721. .getMonitorAreaContaining (windowPos.getX(),
  55722. windowPos.getY(),
  55723. true));
  55724. int deltaY = wantedY - currentY;
  55725. const int newY = jlimit (mon.getY(),
  55726. mon.getBottom() - windowPos.getHeight(),
  55727. windowPos.getY() + deltaY);
  55728. deltaY -= newY - windowPos.getY();
  55729. childYOffset -= deltaY;
  55730. windowPos.setPosition (windowPos.getX(), newY);
  55731. updateYPositions();
  55732. }
  55733. break;
  55734. }
  55735. }
  55736. }
  55737. void resizeToBestWindowPos()
  55738. {
  55739. Rectangle<int> r (windowPos);
  55740. if (childYOffset < 0)
  55741. {
  55742. r.setBounds (r.getX(), r.getY() - childYOffset,
  55743. r.getWidth(), r.getHeight() + childYOffset);
  55744. }
  55745. else if (childYOffset > 0)
  55746. {
  55747. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55748. if (spaceAtBottom > 0)
  55749. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55750. }
  55751. setBounds (r);
  55752. updateYPositions();
  55753. }
  55754. void alterChildYPos (const int delta)
  55755. {
  55756. if (isScrolling())
  55757. {
  55758. childYOffset += delta;
  55759. if (delta < 0)
  55760. {
  55761. childYOffset = jmax (childYOffset, 0);
  55762. }
  55763. else if (delta > 0)
  55764. {
  55765. childYOffset = jmin (childYOffset,
  55766. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55767. }
  55768. updateYPositions();
  55769. }
  55770. else
  55771. {
  55772. childYOffset = 0;
  55773. }
  55774. resizeToBestWindowPos();
  55775. repaint();
  55776. }
  55777. int updateYPositions()
  55778. {
  55779. int x = 0;
  55780. int childNum = 0;
  55781. for (int col = 0; col < numColumns; ++col)
  55782. {
  55783. const int numChildren = jmin (getNumChildComponents() - childNum,
  55784. (getNumChildComponents() + numColumns - 1) / numColumns);
  55785. const int colW = columnWidths [col];
  55786. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55787. for (int i = 0; i < numChildren; ++i)
  55788. {
  55789. Component* const c = getChildComponent (childNum + i);
  55790. c->setBounds (x, y, colW, c->getHeight());
  55791. y += c->getHeight();
  55792. }
  55793. x += colW;
  55794. childNum += numChildren;
  55795. }
  55796. return x;
  55797. }
  55798. bool isScrolling() const throw()
  55799. {
  55800. return childYOffset != 0 || needsToScroll;
  55801. }
  55802. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55803. {
  55804. if (currentChild->isValidComponent())
  55805. currentChild->setHighlighted (false);
  55806. currentChild = child;
  55807. if (currentChild != 0)
  55808. {
  55809. currentChild->setHighlighted (true);
  55810. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55811. }
  55812. }
  55813. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55814. {
  55815. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55816. activeSubMenu = 0;
  55817. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55818. {
  55819. int left = 0, top = 0;
  55820. childComp->relativePositionToGlobal (left, top);
  55821. int right = childComp->getWidth(), bottom = childComp->getHeight();
  55822. childComp->relativePositionToGlobal (right, bottom);
  55823. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55824. dismissOnMouseUp,
  55825. this,
  55826. left, right, top, bottom,
  55827. 0, maximumNumColumns,
  55828. standardItemHeight,
  55829. false, 0, menuBarComponent,
  55830. managerOfChosenCommand,
  55831. componentAttachedTo);
  55832. if (activeSubMenu != 0)
  55833. {
  55834. activeSubMenu->setVisible (true);
  55835. activeSubMenu->enterModalState (false);
  55836. activeSubMenu->toFront (false);
  55837. return true;
  55838. }
  55839. }
  55840. return false;
  55841. }
  55842. void highlightItemUnderMouse (const int mx, const int my, const int x, const int y)
  55843. {
  55844. isOver = reallyContains (x, y, true);
  55845. if (isOver)
  55846. hasBeenOver = true;
  55847. if (abs (lastMouseX - mx) > 2 || abs (lastMouseY - my) > 2)
  55848. {
  55849. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55850. if (disableMouseMoves && isOver)
  55851. disableMouseMoves = false;
  55852. }
  55853. if (disableMouseMoves)
  55854. return;
  55855. bool isMovingTowardsMenu = false;
  55856. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55857. if (isOver && (activeSubMenu != 0) && (mx != lastMouseX || my != lastMouseY))
  55858. {
  55859. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55860. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55861. // extends from the last mouse pos to the submenu's rectangle..
  55862. float subX = (float) activeSubMenu->getScreenX();
  55863. if (activeSubMenu->getX() > getX())
  55864. {
  55865. lastMouseX -= 2; // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55866. }
  55867. else
  55868. {
  55869. lastMouseX += 2;
  55870. subX += activeSubMenu->getWidth();
  55871. }
  55872. Path areaTowardsSubMenu;
  55873. areaTowardsSubMenu.addTriangle ((float) lastMouseX,
  55874. (float) lastMouseY,
  55875. subX,
  55876. (float) activeSubMenu->getScreenY(),
  55877. subX,
  55878. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55879. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) mx, (float) my);
  55880. }
  55881. lastMouseX = mx;
  55882. lastMouseY = my;
  55883. if (! isMovingTowardsMenu)
  55884. {
  55885. Component* c = getComponentAt (x, y);
  55886. if (c == this)
  55887. c = 0;
  55888. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55889. if (mic == 0 && c != 0)
  55890. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55891. if (mic != currentChild
  55892. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55893. {
  55894. if (isOver && (c != 0) && (activeSubMenu != 0))
  55895. {
  55896. activeSubMenu->hide (0);
  55897. }
  55898. if (! isOver)
  55899. mic = 0;
  55900. setCurrentlyHighlightedChild (mic);
  55901. }
  55902. }
  55903. }
  55904. void triggerCurrentlyHighlightedItem()
  55905. {
  55906. if (currentChild->isValidComponent()
  55907. && currentChild->itemInfo.canBeTriggered()
  55908. && (currentChild->itemInfo.customComp == 0
  55909. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55910. {
  55911. dismissMenu (&currentChild->itemInfo);
  55912. }
  55913. }
  55914. void selectNextItem (const int delta)
  55915. {
  55916. disableTimerUntilMouseMoves();
  55917. PopupMenu::ItemComponent* mic = 0;
  55918. bool wasLastOne = (currentChild == 0);
  55919. const int numItems = getNumChildComponents();
  55920. for (int i = 0; i < numItems + 1; ++i)
  55921. {
  55922. int index = (delta > 0) ? i : (numItems - 1 - i);
  55923. index = (index + numItems) % numItems;
  55924. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55925. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55926. && wasLastOne)
  55927. break;
  55928. if (mic == currentChild)
  55929. wasLastOne = true;
  55930. }
  55931. setCurrentlyHighlightedChild (mic);
  55932. }
  55933. void disableTimerUntilMouseMoves()
  55934. {
  55935. disableMouseMoves = true;
  55936. if (owner != 0)
  55937. owner->disableTimerUntilMouseMoves();
  55938. }
  55939. Window (const Window&);
  55940. Window& operator= (const Window&);
  55941. };
  55942. PopupMenu::PopupMenu()
  55943. : lookAndFeel (0),
  55944. separatorPending (false)
  55945. {
  55946. }
  55947. PopupMenu::PopupMenu (const PopupMenu& other)
  55948. : lookAndFeel (other.lookAndFeel),
  55949. separatorPending (false)
  55950. {
  55951. items.ensureStorageAllocated (other.items.size());
  55952. for (int i = 0; i < other.items.size(); ++i)
  55953. items.add (new Item (*other.items.getUnchecked(i)));
  55954. }
  55955. const PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55956. {
  55957. if (this != &other)
  55958. {
  55959. lookAndFeel = other.lookAndFeel;
  55960. clear();
  55961. items.ensureStorageAllocated (other.items.size());
  55962. for (int i = 0; i < other.items.size(); ++i)
  55963. items.add (new Item (*other.items.getUnchecked(i)));
  55964. }
  55965. return *this;
  55966. }
  55967. PopupMenu::~PopupMenu()
  55968. {
  55969. clear();
  55970. }
  55971. void PopupMenu::clear()
  55972. {
  55973. items.clear();
  55974. separatorPending = false;
  55975. }
  55976. void PopupMenu::addSeparatorIfPending()
  55977. {
  55978. if (separatorPending)
  55979. {
  55980. separatorPending = false;
  55981. if (items.size() > 0)
  55982. items.add (new Item());
  55983. }
  55984. }
  55985. void PopupMenu::addItem (const int itemResultId,
  55986. const String& itemText,
  55987. const bool isActive,
  55988. const bool isTicked,
  55989. const Image* const iconToUse)
  55990. {
  55991. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55992. // didn't pick anything, so you shouldn't use it as the id
  55993. // for an item..
  55994. addSeparatorIfPending();
  55995. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55996. iconToUse, Colours::black, false, 0, 0, 0));
  55997. }
  55998. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55999. const int commandID,
  56000. const String& displayName)
  56001. {
  56002. jassert (commandManager != 0 && commandID != 0);
  56003. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  56004. if (registeredInfo != 0)
  56005. {
  56006. ApplicationCommandInfo info (*registeredInfo);
  56007. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  56008. addSeparatorIfPending();
  56009. items.add (new Item (commandID,
  56010. displayName.isNotEmpty() ? displayName
  56011. : info.shortName,
  56012. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  56013. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  56014. 0,
  56015. Colours::black,
  56016. false,
  56017. 0, 0,
  56018. commandManager));
  56019. }
  56020. }
  56021. void PopupMenu::addColouredItem (const int itemResultId,
  56022. const String& itemText,
  56023. const Colour& itemTextColour,
  56024. const bool isActive,
  56025. const bool isTicked,
  56026. const Image* const iconToUse)
  56027. {
  56028. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56029. // didn't pick anything, so you shouldn't use it as the id
  56030. // for an item..
  56031. addSeparatorIfPending();
  56032. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  56033. iconToUse, itemTextColour, true, 0, 0, 0));
  56034. }
  56035. void PopupMenu::addCustomItem (const int itemResultId,
  56036. PopupMenuCustomComponent* const customComponent)
  56037. {
  56038. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56039. // didn't pick anything, so you shouldn't use it as the id
  56040. // for an item..
  56041. addSeparatorIfPending();
  56042. items.add (new Item (itemResultId, String::empty, true, false, 0,
  56043. Colours::black, false, customComponent, 0, 0));
  56044. }
  56045. class NormalComponentWrapper : public PopupMenuCustomComponent
  56046. {
  56047. public:
  56048. NormalComponentWrapper (Component* const comp,
  56049. const int w, const int h,
  56050. const bool triggerMenuItemAutomaticallyWhenClicked)
  56051. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  56052. width (w),
  56053. height (h)
  56054. {
  56055. addAndMakeVisible (comp);
  56056. }
  56057. ~NormalComponentWrapper() {}
  56058. void getIdealSize (int& idealWidth, int& idealHeight)
  56059. {
  56060. idealWidth = width;
  56061. idealHeight = height;
  56062. }
  56063. void resized()
  56064. {
  56065. if (getChildComponent(0) != 0)
  56066. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  56067. }
  56068. juce_UseDebuggingNewOperator
  56069. private:
  56070. const int width, height;
  56071. NormalComponentWrapper (const NormalComponentWrapper&);
  56072. const NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  56073. };
  56074. void PopupMenu::addCustomItem (const int itemResultId,
  56075. Component* customComponent,
  56076. int idealWidth, int idealHeight,
  56077. const bool triggerMenuItemAutomaticallyWhenClicked)
  56078. {
  56079. addCustomItem (itemResultId,
  56080. new NormalComponentWrapper (customComponent,
  56081. idealWidth, idealHeight,
  56082. triggerMenuItemAutomaticallyWhenClicked));
  56083. }
  56084. void PopupMenu::addSubMenu (const String& subMenuName,
  56085. const PopupMenu& subMenu,
  56086. const bool isActive,
  56087. Image* const iconToUse,
  56088. const bool isTicked)
  56089. {
  56090. addSeparatorIfPending();
  56091. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  56092. iconToUse, Colours::black, false, 0, &subMenu, 0));
  56093. }
  56094. void PopupMenu::addSeparator()
  56095. {
  56096. separatorPending = true;
  56097. }
  56098. class HeaderItemComponent : public PopupMenuCustomComponent
  56099. {
  56100. public:
  56101. HeaderItemComponent (const String& name)
  56102. : PopupMenuCustomComponent (false)
  56103. {
  56104. setName (name);
  56105. }
  56106. ~HeaderItemComponent()
  56107. {
  56108. }
  56109. void paint (Graphics& g)
  56110. {
  56111. Font f (getLookAndFeel().getPopupMenuFont());
  56112. f.setBold (true);
  56113. g.setFont (f);
  56114. g.setColour (findColour (PopupMenu::headerTextColourId));
  56115. g.drawFittedText (getName(),
  56116. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  56117. Justification::bottomLeft, 1);
  56118. }
  56119. void getIdealSize (int& idealWidth,
  56120. int& idealHeight)
  56121. {
  56122. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  56123. idealHeight += idealHeight / 2;
  56124. idealWidth += idealWidth / 4;
  56125. }
  56126. juce_UseDebuggingNewOperator
  56127. };
  56128. void PopupMenu::addSectionHeader (const String& title)
  56129. {
  56130. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  56131. }
  56132. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  56133. const int itemIdThatMustBeVisible,
  56134. const int minimumWidth,
  56135. const int maximumNumColumns,
  56136. const int standardItemHeight,
  56137. const bool alignToRectangle,
  56138. Component* menuBarComponent,
  56139. ApplicationCommandManager** managerOfChosenCommand,
  56140. Component* const componentAttachedTo)
  56141. {
  56142. Window* const pw
  56143. = Window::create (*this,
  56144. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56145. 0,
  56146. x, x + w,
  56147. y, y + h,
  56148. minimumWidth,
  56149. maximumNumColumns,
  56150. standardItemHeight,
  56151. alignToRectangle,
  56152. itemIdThatMustBeVisible,
  56153. menuBarComponent,
  56154. managerOfChosenCommand,
  56155. componentAttachedTo);
  56156. if (pw != 0)
  56157. pw->setVisible (true);
  56158. return pw;
  56159. }
  56160. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56161. const int itemIdThatMustBeVisible,
  56162. const int minimumWidth,
  56163. const int maximumNumColumns,
  56164. const int standardItemHeight,
  56165. const bool alignToRectangle,
  56166. Component* const componentAttachedTo)
  56167. {
  56168. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56169. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56170. if (prevFocused != 0)
  56171. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56172. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56173. if (prevTopLevel != 0)
  56174. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56175. Window::wasHiddenBecauseOfAppChange() = false;
  56176. int result = 0;
  56177. ApplicationCommandManager* managerOfChosenCommand = 0;
  56178. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56179. itemIdThatMustBeVisible,
  56180. minimumWidth,
  56181. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56182. standardItemHeight,
  56183. alignToRectangle, 0,
  56184. &managerOfChosenCommand,
  56185. componentAttachedTo));
  56186. if (popupComp != 0)
  56187. {
  56188. popupComp->enterModalState (false);
  56189. popupComp->toFront (false); // need to do this after making it modal, or it could
  56190. // be stuck behind other comps that are already modal..
  56191. result = popupComp->runModalLoop();
  56192. popupComp = 0;
  56193. if (! Window::wasHiddenBecauseOfAppChange())
  56194. {
  56195. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56196. prevTopLevel->toFront (true);
  56197. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56198. prevFocused->grabKeyboardFocus();
  56199. }
  56200. }
  56201. if (managerOfChosenCommand != 0 && result != 0)
  56202. {
  56203. ApplicationCommandTarget::InvocationInfo info (result);
  56204. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56205. managerOfChosenCommand->invoke (info, true);
  56206. }
  56207. return result;
  56208. }
  56209. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56210. const int minimumWidth,
  56211. const int maximumNumColumns,
  56212. const int standardItemHeight)
  56213. {
  56214. int x, y;
  56215. Desktop::getMousePosition (x, y);
  56216. return showAt (x, y,
  56217. itemIdThatMustBeVisible,
  56218. minimumWidth,
  56219. maximumNumColumns,
  56220. standardItemHeight);
  56221. }
  56222. int PopupMenu::showAt (const int screenX,
  56223. const int screenY,
  56224. const int itemIdThatMustBeVisible,
  56225. const int minimumWidth,
  56226. const int maximumNumColumns,
  56227. const int standardItemHeight)
  56228. {
  56229. return showMenu (screenX, screenY, 1, 1,
  56230. itemIdThatMustBeVisible,
  56231. minimumWidth, maximumNumColumns,
  56232. standardItemHeight,
  56233. false, 0);
  56234. }
  56235. int PopupMenu::showAt (Component* componentToAttachTo,
  56236. const int itemIdThatMustBeVisible,
  56237. const int minimumWidth,
  56238. const int maximumNumColumns,
  56239. const int standardItemHeight)
  56240. {
  56241. if (componentToAttachTo != 0)
  56242. {
  56243. return showMenu (componentToAttachTo->getScreenX(),
  56244. componentToAttachTo->getScreenY(),
  56245. componentToAttachTo->getWidth(),
  56246. componentToAttachTo->getHeight(),
  56247. itemIdThatMustBeVisible,
  56248. minimumWidth,
  56249. maximumNumColumns,
  56250. standardItemHeight,
  56251. true, componentToAttachTo);
  56252. }
  56253. else
  56254. {
  56255. return show (itemIdThatMustBeVisible,
  56256. minimumWidth,
  56257. maximumNumColumns,
  56258. standardItemHeight);
  56259. }
  56260. }
  56261. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56262. {
  56263. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  56264. {
  56265. Window* const pmw = Window::getActiveWindows()[i];
  56266. if (pmw != 0)
  56267. pmw->dismissMenu (0);
  56268. }
  56269. }
  56270. int PopupMenu::getNumItems() const throw()
  56271. {
  56272. int num = 0;
  56273. for (int i = items.size(); --i >= 0;)
  56274. if (! (items.getUnchecked(i))->isSeparator)
  56275. ++num;
  56276. return num;
  56277. }
  56278. bool PopupMenu::containsCommandItem (const int commandID) const
  56279. {
  56280. for (int i = items.size(); --i >= 0;)
  56281. {
  56282. const Item* mi = items.getUnchecked (i);
  56283. if ((mi->itemId == commandID && mi->commandManager != 0)
  56284. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56285. {
  56286. return true;
  56287. }
  56288. }
  56289. return false;
  56290. }
  56291. bool PopupMenu::containsAnyActiveItems() const throw()
  56292. {
  56293. for (int i = items.size(); --i >= 0;)
  56294. {
  56295. const Item* const mi = items.getUnchecked (i);
  56296. if (mi->subMenu != 0)
  56297. {
  56298. if (mi->subMenu->containsAnyActiveItems())
  56299. return true;
  56300. }
  56301. else if (mi->active)
  56302. {
  56303. return true;
  56304. }
  56305. }
  56306. return false;
  56307. }
  56308. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56309. {
  56310. lookAndFeel = newLookAndFeel;
  56311. }
  56312. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56313. : isHighlighted (false),
  56314. isTriggeredAutomatically (isTriggeredAutomatically_)
  56315. {
  56316. }
  56317. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56318. {
  56319. }
  56320. void PopupMenuCustomComponent::triggerMenuItem()
  56321. {
  56322. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  56323. if (mic != 0)
  56324. {
  56325. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  56326. if (pmw != 0)
  56327. {
  56328. pmw->dismissMenu (&mic->itemInfo);
  56329. }
  56330. else
  56331. {
  56332. // something must have gone wrong with the component hierarchy if this happens..
  56333. jassertfalse
  56334. }
  56335. }
  56336. else
  56337. {
  56338. // why isn't this component inside a menu? Not much point triggering the item if
  56339. // there's no menu.
  56340. jassertfalse
  56341. }
  56342. }
  56343. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56344. : subMenu (0),
  56345. itemId (0),
  56346. isSeparator (false),
  56347. isTicked (false),
  56348. isEnabled (false),
  56349. isCustomComponent (false),
  56350. isSectionHeader (false),
  56351. customColour (0),
  56352. customImage (0),
  56353. menu (menu_),
  56354. index (0)
  56355. {
  56356. }
  56357. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56358. {
  56359. }
  56360. bool PopupMenu::MenuItemIterator::next()
  56361. {
  56362. if (index >= menu.items.size())
  56363. return false;
  56364. const Item* const item = menu.items.getUnchecked (index);
  56365. ++index;
  56366. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56367. subMenu = item->subMenu;
  56368. itemId = item->itemId;
  56369. isSeparator = item->isSeparator;
  56370. isTicked = item->isTicked;
  56371. isEnabled = item->active;
  56372. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  56373. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56374. customColour = item->usesColour ? &(item->textColour) : 0;
  56375. customImage = item->image;
  56376. commandManager = item->commandManager;
  56377. return true;
  56378. }
  56379. END_JUCE_NAMESPACE
  56380. /*** End of inlined file: juce_PopupMenu.cpp ***/
  56381. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  56382. BEGIN_JUCE_NAMESPACE
  56383. ComponentDragger::ComponentDragger()
  56384. : constrainer (0),
  56385. originalX (0),
  56386. originalY (0)
  56387. {
  56388. }
  56389. ComponentDragger::~ComponentDragger()
  56390. {
  56391. }
  56392. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56393. ComponentBoundsConstrainer* const constrainer_)
  56394. {
  56395. jassert (componentToDrag->isValidComponent());
  56396. if (componentToDrag->isValidComponent())
  56397. {
  56398. constrainer = constrainer_;
  56399. originalX = 0;
  56400. originalY = 0;
  56401. componentToDrag->relativePositionToGlobal (originalX, originalY);
  56402. }
  56403. }
  56404. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56405. {
  56406. jassert (componentToDrag->isValidComponent());
  56407. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56408. if (componentToDrag->isValidComponent())
  56409. {
  56410. int x = originalX;
  56411. int y = originalY;
  56412. int w = componentToDrag->getWidth();
  56413. int h = componentToDrag->getHeight();
  56414. const Component* const parentComp = componentToDrag->getParentComponent();
  56415. if (parentComp != 0)
  56416. parentComp->globalPositionToRelative (x, y);
  56417. x += e.getDistanceFromDragStartX();
  56418. y += e.getDistanceFromDragStartY();
  56419. if (constrainer != 0)
  56420. constrainer->setBoundsForComponent (componentToDrag, x, y, w, h,
  56421. false, false, false, false);
  56422. else
  56423. componentToDrag->setBounds (x, y, w, h);
  56424. }
  56425. }
  56426. END_JUCE_NAMESPACE
  56427. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  56428. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  56429. BEGIN_JUCE_NAMESPACE
  56430. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56431. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56432. class DragImageComponent : public Component,
  56433. public Timer
  56434. {
  56435. private:
  56436. ScopedPointer <Image> image;
  56437. Component* const source;
  56438. DragAndDropContainer* const owner;
  56439. ScopedPointer <ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56440. Component* mouseDragSource;
  56441. DragAndDropTarget* currentlyOver;
  56442. String dragDesc;
  56443. const int imageX, imageY;
  56444. bool hasCheckedForExternalDrag, drawImage;
  56445. DragImageComponent (const DragImageComponent&);
  56446. const DragImageComponent& operator= (const DragImageComponent&);
  56447. public:
  56448. DragImageComponent (Image* const im,
  56449. const String& desc,
  56450. Component* const s,
  56451. DragAndDropContainer* const o,
  56452. const int imageX_, const int imageY_)
  56453. : image (im),
  56454. source (s),
  56455. owner (o),
  56456. currentlyOver (0),
  56457. dragDesc (desc),
  56458. imageX (imageX_),
  56459. imageY (imageY_),
  56460. hasCheckedForExternalDrag (false),
  56461. drawImage (true)
  56462. {
  56463. setSize (im->getWidth(), im->getHeight());
  56464. sourceWatcher = new ComponentDeletionWatcher (source);
  56465. mouseDragSource = Component::getComponentUnderMouse();
  56466. if (mouseDragSource == 0)
  56467. mouseDragSource = source;
  56468. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56469. mouseDragSource->addMouseListener (this, false);
  56470. startTimer (200);
  56471. setInterceptsMouseClicks (false, false);
  56472. setAlwaysOnTop (true);
  56473. }
  56474. ~DragImageComponent()
  56475. {
  56476. if ((DragImageComponent*) owner->dragImageComponent == this)
  56477. owner->dragImageComponent.release();
  56478. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56479. {
  56480. mouseDragSource->removeMouseListener (this);
  56481. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56482. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56483. currentlyOver->itemDragExit (dragDesc, source);
  56484. }
  56485. }
  56486. void paint (Graphics& g)
  56487. {
  56488. if (isOpaque())
  56489. g.fillAll (Colours::white);
  56490. if (drawImage)
  56491. {
  56492. g.setOpacity (1.0f);
  56493. g.drawImageAt (image, 0, 0);
  56494. }
  56495. }
  56496. DragAndDropTarget* findTarget (const int screenX, const int screenY,
  56497. int& relX, int& relY) const
  56498. {
  56499. Component* hit = getParentComponent();
  56500. if (hit == 0)
  56501. {
  56502. hit = Desktop::getInstance().findComponentAt (screenX, screenY);
  56503. }
  56504. else
  56505. {
  56506. int rx = screenX, ry = screenY;
  56507. hit->globalPositionToRelative (rx, ry);
  56508. hit = hit->getComponentAt (rx, ry);
  56509. }
  56510. // (note: use a local copy of the dragDesc member in case the callback runs
  56511. // a modal loop and deletes this object before the method completes)
  56512. const String dragDescLocal (dragDesc);
  56513. while (hit != 0)
  56514. {
  56515. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56516. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56517. {
  56518. relX = screenX;
  56519. relY = screenY;
  56520. hit->globalPositionToRelative (relX, relY);
  56521. return ddt;
  56522. }
  56523. hit = hit->getParentComponent();
  56524. }
  56525. return 0;
  56526. }
  56527. void mouseUp (const MouseEvent& e)
  56528. {
  56529. if (e.originalComponent != this)
  56530. {
  56531. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56532. mouseDragSource->removeMouseListener (this);
  56533. bool dropAccepted = false;
  56534. DragAndDropTarget* ddt = 0;
  56535. int relX = 0, relY = 0;
  56536. if (isVisible())
  56537. {
  56538. setVisible (false);
  56539. ddt = findTarget (e.getScreenX(),
  56540. e.getScreenY(),
  56541. relX, relY);
  56542. // fade this component and remove it - it'll be deleted later by the timer callback
  56543. dropAccepted = ddt != 0;
  56544. setVisible (true);
  56545. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56546. {
  56547. fadeOutComponent (120);
  56548. }
  56549. else
  56550. {
  56551. int targetX = source->getWidth() / 2;
  56552. int targetY = source->getHeight() / 2;
  56553. source->relativePositionToGlobal (targetX, targetY);
  56554. int ourCentreX = getWidth() / 2;
  56555. int ourCentreY = getHeight() / 2;
  56556. relativePositionToGlobal (ourCentreX, ourCentreY);
  56557. fadeOutComponent (120,
  56558. targetX - ourCentreX,
  56559. targetY - ourCentreY);
  56560. }
  56561. }
  56562. if (getParentComponent() != 0)
  56563. getParentComponent()->removeChildComponent (this);
  56564. if (dropAccepted && ddt != 0)
  56565. {
  56566. // (note: use a local copy of the dragDesc member in case the callback runs
  56567. // a modal loop and deletes this object before the method completes)
  56568. const String dragDescLocal (dragDesc);
  56569. currentlyOverWatcher = 0;
  56570. currentlyOver = 0;
  56571. ddt->itemDropped (dragDescLocal, source, relX, relY);
  56572. }
  56573. // careful - this object could now be deleted..
  56574. }
  56575. }
  56576. void updateLocation (const bool canDoExternalDrag, int x, int y)
  56577. {
  56578. // (note: use a local copy of the dragDesc member in case the callback runs
  56579. // a modal loop and deletes this object before it returns)
  56580. const String dragDescLocal (dragDesc);
  56581. int newX = x + imageX;
  56582. int newY = y + imageY;
  56583. if (getParentComponent() != 0)
  56584. getParentComponent()->globalPositionToRelative (newX, newY);
  56585. //if (newX != getX() || newY != getY())
  56586. {
  56587. setTopLeftPosition (newX, newY);
  56588. int relX = 0, relY = 0;
  56589. DragAndDropTarget* const ddt = findTarget (x, y, relX, relY);
  56590. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56591. if (ddt != currentlyOver)
  56592. {
  56593. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56594. {
  56595. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56596. if (over != 0
  56597. && over->isValidComponent()
  56598. && ! (sourceWatcher->hasBeenDeleted())
  56599. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56600. {
  56601. currentlyOver->itemDragExit (dragDescLocal, source);
  56602. }
  56603. }
  56604. currentlyOver = ddt;
  56605. currentlyOverWatcher = 0;
  56606. if (ddt != 0)
  56607. {
  56608. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56609. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56610. currentlyOver->itemDragEnter (dragDescLocal, source, relX, relY);
  56611. }
  56612. }
  56613. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56614. {
  56615. currentlyOver = 0;
  56616. currentlyOverWatcher = 0;
  56617. }
  56618. if (currentlyOver != 0
  56619. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56620. currentlyOver->itemDragMove (dragDescLocal, source, relX, relY);
  56621. if (currentlyOver == 0
  56622. && canDoExternalDrag
  56623. && ! hasCheckedForExternalDrag)
  56624. {
  56625. if (Desktop::getInstance().findComponentAt (x, y) == 0)
  56626. {
  56627. hasCheckedForExternalDrag = true;
  56628. StringArray files;
  56629. bool canMoveFiles = false;
  56630. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56631. && files.size() > 0)
  56632. {
  56633. ComponentDeletionWatcher cdw (this);
  56634. setVisible (false);
  56635. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56636. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56637. if (! cdw.hasBeenDeleted())
  56638. delete this;
  56639. return;
  56640. }
  56641. }
  56642. }
  56643. }
  56644. }
  56645. void mouseDrag (const MouseEvent& e)
  56646. {
  56647. if (e.originalComponent != this)
  56648. updateLocation (true, e.getScreenX(), e.getScreenY());
  56649. }
  56650. void timerCallback()
  56651. {
  56652. if (sourceWatcher->hasBeenDeleted())
  56653. {
  56654. delete this;
  56655. }
  56656. else if (! isMouseButtonDownAnywhere())
  56657. {
  56658. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56659. mouseDragSource->removeMouseListener (this);
  56660. delete this;
  56661. }
  56662. }
  56663. };
  56664. DragAndDropContainer::DragAndDropContainer()
  56665. {
  56666. }
  56667. DragAndDropContainer::~DragAndDropContainer()
  56668. {
  56669. dragImageComponent = 0;
  56670. }
  56671. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56672. Component* sourceComponent,
  56673. Image* dragImage_,
  56674. const bool allowDraggingToExternalWindows,
  56675. const Point<int>* imageOffsetFromMouse)
  56676. {
  56677. ScopedPointer <Image> dragImage (dragImage_);
  56678. if (dragImageComponent == 0)
  56679. {
  56680. Component* const thisComp = dynamic_cast <Component*> (this);
  56681. if (thisComp != 0)
  56682. {
  56683. int mx, my;
  56684. Desktop::getLastMouseDownPosition (mx, my);
  56685. int imageX = 0, imageY = 0;
  56686. if (dragImage == 0)
  56687. {
  56688. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56689. if (dragImage->getFormat() != Image::ARGB)
  56690. {
  56691. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56692. Graphics g2 (*newIm);
  56693. g2.drawImageAt (dragImage, 0, 0);
  56694. dragImage = newIm;
  56695. }
  56696. dragImage->multiplyAllAlphas (0.6f);
  56697. const int lo = 150;
  56698. const int hi = 400;
  56699. int rx = mx, ry = my;
  56700. sourceComponent->globalPositionToRelative (rx, ry);
  56701. const int cx = jlimit (0, dragImage->getWidth(), rx);
  56702. const int cy = jlimit (0, dragImage->getHeight(), ry);
  56703. for (int y = dragImage->getHeight(); --y >= 0;)
  56704. {
  56705. const double dy = (y - cy) * (y - cy);
  56706. for (int x = dragImage->getWidth(); --x >= 0;)
  56707. {
  56708. const int dx = x - cx;
  56709. const int distance = roundToInt (sqrt (dx * dx + dy));
  56710. if (distance > lo)
  56711. {
  56712. const float alpha = (distance > hi) ? 0
  56713. : (hi - distance) / (float) (hi - lo)
  56714. + Random::getSystemRandom().nextFloat() * 0.008f;
  56715. dragImage->multiplyAlphaAt (x, y, alpha);
  56716. }
  56717. }
  56718. }
  56719. imageX = -cx;
  56720. imageY = -cy;
  56721. }
  56722. else
  56723. {
  56724. if (imageOffsetFromMouse == 0)
  56725. {
  56726. imageX = dragImage->getWidth() / -2;
  56727. imageY = dragImage->getHeight() / -2;
  56728. }
  56729. else
  56730. {
  56731. imageX = imageOffsetFromMouse->getX();
  56732. imageY = imageOffsetFromMouse->getY();
  56733. }
  56734. }
  56735. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56736. this, imageX, imageY);
  56737. currentDragDesc = sourceDescription;
  56738. if (allowDraggingToExternalWindows)
  56739. {
  56740. if (! Desktop::canUseSemiTransparentWindows())
  56741. dragImageComponent->setOpaque (true);
  56742. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56743. | ComponentPeer::windowIsTemporary
  56744. | ComponentPeer::windowIgnoresKeyPresses);
  56745. }
  56746. else
  56747. thisComp->addChildComponent (dragImageComponent);
  56748. ((DragImageComponent*) dragImageComponent)->updateLocation (false, mx, my);
  56749. dragImageComponent->setVisible (true);
  56750. }
  56751. else
  56752. {
  56753. // this class must only be implemented by an object that
  56754. // is also a Component.
  56755. jassertfalse
  56756. }
  56757. }
  56758. }
  56759. bool DragAndDropContainer::isDragAndDropActive() const
  56760. {
  56761. return dragImageComponent != 0;
  56762. }
  56763. const String DragAndDropContainer::getCurrentDragDescription() const
  56764. {
  56765. return (dragImageComponent != 0) ? currentDragDesc
  56766. : String::empty;
  56767. }
  56768. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56769. {
  56770. if (c == 0)
  56771. return 0;
  56772. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56773. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56774. }
  56775. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56776. {
  56777. return false;
  56778. }
  56779. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56780. {
  56781. }
  56782. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56783. {
  56784. }
  56785. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56786. {
  56787. }
  56788. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56789. {
  56790. return true;
  56791. }
  56792. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56793. {
  56794. }
  56795. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56796. {
  56797. }
  56798. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56799. {
  56800. }
  56801. END_JUCE_NAMESPACE
  56802. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56803. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56804. BEGIN_JUCE_NAMESPACE
  56805. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56806. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56807. // isStandard set depending on which interface was used to create the cursor
  56808. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56809. static CriticalSection activeCursorListLock;
  56810. static VoidArray activeCursors;
  56811. class SharedMouseCursorInternal : public ReferenceCountedObject
  56812. {
  56813. public:
  56814. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56815. : standardType (type),
  56816. isStandard (true)
  56817. {
  56818. handle = juce_createStandardMouseCursor (standardType);
  56819. activeCursors.add (this);
  56820. }
  56821. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56822. : standardType (MouseCursor::NormalCursor),
  56823. isStandard (false)
  56824. {
  56825. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56826. }
  56827. ~SharedMouseCursorInternal() throw()
  56828. {
  56829. juce_deleteMouseCursor (handle, isStandard);
  56830. activeCursors.removeValue (this);
  56831. }
  56832. void* getHandle() const throw()
  56833. {
  56834. return handle;
  56835. }
  56836. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56837. {
  56838. for (int i = activeCursors.size(); --i >= 0;)
  56839. {
  56840. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56841. if (r->standardType == type)
  56842. return r;
  56843. }
  56844. return new SharedMouseCursorInternal (type);
  56845. }
  56846. juce_UseDebuggingNewOperator
  56847. private:
  56848. void* handle;
  56849. const MouseCursor::StandardCursorType standardType;
  56850. const bool isStandard;
  56851. const SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56852. };
  56853. MouseCursor::MouseCursor() throw()
  56854. {
  56855. const ScopedLock sl (activeCursorListLock);
  56856. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56857. }
  56858. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56859. {
  56860. const ScopedLock sl (activeCursorListLock);
  56861. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56862. }
  56863. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56864. {
  56865. const ScopedLock sl (activeCursorListLock);
  56866. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56867. }
  56868. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56869. : cursorHandle (other.cursorHandle)
  56870. {
  56871. }
  56872. MouseCursor::~MouseCursor() throw()
  56873. {
  56874. }
  56875. const MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56876. {
  56877. cursorHandle = other.cursorHandle;
  56878. return *this;
  56879. }
  56880. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56881. {
  56882. return cursorHandle == other.cursorHandle;
  56883. }
  56884. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56885. {
  56886. return cursorHandle != other.cursorHandle;
  56887. }
  56888. void* MouseCursor::getHandle() const throw()
  56889. {
  56890. return cursorHandle->getHandle();
  56891. }
  56892. void MouseCursor::showWaitCursor() throw()
  56893. {
  56894. const MouseCursor mc (MouseCursor::WaitCursor);
  56895. mc.showInAllWindows();
  56896. }
  56897. void MouseCursor::hideWaitCursor() throw()
  56898. {
  56899. Component* const c = Component::getComponentUnderMouse();
  56900. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56901. : MouseCursor::NormalCursor);
  56902. mc.showInAllWindows();
  56903. }
  56904. END_JUCE_NAMESPACE
  56905. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56906. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56907. BEGIN_JUCE_NAMESPACE
  56908. MouseEvent::MouseEvent (const int x_,
  56909. const int y_,
  56910. const ModifierKeys& mods_,
  56911. Component* const originator,
  56912. const Time& eventTime_,
  56913. const int mouseDownX_,
  56914. const int mouseDownY_,
  56915. const Time& mouseDownTime_,
  56916. const int numberOfClicks_,
  56917. const bool mouseWasDragged) throw()
  56918. : x (x_),
  56919. y (y_),
  56920. mods (mods_),
  56921. eventComponent (originator),
  56922. originalComponent (originator),
  56923. eventTime (eventTime_),
  56924. mouseDownX (mouseDownX_),
  56925. mouseDownY (mouseDownY_),
  56926. mouseDownTime (mouseDownTime_),
  56927. numberOfClicks (numberOfClicks_),
  56928. wasMovedSinceMouseDown (mouseWasDragged)
  56929. {
  56930. }
  56931. MouseEvent::~MouseEvent() throw()
  56932. {
  56933. }
  56934. bool MouseEvent::mouseWasClicked() const throw()
  56935. {
  56936. return ! wasMovedSinceMouseDown;
  56937. }
  56938. int MouseEvent::getMouseDownX() const throw()
  56939. {
  56940. return mouseDownX;
  56941. }
  56942. int MouseEvent::getMouseDownY() const throw()
  56943. {
  56944. return mouseDownY;
  56945. }
  56946. int MouseEvent::getDistanceFromDragStartX() const throw()
  56947. {
  56948. return x - mouseDownX;
  56949. }
  56950. int MouseEvent::getDistanceFromDragStartY() const throw()
  56951. {
  56952. return y - mouseDownY;
  56953. }
  56954. int MouseEvent::getDistanceFromDragStart() const throw()
  56955. {
  56956. return roundToInt (juce_hypot (getDistanceFromDragStartX(),
  56957. getDistanceFromDragStartY()));
  56958. }
  56959. int MouseEvent::getLengthOfMousePress() const throw()
  56960. {
  56961. if (mouseDownTime.toMilliseconds() > 0)
  56962. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56963. return 0;
  56964. }
  56965. int MouseEvent::getScreenX() const throw()
  56966. {
  56967. int sx = x, sy = y;
  56968. eventComponent->relativePositionToGlobal (sx, sy);
  56969. return sx;
  56970. }
  56971. int MouseEvent::getScreenY() const throw()
  56972. {
  56973. int sx = x, sy = y;
  56974. eventComponent->relativePositionToGlobal (sx, sy);
  56975. return sy;
  56976. }
  56977. int MouseEvent::getMouseDownScreenX() const throw()
  56978. {
  56979. int sx = mouseDownX, sy = mouseDownY;
  56980. eventComponent->relativePositionToGlobal (sx, sy);
  56981. return sx;
  56982. }
  56983. int MouseEvent::getMouseDownScreenY() const throw()
  56984. {
  56985. int sx = mouseDownX, sy = mouseDownY;
  56986. eventComponent->relativePositionToGlobal (sx, sy);
  56987. return sy;
  56988. }
  56989. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56990. {
  56991. if (otherComponent == 0)
  56992. {
  56993. jassertfalse
  56994. return *this;
  56995. }
  56996. MouseEvent me (*this);
  56997. eventComponent->relativePositionToOtherComponent (otherComponent, me.x, me.y);
  56998. eventComponent->relativePositionToOtherComponent (otherComponent, me.mouseDownX, me.mouseDownY);
  56999. me.eventComponent = otherComponent;
  57000. return me;
  57001. }
  57002. static int doubleClickTimeOutMs = 400;
  57003. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  57004. {
  57005. doubleClickTimeOutMs = newTime;
  57006. }
  57007. int MouseEvent::getDoubleClickTimeout() throw()
  57008. {
  57009. return doubleClickTimeOutMs;
  57010. }
  57011. END_JUCE_NAMESPACE
  57012. /*** End of inlined file: juce_MouseEvent.cpp ***/
  57013. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  57014. BEGIN_JUCE_NAMESPACE
  57015. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  57016. : source (0),
  57017. hoverTimeMillisecs (hoverTimeMillisecs_),
  57018. hasJustHovered (false)
  57019. {
  57020. internalTimer.owner = this;
  57021. }
  57022. MouseHoverDetector::~MouseHoverDetector()
  57023. {
  57024. setHoverComponent (0);
  57025. }
  57026. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  57027. {
  57028. hoverTimeMillisecs = newTimeInMillisecs;
  57029. }
  57030. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  57031. {
  57032. if (source != newSourceComponent)
  57033. {
  57034. internalTimer.stopTimer();
  57035. hasJustHovered = false;
  57036. if (source != 0)
  57037. {
  57038. // ! you need to delete the hover detector before deleting its component
  57039. jassert (source->isValidComponent());
  57040. source->removeMouseListener (&internalTimer);
  57041. }
  57042. source = newSourceComponent;
  57043. if (newSourceComponent != 0)
  57044. newSourceComponent->addMouseListener (&internalTimer, false);
  57045. }
  57046. }
  57047. void MouseHoverDetector::hoverTimerCallback()
  57048. {
  57049. internalTimer.stopTimer();
  57050. if (source != 0)
  57051. {
  57052. int mx, my;
  57053. source->getMouseXYRelative (mx, my);
  57054. if (source->reallyContains (mx, my, false))
  57055. {
  57056. hasJustHovered = true;
  57057. mouseHovered (mx, my);
  57058. }
  57059. }
  57060. }
  57061. void MouseHoverDetector::checkJustHoveredCallback()
  57062. {
  57063. if (hasJustHovered)
  57064. {
  57065. hasJustHovered = false;
  57066. mouseMovedAfterHover();
  57067. }
  57068. }
  57069. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57070. {
  57071. owner->hoverTimerCallback();
  57072. }
  57073. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57074. {
  57075. stopTimer();
  57076. owner->checkJustHoveredCallback();
  57077. }
  57078. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57079. {
  57080. stopTimer();
  57081. owner->checkJustHoveredCallback();
  57082. }
  57083. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57084. {
  57085. stopTimer();
  57086. owner->checkJustHoveredCallback();
  57087. }
  57088. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57089. {
  57090. stopTimer();
  57091. owner->checkJustHoveredCallback();
  57092. }
  57093. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57094. {
  57095. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57096. {
  57097. lastX = e.x;
  57098. lastY = e.y;
  57099. if (owner->source != 0)
  57100. startTimer (owner->hoverTimeMillisecs);
  57101. owner->checkJustHoveredCallback();
  57102. }
  57103. }
  57104. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57105. {
  57106. stopTimer();
  57107. owner->checkJustHoveredCallback();
  57108. }
  57109. END_JUCE_NAMESPACE
  57110. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  57111. /*** Start of inlined file: juce_MouseListener.cpp ***/
  57112. BEGIN_JUCE_NAMESPACE
  57113. void MouseListener::mouseEnter (const MouseEvent&)
  57114. {
  57115. }
  57116. void MouseListener::mouseExit (const MouseEvent&)
  57117. {
  57118. }
  57119. void MouseListener::mouseDown (const MouseEvent&)
  57120. {
  57121. }
  57122. void MouseListener::mouseUp (const MouseEvent&)
  57123. {
  57124. }
  57125. void MouseListener::mouseDrag (const MouseEvent&)
  57126. {
  57127. }
  57128. void MouseListener::mouseMove (const MouseEvent&)
  57129. {
  57130. }
  57131. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57132. {
  57133. }
  57134. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57135. {
  57136. }
  57137. END_JUCE_NAMESPACE
  57138. /*** End of inlined file: juce_MouseListener.cpp ***/
  57139. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57140. BEGIN_JUCE_NAMESPACE
  57141. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57142. const String& buttonTextWhenTrue,
  57143. const String& buttonTextWhenFalse)
  57144. : PropertyComponent (name),
  57145. onText (buttonTextWhenTrue),
  57146. offText (buttonTextWhenFalse)
  57147. {
  57148. createButton();
  57149. button->addButtonListener (this);
  57150. }
  57151. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57152. const String& name,
  57153. const String& buttonText)
  57154. : PropertyComponent (name),
  57155. onText (buttonText),
  57156. offText (buttonText)
  57157. {
  57158. createButton();
  57159. button->setButtonText (buttonText);
  57160. button->getToggleStateValue().referTo (valueToControl);
  57161. button->setClickingTogglesState (true);
  57162. }
  57163. BooleanPropertyComponent::~BooleanPropertyComponent()
  57164. {
  57165. deleteAllChildren();
  57166. }
  57167. void BooleanPropertyComponent::createButton()
  57168. {
  57169. addAndMakeVisible (button = new ToggleButton (String::empty));
  57170. button->setClickingTogglesState (false);
  57171. }
  57172. void BooleanPropertyComponent::setState (const bool newState)
  57173. {
  57174. button->setToggleState (newState, true);
  57175. }
  57176. bool BooleanPropertyComponent::getState() const
  57177. {
  57178. return button->getToggleState();
  57179. }
  57180. void BooleanPropertyComponent::paint (Graphics& g)
  57181. {
  57182. PropertyComponent::paint (g);
  57183. const Rectangle<int> r (button->getBounds());
  57184. g.setColour (Colours::white);
  57185. g.fillRect (r);
  57186. g.setColour (findColour (ComboBox::outlineColourId));
  57187. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57188. }
  57189. void BooleanPropertyComponent::refresh()
  57190. {
  57191. button->setToggleState (getState(), false);
  57192. button->setButtonText (button->getToggleState() ? onText : offText);
  57193. }
  57194. void BooleanPropertyComponent::buttonClicked (Button*)
  57195. {
  57196. setState (! getState());
  57197. }
  57198. END_JUCE_NAMESPACE
  57199. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57200. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57201. BEGIN_JUCE_NAMESPACE
  57202. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57203. const bool triggerOnMouseDown)
  57204. : PropertyComponent (name)
  57205. {
  57206. addAndMakeVisible (button = new TextButton (String::empty));
  57207. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57208. button->addButtonListener (this);
  57209. }
  57210. ButtonPropertyComponent::~ButtonPropertyComponent()
  57211. {
  57212. deleteAllChildren();
  57213. }
  57214. void ButtonPropertyComponent::refresh()
  57215. {
  57216. button->setButtonText (getButtonText());
  57217. }
  57218. void ButtonPropertyComponent::buttonClicked (Button*)
  57219. {
  57220. buttonClicked();
  57221. }
  57222. END_JUCE_NAMESPACE
  57223. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57224. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57225. BEGIN_JUCE_NAMESPACE
  57226. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57227. : PropertyComponent (name),
  57228. comboBox (0)
  57229. {
  57230. }
  57231. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57232. const String& name,
  57233. const StringArray& choices_,
  57234. const Array <int>* choiceIDs)
  57235. : PropertyComponent (name),
  57236. choices (choices_),
  57237. comboBox (0)
  57238. {
  57239. createComboBox (choiceIDs);
  57240. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57241. }
  57242. ChoicePropertyComponent::~ChoicePropertyComponent()
  57243. {
  57244. deleteAllChildren();
  57245. }
  57246. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57247. {
  57248. // The array of IDs must contain the same number of values as the choices list!
  57249. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57250. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57251. for (int i = 0; i < choices.size(); ++i)
  57252. {
  57253. if (choices[i].isNotEmpty())
  57254. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57255. : ((*choiceIDs)[i]));
  57256. else
  57257. comboBox->addSeparator();
  57258. }
  57259. comboBox->setEditableText (false);
  57260. }
  57261. void ChoicePropertyComponent::setIndex (const int newIndex)
  57262. {
  57263. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57264. }
  57265. int ChoicePropertyComponent::getIndex() const
  57266. {
  57267. return comboBox->getSelectedItemIndex();
  57268. }
  57269. const StringArray& ChoicePropertyComponent::getChoices() const
  57270. {
  57271. return choices;
  57272. }
  57273. void ChoicePropertyComponent::refresh()
  57274. {
  57275. if (comboBox == 0)
  57276. {
  57277. createComboBox (0);
  57278. comboBox->addListener (this);
  57279. }
  57280. comboBox->setSelectedId (getIndex() + 1, true);
  57281. }
  57282. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57283. {
  57284. const int newIndex = comboBox->getSelectedId() - 1;
  57285. if (newIndex != getIndex())
  57286. setIndex (newIndex);
  57287. }
  57288. END_JUCE_NAMESPACE
  57289. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57290. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57291. BEGIN_JUCE_NAMESPACE
  57292. PropertyComponent::PropertyComponent (const String& name,
  57293. const int preferredHeight_)
  57294. : Component (name),
  57295. preferredHeight (preferredHeight_)
  57296. {
  57297. jassert (name.isNotEmpty());
  57298. }
  57299. PropertyComponent::~PropertyComponent()
  57300. {
  57301. }
  57302. void PropertyComponent::paint (Graphics& g)
  57303. {
  57304. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57305. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57306. }
  57307. void PropertyComponent::resized()
  57308. {
  57309. if (getNumChildComponents() > 0)
  57310. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57311. }
  57312. void PropertyComponent::enablementChanged()
  57313. {
  57314. repaint();
  57315. }
  57316. END_JUCE_NAMESPACE
  57317. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57318. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57319. BEGIN_JUCE_NAMESPACE
  57320. class PropertyHolderComponent : public Component
  57321. {
  57322. public:
  57323. PropertyHolderComponent()
  57324. {
  57325. }
  57326. ~PropertyHolderComponent()
  57327. {
  57328. deleteAllChildren();
  57329. }
  57330. void paint (Graphics&)
  57331. {
  57332. }
  57333. void updateLayout (const int width);
  57334. void refreshAll() const;
  57335. };
  57336. class PropertySectionComponent : public Component
  57337. {
  57338. public:
  57339. PropertySectionComponent (const String& sectionTitle,
  57340. const Array <PropertyComponent*>& newProperties,
  57341. const bool open)
  57342. : Component (sectionTitle),
  57343. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57344. isOpen_ (open)
  57345. {
  57346. for (int i = newProperties.size(); --i >= 0;)
  57347. {
  57348. addAndMakeVisible (newProperties.getUnchecked(i));
  57349. newProperties.getUnchecked(i)->refresh();
  57350. }
  57351. }
  57352. ~PropertySectionComponent()
  57353. {
  57354. deleteAllChildren();
  57355. }
  57356. void paint (Graphics& g)
  57357. {
  57358. if (titleHeight > 0)
  57359. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57360. }
  57361. void resized()
  57362. {
  57363. int y = titleHeight;
  57364. for (int i = getNumChildComponents(); --i >= 0;)
  57365. {
  57366. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57367. if (pec != 0)
  57368. {
  57369. const int prefH = pec->getPreferredHeight();
  57370. pec->setBounds (1, y, getWidth() - 2, prefH);
  57371. y += prefH;
  57372. }
  57373. }
  57374. }
  57375. int getPreferredHeight() const
  57376. {
  57377. int y = titleHeight;
  57378. if (isOpen())
  57379. {
  57380. for (int i = 0; i < getNumChildComponents(); ++i)
  57381. {
  57382. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57383. if (pec != 0)
  57384. y += pec->getPreferredHeight();
  57385. }
  57386. }
  57387. return y;
  57388. }
  57389. void setOpen (const bool open)
  57390. {
  57391. if (isOpen_ != open)
  57392. {
  57393. isOpen_ = open;
  57394. for (int i = 0; i < getNumChildComponents(); ++i)
  57395. {
  57396. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57397. if (pec != 0)
  57398. pec->setVisible (open);
  57399. }
  57400. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57401. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57402. if (pp != 0)
  57403. pp->resized();
  57404. }
  57405. }
  57406. bool isOpen() const
  57407. {
  57408. return isOpen_;
  57409. }
  57410. void refreshAll() const
  57411. {
  57412. for (int i = 0; i < getNumChildComponents(); ++i)
  57413. {
  57414. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57415. if (pec != 0)
  57416. pec->refresh();
  57417. }
  57418. }
  57419. void mouseDown (const MouseEvent&)
  57420. {
  57421. }
  57422. void mouseUp (const MouseEvent& e)
  57423. {
  57424. if (e.getMouseDownX() < titleHeight
  57425. && e.x < titleHeight
  57426. && e.y < titleHeight
  57427. && e.getNumberOfClicks() != 2)
  57428. {
  57429. setOpen (! isOpen());
  57430. }
  57431. }
  57432. void mouseDoubleClick (const MouseEvent& e)
  57433. {
  57434. if (e.y < titleHeight)
  57435. setOpen (! isOpen());
  57436. }
  57437. private:
  57438. int titleHeight;
  57439. bool isOpen_;
  57440. };
  57441. void PropertyHolderComponent::updateLayout (const int width)
  57442. {
  57443. int y = 0;
  57444. for (int i = getNumChildComponents(); --i >= 0;)
  57445. {
  57446. PropertySectionComponent* const section
  57447. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57448. if (section != 0)
  57449. {
  57450. const int prefH = section->getPreferredHeight();
  57451. section->setBounds (0, y, width, prefH);
  57452. y += prefH;
  57453. }
  57454. }
  57455. setSize (width, y);
  57456. repaint();
  57457. }
  57458. void PropertyHolderComponent::refreshAll() const
  57459. {
  57460. for (int i = getNumChildComponents(); --i >= 0;)
  57461. {
  57462. PropertySectionComponent* const section
  57463. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57464. if (section != 0)
  57465. section->refreshAll();
  57466. }
  57467. }
  57468. PropertyPanel::PropertyPanel()
  57469. {
  57470. messageWhenEmpty = TRANS("(nothing selected)");
  57471. addAndMakeVisible (viewport = new Viewport());
  57472. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57473. viewport->setFocusContainer (true);
  57474. }
  57475. PropertyPanel::~PropertyPanel()
  57476. {
  57477. clear();
  57478. deleteAllChildren();
  57479. }
  57480. void PropertyPanel::paint (Graphics& g)
  57481. {
  57482. if (propertyHolderComponent->getNumChildComponents() == 0)
  57483. {
  57484. g.setColour (Colours::black.withAlpha (0.5f));
  57485. g.setFont (14.0f);
  57486. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57487. Justification::centred, true);
  57488. }
  57489. }
  57490. void PropertyPanel::resized()
  57491. {
  57492. viewport->setBounds (0, 0, getWidth(), getHeight());
  57493. updatePropHolderLayout();
  57494. }
  57495. void PropertyPanel::clear()
  57496. {
  57497. if (propertyHolderComponent->getNumChildComponents() > 0)
  57498. {
  57499. propertyHolderComponent->deleteAllChildren();
  57500. repaint();
  57501. }
  57502. }
  57503. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57504. {
  57505. if (propertyHolderComponent->getNumChildComponents() == 0)
  57506. repaint();
  57507. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57508. newProperties,
  57509. true), 0);
  57510. updatePropHolderLayout();
  57511. }
  57512. void PropertyPanel::addSection (const String& sectionTitle,
  57513. const Array <PropertyComponent*>& newProperties,
  57514. const bool shouldBeOpen)
  57515. {
  57516. jassert (sectionTitle.isNotEmpty());
  57517. if (propertyHolderComponent->getNumChildComponents() == 0)
  57518. repaint();
  57519. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57520. newProperties,
  57521. shouldBeOpen), 0);
  57522. updatePropHolderLayout();
  57523. }
  57524. void PropertyPanel::updatePropHolderLayout() const
  57525. {
  57526. const int maxWidth = viewport->getMaximumVisibleWidth();
  57527. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57528. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57529. if (maxWidth != newMaxWidth)
  57530. {
  57531. // need to do this twice because of scrollbars changing the size, etc.
  57532. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57533. }
  57534. }
  57535. void PropertyPanel::refreshAll() const
  57536. {
  57537. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57538. }
  57539. const StringArray PropertyPanel::getSectionNames() const
  57540. {
  57541. StringArray s;
  57542. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57543. {
  57544. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57545. if (section != 0 && section->getName().isNotEmpty())
  57546. s.add (section->getName());
  57547. }
  57548. return s;
  57549. }
  57550. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57551. {
  57552. int index = 0;
  57553. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57554. {
  57555. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57556. if (section != 0 && section->getName().isNotEmpty())
  57557. {
  57558. if (index == sectionIndex)
  57559. return section->isOpen();
  57560. ++index;
  57561. }
  57562. }
  57563. return false;
  57564. }
  57565. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57566. {
  57567. int index = 0;
  57568. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57569. {
  57570. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57571. if (section != 0 && section->getName().isNotEmpty())
  57572. {
  57573. if (index == sectionIndex)
  57574. {
  57575. section->setOpen (shouldBeOpen);
  57576. break;
  57577. }
  57578. ++index;
  57579. }
  57580. }
  57581. }
  57582. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57583. {
  57584. int index = 0;
  57585. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57586. {
  57587. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57588. if (section != 0 && section->getName().isNotEmpty())
  57589. {
  57590. if (index == sectionIndex)
  57591. {
  57592. section->setEnabled (shouldBeEnabled);
  57593. break;
  57594. }
  57595. ++index;
  57596. }
  57597. }
  57598. }
  57599. XmlElement* PropertyPanel::getOpennessState() const
  57600. {
  57601. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57602. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57603. const StringArray sections (getSectionNames());
  57604. for (int i = 0; i < sections.size(); ++i)
  57605. {
  57606. if (sections[i].isNotEmpty())
  57607. {
  57608. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57609. e->setAttribute ("name", sections[i]);
  57610. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57611. }
  57612. }
  57613. return xml;
  57614. }
  57615. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57616. {
  57617. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57618. {
  57619. const StringArray sections (getSectionNames());
  57620. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57621. {
  57622. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57623. e->getBoolAttribute (T("open")));
  57624. }
  57625. viewport->setViewPosition (viewport->getViewPositionX(),
  57626. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57627. }
  57628. }
  57629. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57630. {
  57631. if (messageWhenEmpty != newMessage)
  57632. {
  57633. messageWhenEmpty = newMessage;
  57634. repaint();
  57635. }
  57636. }
  57637. const String& PropertyPanel::getMessageWhenEmpty() const
  57638. {
  57639. return messageWhenEmpty;
  57640. }
  57641. END_JUCE_NAMESPACE
  57642. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57643. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57644. BEGIN_JUCE_NAMESPACE
  57645. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57646. const double rangeMin,
  57647. const double rangeMax,
  57648. const double interval,
  57649. const double skewFactor)
  57650. : PropertyComponent (name)
  57651. {
  57652. addAndMakeVisible (slider = new Slider (name));
  57653. slider->setRange (rangeMin, rangeMax, interval);
  57654. slider->setSkewFactor (skewFactor);
  57655. slider->setSliderStyle (Slider::LinearBar);
  57656. slider->addListener (this);
  57657. }
  57658. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57659. const String& name,
  57660. const double rangeMin,
  57661. const double rangeMax,
  57662. const double interval,
  57663. const double skewFactor)
  57664. : PropertyComponent (name)
  57665. {
  57666. addAndMakeVisible (slider = new Slider (name));
  57667. slider->setRange (rangeMin, rangeMax, interval);
  57668. slider->setSkewFactor (skewFactor);
  57669. slider->setSliderStyle (Slider::LinearBar);
  57670. slider->getValueObject().referTo (valueToControl);
  57671. }
  57672. SliderPropertyComponent::~SliderPropertyComponent()
  57673. {
  57674. deleteAllChildren();
  57675. }
  57676. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57677. {
  57678. }
  57679. const double SliderPropertyComponent::getValue() const
  57680. {
  57681. return slider->getValue();
  57682. }
  57683. void SliderPropertyComponent::refresh()
  57684. {
  57685. slider->setValue (getValue(), false);
  57686. }
  57687. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57688. {
  57689. if (getValue() != slider->getValue())
  57690. setValue (slider->getValue());
  57691. }
  57692. END_JUCE_NAMESPACE
  57693. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57694. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57695. BEGIN_JUCE_NAMESPACE
  57696. class TextPropLabel : public Label
  57697. {
  57698. TextPropertyComponent& owner;
  57699. int maxChars;
  57700. bool isMultiline;
  57701. public:
  57702. TextPropLabel (TextPropertyComponent& owner_,
  57703. const int maxChars_, const bool isMultiline_)
  57704. : Label (String::empty, String::empty),
  57705. owner (owner_),
  57706. maxChars (maxChars_),
  57707. isMultiline (isMultiline_)
  57708. {
  57709. setEditable (true, true, false);
  57710. setColour (backgroundColourId, Colours::white);
  57711. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57712. }
  57713. ~TextPropLabel()
  57714. {
  57715. }
  57716. TextEditor* createEditorComponent()
  57717. {
  57718. TextEditor* const textEditor = Label::createEditorComponent();
  57719. textEditor->setInputRestrictions (maxChars);
  57720. if (isMultiline)
  57721. {
  57722. textEditor->setMultiLine (true, true);
  57723. textEditor->setReturnKeyStartsNewLine (true);
  57724. }
  57725. return textEditor;
  57726. }
  57727. void textWasEdited()
  57728. {
  57729. owner.textWasEdited();
  57730. }
  57731. };
  57732. TextPropertyComponent::TextPropertyComponent (const String& name,
  57733. const int maxNumChars,
  57734. const bool isMultiLine)
  57735. : PropertyComponent (name)
  57736. {
  57737. createEditor (maxNumChars, isMultiLine);
  57738. }
  57739. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57740. const String& name,
  57741. const int maxNumChars,
  57742. const bool isMultiLine)
  57743. : PropertyComponent (name)
  57744. {
  57745. createEditor (maxNumChars, isMultiLine);
  57746. textEditor->getTextValue().referTo (valueToControl);
  57747. }
  57748. TextPropertyComponent::~TextPropertyComponent()
  57749. {
  57750. deleteAllChildren();
  57751. }
  57752. void TextPropertyComponent::setText (const String& newText)
  57753. {
  57754. textEditor->setText (newText, true);
  57755. }
  57756. const String TextPropertyComponent::getText() const
  57757. {
  57758. return textEditor->getText();
  57759. }
  57760. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57761. {
  57762. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57763. if (isMultiLine)
  57764. {
  57765. textEditor->setJustificationType (Justification::topLeft);
  57766. preferredHeight = 120;
  57767. }
  57768. }
  57769. void TextPropertyComponent::refresh()
  57770. {
  57771. textEditor->setText (getText(), false);
  57772. }
  57773. void TextPropertyComponent::textWasEdited()
  57774. {
  57775. const String newText (textEditor->getText());
  57776. if (getText() != newText)
  57777. setText (newText);
  57778. }
  57779. END_JUCE_NAMESPACE
  57780. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57781. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57782. BEGIN_JUCE_NAMESPACE
  57783. class SimpleDeviceManagerInputLevelMeter : public Component,
  57784. public Timer
  57785. {
  57786. public:
  57787. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57788. : manager (manager_),
  57789. level (0)
  57790. {
  57791. startTimer (50);
  57792. manager->enableInputLevelMeasurement (true);
  57793. }
  57794. ~SimpleDeviceManagerInputLevelMeter()
  57795. {
  57796. manager->enableInputLevelMeasurement (false);
  57797. }
  57798. void timerCallback()
  57799. {
  57800. const float newLevel = (float) manager->getCurrentInputLevel();
  57801. if (fabsf (level - newLevel) > 0.005f)
  57802. {
  57803. level = newLevel;
  57804. repaint();
  57805. }
  57806. }
  57807. void paint (Graphics& g)
  57808. {
  57809. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57810. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57811. }
  57812. private:
  57813. AudioDeviceManager* const manager;
  57814. float level;
  57815. };
  57816. class MidiInputSelectorComponentListBox : public ListBox,
  57817. public ListBoxModel
  57818. {
  57819. public:
  57820. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57821. const String& noItemsMessage_,
  57822. const int minNumber_,
  57823. const int maxNumber_)
  57824. : ListBox (String::empty, 0),
  57825. deviceManager (deviceManager_),
  57826. noItemsMessage (noItemsMessage_),
  57827. minNumber (minNumber_),
  57828. maxNumber (maxNumber_)
  57829. {
  57830. items = MidiInput::getDevices();
  57831. setModel (this);
  57832. setOutlineThickness (1);
  57833. }
  57834. ~MidiInputSelectorComponentListBox()
  57835. {
  57836. }
  57837. int getNumRows()
  57838. {
  57839. return items.size();
  57840. }
  57841. void paintListBoxItem (int row,
  57842. Graphics& g,
  57843. int width, int height,
  57844. bool rowIsSelected)
  57845. {
  57846. if (((unsigned int) row) < (unsigned int) items.size())
  57847. {
  57848. if (rowIsSelected)
  57849. g.fillAll (findColour (TextEditor::highlightColourId)
  57850. .withMultipliedAlpha (0.3f));
  57851. const String item (items [row]);
  57852. bool enabled = deviceManager.isMidiInputEnabled (item);
  57853. const int x = getTickX();
  57854. const float tickW = height * 0.75f;
  57855. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57856. enabled, true, true, false);
  57857. g.setFont (height * 0.6f);
  57858. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57859. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57860. }
  57861. }
  57862. void listBoxItemClicked (int row, const MouseEvent& e)
  57863. {
  57864. selectRow (row);
  57865. if (e.x < getTickX())
  57866. flipEnablement (row);
  57867. }
  57868. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57869. {
  57870. flipEnablement (row);
  57871. }
  57872. void returnKeyPressed (int row)
  57873. {
  57874. flipEnablement (row);
  57875. }
  57876. void paint (Graphics& g)
  57877. {
  57878. ListBox::paint (g);
  57879. if (items.size() == 0)
  57880. {
  57881. g.setColour (Colours::grey);
  57882. g.setFont (13.0f);
  57883. g.drawText (noItemsMessage,
  57884. 0, 0, getWidth(), getHeight() / 2,
  57885. Justification::centred, true);
  57886. }
  57887. }
  57888. int getBestHeight (const int preferredHeight)
  57889. {
  57890. const int extra = getOutlineThickness() * 2;
  57891. return jmax (getRowHeight() * 2 + extra,
  57892. jmin (getRowHeight() * getNumRows() + extra,
  57893. preferredHeight));
  57894. }
  57895. juce_UseDebuggingNewOperator
  57896. private:
  57897. AudioDeviceManager& deviceManager;
  57898. const String noItemsMessage;
  57899. StringArray items;
  57900. int minNumber, maxNumber;
  57901. void flipEnablement (const int row)
  57902. {
  57903. if (((unsigned int) row) < (unsigned int) items.size())
  57904. {
  57905. const String item (items [row]);
  57906. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57907. }
  57908. }
  57909. int getTickX() const
  57910. {
  57911. return getRowHeight() + 5;
  57912. }
  57913. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57914. const MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57915. };
  57916. class AudioDeviceSettingsPanel : public Component,
  57917. public ComboBoxListener,
  57918. public ChangeListener,
  57919. public ButtonListener
  57920. {
  57921. public:
  57922. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57923. AudioIODeviceType::DeviceSetupDetails& setup_,
  57924. const bool hideAdvancedOptionsWithButton)
  57925. : type (type_),
  57926. setup (setup_)
  57927. {
  57928. sampleRateDropDown = 0;
  57929. sampleRateLabel = 0;
  57930. bufferSizeDropDown = 0;
  57931. bufferSizeLabel = 0;
  57932. outputDeviceDropDown = 0;
  57933. outputDeviceLabel = 0;
  57934. inputDeviceDropDown = 0;
  57935. inputDeviceLabel = 0;
  57936. testButton = 0;
  57937. inputLevelMeter = 0;
  57938. showUIButton = 0;
  57939. inputChanList = 0;
  57940. outputChanList = 0;
  57941. inputChanLabel = 0;
  57942. outputChanLabel = 0;
  57943. showAdvancedSettingsButton = 0;
  57944. if (hideAdvancedOptionsWithButton)
  57945. {
  57946. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57947. showAdvancedSettingsButton->addButtonListener (this);
  57948. }
  57949. type->scanForDevices();
  57950. setup.manager->addChangeListener (this);
  57951. changeListenerCallback (0);
  57952. }
  57953. ~AudioDeviceSettingsPanel()
  57954. {
  57955. setup.manager->removeChangeListener (this);
  57956. deleteAndZero (outputDeviceLabel);
  57957. deleteAndZero (inputDeviceLabel);
  57958. deleteAndZero (sampleRateLabel);
  57959. deleteAndZero (bufferSizeLabel);
  57960. deleteAndZero (showUIButton);
  57961. deleteAndZero (inputChanLabel);
  57962. deleteAndZero (outputChanLabel);
  57963. deleteAndZero (showAdvancedSettingsButton);
  57964. deleteAllChildren();
  57965. }
  57966. void resized()
  57967. {
  57968. const int lx = proportionOfWidth (0.35f);
  57969. const int w = proportionOfWidth (0.4f);
  57970. const int h = 24;
  57971. const int space = 6;
  57972. const int dh = h + space;
  57973. int y = 0;
  57974. if (outputDeviceDropDown != 0)
  57975. {
  57976. outputDeviceDropDown->setBounds (lx, y, w, h);
  57977. if (testButton != 0)
  57978. testButton->setBounds (proportionOfWidth (0.77f),
  57979. outputDeviceDropDown->getY(),
  57980. proportionOfWidth (0.18f),
  57981. h);
  57982. y += dh;
  57983. }
  57984. if (inputDeviceDropDown != 0)
  57985. {
  57986. inputDeviceDropDown->setBounds (lx, y, w, h);
  57987. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57988. inputDeviceDropDown->getY(),
  57989. proportionOfWidth (0.18f),
  57990. h);
  57991. y += dh;
  57992. }
  57993. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57994. if (outputChanList != 0)
  57995. {
  57996. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57997. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57998. y += bh + space;
  57999. }
  58000. if (inputChanList != 0)
  58001. {
  58002. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  58003. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58004. y += bh + space;
  58005. }
  58006. y += space * 2;
  58007. if (showAdvancedSettingsButton != 0)
  58008. {
  58009. showAdvancedSettingsButton->changeWidthToFitText (h);
  58010. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  58011. }
  58012. if (sampleRateDropDown != 0)
  58013. {
  58014. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  58015. || ! showAdvancedSettingsButton->isVisible());
  58016. sampleRateDropDown->setBounds (lx, y, w, h);
  58017. y += dh;
  58018. }
  58019. if (bufferSizeDropDown != 0)
  58020. {
  58021. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  58022. || ! showAdvancedSettingsButton->isVisible());
  58023. bufferSizeDropDown->setBounds (lx, y, w, h);
  58024. y += dh;
  58025. }
  58026. if (showUIButton != 0)
  58027. {
  58028. showUIButton->setVisible (showAdvancedSettingsButton == 0
  58029. || ! showAdvancedSettingsButton->isVisible());
  58030. showUIButton->changeWidthToFitText (h);
  58031. showUIButton->setTopLeftPosition (lx, y);
  58032. }
  58033. }
  58034. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58035. {
  58036. if (comboBoxThatHasChanged == 0)
  58037. return;
  58038. AudioDeviceManager::AudioDeviceSetup config;
  58039. setup.manager->getAudioDeviceSetup (config);
  58040. String error;
  58041. if (comboBoxThatHasChanged == outputDeviceDropDown
  58042. || comboBoxThatHasChanged == inputDeviceDropDown)
  58043. {
  58044. if (outputDeviceDropDown != 0)
  58045. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58046. : outputDeviceDropDown->getText();
  58047. if (inputDeviceDropDown != 0)
  58048. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58049. : inputDeviceDropDown->getText();
  58050. if (! type->hasSeparateInputsAndOutputs())
  58051. config.inputDeviceName = config.outputDeviceName;
  58052. if (comboBoxThatHasChanged == inputDeviceDropDown)
  58053. config.useDefaultInputChannels = true;
  58054. else
  58055. config.useDefaultOutputChannels = true;
  58056. error = setup.manager->setAudioDeviceSetup (config, true);
  58057. showCorrectDeviceName (inputDeviceDropDown, true);
  58058. showCorrectDeviceName (outputDeviceDropDown, false);
  58059. updateControlPanelButton();
  58060. resized();
  58061. }
  58062. else if (comboBoxThatHasChanged == sampleRateDropDown)
  58063. {
  58064. if (sampleRateDropDown->getSelectedId() > 0)
  58065. {
  58066. config.sampleRate = sampleRateDropDown->getSelectedId();
  58067. error = setup.manager->setAudioDeviceSetup (config, true);
  58068. }
  58069. }
  58070. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58071. {
  58072. if (bufferSizeDropDown->getSelectedId() > 0)
  58073. {
  58074. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58075. error = setup.manager->setAudioDeviceSetup (config, true);
  58076. }
  58077. }
  58078. if (error.isNotEmpty())
  58079. {
  58080. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58081. T("Error when trying to open audio device!"),
  58082. error);
  58083. }
  58084. }
  58085. void buttonClicked (Button* button)
  58086. {
  58087. if (button == showAdvancedSettingsButton)
  58088. {
  58089. showAdvancedSettingsButton->setVisible (false);
  58090. resized();
  58091. }
  58092. else if (button == showUIButton)
  58093. {
  58094. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58095. if (device != 0 && device->showControlPanel())
  58096. {
  58097. setup.manager->closeAudioDevice();
  58098. setup.manager->restartLastAudioDevice();
  58099. getTopLevelComponent()->toFront (true);
  58100. }
  58101. }
  58102. else if (button == testButton && testButton != 0)
  58103. {
  58104. setup.manager->playTestSound();
  58105. }
  58106. }
  58107. void updateControlPanelButton()
  58108. {
  58109. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58110. deleteAndZero (showUIButton);
  58111. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58112. {
  58113. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58114. TRANS ("opens the device's own control panel")));
  58115. showUIButton->addButtonListener (this);
  58116. }
  58117. resized();
  58118. }
  58119. void changeListenerCallback (void*)
  58120. {
  58121. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58122. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58123. {
  58124. if (outputDeviceDropDown == 0)
  58125. {
  58126. outputDeviceDropDown = new ComboBox (String::empty);
  58127. outputDeviceDropDown->addListener (this);
  58128. addAndMakeVisible (outputDeviceDropDown);
  58129. outputDeviceLabel = new Label (String::empty,
  58130. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58131. : TRANS ("device:"));
  58132. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58133. if (setup.maxNumOutputChannels > 0)
  58134. {
  58135. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58136. testButton->addButtonListener (this);
  58137. }
  58138. }
  58139. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58140. }
  58141. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58142. {
  58143. if (inputDeviceDropDown == 0)
  58144. {
  58145. inputDeviceDropDown = new ComboBox (String::empty);
  58146. inputDeviceDropDown->addListener (this);
  58147. addAndMakeVisible (inputDeviceDropDown);
  58148. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58149. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58150. addAndMakeVisible (inputLevelMeter
  58151. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58152. }
  58153. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58154. }
  58155. updateControlPanelButton();
  58156. showCorrectDeviceName (inputDeviceDropDown, true);
  58157. showCorrectDeviceName (outputDeviceDropDown, false);
  58158. if (currentDevice != 0)
  58159. {
  58160. if (setup.maxNumOutputChannels > 0
  58161. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58162. {
  58163. if (outputChanList == 0)
  58164. {
  58165. addAndMakeVisible (outputChanList
  58166. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58167. TRANS ("(no audio output channels found)")));
  58168. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58169. outputChanLabel->attachToComponent (outputChanList, true);
  58170. }
  58171. outputChanList->refresh();
  58172. }
  58173. else
  58174. {
  58175. deleteAndZero (outputChanLabel);
  58176. deleteAndZero (outputChanList);
  58177. }
  58178. if (setup.maxNumInputChannels > 0
  58179. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58180. {
  58181. if (inputChanList == 0)
  58182. {
  58183. addAndMakeVisible (inputChanList
  58184. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58185. TRANS ("(no audio input channels found)")));
  58186. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58187. inputChanLabel->attachToComponent (inputChanList, true);
  58188. }
  58189. inputChanList->refresh();
  58190. }
  58191. else
  58192. {
  58193. deleteAndZero (inputChanLabel);
  58194. deleteAndZero (inputChanList);
  58195. }
  58196. // sample rate..
  58197. {
  58198. if (sampleRateDropDown == 0)
  58199. {
  58200. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58201. sampleRateDropDown->addListener (this);
  58202. delete sampleRateLabel;
  58203. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58204. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58205. }
  58206. else
  58207. {
  58208. sampleRateDropDown->clear();
  58209. sampleRateDropDown->removeListener (this);
  58210. }
  58211. const int numRates = currentDevice->getNumSampleRates();
  58212. for (int i = 0; i < numRates; ++i)
  58213. {
  58214. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58215. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58216. }
  58217. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58218. sampleRateDropDown->addListener (this);
  58219. }
  58220. // buffer size
  58221. {
  58222. if (bufferSizeDropDown == 0)
  58223. {
  58224. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58225. bufferSizeDropDown->addListener (this);
  58226. delete bufferSizeLabel;
  58227. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58228. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58229. }
  58230. else
  58231. {
  58232. bufferSizeDropDown->clear();
  58233. }
  58234. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58235. double currentRate = currentDevice->getCurrentSampleRate();
  58236. if (currentRate == 0)
  58237. currentRate = 48000.0;
  58238. for (int i = 0; i < numBufferSizes; ++i)
  58239. {
  58240. const int bs = currentDevice->getBufferSizeSamples (i);
  58241. bufferSizeDropDown->addItem (String (bs)
  58242. + T(" samples (")
  58243. + String (bs * 1000.0 / currentRate, 1)
  58244. + T(" ms)"),
  58245. bs);
  58246. }
  58247. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58248. }
  58249. }
  58250. else
  58251. {
  58252. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58253. deleteAndZero (sampleRateLabel);
  58254. deleteAndZero (bufferSizeLabel);
  58255. deleteAndZero (sampleRateDropDown);
  58256. deleteAndZero (bufferSizeDropDown);
  58257. if (outputDeviceDropDown != 0)
  58258. outputDeviceDropDown->setSelectedId (-1, true);
  58259. if (inputDeviceDropDown != 0)
  58260. inputDeviceDropDown->setSelectedId (-1, true);
  58261. }
  58262. resized();
  58263. setSize (getWidth(), getLowestY() + 4);
  58264. }
  58265. private:
  58266. AudioIODeviceType* const type;
  58267. const AudioIODeviceType::DeviceSetupDetails setup;
  58268. ComboBox* outputDeviceDropDown;
  58269. ComboBox* inputDeviceDropDown;
  58270. ComboBox* sampleRateDropDown;
  58271. ComboBox* bufferSizeDropDown;
  58272. Label* outputDeviceLabel;
  58273. Label* inputDeviceLabel;
  58274. Label* sampleRateLabel;
  58275. Label* bufferSizeLabel;
  58276. Label* inputChanLabel;
  58277. Label* outputChanLabel;
  58278. TextButton* testButton;
  58279. Component* inputLevelMeter;
  58280. TextButton* showUIButton;
  58281. TextButton* showAdvancedSettingsButton;
  58282. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58283. {
  58284. if (box != 0)
  58285. {
  58286. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58287. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58288. box->setSelectedId (index + 1, true);
  58289. if (testButton != 0 && ! isInput)
  58290. testButton->setEnabled (index >= 0);
  58291. }
  58292. }
  58293. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58294. {
  58295. const StringArray devs (type->getDeviceNames (isInputs));
  58296. combo.clear (true);
  58297. for (int i = 0; i < devs.size(); ++i)
  58298. combo.addItem (devs[i], i + 1);
  58299. combo.addItem (TRANS("<< none >>"), -1);
  58300. combo.setSelectedId (-1, true);
  58301. }
  58302. int getLowestY() const
  58303. {
  58304. int y = 0;
  58305. for (int i = getNumChildComponents(); --i >= 0;)
  58306. y = jmax (y, getChildComponent (i)->getBottom());
  58307. return y;
  58308. }
  58309. public:
  58310. class ChannelSelectorListBox : public ListBox,
  58311. public ListBoxModel
  58312. {
  58313. public:
  58314. enum BoxType
  58315. {
  58316. audioInputType,
  58317. audioOutputType
  58318. };
  58319. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58320. const BoxType type_,
  58321. const String& noItemsMessage_)
  58322. : ListBox (String::empty, 0),
  58323. setup (setup_),
  58324. type (type_),
  58325. noItemsMessage (noItemsMessage_)
  58326. {
  58327. refresh();
  58328. setModel (this);
  58329. setOutlineThickness (1);
  58330. }
  58331. ~ChannelSelectorListBox()
  58332. {
  58333. }
  58334. void refresh()
  58335. {
  58336. items.clear();
  58337. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58338. if (currentDevice != 0)
  58339. {
  58340. if (type == audioInputType)
  58341. items = currentDevice->getInputChannelNames();
  58342. else if (type == audioOutputType)
  58343. items = currentDevice->getOutputChannelNames();
  58344. if (setup.useStereoPairs)
  58345. {
  58346. StringArray pairs;
  58347. for (int i = 0; i < items.size(); i += 2)
  58348. {
  58349. String name (items[i]);
  58350. String name2 (items[i + 1]);
  58351. String commonBit;
  58352. for (int j = 0; j < name.length(); ++j)
  58353. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58354. commonBit = name.substring (0, j);
  58355. pairs.add (name.trim()
  58356. + " + "
  58357. + name2.substring (commonBit.length()).trim());
  58358. }
  58359. items = pairs;
  58360. }
  58361. }
  58362. updateContent();
  58363. repaint();
  58364. }
  58365. int getNumRows()
  58366. {
  58367. return items.size();
  58368. }
  58369. void paintListBoxItem (int row,
  58370. Graphics& g,
  58371. int width, int height,
  58372. bool rowIsSelected)
  58373. {
  58374. if (((unsigned int) row) < (unsigned int) items.size())
  58375. {
  58376. if (rowIsSelected)
  58377. g.fillAll (findColour (TextEditor::highlightColourId)
  58378. .withMultipliedAlpha (0.3f));
  58379. const String item (items [row]);
  58380. bool enabled = false;
  58381. AudioDeviceManager::AudioDeviceSetup config;
  58382. setup.manager->getAudioDeviceSetup (config);
  58383. if (setup.useStereoPairs)
  58384. {
  58385. if (type == audioInputType)
  58386. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58387. else if (type == audioOutputType)
  58388. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58389. }
  58390. else
  58391. {
  58392. if (type == audioInputType)
  58393. enabled = config.inputChannels [row];
  58394. else if (type == audioOutputType)
  58395. enabled = config.outputChannels [row];
  58396. }
  58397. const int x = getTickX();
  58398. const float tickW = height * 0.75f;
  58399. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58400. enabled, true, true, false);
  58401. g.setFont (height * 0.6f);
  58402. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58403. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58404. }
  58405. }
  58406. void listBoxItemClicked (int row, const MouseEvent& e)
  58407. {
  58408. selectRow (row);
  58409. if (e.x < getTickX())
  58410. flipEnablement (row);
  58411. }
  58412. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58413. {
  58414. flipEnablement (row);
  58415. }
  58416. void returnKeyPressed (int row)
  58417. {
  58418. flipEnablement (row);
  58419. }
  58420. void paint (Graphics& g)
  58421. {
  58422. ListBox::paint (g);
  58423. if (items.size() == 0)
  58424. {
  58425. g.setColour (Colours::grey);
  58426. g.setFont (13.0f);
  58427. g.drawText (noItemsMessage,
  58428. 0, 0, getWidth(), getHeight() / 2,
  58429. Justification::centred, true);
  58430. }
  58431. }
  58432. int getBestHeight (int maxHeight)
  58433. {
  58434. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58435. getNumRows())
  58436. + getOutlineThickness() * 2;
  58437. }
  58438. juce_UseDebuggingNewOperator
  58439. private:
  58440. const AudioIODeviceType::DeviceSetupDetails setup;
  58441. const BoxType type;
  58442. const String noItemsMessage;
  58443. StringArray items;
  58444. void flipEnablement (const int row)
  58445. {
  58446. jassert (type == audioInputType || type == audioOutputType);
  58447. if (((unsigned int) row) < (unsigned int) items.size())
  58448. {
  58449. AudioDeviceManager::AudioDeviceSetup config;
  58450. setup.manager->getAudioDeviceSetup (config);
  58451. if (setup.useStereoPairs)
  58452. {
  58453. BitArray bits;
  58454. BitArray& original = (type == audioInputType ? config.inputChannels
  58455. : config.outputChannels);
  58456. int i;
  58457. for (i = 0; i < 256; i += 2)
  58458. bits.setBit (i / 2, original [i] || original [i + 1]);
  58459. if (type == audioInputType)
  58460. {
  58461. config.useDefaultInputChannels = false;
  58462. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58463. }
  58464. else
  58465. {
  58466. config.useDefaultOutputChannels = false;
  58467. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58468. }
  58469. for (i = 0; i < 256; ++i)
  58470. original.setBit (i, bits [i / 2]);
  58471. }
  58472. else
  58473. {
  58474. if (type == audioInputType)
  58475. {
  58476. config.useDefaultInputChannels = false;
  58477. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58478. }
  58479. else
  58480. {
  58481. config.useDefaultOutputChannels = false;
  58482. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58483. }
  58484. }
  58485. String error (setup.manager->setAudioDeviceSetup (config, true));
  58486. if (! error.isEmpty())
  58487. {
  58488. //xxx
  58489. }
  58490. }
  58491. }
  58492. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58493. {
  58494. const int numActive = chans.countNumberOfSetBits();
  58495. if (chans [index])
  58496. {
  58497. if (numActive > minNumber)
  58498. chans.setBit (index, false);
  58499. }
  58500. else
  58501. {
  58502. if (numActive >= maxNumber)
  58503. {
  58504. const int firstActiveChan = chans.findNextSetBit();
  58505. chans.setBit (index > firstActiveChan
  58506. ? firstActiveChan : chans.getHighestBit(),
  58507. false);
  58508. }
  58509. chans.setBit (index, true);
  58510. }
  58511. }
  58512. int getTickX() const
  58513. {
  58514. return getRowHeight() + 5;
  58515. }
  58516. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58517. const ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58518. };
  58519. private:
  58520. ChannelSelectorListBox* inputChanList;
  58521. ChannelSelectorListBox* outputChanList;
  58522. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58523. const AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58524. };
  58525. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58526. const int minInputChannels_,
  58527. const int maxInputChannels_,
  58528. const int minOutputChannels_,
  58529. const int maxOutputChannels_,
  58530. const bool showMidiInputOptions,
  58531. const bool showMidiOutputSelector,
  58532. const bool showChannelsAsStereoPairs_,
  58533. const bool hideAdvancedOptionsWithButton_)
  58534. : deviceManager (deviceManager_),
  58535. deviceTypeDropDown (0),
  58536. deviceTypeDropDownLabel (0),
  58537. audioDeviceSettingsComp (0),
  58538. minOutputChannels (minOutputChannels_),
  58539. maxOutputChannels (maxOutputChannels_),
  58540. minInputChannels (minInputChannels_),
  58541. maxInputChannels (maxInputChannels_),
  58542. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58543. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58544. {
  58545. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58546. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58547. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58548. {
  58549. deviceTypeDropDown = new ComboBox (String::empty);
  58550. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58551. {
  58552. deviceTypeDropDown
  58553. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58554. i + 1);
  58555. }
  58556. addAndMakeVisible (deviceTypeDropDown);
  58557. deviceTypeDropDown->addListener (this);
  58558. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58559. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58560. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58561. }
  58562. if (showMidiInputOptions)
  58563. {
  58564. addAndMakeVisible (midiInputsList
  58565. = new MidiInputSelectorComponentListBox (deviceManager,
  58566. TRANS("(no midi inputs available)"),
  58567. 0, 0));
  58568. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58569. midiInputsLabel->setJustificationType (Justification::topRight);
  58570. midiInputsLabel->attachToComponent (midiInputsList, true);
  58571. }
  58572. else
  58573. {
  58574. midiInputsList = 0;
  58575. midiInputsLabel = 0;
  58576. }
  58577. if (showMidiOutputSelector)
  58578. {
  58579. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58580. midiOutputSelector->addListener (this);
  58581. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58582. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58583. }
  58584. else
  58585. {
  58586. midiOutputSelector = 0;
  58587. midiOutputLabel = 0;
  58588. }
  58589. deviceManager_.addChangeListener (this);
  58590. changeListenerCallback (0);
  58591. }
  58592. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58593. {
  58594. deviceManager.removeChangeListener (this);
  58595. deleteAllChildren();
  58596. }
  58597. void AudioDeviceSelectorComponent::resized()
  58598. {
  58599. const int lx = proportionOfWidth (0.35f);
  58600. const int w = proportionOfWidth (0.4f);
  58601. const int h = 24;
  58602. const int space = 6;
  58603. const int dh = h + space;
  58604. int y = 15;
  58605. if (deviceTypeDropDown != 0)
  58606. {
  58607. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58608. y += dh + space * 2;
  58609. }
  58610. if (audioDeviceSettingsComp != 0)
  58611. {
  58612. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58613. y += audioDeviceSettingsComp->getHeight() + space;
  58614. }
  58615. if (midiInputsList != 0)
  58616. {
  58617. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58618. midiInputsList->setBounds (lx, y, w, bh);
  58619. y += bh + space;
  58620. }
  58621. if (midiOutputSelector != 0)
  58622. midiOutputSelector->setBounds (lx, y, w, h);
  58623. }
  58624. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58625. {
  58626. if (child == audioDeviceSettingsComp)
  58627. resized();
  58628. }
  58629. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58630. {
  58631. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58632. if (device != 0 && device->hasControlPanel())
  58633. {
  58634. if (device->showControlPanel())
  58635. deviceManager.restartLastAudioDevice();
  58636. getTopLevelComponent()->toFront (true);
  58637. }
  58638. }
  58639. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58640. {
  58641. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58642. {
  58643. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58644. if (type != 0)
  58645. {
  58646. deleteAndZero (audioDeviceSettingsComp);
  58647. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58648. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58649. }
  58650. }
  58651. else if (comboBoxThatHasChanged == midiOutputSelector)
  58652. {
  58653. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58654. }
  58655. }
  58656. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58657. {
  58658. if (deviceTypeDropDown != 0)
  58659. {
  58660. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58661. }
  58662. if (audioDeviceSettingsComp == 0
  58663. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58664. {
  58665. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58666. deleteAndZero (audioDeviceSettingsComp);
  58667. AudioIODeviceType* const type
  58668. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58669. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58670. if (type != 0)
  58671. {
  58672. AudioIODeviceType::DeviceSetupDetails details;
  58673. details.manager = &deviceManager;
  58674. details.minNumInputChannels = minInputChannels;
  58675. details.maxNumInputChannels = maxInputChannels;
  58676. details.minNumOutputChannels = minOutputChannels;
  58677. details.maxNumOutputChannels = maxOutputChannels;
  58678. details.useStereoPairs = showChannelsAsStereoPairs;
  58679. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58680. if (audioDeviceSettingsComp != 0)
  58681. {
  58682. addAndMakeVisible (audioDeviceSettingsComp);
  58683. audioDeviceSettingsComp->resized();
  58684. }
  58685. }
  58686. }
  58687. if (midiInputsList != 0)
  58688. {
  58689. midiInputsList->updateContent();
  58690. midiInputsList->repaint();
  58691. }
  58692. if (midiOutputSelector != 0)
  58693. {
  58694. midiOutputSelector->clear();
  58695. const StringArray midiOuts (MidiOutput::getDevices());
  58696. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58697. midiOutputSelector->addSeparator();
  58698. for (int i = 0; i < midiOuts.size(); ++i)
  58699. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58700. int current = -1;
  58701. if (deviceManager.getDefaultMidiOutput() != 0)
  58702. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58703. midiOutputSelector->setSelectedId (current, true);
  58704. }
  58705. resized();
  58706. }
  58707. END_JUCE_NAMESPACE
  58708. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58709. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58710. BEGIN_JUCE_NAMESPACE
  58711. BubbleComponent::BubbleComponent()
  58712. : side (0),
  58713. allowablePlacements (above | below | left | right),
  58714. arrowTipX (0.0f),
  58715. arrowTipY (0.0f)
  58716. {
  58717. setInterceptsMouseClicks (false, false);
  58718. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58719. setComponentEffect (&shadow);
  58720. }
  58721. BubbleComponent::~BubbleComponent()
  58722. {
  58723. }
  58724. void BubbleComponent::paint (Graphics& g)
  58725. {
  58726. int x = content.getX();
  58727. int y = content.getY();
  58728. int w = content.getWidth();
  58729. int h = content.getHeight();
  58730. int cw, ch;
  58731. getContentSize (cw, ch);
  58732. if (side == 3)
  58733. x += w - cw;
  58734. else if (side != 1)
  58735. x += (w - cw) / 2;
  58736. w = cw;
  58737. if (side == 2)
  58738. y += h - ch;
  58739. else if (side != 0)
  58740. y += (h - ch) / 2;
  58741. h = ch;
  58742. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58743. (float) x, (float) y,
  58744. (float) w, (float) h);
  58745. const int cx = x + (w - cw) / 2;
  58746. const int cy = y + (h - ch) / 2;
  58747. const int indent = 3;
  58748. g.setOrigin (cx + indent, cy + indent);
  58749. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58750. paintContent (g, cw - indent * 2, ch - indent * 2);
  58751. }
  58752. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58753. {
  58754. allowablePlacements = newPlacement;
  58755. }
  58756. void BubbleComponent::setPosition (Component* componentToPointTo)
  58757. {
  58758. jassert (componentToPointTo->isValidComponent());
  58759. int tx = 0;
  58760. int ty = 0;
  58761. if (getParentComponent() != 0)
  58762. componentToPointTo->relativePositionToOtherComponent (getParentComponent(), tx, ty);
  58763. else
  58764. componentToPointTo->relativePositionToGlobal (tx, ty);
  58765. setPosition (Rectangle<int> (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58766. }
  58767. void BubbleComponent::setPosition (const int arrowTipX_,
  58768. const int arrowTipY_)
  58769. {
  58770. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58771. }
  58772. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58773. {
  58774. Rectangle<int> availableSpace;
  58775. if (getParentComponent() != 0)
  58776. {
  58777. availableSpace.setSize (getParentComponent()->getWidth(),
  58778. getParentComponent()->getHeight());
  58779. }
  58780. else
  58781. {
  58782. availableSpace = getParentMonitorArea();
  58783. }
  58784. int x = 0;
  58785. int y = 0;
  58786. int w = 150;
  58787. int h = 30;
  58788. getContentSize (w, h);
  58789. w += 30;
  58790. h += 30;
  58791. const float edgeIndent = 2.0f;
  58792. const int arrowLength = jmin (10, h / 3, w / 3);
  58793. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58794. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58795. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58796. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58797. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58798. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58799. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58800. {
  58801. spaceLeft = spaceRight = 0;
  58802. }
  58803. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58804. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58805. {
  58806. spaceAbove = spaceBelow = 0;
  58807. }
  58808. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58809. {
  58810. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58811. arrowTipX = w * 0.5f;
  58812. content.setSize (w, h - arrowLength);
  58813. if (spaceAbove >= spaceBelow)
  58814. {
  58815. // above
  58816. y = rectangleToPointTo.getY() - h;
  58817. content.setPosition (0, 0);
  58818. arrowTipY = h - edgeIndent;
  58819. side = 2;
  58820. }
  58821. else
  58822. {
  58823. // below
  58824. y = rectangleToPointTo.getBottom();
  58825. content.setPosition (0, arrowLength);
  58826. arrowTipY = edgeIndent;
  58827. side = 0;
  58828. }
  58829. }
  58830. else
  58831. {
  58832. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58833. arrowTipY = h * 0.5f;
  58834. content.setSize (w - arrowLength, h);
  58835. if (spaceLeft > spaceRight)
  58836. {
  58837. // on the left
  58838. x = rectangleToPointTo.getX() - w;
  58839. content.setPosition (0, 0);
  58840. arrowTipX = w - edgeIndent;
  58841. side = 3;
  58842. }
  58843. else
  58844. {
  58845. // on the right
  58846. x = rectangleToPointTo.getRight();
  58847. content.setPosition (arrowLength, 0);
  58848. arrowTipX = edgeIndent;
  58849. side = 1;
  58850. }
  58851. }
  58852. setBounds (x, y, w, h);
  58853. }
  58854. END_JUCE_NAMESPACE
  58855. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58856. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58857. BEGIN_JUCE_NAMESPACE
  58858. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58859. : fadeOutLength (fadeOutLengthMs),
  58860. deleteAfterUse (false)
  58861. {
  58862. }
  58863. BubbleMessageComponent::~BubbleMessageComponent()
  58864. {
  58865. fadeOutComponent (fadeOutLength);
  58866. }
  58867. void BubbleMessageComponent::showAt (int x, int y,
  58868. const String& text,
  58869. const int numMillisecondsBeforeRemoving,
  58870. const bool removeWhenMouseClicked,
  58871. const bool deleteSelfAfterUse)
  58872. {
  58873. textLayout.clear();
  58874. textLayout.setText (text, Font (14.0f));
  58875. textLayout.layout (256, Justification::centredLeft, true);
  58876. setPosition (x, y);
  58877. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58878. }
  58879. void BubbleMessageComponent::showAt (Component* const component,
  58880. const String& text,
  58881. const int numMillisecondsBeforeRemoving,
  58882. const bool removeWhenMouseClicked,
  58883. const bool deleteSelfAfterUse)
  58884. {
  58885. textLayout.clear();
  58886. textLayout.setText (text, Font (14.0f));
  58887. textLayout.layout (256, Justification::centredLeft, true);
  58888. setPosition (component);
  58889. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58890. }
  58891. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58892. const bool removeWhenMouseClicked,
  58893. const bool deleteSelfAfterUse)
  58894. {
  58895. setVisible (true);
  58896. deleteAfterUse = deleteSelfAfterUse;
  58897. if (numMillisecondsBeforeRemoving > 0)
  58898. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58899. else
  58900. expiryTime = 0;
  58901. startTimer (77);
  58902. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58903. if (! (removeWhenMouseClicked && isShowing()))
  58904. mouseClickCounter += 0xfffff;
  58905. repaint();
  58906. }
  58907. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58908. {
  58909. w = textLayout.getWidth() + 16;
  58910. h = textLayout.getHeight() + 16;
  58911. }
  58912. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58913. {
  58914. g.setColour (findColour (TooltipWindow::textColourId));
  58915. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58916. }
  58917. void BubbleMessageComponent::timerCallback()
  58918. {
  58919. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58920. {
  58921. stopTimer();
  58922. setVisible (false);
  58923. if (deleteAfterUse)
  58924. delete this;
  58925. }
  58926. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58927. {
  58928. stopTimer();
  58929. fadeOutComponent (fadeOutLength);
  58930. if (deleteAfterUse)
  58931. delete this;
  58932. }
  58933. }
  58934. END_JUCE_NAMESPACE
  58935. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58936. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58937. BEGIN_JUCE_NAMESPACE
  58938. static const int swatchesPerRow = 8;
  58939. static const int swatchHeight = 22;
  58940. class ColourComponentSlider : public Slider
  58941. {
  58942. public:
  58943. ColourComponentSlider (const String& name)
  58944. : Slider (name)
  58945. {
  58946. setRange (0.0, 255.0, 1.0);
  58947. }
  58948. ~ColourComponentSlider()
  58949. {
  58950. }
  58951. const String getTextFromValue (double value)
  58952. {
  58953. return String::formatted (T("%02X"), (int) value);
  58954. }
  58955. double getValueFromText (const String& text)
  58956. {
  58957. return (double) text.getHexValue32();
  58958. }
  58959. private:
  58960. ColourComponentSlider (const ColourComponentSlider&);
  58961. const ColourComponentSlider& operator= (const ColourComponentSlider&);
  58962. };
  58963. class ColourSpaceMarker : public Component
  58964. {
  58965. public:
  58966. ColourSpaceMarker()
  58967. {
  58968. setInterceptsMouseClicks (false, false);
  58969. }
  58970. ~ColourSpaceMarker()
  58971. {
  58972. }
  58973. void paint (Graphics& g)
  58974. {
  58975. g.setColour (Colour::greyLevel (0.1f));
  58976. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58977. g.setColour (Colour::greyLevel (0.9f));
  58978. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58979. }
  58980. private:
  58981. ColourSpaceMarker (const ColourSpaceMarker&);
  58982. const ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58983. };
  58984. class ColourSpaceView : public Component
  58985. {
  58986. ColourSelector* const owner;
  58987. float& h;
  58988. float& s;
  58989. float& v;
  58990. float lastHue;
  58991. ColourSpaceMarker* marker;
  58992. const int edge;
  58993. public:
  58994. ColourSpaceView (ColourSelector* owner_,
  58995. float& h_, float& s_, float& v_,
  58996. const int edgeSize)
  58997. : owner (owner_),
  58998. h (h_), s (s_), v (v_),
  58999. lastHue (0.0f),
  59000. edge (edgeSize)
  59001. {
  59002. addAndMakeVisible (marker = new ColourSpaceMarker());
  59003. setMouseCursor (MouseCursor::CrosshairCursor);
  59004. }
  59005. ~ColourSpaceView()
  59006. {
  59007. deleteAllChildren();
  59008. }
  59009. void paint (Graphics& g)
  59010. {
  59011. if (colours == 0)
  59012. {
  59013. const int width = getWidth() / 2;
  59014. const int height = getHeight() / 2;
  59015. colours = new Image (Image::RGB, width, height, false);
  59016. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  59017. for (int y = 0; y < height; ++y)
  59018. {
  59019. const float v = 1.0f - y / (float) height;
  59020. for (int x = 0; x < width; ++x)
  59021. {
  59022. const float s = x / (float) width;
  59023. const Colour col (h, s, v, 1.0f);
  59024. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  59025. pix->set (col.getPixelARGB());
  59026. }
  59027. }
  59028. }
  59029. g.setOpacity (1.0f);
  59030. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  59031. 0, 0, colours->getWidth(), colours->getHeight());
  59032. }
  59033. void mouseDown (const MouseEvent& e)
  59034. {
  59035. mouseDrag (e);
  59036. }
  59037. void mouseDrag (const MouseEvent& e)
  59038. {
  59039. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  59040. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  59041. owner->setSV (s, v);
  59042. }
  59043. void updateIfNeeded()
  59044. {
  59045. if (lastHue != h)
  59046. {
  59047. lastHue = h;
  59048. colours = 0;
  59049. repaint();
  59050. }
  59051. updateMarker();
  59052. }
  59053. void resized()
  59054. {
  59055. colours = 0;
  59056. updateMarker();
  59057. }
  59058. private:
  59059. ScopedPointer <Image> colours;
  59060. void updateMarker() const throw()
  59061. {
  59062. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  59063. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  59064. edge * 2, edge * 2);
  59065. }
  59066. ColourSpaceView (const ColourSpaceView&);
  59067. const ColourSpaceView& operator= (const ColourSpaceView&);
  59068. };
  59069. class HueSelectorMarker : public Component
  59070. {
  59071. public:
  59072. HueSelectorMarker()
  59073. {
  59074. setInterceptsMouseClicks (false, false);
  59075. }
  59076. ~HueSelectorMarker()
  59077. {
  59078. }
  59079. void paint (Graphics& g)
  59080. {
  59081. Path p;
  59082. p.addTriangle (1.0f, 1.0f,
  59083. getWidth() * 0.3f, getHeight() * 0.5f,
  59084. 1.0f, getHeight() - 1.0f);
  59085. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59086. getWidth() * 0.7f, getHeight() * 0.5f,
  59087. getWidth() - 1.0f, getHeight() - 1.0f);
  59088. g.setColour (Colours::white.withAlpha (0.75f));
  59089. g.fillPath (p);
  59090. g.setColour (Colours::black.withAlpha (0.75f));
  59091. g.strokePath (p, PathStrokeType (1.2f));
  59092. }
  59093. private:
  59094. HueSelectorMarker (const HueSelectorMarker&);
  59095. const HueSelectorMarker& operator= (const HueSelectorMarker&);
  59096. };
  59097. class HueSelectorComp : public Component
  59098. {
  59099. public:
  59100. HueSelectorComp (ColourSelector* owner_,
  59101. float& h_, float& s_, float& v_,
  59102. const int edgeSize)
  59103. : owner (owner_),
  59104. h (h_), s (s_), v (v_),
  59105. lastHue (0.0f),
  59106. edge (edgeSize)
  59107. {
  59108. addAndMakeVisible (marker = new HueSelectorMarker());
  59109. }
  59110. ~HueSelectorComp()
  59111. {
  59112. deleteAllChildren();
  59113. }
  59114. void paint (Graphics& g)
  59115. {
  59116. const float yScale = 1.0f / (getHeight() - edge * 2);
  59117. const Rectangle<int> clip (g.getClipBounds());
  59118. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59119. {
  59120. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59121. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59122. }
  59123. }
  59124. void resized()
  59125. {
  59126. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59127. getWidth(), edge * 2);
  59128. }
  59129. void mouseDown (const MouseEvent& e)
  59130. {
  59131. mouseDrag (e);
  59132. }
  59133. void mouseDrag (const MouseEvent& e)
  59134. {
  59135. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59136. owner->setHue (hue);
  59137. }
  59138. void updateIfNeeded()
  59139. {
  59140. resized();
  59141. }
  59142. private:
  59143. ColourSelector* const owner;
  59144. float& h;
  59145. float& s;
  59146. float& v;
  59147. float lastHue;
  59148. HueSelectorMarker* marker;
  59149. const int edge;
  59150. HueSelectorComp (const HueSelectorComp&);
  59151. const HueSelectorComp& operator= (const HueSelectorComp&);
  59152. };
  59153. class ColourSelector::SwatchComponent : public Component
  59154. {
  59155. public:
  59156. SwatchComponent (ColourSelector* owner_, int index_)
  59157. : owner (owner_),
  59158. index (index_)
  59159. {
  59160. }
  59161. ~SwatchComponent()
  59162. {
  59163. }
  59164. void paint (Graphics& g)
  59165. {
  59166. const Colour colour (owner->getSwatchColour (index));
  59167. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59168. 6, 6,
  59169. Colour (0xffdddddd).overlaidWith (colour),
  59170. Colour (0xffffffff).overlaidWith (colour));
  59171. }
  59172. void mouseDown (const MouseEvent&)
  59173. {
  59174. PopupMenu m;
  59175. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59176. m.addSeparator();
  59177. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59178. const int r = m.showAt (this);
  59179. if (r == 1)
  59180. {
  59181. owner->setCurrentColour (owner->getSwatchColour (index));
  59182. }
  59183. else if (r == 2)
  59184. {
  59185. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59186. {
  59187. owner->setSwatchColour (index, owner->getCurrentColour());
  59188. repaint();
  59189. }
  59190. }
  59191. }
  59192. private:
  59193. ColourSelector* const owner;
  59194. const int index;
  59195. SwatchComponent (const SwatchComponent&);
  59196. const SwatchComponent& operator= (const SwatchComponent&);
  59197. };
  59198. ColourSelector::ColourSelector (const int flags_,
  59199. const int edgeGap_,
  59200. const int gapAroundColourSpaceComponent)
  59201. : colour (Colours::white),
  59202. flags (flags_),
  59203. topSpace (0),
  59204. edgeGap (edgeGap_)
  59205. {
  59206. // not much point having a selector with no components in it!
  59207. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59208. updateHSV();
  59209. if ((flags & showSliders) != 0)
  59210. {
  59211. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59212. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59213. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59214. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59215. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59216. for (int i = 4; --i >= 0;)
  59217. sliders[i]->addListener (this);
  59218. }
  59219. else
  59220. {
  59221. zeromem (sliders, sizeof (sliders));
  59222. }
  59223. if ((flags & showColourspace) != 0)
  59224. {
  59225. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59226. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59227. }
  59228. else
  59229. {
  59230. colourSpace = 0;
  59231. hueSelector = 0;
  59232. }
  59233. update();
  59234. }
  59235. ColourSelector::~ColourSelector()
  59236. {
  59237. dispatchPendingMessages();
  59238. swatchComponents.clear();
  59239. deleteAllChildren();
  59240. }
  59241. const Colour ColourSelector::getCurrentColour() const
  59242. {
  59243. return ((flags & showAlphaChannel) != 0) ? colour
  59244. : colour.withAlpha ((uint8) 0xff);
  59245. }
  59246. void ColourSelector::setCurrentColour (const Colour& c)
  59247. {
  59248. if (c != colour)
  59249. {
  59250. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59251. updateHSV();
  59252. update();
  59253. }
  59254. }
  59255. void ColourSelector::setHue (float newH)
  59256. {
  59257. newH = jlimit (0.0f, 1.0f, newH);
  59258. if (h != newH)
  59259. {
  59260. h = newH;
  59261. colour = Colour (h, s, v, colour.getFloatAlpha());
  59262. update();
  59263. }
  59264. }
  59265. void ColourSelector::setSV (float newS, float newV)
  59266. {
  59267. newS = jlimit (0.0f, 1.0f, newS);
  59268. newV = jlimit (0.0f, 1.0f, newV);
  59269. if (s != newS || v != newV)
  59270. {
  59271. s = newS;
  59272. v = newV;
  59273. colour = Colour (h, s, v, colour.getFloatAlpha());
  59274. update();
  59275. }
  59276. }
  59277. void ColourSelector::updateHSV()
  59278. {
  59279. colour.getHSB (h, s, v);
  59280. }
  59281. void ColourSelector::update()
  59282. {
  59283. if (sliders[0] != 0)
  59284. {
  59285. sliders[0]->setValue ((int) colour.getRed());
  59286. sliders[1]->setValue ((int) colour.getGreen());
  59287. sliders[2]->setValue ((int) colour.getBlue());
  59288. sliders[3]->setValue ((int) colour.getAlpha());
  59289. }
  59290. if (colourSpace != 0)
  59291. {
  59292. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59293. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59294. }
  59295. if ((flags & showColourAtTop) != 0)
  59296. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59297. sendChangeMessage (this);
  59298. }
  59299. void ColourSelector::paint (Graphics& g)
  59300. {
  59301. g.fillAll (findColour (backgroundColourId));
  59302. if ((flags & showColourAtTop) != 0)
  59303. {
  59304. const Colour colour (getCurrentColour());
  59305. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59306. 10, 10,
  59307. Colour (0xffdddddd).overlaidWith (colour),
  59308. Colour (0xffffffff).overlaidWith (colour));
  59309. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59310. g.setFont (14.0f, true);
  59311. g.drawText (((flags & showAlphaChannel) != 0)
  59312. ? String::formatted (T("#%02X%02X%02X%02X"),
  59313. (int) colour.getAlpha(),
  59314. (int) colour.getRed(),
  59315. (int) colour.getGreen(),
  59316. (int) colour.getBlue())
  59317. : String::formatted (T("#%02X%02X%02X"),
  59318. (int) colour.getRed(),
  59319. (int) colour.getGreen(),
  59320. (int) colour.getBlue()),
  59321. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59322. Justification::centred, false);
  59323. }
  59324. if ((flags & showSliders) != 0)
  59325. {
  59326. g.setColour (findColour (labelTextColourId));
  59327. g.setFont (11.0f);
  59328. for (int i = 4; --i >= 0;)
  59329. {
  59330. if (sliders[i]->isVisible())
  59331. g.drawText (sliders[i]->getName() + T(":"),
  59332. 0, sliders[i]->getY(),
  59333. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59334. Justification::centredRight, false);
  59335. }
  59336. }
  59337. }
  59338. void ColourSelector::resized()
  59339. {
  59340. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59341. const int numSwatches = getNumSwatches();
  59342. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59343. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59344. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59345. int y = topSpace;
  59346. if ((flags & showColourspace) != 0)
  59347. {
  59348. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59349. colourSpace->setBounds (edgeGap, y,
  59350. getWidth() - hueWidth - edgeGap - 4,
  59351. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59352. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59353. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59354. colourSpace->getHeight());
  59355. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59356. }
  59357. if ((flags & showSliders) != 0)
  59358. {
  59359. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59360. for (int i = 0; i < numSliders; ++i)
  59361. {
  59362. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59363. proportionOfWidth (0.72f), sliderHeight - 2);
  59364. y += sliderHeight;
  59365. }
  59366. }
  59367. if (numSwatches > 0)
  59368. {
  59369. const int startX = 8;
  59370. const int xGap = 4;
  59371. const int yGap = 4;
  59372. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59373. y += edgeGap;
  59374. if (swatchComponents.size() != numSwatches)
  59375. {
  59376. swatchComponents.clear();
  59377. for (int i = 0; i < numSwatches; ++i)
  59378. {
  59379. SwatchComponent* const sc = new SwatchComponent (this, i);
  59380. swatchComponents.add (sc);
  59381. addAndMakeVisible (sc);
  59382. }
  59383. }
  59384. int x = startX;
  59385. for (int i = 0; i < swatchComponents.size(); ++i)
  59386. {
  59387. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59388. sc->setBounds (x + xGap / 2,
  59389. y + yGap / 2,
  59390. swatchWidth - xGap,
  59391. swatchHeight - yGap);
  59392. if (((i + 1) % swatchesPerRow) == 0)
  59393. {
  59394. x = startX;
  59395. y += swatchHeight;
  59396. }
  59397. else
  59398. {
  59399. x += swatchWidth;
  59400. }
  59401. }
  59402. }
  59403. }
  59404. void ColourSelector::sliderValueChanged (Slider*)
  59405. {
  59406. if (sliders[0] != 0)
  59407. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59408. (uint8) sliders[1]->getValue(),
  59409. (uint8) sliders[2]->getValue(),
  59410. (uint8) sliders[3]->getValue()));
  59411. }
  59412. int ColourSelector::getNumSwatches() const
  59413. {
  59414. return 0;
  59415. }
  59416. const Colour ColourSelector::getSwatchColour (const int) const
  59417. {
  59418. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59419. return Colours::black;
  59420. }
  59421. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59422. {
  59423. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59424. }
  59425. END_JUCE_NAMESPACE
  59426. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59427. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59428. BEGIN_JUCE_NAMESPACE
  59429. class ShadowWindow : public Component
  59430. {
  59431. Component* owner;
  59432. Image** shadowImageSections;
  59433. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59434. public:
  59435. ShadowWindow (Component* const owner_,
  59436. const int type_,
  59437. Image** const shadowImageSections_)
  59438. : owner (owner_),
  59439. shadowImageSections (shadowImageSections_),
  59440. type (type_)
  59441. {
  59442. setInterceptsMouseClicks (false, false);
  59443. if (owner_->isOnDesktop())
  59444. {
  59445. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59446. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59447. | ComponentPeer::windowIsTemporary
  59448. | ComponentPeer::windowIgnoresKeyPresses);
  59449. }
  59450. else if (owner_->getParentComponent() != 0)
  59451. {
  59452. owner_->getParentComponent()->addChildComponent (this);
  59453. }
  59454. }
  59455. ~ShadowWindow()
  59456. {
  59457. }
  59458. void paint (Graphics& g)
  59459. {
  59460. Image* const topLeft = shadowImageSections [type * 3];
  59461. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59462. Image* const filler = shadowImageSections [type * 3 + 2];
  59463. g.setOpacity (1.0f);
  59464. if (type < 2)
  59465. {
  59466. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59467. g.drawImage (topLeft,
  59468. 0, 0, topLeft->getWidth(), imH,
  59469. 0, 0, topLeft->getWidth(), imH);
  59470. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59471. g.drawImage (bottomRight,
  59472. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59473. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59474. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59475. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59476. }
  59477. else
  59478. {
  59479. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59480. g.drawImage (topLeft,
  59481. 0, 0, imW, topLeft->getHeight(),
  59482. 0, 0, imW, topLeft->getHeight());
  59483. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59484. g.drawImage (bottomRight,
  59485. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59486. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59487. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59488. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59489. }
  59490. }
  59491. void resized()
  59492. {
  59493. repaint(); // (needed for correct repainting)
  59494. }
  59495. private:
  59496. ShadowWindow (const ShadowWindow&);
  59497. const ShadowWindow& operator= (const ShadowWindow&);
  59498. };
  59499. DropShadower::DropShadower (const float alpha_,
  59500. const int xOffset_,
  59501. const int yOffset_,
  59502. const float blurRadius_)
  59503. : owner (0),
  59504. numShadows (0),
  59505. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59506. xOffset (xOffset_),
  59507. yOffset (yOffset_),
  59508. alpha (alpha_),
  59509. blurRadius (blurRadius_),
  59510. inDestructor (false),
  59511. reentrant (false)
  59512. {
  59513. }
  59514. DropShadower::~DropShadower()
  59515. {
  59516. if (owner != 0)
  59517. owner->removeComponentListener (this);
  59518. inDestructor = true;
  59519. deleteShadowWindows();
  59520. }
  59521. void DropShadower::deleteShadowWindows()
  59522. {
  59523. if (numShadows > 0)
  59524. {
  59525. int i;
  59526. for (i = numShadows; --i >= 0;)
  59527. delete shadowWindows[i];
  59528. for (i = 12; --i >= 0;)
  59529. delete shadowImageSections[i];
  59530. numShadows = 0;
  59531. }
  59532. }
  59533. void DropShadower::setOwner (Component* componentToFollow)
  59534. {
  59535. if (componentToFollow != owner)
  59536. {
  59537. if (owner != 0)
  59538. owner->removeComponentListener (this);
  59539. // (the component can't be null)
  59540. jassert (componentToFollow != 0);
  59541. owner = componentToFollow;
  59542. jassert (owner != 0);
  59543. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59544. owner->addComponentListener (this);
  59545. updateShadows();
  59546. }
  59547. }
  59548. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59549. {
  59550. updateShadows();
  59551. }
  59552. void DropShadower::componentBroughtToFront (Component&)
  59553. {
  59554. bringShadowWindowsToFront();
  59555. }
  59556. void DropShadower::componentChildrenChanged (Component&)
  59557. {
  59558. }
  59559. void DropShadower::componentParentHierarchyChanged (Component&)
  59560. {
  59561. deleteShadowWindows();
  59562. updateShadows();
  59563. }
  59564. void DropShadower::componentVisibilityChanged (Component&)
  59565. {
  59566. updateShadows();
  59567. }
  59568. void DropShadower::updateShadows()
  59569. {
  59570. if (reentrant || inDestructor || (owner == 0))
  59571. return;
  59572. reentrant = true;
  59573. ComponentPeer* const nw = owner->getPeer();
  59574. const bool isOwnerVisible = owner->isVisible()
  59575. && (nw == 0 || ! nw->isMinimised());
  59576. const bool createShadowWindows = numShadows == 0
  59577. && owner->getWidth() > 0
  59578. && owner->getHeight() > 0
  59579. && isOwnerVisible
  59580. && (Desktop::canUseSemiTransparentWindows()
  59581. || owner->getParentComponent() != 0);
  59582. if (createShadowWindows)
  59583. {
  59584. // keep a cached version of the image to save doing the gaussian too often
  59585. String imageId;
  59586. imageId << shadowEdge << T(',')
  59587. << xOffset << T(',')
  59588. << yOffset << T(',')
  59589. << alpha;
  59590. const int hash = imageId.hashCode();
  59591. Image* bigIm = ImageCache::getFromHashCode (hash);
  59592. if (bigIm == 0)
  59593. {
  59594. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59595. Graphics bigG (*bigIm);
  59596. bigG.setColour (Colours::black.withAlpha (alpha));
  59597. bigG.fillRect (shadowEdge + xOffset,
  59598. shadowEdge + yOffset,
  59599. bigIm->getWidth() - (shadowEdge * 2),
  59600. bigIm->getHeight() - (shadowEdge * 2));
  59601. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59602. blurKernel.createGaussianBlur (blurRadius);
  59603. blurKernel.applyToImage (*bigIm, 0,
  59604. xOffset,
  59605. yOffset,
  59606. bigIm->getWidth(),
  59607. bigIm->getHeight());
  59608. ImageCache::addImageToCache (bigIm, hash);
  59609. }
  59610. const int iw = bigIm->getWidth();
  59611. const int ih = bigIm->getHeight();
  59612. const int shadowEdge2 = shadowEdge * 2;
  59613. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59614. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59615. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59616. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59617. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59618. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59619. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59620. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59621. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59622. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59623. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59624. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59625. ImageCache::release (bigIm);
  59626. for (int i = 0; i < 4; ++i)
  59627. {
  59628. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59629. ++numShadows;
  59630. }
  59631. }
  59632. if (numShadows > 0)
  59633. {
  59634. for (int i = numShadows; --i >= 0;)
  59635. {
  59636. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59637. shadowWindows[i]->setVisible (isOwnerVisible);
  59638. }
  59639. const int x = owner->getX();
  59640. const int y = owner->getY() - shadowEdge;
  59641. const int w = owner->getWidth();
  59642. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59643. shadowWindows[0]->setBounds (x - shadowEdge,
  59644. y,
  59645. shadowEdge,
  59646. h);
  59647. shadowWindows[1]->setBounds (x + w,
  59648. y,
  59649. shadowEdge,
  59650. h);
  59651. shadowWindows[2]->setBounds (x,
  59652. y,
  59653. w,
  59654. shadowEdge);
  59655. shadowWindows[3]->setBounds (x,
  59656. owner->getBottom(),
  59657. w,
  59658. shadowEdge);
  59659. }
  59660. reentrant = false;
  59661. if (createShadowWindows)
  59662. bringShadowWindowsToFront();
  59663. }
  59664. void DropShadower::setShadowImage (Image* const src,
  59665. const int num,
  59666. const int w,
  59667. const int h,
  59668. const int sx,
  59669. const int sy)
  59670. {
  59671. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59672. Graphics g (*shadowImageSections[num]);
  59673. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59674. }
  59675. void DropShadower::bringShadowWindowsToFront()
  59676. {
  59677. if (! (inDestructor || reentrant))
  59678. {
  59679. updateShadows();
  59680. reentrant = true;
  59681. for (int i = numShadows; --i >= 0;)
  59682. shadowWindows[i]->toBehind (owner);
  59683. reentrant = false;
  59684. }
  59685. }
  59686. END_JUCE_NAMESPACE
  59687. /*** End of inlined file: juce_DropShadower.cpp ***/
  59688. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59689. BEGIN_JUCE_NAMESPACE
  59690. class MagnifyingPeer : public ComponentPeer
  59691. {
  59692. public:
  59693. MagnifyingPeer (Component* const component_,
  59694. MagnifierComponent* const magnifierComp_)
  59695. : ComponentPeer (component_, 0),
  59696. magnifierComp (magnifierComp_)
  59697. {
  59698. }
  59699. ~MagnifyingPeer()
  59700. {
  59701. }
  59702. void* getNativeHandle() const { return 0; }
  59703. void setVisible (bool) {}
  59704. void setTitle (const String&) {}
  59705. void setPosition (int, int) {}
  59706. void setSize (int, int) {}
  59707. void setBounds (int, int, int, int, const bool) {}
  59708. void setMinimised (bool) {}
  59709. bool isMinimised() const { return false; }
  59710. void setFullScreen (bool) {}
  59711. bool isFullScreen() const { return false; }
  59712. const BorderSize getFrameSize() const { return BorderSize (0); }
  59713. bool setAlwaysOnTop (bool) { return true; }
  59714. void toFront (bool) {}
  59715. void toBehind (ComponentPeer*) {}
  59716. void setIcon (const Image&) {}
  59717. bool isFocused() const
  59718. {
  59719. return magnifierComp->hasKeyboardFocus (true);
  59720. }
  59721. void grabFocus()
  59722. {
  59723. ComponentPeer* peer = magnifierComp->getPeer();
  59724. if (peer != 0)
  59725. peer->grabFocus();
  59726. }
  59727. void textInputRequired (int x, int y)
  59728. {
  59729. ComponentPeer* peer = magnifierComp->getPeer();
  59730. if (peer != 0)
  59731. peer->textInputRequired (x, y);
  59732. }
  59733. void getBounds (int& x, int& y, int& w, int& h) const
  59734. {
  59735. x = magnifierComp->getScreenX();
  59736. y = magnifierComp->getScreenY();
  59737. w = component->getWidth();
  59738. h = component->getHeight();
  59739. }
  59740. int getScreenX() const { return magnifierComp->getScreenX(); }
  59741. int getScreenY() const { return magnifierComp->getScreenY(); }
  59742. void relativePositionToGlobal (int& x, int& y)
  59743. {
  59744. const double zoom = magnifierComp->getScaleFactor();
  59745. x = roundToInt (x * zoom);
  59746. y = roundToInt (y * zoom);
  59747. magnifierComp->relativePositionToGlobal (x, y);
  59748. }
  59749. void globalPositionToRelative (int& x, int& y)
  59750. {
  59751. magnifierComp->globalPositionToRelative (x, y);
  59752. const double zoom = magnifierComp->getScaleFactor();
  59753. x = roundToInt (x / zoom);
  59754. y = roundToInt (y / zoom);
  59755. }
  59756. bool contains (int x, int y, bool) const
  59757. {
  59758. return ((unsigned int) x) < (unsigned int) magnifierComp->getWidth()
  59759. && ((unsigned int) y) < (unsigned int) magnifierComp->getHeight();
  59760. }
  59761. void repaint (int x, int y, int w, int h)
  59762. {
  59763. const double zoom = magnifierComp->getScaleFactor();
  59764. magnifierComp->repaint ((int) (x * zoom),
  59765. (int) (y * zoom),
  59766. roundToInt (w * zoom) + 1,
  59767. roundToInt (h * zoom) + 1);
  59768. }
  59769. void performAnyPendingRepaintsNow()
  59770. {
  59771. }
  59772. juce_UseDebuggingNewOperator
  59773. private:
  59774. MagnifierComponent* const magnifierComp;
  59775. MagnifyingPeer (const MagnifyingPeer&);
  59776. const MagnifyingPeer& operator= (const MagnifyingPeer&);
  59777. };
  59778. class PeerHolderComp : public Component
  59779. {
  59780. public:
  59781. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59782. : magnifierComp (magnifierComp_)
  59783. {
  59784. setVisible (true);
  59785. }
  59786. ~PeerHolderComp()
  59787. {
  59788. }
  59789. ComponentPeer* createNewPeer (int, void*)
  59790. {
  59791. return new MagnifyingPeer (this, magnifierComp);
  59792. }
  59793. void childBoundsChanged (Component* c)
  59794. {
  59795. if (c != 0)
  59796. {
  59797. setSize (c->getWidth(), c->getHeight());
  59798. magnifierComp->childBoundsChanged (this);
  59799. }
  59800. }
  59801. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59802. {
  59803. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59804. Component* const p = magnifierComp->getParentComponent();
  59805. if (p != 0)
  59806. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59807. }
  59808. private:
  59809. MagnifierComponent* const magnifierComp;
  59810. PeerHolderComp (const PeerHolderComp&);
  59811. const PeerHolderComp& operator= (const PeerHolderComp&);
  59812. };
  59813. MagnifierComponent::MagnifierComponent (Component* const content_,
  59814. const bool deleteContentCompWhenNoLongerNeeded)
  59815. : content (content_),
  59816. scaleFactor (0.0),
  59817. peer (0),
  59818. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59819. quality (Graphics::lowResamplingQuality)
  59820. {
  59821. holderComp = new PeerHolderComp (this);
  59822. setScaleFactor (1.0);
  59823. }
  59824. MagnifierComponent::~MagnifierComponent()
  59825. {
  59826. delete holderComp;
  59827. if (deleteContent)
  59828. delete content;
  59829. }
  59830. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59831. {
  59832. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59833. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59834. if (scaleFactor != newScaleFactor)
  59835. {
  59836. scaleFactor = newScaleFactor;
  59837. if (scaleFactor == 1.0)
  59838. {
  59839. holderComp->removeFromDesktop();
  59840. peer = 0;
  59841. addChildComponent (content);
  59842. childBoundsChanged (content);
  59843. }
  59844. else
  59845. {
  59846. holderComp->addAndMakeVisible (content);
  59847. holderComp->childBoundsChanged (content);
  59848. childBoundsChanged (holderComp);
  59849. holderComp->addToDesktop (0);
  59850. peer = holderComp->getPeer();
  59851. }
  59852. repaint();
  59853. }
  59854. }
  59855. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59856. {
  59857. quality = newQuality;
  59858. }
  59859. void MagnifierComponent::paint (Graphics& g)
  59860. {
  59861. const int w = holderComp->getWidth();
  59862. const int h = holderComp->getHeight();
  59863. if (w == 0 || h == 0)
  59864. return;
  59865. const Rectangle<int> r (g.getClipBounds());
  59866. const int srcX = (int) (r.getX() / scaleFactor);
  59867. const int srcY = (int) (r.getY() / scaleFactor);
  59868. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59869. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59870. if (scaleFactor >= 1.0)
  59871. {
  59872. ++srcW;
  59873. ++srcH;
  59874. }
  59875. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59876. temp.clear (srcX, srcY, srcW, srcH);
  59877. {
  59878. Graphics g2 (temp);
  59879. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59880. holderComp->paintEntireComponent (g2);
  59881. }
  59882. g.setImageResamplingQuality (quality);
  59883. g.drawImageTransformed (&temp, temp.getBounds(),
  59884. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59885. false);
  59886. }
  59887. void MagnifierComponent::childBoundsChanged (Component* c)
  59888. {
  59889. if (c != 0)
  59890. setSize (roundToInt (c->getWidth() * scaleFactor),
  59891. roundToInt (c->getHeight() * scaleFactor));
  59892. }
  59893. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59894. {
  59895. if (peer != 0)
  59896. peer->handleMouseDown (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59897. }
  59898. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59899. {
  59900. if (peer != 0)
  59901. peer->handleMouseUp (e.mods.getRawFlags(), scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59902. }
  59903. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59904. {
  59905. if (peer != 0)
  59906. peer->handleMouseDrag (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59907. }
  59908. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59909. {
  59910. if (peer != 0)
  59911. peer->handleMouseMove (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59912. }
  59913. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59914. {
  59915. if (peer != 0)
  59916. peer->handleMouseEnter (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59917. }
  59918. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59919. {
  59920. if (peer != 0)
  59921. peer->handleMouseExit (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59922. }
  59923. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59924. {
  59925. if (peer != 0)
  59926. peer->handleMouseWheel (roundToInt (ix * 256.0f),
  59927. roundToInt (iy * 256.0f),
  59928. e.eventTime.toMilliseconds());
  59929. else
  59930. Component::mouseWheelMove (e, ix, iy);
  59931. }
  59932. int MagnifierComponent::scaleInt (const int n) const
  59933. {
  59934. return roundToInt (n / scaleFactor);
  59935. }
  59936. END_JUCE_NAMESPACE
  59937. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59938. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59939. BEGIN_JUCE_NAMESPACE
  59940. class MidiKeyboardUpDownButton : public Button
  59941. {
  59942. public:
  59943. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59944. const int delta_)
  59945. : Button (String::empty),
  59946. owner (owner_),
  59947. delta (delta_)
  59948. {
  59949. setOpaque (true);
  59950. }
  59951. ~MidiKeyboardUpDownButton()
  59952. {
  59953. }
  59954. void clicked()
  59955. {
  59956. int note = owner->getLowestVisibleKey();
  59957. if (delta < 0)
  59958. note = (note - 1) / 12;
  59959. else
  59960. note = note / 12 + 1;
  59961. owner->setLowestVisibleKey (note * 12);
  59962. }
  59963. void paintButton (Graphics& g,
  59964. bool isMouseOverButton,
  59965. bool isButtonDown)
  59966. {
  59967. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59968. isMouseOverButton, isButtonDown,
  59969. delta > 0);
  59970. }
  59971. private:
  59972. MidiKeyboardComponent* const owner;
  59973. const int delta;
  59974. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59975. const MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59976. };
  59977. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59978. const Orientation orientation_)
  59979. : state (state_),
  59980. xOffset (0),
  59981. blackNoteLength (1),
  59982. keyWidth (16.0f),
  59983. orientation (orientation_),
  59984. midiChannel (1),
  59985. midiInChannelMask (0xffff),
  59986. velocity (1.0f),
  59987. noteUnderMouse (-1),
  59988. mouseDownNote (-1),
  59989. rangeStart (0),
  59990. rangeEnd (127),
  59991. firstKey (12 * 4),
  59992. canScroll (true),
  59993. mouseDragging (false),
  59994. useMousePositionForVelocity (true),
  59995. keyMappingOctave (6),
  59996. octaveNumForMiddleC (3)
  59997. {
  59998. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59999. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  60000. // initialise with a default set of querty key-mappings..
  60001. const char* const keymap = "awsedftgyhujkolp;";
  60002. for (int i = String (keymap).length(); --i >= 0;)
  60003. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  60004. setOpaque (true);
  60005. setWantsKeyboardFocus (true);
  60006. state.addListener (this);
  60007. }
  60008. MidiKeyboardComponent::~MidiKeyboardComponent()
  60009. {
  60010. state.removeListener (this);
  60011. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  60012. deleteAllChildren();
  60013. }
  60014. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  60015. {
  60016. keyWidth = widthInPixels;
  60017. resized();
  60018. }
  60019. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  60020. {
  60021. if (orientation != newOrientation)
  60022. {
  60023. orientation = newOrientation;
  60024. resized();
  60025. }
  60026. }
  60027. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  60028. const int highestNote)
  60029. {
  60030. jassert (lowestNote >= 0 && lowestNote <= 127);
  60031. jassert (highestNote >= 0 && highestNote <= 127);
  60032. jassert (lowestNote <= highestNote);
  60033. if (rangeStart != lowestNote || rangeEnd != highestNote)
  60034. {
  60035. rangeStart = jlimit (0, 127, lowestNote);
  60036. rangeEnd = jlimit (0, 127, highestNote);
  60037. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  60038. resized();
  60039. }
  60040. }
  60041. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  60042. {
  60043. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  60044. if (noteNumber != firstKey)
  60045. {
  60046. firstKey = noteNumber;
  60047. sendChangeMessage (this);
  60048. resized();
  60049. }
  60050. }
  60051. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  60052. {
  60053. if (canScroll != canScroll_)
  60054. {
  60055. canScroll = canScroll_;
  60056. resized();
  60057. }
  60058. }
  60059. void MidiKeyboardComponent::colourChanged()
  60060. {
  60061. repaint();
  60062. }
  60063. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  60064. {
  60065. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  60066. if (midiChannel != midiChannelNumber)
  60067. {
  60068. resetAnyKeysInUse();
  60069. midiChannel = jlimit (1, 16, midiChannelNumber);
  60070. }
  60071. }
  60072. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  60073. {
  60074. midiInChannelMask = midiChannelMask;
  60075. triggerAsyncUpdate();
  60076. }
  60077. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  60078. {
  60079. velocity = jlimit (0.0f, 1.0f, velocity_);
  60080. useMousePositionForVelocity = useMousePositionForVelocity_;
  60081. }
  60082. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  60083. {
  60084. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  60085. static const float blackNoteWidth = 0.7f;
  60086. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  60087. 1.0f, 2 - blackNoteWidth * 0.4f,
  60088. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  60089. 4.0f, 5 - blackNoteWidth * 0.5f,
  60090. 5.0f, 6 - blackNoteWidth * 0.3f,
  60091. 6.0f };
  60092. static const float widths[] = { 1.0f, blackNoteWidth,
  60093. 1.0f, blackNoteWidth,
  60094. 1.0f, 1.0f, blackNoteWidth,
  60095. 1.0f, blackNoteWidth,
  60096. 1.0f, blackNoteWidth,
  60097. 1.0f };
  60098. const int octave = midiNoteNumber / 12;
  60099. const int note = midiNoteNumber % 12;
  60100. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  60101. w = roundToInt (widths [note] * keyWidth);
  60102. }
  60103. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  60104. {
  60105. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  60106. int rx, rw;
  60107. getKeyPosition (rangeStart, keyWidth, rx, rw);
  60108. x -= xOffset + rx;
  60109. }
  60110. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  60111. {
  60112. int x, y;
  60113. getKeyPos (midiNoteNumber, x, y);
  60114. return x;
  60115. }
  60116. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  60117. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  60118. int MidiKeyboardComponent::xyToNote (int x, int y, float& mousePositionVelocity)
  60119. {
  60120. if (! reallyContains (x, y, false))
  60121. return -1;
  60122. if (orientation != horizontalKeyboard)
  60123. {
  60124. swapVariables (x, y);
  60125. if (orientation == verticalKeyboardFacingLeft)
  60126. y = getWidth() - y;
  60127. else
  60128. x = getHeight() - x;
  60129. }
  60130. return remappedXYToNote (x + xOffset, y, mousePositionVelocity);
  60131. }
  60132. int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionVelocity) const
  60133. {
  60134. if (y < blackNoteLength)
  60135. {
  60136. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60137. {
  60138. for (int i = 0; i < 5; ++i)
  60139. {
  60140. const int note = octaveStart + blackNotes [i];
  60141. if (note >= rangeStart && note <= rangeEnd)
  60142. {
  60143. int kx, kw;
  60144. getKeyPos (note, kx, kw);
  60145. kx += xOffset;
  60146. if (x >= kx && x < kx + kw)
  60147. {
  60148. mousePositionVelocity = y / (float) blackNoteLength;
  60149. return note;
  60150. }
  60151. }
  60152. }
  60153. }
  60154. }
  60155. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60156. {
  60157. for (int i = 0; i < 7; ++i)
  60158. {
  60159. const int note = octaveStart + whiteNotes [i];
  60160. if (note >= rangeStart && note <= rangeEnd)
  60161. {
  60162. int kx, kw;
  60163. getKeyPos (note, kx, kw);
  60164. kx += xOffset;
  60165. if (x >= kx && x < kx + kw)
  60166. {
  60167. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60168. mousePositionVelocity = y / (float) whiteNoteLength;
  60169. return note;
  60170. }
  60171. }
  60172. }
  60173. }
  60174. mousePositionVelocity = 0;
  60175. return -1;
  60176. }
  60177. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60178. {
  60179. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60180. {
  60181. int x, w;
  60182. getKeyPos (noteNum, x, w);
  60183. if (orientation == horizontalKeyboard)
  60184. repaint (x, 0, w, getHeight());
  60185. else if (orientation == verticalKeyboardFacingLeft)
  60186. repaint (0, x, getWidth(), w);
  60187. else if (orientation == verticalKeyboardFacingRight)
  60188. repaint (0, getHeight() - x - w, getWidth(), w);
  60189. }
  60190. }
  60191. void MidiKeyboardComponent::paint (Graphics& g)
  60192. {
  60193. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60194. const Colour lineColour (findColour (keySeparatorLineColourId));
  60195. const Colour textColour (findColour (textLabelColourId));
  60196. int x, w, octave;
  60197. for (octave = 0; octave < 128; octave += 12)
  60198. {
  60199. for (int white = 0; white < 7; ++white)
  60200. {
  60201. const int noteNum = octave + whiteNotes [white];
  60202. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60203. {
  60204. getKeyPos (noteNum, x, w);
  60205. if (orientation == horizontalKeyboard)
  60206. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60207. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60208. noteUnderMouse == noteNum,
  60209. lineColour, textColour);
  60210. else if (orientation == verticalKeyboardFacingLeft)
  60211. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60212. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60213. noteUnderMouse == noteNum,
  60214. lineColour, textColour);
  60215. else if (orientation == verticalKeyboardFacingRight)
  60216. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60217. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60218. noteUnderMouse == noteNum,
  60219. lineColour, textColour);
  60220. }
  60221. }
  60222. }
  60223. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60224. if (orientation == verticalKeyboardFacingLeft)
  60225. {
  60226. x1 = getWidth() - 1.0f;
  60227. x2 = getWidth() - 5.0f;
  60228. }
  60229. else if (orientation == verticalKeyboardFacingRight)
  60230. x2 = 5.0f;
  60231. else
  60232. y2 = 5.0f;
  60233. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60234. Colours::transparentBlack, x2, y2, false));
  60235. getKeyPos (rangeEnd, x, w);
  60236. x += w;
  60237. if (orientation == verticalKeyboardFacingLeft)
  60238. g.fillRect (getWidth() - 5, 0, 5, x);
  60239. else if (orientation == verticalKeyboardFacingRight)
  60240. g.fillRect (0, 0, 5, x);
  60241. else
  60242. g.fillRect (0, 0, x, 5);
  60243. g.setColour (lineColour);
  60244. if (orientation == verticalKeyboardFacingLeft)
  60245. g.fillRect (0, 0, 1, x);
  60246. else if (orientation == verticalKeyboardFacingRight)
  60247. g.fillRect (getWidth() - 1, 0, 1, x);
  60248. else
  60249. g.fillRect (0, getHeight() - 1, x, 1);
  60250. const Colour blackNoteColour (findColour (blackNoteColourId));
  60251. for (octave = 0; octave < 128; octave += 12)
  60252. {
  60253. for (int black = 0; black < 5; ++black)
  60254. {
  60255. const int noteNum = octave + blackNotes [black];
  60256. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60257. {
  60258. getKeyPos (noteNum, x, w);
  60259. if (orientation == horizontalKeyboard)
  60260. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60261. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60262. noteUnderMouse == noteNum,
  60263. blackNoteColour);
  60264. else if (orientation == verticalKeyboardFacingLeft)
  60265. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60266. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60267. noteUnderMouse == noteNum,
  60268. blackNoteColour);
  60269. else if (orientation == verticalKeyboardFacingRight)
  60270. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60271. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60272. noteUnderMouse == noteNum,
  60273. blackNoteColour);
  60274. }
  60275. }
  60276. }
  60277. }
  60278. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60279. Graphics& g, int x, int y, int w, int h,
  60280. bool isDown, bool isOver,
  60281. const Colour& lineColour,
  60282. const Colour& textColour)
  60283. {
  60284. Colour c (Colours::transparentWhite);
  60285. if (isDown)
  60286. c = findColour (keyDownOverlayColourId);
  60287. if (isOver)
  60288. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60289. g.setColour (c);
  60290. g.fillRect (x, y, w, h);
  60291. const String text (getWhiteNoteText (midiNoteNumber));
  60292. if (! text.isEmpty())
  60293. {
  60294. g.setColour (textColour);
  60295. Font f (jmin (12.0f, keyWidth * 0.9f));
  60296. f.setHorizontalScale (0.8f);
  60297. g.setFont (f);
  60298. Justification justification (Justification::centredBottom);
  60299. if (orientation == verticalKeyboardFacingLeft)
  60300. justification = Justification::centredLeft;
  60301. else if (orientation == verticalKeyboardFacingRight)
  60302. justification = Justification::centredRight;
  60303. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60304. }
  60305. g.setColour (lineColour);
  60306. if (orientation == horizontalKeyboard)
  60307. g.fillRect (x, y, 1, h);
  60308. else if (orientation == verticalKeyboardFacingLeft)
  60309. g.fillRect (x, y, w, 1);
  60310. else if (orientation == verticalKeyboardFacingRight)
  60311. g.fillRect (x, y + h - 1, w, 1);
  60312. if (midiNoteNumber == rangeEnd)
  60313. {
  60314. if (orientation == horizontalKeyboard)
  60315. g.fillRect (x + w, y, 1, h);
  60316. else if (orientation == verticalKeyboardFacingLeft)
  60317. g.fillRect (x, y + h, w, 1);
  60318. else if (orientation == verticalKeyboardFacingRight)
  60319. g.fillRect (x, y - 1, w, 1);
  60320. }
  60321. }
  60322. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60323. Graphics& g, int x, int y, int w, int h,
  60324. bool isDown, bool isOver,
  60325. const Colour& noteFillColour)
  60326. {
  60327. Colour c (noteFillColour);
  60328. if (isDown)
  60329. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60330. if (isOver)
  60331. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60332. g.setColour (c);
  60333. g.fillRect (x, y, w, h);
  60334. if (isDown)
  60335. {
  60336. g.setColour (noteFillColour);
  60337. g.drawRect (x, y, w, h);
  60338. }
  60339. else
  60340. {
  60341. const int xIndent = jmax (1, jmin (w, h) / 8);
  60342. g.setColour (c.brighter());
  60343. if (orientation == horizontalKeyboard)
  60344. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60345. else if (orientation == verticalKeyboardFacingLeft)
  60346. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60347. else if (orientation == verticalKeyboardFacingRight)
  60348. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60349. }
  60350. }
  60351. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60352. {
  60353. octaveNumForMiddleC = octaveNumForMiddleC_;
  60354. repaint();
  60355. }
  60356. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60357. {
  60358. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60359. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60360. return String::empty;
  60361. }
  60362. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60363. const bool isMouseOver,
  60364. const bool isButtonDown,
  60365. const bool movesOctavesUp)
  60366. {
  60367. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60368. float angle;
  60369. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60370. angle = movesOctavesUp ? 0.0f : 0.5f;
  60371. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60372. angle = movesOctavesUp ? 0.25f : 0.75f;
  60373. else
  60374. angle = movesOctavesUp ? 0.75f : 0.25f;
  60375. Path path;
  60376. path.lineTo (0.0f, 1.0f);
  60377. path.lineTo (1.0f, 0.5f);
  60378. path.closeSubPath();
  60379. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60380. g.setColour (findColour (upDownButtonArrowColourId)
  60381. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60382. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60383. w - 2.0f,
  60384. h - 2.0f,
  60385. true));
  60386. }
  60387. void MidiKeyboardComponent::resized()
  60388. {
  60389. int w = getWidth();
  60390. int h = getHeight();
  60391. if (w > 0 && h > 0)
  60392. {
  60393. if (orientation != horizontalKeyboard)
  60394. swapVariables (w, h);
  60395. blackNoteLength = roundToInt (h * 0.7f);
  60396. int kx2, kw2;
  60397. getKeyPos (rangeEnd, kx2, kw2);
  60398. kx2 += kw2;
  60399. if (firstKey != rangeStart)
  60400. {
  60401. int kx1, kw1;
  60402. getKeyPos (rangeStart, kx1, kw1);
  60403. if (kx2 - kx1 <= w)
  60404. {
  60405. firstKey = rangeStart;
  60406. sendChangeMessage (this);
  60407. repaint();
  60408. }
  60409. }
  60410. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60411. scrollDown->setVisible (showScrollButtons);
  60412. scrollUp->setVisible (showScrollButtons);
  60413. xOffset = 0;
  60414. if (showScrollButtons)
  60415. {
  60416. const int scrollButtonW = jmin (12, w / 2);
  60417. if (orientation == horizontalKeyboard)
  60418. {
  60419. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60420. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60421. }
  60422. else if (orientation == verticalKeyboardFacingLeft)
  60423. {
  60424. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60425. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60426. }
  60427. else if (orientation == verticalKeyboardFacingRight)
  60428. {
  60429. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60430. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60431. }
  60432. int endOfLastKey, kw;
  60433. getKeyPos (rangeEnd, endOfLastKey, kw);
  60434. endOfLastKey += kw;
  60435. float mousePositionVelocity;
  60436. const int spaceAvailable = w - scrollButtonW * 2;
  60437. const int lastStartKey = remappedXYToNote (endOfLastKey - spaceAvailable, 0, mousePositionVelocity) + 1;
  60438. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60439. {
  60440. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60441. sendChangeMessage (this);
  60442. }
  60443. int newOffset = 0;
  60444. getKeyPos (firstKey, newOffset, kw);
  60445. xOffset = newOffset - scrollButtonW;
  60446. }
  60447. else
  60448. {
  60449. firstKey = rangeStart;
  60450. }
  60451. timerCallback();
  60452. repaint();
  60453. }
  60454. }
  60455. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60456. {
  60457. triggerAsyncUpdate();
  60458. }
  60459. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60460. {
  60461. triggerAsyncUpdate();
  60462. }
  60463. void MidiKeyboardComponent::handleAsyncUpdate()
  60464. {
  60465. for (int i = rangeStart; i <= rangeEnd; ++i)
  60466. {
  60467. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60468. {
  60469. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60470. repaintNote (i);
  60471. }
  60472. }
  60473. }
  60474. void MidiKeyboardComponent::resetAnyKeysInUse()
  60475. {
  60476. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60477. {
  60478. state.allNotesOff (midiChannel);
  60479. keysPressed.clear();
  60480. mouseDownNote = -1;
  60481. }
  60482. }
  60483. void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y)
  60484. {
  60485. float mousePositionVelocity = 0.0f;
  60486. const int newNote = (mouseDragging || isMouseOver())
  60487. ? xyToNote (x, y, mousePositionVelocity) : -1;
  60488. if (noteUnderMouse != newNote)
  60489. {
  60490. if (mouseDownNote >= 0)
  60491. {
  60492. state.noteOff (midiChannel, mouseDownNote);
  60493. mouseDownNote = -1;
  60494. }
  60495. if (mouseDragging && newNote >= 0)
  60496. {
  60497. if (! useMousePositionForVelocity)
  60498. mousePositionVelocity = 1.0f;
  60499. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60500. mouseDownNote = newNote;
  60501. }
  60502. repaintNote (noteUnderMouse);
  60503. noteUnderMouse = newNote;
  60504. repaintNote (noteUnderMouse);
  60505. }
  60506. else if (mouseDownNote >= 0 && ! mouseDragging)
  60507. {
  60508. state.noteOff (midiChannel, mouseDownNote);
  60509. mouseDownNote = -1;
  60510. }
  60511. }
  60512. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60513. {
  60514. updateNoteUnderMouse (e.x, e.y);
  60515. stopTimer();
  60516. }
  60517. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60518. {
  60519. float mousePositionVelocity;
  60520. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60521. if (newNote >= 0)
  60522. mouseDraggedToKey (newNote, e);
  60523. updateNoteUnderMouse (e.x, e.y);
  60524. }
  60525. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60526. {
  60527. return true;
  60528. }
  60529. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60530. {
  60531. }
  60532. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60533. {
  60534. float mousePositionVelocity;
  60535. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60536. mouseDragging = false;
  60537. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60538. {
  60539. repaintNote (noteUnderMouse);
  60540. noteUnderMouse = -1;
  60541. mouseDragging = true;
  60542. updateNoteUnderMouse (e.x, e.y);
  60543. startTimer (500);
  60544. }
  60545. }
  60546. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60547. {
  60548. mouseDragging = false;
  60549. updateNoteUnderMouse (e.x, e.y);
  60550. stopTimer();
  60551. }
  60552. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60553. {
  60554. updateNoteUnderMouse (e.x, e.y);
  60555. }
  60556. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60557. {
  60558. updateNoteUnderMouse (e.x, e.y);
  60559. }
  60560. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60561. {
  60562. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60563. }
  60564. void MidiKeyboardComponent::timerCallback()
  60565. {
  60566. int mx, my;
  60567. getMouseXYRelative (mx, my);
  60568. updateNoteUnderMouse (mx, my);
  60569. }
  60570. void MidiKeyboardComponent::clearKeyMappings()
  60571. {
  60572. resetAnyKeysInUse();
  60573. keyPressNotes.clear();
  60574. keyPresses.clear();
  60575. }
  60576. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60577. const int midiNoteOffsetFromC)
  60578. {
  60579. removeKeyPressForNote (midiNoteOffsetFromC);
  60580. keyPressNotes.add (midiNoteOffsetFromC);
  60581. keyPresses.add (key);
  60582. }
  60583. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60584. {
  60585. for (int i = keyPressNotes.size(); --i >= 0;)
  60586. {
  60587. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60588. {
  60589. keyPressNotes.remove (i);
  60590. keyPresses.remove (i);
  60591. }
  60592. }
  60593. }
  60594. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60595. {
  60596. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60597. keyMappingOctave = newOctaveNumber;
  60598. }
  60599. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60600. {
  60601. bool keyPressUsed = false;
  60602. for (int i = keyPresses.size(); --i >= 0;)
  60603. {
  60604. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60605. if (keyPresses.getReference(i).isCurrentlyDown())
  60606. {
  60607. if (! keysPressed [note])
  60608. {
  60609. keysPressed.setBit (note);
  60610. state.noteOn (midiChannel, note, velocity);
  60611. keyPressUsed = true;
  60612. }
  60613. }
  60614. else
  60615. {
  60616. if (keysPressed [note])
  60617. {
  60618. keysPressed.clearBit (note);
  60619. state.noteOff (midiChannel, note);
  60620. keyPressUsed = true;
  60621. }
  60622. }
  60623. }
  60624. return keyPressUsed;
  60625. }
  60626. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60627. {
  60628. resetAnyKeysInUse();
  60629. }
  60630. END_JUCE_NAMESPACE
  60631. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60632. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60633. #if JUCE_OPENGL
  60634. BEGIN_JUCE_NAMESPACE
  60635. extern void juce_glViewport (const int w, const int h);
  60636. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60637. const int alphaBits_,
  60638. const int depthBufferBits_,
  60639. const int stencilBufferBits_) throw()
  60640. : redBits (bitsPerRGBComponent),
  60641. greenBits (bitsPerRGBComponent),
  60642. blueBits (bitsPerRGBComponent),
  60643. alphaBits (alphaBits_),
  60644. depthBufferBits (depthBufferBits_),
  60645. stencilBufferBits (stencilBufferBits_),
  60646. accumulationBufferRedBits (0),
  60647. accumulationBufferGreenBits (0),
  60648. accumulationBufferBlueBits (0),
  60649. accumulationBufferAlphaBits (0),
  60650. fullSceneAntiAliasingNumSamples (0)
  60651. {
  60652. }
  60653. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60654. {
  60655. return memcmp (this, &other, sizeof (other)) == 0;
  60656. }
  60657. static VoidArray knownContexts;
  60658. OpenGLContext::OpenGLContext() throw()
  60659. {
  60660. knownContexts.add (this);
  60661. }
  60662. OpenGLContext::~OpenGLContext()
  60663. {
  60664. knownContexts.removeValue (this);
  60665. }
  60666. OpenGLContext* OpenGLContext::getCurrentContext()
  60667. {
  60668. for (int i = knownContexts.size(); --i >= 0;)
  60669. {
  60670. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60671. if (oglc->isActive())
  60672. return oglc;
  60673. }
  60674. return 0;
  60675. }
  60676. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60677. {
  60678. public:
  60679. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60680. : ComponentMovementWatcher (owner_),
  60681. owner (owner_),
  60682. wasShowing (false)
  60683. {
  60684. }
  60685. ~OpenGLComponentWatcher() {}
  60686. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60687. {
  60688. owner->updateContextPosition();
  60689. }
  60690. void componentPeerChanged()
  60691. {
  60692. const ScopedLock sl (owner->getContextLock());
  60693. owner->deleteContext();
  60694. }
  60695. void componentVisibilityChanged (Component&)
  60696. {
  60697. const bool isShowingNow = owner->isShowing();
  60698. if (wasShowing != isShowingNow)
  60699. {
  60700. wasShowing = isShowingNow;
  60701. owner->updateContextPosition();
  60702. }
  60703. }
  60704. juce_UseDebuggingNewOperator
  60705. private:
  60706. OpenGLComponent* const owner;
  60707. bool wasShowing;
  60708. };
  60709. OpenGLComponent::OpenGLComponent()
  60710. : context (0),
  60711. contextToShareListsWith (0),
  60712. needToUpdateViewport (true)
  60713. {
  60714. setOpaque (true);
  60715. componentWatcher = new OpenGLComponentWatcher (this);
  60716. }
  60717. OpenGLComponent::~OpenGLComponent()
  60718. {
  60719. deleteContext();
  60720. componentWatcher = 0;
  60721. }
  60722. void OpenGLComponent::deleteContext()
  60723. {
  60724. const ScopedLock sl (contextLock);
  60725. deleteAndZero (context);
  60726. }
  60727. void OpenGLComponent::updateContextPosition()
  60728. {
  60729. needToUpdateViewport = true;
  60730. if (getWidth() > 0 && getHeight() > 0)
  60731. {
  60732. Component* const topComp = getTopLevelComponent();
  60733. if (topComp->getPeer() != 0)
  60734. {
  60735. const ScopedLock sl (contextLock);
  60736. if (context != 0)
  60737. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60738. getScreenY() - topComp->getScreenY(),
  60739. getWidth(),
  60740. getHeight(),
  60741. topComp->getHeight());
  60742. }
  60743. }
  60744. }
  60745. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60746. {
  60747. OpenGLPixelFormat pf;
  60748. const ScopedLock sl (contextLock);
  60749. if (context != 0)
  60750. pf = context->getPixelFormat();
  60751. return pf;
  60752. }
  60753. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60754. {
  60755. if (! (preferredPixelFormat == formatToUse))
  60756. {
  60757. const ScopedLock sl (contextLock);
  60758. deleteContext();
  60759. preferredPixelFormat = formatToUse;
  60760. }
  60761. }
  60762. void OpenGLComponent::shareWith (OpenGLContext* c)
  60763. {
  60764. if (contextToShareListsWith != c)
  60765. {
  60766. const ScopedLock sl (contextLock);
  60767. deleteContext();
  60768. contextToShareListsWith = c;
  60769. }
  60770. }
  60771. bool OpenGLComponent::makeCurrentContextActive()
  60772. {
  60773. if (context == 0)
  60774. {
  60775. const ScopedLock sl (contextLock);
  60776. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60777. {
  60778. context = OpenGLContext::createContextForWindow (this,
  60779. preferredPixelFormat,
  60780. contextToShareListsWith);
  60781. if (context != 0)
  60782. {
  60783. updateContextPosition();
  60784. if (context->makeActive())
  60785. newOpenGLContextCreated();
  60786. }
  60787. }
  60788. }
  60789. return context != 0 && context->makeActive();
  60790. }
  60791. void OpenGLComponent::makeCurrentContextInactive()
  60792. {
  60793. if (context != 0)
  60794. context->makeInactive();
  60795. }
  60796. bool OpenGLComponent::isActiveContext() const throw()
  60797. {
  60798. return context != 0 && context->isActive();
  60799. }
  60800. void OpenGLComponent::swapBuffers()
  60801. {
  60802. if (context != 0)
  60803. context->swapBuffers();
  60804. }
  60805. void OpenGLComponent::paint (Graphics&)
  60806. {
  60807. if (renderAndSwapBuffers())
  60808. {
  60809. ComponentPeer* const peer = getPeer();
  60810. if (peer != 0)
  60811. {
  60812. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  60813. getScreenY() - peer->getScreenY(),
  60814. getWidth(), getHeight());
  60815. }
  60816. }
  60817. }
  60818. bool OpenGLComponent::renderAndSwapBuffers()
  60819. {
  60820. const ScopedLock sl (contextLock);
  60821. if (! makeCurrentContextActive())
  60822. return false;
  60823. if (needToUpdateViewport)
  60824. {
  60825. needToUpdateViewport = false;
  60826. juce_glViewport (getWidth(), getHeight());
  60827. }
  60828. renderOpenGL();
  60829. swapBuffers();
  60830. return true;
  60831. }
  60832. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60833. {
  60834. Component::internalRepaint (x, y, w, h);
  60835. if (context != 0)
  60836. context->repaint();
  60837. }
  60838. END_JUCE_NAMESPACE
  60839. #endif
  60840. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60841. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60842. BEGIN_JUCE_NAMESPACE
  60843. PreferencesPanel::PreferencesPanel()
  60844. : buttonSize (70)
  60845. {
  60846. }
  60847. PreferencesPanel::~PreferencesPanel()
  60848. {
  60849. currentPage = 0;
  60850. deleteAllChildren();
  60851. }
  60852. void PreferencesPanel::addSettingsPage (const String& title,
  60853. const Drawable* icon,
  60854. const Drawable* overIcon,
  60855. const Drawable* downIcon)
  60856. {
  60857. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60858. button->setImages (icon, overIcon, downIcon);
  60859. button->setRadioGroupId (1);
  60860. button->addButtonListener (this);
  60861. button->setClickingTogglesState (true);
  60862. button->setWantsKeyboardFocus (false);
  60863. addAndMakeVisible (button);
  60864. resized();
  60865. if (currentPage == 0)
  60866. setCurrentPage (title);
  60867. }
  60868. void PreferencesPanel::addSettingsPage (const String& title,
  60869. const char* imageData,
  60870. const int imageDataSize)
  60871. {
  60872. DrawableImage icon, iconOver, iconDown;
  60873. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60874. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60875. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60876. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60877. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60878. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60879. }
  60880. class PrefsDialogWindow : public DialogWindow
  60881. {
  60882. public:
  60883. PrefsDialogWindow (const String& dialogtitle,
  60884. const Colour& backgroundColour)
  60885. : DialogWindow (dialogtitle, backgroundColour, true)
  60886. {
  60887. }
  60888. ~PrefsDialogWindow()
  60889. {
  60890. }
  60891. void closeButtonPressed()
  60892. {
  60893. exitModalState (0);
  60894. }
  60895. private:
  60896. PrefsDialogWindow (const PrefsDialogWindow&);
  60897. const PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60898. };
  60899. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60900. int dialogWidth,
  60901. int dialogHeight,
  60902. const Colour& backgroundColour)
  60903. {
  60904. setSize (dialogWidth, dialogHeight);
  60905. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60906. dw.setContentComponent (this, true, true);
  60907. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60908. dw.runModalLoop();
  60909. dw.setContentComponent (0, false, false);
  60910. }
  60911. void PreferencesPanel::resized()
  60912. {
  60913. int x = 0;
  60914. for (int i = 0; i < getNumChildComponents(); ++i)
  60915. {
  60916. Component* c = getChildComponent (i);
  60917. if (dynamic_cast <DrawableButton*> (c) == 0)
  60918. {
  60919. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60920. }
  60921. else
  60922. {
  60923. c->setBounds (x, 0, buttonSize, buttonSize);
  60924. x += buttonSize;
  60925. }
  60926. }
  60927. }
  60928. void PreferencesPanel::paint (Graphics& g)
  60929. {
  60930. g.setColour (Colours::grey);
  60931. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60932. }
  60933. void PreferencesPanel::setCurrentPage (const String& pageName)
  60934. {
  60935. if (currentPageName != pageName)
  60936. {
  60937. currentPageName = pageName;
  60938. currentPage = 0;
  60939. currentPage = createComponentForPage (pageName);
  60940. if (currentPage != 0)
  60941. {
  60942. addAndMakeVisible (currentPage);
  60943. currentPage->toBack();
  60944. resized();
  60945. }
  60946. for (int i = 0; i < getNumChildComponents(); ++i)
  60947. {
  60948. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60949. if (db != 0 && db->getName() == pageName)
  60950. {
  60951. db->setToggleState (true, false);
  60952. break;
  60953. }
  60954. }
  60955. }
  60956. }
  60957. void PreferencesPanel::buttonClicked (Button*)
  60958. {
  60959. for (int i = 0; i < getNumChildComponents(); ++i)
  60960. {
  60961. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60962. if (db != 0 && db->getToggleState())
  60963. {
  60964. setCurrentPage (db->getName());
  60965. break;
  60966. }
  60967. }
  60968. }
  60969. END_JUCE_NAMESPACE
  60970. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60971. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60972. #if JUCE_WINDOWS || JUCE_LINUX
  60973. BEGIN_JUCE_NAMESPACE
  60974. SystemTrayIconComponent::SystemTrayIconComponent()
  60975. {
  60976. addToDesktop (0);
  60977. }
  60978. SystemTrayIconComponent::~SystemTrayIconComponent()
  60979. {
  60980. }
  60981. END_JUCE_NAMESPACE
  60982. #endif
  60983. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60984. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60985. BEGIN_JUCE_NAMESPACE
  60986. static const int titleH = 24;
  60987. static const int iconWidth = 80;
  60988. class AlertWindowTextEditor : public TextEditor
  60989. {
  60990. public:
  60991. static const tchar passwordChar;
  60992. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60993. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60994. {
  60995. setSelectAllWhenFocused (true);
  60996. }
  60997. ~AlertWindowTextEditor()
  60998. {
  60999. }
  61000. void returnPressed()
  61001. {
  61002. // pass these up the component hierarchy to be trigger the buttons
  61003. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  61004. }
  61005. void escapePressed()
  61006. {
  61007. // pass these up the component hierarchy to be trigger the buttons
  61008. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  61009. }
  61010. private:
  61011. AlertWindowTextEditor (const AlertWindowTextEditor&);
  61012. const AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  61013. };
  61014. #if JUCE_LINUX
  61015. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  61016. #else
  61017. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  61018. #endif
  61019. AlertWindow::AlertWindow (const String& title,
  61020. const String& message,
  61021. AlertIconType iconType,
  61022. Component* associatedComponent_)
  61023. : TopLevelWindow (title, true),
  61024. alertIconType (iconType),
  61025. associatedComponent (associatedComponent_)
  61026. {
  61027. if (message.isEmpty())
  61028. text = T(" "); // to force an update if the message is empty
  61029. setMessage (message);
  61030. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  61031. {
  61032. Component* const c = Desktop::getInstance().getComponent (i);
  61033. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  61034. {
  61035. setAlwaysOnTop (true);
  61036. break;
  61037. }
  61038. }
  61039. if (JUCEApplication::getInstance() == 0)
  61040. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  61041. lookAndFeelChanged();
  61042. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  61043. }
  61044. AlertWindow::~AlertWindow()
  61045. {
  61046. for (int i = customComps.size(); --i >= 0;)
  61047. removeChildComponent ((Component*) customComps[i]);
  61048. deleteAllChildren();
  61049. }
  61050. void AlertWindow::userTriedToCloseWindow()
  61051. {
  61052. exitModalState (0);
  61053. }
  61054. void AlertWindow::setMessage (const String& message)
  61055. {
  61056. const String newMessage (message.substring (0, 2048));
  61057. if (text != newMessage)
  61058. {
  61059. text = newMessage;
  61060. font.setHeight (15.0f);
  61061. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  61062. textLayout.setText (getName() + T("\n\n"), titleFont);
  61063. textLayout.appendText (text, font);
  61064. updateLayout (true);
  61065. repaint();
  61066. }
  61067. }
  61068. void AlertWindow::buttonClicked (Button* button)
  61069. {
  61070. for (int i = 0; i < buttons.size(); i++)
  61071. {
  61072. TextButton* const c = (TextButton*) buttons[i];
  61073. if (button->getName() == c->getName())
  61074. {
  61075. if (c->getParentComponent() != 0)
  61076. c->getParentComponent()->exitModalState (c->getCommandID());
  61077. break;
  61078. }
  61079. }
  61080. }
  61081. void AlertWindow::addButton (const String& name,
  61082. const int returnValue,
  61083. const KeyPress& shortcutKey1,
  61084. const KeyPress& shortcutKey2)
  61085. {
  61086. TextButton* const b = new TextButton (name, String::empty);
  61087. b->setWantsKeyboardFocus (true);
  61088. b->setMouseClickGrabsKeyboardFocus (false);
  61089. b->setCommandToTrigger (0, returnValue, false);
  61090. b->addShortcut (shortcutKey1);
  61091. b->addShortcut (shortcutKey2);
  61092. b->addButtonListener (this);
  61093. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  61094. addAndMakeVisible (b, 0);
  61095. buttons.add (b);
  61096. updateLayout (false);
  61097. }
  61098. int AlertWindow::getNumButtons() const
  61099. {
  61100. return buttons.size();
  61101. }
  61102. void AlertWindow::addTextEditor (const String& name,
  61103. const String& initialContents,
  61104. const String& onScreenLabel,
  61105. const bool isPasswordBox)
  61106. {
  61107. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  61108. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  61109. tc->setFont (font);
  61110. tc->setText (initialContents);
  61111. tc->setCaretPosition (initialContents.length());
  61112. addAndMakeVisible (tc);
  61113. textBoxes.add (tc);
  61114. allComps.add (tc);
  61115. textboxNames.add (onScreenLabel);
  61116. updateLayout (false);
  61117. }
  61118. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  61119. {
  61120. for (int i = textBoxes.size(); --i >= 0;)
  61121. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  61122. return ((TextEditor*)textBoxes[i])->getText();
  61123. return String::empty;
  61124. }
  61125. void AlertWindow::addComboBox (const String& name,
  61126. const StringArray& items,
  61127. const String& onScreenLabel)
  61128. {
  61129. ComboBox* const cb = new ComboBox (name);
  61130. for (int i = 0; i < items.size(); ++i)
  61131. cb->addItem (items[i], i + 1);
  61132. addAndMakeVisible (cb);
  61133. cb->setSelectedItemIndex (0);
  61134. comboBoxes.add (cb);
  61135. allComps.add (cb);
  61136. comboBoxNames.add (onScreenLabel);
  61137. updateLayout (false);
  61138. }
  61139. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61140. {
  61141. for (int i = comboBoxes.size(); --i >= 0;)
  61142. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61143. return (ComboBox*) comboBoxes[i];
  61144. return 0;
  61145. }
  61146. class AlertTextComp : public TextEditor
  61147. {
  61148. AlertTextComp (const AlertTextComp&);
  61149. const AlertTextComp& operator= (const AlertTextComp&);
  61150. int bestWidth;
  61151. public:
  61152. AlertTextComp (const String& message,
  61153. const Font& font)
  61154. {
  61155. setReadOnly (true);
  61156. setMultiLine (true, true);
  61157. setCaretVisible (false);
  61158. setScrollbarsShown (true);
  61159. lookAndFeelChanged();
  61160. setWantsKeyboardFocus (false);
  61161. setFont (font);
  61162. setText (message, false);
  61163. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61164. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61165. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61166. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61167. }
  61168. ~AlertTextComp()
  61169. {
  61170. }
  61171. int getPreferredWidth() const throw() { return bestWidth; }
  61172. void updateLayout (const int width)
  61173. {
  61174. TextLayout text;
  61175. text.appendText (getText(), getFont());
  61176. text.layout (width - 8, Justification::topLeft, true);
  61177. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61178. }
  61179. };
  61180. void AlertWindow::addTextBlock (const String& text)
  61181. {
  61182. AlertTextComp* const c = new AlertTextComp (text, font);
  61183. textBlocks.add (c);
  61184. allComps.add (c);
  61185. addAndMakeVisible (c);
  61186. updateLayout (false);
  61187. }
  61188. void AlertWindow::addProgressBarComponent (double& progressValue)
  61189. {
  61190. ProgressBar* const pb = new ProgressBar (progressValue);
  61191. progressBars.add (pb);
  61192. allComps.add (pb);
  61193. addAndMakeVisible (pb);
  61194. updateLayout (false);
  61195. }
  61196. void AlertWindow::addCustomComponent (Component* const component)
  61197. {
  61198. customComps.add (component);
  61199. allComps.add (component);
  61200. addAndMakeVisible (component);
  61201. updateLayout (false);
  61202. }
  61203. int AlertWindow::getNumCustomComponents() const
  61204. {
  61205. return customComps.size();
  61206. }
  61207. Component* AlertWindow::getCustomComponent (const int index) const
  61208. {
  61209. return (Component*) customComps [index];
  61210. }
  61211. Component* AlertWindow::removeCustomComponent (const int index)
  61212. {
  61213. Component* const c = getCustomComponent (index);
  61214. if (c != 0)
  61215. {
  61216. customComps.removeValue (c);
  61217. allComps.removeValue (c);
  61218. removeChildComponent (c);
  61219. updateLayout (false);
  61220. }
  61221. return c;
  61222. }
  61223. void AlertWindow::paint (Graphics& g)
  61224. {
  61225. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61226. g.setColour (findColour (textColourId));
  61227. g.setFont (getLookAndFeel().getAlertWindowFont());
  61228. int i;
  61229. for (i = textBoxes.size(); --i >= 0;)
  61230. {
  61231. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61232. g.drawFittedText (textboxNames[i],
  61233. te->getX(), te->getY() - 14,
  61234. te->getWidth(), 14,
  61235. Justification::centredLeft, 1);
  61236. }
  61237. for (i = comboBoxNames.size(); --i >= 0;)
  61238. {
  61239. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61240. g.drawFittedText (comboBoxNames[i],
  61241. cb->getX(), cb->getY() - 14,
  61242. cb->getWidth(), 14,
  61243. Justification::centredLeft, 1);
  61244. }
  61245. for (i = customComps.size(); --i >= 0;)
  61246. {
  61247. const Component* const c = (Component*) customComps[i];
  61248. g.drawFittedText (c->getName(),
  61249. c->getX(), c->getY() - 14,
  61250. c->getWidth(), 14,
  61251. Justification::centredLeft, 1);
  61252. }
  61253. }
  61254. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61255. {
  61256. const int wid = jmax (font.getStringWidth (text),
  61257. font.getStringWidth (getName()));
  61258. const int sw = (int) sqrt (font.getHeight() * wid);
  61259. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61260. const int edgeGap = 10;
  61261. const int labelHeight = 18;
  61262. int iconSpace;
  61263. if (alertIconType == NoIcon)
  61264. {
  61265. textLayout.layout (w, Justification::horizontallyCentred, true);
  61266. iconSpace = 0;
  61267. }
  61268. else
  61269. {
  61270. textLayout.layout (w, Justification::left, true);
  61271. iconSpace = iconWidth;
  61272. }
  61273. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61274. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61275. const int textLayoutH = textLayout.getHeight();
  61276. const int textBottom = 16 + titleH + textLayoutH;
  61277. int h = textBottom;
  61278. int buttonW = 40;
  61279. int i;
  61280. for (i = 0; i < buttons.size(); ++i)
  61281. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61282. w = jmax (buttonW, w);
  61283. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61284. if (buttons.size() > 0)
  61285. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61286. for (i = customComps.size(); --i >= 0;)
  61287. {
  61288. Component* c = (Component*) customComps[i];
  61289. w = jmax (w, (c->getWidth() * 100) / 80);
  61290. h += 10 + c->getHeight();
  61291. if (c->getName().isNotEmpty())
  61292. h += labelHeight;
  61293. }
  61294. for (i = textBlocks.size(); --i >= 0;)
  61295. {
  61296. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61297. w = jmax (w, ac->getPreferredWidth());
  61298. }
  61299. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61300. for (i = textBlocks.size(); --i >= 0;)
  61301. {
  61302. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61303. ac->updateLayout ((int) (w * 0.8f));
  61304. h += ac->getHeight() + 10;
  61305. }
  61306. h = jmin (getParentHeight() - 50, h);
  61307. if (onlyIncreaseSize)
  61308. {
  61309. w = jmax (w, getWidth());
  61310. h = jmax (h, getHeight());
  61311. }
  61312. if (! isVisible())
  61313. {
  61314. centreAroundComponent (associatedComponent, w, h);
  61315. }
  61316. else
  61317. {
  61318. const int cx = getX() + getWidth() / 2;
  61319. const int cy = getY() + getHeight() / 2;
  61320. setBounds (cx - w / 2,
  61321. cy - h / 2,
  61322. w, h);
  61323. }
  61324. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61325. const int spacer = 16;
  61326. int totalWidth = -spacer;
  61327. for (i = buttons.size(); --i >= 0;)
  61328. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61329. int x = (w - totalWidth) / 2;
  61330. int y = (int) (getHeight() * 0.95f);
  61331. for (i = 0; i < buttons.size(); ++i)
  61332. {
  61333. TextButton* const c = (TextButton*) buttons[i];
  61334. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61335. c->setTopLeftPosition (x, ny);
  61336. if (ny < y)
  61337. y = ny;
  61338. x += c->getWidth() + spacer;
  61339. c->toFront (false);
  61340. }
  61341. y = textBottom;
  61342. for (i = 0; i < allComps.size(); ++i)
  61343. {
  61344. Component* const c = (Component*) allComps[i];
  61345. int h = 22;
  61346. const int comboIndex = comboBoxes.indexOf (c);
  61347. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61348. y += labelHeight;
  61349. const int tbIndex = textBoxes.indexOf (c);
  61350. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61351. y += labelHeight;
  61352. if (customComps.contains (c))
  61353. {
  61354. if (c->getName().isNotEmpty())
  61355. y += labelHeight;
  61356. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61357. h = c->getHeight();
  61358. }
  61359. else if (textBlocks.contains (c))
  61360. {
  61361. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61362. h = c->getHeight();
  61363. }
  61364. else
  61365. {
  61366. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61367. }
  61368. y += h + 10;
  61369. }
  61370. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61371. }
  61372. bool AlertWindow::containsAnyExtraComponents() const
  61373. {
  61374. return textBoxes.size()
  61375. + comboBoxes.size()
  61376. + progressBars.size()
  61377. + customComps.size() > 0;
  61378. }
  61379. void AlertWindow::mouseDown (const MouseEvent&)
  61380. {
  61381. dragger.startDraggingComponent (this, &constrainer);
  61382. }
  61383. void AlertWindow::mouseDrag (const MouseEvent& e)
  61384. {
  61385. dragger.dragComponent (this, e);
  61386. }
  61387. bool AlertWindow::keyPressed (const KeyPress& key)
  61388. {
  61389. for (int i = buttons.size(); --i >= 0;)
  61390. {
  61391. TextButton* const b = (TextButton*) buttons[i];
  61392. if (b->isRegisteredForShortcut (key))
  61393. {
  61394. b->triggerClick();
  61395. return true;
  61396. }
  61397. }
  61398. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61399. {
  61400. exitModalState (0);
  61401. return true;
  61402. }
  61403. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61404. {
  61405. ((TextButton*) buttons.getFirst())->triggerClick();
  61406. return true;
  61407. }
  61408. return false;
  61409. }
  61410. void AlertWindow::lookAndFeelChanged()
  61411. {
  61412. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61413. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61414. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61415. }
  61416. int AlertWindow::getDesktopWindowStyleFlags() const
  61417. {
  61418. return getLookAndFeel().getAlertBoxWindowFlags();
  61419. }
  61420. struct AlertWindowInfo
  61421. {
  61422. String title, message, button1, button2, button3;
  61423. AlertWindow::AlertIconType iconType;
  61424. int numButtons;
  61425. Component* associatedComponent;
  61426. int run() const
  61427. {
  61428. return (int) (pointer_sized_int)
  61429. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61430. }
  61431. private:
  61432. int show() const
  61433. {
  61434. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61435. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61436. : LookAndFeel::getDefaultLookAndFeel();
  61437. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61438. iconType, numButtons, associatedComponent));
  61439. jassert (alertBox != 0); // you have to return one of these!
  61440. return alertBox->runModalLoop();
  61441. }
  61442. static void* showCallback (void* userData)
  61443. {
  61444. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61445. }
  61446. };
  61447. void AlertWindow::showMessageBox (AlertIconType iconType,
  61448. const String& title,
  61449. const String& message,
  61450. const String& buttonText,
  61451. Component* associatedComponent)
  61452. {
  61453. AlertWindowInfo info;
  61454. info.title = title;
  61455. info.message = message;
  61456. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61457. info.iconType = iconType;
  61458. info.numButtons = 1;
  61459. info.associatedComponent = associatedComponent;
  61460. info.run();
  61461. }
  61462. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61463. const String& title,
  61464. const String& message,
  61465. const String& button1Text,
  61466. const String& button2Text,
  61467. Component* associatedComponent)
  61468. {
  61469. AlertWindowInfo info;
  61470. info.title = title;
  61471. info.message = message;
  61472. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61473. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61474. info.iconType = iconType;
  61475. info.numButtons = 2;
  61476. info.associatedComponent = associatedComponent;
  61477. return info.run() != 0;
  61478. }
  61479. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61480. const String& title,
  61481. const String& message,
  61482. const String& button1Text,
  61483. const String& button2Text,
  61484. const String& button3Text,
  61485. Component* associatedComponent)
  61486. {
  61487. AlertWindowInfo info;
  61488. info.title = title;
  61489. info.message = message;
  61490. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61491. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61492. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61493. info.iconType = iconType;
  61494. info.numButtons = 3;
  61495. info.associatedComponent = associatedComponent;
  61496. return info.run();
  61497. }
  61498. END_JUCE_NAMESPACE
  61499. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61500. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61501. BEGIN_JUCE_NAMESPACE
  61502. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61503. static const int fakeMouseMoveMessage = 0x7fff00ff;
  61504. static VoidArray heavyweightPeers;
  61505. ComponentPeer::ComponentPeer (Component* const component_,
  61506. const int styleFlags_) throw()
  61507. : component (component_),
  61508. styleFlags (styleFlags_),
  61509. lastPaintTime (0),
  61510. constrainer (0),
  61511. lastFocusedComponent (0),
  61512. lastDragAndDropCompUnderMouse (0),
  61513. fakeMouseMessageSent (false),
  61514. isWindowMinimised (false)
  61515. {
  61516. heavyweightPeers.add (this);
  61517. }
  61518. ComponentPeer::~ComponentPeer()
  61519. {
  61520. heavyweightPeers.removeValue (this);
  61521. Desktop::getInstance().triggerFocusCallback();
  61522. }
  61523. int ComponentPeer::getNumPeers() throw()
  61524. {
  61525. return heavyweightPeers.size();
  61526. }
  61527. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61528. {
  61529. return (ComponentPeer*) heavyweightPeers [index];
  61530. }
  61531. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61532. {
  61533. for (int i = heavyweightPeers.size(); --i >= 0;)
  61534. {
  61535. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61536. if (peer->getComponent() == component)
  61537. return peer;
  61538. }
  61539. return 0;
  61540. }
  61541. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61542. {
  61543. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61544. }
  61545. void ComponentPeer::updateCurrentModifiers() throw()
  61546. {
  61547. ModifierKeys::updateCurrentModifiers();
  61548. }
  61549. void ComponentPeer::handleMouseEnter (int x, int y, const int64 time)
  61550. {
  61551. jassert (component->isValidComponent());
  61552. updateCurrentModifiers();
  61553. Component* c = component->getComponentAt (x, y);
  61554. const ComponentDeletionWatcher deletionChecker (component);
  61555. if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0)
  61556. {
  61557. jassert (Component::componentUnderMouse->isValidComponent());
  61558. const int oldX = x;
  61559. const int oldY = y;
  61560. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61561. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61562. Component::componentUnderMouse = 0;
  61563. if (deletionChecker.hasBeenDeleted())
  61564. return;
  61565. c = component->getComponentAt (oldX, oldY);
  61566. }
  61567. Component::componentUnderMouse = c;
  61568. if (Component::componentUnderMouse != 0)
  61569. {
  61570. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61571. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61572. }
  61573. }
  61574. void ComponentPeer::handleMouseMove (int x, int y, const int64 time)
  61575. {
  61576. jassert (component->isValidComponent());
  61577. updateCurrentModifiers();
  61578. fakeMouseMessageSent = false;
  61579. const ComponentDeletionWatcher deletionChecker (component);
  61580. Component* c = component->getComponentAt (x, y);
  61581. if (c != Component::componentUnderMouse)
  61582. {
  61583. const int oldX = x;
  61584. const int oldY = y;
  61585. if (Component::componentUnderMouse != 0)
  61586. {
  61587. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61588. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61589. x = oldX;
  61590. y = oldY;
  61591. Component::componentUnderMouse = 0;
  61592. if (deletionChecker.hasBeenDeleted())
  61593. return; // if this window has just been deleted..
  61594. c = component->getComponentAt (x, y);
  61595. }
  61596. Component::componentUnderMouse = c;
  61597. if (c != 0)
  61598. {
  61599. component->relativePositionToOtherComponent (c, x, y);
  61600. c->internalMouseEnter (x, y, time);
  61601. x = oldX;
  61602. y = oldY;
  61603. if (deletionChecker.hasBeenDeleted())
  61604. return; // if this window has just been deleted..
  61605. }
  61606. }
  61607. if (Component::componentUnderMouse != 0)
  61608. {
  61609. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61610. Component::componentUnderMouse->internalMouseMove (x, y, time);
  61611. }
  61612. }
  61613. void ComponentPeer::handleMouseDown (int x, int y, const int64 time)
  61614. {
  61615. Desktop::getInstance().incrementMouseClickCounter();
  61616. updateCurrentModifiers();
  61617. if (ModifierKeys::getCurrentModifiers().getNumMouseButtonsDown() == 1)
  61618. {
  61619. Component::componentUnderMouse = component->getComponentAt (x, y);
  61620. if (Component::componentUnderMouse != 0)
  61621. {
  61622. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61623. Component::componentUnderMouse->internalMouseDown (x, y, time);
  61624. }
  61625. }
  61626. }
  61627. void ComponentPeer::handleMouseDrag (int x, int y, const int64 time)
  61628. {
  61629. updateCurrentModifiers();
  61630. if (Component::componentUnderMouse != 0)
  61631. {
  61632. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61633. Component::componentUnderMouse->internalMouseDrag (x, y, time);
  61634. }
  61635. }
  61636. void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time)
  61637. {
  61638. updateCurrentModifiers();
  61639. if (ModifierKeys (oldModifiers).getNumMouseButtonsDown() == 1)
  61640. {
  61641. const ComponentDeletionWatcher deletionChecker (component);
  61642. Component* c = component->getComponentAt (x, y);
  61643. if (c != Component::componentUnderMouse)
  61644. {
  61645. const int oldX = x;
  61646. const int oldY = y;
  61647. if (Component::componentUnderMouse != 0)
  61648. {
  61649. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61650. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61651. x = oldX;
  61652. y = oldY;
  61653. if (Component::componentUnderMouse != 0)
  61654. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61655. if (deletionChecker.hasBeenDeleted())
  61656. return;
  61657. c = component->getComponentAt (oldX, oldY);
  61658. }
  61659. Component::componentUnderMouse = c;
  61660. if (Component::componentUnderMouse != 0)
  61661. {
  61662. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61663. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61664. }
  61665. }
  61666. else
  61667. {
  61668. if (Component::componentUnderMouse != 0)
  61669. {
  61670. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61671. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61672. }
  61673. }
  61674. }
  61675. }
  61676. void ComponentPeer::handleMouseExit (int x, int y, const int64 time)
  61677. {
  61678. jassert (component->isValidComponent());
  61679. updateCurrentModifiers();
  61680. if (Component::componentUnderMouse != 0)
  61681. {
  61682. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61683. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61684. Component::componentUnderMouse = 0;
  61685. }
  61686. }
  61687. void ComponentPeer::handleMouseWheel (const int amountX, const int amountY, const int64 time)
  61688. {
  61689. updateCurrentModifiers();
  61690. if (Component::componentUnderMouse != 0)
  61691. Component::componentUnderMouse->internalMouseWheel (amountX, amountY, time);
  61692. }
  61693. void ComponentPeer::sendFakeMouseMove() throw()
  61694. {
  61695. if ((! fakeMouseMessageSent)
  61696. && component->flags.hasHeavyweightPeerFlag
  61697. && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61698. {
  61699. if (! isMinimised())
  61700. {
  61701. int realX, realY, realW, realH;
  61702. getBounds (realX, realY, realW, realH);
  61703. component->bounds_.setBounds (realX, realY, realW, realH);
  61704. }
  61705. int x, y;
  61706. component->getMouseXYRelative (x, y);
  61707. if (((unsigned int) x) < (unsigned int) component->getWidth()
  61708. && ((unsigned int) y) < (unsigned int) component->getHeight()
  61709. && contains (x, y, false))
  61710. {
  61711. postMessage (new Message (fakeMouseMoveMessage, x, y, 0));
  61712. }
  61713. fakeMouseMessageSent = true;
  61714. }
  61715. }
  61716. void ComponentPeer::handleMessage (const Message& message)
  61717. {
  61718. if (message.intParameter1 == fakeMouseMoveMessage)
  61719. {
  61720. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61721. handleMouseMove (message.intParameter2,
  61722. message.intParameter3,
  61723. Time::currentTimeMillis());
  61724. }
  61725. }
  61726. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61727. {
  61728. Graphics g (&contextToPaintTo);
  61729. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61730. g.saveState();
  61731. #endif
  61732. JUCE_TRY
  61733. {
  61734. component->paintEntireComponent (g);
  61735. }
  61736. JUCE_CATCH_EXCEPTION
  61737. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61738. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61739. // clearly when things are being repainted.
  61740. {
  61741. g.restoreState();
  61742. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61743. (uint8) Random::getSystemRandom().nextInt (255),
  61744. (uint8) Random::getSystemRandom().nextInt (255),
  61745. (uint8) 0x50));
  61746. }
  61747. #endif
  61748. }
  61749. bool ComponentPeer::handleKeyPress (const int keyCode,
  61750. const juce_wchar textCharacter)
  61751. {
  61752. updateCurrentModifiers();
  61753. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61754. ? Component::currentlyFocusedComponent
  61755. : component;
  61756. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61757. {
  61758. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61759. if (currentModalComp != 0)
  61760. target = currentModalComp;
  61761. }
  61762. const KeyPress keyInfo (keyCode,
  61763. ModifierKeys::getCurrentModifiers().getRawFlags()
  61764. & ModifierKeys::allKeyboardModifiers,
  61765. textCharacter);
  61766. bool keyWasUsed = false;
  61767. while (target != 0)
  61768. {
  61769. const ComponentDeletionWatcher deletionChecker (target);
  61770. if (target->keyListeners_ != 0)
  61771. {
  61772. for (int i = target->keyListeners_->size(); --i >= 0;)
  61773. {
  61774. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61775. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61776. return keyWasUsed;
  61777. i = jmin (i, target->keyListeners_->size());
  61778. }
  61779. }
  61780. keyWasUsed = target->keyPressed (keyInfo);
  61781. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61782. break;
  61783. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61784. {
  61785. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61786. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61787. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61788. break;
  61789. }
  61790. target = target->parentComponent_;
  61791. }
  61792. return keyWasUsed;
  61793. }
  61794. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61795. {
  61796. updateCurrentModifiers();
  61797. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61798. ? Component::currentlyFocusedComponent
  61799. : component;
  61800. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61801. {
  61802. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61803. if (currentModalComp != 0)
  61804. target = currentModalComp;
  61805. }
  61806. bool keyWasUsed = false;
  61807. while (target != 0)
  61808. {
  61809. const ComponentDeletionWatcher deletionChecker (target);
  61810. keyWasUsed = target->keyStateChanged (isKeyDown);
  61811. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61812. break;
  61813. if (target->keyListeners_ != 0)
  61814. {
  61815. for (int i = target->keyListeners_->size(); --i >= 0;)
  61816. {
  61817. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61818. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61819. return keyWasUsed;
  61820. i = jmin (i, target->keyListeners_->size());
  61821. }
  61822. }
  61823. target = target->parentComponent_;
  61824. }
  61825. return keyWasUsed;
  61826. }
  61827. void ComponentPeer::handleModifierKeysChange()
  61828. {
  61829. updateCurrentModifiers();
  61830. Component* target = Component::getComponentUnderMouse();
  61831. if (target == 0)
  61832. target = Component::getCurrentlyFocusedComponent();
  61833. if (target == 0)
  61834. target = component;
  61835. if (target->isValidComponent())
  61836. target->internalModifierKeysChanged();
  61837. }
  61838. void ComponentPeer::handleBroughtToFront()
  61839. {
  61840. updateCurrentModifiers();
  61841. if (component != 0)
  61842. component->internalBroughtToFront();
  61843. }
  61844. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61845. {
  61846. constrainer = newConstrainer;
  61847. }
  61848. void ComponentPeer::handleMovedOrResized()
  61849. {
  61850. jassert (component->isValidComponent());
  61851. updateCurrentModifiers();
  61852. const bool nowMinimised = isMinimised();
  61853. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61854. {
  61855. const ComponentDeletionWatcher deletionChecker (component);
  61856. int realX, realY, realW, realH;
  61857. getBounds (realX, realY, realW, realH);
  61858. const bool wasMoved = (component->getX() != realX || component->getY() != realY);
  61859. const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH);
  61860. if (wasMoved || wasResized)
  61861. {
  61862. component->bounds_.setBounds (realX, realY, realW, realH);
  61863. if (wasResized)
  61864. component->repaint();
  61865. component->sendMovedResizedMessages (wasMoved, wasResized);
  61866. if (deletionChecker.hasBeenDeleted())
  61867. return;
  61868. }
  61869. }
  61870. if (isWindowMinimised != nowMinimised)
  61871. {
  61872. isWindowMinimised = nowMinimised;
  61873. component->minimisationStateChanged (nowMinimised);
  61874. component->sendVisibilityChangeMessage();
  61875. }
  61876. if (! isFullScreen())
  61877. lastNonFullscreenBounds = component->getBounds();
  61878. }
  61879. void ComponentPeer::handleFocusGain()
  61880. {
  61881. updateCurrentModifiers();
  61882. if (component->isParentOf (lastFocusedComponent))
  61883. {
  61884. Component::currentlyFocusedComponent = lastFocusedComponent;
  61885. Desktop::getInstance().triggerFocusCallback();
  61886. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61887. }
  61888. else
  61889. {
  61890. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61891. component->grabKeyboardFocus();
  61892. else
  61893. Component::bringModalComponentToFront();
  61894. }
  61895. }
  61896. void ComponentPeer::handleFocusLoss()
  61897. {
  61898. updateCurrentModifiers();
  61899. if (component->hasKeyboardFocus (true))
  61900. {
  61901. lastFocusedComponent = Component::currentlyFocusedComponent;
  61902. if (lastFocusedComponent != 0)
  61903. {
  61904. Component::currentlyFocusedComponent = 0;
  61905. Desktop::getInstance().triggerFocusCallback();
  61906. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61907. }
  61908. }
  61909. }
  61910. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61911. {
  61912. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61913. ? lastFocusedComponent
  61914. : component;
  61915. }
  61916. void ComponentPeer::handleScreenSizeChange()
  61917. {
  61918. updateCurrentModifiers();
  61919. component->parentSizeChanged();
  61920. handleMovedOrResized();
  61921. }
  61922. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61923. {
  61924. lastNonFullscreenBounds = newBounds;
  61925. }
  61926. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61927. {
  61928. return lastNonFullscreenBounds;
  61929. }
  61930. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61931. const StringArray& files,
  61932. FileDragAndDropTarget* const lastOne)
  61933. {
  61934. while (c != 0)
  61935. {
  61936. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61937. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61938. return t;
  61939. c = c->getParentComponent();
  61940. }
  61941. return 0;
  61942. }
  61943. void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y)
  61944. {
  61945. updateCurrentModifiers();
  61946. FileDragAndDropTarget* lastTarget = 0;
  61947. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61948. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61949. FileDragAndDropTarget* newTarget = 0;
  61950. Component* const compUnderMouse = component->getComponentAt (x, y);
  61951. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61952. {
  61953. lastDragAndDropCompUnderMouse = compUnderMouse;
  61954. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61955. if (newTarget != lastTarget)
  61956. {
  61957. if (lastTarget != 0)
  61958. lastTarget->fileDragExit (files);
  61959. dragAndDropTargetComponent = 0;
  61960. if (newTarget != 0)
  61961. {
  61962. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61963. int mx = x, my = y;
  61964. component->relativePositionToOtherComponent (targetComp, mx, my);
  61965. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  61966. newTarget->fileDragEnter (files, mx, my);
  61967. }
  61968. }
  61969. }
  61970. else
  61971. {
  61972. newTarget = lastTarget;
  61973. }
  61974. if (newTarget != 0)
  61975. {
  61976. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61977. component->relativePositionToOtherComponent (targetComp, x, y);
  61978. newTarget->fileDragMove (files, x, y);
  61979. }
  61980. }
  61981. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61982. {
  61983. handleFileDragMove (files, -1, -1);
  61984. jassert (dragAndDropTargetComponent == 0);
  61985. lastDragAndDropCompUnderMouse = 0;
  61986. }
  61987. void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y)
  61988. {
  61989. handleFileDragMove (files, x, y);
  61990. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61991. {
  61992. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61993. dragAndDropTargetComponent = 0;
  61994. lastDragAndDropCompUnderMouse = 0;
  61995. if (target != 0)
  61996. {
  61997. Component* const targetComp = dynamic_cast <Component*> (target);
  61998. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61999. {
  62000. targetComp->internalModalInputAttempt();
  62001. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62002. return;
  62003. }
  62004. component->relativePositionToOtherComponent (targetComp, x, y);
  62005. target->filesDropped (files, x, y);
  62006. }
  62007. }
  62008. }
  62009. void ComponentPeer::handleUserClosingWindow()
  62010. {
  62011. updateCurrentModifiers();
  62012. component->userTriedToCloseWindow();
  62013. }
  62014. void ComponentPeer::bringModalComponentToFront()
  62015. {
  62016. Component::bringModalComponentToFront();
  62017. }
  62018. void ComponentPeer::clearMaskedRegion() throw()
  62019. {
  62020. maskedRegion.clear();
  62021. }
  62022. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  62023. {
  62024. maskedRegion.add (x, y, w, h);
  62025. }
  62026. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  62027. {
  62028. StringArray s;
  62029. s.add ("Software Renderer");
  62030. return s;
  62031. }
  62032. int ComponentPeer::getCurrentRenderingEngine() throw()
  62033. {
  62034. return 0;
  62035. }
  62036. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  62037. {
  62038. }
  62039. END_JUCE_NAMESPACE
  62040. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  62041. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  62042. BEGIN_JUCE_NAMESPACE
  62043. DialogWindow::DialogWindow (const String& name,
  62044. const Colour& backgroundColour_,
  62045. const bool escapeKeyTriggersCloseButton_,
  62046. const bool addToDesktop_)
  62047. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  62048. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  62049. {
  62050. }
  62051. DialogWindow::~DialogWindow()
  62052. {
  62053. }
  62054. void DialogWindow::resized()
  62055. {
  62056. DocumentWindow::resized();
  62057. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  62058. if (escapeKeyTriggersCloseButton
  62059. && getCloseButton() != 0
  62060. && ! getCloseButton()->isRegisteredForShortcut (esc))
  62061. {
  62062. getCloseButton()->addShortcut (esc);
  62063. }
  62064. }
  62065. class TempDialogWindow : public DialogWindow
  62066. {
  62067. public:
  62068. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  62069. : DialogWindow (title, colour, escapeCloses, true)
  62070. {
  62071. }
  62072. ~TempDialogWindow()
  62073. {
  62074. }
  62075. void closeButtonPressed()
  62076. {
  62077. setVisible (false);
  62078. }
  62079. private:
  62080. TempDialogWindow (const TempDialogWindow&);
  62081. const TempDialogWindow& operator= (const TempDialogWindow&);
  62082. };
  62083. int DialogWindow::showModalDialog (const String& dialogTitle,
  62084. Component* contentComponent,
  62085. Component* componentToCentreAround,
  62086. const Colour& colour,
  62087. const bool escapeKeyTriggersCloseButton,
  62088. const bool shouldBeResizable,
  62089. const bool useBottomRightCornerResizer)
  62090. {
  62091. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62092. dw.setContentComponent (contentComponent, true, true);
  62093. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62094. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62095. const int result = dw.runModalLoop();
  62096. dw.setContentComponent (0, false);
  62097. return result;
  62098. }
  62099. END_JUCE_NAMESPACE
  62100. /*** End of inlined file: juce_DialogWindow.cpp ***/
  62101. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  62102. BEGIN_JUCE_NAMESPACE
  62103. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  62104. {
  62105. public:
  62106. ButtonListenerProxy (DocumentWindow& owner_)
  62107. : owner (owner_)
  62108. {
  62109. }
  62110. void buttonClicked (Button* button)
  62111. {
  62112. if (button == owner.getMinimiseButton())
  62113. owner.minimiseButtonPressed();
  62114. else if (button == owner.getMaximiseButton())
  62115. owner.maximiseButtonPressed();
  62116. else if (button == owner.getCloseButton())
  62117. owner.closeButtonPressed();
  62118. }
  62119. juce_UseDebuggingNewOperator
  62120. private:
  62121. DocumentWindow& owner;
  62122. ButtonListenerProxy (const ButtonListenerProxy&);
  62123. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  62124. };
  62125. DocumentWindow::DocumentWindow (const String& title,
  62126. const Colour& backgroundColour,
  62127. const int requiredButtons_,
  62128. const bool addToDesktop_)
  62129. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62130. titleBarHeight (26),
  62131. menuBarHeight (24),
  62132. requiredButtons (requiredButtons_),
  62133. #if JUCE_MAC
  62134. positionTitleBarButtonsOnLeft (true),
  62135. #else
  62136. positionTitleBarButtonsOnLeft (false),
  62137. #endif
  62138. drawTitleTextCentred (true),
  62139. menuBarModel (0)
  62140. {
  62141. setResizeLimits (128, 128, 32768, 32768);
  62142. lookAndFeelChanged();
  62143. }
  62144. DocumentWindow::~DocumentWindow()
  62145. {
  62146. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62147. titleBarButtons[i] = 0;
  62148. menuBar = 0;
  62149. }
  62150. void DocumentWindow::repaintTitleBar()
  62151. {
  62152. const Rectangle<int> titleBarArea (getTitleBarArea());
  62153. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62154. titleBarArea.getWidth(), titleBarArea.getHeight());
  62155. }
  62156. void DocumentWindow::setName (const String& newName)
  62157. {
  62158. if (newName != getName())
  62159. {
  62160. Component::setName (newName);
  62161. repaintTitleBar();
  62162. }
  62163. }
  62164. void DocumentWindow::setIcon (const Image* imageToUse)
  62165. {
  62166. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62167. repaintTitleBar();
  62168. }
  62169. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62170. {
  62171. titleBarHeight = newHeight;
  62172. resized();
  62173. repaintTitleBar();
  62174. }
  62175. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62176. const bool positionTitleBarButtonsOnLeft_)
  62177. {
  62178. requiredButtons = requiredButtons_;
  62179. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62180. lookAndFeelChanged();
  62181. }
  62182. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62183. {
  62184. drawTitleTextCentred = textShouldBeCentred;
  62185. repaintTitleBar();
  62186. }
  62187. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62188. const int menuBarHeight_)
  62189. {
  62190. if (menuBarModel != menuBarModel_)
  62191. {
  62192. menuBar = 0;
  62193. menuBarModel = menuBarModel_;
  62194. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62195. : getLookAndFeel().getDefaultMenuBarHeight();
  62196. if (menuBarModel != 0)
  62197. {
  62198. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62199. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62200. menuBar->setEnabled (isActiveWindow());
  62201. }
  62202. resized();
  62203. }
  62204. }
  62205. void DocumentWindow::closeButtonPressed()
  62206. {
  62207. /* If you've got a close button, you have to override this method to get
  62208. rid of your window!
  62209. If the window is just a pop-up, you should override this method and make
  62210. it delete the window in whatever way is appropriate for your app. E.g. you
  62211. might just want to call "delete this".
  62212. If your app is centred around this window such that the whole app should quit when
  62213. the window is closed, then you will probably want to use this method as an opportunity
  62214. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62215. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62216. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62217. or closing it via the taskbar icon on Windows).
  62218. */
  62219. jassertfalse
  62220. }
  62221. void DocumentWindow::minimiseButtonPressed()
  62222. {
  62223. setMinimised (true);
  62224. }
  62225. void DocumentWindow::maximiseButtonPressed()
  62226. {
  62227. setFullScreen (! isFullScreen());
  62228. }
  62229. void DocumentWindow::paint (Graphics& g)
  62230. {
  62231. ResizableWindow::paint (g);
  62232. if (resizableBorder == 0)
  62233. {
  62234. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62235. const BorderSize border (getBorderThickness());
  62236. g.fillRect (0, 0, getWidth(), border.getTop());
  62237. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62238. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62239. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62240. }
  62241. const Rectangle<int> titleBarArea (getTitleBarArea());
  62242. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62243. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62244. int titleSpaceX1 = 6;
  62245. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62246. for (int i = 0; i < 3; ++i)
  62247. {
  62248. if (titleBarButtons[i] != 0)
  62249. {
  62250. if (positionTitleBarButtonsOnLeft)
  62251. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62252. else
  62253. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62254. }
  62255. }
  62256. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62257. titleBarArea.getWidth(),
  62258. titleBarArea.getHeight(),
  62259. titleSpaceX1,
  62260. jmax (1, titleSpaceX2 - titleSpaceX1),
  62261. titleBarIcon,
  62262. ! drawTitleTextCentred);
  62263. }
  62264. void DocumentWindow::resized()
  62265. {
  62266. ResizableWindow::resized();
  62267. if (titleBarButtons[1] != 0)
  62268. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62269. const Rectangle<int> titleBarArea (getTitleBarArea());
  62270. getLookAndFeel()
  62271. .positionDocumentWindowButtons (*this,
  62272. titleBarArea.getX(), titleBarArea.getY(),
  62273. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62274. titleBarButtons[0],
  62275. titleBarButtons[1],
  62276. titleBarButtons[2],
  62277. positionTitleBarButtonsOnLeft);
  62278. if (menuBar != 0)
  62279. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62280. titleBarArea.getWidth(), menuBarHeight);
  62281. }
  62282. const BorderSize DocumentWindow::getBorderThickness()
  62283. {
  62284. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62285. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62286. }
  62287. const BorderSize DocumentWindow::getContentComponentBorder()
  62288. {
  62289. BorderSize border (getBorderThickness());
  62290. border.setTop (border.getTop()
  62291. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62292. + (menuBar != 0 ? menuBarHeight : 0));
  62293. return border;
  62294. }
  62295. int DocumentWindow::getTitleBarHeight() const
  62296. {
  62297. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62298. }
  62299. const Rectangle<int> DocumentWindow::getTitleBarArea()
  62300. {
  62301. const BorderSize border (getBorderThickness());
  62302. return Rectangle<int> (border.getLeft(), border.getTop(),
  62303. getWidth() - border.getLeftAndRight(),
  62304. getTitleBarHeight());
  62305. }
  62306. Button* DocumentWindow::getCloseButton() const throw()
  62307. {
  62308. return titleBarButtons[2];
  62309. }
  62310. Button* DocumentWindow::getMinimiseButton() const throw()
  62311. {
  62312. return titleBarButtons[0];
  62313. }
  62314. Button* DocumentWindow::getMaximiseButton() const throw()
  62315. {
  62316. return titleBarButtons[1];
  62317. }
  62318. int DocumentWindow::getDesktopWindowStyleFlags() const
  62319. {
  62320. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62321. if ((requiredButtons & minimiseButton) != 0)
  62322. flags |= ComponentPeer::windowHasMinimiseButton;
  62323. if ((requiredButtons & maximiseButton) != 0)
  62324. flags |= ComponentPeer::windowHasMaximiseButton;
  62325. if ((requiredButtons & closeButton) != 0)
  62326. flags |= ComponentPeer::windowHasCloseButton;
  62327. return flags;
  62328. }
  62329. void DocumentWindow::lookAndFeelChanged()
  62330. {
  62331. int i;
  62332. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62333. titleBarButtons[i] = 0;
  62334. if (! isUsingNativeTitleBar())
  62335. {
  62336. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62337. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62338. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62339. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62340. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62341. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62342. for (i = 0; i < 3; ++i)
  62343. {
  62344. if (titleBarButtons[i] != 0)
  62345. {
  62346. if (buttonListener == 0)
  62347. buttonListener = new ButtonListenerProxy (*this);
  62348. titleBarButtons[i]->addButtonListener (buttonListener);
  62349. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62350. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62351. Component::addAndMakeVisible (titleBarButtons[i]);
  62352. }
  62353. }
  62354. if (getCloseButton() != 0)
  62355. {
  62356. #if JUCE_MAC
  62357. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62358. #else
  62359. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62360. #endif
  62361. }
  62362. }
  62363. activeWindowStatusChanged();
  62364. ResizableWindow::lookAndFeelChanged();
  62365. }
  62366. void DocumentWindow::parentHierarchyChanged()
  62367. {
  62368. lookAndFeelChanged();
  62369. }
  62370. void DocumentWindow::activeWindowStatusChanged()
  62371. {
  62372. ResizableWindow::activeWindowStatusChanged();
  62373. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62374. if (titleBarButtons[i] != 0)
  62375. titleBarButtons[i]->setEnabled (isActiveWindow());
  62376. if (menuBar != 0)
  62377. menuBar->setEnabled (isActiveWindow());
  62378. }
  62379. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62380. {
  62381. if (getTitleBarArea().contains (e.x, e.y)
  62382. && getMaximiseButton() != 0)
  62383. {
  62384. getMaximiseButton()->triggerClick();
  62385. }
  62386. }
  62387. void DocumentWindow::userTriedToCloseWindow()
  62388. {
  62389. closeButtonPressed();
  62390. }
  62391. END_JUCE_NAMESPACE
  62392. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62393. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62394. BEGIN_JUCE_NAMESPACE
  62395. ResizableWindow::ResizableWindow (const String& name,
  62396. const bool addToDesktop_)
  62397. : TopLevelWindow (name, addToDesktop_),
  62398. resizeToFitContent (false),
  62399. fullscreen (false),
  62400. lastNonFullScreenPos (50, 50, 256, 256),
  62401. constrainer (0)
  62402. #ifdef JUCE_DEBUG
  62403. , hasBeenResized (false)
  62404. #endif
  62405. {
  62406. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62407. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62408. if (addToDesktop_)
  62409. Component::addToDesktop (getDesktopWindowStyleFlags());
  62410. }
  62411. ResizableWindow::ResizableWindow (const String& name,
  62412. const Colour& backgroundColour_,
  62413. const bool addToDesktop_)
  62414. : TopLevelWindow (name, addToDesktop_),
  62415. resizeToFitContent (false),
  62416. fullscreen (false),
  62417. lastNonFullScreenPos (50, 50, 256, 256),
  62418. constrainer (0)
  62419. #ifdef JUCE_DEBUG
  62420. , hasBeenResized (false)
  62421. #endif
  62422. {
  62423. setBackgroundColour (backgroundColour_);
  62424. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62425. if (addToDesktop_)
  62426. Component::addToDesktop (getDesktopWindowStyleFlags());
  62427. }
  62428. ResizableWindow::~ResizableWindow()
  62429. {
  62430. resizableCorner = 0;
  62431. resizableBorder = 0;
  62432. contentComponent = 0;
  62433. // have you been adding your own components directly to this window..? tut tut tut.
  62434. // Read the instructions for using a ResizableWindow!
  62435. jassert (getNumChildComponents() == 0);
  62436. }
  62437. int ResizableWindow::getDesktopWindowStyleFlags() const
  62438. {
  62439. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62440. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62441. flags |= ComponentPeer::windowIsResizable;
  62442. return flags;
  62443. }
  62444. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62445. const bool deleteOldOne,
  62446. const bool resizeToFit)
  62447. {
  62448. resizeToFitContent = resizeToFit;
  62449. if (newContentComponent != (Component*) contentComponent)
  62450. {
  62451. if (! deleteOldOne)
  62452. removeChildComponent (contentComponent.release());
  62453. contentComponent = newContentComponent;
  62454. Component::addAndMakeVisible (contentComponent);
  62455. }
  62456. if (resizeToFit)
  62457. childBoundsChanged (contentComponent);
  62458. resized(); // must always be called to position the new content comp
  62459. }
  62460. void ResizableWindow::setContentComponentSize (int width, int height)
  62461. {
  62462. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62463. const BorderSize border (getContentComponentBorder());
  62464. setSize (width + border.getLeftAndRight(),
  62465. height + border.getTopAndBottom());
  62466. }
  62467. const BorderSize ResizableWindow::getBorderThickness()
  62468. {
  62469. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62470. }
  62471. const BorderSize ResizableWindow::getContentComponentBorder()
  62472. {
  62473. return getBorderThickness();
  62474. }
  62475. void ResizableWindow::moved()
  62476. {
  62477. updateLastPos();
  62478. }
  62479. void ResizableWindow::visibilityChanged()
  62480. {
  62481. TopLevelWindow::visibilityChanged();
  62482. updateLastPos();
  62483. }
  62484. void ResizableWindow::resized()
  62485. {
  62486. if (resizableBorder != 0)
  62487. {
  62488. resizableBorder->setVisible (! isFullScreen());
  62489. resizableBorder->setBorderThickness (getBorderThickness());
  62490. resizableBorder->setSize (getWidth(), getHeight());
  62491. resizableBorder->toBack();
  62492. }
  62493. if (resizableCorner != 0)
  62494. {
  62495. resizableCorner->setVisible (! isFullScreen());
  62496. const int resizerSize = 18;
  62497. resizableCorner->setBounds (getWidth() - resizerSize,
  62498. getHeight() - resizerSize,
  62499. resizerSize, resizerSize);
  62500. }
  62501. if (contentComponent != 0)
  62502. contentComponent->setBoundsInset (getContentComponentBorder());
  62503. updateLastPos();
  62504. #ifdef JUCE_DEBUG
  62505. hasBeenResized = true;
  62506. #endif
  62507. }
  62508. void ResizableWindow::childBoundsChanged (Component* child)
  62509. {
  62510. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62511. {
  62512. // not going to look very good if this component has a zero size..
  62513. jassert (child->getWidth() > 0);
  62514. jassert (child->getHeight() > 0);
  62515. const BorderSize borders (getContentComponentBorder());
  62516. setSize (child->getWidth() + borders.getLeftAndRight(),
  62517. child->getHeight() + borders.getTopAndBottom());
  62518. }
  62519. }
  62520. void ResizableWindow::activeWindowStatusChanged()
  62521. {
  62522. const BorderSize borders (getContentComponentBorder());
  62523. repaint (0, 0, getWidth(), borders.getTop());
  62524. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62525. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62526. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62527. }
  62528. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62529. const bool useBottomRightCornerResizer)
  62530. {
  62531. if (shouldBeResizable)
  62532. {
  62533. if (useBottomRightCornerResizer)
  62534. {
  62535. resizableBorder = 0;
  62536. if (resizableCorner == 0)
  62537. {
  62538. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62539. resizableCorner->setAlwaysOnTop (true);
  62540. }
  62541. }
  62542. else
  62543. {
  62544. resizableCorner = 0;
  62545. if (resizableBorder == 0)
  62546. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62547. }
  62548. }
  62549. else
  62550. {
  62551. resizableCorner = 0;
  62552. resizableBorder = 0;
  62553. }
  62554. if (isUsingNativeTitleBar())
  62555. recreateDesktopWindow();
  62556. childBoundsChanged (contentComponent);
  62557. resized();
  62558. }
  62559. bool ResizableWindow::isResizable() const throw()
  62560. {
  62561. return resizableCorner != 0
  62562. || resizableBorder != 0;
  62563. }
  62564. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62565. const int newMinimumHeight,
  62566. const int newMaximumWidth,
  62567. const int newMaximumHeight) throw()
  62568. {
  62569. // if you've set up a custom constrainer then these settings won't have any effect..
  62570. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62571. if (constrainer == 0)
  62572. setConstrainer (&defaultConstrainer);
  62573. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62574. newMaximumWidth, newMaximumHeight);
  62575. setBoundsConstrained (getX(), getY(), getWidth(), getHeight());
  62576. }
  62577. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62578. {
  62579. if (constrainer != newConstrainer)
  62580. {
  62581. constrainer = newConstrainer;
  62582. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62583. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62584. resizableCorner = 0;
  62585. resizableBorder = 0;
  62586. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62587. ComponentPeer* const peer = getPeer();
  62588. if (peer != 0)
  62589. peer->setConstrainer (newConstrainer);
  62590. }
  62591. }
  62592. void ResizableWindow::setBoundsConstrained (int x, int y, int w, int h)
  62593. {
  62594. if (constrainer != 0)
  62595. constrainer->setBoundsForComponent (this, x, y, w, h, false, false, false, false);
  62596. else
  62597. setBounds (x, y, w, h);
  62598. }
  62599. void ResizableWindow::paint (Graphics& g)
  62600. {
  62601. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62602. getBorderThickness(), *this);
  62603. if (! isFullScreen())
  62604. {
  62605. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62606. getBorderThickness(), *this);
  62607. }
  62608. #ifdef JUCE_DEBUG
  62609. /* If this fails, then you've probably written a subclass with a resized()
  62610. callback but forgotten to make it call its parent class's resized() method.
  62611. It's important when you override methods like resized(), moved(),
  62612. etc., that you make sure the base class methods also get called.
  62613. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62614. because your content should all be inside the content component - and it's the
  62615. content component's resized() method that you should be using to do your
  62616. layout.
  62617. */
  62618. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62619. #endif
  62620. }
  62621. void ResizableWindow::lookAndFeelChanged()
  62622. {
  62623. resized();
  62624. if (isOnDesktop())
  62625. {
  62626. Component::addToDesktop (getDesktopWindowStyleFlags());
  62627. ComponentPeer* const peer = getPeer();
  62628. if (peer != 0)
  62629. peer->setConstrainer (constrainer);
  62630. }
  62631. }
  62632. const Colour ResizableWindow::getBackgroundColour() const throw()
  62633. {
  62634. return findColour (backgroundColourId, false);
  62635. }
  62636. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62637. {
  62638. Colour backgroundColour (newColour);
  62639. if (! Desktop::canUseSemiTransparentWindows())
  62640. backgroundColour = newColour.withAlpha (1.0f);
  62641. setColour (backgroundColourId, backgroundColour);
  62642. setOpaque (backgroundColour.isOpaque());
  62643. repaint();
  62644. }
  62645. bool ResizableWindow::isFullScreen() const
  62646. {
  62647. if (isOnDesktop())
  62648. {
  62649. ComponentPeer* const peer = getPeer();
  62650. return peer != 0 && peer->isFullScreen();
  62651. }
  62652. return fullscreen;
  62653. }
  62654. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62655. {
  62656. if (shouldBeFullScreen != isFullScreen())
  62657. {
  62658. updateLastPos();
  62659. fullscreen = shouldBeFullScreen;
  62660. if (isOnDesktop())
  62661. {
  62662. ComponentPeer* const peer = getPeer();
  62663. if (peer != 0)
  62664. {
  62665. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62666. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62667. peer->setFullScreen (shouldBeFullScreen);
  62668. if (! shouldBeFullScreen)
  62669. setBounds (lastPos);
  62670. }
  62671. else
  62672. {
  62673. jassertfalse
  62674. }
  62675. }
  62676. else
  62677. {
  62678. if (shouldBeFullScreen)
  62679. setBounds (0, 0, getParentWidth(), getParentHeight());
  62680. else
  62681. setBounds (lastNonFullScreenPos);
  62682. }
  62683. resized();
  62684. }
  62685. }
  62686. bool ResizableWindow::isMinimised() const
  62687. {
  62688. ComponentPeer* const peer = getPeer();
  62689. return (peer != 0) && peer->isMinimised();
  62690. }
  62691. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62692. {
  62693. if (shouldMinimise != isMinimised())
  62694. {
  62695. ComponentPeer* const peer = getPeer();
  62696. if (peer != 0)
  62697. {
  62698. updateLastPos();
  62699. peer->setMinimised (shouldMinimise);
  62700. }
  62701. else
  62702. {
  62703. jassertfalse
  62704. }
  62705. }
  62706. }
  62707. void ResizableWindow::updateLastPos()
  62708. {
  62709. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62710. {
  62711. lastNonFullScreenPos = getBounds();
  62712. }
  62713. }
  62714. void ResizableWindow::parentSizeChanged()
  62715. {
  62716. if (isFullScreen() && getParentComponent() != 0)
  62717. {
  62718. setBounds (0, 0, getParentWidth(), getParentHeight());
  62719. }
  62720. }
  62721. const String ResizableWindow::getWindowStateAsString()
  62722. {
  62723. updateLastPos();
  62724. String s;
  62725. if (isFullScreen())
  62726. s << "fs ";
  62727. s << lastNonFullScreenPos.getX() << T(' ')
  62728. << lastNonFullScreenPos.getY() << T(' ')
  62729. << lastNonFullScreenPos.getWidth() << T(' ')
  62730. << lastNonFullScreenPos.getHeight();
  62731. return s;
  62732. }
  62733. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62734. {
  62735. StringArray tokens;
  62736. tokens.addTokens (s, false);
  62737. tokens.removeEmptyStrings();
  62738. tokens.trim();
  62739. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62740. const int n = fs ? 1 : 0;
  62741. if (tokens.size() != 4 + n)
  62742. return false;
  62743. Rectangle<int> r (tokens[n].getIntValue(),
  62744. tokens[n + 1].getIntValue(),
  62745. tokens[n + 2].getIntValue(),
  62746. tokens[n + 3].getIntValue());
  62747. if (r.isEmpty())
  62748. return false;
  62749. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (r.getX(), r.getY()));
  62750. if (! screen.contains (r))
  62751. {
  62752. r.setSize (jmin (r.getWidth(), screen.getWidth()),
  62753. jmin (r.getHeight(), screen.getHeight()));
  62754. r.setPosition (jlimit (screen.getX(), screen.getRight() - r.getWidth(), r.getX()),
  62755. jlimit (screen.getY(), screen.getBottom() - r.getHeight(), r.getY()));
  62756. }
  62757. lastNonFullScreenPos = r;
  62758. if (isOnDesktop())
  62759. {
  62760. ComponentPeer* const peer = getPeer();
  62761. if (peer != 0)
  62762. peer->setNonFullScreenBounds (r);
  62763. }
  62764. setFullScreen (fs);
  62765. if (! fs)
  62766. setBoundsConstrained (r.getX(),
  62767. r.getY(),
  62768. r.getWidth(),
  62769. r.getHeight());
  62770. return true;
  62771. }
  62772. void ResizableWindow::mouseDown (const MouseEvent&)
  62773. {
  62774. if (! isFullScreen())
  62775. dragger.startDraggingComponent (this, constrainer);
  62776. }
  62777. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62778. {
  62779. if (! isFullScreen())
  62780. dragger.dragComponent (this, e);
  62781. }
  62782. #ifdef JUCE_DEBUG
  62783. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62784. {
  62785. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62786. manages its child components automatically, and if you add your own it'll cause
  62787. trouble. Instead, use setContentComponent() to give it a component which
  62788. will be automatically resized and kept in the right place - then you can add
  62789. subcomponents to the content comp. See the notes for the ResizableWindow class
  62790. for more info.
  62791. If you really know what you're doing and want to avoid this assertion, just call
  62792. Component::addChildComponent directly.
  62793. */
  62794. jassertfalse
  62795. Component::addChildComponent (child, zOrder);
  62796. }
  62797. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62798. {
  62799. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62800. manages its child components automatically, and if you add your own it'll cause
  62801. trouble. Instead, use setContentComponent() to give it a component which
  62802. will be automatically resized and kept in the right place - then you can add
  62803. subcomponents to the content comp. See the notes for the ResizableWindow class
  62804. for more info.
  62805. If you really know what you're doing and want to avoid this assertion, just call
  62806. Component::addAndMakeVisible directly.
  62807. */
  62808. jassertfalse
  62809. Component::addAndMakeVisible (child, zOrder);
  62810. }
  62811. #endif
  62812. END_JUCE_NAMESPACE
  62813. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62814. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62815. BEGIN_JUCE_NAMESPACE
  62816. SplashScreen::SplashScreen()
  62817. : backgroundImage (0)
  62818. {
  62819. setOpaque (true);
  62820. }
  62821. SplashScreen::~SplashScreen()
  62822. {
  62823. ImageCache::releaseOrDelete (backgroundImage);
  62824. }
  62825. void SplashScreen::show (const String& title,
  62826. Image* const backgroundImage_,
  62827. const int minimumTimeToDisplayFor,
  62828. const bool useDropShadow,
  62829. const bool removeOnMouseClick)
  62830. {
  62831. backgroundImage = backgroundImage_;
  62832. jassert (backgroundImage_ != 0);
  62833. if (backgroundImage_ != 0)
  62834. {
  62835. setOpaque (! backgroundImage_->hasAlphaChannel());
  62836. show (title,
  62837. backgroundImage_->getWidth(),
  62838. backgroundImage_->getHeight(),
  62839. minimumTimeToDisplayFor,
  62840. useDropShadow,
  62841. removeOnMouseClick);
  62842. }
  62843. }
  62844. void SplashScreen::show (const String& title,
  62845. const int width,
  62846. const int height,
  62847. const int minimumTimeToDisplayFor,
  62848. const bool useDropShadow,
  62849. const bool removeOnMouseClick)
  62850. {
  62851. setName (title);
  62852. setAlwaysOnTop (true);
  62853. setVisible (true);
  62854. centreWithSize (width, height);
  62855. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62856. toFront (false);
  62857. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62858. repaint();
  62859. originalClickCounter = removeOnMouseClick
  62860. ? Desktop::getMouseButtonClickCounter()
  62861. : std::numeric_limits<int>::max();
  62862. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62863. startTimer (50);
  62864. }
  62865. void SplashScreen::paint (Graphics& g)
  62866. {
  62867. if (backgroundImage != 0)
  62868. {
  62869. g.setOpacity (1.0f);
  62870. g.drawImage (backgroundImage,
  62871. 0, 0, getWidth(), getHeight(),
  62872. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62873. }
  62874. }
  62875. void SplashScreen::timerCallback()
  62876. {
  62877. if (Time::getCurrentTime() > earliestTimeToDelete
  62878. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62879. {
  62880. delete this;
  62881. }
  62882. }
  62883. END_JUCE_NAMESPACE
  62884. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62885. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62886. BEGIN_JUCE_NAMESPACE
  62887. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62888. const bool hasProgressBar,
  62889. const bool hasCancelButton,
  62890. const int timeOutMsWhenCancelling_,
  62891. const String& cancelButtonText)
  62892. : Thread ("Juce Progress Window"),
  62893. progress (0.0),
  62894. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62895. {
  62896. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62897. .createAlertWindow (title, String::empty, cancelButtonText,
  62898. String::empty, String::empty,
  62899. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62900. if (hasProgressBar)
  62901. alertWindow->addProgressBarComponent (progress);
  62902. }
  62903. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62904. {
  62905. stopThread (timeOutMsWhenCancelling);
  62906. }
  62907. bool ThreadWithProgressWindow::runThread (const int priority)
  62908. {
  62909. startThread (priority);
  62910. startTimer (100);
  62911. {
  62912. const ScopedLock sl (messageLock);
  62913. alertWindow->setMessage (message);
  62914. }
  62915. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62916. stopThread (timeOutMsWhenCancelling);
  62917. alertWindow->setVisible (false);
  62918. return finishedNaturally;
  62919. }
  62920. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62921. {
  62922. progress = newProgress;
  62923. }
  62924. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62925. {
  62926. const ScopedLock sl (messageLock);
  62927. message = newStatusMessage;
  62928. }
  62929. void ThreadWithProgressWindow::timerCallback()
  62930. {
  62931. if (! isThreadRunning())
  62932. {
  62933. // thread has finished normally..
  62934. alertWindow->exitModalState (1);
  62935. alertWindow->setVisible (false);
  62936. }
  62937. else
  62938. {
  62939. const ScopedLock sl (messageLock);
  62940. alertWindow->setMessage (message);
  62941. }
  62942. }
  62943. END_JUCE_NAMESPACE
  62944. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62945. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62946. BEGIN_JUCE_NAMESPACE
  62947. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62948. const int millisecondsBeforeTipAppears_)
  62949. : Component ("tooltip"),
  62950. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62951. mouseX (0),
  62952. mouseY (0),
  62953. lastHideTime (0),
  62954. lastComponentUnderMouse (0),
  62955. changedCompsSinceShown (true)
  62956. {
  62957. startTimer (123);
  62958. setAlwaysOnTop (true);
  62959. setOpaque (true);
  62960. if (parentComponent != 0)
  62961. parentComponent->addChildComponent (this);
  62962. }
  62963. TooltipWindow::~TooltipWindow()
  62964. {
  62965. hide();
  62966. }
  62967. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62968. {
  62969. millisecondsBeforeTipAppears = newTimeMs;
  62970. }
  62971. void TooltipWindow::paint (Graphics& g)
  62972. {
  62973. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62974. }
  62975. void TooltipWindow::mouseEnter (const MouseEvent&)
  62976. {
  62977. hide();
  62978. }
  62979. void TooltipWindow::showFor (const String& tip)
  62980. {
  62981. jassert (tip.isNotEmpty());
  62982. tipShowing = tip;
  62983. int mx, my;
  62984. Desktop::getMousePosition (mx, my);
  62985. if (getParentComponent() != 0)
  62986. getParentComponent()->globalPositionToRelative (mx, my);
  62987. int x, y, w, h;
  62988. getLookAndFeel().getTooltipSize (tip, w, h);
  62989. if (mx > getParentWidth() / 2)
  62990. x = mx - (w + 12);
  62991. else
  62992. x = mx + 24;
  62993. if (my > getParentHeight() / 2)
  62994. y = my - (h + 6);
  62995. else
  62996. y = my + 6;
  62997. setBounds (x, y, w, h);
  62998. setVisible (true);
  62999. if (getParentComponent() == 0)
  63000. {
  63001. addToDesktop (ComponentPeer::windowHasDropShadow
  63002. | ComponentPeer::windowIsTemporary
  63003. | ComponentPeer::windowIgnoresKeyPresses);
  63004. }
  63005. toFront (false);
  63006. }
  63007. const String TooltipWindow::getTipFor (Component* const c)
  63008. {
  63009. if (c->isValidComponent()
  63010. && Process::isForegroundProcess()
  63011. && ! Component::isMouseButtonDownAnywhere())
  63012. {
  63013. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  63014. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  63015. return ttc->getTooltip();
  63016. }
  63017. return String::empty;
  63018. }
  63019. void TooltipWindow::hide()
  63020. {
  63021. tipShowing = String::empty;
  63022. removeFromDesktop();
  63023. setVisible (false);
  63024. }
  63025. void TooltipWindow::timerCallback()
  63026. {
  63027. const unsigned int now = Time::getApproximateMillisecondCounter();
  63028. Component* const newComp = Component::getComponentUnderMouse();
  63029. const String newTip (getTipFor (newComp));
  63030. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  63031. lastComponentUnderMouse = newComp;
  63032. lastTipUnderMouse = newTip;
  63033. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  63034. const bool mouseWasClicked = clickCount > mouseClicks;
  63035. mouseClicks = clickCount;
  63036. int mx, my;
  63037. Desktop::getMousePosition (mx, my);
  63038. const bool mouseMovedQuickly = (abs (mx - mouseX) + abs (my - mouseY) > 12);
  63039. mouseX = mx;
  63040. mouseY = my;
  63041. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  63042. lastCompChangeTime = now;
  63043. if (isVisible() || now < lastHideTime + 500)
  63044. {
  63045. // if a tip is currently visible (or has just disappeared), update to a new one
  63046. // immediately if needed..
  63047. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  63048. {
  63049. if (isVisible())
  63050. {
  63051. lastHideTime = now;
  63052. hide();
  63053. }
  63054. }
  63055. else if (tipChanged)
  63056. {
  63057. showFor (newTip);
  63058. }
  63059. }
  63060. else
  63061. {
  63062. // if there isn't currently a tip, but one is needed, only let it
  63063. // appear after a timeout..
  63064. if (newTip.isNotEmpty()
  63065. && newTip != tipShowing
  63066. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  63067. {
  63068. showFor (newTip);
  63069. }
  63070. }
  63071. }
  63072. END_JUCE_NAMESPACE
  63073. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  63074. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  63075. BEGIN_JUCE_NAMESPACE
  63076. class TopLevelWindowManager : public Timer,
  63077. public DeletedAtShutdown
  63078. {
  63079. public:
  63080. TopLevelWindowManager()
  63081. : currentActive (0)
  63082. {
  63083. }
  63084. ~TopLevelWindowManager()
  63085. {
  63086. clearSingletonInstance();
  63087. }
  63088. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  63089. void timerCallback()
  63090. {
  63091. startTimer (jmin (1731, getTimerInterval() * 2));
  63092. TopLevelWindow* active = 0;
  63093. if (Process::isForegroundProcess())
  63094. {
  63095. active = currentActive;
  63096. Component* const c = Component::getCurrentlyFocusedComponent();
  63097. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63098. if (tlw == 0 && c != 0)
  63099. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63100. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63101. if (tlw != 0)
  63102. active = tlw;
  63103. }
  63104. if (active != currentActive)
  63105. {
  63106. currentActive = active;
  63107. for (int i = windows.size(); --i >= 0;)
  63108. {
  63109. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63110. tlw->setWindowActive (isWindowActive (tlw));
  63111. i = jmin (i, windows.size() - 1);
  63112. }
  63113. Desktop::getInstance().triggerFocusCallback();
  63114. }
  63115. }
  63116. bool addWindow (TopLevelWindow* const w) throw()
  63117. {
  63118. windows.add (w);
  63119. startTimer (10);
  63120. return isWindowActive (w);
  63121. }
  63122. void removeWindow (TopLevelWindow* const w) throw()
  63123. {
  63124. startTimer (10);
  63125. if (currentActive == w)
  63126. currentActive = 0;
  63127. windows.removeValue (w);
  63128. if (windows.size() == 0)
  63129. deleteInstance();
  63130. }
  63131. VoidArray windows;
  63132. private:
  63133. TopLevelWindow* currentActive;
  63134. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63135. {
  63136. return (tlw == currentActive
  63137. || tlw->isParentOf (currentActive)
  63138. || tlw->hasKeyboardFocus (true))
  63139. && tlw->isShowing();
  63140. }
  63141. TopLevelWindowManager (const TopLevelWindowManager&);
  63142. const TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63143. };
  63144. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63145. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63146. {
  63147. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63148. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63149. }
  63150. TopLevelWindow::TopLevelWindow (const String& name,
  63151. const bool addToDesktop_)
  63152. : Component (name),
  63153. useDropShadow (true),
  63154. useNativeTitleBar (false),
  63155. windowIsActive_ (false)
  63156. {
  63157. setOpaque (true);
  63158. if (addToDesktop_)
  63159. Component::addToDesktop (getDesktopWindowStyleFlags());
  63160. else
  63161. setDropShadowEnabled (true);
  63162. setWantsKeyboardFocus (true);
  63163. setBroughtToFrontOnMouseClick (true);
  63164. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63165. }
  63166. TopLevelWindow::~TopLevelWindow()
  63167. {
  63168. shadower = 0;
  63169. TopLevelWindowManager::getInstance()->removeWindow (this);
  63170. }
  63171. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63172. {
  63173. if (hasKeyboardFocus (true))
  63174. TopLevelWindowManager::getInstance()->timerCallback();
  63175. else
  63176. TopLevelWindowManager::getInstance()->startTimer (10);
  63177. }
  63178. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63179. {
  63180. if (windowIsActive_ != isNowActive)
  63181. {
  63182. windowIsActive_ = isNowActive;
  63183. activeWindowStatusChanged();
  63184. }
  63185. }
  63186. void TopLevelWindow::activeWindowStatusChanged()
  63187. {
  63188. }
  63189. void TopLevelWindow::parentHierarchyChanged()
  63190. {
  63191. setDropShadowEnabled (useDropShadow);
  63192. }
  63193. void TopLevelWindow::visibilityChanged()
  63194. {
  63195. if (isShowing())
  63196. toFront (true);
  63197. }
  63198. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63199. {
  63200. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63201. if (useDropShadow)
  63202. flags |= ComponentPeer::windowHasDropShadow;
  63203. if (useNativeTitleBar)
  63204. flags |= ComponentPeer::windowHasTitleBar;
  63205. return flags;
  63206. }
  63207. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63208. {
  63209. useDropShadow = useShadow;
  63210. if (isOnDesktop())
  63211. {
  63212. shadower = 0;
  63213. Component::addToDesktop (getDesktopWindowStyleFlags());
  63214. }
  63215. else
  63216. {
  63217. if (useShadow && isOpaque())
  63218. {
  63219. if (shadower == 0)
  63220. {
  63221. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63222. if (shadower != 0)
  63223. shadower->setOwner (this);
  63224. }
  63225. }
  63226. else
  63227. {
  63228. shadower = 0;
  63229. }
  63230. }
  63231. }
  63232. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63233. {
  63234. if (useNativeTitleBar != useNativeTitleBar_)
  63235. {
  63236. useNativeTitleBar = useNativeTitleBar_;
  63237. recreateDesktopWindow();
  63238. sendLookAndFeelChange();
  63239. }
  63240. }
  63241. void TopLevelWindow::recreateDesktopWindow()
  63242. {
  63243. if (isOnDesktop())
  63244. {
  63245. Component::addToDesktop (getDesktopWindowStyleFlags());
  63246. toFront (true);
  63247. }
  63248. }
  63249. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63250. {
  63251. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63252. because this class needs to make sure its layout corresponds with settings like whether
  63253. it's got a native title bar or not.
  63254. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63255. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63256. method, then add or remove whatever flags are necessary from this value before returning it.
  63257. */
  63258. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63259. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63260. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63261. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63262. sendLookAndFeelChange();
  63263. }
  63264. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63265. {
  63266. if (c == 0)
  63267. c = TopLevelWindow::getActiveTopLevelWindow();
  63268. if (c == 0)
  63269. {
  63270. centreWithSize (width, height);
  63271. }
  63272. else
  63273. {
  63274. int x = (c->getWidth() - width) / 2;
  63275. int y = (c->getHeight() - height) / 2;
  63276. c->relativePositionToGlobal (x, y);
  63277. Rectangle<int> parentArea (c->getParentMonitorArea());
  63278. if (getParentComponent() != 0)
  63279. {
  63280. getParentComponent()->globalPositionToRelative (x, y);
  63281. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63282. }
  63283. parentArea.reduce (12, 12);
  63284. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), x),
  63285. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), y),
  63286. width, height);
  63287. }
  63288. }
  63289. int TopLevelWindow::getNumTopLevelWindows() throw()
  63290. {
  63291. return TopLevelWindowManager::getInstance()->windows.size();
  63292. }
  63293. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63294. {
  63295. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63296. }
  63297. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63298. {
  63299. TopLevelWindow* best = 0;
  63300. int bestNumTWLParents = -1;
  63301. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63302. {
  63303. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63304. if (tlw->isActiveWindow())
  63305. {
  63306. int numTWLParents = 0;
  63307. const Component* c = tlw->getParentComponent();
  63308. while (c != 0)
  63309. {
  63310. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63311. ++numTWLParents;
  63312. c = c->getParentComponent();
  63313. }
  63314. if (bestNumTWLParents < numTWLParents)
  63315. {
  63316. best = tlw;
  63317. bestNumTWLParents = numTWLParents;
  63318. }
  63319. }
  63320. }
  63321. return best;
  63322. }
  63323. END_JUCE_NAMESPACE
  63324. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  63325. /*** Start of inlined file: juce_Colour.cpp ***/
  63326. BEGIN_JUCE_NAMESPACE
  63327. static uint8 floatAlphaToInt (const float alpha)
  63328. {
  63329. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63330. }
  63331. static const float oneOver255 = 1.0f / 255.0f;
  63332. Colour::Colour() throw()
  63333. : argb (0)
  63334. {
  63335. }
  63336. Colour::Colour (const Colour& other) throw()
  63337. : argb (other.argb)
  63338. {
  63339. }
  63340. const Colour& Colour::operator= (const Colour& other) throw()
  63341. {
  63342. argb = other.argb;
  63343. return *this;
  63344. }
  63345. bool Colour::operator== (const Colour& other) const throw()
  63346. {
  63347. return argb.getARGB() == other.argb.getARGB();
  63348. }
  63349. bool Colour::operator!= (const Colour& other) const throw()
  63350. {
  63351. return argb.getARGB() != other.argb.getARGB();
  63352. }
  63353. Colour::Colour (const uint32 argb_) throw()
  63354. : argb (argb_)
  63355. {
  63356. }
  63357. Colour::Colour (const uint8 red,
  63358. const uint8 green,
  63359. const uint8 blue) throw()
  63360. {
  63361. argb.setARGB (0xff, red, green, blue);
  63362. }
  63363. const Colour Colour::fromRGB (const uint8 red,
  63364. const uint8 green,
  63365. const uint8 blue) throw()
  63366. {
  63367. return Colour (red, green, blue);
  63368. }
  63369. Colour::Colour (const uint8 red,
  63370. const uint8 green,
  63371. const uint8 blue,
  63372. const uint8 alpha) throw()
  63373. {
  63374. argb.setARGB (alpha, red, green, blue);
  63375. }
  63376. const Colour Colour::fromRGBA (const uint8 red,
  63377. const uint8 green,
  63378. const uint8 blue,
  63379. const uint8 alpha) throw()
  63380. {
  63381. return Colour (red, green, blue, alpha);
  63382. }
  63383. Colour::Colour (const uint8 red,
  63384. const uint8 green,
  63385. const uint8 blue,
  63386. const float alpha) throw()
  63387. {
  63388. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63389. }
  63390. const Colour Colour::fromRGBAFloat (const uint8 red,
  63391. const uint8 green,
  63392. const uint8 blue,
  63393. const float alpha) throw()
  63394. {
  63395. return Colour (red, green, blue, alpha);
  63396. }
  63397. static void convertHSBtoRGB (float h, float s, float v,
  63398. uint8& r, uint8& g, uint8& b) throw()
  63399. {
  63400. v = jlimit (0.0f, 1.0f, v);
  63401. v *= 255.0f;
  63402. const uint8 intV = (uint8) roundToInt (v);
  63403. if (s <= 0)
  63404. {
  63405. r = intV;
  63406. g = intV;
  63407. b = intV;
  63408. }
  63409. else
  63410. {
  63411. s = jmin (1.0f, s);
  63412. h = jlimit (0.0f, 1.0f, h);
  63413. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63414. const float f = h - floorf (h);
  63415. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63416. const float y = v * (1.0f - s * f);
  63417. const float z = v * (1.0f - (s * (1.0f - f)));
  63418. if (h < 1.0f)
  63419. {
  63420. r = intV;
  63421. g = (uint8) roundToInt (z);
  63422. b = x;
  63423. }
  63424. else if (h < 2.0f)
  63425. {
  63426. r = (uint8) roundToInt (y);
  63427. g = intV;
  63428. b = x;
  63429. }
  63430. else if (h < 3.0f)
  63431. {
  63432. r = x;
  63433. g = intV;
  63434. b = (uint8) roundToInt (z);
  63435. }
  63436. else if (h < 4.0f)
  63437. {
  63438. r = x;
  63439. g = (uint8) roundToInt (y);
  63440. b = intV;
  63441. }
  63442. else if (h < 5.0f)
  63443. {
  63444. r = (uint8) roundToInt (z);
  63445. g = x;
  63446. b = intV;
  63447. }
  63448. else if (h < 6.0f)
  63449. {
  63450. r = intV;
  63451. g = x;
  63452. b = (uint8) roundToInt (y);
  63453. }
  63454. else
  63455. {
  63456. r = 0;
  63457. g = 0;
  63458. b = 0;
  63459. }
  63460. }
  63461. }
  63462. Colour::Colour (const float hue,
  63463. const float saturation,
  63464. const float brightness,
  63465. const float alpha) throw()
  63466. {
  63467. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63468. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63469. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63470. }
  63471. const Colour Colour::fromHSV (const float hue,
  63472. const float saturation,
  63473. const float brightness,
  63474. const float alpha) throw()
  63475. {
  63476. return Colour (hue, saturation, brightness, alpha);
  63477. }
  63478. Colour::Colour (const float hue,
  63479. const float saturation,
  63480. const float brightness,
  63481. const uint8 alpha) throw()
  63482. {
  63483. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63484. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63485. argb.setARGB (alpha, r, g, b);
  63486. }
  63487. Colour::~Colour() throw()
  63488. {
  63489. }
  63490. const PixelARGB Colour::getPixelARGB() const throw()
  63491. {
  63492. PixelARGB p (argb);
  63493. p.premultiply();
  63494. return p;
  63495. }
  63496. uint32 Colour::getARGB() const throw()
  63497. {
  63498. return argb.getARGB();
  63499. }
  63500. bool Colour::isTransparent() const throw()
  63501. {
  63502. return getAlpha() == 0;
  63503. }
  63504. bool Colour::isOpaque() const throw()
  63505. {
  63506. return getAlpha() == 0xff;
  63507. }
  63508. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63509. {
  63510. PixelARGB newCol (argb);
  63511. newCol.setAlpha (newAlpha);
  63512. return Colour (newCol.getARGB());
  63513. }
  63514. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63515. {
  63516. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63517. PixelARGB newCol (argb);
  63518. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63519. return Colour (newCol.getARGB());
  63520. }
  63521. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63522. {
  63523. jassert (alphaMultiplier >= 0);
  63524. PixelARGB newCol (argb);
  63525. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63526. return Colour (newCol.getARGB());
  63527. }
  63528. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63529. {
  63530. const int destAlpha = getAlpha();
  63531. if (destAlpha > 0)
  63532. {
  63533. const int invA = 0xff - (int) src.getAlpha();
  63534. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63535. if (resA > 0)
  63536. {
  63537. const int da = (invA * destAlpha) / resA;
  63538. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63539. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63540. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63541. (uint8) resA);
  63542. }
  63543. return *this;
  63544. }
  63545. else
  63546. {
  63547. return src;
  63548. }
  63549. }
  63550. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63551. {
  63552. if (proportionOfOther <= 0)
  63553. return *this;
  63554. if (proportionOfOther >= 1.0f)
  63555. return other;
  63556. PixelARGB c1 (getPixelARGB());
  63557. const PixelARGB c2 (other.getPixelARGB());
  63558. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63559. c1.unpremultiply();
  63560. return Colour (c1.getARGB());
  63561. }
  63562. float Colour::getFloatRed() const throw()
  63563. {
  63564. return getRed() * oneOver255;
  63565. }
  63566. float Colour::getFloatGreen() const throw()
  63567. {
  63568. return getGreen() * oneOver255;
  63569. }
  63570. float Colour::getFloatBlue() const throw()
  63571. {
  63572. return getBlue() * oneOver255;
  63573. }
  63574. float Colour::getFloatAlpha() const throw()
  63575. {
  63576. return getAlpha() * oneOver255;
  63577. }
  63578. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63579. {
  63580. const int r = getRed();
  63581. const int g = getGreen();
  63582. const int b = getBlue();
  63583. const int hi = jmax (r, g, b);
  63584. const int lo = jmin (r, g, b);
  63585. if (hi != 0)
  63586. {
  63587. s = (hi - lo) / (float) hi;
  63588. if (s != 0)
  63589. {
  63590. const float invDiff = 1.0f / (hi - lo);
  63591. const float red = (hi - r) * invDiff;
  63592. const float green = (hi - g) * invDiff;
  63593. const float blue = (hi - b) * invDiff;
  63594. if (r == hi)
  63595. h = blue - green;
  63596. else if (g == hi)
  63597. h = 2.0f + red - blue;
  63598. else
  63599. h = 4.0f + green - red;
  63600. h *= 1.0f / 6.0f;
  63601. if (h < 0)
  63602. ++h;
  63603. }
  63604. else
  63605. {
  63606. h = 0;
  63607. }
  63608. }
  63609. else
  63610. {
  63611. s = 0;
  63612. h = 0;
  63613. }
  63614. v = hi * oneOver255;
  63615. }
  63616. float Colour::getHue() const throw()
  63617. {
  63618. float h, s, b;
  63619. getHSB (h, s, b);
  63620. return h;
  63621. }
  63622. const Colour Colour::withHue (const float hue) const throw()
  63623. {
  63624. float h, s, b;
  63625. getHSB (h, s, b);
  63626. return Colour (hue, s, b, getAlpha());
  63627. }
  63628. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63629. {
  63630. float h, s, b;
  63631. getHSB (h, s, b);
  63632. h += amountToRotate;
  63633. h -= floorf (h);
  63634. return Colour (h, s, b, getAlpha());
  63635. }
  63636. float Colour::getSaturation() const throw()
  63637. {
  63638. float h, s, b;
  63639. getHSB (h, s, b);
  63640. return s;
  63641. }
  63642. const Colour Colour::withSaturation (const float saturation) const throw()
  63643. {
  63644. float h, s, b;
  63645. getHSB (h, s, b);
  63646. return Colour (h, saturation, b, getAlpha());
  63647. }
  63648. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63649. {
  63650. float h, s, b;
  63651. getHSB (h, s, b);
  63652. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63653. }
  63654. float Colour::getBrightness() const throw()
  63655. {
  63656. float h, s, b;
  63657. getHSB (h, s, b);
  63658. return b;
  63659. }
  63660. const Colour Colour::withBrightness (const float brightness) const throw()
  63661. {
  63662. float h, s, b;
  63663. getHSB (h, s, b);
  63664. return Colour (h, s, brightness, getAlpha());
  63665. }
  63666. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63667. {
  63668. float h, s, b;
  63669. getHSB (h, s, b);
  63670. b *= amount;
  63671. if (b > 1.0f)
  63672. b = 1.0f;
  63673. return Colour (h, s, b, getAlpha());
  63674. }
  63675. const Colour Colour::brighter (float amount) const throw()
  63676. {
  63677. amount = 1.0f / (1.0f + amount);
  63678. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63679. (uint8) (255 - (amount * (255 - getGreen()))),
  63680. (uint8) (255 - (amount * (255 - getBlue()))),
  63681. getAlpha());
  63682. }
  63683. const Colour Colour::darker (float amount) const throw()
  63684. {
  63685. amount = 1.0f / (1.0f + amount);
  63686. return Colour ((uint8) (amount * getRed()),
  63687. (uint8) (amount * getGreen()),
  63688. (uint8) (amount * getBlue()),
  63689. getAlpha());
  63690. }
  63691. const Colour Colour::greyLevel (const float brightness) throw()
  63692. {
  63693. const uint8 level
  63694. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63695. return Colour (level, level, level);
  63696. }
  63697. const Colour Colour::contrasting (const float amount) const throw()
  63698. {
  63699. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63700. ? Colours::black
  63701. : Colours::white).withAlpha (amount));
  63702. }
  63703. const Colour Colour::contrasting (const Colour& colour1,
  63704. const Colour& colour2) throw()
  63705. {
  63706. const float b1 = colour1.getBrightness();
  63707. const float b2 = colour2.getBrightness();
  63708. float best = 0.0f;
  63709. float bestDist = 0.0f;
  63710. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63711. {
  63712. const float d1 = fabsf (i - b1);
  63713. const float d2 = fabsf (i - b2);
  63714. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63715. if (dist > bestDist)
  63716. {
  63717. best = i;
  63718. bestDist = dist;
  63719. }
  63720. }
  63721. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63722. .withBrightness (best);
  63723. }
  63724. const String Colour::toString() const throw()
  63725. {
  63726. return String::toHexString ((int) argb.getARGB());
  63727. }
  63728. const Colour Colour::fromString (const String& encodedColourString)
  63729. {
  63730. return Colour ((uint32) encodedColourString.getHexValue32());
  63731. }
  63732. END_JUCE_NAMESPACE
  63733. /*** End of inlined file: juce_Colour.cpp ***/
  63734. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63735. BEGIN_JUCE_NAMESPACE
  63736. ColourGradient::ColourGradient() throw()
  63737. {
  63738. #ifdef JUCE_DEBUG
  63739. x1 = 987654.0f;
  63740. #endif
  63741. }
  63742. ColourGradient::ColourGradient (const Colour& colour1,
  63743. const float x1_,
  63744. const float y1_,
  63745. const Colour& colour2,
  63746. const float x2_,
  63747. const float y2_,
  63748. const bool isRadial_) throw()
  63749. : x1 (x1_),
  63750. y1 (y1_),
  63751. x2 (x2_),
  63752. y2 (y2_),
  63753. isRadial (isRadial_)
  63754. {
  63755. colours.add (0);
  63756. colours.add (colour1.getARGB());
  63757. colours.add (1 << 16);
  63758. colours.add (colour2.getARGB());
  63759. }
  63760. ColourGradient::~ColourGradient() throw()
  63761. {
  63762. }
  63763. void ColourGradient::clearColours() throw()
  63764. {
  63765. colours.clear();
  63766. }
  63767. void ColourGradient::addColour (const double proportionAlongGradient,
  63768. const Colour& colour) throw()
  63769. {
  63770. // must be within the two end-points
  63771. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63772. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63773. int i;
  63774. for (i = 0; i < colours.size(); i += 2)
  63775. if (colours.getUnchecked(i) > pos)
  63776. break;
  63777. colours.insert (i, pos);
  63778. colours.insert (i + 1, colour.getARGB());
  63779. }
  63780. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63781. {
  63782. for (int i = 1; i < colours.size(); i += 2)
  63783. {
  63784. const Colour c (colours.getUnchecked(i));
  63785. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63786. }
  63787. }
  63788. int ColourGradient::getNumColours() const throw()
  63789. {
  63790. return colours.size() >> 1;
  63791. }
  63792. double ColourGradient::getColourPosition (const int index) const throw()
  63793. {
  63794. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63795. }
  63796. const Colour ColourGradient::getColour (const int index) const throw()
  63797. {
  63798. return Colour (colours [(index << 1) + 1]);
  63799. }
  63800. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63801. {
  63802. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63803. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63804. if (integerPos <= 0 || colours.size() <= 2)
  63805. return getColour (0);
  63806. int i = colours.size() - 2;
  63807. while (integerPos < (int) colours.getUnchecked(i))
  63808. i -= 2;
  63809. if (i >= colours.size() - 2)
  63810. return Colour (colours.getUnchecked(i));
  63811. const int pos1 = colours.getUnchecked (i);
  63812. const Colour col1 (colours.getUnchecked (i + 1));
  63813. const int pos2 = colours.getUnchecked (i + 2);
  63814. const Colour col2 (colours.getUnchecked (i + 3));
  63815. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63816. }
  63817. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63818. {
  63819. #ifdef JUCE_DEBUG
  63820. // trying to use the object without setting its co-ordinates? Have a careful read of
  63821. // the comments for the constructors.
  63822. jassert (x1 != 987654.0f);
  63823. #endif
  63824. const int numColours = colours.size() >> 1;
  63825. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63826. transform.transformPoint (tx1, ty1);
  63827. transform.transformPoint (tx2, ty2);
  63828. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63829. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63830. lookupTable.malloc (numEntries);
  63831. if (numColours >= 2)
  63832. {
  63833. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63834. PixelARGB pix1 (colours.getUnchecked (1));
  63835. pix1.premultiply();
  63836. int index = 0;
  63837. for (int j = 2; j < colours.size(); j += 2)
  63838. {
  63839. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63840. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63841. pix2.premultiply();
  63842. for (int i = 0; i < numToDo; ++i)
  63843. {
  63844. jassert (index >= 0 && index < numEntries);
  63845. lookupTable[index] = pix1;
  63846. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63847. ++index;
  63848. }
  63849. pix1 = pix2;
  63850. }
  63851. while (index < numEntries)
  63852. lookupTable [index++] = pix1;
  63853. }
  63854. else
  63855. {
  63856. jassertfalse // no colours specified!
  63857. }
  63858. return numEntries;
  63859. }
  63860. bool ColourGradient::isOpaque() const throw()
  63861. {
  63862. for (int i = 1; i < colours.size(); i += 2)
  63863. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63864. return false;
  63865. return true;
  63866. }
  63867. bool ColourGradient::isInvisible() const throw()
  63868. {
  63869. for (int i = 1; i < colours.size(); i += 2)
  63870. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63871. return false;
  63872. return true;
  63873. }
  63874. END_JUCE_NAMESPACE
  63875. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63876. /*** Start of inlined file: juce_Colours.cpp ***/
  63877. BEGIN_JUCE_NAMESPACE
  63878. const Colour Colours::transparentBlack (0);
  63879. const Colour Colours::transparentWhite (0x00ffffff);
  63880. const Colour Colours::aliceblue (0xfff0f8ff);
  63881. const Colour Colours::antiquewhite (0xfffaebd7);
  63882. const Colour Colours::aqua (0xff00ffff);
  63883. const Colour Colours::aquamarine (0xff7fffd4);
  63884. const Colour Colours::azure (0xfff0ffff);
  63885. const Colour Colours::beige (0xfff5f5dc);
  63886. const Colour Colours::bisque (0xffffe4c4);
  63887. const Colour Colours::black (0xff000000);
  63888. const Colour Colours::blanchedalmond (0xffffebcd);
  63889. const Colour Colours::blue (0xff0000ff);
  63890. const Colour Colours::blueviolet (0xff8a2be2);
  63891. const Colour Colours::brown (0xffa52a2a);
  63892. const Colour Colours::burlywood (0xffdeb887);
  63893. const Colour Colours::cadetblue (0xff5f9ea0);
  63894. const Colour Colours::chartreuse (0xff7fff00);
  63895. const Colour Colours::chocolate (0xffd2691e);
  63896. const Colour Colours::coral (0xffff7f50);
  63897. const Colour Colours::cornflowerblue (0xff6495ed);
  63898. const Colour Colours::cornsilk (0xfffff8dc);
  63899. const Colour Colours::crimson (0xffdc143c);
  63900. const Colour Colours::cyan (0xff00ffff);
  63901. const Colour Colours::darkblue (0xff00008b);
  63902. const Colour Colours::darkcyan (0xff008b8b);
  63903. const Colour Colours::darkgoldenrod (0xffb8860b);
  63904. const Colour Colours::darkgrey (0xff555555);
  63905. const Colour Colours::darkgreen (0xff006400);
  63906. const Colour Colours::darkkhaki (0xffbdb76b);
  63907. const Colour Colours::darkmagenta (0xff8b008b);
  63908. const Colour Colours::darkolivegreen (0xff556b2f);
  63909. const Colour Colours::darkorange (0xffff8c00);
  63910. const Colour Colours::darkorchid (0xff9932cc);
  63911. const Colour Colours::darkred (0xff8b0000);
  63912. const Colour Colours::darksalmon (0xffe9967a);
  63913. const Colour Colours::darkseagreen (0xff8fbc8f);
  63914. const Colour Colours::darkslateblue (0xff483d8b);
  63915. const Colour Colours::darkslategrey (0xff2f4f4f);
  63916. const Colour Colours::darkturquoise (0xff00ced1);
  63917. const Colour Colours::darkviolet (0xff9400d3);
  63918. const Colour Colours::deeppink (0xffff1493);
  63919. const Colour Colours::deepskyblue (0xff00bfff);
  63920. const Colour Colours::dimgrey (0xff696969);
  63921. const Colour Colours::dodgerblue (0xff1e90ff);
  63922. const Colour Colours::firebrick (0xffb22222);
  63923. const Colour Colours::floralwhite (0xfffffaf0);
  63924. const Colour Colours::forestgreen (0xff228b22);
  63925. const Colour Colours::fuchsia (0xffff00ff);
  63926. const Colour Colours::gainsboro (0xffdcdcdc);
  63927. const Colour Colours::gold (0xffffd700);
  63928. const Colour Colours::goldenrod (0xffdaa520);
  63929. const Colour Colours::grey (0xff808080);
  63930. const Colour Colours::green (0xff008000);
  63931. const Colour Colours::greenyellow (0xffadff2f);
  63932. const Colour Colours::honeydew (0xfff0fff0);
  63933. const Colour Colours::hotpink (0xffff69b4);
  63934. const Colour Colours::indianred (0xffcd5c5c);
  63935. const Colour Colours::indigo (0xff4b0082);
  63936. const Colour Colours::ivory (0xfffffff0);
  63937. const Colour Colours::khaki (0xfff0e68c);
  63938. const Colour Colours::lavender (0xffe6e6fa);
  63939. const Colour Colours::lavenderblush (0xfffff0f5);
  63940. const Colour Colours::lemonchiffon (0xfffffacd);
  63941. const Colour Colours::lightblue (0xffadd8e6);
  63942. const Colour Colours::lightcoral (0xfff08080);
  63943. const Colour Colours::lightcyan (0xffe0ffff);
  63944. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63945. const Colour Colours::lightgreen (0xff90ee90);
  63946. const Colour Colours::lightgrey (0xffd3d3d3);
  63947. const Colour Colours::lightpink (0xffffb6c1);
  63948. const Colour Colours::lightsalmon (0xffffa07a);
  63949. const Colour Colours::lightseagreen (0xff20b2aa);
  63950. const Colour Colours::lightskyblue (0xff87cefa);
  63951. const Colour Colours::lightslategrey (0xff778899);
  63952. const Colour Colours::lightsteelblue (0xffb0c4de);
  63953. const Colour Colours::lightyellow (0xffffffe0);
  63954. const Colour Colours::lime (0xff00ff00);
  63955. const Colour Colours::limegreen (0xff32cd32);
  63956. const Colour Colours::linen (0xfffaf0e6);
  63957. const Colour Colours::magenta (0xffff00ff);
  63958. const Colour Colours::maroon (0xff800000);
  63959. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63960. const Colour Colours::mediumblue (0xff0000cd);
  63961. const Colour Colours::mediumorchid (0xffba55d3);
  63962. const Colour Colours::mediumpurple (0xff9370db);
  63963. const Colour Colours::mediumseagreen (0xff3cb371);
  63964. const Colour Colours::mediumslateblue (0xff7b68ee);
  63965. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63966. const Colour Colours::mediumturquoise (0xff48d1cc);
  63967. const Colour Colours::mediumvioletred (0xffc71585);
  63968. const Colour Colours::midnightblue (0xff191970);
  63969. const Colour Colours::mintcream (0xfff5fffa);
  63970. const Colour Colours::mistyrose (0xffffe4e1);
  63971. const Colour Colours::navajowhite (0xffffdead);
  63972. const Colour Colours::navy (0xff000080);
  63973. const Colour Colours::oldlace (0xfffdf5e6);
  63974. const Colour Colours::olive (0xff808000);
  63975. const Colour Colours::olivedrab (0xff6b8e23);
  63976. const Colour Colours::orange (0xffffa500);
  63977. const Colour Colours::orangered (0xffff4500);
  63978. const Colour Colours::orchid (0xffda70d6);
  63979. const Colour Colours::palegoldenrod (0xffeee8aa);
  63980. const Colour Colours::palegreen (0xff98fb98);
  63981. const Colour Colours::paleturquoise (0xffafeeee);
  63982. const Colour Colours::palevioletred (0xffdb7093);
  63983. const Colour Colours::papayawhip (0xffffefd5);
  63984. const Colour Colours::peachpuff (0xffffdab9);
  63985. const Colour Colours::peru (0xffcd853f);
  63986. const Colour Colours::pink (0xffffc0cb);
  63987. const Colour Colours::plum (0xffdda0dd);
  63988. const Colour Colours::powderblue (0xffb0e0e6);
  63989. const Colour Colours::purple (0xff800080);
  63990. const Colour Colours::red (0xffff0000);
  63991. const Colour Colours::rosybrown (0xffbc8f8f);
  63992. const Colour Colours::royalblue (0xff4169e1);
  63993. const Colour Colours::saddlebrown (0xff8b4513);
  63994. const Colour Colours::salmon (0xfffa8072);
  63995. const Colour Colours::sandybrown (0xfff4a460);
  63996. const Colour Colours::seagreen (0xff2e8b57);
  63997. const Colour Colours::seashell (0xfffff5ee);
  63998. const Colour Colours::sienna (0xffa0522d);
  63999. const Colour Colours::silver (0xffc0c0c0);
  64000. const Colour Colours::skyblue (0xff87ceeb);
  64001. const Colour Colours::slateblue (0xff6a5acd);
  64002. const Colour Colours::slategrey (0xff708090);
  64003. const Colour Colours::snow (0xfffffafa);
  64004. const Colour Colours::springgreen (0xff00ff7f);
  64005. const Colour Colours::steelblue (0xff4682b4);
  64006. const Colour Colours::tan (0xffd2b48c);
  64007. const Colour Colours::teal (0xff008080);
  64008. const Colour Colours::thistle (0xffd8bfd8);
  64009. const Colour Colours::tomato (0xffff6347);
  64010. const Colour Colours::turquoise (0xff40e0d0);
  64011. const Colour Colours::violet (0xffee82ee);
  64012. const Colour Colours::wheat (0xfff5deb3);
  64013. const Colour Colours::white (0xffffffff);
  64014. const Colour Colours::whitesmoke (0xfff5f5f5);
  64015. const Colour Colours::yellow (0xffffff00);
  64016. const Colour Colours::yellowgreen (0xff9acd32);
  64017. const Colour Colours::findColourForName (const String& colourName,
  64018. const Colour& defaultColour)
  64019. {
  64020. static const int presets[] =
  64021. {
  64022. // (first value is the string's hashcode, second is ARGB)
  64023. 0x05978fff, 0xff000000, /* black */
  64024. 0x06bdcc29, 0xffffffff, /* white */
  64025. 0x002e305a, 0xff0000ff, /* blue */
  64026. 0x00308adf, 0xff808080, /* grey */
  64027. 0x05e0cf03, 0xff008000, /* green */
  64028. 0x0001b891, 0xffff0000, /* red */
  64029. 0xd43c6474, 0xffffff00, /* yellow */
  64030. 0x620886da, 0xfff0f8ff, /* aliceblue */
  64031. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  64032. 0x002dcebc, 0xff00ffff, /* aqua */
  64033. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  64034. 0x0590228f, 0xfff0ffff, /* azure */
  64035. 0x05947fe4, 0xfff5f5dc, /* beige */
  64036. 0xad388e35, 0xffffe4c4, /* bisque */
  64037. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  64038. 0x39129959, 0xff8a2be2, /* blueviolet */
  64039. 0x059a8136, 0xffa52a2a, /* brown */
  64040. 0x89cea8f9, 0xffdeb887, /* burlywood */
  64041. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  64042. 0x6b748956, 0xff7fff00, /* chartreuse */
  64043. 0x2903623c, 0xffd2691e, /* chocolate */
  64044. 0x05a74431, 0xffff7f50, /* coral */
  64045. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  64046. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  64047. 0x3d8c4edf, 0xffdc143c, /* crimson */
  64048. 0x002ed323, 0xff00ffff, /* cyan */
  64049. 0x67cc74d0, 0xff00008b, /* darkblue */
  64050. 0x67cd1799, 0xff008b8b, /* darkcyan */
  64051. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  64052. 0x67cecf55, 0xff555555, /* darkgrey */
  64053. 0x920b194d, 0xff006400, /* darkgreen */
  64054. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  64055. 0x5c293873, 0xff8b008b, /* darkmagenta */
  64056. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  64057. 0xbcfd2524, 0xffff8c00, /* darkorange */
  64058. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  64059. 0x55ee0d5b, 0xff8b0000, /* darkred */
  64060. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  64061. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  64062. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  64063. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  64064. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  64065. 0xc8769375, 0xff9400d3, /* darkviolet */
  64066. 0x25832862, 0xffff1493, /* deeppink */
  64067. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  64068. 0x634c8b67, 0xff696969, /* dimgrey */
  64069. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  64070. 0xef19e3cb, 0xffb22222, /* firebrick */
  64071. 0xb852b195, 0xfffffaf0, /* floralwhite */
  64072. 0xd086fd06, 0xff228b22, /* forestgreen */
  64073. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  64074. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  64075. 0x00308060, 0xffffd700, /* gold */
  64076. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  64077. 0xbab8a537, 0xffadff2f, /* greenyellow */
  64078. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  64079. 0x41892743, 0xffff69b4, /* hotpink */
  64080. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  64081. 0xb969fed2, 0xff4b0082, /* indigo */
  64082. 0x05fef6a9, 0xfffffff0, /* ivory */
  64083. 0x06149302, 0xfff0e68c, /* khaki */
  64084. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  64085. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  64086. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  64087. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  64088. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  64089. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  64090. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  64091. 0xf40157ad, 0xff90ee90, /* lightgreen */
  64092. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  64093. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  64094. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  64095. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  64096. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64097. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64098. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64099. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64100. 0x0032afd5, 0xff00ff00, /* lime */
  64101. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64102. 0x06234efa, 0xfffaf0e6, /* linen */
  64103. 0x316858a9, 0xffff00ff, /* magenta */
  64104. 0xbf8ca470, 0xff800000, /* maroon */
  64105. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64106. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64107. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64108. 0x07556b71, 0xff9370db, /* mediumpurple */
  64109. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64110. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64111. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64112. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64113. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64114. 0x168eb32a, 0xff191970, /* midnightblue */
  64115. 0x4306b960, 0xfff5fffa, /* mintcream */
  64116. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64117. 0xe97218a6, 0xffffdead, /* navajowhite */
  64118. 0x00337bb6, 0xff000080, /* navy */
  64119. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64120. 0x064ee1db, 0xff808000, /* olive */
  64121. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64122. 0xc3de262e, 0xffffa500, /* orange */
  64123. 0x58bebba3, 0xffff4500, /* orangered */
  64124. 0xc3def8a3, 0xffda70d6, /* orchid */
  64125. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64126. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64127. 0x74022737, 0xffafeeee, /* paleturquoise */
  64128. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64129. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64130. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64131. 0x003472f8, 0xffcd853f, /* peru */
  64132. 0x00348176, 0xffffc0cb, /* pink */
  64133. 0x00348d94, 0xffdda0dd, /* plum */
  64134. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64135. 0xc5c507bc, 0xff800080, /* purple */
  64136. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64137. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64138. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64139. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64140. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64141. 0x34636c14, 0xff2e8b57, /* seagreen */
  64142. 0x3507fb41, 0xfffff5ee, /* seashell */
  64143. 0xca348772, 0xffa0522d, /* sienna */
  64144. 0xca37d30d, 0xffc0c0c0, /* silver */
  64145. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64146. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64147. 0x44ab37f8, 0xff708090, /* slategrey */
  64148. 0x0035f183, 0xfffffafa, /* snow */
  64149. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64150. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64151. 0x0001bfa1, 0xffd2b48c, /* tan */
  64152. 0x0036425c, 0xff008080, /* teal */
  64153. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64154. 0xcc41600a, 0xffff6347, /* tomato */
  64155. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64156. 0xcf57947f, 0xffee82ee, /* violet */
  64157. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64158. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64159. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64160. };
  64161. const int hash = colourName.trim().toLowerCase().hashCode();
  64162. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64163. if (presets [i] == hash)
  64164. return Colour (presets [i + 1]);
  64165. return defaultColour;
  64166. }
  64167. END_JUCE_NAMESPACE
  64168. /*** End of inlined file: juce_Colours.cpp ***/
  64169. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  64170. BEGIN_JUCE_NAMESPACE
  64171. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64172. static void copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64173. {
  64174. while (--numLines >= 0)
  64175. {
  64176. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64177. src += srcLineStride;
  64178. dest += destLineStride;
  64179. }
  64180. }
  64181. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  64182. const Path& path, const AffineTransform& transform) throw()
  64183. : bounds (bounds_),
  64184. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64185. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64186. needToCheckEmptinesss (true)
  64187. {
  64188. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64189. int* t = table;
  64190. for (int i = bounds.getHeight(); --i >= 0;)
  64191. {
  64192. *t = 0;
  64193. t += lineStrideElements;
  64194. }
  64195. const int topLimit = bounds.getY() << 8;
  64196. const int heightLimit = bounds.getHeight() << 8;
  64197. const int leftLimit = bounds.getX() << 8;
  64198. const int rightLimit = bounds.getRight() << 8;
  64199. PathFlatteningIterator iter (path, transform);
  64200. while (iter.next())
  64201. {
  64202. int y1 = roundToInt (iter.y1 * 256.0f);
  64203. int y2 = roundToInt (iter.y2 * 256.0f);
  64204. if (y1 != y2)
  64205. {
  64206. y1 -= topLimit;
  64207. y2 -= topLimit;
  64208. const int startY = y1;
  64209. int direction = -1;
  64210. if (y1 > y2)
  64211. {
  64212. swapVariables (y1, y2);
  64213. direction = 1;
  64214. }
  64215. if (y1 < 0)
  64216. y1 = 0;
  64217. if (y2 > heightLimit)
  64218. y2 = heightLimit;
  64219. if (y1 < y2)
  64220. {
  64221. const double startX = 256.0f * iter.x1;
  64222. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64223. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64224. do
  64225. {
  64226. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64227. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64228. if (x < leftLimit)
  64229. x = leftLimit;
  64230. else if (x >= rightLimit)
  64231. x = rightLimit - 1;
  64232. addEdgePoint (x, y1 >> 8, direction * step);
  64233. y1 += step;
  64234. }
  64235. while (y1 < y2);
  64236. }
  64237. }
  64238. }
  64239. sanitiseLevels (path.isUsingNonZeroWinding());
  64240. }
  64241. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd) throw()
  64242. : bounds (rectangleToAdd),
  64243. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64244. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64245. needToCheckEmptinesss (true)
  64246. {
  64247. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64248. table[0] = 0;
  64249. const int x1 = rectangleToAdd.getX() << 8;
  64250. const int x2 = rectangleToAdd.getRight() << 8;
  64251. int* t = table;
  64252. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64253. {
  64254. t[0] = 2;
  64255. t[1] = x1;
  64256. t[2] = 255;
  64257. t[3] = x2;
  64258. t[4] = 0;
  64259. t += lineStrideElements;
  64260. }
  64261. }
  64262. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64263. : bounds (rectanglesToAdd.getBounds()),
  64264. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64265. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64266. needToCheckEmptinesss (true)
  64267. {
  64268. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64269. int* t = table;
  64270. for (int i = bounds.getHeight(); --i >= 0;)
  64271. {
  64272. *t = 0;
  64273. t += lineStrideElements;
  64274. }
  64275. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64276. {
  64277. const Rectangle<int>* const r = iter.getRectangle();
  64278. const int x1 = r->getX() << 8;
  64279. const int x2 = r->getRight() << 8;
  64280. int y = r->getY() - bounds.getY();
  64281. for (int j = r->getHeight(); --j >= 0;)
  64282. {
  64283. addEdgePoint (x1, y, 255);
  64284. addEdgePoint (x2, y, -255);
  64285. ++y;
  64286. }
  64287. }
  64288. sanitiseLevels (true);
  64289. }
  64290. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64291. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64292. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64293. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64294. needToCheckEmptinesss (true)
  64295. {
  64296. jassert (w > 0 && h > 0);
  64297. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64298. table[0] = 0;
  64299. const int x1 = roundToInt (x * 256.0f);
  64300. const int x2 = roundToInt ((x + w) * 256.0f);
  64301. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64302. jassert (y1 < 256);
  64303. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64304. if (x2 <= x1 || y2 <= y1)
  64305. {
  64306. bounds.setHeight (0);
  64307. return;
  64308. }
  64309. int lineY = 0;
  64310. int* t = table;
  64311. if ((y1 >> 8) == (y2 >> 8))
  64312. {
  64313. t[0] = 2;
  64314. t[1] = x1;
  64315. t[2] = y2 - y1;
  64316. t[3] = x2;
  64317. t[4] = 0;
  64318. ++lineY;
  64319. t += lineStrideElements;
  64320. }
  64321. else
  64322. {
  64323. t[0] = 2;
  64324. t[1] = x1;
  64325. t[2] = 255 - (y1 & 255);
  64326. t[3] = x2;
  64327. t[4] = 0;
  64328. ++lineY;
  64329. t += lineStrideElements;
  64330. while (lineY < (y2 >> 8))
  64331. {
  64332. t[0] = 2;
  64333. t[1] = x1;
  64334. t[2] = 255;
  64335. t[3] = x2;
  64336. t[4] = 0;
  64337. ++lineY;
  64338. t += lineStrideElements;
  64339. }
  64340. jassert (lineY < bounds.getHeight());
  64341. t[0] = 2;
  64342. t[1] = x1;
  64343. t[2] = y2 & 255;
  64344. t[3] = x2;
  64345. t[4] = 0;
  64346. ++lineY;
  64347. t += lineStrideElements;
  64348. }
  64349. while (lineY < bounds.getHeight())
  64350. {
  64351. t[0] = 0;
  64352. t += lineStrideElements;
  64353. ++lineY;
  64354. }
  64355. }
  64356. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64357. : table (0)
  64358. {
  64359. operator= (other);
  64360. }
  64361. const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64362. {
  64363. bounds = other.bounds;
  64364. maxEdgesPerLine = other.maxEdgesPerLine;
  64365. lineStrideElements = other.lineStrideElements;
  64366. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64367. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64368. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64369. return *this;
  64370. }
  64371. EdgeTable::~EdgeTable() throw()
  64372. {
  64373. }
  64374. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64375. {
  64376. // Convert the table from relative windings to absolute levels..
  64377. int* lineStart = table;
  64378. for (int i = bounds.getHeight(); --i >= 0;)
  64379. {
  64380. int* line = lineStart;
  64381. lineStart += lineStrideElements;
  64382. int num = *line;
  64383. if (num == 0)
  64384. continue;
  64385. int level = 0;
  64386. if (useNonZeroWinding)
  64387. {
  64388. while (--num > 0)
  64389. {
  64390. line += 2;
  64391. level += *line;
  64392. int corrected = abs (level);
  64393. if (corrected >> 8)
  64394. corrected = 255;
  64395. *line = corrected;
  64396. }
  64397. }
  64398. else
  64399. {
  64400. while (--num > 0)
  64401. {
  64402. line += 2;
  64403. level += *line;
  64404. int corrected = abs (level);
  64405. if (corrected >> 8)
  64406. {
  64407. corrected &= 511;
  64408. if (corrected >> 8)
  64409. corrected = 511 - corrected;
  64410. }
  64411. *line = corrected;
  64412. }
  64413. }
  64414. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64415. }
  64416. }
  64417. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64418. {
  64419. if (newNumEdgesPerLine != maxEdgesPerLine)
  64420. {
  64421. maxEdgesPerLine = newNumEdgesPerLine;
  64422. jassert (bounds.getHeight() > 0);
  64423. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64424. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64425. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64426. table.swapWith (newTable);
  64427. lineStrideElements = newLineStrideElements;
  64428. }
  64429. }
  64430. void EdgeTable::optimiseTable() throw()
  64431. {
  64432. int maxLineElements = 0;
  64433. for (int i = bounds.getHeight(); --i >= 0;)
  64434. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64435. remapTableForNumEdges (maxLineElements);
  64436. }
  64437. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64438. {
  64439. jassert (y >= 0 && y < bounds.getHeight());
  64440. int* line = table + lineStrideElements * y;
  64441. const int numPoints = line[0];
  64442. int n = numPoints << 1;
  64443. if (n > 0)
  64444. {
  64445. while (n > 0)
  64446. {
  64447. const int cx = line [n - 1];
  64448. if (cx <= x)
  64449. {
  64450. if (cx == x)
  64451. {
  64452. line [n] += winding;
  64453. return;
  64454. }
  64455. break;
  64456. }
  64457. n -= 2;
  64458. }
  64459. if (numPoints >= maxEdgesPerLine)
  64460. {
  64461. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64462. jassert (numPoints < maxEdgesPerLine);
  64463. line = table + lineStrideElements * y;
  64464. }
  64465. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64466. }
  64467. line [n + 1] = x;
  64468. line [n + 2] = winding;
  64469. line[0]++;
  64470. }
  64471. void EdgeTable::translate (float dx, int dy) throw()
  64472. {
  64473. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64474. int* lineStart = table;
  64475. const int intDx = (int) (dx * 256.0f);
  64476. for (int i = bounds.getHeight(); --i >= 0;)
  64477. {
  64478. int* line = lineStart;
  64479. lineStart += lineStrideElements;
  64480. int num = *line++;
  64481. while (--num >= 0)
  64482. {
  64483. *line += intDx;
  64484. line += 2;
  64485. }
  64486. }
  64487. }
  64488. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64489. {
  64490. jassert (y >= 0 && y < bounds.getHeight());
  64491. int* dest = table + lineStrideElements * y;
  64492. if (dest[0] == 0)
  64493. return;
  64494. int otherNumPoints = *otherLine;
  64495. if (otherNumPoints == 0)
  64496. {
  64497. *dest = 0;
  64498. return;
  64499. }
  64500. const int right = bounds.getRight() << 8;
  64501. // optimise for the common case where our line lies entirely within a
  64502. // single pair of points, as happens when clipping to a simple rect.
  64503. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64504. {
  64505. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64506. return;
  64507. }
  64508. ++otherLine;
  64509. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64510. int* temp = (int*) alloca (lineSizeBytes);
  64511. memcpy (temp, dest, lineSizeBytes);
  64512. const int* src1 = temp;
  64513. int srcNum1 = *src1++;
  64514. int x1 = *src1++;
  64515. const int* src2 = otherLine;
  64516. int srcNum2 = otherNumPoints;
  64517. int x2 = *src2++;
  64518. int destIndex = 0, destTotal = 0;
  64519. int level1 = 0, level2 = 0;
  64520. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64521. while (srcNum1 > 0 && srcNum2 > 0)
  64522. {
  64523. int nextX;
  64524. if (x1 < x2)
  64525. {
  64526. nextX = x1;
  64527. level1 = *src1++;
  64528. x1 = *src1++;
  64529. --srcNum1;
  64530. }
  64531. else if (x1 == x2)
  64532. {
  64533. nextX = x1;
  64534. level1 = *src1++;
  64535. level2 = *src2++;
  64536. x1 = *src1++;
  64537. x2 = *src2++;
  64538. --srcNum1;
  64539. --srcNum2;
  64540. }
  64541. else
  64542. {
  64543. nextX = x2;
  64544. level2 = *src2++;
  64545. x2 = *src2++;
  64546. --srcNum2;
  64547. }
  64548. if (nextX > lastX)
  64549. {
  64550. if (nextX >= right)
  64551. break;
  64552. lastX = nextX;
  64553. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64554. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64555. if (nextLevel != lastLevel)
  64556. {
  64557. if (destTotal >= maxEdgesPerLine)
  64558. {
  64559. dest[0] = destTotal;
  64560. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64561. dest = table + lineStrideElements * y;
  64562. }
  64563. ++destTotal;
  64564. lastLevel = nextLevel;
  64565. dest[++destIndex] = nextX;
  64566. dest[++destIndex] = nextLevel;
  64567. }
  64568. }
  64569. }
  64570. if (lastLevel > 0)
  64571. {
  64572. if (destTotal >= maxEdgesPerLine)
  64573. {
  64574. dest[0] = destTotal;
  64575. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64576. dest = table + lineStrideElements * y;
  64577. }
  64578. ++destTotal;
  64579. dest[++destIndex] = right;
  64580. dest[++destIndex] = 0;
  64581. }
  64582. dest[0] = destTotal;
  64583. #if JUCE_DEBUG
  64584. int last = std::numeric_limits<int>::min();
  64585. for (int i = 0; i < dest[0]; ++i)
  64586. {
  64587. jassert (dest[i * 2 + 1] > last);
  64588. last = dest[i * 2 + 1];
  64589. }
  64590. jassert (dest [dest[0] * 2] == 0);
  64591. #endif
  64592. }
  64593. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64594. {
  64595. int* lastItem = dest + (dest[0] * 2 - 1);
  64596. if (x2 < lastItem[0])
  64597. {
  64598. if (x2 <= dest[1])
  64599. {
  64600. dest[0] = 0;
  64601. return;
  64602. }
  64603. while (x2 < lastItem[-2])
  64604. {
  64605. --(dest[0]);
  64606. lastItem -= 2;
  64607. }
  64608. lastItem[0] = x2;
  64609. lastItem[1] = 0;
  64610. }
  64611. if (x1 > dest[1])
  64612. {
  64613. while (lastItem[0] > x1)
  64614. lastItem -= 2;
  64615. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64616. if (itemsRemoved > 0)
  64617. {
  64618. dest[0] -= itemsRemoved;
  64619. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64620. }
  64621. dest[1] = x1;
  64622. }
  64623. }
  64624. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64625. {
  64626. const Rectangle<int> clipped (r.getIntersection (bounds));
  64627. if (clipped.isEmpty())
  64628. {
  64629. needToCheckEmptinesss = false;
  64630. bounds.setHeight (0);
  64631. }
  64632. else
  64633. {
  64634. const int top = clipped.getY() - bounds.getY();
  64635. const int bottom = clipped.getBottom() - bounds.getY();
  64636. if (bottom < bounds.getHeight())
  64637. bounds.setHeight (bottom);
  64638. if (clipped.getRight() < bounds.getRight())
  64639. bounds.setRight (clipped.getRight());
  64640. for (int i = top; --i >= 0;)
  64641. table [lineStrideElements * i] = 0;
  64642. if (clipped.getX() > bounds.getX())
  64643. {
  64644. const int x1 = clipped.getX() << 8;
  64645. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64646. int* line = table + lineStrideElements * top;
  64647. for (int i = bottom - top; --i >= 0;)
  64648. {
  64649. if (line[0] != 0)
  64650. clipEdgeTableLineToRange (line, x1, x2);
  64651. line += lineStrideElements;
  64652. }
  64653. }
  64654. needToCheckEmptinesss = true;
  64655. }
  64656. }
  64657. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64658. {
  64659. const Rectangle<int> clipped (r.getIntersection (bounds));
  64660. if (! clipped.isEmpty())
  64661. {
  64662. const int top = clipped.getY() - bounds.getY();
  64663. const int bottom = clipped.getBottom() - bounds.getY();
  64664. //XXX optimise here by shortening the table if it fills top or bottom
  64665. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64666. clipped.getX() << 8, 0,
  64667. clipped.getRight() << 8, 255,
  64668. std::numeric_limits<int>::max(), 0 };
  64669. for (int i = top; i < bottom; ++i)
  64670. intersectWithEdgeTableLine (i, rectLine);
  64671. needToCheckEmptinesss = true;
  64672. }
  64673. }
  64674. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64675. {
  64676. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64677. if (clipped.isEmpty())
  64678. {
  64679. needToCheckEmptinesss = false;
  64680. bounds.setHeight (0);
  64681. }
  64682. else
  64683. {
  64684. const int top = clipped.getY() - bounds.getY();
  64685. const int bottom = clipped.getBottom() - bounds.getY();
  64686. if (bottom < bounds.getHeight())
  64687. bounds.setHeight (bottom);
  64688. if (clipped.getRight() < bounds.getRight())
  64689. bounds.setRight (clipped.getRight());
  64690. int i = 0;
  64691. for (i = top; --i >= 0;)
  64692. table [lineStrideElements * i] = 0;
  64693. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64694. for (i = top; i < bottom; ++i)
  64695. {
  64696. intersectWithEdgeTableLine (i, otherLine);
  64697. otherLine += other.lineStrideElements;
  64698. }
  64699. needToCheckEmptinesss = true;
  64700. }
  64701. }
  64702. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64703. {
  64704. y -= bounds.getY();
  64705. if (y < 0 || y >= bounds.getHeight())
  64706. return;
  64707. needToCheckEmptinesss = true;
  64708. if (numPixels <= 0)
  64709. {
  64710. table [lineStrideElements * y] = 0;
  64711. return;
  64712. }
  64713. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64714. int destIndex = 0, lastLevel = 0;
  64715. while (--numPixels >= 0)
  64716. {
  64717. const int alpha = *mask;
  64718. mask += maskStride;
  64719. if (alpha != lastLevel)
  64720. {
  64721. tempLine[++destIndex] = (x << 8);
  64722. tempLine[++destIndex] = alpha;
  64723. lastLevel = alpha;
  64724. }
  64725. ++x;
  64726. }
  64727. if (lastLevel > 0)
  64728. {
  64729. tempLine[++destIndex] = (x << 8);
  64730. tempLine[++destIndex] = 0;
  64731. }
  64732. tempLine[0] = destIndex >> 1;
  64733. intersectWithEdgeTableLine (y, tempLine);
  64734. }
  64735. bool EdgeTable::isEmpty() throw()
  64736. {
  64737. if (needToCheckEmptinesss)
  64738. {
  64739. needToCheckEmptinesss = false;
  64740. int* t = table;
  64741. for (int i = bounds.getHeight(); --i >= 0;)
  64742. {
  64743. if (t[0] > 1)
  64744. return false;
  64745. t += lineStrideElements;
  64746. }
  64747. bounds.setHeight (0);
  64748. }
  64749. return bounds.getHeight() == 0;
  64750. }
  64751. END_JUCE_NAMESPACE
  64752. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64753. /*** Start of inlined file: juce_FillType.cpp ***/
  64754. BEGIN_JUCE_NAMESPACE
  64755. FillType::FillType() throw()
  64756. : colour (0xff000000), image (0)
  64757. {
  64758. }
  64759. FillType::FillType (const Colour& colour_) throw()
  64760. : colour (colour_), image (0)
  64761. {
  64762. }
  64763. FillType::FillType (const ColourGradient& gradient_) throw()
  64764. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64765. {
  64766. }
  64767. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64768. : colour (0xff000000), image (&image_), transform (transform_)
  64769. {
  64770. }
  64771. FillType::FillType (const FillType& other) throw()
  64772. : colour (other.colour),
  64773. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64774. image (other.image), transform (other.transform)
  64775. {
  64776. }
  64777. const FillType& FillType::operator= (const FillType& other) throw()
  64778. {
  64779. if (this != &other)
  64780. {
  64781. colour = other.colour;
  64782. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64783. image = other.image;
  64784. transform = other.transform;
  64785. }
  64786. return *this;
  64787. }
  64788. FillType::~FillType() throw()
  64789. {
  64790. }
  64791. void FillType::setColour (const Colour& newColour) throw()
  64792. {
  64793. gradient = 0;
  64794. image = 0;
  64795. colour = newColour;
  64796. }
  64797. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64798. {
  64799. if (gradient != 0)
  64800. {
  64801. *gradient = newGradient;
  64802. }
  64803. else
  64804. {
  64805. image = 0;
  64806. gradient = new ColourGradient (newGradient);
  64807. colour = Colours::black;
  64808. }
  64809. }
  64810. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64811. {
  64812. gradient = 0;
  64813. image = &image_;
  64814. transform = transform_;
  64815. colour = Colours::black;
  64816. }
  64817. void FillType::setOpacity (const float newOpacity) throw()
  64818. {
  64819. colour = colour.withAlpha (newOpacity);
  64820. }
  64821. END_JUCE_NAMESPACE
  64822. /*** End of inlined file: juce_FillType.cpp ***/
  64823. /*** Start of inlined file: juce_Graphics.cpp ***/
  64824. BEGIN_JUCE_NAMESPACE
  64825. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64826. template <typename Type>
  64827. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64828. {
  64829. const int maxVal = 0x3fffffff;
  64830. return (int) x >= -maxVal && (int) x <= maxVal
  64831. && (int) y >= -maxVal && (int) y <= maxVal
  64832. && (int) w >= -maxVal && (int) w <= maxVal
  64833. && (int) h >= -maxVal && (int) h <= maxVal;
  64834. }
  64835. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64836. {
  64837. }
  64838. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64839. {
  64840. }
  64841. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64842. : context (imageToDrawOnto.createLowLevelContext()),
  64843. contextToDelete (context),
  64844. saveStatePending (false)
  64845. {
  64846. resetToDefaultState();
  64847. }
  64848. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64849. : context (internalContext),
  64850. saveStatePending (false)
  64851. {
  64852. resetToDefaultState();
  64853. }
  64854. Graphics::~Graphics() throw()
  64855. {
  64856. }
  64857. void Graphics::resetToDefaultState() throw()
  64858. {
  64859. saveStateIfPending();
  64860. context->setFill (FillType());
  64861. context->setFont (Font());
  64862. context->setInterpolationQuality (defaultQuality);
  64863. }
  64864. bool Graphics::isVectorDevice() const throw()
  64865. {
  64866. return context->isVectorDevice();
  64867. }
  64868. bool Graphics::reduceClipRegion (const int x, const int y,
  64869. const int w, const int h) throw()
  64870. {
  64871. saveStateIfPending();
  64872. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64873. }
  64874. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64875. {
  64876. saveStateIfPending();
  64877. return context->clipToRectangleList (clipRegion);
  64878. }
  64879. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64880. {
  64881. saveStateIfPending();
  64882. context->clipToPath (path, transform);
  64883. return ! context->isClipEmpty();
  64884. }
  64885. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64886. {
  64887. saveStateIfPending();
  64888. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64889. return ! context->isClipEmpty();
  64890. }
  64891. void Graphics::excludeClipRegion (const int x, const int y,
  64892. const int w, const int h) throw()
  64893. {
  64894. saveStateIfPending();
  64895. context->excludeClipRectangle (Rectangle<int> (x, y, w, h));
  64896. }
  64897. bool Graphics::isClipEmpty() const throw()
  64898. {
  64899. return context->isClipEmpty();
  64900. }
  64901. const Rectangle<int> Graphics::getClipBounds() const throw()
  64902. {
  64903. return context->getClipBounds();
  64904. }
  64905. void Graphics::saveState() throw()
  64906. {
  64907. saveStateIfPending();
  64908. saveStatePending = true;
  64909. }
  64910. void Graphics::restoreState() throw()
  64911. {
  64912. if (saveStatePending)
  64913. saveStatePending = false;
  64914. else
  64915. context->restoreState();
  64916. }
  64917. void Graphics::saveStateIfPending() throw()
  64918. {
  64919. if (saveStatePending)
  64920. {
  64921. saveStatePending = false;
  64922. context->saveState();
  64923. }
  64924. }
  64925. void Graphics::setOrigin (const int newOriginX,
  64926. const int newOriginY) throw()
  64927. {
  64928. saveStateIfPending();
  64929. context->setOrigin (newOriginX, newOriginY);
  64930. }
  64931. bool Graphics::clipRegionIntersects (const int x, const int y,
  64932. const int w, const int h) const throw()
  64933. {
  64934. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64935. }
  64936. void Graphics::setColour (const Colour& newColour) throw()
  64937. {
  64938. saveStateIfPending();
  64939. context->setFill (FillType (newColour));
  64940. }
  64941. void Graphics::setOpacity (const float newOpacity) throw()
  64942. {
  64943. saveStateIfPending();
  64944. context->setOpacity (newOpacity);
  64945. }
  64946. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64947. {
  64948. saveStateIfPending();
  64949. context->setFill (FillType (gradient));
  64950. }
  64951. void Graphics::setTiledImageFill (const Image& imageToUse,
  64952. const int anchorX,
  64953. const int anchorY,
  64954. const float opacity) throw()
  64955. {
  64956. saveStateIfPending();
  64957. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64958. context->setOpacity (opacity);
  64959. }
  64960. void Graphics::setFillType (const FillType& newFill) throw()
  64961. {
  64962. saveStateIfPending();
  64963. context->setFill (newFill);
  64964. }
  64965. void Graphics::setFont (const Font& newFont) throw()
  64966. {
  64967. saveStateIfPending();
  64968. context->setFont (newFont);
  64969. }
  64970. void Graphics::setFont (const float newFontHeight,
  64971. const int newFontStyleFlags) throw()
  64972. {
  64973. saveStateIfPending();
  64974. Font f (context->getFont());
  64975. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64976. context->setFont (f);
  64977. }
  64978. void Graphics::drawSingleLineText (const String& text,
  64979. const int startX,
  64980. const int baselineY) const throw()
  64981. {
  64982. if (text.isNotEmpty()
  64983. && startX < context->getClipBounds().getRight())
  64984. {
  64985. GlyphArrangement arr;
  64986. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64987. arr.draw (*this);
  64988. }
  64989. }
  64990. void Graphics::drawTextAsPath (const String& text,
  64991. const AffineTransform& transform) const throw()
  64992. {
  64993. if (text.isNotEmpty())
  64994. {
  64995. GlyphArrangement arr;
  64996. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64997. arr.draw (*this, transform);
  64998. }
  64999. }
  65000. void Graphics::drawMultiLineText (const String& text,
  65001. const int startX,
  65002. const int baselineY,
  65003. const int maximumLineWidth) const throw()
  65004. {
  65005. if (text.isNotEmpty()
  65006. && startX < context->getClipBounds().getRight())
  65007. {
  65008. GlyphArrangement arr;
  65009. arr.addJustifiedText (context->getFont(), text,
  65010. (float) startX, (float) baselineY, (float) maximumLineWidth,
  65011. Justification::left);
  65012. arr.draw (*this);
  65013. }
  65014. }
  65015. void Graphics::drawText (const String& text,
  65016. const int x,
  65017. const int y,
  65018. const int width,
  65019. const int height,
  65020. const Justification& justificationType,
  65021. const bool useEllipsesIfTooBig) const throw()
  65022. {
  65023. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  65024. {
  65025. GlyphArrangement arr;
  65026. arr.addCurtailedLineOfText (context->getFont(), text,
  65027. 0.0f, 0.0f, (float)width,
  65028. useEllipsesIfTooBig);
  65029. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  65030. (float) x, (float) y,
  65031. (float) width, (float) height,
  65032. justificationType);
  65033. arr.draw (*this);
  65034. }
  65035. }
  65036. void Graphics::drawFittedText (const String& text,
  65037. const int x,
  65038. const int y,
  65039. const int width,
  65040. const int height,
  65041. const Justification& justification,
  65042. const int maximumNumberOfLines,
  65043. const float minimumHorizontalScale) const throw()
  65044. {
  65045. if (text.isNotEmpty()
  65046. && width > 0 && height > 0
  65047. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  65048. {
  65049. GlyphArrangement arr;
  65050. arr.addFittedText (context->getFont(), text,
  65051. (float) x, (float) y,
  65052. (float) width, (float) height,
  65053. justification,
  65054. maximumNumberOfLines,
  65055. minimumHorizontalScale);
  65056. arr.draw (*this);
  65057. }
  65058. }
  65059. void Graphics::fillRect (int x,
  65060. int y,
  65061. int width,
  65062. int height) const throw()
  65063. {
  65064. // passing in a silly number can cause maths problems in rendering!
  65065. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65066. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65067. }
  65068. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  65069. {
  65070. context->fillRect (r, false);
  65071. }
  65072. void Graphics::fillRect (const float x,
  65073. const float y,
  65074. const float width,
  65075. const float height) const throw()
  65076. {
  65077. // passing in a silly number can cause maths problems in rendering!
  65078. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65079. Path p;
  65080. p.addRectangle (x, y, width, height);
  65081. fillPath (p);
  65082. }
  65083. void Graphics::setPixel (int x, int y) const throw()
  65084. {
  65085. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  65086. }
  65087. void Graphics::fillAll() const throw()
  65088. {
  65089. fillRect (context->getClipBounds());
  65090. }
  65091. void Graphics::fillAll (const Colour& colourToUse) const throw()
  65092. {
  65093. if (! colourToUse.isTransparent())
  65094. {
  65095. const Rectangle<int> clip (context->getClipBounds());
  65096. context->saveState();
  65097. context->setFill (FillType (colourToUse));
  65098. context->fillRect (clip, false);
  65099. context->restoreState();
  65100. }
  65101. }
  65102. void Graphics::fillPath (const Path& path,
  65103. const AffineTransform& transform) const throw()
  65104. {
  65105. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65106. context->fillPath (path, transform);
  65107. }
  65108. void Graphics::strokePath (const Path& path,
  65109. const PathStrokeType& strokeType,
  65110. const AffineTransform& transform) const throw()
  65111. {
  65112. Path stroke;
  65113. strokeType.createStrokedPath (stroke, path, transform);
  65114. fillPath (stroke);
  65115. }
  65116. void Graphics::drawRect (const int x,
  65117. const int y,
  65118. const int width,
  65119. const int height,
  65120. const int lineThickness) const throw()
  65121. {
  65122. // passing in a silly number can cause maths problems in rendering!
  65123. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65124. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  65125. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65126. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65127. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  65128. }
  65129. void Graphics::drawRect (const float x,
  65130. const float y,
  65131. const float width,
  65132. const float height,
  65133. const float lineThickness) const throw()
  65134. {
  65135. // passing in a silly number can cause maths problems in rendering!
  65136. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65137. Path p;
  65138. p.addRectangle (x, y, width, lineThickness);
  65139. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65140. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65141. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65142. fillPath (p);
  65143. }
  65144. void Graphics::drawRect (const Rectangle<int>& r,
  65145. const int lineThickness) const throw()
  65146. {
  65147. drawRect (r.getX(), r.getY(),
  65148. r.getWidth(), r.getHeight(),
  65149. lineThickness);
  65150. }
  65151. void Graphics::drawBevel (const int x,
  65152. const int y,
  65153. const int width,
  65154. const int height,
  65155. const int bevelThickness,
  65156. const Colour& topLeftColour,
  65157. const Colour& bottomRightColour,
  65158. const bool useGradient,
  65159. const bool sharpEdgeOnOutside) const throw()
  65160. {
  65161. // passing in a silly number can cause maths problems in rendering!
  65162. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65163. if (clipRegionIntersects (x, y, width, height))
  65164. {
  65165. context->saveState();
  65166. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65167. const float ramp = oldOpacity / bevelThickness;
  65168. for (int i = bevelThickness; --i >= 0;)
  65169. {
  65170. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65171. : oldOpacity;
  65172. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65173. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  65174. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65175. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65176. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65177. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  65178. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65179. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65180. }
  65181. context->restoreState();
  65182. }
  65183. }
  65184. void Graphics::fillEllipse (const float x,
  65185. const float y,
  65186. const float width,
  65187. const float height) const throw()
  65188. {
  65189. // passing in a silly number can cause maths problems in rendering!
  65190. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65191. Path p;
  65192. p.addEllipse (x, y, width, height);
  65193. fillPath (p);
  65194. }
  65195. void Graphics::drawEllipse (const float x,
  65196. const float y,
  65197. const float width,
  65198. const float height,
  65199. const float lineThickness) const throw()
  65200. {
  65201. // passing in a silly number can cause maths problems in rendering!
  65202. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65203. Path p;
  65204. p.addEllipse (x, y, width, height);
  65205. strokePath (p, PathStrokeType (lineThickness));
  65206. }
  65207. void Graphics::fillRoundedRectangle (const float x,
  65208. const float y,
  65209. const float width,
  65210. const float height,
  65211. const float cornerSize) const throw()
  65212. {
  65213. // passing in a silly number can cause maths problems in rendering!
  65214. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65215. Path p;
  65216. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65217. fillPath (p);
  65218. }
  65219. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  65220. const float cornerSize) const throw()
  65221. {
  65222. fillRoundedRectangle ((float) r.getX(),
  65223. (float) r.getY(),
  65224. (float) r.getWidth(),
  65225. (float) r.getHeight(),
  65226. cornerSize);
  65227. }
  65228. void Graphics::drawRoundedRectangle (const float x,
  65229. const float y,
  65230. const float width,
  65231. const float height,
  65232. const float cornerSize,
  65233. const float lineThickness) const throw()
  65234. {
  65235. // passing in a silly number can cause maths problems in rendering!
  65236. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65237. Path p;
  65238. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65239. strokePath (p, PathStrokeType (lineThickness));
  65240. }
  65241. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  65242. const float cornerSize,
  65243. const float lineThickness) const throw()
  65244. {
  65245. drawRoundedRectangle ((float) r.getX(),
  65246. (float) r.getY(),
  65247. (float) r.getWidth(),
  65248. (float) r.getHeight(),
  65249. cornerSize, lineThickness);
  65250. }
  65251. void Graphics::drawArrow (const float startX,
  65252. const float startY,
  65253. const float endX,
  65254. const float endY,
  65255. const float lineThickness,
  65256. const float arrowheadWidth,
  65257. const float arrowheadLength) const throw()
  65258. {
  65259. Path p;
  65260. p.addArrow (startX, startY, endX, endY,
  65261. lineThickness, arrowheadWidth, arrowheadLength);
  65262. fillPath (p);
  65263. }
  65264. void Graphics::fillCheckerBoard (int x, int y,
  65265. int width, int height,
  65266. const int checkWidth,
  65267. const int checkHeight,
  65268. const Colour& colour1,
  65269. const Colour& colour2) const throw()
  65270. {
  65271. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65272. if (checkWidth > 0 && checkHeight > 0)
  65273. {
  65274. context->saveState();
  65275. if (colour1 == colour2)
  65276. {
  65277. context->setFill (FillType (colour1));
  65278. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65279. }
  65280. else
  65281. {
  65282. const Rectangle<int> clip (context->getClipBounds());
  65283. const int right = jmin (x + width, clip.getRight());
  65284. const int bottom = jmin (y + height, clip.getBottom());
  65285. int cy = 0;
  65286. while (y < bottom)
  65287. {
  65288. int cx = cy;
  65289. for (int xx = x; xx < right; xx += checkWidth)
  65290. {
  65291. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65292. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65293. false);
  65294. }
  65295. ++cy;
  65296. y += checkHeight;
  65297. }
  65298. }
  65299. context->restoreState();
  65300. }
  65301. }
  65302. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65303. {
  65304. context->drawVerticalLine (x, top, bottom);
  65305. }
  65306. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65307. {
  65308. context->drawHorizontalLine (y, left, right);
  65309. }
  65310. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65311. {
  65312. context->drawLine (x1, y1, x2, y2);
  65313. }
  65314. void Graphics::drawLine (const float startX,
  65315. const float startY,
  65316. const float endX,
  65317. const float endY,
  65318. const float lineThickness) const throw()
  65319. {
  65320. Path p;
  65321. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65322. fillPath (p);
  65323. }
  65324. void Graphics::drawLine (const Line& line) const throw()
  65325. {
  65326. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65327. }
  65328. void Graphics::drawLine (const Line& line,
  65329. const float lineThickness) const throw()
  65330. {
  65331. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65332. }
  65333. void Graphics::drawDashedLine (const float startX,
  65334. const float startY,
  65335. const float endX,
  65336. const float endY,
  65337. const float* const dashLengths,
  65338. const int numDashLengths,
  65339. const float lineThickness) const throw()
  65340. {
  65341. const double dx = endX - startX;
  65342. const double dy = endY - startY;
  65343. const double totalLen = juce_hypot (dx, dy);
  65344. if (totalLen >= 0.5)
  65345. {
  65346. const double onePixAlpha = 1.0 / totalLen;
  65347. double alpha = 0.0;
  65348. float x = startX;
  65349. float y = startY;
  65350. int n = 0;
  65351. while (alpha < 1.0f)
  65352. {
  65353. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65354. n = n % numDashLengths;
  65355. const float oldX = x;
  65356. const float oldY = y;
  65357. x = (float) (startX + dx * alpha);
  65358. y = (float) (startY + dy * alpha);
  65359. if ((n & 1) != 0)
  65360. {
  65361. if (lineThickness != 1.0f)
  65362. drawLine (oldX, oldY, x, y, lineThickness);
  65363. else
  65364. drawLine (oldX, oldY, x, y);
  65365. }
  65366. }
  65367. }
  65368. }
  65369. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65370. {
  65371. saveStateIfPending();
  65372. context->setInterpolationQuality (newQuality);
  65373. }
  65374. void Graphics::drawImageAt (const Image* const imageToDraw,
  65375. const int topLeftX,
  65376. const int topLeftY,
  65377. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65378. {
  65379. if (imageToDraw != 0)
  65380. {
  65381. const int imageW = imageToDraw->getWidth();
  65382. const int imageH = imageToDraw->getHeight();
  65383. drawImage (imageToDraw,
  65384. topLeftX, topLeftY, imageW, imageH,
  65385. 0, 0, imageW, imageH,
  65386. fillAlphaChannelWithCurrentBrush);
  65387. }
  65388. }
  65389. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65390. const int destX,
  65391. const int destY,
  65392. const int destW,
  65393. const int destH,
  65394. const RectanglePlacement& placementWithinTarget,
  65395. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65396. {
  65397. // passing in a silly number can cause maths problems in rendering!
  65398. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65399. if (imageToDraw != 0)
  65400. {
  65401. const int imageW = imageToDraw->getWidth();
  65402. const int imageH = imageToDraw->getHeight();
  65403. if (imageW > 0 && imageH > 0)
  65404. {
  65405. double newX = 0.0, newY = 0.0;
  65406. double newW = imageW;
  65407. double newH = imageH;
  65408. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65409. destX, destY, destW, destH);
  65410. if (newW > 0 && newH > 0)
  65411. {
  65412. drawImage (imageToDraw,
  65413. roundToInt (newX), roundToInt (newY),
  65414. roundToInt (newW), roundToInt (newH),
  65415. 0, 0, imageW, imageH,
  65416. fillAlphaChannelWithCurrentBrush);
  65417. }
  65418. }
  65419. }
  65420. }
  65421. void Graphics::drawImage (const Image* const imageToDraw,
  65422. int dx, int dy, int dw, int dh,
  65423. int sx, int sy, int sw, int sh,
  65424. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65425. {
  65426. // passing in a silly number can cause maths problems in rendering!
  65427. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65428. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65429. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65430. {
  65431. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65432. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65433. .translated ((float) dx, (float) dy),
  65434. fillAlphaChannelWithCurrentBrush);
  65435. }
  65436. }
  65437. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65438. const Rectangle<int>& imageSubRegion,
  65439. const AffineTransform& transform,
  65440. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65441. {
  65442. if (imageToDraw != 0 && ! context->isClipEmpty())
  65443. {
  65444. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65445. if (fillAlphaChannelWithCurrentBrush)
  65446. {
  65447. context->saveState();
  65448. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65449. fillAll();
  65450. context->restoreState();
  65451. }
  65452. else
  65453. {
  65454. context->drawImage (*imageToDraw, srcClip, transform, false);
  65455. }
  65456. }
  65457. }
  65458. END_JUCE_NAMESPACE
  65459. /*** End of inlined file: juce_Graphics.cpp ***/
  65460. /*** Start of inlined file: juce_Justification.cpp ***/
  65461. BEGIN_JUCE_NAMESPACE
  65462. Justification::Justification (const Justification& other) throw()
  65463. : flags (other.flags)
  65464. {
  65465. }
  65466. const Justification& Justification::operator= (const Justification& other) throw()
  65467. {
  65468. flags = other.flags;
  65469. return *this;
  65470. }
  65471. int Justification::getOnlyVerticalFlags() const throw()
  65472. {
  65473. return flags & (top | bottom | verticallyCentred);
  65474. }
  65475. int Justification::getOnlyHorizontalFlags() const throw()
  65476. {
  65477. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65478. }
  65479. void Justification::applyToRectangle (int& x, int& y,
  65480. const int w, const int h,
  65481. const int spaceX, const int spaceY,
  65482. const int spaceW, const int spaceH) const throw()
  65483. {
  65484. if ((flags & horizontallyCentred) != 0)
  65485. {
  65486. x = spaceX + ((spaceW - w) >> 1);
  65487. }
  65488. else if ((flags & right) != 0)
  65489. {
  65490. x = spaceX + spaceW - w;
  65491. }
  65492. else
  65493. {
  65494. x = spaceX;
  65495. }
  65496. if ((flags & verticallyCentred) != 0)
  65497. {
  65498. y = spaceY + ((spaceH - h) >> 1);
  65499. }
  65500. else if ((flags & bottom) != 0)
  65501. {
  65502. y = spaceY + spaceH - h;
  65503. }
  65504. else
  65505. {
  65506. y = spaceY;
  65507. }
  65508. }
  65509. END_JUCE_NAMESPACE
  65510. /*** End of inlined file: juce_Justification.cpp ***/
  65511. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65512. BEGIN_JUCE_NAMESPACE
  65513. // this will throw an assertion if you try to draw something that's not
  65514. // possible in postscript
  65515. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65516. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65517. #define notPossibleInPostscriptAssert jassertfalse
  65518. #else
  65519. #define notPossibleInPostscriptAssert
  65520. #endif
  65521. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65522. const String& documentTitle,
  65523. const int totalWidth_,
  65524. const int totalHeight_)
  65525. : out (resultingPostScript),
  65526. totalWidth (totalWidth_),
  65527. totalHeight (totalHeight_),
  65528. needToClip (true)
  65529. {
  65530. stateStack.add (new SavedState());
  65531. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65532. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65533. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65534. "\n%%BoundingBox: 0 0 600 824"
  65535. "\n%%Pages: 0"
  65536. "\n%%Creator: Raw Material Software JUCE"
  65537. "\n%%Title: " << documentTitle <<
  65538. "\n%%CreationDate: none"
  65539. "\n%%LanguageLevel: 2"
  65540. "\n%%EndComments"
  65541. "\n%%BeginProlog"
  65542. "\n%%BeginResource: JRes"
  65543. "\n/bd {bind def} bind def"
  65544. "\n/c {setrgbcolor} bd"
  65545. "\n/m {moveto} bd"
  65546. "\n/l {lineto} bd"
  65547. "\n/rl {rlineto} bd"
  65548. "\n/ct {curveto} bd"
  65549. "\n/cp {closepath} bd"
  65550. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65551. "\n/doclip {initclip newpath} bd"
  65552. "\n/endclip {clip newpath} bd"
  65553. "\n%%EndResource"
  65554. "\n%%EndProlog"
  65555. "\n%%BeginSetup"
  65556. "\n%%EndSetup"
  65557. "\n%%Page: 1 1"
  65558. "\n%%BeginPageSetup"
  65559. "\n%%EndPageSetup\n\n"
  65560. << "40 800 translate\n"
  65561. << scale << ' ' << scale << " scale\n\n";
  65562. }
  65563. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65564. {
  65565. }
  65566. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65567. {
  65568. return true;
  65569. }
  65570. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65571. {
  65572. if (x != 0 || y != 0)
  65573. {
  65574. stateStack.getLast()->xOffset += x;
  65575. stateStack.getLast()->yOffset += y;
  65576. needToClip = true;
  65577. }
  65578. }
  65579. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65580. {
  65581. needToClip = true;
  65582. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65583. }
  65584. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65585. {
  65586. needToClip = true;
  65587. return stateStack.getLast()->clip.clipTo (clipRegion);
  65588. }
  65589. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65590. {
  65591. needToClip = true;
  65592. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65593. }
  65594. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65595. {
  65596. writeClip();
  65597. Path p (path);
  65598. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65599. writePath (p);
  65600. out << "clip\n";
  65601. }
  65602. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65603. {
  65604. needToClip = true;
  65605. jassertfalse // xxx
  65606. }
  65607. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65608. {
  65609. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65610. }
  65611. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65612. {
  65613. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65614. -stateStack.getLast()->yOffset);
  65615. }
  65616. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65617. {
  65618. return stateStack.getLast()->clip.isEmpty();
  65619. }
  65620. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65621. : xOffset (0),
  65622. yOffset (0)
  65623. {
  65624. }
  65625. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65626. {
  65627. }
  65628. void LowLevelGraphicsPostScriptRenderer::saveState()
  65629. {
  65630. stateStack.add (new SavedState (*stateStack.getLast()));
  65631. }
  65632. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65633. {
  65634. jassert (stateStack.size() > 0);
  65635. if (stateStack.size() > 0)
  65636. stateStack.removeLast();
  65637. }
  65638. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65639. {
  65640. if (needToClip)
  65641. {
  65642. needToClip = false;
  65643. out << "doclip ";
  65644. int itemsOnLine = 0;
  65645. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65646. {
  65647. if (++itemsOnLine == 6)
  65648. {
  65649. itemsOnLine = 0;
  65650. out << '\n';
  65651. }
  65652. const Rectangle<int>& r = *i.getRectangle();
  65653. out << r.getX() << ' ' << -r.getY() << ' '
  65654. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65655. }
  65656. out << "endclip\n";
  65657. }
  65658. }
  65659. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65660. {
  65661. Colour c (Colours::white.overlaidWith (colour));
  65662. if (lastColour != c)
  65663. {
  65664. lastColour = c;
  65665. out << String (c.getFloatRed(), 3) << ' '
  65666. << String (c.getFloatGreen(), 3) << ' '
  65667. << String (c.getFloatBlue(), 3) << " c\n";
  65668. }
  65669. }
  65670. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65671. {
  65672. out << String (x, 2) << ' '
  65673. << String (-y, 2) << ' ';
  65674. }
  65675. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65676. {
  65677. out << "newpath ";
  65678. float lastX = 0.0f;
  65679. float lastY = 0.0f;
  65680. int itemsOnLine = 0;
  65681. Path::Iterator i (path);
  65682. while (i.next())
  65683. {
  65684. if (++itemsOnLine == 4)
  65685. {
  65686. itemsOnLine = 0;
  65687. out << '\n';
  65688. }
  65689. switch (i.elementType)
  65690. {
  65691. case Path::Iterator::startNewSubPath:
  65692. writeXY (i.x1, i.y1);
  65693. lastX = i.x1;
  65694. lastY = i.y1;
  65695. out << "m ";
  65696. break;
  65697. case Path::Iterator::lineTo:
  65698. writeXY (i.x1, i.y1);
  65699. lastX = i.x1;
  65700. lastY = i.y1;
  65701. out << "l ";
  65702. break;
  65703. case Path::Iterator::quadraticTo:
  65704. {
  65705. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65706. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65707. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65708. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65709. writeXY (cp1x, cp1y);
  65710. writeXY (cp2x, cp2y);
  65711. writeXY (i.x2, i.y2);
  65712. out << "ct ";
  65713. lastX = i.x2;
  65714. lastY = i.y2;
  65715. }
  65716. break;
  65717. case Path::Iterator::cubicTo:
  65718. writeXY (i.x1, i.y1);
  65719. writeXY (i.x2, i.y2);
  65720. writeXY (i.x3, i.y3);
  65721. out << "ct ";
  65722. lastX = i.x3;
  65723. lastY = i.y3;
  65724. break;
  65725. case Path::Iterator::closePath:
  65726. out << "cp ";
  65727. break;
  65728. default:
  65729. jassertfalse
  65730. break;
  65731. }
  65732. }
  65733. out << '\n';
  65734. }
  65735. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65736. {
  65737. out << "[ "
  65738. << trans.mat00 << ' '
  65739. << trans.mat10 << ' '
  65740. << trans.mat01 << ' '
  65741. << trans.mat11 << ' '
  65742. << trans.mat02 << ' '
  65743. << trans.mat12 << " ] concat ";
  65744. }
  65745. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65746. {
  65747. stateStack.getLast()->fillType = fillType;
  65748. }
  65749. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65750. {
  65751. }
  65752. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65753. {
  65754. }
  65755. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65756. {
  65757. if (stateStack.getLast()->fillType.isColour())
  65758. {
  65759. writeClip();
  65760. writeColour (stateStack.getLast()->fillType.colour);
  65761. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65762. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65763. }
  65764. else
  65765. {
  65766. Path p;
  65767. p.addRectangle (r);
  65768. fillPath (p, AffineTransform::identity);
  65769. }
  65770. }
  65771. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65772. {
  65773. if (stateStack.getLast()->fillType.isColour())
  65774. {
  65775. writeClip();
  65776. Path p (path);
  65777. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65778. (float) stateStack.getLast()->yOffset));
  65779. writePath (p);
  65780. writeColour (stateStack.getLast()->fillType.colour);
  65781. out << "fill\n";
  65782. }
  65783. else if (stateStack.getLast()->fillType.isGradient())
  65784. {
  65785. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65786. // postscript can't do semi-transparent ones.
  65787. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65788. writeClip();
  65789. out << "gsave ";
  65790. {
  65791. Path p (path);
  65792. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65793. writePath (p);
  65794. out << "clip\n";
  65795. }
  65796. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65797. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65798. // time-being, this just fills it with the average colour..
  65799. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65800. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65801. out << "grestore\n";
  65802. }
  65803. }
  65804. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65805. const int sx, const int sy,
  65806. const int maxW, const int maxH) const
  65807. {
  65808. out << "{<\n";
  65809. const int w = jmin (maxW, im.getWidth());
  65810. const int h = jmin (maxH, im.getHeight());
  65811. int charsOnLine = 0;
  65812. const Image::BitmapData srcData (im, 0, 0, w, h);
  65813. Colour pixel;
  65814. for (int y = h; --y >= 0;)
  65815. {
  65816. for (int x = 0; x < w; ++x)
  65817. {
  65818. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65819. if (x >= sx && y >= sy)
  65820. {
  65821. if (im.isARGB())
  65822. {
  65823. PixelARGB p (*(const PixelARGB*) pixelData);
  65824. p.unpremultiply();
  65825. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65826. }
  65827. else if (im.isRGB())
  65828. {
  65829. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65830. }
  65831. else
  65832. {
  65833. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65834. }
  65835. }
  65836. else
  65837. {
  65838. pixel = Colours::transparentWhite;
  65839. }
  65840. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65841. out << String::toHexString (pixelValues, 3, 0);
  65842. charsOnLine += 3;
  65843. if (charsOnLine > 100)
  65844. {
  65845. out << '\n';
  65846. charsOnLine = 0;
  65847. }
  65848. }
  65849. }
  65850. out << "\n>}\n";
  65851. }
  65852. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65853. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65854. {
  65855. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65856. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65857. writeClip();
  65858. out << "gsave ";
  65859. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65860. .scaled (1.0f, -1.0f));
  65861. RectangleList imageClip;
  65862. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65863. imageClip.clipTo (srcClip);
  65864. out << "newpath ";
  65865. int itemsOnLine = 0;
  65866. for (RectangleList::Iterator i (imageClip); i.next();)
  65867. {
  65868. if (++itemsOnLine == 6)
  65869. {
  65870. out << '\n';
  65871. itemsOnLine = 0;
  65872. }
  65873. const Rectangle<int>& r = *i.getRectangle();
  65874. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65875. }
  65876. out << " clip newpath\n";
  65877. out << w << ' ' << h << " scale\n";
  65878. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65879. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65880. out << "false 3 colorimage grestore\n";
  65881. needToClip = true;
  65882. }
  65883. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65884. {
  65885. Path p;
  65886. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65887. fillPath (p, AffineTransform::identity);
  65888. }
  65889. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65890. {
  65891. drawLine (x, top, x, bottom);
  65892. }
  65893. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65894. {
  65895. drawLine (left, y, right, y);
  65896. }
  65897. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65898. {
  65899. stateStack.getLast()->font = newFont;
  65900. }
  65901. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65902. {
  65903. return stateStack.getLast()->font;
  65904. }
  65905. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65906. {
  65907. Path p;
  65908. Font& font = stateStack.getLast()->font;
  65909. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65910. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65911. }
  65912. END_JUCE_NAMESPACE
  65913. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65914. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65915. BEGIN_JUCE_NAMESPACE
  65916. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65917. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65918. #endif
  65919. #if JUCE_MSVC && JUCE_DEBUG
  65920. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65921. #endif
  65922. #if JUCE_MSVC
  65923. #pragma warning (push)
  65924. #pragma warning (disable: 4127) // "expression is constant" warning
  65925. #endif
  65926. template <class PixelType, bool replaceExisting = false>
  65927. class SolidColourEdgeTableRenderer
  65928. {
  65929. public:
  65930. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65931. : data (data_),
  65932. sourceColour (colour)
  65933. {
  65934. if (sizeof (PixelType) == 3)
  65935. {
  65936. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65937. && sourceColour.getGreen() == sourceColour.getBlue();
  65938. filler[0].set (sourceColour);
  65939. filler[1].set (sourceColour);
  65940. filler[2].set (sourceColour);
  65941. filler[3].set (sourceColour);
  65942. }
  65943. }
  65944. forcedinline void setEdgeTableYPos (const int y) throw()
  65945. {
  65946. linePixels = (PixelType*) data.getLinePointer (y);
  65947. }
  65948. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65949. {
  65950. if (replaceExisting)
  65951. linePixels[x].set (sourceColour);
  65952. else
  65953. linePixels[x].blend (sourceColour, alphaLevel);
  65954. }
  65955. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65956. {
  65957. PixelARGB p (sourceColour);
  65958. p.multiplyAlpha (alphaLevel);
  65959. PixelType* dest = linePixels + x;
  65960. if (replaceExisting || p.getAlpha() >= 0xff)
  65961. replaceLine (dest, p, width);
  65962. else
  65963. blendLine (dest, p, width);
  65964. }
  65965. private:
  65966. const Image::BitmapData& data;
  65967. PixelType* linePixels;
  65968. PixelARGB sourceColour;
  65969. PixelRGB filler [4];
  65970. bool areRGBComponentsEqual;
  65971. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  65972. {
  65973. do
  65974. {
  65975. dest->blend (colour);
  65976. ++dest;
  65977. } while (--width > 0);
  65978. }
  65979. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65980. {
  65981. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65982. {
  65983. memset (dest, colour.getRed(), width * 3);
  65984. }
  65985. else
  65986. {
  65987. if (width >> 5)
  65988. {
  65989. const int* const intFiller = (const int*) filler;
  65990. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65991. {
  65992. dest->set (colour);
  65993. ++dest;
  65994. --width;
  65995. }
  65996. while (width > 4)
  65997. {
  65998. ((int*) dest) [0] = intFiller[0];
  65999. ((int*) dest) [1] = intFiller[1];
  66000. ((int*) dest) [2] = intFiller[2];
  66001. dest = (PixelRGB*) (((uint8*) dest) + 12);
  66002. width -= 4;
  66003. }
  66004. }
  66005. while (--width >= 0)
  66006. {
  66007. dest->set (colour);
  66008. ++dest;
  66009. }
  66010. }
  66011. }
  66012. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  66013. {
  66014. memset (dest, colour.getAlpha(), width);
  66015. }
  66016. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  66017. {
  66018. do
  66019. {
  66020. dest->set (colour);
  66021. ++dest;
  66022. } while (--width > 0);
  66023. }
  66024. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  66025. const SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  66026. };
  66027. class LinearGradientPixelGenerator
  66028. {
  66029. public:
  66030. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  66031. : lookupTable (lookupTable_), numEntries (numEntries_)
  66032. {
  66033. jassert (numEntries_ >= 0);
  66034. float x1 = gradient.x1;
  66035. float y1 = gradient.y1;
  66036. float x2 = gradient.x2;
  66037. float y2 = gradient.y2;
  66038. if (! transform.isIdentity())
  66039. {
  66040. const Line l (x2, y2, x1, y1);
  66041. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  66042. float x3 = p3.getX();
  66043. float y3 = p3.getY();
  66044. transform.transformPoint (x1, y1);
  66045. transform.transformPoint (x2, y2);
  66046. transform.transformPoint (x3, y3);
  66047. const Line l2 (x2, y2, x3, y3);
  66048. const float prop = l2.findNearestPointTo (x1, y1);
  66049. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  66050. x2 = newP2.getX();
  66051. y2 = newP2.getY();
  66052. }
  66053. vertical = fabs (x1 - x2) < 0.001f;
  66054. horizontal = fabs (y1 - y2) < 0.001f;
  66055. if (vertical)
  66056. {
  66057. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  66058. start = roundToInt (y1 * scale);
  66059. }
  66060. else if (horizontal)
  66061. {
  66062. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  66063. start = roundToInt (x1 * scale);
  66064. }
  66065. else
  66066. {
  66067. grad = (y2 - y1) / (double) (x1 - x2);
  66068. yTerm = y1 - x1 / grad;
  66069. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  66070. grad *= scale;
  66071. }
  66072. }
  66073. forcedinline void setY (const int y) throw()
  66074. {
  66075. if (vertical)
  66076. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  66077. else if (! horizontal)
  66078. start = roundToInt ((y - yTerm) * grad);
  66079. }
  66080. forcedinline const PixelARGB getPixel (const int x) const throw()
  66081. {
  66082. return vertical ? linePix
  66083. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  66084. }
  66085. private:
  66086. const PixelARGB* const lookupTable;
  66087. const int numEntries;
  66088. PixelARGB linePix;
  66089. int start, scale;
  66090. double grad, yTerm;
  66091. bool vertical, horizontal;
  66092. enum { numScaleBits = 12 };
  66093. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  66094. const LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  66095. };
  66096. class RadialGradientPixelGenerator
  66097. {
  66098. public:
  66099. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66100. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66101. : lookupTable (lookupTable_),
  66102. numEntries (numEntries_),
  66103. gx1 (gradient.x1),
  66104. gy1 (gradient.y1)
  66105. {
  66106. jassert (numEntries_ >= 0);
  66107. const float gdx = gradient.x1 - gradient.x2;
  66108. const float gdy = gradient.y1 - gradient.y2;
  66109. maxDist = gdx * gdx + gdy * gdy;
  66110. invScale = numEntries / sqrt (maxDist);
  66111. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66112. }
  66113. forcedinline void setY (const int y) throw()
  66114. {
  66115. dy = y - gy1;
  66116. dy *= dy;
  66117. }
  66118. forcedinline const PixelARGB getPixel (const int px) const throw()
  66119. {
  66120. double x = px - gx1;
  66121. x *= x;
  66122. x += dy;
  66123. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66124. }
  66125. protected:
  66126. const PixelARGB* const lookupTable;
  66127. const int numEntries;
  66128. const double gx1, gy1;
  66129. double maxDist, invScale, dy;
  66130. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66131. const RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66132. };
  66133. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66134. {
  66135. public:
  66136. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66137. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66138. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66139. inverseTransform (transform.inverted())
  66140. {
  66141. tM10 = inverseTransform.mat10;
  66142. tM00 = inverseTransform.mat00;
  66143. }
  66144. forcedinline void setY (const int y) throw()
  66145. {
  66146. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66147. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66148. }
  66149. forcedinline const PixelARGB getPixel (const int px) const throw()
  66150. {
  66151. double x = px;
  66152. const double y = tM10 * x + lineYM11;
  66153. x = tM00 * x + lineYM01;
  66154. x *= x;
  66155. x += y * y;
  66156. if (x >= maxDist)
  66157. return lookupTable [numEntries];
  66158. else
  66159. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66160. }
  66161. private:
  66162. double tM10, tM00, lineYM01, lineYM11;
  66163. const AffineTransform inverseTransform;
  66164. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66165. const TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66166. };
  66167. template <class PixelType, class GradientType>
  66168. class GradientEdgeTableRenderer : public GradientType
  66169. {
  66170. public:
  66171. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66172. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66173. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66174. destData (destData_)
  66175. {
  66176. }
  66177. forcedinline void setEdgeTableYPos (const int y) throw()
  66178. {
  66179. linePixels = (PixelType*) destData.getLinePointer (y);
  66180. GradientType::setY (y);
  66181. }
  66182. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66183. {
  66184. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66185. }
  66186. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66187. {
  66188. PixelType* dest = linePixels + x;
  66189. if (alphaLevel < 0xff)
  66190. {
  66191. do
  66192. {
  66193. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66194. } while (--width > 0);
  66195. }
  66196. else
  66197. {
  66198. do
  66199. {
  66200. (dest++)->blend (GradientType::getPixel (x++));
  66201. } while (--width > 0);
  66202. }
  66203. }
  66204. private:
  66205. const Image::BitmapData& destData;
  66206. PixelType* linePixels;
  66207. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66208. const GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66209. };
  66210. static forcedinline int safeModulo (int n, const int divisor) throw()
  66211. {
  66212. jassert (divisor > 0);
  66213. n %= divisor;
  66214. return (n < 0) ? (n + divisor) : n;
  66215. }
  66216. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66217. class ImageFillEdgeTableRenderer
  66218. {
  66219. public:
  66220. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66221. const Image::BitmapData& srcData_,
  66222. const int extraAlpha_,
  66223. const int x, const int y) throw()
  66224. : destData (destData_),
  66225. srcData (srcData_),
  66226. extraAlpha (extraAlpha_ + 1),
  66227. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66228. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66229. {
  66230. }
  66231. forcedinline void setEdgeTableYPos (int y) throw()
  66232. {
  66233. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66234. y -= yOffset;
  66235. if (repeatPattern)
  66236. {
  66237. jassert (y >= 0);
  66238. y %= srcData.height;
  66239. }
  66240. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66241. }
  66242. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66243. {
  66244. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66245. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66246. }
  66247. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66248. {
  66249. DestPixelType* dest = linePixels + x;
  66250. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66251. x -= xOffset;
  66252. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66253. if (alphaLevel < 0xfe)
  66254. {
  66255. do
  66256. {
  66257. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66258. } while (--width > 0);
  66259. }
  66260. else
  66261. {
  66262. if (repeatPattern)
  66263. {
  66264. do
  66265. {
  66266. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66267. } while (--width > 0);
  66268. }
  66269. else
  66270. {
  66271. copyRow (dest, sourceLineStart + x, width);
  66272. }
  66273. }
  66274. }
  66275. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66276. {
  66277. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66278. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66279. uint8* mask = (uint8*) (s + x - xOffset);
  66280. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66281. mask += PixelARGB::indexA;
  66282. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66283. }
  66284. private:
  66285. const Image::BitmapData& destData;
  66286. const Image::BitmapData& srcData;
  66287. const int extraAlpha, xOffset, yOffset;
  66288. DestPixelType* linePixels;
  66289. SrcPixelType* sourceLineStart;
  66290. template <class PixelType1, class PixelType2>
  66291. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66292. {
  66293. do
  66294. {
  66295. dest++ ->blend (*src++);
  66296. } while (--width > 0);
  66297. }
  66298. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66299. {
  66300. memcpy (dest, src, width * sizeof (PixelRGB));
  66301. }
  66302. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66303. const ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66304. };
  66305. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66306. class TransformedImageFillEdgeTableRenderer
  66307. {
  66308. public:
  66309. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66310. const Image::BitmapData& srcData_,
  66311. const AffineTransform& transform,
  66312. const int extraAlpha_,
  66313. const bool betterQuality_) throw()
  66314. : interpolator (transform),
  66315. destData (destData_),
  66316. srcData (srcData_),
  66317. extraAlpha (extraAlpha_ + 1),
  66318. betterQuality (betterQuality_),
  66319. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66320. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66321. maxX (srcData_.width - 1),
  66322. maxY (srcData_.height - 1),
  66323. scratchSize (2048)
  66324. {
  66325. scratchBuffer.malloc (scratchSize);
  66326. }
  66327. ~TransformedImageFillEdgeTableRenderer() throw()
  66328. {
  66329. }
  66330. forcedinline void setEdgeTableYPos (const int newY) throw()
  66331. {
  66332. y = newY;
  66333. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66334. }
  66335. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66336. {
  66337. alphaLevel *= extraAlpha;
  66338. alphaLevel >>= 8;
  66339. SrcPixelType p;
  66340. generate (&p, x, 1);
  66341. linePixels[x].blend (p, alphaLevel);
  66342. }
  66343. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66344. {
  66345. if (width > scratchSize)
  66346. {
  66347. scratchSize = width;
  66348. scratchBuffer.malloc (scratchSize);
  66349. }
  66350. SrcPixelType* span = scratchBuffer;
  66351. generate (span, x, width);
  66352. DestPixelType* dest = linePixels + x;
  66353. alphaLevel *= extraAlpha;
  66354. alphaLevel >>= 8;
  66355. if (alphaLevel < 0xfe)
  66356. {
  66357. do
  66358. {
  66359. dest++ ->blend (*span++, alphaLevel);
  66360. } while (--width > 0);
  66361. }
  66362. else
  66363. {
  66364. do
  66365. {
  66366. dest++ ->blend (*span++);
  66367. } while (--width > 0);
  66368. }
  66369. }
  66370. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66371. {
  66372. if (width > scratchSize)
  66373. {
  66374. scratchSize = width;
  66375. scratchBuffer.malloc (scratchSize);
  66376. }
  66377. uint8* mask = (uint8*) scratchBuffer;
  66378. y = y_;
  66379. generate ((SrcPixelType*) mask, x, width);
  66380. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66381. mask += PixelARGB::indexA;
  66382. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66383. }
  66384. private:
  66385. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66386. {
  66387. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66388. do
  66389. {
  66390. int hiResX, hiResY;
  66391. this->interpolator.next (hiResX, hiResY);
  66392. hiResX += pixelOffsetInt;
  66393. hiResY += pixelOffsetInt;
  66394. int loResX = hiResX >> 8;
  66395. int loResY = hiResY >> 8;
  66396. if (repeatPattern)
  66397. {
  66398. loResX = safeModulo (loResX, srcData.width);
  66399. loResY = safeModulo (loResY, srcData.height);
  66400. }
  66401. if (betterQuality
  66402. && ((unsigned int) loResX) < (unsigned int) maxX
  66403. && ((unsigned int) loResY) < (unsigned int) maxY)
  66404. {
  66405. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66406. hiResX &= 255;
  66407. hiResY &= 255;
  66408. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66409. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66410. c[0] += weight * src[0];
  66411. c[1] += weight * src[1];
  66412. c[2] += weight * src[2];
  66413. c[3] += weight * src[3];
  66414. weight = hiResX * (256 - hiResY);
  66415. c[0] += weight * src[4];
  66416. c[1] += weight * src[5];
  66417. c[2] += weight * src[6];
  66418. c[3] += weight * src[7];
  66419. src += this->srcData.lineStride;
  66420. weight = (256 - hiResX) * hiResY;
  66421. c[0] += weight * src[0];
  66422. c[1] += weight * src[1];
  66423. c[2] += weight * src[2];
  66424. c[3] += weight * src[3];
  66425. weight = hiResX * hiResY;
  66426. c[0] += weight * src[4];
  66427. c[1] += weight * src[5];
  66428. c[2] += weight * src[6];
  66429. c[3] += weight * src[7];
  66430. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66431. (uint8) (c[PixelARGB::indexR] >> 16),
  66432. (uint8) (c[PixelARGB::indexG] >> 16),
  66433. (uint8) (c[PixelARGB::indexB] >> 16));
  66434. }
  66435. else
  66436. {
  66437. if (! repeatPattern)
  66438. {
  66439. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66440. if (loResX < 0) loResX = 0;
  66441. if (loResY < 0) loResY = 0;
  66442. if (loResX > maxX) loResX = maxX;
  66443. if (loResY > maxY) loResY = maxY;
  66444. }
  66445. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66446. }
  66447. ++dest;
  66448. } while (--numPixels > 0);
  66449. }
  66450. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66451. {
  66452. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66453. do
  66454. {
  66455. int hiResX, hiResY;
  66456. this->interpolator.next (hiResX, hiResY);
  66457. hiResX += pixelOffsetInt;
  66458. hiResY += pixelOffsetInt;
  66459. int loResX = hiResX >> 8;
  66460. int loResY = hiResY >> 8;
  66461. if (repeatPattern)
  66462. {
  66463. loResX = safeModulo (loResX, srcData.width);
  66464. loResY = safeModulo (loResY, srcData.height);
  66465. }
  66466. if (betterQuality
  66467. && ((unsigned int) loResX) < (unsigned int) maxX
  66468. && ((unsigned int) loResY) < (unsigned int) maxY)
  66469. {
  66470. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66471. hiResX &= 255;
  66472. hiResY &= 255;
  66473. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66474. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66475. c[0] += weight * src[0];
  66476. c[1] += weight * src[1];
  66477. c[2] += weight * src[2];
  66478. weight = hiResX * (256 - hiResY);
  66479. c[0] += weight * src[3];
  66480. c[1] += weight * src[4];
  66481. c[2] += weight * src[5];
  66482. src += this->srcData.lineStride;
  66483. weight = (256 - hiResX) * hiResY;
  66484. c[0] += weight * src[0];
  66485. c[1] += weight * src[1];
  66486. c[2] += weight * src[2];
  66487. weight = hiResX * hiResY;
  66488. c[0] += weight * src[3];
  66489. c[1] += weight * src[4];
  66490. c[2] += weight * src[5];
  66491. dest->setARGB ((uint8) 255,
  66492. (uint8) (c[PixelRGB::indexR] >> 16),
  66493. (uint8) (c[PixelRGB::indexG] >> 16),
  66494. (uint8) (c[PixelRGB::indexB] >> 16));
  66495. }
  66496. else
  66497. {
  66498. if (! repeatPattern)
  66499. {
  66500. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66501. if (loResX < 0) loResX = 0;
  66502. if (loResY < 0) loResY = 0;
  66503. if (loResX > maxX) loResX = maxX;
  66504. if (loResY > maxY) loResY = maxY;
  66505. }
  66506. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66507. }
  66508. ++dest;
  66509. } while (--numPixels > 0);
  66510. }
  66511. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66512. {
  66513. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66514. do
  66515. {
  66516. int hiResX, hiResY;
  66517. this->interpolator.next (hiResX, hiResY);
  66518. hiResX += pixelOffsetInt;
  66519. hiResY += pixelOffsetInt;
  66520. int loResX = hiResX >> 8;
  66521. int loResY = hiResY >> 8;
  66522. if (repeatPattern)
  66523. {
  66524. loResX = safeModulo (loResX, srcData.width);
  66525. loResY = safeModulo (loResY, srcData.height);
  66526. }
  66527. if (betterQuality
  66528. && ((unsigned int) loResX) < (unsigned int) maxX
  66529. && ((unsigned int) loResY) < (unsigned int) maxY)
  66530. {
  66531. hiResX &= 255;
  66532. hiResY &= 255;
  66533. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66534. uint32 c = 256 * 128;
  66535. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66536. c += src[1] * (hiResX * (256 - hiResY));
  66537. src += this->srcData.lineStride;
  66538. c += src[0] * ((256 - hiResX) * hiResY);
  66539. c += src[1] * (hiResX * hiResY);
  66540. *((uint8*) dest) = (uint8) c;
  66541. }
  66542. else
  66543. {
  66544. if (! repeatPattern)
  66545. {
  66546. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66547. if (loResX < 0) loResX = 0;
  66548. if (loResY < 0) loResY = 0;
  66549. if (loResX > maxX) loResX = maxX;
  66550. if (loResY > maxY) loResY = maxY;
  66551. }
  66552. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66553. }
  66554. ++dest;
  66555. } while (--numPixels > 0);
  66556. }
  66557. class TransformedImageSpanInterpolator
  66558. {
  66559. public:
  66560. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66561. : inverseTransform (transform.inverted())
  66562. {}
  66563. void setStartOfLine (float x, float y, const int numPixels) throw()
  66564. {
  66565. float x1 = x, y1 = y;
  66566. inverseTransform.transformPoint (x1, y1);
  66567. x += numPixels;
  66568. inverseTransform.transformPoint (x, y);
  66569. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66570. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66571. }
  66572. void next (int& x, int& y) throw()
  66573. {
  66574. x = xBresenham.n;
  66575. xBresenham.stepToNext();
  66576. y = yBresenham.n;
  66577. yBresenham.stepToNext();
  66578. }
  66579. private:
  66580. class BresenhamInterpolator
  66581. {
  66582. public:
  66583. BresenhamInterpolator() throw() {}
  66584. void set (const int n1, const int n2, const int numSteps_) throw()
  66585. {
  66586. numSteps = jmax (1, numSteps_);
  66587. step = (n2 - n1) / numSteps;
  66588. remainder = modulo = (n2 - n1) % numSteps;
  66589. n = n1;
  66590. if (modulo <= 0)
  66591. {
  66592. modulo += numSteps;
  66593. remainder += numSteps;
  66594. --step;
  66595. }
  66596. modulo -= numSteps;
  66597. }
  66598. forcedinline void stepToNext() throw()
  66599. {
  66600. modulo += remainder;
  66601. n += step;
  66602. if (modulo > 0)
  66603. {
  66604. modulo -= numSteps;
  66605. ++n;
  66606. }
  66607. }
  66608. int n;
  66609. private:
  66610. int numSteps, step, modulo, remainder;
  66611. };
  66612. const AffineTransform inverseTransform;
  66613. BresenhamInterpolator xBresenham, yBresenham;
  66614. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66615. const TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66616. };
  66617. TransformedImageSpanInterpolator interpolator;
  66618. const Image::BitmapData& destData;
  66619. const Image::BitmapData& srcData;
  66620. const int extraAlpha;
  66621. const bool betterQuality;
  66622. const float pixelOffset;
  66623. const int pixelOffsetInt, maxX, maxY;
  66624. int y;
  66625. DestPixelType* linePixels;
  66626. HeapBlock <SrcPixelType> scratchBuffer;
  66627. int scratchSize;
  66628. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66629. const TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66630. };
  66631. class LLGCSavedState
  66632. {
  66633. public:
  66634. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66635. const Font& font_, const FillType& fillType_,
  66636. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66637. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66638. xOffset (xOffset_), yOffset (yOffset_),
  66639. font (font_), fillType (fillType_),
  66640. interpolationQuality (interpolationQuality_)
  66641. {
  66642. }
  66643. LLGCSavedState (const LLGCSavedState& other) throw()
  66644. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66645. yOffset (other.yOffset), font (other.font),
  66646. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66647. {
  66648. }
  66649. ~LLGCSavedState() throw()
  66650. {
  66651. }
  66652. bool clipToRectangle (const Rectangle<int>& r) throw()
  66653. {
  66654. dupeEdgeTableIfMultiplyReferenced();
  66655. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66656. return ! edgeTable->edgeTable.isEmpty();
  66657. }
  66658. bool clipToRectangleList (const RectangleList& r) throw()
  66659. {
  66660. dupeEdgeTableIfMultiplyReferenced();
  66661. RectangleList offsetList (r);
  66662. offsetList.offsetAll (xOffset, yOffset);
  66663. EdgeTable e2 (offsetList);
  66664. edgeTable->edgeTable.clipToEdgeTable (e2);
  66665. return ! edgeTable->edgeTable.isEmpty();
  66666. }
  66667. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66668. {
  66669. dupeEdgeTableIfMultiplyReferenced();
  66670. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66671. return ! edgeTable->edgeTable.isEmpty();
  66672. }
  66673. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66674. {
  66675. dupeEdgeTableIfMultiplyReferenced();
  66676. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66677. edgeTable->edgeTable.clipToEdgeTable (et);
  66678. }
  66679. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66680. {
  66681. et.clipToEdgeTable (edgeTable->edgeTable);
  66682. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66683. if (fillType.isGradient())
  66684. {
  66685. jassert (! replaceContents); // that option is just for solid colours
  66686. ColourGradient g2 (*(fillType.gradient));
  66687. g2.multiplyOpacity (fillType.getOpacity());
  66688. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66689. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66690. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66691. const bool isIdentity = transform.isOnlyTranslation();
  66692. if (isIdentity)
  66693. {
  66694. // If our translation doesn't involve any distortion, we can speed it up..
  66695. transform.transformPoint (g2.x1, g2.y1);
  66696. transform.transformPoint (g2.x2, g2.y2);
  66697. transform = AffineTransform::identity;
  66698. }
  66699. HeapBlock <PixelARGB> lookupTable;
  66700. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66701. jassert (numLookupEntries > 0);
  66702. switch (image.getFormat())
  66703. {
  66704. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66705. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66706. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66707. }
  66708. }
  66709. else if (fillType.isTiledImage())
  66710. {
  66711. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66712. }
  66713. else
  66714. {
  66715. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66716. switch (image.getFormat())
  66717. {
  66718. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66719. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66720. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66721. }
  66722. }
  66723. }
  66724. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66725. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66726. {
  66727. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66728. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66729. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66730. const int alpha = fillType.colour.getAlpha();
  66731. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66732. if (transform.isOnlyTranslation())
  66733. {
  66734. // If our translation doesn't involve any distortion, just use a simple blit..
  66735. int tx = (int) (transform.getTranslationX() * 256.0f);
  66736. int ty = (int) (transform.getTranslationY() * 256.0f);
  66737. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66738. {
  66739. tx = ((tx + 128) >> 8);
  66740. ty = ((ty + 128) >> 8);
  66741. if (tiledFillClipRegion != 0)
  66742. {
  66743. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66744. }
  66745. else
  66746. {
  66747. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66748. et.clipToEdgeTable (edgeTable->edgeTable);
  66749. if (! et.isEmpty())
  66750. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66751. }
  66752. return;
  66753. }
  66754. }
  66755. if (transform.isSingularity())
  66756. return;
  66757. if (tiledFillClipRegion != 0)
  66758. {
  66759. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66760. }
  66761. else
  66762. {
  66763. Path p;
  66764. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66765. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66766. et.clipToEdgeTable (edgeTable->edgeTable);
  66767. if (! et.isEmpty())
  66768. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66769. }
  66770. }
  66771. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66772. {
  66773. if (! image.hasAlphaChannel())
  66774. {
  66775. Path p;
  66776. p.addRectangle (srcClip);
  66777. clipToPath (p, t);
  66778. return;
  66779. }
  66780. dupeEdgeTableIfMultiplyReferenced();
  66781. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66782. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66783. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66784. EdgeTable& et = edgeTable->edgeTable;
  66785. if (transform.isOnlyTranslation())
  66786. {
  66787. // If our translation doesn't involve any distortion, just use a simple blit..
  66788. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66789. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66790. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66791. {
  66792. const int imageX = ((tx + 128) >> 8);
  66793. const int imageY = ((ty + 128) >> 8);
  66794. if (image.getFormat() == Image::ARGB)
  66795. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66796. else
  66797. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66798. return;
  66799. }
  66800. }
  66801. if (transform.isSingularity())
  66802. {
  66803. et.clipToRectangle (Rectangle<int>());
  66804. return;
  66805. }
  66806. {
  66807. Path p;
  66808. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66809. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66810. et.clipToEdgeTable (et2);
  66811. }
  66812. if (! et.isEmpty())
  66813. {
  66814. if (image.getFormat() == Image::ARGB)
  66815. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66816. else
  66817. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66818. }
  66819. }
  66820. template <class SrcPixelType>
  66821. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66822. {
  66823. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66824. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66825. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66826. et.getMaximumBounds().getWidth());
  66827. }
  66828. template <class SrcPixelType>
  66829. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66830. {
  66831. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66832. et.clipToRectangle (r);
  66833. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66834. for (int y = 0; y < r.getHeight(); ++y)
  66835. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66836. }
  66837. class EdgeTableHolder : public ReferenceCountedObject
  66838. {
  66839. public:
  66840. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66841. EdgeTable edgeTable;
  66842. };
  66843. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66844. int xOffset, yOffset;
  66845. Font font;
  66846. FillType fillType;
  66847. Graphics::ResamplingQuality interpolationQuality;
  66848. private:
  66849. const LLGCSavedState& operator= (const LLGCSavedState&);
  66850. void dupeEdgeTableIfMultiplyReferenced() throw()
  66851. {
  66852. if (edgeTable->getReferenceCount() > 1)
  66853. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66854. }
  66855. template <class DestPixelType>
  66856. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66857. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66858. {
  66859. jassert (destData.pixelStride == sizeof (DestPixelType));
  66860. if (g.isRadial)
  66861. {
  66862. if (isIdentity)
  66863. {
  66864. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66865. et.iterate (renderer);
  66866. }
  66867. else
  66868. {
  66869. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66870. et.iterate (renderer);
  66871. }
  66872. }
  66873. else
  66874. {
  66875. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66876. et.iterate (renderer);
  66877. }
  66878. }
  66879. template <class DestPixelType>
  66880. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66881. {
  66882. jassert (destData.pixelStride == sizeof (DestPixelType));
  66883. if (replaceContents)
  66884. {
  66885. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66886. et.iterate (r);
  66887. }
  66888. else
  66889. {
  66890. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66891. et.iterate (r);
  66892. }
  66893. }
  66894. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66895. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66896. {
  66897. switch (destImage.getFormat())
  66898. {
  66899. case Image::ARGB:
  66900. switch (srcImage.getFormat())
  66901. {
  66902. case Image::ARGB:
  66903. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66904. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66905. break;
  66906. case Image::RGB:
  66907. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66908. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66909. break;
  66910. default:
  66911. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66912. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66913. break;
  66914. }
  66915. break;
  66916. case Image::RGB:
  66917. switch (srcImage.getFormat())
  66918. {
  66919. case Image::ARGB:
  66920. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66921. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66922. break;
  66923. case Image::RGB:
  66924. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66925. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66926. break;
  66927. default:
  66928. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66929. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66930. break;
  66931. }
  66932. break;
  66933. default:
  66934. switch (srcImage.getFormat())
  66935. {
  66936. case Image::ARGB:
  66937. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66938. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66939. break;
  66940. case Image::RGB:
  66941. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66942. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66943. break;
  66944. default:
  66945. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66946. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66947. break;
  66948. }
  66949. break;
  66950. }
  66951. }
  66952. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66953. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66954. {
  66955. switch (destImage.getFormat())
  66956. {
  66957. case Image::ARGB:
  66958. switch (srcImage.getFormat())
  66959. {
  66960. case Image::ARGB:
  66961. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66962. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66963. break;
  66964. case Image::RGB:
  66965. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66966. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66967. break;
  66968. default:
  66969. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66970. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66971. break;
  66972. }
  66973. break;
  66974. case Image::RGB:
  66975. switch (srcImage.getFormat())
  66976. {
  66977. case Image::ARGB:
  66978. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66979. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66980. break;
  66981. case Image::RGB:
  66982. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66983. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66984. break;
  66985. default:
  66986. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66987. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66988. break;
  66989. }
  66990. break;
  66991. default:
  66992. switch (srcImage.getFormat())
  66993. {
  66994. case Image::ARGB:
  66995. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66996. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66997. break;
  66998. case Image::RGB:
  66999. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67000. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67001. break;
  67002. default:
  67003. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67004. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67005. break;
  67006. }
  67007. break;
  67008. }
  67009. }
  67010. };
  67011. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  67012. : image (image_)
  67013. {
  67014. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  67015. FillType(), Graphics::mediumResamplingQuality);
  67016. }
  67017. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  67018. {
  67019. }
  67020. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  67021. {
  67022. return false;
  67023. }
  67024. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  67025. {
  67026. currentState->xOffset += x;
  67027. currentState->yOffset += y;
  67028. }
  67029. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  67030. {
  67031. return currentState->clipToRectangle (r);
  67032. }
  67033. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  67034. {
  67035. return currentState->clipToRectangleList (clipRegion);
  67036. }
  67037. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  67038. {
  67039. currentState->excludeClipRectangle (r);
  67040. }
  67041. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  67042. {
  67043. currentState->clipToPath (path, transform);
  67044. }
  67045. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  67046. {
  67047. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  67048. }
  67049. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  67050. {
  67051. return currentState->edgeTable->edgeTable.getMaximumBounds()
  67052. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  67053. }
  67054. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  67055. {
  67056. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  67057. }
  67058. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  67059. {
  67060. return currentState->edgeTable->edgeTable.isEmpty();
  67061. }
  67062. void LowLevelGraphicsSoftwareRenderer::saveState()
  67063. {
  67064. stateStack.add (new LLGCSavedState (*currentState));
  67065. }
  67066. void LowLevelGraphicsSoftwareRenderer::restoreState()
  67067. {
  67068. LLGCSavedState* const top = stateStack.getLast();
  67069. if (top != 0)
  67070. {
  67071. currentState = top;
  67072. stateStack.removeLast (1, false);
  67073. }
  67074. else
  67075. {
  67076. jassertfalse // trying to pop with an empty stack!
  67077. }
  67078. }
  67079. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  67080. {
  67081. currentState->fillType = fillType;
  67082. }
  67083. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  67084. {
  67085. currentState->fillType.setOpacity (newOpacity);
  67086. }
  67087. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  67088. {
  67089. currentState->interpolationQuality = quality;
  67090. }
  67091. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  67092. {
  67093. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  67094. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  67095. if (! clipped.isEmpty())
  67096. {
  67097. EdgeTable et (clipped);
  67098. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67099. }
  67100. }
  67101. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67102. {
  67103. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67104. path, transform.translated ((float) currentState->xOffset,
  67105. (float) currentState->yOffset));
  67106. currentState->fillEdgeTable (image, et);
  67107. }
  67108. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  67109. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67110. {
  67111. jassert (sourceImage.getBounds().contains (srcClip));
  67112. currentState->renderImage (image, sourceImage, srcClip, transform,
  67113. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67114. }
  67115. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67116. {
  67117. Path p;
  67118. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67119. fillPath (p, AffineTransform::identity);
  67120. }
  67121. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67122. {
  67123. if (bottom > top)
  67124. {
  67125. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67126. currentState->fillEdgeTable (image, et);
  67127. }
  67128. }
  67129. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67130. {
  67131. if (right > left)
  67132. {
  67133. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67134. (float) (right - left), 1.0f);
  67135. currentState->fillEdgeTable (image, et);
  67136. }
  67137. }
  67138. class GlyphCache : private DeletedAtShutdown
  67139. {
  67140. public:
  67141. GlyphCache() throw()
  67142. : accessCounter (0), hits (0), misses (0)
  67143. {
  67144. for (int i = 120; --i >= 0;)
  67145. glyphs.add (new CachedGlyph());
  67146. }
  67147. ~GlyphCache() throw()
  67148. {
  67149. clearSingletonInstance();
  67150. }
  67151. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67152. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67153. {
  67154. ++accessCounter;
  67155. int oldestCounter = std::numeric_limits<int>::max();
  67156. CachedGlyph* oldest = 0;
  67157. for (int i = glyphs.size(); --i >= 0;)
  67158. {
  67159. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67160. if (glyph->glyph == glyphNumber && glyph->font == font)
  67161. {
  67162. ++hits;
  67163. glyph->lastAccessCount = accessCounter;
  67164. glyph->draw (state, image, x, y);
  67165. return;
  67166. }
  67167. if (glyph->lastAccessCount <= oldestCounter)
  67168. {
  67169. oldestCounter = glyph->lastAccessCount;
  67170. oldest = glyph;
  67171. }
  67172. }
  67173. if (hits + ++misses > (glyphs.size() << 4))
  67174. {
  67175. if (misses * 2 > hits)
  67176. {
  67177. for (int i = 32; --i >= 0;)
  67178. glyphs.add (new CachedGlyph());
  67179. }
  67180. hits = misses = 0;
  67181. oldest = glyphs.getLast();
  67182. }
  67183. jassert (oldest != 0);
  67184. oldest->lastAccessCount = accessCounter;
  67185. oldest->generate (font, glyphNumber);
  67186. oldest->draw (state, image, x, y);
  67187. }
  67188. class CachedGlyph
  67189. {
  67190. public:
  67191. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67192. ~CachedGlyph() {}
  67193. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67194. {
  67195. if (edgeTable != 0)
  67196. {
  67197. EdgeTable et (*edgeTable);
  67198. et.translate (x, roundToInt (y));
  67199. state.fillEdgeTable (image, et, false);
  67200. }
  67201. }
  67202. void generate (const Font& newFont, const int glyphNumber) throw()
  67203. {
  67204. font = newFont;
  67205. glyph = glyphNumber;
  67206. edgeTable = 0;
  67207. Path glyphPath;
  67208. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67209. if (! glyphPath.isEmpty())
  67210. {
  67211. const float fontHeight = font.getHeight();
  67212. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  67213. .translated (0.0f, -0.5f));
  67214. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  67215. glyphPath, transform);
  67216. }
  67217. }
  67218. int glyph, lastAccessCount;
  67219. Font font;
  67220. juce_UseDebuggingNewOperator
  67221. private:
  67222. ScopedPointer <EdgeTable> edgeTable;
  67223. CachedGlyph (const CachedGlyph&);
  67224. const CachedGlyph& operator= (const CachedGlyph&);
  67225. };
  67226. juce_UseDebuggingNewOperator
  67227. private:
  67228. OwnedArray <CachedGlyph> glyphs;
  67229. int accessCounter, hits, misses;
  67230. GlyphCache (const GlyphCache&);
  67231. const GlyphCache& operator= (const GlyphCache&);
  67232. };
  67233. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67234. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67235. {
  67236. currentState->font = newFont;
  67237. }
  67238. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67239. {
  67240. return currentState->font;
  67241. }
  67242. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67243. {
  67244. Font& f = currentState->font;
  67245. if (transform.isOnlyTranslation())
  67246. {
  67247. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67248. transform.getTranslationX() + (float) currentState->xOffset,
  67249. transform.getTranslationY() + (float) currentState->yOffset);
  67250. }
  67251. else
  67252. {
  67253. Path p;
  67254. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67255. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67256. }
  67257. }
  67258. #if JUCE_MSVC
  67259. #pragma warning (pop)
  67260. #endif
  67261. END_JUCE_NAMESPACE
  67262. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  67263. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  67264. BEGIN_JUCE_NAMESPACE
  67265. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67266. : flags (other.flags)
  67267. {
  67268. }
  67269. const RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67270. {
  67271. flags = other.flags;
  67272. return *this;
  67273. }
  67274. void RectanglePlacement::applyTo (double& x, double& y,
  67275. double& w, double& h,
  67276. const double dx, const double dy,
  67277. const double dw, const double dh) const throw()
  67278. {
  67279. if (w == 0 || h == 0)
  67280. return;
  67281. if ((flags & stretchToFit) != 0)
  67282. {
  67283. x = dx;
  67284. y = dy;
  67285. w = dw;
  67286. h = dh;
  67287. }
  67288. else
  67289. {
  67290. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67291. : jmin (dw / w, dh / h);
  67292. if ((flags & onlyReduceInSize) != 0)
  67293. scale = jmin (scale, 1.0);
  67294. if ((flags & onlyIncreaseInSize) != 0)
  67295. scale = jmax (scale, 1.0);
  67296. w *= scale;
  67297. h *= scale;
  67298. if ((flags & xLeft) != 0)
  67299. x = dx;
  67300. else if ((flags & xRight) != 0)
  67301. x = dx + dw - w;
  67302. else
  67303. x = dx + (dw - w) * 0.5;
  67304. if ((flags & yTop) != 0)
  67305. y = dy;
  67306. else if ((flags & yBottom) != 0)
  67307. y = dy + dh - h;
  67308. else
  67309. y = dy + (dh - h) * 0.5;
  67310. }
  67311. }
  67312. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67313. float w, float h,
  67314. const float dx, const float dy,
  67315. const float dw, const float dh) const throw()
  67316. {
  67317. if (w == 0 || h == 0)
  67318. return AffineTransform::identity;
  67319. const float scaleX = dw / w;
  67320. const float scaleY = dh / h;
  67321. if ((flags & stretchToFit) != 0)
  67322. return AffineTransform::translation (-x, -y)
  67323. .scaled (scaleX, scaleY)
  67324. .translated (dx, dy);
  67325. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67326. : jmin (scaleX, scaleY);
  67327. if ((flags & onlyReduceInSize) != 0)
  67328. scale = jmin (scale, 1.0f);
  67329. if ((flags & onlyIncreaseInSize) != 0)
  67330. scale = jmax (scale, 1.0f);
  67331. w *= scale;
  67332. h *= scale;
  67333. float newX = dx;
  67334. if ((flags & xRight) != 0)
  67335. newX += dw - w; // right
  67336. else if ((flags & xLeft) == 0)
  67337. newX += (dw - w) / 2.0f; // centre
  67338. float newY = dy;
  67339. if ((flags & yBottom) != 0)
  67340. newY += dh - h; // bottom
  67341. else if ((flags & yTop) == 0)
  67342. newY += (dh - h) / 2.0f; // centre
  67343. return AffineTransform::translation (-x, -y)
  67344. .scaled (scale, scale)
  67345. .translated (newX, newY);
  67346. }
  67347. END_JUCE_NAMESPACE
  67348. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  67349. /*** Start of inlined file: juce_Drawable.cpp ***/
  67350. BEGIN_JUCE_NAMESPACE
  67351. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67352. const AffineTransform& transform_,
  67353. const float opacity_) throw()
  67354. : g (g_),
  67355. transform (transform_),
  67356. opacity (opacity_)
  67357. {
  67358. }
  67359. Drawable::Drawable()
  67360. {
  67361. }
  67362. Drawable::~Drawable()
  67363. {
  67364. }
  67365. void Drawable::draw (Graphics& g, const float opacity,
  67366. const AffineTransform& transform) const
  67367. {
  67368. render (RenderingContext (g, transform, opacity));
  67369. }
  67370. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67371. {
  67372. draw (g, opacity, AffineTransform::translation (x, y));
  67373. }
  67374. void Drawable::drawWithin (Graphics& g,
  67375. const int destX,
  67376. const int destY,
  67377. const int destW,
  67378. const int destH,
  67379. const RectanglePlacement& placement,
  67380. const float opacity) const
  67381. {
  67382. if (destW > 0 && destH > 0)
  67383. {
  67384. Rectangle<float> bounds (getBounds());
  67385. draw (g, opacity,
  67386. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  67387. (float) destX, (float) destY,
  67388. (float) destW, (float) destH));
  67389. }
  67390. }
  67391. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67392. {
  67393. Drawable* result = 0;
  67394. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67395. if (image != 0)
  67396. {
  67397. DrawableImage* const di = new DrawableImage();
  67398. di->setImage (image, true);
  67399. result = di;
  67400. }
  67401. else
  67402. {
  67403. const String asString (String::createStringFromData (data, (int) numBytes));
  67404. XmlDocument doc (asString);
  67405. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67406. if (outer != 0 && outer->hasTagName (T("svg")))
  67407. {
  67408. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67409. if (svg != 0)
  67410. result = Drawable::createFromSVG (*svg);
  67411. }
  67412. }
  67413. return result;
  67414. }
  67415. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67416. {
  67417. MemoryBlock mb;
  67418. dataSource.readIntoMemoryBlock (mb);
  67419. return createFromImageData (mb.getData(), mb.getSize());
  67420. }
  67421. Drawable* Drawable::createFromImageFile (const File& file)
  67422. {
  67423. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67424. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67425. }
  67426. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67427. {
  67428. Drawable* d = DrawablePath::createFromValueTree (tree);
  67429. if (d == 0)
  67430. {
  67431. d = DrawableComposite::createFromValueTree (tree);
  67432. if (d == 0)
  67433. {
  67434. d = DrawableImage::createFromValueTree (tree);
  67435. if (d == 0)
  67436. d = DrawableText::createFromValueTree (tree);
  67437. }
  67438. }
  67439. return d;
  67440. }
  67441. END_JUCE_NAMESPACE
  67442. /*** End of inlined file: juce_Drawable.cpp ***/
  67443. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67444. BEGIN_JUCE_NAMESPACE
  67445. DrawableComposite::DrawableComposite()
  67446. {
  67447. }
  67448. DrawableComposite::~DrawableComposite()
  67449. {
  67450. }
  67451. void DrawableComposite::insertDrawable (Drawable* drawable,
  67452. const AffineTransform& transform,
  67453. const int index)
  67454. {
  67455. if (drawable != 0)
  67456. {
  67457. if (! drawables.contains (drawable))
  67458. {
  67459. drawables.insert (index, drawable);
  67460. if (transform.isIdentity())
  67461. transforms.insert (index, 0);
  67462. else
  67463. transforms.insert (index, new AffineTransform (transform));
  67464. }
  67465. else
  67466. {
  67467. jassertfalse // trying to add a drawable that's already in here!
  67468. }
  67469. }
  67470. }
  67471. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67472. const AffineTransform& transform,
  67473. const int index)
  67474. {
  67475. insertDrawable (drawable.createCopy(), transform, index);
  67476. }
  67477. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67478. {
  67479. drawables.remove (index, deleteDrawable);
  67480. transforms.remove (index);
  67481. }
  67482. void DrawableComposite::bringToFront (const int index)
  67483. {
  67484. if (index >= 0 && index < drawables.size() - 1)
  67485. {
  67486. drawables.move (index, -1);
  67487. transforms.move (index, -1);
  67488. }
  67489. }
  67490. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67491. {
  67492. if (drawables.size() > 0 && context.opacity > 0)
  67493. {
  67494. if (context.opacity >= 1.0f || drawables.size() == 1)
  67495. {
  67496. Drawable::RenderingContext contextCopy (context);
  67497. for (int i = 0; i < drawables.size(); ++i)
  67498. {
  67499. const AffineTransform* const t = transforms.getUnchecked(i);
  67500. contextCopy.transform = (t == 0) ? context.transform
  67501. : t->followedBy (context.transform);
  67502. drawables.getUnchecked(i)->render (contextCopy);
  67503. }
  67504. }
  67505. else
  67506. {
  67507. // To correctly render a whole composite layer with an overall transparency,
  67508. // we need to render everything opaquely into a temp buffer, then blend that
  67509. // with the target opacity...
  67510. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67511. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67512. {
  67513. Graphics tempG (tempImage);
  67514. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67515. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67516. render (tempContext);
  67517. }
  67518. context.g.setOpacity (context.opacity);
  67519. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67520. }
  67521. }
  67522. }
  67523. const Rectangle<float> DrawableComposite::getBounds() const
  67524. {
  67525. Rectangle<float> bounds;
  67526. for (int i = 0; i < drawables.size(); ++i)
  67527. {
  67528. const Drawable* const d = drawables.getUnchecked(i);
  67529. const AffineTransform* const t = transforms.getUnchecked(i);
  67530. bounds = bounds.getUnion (t == 0 ? d->getBounds()
  67531. : d->getBounds().transformed (*t));
  67532. }
  67533. return bounds;
  67534. }
  67535. bool DrawableComposite::hitTest (float x, float y) const
  67536. {
  67537. for (int i = 0; i < drawables.size(); ++i)
  67538. {
  67539. float tx = x;
  67540. float ty = y;
  67541. const AffineTransform* const t = transforms.getUnchecked(i);
  67542. if (t != 0)
  67543. t->inverted().transformPoint (tx, ty);
  67544. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67545. return true;
  67546. }
  67547. return false;
  67548. }
  67549. Drawable* DrawableComposite::createCopy() const
  67550. {
  67551. DrawableComposite* const dc = new DrawableComposite();
  67552. for (int i = 0; i < drawables.size(); ++i)
  67553. {
  67554. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67555. const AffineTransform* const t = transforms.getUnchecked(i);
  67556. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67557. }
  67558. return dc;
  67559. }
  67560. ValueTree DrawableComposite::createValueTree() const throw()
  67561. {
  67562. ValueTree v (T("Group"));
  67563. if (getName().isNotEmpty())
  67564. v.setProperty ("id", getName(), 0);
  67565. for (int i = 0; i < drawables.size(); ++i)
  67566. {
  67567. Drawable* const d = drawables.getUnchecked(i);
  67568. ValueTree child (d->createValueTree());
  67569. AffineTransform* transform = transforms.getUnchecked(i);
  67570. if (transform != 0)
  67571. {
  67572. String t;
  67573. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67574. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67575. child.setProperty ("transform", t, 0);
  67576. }
  67577. v.addChild (child, -1, 0);
  67578. }
  67579. return v;
  67580. }
  67581. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67582. {
  67583. if (! tree.hasType ("Group"))
  67584. return 0;
  67585. DrawableComposite* dc = new DrawableComposite();
  67586. dc->setName (tree ["id"]);
  67587. for (int i = 0; i < tree.getNumChildren(); ++i)
  67588. {
  67589. ValueTree childTree (tree.getChild (i));
  67590. Drawable* d = Drawable::createFromValueTree (childTree);
  67591. if (d != 0)
  67592. {
  67593. AffineTransform transform;
  67594. const String transformAtt (childTree ["transform"].toString());
  67595. if (transformAtt.isNotEmpty())
  67596. {
  67597. StringArray tokens;
  67598. tokens.addTokens (transformAtt.trim(), false);
  67599. tokens.removeEmptyStrings (true);
  67600. if (tokens.size() == 6)
  67601. {
  67602. float f[6];
  67603. for (int j = 0; j < 6; ++j)
  67604. f[j] = (float) tokens[j].getDoubleValue();
  67605. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67606. }
  67607. }
  67608. dc->insertDrawable (d, transform);
  67609. }
  67610. }
  67611. return dc;
  67612. }
  67613. END_JUCE_NAMESPACE
  67614. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67615. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67616. BEGIN_JUCE_NAMESPACE
  67617. DrawableImage::DrawableImage()
  67618. : image (0),
  67619. canDeleteImage (false),
  67620. opacity (1.0f),
  67621. overlayColour (0x00000000)
  67622. {
  67623. }
  67624. DrawableImage::~DrawableImage()
  67625. {
  67626. clearImage();
  67627. }
  67628. void DrawableImage::clearImage()
  67629. {
  67630. if (canDeleteImage && image != 0)
  67631. ImageCache::releaseOrDelete (image);
  67632. image = 0;
  67633. }
  67634. void DrawableImage::setImage (const Image& imageToCopy)
  67635. {
  67636. clearImage();
  67637. image = new Image (imageToCopy);
  67638. canDeleteImage = true;
  67639. }
  67640. void DrawableImage::setImage (Image* imageToUse,
  67641. const bool releaseWhenNotNeeded)
  67642. {
  67643. clearImage();
  67644. image = imageToUse;
  67645. canDeleteImage = releaseWhenNotNeeded;
  67646. }
  67647. void DrawableImage::setOpacity (const float newOpacity)
  67648. {
  67649. opacity = newOpacity;
  67650. }
  67651. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67652. {
  67653. overlayColour = newOverlayColour;
  67654. }
  67655. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67656. {
  67657. if (image != 0)
  67658. {
  67659. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67660. {
  67661. context.g.setOpacity (context.opacity * opacity);
  67662. context.g.drawImageTransformed (image, image->getBounds(),
  67663. context.transform, false);
  67664. }
  67665. if (! overlayColour.isTransparent())
  67666. {
  67667. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67668. context.g.drawImageTransformed (image, image->getBounds(),
  67669. context.transform, true);
  67670. }
  67671. }
  67672. }
  67673. const Rectangle<float> DrawableImage::getBounds() const
  67674. {
  67675. if (image == 0)
  67676. return Rectangle<float>();
  67677. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67678. }
  67679. bool DrawableImage::hitTest (float x, float y) const
  67680. {
  67681. return image != 0
  67682. && x >= 0.0f
  67683. && y >= 0.0f
  67684. && x < image->getWidth()
  67685. && y < image->getHeight()
  67686. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67687. }
  67688. Drawable* DrawableImage::createCopy() const
  67689. {
  67690. DrawableImage* const di = new DrawableImage();
  67691. di->opacity = opacity;
  67692. di->overlayColour = overlayColour;
  67693. if (image != 0)
  67694. {
  67695. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67696. {
  67697. di->setImage (*image);
  67698. }
  67699. else
  67700. {
  67701. ImageCache::incReferenceCount (image);
  67702. di->setImage (image, true);
  67703. }
  67704. }
  67705. return di;
  67706. }
  67707. ValueTree DrawableImage::createValueTree() const throw()
  67708. {
  67709. ValueTree v (T("Image"));
  67710. if (getName().isNotEmpty())
  67711. v.setProperty ("id", getName(), 0);
  67712. if (opacity < 1.0f)
  67713. v.setProperty ("opacity", (double) opacity, 0);
  67714. if (! overlayColour.isTransparent())
  67715. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67716. if (image != 0)
  67717. {
  67718. MemoryOutputStream imageData;
  67719. PNGImageFormat pngFormat;
  67720. if (pngFormat.writeImageToStream (*image, imageData))
  67721. {
  67722. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67723. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67724. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67725. v.setProperty ("data", base64, 0);
  67726. }
  67727. }
  67728. return v;
  67729. }
  67730. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67731. {
  67732. if (! tree.hasType ("Image"))
  67733. return 0;
  67734. DrawableImage* di = new DrawableImage();
  67735. di->setName (tree ["id"]);
  67736. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67737. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67738. MemoryBlock imageData;
  67739. if (imageData.fromBase64Encoding (tree ["data"]))
  67740. {
  67741. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67742. if (im == 0)
  67743. return false;
  67744. di->setImage (im, true);
  67745. }
  67746. return di;
  67747. }
  67748. END_JUCE_NAMESPACE
  67749. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67750. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67751. BEGIN_JUCE_NAMESPACE
  67752. DrawablePath::DrawablePath()
  67753. : mainFill (FillType (Colours::black)),
  67754. strokeFill (FillType (Colours::transparentBlack)),
  67755. strokeType (0.0f)
  67756. {
  67757. }
  67758. DrawablePath::~DrawablePath()
  67759. {
  67760. }
  67761. void DrawablePath::setPath (const Path& newPath) throw()
  67762. {
  67763. path = newPath;
  67764. updateOutline();
  67765. }
  67766. void DrawablePath::setFill (const FillType& newFill) throw()
  67767. {
  67768. mainFill = newFill;
  67769. }
  67770. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67771. {
  67772. strokeFill = newFill;
  67773. }
  67774. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67775. {
  67776. strokeType = newStrokeType;
  67777. updateOutline();
  67778. }
  67779. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67780. {
  67781. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67782. }
  67783. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67784. {
  67785. {
  67786. FillType f (mainFill);
  67787. if (f.isGradient())
  67788. f.gradient->multiplyOpacity (context.opacity);
  67789. f.transform = f.transform.followedBy (context.transform);
  67790. context.g.setFillType (f);
  67791. context.g.fillPath (path, context.transform);
  67792. }
  67793. if (strokeType.getStrokeThickness() > 0.0f)
  67794. {
  67795. FillType f (strokeFill);
  67796. if (f.isGradient())
  67797. f.gradient->multiplyOpacity (context.opacity);
  67798. f.transform = f.transform.followedBy (context.transform);
  67799. context.g.setFillType (f);
  67800. context.g.fillPath (stroke, context.transform);
  67801. }
  67802. }
  67803. void DrawablePath::updateOutline()
  67804. {
  67805. stroke.clear();
  67806. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67807. }
  67808. const Rectangle<float> DrawablePath::getBounds() const
  67809. {
  67810. if (strokeType.getStrokeThickness() > 0.0f)
  67811. return stroke.getBounds();
  67812. else
  67813. return path.getBounds();
  67814. }
  67815. bool DrawablePath::hitTest (float x, float y) const
  67816. {
  67817. return path.contains (x, y)
  67818. || stroke.contains (x, y);
  67819. }
  67820. Drawable* DrawablePath::createCopy() const
  67821. {
  67822. DrawablePath* const dp = new DrawablePath();
  67823. dp->path = path;
  67824. dp->stroke = stroke;
  67825. dp->mainFill = mainFill;
  67826. dp->strokeFill = strokeFill;
  67827. dp->strokeType = strokeType;
  67828. return dp;
  67829. }
  67830. static const FillType readFillTypeFromTree (const ValueTree& v)
  67831. {
  67832. const String type (v["type"].toString());
  67833. if (type.equalsIgnoreCase (T("solid")))
  67834. {
  67835. const String colour (v ["colour"].toString());
  67836. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67837. : (uint32) colour.getHexValue32()));
  67838. }
  67839. else if (type.equalsIgnoreCase ("gradient"))
  67840. {
  67841. ColourGradient g;
  67842. g.x1 = v["x1"];
  67843. g.y1 = v["y1"];
  67844. g.x2 = v["x2"];
  67845. g.y2 = v["y2"];
  67846. g.isRadial = v["radial"];
  67847. StringArray colours;
  67848. colours.addTokens (v["colours"].toString(), false);
  67849. for (int i = 0; i < colours.size() / 2; ++i)
  67850. g.addColour (colours[i * 2].getDoubleValue(),
  67851. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67852. return FillType (g);
  67853. }
  67854. jassertfalse
  67855. return FillType();
  67856. }
  67857. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67858. {
  67859. ValueTree v (tagName);
  67860. if (fillType.isColour())
  67861. {
  67862. v.setProperty ("type", T("solid"), 0);
  67863. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67864. }
  67865. else if (fillType.isGradient())
  67866. {
  67867. v.setProperty ("type", T("gradient"), 0);
  67868. v.setProperty ("x1", fillType.gradient->x1, 0);
  67869. v.setProperty ("y1", fillType.gradient->y1, 0);
  67870. v.setProperty ("x2", fillType.gradient->x2, 0);
  67871. v.setProperty ("y2", fillType.gradient->y2, 0);
  67872. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67873. String s;
  67874. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67875. s << " " << fillType.gradient->getColourPosition (i)
  67876. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67877. v.setProperty ("colours", s.trimStart(), 0);
  67878. }
  67879. else
  67880. {
  67881. jassertfalse //xxx
  67882. }
  67883. return v;
  67884. }
  67885. ValueTree DrawablePath::createValueTree() const throw()
  67886. {
  67887. ValueTree v (T("Path"));
  67888. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67889. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67890. if (getName().isNotEmpty())
  67891. v.setProperty ("id", getName(), 0);
  67892. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67893. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67894. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67895. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67896. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67897. v.setProperty ("path", path.toString(), 0);
  67898. return v;
  67899. }
  67900. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67901. {
  67902. if (! tree.hasType ("Path"))
  67903. return 0;
  67904. DrawablePath* p = new DrawablePath();
  67905. p->setName (tree ["id"]);
  67906. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67907. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67908. const String jointStyle (tree ["jointStyle"].toString());
  67909. const String endStyle (tree ["capStyle"].toString());
  67910. p->strokeType
  67911. = PathStrokeType (tree ["strokeWidth"],
  67912. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67913. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67914. : PathStrokeType::mitered),
  67915. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67916. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67917. : PathStrokeType::butt));
  67918. p->path.clear();
  67919. p->path.restoreFromString (tree ["path"]);
  67920. p->updateOutline();
  67921. return p;
  67922. }
  67923. END_JUCE_NAMESPACE
  67924. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67925. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67926. BEGIN_JUCE_NAMESPACE
  67927. DrawableText::DrawableText()
  67928. : colour (Colours::white)
  67929. {
  67930. }
  67931. DrawableText::~DrawableText()
  67932. {
  67933. }
  67934. void DrawableText::setText (const GlyphArrangement& newText)
  67935. {
  67936. text = newText;
  67937. }
  67938. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67939. {
  67940. text.clear();
  67941. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67942. }
  67943. void DrawableText::setColour (const Colour& newColour)
  67944. {
  67945. colour = newColour;
  67946. }
  67947. void DrawableText::render (const Drawable::RenderingContext& context) const
  67948. {
  67949. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67950. text.draw (context.g, context.transform);
  67951. }
  67952. const Rectangle<float> DrawableText::getBounds() const
  67953. {
  67954. float x, y, w, h;
  67955. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67956. w -= x;
  67957. h -= y;
  67958. return Rectangle<float> (x, y, w, h);
  67959. }
  67960. bool DrawableText::hitTest (float x, float y) const
  67961. {
  67962. return text.findGlyphIndexAt (x, y) >= 0;
  67963. }
  67964. Drawable* DrawableText::createCopy() const
  67965. {
  67966. DrawableText* const dt = new DrawableText();
  67967. dt->text = text;
  67968. dt->colour = colour;
  67969. return dt;
  67970. }
  67971. ValueTree DrawableText::createValueTree() const throw()
  67972. {
  67973. ValueTree v (T("Text"));
  67974. if (getName().isNotEmpty())
  67975. v.setProperty ("id", getName(), 0);
  67976. jassertfalse // xxx not finished!
  67977. return v;
  67978. }
  67979. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67980. {
  67981. if (! tree.hasType ("Text"))
  67982. return 0;
  67983. DrawableText* dt = new DrawableText();
  67984. dt->setName (tree ["id"]);
  67985. jassertfalse // xxx not finished!
  67986. return dt;
  67987. }
  67988. END_JUCE_NAMESPACE
  67989. /*** End of inlined file: juce_DrawableText.cpp ***/
  67990. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67991. BEGIN_JUCE_NAMESPACE
  67992. class SVGState
  67993. {
  67994. public:
  67995. SVGState (const XmlElement* const topLevel)
  67996. : topLevelXml (topLevel),
  67997. elementX (0), elementY (0),
  67998. width (512), height (512),
  67999. viewBoxW (0), viewBoxH (0)
  68000. {
  68001. }
  68002. ~SVGState()
  68003. {
  68004. }
  68005. Drawable* parseSVGElement (const XmlElement& xml)
  68006. {
  68007. if (! xml.hasTagName (T("svg")))
  68008. return 0;
  68009. DrawableComposite* const drawable = new DrawableComposite();
  68010. drawable->setName (xml.getStringAttribute (T("id")));
  68011. SVGState newState (*this);
  68012. if (xml.hasAttribute (T("transform")))
  68013. newState.addTransform (xml);
  68014. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  68015. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  68016. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  68017. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  68018. if (xml.hasAttribute (T("viewBox")))
  68019. {
  68020. const String viewParams (xml.getStringAttribute (T("viewBox")));
  68021. int i = 0;
  68022. float vx, vy, vw, vh;
  68023. if (parseCoords (viewParams, vx, vy, i, true)
  68024. && parseCoords (viewParams, vw, vh, i, true)
  68025. && vw > 0
  68026. && vh > 0)
  68027. {
  68028. newState.viewBoxW = vw;
  68029. newState.viewBoxH = vh;
  68030. int placementFlags = 0;
  68031. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  68032. if (aspect.containsIgnoreCase (T("none")))
  68033. {
  68034. placementFlags = RectanglePlacement::stretchToFit;
  68035. }
  68036. else
  68037. {
  68038. if (aspect.containsIgnoreCase (T("slice")))
  68039. placementFlags |= RectanglePlacement::fillDestination;
  68040. if (aspect.containsIgnoreCase (T("xMin")))
  68041. placementFlags |= RectanglePlacement::xLeft;
  68042. else if (aspect.containsIgnoreCase (T("xMax")))
  68043. placementFlags |= RectanglePlacement::xRight;
  68044. else
  68045. placementFlags |= RectanglePlacement::xMid;
  68046. if (aspect.containsIgnoreCase (T("yMin")))
  68047. placementFlags |= RectanglePlacement::yTop;
  68048. else if (aspect.containsIgnoreCase (T("yMax")))
  68049. placementFlags |= RectanglePlacement::yBottom;
  68050. else
  68051. placementFlags |= RectanglePlacement::yMid;
  68052. }
  68053. const RectanglePlacement placement (placementFlags);
  68054. newState.transform
  68055. = placement.getTransformToFit (vx, vy, vw, vh,
  68056. 0.0f, 0.0f, newState.width, newState.height)
  68057. .followedBy (newState.transform);
  68058. }
  68059. }
  68060. else
  68061. {
  68062. if (viewBoxW == 0)
  68063. newState.viewBoxW = newState.width;
  68064. if (viewBoxH == 0)
  68065. newState.viewBoxH = newState.height;
  68066. }
  68067. newState.parseSubElements (xml, drawable);
  68068. return drawable;
  68069. }
  68070. private:
  68071. const XmlElement* const topLevelXml;
  68072. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  68073. AffineTransform transform;
  68074. String cssStyleText;
  68075. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  68076. {
  68077. forEachXmlChildElement (xml, e)
  68078. {
  68079. Drawable* d = 0;
  68080. if (e->hasTagName (T("g")))
  68081. d = parseGroupElement (*e);
  68082. else if (e->hasTagName (T("svg")))
  68083. d = parseSVGElement (*e);
  68084. else if (e->hasTagName (T("path")))
  68085. d = parsePath (*e);
  68086. else if (e->hasTagName (T("rect")))
  68087. d = parseRect (*e);
  68088. else if (e->hasTagName (T("circle")))
  68089. d = parseCircle (*e);
  68090. else if (e->hasTagName (T("ellipse")))
  68091. d = parseEllipse (*e);
  68092. else if (e->hasTagName (T("line")))
  68093. d = parseLine (*e);
  68094. else if (e->hasTagName (T("polyline")))
  68095. d = parsePolygon (*e, true);
  68096. else if (e->hasTagName (T("polygon")))
  68097. d = parsePolygon (*e, false);
  68098. else if (e->hasTagName (T("text")))
  68099. d = parseText (*e);
  68100. else if (e->hasTagName (T("switch")))
  68101. d = parseSwitch (*e);
  68102. else if (e->hasTagName (T("style")))
  68103. parseCSSStyle (*e);
  68104. parentDrawable->insertDrawable (d);
  68105. }
  68106. }
  68107. DrawableComposite* parseSwitch (const XmlElement& xml)
  68108. {
  68109. const XmlElement* const group = xml.getChildByName (T("g"));
  68110. if (group != 0)
  68111. return parseGroupElement (*group);
  68112. return 0;
  68113. }
  68114. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68115. {
  68116. DrawableComposite* const drawable = new DrawableComposite();
  68117. drawable->setName (xml.getStringAttribute (T("id")));
  68118. if (xml.hasAttribute (T("transform")))
  68119. {
  68120. SVGState newState (*this);
  68121. newState.addTransform (xml);
  68122. newState.parseSubElements (xml, drawable);
  68123. }
  68124. else
  68125. {
  68126. parseSubElements (xml, drawable);
  68127. }
  68128. return drawable;
  68129. }
  68130. Drawable* parsePath (const XmlElement& xml) const
  68131. {
  68132. const String d (xml.getStringAttribute (T("d")).trimStart());
  68133. Path path;
  68134. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68135. path.setUsingNonZeroWinding (false);
  68136. int index = 0;
  68137. float lastX = 0, lastY = 0;
  68138. float lastX2 = 0, lastY2 = 0;
  68139. tchar lastCommandChar = 0;
  68140. bool carryOn = true;
  68141. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68142. for (;;)
  68143. {
  68144. float x, y, x2, y2, x3, y3;
  68145. const bool isRelative = (d[index] >= 'a' && d[index] <= 'z');
  68146. if (validCommandChars.containsChar (d[index]))
  68147. lastCommandChar = d [index++];
  68148. switch (lastCommandChar)
  68149. {
  68150. case T('M'):
  68151. case T('m'):
  68152. case T('L'):
  68153. case T('l'):
  68154. if (parseCoords (d, x, y, index, false))
  68155. {
  68156. if (isRelative)
  68157. {
  68158. x += lastX;
  68159. y += lastY;
  68160. }
  68161. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68162. path.startNewSubPath (x, y);
  68163. else
  68164. path.lineTo (x, y);
  68165. lastX2 = lastX;
  68166. lastY2 = lastY;
  68167. lastX = x;
  68168. lastY = y;
  68169. }
  68170. else
  68171. {
  68172. ++index;
  68173. }
  68174. break;
  68175. case T('H'):
  68176. case T('h'):
  68177. if (parseCoord (d, x, index, false, true))
  68178. {
  68179. if (isRelative)
  68180. x += lastX;
  68181. path.lineTo (x, lastY);
  68182. lastX2 = lastX;
  68183. lastX = x;
  68184. }
  68185. else
  68186. {
  68187. ++index;
  68188. }
  68189. break;
  68190. case T('V'):
  68191. case T('v'):
  68192. if (parseCoord (d, y, index, false, false))
  68193. {
  68194. if (isRelative)
  68195. y += lastY;
  68196. path.lineTo (lastX, y);
  68197. lastY2 = lastY;
  68198. lastY = y;
  68199. }
  68200. else
  68201. {
  68202. ++index;
  68203. }
  68204. break;
  68205. case T('C'):
  68206. case T('c'):
  68207. if (parseCoords (d, x, y, index, false)
  68208. && parseCoords (d, x2, y2, index, false)
  68209. && parseCoords (d, x3, y3, index, false))
  68210. {
  68211. if (isRelative)
  68212. {
  68213. x += lastX;
  68214. y += lastY;
  68215. x2 += lastX;
  68216. y2 += lastY;
  68217. x3 += lastX;
  68218. y3 += lastY;
  68219. }
  68220. path.cubicTo (x, y, x2, y2, x3, y3);
  68221. lastX2 = x2;
  68222. lastY2 = y2;
  68223. lastX = x3;
  68224. lastY = y3;
  68225. }
  68226. else
  68227. {
  68228. ++index;
  68229. }
  68230. break;
  68231. case T('S'):
  68232. case T('s'):
  68233. if (parseCoords (d, x, y, index, false)
  68234. && parseCoords (d, x3, y3, index, false))
  68235. {
  68236. if (isRelative)
  68237. {
  68238. x += lastX;
  68239. y += lastY;
  68240. x3 += lastX;
  68241. y3 += lastY;
  68242. }
  68243. x2 = lastX + (lastX - lastX2);
  68244. y2 = lastY + (lastY - lastY2);
  68245. path.cubicTo (x2, y2, x, y, x3, y3);
  68246. lastX2 = x;
  68247. lastY2 = y;
  68248. lastX = x3;
  68249. lastY = y3;
  68250. }
  68251. else
  68252. {
  68253. ++index;
  68254. }
  68255. break;
  68256. case T('Q'):
  68257. case T('q'):
  68258. if (parseCoords (d, x, y, index, false)
  68259. && parseCoords (d, x2, y2, index, false))
  68260. {
  68261. if (isRelative)
  68262. {
  68263. x += lastX;
  68264. y += lastY;
  68265. x2 += lastX;
  68266. y2 += lastY;
  68267. }
  68268. path.quadraticTo (x, y, x2, y2);
  68269. lastX2 = x;
  68270. lastY2 = y;
  68271. lastX = x2;
  68272. lastY = y2;
  68273. }
  68274. else
  68275. {
  68276. ++index;
  68277. }
  68278. break;
  68279. case T('T'):
  68280. case T('t'):
  68281. if (parseCoords (d, x, y, index, false))
  68282. {
  68283. if (isRelative)
  68284. {
  68285. x += lastX;
  68286. y += lastY;
  68287. }
  68288. x2 = lastX + (lastX - lastX2);
  68289. y2 = lastY + (lastY - lastY2);
  68290. path.quadraticTo (x2, y2, x, y);
  68291. lastX2 = x2;
  68292. lastY2 = y2;
  68293. lastX = x;
  68294. lastY = y;
  68295. }
  68296. else
  68297. {
  68298. ++index;
  68299. }
  68300. break;
  68301. case T('A'):
  68302. case T('a'):
  68303. if (parseCoords (d, x, y, index, false))
  68304. {
  68305. String num;
  68306. if (parseNextNumber (d, num, index, false))
  68307. {
  68308. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68309. if (parseNextNumber (d, num, index, false))
  68310. {
  68311. const bool largeArc = num.getIntValue() != 0;
  68312. if (parseNextNumber (d, num, index, false))
  68313. {
  68314. const bool sweep = num.getIntValue() != 0;
  68315. if (parseCoords (d, x2, y2, index, false))
  68316. {
  68317. if (isRelative)
  68318. {
  68319. x2 += lastX;
  68320. y2 += lastY;
  68321. }
  68322. if (lastX != x2 || lastY != y2)
  68323. {
  68324. double centreX, centreY, startAngle, deltaAngle;
  68325. double rx = x, ry = y;
  68326. endpointToCentreParameters (lastX, lastY, x2, y2,
  68327. angle, largeArc, sweep,
  68328. rx, ry, centreX, centreY,
  68329. startAngle, deltaAngle);
  68330. path.addCentredArc ((float) centreX, (float) centreY,
  68331. (float) rx, (float) ry,
  68332. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68333. false);
  68334. path.lineTo (x2, y2);
  68335. }
  68336. lastX2 = lastX;
  68337. lastY2 = lastY;
  68338. lastX = x2;
  68339. lastY = y2;
  68340. }
  68341. }
  68342. }
  68343. }
  68344. }
  68345. else
  68346. {
  68347. ++index;
  68348. }
  68349. break;
  68350. case T('Z'):
  68351. case T('z'):
  68352. path.closeSubPath();
  68353. while (CharacterFunctions::isWhitespace (d [index]))
  68354. ++index;
  68355. break;
  68356. default:
  68357. carryOn = false;
  68358. break;
  68359. }
  68360. if (! carryOn)
  68361. break;
  68362. }
  68363. return parseShape (xml, path);
  68364. }
  68365. Drawable* parseRect (const XmlElement& xml) const
  68366. {
  68367. Path rect;
  68368. const bool hasRX = xml.hasAttribute (T("rx"));
  68369. const bool hasRY = xml.hasAttribute (T("ry"));
  68370. if (hasRX || hasRY)
  68371. {
  68372. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68373. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68374. if (! hasRX)
  68375. rx = ry;
  68376. else if (! hasRY)
  68377. ry = rx;
  68378. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68379. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68380. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68381. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68382. rx, ry);
  68383. }
  68384. else
  68385. {
  68386. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68387. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68388. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68389. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68390. }
  68391. return parseShape (xml, rect);
  68392. }
  68393. Drawable* parseCircle (const XmlElement& xml) const
  68394. {
  68395. Path circle;
  68396. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68397. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68398. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68399. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68400. return parseShape (xml, circle);
  68401. }
  68402. Drawable* parseEllipse (const XmlElement& xml) const
  68403. {
  68404. Path ellipse;
  68405. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68406. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68407. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68408. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68409. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68410. return parseShape (xml, ellipse);
  68411. }
  68412. Drawable* parseLine (const XmlElement& xml) const
  68413. {
  68414. Path line;
  68415. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68416. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68417. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68418. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68419. line.startNewSubPath (x1, y1);
  68420. line.lineTo (x2, y2);
  68421. return parseShape (xml, line);
  68422. }
  68423. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68424. {
  68425. const String points (xml.getStringAttribute (T("points")));
  68426. Path path;
  68427. int index = 0;
  68428. float x, y;
  68429. if (parseCoords (points, x, y, index, true))
  68430. {
  68431. float firstX = x;
  68432. float firstY = y;
  68433. float lastX = 0, lastY = 0;
  68434. path.startNewSubPath (x, y);
  68435. while (parseCoords (points, x, y, index, true))
  68436. {
  68437. lastX = x;
  68438. lastY = y;
  68439. path.lineTo (x, y);
  68440. }
  68441. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68442. path.closeSubPath();
  68443. }
  68444. return parseShape (xml, path);
  68445. }
  68446. Drawable* parseShape (const XmlElement& xml, Path& path,
  68447. const bool shouldParseTransform = true) const
  68448. {
  68449. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68450. {
  68451. SVGState newState (*this);
  68452. newState.addTransform (xml);
  68453. return newState.parseShape (xml, path, false);
  68454. }
  68455. DrawablePath* dp = new DrawablePath();
  68456. dp->setName (xml.getStringAttribute (T("id")));
  68457. dp->setFill (FillType (Colours::transparentBlack));
  68458. path.applyTransform (transform);
  68459. dp->setPath (path);
  68460. Path::Iterator iter (path);
  68461. bool containsClosedSubPath = false;
  68462. while (iter.next())
  68463. {
  68464. if (iter.elementType == Path::Iterator::closePath)
  68465. {
  68466. containsClosedSubPath = true;
  68467. break;
  68468. }
  68469. }
  68470. dp->setFill (getPathFillType (path,
  68471. getStyleAttribute (&xml, T("fill")),
  68472. getStyleAttribute (&xml, T("fill-opacity")),
  68473. getStyleAttribute (&xml, T("opacity")),
  68474. containsClosedSubPath ? Colours::black
  68475. : Colours::transparentBlack));
  68476. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68477. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68478. {
  68479. dp->setStrokeFill (getPathFillType (path, strokeType,
  68480. getStyleAttribute (&xml, T("stroke-opacity")),
  68481. getStyleAttribute (&xml, T("opacity")),
  68482. Colours::transparentBlack));
  68483. dp->setStrokeType (getStrokeFor (&xml));
  68484. }
  68485. return dp;
  68486. }
  68487. const XmlElement* findLinkedElement (const XmlElement* e) const
  68488. {
  68489. const String id (e->getStringAttribute (T("xlink:href")));
  68490. if (! id.startsWithChar (T('#')))
  68491. return 0;
  68492. return findElementForId (topLevelXml, id.substring (1));
  68493. }
  68494. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68495. {
  68496. if (fillXml == 0)
  68497. return;
  68498. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68499. {
  68500. int index = 0;
  68501. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68502. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68503. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68504. double offset = e->getDoubleAttribute (T("offset"));
  68505. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68506. offset *= 0.01;
  68507. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68508. }
  68509. }
  68510. const FillType getPathFillType (const Path& path,
  68511. const String& fill,
  68512. const String& fillOpacity,
  68513. const String& overallOpacity,
  68514. const Colour& defaultColour) const
  68515. {
  68516. float opacity = 1.0f;
  68517. if (overallOpacity.isNotEmpty())
  68518. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68519. if (fillOpacity.isNotEmpty())
  68520. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68521. if (fill.startsWithIgnoreCase (T("url")))
  68522. {
  68523. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68524. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68525. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68526. if (fillXml != 0
  68527. && (fillXml->hasTagName (T("linearGradient"))
  68528. || fillXml->hasTagName (T("radialGradient"))))
  68529. {
  68530. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68531. ColourGradient gradient;
  68532. addGradientStopsIn (gradient, inheritedFrom);
  68533. addGradientStopsIn (gradient, fillXml);
  68534. if (gradient.getNumColours() > 0)
  68535. {
  68536. gradient.addColour (0.0, gradient.getColour (0));
  68537. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68538. }
  68539. else
  68540. {
  68541. gradient.addColour (0.0, Colours::black);
  68542. gradient.addColour (1.0, Colours::black);
  68543. }
  68544. if (overallOpacity.isNotEmpty())
  68545. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68546. jassert (gradient.getNumColours() > 0);
  68547. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68548. float width = viewBoxW;
  68549. float height = viewBoxH;
  68550. float dx = 0.0f;
  68551. float dy = 0.0f;
  68552. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68553. if (! userSpace)
  68554. {
  68555. const Rectangle<float> bounds (path.getBounds());
  68556. dx = bounds.getX();
  68557. dy = bounds.getY();
  68558. width = bounds.getWidth();
  68559. height = bounds.getHeight();
  68560. }
  68561. if (gradient.isRadial)
  68562. {
  68563. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68564. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68565. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68566. gradient.x2 = gradient.x1 + radius;
  68567. gradient.y2 = gradient.y1;
  68568. //xxx (the fx, fy focal point isn't handled properly here..)
  68569. }
  68570. else
  68571. {
  68572. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68573. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68574. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68575. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68576. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68577. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68578. }
  68579. FillType type (gradient);
  68580. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68581. .followedBy (transform);
  68582. return type;
  68583. }
  68584. }
  68585. if (fill.equalsIgnoreCase (T("none")))
  68586. return Colours::transparentBlack;
  68587. int i = 0;
  68588. const Colour colour (parseColour (fill, i, defaultColour));
  68589. return colour.withMultipliedAlpha (opacity);
  68590. }
  68591. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68592. {
  68593. const String width (getStyleAttribute (xml, T("stroke-width")));
  68594. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68595. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68596. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68597. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68598. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68599. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68600. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68601. if (join.equalsIgnoreCase (T("round")))
  68602. joinStyle = PathStrokeType::curved;
  68603. else if (join.equalsIgnoreCase (T("bevel")))
  68604. joinStyle = PathStrokeType::beveled;
  68605. if (cap.equalsIgnoreCase (T("round")))
  68606. capStyle = PathStrokeType::rounded;
  68607. else if (cap.equalsIgnoreCase (T("square")))
  68608. capStyle = PathStrokeType::square;
  68609. float ox = 0.0f, oy = 0.0f;
  68610. transform.transformPoint (ox, oy);
  68611. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68612. transform.transformPoint (x, y);
  68613. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68614. joinStyle, capStyle);
  68615. }
  68616. Drawable* parseText (const XmlElement& xml)
  68617. {
  68618. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68619. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68620. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68621. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68622. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68623. //xxx not done text yet!
  68624. forEachXmlChildElement (xml, e)
  68625. {
  68626. if (e->isTextElement())
  68627. {
  68628. const String text (e->getText());
  68629. Path path;
  68630. Drawable* s = parseShape (*e, path);
  68631. delete s;
  68632. }
  68633. else if (e->hasTagName (T("tspan")))
  68634. {
  68635. Drawable* s = parseText (*e);
  68636. delete s;
  68637. }
  68638. }
  68639. return 0;
  68640. }
  68641. void addTransform (const XmlElement& xml)
  68642. {
  68643. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68644. .followedBy (transform);
  68645. }
  68646. bool parseCoord (const String& s, float& value, int& index,
  68647. const bool allowUnits, const bool isX) const
  68648. {
  68649. String number;
  68650. if (! parseNextNumber (s, number, index, allowUnits))
  68651. {
  68652. value = 0;
  68653. return false;
  68654. }
  68655. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68656. return true;
  68657. }
  68658. bool parseCoords (const String& s, float& x, float& y,
  68659. int& index, const bool allowUnits) const
  68660. {
  68661. return parseCoord (s, x, index, allowUnits, true)
  68662. && parseCoord (s, y, index, allowUnits, false);
  68663. }
  68664. float getCoordLength (const String& s, const float sizeForProportions) const
  68665. {
  68666. float n = s.getFloatValue();
  68667. const int len = s.length();
  68668. if (len > 2)
  68669. {
  68670. const float dpi = 96.0f;
  68671. const tchar n1 = s [len - 2];
  68672. const tchar n2 = s [len - 1];
  68673. if (n1 == T('i') && n2 == T('n'))
  68674. n *= dpi;
  68675. else if (n1 == T('m') && n2 == T('m'))
  68676. n *= dpi / 25.4f;
  68677. else if (n1 == T('c') && n2 == T('m'))
  68678. n *= dpi / 2.54f;
  68679. else if (n1 == T('p') && n2 == T('c'))
  68680. n *= 15.0f;
  68681. else if (n2 == T('%'))
  68682. n *= 0.01f * sizeForProportions;
  68683. }
  68684. return n;
  68685. }
  68686. void getCoordList (Array <float>& coords, const String& list,
  68687. const bool allowUnits, const bool isX) const
  68688. {
  68689. int index = 0;
  68690. float value;
  68691. while (parseCoord (list, value, index, allowUnits, isX))
  68692. coords.add (value);
  68693. }
  68694. void parseCSSStyle (const XmlElement& xml)
  68695. {
  68696. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68697. }
  68698. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68699. const String& defaultValue = String::empty) const
  68700. {
  68701. if (xml->hasAttribute (attributeName))
  68702. return xml->getStringAttribute (attributeName, defaultValue);
  68703. const String styleAtt (xml->getStringAttribute (T("style")));
  68704. if (styleAtt.isNotEmpty())
  68705. {
  68706. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68707. if (value.isNotEmpty())
  68708. return value;
  68709. }
  68710. else if (xml->hasAttribute (T("class")))
  68711. {
  68712. const String className (T(".") + xml->getStringAttribute (T("class")));
  68713. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68714. if (index < 0)
  68715. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68716. if (index >= 0)
  68717. {
  68718. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68719. if (openBracket > index)
  68720. {
  68721. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68722. if (closeBracket > openBracket)
  68723. {
  68724. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68725. if (value.isNotEmpty())
  68726. return value;
  68727. }
  68728. }
  68729. }
  68730. }
  68731. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68732. if (xml != 0)
  68733. return getStyleAttribute (xml, attributeName, defaultValue);
  68734. return defaultValue;
  68735. }
  68736. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68737. {
  68738. if (xml->hasAttribute (attributeName))
  68739. return xml->getStringAttribute (attributeName);
  68740. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68741. if (xml != 0)
  68742. return getInheritedAttribute (xml, attributeName);
  68743. return String::empty;
  68744. }
  68745. static bool isIdentifierChar (const tchar c)
  68746. {
  68747. return CharacterFunctions::isLetter (c) || c == T('-');
  68748. }
  68749. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68750. {
  68751. int i = 0;
  68752. for (;;)
  68753. {
  68754. i = list.indexOf (i, attributeName);
  68755. if (i < 0)
  68756. break;
  68757. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68758. && ! isIdentifierChar (list [i + attributeName.length()]))
  68759. {
  68760. i = list.indexOfChar (i, T(':'));
  68761. if (i < 0)
  68762. break;
  68763. int end = list.indexOfChar (i, T(';'));
  68764. if (end < 0)
  68765. end = 0x7ffff;
  68766. return list.substring (i + 1, end).trim();
  68767. }
  68768. ++i;
  68769. }
  68770. return defaultValue;
  68771. }
  68772. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68773. {
  68774. const tchar* const s = (const tchar*) source;
  68775. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68776. ++index;
  68777. int start = index;
  68778. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68779. ++index;
  68780. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68781. ++index;
  68782. if ((s[index] == T('e') || s[index] == T('E'))
  68783. && (CharacterFunctions::isDigit (s[index + 1])
  68784. || s[index + 1] == T('-')
  68785. || s[index + 1] == T('+')))
  68786. {
  68787. index += 2;
  68788. while (CharacterFunctions::isDigit (s[index]))
  68789. ++index;
  68790. }
  68791. if (allowUnits)
  68792. {
  68793. while (CharacterFunctions::isLetter (s[index]))
  68794. ++index;
  68795. }
  68796. if (index == start)
  68797. return false;
  68798. value = String (s + start, index - start);
  68799. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68800. ++index;
  68801. return true;
  68802. }
  68803. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68804. {
  68805. if (s [index] == T('#'))
  68806. {
  68807. uint32 hex [6];
  68808. zeromem (hex, sizeof (hex));
  68809. int numChars = 0;
  68810. for (int i = 6; --i >= 0;)
  68811. {
  68812. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68813. if (hexValue >= 0)
  68814. hex [numChars++] = hexValue;
  68815. else
  68816. break;
  68817. }
  68818. if (numChars <= 3)
  68819. return Colour ((uint8) (hex [0] * 0x11),
  68820. (uint8) (hex [1] * 0x11),
  68821. (uint8) (hex [2] * 0x11));
  68822. else
  68823. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68824. (uint8) ((hex [2] << 4) + hex [3]),
  68825. (uint8) ((hex [4] << 4) + hex [5]));
  68826. }
  68827. else if (s [index] == T('r')
  68828. && s [index + 1] == T('g')
  68829. && s [index + 2] == T('b'))
  68830. {
  68831. const int openBracket = s.indexOfChar (index, T('('));
  68832. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68833. if (openBracket >= 3 && closeBracket > openBracket)
  68834. {
  68835. index = closeBracket;
  68836. StringArray tokens;
  68837. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68838. tokens.trim();
  68839. tokens.removeEmptyStrings();
  68840. if (tokens[0].containsChar (T('%')))
  68841. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68842. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68843. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68844. else
  68845. return Colour ((uint8) tokens[0].getIntValue(),
  68846. (uint8) tokens[1].getIntValue(),
  68847. (uint8) tokens[2].getIntValue());
  68848. }
  68849. }
  68850. return Colours::findColourForName (s, defaultColour);
  68851. }
  68852. static const AffineTransform parseTransform (String t)
  68853. {
  68854. AffineTransform result;
  68855. while (t.isNotEmpty())
  68856. {
  68857. StringArray tokens;
  68858. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68859. .upToFirstOccurrenceOf (T(")"), false, false),
  68860. T(", "), 0);
  68861. tokens.removeEmptyStrings (true);
  68862. float numbers [6];
  68863. for (int i = 0; i < 6; ++i)
  68864. numbers[i] = tokens[i].getFloatValue();
  68865. AffineTransform trans;
  68866. if (t.startsWithIgnoreCase (T("matrix")))
  68867. {
  68868. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68869. numbers[1], numbers[3], numbers[5]);
  68870. }
  68871. else if (t.startsWithIgnoreCase (T("translate")))
  68872. {
  68873. trans = trans.translated (numbers[0], numbers[1]);
  68874. }
  68875. else if (t.startsWithIgnoreCase (T("scale")))
  68876. {
  68877. if (tokens.size() == 1)
  68878. trans = trans.scaled (numbers[0], numbers[0]);
  68879. else
  68880. trans = trans.scaled (numbers[0], numbers[1]);
  68881. }
  68882. else if (t.startsWithIgnoreCase (T("rotate")))
  68883. {
  68884. if (tokens.size() != 3)
  68885. trans = trans.rotated (numbers[0] / (180.0f / float_Pi));
  68886. else
  68887. trans = trans.rotated (numbers[0] / (180.0f / float_Pi),
  68888. numbers[1], numbers[2]);
  68889. }
  68890. else if (t.startsWithIgnoreCase (T("skewX")))
  68891. {
  68892. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68893. 0.0f, 1.0f, 0.0f);
  68894. }
  68895. else if (t.startsWithIgnoreCase (T("skewY")))
  68896. {
  68897. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68898. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68899. }
  68900. result = trans.followedBy (result);
  68901. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68902. }
  68903. return result;
  68904. }
  68905. static void endpointToCentreParameters (const double x1, const double y1,
  68906. const double x2, const double y2,
  68907. const double angle,
  68908. const bool largeArc, const bool sweep,
  68909. double& rx, double& ry,
  68910. double& centreX, double& centreY,
  68911. double& startAngle, double& deltaAngle)
  68912. {
  68913. const double midX = (x1 - x2) * 0.5;
  68914. const double midY = (y1 - y2) * 0.5;
  68915. const double cosAngle = cos (angle);
  68916. const double sinAngle = sin (angle);
  68917. const double xp = cosAngle * midX + sinAngle * midY;
  68918. const double yp = cosAngle * midY - sinAngle * midX;
  68919. const double xp2 = xp * xp;
  68920. const double yp2 = yp * yp;
  68921. double rx2 = rx * rx;
  68922. double ry2 = ry * ry;
  68923. const double s = (xp2 / rx2) + (yp2 / ry2);
  68924. double c;
  68925. if (s <= 1.0)
  68926. {
  68927. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68928. / (( rx2 * yp2) + (ry2 * xp2))));
  68929. if (largeArc == sweep)
  68930. c = -c;
  68931. }
  68932. else
  68933. {
  68934. const double s2 = sqrt (s);
  68935. rx *= s2;
  68936. ry *= s2;
  68937. rx2 = rx * rx;
  68938. ry2 = ry * ry;
  68939. c = 0;
  68940. }
  68941. const double cpx = ((rx * yp) / ry) * c;
  68942. const double cpy = ((-ry * xp) / rx) * c;
  68943. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68944. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68945. const double ux = (xp - cpx) / rx;
  68946. const double uy = (yp - cpy) / ry;
  68947. const double vx = (-xp - cpx) / rx;
  68948. const double vy = (-yp - cpy) / ry;
  68949. const double length = juce_hypot (ux, uy);
  68950. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68951. if (uy < 0)
  68952. startAngle = -startAngle;
  68953. startAngle += double_Pi * 0.5;
  68954. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68955. / (length * juce_hypot (vx, vy))));
  68956. if ((ux * vy) - (uy * vx) < 0)
  68957. deltaAngle = -deltaAngle;
  68958. if (sweep)
  68959. {
  68960. if (deltaAngle < 0)
  68961. deltaAngle += double_Pi * 2.0;
  68962. }
  68963. else
  68964. {
  68965. if (deltaAngle > 0)
  68966. deltaAngle -= double_Pi * 2.0;
  68967. }
  68968. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68969. }
  68970. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68971. {
  68972. forEachXmlChildElement (*parent, e)
  68973. {
  68974. if (e->compareAttribute (T("id"), id))
  68975. return e;
  68976. const XmlElement* const found = findElementForId (e, id);
  68977. if (found != 0)
  68978. return found;
  68979. }
  68980. return 0;
  68981. }
  68982. const SVGState& operator= (const SVGState&);
  68983. };
  68984. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68985. {
  68986. SVGState state (&svgDocument);
  68987. return state.parseSVGElement (svgDocument);
  68988. }
  68989. END_JUCE_NAMESPACE
  68990. /*** End of inlined file: juce_SVGParser.cpp ***/
  68991. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68992. BEGIN_JUCE_NAMESPACE
  68993. #if JUCE_MSVC
  68994. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68995. #endif
  68996. DropShadowEffect::DropShadowEffect()
  68997. : offsetX (0),
  68998. offsetY (0),
  68999. radius (4),
  69000. opacity (0.6f)
  69001. {
  69002. }
  69003. DropShadowEffect::~DropShadowEffect()
  69004. {
  69005. }
  69006. void DropShadowEffect::setShadowProperties (const float newRadius,
  69007. const float newOpacity,
  69008. const int newShadowOffsetX,
  69009. const int newShadowOffsetY)
  69010. {
  69011. radius = jmax (1.1f, newRadius);
  69012. offsetX = newShadowOffsetX;
  69013. offsetY = newShadowOffsetY;
  69014. opacity = newOpacity;
  69015. }
  69016. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  69017. {
  69018. const int w = image.getWidth();
  69019. const int h = image.getHeight();
  69020. Image shadowImage (Image::SingleChannel, w, h, false);
  69021. const Image::BitmapData srcData (image, 0, 0, w, h);
  69022. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  69023. const int filter = roundToInt (63.0f / radius);
  69024. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  69025. for (int x = w; --x >= 0;)
  69026. {
  69027. int shadowAlpha = 0;
  69028. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  69029. uint8* shadowPix = destData.data + x;
  69030. for (int y = h; --y >= 0;)
  69031. {
  69032. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  69033. *shadowPix = (uint8) shadowAlpha;
  69034. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  69035. shadowPix += destData.lineStride;
  69036. }
  69037. }
  69038. for (int y = h; --y >= 0;)
  69039. {
  69040. int shadowAlpha = 0;
  69041. uint8* shadowPix = destData.getLinePointer (y);
  69042. for (int x = w; --x >= 0;)
  69043. {
  69044. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  69045. *shadowPix++ = (uint8) shadowAlpha;
  69046. }
  69047. }
  69048. g.setColour (Colours::black.withAlpha (opacity));
  69049. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  69050. g.setOpacity (1.0f);
  69051. g.drawImageAt (&image, 0, 0);
  69052. }
  69053. END_JUCE_NAMESPACE
  69054. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  69055. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  69056. BEGIN_JUCE_NAMESPACE
  69057. GlowEffect::GlowEffect()
  69058. : radius (2.0f),
  69059. colour (Colours::white)
  69060. {
  69061. }
  69062. GlowEffect::~GlowEffect()
  69063. {
  69064. }
  69065. void GlowEffect::setGlowProperties (const float newRadius,
  69066. const Colour& newColour)
  69067. {
  69068. radius = newRadius;
  69069. colour = newColour;
  69070. }
  69071. void GlowEffect::applyEffect (Image& image, Graphics& g)
  69072. {
  69073. const int w = image.getWidth();
  69074. const int h = image.getHeight();
  69075. Image temp (image.getFormat(), w, h, true);
  69076. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  69077. blurKernel.createGaussianBlur (radius);
  69078. blurKernel.rescaleAllValues (radius);
  69079. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  69080. g.setColour (colour);
  69081. g.drawImageAt (&temp, 0, 0, true);
  69082. g.setOpacity (1.0f);
  69083. g.drawImageAt (&image, 0, 0, false);
  69084. }
  69085. END_JUCE_NAMESPACE
  69086. /*** End of inlined file: juce_GlowEffect.cpp ***/
  69087. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69088. BEGIN_JUCE_NAMESPACE
  69089. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  69090. : opacity (opacity_)
  69091. {
  69092. }
  69093. ReduceOpacityEffect::~ReduceOpacityEffect()
  69094. {
  69095. }
  69096. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69097. {
  69098. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69099. }
  69100. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69101. {
  69102. g.setOpacity (opacity);
  69103. g.drawImageAt (&image, 0, 0);
  69104. }
  69105. END_JUCE_NAMESPACE
  69106. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69107. /*** Start of inlined file: juce_Font.cpp ***/
  69108. BEGIN_JUCE_NAMESPACE
  69109. static const float minFontHeight = 0.1f;
  69110. static const float maxFontHeight = 10000.0f;
  69111. static const float defaultFontHeight = 14.0f;
  69112. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69113. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69114. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69115. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69116. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69117. const float kerning_, const float ascent_, const int styleFlags_,
  69118. Typeface* const typeface_) throw()
  69119. : typefaceName (typefaceName_),
  69120. height (height_),
  69121. horizontalScale (horizontalScale_),
  69122. kerning (kerning_),
  69123. ascent (ascent_),
  69124. styleFlags (styleFlags_),
  69125. typeface (typeface_)
  69126. {
  69127. }
  69128. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69129. : typefaceName (other.typefaceName),
  69130. height (other.height),
  69131. horizontalScale (other.horizontalScale),
  69132. kerning (other.kerning),
  69133. ascent (other.ascent),
  69134. styleFlags (other.styleFlags),
  69135. typeface (other.typeface)
  69136. {
  69137. }
  69138. Font::Font() throw()
  69139. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69140. 1.0f, 0, 0, Font::plain, 0))
  69141. {
  69142. }
  69143. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69144. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69145. 1.0f, 0, 0, styleFlags_, 0))
  69146. {
  69147. }
  69148. Font::Font (const String& typefaceName_,
  69149. const float fontHeight,
  69150. const int styleFlags_) throw()
  69151. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69152. 1.0f, 0, 0, styleFlags_, 0))
  69153. {
  69154. }
  69155. Font::Font (const Font& other) throw()
  69156. : font (other.font)
  69157. {
  69158. }
  69159. const Font& Font::operator= (const Font& other) throw()
  69160. {
  69161. font = other.font;
  69162. return *this;
  69163. }
  69164. Font::~Font() throw()
  69165. {
  69166. }
  69167. Font::Font (const Typeface::Ptr& typeface) throw()
  69168. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69169. 1.0f, 0, 0, Font::plain, typeface))
  69170. {
  69171. }
  69172. bool Font::operator== (const Font& other) const throw()
  69173. {
  69174. return font == other.font
  69175. || (font->height == other.font->height
  69176. && font->styleFlags == other.font->styleFlags
  69177. && font->horizontalScale == other.font->horizontalScale
  69178. && font->kerning == other.font->kerning
  69179. && font->typefaceName == other.font->typefaceName);
  69180. }
  69181. bool Font::operator!= (const Font& other) const throw()
  69182. {
  69183. return ! operator== (other);
  69184. }
  69185. void Font::dupeInternalIfShared() throw()
  69186. {
  69187. if (font->getReferenceCount() > 1)
  69188. font = new SharedFontInternal (*font);
  69189. }
  69190. const String Font::getDefaultSansSerifFontName() throw()
  69191. {
  69192. return juce_defaultFontNameSans;
  69193. }
  69194. const String Font::getDefaultSerifFontName() throw()
  69195. {
  69196. return juce_defaultFontNameSerif;
  69197. }
  69198. const String Font::getDefaultMonospacedFontName() throw()
  69199. {
  69200. return juce_defaultFontNameMono;
  69201. }
  69202. void Font::setTypefaceName (const String& faceName) throw()
  69203. {
  69204. if (faceName != font->typefaceName)
  69205. {
  69206. dupeInternalIfShared();
  69207. font->typefaceName = faceName;
  69208. font->typeface = 0;
  69209. font->ascent = 0;
  69210. }
  69211. }
  69212. static String fallbackFont;
  69213. const String Font::getFallbackFontName() throw()
  69214. {
  69215. return fallbackFont;
  69216. }
  69217. void Font::setFallbackFontName (const String& name) throw()
  69218. {
  69219. fallbackFont = name;
  69220. }
  69221. void Font::setHeight (float newHeight) throw()
  69222. {
  69223. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69224. if (font->height != newHeight)
  69225. {
  69226. dupeInternalIfShared();
  69227. font->height = newHeight;
  69228. }
  69229. }
  69230. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69231. {
  69232. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69233. if (font->height != newHeight)
  69234. {
  69235. dupeInternalIfShared();
  69236. font->horizontalScale *= (font->height / newHeight);
  69237. font->height = newHeight;
  69238. }
  69239. }
  69240. void Font::setStyleFlags (const int newFlags) throw()
  69241. {
  69242. if (font->styleFlags != newFlags)
  69243. {
  69244. dupeInternalIfShared();
  69245. font->styleFlags = newFlags;
  69246. font->typeface = 0;
  69247. font->ascent = 0;
  69248. }
  69249. }
  69250. void Font::setSizeAndStyle (float newHeight,
  69251. const int newStyleFlags,
  69252. const float newHorizontalScale,
  69253. const float newKerningAmount) throw()
  69254. {
  69255. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69256. if (font->height != newHeight
  69257. || font->horizontalScale != newHorizontalScale
  69258. || font->kerning != newKerningAmount)
  69259. {
  69260. dupeInternalIfShared();
  69261. font->height = newHeight;
  69262. font->horizontalScale = newHorizontalScale;
  69263. font->kerning = newKerningAmount;
  69264. }
  69265. setStyleFlags (newStyleFlags);
  69266. }
  69267. void Font::setHorizontalScale (const float scaleFactor) throw()
  69268. {
  69269. dupeInternalIfShared();
  69270. font->horizontalScale = scaleFactor;
  69271. }
  69272. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69273. {
  69274. dupeInternalIfShared();
  69275. font->kerning = extraKerning;
  69276. }
  69277. void Font::setBold (const bool shouldBeBold) throw()
  69278. {
  69279. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69280. : (font->styleFlags & ~bold));
  69281. }
  69282. bool Font::isBold() const throw()
  69283. {
  69284. return (font->styleFlags & bold) != 0;
  69285. }
  69286. void Font::setItalic (const bool shouldBeItalic) throw()
  69287. {
  69288. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69289. : (font->styleFlags & ~italic));
  69290. }
  69291. bool Font::isItalic() const throw()
  69292. {
  69293. return (font->styleFlags & italic) != 0;
  69294. }
  69295. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69296. {
  69297. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69298. : (font->styleFlags & ~underlined));
  69299. }
  69300. bool Font::isUnderlined() const throw()
  69301. {
  69302. return (font->styleFlags & underlined) != 0;
  69303. }
  69304. float Font::getAscent() const throw()
  69305. {
  69306. if (font->ascent == 0)
  69307. font->ascent = getTypeface()->getAscent();
  69308. return font->height * font->ascent;
  69309. }
  69310. float Font::getDescent() const throw()
  69311. {
  69312. return font->height - getAscent();
  69313. }
  69314. int Font::getStringWidth (const String& text) const throw()
  69315. {
  69316. return roundToInt (getStringWidthFloat (text));
  69317. }
  69318. float Font::getStringWidthFloat (const String& text) const throw()
  69319. {
  69320. float w = getTypeface()->getStringWidth (text);
  69321. if (font->kerning != 0)
  69322. w += font->kerning * text.length();
  69323. return w * font->height * font->horizontalScale;
  69324. }
  69325. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69326. {
  69327. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69328. const float scale = font->height * font->horizontalScale;
  69329. const int num = xOffsets.size();
  69330. if (num > 0)
  69331. {
  69332. float* const x = &(xOffsets.getReference(0));
  69333. if (font->kerning != 0)
  69334. {
  69335. for (int i = 0; i < num; ++i)
  69336. x[i] = (x[i] + i * font->kerning) * scale;
  69337. }
  69338. else
  69339. {
  69340. for (int i = 0; i < num; ++i)
  69341. x[i] *= scale;
  69342. }
  69343. }
  69344. }
  69345. void Font::findFonts (OwnedArray<Font>& destArray) throw()
  69346. {
  69347. const StringArray names (findAllTypefaceNames());
  69348. for (int i = 0; i < names.size(); ++i)
  69349. destArray.add (new Font (names[i], defaultFontHeight, Font::plain));
  69350. }
  69351. class TypefaceCache : public DeletedAtShutdown
  69352. {
  69353. public:
  69354. TypefaceCache (int numToCache = 10) throw()
  69355. : counter (1)
  69356. {
  69357. while (--numToCache >= 0)
  69358. faces.add (new CachedFace());
  69359. }
  69360. ~TypefaceCache()
  69361. {
  69362. clearUpDefaultFontNames();
  69363. clearSingletonInstance();
  69364. }
  69365. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69366. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69367. {
  69368. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69369. const String faceName (font.getTypefaceName());
  69370. int i;
  69371. for (i = faces.size(); --i >= 0;)
  69372. {
  69373. CachedFace* const face = faces.getUnchecked(i);
  69374. if (face->flags == flags
  69375. && face->typefaceName == faceName)
  69376. {
  69377. face->lastUsageCount = ++counter;
  69378. return face->typeFace;
  69379. }
  69380. }
  69381. int replaceIndex = 0;
  69382. int bestLastUsageCount = std::numeric_limits<int>::max();
  69383. for (i = faces.size(); --i >= 0;)
  69384. {
  69385. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69386. if (bestLastUsageCount > lu)
  69387. {
  69388. bestLastUsageCount = lu;
  69389. replaceIndex = i;
  69390. }
  69391. }
  69392. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69393. face->typefaceName = faceName;
  69394. face->flags = flags;
  69395. face->lastUsageCount = ++counter;
  69396. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69397. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69398. return face->typeFace;
  69399. }
  69400. juce_UseDebuggingNewOperator
  69401. private:
  69402. struct CachedFace
  69403. {
  69404. CachedFace() throw()
  69405. : lastUsageCount (0), flags (-1)
  69406. {
  69407. }
  69408. String typefaceName;
  69409. int lastUsageCount;
  69410. int flags;
  69411. Typeface::Ptr typeFace;
  69412. };
  69413. int counter;
  69414. OwnedArray <CachedFace> faces;
  69415. TypefaceCache (const TypefaceCache&);
  69416. const TypefaceCache& operator= (const TypefaceCache&);
  69417. };
  69418. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69419. Typeface* Font::getTypeface() const throw()
  69420. {
  69421. if (font->typeface == 0)
  69422. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69423. return font->typeface;
  69424. }
  69425. END_JUCE_NAMESPACE
  69426. /*** End of inlined file: juce_Font.cpp ***/
  69427. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69428. BEGIN_JUCE_NAMESPACE
  69429. PositionedGlyph::PositionedGlyph()
  69430. {
  69431. }
  69432. void PositionedGlyph::draw (const Graphics& g) const
  69433. {
  69434. if (! isWhitespace())
  69435. {
  69436. g.getInternalContext()->setFont (font);
  69437. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69438. }
  69439. }
  69440. void PositionedGlyph::draw (const Graphics& g,
  69441. const AffineTransform& transform) const
  69442. {
  69443. if (! isWhitespace())
  69444. {
  69445. g.getInternalContext()->setFont (font);
  69446. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69447. .followedBy (transform));
  69448. }
  69449. }
  69450. void PositionedGlyph::createPath (Path& path) const
  69451. {
  69452. if (! isWhitespace())
  69453. {
  69454. Typeface* const t = font.getTypeface();
  69455. if (t != 0)
  69456. {
  69457. Path p;
  69458. t->getOutlineForGlyph (glyph, p);
  69459. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69460. .translated (x, y));
  69461. }
  69462. }
  69463. }
  69464. bool PositionedGlyph::hitTest (float px, float py) const
  69465. {
  69466. if (px >= getLeft() && px < getRight()
  69467. && py >= getTop() && py < getBottom()
  69468. && ! isWhitespace())
  69469. {
  69470. Typeface* const t = font.getTypeface();
  69471. if (t != 0)
  69472. {
  69473. Path p;
  69474. t->getOutlineForGlyph (glyph, p);
  69475. AffineTransform::translation (-x, -y)
  69476. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69477. .transformPoint (px, py);
  69478. return p.contains (px, py);
  69479. }
  69480. }
  69481. return false;
  69482. }
  69483. void PositionedGlyph::moveBy (const float deltaX,
  69484. const float deltaY)
  69485. {
  69486. x += deltaX;
  69487. y += deltaY;
  69488. }
  69489. GlyphArrangement::GlyphArrangement()
  69490. {
  69491. glyphs.ensureStorageAllocated (128);
  69492. }
  69493. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69494. {
  69495. addGlyphArrangement (other);
  69496. }
  69497. const GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69498. {
  69499. if (this != &other)
  69500. {
  69501. clear();
  69502. addGlyphArrangement (other);
  69503. }
  69504. return *this;
  69505. }
  69506. GlyphArrangement::~GlyphArrangement()
  69507. {
  69508. }
  69509. void GlyphArrangement::clear()
  69510. {
  69511. glyphs.clear();
  69512. }
  69513. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69514. {
  69515. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69516. return *glyphs [index];
  69517. }
  69518. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69519. {
  69520. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69521. for (int i = 0; i < other.glyphs.size(); ++i)
  69522. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69523. }
  69524. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69525. {
  69526. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69527. }
  69528. void GlyphArrangement::addLineOfText (const Font& font,
  69529. const String& text,
  69530. const float xOffset,
  69531. const float yOffset)
  69532. {
  69533. addCurtailedLineOfText (font, text,
  69534. xOffset, yOffset,
  69535. 1.0e10f, false);
  69536. }
  69537. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69538. const String& text,
  69539. float xOffset,
  69540. const float yOffset,
  69541. const float maxWidthPixels,
  69542. const bool useEllipsis)
  69543. {
  69544. int textLen = text.length();
  69545. if (textLen > 0)
  69546. {
  69547. Array <int> newGlyphs;
  69548. Array <float> xOffsets;
  69549. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69550. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69551. textLen = jmin (textLen, newGlyphs.size());
  69552. for (int i = 0; i < textLen; ++i)
  69553. {
  69554. const float thisX = xOffsets.getUnchecked (i);
  69555. const float nextX = xOffsets.getUnchecked (i + 1);
  69556. if (nextX > maxWidthPixels + 1.0f)
  69557. {
  69558. // curtail the string if it's too wide..
  69559. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69560. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69561. break;
  69562. }
  69563. else
  69564. {
  69565. PositionedGlyph* const pg = new PositionedGlyph();
  69566. pg->x = xOffset + thisX;
  69567. pg->y = yOffset;
  69568. pg->w = nextX - thisX;
  69569. pg->font = font;
  69570. pg->glyph = newGlyphs.getUnchecked(i);
  69571. pg->character = unicodeText[i];
  69572. glyphs.add (pg);
  69573. }
  69574. }
  69575. }
  69576. }
  69577. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69578. const int startIndex, int endIndex)
  69579. {
  69580. int numDeleted = 0;
  69581. if (glyphs.size() > 0)
  69582. {
  69583. Array<int> dotGlyphs;
  69584. Array<float> dotXs;
  69585. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69586. const float dx = dotXs[1];
  69587. float xOffset = 0.0f, yOffset = 0.0f;
  69588. while (endIndex > startIndex)
  69589. {
  69590. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69591. xOffset = pg->x;
  69592. yOffset = pg->y;
  69593. glyphs.remove (endIndex);
  69594. ++numDeleted;
  69595. if (xOffset + dx * 3 <= maxXPos)
  69596. break;
  69597. }
  69598. for (int i = 3; --i >= 0;)
  69599. {
  69600. PositionedGlyph* const pg = new PositionedGlyph();
  69601. pg->x = xOffset;
  69602. pg->y = yOffset;
  69603. pg->w = dx;
  69604. pg->font = font;
  69605. pg->character = '.';
  69606. pg->glyph = dotGlyphs.getFirst();
  69607. glyphs.insert (endIndex++, pg);
  69608. --numDeleted;
  69609. xOffset += dx;
  69610. if (xOffset > maxXPos)
  69611. break;
  69612. }
  69613. }
  69614. return numDeleted;
  69615. }
  69616. void GlyphArrangement::addJustifiedText (const Font& font,
  69617. const String& text,
  69618. float x, float y,
  69619. const float maxLineWidth,
  69620. const Justification& horizontalLayout)
  69621. {
  69622. int lineStartIndex = glyphs.size();
  69623. addLineOfText (font, text, x, y);
  69624. const float originalY = y;
  69625. while (lineStartIndex < glyphs.size())
  69626. {
  69627. int i = lineStartIndex;
  69628. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69629. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69630. ++i;
  69631. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69632. int lastWordBreakIndex = -1;
  69633. while (i < glyphs.size())
  69634. {
  69635. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69636. const juce_wchar c = pg->getCharacter();
  69637. if (c == T('\r') || c == T('\n'))
  69638. {
  69639. ++i;
  69640. if (c == T('\r') && i < glyphs.size()
  69641. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69642. ++i;
  69643. break;
  69644. }
  69645. else if (pg->isWhitespace())
  69646. {
  69647. lastWordBreakIndex = i + 1;
  69648. }
  69649. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69650. {
  69651. if (lastWordBreakIndex >= 0)
  69652. i = lastWordBreakIndex;
  69653. break;
  69654. }
  69655. ++i;
  69656. }
  69657. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69658. float currentLineEndX = currentLineStartX;
  69659. for (int j = i; --j >= lineStartIndex;)
  69660. {
  69661. if (! glyphs.getUnchecked (j)->isWhitespace())
  69662. {
  69663. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69664. break;
  69665. }
  69666. }
  69667. float deltaX = 0.0f;
  69668. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69669. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69670. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69671. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69672. else if (horizontalLayout.testFlags (Justification::right))
  69673. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69674. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69675. x + deltaX - currentLineStartX, y - originalY);
  69676. lineStartIndex = i;
  69677. y += font.getHeight();
  69678. }
  69679. }
  69680. void GlyphArrangement::addFittedText (const Font& f,
  69681. const String& text,
  69682. const float x, const float y,
  69683. const float width, const float height,
  69684. const Justification& layout,
  69685. int maximumLines,
  69686. const float minimumHorizontalScale)
  69687. {
  69688. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69689. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69690. if (text.containsAnyOf (T("\r\n")))
  69691. {
  69692. GlyphArrangement ga;
  69693. ga.addJustifiedText (f, text, x, y, width, layout);
  69694. float l, t, r, b;
  69695. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69696. float dy = y - t;
  69697. if (layout.testFlags (Justification::verticallyCentred))
  69698. dy += (height - (b - t)) * 0.5f;
  69699. else if (layout.testFlags (Justification::bottom))
  69700. dy += height - (b - t);
  69701. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69702. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69703. for (int i = 0; i < ga.glyphs.size(); ++i)
  69704. glyphs.add (ga.glyphs.getUnchecked (i));
  69705. ga.glyphs.clear (false);
  69706. return;
  69707. }
  69708. int startIndex = glyphs.size();
  69709. addLineOfText (f, text.trim(), x, y);
  69710. if (glyphs.size() > startIndex)
  69711. {
  69712. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69713. - glyphs.getUnchecked (startIndex)->getLeft();
  69714. if (lineWidth <= 0)
  69715. return;
  69716. if (lineWidth * minimumHorizontalScale < width)
  69717. {
  69718. if (lineWidth > width)
  69719. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69720. width / lineWidth);
  69721. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69722. x, y, width, height, layout);
  69723. }
  69724. else if (maximumLines <= 1)
  69725. {
  69726. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69727. x, y, width, height, f, layout, minimumHorizontalScale);
  69728. }
  69729. else
  69730. {
  69731. Font font (f);
  69732. String txt (text.trim());
  69733. const int length = txt.length();
  69734. const int originalStartIndex = startIndex;
  69735. int numLines = 1;
  69736. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69737. maximumLines = 1;
  69738. maximumLines = jmin (maximumLines, length);
  69739. while (numLines < maximumLines)
  69740. {
  69741. ++numLines;
  69742. const float newFontHeight = height / (float) numLines;
  69743. if (newFontHeight < font.getHeight())
  69744. {
  69745. font.setHeight (jmax (8.0f, newFontHeight));
  69746. removeRangeOfGlyphs (startIndex, -1);
  69747. addLineOfText (font, txt, x, y);
  69748. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69749. - glyphs.getUnchecked (startIndex)->getLeft();
  69750. }
  69751. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69752. break;
  69753. }
  69754. if (numLines < 1)
  69755. numLines = 1;
  69756. float lineY = y;
  69757. float widthPerLine = lineWidth / numLines;
  69758. int lastLineStartIndex = 0;
  69759. for (int line = 0; line < numLines; ++line)
  69760. {
  69761. int i = startIndex;
  69762. lastLineStartIndex = i;
  69763. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69764. if (line == numLines - 1)
  69765. {
  69766. widthPerLine = width;
  69767. i = glyphs.size();
  69768. }
  69769. else
  69770. {
  69771. while (i < glyphs.size())
  69772. {
  69773. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69774. if (lineWidth > widthPerLine)
  69775. {
  69776. // got to a point where the line's too long, so skip forward to find a
  69777. // good place to break it..
  69778. const int searchStartIndex = i;
  69779. while (i < glyphs.size())
  69780. {
  69781. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69782. {
  69783. if (glyphs.getUnchecked (i)->isWhitespace()
  69784. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69785. {
  69786. ++i;
  69787. break;
  69788. }
  69789. }
  69790. else
  69791. {
  69792. // can't find a suitable break, so try looking backwards..
  69793. i = searchStartIndex;
  69794. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69795. {
  69796. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69797. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69798. {
  69799. i -= back - 1;
  69800. break;
  69801. }
  69802. }
  69803. break;
  69804. }
  69805. ++i;
  69806. }
  69807. break;
  69808. }
  69809. ++i;
  69810. }
  69811. int wsStart = i;
  69812. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69813. --wsStart;
  69814. int wsEnd = i;
  69815. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69816. ++wsEnd;
  69817. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69818. i = jmax (wsStart, startIndex + 1);
  69819. }
  69820. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69821. x, lineY, width, font.getHeight(), font,
  69822. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69823. minimumHorizontalScale);
  69824. startIndex = i;
  69825. lineY += font.getHeight();
  69826. if (startIndex >= glyphs.size())
  69827. break;
  69828. }
  69829. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69830. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69831. }
  69832. }
  69833. }
  69834. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69835. const float dx, const float dy)
  69836. {
  69837. jassert (startIndex >= 0);
  69838. if (dx != 0.0f || dy != 0.0f)
  69839. {
  69840. if (num < 0 || startIndex + num > glyphs.size())
  69841. num = glyphs.size() - startIndex;
  69842. while (--num >= 0)
  69843. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69844. }
  69845. }
  69846. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69847. const Justification& justification, float minimumHorizontalScale)
  69848. {
  69849. int numDeleted = 0;
  69850. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69851. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69852. if (lineWidth > w)
  69853. {
  69854. if (minimumHorizontalScale < 1.0f)
  69855. {
  69856. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69857. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69858. }
  69859. if (lineWidth > w)
  69860. {
  69861. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69862. numGlyphs -= numDeleted;
  69863. }
  69864. }
  69865. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69866. return numDeleted;
  69867. }
  69868. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69869. const float horizontalScaleFactor)
  69870. {
  69871. jassert (startIndex >= 0);
  69872. if (num < 0 || startIndex + num > glyphs.size())
  69873. num = glyphs.size() - startIndex;
  69874. if (num > 0)
  69875. {
  69876. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69877. while (--num >= 0)
  69878. {
  69879. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69880. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69881. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69882. pg->w *= horizontalScaleFactor;
  69883. }
  69884. }
  69885. }
  69886. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69887. float& left,
  69888. float& top,
  69889. float& right,
  69890. float& bottom,
  69891. const bool includeWhitespace) const
  69892. {
  69893. jassert (startIndex >= 0);
  69894. if (num < 0 || startIndex + num > glyphs.size())
  69895. num = glyphs.size() - startIndex;
  69896. left = 0.0f;
  69897. top = 0.0f;
  69898. right = 0.0f;
  69899. bottom = 0.0f;
  69900. bool isFirst = true;
  69901. while (--num >= 0)
  69902. {
  69903. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69904. if (includeWhitespace || ! pg->isWhitespace())
  69905. {
  69906. if (isFirst)
  69907. {
  69908. isFirst = false;
  69909. left = pg->getLeft();
  69910. top = pg->getTop();
  69911. right = pg->getRight();
  69912. bottom = pg->getBottom();
  69913. }
  69914. else
  69915. {
  69916. left = jmin (left, pg->getLeft());
  69917. top = jmin (top, pg->getTop());
  69918. right = jmax (right, pg->getRight());
  69919. bottom = jmax (bottom, pg->getBottom());
  69920. }
  69921. }
  69922. }
  69923. }
  69924. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69925. const int num,
  69926. const float x, const float y,
  69927. const float width, const float height,
  69928. const Justification& justification)
  69929. {
  69930. jassert (num >= 0 && startIndex >= 0);
  69931. if (glyphs.size() > 0 && num > 0)
  69932. {
  69933. float left, top, right, bottom;
  69934. getBoundingBox (startIndex, num, left, top, right, bottom,
  69935. ! justification.testFlags (Justification::horizontallyJustified
  69936. | Justification::horizontallyCentred));
  69937. float deltaX = 0.0f;
  69938. if (justification.testFlags (Justification::horizontallyJustified))
  69939. deltaX = x - left;
  69940. else if (justification.testFlags (Justification::horizontallyCentred))
  69941. deltaX = x + (width - (right - left)) * 0.5f - left;
  69942. else if (justification.testFlags (Justification::right))
  69943. deltaX = (x + width) - right;
  69944. else
  69945. deltaX = x - left;
  69946. float deltaY = 0.0f;
  69947. if (justification.testFlags (Justification::top))
  69948. deltaY = y - top;
  69949. else if (justification.testFlags (Justification::bottom))
  69950. deltaY = (y + height) - bottom;
  69951. else
  69952. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69953. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69954. if (justification.testFlags (Justification::horizontallyJustified))
  69955. {
  69956. int lineStart = 0;
  69957. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69958. int i;
  69959. for (i = 0; i < num; ++i)
  69960. {
  69961. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69962. if (glyphY != baseY)
  69963. {
  69964. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69965. lineStart = i;
  69966. baseY = glyphY;
  69967. }
  69968. }
  69969. if (i > lineStart)
  69970. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69971. }
  69972. }
  69973. }
  69974. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69975. {
  69976. if (start + num < glyphs.size()
  69977. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69978. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69979. {
  69980. int numSpaces = 0;
  69981. int spacesAtEnd = 0;
  69982. for (int i = 0; i < num; ++i)
  69983. {
  69984. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69985. {
  69986. ++spacesAtEnd;
  69987. ++numSpaces;
  69988. }
  69989. else
  69990. {
  69991. spacesAtEnd = 0;
  69992. }
  69993. }
  69994. numSpaces -= spacesAtEnd;
  69995. if (numSpaces > 0)
  69996. {
  69997. const float startX = glyphs.getUnchecked (start)->getLeft();
  69998. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69999. const float extraPaddingBetweenWords
  70000. = (targetWidth - (endX - startX)) / (float) numSpaces;
  70001. float deltaX = 0.0f;
  70002. for (int i = 0; i < num; ++i)
  70003. {
  70004. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  70005. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70006. deltaX += extraPaddingBetweenWords;
  70007. }
  70008. }
  70009. }
  70010. }
  70011. void GlyphArrangement::draw (const Graphics& g) const
  70012. {
  70013. for (int i = 0; i < glyphs.size(); ++i)
  70014. {
  70015. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70016. if (pg->font.isUnderlined())
  70017. {
  70018. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70019. float nextX = pg->x + pg->w;
  70020. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70021. nextX = glyphs.getUnchecked (i + 1)->x;
  70022. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  70023. nextX - pg->x, lineThickness);
  70024. }
  70025. pg->draw (g);
  70026. }
  70027. }
  70028. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  70029. {
  70030. for (int i = 0; i < glyphs.size(); ++i)
  70031. {
  70032. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70033. if (pg->font.isUnderlined())
  70034. {
  70035. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70036. float nextX = pg->x + pg->w;
  70037. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70038. nextX = glyphs.getUnchecked (i + 1)->x;
  70039. Path p;
  70040. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  70041. nextX, pg->y + lineThickness * 2.0f,
  70042. lineThickness);
  70043. g.fillPath (p, transform);
  70044. }
  70045. pg->draw (g, transform);
  70046. }
  70047. }
  70048. void GlyphArrangement::createPath (Path& path) const
  70049. {
  70050. for (int i = 0; i < glyphs.size(); ++i)
  70051. glyphs.getUnchecked (i)->createPath (path);
  70052. }
  70053. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  70054. {
  70055. for (int i = 0; i < glyphs.size(); ++i)
  70056. if (glyphs.getUnchecked (i)->hitTest (x, y))
  70057. return i;
  70058. return -1;
  70059. }
  70060. END_JUCE_NAMESPACE
  70061. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  70062. /*** Start of inlined file: juce_TextLayout.cpp ***/
  70063. BEGIN_JUCE_NAMESPACE
  70064. class TextLayout::Token
  70065. {
  70066. public:
  70067. String text;
  70068. Font font;
  70069. int x, y, w, h;
  70070. int line, lineHeight;
  70071. bool isWhitespace, isNewLine;
  70072. Token (const String& t,
  70073. const Font& f,
  70074. const bool isWhitespace_) throw()
  70075. : text (t),
  70076. font (f),
  70077. x(0),
  70078. y(0),
  70079. isWhitespace (isWhitespace_)
  70080. {
  70081. w = font.getStringWidth (t);
  70082. h = roundToInt (f.getHeight());
  70083. isNewLine = t.containsAnyOf (T("\r\n"));
  70084. }
  70085. Token (const Token& other) throw()
  70086. : text (other.text),
  70087. font (other.font),
  70088. x (other.x),
  70089. y (other.y),
  70090. w (other.w),
  70091. h (other.h),
  70092. line (other.line),
  70093. lineHeight (other.lineHeight),
  70094. isWhitespace (other.isWhitespace),
  70095. isNewLine (other.isNewLine)
  70096. {
  70097. }
  70098. ~Token() throw()
  70099. {
  70100. }
  70101. void draw (Graphics& g,
  70102. const int xOffset,
  70103. const int yOffset) throw()
  70104. {
  70105. if (! isWhitespace)
  70106. {
  70107. g.setFont (font);
  70108. g.drawSingleLineText (text.trimEnd(),
  70109. xOffset + x,
  70110. yOffset + y + (lineHeight - h)
  70111. + roundToInt (font.getAscent()));
  70112. }
  70113. }
  70114. juce_UseDebuggingNewOperator
  70115. };
  70116. TextLayout::TextLayout() throw()
  70117. : totalLines (0)
  70118. {
  70119. tokens.ensureStorageAllocated (64);
  70120. }
  70121. TextLayout::TextLayout (const String& text,
  70122. const Font& font) throw()
  70123. : totalLines (0)
  70124. {
  70125. tokens.ensureStorageAllocated (64);
  70126. appendText (text, font);
  70127. }
  70128. TextLayout::TextLayout (const TextLayout& other) throw()
  70129. : totalLines (0)
  70130. {
  70131. *this = other;
  70132. }
  70133. const TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70134. {
  70135. if (this != &other)
  70136. {
  70137. clear();
  70138. totalLines = other.totalLines;
  70139. for (int i = 0; i < other.tokens.size(); ++i)
  70140. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70141. }
  70142. return *this;
  70143. }
  70144. TextLayout::~TextLayout() throw()
  70145. {
  70146. clear();
  70147. }
  70148. void TextLayout::clear() throw()
  70149. {
  70150. tokens.clear();
  70151. totalLines = 0;
  70152. }
  70153. void TextLayout::appendText (const String& text,
  70154. const Font& font) throw()
  70155. {
  70156. const tchar* t = text;
  70157. String currentString;
  70158. int lastCharType = 0;
  70159. for (;;)
  70160. {
  70161. const tchar c = *t++;
  70162. if (c == 0)
  70163. break;
  70164. int charType;
  70165. if (c == T('\r') || c == T('\n'))
  70166. {
  70167. charType = 0;
  70168. }
  70169. else if (CharacterFunctions::isWhitespace (c))
  70170. {
  70171. charType = 2;
  70172. }
  70173. else
  70174. {
  70175. charType = 1;
  70176. }
  70177. if (charType == 0 || charType != lastCharType)
  70178. {
  70179. if (currentString.isNotEmpty())
  70180. {
  70181. tokens.add (new Token (currentString, font,
  70182. lastCharType == 2 || lastCharType == 0));
  70183. }
  70184. currentString = String::charToString (c);
  70185. if (c == T('\r') && *t == T('\n'))
  70186. currentString += *t++;
  70187. }
  70188. else
  70189. {
  70190. currentString += c;
  70191. }
  70192. lastCharType = charType;
  70193. }
  70194. if (currentString.isNotEmpty())
  70195. tokens.add (new Token (currentString, font, lastCharType == 2));
  70196. }
  70197. void TextLayout::setText (const String& text, const Font& font) throw()
  70198. {
  70199. clear();
  70200. appendText (text, font);
  70201. }
  70202. void TextLayout::layout (int maxWidth,
  70203. const Justification& justification,
  70204. const bool attemptToBalanceLineLengths) throw()
  70205. {
  70206. if (attemptToBalanceLineLengths)
  70207. {
  70208. const int originalW = maxWidth;
  70209. int bestWidth = maxWidth;
  70210. float bestLineProportion = 0.0f;
  70211. while (maxWidth > originalW / 2)
  70212. {
  70213. layout (maxWidth, justification, false);
  70214. if (getNumLines() <= 1)
  70215. return;
  70216. const int lastLineW = getLineWidth (getNumLines() - 1);
  70217. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70218. const float prop = lastLineW / (float) lastButOneLineW;
  70219. if (prop > 0.9f)
  70220. return;
  70221. if (prop > bestLineProportion)
  70222. {
  70223. bestLineProportion = prop;
  70224. bestWidth = maxWidth;
  70225. }
  70226. maxWidth -= 10;
  70227. }
  70228. layout (bestWidth, justification, false);
  70229. }
  70230. else
  70231. {
  70232. int x = 0;
  70233. int y = 0;
  70234. int h = 0;
  70235. totalLines = 0;
  70236. int i;
  70237. for (i = 0; i < tokens.size(); ++i)
  70238. {
  70239. Token* const t = tokens.getUnchecked(i);
  70240. t->x = x;
  70241. t->y = y;
  70242. t->line = totalLines;
  70243. x += t->w;
  70244. h = jmax (h, t->h);
  70245. const Token* nextTok = tokens [i + 1];
  70246. if (nextTok == 0)
  70247. break;
  70248. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70249. {
  70250. // finished a line, so go back and update the heights of the things on it
  70251. for (int j = i; j >= 0; --j)
  70252. {
  70253. Token* const tok = tokens.getUnchecked(j);
  70254. if (tok->line == totalLines)
  70255. tok->lineHeight = h;
  70256. else
  70257. break;
  70258. }
  70259. x = 0;
  70260. y += h;
  70261. h = 0;
  70262. ++totalLines;
  70263. }
  70264. }
  70265. // finished a line, so go back and update the heights of the things on it
  70266. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70267. {
  70268. Token* const t = tokens.getUnchecked(j);
  70269. if (t->line == totalLines)
  70270. t->lineHeight = h;
  70271. else
  70272. break;
  70273. }
  70274. ++totalLines;
  70275. if (! justification.testFlags (Justification::left))
  70276. {
  70277. int totalW = getWidth();
  70278. for (i = totalLines; --i >= 0;)
  70279. {
  70280. const int lineW = getLineWidth (i);
  70281. int dx = 0;
  70282. if (justification.testFlags (Justification::horizontallyCentred))
  70283. dx = (totalW - lineW) / 2;
  70284. else if (justification.testFlags (Justification::right))
  70285. dx = totalW - lineW;
  70286. for (int j = tokens.size(); --j >= 0;)
  70287. {
  70288. Token* const t = tokens.getUnchecked(j);
  70289. if (t->line == i)
  70290. t->x += dx;
  70291. }
  70292. }
  70293. }
  70294. }
  70295. }
  70296. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70297. {
  70298. int maxW = 0;
  70299. for (int i = tokens.size(); --i >= 0;)
  70300. {
  70301. const Token* const t = tokens.getUnchecked(i);
  70302. if (t->line == lineNumber && ! t->isWhitespace)
  70303. maxW = jmax (maxW, t->x + t->w);
  70304. }
  70305. return maxW;
  70306. }
  70307. int TextLayout::getWidth() const throw()
  70308. {
  70309. int maxW = 0;
  70310. for (int i = tokens.size(); --i >= 0;)
  70311. {
  70312. const Token* const t = tokens.getUnchecked(i);
  70313. if (! t->isWhitespace)
  70314. maxW = jmax (maxW, t->x + t->w);
  70315. }
  70316. return maxW;
  70317. }
  70318. int TextLayout::getHeight() const throw()
  70319. {
  70320. int maxH = 0;
  70321. for (int i = tokens.size(); --i >= 0;)
  70322. {
  70323. const Token* const t = tokens.getUnchecked(i);
  70324. if (! t->isWhitespace)
  70325. maxH = jmax (maxH, t->y + t->h);
  70326. }
  70327. return maxH;
  70328. }
  70329. void TextLayout::draw (Graphics& g,
  70330. const int xOffset,
  70331. const int yOffset) const throw()
  70332. {
  70333. for (int i = tokens.size(); --i >= 0;)
  70334. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70335. }
  70336. void TextLayout::drawWithin (Graphics& g,
  70337. int x, int y, int w, int h,
  70338. const Justification& justification) const throw()
  70339. {
  70340. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70341. x, y, w, h);
  70342. draw (g, x, y);
  70343. }
  70344. END_JUCE_NAMESPACE
  70345. /*** End of inlined file: juce_TextLayout.cpp ***/
  70346. /*** Start of inlined file: juce_Typeface.cpp ***/
  70347. BEGIN_JUCE_NAMESPACE
  70348. Typeface::Typeface (const String& name_) throw()
  70349. : name (name_)
  70350. {
  70351. }
  70352. Typeface::~Typeface()
  70353. {
  70354. }
  70355. class CustomTypeface::GlyphInfo
  70356. {
  70357. public:
  70358. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70359. : character (character_), path (path_), width (width_)
  70360. {
  70361. }
  70362. ~GlyphInfo() throw()
  70363. {
  70364. }
  70365. struct KerningPair
  70366. {
  70367. juce_wchar character2;
  70368. float kerningAmount;
  70369. };
  70370. void addKerningPair (const juce_wchar subsequentCharacter,
  70371. const float extraKerningAmount) throw()
  70372. {
  70373. KerningPair kp;
  70374. kp.character2 = subsequentCharacter;
  70375. kp.kerningAmount = extraKerningAmount;
  70376. kerningPairs.add (kp);
  70377. }
  70378. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70379. {
  70380. if (subsequentCharacter != 0)
  70381. {
  70382. for (int i = kerningPairs.size(); --i >= 0;)
  70383. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70384. return width + kerningPairs.getReference(i).kerningAmount;
  70385. }
  70386. return width;
  70387. }
  70388. const juce_wchar character;
  70389. const Path path;
  70390. float width;
  70391. Array <KerningPair> kerningPairs;
  70392. juce_UseDebuggingNewOperator
  70393. private:
  70394. GlyphInfo (const GlyphInfo&);
  70395. const GlyphInfo& operator= (const GlyphInfo&);
  70396. };
  70397. CustomTypeface::CustomTypeface()
  70398. : Typeface (String::empty)
  70399. {
  70400. clear();
  70401. }
  70402. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70403. : Typeface (String::empty)
  70404. {
  70405. clear();
  70406. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70407. BufferedInputStream in (&gzin, 32768, false);
  70408. name = in.readString();
  70409. isBold = in.readBool();
  70410. isItalic = in.readBool();
  70411. ascent = in.readFloat();
  70412. defaultCharacter = (juce_wchar) in.readShort();
  70413. int i, numChars = in.readInt();
  70414. for (i = 0; i < numChars; ++i)
  70415. {
  70416. const juce_wchar c = (juce_wchar) in.readShort();
  70417. const float width = in.readFloat();
  70418. Path p;
  70419. p.loadPathFromStream (in);
  70420. addGlyph (c, p, width);
  70421. }
  70422. const int numKerningPairs = in.readInt();
  70423. for (i = 0; i < numKerningPairs; ++i)
  70424. {
  70425. const juce_wchar char1 = (juce_wchar) in.readShort();
  70426. const juce_wchar char2 = (juce_wchar) in.readShort();
  70427. addKerningPair (char1, char2, in.readFloat());
  70428. }
  70429. }
  70430. CustomTypeface::~CustomTypeface()
  70431. {
  70432. }
  70433. void CustomTypeface::clear()
  70434. {
  70435. defaultCharacter = 0;
  70436. ascent = 1.0f;
  70437. isBold = isItalic = false;
  70438. zeromem (lookupTable, sizeof (lookupTable));
  70439. glyphs.clear();
  70440. }
  70441. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70442. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70443. {
  70444. name = name_;
  70445. defaultCharacter = defaultCharacter_;
  70446. ascent = ascent_;
  70447. isBold = isBold_;
  70448. isItalic = isItalic_;
  70449. }
  70450. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70451. {
  70452. // Check that you're not trying to add the same character twice..
  70453. jassert (findGlyph (character, false) == 0);
  70454. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70455. lookupTable [character] = (short) glyphs.size();
  70456. glyphs.add (new GlyphInfo (character, path, width));
  70457. }
  70458. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70459. {
  70460. if (extraAmount != 0)
  70461. {
  70462. GlyphInfo* const g = findGlyph (char1, true);
  70463. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70464. if (g != 0)
  70465. g->addKerningPair (char2, extraAmount);
  70466. }
  70467. }
  70468. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70469. {
  70470. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70471. return glyphs [(int) lookupTable [(int) character]];
  70472. for (int i = 0; i < glyphs.size(); ++i)
  70473. {
  70474. GlyphInfo* const g = glyphs.getUnchecked(i);
  70475. if (g->character == character)
  70476. return g;
  70477. }
  70478. if (loadIfNeeded && loadGlyphIfPossible (character))
  70479. return findGlyph (character, false);
  70480. return 0;
  70481. }
  70482. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70483. {
  70484. GlyphInfo* glyph = findGlyph (character, true);
  70485. if (glyph == 0)
  70486. {
  70487. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70488. glyph = findGlyph (L' ', true);
  70489. if (glyph == 0)
  70490. {
  70491. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70492. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70493. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70494. {
  70495. //xxx
  70496. }
  70497. if (glyph == 0)
  70498. glyph = findGlyph (defaultCharacter, true);
  70499. }
  70500. }
  70501. return glyph;
  70502. }
  70503. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70504. {
  70505. return false;
  70506. }
  70507. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70508. {
  70509. for (int i = 0; i < numCharacters; ++i)
  70510. {
  70511. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70512. Array <int> glyphIndexes;
  70513. Array <float> offsets;
  70514. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70515. const int glyphIndex = glyphIndexes.getFirst();
  70516. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70517. {
  70518. const float glyphWidth = offsets[1];
  70519. Path p;
  70520. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70521. addGlyph (c, p, glyphWidth);
  70522. for (int j = glyphs.size() - 1; --j >= 0;)
  70523. {
  70524. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70525. glyphIndexes.clearQuick();
  70526. offsets.clearQuick();
  70527. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70528. if (offsets.size() > 1)
  70529. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70530. }
  70531. }
  70532. }
  70533. }
  70534. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70535. {
  70536. GZIPCompressorOutputStream out (&outputStream);
  70537. out.writeString (name);
  70538. out.writeBool (isBold);
  70539. out.writeBool (isItalic);
  70540. out.writeFloat (ascent);
  70541. out.writeShort ((short) (unsigned short) defaultCharacter);
  70542. out.writeInt (glyphs.size());
  70543. int i, numKerningPairs = 0;
  70544. for (i = 0; i < glyphs.size(); ++i)
  70545. {
  70546. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70547. out.writeShort ((short) (unsigned short) g->character);
  70548. out.writeFloat (g->width);
  70549. g->path.writePathToStream (out);
  70550. numKerningPairs += g->kerningPairs.size();
  70551. }
  70552. out.writeInt (numKerningPairs);
  70553. for (i = 0; i < glyphs.size(); ++i)
  70554. {
  70555. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70556. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70557. {
  70558. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70559. out.writeShort ((short) (unsigned short) g->character);
  70560. out.writeShort ((short) (unsigned short) p.character2);
  70561. out.writeFloat (p.kerningAmount);
  70562. }
  70563. }
  70564. return true;
  70565. }
  70566. float CustomTypeface::getAscent() const
  70567. {
  70568. return ascent;
  70569. }
  70570. float CustomTypeface::getDescent() const
  70571. {
  70572. return 1.0f - ascent;
  70573. }
  70574. float CustomTypeface::getStringWidth (const String& text)
  70575. {
  70576. float x = 0;
  70577. const juce_wchar* t = (const juce_wchar*) text;
  70578. while (*t != 0)
  70579. {
  70580. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70581. if (glyph != 0)
  70582. x += glyph->getHorizontalSpacing (*t);
  70583. }
  70584. return x;
  70585. }
  70586. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70587. {
  70588. xOffsets.add (0);
  70589. float x = 0;
  70590. const juce_wchar* t = (const juce_wchar*) text;
  70591. while (*t != 0)
  70592. {
  70593. const juce_wchar c = *t++;
  70594. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70595. if (glyph != 0)
  70596. {
  70597. x += glyph->getHorizontalSpacing (*t);
  70598. resultGlyphs.add ((int) glyph->character);
  70599. xOffsets.add (x);
  70600. }
  70601. }
  70602. }
  70603. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70604. {
  70605. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70606. if (glyph != 0)
  70607. {
  70608. path = glyph->path;
  70609. return true;
  70610. }
  70611. return false;
  70612. }
  70613. END_JUCE_NAMESPACE
  70614. /*** End of inlined file: juce_Typeface.cpp ***/
  70615. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70616. BEGIN_JUCE_NAMESPACE
  70617. AffineTransform::AffineTransform() throw()
  70618. : mat00 (1.0f),
  70619. mat01 (0),
  70620. mat02 (0),
  70621. mat10 (0),
  70622. mat11 (1.0f),
  70623. mat12 (0)
  70624. {
  70625. }
  70626. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70627. : mat00 (other.mat00),
  70628. mat01 (other.mat01),
  70629. mat02 (other.mat02),
  70630. mat10 (other.mat10),
  70631. mat11 (other.mat11),
  70632. mat12 (other.mat12)
  70633. {
  70634. }
  70635. AffineTransform::AffineTransform (const float mat00_,
  70636. const float mat01_,
  70637. const float mat02_,
  70638. const float mat10_,
  70639. const float mat11_,
  70640. const float mat12_) throw()
  70641. : mat00 (mat00_),
  70642. mat01 (mat01_),
  70643. mat02 (mat02_),
  70644. mat10 (mat10_),
  70645. mat11 (mat11_),
  70646. mat12 (mat12_)
  70647. {
  70648. }
  70649. const AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70650. {
  70651. mat00 = other.mat00;
  70652. mat01 = other.mat01;
  70653. mat02 = other.mat02;
  70654. mat10 = other.mat10;
  70655. mat11 = other.mat11;
  70656. mat12 = other.mat12;
  70657. return *this;
  70658. }
  70659. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70660. {
  70661. return mat00 == other.mat00
  70662. && mat01 == other.mat01
  70663. && mat02 == other.mat02
  70664. && mat10 == other.mat10
  70665. && mat11 == other.mat11
  70666. && mat12 == other.mat12;
  70667. }
  70668. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70669. {
  70670. return ! operator== (other);
  70671. }
  70672. bool AffineTransform::isIdentity() const throw()
  70673. {
  70674. return (mat01 == 0)
  70675. && (mat02 == 0)
  70676. && (mat10 == 0)
  70677. && (mat12 == 0)
  70678. && (mat00 == 1.0f)
  70679. && (mat11 == 1.0f);
  70680. }
  70681. const AffineTransform AffineTransform::identity;
  70682. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70683. {
  70684. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70685. other.mat00 * mat01 + other.mat01 * mat11,
  70686. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70687. other.mat10 * mat00 + other.mat11 * mat10,
  70688. other.mat10 * mat01 + other.mat11 * mat11,
  70689. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70690. }
  70691. const AffineTransform AffineTransform::followedBy (const float omat00,
  70692. const float omat01,
  70693. const float omat02,
  70694. const float omat10,
  70695. const float omat11,
  70696. const float omat12) const throw()
  70697. {
  70698. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70699. omat00 * mat01 + omat01 * mat11,
  70700. omat00 * mat02 + omat01 * mat12 + omat02,
  70701. omat10 * mat00 + omat11 * mat10,
  70702. omat10 * mat01 + omat11 * mat11,
  70703. omat10 * mat02 + omat11 * mat12 + omat12);
  70704. }
  70705. const AffineTransform AffineTransform::translated (const float dx,
  70706. const float dy) const throw()
  70707. {
  70708. return AffineTransform (mat00, mat01, mat02 + dx,
  70709. mat10, mat11, mat12 + dy);
  70710. }
  70711. const AffineTransform AffineTransform::translation (const float dx,
  70712. const float dy) throw()
  70713. {
  70714. return AffineTransform (1.0f, 0, dx,
  70715. 0, 1.0f, dy);
  70716. }
  70717. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70718. {
  70719. const float cosRad = cosf (rad);
  70720. const float sinRad = sinf (rad);
  70721. return followedBy (cosRad, -sinRad, 0,
  70722. sinRad, cosRad, 0);
  70723. }
  70724. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70725. {
  70726. const float cosRad = cosf (rad);
  70727. const float sinRad = sinf (rad);
  70728. return AffineTransform (cosRad, -sinRad, 0,
  70729. sinRad, cosRad, 0);
  70730. }
  70731. const AffineTransform AffineTransform::rotated (const float angle,
  70732. const float pivotX,
  70733. const float pivotY) const throw()
  70734. {
  70735. return translated (-pivotX, -pivotY)
  70736. .rotated (angle)
  70737. .translated (pivotX, pivotY);
  70738. }
  70739. const AffineTransform AffineTransform::rotation (const float angle,
  70740. const float pivotX,
  70741. const float pivotY) throw()
  70742. {
  70743. return translation (-pivotX, -pivotY)
  70744. .rotated (angle)
  70745. .translated (pivotX, pivotY);
  70746. }
  70747. const AffineTransform AffineTransform::scaled (const float factorX,
  70748. const float factorY) const throw()
  70749. {
  70750. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70751. factorY * mat10, factorY * mat11, factorY * mat12);
  70752. }
  70753. const AffineTransform AffineTransform::scale (const float factorX,
  70754. const float factorY) throw()
  70755. {
  70756. return AffineTransform (factorX, 0, 0,
  70757. 0, factorY, 0);
  70758. }
  70759. const AffineTransform AffineTransform::sheared (const float shearX,
  70760. const float shearY) const throw()
  70761. {
  70762. return followedBy (1.0f, shearX, 0,
  70763. shearY, 1.0f, 0);
  70764. }
  70765. const AffineTransform AffineTransform::inverted() const throw()
  70766. {
  70767. double determinant = (mat00 * mat11 - mat10 * mat01);
  70768. if (determinant != 0.0)
  70769. {
  70770. determinant = 1.0 / determinant;
  70771. const float dst00 = (float) (mat11 * determinant);
  70772. const float dst10 = (float) (-mat10 * determinant);
  70773. const float dst01 = (float) (-mat01 * determinant);
  70774. const float dst11 = (float) (mat00 * determinant);
  70775. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70776. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70777. }
  70778. else
  70779. {
  70780. // singularity..
  70781. return *this;
  70782. }
  70783. }
  70784. bool AffineTransform::isSingularity() const throw()
  70785. {
  70786. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70787. }
  70788. bool AffineTransform::isOnlyTranslation() const throw()
  70789. {
  70790. return (mat01 == 0)
  70791. && (mat10 == 0)
  70792. && (mat00 == 1.0f)
  70793. && (mat11 == 1.0f);
  70794. }
  70795. void AffineTransform::transformPoint (float& x,
  70796. float& y) const throw()
  70797. {
  70798. const float oldX = x;
  70799. x = mat00 * oldX + mat01 * y + mat02;
  70800. y = mat10 * oldX + mat11 * y + mat12;
  70801. }
  70802. void AffineTransform::transformPoint (double& x,
  70803. double& y) const throw()
  70804. {
  70805. const double oldX = x;
  70806. x = mat00 * oldX + mat01 * y + mat02;
  70807. y = mat10 * oldX + mat11 * y + mat12;
  70808. }
  70809. END_JUCE_NAMESPACE
  70810. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70811. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70812. BEGIN_JUCE_NAMESPACE
  70813. BorderSize::BorderSize() throw()
  70814. : top (0),
  70815. left (0),
  70816. bottom (0),
  70817. right (0)
  70818. {
  70819. }
  70820. BorderSize::BorderSize (const BorderSize& other) throw()
  70821. : top (other.top),
  70822. left (other.left),
  70823. bottom (other.bottom),
  70824. right (other.right)
  70825. {
  70826. }
  70827. BorderSize::BorderSize (const int topGap,
  70828. const int leftGap,
  70829. const int bottomGap,
  70830. const int rightGap) throw()
  70831. : top (topGap),
  70832. left (leftGap),
  70833. bottom (bottomGap),
  70834. right (rightGap)
  70835. {
  70836. }
  70837. BorderSize::BorderSize (const int allGaps) throw()
  70838. : top (allGaps),
  70839. left (allGaps),
  70840. bottom (allGaps),
  70841. right (allGaps)
  70842. {
  70843. }
  70844. BorderSize::~BorderSize() throw()
  70845. {
  70846. }
  70847. void BorderSize::setTop (const int newTopGap) throw()
  70848. {
  70849. top = newTopGap;
  70850. }
  70851. void BorderSize::setLeft (const int newLeftGap) throw()
  70852. {
  70853. left = newLeftGap;
  70854. }
  70855. void BorderSize::setBottom (const int newBottomGap) throw()
  70856. {
  70857. bottom = newBottomGap;
  70858. }
  70859. void BorderSize::setRight (const int newRightGap) throw()
  70860. {
  70861. right = newRightGap;
  70862. }
  70863. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70864. {
  70865. return Rectangle<int> (r.getX() + left,
  70866. r.getY() + top,
  70867. r.getWidth() - (left + right),
  70868. r.getHeight() - (top + bottom));
  70869. }
  70870. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70871. {
  70872. r.setBounds (r.getX() + left,
  70873. r.getY() + top,
  70874. r.getWidth() - (left + right),
  70875. r.getHeight() - (top + bottom));
  70876. }
  70877. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70878. {
  70879. return Rectangle<int> (r.getX() - left,
  70880. r.getY() - top,
  70881. r.getWidth() + (left + right),
  70882. r.getHeight() + (top + bottom));
  70883. }
  70884. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70885. {
  70886. r.setBounds (r.getX() - left,
  70887. r.getY() - top,
  70888. r.getWidth() + (left + right),
  70889. r.getHeight() + (top + bottom));
  70890. }
  70891. bool BorderSize::operator== (const BorderSize& other) const throw()
  70892. {
  70893. return top == other.top
  70894. && left == other.left
  70895. && bottom == other.bottom
  70896. && right == other.right;
  70897. }
  70898. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70899. {
  70900. return ! operator== (other);
  70901. }
  70902. END_JUCE_NAMESPACE
  70903. /*** End of inlined file: juce_BorderSize.cpp ***/
  70904. /*** Start of inlined file: juce_Line.cpp ***/
  70905. BEGIN_JUCE_NAMESPACE
  70906. static bool juce_lineIntersection (const float x1, const float y1,
  70907. const float x2, const float y2,
  70908. const float x3, const float y3,
  70909. const float x4, const float y4,
  70910. float& intersectionX,
  70911. float& intersectionY) throw()
  70912. {
  70913. if (x2 != x3 || y2 != y3)
  70914. {
  70915. const float dx1 = x2 - x1;
  70916. const float dy1 = y2 - y1;
  70917. const float dx2 = x4 - x3;
  70918. const float dy2 = y4 - y3;
  70919. const float divisor = dx1 * dy2 - dx2 * dy1;
  70920. if (divisor == 0)
  70921. {
  70922. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70923. {
  70924. if (dy1 == 0 && dy2 != 0)
  70925. {
  70926. const float along = (y1 - y3) / dy2;
  70927. intersectionX = x3 + along * dx2;
  70928. intersectionY = y1;
  70929. return along >= 0 && along <= 1.0f;
  70930. }
  70931. else if (dy2 == 0 && dy1 != 0)
  70932. {
  70933. const float along = (y3 - y1) / dy1;
  70934. intersectionX = x1 + along * dx1;
  70935. intersectionY = y3;
  70936. return along >= 0 && along <= 1.0f;
  70937. }
  70938. else if (dx1 == 0 && dx2 != 0)
  70939. {
  70940. const float along = (x1 - x3) / dx2;
  70941. intersectionX = x1;
  70942. intersectionY = y3 + along * dy2;
  70943. return along >= 0 && along <= 1.0f;
  70944. }
  70945. else if (dx2 == 0 && dx1 != 0)
  70946. {
  70947. const float along = (x3 - x1) / dx1;
  70948. intersectionX = x3;
  70949. intersectionY = y1 + along * dy1;
  70950. return along >= 0 && along <= 1.0f;
  70951. }
  70952. }
  70953. intersectionX = 0.5f * (x2 + x3);
  70954. intersectionY = 0.5f * (y2 + y3);
  70955. return false;
  70956. }
  70957. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70958. intersectionX = x1 + along1 * dx1;
  70959. intersectionY = y1 + along1 * dy1;
  70960. if (along1 < 0 || along1 > 1.0f)
  70961. return false;
  70962. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70963. return along2 >= 0 && along2 <= 1.0f;
  70964. }
  70965. intersectionX = x2;
  70966. intersectionY = y2;
  70967. return true;
  70968. }
  70969. Line::Line() throw()
  70970. : startX (0.0f),
  70971. startY (0.0f),
  70972. endX (0.0f),
  70973. endY (0.0f)
  70974. {
  70975. }
  70976. Line::Line (const Line& other) throw()
  70977. : startX (other.startX),
  70978. startY (other.startY),
  70979. endX (other.endX),
  70980. endY (other.endY)
  70981. {
  70982. }
  70983. Line::Line (const float startX_, const float startY_,
  70984. const float endX_, const float endY_) throw()
  70985. : startX (startX_),
  70986. startY (startY_),
  70987. endX (endX_),
  70988. endY (endY_)
  70989. {
  70990. }
  70991. Line::Line (const Point<float>& start,
  70992. const Point<float>& end) throw()
  70993. : startX (start.getX()),
  70994. startY (start.getY()),
  70995. endX (end.getX()),
  70996. endY (end.getY())
  70997. {
  70998. }
  70999. const Line& Line::operator= (const Line& other) throw()
  71000. {
  71001. startX = other.startX;
  71002. startY = other.startY;
  71003. endX = other.endX;
  71004. endY = other.endY;
  71005. return *this;
  71006. }
  71007. Line::~Line() throw()
  71008. {
  71009. }
  71010. const Point<float> Line::getStart() const throw()
  71011. {
  71012. return Point<float> (startX, startY);
  71013. }
  71014. const Point<float> Line::getEnd() const throw()
  71015. {
  71016. return Point<float> (endX, endY);
  71017. }
  71018. void Line::setStart (const float newStartX,
  71019. const float newStartY) throw()
  71020. {
  71021. startX = newStartX;
  71022. startY = newStartY;
  71023. }
  71024. void Line::setStart (const Point<float>& newStart) throw()
  71025. {
  71026. startX = newStart.getX();
  71027. startY = newStart.getY();
  71028. }
  71029. void Line::setEnd (const float newEndX,
  71030. const float newEndY) throw()
  71031. {
  71032. endX = newEndX;
  71033. endY = newEndY;
  71034. }
  71035. void Line::setEnd (const Point<float>& newEnd) throw()
  71036. {
  71037. endX = newEnd.getX();
  71038. endY = newEnd.getY();
  71039. }
  71040. bool Line::operator== (const Line& other) const throw()
  71041. {
  71042. return startX == other.startX
  71043. && startY == other.startY
  71044. && endX == other.endX
  71045. && endY == other.endY;
  71046. }
  71047. bool Line::operator!= (const Line& other) const throw()
  71048. {
  71049. return startX != other.startX
  71050. || startY != other.startY
  71051. || endX != other.endX
  71052. || endY != other.endY;
  71053. }
  71054. void Line::applyTransform (const AffineTransform& transform) throw()
  71055. {
  71056. transform.transformPoint (startX, startY);
  71057. transform.transformPoint (endX, endY);
  71058. }
  71059. float Line::getLength() const throw()
  71060. {
  71061. return (float) juce_hypot (startX - endX,
  71062. startY - endY);
  71063. }
  71064. float Line::getAngle() const throw()
  71065. {
  71066. return atan2f (endX - startX,
  71067. endY - startY);
  71068. }
  71069. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  71070. {
  71071. const float alpha = distanceFromStart / getLength();
  71072. return Point<float> (startX + (endX - startX) * alpha,
  71073. startY + (endY - startY) * alpha);
  71074. }
  71075. const Point<float> Line::getPointAlongLine (const float offsetX,
  71076. const float offsetY) const throw()
  71077. {
  71078. const float dx = endX - startX;
  71079. const float dy = endY - startY;
  71080. const double length = juce_hypot (dx, dy);
  71081. if (length == 0)
  71082. return Point<float> (startX, startY);
  71083. else
  71084. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  71085. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  71086. }
  71087. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  71088. {
  71089. return Point<float> (startX + (endX - startX) * alpha,
  71090. startY + (endY - startY) * alpha);
  71091. }
  71092. float Line::getDistanceFromLine (const float x,
  71093. const float y) const throw()
  71094. {
  71095. const double dx = endX - startX;
  71096. const double dy = endY - startY;
  71097. const double length = dx * dx + dy * dy;
  71098. if (length > 0)
  71099. {
  71100. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71101. if (prop >= 0.0f && prop < 1.0f)
  71102. {
  71103. return (float) juce_hypot (x - (startX + prop * dx),
  71104. y - (startY + prop * dy));
  71105. }
  71106. }
  71107. return (float) jmin (juce_hypot (x - startX, y - startY),
  71108. juce_hypot (x - endX, y - endY));
  71109. }
  71110. float Line::findNearestPointTo (const float x,
  71111. const float y) const throw()
  71112. {
  71113. const double dx = endX - startX;
  71114. const double dy = endY - startY;
  71115. const double length = dx * dx + dy * dy;
  71116. if (length <= 0.0)
  71117. return 0.0f;
  71118. return jlimit (0.0f, 1.0f,
  71119. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71120. }
  71121. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71122. {
  71123. const float length = getLength();
  71124. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71125. getEnd());
  71126. }
  71127. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71128. {
  71129. const float length = getLength();
  71130. return Line (getStart(),
  71131. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71132. }
  71133. bool Line::clipToPath (const Path& path,
  71134. const bool keepSectionOutsidePath) throw()
  71135. {
  71136. const bool startInside = path.contains (startX, startY);
  71137. const bool endInside = path.contains (endX, endY);
  71138. if (startInside == endInside)
  71139. {
  71140. if (keepSectionOutsidePath != startInside)
  71141. {
  71142. // entirely outside the path
  71143. return false;
  71144. }
  71145. else
  71146. {
  71147. // entirely inside the path
  71148. startX = 0.0f;
  71149. startY = 0.0f;
  71150. endX = 0.0f;
  71151. endY = 0.0f;
  71152. return true;
  71153. }
  71154. }
  71155. else
  71156. {
  71157. bool changed = false;
  71158. PathFlatteningIterator iter (path, AffineTransform::identity);
  71159. while (iter.next())
  71160. {
  71161. float ix, iy;
  71162. if (intersects (Line (iter.x1, iter.y1,
  71163. iter.x2, iter.y2),
  71164. ix, iy))
  71165. {
  71166. if ((startInside && keepSectionOutsidePath)
  71167. || (endInside && ! keepSectionOutsidePath))
  71168. {
  71169. setStart (ix, iy);
  71170. }
  71171. else
  71172. {
  71173. setEnd (ix, iy);
  71174. }
  71175. changed = true;
  71176. }
  71177. }
  71178. return changed;
  71179. }
  71180. }
  71181. bool Line::intersects (const Line& line,
  71182. float& intersectionX,
  71183. float& intersectionY) const throw()
  71184. {
  71185. return juce_lineIntersection (startX, startY,
  71186. endX, endY,
  71187. line.startX, line.startY,
  71188. line.endX, line.endY,
  71189. intersectionX,
  71190. intersectionY);
  71191. }
  71192. bool Line::isVertical() const throw()
  71193. {
  71194. return startX == endX;
  71195. }
  71196. bool Line::isHorizontal() const throw()
  71197. {
  71198. return startY == endY;
  71199. }
  71200. bool Line::isPointAbove (const float x, const float y) const throw()
  71201. {
  71202. return startX != endX
  71203. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71204. }
  71205. END_JUCE_NAMESPACE
  71206. /*** End of inlined file: juce_Line.cpp ***/
  71207. /*** Start of inlined file: juce_Path.cpp ***/
  71208. BEGIN_JUCE_NAMESPACE
  71209. // tests that some co-ords aren't NaNs
  71210. #define CHECK_COORDS_ARE_VALID(x, y) \
  71211. jassert (x == x && y == y);
  71212. const float Path::lineMarker = 100001.0f;
  71213. const float Path::moveMarker = 100002.0f;
  71214. const float Path::quadMarker = 100003.0f;
  71215. const float Path::cubicMarker = 100004.0f;
  71216. const float Path::closeSubPathMarker = 100005.0f;
  71217. static const int defaultGranularity = 32;
  71218. Path::Path() throw()
  71219. : numElements (0),
  71220. pathXMin (0),
  71221. pathXMax (0),
  71222. pathYMin (0),
  71223. pathYMax (0),
  71224. useNonZeroWinding (true)
  71225. {
  71226. }
  71227. Path::~Path() throw()
  71228. {
  71229. }
  71230. Path::Path (const Path& other) throw()
  71231. : numElements (other.numElements),
  71232. pathXMin (other.pathXMin),
  71233. pathXMax (other.pathXMax),
  71234. pathYMin (other.pathYMin),
  71235. pathYMax (other.pathYMax),
  71236. useNonZeroWinding (other.useNonZeroWinding)
  71237. {
  71238. if (numElements > 0)
  71239. {
  71240. data.setAllocatedSize (numElements);
  71241. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71242. }
  71243. }
  71244. const Path& Path::operator= (const Path& other) throw()
  71245. {
  71246. if (this != &other)
  71247. {
  71248. data.ensureAllocatedSize (other.numElements);
  71249. numElements = other.numElements;
  71250. pathXMin = other.pathXMin;
  71251. pathXMax = other.pathXMax;
  71252. pathYMin = other.pathYMin;
  71253. pathYMax = other.pathYMax;
  71254. useNonZeroWinding = other.useNonZeroWinding;
  71255. if (numElements > 0)
  71256. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71257. }
  71258. return *this;
  71259. }
  71260. void Path::clear() throw()
  71261. {
  71262. numElements = 0;
  71263. pathXMin = 0;
  71264. pathYMin = 0;
  71265. pathYMax = 0;
  71266. pathXMax = 0;
  71267. }
  71268. void Path::swapWithPath (Path& other)
  71269. {
  71270. data.swapWith (other.data);
  71271. swapVariables <int> (numElements, other.numElements);
  71272. swapVariables <float> (pathXMin, other.pathXMin);
  71273. swapVariables <float> (pathXMax, other.pathXMax);
  71274. swapVariables <float> (pathYMin, other.pathYMin);
  71275. swapVariables <float> (pathYMax, other.pathYMax);
  71276. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71277. }
  71278. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71279. {
  71280. useNonZeroWinding = isNonZero;
  71281. }
  71282. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71283. const bool preserveProportions) throw()
  71284. {
  71285. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71286. }
  71287. bool Path::isEmpty() const throw()
  71288. {
  71289. int i = 0;
  71290. while (i < numElements)
  71291. {
  71292. const float type = data.elements [i++];
  71293. if (type == moveMarker)
  71294. {
  71295. i += 2;
  71296. }
  71297. else if (type == lineMarker
  71298. || type == quadMarker
  71299. || type == cubicMarker)
  71300. {
  71301. return false;
  71302. }
  71303. }
  71304. return true;
  71305. }
  71306. const Rectangle<float> Path::getBounds () const throw()
  71307. {
  71308. return Rectangle<float> (pathXMin, pathYMin,
  71309. pathXMax - pathXMin,
  71310. pathYMax - pathYMin);
  71311. }
  71312. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  71313. {
  71314. return getBounds().transformed (transform);
  71315. }
  71316. void Path::startNewSubPath (const float x,
  71317. const float y) throw()
  71318. {
  71319. CHECK_COORDS_ARE_VALID (x, y);
  71320. if (numElements == 0)
  71321. {
  71322. pathXMin = pathXMax = x;
  71323. pathYMin = pathYMax = y;
  71324. }
  71325. else
  71326. {
  71327. pathXMin = jmin (pathXMin, x);
  71328. pathXMax = jmax (pathXMax, x);
  71329. pathYMin = jmin (pathYMin, y);
  71330. pathYMax = jmax (pathYMax, y);
  71331. }
  71332. data.ensureAllocatedSize (numElements + 3);
  71333. data.elements [numElements++] = moveMarker;
  71334. data.elements [numElements++] = x;
  71335. data.elements [numElements++] = y;
  71336. }
  71337. void Path::lineTo (const float x, const float y) throw()
  71338. {
  71339. CHECK_COORDS_ARE_VALID (x, y);
  71340. if (numElements == 0)
  71341. startNewSubPath (0, 0);
  71342. data.ensureAllocatedSize (numElements + 3);
  71343. data.elements [numElements++] = lineMarker;
  71344. data.elements [numElements++] = x;
  71345. data.elements [numElements++] = y;
  71346. pathXMin = jmin (pathXMin, x);
  71347. pathXMax = jmax (pathXMax, x);
  71348. pathYMin = jmin (pathYMin, y);
  71349. pathYMax = jmax (pathYMax, y);
  71350. }
  71351. void Path::quadraticTo (const float x1, const float y1,
  71352. const float x2, const float y2) throw()
  71353. {
  71354. CHECK_COORDS_ARE_VALID (x1, y1);
  71355. CHECK_COORDS_ARE_VALID (x2, y2);
  71356. if (numElements == 0)
  71357. startNewSubPath (0, 0);
  71358. data.ensureAllocatedSize (numElements + 5);
  71359. data.elements [numElements++] = quadMarker;
  71360. data.elements [numElements++] = x1;
  71361. data.elements [numElements++] = y1;
  71362. data.elements [numElements++] = x2;
  71363. data.elements [numElements++] = y2;
  71364. pathXMin = jmin (pathXMin, x1, x2);
  71365. pathXMax = jmax (pathXMax, x1, x2);
  71366. pathYMin = jmin (pathYMin, y1, y2);
  71367. pathYMax = jmax (pathYMax, y1, y2);
  71368. }
  71369. void Path::cubicTo (const float x1, const float y1,
  71370. const float x2, const float y2,
  71371. const float x3, const float y3) throw()
  71372. {
  71373. CHECK_COORDS_ARE_VALID (x1, y1);
  71374. CHECK_COORDS_ARE_VALID (x2, y2);
  71375. CHECK_COORDS_ARE_VALID (x3, y3);
  71376. if (numElements == 0)
  71377. startNewSubPath (0, 0);
  71378. data.ensureAllocatedSize (numElements + 7);
  71379. data.elements [numElements++] = cubicMarker;
  71380. data.elements [numElements++] = x1;
  71381. data.elements [numElements++] = y1;
  71382. data.elements [numElements++] = x2;
  71383. data.elements [numElements++] = y2;
  71384. data.elements [numElements++] = x3;
  71385. data.elements [numElements++] = y3;
  71386. pathXMin = jmin (pathXMin, x1, x2, x3);
  71387. pathXMax = jmax (pathXMax, x1, x2, x3);
  71388. pathYMin = jmin (pathYMin, y1, y2, y3);
  71389. pathYMax = jmax (pathYMax, y1, y2, y3);
  71390. }
  71391. void Path::closeSubPath() throw()
  71392. {
  71393. if (numElements > 0
  71394. && data.elements [numElements - 1] != closeSubPathMarker)
  71395. {
  71396. data.ensureAllocatedSize (numElements + 1);
  71397. data.elements [numElements++] = closeSubPathMarker;
  71398. }
  71399. }
  71400. const Point<float> Path::getCurrentPosition() const
  71401. {
  71402. int i = numElements - 1;
  71403. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71404. {
  71405. while (i >= 0)
  71406. {
  71407. if (data.elements[i] == moveMarker)
  71408. {
  71409. i += 2;
  71410. break;
  71411. }
  71412. --i;
  71413. }
  71414. }
  71415. if (i > 0)
  71416. return Point<float> (data.elements [i - 1], data.elements [i]);
  71417. return Point<float>();
  71418. }
  71419. void Path::addRectangle (const float x, const float y,
  71420. const float w, const float h) throw()
  71421. {
  71422. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71423. if (w < 0)
  71424. swapVariables (x1, x2);
  71425. if (h < 0)
  71426. swapVariables (y1, y2);
  71427. data.ensureAllocatedSize (numElements + 13);
  71428. if (numElements == 0)
  71429. {
  71430. pathXMin = x1;
  71431. pathXMax = x2;
  71432. pathYMin = y1;
  71433. pathYMax = y2;
  71434. }
  71435. else
  71436. {
  71437. pathXMin = jmin (pathXMin, x1);
  71438. pathXMax = jmax (pathXMax, x2);
  71439. pathYMin = jmin (pathYMin, y1);
  71440. pathYMax = jmax (pathYMax, y2);
  71441. }
  71442. data.elements [numElements++] = moveMarker;
  71443. data.elements [numElements++] = x1;
  71444. data.elements [numElements++] = y2;
  71445. data.elements [numElements++] = lineMarker;
  71446. data.elements [numElements++] = x1;
  71447. data.elements [numElements++] = y1;
  71448. data.elements [numElements++] = lineMarker;
  71449. data.elements [numElements++] = x2;
  71450. data.elements [numElements++] = y1;
  71451. data.elements [numElements++] = lineMarker;
  71452. data.elements [numElements++] = x2;
  71453. data.elements [numElements++] = y2;
  71454. data.elements [numElements++] = closeSubPathMarker;
  71455. }
  71456. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71457. {
  71458. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71459. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71460. }
  71461. void Path::addRoundedRectangle (const float x, const float y,
  71462. const float w, const float h,
  71463. float csx,
  71464. float csy) throw()
  71465. {
  71466. csx = jmin (csx, w * 0.5f);
  71467. csy = jmin (csy, h * 0.5f);
  71468. const float cs45x = csx * 0.45f;
  71469. const float cs45y = csy * 0.45f;
  71470. const float x2 = x + w;
  71471. const float y2 = y + h;
  71472. startNewSubPath (x + csx, y);
  71473. lineTo (x2 - csx, y);
  71474. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71475. lineTo (x2, y2 - csy);
  71476. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71477. lineTo (x + csx, y2);
  71478. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71479. lineTo (x, y + csy);
  71480. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71481. closeSubPath();
  71482. }
  71483. void Path::addRoundedRectangle (const float x, const float y,
  71484. const float w, const float h,
  71485. float cs) throw()
  71486. {
  71487. addRoundedRectangle (x, y, w, h, cs, cs);
  71488. }
  71489. void Path::addTriangle (const float x1, const float y1,
  71490. const float x2, const float y2,
  71491. const float x3, const float y3) throw()
  71492. {
  71493. startNewSubPath (x1, y1);
  71494. lineTo (x2, y2);
  71495. lineTo (x3, y3);
  71496. closeSubPath();
  71497. }
  71498. void Path::addQuadrilateral (const float x1, const float y1,
  71499. const float x2, const float y2,
  71500. const float x3, const float y3,
  71501. const float x4, const float y4) throw()
  71502. {
  71503. startNewSubPath (x1, y1);
  71504. lineTo (x2, y2);
  71505. lineTo (x3, y3);
  71506. lineTo (x4, y4);
  71507. closeSubPath();
  71508. }
  71509. void Path::addEllipse (const float x, const float y,
  71510. const float w, const float h) throw()
  71511. {
  71512. const float hw = w * 0.5f;
  71513. const float hw55 = hw * 0.55f;
  71514. const float hh = h * 0.5f;
  71515. const float hh45 = hh * 0.55f;
  71516. const float cx = x + hw;
  71517. const float cy = y + hh;
  71518. startNewSubPath (cx, cy - hh);
  71519. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71520. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71521. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71522. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71523. closeSubPath();
  71524. }
  71525. void Path::addArc (const float x, const float y,
  71526. const float w, const float h,
  71527. const float fromRadians,
  71528. const float toRadians,
  71529. const bool startAsNewSubPath) throw()
  71530. {
  71531. const float radiusX = w / 2.0f;
  71532. const float radiusY = h / 2.0f;
  71533. addCentredArc (x + radiusX,
  71534. y + radiusY,
  71535. radiusX, radiusY,
  71536. 0.0f,
  71537. fromRadians, toRadians,
  71538. startAsNewSubPath);
  71539. }
  71540. static const float ellipseAngularIncrement = 0.05f;
  71541. void Path::addCentredArc (const float centreX, const float centreY,
  71542. const float radiusX, const float radiusY,
  71543. const float rotationOfEllipse,
  71544. const float fromRadians,
  71545. const float toRadians,
  71546. const bool startAsNewSubPath) throw()
  71547. {
  71548. if (radiusX > 0.0f && radiusY > 0.0f)
  71549. {
  71550. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71551. float angle = fromRadians;
  71552. if (startAsNewSubPath)
  71553. {
  71554. float x = centreX + radiusX * sinf (angle);
  71555. float y = centreY - radiusY * cosf (angle);
  71556. if (rotationOfEllipse != 0)
  71557. rotation.transformPoint (x, y);
  71558. startNewSubPath (x, y);
  71559. }
  71560. if (fromRadians < toRadians)
  71561. {
  71562. if (startAsNewSubPath)
  71563. angle += ellipseAngularIncrement;
  71564. while (angle < toRadians)
  71565. {
  71566. float x = centreX + radiusX * sinf (angle);
  71567. float y = centreY - radiusY * cosf (angle);
  71568. if (rotationOfEllipse != 0)
  71569. rotation.transformPoint (x, y);
  71570. lineTo (x, y);
  71571. angle += ellipseAngularIncrement;
  71572. }
  71573. }
  71574. else
  71575. {
  71576. if (startAsNewSubPath)
  71577. angle -= ellipseAngularIncrement;
  71578. while (angle > toRadians)
  71579. {
  71580. float x = centreX + radiusX * sinf (angle);
  71581. float y = centreY - radiusY * cosf (angle);
  71582. if (rotationOfEllipse != 0)
  71583. rotation.transformPoint (x, y);
  71584. lineTo (x, y);
  71585. angle -= ellipseAngularIncrement;
  71586. }
  71587. }
  71588. float x = centreX + radiusX * sinf (toRadians);
  71589. float y = centreY - radiusY * cosf (toRadians);
  71590. if (rotationOfEllipse != 0)
  71591. rotation.transformPoint (x, y);
  71592. lineTo (x, y);
  71593. }
  71594. }
  71595. void Path::addPieSegment (const float x, const float y,
  71596. const float width, const float height,
  71597. const float fromRadians,
  71598. const float toRadians,
  71599. const float innerCircleProportionalSize)
  71600. {
  71601. float hw = width * 0.5f;
  71602. float hh = height * 0.5f;
  71603. const float centreX = x + hw;
  71604. const float centreY = y + hh;
  71605. startNewSubPath (centreX + hw * sinf (fromRadians),
  71606. centreY - hh * cosf (fromRadians));
  71607. addArc (x, y, width, height, fromRadians, toRadians);
  71608. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71609. {
  71610. closeSubPath();
  71611. if (innerCircleProportionalSize > 0)
  71612. {
  71613. hw *= innerCircleProportionalSize;
  71614. hh *= innerCircleProportionalSize;
  71615. startNewSubPath (centreX + hw * sinf (toRadians),
  71616. centreY - hh * cosf (toRadians));
  71617. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71618. toRadians, fromRadians);
  71619. }
  71620. }
  71621. else
  71622. {
  71623. if (innerCircleProportionalSize > 0)
  71624. {
  71625. hw *= innerCircleProportionalSize;
  71626. hh *= innerCircleProportionalSize;
  71627. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71628. toRadians, fromRadians);
  71629. }
  71630. else
  71631. {
  71632. lineTo (centreX, centreY);
  71633. }
  71634. }
  71635. closeSubPath();
  71636. }
  71637. static void perpendicularOffset (const float x1, const float y1,
  71638. const float x2, const float y2,
  71639. const float offsetX, const float offsetY,
  71640. float& resultX, float& resultY) throw()
  71641. {
  71642. const float dx = x2 - x1;
  71643. const float dy = y2 - y1;
  71644. const float len = juce_hypotf (dx, dy);
  71645. if (len == 0)
  71646. {
  71647. resultX = x1;
  71648. resultY = y1;
  71649. }
  71650. else
  71651. {
  71652. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71653. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71654. }
  71655. }
  71656. void Path::addLineSegment (const float startX, const float startY,
  71657. const float endX, const float endY,
  71658. float lineThickness) throw()
  71659. {
  71660. lineThickness *= 0.5f;
  71661. float x, y;
  71662. perpendicularOffset (startX, startY, endX, endY,
  71663. 0, lineThickness, x, y);
  71664. startNewSubPath (x, y);
  71665. perpendicularOffset (startX, startY, endX, endY,
  71666. 0, -lineThickness, x, y);
  71667. lineTo (x, y);
  71668. perpendicularOffset (endX, endY, startX, startY,
  71669. 0, lineThickness, x, y);
  71670. lineTo (x, y);
  71671. perpendicularOffset (endX, endY, startX, startY,
  71672. 0, -lineThickness, x, y);
  71673. lineTo (x, y);
  71674. closeSubPath();
  71675. }
  71676. void Path::addArrow (const float startX, const float startY,
  71677. const float endX, const float endY,
  71678. float lineThickness,
  71679. float arrowheadWidth,
  71680. float arrowheadLength) throw()
  71681. {
  71682. lineThickness *= 0.5f;
  71683. arrowheadWidth *= 0.5f;
  71684. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71685. startY - endY));
  71686. float x, y;
  71687. perpendicularOffset (startX, startY, endX, endY,
  71688. 0, lineThickness, x, y);
  71689. startNewSubPath (x, y);
  71690. perpendicularOffset (startX, startY, endX, endY,
  71691. 0, -lineThickness, x, y);
  71692. lineTo (x, y);
  71693. perpendicularOffset (endX, endY, startX, startY,
  71694. arrowheadLength, lineThickness, x, y);
  71695. lineTo (x, y);
  71696. perpendicularOffset (endX, endY, startX, startY,
  71697. arrowheadLength, arrowheadWidth, x, y);
  71698. lineTo (x, y);
  71699. perpendicularOffset (endX, endY, startX, startY,
  71700. 0, 0, x, y);
  71701. lineTo (x, y);
  71702. perpendicularOffset (endX, endY, startX, startY,
  71703. arrowheadLength, -arrowheadWidth, x, y);
  71704. lineTo (x, y);
  71705. perpendicularOffset (endX, endY, startX, startY,
  71706. arrowheadLength, -lineThickness, x, y);
  71707. lineTo (x, y);
  71708. closeSubPath();
  71709. }
  71710. void Path::addStar (const float centreX,
  71711. const float centreY,
  71712. const int numberOfPoints,
  71713. const float innerRadius,
  71714. const float outerRadius,
  71715. const float startAngle)
  71716. {
  71717. jassert (numberOfPoints > 1); // this would be silly.
  71718. if (numberOfPoints > 1)
  71719. {
  71720. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71721. for (int i = 0; i < numberOfPoints; ++i)
  71722. {
  71723. float angle = startAngle + i * angleBetweenPoints;
  71724. const float x = centreX + outerRadius * sinf (angle);
  71725. const float y = centreY - outerRadius * cosf (angle);
  71726. if (i == 0)
  71727. startNewSubPath (x, y);
  71728. else
  71729. lineTo (x, y);
  71730. angle += angleBetweenPoints * 0.5f;
  71731. lineTo (centreX + innerRadius * sinf (angle),
  71732. centreY - innerRadius * cosf (angle));
  71733. }
  71734. closeSubPath();
  71735. }
  71736. }
  71737. void Path::addBubble (float x, float y,
  71738. float w, float h,
  71739. float cs,
  71740. float tipX,
  71741. float tipY,
  71742. int whichSide,
  71743. float arrowPos,
  71744. float arrowWidth)
  71745. {
  71746. if (w > 1.0f && h > 1.0f)
  71747. {
  71748. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71749. const float cs2 = 2.0f * cs;
  71750. startNewSubPath (x + cs, y);
  71751. if (whichSide == 0)
  71752. {
  71753. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71754. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71755. lineTo (arrowX1, y);
  71756. lineTo (tipX, tipY);
  71757. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71758. }
  71759. lineTo (x + w - cs, y);
  71760. if (cs > 0.0f)
  71761. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71762. if (whichSide == 3)
  71763. {
  71764. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71765. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71766. lineTo (x + w, arrowY1);
  71767. lineTo (tipX, tipY);
  71768. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71769. }
  71770. lineTo (x + w, y + h - cs);
  71771. if (cs > 0.0f)
  71772. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71773. if (whichSide == 2)
  71774. {
  71775. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71776. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71777. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71778. lineTo (tipX, tipY);
  71779. lineTo (arrowX1, y + h);
  71780. }
  71781. lineTo (x + cs, y + h);
  71782. if (cs > 0.0f)
  71783. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71784. if (whichSide == 1)
  71785. {
  71786. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71787. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71788. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71789. lineTo (tipX, tipY);
  71790. lineTo (x, arrowY1);
  71791. }
  71792. lineTo (x, y + cs);
  71793. if (cs > 0.0f)
  71794. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71795. closeSubPath();
  71796. }
  71797. }
  71798. void Path::addPath (const Path& other) throw()
  71799. {
  71800. int i = 0;
  71801. while (i < other.numElements)
  71802. {
  71803. const float type = other.data.elements [i++];
  71804. if (type == moveMarker)
  71805. {
  71806. startNewSubPath (other.data.elements [i],
  71807. other.data.elements [i + 1]);
  71808. i += 2;
  71809. }
  71810. else if (type == lineMarker)
  71811. {
  71812. lineTo (other.data.elements [i],
  71813. other.data.elements [i + 1]);
  71814. i += 2;
  71815. }
  71816. else if (type == quadMarker)
  71817. {
  71818. quadraticTo (other.data.elements [i],
  71819. other.data.elements [i + 1],
  71820. other.data.elements [i + 2],
  71821. other.data.elements [i + 3]);
  71822. i += 4;
  71823. }
  71824. else if (type == cubicMarker)
  71825. {
  71826. cubicTo (other.data.elements [i],
  71827. other.data.elements [i + 1],
  71828. other.data.elements [i + 2],
  71829. other.data.elements [i + 3],
  71830. other.data.elements [i + 4],
  71831. other.data.elements [i + 5]);
  71832. i += 6;
  71833. }
  71834. else if (type == closeSubPathMarker)
  71835. {
  71836. closeSubPath();
  71837. }
  71838. else
  71839. {
  71840. // something's gone wrong with the element list!
  71841. jassertfalse
  71842. }
  71843. }
  71844. }
  71845. void Path::addPath (const Path& other,
  71846. const AffineTransform& transformToApply) throw()
  71847. {
  71848. int i = 0;
  71849. while (i < other.numElements)
  71850. {
  71851. const float type = other.data.elements [i++];
  71852. if (type == closeSubPathMarker)
  71853. {
  71854. closeSubPath();
  71855. }
  71856. else
  71857. {
  71858. float x = other.data.elements [i++];
  71859. float y = other.data.elements [i++];
  71860. transformToApply.transformPoint (x, y);
  71861. if (type == moveMarker)
  71862. {
  71863. startNewSubPath (x, y);
  71864. }
  71865. else if (type == lineMarker)
  71866. {
  71867. lineTo (x, y);
  71868. }
  71869. else if (type == quadMarker)
  71870. {
  71871. float x2 = other.data.elements [i++];
  71872. float y2 = other.data.elements [i++];
  71873. transformToApply.transformPoint (x2, y2);
  71874. quadraticTo (x, y, x2, y2);
  71875. }
  71876. else if (type == cubicMarker)
  71877. {
  71878. float x2 = other.data.elements [i++];
  71879. float y2 = other.data.elements [i++];
  71880. float x3 = other.data.elements [i++];
  71881. float y3 = other.data.elements [i++];
  71882. transformToApply.transformPoint (x2, y2);
  71883. transformToApply.transformPoint (x3, y3);
  71884. cubicTo (x, y, x2, y2, x3, y3);
  71885. }
  71886. else
  71887. {
  71888. // something's gone wrong with the element list!
  71889. jassertfalse
  71890. }
  71891. }
  71892. }
  71893. }
  71894. void Path::applyTransform (const AffineTransform& transform) throw()
  71895. {
  71896. int i = 0;
  71897. pathYMin = pathXMin = 0;
  71898. pathYMax = pathXMax = 0;
  71899. bool setMaxMin = false;
  71900. while (i < numElements)
  71901. {
  71902. const float type = data.elements [i++];
  71903. if (type == moveMarker)
  71904. {
  71905. transform.transformPoint (data.elements [i],
  71906. data.elements [i + 1]);
  71907. if (setMaxMin)
  71908. {
  71909. pathXMin = jmin (pathXMin, data.elements [i]);
  71910. pathXMax = jmax (pathXMax, data.elements [i]);
  71911. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71912. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71913. }
  71914. else
  71915. {
  71916. pathXMin = pathXMax = data.elements [i];
  71917. pathYMin = pathYMax = data.elements [i + 1];
  71918. setMaxMin = true;
  71919. }
  71920. i += 2;
  71921. }
  71922. else if (type == lineMarker)
  71923. {
  71924. transform.transformPoint (data.elements [i],
  71925. data.elements [i + 1]);
  71926. pathXMin = jmin (pathXMin, data.elements [i]);
  71927. pathXMax = jmax (pathXMax, data.elements [i]);
  71928. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71929. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71930. i += 2;
  71931. }
  71932. else if (type == quadMarker)
  71933. {
  71934. transform.transformPoint (data.elements [i],
  71935. data.elements [i + 1]);
  71936. transform.transformPoint (data.elements [i + 2],
  71937. data.elements [i + 3]);
  71938. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71939. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71940. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71941. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71942. i += 4;
  71943. }
  71944. else if (type == cubicMarker)
  71945. {
  71946. transform.transformPoint (data.elements [i],
  71947. data.elements [i + 1]);
  71948. transform.transformPoint (data.elements [i + 2],
  71949. data.elements [i + 3]);
  71950. transform.transformPoint (data.elements [i + 4],
  71951. data.elements [i + 5]);
  71952. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71953. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71954. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71955. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71956. i += 6;
  71957. }
  71958. }
  71959. }
  71960. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71961. const float w, const float h,
  71962. const bool preserveProportions,
  71963. const Justification& justification) const throw()
  71964. {
  71965. Rectangle<float> bounds (getBounds());
  71966. if (preserveProportions)
  71967. {
  71968. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71969. return AffineTransform::identity;
  71970. float newW, newH;
  71971. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71972. if (srcRatio > h / w)
  71973. {
  71974. newW = h / srcRatio;
  71975. newH = h;
  71976. }
  71977. else
  71978. {
  71979. newW = w;
  71980. newH = w * srcRatio;
  71981. }
  71982. float newXCentre = x;
  71983. float newYCentre = y;
  71984. if (justification.testFlags (Justification::left))
  71985. newXCentre += newW * 0.5f;
  71986. else if (justification.testFlags (Justification::right))
  71987. newXCentre += w - newW * 0.5f;
  71988. else
  71989. newXCentre += w * 0.5f;
  71990. if (justification.testFlags (Justification::top))
  71991. newYCentre += newH * 0.5f;
  71992. else if (justification.testFlags (Justification::bottom))
  71993. newYCentre += h - newH * 0.5f;
  71994. else
  71995. newYCentre += h * 0.5f;
  71996. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71997. bounds.getHeight() * -0.5f - bounds.getY())
  71998. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71999. .translated (newXCentre, newYCentre);
  72000. }
  72001. else
  72002. {
  72003. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  72004. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  72005. .translated (x, y);
  72006. }
  72007. }
  72008. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  72009. {
  72010. if (x <= pathXMin || x >= pathXMax
  72011. || y <= pathYMin || y >= pathYMax)
  72012. return false;
  72013. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72014. int positiveCrossings = 0;
  72015. int negativeCrossings = 0;
  72016. while (i.next())
  72017. {
  72018. if ((i.y1 <= y && i.y2 > y)
  72019. || (i.y2 <= y && i.y1 > y))
  72020. {
  72021. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  72022. if (intersectX <= x)
  72023. {
  72024. if (i.y1 < i.y2)
  72025. ++positiveCrossings;
  72026. else
  72027. ++negativeCrossings;
  72028. }
  72029. }
  72030. }
  72031. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  72032. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  72033. }
  72034. bool Path::intersectsLine (const float x1, const float y1,
  72035. const float x2, const float y2,
  72036. const float tolerence) throw()
  72037. {
  72038. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72039. const Line line1 (x1, y1, x2, y2);
  72040. while (i.next())
  72041. {
  72042. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  72043. float ix, iy;
  72044. if (line1.intersects (line2, ix, iy))
  72045. return true;
  72046. }
  72047. return false;
  72048. }
  72049. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  72050. {
  72051. if (cornerRadius <= 0.01f)
  72052. return *this;
  72053. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  72054. int n = 0;
  72055. bool lastWasLine = false, firstWasLine = false;
  72056. Path p;
  72057. while (n < numElements)
  72058. {
  72059. const float type = data.elements [n++];
  72060. if (type == moveMarker)
  72061. {
  72062. indexOfPathStart = p.numElements;
  72063. indexOfPathStartThis = n - 1;
  72064. const float x = data.elements [n++];
  72065. const float y = data.elements [n++];
  72066. p.startNewSubPath (x, y);
  72067. lastWasLine = false;
  72068. firstWasLine = (data.elements [n] == lineMarker);
  72069. }
  72070. else if (type == lineMarker || type == closeSubPathMarker)
  72071. {
  72072. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  72073. if (type == lineMarker)
  72074. {
  72075. endX = data.elements [n++];
  72076. endY = data.elements [n++];
  72077. if (n > 8)
  72078. {
  72079. startX = data.elements [n - 8];
  72080. startY = data.elements [n - 7];
  72081. joinX = data.elements [n - 5];
  72082. joinY = data.elements [n - 4];
  72083. }
  72084. }
  72085. else
  72086. {
  72087. endX = data.elements [indexOfPathStartThis + 1];
  72088. endY = data.elements [indexOfPathStartThis + 2];
  72089. if (n > 6)
  72090. {
  72091. startX = data.elements [n - 6];
  72092. startY = data.elements [n - 5];
  72093. joinX = data.elements [n - 3];
  72094. joinY = data.elements [n - 2];
  72095. }
  72096. }
  72097. if (lastWasLine)
  72098. {
  72099. const double len1 = juce_hypot (startX - joinX,
  72100. startY - joinY);
  72101. if (len1 > 0)
  72102. {
  72103. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72104. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72105. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72106. }
  72107. const double len2 = juce_hypot (endX - joinX,
  72108. endY - joinY);
  72109. if (len2 > 0)
  72110. {
  72111. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72112. p.quadraticTo (joinX, joinY,
  72113. (float) (joinX + (endX - joinX) * propNeeded),
  72114. (float) (joinY + (endY - joinY) * propNeeded));
  72115. }
  72116. p.lineTo (endX, endY);
  72117. }
  72118. else if (type == lineMarker)
  72119. {
  72120. p.lineTo (endX, endY);
  72121. lastWasLine = true;
  72122. }
  72123. if (type == closeSubPathMarker)
  72124. {
  72125. if (firstWasLine)
  72126. {
  72127. startX = data.elements [n - 3];
  72128. startY = data.elements [n - 2];
  72129. joinX = endX;
  72130. joinY = endY;
  72131. endX = data.elements [indexOfPathStartThis + 4];
  72132. endY = data.elements [indexOfPathStartThis + 5];
  72133. const double len1 = juce_hypot (startX - joinX,
  72134. startY - joinY);
  72135. if (len1 > 0)
  72136. {
  72137. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72138. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72139. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72140. }
  72141. const double len2 = juce_hypot (endX - joinX,
  72142. endY - joinY);
  72143. if (len2 > 0)
  72144. {
  72145. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72146. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72147. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72148. p.quadraticTo (joinX, joinY, endX, endY);
  72149. p.data.elements [indexOfPathStart + 1] = endX;
  72150. p.data.elements [indexOfPathStart + 2] = endY;
  72151. }
  72152. }
  72153. p.closeSubPath();
  72154. }
  72155. }
  72156. else if (type == quadMarker)
  72157. {
  72158. lastWasLine = false;
  72159. const float x1 = data.elements [n++];
  72160. const float y1 = data.elements [n++];
  72161. const float x2 = data.elements [n++];
  72162. const float y2 = data.elements [n++];
  72163. p.quadraticTo (x1, y1, x2, y2);
  72164. }
  72165. else if (type == cubicMarker)
  72166. {
  72167. lastWasLine = false;
  72168. const float x1 = data.elements [n++];
  72169. const float y1 = data.elements [n++];
  72170. const float x2 = data.elements [n++];
  72171. const float y2 = data.elements [n++];
  72172. const float x3 = data.elements [n++];
  72173. const float y3 = data.elements [n++];
  72174. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72175. }
  72176. }
  72177. return p;
  72178. }
  72179. void Path::loadPathFromStream (InputStream& source)
  72180. {
  72181. while (! source.isExhausted())
  72182. {
  72183. switch (source.readByte())
  72184. {
  72185. case 'm':
  72186. {
  72187. const float x = source.readFloat();
  72188. const float y = source.readFloat();
  72189. startNewSubPath (x, y);
  72190. break;
  72191. }
  72192. case 'l':
  72193. {
  72194. const float x = source.readFloat();
  72195. const float y = source.readFloat();
  72196. lineTo (x, y);
  72197. break;
  72198. }
  72199. case 'q':
  72200. {
  72201. const float x1 = source.readFloat();
  72202. const float y1 = source.readFloat();
  72203. const float x2 = source.readFloat();
  72204. const float y2 = source.readFloat();
  72205. quadraticTo (x1, y1, x2, y2);
  72206. break;
  72207. }
  72208. case 'b':
  72209. {
  72210. const float x1 = source.readFloat();
  72211. const float y1 = source.readFloat();
  72212. const float x2 = source.readFloat();
  72213. const float y2 = source.readFloat();
  72214. const float x3 = source.readFloat();
  72215. const float y3 = source.readFloat();
  72216. cubicTo (x1, y1, x2, y2, x3, y3);
  72217. break;
  72218. }
  72219. case 'c':
  72220. closeSubPath();
  72221. break;
  72222. case 'n':
  72223. useNonZeroWinding = true;
  72224. break;
  72225. case 'z':
  72226. useNonZeroWinding = false;
  72227. break;
  72228. case 'e':
  72229. return; // end of path marker
  72230. default:
  72231. jassertfalse // illegal char in the stream
  72232. break;
  72233. }
  72234. }
  72235. }
  72236. void Path::loadPathFromData (const unsigned char* const data,
  72237. const int numberOfBytes) throw()
  72238. {
  72239. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72240. loadPathFromStream (in);
  72241. }
  72242. void Path::writePathToStream (OutputStream& dest) const
  72243. {
  72244. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72245. int i = 0;
  72246. while (i < numElements)
  72247. {
  72248. const float type = data.elements [i++];
  72249. if (type == moveMarker)
  72250. {
  72251. dest.writeByte ('m');
  72252. dest.writeFloat (data.elements [i++]);
  72253. dest.writeFloat (data.elements [i++]);
  72254. }
  72255. else if (type == lineMarker)
  72256. {
  72257. dest.writeByte ('l');
  72258. dest.writeFloat (data.elements [i++]);
  72259. dest.writeFloat (data.elements [i++]);
  72260. }
  72261. else if (type == quadMarker)
  72262. {
  72263. dest.writeByte ('q');
  72264. dest.writeFloat (data.elements [i++]);
  72265. dest.writeFloat (data.elements [i++]);
  72266. dest.writeFloat (data.elements [i++]);
  72267. dest.writeFloat (data.elements [i++]);
  72268. }
  72269. else if (type == cubicMarker)
  72270. {
  72271. dest.writeByte ('b');
  72272. dest.writeFloat (data.elements [i++]);
  72273. dest.writeFloat (data.elements [i++]);
  72274. dest.writeFloat (data.elements [i++]);
  72275. dest.writeFloat (data.elements [i++]);
  72276. dest.writeFloat (data.elements [i++]);
  72277. dest.writeFloat (data.elements [i++]);
  72278. }
  72279. else if (type == closeSubPathMarker)
  72280. {
  72281. dest.writeByte ('c');
  72282. }
  72283. }
  72284. dest.writeByte ('e'); // marks the end-of-path
  72285. }
  72286. const String Path::toString() const
  72287. {
  72288. MemoryOutputStream s (2048, 2048);
  72289. if (! useNonZeroWinding)
  72290. s << "a ";
  72291. int i = 0;
  72292. float lastMarker = 0.0f;
  72293. while (i < numElements)
  72294. {
  72295. const float marker = data.elements [i++];
  72296. char markerChar = 0;
  72297. int numCoords = 0;
  72298. if (marker == moveMarker)
  72299. {
  72300. markerChar = 'm';
  72301. numCoords = 2;
  72302. }
  72303. else if (marker == lineMarker)
  72304. {
  72305. markerChar = 'l';
  72306. numCoords = 2;
  72307. }
  72308. else if (marker == quadMarker)
  72309. {
  72310. markerChar = 'q';
  72311. numCoords = 4;
  72312. }
  72313. else if (marker == cubicMarker)
  72314. {
  72315. markerChar = 'c';
  72316. numCoords = 6;
  72317. }
  72318. else
  72319. {
  72320. jassert (marker == closeSubPathMarker);
  72321. markerChar = 'z';
  72322. }
  72323. if (marker != lastMarker)
  72324. {
  72325. s << markerChar << ' ';
  72326. lastMarker = marker;
  72327. }
  72328. while (--numCoords >= 0 && i < numElements)
  72329. {
  72330. String n (data.elements [i++], 3);
  72331. if (n.endsWithChar (T('0')))
  72332. {
  72333. do
  72334. {
  72335. n = n.dropLastCharacters (1);
  72336. } while (n.endsWithChar (T('0')));
  72337. if (n.endsWithChar (T('.')))
  72338. n = n.dropLastCharacters (1);
  72339. }
  72340. s << n << ' ';
  72341. }
  72342. }
  72343. const char* const result = (const char*) s.getData();
  72344. size_t len = s.getDataSize();
  72345. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72346. --len;
  72347. return String (result, len);
  72348. }
  72349. static const String nextToken (const tchar*& t)
  72350. {
  72351. while (CharacterFunctions::isWhitespace (*t))
  72352. ++t;
  72353. const tchar* const start = t;
  72354. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72355. ++t;
  72356. const int length = (int) (t - start);
  72357. while (CharacterFunctions::isWhitespace (*t))
  72358. ++t;
  72359. return String (start, length);
  72360. }
  72361. void Path::restoreFromString (const String& stringVersion)
  72362. {
  72363. clear();
  72364. setUsingNonZeroWinding (true);
  72365. const tchar* t = stringVersion;
  72366. tchar marker = T('m');
  72367. int numValues = 2;
  72368. float values [6];
  72369. while (*t != 0)
  72370. {
  72371. const String token (nextToken (t));
  72372. const tchar firstChar = token[0];
  72373. int startNum = 0;
  72374. if (firstChar == T('m') || firstChar == T('l'))
  72375. {
  72376. marker = firstChar;
  72377. numValues = 2;
  72378. }
  72379. else if (firstChar == T('q'))
  72380. {
  72381. marker = firstChar;
  72382. numValues = 4;
  72383. }
  72384. else if (firstChar == T('c'))
  72385. {
  72386. marker = firstChar;
  72387. numValues = 6;
  72388. }
  72389. else if (firstChar == T('z'))
  72390. {
  72391. marker = firstChar;
  72392. numValues = 0;
  72393. }
  72394. else if (firstChar == T('a'))
  72395. {
  72396. setUsingNonZeroWinding (false);
  72397. continue;
  72398. }
  72399. else
  72400. {
  72401. ++startNum;
  72402. values [0] = token.getFloatValue();
  72403. }
  72404. for (int i = startNum; i < numValues; ++i)
  72405. values [i] = nextToken (t).getFloatValue();
  72406. switch (marker)
  72407. {
  72408. case T('m'):
  72409. startNewSubPath (values[0], values[1]);
  72410. break;
  72411. case T('l'):
  72412. lineTo (values[0], values[1]);
  72413. break;
  72414. case T('q'):
  72415. quadraticTo (values[0], values[1],
  72416. values[2], values[3]);
  72417. break;
  72418. case T('c'):
  72419. cubicTo (values[0], values[1],
  72420. values[2], values[3],
  72421. values[4], values[5]);
  72422. break;
  72423. case T('z'):
  72424. closeSubPath();
  72425. break;
  72426. default:
  72427. jassertfalse // illegal string format?
  72428. break;
  72429. }
  72430. }
  72431. }
  72432. Path::Iterator::Iterator (const Path& path_)
  72433. : path (path_),
  72434. index (0)
  72435. {
  72436. }
  72437. Path::Iterator::~Iterator()
  72438. {
  72439. }
  72440. bool Path::Iterator::next()
  72441. {
  72442. const float* const elements = path.data.elements;
  72443. if (index < path.numElements)
  72444. {
  72445. const float type = elements [index++];
  72446. if (type == moveMarker)
  72447. {
  72448. elementType = startNewSubPath;
  72449. x1 = elements [index++];
  72450. y1 = elements [index++];
  72451. }
  72452. else if (type == lineMarker)
  72453. {
  72454. elementType = lineTo;
  72455. x1 = elements [index++];
  72456. y1 = elements [index++];
  72457. }
  72458. else if (type == quadMarker)
  72459. {
  72460. elementType = quadraticTo;
  72461. x1 = elements [index++];
  72462. y1 = elements [index++];
  72463. x2 = elements [index++];
  72464. y2 = elements [index++];
  72465. }
  72466. else if (type == cubicMarker)
  72467. {
  72468. elementType = cubicTo;
  72469. x1 = elements [index++];
  72470. y1 = elements [index++];
  72471. x2 = elements [index++];
  72472. y2 = elements [index++];
  72473. x3 = elements [index++];
  72474. y3 = elements [index++];
  72475. }
  72476. else if (type == closeSubPathMarker)
  72477. {
  72478. elementType = closePath;
  72479. }
  72480. return true;
  72481. }
  72482. return false;
  72483. }
  72484. END_JUCE_NAMESPACE
  72485. /*** End of inlined file: juce_Path.cpp ***/
  72486. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72487. BEGIN_JUCE_NAMESPACE
  72488. #if JUCE_MSVC
  72489. #pragma optimize ("t", on)
  72490. #endif
  72491. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72492. const AffineTransform& transform_,
  72493. float tolerence_) throw()
  72494. : x2 (0),
  72495. y2 (0),
  72496. closesSubPath (false),
  72497. subPathIndex (-1),
  72498. path (path_),
  72499. transform (transform_),
  72500. points (path_.data.elements),
  72501. tolerence (tolerence_ * tolerence_),
  72502. subPathCloseX (0),
  72503. subPathCloseY (0),
  72504. stackBase (32),
  72505. index (0),
  72506. stackSize (32)
  72507. {
  72508. isIdentityTransform = transform.isIdentity();
  72509. stackPos = stackBase;
  72510. }
  72511. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72512. {
  72513. }
  72514. bool PathFlatteningIterator::next() throw()
  72515. {
  72516. x1 = x2;
  72517. y1 = y2;
  72518. float x3 = 0;
  72519. float y3 = 0;
  72520. float x4 = 0;
  72521. float y4 = 0;
  72522. float type;
  72523. for (;;)
  72524. {
  72525. if (stackPos == stackBase)
  72526. {
  72527. if (index >= path.numElements)
  72528. {
  72529. return false;
  72530. }
  72531. else
  72532. {
  72533. type = points [index++];
  72534. if (type != Path::closeSubPathMarker)
  72535. {
  72536. x2 = points [index++];
  72537. y2 = points [index++];
  72538. if (! isIdentityTransform)
  72539. transform.transformPoint (x2, y2);
  72540. if (type == Path::quadMarker)
  72541. {
  72542. x3 = points [index++];
  72543. y3 = points [index++];
  72544. if (! isIdentityTransform)
  72545. transform.transformPoint (x3, y3);
  72546. }
  72547. else if (type == Path::cubicMarker)
  72548. {
  72549. x3 = points [index++];
  72550. y3 = points [index++];
  72551. x4 = points [index++];
  72552. y4 = points [index++];
  72553. if (! isIdentityTransform)
  72554. {
  72555. transform.transformPoint (x3, y3);
  72556. transform.transformPoint (x4, y4);
  72557. }
  72558. }
  72559. }
  72560. }
  72561. }
  72562. else
  72563. {
  72564. type = *--stackPos;
  72565. if (type != Path::closeSubPathMarker)
  72566. {
  72567. x2 = *--stackPos;
  72568. y2 = *--stackPos;
  72569. if (type == Path::quadMarker)
  72570. {
  72571. x3 = *--stackPos;
  72572. y3 = *--stackPos;
  72573. }
  72574. else if (type == Path::cubicMarker)
  72575. {
  72576. x3 = *--stackPos;
  72577. y3 = *--stackPos;
  72578. x4 = *--stackPos;
  72579. y4 = *--stackPos;
  72580. }
  72581. }
  72582. }
  72583. if (type == Path::lineMarker)
  72584. {
  72585. ++subPathIndex;
  72586. closesSubPath = (stackPos == stackBase)
  72587. && (index < path.numElements)
  72588. && (points [index] == Path::closeSubPathMarker)
  72589. && x2 == subPathCloseX
  72590. && y2 == subPathCloseY;
  72591. return true;
  72592. }
  72593. else if (type == Path::quadMarker)
  72594. {
  72595. const int offset = (int) (stackPos - stackBase);
  72596. if (offset >= stackSize - 10)
  72597. {
  72598. stackSize <<= 1;
  72599. stackBase.realloc (stackSize);
  72600. stackPos = stackBase + offset;
  72601. }
  72602. const float dx1 = x1 - x2;
  72603. const float dy1 = y1 - y2;
  72604. const float dx2 = x2 - x3;
  72605. const float dy2 = y2 - y3;
  72606. const float m1x = (x1 + x2) * 0.5f;
  72607. const float m1y = (y1 + y2) * 0.5f;
  72608. const float m2x = (x2 + x3) * 0.5f;
  72609. const float m2y = (y2 + y3) * 0.5f;
  72610. const float m3x = (m1x + m2x) * 0.5f;
  72611. const float m3y = (m1y + m2y) * 0.5f;
  72612. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72613. {
  72614. *stackPos++ = y3;
  72615. *stackPos++ = x3;
  72616. *stackPos++ = m2y;
  72617. *stackPos++ = m2x;
  72618. *stackPos++ = Path::quadMarker;
  72619. *stackPos++ = m3y;
  72620. *stackPos++ = m3x;
  72621. *stackPos++ = m1y;
  72622. *stackPos++ = m1x;
  72623. *stackPos++ = Path::quadMarker;
  72624. }
  72625. else
  72626. {
  72627. *stackPos++ = y3;
  72628. *stackPos++ = x3;
  72629. *stackPos++ = Path::lineMarker;
  72630. *stackPos++ = m3y;
  72631. *stackPos++ = m3x;
  72632. *stackPos++ = Path::lineMarker;
  72633. }
  72634. jassert (stackPos < stackBase + stackSize);
  72635. }
  72636. else if (type == Path::cubicMarker)
  72637. {
  72638. const int offset = (int) (stackPos - stackBase);
  72639. if (offset >= stackSize - 16)
  72640. {
  72641. stackSize <<= 1;
  72642. stackBase.realloc (stackSize);
  72643. stackPos = stackBase + offset;
  72644. }
  72645. const float dx1 = x1 - x2;
  72646. const float dy1 = y1 - y2;
  72647. const float dx2 = x2 - x3;
  72648. const float dy2 = y2 - y3;
  72649. const float dx3 = x3 - x4;
  72650. const float dy3 = y3 - y4;
  72651. const float m1x = (x1 + x2) * 0.5f;
  72652. const float m1y = (y1 + y2) * 0.5f;
  72653. const float m2x = (x3 + x2) * 0.5f;
  72654. const float m2y = (y3 + y2) * 0.5f;
  72655. const float m3x = (x3 + x4) * 0.5f;
  72656. const float m3y = (y3 + y4) * 0.5f;
  72657. const float m4x = (m1x + m2x) * 0.5f;
  72658. const float m4y = (m1y + m2y) * 0.5f;
  72659. const float m5x = (m3x + m2x) * 0.5f;
  72660. const float m5y = (m3y + m2y) * 0.5f;
  72661. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72662. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72663. {
  72664. *stackPos++ = y4;
  72665. *stackPos++ = x4;
  72666. *stackPos++ = m3y;
  72667. *stackPos++ = m3x;
  72668. *stackPos++ = m5y;
  72669. *stackPos++ = m5x;
  72670. *stackPos++ = Path::cubicMarker;
  72671. *stackPos++ = (m4y + m5y) * 0.5f;
  72672. *stackPos++ = (m4x + m5x) * 0.5f;
  72673. *stackPos++ = m4y;
  72674. *stackPos++ = m4x;
  72675. *stackPos++ = m1y;
  72676. *stackPos++ = m1x;
  72677. *stackPos++ = Path::cubicMarker;
  72678. }
  72679. else
  72680. {
  72681. *stackPos++ = y4;
  72682. *stackPos++ = x4;
  72683. *stackPos++ = Path::lineMarker;
  72684. *stackPos++ = m5y;
  72685. *stackPos++ = m5x;
  72686. *stackPos++ = Path::lineMarker;
  72687. *stackPos++ = m4y;
  72688. *stackPos++ = m4x;
  72689. *stackPos++ = Path::lineMarker;
  72690. }
  72691. }
  72692. else if (type == Path::closeSubPathMarker)
  72693. {
  72694. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72695. {
  72696. x1 = x2;
  72697. y1 = y2;
  72698. x2 = subPathCloseX;
  72699. y2 = subPathCloseY;
  72700. closesSubPath = true;
  72701. return true;
  72702. }
  72703. }
  72704. else
  72705. {
  72706. jassert (type == Path::moveMarker);
  72707. subPathIndex = -1;
  72708. subPathCloseX = x1 = x2;
  72709. subPathCloseY = y1 = y2;
  72710. }
  72711. }
  72712. }
  72713. END_JUCE_NAMESPACE
  72714. /*** End of inlined file: juce_PathIterator.cpp ***/
  72715. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72716. BEGIN_JUCE_NAMESPACE
  72717. PathStrokeType::PathStrokeType (const float strokeThickness,
  72718. const JointStyle jointStyle_,
  72719. const EndCapStyle endStyle_) throw()
  72720. : thickness (strokeThickness),
  72721. jointStyle (jointStyle_),
  72722. endStyle (endStyle_)
  72723. {
  72724. }
  72725. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72726. : thickness (other.thickness),
  72727. jointStyle (other.jointStyle),
  72728. endStyle (other.endStyle)
  72729. {
  72730. }
  72731. const PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72732. {
  72733. thickness = other.thickness;
  72734. jointStyle = other.jointStyle;
  72735. endStyle = other.endStyle;
  72736. return *this;
  72737. }
  72738. PathStrokeType::~PathStrokeType() throw()
  72739. {
  72740. }
  72741. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72742. {
  72743. return thickness == other.thickness
  72744. && jointStyle == other.jointStyle
  72745. && endStyle == other.endStyle;
  72746. }
  72747. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72748. {
  72749. return ! operator== (other);
  72750. }
  72751. static bool lineIntersection (const float x1, const float y1,
  72752. const float x2, const float y2,
  72753. const float x3, const float y3,
  72754. const float x4, const float y4,
  72755. float& intersectionX,
  72756. float& intersectionY,
  72757. float& distanceBeyondLine1EndSquared) throw()
  72758. {
  72759. if (x2 != x3 || y2 != y3)
  72760. {
  72761. const float dx1 = x2 - x1;
  72762. const float dy1 = y2 - y1;
  72763. const float dx2 = x4 - x3;
  72764. const float dy2 = y4 - y3;
  72765. const float divisor = dx1 * dy2 - dx2 * dy1;
  72766. if (divisor == 0)
  72767. {
  72768. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72769. {
  72770. if (dy1 == 0 && dy2 != 0)
  72771. {
  72772. const float along = (y1 - y3) / dy2;
  72773. intersectionX = x3 + along * dx2;
  72774. intersectionY = y1;
  72775. distanceBeyondLine1EndSquared = intersectionX - x2;
  72776. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72777. if ((x2 > x1) == (intersectionX < x2))
  72778. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72779. return along >= 0 && along <= 1.0f;
  72780. }
  72781. else if (dy2 == 0 && dy1 != 0)
  72782. {
  72783. const float along = (y3 - y1) / dy1;
  72784. intersectionX = x1 + along * dx1;
  72785. intersectionY = y3;
  72786. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72787. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72788. if (along < 1.0f)
  72789. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72790. return along >= 0 && along <= 1.0f;
  72791. }
  72792. else if (dx1 == 0 && dx2 != 0)
  72793. {
  72794. const float along = (x1 - x3) / dx2;
  72795. intersectionX = x1;
  72796. intersectionY = y3 + along * dy2;
  72797. distanceBeyondLine1EndSquared = intersectionY - y2;
  72798. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72799. if ((y2 > y1) == (intersectionY < y2))
  72800. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72801. return along >= 0 && along <= 1.0f;
  72802. }
  72803. else if (dx2 == 0 && dx1 != 0)
  72804. {
  72805. const float along = (x3 - x1) / dx1;
  72806. intersectionX = x3;
  72807. intersectionY = y1 + along * dy1;
  72808. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72809. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72810. if (along < 1.0f)
  72811. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72812. return along >= 0 && along <= 1.0f;
  72813. }
  72814. }
  72815. intersectionX = 0.5f * (x2 + x3);
  72816. intersectionY = 0.5f * (y2 + y3);
  72817. distanceBeyondLine1EndSquared = 0.0f;
  72818. return false;
  72819. }
  72820. else
  72821. {
  72822. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72823. intersectionX = x1 + along1 * dx1;
  72824. intersectionY = y1 + along1 * dy1;
  72825. if (along1 >= 0 && along1 <= 1.0f)
  72826. {
  72827. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72828. if (along2 >= 0 && along2 <= divisor)
  72829. {
  72830. distanceBeyondLine1EndSquared = 0.0f;
  72831. return true;
  72832. }
  72833. }
  72834. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72835. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72836. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72837. if (along1 < 1.0f)
  72838. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72839. return false;
  72840. }
  72841. }
  72842. intersectionX = x2;
  72843. intersectionY = y2;
  72844. distanceBeyondLine1EndSquared = 0.0f;
  72845. return true;
  72846. }
  72847. // part of stroke drawing stuff
  72848. static void addEdgeAndJoint (Path& destPath,
  72849. const PathStrokeType::JointStyle style,
  72850. const float maxMiterExtensionSquared, const float width,
  72851. const float x1, const float y1,
  72852. const float x2, const float y2,
  72853. const float x3, const float y3,
  72854. const float x4, const float y4,
  72855. const float midX, const float midY) throw()
  72856. {
  72857. if (style == PathStrokeType::beveled
  72858. || (x3 == x4 && y3 == y4)
  72859. || (x1 == x2 && y1 == y2))
  72860. {
  72861. destPath.lineTo (x2, y2);
  72862. destPath.lineTo (x3, y3);
  72863. }
  72864. else
  72865. {
  72866. float jx, jy, distanceBeyondLine1EndSquared;
  72867. // if they intersect, use this point..
  72868. if (lineIntersection (x1, y1, x2, y2,
  72869. x3, y3, x4, y4,
  72870. jx, jy, distanceBeyondLine1EndSquared))
  72871. {
  72872. destPath.lineTo (jx, jy);
  72873. }
  72874. else
  72875. {
  72876. if (style == PathStrokeType::mitered)
  72877. {
  72878. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72879. && distanceBeyondLine1EndSquared > 0.0f)
  72880. {
  72881. destPath.lineTo (jx, jy);
  72882. }
  72883. else
  72884. {
  72885. // the end sticks out too far, so just use a blunt joint
  72886. destPath.lineTo (x2, y2);
  72887. destPath.lineTo (x3, y3);
  72888. }
  72889. }
  72890. else
  72891. {
  72892. // curved joints
  72893. float angle1 = atan2f (x2 - midX, y2 - midY);
  72894. float angle2 = atan2f (x3 - midX, y3 - midY);
  72895. const float angleIncrement = 0.1f;
  72896. destPath.lineTo (x2, y2);
  72897. if (fabs (angle1 - angle2) > angleIncrement)
  72898. {
  72899. if (angle2 > angle1 + float_Pi
  72900. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72901. {
  72902. if (angle2 > angle1)
  72903. angle2 -= float_Pi * 2.0f;
  72904. jassert (angle1 <= angle2 + float_Pi);
  72905. angle1 -= angleIncrement;
  72906. while (angle1 > angle2)
  72907. {
  72908. destPath.lineTo (midX + width * sinf (angle1),
  72909. midY + width * cosf (angle1));
  72910. angle1 -= angleIncrement;
  72911. }
  72912. }
  72913. else
  72914. {
  72915. if (angle1 > angle2)
  72916. angle1 -= float_Pi * 2.0f;
  72917. jassert (angle1 >= angle2 - float_Pi);
  72918. angle1 += angleIncrement;
  72919. while (angle1 < angle2)
  72920. {
  72921. destPath.lineTo (midX + width * sinf (angle1),
  72922. midY + width * cosf (angle1));
  72923. angle1 += angleIncrement;
  72924. }
  72925. }
  72926. }
  72927. destPath.lineTo (x3, y3);
  72928. }
  72929. }
  72930. }
  72931. }
  72932. static inline void addLineEnd (Path& destPath,
  72933. const PathStrokeType::EndCapStyle style,
  72934. const float x1, const float y1,
  72935. const float x2, const float y2,
  72936. const float width) throw()
  72937. {
  72938. if (style == PathStrokeType::butt)
  72939. {
  72940. destPath.lineTo (x2, y2);
  72941. }
  72942. else
  72943. {
  72944. float offx1, offy1, offx2, offy2;
  72945. float dx = x2 - x1;
  72946. float dy = y2 - y1;
  72947. const float len = juce_hypotf (dx, dy);
  72948. if (len == 0)
  72949. {
  72950. offx1 = offx2 = x1;
  72951. offy1 = offy2 = y1;
  72952. }
  72953. else
  72954. {
  72955. const float offset = width / len;
  72956. dx *= offset;
  72957. dy *= offset;
  72958. offx1 = x1 + dy;
  72959. offy1 = y1 - dx;
  72960. offx2 = x2 + dy;
  72961. offy2 = y2 - dx;
  72962. }
  72963. if (style == PathStrokeType::square)
  72964. {
  72965. // sqaure ends
  72966. destPath.lineTo (offx1, offy1);
  72967. destPath.lineTo (offx2, offy2);
  72968. destPath.lineTo (x2, y2);
  72969. }
  72970. else
  72971. {
  72972. // rounded ends
  72973. const float midx = (offx1 + offx2) * 0.5f;
  72974. const float midy = (offy1 + offy2) * 0.5f;
  72975. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72976. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72977. midx, midy);
  72978. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72979. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72980. x2, y2);
  72981. }
  72982. }
  72983. }
  72984. struct LineSection
  72985. {
  72986. LineSection() {}
  72987. LineSection (int) {}
  72988. float x1, y1, x2, y2; // original line
  72989. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72990. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72991. };
  72992. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72993. const bool isClosed,
  72994. const float width, const float maxMiterExtensionSquared,
  72995. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle) throw()
  72996. {
  72997. jassert (subPath.size() > 0);
  72998. const LineSection& firstLine = subPath.getReference (0);
  72999. float lastX1 = firstLine.lx1;
  73000. float lastY1 = firstLine.ly1;
  73001. float lastX2 = firstLine.lx2;
  73002. float lastY2 = firstLine.ly2;
  73003. if (isClosed)
  73004. {
  73005. destPath.startNewSubPath (lastX1, lastY1);
  73006. }
  73007. else
  73008. {
  73009. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  73010. addLineEnd (destPath, endStyle,
  73011. firstLine.rx2, firstLine.ry2,
  73012. lastX1, lastY1,
  73013. width);
  73014. }
  73015. int i;
  73016. for (i = 1; i < subPath.size(); ++i)
  73017. {
  73018. const LineSection& l = subPath.getReference (i);
  73019. addEdgeAndJoint (destPath, jointStyle,
  73020. maxMiterExtensionSquared, width,
  73021. lastX1, lastY1, lastX2, lastY2,
  73022. l.lx1, l.ly1, l.lx2, l.ly2,
  73023. l.x1, l.y1);
  73024. lastX1 = l.lx1;
  73025. lastY1 = l.ly1;
  73026. lastX2 = l.lx2;
  73027. lastY2 = l.ly2;
  73028. }
  73029. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  73030. if (isClosed)
  73031. {
  73032. const LineSection& l = subPath.getReference (0);
  73033. addEdgeAndJoint (destPath, jointStyle,
  73034. maxMiterExtensionSquared, width,
  73035. lastX1, lastY1, lastX2, lastY2,
  73036. l.lx1, l.ly1, l.lx2, l.ly2,
  73037. l.x1, l.y1);
  73038. destPath.closeSubPath();
  73039. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  73040. }
  73041. else
  73042. {
  73043. destPath.lineTo (lastX2, lastY2);
  73044. addLineEnd (destPath, endStyle,
  73045. lastX2, lastY2,
  73046. lastLine.rx1, lastLine.ry1,
  73047. width);
  73048. }
  73049. lastX1 = lastLine.rx1;
  73050. lastY1 = lastLine.ry1;
  73051. lastX2 = lastLine.rx2;
  73052. lastY2 = lastLine.ry2;
  73053. for (i = subPath.size() - 1; --i >= 0;)
  73054. {
  73055. const LineSection& l = subPath.getReference (i);
  73056. addEdgeAndJoint (destPath, jointStyle,
  73057. maxMiterExtensionSquared, width,
  73058. lastX1, lastY1, lastX2, lastY2,
  73059. l.rx1, l.ry1, l.rx2, l.ry2,
  73060. l.x2, l.y2);
  73061. lastX1 = l.rx1;
  73062. lastY1 = l.ry1;
  73063. lastX2 = l.rx2;
  73064. lastY2 = l.ry2;
  73065. }
  73066. if (isClosed)
  73067. {
  73068. addEdgeAndJoint (destPath, jointStyle,
  73069. maxMiterExtensionSquared, width,
  73070. lastX1, lastY1, lastX2, lastY2,
  73071. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  73072. lastLine.x2, lastLine.y2);
  73073. }
  73074. else
  73075. {
  73076. // do the last line
  73077. destPath.lineTo (lastX2, lastY2);
  73078. }
  73079. destPath.closeSubPath();
  73080. }
  73081. void PathStrokeType::createStrokedPath (Path& destPath,
  73082. const Path& source,
  73083. const AffineTransform& transform,
  73084. const float extraAccuracy) const throw()
  73085. {
  73086. if (thickness <= 0)
  73087. {
  73088. destPath.clear();
  73089. return;
  73090. }
  73091. const Path* sourcePath = &source;
  73092. Path temp;
  73093. if (sourcePath == &destPath)
  73094. {
  73095. destPath.swapWithPath (temp);
  73096. sourcePath = &temp;
  73097. }
  73098. else
  73099. {
  73100. destPath.clear();
  73101. }
  73102. destPath.setUsingNonZeroWinding (true);
  73103. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73104. const float width = 0.5f * thickness;
  73105. // Iterate the path, creating a list of the
  73106. // left/right-hand lines along either side of it...
  73107. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73108. Array <LineSection> subPath;
  73109. LineSection l;
  73110. l.x1 = 0;
  73111. l.y1 = 0;
  73112. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73113. while (it.next())
  73114. {
  73115. if (it.subPathIndex == 0)
  73116. {
  73117. if (subPath.size() > 0)
  73118. {
  73119. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73120. subPath.clearQuick();
  73121. }
  73122. l.x1 = it.x1;
  73123. l.y1 = it.y1;
  73124. }
  73125. l.x2 = it.x2;
  73126. l.y2 = it.y2;
  73127. float dx = l.x2 - l.x1;
  73128. float dy = l.y2 - l.y1;
  73129. const float hypotSquared = dx*dx + dy*dy;
  73130. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73131. {
  73132. const float len = sqrtf (hypotSquared);
  73133. if (len == 0)
  73134. {
  73135. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73136. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73137. }
  73138. else
  73139. {
  73140. const float offset = width / len;
  73141. dx *= offset;
  73142. dy *= offset;
  73143. l.rx2 = l.x1 - dy;
  73144. l.ry2 = l.y1 + dx;
  73145. l.lx1 = l.x1 + dy;
  73146. l.ly1 = l.y1 - dx;
  73147. l.lx2 = l.x2 + dy;
  73148. l.ly2 = l.y2 - dx;
  73149. l.rx1 = l.x2 - dy;
  73150. l.ry1 = l.y2 + dx;
  73151. }
  73152. subPath.add (l);
  73153. if (it.closesSubPath)
  73154. {
  73155. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73156. subPath.clearQuick();
  73157. }
  73158. else
  73159. {
  73160. l.x1 = it.x2;
  73161. l.y1 = it.y2;
  73162. }
  73163. }
  73164. }
  73165. if (subPath.size() > 0)
  73166. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73167. }
  73168. void PathStrokeType::createDashedStroke (Path& destPath,
  73169. const Path& sourcePath,
  73170. const float* dashLengths,
  73171. int numDashLengths,
  73172. const AffineTransform& transform,
  73173. const float extraAccuracy) const throw()
  73174. {
  73175. if (thickness <= 0)
  73176. return;
  73177. // this should really be an even number..
  73178. jassert ((numDashLengths & 1) == 0);
  73179. Path newDestPath;
  73180. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73181. bool first = true;
  73182. int dashNum = 0;
  73183. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73184. float dx = 0.0f, dy = 0.0f;
  73185. for (;;)
  73186. {
  73187. const bool isSolid = ((dashNum & 1) == 0);
  73188. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73189. jassert (dashLen > 0); // must be a positive increment!
  73190. if (dashLen <= 0)
  73191. break;
  73192. pos += dashLen;
  73193. while (pos > lineEndPos)
  73194. {
  73195. if (! it.next())
  73196. {
  73197. if (isSolid && ! first)
  73198. newDestPath.lineTo (it.x2, it.y2);
  73199. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73200. return;
  73201. }
  73202. if (isSolid && ! first)
  73203. newDestPath.lineTo (it.x1, it.y1);
  73204. else
  73205. newDestPath.startNewSubPath (it.x1, it.y1);
  73206. dx = it.x2 - it.x1;
  73207. dy = it.y2 - it.y1;
  73208. lineLen = juce_hypotf (dx, dy);
  73209. lineEndPos += lineLen;
  73210. first = it.closesSubPath;
  73211. }
  73212. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73213. if (isSolid)
  73214. newDestPath.lineTo (it.x1 + dx * alpha,
  73215. it.y1 + dy * alpha);
  73216. else
  73217. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73218. it.y1 + dy * alpha);
  73219. }
  73220. }
  73221. END_JUCE_NAMESPACE
  73222. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  73223. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  73224. BEGIN_JUCE_NAMESPACE
  73225. PositionedRectangle::PositionedRectangle() throw()
  73226. : x (0.0),
  73227. y (0.0),
  73228. w (0.0),
  73229. h (0.0),
  73230. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73231. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73232. wMode (absoluteSize),
  73233. hMode (absoluteSize)
  73234. {
  73235. }
  73236. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73237. : x (other.x),
  73238. y (other.y),
  73239. w (other.w),
  73240. h (other.h),
  73241. xMode (other.xMode),
  73242. yMode (other.yMode),
  73243. wMode (other.wMode),
  73244. hMode (other.hMode)
  73245. {
  73246. }
  73247. const PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73248. {
  73249. x = other.x;
  73250. y = other.y;
  73251. w = other.w;
  73252. h = other.h;
  73253. xMode = other.xMode;
  73254. yMode = other.yMode;
  73255. wMode = other.wMode;
  73256. hMode = other.hMode;
  73257. return *this;
  73258. }
  73259. PositionedRectangle::~PositionedRectangle() throw()
  73260. {
  73261. }
  73262. const bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73263. {
  73264. return x == other.x
  73265. && y == other.y
  73266. && w == other.w
  73267. && h == other.h
  73268. && xMode == other.xMode
  73269. && yMode == other.yMode
  73270. && wMode == other.wMode
  73271. && hMode == other.hMode;
  73272. }
  73273. const bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73274. {
  73275. return ! operator== (other);
  73276. }
  73277. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73278. {
  73279. StringArray tokens;
  73280. tokens.addTokens (stringVersion, false);
  73281. decodePosString (tokens [0], xMode, x);
  73282. decodePosString (tokens [1], yMode, y);
  73283. decodeSizeString (tokens [2], wMode, w);
  73284. decodeSizeString (tokens [3], hMode, h);
  73285. }
  73286. const String PositionedRectangle::toString() const throw()
  73287. {
  73288. String s;
  73289. s.preallocateStorage (12);
  73290. addPosDescription (s, xMode, x);
  73291. s << T(' ');
  73292. addPosDescription (s, yMode, y);
  73293. s << T(' ');
  73294. addSizeDescription (s, wMode, w);
  73295. s << T(' ');
  73296. addSizeDescription (s, hMode, h);
  73297. return s;
  73298. }
  73299. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  73300. {
  73301. jassert (! target.isEmpty());
  73302. double x_, y_, w_, h_;
  73303. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73304. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73305. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  73306. roundToInt (w_), roundToInt (h_));
  73307. }
  73308. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  73309. double& x_, double& y_,
  73310. double& w_, double& h_) const throw()
  73311. {
  73312. jassert (! target.isEmpty());
  73313. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73314. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73315. }
  73316. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73317. {
  73318. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73319. }
  73320. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  73321. const Rectangle<int>& target) throw()
  73322. {
  73323. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73324. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73325. }
  73326. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73327. const double newW, const double newH,
  73328. const Rectangle<int>& target) throw()
  73329. {
  73330. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73331. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73332. }
  73333. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73334. {
  73335. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73336. updateFrom (comp.getBounds(), Rectangle<int>());
  73337. else
  73338. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73339. }
  73340. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73341. {
  73342. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73343. }
  73344. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73345. {
  73346. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73347. | absoluteFromParentBottomRight
  73348. | absoluteFromParentCentre
  73349. | proportionOfParentSize));
  73350. }
  73351. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73352. {
  73353. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73354. }
  73355. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73356. {
  73357. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73358. | absoluteFromParentBottomRight
  73359. | absoluteFromParentCentre
  73360. | proportionOfParentSize));
  73361. }
  73362. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73363. {
  73364. return (SizeMode) wMode;
  73365. }
  73366. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73367. {
  73368. return (SizeMode) hMode;
  73369. }
  73370. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73371. const PositionMode xMode_,
  73372. const AnchorPoint yAnchor,
  73373. const PositionMode yMode_,
  73374. const SizeMode widthMode,
  73375. const SizeMode heightMode,
  73376. const Rectangle<int>& target) throw()
  73377. {
  73378. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73379. {
  73380. double tx, tw;
  73381. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73382. xMode = (uint8) (xAnchor | xMode_);
  73383. wMode = (uint8) widthMode;
  73384. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73385. }
  73386. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73387. {
  73388. double ty, th;
  73389. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73390. yMode = (uint8) (yAnchor | yMode_);
  73391. hMode = (uint8) heightMode;
  73392. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73393. }
  73394. }
  73395. bool PositionedRectangle::isPositionAbsolute() const throw()
  73396. {
  73397. return xMode == absoluteFromParentTopLeft
  73398. && yMode == absoluteFromParentTopLeft
  73399. && wMode == absoluteSize
  73400. && hMode == absoluteSize;
  73401. }
  73402. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73403. {
  73404. if ((mode & proportionOfParentSize) != 0)
  73405. {
  73406. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73407. }
  73408. else
  73409. {
  73410. s << (roundToInt (value * 100.0) / 100.0);
  73411. if ((mode & absoluteFromParentBottomRight) != 0)
  73412. s << T('R');
  73413. else if ((mode & absoluteFromParentCentre) != 0)
  73414. s << T('C');
  73415. }
  73416. if ((mode & anchorAtRightOrBottom) != 0)
  73417. s << T('r');
  73418. else if ((mode & anchorAtCentre) != 0)
  73419. s << T('c');
  73420. }
  73421. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73422. {
  73423. if (mode == proportionalSize)
  73424. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73425. else if (mode == parentSizeMinusAbsolute)
  73426. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73427. else
  73428. s << (roundToInt (value * 100.0) / 100.0);
  73429. }
  73430. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73431. {
  73432. if (s.containsChar (T('r')))
  73433. mode = anchorAtRightOrBottom;
  73434. else if (s.containsChar (T('c')))
  73435. mode = anchorAtCentre;
  73436. else
  73437. mode = anchorAtLeftOrTop;
  73438. if (s.containsChar (T('%')))
  73439. {
  73440. mode |= proportionOfParentSize;
  73441. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73442. }
  73443. else
  73444. {
  73445. if (s.containsChar (T('R')))
  73446. mode |= absoluteFromParentBottomRight;
  73447. else if (s.containsChar (T('C')))
  73448. mode |= absoluteFromParentCentre;
  73449. else
  73450. mode |= absoluteFromParentTopLeft;
  73451. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73452. }
  73453. }
  73454. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73455. {
  73456. if (s.containsChar (T('%')))
  73457. {
  73458. mode = proportionalSize;
  73459. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73460. }
  73461. else if (s.containsChar (T('M')))
  73462. {
  73463. mode = parentSizeMinusAbsolute;
  73464. value = s.getDoubleValue();
  73465. }
  73466. else
  73467. {
  73468. mode = absoluteSize;
  73469. value = s.getDoubleValue();
  73470. }
  73471. }
  73472. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73473. const double x_, const double w_,
  73474. const uint8 xMode_, const uint8 wMode_,
  73475. const int parentPos,
  73476. const int parentSize) const throw()
  73477. {
  73478. if (wMode_ == proportionalSize)
  73479. wOut = roundToInt (w_ * parentSize);
  73480. else if (wMode_ == parentSizeMinusAbsolute)
  73481. wOut = jmax (0, parentSize - roundToInt (w_));
  73482. else
  73483. wOut = roundToInt (w_);
  73484. if ((xMode_ & proportionOfParentSize) != 0)
  73485. xOut = parentPos + x_ * parentSize;
  73486. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73487. xOut = (parentPos + parentSize) - x_;
  73488. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73489. xOut = x_ + (parentPos + parentSize / 2);
  73490. else
  73491. xOut = x_ + parentPos;
  73492. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73493. xOut -= wOut;
  73494. else if ((xMode_ & anchorAtCentre) != 0)
  73495. xOut -= wOut / 2;
  73496. }
  73497. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73498. double x_, const double w_,
  73499. const uint8 xMode_, const uint8 wMode_,
  73500. const int parentPos,
  73501. const int parentSize) const throw()
  73502. {
  73503. if (wMode_ == proportionalSize)
  73504. {
  73505. if (parentSize > 0)
  73506. wOut = w_ / parentSize;
  73507. }
  73508. else if (wMode_ == parentSizeMinusAbsolute)
  73509. wOut = parentSize - w_;
  73510. else
  73511. wOut = w_;
  73512. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73513. x_ += w_;
  73514. else if ((xMode_ & anchorAtCentre) != 0)
  73515. x_ += w_ / 2;
  73516. if ((xMode_ & proportionOfParentSize) != 0)
  73517. {
  73518. if (parentSize > 0)
  73519. xOut = (x_ - parentPos) / parentSize;
  73520. }
  73521. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73522. xOut = (parentPos + parentSize) - x_;
  73523. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73524. xOut = x_ - (parentPos + parentSize / 2);
  73525. else
  73526. xOut = x_ - parentPos;
  73527. }
  73528. END_JUCE_NAMESPACE
  73529. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73530. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73531. BEGIN_JUCE_NAMESPACE
  73532. RectangleList::RectangleList() throw()
  73533. {
  73534. }
  73535. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73536. {
  73537. if (! rect.isEmpty())
  73538. rects.add (rect);
  73539. }
  73540. RectangleList::RectangleList (const RectangleList& other) throw()
  73541. : rects (other.rects)
  73542. {
  73543. }
  73544. const RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73545. {
  73546. rects = other.rects;
  73547. return *this;
  73548. }
  73549. RectangleList::~RectangleList() throw()
  73550. {
  73551. }
  73552. void RectangleList::clear() throw()
  73553. {
  73554. rects.clearQuick();
  73555. }
  73556. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73557. {
  73558. if (((unsigned int) index) < (unsigned int) rects.size())
  73559. return rects.getReference (index);
  73560. return Rectangle<int>();
  73561. }
  73562. bool RectangleList::isEmpty() const throw()
  73563. {
  73564. return rects.size() == 0;
  73565. }
  73566. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73567. : current (0),
  73568. owner (list),
  73569. index (list.rects.size())
  73570. {
  73571. }
  73572. RectangleList::Iterator::~Iterator() throw()
  73573. {
  73574. }
  73575. bool RectangleList::Iterator::next() throw()
  73576. {
  73577. if (--index >= 0)
  73578. {
  73579. current = & (owner.rects.getReference (index));
  73580. return true;
  73581. }
  73582. return false;
  73583. }
  73584. void RectangleList::add (const Rectangle<int>& rect) throw()
  73585. {
  73586. if (! rect.isEmpty())
  73587. {
  73588. if (rects.size() == 0)
  73589. {
  73590. rects.add (rect);
  73591. }
  73592. else
  73593. {
  73594. bool anyOverlaps = false;
  73595. int i;
  73596. for (i = rects.size(); --i >= 0;)
  73597. {
  73598. Rectangle<int>& ourRect = rects.getReference (i);
  73599. if (rect.intersects (ourRect))
  73600. {
  73601. if (rect.contains (ourRect))
  73602. rects.remove (i);
  73603. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73604. anyOverlaps = true;
  73605. }
  73606. }
  73607. if (anyOverlaps && rects.size() > 0)
  73608. {
  73609. RectangleList r (rect);
  73610. for (i = rects.size(); --i >= 0;)
  73611. {
  73612. const Rectangle<int>& ourRect = rects.getReference (i);
  73613. if (rect.intersects (ourRect))
  73614. {
  73615. r.subtract (ourRect);
  73616. if (r.rects.size() == 0)
  73617. return;
  73618. }
  73619. }
  73620. for (i = r.getNumRectangles(); --i >= 0;)
  73621. rects.add (r.rects.getReference (i));
  73622. }
  73623. else
  73624. {
  73625. rects.add (rect);
  73626. }
  73627. }
  73628. }
  73629. }
  73630. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73631. {
  73632. rects.add (rect);
  73633. }
  73634. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73635. {
  73636. if (rects.size() == 0)
  73637. {
  73638. if (w > 0 && h > 0)
  73639. rects.add (Rectangle<int> (x, y, w, h));
  73640. }
  73641. else
  73642. {
  73643. add (Rectangle<int> (x, y, w, h));
  73644. }
  73645. }
  73646. void RectangleList::add (const RectangleList& other) throw()
  73647. {
  73648. for (int i = 0; i < other.rects.size(); ++i)
  73649. add (other.rects.getReference (i));
  73650. }
  73651. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73652. {
  73653. const int originalNumRects = rects.size();
  73654. if (originalNumRects > 0)
  73655. {
  73656. const int x1 = rect.x;
  73657. const int y1 = rect.y;
  73658. const int x2 = x1 + rect.w;
  73659. const int y2 = y1 + rect.h;
  73660. for (int i = getNumRectangles(); --i >= 0;)
  73661. {
  73662. Rectangle<int>& r = rects.getReference (i);
  73663. const int rx1 = r.x;
  73664. const int ry1 = r.y;
  73665. const int rx2 = rx1 + r.w;
  73666. const int ry2 = ry1 + r.h;
  73667. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73668. {
  73669. if (x1 > rx1 && x1 < rx2)
  73670. {
  73671. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73672. {
  73673. r.w = x1 - rx1;
  73674. }
  73675. else
  73676. {
  73677. r.x = x1;
  73678. r.w = rx2 - x1;
  73679. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73680. i += 2;
  73681. }
  73682. }
  73683. else if (x2 > rx1 && x2 < rx2)
  73684. {
  73685. r.x = x2;
  73686. r.w = rx2 - x2;
  73687. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73688. {
  73689. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73690. i += 2;
  73691. }
  73692. }
  73693. else if (y1 > ry1 && y1 < ry2)
  73694. {
  73695. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73696. {
  73697. r.h = y1 - ry1;
  73698. }
  73699. else
  73700. {
  73701. r.y = y1;
  73702. r.h = ry2 - y1;
  73703. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73704. i += 2;
  73705. }
  73706. }
  73707. else if (y2 > ry1 && y2 < ry2)
  73708. {
  73709. r.y = y2;
  73710. r.h = ry2 - y2;
  73711. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73712. {
  73713. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73714. i += 2;
  73715. }
  73716. }
  73717. else
  73718. {
  73719. rects.remove (i);
  73720. }
  73721. }
  73722. }
  73723. if (rects.size() > originalNumRects + 10)
  73724. consolidate();
  73725. }
  73726. }
  73727. void RectangleList::subtract (const RectangleList& otherList) throw()
  73728. {
  73729. for (int i = otherList.rects.size(); --i >= 0;)
  73730. subtract (otherList.rects.getReference (i));
  73731. }
  73732. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73733. {
  73734. bool notEmpty = false;
  73735. if (rect.isEmpty())
  73736. {
  73737. clear();
  73738. }
  73739. else
  73740. {
  73741. for (int i = rects.size(); --i >= 0;)
  73742. {
  73743. Rectangle<int>& r = rects.getReference (i);
  73744. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73745. rects.remove (i);
  73746. else
  73747. notEmpty = true;
  73748. }
  73749. }
  73750. return notEmpty;
  73751. }
  73752. bool RectangleList::clipTo (const RectangleList& other) throw()
  73753. {
  73754. if (rects.size() == 0)
  73755. return false;
  73756. RectangleList result;
  73757. for (int j = 0; j < rects.size(); ++j)
  73758. {
  73759. const Rectangle<int>& rect = rects.getReference (j);
  73760. for (int i = other.rects.size(); --i >= 0;)
  73761. {
  73762. Rectangle<int> r (other.rects.getReference (i));
  73763. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73764. result.rects.add (r);
  73765. }
  73766. }
  73767. swapWith (result);
  73768. return ! isEmpty();
  73769. }
  73770. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73771. {
  73772. destRegion.clear();
  73773. if (! rect.isEmpty())
  73774. {
  73775. for (int i = rects.size(); --i >= 0;)
  73776. {
  73777. Rectangle<int> r (rects.getReference (i));
  73778. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73779. destRegion.rects.add (r);
  73780. }
  73781. }
  73782. return destRegion.rects.size() > 0;
  73783. }
  73784. void RectangleList::swapWith (RectangleList& otherList) throw()
  73785. {
  73786. rects.swapWithArray (otherList.rects);
  73787. }
  73788. void RectangleList::consolidate() throw()
  73789. {
  73790. int i;
  73791. for (i = 0; i < getNumRectangles() - 1; ++i)
  73792. {
  73793. Rectangle<int>& r = rects.getReference (i);
  73794. const int rx1 = r.x;
  73795. const int ry1 = r.y;
  73796. const int rx2 = rx1 + r.w;
  73797. const int ry2 = ry1 + r.h;
  73798. for (int j = rects.size(); --j > i;)
  73799. {
  73800. Rectangle<int>& r2 = rects.getReference (j);
  73801. const int jrx1 = r2.x;
  73802. const int jry1 = r2.y;
  73803. const int jrx2 = jrx1 + r2.w;
  73804. const int jry2 = jry1 + r2.h;
  73805. // if the vertical edges of any blocks are touching and their horizontals don't
  73806. // line up, split them horizontally..
  73807. if (jrx1 == rx2 || jrx2 == rx1)
  73808. {
  73809. if (jry1 > ry1 && jry1 < ry2)
  73810. {
  73811. r.h = jry1 - ry1;
  73812. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73813. i = -1;
  73814. break;
  73815. }
  73816. if (jry2 > ry1 && jry2 < ry2)
  73817. {
  73818. r.h = jry2 - ry1;
  73819. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73820. i = -1;
  73821. break;
  73822. }
  73823. else if (ry1 > jry1 && ry1 < jry2)
  73824. {
  73825. r2.h = ry1 - jry1;
  73826. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73827. i = -1;
  73828. break;
  73829. }
  73830. else if (ry2 > jry1 && ry2 < jry2)
  73831. {
  73832. r2.h = ry2 - jry1;
  73833. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73834. i = -1;
  73835. break;
  73836. }
  73837. }
  73838. }
  73839. }
  73840. for (i = 0; i < rects.size() - 1; ++i)
  73841. {
  73842. Rectangle<int>& r = rects.getReference (i);
  73843. for (int j = rects.size(); --j > i;)
  73844. {
  73845. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73846. {
  73847. rects.remove (j);
  73848. i = -1;
  73849. break;
  73850. }
  73851. }
  73852. }
  73853. }
  73854. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73855. {
  73856. for (int i = getNumRectangles(); --i >= 0;)
  73857. if (rects.getReference (i).contains (x, y))
  73858. return true;
  73859. return false;
  73860. }
  73861. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73862. {
  73863. if (rects.size() > 1)
  73864. {
  73865. RectangleList r (rectangleToCheck);
  73866. for (int i = rects.size(); --i >= 0;)
  73867. {
  73868. r.subtract (rects.getReference (i));
  73869. if (r.rects.size() == 0)
  73870. return true;
  73871. }
  73872. }
  73873. else if (rects.size() > 0)
  73874. {
  73875. return rects.getReference (0).contains (rectangleToCheck);
  73876. }
  73877. return false;
  73878. }
  73879. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73880. {
  73881. for (int i = rects.size(); --i >= 0;)
  73882. if (rects.getReference (i).intersects (rectangleToCheck))
  73883. return true;
  73884. return false;
  73885. }
  73886. bool RectangleList::intersects (const RectangleList& other) const throw()
  73887. {
  73888. for (int i = rects.size(); --i >= 0;)
  73889. if (other.intersectsRectangle (rects.getReference (i)))
  73890. return true;
  73891. return false;
  73892. }
  73893. const Rectangle<int> RectangleList::getBounds() const throw()
  73894. {
  73895. if (rects.size() <= 1)
  73896. {
  73897. if (rects.size() == 0)
  73898. return Rectangle<int>();
  73899. else
  73900. return rects.getReference (0);
  73901. }
  73902. else
  73903. {
  73904. const Rectangle<int>& r = rects.getReference (0);
  73905. int minX = r.x;
  73906. int minY = r.y;
  73907. int maxX = minX + r.w;
  73908. int maxY = minY + r.h;
  73909. for (int i = rects.size(); --i > 0;)
  73910. {
  73911. const Rectangle<int>& r2 = rects.getReference (i);
  73912. minX = jmin (minX, r2.x);
  73913. minY = jmin (minY, r2.y);
  73914. maxX = jmax (maxX, r2.getRight());
  73915. maxY = jmax (maxY, r2.getBottom());
  73916. }
  73917. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73918. }
  73919. }
  73920. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73921. {
  73922. for (int i = rects.size(); --i >= 0;)
  73923. {
  73924. Rectangle<int>& r = rects.getReference (i);
  73925. r.x += dx;
  73926. r.y += dy;
  73927. }
  73928. }
  73929. const Path RectangleList::toPath() const throw()
  73930. {
  73931. Path p;
  73932. for (int i = rects.size(); --i >= 0;)
  73933. {
  73934. const Rectangle<int>& r = rects.getReference (i);
  73935. p.addRectangle ((float) r.x,
  73936. (float) r.y,
  73937. (float) r.w,
  73938. (float) r.h);
  73939. }
  73940. return p;
  73941. }
  73942. END_JUCE_NAMESPACE
  73943. /*** End of inlined file: juce_RectangleList.cpp ***/
  73944. /*** Start of inlined file: juce_Image.cpp ***/
  73945. BEGIN_JUCE_NAMESPACE
  73946. static const int fullAlphaThreshold = 253;
  73947. Image::Image (const PixelFormat format_,
  73948. const int imageWidth_,
  73949. const int imageHeight_)
  73950. : format (format_),
  73951. imageWidth (imageWidth_),
  73952. imageHeight (imageHeight_),
  73953. imageData (0)
  73954. {
  73955. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73956. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73957. // actual image will be at least 1x1.
  73958. }
  73959. Image::Image (const PixelFormat format_,
  73960. const int imageWidth_,
  73961. const int imageHeight_,
  73962. const bool clearImage)
  73963. : format (format_),
  73964. imageWidth (imageWidth_),
  73965. imageHeight (imageHeight_)
  73966. {
  73967. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73968. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73969. // actual image will be at least 1x1.
  73970. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73971. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73972. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73973. imageData = imageDataAllocated;
  73974. }
  73975. Image::Image (const Image& other)
  73976. : format (other.format),
  73977. imageWidth (other.imageWidth),
  73978. imageHeight (other.imageHeight)
  73979. {
  73980. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73981. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73982. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73983. imageData = imageDataAllocated;
  73984. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73985. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73986. }
  73987. Image::~Image()
  73988. {
  73989. }
  73990. LowLevelGraphicsContext* Image::createLowLevelContext()
  73991. {
  73992. return new LowLevelGraphicsSoftwareRenderer (*this);
  73993. }
  73994. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73995. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73996. lineStride (image.lineStride),
  73997. pixelStride (image.pixelStride),
  73998. width (w),
  73999. height (h)
  74000. {
  74001. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74002. }
  74003. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  74004. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74005. lineStride (image.lineStride),
  74006. pixelStride (image.pixelStride),
  74007. width (w),
  74008. height (h)
  74009. {
  74010. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74011. }
  74012. Image::BitmapData::~BitmapData()
  74013. {
  74014. }
  74015. void Image::setPixelData (int x, int y, int w, int h,
  74016. const uint8* sourcePixelData, int sourceLineStride)
  74017. {
  74018. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  74019. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  74020. {
  74021. const BitmapData dest (*this, x, y, w, h, true);
  74022. for (int i = 0; i < h; ++i)
  74023. {
  74024. memcpy (dest.getLinePointer(i),
  74025. sourcePixelData + sourceLineStride * i,
  74026. w * dest.pixelStride);
  74027. }
  74028. }
  74029. }
  74030. void Image::clear (int dx, int dy, int dw, int dh,
  74031. const Colour& colourToClearTo)
  74032. {
  74033. const PixelARGB col (colourToClearTo.getPixelARGB());
  74034. const BitmapData destData (*this, dx, dy, dw, dh, true);
  74035. uint8* dest = destData.data;
  74036. while (--dh >= 0)
  74037. {
  74038. uint8* line = dest;
  74039. dest += destData.lineStride;
  74040. if (isARGB())
  74041. {
  74042. for (int x = dw; --x >= 0;)
  74043. {
  74044. ((PixelARGB*) line)->set (col);
  74045. line += destData.pixelStride;
  74046. }
  74047. }
  74048. else if (isRGB())
  74049. {
  74050. for (int x = dw; --x >= 0;)
  74051. {
  74052. ((PixelRGB*) line)->set (col);
  74053. line += destData.pixelStride;
  74054. }
  74055. }
  74056. else
  74057. {
  74058. for (int x = dw; --x >= 0;)
  74059. {
  74060. *line = col.getAlpha();
  74061. line += destData.pixelStride;
  74062. }
  74063. }
  74064. }
  74065. }
  74066. Image* Image::createCopy (int newWidth, int newHeight,
  74067. const Graphics::ResamplingQuality quality) const
  74068. {
  74069. if (newWidth < 0)
  74070. newWidth = imageWidth;
  74071. if (newHeight < 0)
  74072. newHeight = imageHeight;
  74073. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  74074. Graphics g (*newImage);
  74075. g.setImageResamplingQuality (quality);
  74076. g.drawImage (this,
  74077. 0, 0, newWidth, newHeight,
  74078. 0, 0, imageWidth, imageHeight,
  74079. false);
  74080. return newImage;
  74081. }
  74082. Image* Image::createCopyOfAlphaChannel() const
  74083. {
  74084. jassert (format != SingleChannel);
  74085. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  74086. if (! hasAlphaChannel())
  74087. {
  74088. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  74089. }
  74090. else
  74091. {
  74092. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  74093. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  74094. for (int y = 0; y < imageHeight; ++y)
  74095. {
  74096. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74097. uint8* dst = destData.getLinePointer (y);
  74098. for (int x = imageWidth; --x >= 0;)
  74099. {
  74100. *dst++ = src->getAlpha();
  74101. ++src;
  74102. }
  74103. }
  74104. }
  74105. return newImage;
  74106. }
  74107. const Colour Image::getPixelAt (const int x, const int y) const
  74108. {
  74109. Colour c;
  74110. if (((unsigned int) x) < (unsigned int) imageWidth
  74111. && ((unsigned int) y) < (unsigned int) imageHeight)
  74112. {
  74113. const BitmapData srcData (*this, x, y, 1, 1);
  74114. if (isARGB())
  74115. {
  74116. PixelARGB p (*(const PixelARGB*) srcData.data);
  74117. p.unpremultiply();
  74118. c = Colour (p.getARGB());
  74119. }
  74120. else if (isRGB())
  74121. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74122. else
  74123. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74124. }
  74125. return c;
  74126. }
  74127. void Image::setPixelAt (const int x, const int y,
  74128. const Colour& colour)
  74129. {
  74130. if (((unsigned int) x) < (unsigned int) imageWidth
  74131. && ((unsigned int) y) < (unsigned int) imageHeight)
  74132. {
  74133. const BitmapData destData (*this, x, y, 1, 1, true);
  74134. const PixelARGB col (colour.getPixelARGB());
  74135. if (isARGB())
  74136. ((PixelARGB*) destData.data)->set (col);
  74137. else if (isRGB())
  74138. ((PixelRGB*) destData.data)->set (col);
  74139. else
  74140. *(destData.data) = col.getAlpha();
  74141. }
  74142. }
  74143. void Image::multiplyAlphaAt (const int x, const int y,
  74144. const float multiplier)
  74145. {
  74146. if (((unsigned int) x) < (unsigned int) imageWidth
  74147. && ((unsigned int) y) < (unsigned int) imageHeight
  74148. && hasAlphaChannel())
  74149. {
  74150. const BitmapData destData (*this, x, y, 1, 1, true);
  74151. if (isARGB())
  74152. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74153. else
  74154. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74155. }
  74156. }
  74157. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74158. {
  74159. if (hasAlphaChannel())
  74160. {
  74161. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74162. if (isARGB())
  74163. {
  74164. for (int y = 0; y < imageHeight; ++y)
  74165. {
  74166. uint8* p = destData.getLinePointer (y);
  74167. for (int x = 0; x < imageWidth; ++x)
  74168. {
  74169. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74170. p += destData.pixelStride;
  74171. }
  74172. }
  74173. }
  74174. else
  74175. {
  74176. for (int y = 0; y < imageHeight; ++y)
  74177. {
  74178. uint8* p = destData.getLinePointer (y);
  74179. for (int x = 0; x < imageWidth; ++x)
  74180. {
  74181. *p = (uint8) (*p * amountToMultiplyBy);
  74182. p += destData.pixelStride;
  74183. }
  74184. }
  74185. }
  74186. }
  74187. else
  74188. {
  74189. jassertfalse // can't do this without an alpha-channel!
  74190. }
  74191. }
  74192. void Image::desaturate()
  74193. {
  74194. if (isARGB() || isRGB())
  74195. {
  74196. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74197. if (isARGB())
  74198. {
  74199. for (int y = 0; y < imageHeight; ++y)
  74200. {
  74201. uint8* p = destData.getLinePointer (y);
  74202. for (int x = 0; x < imageWidth; ++x)
  74203. {
  74204. ((PixelARGB*) p)->desaturate();
  74205. p += destData.pixelStride;
  74206. }
  74207. }
  74208. }
  74209. else
  74210. {
  74211. for (int y = 0; y < imageHeight; ++y)
  74212. {
  74213. uint8* p = destData.getLinePointer (y);
  74214. for (int x = 0; x < imageWidth; ++x)
  74215. {
  74216. ((PixelRGB*) p)->desaturate();
  74217. p += destData.pixelStride;
  74218. }
  74219. }
  74220. }
  74221. }
  74222. }
  74223. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74224. {
  74225. if (hasAlphaChannel())
  74226. {
  74227. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74228. SparseSet <int> pixelsOnRow;
  74229. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74230. for (int y = 0; y < imageHeight; ++y)
  74231. {
  74232. pixelsOnRow.clear();
  74233. const uint8* lineData = srcData.getLinePointer (y);
  74234. if (isARGB())
  74235. {
  74236. for (int x = 0; x < imageWidth; ++x)
  74237. {
  74238. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74239. pixelsOnRow.addRange (x, 1);
  74240. lineData += srcData.pixelStride;
  74241. }
  74242. }
  74243. else
  74244. {
  74245. for (int x = 0; x < imageWidth; ++x)
  74246. {
  74247. if (*lineData >= threshold)
  74248. pixelsOnRow.addRange (x, 1);
  74249. lineData += srcData.pixelStride;
  74250. }
  74251. }
  74252. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74253. {
  74254. int x, w;
  74255. if (pixelsOnRow.getRange (i, x, w))
  74256. result.add (Rectangle<int> (x, y, w, 1));
  74257. }
  74258. result.consolidate();
  74259. }
  74260. }
  74261. else
  74262. {
  74263. result.add (0, 0, imageWidth, imageHeight);
  74264. }
  74265. }
  74266. void Image::moveImageSection (int dx, int dy,
  74267. int sx, int sy,
  74268. int w, int h)
  74269. {
  74270. if (dx < 0)
  74271. {
  74272. w += dx;
  74273. sx -= dx;
  74274. dx = 0;
  74275. }
  74276. if (dy < 0)
  74277. {
  74278. h += dy;
  74279. sy -= dy;
  74280. dy = 0;
  74281. }
  74282. if (sx < 0)
  74283. {
  74284. w += sx;
  74285. dx -= sx;
  74286. sx = 0;
  74287. }
  74288. if (sy < 0)
  74289. {
  74290. h += sy;
  74291. dy -= sy;
  74292. sy = 0;
  74293. }
  74294. const int minX = jmin (dx, sx);
  74295. const int minY = jmin (dy, sy);
  74296. w = jmin (w, getWidth() - jmax (sx, dx));
  74297. h = jmin (h, getHeight() - jmax (sy, dy));
  74298. if (w > 0 && h > 0)
  74299. {
  74300. const int maxX = jmax (dx, sx) + w;
  74301. const int maxY = jmax (dy, sy) + h;
  74302. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74303. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74304. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74305. const int lineSize = destData.pixelStride * w;
  74306. if (dy > sy)
  74307. {
  74308. while (--h >= 0)
  74309. {
  74310. const int offset = h * destData.lineStride;
  74311. memmove (dst + offset, src + offset, lineSize);
  74312. }
  74313. }
  74314. else if (dst != src)
  74315. {
  74316. while (--h >= 0)
  74317. {
  74318. memmove (dst, src, lineSize);
  74319. dst += destData.lineStride;
  74320. src += destData.lineStride;
  74321. }
  74322. }
  74323. }
  74324. }
  74325. END_JUCE_NAMESPACE
  74326. /*** End of inlined file: juce_Image.cpp ***/
  74327. /*** Start of inlined file: juce_ImageCache.cpp ***/
  74328. BEGIN_JUCE_NAMESPACE
  74329. struct ImageCacheItem
  74330. {
  74331. ScopedPointer <Image> image;
  74332. int64 hashCode;
  74333. int refCount;
  74334. uint32 releaseTime;
  74335. juce_UseDebuggingNewOperator
  74336. };
  74337. static ImageCache* instance = 0;
  74338. static int cacheTimeout = 5000;
  74339. ImageCache::ImageCache()
  74340. {
  74341. }
  74342. ImageCache::~ImageCache()
  74343. {
  74344. jassert (instance == this);
  74345. instance = 0;
  74346. }
  74347. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74348. {
  74349. if (instance != 0)
  74350. {
  74351. const ScopedLock sl (instance->lock);
  74352. for (int i = instance->images.size(); --i >= 0;)
  74353. {
  74354. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74355. if (ci->hashCode == hashCode)
  74356. {
  74357. ci->refCount++;
  74358. return ci->image;
  74359. }
  74360. }
  74361. }
  74362. return 0;
  74363. }
  74364. void ImageCache::addImageToCache (Image* const image,
  74365. const int64 hashCode)
  74366. {
  74367. if (image != 0)
  74368. {
  74369. if (instance == 0)
  74370. instance = new ImageCache();
  74371. ImageCacheItem* const newC = new ImageCacheItem();
  74372. newC->hashCode = hashCode;
  74373. newC->image = image;
  74374. newC->refCount = 1;
  74375. newC->releaseTime = 0;
  74376. const ScopedLock sl (instance->lock);
  74377. instance->images.add (newC);
  74378. }
  74379. }
  74380. void ImageCache::release (Image* const imageToRelease)
  74381. {
  74382. if (imageToRelease != 0 && instance != 0)
  74383. {
  74384. const ScopedLock sl (instance->lock);
  74385. for (int i = instance->images.size(); --i >= 0;)
  74386. {
  74387. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74388. if ((Image*) ci->image == imageToRelease)
  74389. {
  74390. if (--(ci->refCount) == 0)
  74391. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74392. if (! instance->isTimerRunning())
  74393. instance->startTimer (999);
  74394. break;
  74395. }
  74396. }
  74397. }
  74398. }
  74399. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74400. {
  74401. if (isImageInCache (imageToRelease))
  74402. release (imageToRelease);
  74403. else
  74404. delete imageToRelease;
  74405. }
  74406. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74407. {
  74408. if (instance != 0)
  74409. {
  74410. const ScopedLock sl (instance->lock);
  74411. for (int i = instance->images.size(); --i >= 0;)
  74412. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74413. return true;
  74414. }
  74415. return false;
  74416. }
  74417. void ImageCache::incReferenceCount (Image* const image)
  74418. {
  74419. if (instance != 0)
  74420. {
  74421. const ScopedLock sl (instance->lock);
  74422. for (int i = instance->images.size(); --i >= 0;)
  74423. {
  74424. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74425. if ((Image*) ci->image == image)
  74426. {
  74427. ci->refCount++;
  74428. return;
  74429. }
  74430. }
  74431. }
  74432. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74433. }
  74434. void ImageCache::timerCallback()
  74435. {
  74436. int numberStillNeedingReleasing = 0;
  74437. const unsigned int now = Time::getApproximateMillisecondCounter();
  74438. const ScopedLock sl (lock);
  74439. for (int i = images.size(); --i >= 0;)
  74440. {
  74441. ImageCacheItem* const ci = images.getUnchecked(i);
  74442. if (ci->refCount <= 0)
  74443. {
  74444. if (now > ci->releaseTime + cacheTimeout
  74445. || now < ci->releaseTime - 1000)
  74446. {
  74447. images.remove (i);
  74448. }
  74449. else
  74450. {
  74451. ++numberStillNeedingReleasing;
  74452. }
  74453. }
  74454. }
  74455. if (numberStillNeedingReleasing == 0)
  74456. stopTimer();
  74457. }
  74458. Image* ImageCache::getFromFile (const File& file)
  74459. {
  74460. const int64 hashCode = file.hashCode64();
  74461. Image* image = getFromHashCode (hashCode);
  74462. if (image == 0)
  74463. {
  74464. image = ImageFileFormat::loadFrom (file);
  74465. addImageToCache (image, hashCode);
  74466. }
  74467. return image;
  74468. }
  74469. Image* ImageCache::getFromMemory (const void* imageData,
  74470. const int dataSize)
  74471. {
  74472. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74473. Image* image = getFromHashCode (hashCode);
  74474. if (image == 0)
  74475. {
  74476. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74477. addImageToCache (image, hashCode);
  74478. }
  74479. return image;
  74480. }
  74481. void ImageCache::setCacheTimeout (const int millisecs)
  74482. {
  74483. cacheTimeout = millisecs;
  74484. }
  74485. END_JUCE_NAMESPACE
  74486. /*** End of inlined file: juce_ImageCache.cpp ***/
  74487. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74488. BEGIN_JUCE_NAMESPACE
  74489. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74490. : values (size_ * size_),
  74491. size (size_)
  74492. {
  74493. clear();
  74494. }
  74495. ImageConvolutionKernel::~ImageConvolutionKernel()
  74496. {
  74497. }
  74498. void ImageConvolutionKernel::setKernelValue (const int x,
  74499. const int y,
  74500. const float value)
  74501. {
  74502. if (((unsigned int) x) < (unsigned int) size
  74503. && ((unsigned int) y) < (unsigned int) size)
  74504. {
  74505. values [x + y * size] = value;
  74506. }
  74507. else
  74508. {
  74509. jassertfalse
  74510. }
  74511. }
  74512. void ImageConvolutionKernel::clear()
  74513. {
  74514. for (int i = size * size; --i >= 0;)
  74515. values[i] = 0;
  74516. }
  74517. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74518. {
  74519. double currentTotal = 0.0;
  74520. for (int i = size * size; --i >= 0;)
  74521. currentTotal += values[i];
  74522. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74523. }
  74524. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74525. {
  74526. for (int i = size * size; --i >= 0;)
  74527. values[i] *= multiplier;
  74528. }
  74529. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74530. {
  74531. const double radiusFactor = -1.0 / (radius * radius * 2);
  74532. const int centre = size >> 1;
  74533. for (int y = size; --y >= 0;)
  74534. {
  74535. for (int x = size; --x >= 0;)
  74536. {
  74537. const int cx = x - centre;
  74538. const int cy = y - centre;
  74539. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74540. }
  74541. }
  74542. setOverallSum (1.0f);
  74543. }
  74544. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74545. const Image* sourceImage,
  74546. int dx,
  74547. int dy,
  74548. int dw,
  74549. int dh) const
  74550. {
  74551. ScopedPointer <Image> imageCreated;
  74552. if (sourceImage == 0)
  74553. {
  74554. sourceImage = imageCreated = destImage.createCopy();
  74555. }
  74556. else
  74557. {
  74558. jassert (sourceImage->getWidth() == destImage.getWidth()
  74559. && sourceImage->getHeight() == destImage.getHeight()
  74560. && sourceImage->getFormat() == destImage.getFormat());
  74561. if (sourceImage->getWidth() != destImage.getWidth()
  74562. || sourceImage->getHeight() != destImage.getHeight()
  74563. || sourceImage->getFormat() != destImage.getFormat())
  74564. return;
  74565. }
  74566. const int imageWidth = destImage.getWidth();
  74567. const int imageHeight = destImage.getHeight();
  74568. if (dx >= imageWidth || dy >= imageHeight)
  74569. return;
  74570. if (dx + dw > imageWidth)
  74571. dw = imageWidth - dx;
  74572. if (dy + dh > imageHeight)
  74573. dh = imageHeight - dy;
  74574. const int dx2 = dx + dw;
  74575. const int dy2 = dy + dh;
  74576. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74577. uint8* line = destData.data;
  74578. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74579. if (destData.pixelStride == 4)
  74580. {
  74581. for (int y = dy; y < dy2; ++y)
  74582. {
  74583. uint8* dest = line;
  74584. line += destData.lineStride;
  74585. for (int x = dx; x < dx2; ++x)
  74586. {
  74587. float c1 = 0;
  74588. float c2 = 0;
  74589. float c3 = 0;
  74590. float c4 = 0;
  74591. for (int yy = 0; yy < size; ++yy)
  74592. {
  74593. const int sy = y + yy - (size >> 1);
  74594. if (sy >= imageHeight)
  74595. break;
  74596. if (sy >= 0)
  74597. {
  74598. int sx = x - (size >> 1);
  74599. const uint8* src = srcData.getPixelPointer (sx, sy);
  74600. for (int xx = 0; xx < size; ++xx)
  74601. {
  74602. if (sx >= imageWidth)
  74603. break;
  74604. if (sx >= 0)
  74605. {
  74606. const float kernelMult = values [xx + yy * size];
  74607. c1 += kernelMult * *src++;
  74608. c2 += kernelMult * *src++;
  74609. c3 += kernelMult * *src++;
  74610. c4 += kernelMult * *src++;
  74611. }
  74612. else
  74613. {
  74614. src += 4;
  74615. }
  74616. ++sx;
  74617. }
  74618. }
  74619. }
  74620. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74621. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74622. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74623. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74624. }
  74625. }
  74626. }
  74627. else if (destData.pixelStride == 3)
  74628. {
  74629. for (int y = dy; y < dy2; ++y)
  74630. {
  74631. uint8* dest = line;
  74632. line += destData.lineStride;
  74633. for (int x = dx; x < dx2; ++x)
  74634. {
  74635. float c1 = 0;
  74636. float c2 = 0;
  74637. float c3 = 0;
  74638. for (int yy = 0; yy < size; ++yy)
  74639. {
  74640. const int sy = y + yy - (size >> 1);
  74641. if (sy >= imageHeight)
  74642. break;
  74643. if (sy >= 0)
  74644. {
  74645. int sx = x - (size >> 1);
  74646. const uint8* src = srcData.getPixelPointer (sx, sy);
  74647. for (int xx = 0; xx < size; ++xx)
  74648. {
  74649. if (sx >= imageWidth)
  74650. break;
  74651. if (sx >= 0)
  74652. {
  74653. const float kernelMult = values [xx + yy * size];
  74654. c1 += kernelMult * *src++;
  74655. c2 += kernelMult * *src++;
  74656. c3 += kernelMult * *src++;
  74657. }
  74658. else
  74659. {
  74660. src += 3;
  74661. }
  74662. ++sx;
  74663. }
  74664. }
  74665. }
  74666. *dest++ = (uint8) roundToInt (c1);
  74667. *dest++ = (uint8) roundToInt (c2);
  74668. *dest++ = (uint8) roundToInt (c3);
  74669. }
  74670. }
  74671. }
  74672. }
  74673. END_JUCE_NAMESPACE
  74674. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74675. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74676. BEGIN_JUCE_NAMESPACE
  74677. /*** Start of inlined file: juce_GIFLoader.h ***/
  74678. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74679. #define __JUCE_GIFLOADER_JUCEHEADER__
  74680. #ifndef DOXYGEN
  74681. class GIFLoader
  74682. {
  74683. public:
  74684. GIFLoader (InputStream& in);
  74685. ~GIFLoader();
  74686. Image* getImage() const { return image; }
  74687. private:
  74688. Image* image;
  74689. InputStream& input;
  74690. uint8 buffer [300];
  74691. uint8 palette [256][4];
  74692. bool dataBlockIsZero, fresh, finished;
  74693. int currentBit, lastBit, lastByteIndex;
  74694. int codeSize, setCodeSize;
  74695. int maxCode, maxCodeSize;
  74696. int firstcode, oldcode;
  74697. int clearCode, end_code;
  74698. enum { maxGifCode = 1 << 12 };
  74699. int table [2] [maxGifCode];
  74700. int stack [2 * maxGifCode];
  74701. int *sp;
  74702. bool getSizeFromHeader (int& width, int& height);
  74703. bool readPalette (const int numCols);
  74704. int readDataBlock (unsigned char* dest);
  74705. int processExtension (int type, int& transparent);
  74706. int readLZWByte (bool initialise, int input_code_size);
  74707. int getCode (int code_size, bool initialise);
  74708. bool readImage (int width, int height, int interlace, int transparent);
  74709. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74710. GIFLoader (const GIFLoader&);
  74711. const GIFLoader& operator= (const GIFLoader&);
  74712. };
  74713. #endif // DOXYGEN
  74714. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74715. /*** End of inlined file: juce_GIFLoader.h ***/
  74716. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74717. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74718. PNGImageFormat::PNGImageFormat() {}
  74719. PNGImageFormat::~PNGImageFormat() {}
  74720. const String PNGImageFormat::getFormatName()
  74721. {
  74722. return T("PNG");
  74723. }
  74724. bool PNGImageFormat::canUnderstand (InputStream& in)
  74725. {
  74726. const int bytesNeeded = 4;
  74727. char header [bytesNeeded];
  74728. return in.read (header, bytesNeeded) == bytesNeeded
  74729. && header[1] == 'P'
  74730. && header[2] == 'N'
  74731. && header[3] == 'G';
  74732. }
  74733. Image* PNGImageFormat::decodeImage (InputStream& in)
  74734. {
  74735. return juce_loadPNGImageFromStream (in);
  74736. }
  74737. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74738. OutputStream& destStream)
  74739. {
  74740. return juce_writePNGImageToStream (sourceImage, destStream);
  74741. }
  74742. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74743. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74744. JPEGImageFormat::JPEGImageFormat()
  74745. : quality (-1.0f)
  74746. {
  74747. }
  74748. JPEGImageFormat::~JPEGImageFormat() {}
  74749. void JPEGImageFormat::setQuality (const float newQuality)
  74750. {
  74751. quality = newQuality;
  74752. }
  74753. const String JPEGImageFormat::getFormatName()
  74754. {
  74755. return T("JPEG");
  74756. }
  74757. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74758. {
  74759. const int bytesNeeded = 10;
  74760. uint8 header [bytesNeeded];
  74761. if (in.read (header, bytesNeeded) == bytesNeeded)
  74762. {
  74763. return header[0] == 0xff
  74764. && header[1] == 0xd8
  74765. && header[2] == 0xff
  74766. && (header[3] == 0xe0 || header[3] == 0xe1);
  74767. }
  74768. return false;
  74769. }
  74770. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74771. {
  74772. return juce_loadJPEGImageFromStream (in);
  74773. }
  74774. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74775. OutputStream& destStream)
  74776. {
  74777. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74778. }
  74779. class GIFImageFormat : public ImageFileFormat
  74780. {
  74781. public:
  74782. GIFImageFormat() {}
  74783. ~GIFImageFormat() {}
  74784. const String getFormatName()
  74785. {
  74786. return T("GIF");
  74787. }
  74788. bool canUnderstand (InputStream& in)
  74789. {
  74790. const int bytesNeeded = 4;
  74791. char header [bytesNeeded];
  74792. return (in.read (header, bytesNeeded) == bytesNeeded)
  74793. && header[0] == 'G'
  74794. && header[1] == 'I'
  74795. && header[2] == 'F';
  74796. }
  74797. Image* decodeImage (InputStream& in)
  74798. {
  74799. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74800. return loader->getImage();
  74801. }
  74802. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74803. {
  74804. return false;
  74805. }
  74806. };
  74807. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74808. {
  74809. static PNGImageFormat png;
  74810. static JPEGImageFormat jpg;
  74811. static GIFImageFormat gif;
  74812. ImageFileFormat* formats[4];
  74813. int numFormats = 0;
  74814. formats [numFormats++] = &png;
  74815. formats [numFormats++] = &jpg;
  74816. formats [numFormats++] = &gif;
  74817. const int64 streamPos = input.getPosition();
  74818. for (int i = 0; i < numFormats; ++i)
  74819. {
  74820. const bool found = formats[i]->canUnderstand (input);
  74821. input.setPosition (streamPos);
  74822. if (found)
  74823. return formats[i];
  74824. }
  74825. return 0;
  74826. }
  74827. Image* ImageFileFormat::loadFrom (InputStream& input)
  74828. {
  74829. ImageFileFormat* const format = findImageFormatForStream (input);
  74830. if (format != 0)
  74831. return format->decodeImage (input);
  74832. return 0;
  74833. }
  74834. Image* ImageFileFormat::loadFrom (const File& file)
  74835. {
  74836. InputStream* const in = file.createInputStream();
  74837. if (in != 0)
  74838. {
  74839. BufferedInputStream b (in, 8192, true);
  74840. return loadFrom (b);
  74841. }
  74842. return 0;
  74843. }
  74844. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74845. {
  74846. if (rawData != 0 && numBytes > 4)
  74847. {
  74848. MemoryInputStream stream (rawData, numBytes, false);
  74849. return loadFrom (stream);
  74850. }
  74851. return 0;
  74852. }
  74853. END_JUCE_NAMESPACE
  74854. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74855. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74856. BEGIN_JUCE_NAMESPACE
  74857. GIFLoader::GIFLoader (InputStream& in)
  74858. : image (0),
  74859. input (in),
  74860. dataBlockIsZero (false),
  74861. fresh (false),
  74862. finished (false)
  74863. {
  74864. currentBit = lastBit = lastByteIndex = 0;
  74865. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74866. firstcode = oldcode = 0;
  74867. clearCode = end_code = 0;
  74868. int imageWidth, imageHeight;
  74869. int transparent = -1;
  74870. if (! getSizeFromHeader (imageWidth, imageHeight))
  74871. return;
  74872. if ((imageWidth <= 0) || (imageHeight <= 0))
  74873. return;
  74874. unsigned char buf [16];
  74875. if (in.read (buf, 3) != 3)
  74876. return;
  74877. int numColours = 2 << (buf[0] & 7);
  74878. if ((buf[0] & 0x80) != 0)
  74879. readPalette (numColours);
  74880. for (;;)
  74881. {
  74882. if (input.read (buf, 1) != 1)
  74883. break;
  74884. if (buf[0] == ';')
  74885. break;
  74886. if (buf[0] == '!')
  74887. {
  74888. if (input.read (buf, 1) != 1)
  74889. break;
  74890. if (processExtension (buf[0], transparent) < 0)
  74891. break;
  74892. continue;
  74893. }
  74894. if (buf[0] != ',')
  74895. continue;
  74896. if (input.read (buf, 9) != 9)
  74897. break;
  74898. imageWidth = makeWord (buf[4], buf[5]);
  74899. imageHeight = makeWord (buf[6], buf[7]);
  74900. numColours = 2 << (buf[8] & 7);
  74901. if ((buf[8] & 0x80) != 0)
  74902. if (! readPalette (numColours))
  74903. break;
  74904. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74905. imageWidth, imageHeight, (transparent >= 0));
  74906. readImage (imageWidth, imageHeight,
  74907. (buf[8] & 0x40) != 0,
  74908. transparent);
  74909. break;
  74910. }
  74911. }
  74912. GIFLoader::~GIFLoader()
  74913. {
  74914. }
  74915. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74916. {
  74917. unsigned char b [8];
  74918. if (input.read (b, 6) == 6)
  74919. {
  74920. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74921. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74922. {
  74923. if (input.read (b, 4) == 4)
  74924. {
  74925. w = makeWord (b[0], b[1]);
  74926. h = makeWord (b[2], b[3]);
  74927. return true;
  74928. }
  74929. }
  74930. }
  74931. return false;
  74932. }
  74933. bool GIFLoader::readPalette (const int numCols)
  74934. {
  74935. unsigned char rgb[4];
  74936. for (int i = 0; i < numCols; ++i)
  74937. {
  74938. input.read (rgb, 3);
  74939. palette [i][0] = rgb[0];
  74940. palette [i][1] = rgb[1];
  74941. palette [i][2] = rgb[2];
  74942. palette [i][3] = 0xff;
  74943. }
  74944. return true;
  74945. }
  74946. int GIFLoader::readDataBlock (unsigned char* const dest)
  74947. {
  74948. unsigned char n;
  74949. if (input.read (&n, 1) == 1)
  74950. {
  74951. dataBlockIsZero = (n == 0);
  74952. if (dataBlockIsZero || (input.read (dest, n) == n))
  74953. return n;
  74954. }
  74955. return -1;
  74956. }
  74957. int GIFLoader::processExtension (const int type, int& transparent)
  74958. {
  74959. unsigned char b [300];
  74960. int n = 0;
  74961. if (type == 0xf9)
  74962. {
  74963. n = readDataBlock (b);
  74964. if (n < 0)
  74965. return 1;
  74966. if ((b[0] & 0x1) != 0)
  74967. transparent = b[3];
  74968. }
  74969. do
  74970. {
  74971. n = readDataBlock (b);
  74972. }
  74973. while (n > 0);
  74974. return n;
  74975. }
  74976. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74977. {
  74978. if (initialise)
  74979. {
  74980. currentBit = 0;
  74981. lastBit = 0;
  74982. finished = false;
  74983. return 0;
  74984. }
  74985. if ((currentBit + codeSize_) >= lastBit)
  74986. {
  74987. if (finished)
  74988. return -1;
  74989. buffer[0] = buffer [lastByteIndex - 2];
  74990. buffer[1] = buffer [lastByteIndex - 1];
  74991. const int n = readDataBlock (&buffer[2]);
  74992. if (n == 0)
  74993. finished = true;
  74994. lastByteIndex = 2 + n;
  74995. currentBit = (currentBit - lastBit) + 16;
  74996. lastBit = (2 + n) * 8 ;
  74997. }
  74998. int result = 0;
  74999. int i = currentBit;
  75000. for (int j = 0; j < codeSize_; ++j)
  75001. {
  75002. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  75003. ++i;
  75004. }
  75005. currentBit += codeSize_;
  75006. return result;
  75007. }
  75008. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  75009. {
  75010. int code, incode, i;
  75011. if (initialise)
  75012. {
  75013. setCodeSize = inputCodeSize;
  75014. codeSize = setCodeSize + 1;
  75015. clearCode = 1 << setCodeSize;
  75016. end_code = clearCode + 1;
  75017. maxCodeSize = 2 * clearCode;
  75018. maxCode = clearCode + 2;
  75019. getCode (0, true);
  75020. fresh = true;
  75021. for (i = 0; i < clearCode; ++i)
  75022. {
  75023. table[0][i] = 0;
  75024. table[1][i] = i;
  75025. }
  75026. for (; i < maxGifCode; ++i)
  75027. {
  75028. table[0][i] = 0;
  75029. table[1][i] = 0;
  75030. }
  75031. sp = stack;
  75032. return 0;
  75033. }
  75034. else if (fresh)
  75035. {
  75036. fresh = false;
  75037. do
  75038. {
  75039. firstcode = oldcode
  75040. = getCode (codeSize, false);
  75041. }
  75042. while (firstcode == clearCode);
  75043. return firstcode;
  75044. }
  75045. if (sp > stack)
  75046. return *--sp;
  75047. while ((code = getCode (codeSize, false)) >= 0)
  75048. {
  75049. if (code == clearCode)
  75050. {
  75051. for (i = 0; i < clearCode; ++i)
  75052. {
  75053. table[0][i] = 0;
  75054. table[1][i] = i;
  75055. }
  75056. for (; i < maxGifCode; ++i)
  75057. {
  75058. table[0][i] = 0;
  75059. table[1][i] = 0;
  75060. }
  75061. codeSize = setCodeSize + 1;
  75062. maxCodeSize = 2 * clearCode;
  75063. maxCode = clearCode + 2;
  75064. sp = stack;
  75065. firstcode = oldcode = getCode (codeSize, false);
  75066. return firstcode;
  75067. }
  75068. else if (code == end_code)
  75069. {
  75070. if (dataBlockIsZero)
  75071. return -2;
  75072. unsigned char buf [260];
  75073. int n;
  75074. while ((n = readDataBlock (buf)) > 0)
  75075. {}
  75076. if (n != 0)
  75077. return -2;
  75078. }
  75079. incode = code;
  75080. if (code >= maxCode)
  75081. {
  75082. *sp++ = firstcode;
  75083. code = oldcode;
  75084. }
  75085. while (code >= clearCode)
  75086. {
  75087. *sp++ = table[1][code];
  75088. if (code == table[0][code])
  75089. return -2;
  75090. code = table[0][code];
  75091. }
  75092. *sp++ = firstcode = table[1][code];
  75093. if ((code = maxCode) < maxGifCode)
  75094. {
  75095. table[0][code] = oldcode;
  75096. table[1][code] = firstcode;
  75097. ++maxCode;
  75098. if ((maxCode >= maxCodeSize)
  75099. && (maxCodeSize < maxGifCode))
  75100. {
  75101. maxCodeSize <<= 1;
  75102. ++codeSize;
  75103. }
  75104. }
  75105. oldcode = incode;
  75106. if (sp > stack)
  75107. return *--sp;
  75108. }
  75109. return code;
  75110. }
  75111. bool GIFLoader::readImage (const int width, const int height,
  75112. const int interlace, const int transparent)
  75113. {
  75114. unsigned char c;
  75115. if (input.read (&c, 1) != 1
  75116. || readLZWByte (true, c) < 0)
  75117. return false;
  75118. if (transparent >= 0)
  75119. {
  75120. palette [transparent][0] = 0;
  75121. palette [transparent][1] = 0;
  75122. palette [transparent][2] = 0;
  75123. palette [transparent][3] = 0;
  75124. }
  75125. int index;
  75126. int xpos = 0, ypos = 0, pass = 0;
  75127. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75128. uint8* p = destData.data;
  75129. const bool hasAlpha = image->hasAlphaChannel();
  75130. while ((index = readLZWByte (false, c)) >= 0)
  75131. {
  75132. const uint8* const paletteEntry = palette [index];
  75133. if (hasAlpha)
  75134. {
  75135. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75136. paletteEntry[0],
  75137. paletteEntry[1],
  75138. paletteEntry[2]);
  75139. ((PixelARGB*) p)->premultiply();
  75140. }
  75141. else
  75142. {
  75143. ((PixelRGB*) p)->setARGB (0,
  75144. paletteEntry[0],
  75145. paletteEntry[1],
  75146. paletteEntry[2]);
  75147. }
  75148. p += destData.pixelStride;
  75149. ++xpos;
  75150. if (xpos == width)
  75151. {
  75152. xpos = 0;
  75153. if (interlace)
  75154. {
  75155. switch (pass)
  75156. {
  75157. case 0:
  75158. case 1:
  75159. ypos += 8;
  75160. break;
  75161. case 2:
  75162. ypos += 4;
  75163. break;
  75164. case 3:
  75165. ypos += 2;
  75166. break;
  75167. }
  75168. while (ypos >= height)
  75169. {
  75170. ++pass;
  75171. switch (pass)
  75172. {
  75173. case 1:
  75174. ypos = 4;
  75175. break;
  75176. case 2:
  75177. ypos = 2;
  75178. break;
  75179. case 3:
  75180. ypos = 1;
  75181. break;
  75182. default:
  75183. return true;
  75184. }
  75185. }
  75186. }
  75187. else
  75188. {
  75189. ++ypos;
  75190. }
  75191. p = destData.getPixelPointer (xpos, ypos);
  75192. }
  75193. if (ypos >= height)
  75194. break;
  75195. }
  75196. return true;
  75197. }
  75198. END_JUCE_NAMESPACE
  75199. /*** End of inlined file: juce_GIFLoader.cpp ***/
  75200. #endif
  75201. //==============================================================================
  75202. // some files include lots of library code, so leave them to the end to avoid cluttering
  75203. // up the build for the clean files.
  75204. #if JUCE_BUILD_CORE
  75205. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75206. namespace zlibNamespace
  75207. {
  75208. #if JUCE_INCLUDE_ZLIB_CODE
  75209. #undef OS_CODE
  75210. #undef fdopen
  75211. /*** Start of inlined file: zlib.h ***/
  75212. #ifndef ZLIB_H
  75213. #define ZLIB_H
  75214. /*** Start of inlined file: zconf.h ***/
  75215. #ifndef ZCONF_H
  75216. #define ZCONF_H
  75217. // *** Just a few hacks here to make it compile nicely with Juce..
  75218. #define Z_PREFIX 1
  75219. #undef __MACTYPES__
  75220. #ifdef _MSC_VER
  75221. #pragma warning (disable : 4131 4127 4244 4267)
  75222. #endif
  75223. #ifdef Z_PREFIX
  75224. # define deflateInit_ z_deflateInit_
  75225. # define deflate z_deflate
  75226. # define deflateEnd z_deflateEnd
  75227. # define inflateInit_ z_inflateInit_
  75228. # define inflate z_inflate
  75229. # define inflateEnd z_inflateEnd
  75230. # define deflateInit2_ z_deflateInit2_
  75231. # define deflateSetDictionary z_deflateSetDictionary
  75232. # define deflateCopy z_deflateCopy
  75233. # define deflateReset z_deflateReset
  75234. # define deflateParams z_deflateParams
  75235. # define deflateBound z_deflateBound
  75236. # define deflatePrime z_deflatePrime
  75237. # define inflateInit2_ z_inflateInit2_
  75238. # define inflateSetDictionary z_inflateSetDictionary
  75239. # define inflateSync z_inflateSync
  75240. # define inflateSyncPoint z_inflateSyncPoint
  75241. # define inflateCopy z_inflateCopy
  75242. # define inflateReset z_inflateReset
  75243. # define inflateBack z_inflateBack
  75244. # define inflateBackEnd z_inflateBackEnd
  75245. # define compress z_compress
  75246. # define compress2 z_compress2
  75247. # define compressBound z_compressBound
  75248. # define uncompress z_uncompress
  75249. # define adler32 z_adler32
  75250. # define crc32 z_crc32
  75251. # define get_crc_table z_get_crc_table
  75252. # define zError z_zError
  75253. # define alloc_func z_alloc_func
  75254. # define free_func z_free_func
  75255. # define in_func z_in_func
  75256. # define out_func z_out_func
  75257. # define Byte z_Byte
  75258. # define uInt z_uInt
  75259. # define uLong z_uLong
  75260. # define Bytef z_Bytef
  75261. # define charf z_charf
  75262. # define intf z_intf
  75263. # define uIntf z_uIntf
  75264. # define uLongf z_uLongf
  75265. # define voidpf z_voidpf
  75266. # define voidp z_voidp
  75267. #endif
  75268. #if defined(__MSDOS__) && !defined(MSDOS)
  75269. # define MSDOS
  75270. #endif
  75271. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75272. # define OS2
  75273. #endif
  75274. #if defined(_WINDOWS) && !defined(WINDOWS)
  75275. # define WINDOWS
  75276. #endif
  75277. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75278. # ifndef WIN32
  75279. # define WIN32
  75280. # endif
  75281. #endif
  75282. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75283. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75284. # ifndef SYS16BIT
  75285. # define SYS16BIT
  75286. # endif
  75287. # endif
  75288. #endif
  75289. #ifdef SYS16BIT
  75290. # define MAXSEG_64K
  75291. #endif
  75292. #ifdef MSDOS
  75293. # define UNALIGNED_OK
  75294. #endif
  75295. #ifdef __STDC_VERSION__
  75296. # ifndef STDC
  75297. # define STDC
  75298. # endif
  75299. # if __STDC_VERSION__ >= 199901L
  75300. # ifndef STDC99
  75301. # define STDC99
  75302. # endif
  75303. # endif
  75304. #endif
  75305. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75306. # define STDC
  75307. #endif
  75308. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75309. # define STDC
  75310. #endif
  75311. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75312. # define STDC
  75313. #endif
  75314. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75315. # define STDC
  75316. #endif
  75317. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75318. # define STDC
  75319. #endif
  75320. #ifndef STDC
  75321. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75322. # define const /* note: need a more gentle solution here */
  75323. # endif
  75324. #endif
  75325. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75326. # define NO_DUMMY_DECL
  75327. #endif
  75328. #ifndef MAX_MEM_LEVEL
  75329. # ifdef MAXSEG_64K
  75330. # define MAX_MEM_LEVEL 8
  75331. # else
  75332. # define MAX_MEM_LEVEL 9
  75333. # endif
  75334. #endif
  75335. #ifndef MAX_WBITS
  75336. # define MAX_WBITS 15 /* 32K LZ77 window */
  75337. #endif
  75338. #ifndef OF /* function prototypes */
  75339. # ifdef STDC
  75340. # define OF(args) args
  75341. # else
  75342. # define OF(args) ()
  75343. # endif
  75344. #endif
  75345. #ifdef SYS16BIT
  75346. # if defined(M_I86SM) || defined(M_I86MM)
  75347. # define SMALL_MEDIUM
  75348. # ifdef _MSC_VER
  75349. # define FAR _far
  75350. # else
  75351. # define FAR far
  75352. # endif
  75353. # endif
  75354. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75355. # define SMALL_MEDIUM
  75356. # ifdef __BORLANDC__
  75357. # define FAR _far
  75358. # else
  75359. # define FAR far
  75360. # endif
  75361. # endif
  75362. #endif
  75363. #if defined(WINDOWS) || defined(WIN32)
  75364. # ifdef ZLIB_DLL
  75365. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75366. # ifdef ZLIB_INTERNAL
  75367. # define ZEXTERN extern __declspec(dllexport)
  75368. # else
  75369. # define ZEXTERN extern __declspec(dllimport)
  75370. # endif
  75371. # endif
  75372. # endif /* ZLIB_DLL */
  75373. # ifdef ZLIB_WINAPI
  75374. # ifdef FAR
  75375. # undef FAR
  75376. # endif
  75377. # include <windows.h>
  75378. # define ZEXPORT WINAPI
  75379. # ifdef WIN32
  75380. # define ZEXPORTVA WINAPIV
  75381. # else
  75382. # define ZEXPORTVA FAR CDECL
  75383. # endif
  75384. # endif
  75385. #endif
  75386. #if defined (__BEOS__)
  75387. # ifdef ZLIB_DLL
  75388. # ifdef ZLIB_INTERNAL
  75389. # define ZEXPORT __declspec(dllexport)
  75390. # define ZEXPORTVA __declspec(dllexport)
  75391. # else
  75392. # define ZEXPORT __declspec(dllimport)
  75393. # define ZEXPORTVA __declspec(dllimport)
  75394. # endif
  75395. # endif
  75396. #endif
  75397. #ifndef ZEXTERN
  75398. # define ZEXTERN extern
  75399. #endif
  75400. #ifndef ZEXPORT
  75401. # define ZEXPORT
  75402. #endif
  75403. #ifndef ZEXPORTVA
  75404. # define ZEXPORTVA
  75405. #endif
  75406. #ifndef FAR
  75407. # define FAR
  75408. #endif
  75409. #if !defined(__MACTYPES__)
  75410. typedef unsigned char Byte; /* 8 bits */
  75411. #endif
  75412. typedef unsigned int uInt; /* 16 bits or more */
  75413. typedef unsigned long uLong; /* 32 bits or more */
  75414. #ifdef SMALL_MEDIUM
  75415. # define Bytef Byte FAR
  75416. #else
  75417. typedef Byte FAR Bytef;
  75418. #endif
  75419. typedef char FAR charf;
  75420. typedef int FAR intf;
  75421. typedef uInt FAR uIntf;
  75422. typedef uLong FAR uLongf;
  75423. #ifdef STDC
  75424. typedef void const *voidpc;
  75425. typedef void FAR *voidpf;
  75426. typedef void *voidp;
  75427. #else
  75428. typedef Byte const *voidpc;
  75429. typedef Byte FAR *voidpf;
  75430. typedef Byte *voidp;
  75431. #endif
  75432. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75433. # include <sys/types.h> /* for off_t */
  75434. # include <unistd.h> /* for SEEK_* and off_t */
  75435. # ifdef VMS
  75436. # include <unixio.h> /* for off_t */
  75437. # endif
  75438. # define z_off_t off_t
  75439. #endif
  75440. #ifndef SEEK_SET
  75441. # define SEEK_SET 0 /* Seek from beginning of file. */
  75442. # define SEEK_CUR 1 /* Seek from current position. */
  75443. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75444. #endif
  75445. #ifndef z_off_t
  75446. # define z_off_t long
  75447. #endif
  75448. #if defined(__OS400__)
  75449. # define NO_vsnprintf
  75450. #endif
  75451. #if defined(__MVS__)
  75452. # define NO_vsnprintf
  75453. # ifdef FAR
  75454. # undef FAR
  75455. # endif
  75456. #endif
  75457. #if defined(__MVS__)
  75458. # pragma map(deflateInit_,"DEIN")
  75459. # pragma map(deflateInit2_,"DEIN2")
  75460. # pragma map(deflateEnd,"DEEND")
  75461. # pragma map(deflateBound,"DEBND")
  75462. # pragma map(inflateInit_,"ININ")
  75463. # pragma map(inflateInit2_,"ININ2")
  75464. # pragma map(inflateEnd,"INEND")
  75465. # pragma map(inflateSync,"INSY")
  75466. # pragma map(inflateSetDictionary,"INSEDI")
  75467. # pragma map(compressBound,"CMBND")
  75468. # pragma map(inflate_table,"INTABL")
  75469. # pragma map(inflate_fast,"INFA")
  75470. # pragma map(inflate_copyright,"INCOPY")
  75471. #endif
  75472. #endif /* ZCONF_H */
  75473. /*** End of inlined file: zconf.h ***/
  75474. #ifdef __cplusplus
  75475. extern "C" {
  75476. #endif
  75477. #define ZLIB_VERSION "1.2.3"
  75478. #define ZLIB_VERNUM 0x1230
  75479. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75480. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75481. struct internal_state;
  75482. typedef struct z_stream_s {
  75483. Bytef *next_in; /* next input byte */
  75484. uInt avail_in; /* number of bytes available at next_in */
  75485. uLong total_in; /* total nb of input bytes read so far */
  75486. Bytef *next_out; /* next output byte should be put there */
  75487. uInt avail_out; /* remaining free space at next_out */
  75488. uLong total_out; /* total nb of bytes output so far */
  75489. char *msg; /* last error message, NULL if no error */
  75490. struct internal_state FAR *state; /* not visible by applications */
  75491. alloc_func zalloc; /* used to allocate the internal state */
  75492. free_func zfree; /* used to free the internal state */
  75493. voidpf opaque; /* private data object passed to zalloc and zfree */
  75494. int data_type; /* best guess about the data type: binary or text */
  75495. uLong adler; /* adler32 value of the uncompressed data */
  75496. uLong reserved; /* reserved for future use */
  75497. } z_stream;
  75498. typedef z_stream FAR *z_streamp;
  75499. typedef struct gz_header_s {
  75500. int text; /* true if compressed data believed to be text */
  75501. uLong time; /* modification time */
  75502. int xflags; /* extra flags (not used when writing a gzip file) */
  75503. int os; /* operating system */
  75504. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75505. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75506. uInt extra_max; /* space at extra (only when reading header) */
  75507. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75508. uInt name_max; /* space at name (only when reading header) */
  75509. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75510. uInt comm_max; /* space at comment (only when reading header) */
  75511. int hcrc; /* true if there was or will be a header crc */
  75512. int done; /* true when done reading gzip header (not used
  75513. when writing a gzip file) */
  75514. } gz_header;
  75515. typedef gz_header FAR *gz_headerp;
  75516. #define Z_NO_FLUSH 0
  75517. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75518. #define Z_SYNC_FLUSH 2
  75519. #define Z_FULL_FLUSH 3
  75520. #define Z_FINISH 4
  75521. #define Z_BLOCK 5
  75522. #define Z_OK 0
  75523. #define Z_STREAM_END 1
  75524. #define Z_NEED_DICT 2
  75525. #define Z_ERRNO (-1)
  75526. #define Z_STREAM_ERROR (-2)
  75527. #define Z_DATA_ERROR (-3)
  75528. #define Z_MEM_ERROR (-4)
  75529. #define Z_BUF_ERROR (-5)
  75530. #define Z_VERSION_ERROR (-6)
  75531. #define Z_NO_COMPRESSION 0
  75532. #define Z_BEST_SPEED 1
  75533. #define Z_BEST_COMPRESSION 9
  75534. #define Z_DEFAULT_COMPRESSION (-1)
  75535. #define Z_FILTERED 1
  75536. #define Z_HUFFMAN_ONLY 2
  75537. #define Z_RLE 3
  75538. #define Z_FIXED 4
  75539. #define Z_DEFAULT_STRATEGY 0
  75540. #define Z_BINARY 0
  75541. #define Z_TEXT 1
  75542. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75543. #define Z_UNKNOWN 2
  75544. #define Z_DEFLATED 8
  75545. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75546. #define zlib_version zlibVersion()
  75547. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75548. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75549. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75550. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75551. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75552. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75553. const Bytef *dictionary,
  75554. uInt dictLength));
  75555. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75556. z_streamp source));
  75557. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75558. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75559. int level,
  75560. int strategy));
  75561. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75562. int good_length,
  75563. int max_lazy,
  75564. int nice_length,
  75565. int max_chain));
  75566. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75567. uLong sourceLen));
  75568. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75569. int bits,
  75570. int value));
  75571. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75572. gz_headerp head));
  75573. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75574. const Bytef *dictionary,
  75575. uInt dictLength));
  75576. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75577. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75578. z_streamp source));
  75579. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75580. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75581. int bits,
  75582. int value));
  75583. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75584. gz_headerp head));
  75585. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75586. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75587. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75588. in_func in, void FAR *in_desc,
  75589. out_func out, void FAR *out_desc));
  75590. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75591. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75592. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75593. const Bytef *source, uLong sourceLen));
  75594. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75595. const Bytef *source, uLong sourceLen,
  75596. int level));
  75597. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75598. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75599. const Bytef *source, uLong sourceLen));
  75600. typedef voidp gzFile;
  75601. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75602. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75603. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75604. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75605. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75606. voidpc buf, unsigned len));
  75607. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75608. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75609. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75610. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75611. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75612. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75613. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75614. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75615. z_off_t offset, int whence));
  75616. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75617. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75618. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75619. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75620. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75621. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75622. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75623. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75624. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75625. z_off_t len2));
  75626. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75627. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75628. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75629. const char *version, int stream_size));
  75630. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75631. const char *version, int stream_size));
  75632. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75633. int windowBits, int memLevel,
  75634. int strategy, const char *version,
  75635. int stream_size));
  75636. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75637. const char *version, int stream_size));
  75638. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75639. unsigned char FAR *window,
  75640. const char *version,
  75641. int stream_size));
  75642. #define deflateInit(strm, level) \
  75643. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75644. #define inflateInit(strm) \
  75645. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75646. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75647. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75648. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75649. #define inflateInit2(strm, windowBits) \
  75650. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75651. #define inflateBackInit(strm, windowBits, window) \
  75652. inflateBackInit_((strm), (windowBits), (window), \
  75653. ZLIB_VERSION, sizeof(z_stream))
  75654. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75655. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75656. #endif
  75657. ZEXTERN const char * ZEXPORT zError OF((int));
  75658. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75659. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75660. #ifdef __cplusplus
  75661. }
  75662. #endif
  75663. #endif /* ZLIB_H */
  75664. /*** End of inlined file: zlib.h ***/
  75665. #undef OS_CODE
  75666. #else
  75667. #include <zlib.h>
  75668. #endif
  75669. }
  75670. BEGIN_JUCE_NAMESPACE
  75671. using namespace zlibNamespace;
  75672. // internal helper object that holds the zlib structures so they don't have to be
  75673. // included publicly.
  75674. class GZIPCompressorHelper
  75675. {
  75676. public:
  75677. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75678. : data (0),
  75679. dataSize (0),
  75680. compLevel (compressionLevel),
  75681. strategy (0),
  75682. setParams (true),
  75683. streamIsValid (false),
  75684. finished (false),
  75685. shouldFinish (false)
  75686. {
  75687. zerostruct (stream);
  75688. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75689. nowrap ? -MAX_WBITS : MAX_WBITS,
  75690. 8, strategy) == Z_OK);
  75691. }
  75692. ~GZIPCompressorHelper()
  75693. {
  75694. if (streamIsValid)
  75695. deflateEnd (&stream);
  75696. }
  75697. bool needsInput() const throw()
  75698. {
  75699. return dataSize <= 0;
  75700. }
  75701. void setInput (uint8* const newData, const int size) throw()
  75702. {
  75703. data = newData;
  75704. dataSize = size;
  75705. }
  75706. int doNextBlock (uint8* const dest, const int destSize) throw()
  75707. {
  75708. if (streamIsValid)
  75709. {
  75710. stream.next_in = data;
  75711. stream.next_out = dest;
  75712. stream.avail_in = dataSize;
  75713. stream.avail_out = destSize;
  75714. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75715. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75716. setParams = false;
  75717. switch (result)
  75718. {
  75719. case Z_STREAM_END:
  75720. finished = true;
  75721. // Deliberate fall-through..
  75722. case Z_OK:
  75723. data += dataSize - stream.avail_in;
  75724. dataSize = stream.avail_in;
  75725. return destSize - stream.avail_out;
  75726. default:
  75727. break;
  75728. }
  75729. }
  75730. return 0;
  75731. }
  75732. private:
  75733. z_stream stream;
  75734. uint8* data;
  75735. int dataSize, compLevel, strategy;
  75736. bool setParams, streamIsValid;
  75737. public:
  75738. bool finished, shouldFinish;
  75739. };
  75740. const int gzipCompBufferSize = 32768;
  75741. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75742. int compressionLevel,
  75743. const bool deleteDestStream,
  75744. const bool noWrap)
  75745. : destStream (destStream_),
  75746. streamToDelete (deleteDestStream ? destStream_ : 0),
  75747. buffer (gzipCompBufferSize)
  75748. {
  75749. if (compressionLevel < 1 || compressionLevel > 9)
  75750. compressionLevel = -1;
  75751. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75752. }
  75753. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75754. {
  75755. flush();
  75756. }
  75757. void GZIPCompressorOutputStream::flush()
  75758. {
  75759. if (! helper->finished)
  75760. {
  75761. helper->shouldFinish = true;
  75762. while (! helper->finished)
  75763. doNextBlock();
  75764. }
  75765. destStream->flush();
  75766. }
  75767. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75768. {
  75769. if (! helper->finished)
  75770. {
  75771. helper->setInput ((uint8*) destBuffer, howMany);
  75772. while (! helper->needsInput())
  75773. {
  75774. if (! doNextBlock())
  75775. return false;
  75776. }
  75777. }
  75778. return true;
  75779. }
  75780. bool GZIPCompressorOutputStream::doNextBlock()
  75781. {
  75782. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75783. if (len > 0)
  75784. return destStream->write (buffer, len);
  75785. else
  75786. return true;
  75787. }
  75788. int64 GZIPCompressorOutputStream::getPosition()
  75789. {
  75790. return destStream->getPosition();
  75791. }
  75792. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75793. {
  75794. jassertfalse // can't do it!
  75795. return false;
  75796. }
  75797. END_JUCE_NAMESPACE
  75798. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75799. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75800. #if JUCE_MSVC
  75801. #pragma warning (push)
  75802. #pragma warning (disable: 4309 4305)
  75803. #endif
  75804. namespace zlibNamespace
  75805. {
  75806. #if JUCE_INCLUDE_ZLIB_CODE
  75807. extern "C"
  75808. {
  75809. #undef OS_CODE
  75810. #undef fdopen
  75811. #define ZLIB_INTERNAL
  75812. #define NO_DUMMY_DECL
  75813. /*** Start of inlined file: adler32.c ***/
  75814. #define ZLIB_INTERNAL
  75815. #define BASE 65521UL /* largest prime smaller than 65536 */
  75816. #define NMAX 5552
  75817. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75818. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75819. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75820. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75821. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75822. #ifdef NO_DIVIDE
  75823. # define MOD(a) \
  75824. do { \
  75825. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75826. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75827. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75828. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75829. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75830. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75831. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75832. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75833. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75834. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75835. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75836. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75837. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75838. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75839. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75840. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75841. if (a >= BASE) a -= BASE; \
  75842. } while (0)
  75843. # define MOD4(a) \
  75844. do { \
  75845. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75846. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75847. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75848. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75849. if (a >= BASE) a -= BASE; \
  75850. } while (0)
  75851. #else
  75852. # define MOD(a) a %= BASE
  75853. # define MOD4(a) a %= BASE
  75854. #endif
  75855. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75856. {
  75857. unsigned long sum2;
  75858. unsigned n;
  75859. sum2 = (adler >> 16) & 0xffff;
  75860. adler &= 0xffff;
  75861. if (len == 1) {
  75862. adler += buf[0];
  75863. if (adler >= BASE)
  75864. adler -= BASE;
  75865. sum2 += adler;
  75866. if (sum2 >= BASE)
  75867. sum2 -= BASE;
  75868. return adler | (sum2 << 16);
  75869. }
  75870. if (buf == Z_NULL)
  75871. return 1L;
  75872. if (len < 16) {
  75873. while (len--) {
  75874. adler += *buf++;
  75875. sum2 += adler;
  75876. }
  75877. if (adler >= BASE)
  75878. adler -= BASE;
  75879. MOD4(sum2); /* only added so many BASE's */
  75880. return adler | (sum2 << 16);
  75881. }
  75882. while (len >= NMAX) {
  75883. len -= NMAX;
  75884. n = NMAX / 16; /* NMAX is divisible by 16 */
  75885. do {
  75886. DO16(buf); /* 16 sums unrolled */
  75887. buf += 16;
  75888. } while (--n);
  75889. MOD(adler);
  75890. MOD(sum2);
  75891. }
  75892. if (len) { /* avoid modulos if none remaining */
  75893. while (len >= 16) {
  75894. len -= 16;
  75895. DO16(buf);
  75896. buf += 16;
  75897. }
  75898. while (len--) {
  75899. adler += *buf++;
  75900. sum2 += adler;
  75901. }
  75902. MOD(adler);
  75903. MOD(sum2);
  75904. }
  75905. return adler | (sum2 << 16);
  75906. }
  75907. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75908. {
  75909. unsigned long sum1;
  75910. unsigned long sum2;
  75911. unsigned rem;
  75912. rem = (unsigned)(len2 % BASE);
  75913. sum1 = adler1 & 0xffff;
  75914. sum2 = rem * sum1;
  75915. MOD(sum2);
  75916. sum1 += (adler2 & 0xffff) + BASE - 1;
  75917. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75918. if (sum1 > BASE) sum1 -= BASE;
  75919. if (sum1 > BASE) sum1 -= BASE;
  75920. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75921. if (sum2 > BASE) sum2 -= BASE;
  75922. return sum1 | (sum2 << 16);
  75923. }
  75924. /*** End of inlined file: adler32.c ***/
  75925. /*** Start of inlined file: compress.c ***/
  75926. #define ZLIB_INTERNAL
  75927. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75928. uLong sourceLen, int level)
  75929. {
  75930. z_stream stream;
  75931. int err;
  75932. stream.next_in = (Bytef*)source;
  75933. stream.avail_in = (uInt)sourceLen;
  75934. #ifdef MAXSEG_64K
  75935. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75936. #endif
  75937. stream.next_out = dest;
  75938. stream.avail_out = (uInt)*destLen;
  75939. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75940. stream.zalloc = (alloc_func)0;
  75941. stream.zfree = (free_func)0;
  75942. stream.opaque = (voidpf)0;
  75943. err = deflateInit(&stream, level);
  75944. if (err != Z_OK) return err;
  75945. err = deflate(&stream, Z_FINISH);
  75946. if (err != Z_STREAM_END) {
  75947. deflateEnd(&stream);
  75948. return err == Z_OK ? Z_BUF_ERROR : err;
  75949. }
  75950. *destLen = stream.total_out;
  75951. err = deflateEnd(&stream);
  75952. return err;
  75953. }
  75954. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75955. {
  75956. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75957. }
  75958. uLong ZEXPORT compressBound (uLong sourceLen)
  75959. {
  75960. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75961. }
  75962. /*** End of inlined file: compress.c ***/
  75963. #undef DO1
  75964. #undef DO8
  75965. /*** Start of inlined file: crc32.c ***/
  75966. #ifdef MAKECRCH
  75967. # include <stdio.h>
  75968. # ifndef DYNAMIC_CRC_TABLE
  75969. # define DYNAMIC_CRC_TABLE
  75970. # endif /* !DYNAMIC_CRC_TABLE */
  75971. #endif /* MAKECRCH */
  75972. /*** Start of inlined file: zutil.h ***/
  75973. #ifndef ZUTIL_H
  75974. #define ZUTIL_H
  75975. #define ZLIB_INTERNAL
  75976. #ifdef STDC
  75977. # ifndef _WIN32_WCE
  75978. # include <stddef.h>
  75979. # endif
  75980. # include <string.h>
  75981. # include <stdlib.h>
  75982. #endif
  75983. #ifdef NO_ERRNO_H
  75984. # ifdef _WIN32_WCE
  75985. # define errno z_errno
  75986. # endif
  75987. extern int errno;
  75988. #else
  75989. # ifndef _WIN32_WCE
  75990. # include <errno.h>
  75991. # endif
  75992. #endif
  75993. #ifndef local
  75994. # define local static
  75995. #endif
  75996. typedef unsigned char uch;
  75997. typedef uch FAR uchf;
  75998. typedef unsigned short ush;
  75999. typedef ush FAR ushf;
  76000. typedef unsigned long ulg;
  76001. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  76002. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  76003. #define ERR_RETURN(strm,err) \
  76004. return (strm->msg = (char*)ERR_MSG(err), (err))
  76005. #ifndef DEF_WBITS
  76006. # define DEF_WBITS MAX_WBITS
  76007. #endif
  76008. #if MAX_MEM_LEVEL >= 8
  76009. # define DEF_MEM_LEVEL 8
  76010. #else
  76011. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  76012. #endif
  76013. #define STORED_BLOCK 0
  76014. #define STATIC_TREES 1
  76015. #define DYN_TREES 2
  76016. #define MIN_MATCH 3
  76017. #define MAX_MATCH 258
  76018. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  76019. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  76020. # define OS_CODE 0x00
  76021. # if defined(__TURBOC__) || defined(__BORLANDC__)
  76022. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  76023. void _Cdecl farfree( void *block );
  76024. void *_Cdecl farmalloc( unsigned long nbytes );
  76025. # else
  76026. # include <alloc.h>
  76027. # endif
  76028. # else /* MSC or DJGPP */
  76029. # include <malloc.h>
  76030. # endif
  76031. #endif
  76032. #ifdef AMIGA
  76033. # define OS_CODE 0x01
  76034. #endif
  76035. #if defined(VAXC) || defined(VMS)
  76036. # define OS_CODE 0x02
  76037. # define F_OPEN(name, mode) \
  76038. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  76039. #endif
  76040. #if defined(ATARI) || defined(atarist)
  76041. # define OS_CODE 0x05
  76042. #endif
  76043. #ifdef OS2
  76044. # define OS_CODE 0x06
  76045. # ifdef M_I86
  76046. #include <malloc.h>
  76047. # endif
  76048. #endif
  76049. #if defined(MACOS) || TARGET_OS_MAC
  76050. # define OS_CODE 0x07
  76051. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  76052. # include <unix.h> /* for fdopen */
  76053. # else
  76054. # ifndef fdopen
  76055. # define fdopen(fd,mode) NULL /* No fdopen() */
  76056. # endif
  76057. # endif
  76058. #endif
  76059. #ifdef TOPS20
  76060. # define OS_CODE 0x0a
  76061. #endif
  76062. #ifdef WIN32
  76063. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  76064. # define OS_CODE 0x0b
  76065. # endif
  76066. #endif
  76067. #ifdef __50SERIES /* Prime/PRIMOS */
  76068. # define OS_CODE 0x0f
  76069. #endif
  76070. #if defined(_BEOS_) || defined(RISCOS)
  76071. # define fdopen(fd,mode) NULL /* No fdopen() */
  76072. #endif
  76073. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  76074. # if defined(_WIN32_WCE)
  76075. # define fdopen(fd,mode) NULL /* No fdopen() */
  76076. # ifndef _PTRDIFF_T_DEFINED
  76077. typedef int ptrdiff_t;
  76078. # define _PTRDIFF_T_DEFINED
  76079. # endif
  76080. # else
  76081. # define fdopen(fd,type) _fdopen(fd,type)
  76082. # endif
  76083. #endif
  76084. #ifndef OS_CODE
  76085. # define OS_CODE 0x03 /* assume Unix */
  76086. #endif
  76087. #ifndef F_OPEN
  76088. # define F_OPEN(name, mode) fopen((name), (mode))
  76089. #endif
  76090. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  76091. # ifndef HAVE_VSNPRINTF
  76092. # define HAVE_VSNPRINTF
  76093. # endif
  76094. #endif
  76095. #if defined(__CYGWIN__)
  76096. # ifndef HAVE_VSNPRINTF
  76097. # define HAVE_VSNPRINTF
  76098. # endif
  76099. #endif
  76100. #ifndef HAVE_VSNPRINTF
  76101. # ifdef MSDOS
  76102. # define NO_vsnprintf
  76103. # endif
  76104. # ifdef __TURBOC__
  76105. # define NO_vsnprintf
  76106. # endif
  76107. # ifdef WIN32
  76108. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76109. # define vsnprintf _vsnprintf
  76110. # endif
  76111. # endif
  76112. # ifdef __SASC
  76113. # define NO_vsnprintf
  76114. # endif
  76115. #endif
  76116. #ifdef VMS
  76117. # define NO_vsnprintf
  76118. #endif
  76119. #if defined(pyr)
  76120. # define NO_MEMCPY
  76121. #endif
  76122. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76123. # define NO_MEMCPY
  76124. #endif
  76125. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76126. # define HAVE_MEMCPY
  76127. #endif
  76128. #ifdef HAVE_MEMCPY
  76129. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76130. # define zmemcpy _fmemcpy
  76131. # define zmemcmp _fmemcmp
  76132. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76133. # else
  76134. # define zmemcpy memcpy
  76135. # define zmemcmp memcmp
  76136. # define zmemzero(dest, len) memset(dest, 0, len)
  76137. # endif
  76138. #else
  76139. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76140. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76141. extern void zmemzero OF((Bytef* dest, uInt len));
  76142. #endif
  76143. #ifdef DEBUG
  76144. # include <stdio.h>
  76145. extern int z_verbose;
  76146. extern void z_error OF((const char *m));
  76147. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76148. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76149. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76150. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76151. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76152. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76153. #else
  76154. # define Assert(cond,msg)
  76155. # define Trace(x)
  76156. # define Tracev(x)
  76157. # define Tracevv(x)
  76158. # define Tracec(c,x)
  76159. # define Tracecv(c,x)
  76160. #endif
  76161. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76162. void zcfree OF((voidpf opaque, voidpf ptr));
  76163. #define ZALLOC(strm, items, size) \
  76164. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76165. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76166. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76167. #endif /* ZUTIL_H */
  76168. /*** End of inlined file: zutil.h ***/
  76169. /* for STDC and FAR definitions */
  76170. #define local static
  76171. #ifndef NOBYFOUR
  76172. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76173. # include <limits.h>
  76174. # define BYFOUR
  76175. # if (UINT_MAX == 0xffffffffUL)
  76176. typedef unsigned int u4;
  76177. # else
  76178. # if (ULONG_MAX == 0xffffffffUL)
  76179. typedef unsigned long u4;
  76180. # else
  76181. # if (USHRT_MAX == 0xffffffffUL)
  76182. typedef unsigned short u4;
  76183. # else
  76184. # undef BYFOUR /* can't find a four-byte integer type! */
  76185. # endif
  76186. # endif
  76187. # endif
  76188. # endif /* STDC */
  76189. #endif /* !NOBYFOUR */
  76190. #ifdef BYFOUR
  76191. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76192. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76193. local unsigned long crc32_little OF((unsigned long,
  76194. const unsigned char FAR *, unsigned));
  76195. local unsigned long crc32_big OF((unsigned long,
  76196. const unsigned char FAR *, unsigned));
  76197. # define TBLS 8
  76198. #else
  76199. # define TBLS 1
  76200. #endif /* BYFOUR */
  76201. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76202. unsigned long vec));
  76203. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76204. #ifdef DYNAMIC_CRC_TABLE
  76205. local volatile int crc_table_empty = 1;
  76206. local unsigned long FAR crc_table[TBLS][256];
  76207. local void make_crc_table OF((void));
  76208. #ifdef MAKECRCH
  76209. local void write_table OF((FILE *, const unsigned long FAR *));
  76210. #endif /* MAKECRCH */
  76211. local void make_crc_table()
  76212. {
  76213. unsigned long c;
  76214. int n, k;
  76215. unsigned long poly; /* polynomial exclusive-or pattern */
  76216. static volatile int first = 1; /* flag to limit concurrent making */
  76217. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76218. if (first) {
  76219. first = 0;
  76220. poly = 0UL;
  76221. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76222. poly |= 1UL << (31 - p[n]);
  76223. for (n = 0; n < 256; n++) {
  76224. c = (unsigned long)n;
  76225. for (k = 0; k < 8; k++)
  76226. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76227. crc_table[0][n] = c;
  76228. }
  76229. #ifdef BYFOUR
  76230. for (n = 0; n < 256; n++) {
  76231. c = crc_table[0][n];
  76232. crc_table[4][n] = REV(c);
  76233. for (k = 1; k < 4; k++) {
  76234. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76235. crc_table[k][n] = c;
  76236. crc_table[k + 4][n] = REV(c);
  76237. }
  76238. }
  76239. #endif /* BYFOUR */
  76240. crc_table_empty = 0;
  76241. }
  76242. else { /* not first */
  76243. while (crc_table_empty)
  76244. ;
  76245. }
  76246. #ifdef MAKECRCH
  76247. {
  76248. FILE *out;
  76249. out = fopen("crc32.h", "w");
  76250. if (out == NULL) return;
  76251. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76252. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76253. fprintf(out, "local const unsigned long FAR ");
  76254. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76255. write_table(out, crc_table[0]);
  76256. # ifdef BYFOUR
  76257. fprintf(out, "#ifdef BYFOUR\n");
  76258. for (k = 1; k < 8; k++) {
  76259. fprintf(out, " },\n {\n");
  76260. write_table(out, crc_table[k]);
  76261. }
  76262. fprintf(out, "#endif\n");
  76263. # endif /* BYFOUR */
  76264. fprintf(out, " }\n};\n");
  76265. fclose(out);
  76266. }
  76267. #endif /* MAKECRCH */
  76268. }
  76269. #ifdef MAKECRCH
  76270. local void write_table(out, table)
  76271. FILE *out;
  76272. const unsigned long FAR *table;
  76273. {
  76274. int n;
  76275. for (n = 0; n < 256; n++)
  76276. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76277. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76278. }
  76279. #endif /* MAKECRCH */
  76280. #else /* !DYNAMIC_CRC_TABLE */
  76281. /*** Start of inlined file: crc32.h ***/
  76282. local const unsigned long FAR crc_table[TBLS][256] =
  76283. {
  76284. {
  76285. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76286. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76287. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76288. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76289. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76290. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76291. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76292. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76293. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76294. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76295. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76296. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76297. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76298. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76299. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76300. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76301. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76302. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76303. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76304. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76305. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76306. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76307. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76308. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76309. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76310. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76311. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76312. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76313. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76314. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76315. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76316. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76317. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76318. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76319. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76320. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76321. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76322. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76323. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76324. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76325. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76326. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76327. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76328. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76329. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76330. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76331. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76332. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76333. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76334. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76335. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76336. 0x2d02ef8dUL
  76337. #ifdef BYFOUR
  76338. },
  76339. {
  76340. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76341. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76342. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76343. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76344. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76345. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76346. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76347. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76348. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76349. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76350. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76351. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76352. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76353. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76354. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76355. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76356. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76357. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76358. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76359. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76360. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76361. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76362. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76363. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76364. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76365. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76366. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76367. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76368. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76369. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76370. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76371. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76372. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76373. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76374. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76375. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76376. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76377. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76378. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76379. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76380. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76381. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76382. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76383. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76384. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76385. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76386. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76387. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76388. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76389. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76390. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76391. 0x9324fd72UL
  76392. },
  76393. {
  76394. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76395. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76396. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76397. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76398. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76399. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76400. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76401. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76402. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76403. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76404. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76405. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76406. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76407. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76408. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76409. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76410. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76411. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76412. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76413. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76414. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76415. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76416. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76417. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76418. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76419. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76420. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76421. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76422. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76423. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76424. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76425. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76426. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76427. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76428. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76429. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76430. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76431. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76432. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76433. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76434. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76435. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76436. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76437. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76438. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76439. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76440. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76441. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76442. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76443. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76444. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76445. 0xbe9834edUL
  76446. },
  76447. {
  76448. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76449. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76450. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76451. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76452. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76453. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76454. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76455. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76456. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76457. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76458. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76459. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76460. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76461. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76462. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76463. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76464. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76465. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76466. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76467. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76468. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76469. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76470. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76471. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76472. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76473. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76474. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76475. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76476. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76477. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76478. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76479. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76480. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76481. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76482. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76483. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76484. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76485. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76486. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76487. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76488. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76489. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76490. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76491. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76492. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76493. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76494. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76495. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76496. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76497. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76498. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76499. 0xde0506f1UL
  76500. },
  76501. {
  76502. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76503. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76504. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76505. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76506. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76507. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76508. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76509. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76510. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76511. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76512. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76513. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76514. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76515. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76516. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76517. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76518. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76519. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76520. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76521. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76522. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76523. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76524. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76525. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76526. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76527. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76528. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76529. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76530. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76531. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76532. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76533. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76534. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76535. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76536. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76537. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76538. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76539. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76540. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76541. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76542. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76543. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76544. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76545. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76546. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76547. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76548. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76549. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76550. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76551. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76552. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76553. 0x8def022dUL
  76554. },
  76555. {
  76556. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76557. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76558. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76559. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76560. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76561. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76562. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76563. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76564. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76565. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76566. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76567. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76568. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76569. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76570. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76571. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76572. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76573. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76574. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76575. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76576. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76577. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76578. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76579. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76580. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76581. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76582. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76583. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76584. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76585. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76586. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76587. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76588. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76589. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76590. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76591. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76592. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76593. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76594. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76595. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76596. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76597. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76598. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76599. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76600. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76601. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76602. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76603. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76604. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76605. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76606. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76607. 0x72fd2493UL
  76608. },
  76609. {
  76610. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76611. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76612. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76613. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76614. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76615. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76616. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76617. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76618. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76619. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76620. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76621. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76622. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76623. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76624. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76625. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76626. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76627. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76628. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76629. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76630. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76631. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76632. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76633. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76634. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76635. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76636. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76637. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76638. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76639. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76640. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76641. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76642. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76643. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76644. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76645. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76646. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76647. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76648. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76649. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76650. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76651. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76652. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76653. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76654. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76655. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76656. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76657. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76658. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76659. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76660. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76661. 0xed3498beUL
  76662. },
  76663. {
  76664. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76665. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76666. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76667. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76668. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76669. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76670. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76671. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76672. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76673. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76674. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76675. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76676. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76677. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76678. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76679. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76680. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76681. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76682. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76683. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76684. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76685. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76686. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76687. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76688. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76689. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76690. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76691. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76692. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76693. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76694. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76695. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76696. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76697. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76698. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76699. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76700. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76701. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76702. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76703. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76704. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76705. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76706. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76707. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76708. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76709. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76710. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76711. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76712. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76713. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76714. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76715. 0xf10605deUL
  76716. #endif
  76717. }
  76718. };
  76719. /*** End of inlined file: crc32.h ***/
  76720. #endif /* DYNAMIC_CRC_TABLE */
  76721. const unsigned long FAR * ZEXPORT get_crc_table()
  76722. {
  76723. #ifdef DYNAMIC_CRC_TABLE
  76724. if (crc_table_empty)
  76725. make_crc_table();
  76726. #endif /* DYNAMIC_CRC_TABLE */
  76727. return (const unsigned long FAR *)crc_table;
  76728. }
  76729. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76730. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76731. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76732. {
  76733. if (buf == Z_NULL) return 0UL;
  76734. #ifdef DYNAMIC_CRC_TABLE
  76735. if (crc_table_empty)
  76736. make_crc_table();
  76737. #endif /* DYNAMIC_CRC_TABLE */
  76738. #ifdef BYFOUR
  76739. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76740. u4 endian;
  76741. endian = 1;
  76742. if (*((unsigned char *)(&endian)))
  76743. return crc32_little(crc, buf, len);
  76744. else
  76745. return crc32_big(crc, buf, len);
  76746. }
  76747. #endif /* BYFOUR */
  76748. crc = crc ^ 0xffffffffUL;
  76749. while (len >= 8) {
  76750. DO8;
  76751. len -= 8;
  76752. }
  76753. if (len) do {
  76754. DO1;
  76755. } while (--len);
  76756. return crc ^ 0xffffffffUL;
  76757. }
  76758. #ifdef BYFOUR
  76759. #define DOLIT4 c ^= *buf4++; \
  76760. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76761. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76762. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76763. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76764. {
  76765. register u4 c;
  76766. register const u4 FAR *buf4;
  76767. c = (u4)crc;
  76768. c = ~c;
  76769. while (len && ((ptrdiff_t)buf & 3)) {
  76770. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76771. len--;
  76772. }
  76773. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76774. while (len >= 32) {
  76775. DOLIT32;
  76776. len -= 32;
  76777. }
  76778. while (len >= 4) {
  76779. DOLIT4;
  76780. len -= 4;
  76781. }
  76782. buf = (const unsigned char FAR *)buf4;
  76783. if (len) do {
  76784. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76785. } while (--len);
  76786. c = ~c;
  76787. return (unsigned long)c;
  76788. }
  76789. #define DOBIG4 c ^= *++buf4; \
  76790. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76791. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76792. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76793. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76794. {
  76795. register u4 c;
  76796. register const u4 FAR *buf4;
  76797. c = REV((u4)crc);
  76798. c = ~c;
  76799. while (len && ((ptrdiff_t)buf & 3)) {
  76800. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76801. len--;
  76802. }
  76803. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76804. buf4--;
  76805. while (len >= 32) {
  76806. DOBIG32;
  76807. len -= 32;
  76808. }
  76809. while (len >= 4) {
  76810. DOBIG4;
  76811. len -= 4;
  76812. }
  76813. buf4++;
  76814. buf = (const unsigned char FAR *)buf4;
  76815. if (len) do {
  76816. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76817. } while (--len);
  76818. c = ~c;
  76819. return (unsigned long)(REV(c));
  76820. }
  76821. #endif /* BYFOUR */
  76822. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76823. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76824. {
  76825. unsigned long sum;
  76826. sum = 0;
  76827. while (vec) {
  76828. if (vec & 1)
  76829. sum ^= *mat;
  76830. vec >>= 1;
  76831. mat++;
  76832. }
  76833. return sum;
  76834. }
  76835. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76836. {
  76837. int n;
  76838. for (n = 0; n < GF2_DIM; n++)
  76839. square[n] = gf2_matrix_times(mat, mat[n]);
  76840. }
  76841. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76842. {
  76843. int n;
  76844. unsigned long row;
  76845. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76846. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76847. if (len2 == 0)
  76848. return crc1;
  76849. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76850. row = 1;
  76851. for (n = 1; n < GF2_DIM; n++) {
  76852. odd[n] = row;
  76853. row <<= 1;
  76854. }
  76855. gf2_matrix_square(even, odd);
  76856. gf2_matrix_square(odd, even);
  76857. do {
  76858. gf2_matrix_square(even, odd);
  76859. if (len2 & 1)
  76860. crc1 = gf2_matrix_times(even, crc1);
  76861. len2 >>= 1;
  76862. if (len2 == 0)
  76863. break;
  76864. gf2_matrix_square(odd, even);
  76865. if (len2 & 1)
  76866. crc1 = gf2_matrix_times(odd, crc1);
  76867. len2 >>= 1;
  76868. } while (len2 != 0);
  76869. crc1 ^= crc2;
  76870. return crc1;
  76871. }
  76872. /*** End of inlined file: crc32.c ***/
  76873. /*** Start of inlined file: deflate.c ***/
  76874. /*** Start of inlined file: deflate.h ***/
  76875. #ifndef DEFLATE_H
  76876. #define DEFLATE_H
  76877. #ifndef NO_GZIP
  76878. # define GZIP
  76879. #endif
  76880. #define NO_DUMMY_DECL
  76881. #define LENGTH_CODES 29
  76882. #define LITERALS 256
  76883. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76884. #define D_CODES 30
  76885. #define BL_CODES 19
  76886. #define HEAP_SIZE (2*L_CODES+1)
  76887. #define MAX_BITS 15
  76888. #define INIT_STATE 42
  76889. #define EXTRA_STATE 69
  76890. #define NAME_STATE 73
  76891. #define COMMENT_STATE 91
  76892. #define HCRC_STATE 103
  76893. #define BUSY_STATE 113
  76894. #define FINISH_STATE 666
  76895. typedef struct ct_data_s {
  76896. union {
  76897. ush freq; /* frequency count */
  76898. ush code; /* bit string */
  76899. } fc;
  76900. union {
  76901. ush dad; /* father node in Huffman tree */
  76902. ush len; /* length of bit string */
  76903. } dl;
  76904. } FAR ct_data;
  76905. #define Freq fc.freq
  76906. #define Code fc.code
  76907. #define Dad dl.dad
  76908. #define Len dl.len
  76909. typedef struct static_tree_desc_s static_tree_desc;
  76910. typedef struct tree_desc_s {
  76911. ct_data *dyn_tree; /* the dynamic tree */
  76912. int max_code; /* largest code with non zero frequency */
  76913. static_tree_desc *stat_desc; /* the corresponding static tree */
  76914. } FAR tree_desc;
  76915. typedef ush Pos;
  76916. typedef Pos FAR Posf;
  76917. typedef unsigned IPos;
  76918. typedef struct internal_state {
  76919. z_streamp strm; /* pointer back to this zlib stream */
  76920. int status; /* as the name implies */
  76921. Bytef *pending_buf; /* output still pending */
  76922. ulg pending_buf_size; /* size of pending_buf */
  76923. Bytef *pending_out; /* next pending byte to output to the stream */
  76924. uInt pending; /* nb of bytes in the pending buffer */
  76925. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76926. gz_headerp gzhead; /* gzip header information to write */
  76927. uInt gzindex; /* where in extra, name, or comment */
  76928. Byte method; /* STORED (for zip only) or DEFLATED */
  76929. int last_flush; /* value of flush param for previous deflate call */
  76930. uInt w_size; /* LZ77 window size (32K by default) */
  76931. uInt w_bits; /* log2(w_size) (8..16) */
  76932. uInt w_mask; /* w_size - 1 */
  76933. Bytef *window;
  76934. ulg window_size;
  76935. Posf *prev;
  76936. Posf *head; /* Heads of the hash chains or NIL. */
  76937. uInt ins_h; /* hash index of string to be inserted */
  76938. uInt hash_size; /* number of elements in hash table */
  76939. uInt hash_bits; /* log2(hash_size) */
  76940. uInt hash_mask; /* hash_size-1 */
  76941. uInt hash_shift;
  76942. long block_start;
  76943. uInt match_length; /* length of best match */
  76944. IPos prev_match; /* previous match */
  76945. int match_available; /* set if previous match exists */
  76946. uInt strstart; /* start of string to insert */
  76947. uInt match_start; /* start of matching string */
  76948. uInt lookahead; /* number of valid bytes ahead in window */
  76949. uInt prev_length;
  76950. uInt max_chain_length;
  76951. uInt max_lazy_match;
  76952. # define max_insert_length max_lazy_match
  76953. int level; /* compression level (1..9) */
  76954. int strategy; /* favor or force Huffman coding*/
  76955. uInt good_match;
  76956. int nice_match; /* Stop searching when current match exceeds this */
  76957. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76958. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76959. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76960. struct tree_desc_s l_desc; /* desc. for literal tree */
  76961. struct tree_desc_s d_desc; /* desc. for distance tree */
  76962. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76963. ush bl_count[MAX_BITS+1];
  76964. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76965. int heap_len; /* number of elements in the heap */
  76966. int heap_max; /* element of largest frequency */
  76967. uch depth[2*L_CODES+1];
  76968. uchf *l_buf; /* buffer for literals or lengths */
  76969. uInt lit_bufsize;
  76970. uInt last_lit; /* running index in l_buf */
  76971. ushf *d_buf;
  76972. ulg opt_len; /* bit length of current block with optimal trees */
  76973. ulg static_len; /* bit length of current block with static trees */
  76974. uInt matches; /* number of string matches in current block */
  76975. int last_eob_len; /* bit length of EOB code for last block */
  76976. #ifdef DEBUG
  76977. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76978. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76979. #endif
  76980. ush bi_buf;
  76981. int bi_valid;
  76982. } FAR deflate_state;
  76983. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76984. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76985. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76986. void _tr_init OF((deflate_state *s));
  76987. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76988. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76989. int eof));
  76990. void _tr_align OF((deflate_state *s));
  76991. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76992. int eof));
  76993. #define d_code(dist) \
  76994. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76995. #ifndef DEBUG
  76996. #if defined(GEN_TREES_H) || !defined(STDC)
  76997. extern uch _length_code[];
  76998. extern uch _dist_code[];
  76999. #else
  77000. extern const uch _length_code[];
  77001. extern const uch _dist_code[];
  77002. #endif
  77003. # define _tr_tally_lit(s, c, flush) \
  77004. { uch cc = (c); \
  77005. s->d_buf[s->last_lit] = 0; \
  77006. s->l_buf[s->last_lit++] = cc; \
  77007. s->dyn_ltree[cc].Freq++; \
  77008. flush = (s->last_lit == s->lit_bufsize-1); \
  77009. }
  77010. # define _tr_tally_dist(s, distance, length, flush) \
  77011. { uch len = (length); \
  77012. ush dist = (distance); \
  77013. s->d_buf[s->last_lit] = dist; \
  77014. s->l_buf[s->last_lit++] = len; \
  77015. dist--; \
  77016. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  77017. s->dyn_dtree[d_code(dist)].Freq++; \
  77018. flush = (s->last_lit == s->lit_bufsize-1); \
  77019. }
  77020. #else
  77021. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  77022. # define _tr_tally_dist(s, distance, length, flush) \
  77023. flush = _tr_tally(s, distance, length)
  77024. #endif
  77025. #endif /* DEFLATE_H */
  77026. /*** End of inlined file: deflate.h ***/
  77027. const char deflate_copyright[] =
  77028. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  77029. typedef enum {
  77030. need_more, /* block not completed, need more input or more output */
  77031. block_done, /* block flush performed */
  77032. finish_started, /* finish started, need only more output at next deflate */
  77033. finish_done /* finish done, accept no more input or output */
  77034. } block_state;
  77035. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  77036. local void fill_window OF((deflate_state *s));
  77037. local block_state deflate_stored OF((deflate_state *s, int flush));
  77038. local block_state deflate_fast OF((deflate_state *s, int flush));
  77039. #ifndef FASTEST
  77040. local block_state deflate_slow OF((deflate_state *s, int flush));
  77041. #endif
  77042. local void lm_init OF((deflate_state *s));
  77043. local void putShortMSB OF((deflate_state *s, uInt b));
  77044. local void flush_pending OF((z_streamp strm));
  77045. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  77046. #ifndef FASTEST
  77047. #ifdef ASMV
  77048. void match_init OF((void)); /* asm code initialization */
  77049. uInt longest_match OF((deflate_state *s, IPos cur_match));
  77050. #else
  77051. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  77052. #endif
  77053. #endif
  77054. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  77055. #ifdef DEBUG
  77056. local void check_match OF((deflate_state *s, IPos start, IPos match,
  77057. int length));
  77058. #endif
  77059. #define NIL 0
  77060. #ifndef TOO_FAR
  77061. # define TOO_FAR 4096
  77062. #endif
  77063. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77064. typedef struct config_s {
  77065. ush good_length; /* reduce lazy search above this match length */
  77066. ush max_lazy; /* do not perform lazy search above this match length */
  77067. ush nice_length; /* quit search above this match length */
  77068. ush max_chain;
  77069. compress_func func;
  77070. } config;
  77071. #ifdef FASTEST
  77072. local const config configuration_table[2] = {
  77073. {0, 0, 0, 0, deflate_stored}, /* store only */
  77074. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  77075. #else
  77076. local const config configuration_table[10] = {
  77077. {0, 0, 0, 0, deflate_stored}, /* store only */
  77078. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  77079. {4, 5, 16, 8, deflate_fast},
  77080. {4, 6, 32, 32, deflate_fast},
  77081. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  77082. {8, 16, 32, 32, deflate_slow},
  77083. {8, 16, 128, 128, deflate_slow},
  77084. {8, 32, 128, 256, deflate_slow},
  77085. {32, 128, 258, 1024, deflate_slow},
  77086. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  77087. #endif
  77088. #define EQUAL 0
  77089. #ifndef NO_DUMMY_DECL
  77090. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  77091. #endif
  77092. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  77093. #ifdef FASTEST
  77094. #define INSERT_STRING(s, str, match_head) \
  77095. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77096. match_head = s->head[s->ins_h], \
  77097. s->head[s->ins_h] = (Pos)(str))
  77098. #else
  77099. #define INSERT_STRING(s, str, match_head) \
  77100. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77101. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77102. s->head[s->ins_h] = (Pos)(str))
  77103. #endif
  77104. #define CLEAR_HASH(s) \
  77105. s->head[s->hash_size-1] = NIL; \
  77106. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77107. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77108. {
  77109. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77110. Z_DEFAULT_STRATEGY, version, stream_size);
  77111. }
  77112. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77113. {
  77114. deflate_state *s;
  77115. int wrap = 1;
  77116. static const char my_version[] = ZLIB_VERSION;
  77117. ushf *overlay;
  77118. if (version == Z_NULL || version[0] != my_version[0] ||
  77119. stream_size != sizeof(z_stream)) {
  77120. return Z_VERSION_ERROR;
  77121. }
  77122. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77123. strm->msg = Z_NULL;
  77124. if (strm->zalloc == (alloc_func)0) {
  77125. strm->zalloc = zcalloc;
  77126. strm->opaque = (voidpf)0;
  77127. }
  77128. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77129. #ifdef FASTEST
  77130. if (level != 0) level = 1;
  77131. #else
  77132. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77133. #endif
  77134. if (windowBits < 0) { /* suppress zlib wrapper */
  77135. wrap = 0;
  77136. windowBits = -windowBits;
  77137. }
  77138. #ifdef GZIP
  77139. else if (windowBits > 15) {
  77140. wrap = 2; /* write gzip wrapper instead */
  77141. windowBits -= 16;
  77142. }
  77143. #endif
  77144. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77145. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77146. strategy < 0 || strategy > Z_FIXED) {
  77147. return Z_STREAM_ERROR;
  77148. }
  77149. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77150. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77151. if (s == Z_NULL) return Z_MEM_ERROR;
  77152. strm->state = (struct internal_state FAR *)s;
  77153. s->strm = strm;
  77154. s->wrap = wrap;
  77155. s->gzhead = Z_NULL;
  77156. s->w_bits = windowBits;
  77157. s->w_size = 1 << s->w_bits;
  77158. s->w_mask = s->w_size - 1;
  77159. s->hash_bits = memLevel + 7;
  77160. s->hash_size = 1 << s->hash_bits;
  77161. s->hash_mask = s->hash_size - 1;
  77162. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77163. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77164. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77165. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77166. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77167. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77168. s->pending_buf = (uchf *) overlay;
  77169. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77170. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77171. s->pending_buf == Z_NULL) {
  77172. s->status = FINISH_STATE;
  77173. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77174. deflateEnd (strm);
  77175. return Z_MEM_ERROR;
  77176. }
  77177. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77178. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77179. s->level = level;
  77180. s->strategy = strategy;
  77181. s->method = (Byte)method;
  77182. return deflateReset(strm);
  77183. }
  77184. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77185. {
  77186. deflate_state *s;
  77187. uInt length = dictLength;
  77188. uInt n;
  77189. IPos hash_head = 0;
  77190. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77191. strm->state->wrap == 2 ||
  77192. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77193. return Z_STREAM_ERROR;
  77194. s = strm->state;
  77195. if (s->wrap)
  77196. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77197. if (length < MIN_MATCH) return Z_OK;
  77198. if (length > MAX_DIST(s)) {
  77199. length = MAX_DIST(s);
  77200. dictionary += dictLength - length; /* use the tail of the dictionary */
  77201. }
  77202. zmemcpy(s->window, dictionary, length);
  77203. s->strstart = length;
  77204. s->block_start = (long)length;
  77205. s->ins_h = s->window[0];
  77206. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77207. for (n = 0; n <= length - MIN_MATCH; n++) {
  77208. INSERT_STRING(s, n, hash_head);
  77209. }
  77210. if (hash_head) hash_head = 0; /* to make compiler happy */
  77211. return Z_OK;
  77212. }
  77213. int ZEXPORT deflateReset (z_streamp strm)
  77214. {
  77215. deflate_state *s;
  77216. if (strm == Z_NULL || strm->state == Z_NULL ||
  77217. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77218. return Z_STREAM_ERROR;
  77219. }
  77220. strm->total_in = strm->total_out = 0;
  77221. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77222. strm->data_type = Z_UNKNOWN;
  77223. s = (deflate_state *)strm->state;
  77224. s->pending = 0;
  77225. s->pending_out = s->pending_buf;
  77226. if (s->wrap < 0) {
  77227. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77228. }
  77229. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77230. strm->adler =
  77231. #ifdef GZIP
  77232. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77233. #endif
  77234. adler32(0L, Z_NULL, 0);
  77235. s->last_flush = Z_NO_FLUSH;
  77236. _tr_init(s);
  77237. lm_init(s);
  77238. return Z_OK;
  77239. }
  77240. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77241. {
  77242. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77243. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77244. strm->state->gzhead = head;
  77245. return Z_OK;
  77246. }
  77247. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77248. {
  77249. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77250. strm->state->bi_valid = bits;
  77251. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77252. return Z_OK;
  77253. }
  77254. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77255. {
  77256. deflate_state *s;
  77257. compress_func func;
  77258. int err = Z_OK;
  77259. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77260. s = strm->state;
  77261. #ifdef FASTEST
  77262. if (level != 0) level = 1;
  77263. #else
  77264. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77265. #endif
  77266. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77267. return Z_STREAM_ERROR;
  77268. }
  77269. func = configuration_table[s->level].func;
  77270. if (func != configuration_table[level].func && strm->total_in != 0) {
  77271. err = deflate(strm, Z_PARTIAL_FLUSH);
  77272. }
  77273. if (s->level != level) {
  77274. s->level = level;
  77275. s->max_lazy_match = configuration_table[level].max_lazy;
  77276. s->good_match = configuration_table[level].good_length;
  77277. s->nice_match = configuration_table[level].nice_length;
  77278. s->max_chain_length = configuration_table[level].max_chain;
  77279. }
  77280. s->strategy = strategy;
  77281. return err;
  77282. }
  77283. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77284. {
  77285. deflate_state *s;
  77286. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77287. s = strm->state;
  77288. s->good_match = good_length;
  77289. s->max_lazy_match = max_lazy;
  77290. s->nice_match = nice_length;
  77291. s->max_chain_length = max_chain;
  77292. return Z_OK;
  77293. }
  77294. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77295. {
  77296. deflate_state *s;
  77297. uLong destLen;
  77298. destLen = sourceLen +
  77299. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77300. if (strm == Z_NULL || strm->state == Z_NULL)
  77301. return destLen;
  77302. s = strm->state;
  77303. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77304. return destLen;
  77305. return compressBound(sourceLen);
  77306. }
  77307. local void putShortMSB (deflate_state *s, uInt b)
  77308. {
  77309. put_byte(s, (Byte)(b >> 8));
  77310. put_byte(s, (Byte)(b & 0xff));
  77311. }
  77312. local void flush_pending (z_streamp strm)
  77313. {
  77314. unsigned len = strm->state->pending;
  77315. if (len > strm->avail_out) len = strm->avail_out;
  77316. if (len == 0) return;
  77317. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77318. strm->next_out += len;
  77319. strm->state->pending_out += len;
  77320. strm->total_out += len;
  77321. strm->avail_out -= len;
  77322. strm->state->pending -= len;
  77323. if (strm->state->pending == 0) {
  77324. strm->state->pending_out = strm->state->pending_buf;
  77325. }
  77326. }
  77327. int ZEXPORT deflate (z_streamp strm, int flush)
  77328. {
  77329. int old_flush; /* value of flush param for previous deflate call */
  77330. deflate_state *s;
  77331. if (strm == Z_NULL || strm->state == Z_NULL ||
  77332. flush > Z_FINISH || flush < 0) {
  77333. return Z_STREAM_ERROR;
  77334. }
  77335. s = strm->state;
  77336. if (strm->next_out == Z_NULL ||
  77337. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77338. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77339. ERR_RETURN(strm, Z_STREAM_ERROR);
  77340. }
  77341. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77342. s->strm = strm; /* just in case */
  77343. old_flush = s->last_flush;
  77344. s->last_flush = flush;
  77345. if (s->status == INIT_STATE) {
  77346. #ifdef GZIP
  77347. if (s->wrap == 2) {
  77348. strm->adler = crc32(0L, Z_NULL, 0);
  77349. put_byte(s, 31);
  77350. put_byte(s, 139);
  77351. put_byte(s, 8);
  77352. if (s->gzhead == NULL) {
  77353. put_byte(s, 0);
  77354. put_byte(s, 0);
  77355. put_byte(s, 0);
  77356. put_byte(s, 0);
  77357. put_byte(s, 0);
  77358. put_byte(s, s->level == 9 ? 2 :
  77359. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77360. 4 : 0));
  77361. put_byte(s, OS_CODE);
  77362. s->status = BUSY_STATE;
  77363. }
  77364. else {
  77365. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77366. (s->gzhead->hcrc ? 2 : 0) +
  77367. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77368. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77369. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77370. );
  77371. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77372. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77373. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77374. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77375. put_byte(s, s->level == 9 ? 2 :
  77376. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77377. 4 : 0));
  77378. put_byte(s, s->gzhead->os & 0xff);
  77379. if (s->gzhead->extra != NULL) {
  77380. put_byte(s, s->gzhead->extra_len & 0xff);
  77381. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77382. }
  77383. if (s->gzhead->hcrc)
  77384. strm->adler = crc32(strm->adler, s->pending_buf,
  77385. s->pending);
  77386. s->gzindex = 0;
  77387. s->status = EXTRA_STATE;
  77388. }
  77389. }
  77390. else
  77391. #endif
  77392. {
  77393. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77394. uInt level_flags;
  77395. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77396. level_flags = 0;
  77397. else if (s->level < 6)
  77398. level_flags = 1;
  77399. else if (s->level == 6)
  77400. level_flags = 2;
  77401. else
  77402. level_flags = 3;
  77403. header |= (level_flags << 6);
  77404. if (s->strstart != 0) header |= PRESET_DICT;
  77405. header += 31 - (header % 31);
  77406. s->status = BUSY_STATE;
  77407. putShortMSB(s, header);
  77408. if (s->strstart != 0) {
  77409. putShortMSB(s, (uInt)(strm->adler >> 16));
  77410. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77411. }
  77412. strm->adler = adler32(0L, Z_NULL, 0);
  77413. }
  77414. }
  77415. #ifdef GZIP
  77416. if (s->status == EXTRA_STATE) {
  77417. if (s->gzhead->extra != NULL) {
  77418. uInt beg = s->pending; /* start of bytes to update crc */
  77419. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77420. if (s->pending == s->pending_buf_size) {
  77421. if (s->gzhead->hcrc && s->pending > beg)
  77422. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77423. s->pending - beg);
  77424. flush_pending(strm);
  77425. beg = s->pending;
  77426. if (s->pending == s->pending_buf_size)
  77427. break;
  77428. }
  77429. put_byte(s, s->gzhead->extra[s->gzindex]);
  77430. s->gzindex++;
  77431. }
  77432. if (s->gzhead->hcrc && s->pending > beg)
  77433. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77434. s->pending - beg);
  77435. if (s->gzindex == s->gzhead->extra_len) {
  77436. s->gzindex = 0;
  77437. s->status = NAME_STATE;
  77438. }
  77439. }
  77440. else
  77441. s->status = NAME_STATE;
  77442. }
  77443. if (s->status == NAME_STATE) {
  77444. if (s->gzhead->name != NULL) {
  77445. uInt beg = s->pending; /* start of bytes to update crc */
  77446. int val;
  77447. do {
  77448. if (s->pending == s->pending_buf_size) {
  77449. if (s->gzhead->hcrc && s->pending > beg)
  77450. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77451. s->pending - beg);
  77452. flush_pending(strm);
  77453. beg = s->pending;
  77454. if (s->pending == s->pending_buf_size) {
  77455. val = 1;
  77456. break;
  77457. }
  77458. }
  77459. val = s->gzhead->name[s->gzindex++];
  77460. put_byte(s, val);
  77461. } while (val != 0);
  77462. if (s->gzhead->hcrc && s->pending > beg)
  77463. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77464. s->pending - beg);
  77465. if (val == 0) {
  77466. s->gzindex = 0;
  77467. s->status = COMMENT_STATE;
  77468. }
  77469. }
  77470. else
  77471. s->status = COMMENT_STATE;
  77472. }
  77473. if (s->status == COMMENT_STATE) {
  77474. if (s->gzhead->comment != NULL) {
  77475. uInt beg = s->pending; /* start of bytes to update crc */
  77476. int val;
  77477. do {
  77478. if (s->pending == s->pending_buf_size) {
  77479. if (s->gzhead->hcrc && s->pending > beg)
  77480. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77481. s->pending - beg);
  77482. flush_pending(strm);
  77483. beg = s->pending;
  77484. if (s->pending == s->pending_buf_size) {
  77485. val = 1;
  77486. break;
  77487. }
  77488. }
  77489. val = s->gzhead->comment[s->gzindex++];
  77490. put_byte(s, val);
  77491. } while (val != 0);
  77492. if (s->gzhead->hcrc && s->pending > beg)
  77493. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77494. s->pending - beg);
  77495. if (val == 0)
  77496. s->status = HCRC_STATE;
  77497. }
  77498. else
  77499. s->status = HCRC_STATE;
  77500. }
  77501. if (s->status == HCRC_STATE) {
  77502. if (s->gzhead->hcrc) {
  77503. if (s->pending + 2 > s->pending_buf_size)
  77504. flush_pending(strm);
  77505. if (s->pending + 2 <= s->pending_buf_size) {
  77506. put_byte(s, (Byte)(strm->adler & 0xff));
  77507. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77508. strm->adler = crc32(0L, Z_NULL, 0);
  77509. s->status = BUSY_STATE;
  77510. }
  77511. }
  77512. else
  77513. s->status = BUSY_STATE;
  77514. }
  77515. #endif
  77516. if (s->pending != 0) {
  77517. flush_pending(strm);
  77518. if (strm->avail_out == 0) {
  77519. s->last_flush = -1;
  77520. return Z_OK;
  77521. }
  77522. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77523. flush != Z_FINISH) {
  77524. ERR_RETURN(strm, Z_BUF_ERROR);
  77525. }
  77526. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77527. ERR_RETURN(strm, Z_BUF_ERROR);
  77528. }
  77529. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77530. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77531. block_state bstate;
  77532. bstate = (*(configuration_table[s->level].func))(s, flush);
  77533. if (bstate == finish_started || bstate == finish_done) {
  77534. s->status = FINISH_STATE;
  77535. }
  77536. if (bstate == need_more || bstate == finish_started) {
  77537. if (strm->avail_out == 0) {
  77538. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77539. }
  77540. return Z_OK;
  77541. }
  77542. if (bstate == block_done) {
  77543. if (flush == Z_PARTIAL_FLUSH) {
  77544. _tr_align(s);
  77545. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77546. _tr_stored_block(s, (char*)0, 0L, 0);
  77547. if (flush == Z_FULL_FLUSH) {
  77548. CLEAR_HASH(s); /* forget history */
  77549. }
  77550. }
  77551. flush_pending(strm);
  77552. if (strm->avail_out == 0) {
  77553. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77554. return Z_OK;
  77555. }
  77556. }
  77557. }
  77558. Assert(strm->avail_out > 0, "bug2");
  77559. if (flush != Z_FINISH) return Z_OK;
  77560. if (s->wrap <= 0) return Z_STREAM_END;
  77561. #ifdef GZIP
  77562. if (s->wrap == 2) {
  77563. put_byte(s, (Byte)(strm->adler & 0xff));
  77564. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77565. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77566. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77567. put_byte(s, (Byte)(strm->total_in & 0xff));
  77568. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77569. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77570. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77571. }
  77572. else
  77573. #endif
  77574. {
  77575. putShortMSB(s, (uInt)(strm->adler >> 16));
  77576. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77577. }
  77578. flush_pending(strm);
  77579. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77580. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77581. }
  77582. int ZEXPORT deflateEnd (z_streamp strm)
  77583. {
  77584. int status;
  77585. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77586. status = strm->state->status;
  77587. if (status != INIT_STATE &&
  77588. status != EXTRA_STATE &&
  77589. status != NAME_STATE &&
  77590. status != COMMENT_STATE &&
  77591. status != HCRC_STATE &&
  77592. status != BUSY_STATE &&
  77593. status != FINISH_STATE) {
  77594. return Z_STREAM_ERROR;
  77595. }
  77596. TRY_FREE(strm, strm->state->pending_buf);
  77597. TRY_FREE(strm, strm->state->head);
  77598. TRY_FREE(strm, strm->state->prev);
  77599. TRY_FREE(strm, strm->state->window);
  77600. ZFREE(strm, strm->state);
  77601. strm->state = Z_NULL;
  77602. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77603. }
  77604. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77605. {
  77606. #ifdef MAXSEG_64K
  77607. return Z_STREAM_ERROR;
  77608. #else
  77609. deflate_state *ds;
  77610. deflate_state *ss;
  77611. ushf *overlay;
  77612. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77613. return Z_STREAM_ERROR;
  77614. }
  77615. ss = source->state;
  77616. zmemcpy(dest, source, sizeof(z_stream));
  77617. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77618. if (ds == Z_NULL) return Z_MEM_ERROR;
  77619. dest->state = (struct internal_state FAR *) ds;
  77620. zmemcpy(ds, ss, sizeof(deflate_state));
  77621. ds->strm = dest;
  77622. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77623. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77624. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77625. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77626. ds->pending_buf = (uchf *) overlay;
  77627. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77628. ds->pending_buf == Z_NULL) {
  77629. deflateEnd (dest);
  77630. return Z_MEM_ERROR;
  77631. }
  77632. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77633. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77634. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77635. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77636. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77637. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77638. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77639. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77640. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77641. ds->bl_desc.dyn_tree = ds->bl_tree;
  77642. return Z_OK;
  77643. #endif /* MAXSEG_64K */
  77644. }
  77645. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77646. {
  77647. unsigned len = strm->avail_in;
  77648. if (len > size) len = size;
  77649. if (len == 0) return 0;
  77650. strm->avail_in -= len;
  77651. if (strm->state->wrap == 1) {
  77652. strm->adler = adler32(strm->adler, strm->next_in, len);
  77653. }
  77654. #ifdef GZIP
  77655. else if (strm->state->wrap == 2) {
  77656. strm->adler = crc32(strm->adler, strm->next_in, len);
  77657. }
  77658. #endif
  77659. zmemcpy(buf, strm->next_in, len);
  77660. strm->next_in += len;
  77661. strm->total_in += len;
  77662. return (int)len;
  77663. }
  77664. local void lm_init (deflate_state *s)
  77665. {
  77666. s->window_size = (ulg)2L*s->w_size;
  77667. CLEAR_HASH(s);
  77668. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77669. s->good_match = configuration_table[s->level].good_length;
  77670. s->nice_match = configuration_table[s->level].nice_length;
  77671. s->max_chain_length = configuration_table[s->level].max_chain;
  77672. s->strstart = 0;
  77673. s->block_start = 0L;
  77674. s->lookahead = 0;
  77675. s->match_length = s->prev_length = MIN_MATCH-1;
  77676. s->match_available = 0;
  77677. s->ins_h = 0;
  77678. #ifndef FASTEST
  77679. #ifdef ASMV
  77680. match_init(); /* initialize the asm code */
  77681. #endif
  77682. #endif
  77683. }
  77684. #ifndef FASTEST
  77685. #ifndef ASMV
  77686. local uInt longest_match(deflate_state *s, IPos cur_match)
  77687. {
  77688. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77689. register Bytef *scan = s->window + s->strstart; /* current string */
  77690. register Bytef *match; /* matched string */
  77691. register int len; /* length of current match */
  77692. int best_len = s->prev_length; /* best match length so far */
  77693. int nice_match = s->nice_match; /* stop if match long enough */
  77694. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77695. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77696. Posf *prev = s->prev;
  77697. uInt wmask = s->w_mask;
  77698. #ifdef UNALIGNED_OK
  77699. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77700. register ush scan_start = *(ushf*)scan;
  77701. register ush scan_end = *(ushf*)(scan+best_len-1);
  77702. #else
  77703. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77704. register Byte scan_end1 = scan[best_len-1];
  77705. register Byte scan_end = scan[best_len];
  77706. #endif
  77707. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77708. if (s->prev_length >= s->good_match) {
  77709. chain_length >>= 2;
  77710. }
  77711. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77712. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77713. do {
  77714. Assert(cur_match < s->strstart, "no future");
  77715. match = s->window + cur_match;
  77716. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77717. if (*(ushf*)(match+best_len-1) != scan_end ||
  77718. *(ushf*)match != scan_start) continue;
  77719. Assert(scan[2] == match[2], "scan[2]?");
  77720. scan++, match++;
  77721. do {
  77722. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77723. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77724. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77725. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77726. scan < strend);
  77727. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77728. if (*scan == *match) scan++;
  77729. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77730. scan = strend - (MAX_MATCH-1);
  77731. #else /* UNALIGNED_OK */
  77732. if (match[best_len] != scan_end ||
  77733. match[best_len-1] != scan_end1 ||
  77734. *match != *scan ||
  77735. *++match != scan[1]) continue;
  77736. scan += 2, match++;
  77737. Assert(*scan == *match, "match[2]?");
  77738. do {
  77739. } while (*++scan == *++match && *++scan == *++match &&
  77740. *++scan == *++match && *++scan == *++match &&
  77741. *++scan == *++match && *++scan == *++match &&
  77742. *++scan == *++match && *++scan == *++match &&
  77743. scan < strend);
  77744. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77745. len = MAX_MATCH - (int)(strend - scan);
  77746. scan = strend - MAX_MATCH;
  77747. #endif /* UNALIGNED_OK */
  77748. if (len > best_len) {
  77749. s->match_start = cur_match;
  77750. best_len = len;
  77751. if (len >= nice_match) break;
  77752. #ifdef UNALIGNED_OK
  77753. scan_end = *(ushf*)(scan+best_len-1);
  77754. #else
  77755. scan_end1 = scan[best_len-1];
  77756. scan_end = scan[best_len];
  77757. #endif
  77758. }
  77759. } while ((cur_match = prev[cur_match & wmask]) > limit
  77760. && --chain_length != 0);
  77761. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77762. return s->lookahead;
  77763. }
  77764. #endif /* ASMV */
  77765. #endif /* FASTEST */
  77766. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77767. {
  77768. register Bytef *scan = s->window + s->strstart; /* current string */
  77769. register Bytef *match; /* matched string */
  77770. register int len; /* length of current match */
  77771. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77772. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77773. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77774. Assert(cur_match < s->strstart, "no future");
  77775. match = s->window + cur_match;
  77776. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77777. scan += 2, match += 2;
  77778. Assert(*scan == *match, "match[2]?");
  77779. do {
  77780. } while (*++scan == *++match && *++scan == *++match &&
  77781. *++scan == *++match && *++scan == *++match &&
  77782. *++scan == *++match && *++scan == *++match &&
  77783. *++scan == *++match && *++scan == *++match &&
  77784. scan < strend);
  77785. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77786. len = MAX_MATCH - (int)(strend - scan);
  77787. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77788. s->match_start = cur_match;
  77789. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77790. }
  77791. #ifdef DEBUG
  77792. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77793. {
  77794. if (zmemcmp(s->window + match,
  77795. s->window + start, length) != EQUAL) {
  77796. fprintf(stderr, " start %u, match %u, length %d\n",
  77797. start, match, length);
  77798. do {
  77799. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77800. } while (--length != 0);
  77801. z_error("invalid match");
  77802. }
  77803. if (z_verbose > 1) {
  77804. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77805. do { putc(s->window[start++], stderr); } while (--length != 0);
  77806. }
  77807. }
  77808. #else
  77809. # define check_match(s, start, match, length)
  77810. #endif /* DEBUG */
  77811. local void fill_window (deflate_state *s)
  77812. {
  77813. register unsigned n, m;
  77814. register Posf *p;
  77815. unsigned more; /* Amount of free space at the end of the window. */
  77816. uInt wsize = s->w_size;
  77817. do {
  77818. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77819. if (sizeof(int) <= 2) {
  77820. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77821. more = wsize;
  77822. } else if (more == (unsigned)(-1)) {
  77823. more--;
  77824. }
  77825. }
  77826. if (s->strstart >= wsize+MAX_DIST(s)) {
  77827. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77828. s->match_start -= wsize;
  77829. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77830. s->block_start -= (long) wsize;
  77831. n = s->hash_size;
  77832. p = &s->head[n];
  77833. do {
  77834. m = *--p;
  77835. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77836. } while (--n);
  77837. n = wsize;
  77838. #ifndef FASTEST
  77839. p = &s->prev[n];
  77840. do {
  77841. m = *--p;
  77842. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77843. } while (--n);
  77844. #endif
  77845. more += wsize;
  77846. }
  77847. if (s->strm->avail_in == 0) return;
  77848. Assert(more >= 2, "more < 2");
  77849. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77850. s->lookahead += n;
  77851. if (s->lookahead >= MIN_MATCH) {
  77852. s->ins_h = s->window[s->strstart];
  77853. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77854. #if MIN_MATCH != 3
  77855. Call UPDATE_HASH() MIN_MATCH-3 more times
  77856. #endif
  77857. }
  77858. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77859. }
  77860. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77861. _tr_flush_block(s, (s->block_start >= 0L ? \
  77862. (charf *)&s->window[(unsigned)s->block_start] : \
  77863. (charf *)Z_NULL), \
  77864. (ulg)((long)s->strstart - s->block_start), \
  77865. (eof)); \
  77866. s->block_start = s->strstart; \
  77867. flush_pending(s->strm); \
  77868. Tracev((stderr,"[FLUSH]")); \
  77869. }
  77870. #define FLUSH_BLOCK(s, eof) { \
  77871. FLUSH_BLOCK_ONLY(s, eof); \
  77872. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77873. }
  77874. local block_state deflate_stored(deflate_state *s, int flush)
  77875. {
  77876. ulg max_block_size = 0xffff;
  77877. ulg max_start;
  77878. if (max_block_size > s->pending_buf_size - 5) {
  77879. max_block_size = s->pending_buf_size - 5;
  77880. }
  77881. for (;;) {
  77882. if (s->lookahead <= 1) {
  77883. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77884. s->block_start >= (long)s->w_size, "slide too late");
  77885. fill_window(s);
  77886. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77887. if (s->lookahead == 0) break; /* flush the current block */
  77888. }
  77889. Assert(s->block_start >= 0L, "block gone");
  77890. s->strstart += s->lookahead;
  77891. s->lookahead = 0;
  77892. max_start = s->block_start + max_block_size;
  77893. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77894. s->lookahead = (uInt)(s->strstart - max_start);
  77895. s->strstart = (uInt)max_start;
  77896. FLUSH_BLOCK(s, 0);
  77897. }
  77898. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77899. FLUSH_BLOCK(s, 0);
  77900. }
  77901. }
  77902. FLUSH_BLOCK(s, flush == Z_FINISH);
  77903. return flush == Z_FINISH ? finish_done : block_done;
  77904. }
  77905. local block_state deflate_fast(deflate_state *s, int flush)
  77906. {
  77907. IPos hash_head = NIL; /* head of the hash chain */
  77908. int bflush; /* set if current block must be flushed */
  77909. for (;;) {
  77910. if (s->lookahead < MIN_LOOKAHEAD) {
  77911. fill_window(s);
  77912. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77913. return need_more;
  77914. }
  77915. if (s->lookahead == 0) break; /* flush the current block */
  77916. }
  77917. if (s->lookahead >= MIN_MATCH) {
  77918. INSERT_STRING(s, s->strstart, hash_head);
  77919. }
  77920. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77921. #ifdef FASTEST
  77922. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77923. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77924. s->match_length = longest_match_fast (s, hash_head);
  77925. }
  77926. #else
  77927. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77928. s->match_length = longest_match (s, hash_head);
  77929. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77930. s->match_length = longest_match_fast (s, hash_head);
  77931. }
  77932. #endif
  77933. }
  77934. if (s->match_length >= MIN_MATCH) {
  77935. check_match(s, s->strstart, s->match_start, s->match_length);
  77936. _tr_tally_dist(s, s->strstart - s->match_start,
  77937. s->match_length - MIN_MATCH, bflush);
  77938. s->lookahead -= s->match_length;
  77939. #ifndef FASTEST
  77940. if (s->match_length <= s->max_insert_length &&
  77941. s->lookahead >= MIN_MATCH) {
  77942. s->match_length--; /* string at strstart already in table */
  77943. do {
  77944. s->strstart++;
  77945. INSERT_STRING(s, s->strstart, hash_head);
  77946. } while (--s->match_length != 0);
  77947. s->strstart++;
  77948. } else
  77949. #endif
  77950. {
  77951. s->strstart += s->match_length;
  77952. s->match_length = 0;
  77953. s->ins_h = s->window[s->strstart];
  77954. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77955. #if MIN_MATCH != 3
  77956. Call UPDATE_HASH() MIN_MATCH-3 more times
  77957. #endif
  77958. }
  77959. } else {
  77960. Tracevv((stderr,"%c", s->window[s->strstart]));
  77961. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77962. s->lookahead--;
  77963. s->strstart++;
  77964. }
  77965. if (bflush) FLUSH_BLOCK(s, 0);
  77966. }
  77967. FLUSH_BLOCK(s, flush == Z_FINISH);
  77968. return flush == Z_FINISH ? finish_done : block_done;
  77969. }
  77970. #ifndef FASTEST
  77971. local block_state deflate_slow(deflate_state *s, int flush)
  77972. {
  77973. IPos hash_head = NIL; /* head of hash chain */
  77974. int bflush; /* set if current block must be flushed */
  77975. for (;;) {
  77976. if (s->lookahead < MIN_LOOKAHEAD) {
  77977. fill_window(s);
  77978. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77979. return need_more;
  77980. }
  77981. if (s->lookahead == 0) break; /* flush the current block */
  77982. }
  77983. if (s->lookahead >= MIN_MATCH) {
  77984. INSERT_STRING(s, s->strstart, hash_head);
  77985. }
  77986. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77987. s->match_length = MIN_MATCH-1;
  77988. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77989. s->strstart - hash_head <= MAX_DIST(s)) {
  77990. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77991. s->match_length = longest_match (s, hash_head);
  77992. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77993. s->match_length = longest_match_fast (s, hash_head);
  77994. }
  77995. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77996. #if TOO_FAR <= 32767
  77997. || (s->match_length == MIN_MATCH &&
  77998. s->strstart - s->match_start > TOO_FAR)
  77999. #endif
  78000. )) {
  78001. s->match_length = MIN_MATCH-1;
  78002. }
  78003. }
  78004. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  78005. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  78006. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  78007. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  78008. s->prev_length - MIN_MATCH, bflush);
  78009. s->lookahead -= s->prev_length-1;
  78010. s->prev_length -= 2;
  78011. do {
  78012. if (++s->strstart <= max_insert) {
  78013. INSERT_STRING(s, s->strstart, hash_head);
  78014. }
  78015. } while (--s->prev_length != 0);
  78016. s->match_available = 0;
  78017. s->match_length = MIN_MATCH-1;
  78018. s->strstart++;
  78019. if (bflush) FLUSH_BLOCK(s, 0);
  78020. } else if (s->match_available) {
  78021. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78022. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78023. if (bflush) {
  78024. FLUSH_BLOCK_ONLY(s, 0);
  78025. }
  78026. s->strstart++;
  78027. s->lookahead--;
  78028. if (s->strm->avail_out == 0) return need_more;
  78029. } else {
  78030. s->match_available = 1;
  78031. s->strstart++;
  78032. s->lookahead--;
  78033. }
  78034. }
  78035. Assert (flush != Z_NO_FLUSH, "no flush?");
  78036. if (s->match_available) {
  78037. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78038. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78039. s->match_available = 0;
  78040. }
  78041. FLUSH_BLOCK(s, flush == Z_FINISH);
  78042. return flush == Z_FINISH ? finish_done : block_done;
  78043. }
  78044. #endif /* FASTEST */
  78045. #if 0
  78046. local block_state deflate_rle(s, flush)
  78047. deflate_state *s;
  78048. int flush;
  78049. {
  78050. int bflush; /* set if current block must be flushed */
  78051. uInt run; /* length of run */
  78052. uInt max; /* maximum length of run */
  78053. uInt prev; /* byte at distance one to match */
  78054. Bytef *scan; /* scan for end of run */
  78055. for (;;) {
  78056. if (s->lookahead < MAX_MATCH) {
  78057. fill_window(s);
  78058. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  78059. return need_more;
  78060. }
  78061. if (s->lookahead == 0) break; /* flush the current block */
  78062. }
  78063. run = 0;
  78064. if (s->strstart > 0) { /* if there is a previous byte, that is */
  78065. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  78066. scan = s->window + s->strstart - 1;
  78067. prev = *scan++;
  78068. do {
  78069. if (*scan++ != prev)
  78070. break;
  78071. } while (++run < max);
  78072. }
  78073. if (run >= MIN_MATCH) {
  78074. check_match(s, s->strstart, s->strstart - 1, run);
  78075. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  78076. s->lookahead -= run;
  78077. s->strstart += run;
  78078. } else {
  78079. Tracevv((stderr,"%c", s->window[s->strstart]));
  78080. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78081. s->lookahead--;
  78082. s->strstart++;
  78083. }
  78084. if (bflush) FLUSH_BLOCK(s, 0);
  78085. }
  78086. FLUSH_BLOCK(s, flush == Z_FINISH);
  78087. return flush == Z_FINISH ? finish_done : block_done;
  78088. }
  78089. #endif
  78090. /*** End of inlined file: deflate.c ***/
  78091. /*** Start of inlined file: inffast.c ***/
  78092. /*** Start of inlined file: inftrees.h ***/
  78093. #ifndef _INFTREES_H_
  78094. #define _INFTREES_H_
  78095. typedef struct {
  78096. unsigned char op; /* operation, extra bits, table bits */
  78097. unsigned char bits; /* bits in this part of the code */
  78098. unsigned short val; /* offset in table or code value */
  78099. } code;
  78100. #define ENOUGH 2048
  78101. #define MAXD 592
  78102. typedef enum {
  78103. CODES,
  78104. LENS,
  78105. DISTS
  78106. } codetype;
  78107. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78108. unsigned codes, code FAR * FAR *table,
  78109. unsigned FAR *bits, unsigned short FAR *work));
  78110. #endif
  78111. /*** End of inlined file: inftrees.h ***/
  78112. /*** Start of inlined file: inflate.h ***/
  78113. #ifndef _INFLATE_H_
  78114. #define _INFLATE_H_
  78115. #ifndef NO_GZIP
  78116. # define GUNZIP
  78117. #endif
  78118. typedef enum {
  78119. HEAD, /* i: waiting for magic header */
  78120. FLAGS, /* i: waiting for method and flags (gzip) */
  78121. TIME, /* i: waiting for modification time (gzip) */
  78122. OS, /* i: waiting for extra flags and operating system (gzip) */
  78123. EXLEN, /* i: waiting for extra length (gzip) */
  78124. EXTRA, /* i: waiting for extra bytes (gzip) */
  78125. NAME, /* i: waiting for end of file name (gzip) */
  78126. COMMENT, /* i: waiting for end of comment (gzip) */
  78127. HCRC, /* i: waiting for header crc (gzip) */
  78128. DICTID, /* i: waiting for dictionary check value */
  78129. DICT, /* waiting for inflateSetDictionary() call */
  78130. TYPE, /* i: waiting for type bits, including last-flag bit */
  78131. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78132. STORED, /* i: waiting for stored size (length and complement) */
  78133. COPY, /* i/o: waiting for input or output to copy stored block */
  78134. TABLE, /* i: waiting for dynamic block table lengths */
  78135. LENLENS, /* i: waiting for code length code lengths */
  78136. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78137. LEN, /* i: waiting for length/lit code */
  78138. LENEXT, /* i: waiting for length extra bits */
  78139. DIST, /* i: waiting for distance code */
  78140. DISTEXT, /* i: waiting for distance extra bits */
  78141. MATCH, /* o: waiting for output space to copy string */
  78142. LIT, /* o: waiting for output space to write literal */
  78143. CHECK, /* i: waiting for 32-bit check value */
  78144. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78145. DONE, /* finished check, done -- remain here until reset */
  78146. BAD, /* got a data error -- remain here until reset */
  78147. MEM, /* got an inflate() memory error -- remain here until reset */
  78148. SYNC /* looking for synchronization bytes to restart inflate() */
  78149. } inflate_mode;
  78150. struct inflate_state {
  78151. inflate_mode mode; /* current inflate mode */
  78152. int last; /* true if processing last block */
  78153. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78154. int havedict; /* true if dictionary provided */
  78155. int flags; /* gzip header method and flags (0 if zlib) */
  78156. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78157. unsigned long check; /* protected copy of check value */
  78158. unsigned long total; /* protected copy of output count */
  78159. gz_headerp head; /* where to save gzip header information */
  78160. unsigned wbits; /* log base 2 of requested window size */
  78161. unsigned wsize; /* window size or zero if not using window */
  78162. unsigned whave; /* valid bytes in the window */
  78163. unsigned write; /* window write index */
  78164. unsigned char FAR *window; /* allocated sliding window, if needed */
  78165. unsigned long hold; /* input bit accumulator */
  78166. unsigned bits; /* number of bits in "in" */
  78167. unsigned length; /* literal or length of data to copy */
  78168. unsigned offset; /* distance back to copy string from */
  78169. unsigned extra; /* extra bits needed */
  78170. code const FAR *lencode; /* starting table for length/literal codes */
  78171. code const FAR *distcode; /* starting table for distance codes */
  78172. unsigned lenbits; /* index bits for lencode */
  78173. unsigned distbits; /* index bits for distcode */
  78174. unsigned ncode; /* number of code length code lengths */
  78175. unsigned nlen; /* number of length code lengths */
  78176. unsigned ndist; /* number of distance code lengths */
  78177. unsigned have; /* number of code lengths in lens[] */
  78178. code FAR *next; /* next available space in codes[] */
  78179. unsigned short lens[320]; /* temporary storage for code lengths */
  78180. unsigned short work[288]; /* work area for code table building */
  78181. code codes[ENOUGH]; /* space for code tables */
  78182. };
  78183. #endif
  78184. /*** End of inlined file: inflate.h ***/
  78185. /*** Start of inlined file: inffast.h ***/
  78186. void inflate_fast OF((z_streamp strm, unsigned start));
  78187. /*** End of inlined file: inffast.h ***/
  78188. #ifndef ASMINF
  78189. #ifdef POSTINC
  78190. # define OFF 0
  78191. # define PUP(a) *(a)++
  78192. #else
  78193. # define OFF 1
  78194. # define PUP(a) *++(a)
  78195. #endif
  78196. void inflate_fast (z_streamp strm, unsigned start)
  78197. {
  78198. struct inflate_state FAR *state;
  78199. unsigned char FAR *in; /* local strm->next_in */
  78200. unsigned char FAR *last; /* while in < last, enough input available */
  78201. unsigned char FAR *out; /* local strm->next_out */
  78202. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78203. unsigned char FAR *end; /* while out < end, enough space available */
  78204. #ifdef INFLATE_STRICT
  78205. unsigned dmax; /* maximum distance from zlib header */
  78206. #endif
  78207. unsigned wsize; /* window size or zero if not using window */
  78208. unsigned whave; /* valid bytes in the window */
  78209. unsigned write; /* window write index */
  78210. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78211. unsigned long hold; /* local strm->hold */
  78212. unsigned bits; /* local strm->bits */
  78213. code const FAR *lcode; /* local strm->lencode */
  78214. code const FAR *dcode; /* local strm->distcode */
  78215. unsigned lmask; /* mask for first level of length codes */
  78216. unsigned dmask; /* mask for first level of distance codes */
  78217. code thisx; /* retrieved table entry */
  78218. unsigned op; /* code bits, operation, extra bits, or */
  78219. unsigned len; /* match length, unused bytes */
  78220. unsigned dist; /* match distance */
  78221. unsigned char FAR *from; /* where to copy match from */
  78222. state = (struct inflate_state FAR *)strm->state;
  78223. in = strm->next_in - OFF;
  78224. last = in + (strm->avail_in - 5);
  78225. out = strm->next_out - OFF;
  78226. beg = out - (start - strm->avail_out);
  78227. end = out + (strm->avail_out - 257);
  78228. #ifdef INFLATE_STRICT
  78229. dmax = state->dmax;
  78230. #endif
  78231. wsize = state->wsize;
  78232. whave = state->whave;
  78233. write = state->write;
  78234. window = state->window;
  78235. hold = state->hold;
  78236. bits = state->bits;
  78237. lcode = state->lencode;
  78238. dcode = state->distcode;
  78239. lmask = (1U << state->lenbits) - 1;
  78240. dmask = (1U << state->distbits) - 1;
  78241. do {
  78242. if (bits < 15) {
  78243. hold += (unsigned long)(PUP(in)) << bits;
  78244. bits += 8;
  78245. hold += (unsigned long)(PUP(in)) << bits;
  78246. bits += 8;
  78247. }
  78248. thisx = lcode[hold & lmask];
  78249. dolen:
  78250. op = (unsigned)(thisx.bits);
  78251. hold >>= op;
  78252. bits -= op;
  78253. op = (unsigned)(thisx.op);
  78254. if (op == 0) { /* literal */
  78255. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78256. "inflate: literal '%c'\n" :
  78257. "inflate: literal 0x%02x\n", thisx.val));
  78258. PUP(out) = (unsigned char)(thisx.val);
  78259. }
  78260. else if (op & 16) { /* length base */
  78261. len = (unsigned)(thisx.val);
  78262. op &= 15; /* number of extra bits */
  78263. if (op) {
  78264. if (bits < op) {
  78265. hold += (unsigned long)(PUP(in)) << bits;
  78266. bits += 8;
  78267. }
  78268. len += (unsigned)hold & ((1U << op) - 1);
  78269. hold >>= op;
  78270. bits -= op;
  78271. }
  78272. Tracevv((stderr, "inflate: length %u\n", len));
  78273. if (bits < 15) {
  78274. hold += (unsigned long)(PUP(in)) << bits;
  78275. bits += 8;
  78276. hold += (unsigned long)(PUP(in)) << bits;
  78277. bits += 8;
  78278. }
  78279. thisx = dcode[hold & dmask];
  78280. dodist:
  78281. op = (unsigned)(thisx.bits);
  78282. hold >>= op;
  78283. bits -= op;
  78284. op = (unsigned)(thisx.op);
  78285. if (op & 16) { /* distance base */
  78286. dist = (unsigned)(thisx.val);
  78287. op &= 15; /* number of extra bits */
  78288. if (bits < op) {
  78289. hold += (unsigned long)(PUP(in)) << bits;
  78290. bits += 8;
  78291. if (bits < op) {
  78292. hold += (unsigned long)(PUP(in)) << bits;
  78293. bits += 8;
  78294. }
  78295. }
  78296. dist += (unsigned)hold & ((1U << op) - 1);
  78297. #ifdef INFLATE_STRICT
  78298. if (dist > dmax) {
  78299. strm->msg = (char *)"invalid distance too far back";
  78300. state->mode = BAD;
  78301. break;
  78302. }
  78303. #endif
  78304. hold >>= op;
  78305. bits -= op;
  78306. Tracevv((stderr, "inflate: distance %u\n", dist));
  78307. op = (unsigned)(out - beg); /* max distance in output */
  78308. if (dist > op) { /* see if copy from window */
  78309. op = dist - op; /* distance back in window */
  78310. if (op > whave) {
  78311. strm->msg = (char *)"invalid distance too far back";
  78312. state->mode = BAD;
  78313. break;
  78314. }
  78315. from = window - OFF;
  78316. if (write == 0) { /* very common case */
  78317. from += wsize - op;
  78318. if (op < len) { /* some from window */
  78319. len -= op;
  78320. do {
  78321. PUP(out) = PUP(from);
  78322. } while (--op);
  78323. from = out - dist; /* rest from output */
  78324. }
  78325. }
  78326. else if (write < op) { /* wrap around window */
  78327. from += wsize + write - op;
  78328. op -= write;
  78329. if (op < len) { /* some from end of window */
  78330. len -= op;
  78331. do {
  78332. PUP(out) = PUP(from);
  78333. } while (--op);
  78334. from = window - OFF;
  78335. if (write < len) { /* some from start of window */
  78336. op = write;
  78337. len -= op;
  78338. do {
  78339. PUP(out) = PUP(from);
  78340. } while (--op);
  78341. from = out - dist; /* rest from output */
  78342. }
  78343. }
  78344. }
  78345. else { /* contiguous in window */
  78346. from += write - op;
  78347. if (op < len) { /* some from window */
  78348. len -= op;
  78349. do {
  78350. PUP(out) = PUP(from);
  78351. } while (--op);
  78352. from = out - dist; /* rest from output */
  78353. }
  78354. }
  78355. while (len > 2) {
  78356. PUP(out) = PUP(from);
  78357. PUP(out) = PUP(from);
  78358. PUP(out) = PUP(from);
  78359. len -= 3;
  78360. }
  78361. if (len) {
  78362. PUP(out) = PUP(from);
  78363. if (len > 1)
  78364. PUP(out) = PUP(from);
  78365. }
  78366. }
  78367. else {
  78368. from = out - dist; /* copy direct from output */
  78369. do { /* minimum length is three */
  78370. PUP(out) = PUP(from);
  78371. PUP(out) = PUP(from);
  78372. PUP(out) = PUP(from);
  78373. len -= 3;
  78374. } while (len > 2);
  78375. if (len) {
  78376. PUP(out) = PUP(from);
  78377. if (len > 1)
  78378. PUP(out) = PUP(from);
  78379. }
  78380. }
  78381. }
  78382. else if ((op & 64) == 0) { /* 2nd level distance code */
  78383. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78384. goto dodist;
  78385. }
  78386. else {
  78387. strm->msg = (char *)"invalid distance code";
  78388. state->mode = BAD;
  78389. break;
  78390. }
  78391. }
  78392. else if ((op & 64) == 0) { /* 2nd level length code */
  78393. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78394. goto dolen;
  78395. }
  78396. else if (op & 32) { /* end-of-block */
  78397. Tracevv((stderr, "inflate: end of block\n"));
  78398. state->mode = TYPE;
  78399. break;
  78400. }
  78401. else {
  78402. strm->msg = (char *)"invalid literal/length code";
  78403. state->mode = BAD;
  78404. break;
  78405. }
  78406. } while (in < last && out < end);
  78407. len = bits >> 3;
  78408. in -= len;
  78409. bits -= len << 3;
  78410. hold &= (1U << bits) - 1;
  78411. strm->next_in = in + OFF;
  78412. strm->next_out = out + OFF;
  78413. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78414. strm->avail_out = (unsigned)(out < end ?
  78415. 257 + (end - out) : 257 - (out - end));
  78416. state->hold = hold;
  78417. state->bits = bits;
  78418. return;
  78419. }
  78420. #endif /* !ASMINF */
  78421. /*** End of inlined file: inffast.c ***/
  78422. #undef PULLBYTE
  78423. #undef LOAD
  78424. #undef RESTORE
  78425. #undef INITBITS
  78426. #undef NEEDBITS
  78427. #undef DROPBITS
  78428. #undef BYTEBITS
  78429. /*** Start of inlined file: inflate.c ***/
  78430. /*** Start of inlined file: inffast.h ***/
  78431. void inflate_fast OF((z_streamp strm, unsigned start));
  78432. /*** End of inlined file: inffast.h ***/
  78433. #ifdef MAKEFIXED
  78434. # ifndef BUILDFIXED
  78435. # define BUILDFIXED
  78436. # endif
  78437. #endif
  78438. local void fixedtables OF((struct inflate_state FAR *state));
  78439. local int updatewindow OF((z_streamp strm, unsigned out));
  78440. #ifdef BUILDFIXED
  78441. void makefixed OF((void));
  78442. #endif
  78443. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78444. unsigned len));
  78445. int ZEXPORT inflateReset (z_streamp strm)
  78446. {
  78447. struct inflate_state FAR *state;
  78448. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78449. state = (struct inflate_state FAR *)strm->state;
  78450. strm->total_in = strm->total_out = state->total = 0;
  78451. strm->msg = Z_NULL;
  78452. strm->adler = 1; /* to support ill-conceived Java test suite */
  78453. state->mode = HEAD;
  78454. state->last = 0;
  78455. state->havedict = 0;
  78456. state->dmax = 32768U;
  78457. state->head = Z_NULL;
  78458. state->wsize = 0;
  78459. state->whave = 0;
  78460. state->write = 0;
  78461. state->hold = 0;
  78462. state->bits = 0;
  78463. state->lencode = state->distcode = state->next = state->codes;
  78464. Tracev((stderr, "inflate: reset\n"));
  78465. return Z_OK;
  78466. }
  78467. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78468. {
  78469. struct inflate_state FAR *state;
  78470. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78471. state = (struct inflate_state FAR *)strm->state;
  78472. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78473. value &= (1L << bits) - 1;
  78474. state->hold += value << state->bits;
  78475. state->bits += bits;
  78476. return Z_OK;
  78477. }
  78478. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78479. {
  78480. struct inflate_state FAR *state;
  78481. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78482. stream_size != (int)(sizeof(z_stream)))
  78483. return Z_VERSION_ERROR;
  78484. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78485. strm->msg = Z_NULL; /* in case we return an error */
  78486. if (strm->zalloc == (alloc_func)0) {
  78487. strm->zalloc = zcalloc;
  78488. strm->opaque = (voidpf)0;
  78489. }
  78490. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78491. state = (struct inflate_state FAR *)
  78492. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78493. if (state == Z_NULL) return Z_MEM_ERROR;
  78494. Tracev((stderr, "inflate: allocated\n"));
  78495. strm->state = (struct internal_state FAR *)state;
  78496. if (windowBits < 0) {
  78497. state->wrap = 0;
  78498. windowBits = -windowBits;
  78499. }
  78500. else {
  78501. state->wrap = (windowBits >> 4) + 1;
  78502. #ifdef GUNZIP
  78503. if (windowBits < 48) windowBits &= 15;
  78504. #endif
  78505. }
  78506. if (windowBits < 8 || windowBits > 15) {
  78507. ZFREE(strm, state);
  78508. strm->state = Z_NULL;
  78509. return Z_STREAM_ERROR;
  78510. }
  78511. state->wbits = (unsigned)windowBits;
  78512. state->window = Z_NULL;
  78513. return inflateReset(strm);
  78514. }
  78515. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78516. {
  78517. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78518. }
  78519. local void fixedtables (struct inflate_state FAR *state)
  78520. {
  78521. #ifdef BUILDFIXED
  78522. static int virgin = 1;
  78523. static code *lenfix, *distfix;
  78524. static code fixed[544];
  78525. if (virgin) {
  78526. unsigned sym, bits;
  78527. static code *next;
  78528. sym = 0;
  78529. while (sym < 144) state->lens[sym++] = 8;
  78530. while (sym < 256) state->lens[sym++] = 9;
  78531. while (sym < 280) state->lens[sym++] = 7;
  78532. while (sym < 288) state->lens[sym++] = 8;
  78533. next = fixed;
  78534. lenfix = next;
  78535. bits = 9;
  78536. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78537. sym = 0;
  78538. while (sym < 32) state->lens[sym++] = 5;
  78539. distfix = next;
  78540. bits = 5;
  78541. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78542. virgin = 0;
  78543. }
  78544. #else /* !BUILDFIXED */
  78545. /*** Start of inlined file: inffixed.h ***/
  78546. static const code lenfix[512] = {
  78547. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78548. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78549. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78550. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78551. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78552. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78553. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78554. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78555. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78556. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78557. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78558. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78559. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78560. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78561. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78562. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78563. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78564. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78565. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78566. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78567. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78568. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78569. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78570. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78571. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78572. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78573. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78574. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78575. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78576. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78577. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78578. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78579. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78580. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78581. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78582. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78583. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78584. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78585. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78586. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78587. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78588. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78589. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78590. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78591. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78592. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78593. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78594. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78595. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78596. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78597. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78598. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78599. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78600. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78601. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78602. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78603. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78604. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78605. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78606. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78607. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78608. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78609. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78610. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78611. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78612. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78613. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78614. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78615. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78616. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78617. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78618. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78619. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78620. {0,9,255}
  78621. };
  78622. static const code distfix[32] = {
  78623. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78624. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78625. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78626. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78627. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78628. {22,5,193},{64,5,0}
  78629. };
  78630. /*** End of inlined file: inffixed.h ***/
  78631. #endif /* BUILDFIXED */
  78632. state->lencode = lenfix;
  78633. state->lenbits = 9;
  78634. state->distcode = distfix;
  78635. state->distbits = 5;
  78636. }
  78637. #ifdef MAKEFIXED
  78638. #include <stdio.h>
  78639. void makefixed()
  78640. {
  78641. unsigned low, size;
  78642. struct inflate_state state;
  78643. fixedtables(&state);
  78644. puts(" /* inffixed.h -- table for decoding fixed codes");
  78645. puts(" * Generated automatically by makefixed().");
  78646. puts(" */");
  78647. puts("");
  78648. puts(" /* WARNING: this file should *not* be used by applications.");
  78649. puts(" It is part of the implementation of this library and is");
  78650. puts(" subject to change. Applications should only use zlib.h.");
  78651. puts(" */");
  78652. puts("");
  78653. size = 1U << 9;
  78654. printf(" static const code lenfix[%u] = {", size);
  78655. low = 0;
  78656. for (;;) {
  78657. if ((low % 7) == 0) printf("\n ");
  78658. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78659. state.lencode[low].val);
  78660. if (++low == size) break;
  78661. putchar(',');
  78662. }
  78663. puts("\n };");
  78664. size = 1U << 5;
  78665. printf("\n static const code distfix[%u] = {", size);
  78666. low = 0;
  78667. for (;;) {
  78668. if ((low % 6) == 0) printf("\n ");
  78669. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78670. state.distcode[low].val);
  78671. if (++low == size) break;
  78672. putchar(',');
  78673. }
  78674. puts("\n };");
  78675. }
  78676. #endif /* MAKEFIXED */
  78677. local int updatewindow (z_streamp strm, unsigned out)
  78678. {
  78679. struct inflate_state FAR *state;
  78680. unsigned copy, dist;
  78681. state = (struct inflate_state FAR *)strm->state;
  78682. if (state->window == Z_NULL) {
  78683. state->window = (unsigned char FAR *)
  78684. ZALLOC(strm, 1U << state->wbits,
  78685. sizeof(unsigned char));
  78686. if (state->window == Z_NULL) return 1;
  78687. }
  78688. if (state->wsize == 0) {
  78689. state->wsize = 1U << state->wbits;
  78690. state->write = 0;
  78691. state->whave = 0;
  78692. }
  78693. copy = out - strm->avail_out;
  78694. if (copy >= state->wsize) {
  78695. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78696. state->write = 0;
  78697. state->whave = state->wsize;
  78698. }
  78699. else {
  78700. dist = state->wsize - state->write;
  78701. if (dist > copy) dist = copy;
  78702. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78703. copy -= dist;
  78704. if (copy) {
  78705. zmemcpy(state->window, strm->next_out - copy, copy);
  78706. state->write = copy;
  78707. state->whave = state->wsize;
  78708. }
  78709. else {
  78710. state->write += dist;
  78711. if (state->write == state->wsize) state->write = 0;
  78712. if (state->whave < state->wsize) state->whave += dist;
  78713. }
  78714. }
  78715. return 0;
  78716. }
  78717. #ifdef GUNZIP
  78718. # define UPDATE(check, buf, len) \
  78719. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78720. #else
  78721. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78722. #endif
  78723. #ifdef GUNZIP
  78724. # define CRC2(check, word) \
  78725. do { \
  78726. hbuf[0] = (unsigned char)(word); \
  78727. hbuf[1] = (unsigned char)((word) >> 8); \
  78728. check = crc32(check, hbuf, 2); \
  78729. } while (0)
  78730. # define CRC4(check, word) \
  78731. do { \
  78732. hbuf[0] = (unsigned char)(word); \
  78733. hbuf[1] = (unsigned char)((word) >> 8); \
  78734. hbuf[2] = (unsigned char)((word) >> 16); \
  78735. hbuf[3] = (unsigned char)((word) >> 24); \
  78736. check = crc32(check, hbuf, 4); \
  78737. } while (0)
  78738. #endif
  78739. #define LOAD() \
  78740. do { \
  78741. put = strm->next_out; \
  78742. left = strm->avail_out; \
  78743. next = strm->next_in; \
  78744. have = strm->avail_in; \
  78745. hold = state->hold; \
  78746. bits = state->bits; \
  78747. } while (0)
  78748. #define RESTORE() \
  78749. do { \
  78750. strm->next_out = put; \
  78751. strm->avail_out = left; \
  78752. strm->next_in = next; \
  78753. strm->avail_in = have; \
  78754. state->hold = hold; \
  78755. state->bits = bits; \
  78756. } while (0)
  78757. #define INITBITS() \
  78758. do { \
  78759. hold = 0; \
  78760. bits = 0; \
  78761. } while (0)
  78762. #define PULLBYTE() \
  78763. do { \
  78764. if (have == 0) goto inf_leave; \
  78765. have--; \
  78766. hold += (unsigned long)(*next++) << bits; \
  78767. bits += 8; \
  78768. } while (0)
  78769. #define NEEDBITS(n) \
  78770. do { \
  78771. while (bits < (unsigned)(n)) \
  78772. PULLBYTE(); \
  78773. } while (0)
  78774. #define BITS(n) \
  78775. ((unsigned)hold & ((1U << (n)) - 1))
  78776. #define DROPBITS(n) \
  78777. do { \
  78778. hold >>= (n); \
  78779. bits -= (unsigned)(n); \
  78780. } while (0)
  78781. #define BYTEBITS() \
  78782. do { \
  78783. hold >>= bits & 7; \
  78784. bits -= bits & 7; \
  78785. } while (0)
  78786. #define REVERSE(q) \
  78787. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78788. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78789. int ZEXPORT inflate (z_streamp strm, int flush)
  78790. {
  78791. struct inflate_state FAR *state;
  78792. unsigned char FAR *next; /* next input */
  78793. unsigned char FAR *put; /* next output */
  78794. unsigned have, left; /* available input and output */
  78795. unsigned long hold; /* bit buffer */
  78796. unsigned bits; /* bits in bit buffer */
  78797. unsigned in, out; /* save starting available input and output */
  78798. unsigned copy; /* number of stored or match bytes to copy */
  78799. unsigned char FAR *from; /* where to copy match bytes from */
  78800. code thisx; /* current decoding table entry */
  78801. code last; /* parent table entry */
  78802. unsigned len; /* length to copy for repeats, bits to drop */
  78803. int ret; /* return code */
  78804. #ifdef GUNZIP
  78805. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78806. #endif
  78807. static const unsigned short order[19] = /* permutation of code lengths */
  78808. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78809. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78810. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78811. return Z_STREAM_ERROR;
  78812. state = (struct inflate_state FAR *)strm->state;
  78813. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78814. LOAD();
  78815. in = have;
  78816. out = left;
  78817. ret = Z_OK;
  78818. for (;;)
  78819. switch (state->mode) {
  78820. case HEAD:
  78821. if (state->wrap == 0) {
  78822. state->mode = TYPEDO;
  78823. break;
  78824. }
  78825. NEEDBITS(16);
  78826. #ifdef GUNZIP
  78827. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78828. state->check = crc32(0L, Z_NULL, 0);
  78829. CRC2(state->check, hold);
  78830. INITBITS();
  78831. state->mode = FLAGS;
  78832. break;
  78833. }
  78834. state->flags = 0; /* expect zlib header */
  78835. if (state->head != Z_NULL)
  78836. state->head->done = -1;
  78837. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78838. #else
  78839. if (
  78840. #endif
  78841. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78842. strm->msg = (char *)"incorrect header check";
  78843. state->mode = BAD;
  78844. break;
  78845. }
  78846. if (BITS(4) != Z_DEFLATED) {
  78847. strm->msg = (char *)"unknown compression method";
  78848. state->mode = BAD;
  78849. break;
  78850. }
  78851. DROPBITS(4);
  78852. len = BITS(4) + 8;
  78853. if (len > state->wbits) {
  78854. strm->msg = (char *)"invalid window size";
  78855. state->mode = BAD;
  78856. break;
  78857. }
  78858. state->dmax = 1U << len;
  78859. Tracev((stderr, "inflate: zlib header ok\n"));
  78860. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78861. state->mode = hold & 0x200 ? DICTID : TYPE;
  78862. INITBITS();
  78863. break;
  78864. #ifdef GUNZIP
  78865. case FLAGS:
  78866. NEEDBITS(16);
  78867. state->flags = (int)(hold);
  78868. if ((state->flags & 0xff) != Z_DEFLATED) {
  78869. strm->msg = (char *)"unknown compression method";
  78870. state->mode = BAD;
  78871. break;
  78872. }
  78873. if (state->flags & 0xe000) {
  78874. strm->msg = (char *)"unknown header flags set";
  78875. state->mode = BAD;
  78876. break;
  78877. }
  78878. if (state->head != Z_NULL)
  78879. state->head->text = (int)((hold >> 8) & 1);
  78880. if (state->flags & 0x0200) CRC2(state->check, hold);
  78881. INITBITS();
  78882. state->mode = TIME;
  78883. case TIME:
  78884. NEEDBITS(32);
  78885. if (state->head != Z_NULL)
  78886. state->head->time = hold;
  78887. if (state->flags & 0x0200) CRC4(state->check, hold);
  78888. INITBITS();
  78889. state->mode = OS;
  78890. case OS:
  78891. NEEDBITS(16);
  78892. if (state->head != Z_NULL) {
  78893. state->head->xflags = (int)(hold & 0xff);
  78894. state->head->os = (int)(hold >> 8);
  78895. }
  78896. if (state->flags & 0x0200) CRC2(state->check, hold);
  78897. INITBITS();
  78898. state->mode = EXLEN;
  78899. case EXLEN:
  78900. if (state->flags & 0x0400) {
  78901. NEEDBITS(16);
  78902. state->length = (unsigned)(hold);
  78903. if (state->head != Z_NULL)
  78904. state->head->extra_len = (unsigned)hold;
  78905. if (state->flags & 0x0200) CRC2(state->check, hold);
  78906. INITBITS();
  78907. }
  78908. else if (state->head != Z_NULL)
  78909. state->head->extra = Z_NULL;
  78910. state->mode = EXTRA;
  78911. case EXTRA:
  78912. if (state->flags & 0x0400) {
  78913. copy = state->length;
  78914. if (copy > have) copy = have;
  78915. if (copy) {
  78916. if (state->head != Z_NULL &&
  78917. state->head->extra != Z_NULL) {
  78918. len = state->head->extra_len - state->length;
  78919. zmemcpy(state->head->extra + len, next,
  78920. len + copy > state->head->extra_max ?
  78921. state->head->extra_max - len : copy);
  78922. }
  78923. if (state->flags & 0x0200)
  78924. state->check = crc32(state->check, next, copy);
  78925. have -= copy;
  78926. next += copy;
  78927. state->length -= copy;
  78928. }
  78929. if (state->length) goto inf_leave;
  78930. }
  78931. state->length = 0;
  78932. state->mode = NAME;
  78933. case NAME:
  78934. if (state->flags & 0x0800) {
  78935. if (have == 0) goto inf_leave;
  78936. copy = 0;
  78937. do {
  78938. len = (unsigned)(next[copy++]);
  78939. if (state->head != Z_NULL &&
  78940. state->head->name != Z_NULL &&
  78941. state->length < state->head->name_max)
  78942. state->head->name[state->length++] = len;
  78943. } while (len && copy < have);
  78944. if (state->flags & 0x0200)
  78945. state->check = crc32(state->check, next, copy);
  78946. have -= copy;
  78947. next += copy;
  78948. if (len) goto inf_leave;
  78949. }
  78950. else if (state->head != Z_NULL)
  78951. state->head->name = Z_NULL;
  78952. state->length = 0;
  78953. state->mode = COMMENT;
  78954. case COMMENT:
  78955. if (state->flags & 0x1000) {
  78956. if (have == 0) goto inf_leave;
  78957. copy = 0;
  78958. do {
  78959. len = (unsigned)(next[copy++]);
  78960. if (state->head != Z_NULL &&
  78961. state->head->comment != Z_NULL &&
  78962. state->length < state->head->comm_max)
  78963. state->head->comment[state->length++] = len;
  78964. } while (len && copy < have);
  78965. if (state->flags & 0x0200)
  78966. state->check = crc32(state->check, next, copy);
  78967. have -= copy;
  78968. next += copy;
  78969. if (len) goto inf_leave;
  78970. }
  78971. else if (state->head != Z_NULL)
  78972. state->head->comment = Z_NULL;
  78973. state->mode = HCRC;
  78974. case HCRC:
  78975. if (state->flags & 0x0200) {
  78976. NEEDBITS(16);
  78977. if (hold != (state->check & 0xffff)) {
  78978. strm->msg = (char *)"header crc mismatch";
  78979. state->mode = BAD;
  78980. break;
  78981. }
  78982. INITBITS();
  78983. }
  78984. if (state->head != Z_NULL) {
  78985. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78986. state->head->done = 1;
  78987. }
  78988. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78989. state->mode = TYPE;
  78990. break;
  78991. #endif
  78992. case DICTID:
  78993. NEEDBITS(32);
  78994. strm->adler = state->check = REVERSE(hold);
  78995. INITBITS();
  78996. state->mode = DICT;
  78997. case DICT:
  78998. if (state->havedict == 0) {
  78999. RESTORE();
  79000. return Z_NEED_DICT;
  79001. }
  79002. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  79003. state->mode = TYPE;
  79004. case TYPE:
  79005. if (flush == Z_BLOCK) goto inf_leave;
  79006. case TYPEDO:
  79007. if (state->last) {
  79008. BYTEBITS();
  79009. state->mode = CHECK;
  79010. break;
  79011. }
  79012. NEEDBITS(3);
  79013. state->last = BITS(1);
  79014. DROPBITS(1);
  79015. switch (BITS(2)) {
  79016. case 0: /* stored block */
  79017. Tracev((stderr, "inflate: stored block%s\n",
  79018. state->last ? " (last)" : ""));
  79019. state->mode = STORED;
  79020. break;
  79021. case 1: /* fixed block */
  79022. fixedtables(state);
  79023. Tracev((stderr, "inflate: fixed codes block%s\n",
  79024. state->last ? " (last)" : ""));
  79025. state->mode = LEN; /* decode codes */
  79026. break;
  79027. case 2: /* dynamic block */
  79028. Tracev((stderr, "inflate: dynamic codes block%s\n",
  79029. state->last ? " (last)" : ""));
  79030. state->mode = TABLE;
  79031. break;
  79032. case 3:
  79033. strm->msg = (char *)"invalid block type";
  79034. state->mode = BAD;
  79035. }
  79036. DROPBITS(2);
  79037. break;
  79038. case STORED:
  79039. BYTEBITS(); /* go to byte boundary */
  79040. NEEDBITS(32);
  79041. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  79042. strm->msg = (char *)"invalid stored block lengths";
  79043. state->mode = BAD;
  79044. break;
  79045. }
  79046. state->length = (unsigned)hold & 0xffff;
  79047. Tracev((stderr, "inflate: stored length %u\n",
  79048. state->length));
  79049. INITBITS();
  79050. state->mode = COPY;
  79051. case COPY:
  79052. copy = state->length;
  79053. if (copy) {
  79054. if (copy > have) copy = have;
  79055. if (copy > left) copy = left;
  79056. if (copy == 0) goto inf_leave;
  79057. zmemcpy(put, next, copy);
  79058. have -= copy;
  79059. next += copy;
  79060. left -= copy;
  79061. put += copy;
  79062. state->length -= copy;
  79063. break;
  79064. }
  79065. Tracev((stderr, "inflate: stored end\n"));
  79066. state->mode = TYPE;
  79067. break;
  79068. case TABLE:
  79069. NEEDBITS(14);
  79070. state->nlen = BITS(5) + 257;
  79071. DROPBITS(5);
  79072. state->ndist = BITS(5) + 1;
  79073. DROPBITS(5);
  79074. state->ncode = BITS(4) + 4;
  79075. DROPBITS(4);
  79076. #ifndef PKZIP_BUG_WORKAROUND
  79077. if (state->nlen > 286 || state->ndist > 30) {
  79078. strm->msg = (char *)"too many length or distance symbols";
  79079. state->mode = BAD;
  79080. break;
  79081. }
  79082. #endif
  79083. Tracev((stderr, "inflate: table sizes ok\n"));
  79084. state->have = 0;
  79085. state->mode = LENLENS;
  79086. case LENLENS:
  79087. while (state->have < state->ncode) {
  79088. NEEDBITS(3);
  79089. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  79090. DROPBITS(3);
  79091. }
  79092. while (state->have < 19)
  79093. state->lens[order[state->have++]] = 0;
  79094. state->next = state->codes;
  79095. state->lencode = (code const FAR *)(state->next);
  79096. state->lenbits = 7;
  79097. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79098. &(state->lenbits), state->work);
  79099. if (ret) {
  79100. strm->msg = (char *)"invalid code lengths set";
  79101. state->mode = BAD;
  79102. break;
  79103. }
  79104. Tracev((stderr, "inflate: code lengths ok\n"));
  79105. state->have = 0;
  79106. state->mode = CODELENS;
  79107. case CODELENS:
  79108. while (state->have < state->nlen + state->ndist) {
  79109. for (;;) {
  79110. thisx = state->lencode[BITS(state->lenbits)];
  79111. if ((unsigned)(thisx.bits) <= bits) break;
  79112. PULLBYTE();
  79113. }
  79114. if (thisx.val < 16) {
  79115. NEEDBITS(thisx.bits);
  79116. DROPBITS(thisx.bits);
  79117. state->lens[state->have++] = thisx.val;
  79118. }
  79119. else {
  79120. if (thisx.val == 16) {
  79121. NEEDBITS(thisx.bits + 2);
  79122. DROPBITS(thisx.bits);
  79123. if (state->have == 0) {
  79124. strm->msg = (char *)"invalid bit length repeat";
  79125. state->mode = BAD;
  79126. break;
  79127. }
  79128. len = state->lens[state->have - 1];
  79129. copy = 3 + BITS(2);
  79130. DROPBITS(2);
  79131. }
  79132. else if (thisx.val == 17) {
  79133. NEEDBITS(thisx.bits + 3);
  79134. DROPBITS(thisx.bits);
  79135. len = 0;
  79136. copy = 3 + BITS(3);
  79137. DROPBITS(3);
  79138. }
  79139. else {
  79140. NEEDBITS(thisx.bits + 7);
  79141. DROPBITS(thisx.bits);
  79142. len = 0;
  79143. copy = 11 + BITS(7);
  79144. DROPBITS(7);
  79145. }
  79146. if (state->have + copy > state->nlen + state->ndist) {
  79147. strm->msg = (char *)"invalid bit length repeat";
  79148. state->mode = BAD;
  79149. break;
  79150. }
  79151. while (copy--)
  79152. state->lens[state->have++] = (unsigned short)len;
  79153. }
  79154. }
  79155. if (state->mode == BAD) break;
  79156. state->next = state->codes;
  79157. state->lencode = (code const FAR *)(state->next);
  79158. state->lenbits = 9;
  79159. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79160. &(state->lenbits), state->work);
  79161. if (ret) {
  79162. strm->msg = (char *)"invalid literal/lengths set";
  79163. state->mode = BAD;
  79164. break;
  79165. }
  79166. state->distcode = (code const FAR *)(state->next);
  79167. state->distbits = 6;
  79168. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79169. &(state->next), &(state->distbits), state->work);
  79170. if (ret) {
  79171. strm->msg = (char *)"invalid distances set";
  79172. state->mode = BAD;
  79173. break;
  79174. }
  79175. Tracev((stderr, "inflate: codes ok\n"));
  79176. state->mode = LEN;
  79177. case LEN:
  79178. if (have >= 6 && left >= 258) {
  79179. RESTORE();
  79180. inflate_fast(strm, out);
  79181. LOAD();
  79182. break;
  79183. }
  79184. for (;;) {
  79185. thisx = state->lencode[BITS(state->lenbits)];
  79186. if ((unsigned)(thisx.bits) <= bits) break;
  79187. PULLBYTE();
  79188. }
  79189. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79190. last = thisx;
  79191. for (;;) {
  79192. thisx = state->lencode[last.val +
  79193. (BITS(last.bits + last.op) >> last.bits)];
  79194. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79195. PULLBYTE();
  79196. }
  79197. DROPBITS(last.bits);
  79198. }
  79199. DROPBITS(thisx.bits);
  79200. state->length = (unsigned)thisx.val;
  79201. if ((int)(thisx.op) == 0) {
  79202. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79203. "inflate: literal '%c'\n" :
  79204. "inflate: literal 0x%02x\n", thisx.val));
  79205. state->mode = LIT;
  79206. break;
  79207. }
  79208. if (thisx.op & 32) {
  79209. Tracevv((stderr, "inflate: end of block\n"));
  79210. state->mode = TYPE;
  79211. break;
  79212. }
  79213. if (thisx.op & 64) {
  79214. strm->msg = (char *)"invalid literal/length code";
  79215. state->mode = BAD;
  79216. break;
  79217. }
  79218. state->extra = (unsigned)(thisx.op) & 15;
  79219. state->mode = LENEXT;
  79220. case LENEXT:
  79221. if (state->extra) {
  79222. NEEDBITS(state->extra);
  79223. state->length += BITS(state->extra);
  79224. DROPBITS(state->extra);
  79225. }
  79226. Tracevv((stderr, "inflate: length %u\n", state->length));
  79227. state->mode = DIST;
  79228. case DIST:
  79229. for (;;) {
  79230. thisx = state->distcode[BITS(state->distbits)];
  79231. if ((unsigned)(thisx.bits) <= bits) break;
  79232. PULLBYTE();
  79233. }
  79234. if ((thisx.op & 0xf0) == 0) {
  79235. last = thisx;
  79236. for (;;) {
  79237. thisx = state->distcode[last.val +
  79238. (BITS(last.bits + last.op) >> last.bits)];
  79239. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79240. PULLBYTE();
  79241. }
  79242. DROPBITS(last.bits);
  79243. }
  79244. DROPBITS(thisx.bits);
  79245. if (thisx.op & 64) {
  79246. strm->msg = (char *)"invalid distance code";
  79247. state->mode = BAD;
  79248. break;
  79249. }
  79250. state->offset = (unsigned)thisx.val;
  79251. state->extra = (unsigned)(thisx.op) & 15;
  79252. state->mode = DISTEXT;
  79253. case DISTEXT:
  79254. if (state->extra) {
  79255. NEEDBITS(state->extra);
  79256. state->offset += BITS(state->extra);
  79257. DROPBITS(state->extra);
  79258. }
  79259. #ifdef INFLATE_STRICT
  79260. if (state->offset > state->dmax) {
  79261. strm->msg = (char *)"invalid distance too far back";
  79262. state->mode = BAD;
  79263. break;
  79264. }
  79265. #endif
  79266. if (state->offset > state->whave + out - left) {
  79267. strm->msg = (char *)"invalid distance too far back";
  79268. state->mode = BAD;
  79269. break;
  79270. }
  79271. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79272. state->mode = MATCH;
  79273. case MATCH:
  79274. if (left == 0) goto inf_leave;
  79275. copy = out - left;
  79276. if (state->offset > copy) { /* copy from window */
  79277. copy = state->offset - copy;
  79278. if (copy > state->write) {
  79279. copy -= state->write;
  79280. from = state->window + (state->wsize - copy);
  79281. }
  79282. else
  79283. from = state->window + (state->write - copy);
  79284. if (copy > state->length) copy = state->length;
  79285. }
  79286. else { /* copy from output */
  79287. from = put - state->offset;
  79288. copy = state->length;
  79289. }
  79290. if (copy > left) copy = left;
  79291. left -= copy;
  79292. state->length -= copy;
  79293. do {
  79294. *put++ = *from++;
  79295. } while (--copy);
  79296. if (state->length == 0) state->mode = LEN;
  79297. break;
  79298. case LIT:
  79299. if (left == 0) goto inf_leave;
  79300. *put++ = (unsigned char)(state->length);
  79301. left--;
  79302. state->mode = LEN;
  79303. break;
  79304. case CHECK:
  79305. if (state->wrap) {
  79306. NEEDBITS(32);
  79307. out -= left;
  79308. strm->total_out += out;
  79309. state->total += out;
  79310. if (out)
  79311. strm->adler = state->check =
  79312. UPDATE(state->check, put - out, out);
  79313. out = left;
  79314. if ((
  79315. #ifdef GUNZIP
  79316. state->flags ? hold :
  79317. #endif
  79318. REVERSE(hold)) != state->check) {
  79319. strm->msg = (char *)"incorrect data check";
  79320. state->mode = BAD;
  79321. break;
  79322. }
  79323. INITBITS();
  79324. Tracev((stderr, "inflate: check matches trailer\n"));
  79325. }
  79326. #ifdef GUNZIP
  79327. state->mode = LENGTH;
  79328. case LENGTH:
  79329. if (state->wrap && state->flags) {
  79330. NEEDBITS(32);
  79331. if (hold != (state->total & 0xffffffffUL)) {
  79332. strm->msg = (char *)"incorrect length check";
  79333. state->mode = BAD;
  79334. break;
  79335. }
  79336. INITBITS();
  79337. Tracev((stderr, "inflate: length matches trailer\n"));
  79338. }
  79339. #endif
  79340. state->mode = DONE;
  79341. case DONE:
  79342. ret = Z_STREAM_END;
  79343. goto inf_leave;
  79344. case BAD:
  79345. ret = Z_DATA_ERROR;
  79346. goto inf_leave;
  79347. case MEM:
  79348. return Z_MEM_ERROR;
  79349. case SYNC:
  79350. default:
  79351. return Z_STREAM_ERROR;
  79352. }
  79353. inf_leave:
  79354. RESTORE();
  79355. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79356. if (updatewindow(strm, out)) {
  79357. state->mode = MEM;
  79358. return Z_MEM_ERROR;
  79359. }
  79360. in -= strm->avail_in;
  79361. out -= strm->avail_out;
  79362. strm->total_in += in;
  79363. strm->total_out += out;
  79364. state->total += out;
  79365. if (state->wrap && out)
  79366. strm->adler = state->check =
  79367. UPDATE(state->check, strm->next_out - out, out);
  79368. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79369. (state->mode == TYPE ? 128 : 0);
  79370. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79371. ret = Z_BUF_ERROR;
  79372. return ret;
  79373. }
  79374. int ZEXPORT inflateEnd (z_streamp strm)
  79375. {
  79376. struct inflate_state FAR *state;
  79377. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79378. return Z_STREAM_ERROR;
  79379. state = (struct inflate_state FAR *)strm->state;
  79380. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79381. ZFREE(strm, strm->state);
  79382. strm->state = Z_NULL;
  79383. Tracev((stderr, "inflate: end\n"));
  79384. return Z_OK;
  79385. }
  79386. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79387. {
  79388. struct inflate_state FAR *state;
  79389. unsigned long id_;
  79390. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79391. state = (struct inflate_state FAR *)strm->state;
  79392. if (state->wrap != 0 && state->mode != DICT)
  79393. return Z_STREAM_ERROR;
  79394. if (state->mode == DICT) {
  79395. id_ = adler32(0L, Z_NULL, 0);
  79396. id_ = adler32(id_, dictionary, dictLength);
  79397. if (id_ != state->check)
  79398. return Z_DATA_ERROR;
  79399. }
  79400. if (updatewindow(strm, strm->avail_out)) {
  79401. state->mode = MEM;
  79402. return Z_MEM_ERROR;
  79403. }
  79404. if (dictLength > state->wsize) {
  79405. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79406. state->wsize);
  79407. state->whave = state->wsize;
  79408. }
  79409. else {
  79410. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79411. dictLength);
  79412. state->whave = dictLength;
  79413. }
  79414. state->havedict = 1;
  79415. Tracev((stderr, "inflate: dictionary set\n"));
  79416. return Z_OK;
  79417. }
  79418. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79419. {
  79420. struct inflate_state FAR *state;
  79421. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79422. state = (struct inflate_state FAR *)strm->state;
  79423. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79424. state->head = head;
  79425. head->done = 0;
  79426. return Z_OK;
  79427. }
  79428. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79429. {
  79430. unsigned got;
  79431. unsigned next;
  79432. got = *have;
  79433. next = 0;
  79434. while (next < len && got < 4) {
  79435. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79436. got++;
  79437. else if (buf[next])
  79438. got = 0;
  79439. else
  79440. got = 4 - got;
  79441. next++;
  79442. }
  79443. *have = got;
  79444. return next;
  79445. }
  79446. int ZEXPORT inflateSync (z_streamp strm)
  79447. {
  79448. unsigned len; /* number of bytes to look at or looked at */
  79449. unsigned long in, out; /* temporary to save total_in and total_out */
  79450. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79451. struct inflate_state FAR *state;
  79452. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79453. state = (struct inflate_state FAR *)strm->state;
  79454. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79455. if (state->mode != SYNC) {
  79456. state->mode = SYNC;
  79457. state->hold <<= state->bits & 7;
  79458. state->bits -= state->bits & 7;
  79459. len = 0;
  79460. while (state->bits >= 8) {
  79461. buf[len++] = (unsigned char)(state->hold);
  79462. state->hold >>= 8;
  79463. state->bits -= 8;
  79464. }
  79465. state->have = 0;
  79466. syncsearch(&(state->have), buf, len);
  79467. }
  79468. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79469. strm->avail_in -= len;
  79470. strm->next_in += len;
  79471. strm->total_in += len;
  79472. if (state->have != 4) return Z_DATA_ERROR;
  79473. in = strm->total_in; out = strm->total_out;
  79474. inflateReset(strm);
  79475. strm->total_in = in; strm->total_out = out;
  79476. state->mode = TYPE;
  79477. return Z_OK;
  79478. }
  79479. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79480. {
  79481. struct inflate_state FAR *state;
  79482. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79483. state = (struct inflate_state FAR *)strm->state;
  79484. return state->mode == STORED && state->bits == 0;
  79485. }
  79486. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79487. {
  79488. struct inflate_state FAR *state;
  79489. struct inflate_state FAR *copy;
  79490. unsigned char FAR *window;
  79491. unsigned wsize;
  79492. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79493. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79494. return Z_STREAM_ERROR;
  79495. state = (struct inflate_state FAR *)source->state;
  79496. copy = (struct inflate_state FAR *)
  79497. ZALLOC(source, 1, sizeof(struct inflate_state));
  79498. if (copy == Z_NULL) return Z_MEM_ERROR;
  79499. window = Z_NULL;
  79500. if (state->window != Z_NULL) {
  79501. window = (unsigned char FAR *)
  79502. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79503. if (window == Z_NULL) {
  79504. ZFREE(source, copy);
  79505. return Z_MEM_ERROR;
  79506. }
  79507. }
  79508. zmemcpy(dest, source, sizeof(z_stream));
  79509. zmemcpy(copy, state, sizeof(struct inflate_state));
  79510. if (state->lencode >= state->codes &&
  79511. state->lencode <= state->codes + ENOUGH - 1) {
  79512. copy->lencode = copy->codes + (state->lencode - state->codes);
  79513. copy->distcode = copy->codes + (state->distcode - state->codes);
  79514. }
  79515. copy->next = copy->codes + (state->next - state->codes);
  79516. if (window != Z_NULL) {
  79517. wsize = 1U << state->wbits;
  79518. zmemcpy(window, state->window, wsize);
  79519. }
  79520. copy->window = window;
  79521. dest->state = (struct internal_state FAR *)copy;
  79522. return Z_OK;
  79523. }
  79524. /*** End of inlined file: inflate.c ***/
  79525. /*** Start of inlined file: inftrees.c ***/
  79526. #define MAXBITS 15
  79527. const char inflate_copyright[] =
  79528. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79529. int inflate_table (codetype type,
  79530. unsigned short FAR *lens,
  79531. unsigned codes,
  79532. code FAR * FAR *table,
  79533. unsigned FAR *bits,
  79534. unsigned short FAR *work)
  79535. {
  79536. unsigned len; /* a code's length in bits */
  79537. unsigned sym; /* index of code symbols */
  79538. unsigned min, max; /* minimum and maximum code lengths */
  79539. unsigned root; /* number of index bits for root table */
  79540. unsigned curr; /* number of index bits for current table */
  79541. unsigned drop; /* code bits to drop for sub-table */
  79542. int left; /* number of prefix codes available */
  79543. unsigned used; /* code entries in table used */
  79544. unsigned huff; /* Huffman code */
  79545. unsigned incr; /* for incrementing code, index */
  79546. unsigned fill; /* index for replicating entries */
  79547. unsigned low; /* low bits for current root entry */
  79548. unsigned mask; /* mask for low root bits */
  79549. code thisx; /* table entry for duplication */
  79550. code FAR *next; /* next available space in table */
  79551. const unsigned short FAR *base; /* base value table to use */
  79552. const unsigned short FAR *extra; /* extra bits table to use */
  79553. int end; /* use base and extra for symbol > end */
  79554. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79555. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79556. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79557. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79558. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79559. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79560. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79561. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79562. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79563. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79564. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79565. 8193, 12289, 16385, 24577, 0, 0};
  79566. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79567. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79568. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79569. 28, 28, 29, 29, 64, 64};
  79570. for (len = 0; len <= MAXBITS; len++)
  79571. count[len] = 0;
  79572. for (sym = 0; sym < codes; sym++)
  79573. count[lens[sym]]++;
  79574. root = *bits;
  79575. for (max = MAXBITS; max >= 1; max--)
  79576. if (count[max] != 0) break;
  79577. if (root > max) root = max;
  79578. if (max == 0) { /* no symbols to code at all */
  79579. thisx.op = (unsigned char)64; /* invalid code marker */
  79580. thisx.bits = (unsigned char)1;
  79581. thisx.val = (unsigned short)0;
  79582. *(*table)++ = thisx; /* make a table to force an error */
  79583. *(*table)++ = thisx;
  79584. *bits = 1;
  79585. return 0; /* no symbols, but wait for decoding to report error */
  79586. }
  79587. for (min = 1; min <= MAXBITS; min++)
  79588. if (count[min] != 0) break;
  79589. if (root < min) root = min;
  79590. left = 1;
  79591. for (len = 1; len <= MAXBITS; len++) {
  79592. left <<= 1;
  79593. left -= count[len];
  79594. if (left < 0) return -1; /* over-subscribed */
  79595. }
  79596. if (left > 0 && (type == CODES || max != 1))
  79597. return -1; /* incomplete set */
  79598. offs[1] = 0;
  79599. for (len = 1; len < MAXBITS; len++)
  79600. offs[len + 1] = offs[len] + count[len];
  79601. for (sym = 0; sym < codes; sym++)
  79602. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79603. switch (type) {
  79604. case CODES:
  79605. base = extra = work; /* dummy value--not used */
  79606. end = 19;
  79607. break;
  79608. case LENS:
  79609. base = lbase;
  79610. base -= 257;
  79611. extra = lext;
  79612. extra -= 257;
  79613. end = 256;
  79614. break;
  79615. default: /* DISTS */
  79616. base = dbase;
  79617. extra = dext;
  79618. end = -1;
  79619. }
  79620. huff = 0; /* starting code */
  79621. sym = 0; /* starting code symbol */
  79622. len = min; /* starting code length */
  79623. next = *table; /* current table to fill in */
  79624. curr = root; /* current table index bits */
  79625. drop = 0; /* current bits to drop from code for index */
  79626. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79627. used = 1U << root; /* use root table entries */
  79628. mask = used - 1; /* mask for comparing low */
  79629. if (type == LENS && used >= ENOUGH - MAXD)
  79630. return 1;
  79631. for (;;) {
  79632. thisx.bits = (unsigned char)(len - drop);
  79633. if ((int)(work[sym]) < end) {
  79634. thisx.op = (unsigned char)0;
  79635. thisx.val = work[sym];
  79636. }
  79637. else if ((int)(work[sym]) > end) {
  79638. thisx.op = (unsigned char)(extra[work[sym]]);
  79639. thisx.val = base[work[sym]];
  79640. }
  79641. else {
  79642. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79643. thisx.val = 0;
  79644. }
  79645. incr = 1U << (len - drop);
  79646. fill = 1U << curr;
  79647. min = fill; /* save offset to next table */
  79648. do {
  79649. fill -= incr;
  79650. next[(huff >> drop) + fill] = thisx;
  79651. } while (fill != 0);
  79652. incr = 1U << (len - 1);
  79653. while (huff & incr)
  79654. incr >>= 1;
  79655. if (incr != 0) {
  79656. huff &= incr - 1;
  79657. huff += incr;
  79658. }
  79659. else
  79660. huff = 0;
  79661. sym++;
  79662. if (--(count[len]) == 0) {
  79663. if (len == max) break;
  79664. len = lens[work[sym]];
  79665. }
  79666. if (len > root && (huff & mask) != low) {
  79667. if (drop == 0)
  79668. drop = root;
  79669. next += min; /* here min is 1 << curr */
  79670. curr = len - drop;
  79671. left = (int)(1 << curr);
  79672. while (curr + drop < max) {
  79673. left -= count[curr + drop];
  79674. if (left <= 0) break;
  79675. curr++;
  79676. left <<= 1;
  79677. }
  79678. used += 1U << curr;
  79679. if (type == LENS && used >= ENOUGH - MAXD)
  79680. return 1;
  79681. low = huff & mask;
  79682. (*table)[low].op = (unsigned char)curr;
  79683. (*table)[low].bits = (unsigned char)root;
  79684. (*table)[low].val = (unsigned short)(next - *table);
  79685. }
  79686. }
  79687. thisx.op = (unsigned char)64; /* invalid code marker */
  79688. thisx.bits = (unsigned char)(len - drop);
  79689. thisx.val = (unsigned short)0;
  79690. while (huff != 0) {
  79691. if (drop != 0 && (huff & mask) != low) {
  79692. drop = 0;
  79693. len = root;
  79694. next = *table;
  79695. thisx.bits = (unsigned char)len;
  79696. }
  79697. next[huff >> drop] = thisx;
  79698. incr = 1U << (len - 1);
  79699. while (huff & incr)
  79700. incr >>= 1;
  79701. if (incr != 0) {
  79702. huff &= incr - 1;
  79703. huff += incr;
  79704. }
  79705. else
  79706. huff = 0;
  79707. }
  79708. *table += used;
  79709. *bits = root;
  79710. return 0;
  79711. }
  79712. /*** End of inlined file: inftrees.c ***/
  79713. /*** Start of inlined file: trees.c ***/
  79714. #ifdef DEBUG
  79715. # include <ctype.h>
  79716. #endif
  79717. #define MAX_BL_BITS 7
  79718. #define END_BLOCK 256
  79719. #define REP_3_6 16
  79720. #define REPZ_3_10 17
  79721. #define REPZ_11_138 18
  79722. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79723. = {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};
  79724. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79725. = {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};
  79726. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79727. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79728. local const uch bl_order[BL_CODES]
  79729. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79730. #define Buf_size (8 * 2*sizeof(char))
  79731. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79732. #if defined(GEN_TREES_H) || !defined(STDC)
  79733. local ct_data static_ltree[L_CODES+2];
  79734. local ct_data static_dtree[D_CODES];
  79735. uch _dist_code[DIST_CODE_LEN];
  79736. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79737. local int base_length[LENGTH_CODES];
  79738. local int base_dist[D_CODES];
  79739. #else
  79740. /*** Start of inlined file: trees.h ***/
  79741. local const ct_data static_ltree[L_CODES+2] = {
  79742. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79743. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79744. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79745. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79746. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79747. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79748. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79749. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79750. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79751. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79752. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79753. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79754. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79755. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79756. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79757. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79758. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79759. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79760. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79761. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79762. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79763. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79764. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79765. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79766. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79767. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79768. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79769. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79770. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79771. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79772. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79773. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79774. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79775. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79776. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79777. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79778. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79779. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79780. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79781. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79782. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79783. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79784. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79785. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79786. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79787. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79788. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79789. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79790. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79791. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79792. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79793. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79794. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79795. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79796. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79797. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79798. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79799. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79800. };
  79801. local const ct_data static_dtree[D_CODES] = {
  79802. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79803. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79804. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79805. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79806. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79807. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79808. };
  79809. const uch _dist_code[DIST_CODE_LEN] = {
  79810. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79811. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79812. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79813. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79814. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79815. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79816. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79817. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79818. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79819. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79820. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79821. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79822. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79823. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79824. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79825. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79826. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79827. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79828. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79829. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79830. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79831. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79832. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79833. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79834. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79835. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79836. };
  79837. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79838. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79839. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79840. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79841. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79842. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79843. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79844. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79845. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79846. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79847. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79848. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79849. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79850. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79851. };
  79852. local const int base_length[LENGTH_CODES] = {
  79853. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79854. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79855. };
  79856. local const int base_dist[D_CODES] = {
  79857. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79858. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79859. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79860. };
  79861. /*** End of inlined file: trees.h ***/
  79862. #endif /* GEN_TREES_H */
  79863. struct static_tree_desc_s {
  79864. const ct_data *static_tree; /* static tree or NULL */
  79865. const intf *extra_bits; /* extra bits for each code or NULL */
  79866. int extra_base; /* base index for extra_bits */
  79867. int elems; /* max number of elements in the tree */
  79868. int max_length; /* max bit length for the codes */
  79869. };
  79870. local static_tree_desc static_l_desc =
  79871. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79872. local static_tree_desc static_d_desc =
  79873. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79874. local static_tree_desc static_bl_desc =
  79875. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79876. local void tr_static_init OF((void));
  79877. local void init_block OF((deflate_state *s));
  79878. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79879. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79880. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79881. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79882. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79883. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79884. local int build_bl_tree OF((deflate_state *s));
  79885. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79886. int blcodes));
  79887. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79888. ct_data *dtree));
  79889. local void set_data_type OF((deflate_state *s));
  79890. local unsigned bi_reverse OF((unsigned value, int length));
  79891. local void bi_windup OF((deflate_state *s));
  79892. local void bi_flush OF((deflate_state *s));
  79893. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79894. int header));
  79895. #ifdef GEN_TREES_H
  79896. local void gen_trees_header OF((void));
  79897. #endif
  79898. #ifndef DEBUG
  79899. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79900. #else /* DEBUG */
  79901. # define send_code(s, c, tree) \
  79902. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79903. send_bits(s, tree[c].Code, tree[c].Len); }
  79904. #endif
  79905. #define put_short(s, w) { \
  79906. put_byte(s, (uch)((w) & 0xff)); \
  79907. put_byte(s, (uch)((ush)(w) >> 8)); \
  79908. }
  79909. #ifdef DEBUG
  79910. local void send_bits OF((deflate_state *s, int value, int length));
  79911. local void send_bits (deflate_state *s, int value, int length)
  79912. {
  79913. Tracevv((stderr," l %2d v %4x ", length, value));
  79914. Assert(length > 0 && length <= 15, "invalid length");
  79915. s->bits_sent += (ulg)length;
  79916. if (s->bi_valid > (int)Buf_size - length) {
  79917. s->bi_buf |= (value << s->bi_valid);
  79918. put_short(s, s->bi_buf);
  79919. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79920. s->bi_valid += length - Buf_size;
  79921. } else {
  79922. s->bi_buf |= value << s->bi_valid;
  79923. s->bi_valid += length;
  79924. }
  79925. }
  79926. #else /* !DEBUG */
  79927. #define send_bits(s, value, length) \
  79928. { int len = length;\
  79929. if (s->bi_valid > (int)Buf_size - len) {\
  79930. int val = value;\
  79931. s->bi_buf |= (val << s->bi_valid);\
  79932. put_short(s, s->bi_buf);\
  79933. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79934. s->bi_valid += len - Buf_size;\
  79935. } else {\
  79936. s->bi_buf |= (value) << s->bi_valid;\
  79937. s->bi_valid += len;\
  79938. }\
  79939. }
  79940. #endif /* DEBUG */
  79941. local void tr_static_init()
  79942. {
  79943. #if defined(GEN_TREES_H) || !defined(STDC)
  79944. static int static_init_done = 0;
  79945. int n; /* iterates over tree elements */
  79946. int bits; /* bit counter */
  79947. int length; /* length value */
  79948. int code; /* code value */
  79949. int dist; /* distance index */
  79950. ush bl_count[MAX_BITS+1];
  79951. if (static_init_done) return;
  79952. static_l_desc.static_tree = static_ltree;
  79953. static_l_desc.extra_bits = extra_lbits;
  79954. static_d_desc.static_tree = static_dtree;
  79955. static_d_desc.extra_bits = extra_dbits;
  79956. static_bl_desc.extra_bits = extra_blbits;
  79957. length = 0;
  79958. for (code = 0; code < LENGTH_CODES-1; code++) {
  79959. base_length[code] = length;
  79960. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79961. _length_code[length++] = (uch)code;
  79962. }
  79963. }
  79964. Assert (length == 256, "tr_static_init: length != 256");
  79965. _length_code[length-1] = (uch)code;
  79966. dist = 0;
  79967. for (code = 0 ; code < 16; code++) {
  79968. base_dist[code] = dist;
  79969. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79970. _dist_code[dist++] = (uch)code;
  79971. }
  79972. }
  79973. Assert (dist == 256, "tr_static_init: dist != 256");
  79974. dist >>= 7; /* from now on, all distances are divided by 128 */
  79975. for ( ; code < D_CODES; code++) {
  79976. base_dist[code] = dist << 7;
  79977. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79978. _dist_code[256 + dist++] = (uch)code;
  79979. }
  79980. }
  79981. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79982. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79983. n = 0;
  79984. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79985. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79986. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79987. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79988. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79989. for (n = 0; n < D_CODES; n++) {
  79990. static_dtree[n].Len = 5;
  79991. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79992. }
  79993. static_init_done = 1;
  79994. # ifdef GEN_TREES_H
  79995. gen_trees_header();
  79996. # endif
  79997. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79998. }
  79999. #ifdef GEN_TREES_H
  80000. # ifndef DEBUG
  80001. # include <stdio.h>
  80002. # endif
  80003. # define SEPARATOR(i, last, width) \
  80004. ((i) == (last)? "\n};\n\n" : \
  80005. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  80006. void gen_trees_header()
  80007. {
  80008. FILE *header = fopen("trees.h", "w");
  80009. int i;
  80010. Assert (header != NULL, "Can't open trees.h");
  80011. fprintf(header,
  80012. "/* header created automatically with -DGEN_TREES_H */\n\n");
  80013. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  80014. for (i = 0; i < L_CODES+2; i++) {
  80015. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  80016. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  80017. }
  80018. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  80019. for (i = 0; i < D_CODES; i++) {
  80020. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  80021. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  80022. }
  80023. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  80024. for (i = 0; i < DIST_CODE_LEN; i++) {
  80025. fprintf(header, "%2u%s", _dist_code[i],
  80026. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  80027. }
  80028. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  80029. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  80030. fprintf(header, "%2u%s", _length_code[i],
  80031. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  80032. }
  80033. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  80034. for (i = 0; i < LENGTH_CODES; i++) {
  80035. fprintf(header, "%1u%s", base_length[i],
  80036. SEPARATOR(i, LENGTH_CODES-1, 20));
  80037. }
  80038. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  80039. for (i = 0; i < D_CODES; i++) {
  80040. fprintf(header, "%5u%s", base_dist[i],
  80041. SEPARATOR(i, D_CODES-1, 10));
  80042. }
  80043. fclose(header);
  80044. }
  80045. #endif /* GEN_TREES_H */
  80046. void _tr_init(deflate_state *s)
  80047. {
  80048. tr_static_init();
  80049. s->l_desc.dyn_tree = s->dyn_ltree;
  80050. s->l_desc.stat_desc = &static_l_desc;
  80051. s->d_desc.dyn_tree = s->dyn_dtree;
  80052. s->d_desc.stat_desc = &static_d_desc;
  80053. s->bl_desc.dyn_tree = s->bl_tree;
  80054. s->bl_desc.stat_desc = &static_bl_desc;
  80055. s->bi_buf = 0;
  80056. s->bi_valid = 0;
  80057. s->last_eob_len = 8; /* enough lookahead for inflate */
  80058. #ifdef DEBUG
  80059. s->compressed_len = 0L;
  80060. s->bits_sent = 0L;
  80061. #endif
  80062. init_block(s);
  80063. }
  80064. local void init_block (deflate_state *s)
  80065. {
  80066. int n; /* iterates over tree elements */
  80067. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  80068. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  80069. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  80070. s->dyn_ltree[END_BLOCK].Freq = 1;
  80071. s->opt_len = s->static_len = 0L;
  80072. s->last_lit = s->matches = 0;
  80073. }
  80074. #define SMALLEST 1
  80075. #define pqremove(s, tree, top) \
  80076. {\
  80077. top = s->heap[SMALLEST]; \
  80078. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  80079. pqdownheap(s, tree, SMALLEST); \
  80080. }
  80081. #define smaller(tree, n, m, depth) \
  80082. (tree[n].Freq < tree[m].Freq || \
  80083. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  80084. local void pqdownheap (deflate_state *s,
  80085. ct_data *tree, /* the tree to restore */
  80086. int k) /* node to move down */
  80087. {
  80088. int v = s->heap[k];
  80089. int j = k << 1; /* left son of k */
  80090. while (j <= s->heap_len) {
  80091. if (j < s->heap_len &&
  80092. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  80093. j++;
  80094. }
  80095. if (smaller(tree, v, s->heap[j], s->depth)) break;
  80096. s->heap[k] = s->heap[j]; k = j;
  80097. j <<= 1;
  80098. }
  80099. s->heap[k] = v;
  80100. }
  80101. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80102. {
  80103. ct_data *tree = desc->dyn_tree;
  80104. int max_code = desc->max_code;
  80105. const ct_data *stree = desc->stat_desc->static_tree;
  80106. const intf *extra = desc->stat_desc->extra_bits;
  80107. int base = desc->stat_desc->extra_base;
  80108. int max_length = desc->stat_desc->max_length;
  80109. int h; /* heap index */
  80110. int n, m; /* iterate over the tree elements */
  80111. int bits; /* bit length */
  80112. int xbits; /* extra bits */
  80113. ush f; /* frequency */
  80114. int overflow = 0; /* number of elements with bit length too large */
  80115. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80116. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80117. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80118. n = s->heap[h];
  80119. bits = tree[tree[n].Dad].Len + 1;
  80120. if (bits > max_length) bits = max_length, overflow++;
  80121. tree[n].Len = (ush)bits;
  80122. if (n > max_code) continue; /* not a leaf node */
  80123. s->bl_count[bits]++;
  80124. xbits = 0;
  80125. if (n >= base) xbits = extra[n-base];
  80126. f = tree[n].Freq;
  80127. s->opt_len += (ulg)f * (bits + xbits);
  80128. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80129. }
  80130. if (overflow == 0) return;
  80131. Trace((stderr,"\nbit length overflow\n"));
  80132. do {
  80133. bits = max_length-1;
  80134. while (s->bl_count[bits] == 0) bits--;
  80135. s->bl_count[bits]--; /* move one leaf down the tree */
  80136. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80137. s->bl_count[max_length]--;
  80138. overflow -= 2;
  80139. } while (overflow > 0);
  80140. for (bits = max_length; bits != 0; bits--) {
  80141. n = s->bl_count[bits];
  80142. while (n != 0) {
  80143. m = s->heap[--h];
  80144. if (m > max_code) continue;
  80145. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80146. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80147. s->opt_len += ((long)bits - (long)tree[m].Len)
  80148. *(long)tree[m].Freq;
  80149. tree[m].Len = (ush)bits;
  80150. }
  80151. n--;
  80152. }
  80153. }
  80154. }
  80155. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80156. int max_code, /* largest code with non zero frequency */
  80157. ushf *bl_count) /* number of codes at each bit length */
  80158. {
  80159. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80160. ush code = 0; /* running code value */
  80161. int bits; /* bit index */
  80162. int n; /* code index */
  80163. for (bits = 1; bits <= MAX_BITS; bits++) {
  80164. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80165. }
  80166. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80167. "inconsistent bit counts");
  80168. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80169. for (n = 0; n <= max_code; n++) {
  80170. int len = tree[n].Len;
  80171. if (len == 0) continue;
  80172. tree[n].Code = bi_reverse(next_code[len]++, len);
  80173. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80174. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80175. }
  80176. }
  80177. local void build_tree (deflate_state *s,
  80178. tree_desc *desc) /* the tree descriptor */
  80179. {
  80180. ct_data *tree = desc->dyn_tree;
  80181. const ct_data *stree = desc->stat_desc->static_tree;
  80182. int elems = desc->stat_desc->elems;
  80183. int n, m; /* iterate over heap elements */
  80184. int max_code = -1; /* largest code with non zero frequency */
  80185. int node; /* new node being created */
  80186. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80187. for (n = 0; n < elems; n++) {
  80188. if (tree[n].Freq != 0) {
  80189. s->heap[++(s->heap_len)] = max_code = n;
  80190. s->depth[n] = 0;
  80191. } else {
  80192. tree[n].Len = 0;
  80193. }
  80194. }
  80195. while (s->heap_len < 2) {
  80196. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80197. tree[node].Freq = 1;
  80198. s->depth[node] = 0;
  80199. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80200. }
  80201. desc->max_code = max_code;
  80202. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80203. node = elems; /* next internal node of the tree */
  80204. do {
  80205. pqremove(s, tree, n); /* n = node of least frequency */
  80206. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80207. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80208. s->heap[--(s->heap_max)] = m;
  80209. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80210. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80211. s->depth[n] : s->depth[m]) + 1);
  80212. tree[n].Dad = tree[m].Dad = (ush)node;
  80213. #ifdef DUMP_BL_TREE
  80214. if (tree == s->bl_tree) {
  80215. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80216. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80217. }
  80218. #endif
  80219. s->heap[SMALLEST] = node++;
  80220. pqdownheap(s, tree, SMALLEST);
  80221. } while (s->heap_len >= 2);
  80222. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80223. gen_bitlen(s, (tree_desc *)desc);
  80224. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80225. }
  80226. local void scan_tree (deflate_state *s,
  80227. ct_data *tree, /* the tree to be scanned */
  80228. int max_code) /* and its largest code of non zero frequency */
  80229. {
  80230. int n; /* iterates over all tree elements */
  80231. int prevlen = -1; /* last emitted length */
  80232. int curlen; /* length of current code */
  80233. int nextlen = tree[0].Len; /* length of next code */
  80234. int count = 0; /* repeat count of the current code */
  80235. int max_count = 7; /* max repeat count */
  80236. int min_count = 4; /* min repeat count */
  80237. if (nextlen == 0) max_count = 138, min_count = 3;
  80238. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80239. for (n = 0; n <= max_code; n++) {
  80240. curlen = nextlen; nextlen = tree[n+1].Len;
  80241. if (++count < max_count && curlen == nextlen) {
  80242. continue;
  80243. } else if (count < min_count) {
  80244. s->bl_tree[curlen].Freq += count;
  80245. } else if (curlen != 0) {
  80246. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80247. s->bl_tree[REP_3_6].Freq++;
  80248. } else if (count <= 10) {
  80249. s->bl_tree[REPZ_3_10].Freq++;
  80250. } else {
  80251. s->bl_tree[REPZ_11_138].Freq++;
  80252. }
  80253. count = 0; prevlen = curlen;
  80254. if (nextlen == 0) {
  80255. max_count = 138, min_count = 3;
  80256. } else if (curlen == nextlen) {
  80257. max_count = 6, min_count = 3;
  80258. } else {
  80259. max_count = 7, min_count = 4;
  80260. }
  80261. }
  80262. }
  80263. local void send_tree (deflate_state *s,
  80264. ct_data *tree, /* the tree to be scanned */
  80265. int max_code) /* and its largest code of non zero frequency */
  80266. {
  80267. int n; /* iterates over all tree elements */
  80268. int prevlen = -1; /* last emitted length */
  80269. int curlen; /* length of current code */
  80270. int nextlen = tree[0].Len; /* length of next code */
  80271. int count = 0; /* repeat count of the current code */
  80272. int max_count = 7; /* max repeat count */
  80273. int min_count = 4; /* min repeat count */
  80274. /* guard already set */
  80275. if (nextlen == 0) max_count = 138, min_count = 3;
  80276. for (n = 0; n <= max_code; n++) {
  80277. curlen = nextlen; nextlen = tree[n+1].Len;
  80278. if (++count < max_count && curlen == nextlen) {
  80279. continue;
  80280. } else if (count < min_count) {
  80281. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80282. } else if (curlen != 0) {
  80283. if (curlen != prevlen) {
  80284. send_code(s, curlen, s->bl_tree); count--;
  80285. }
  80286. Assert(count >= 3 && count <= 6, " 3_6?");
  80287. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80288. } else if (count <= 10) {
  80289. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80290. } else {
  80291. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80292. }
  80293. count = 0; prevlen = curlen;
  80294. if (nextlen == 0) {
  80295. max_count = 138, min_count = 3;
  80296. } else if (curlen == nextlen) {
  80297. max_count = 6, min_count = 3;
  80298. } else {
  80299. max_count = 7, min_count = 4;
  80300. }
  80301. }
  80302. }
  80303. local int build_bl_tree (deflate_state *s)
  80304. {
  80305. int max_blindex; /* index of last bit length code of non zero freq */
  80306. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80307. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80308. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80309. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80310. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80311. }
  80312. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80313. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80314. s->opt_len, s->static_len));
  80315. return max_blindex;
  80316. }
  80317. local void send_all_trees (deflate_state *s,
  80318. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80319. {
  80320. int rank; /* index in bl_order */
  80321. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80322. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80323. "too many codes");
  80324. Tracev((stderr, "\nbl counts: "));
  80325. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80326. send_bits(s, dcodes-1, 5);
  80327. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80328. for (rank = 0; rank < blcodes; rank++) {
  80329. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80330. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80331. }
  80332. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80333. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80334. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80335. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80336. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80337. }
  80338. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80339. {
  80340. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80341. #ifdef DEBUG
  80342. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80343. s->compressed_len += (stored_len + 4) << 3;
  80344. #endif
  80345. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80346. }
  80347. void _tr_align (deflate_state *s)
  80348. {
  80349. send_bits(s, STATIC_TREES<<1, 3);
  80350. send_code(s, END_BLOCK, static_ltree);
  80351. #ifdef DEBUG
  80352. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80353. #endif
  80354. bi_flush(s);
  80355. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80356. send_bits(s, STATIC_TREES<<1, 3);
  80357. send_code(s, END_BLOCK, static_ltree);
  80358. #ifdef DEBUG
  80359. s->compressed_len += 10L;
  80360. #endif
  80361. bi_flush(s);
  80362. }
  80363. s->last_eob_len = 7;
  80364. }
  80365. void _tr_flush_block (deflate_state *s,
  80366. charf *buf, /* input block, or NULL if too old */
  80367. ulg stored_len, /* length of input block */
  80368. int eof) /* true if this is the last block for a file */
  80369. {
  80370. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80371. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80372. if (s->level > 0) {
  80373. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80374. set_data_type(s);
  80375. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80376. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80377. s->static_len));
  80378. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80379. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80380. s->static_len));
  80381. max_blindex = build_bl_tree(s);
  80382. opt_lenb = (s->opt_len+3+7)>>3;
  80383. static_lenb = (s->static_len+3+7)>>3;
  80384. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80385. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80386. s->last_lit));
  80387. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80388. } else {
  80389. Assert(buf != (char*)0, "lost buf");
  80390. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80391. }
  80392. #ifdef FORCE_STORED
  80393. if (buf != (char*)0) { /* force stored block */
  80394. #else
  80395. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80396. #endif
  80397. _tr_stored_block(s, buf, stored_len, eof);
  80398. #ifdef FORCE_STATIC
  80399. } else if (static_lenb >= 0) { /* force static trees */
  80400. #else
  80401. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80402. #endif
  80403. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80404. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80405. #ifdef DEBUG
  80406. s->compressed_len += 3 + s->static_len;
  80407. #endif
  80408. } else {
  80409. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80410. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80411. max_blindex+1);
  80412. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80413. #ifdef DEBUG
  80414. s->compressed_len += 3 + s->opt_len;
  80415. #endif
  80416. }
  80417. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80418. init_block(s);
  80419. if (eof) {
  80420. bi_windup(s);
  80421. #ifdef DEBUG
  80422. s->compressed_len += 7; /* align on byte boundary */
  80423. #endif
  80424. }
  80425. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80426. s->compressed_len-7*eof));
  80427. }
  80428. int _tr_tally (deflate_state *s,
  80429. unsigned dist, /* distance of matched string */
  80430. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80431. {
  80432. s->d_buf[s->last_lit] = (ush)dist;
  80433. s->l_buf[s->last_lit++] = (uch)lc;
  80434. if (dist == 0) {
  80435. s->dyn_ltree[lc].Freq++;
  80436. } else {
  80437. s->matches++;
  80438. dist--; /* dist = match distance - 1 */
  80439. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80440. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80441. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80442. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80443. s->dyn_dtree[d_code(dist)].Freq++;
  80444. }
  80445. #ifdef TRUNCATE_BLOCK
  80446. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80447. ulg out_length = (ulg)s->last_lit*8L;
  80448. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80449. int dcode;
  80450. for (dcode = 0; dcode < D_CODES; dcode++) {
  80451. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80452. (5L+extra_dbits[dcode]);
  80453. }
  80454. out_length >>= 3;
  80455. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80456. s->last_lit, in_length, out_length,
  80457. 100L - out_length*100L/in_length));
  80458. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80459. }
  80460. #endif
  80461. return (s->last_lit == s->lit_bufsize-1);
  80462. }
  80463. local void compress_block (deflate_state *s,
  80464. ct_data *ltree, /* literal tree */
  80465. ct_data *dtree) /* distance tree */
  80466. {
  80467. unsigned dist; /* distance of matched string */
  80468. int lc; /* match length or unmatched char (if dist == 0) */
  80469. unsigned lx = 0; /* running index in l_buf */
  80470. unsigned code; /* the code to send */
  80471. int extra; /* number of extra bits to send */
  80472. if (s->last_lit != 0) do {
  80473. dist = s->d_buf[lx];
  80474. lc = s->l_buf[lx++];
  80475. if (dist == 0) {
  80476. send_code(s, lc, ltree); /* send a literal byte */
  80477. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80478. } else {
  80479. code = _length_code[lc];
  80480. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80481. extra = extra_lbits[code];
  80482. if (extra != 0) {
  80483. lc -= base_length[code];
  80484. send_bits(s, lc, extra); /* send the extra length bits */
  80485. }
  80486. dist--; /* dist is now the match distance - 1 */
  80487. code = d_code(dist);
  80488. Assert (code < D_CODES, "bad d_code");
  80489. send_code(s, code, dtree); /* send the distance code */
  80490. extra = extra_dbits[code];
  80491. if (extra != 0) {
  80492. dist -= base_dist[code];
  80493. send_bits(s, dist, extra); /* send the extra distance bits */
  80494. }
  80495. } /* literal or match pair ? */
  80496. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80497. "pendingBuf overflow");
  80498. } while (lx < s->last_lit);
  80499. send_code(s, END_BLOCK, ltree);
  80500. s->last_eob_len = ltree[END_BLOCK].Len;
  80501. }
  80502. local void set_data_type (deflate_state *s)
  80503. {
  80504. int n;
  80505. for (n = 0; n < 9; n++)
  80506. if (s->dyn_ltree[n].Freq != 0)
  80507. break;
  80508. if (n == 9)
  80509. for (n = 14; n < 32; n++)
  80510. if (s->dyn_ltree[n].Freq != 0)
  80511. break;
  80512. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80513. }
  80514. local unsigned bi_reverse (unsigned code, int len)
  80515. {
  80516. register unsigned res = 0;
  80517. do {
  80518. res |= code & 1;
  80519. code >>= 1, res <<= 1;
  80520. } while (--len > 0);
  80521. return res >> 1;
  80522. }
  80523. local void bi_flush (deflate_state *s)
  80524. {
  80525. if (s->bi_valid == 16) {
  80526. put_short(s, s->bi_buf);
  80527. s->bi_buf = 0;
  80528. s->bi_valid = 0;
  80529. } else if (s->bi_valid >= 8) {
  80530. put_byte(s, (Byte)s->bi_buf);
  80531. s->bi_buf >>= 8;
  80532. s->bi_valid -= 8;
  80533. }
  80534. }
  80535. local void bi_windup (deflate_state *s)
  80536. {
  80537. if (s->bi_valid > 8) {
  80538. put_short(s, s->bi_buf);
  80539. } else if (s->bi_valid > 0) {
  80540. put_byte(s, (Byte)s->bi_buf);
  80541. }
  80542. s->bi_buf = 0;
  80543. s->bi_valid = 0;
  80544. #ifdef DEBUG
  80545. s->bits_sent = (s->bits_sent+7) & ~7;
  80546. #endif
  80547. }
  80548. local void copy_block(deflate_state *s,
  80549. charf *buf, /* the input data */
  80550. unsigned len, /* its length */
  80551. int header) /* true if block header must be written */
  80552. {
  80553. bi_windup(s); /* align on byte boundary */
  80554. s->last_eob_len = 8; /* enough lookahead for inflate */
  80555. if (header) {
  80556. put_short(s, (ush)len);
  80557. put_short(s, (ush)~len);
  80558. #ifdef DEBUG
  80559. s->bits_sent += 2*16;
  80560. #endif
  80561. }
  80562. #ifdef DEBUG
  80563. s->bits_sent += (ulg)len<<3;
  80564. #endif
  80565. while (len--) {
  80566. put_byte(s, *buf++);
  80567. }
  80568. }
  80569. /*** End of inlined file: trees.c ***/
  80570. /*** Start of inlined file: zutil.c ***/
  80571. #ifndef NO_DUMMY_DECL
  80572. struct internal_state {int dummy;}; /* for buggy compilers */
  80573. #endif
  80574. const char * const z_errmsg[10] = {
  80575. "need dictionary", /* Z_NEED_DICT 2 */
  80576. "stream end", /* Z_STREAM_END 1 */
  80577. "", /* Z_OK 0 */
  80578. "file error", /* Z_ERRNO (-1) */
  80579. "stream error", /* Z_STREAM_ERROR (-2) */
  80580. "data error", /* Z_DATA_ERROR (-3) */
  80581. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80582. "buffer error", /* Z_BUF_ERROR (-5) */
  80583. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80584. ""};
  80585. #ifdef DEBUG
  80586. # ifndef verbose
  80587. # define verbose 0
  80588. # endif
  80589. int z_verbose = verbose;
  80590. void z_error (const char *m)
  80591. {
  80592. fprintf(stderr, "%s\n", m);
  80593. exit(1);
  80594. }
  80595. #endif
  80596. const char * ZEXPORT zError(int err)
  80597. {
  80598. return ERR_MSG(err);
  80599. }
  80600. #if defined(_WIN32_WCE)
  80601. int errno = 0;
  80602. #endif
  80603. #ifndef HAVE_MEMCPY
  80604. void zmemcpy(dest, source, len)
  80605. Bytef* dest;
  80606. const Bytef* source;
  80607. uInt len;
  80608. {
  80609. if (len == 0) return;
  80610. do {
  80611. *dest++ = *source++; /* ??? to be unrolled */
  80612. } while (--len != 0);
  80613. }
  80614. int zmemcmp(s1, s2, len)
  80615. const Bytef* s1;
  80616. const Bytef* s2;
  80617. uInt len;
  80618. {
  80619. uInt j;
  80620. for (j = 0; j < len; j++) {
  80621. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80622. }
  80623. return 0;
  80624. }
  80625. void zmemzero(dest, len)
  80626. Bytef* dest;
  80627. uInt len;
  80628. {
  80629. if (len == 0) return;
  80630. do {
  80631. *dest++ = 0; /* ??? to be unrolled */
  80632. } while (--len != 0);
  80633. }
  80634. #endif
  80635. #ifdef SYS16BIT
  80636. #ifdef __TURBOC__
  80637. # define MY_ZCALLOC
  80638. #define MAX_PTR 10
  80639. local int next_ptr = 0;
  80640. typedef struct ptr_table_s {
  80641. voidpf org_ptr;
  80642. voidpf new_ptr;
  80643. } ptr_table;
  80644. local ptr_table table[MAX_PTR];
  80645. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80646. {
  80647. voidpf buf = opaque; /* just to make some compilers happy */
  80648. ulg bsize = (ulg)items*size;
  80649. if (bsize < 65520L) {
  80650. buf = farmalloc(bsize);
  80651. if (*(ush*)&buf != 0) return buf;
  80652. } else {
  80653. buf = farmalloc(bsize + 16L);
  80654. }
  80655. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80656. table[next_ptr].org_ptr = buf;
  80657. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80658. *(ush*)&buf = 0;
  80659. table[next_ptr++].new_ptr = buf;
  80660. return buf;
  80661. }
  80662. void zcfree (voidpf opaque, voidpf ptr)
  80663. {
  80664. int n;
  80665. if (*(ush*)&ptr != 0) { /* object < 64K */
  80666. farfree(ptr);
  80667. return;
  80668. }
  80669. for (n = 0; n < next_ptr; n++) {
  80670. if (ptr != table[n].new_ptr) continue;
  80671. farfree(table[n].org_ptr);
  80672. while (++n < next_ptr) {
  80673. table[n-1] = table[n];
  80674. }
  80675. next_ptr--;
  80676. return;
  80677. }
  80678. ptr = opaque; /* just to make some compilers happy */
  80679. Assert(0, "zcfree: ptr not found");
  80680. }
  80681. #endif /* __TURBOC__ */
  80682. #ifdef M_I86
  80683. # define MY_ZCALLOC
  80684. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80685. # define _halloc halloc
  80686. # define _hfree hfree
  80687. #endif
  80688. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80689. {
  80690. if (opaque) opaque = 0; /* to make compiler happy */
  80691. return _halloc((long)items, size);
  80692. }
  80693. void zcfree (voidpf opaque, voidpf ptr)
  80694. {
  80695. if (opaque) opaque = 0; /* to make compiler happy */
  80696. _hfree(ptr);
  80697. }
  80698. #endif /* M_I86 */
  80699. #endif /* SYS16BIT */
  80700. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80701. #ifndef STDC
  80702. extern voidp malloc OF((uInt size));
  80703. extern voidp calloc OF((uInt items, uInt size));
  80704. extern void free OF((voidpf ptr));
  80705. #endif
  80706. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80707. {
  80708. if (opaque) items += size - size; /* make compiler happy */
  80709. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80710. (voidpf)calloc(items, size);
  80711. }
  80712. void zcfree (voidpf opaque, voidpf ptr)
  80713. {
  80714. free(ptr);
  80715. if (opaque) return; /* make compiler happy */
  80716. }
  80717. #endif /* MY_ZCALLOC */
  80718. /*** End of inlined file: zutil.c ***/
  80719. #undef Byte
  80720. }
  80721. #else
  80722. #include <zlib.h>
  80723. #endif
  80724. }
  80725. #if JUCE_MSVC
  80726. #pragma warning (pop)
  80727. #endif
  80728. BEGIN_JUCE_NAMESPACE
  80729. using namespace zlibNamespace;
  80730. // internal helper object that holds the zlib structures so they don't have to be
  80731. // included publicly.
  80732. class GZIPDecompressHelper
  80733. {
  80734. public:
  80735. GZIPDecompressHelper (const bool noWrap) throw()
  80736. : data (0),
  80737. dataSize (0),
  80738. finished (true),
  80739. needsDictionary (false),
  80740. error (true),
  80741. streamIsValid (false)
  80742. {
  80743. zerostruct (stream);
  80744. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80745. finished = error = ! streamIsValid;
  80746. }
  80747. ~GZIPDecompressHelper() throw()
  80748. {
  80749. if (streamIsValid)
  80750. inflateEnd (&stream);
  80751. }
  80752. bool needsInput() const throw() { return dataSize <= 0; }
  80753. void setInput (uint8* const data_, const int size) throw()
  80754. {
  80755. data = data_;
  80756. dataSize = size;
  80757. }
  80758. int doNextBlock (uint8* const dest, const int destSize) throw()
  80759. {
  80760. if (streamIsValid && data != 0 && ! finished)
  80761. {
  80762. stream.next_in = data;
  80763. stream.next_out = dest;
  80764. stream.avail_in = dataSize;
  80765. stream.avail_out = destSize;
  80766. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80767. {
  80768. case Z_STREAM_END:
  80769. finished = true;
  80770. // deliberate fall-through
  80771. case Z_OK:
  80772. data += dataSize - stream.avail_in;
  80773. dataSize = stream.avail_in;
  80774. return destSize - stream.avail_out;
  80775. case Z_NEED_DICT:
  80776. needsDictionary = true;
  80777. data += dataSize - stream.avail_in;
  80778. dataSize = stream.avail_in;
  80779. break;
  80780. case Z_DATA_ERROR:
  80781. case Z_MEM_ERROR:
  80782. error = true;
  80783. default:
  80784. break;
  80785. }
  80786. }
  80787. return 0;
  80788. }
  80789. private:
  80790. z_stream stream;
  80791. uint8* data;
  80792. int dataSize;
  80793. public:
  80794. bool finished, needsDictionary, error, streamIsValid;
  80795. };
  80796. const int gzipDecompBufferSize = 32768;
  80797. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80798. const bool deleteSourceWhenDestroyed,
  80799. const bool noWrap_,
  80800. const int64 uncompressedStreamLength_)
  80801. : sourceStream (sourceStream_),
  80802. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80803. uncompressedStreamLength (uncompressedStreamLength_),
  80804. noWrap (noWrap_),
  80805. isEof (false),
  80806. activeBufferSize (0),
  80807. originalSourcePos (sourceStream_->getPosition()),
  80808. currentPos (0),
  80809. buffer (gzipDecompBufferSize),
  80810. helper (new GZIPDecompressHelper (noWrap_))
  80811. {
  80812. }
  80813. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80814. {
  80815. }
  80816. int64 GZIPDecompressorInputStream::getTotalLength()
  80817. {
  80818. return uncompressedStreamLength;
  80819. }
  80820. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80821. {
  80822. if ((howMany > 0) && ! isEof)
  80823. {
  80824. jassert (destBuffer != 0);
  80825. if (destBuffer != 0)
  80826. {
  80827. int numRead = 0;
  80828. uint8* d = (uint8*) destBuffer;
  80829. while (! helper->error)
  80830. {
  80831. const int n = helper->doNextBlock (d, howMany);
  80832. currentPos += n;
  80833. if (n == 0)
  80834. {
  80835. if (helper->finished || helper->needsDictionary)
  80836. {
  80837. isEof = true;
  80838. return numRead;
  80839. }
  80840. if (helper->needsInput())
  80841. {
  80842. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80843. if (activeBufferSize > 0)
  80844. {
  80845. helper->setInput ((uint8*) buffer, activeBufferSize);
  80846. }
  80847. else
  80848. {
  80849. isEof = true;
  80850. return numRead;
  80851. }
  80852. }
  80853. }
  80854. else
  80855. {
  80856. numRead += n;
  80857. howMany -= n;
  80858. d += n;
  80859. if (howMany <= 0)
  80860. return numRead;
  80861. }
  80862. }
  80863. }
  80864. }
  80865. return 0;
  80866. }
  80867. bool GZIPDecompressorInputStream::isExhausted()
  80868. {
  80869. return helper->error || isEof;
  80870. }
  80871. int64 GZIPDecompressorInputStream::getPosition()
  80872. {
  80873. return currentPos;
  80874. }
  80875. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80876. {
  80877. if (newPos < currentPos)
  80878. {
  80879. // to go backwards, reset the stream and start again..
  80880. isEof = false;
  80881. activeBufferSize = 0;
  80882. currentPos = 0;
  80883. helper = new GZIPDecompressHelper (noWrap);
  80884. sourceStream->setPosition (originalSourcePos);
  80885. }
  80886. skipNextBytes (newPos - currentPos);
  80887. return true;
  80888. }
  80889. END_JUCE_NAMESPACE
  80890. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80891. #endif
  80892. #if JUCE_BUILD_MISC
  80893. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80894. #if JUCE_USE_FLAC
  80895. #if JUCE_WINDOWS
  80896. #include <windows.h>
  80897. #endif
  80898. #ifdef _MSC_VER
  80899. #pragma warning (disable : 4505)
  80900. #pragma warning (push)
  80901. #endif
  80902. namespace FlacNamespace
  80903. {
  80904. #if JUCE_INCLUDE_FLAC_CODE
  80905. #define FLAC__NO_DLL 1
  80906. #if ! defined (SIZE_MAX)
  80907. #define SIZE_MAX 0xffffffff
  80908. #endif
  80909. #define __STDC_LIMIT_MACROS 1
  80910. /*** Start of inlined file: all.h ***/
  80911. #ifndef FLAC__ALL_H
  80912. #define FLAC__ALL_H
  80913. /*** Start of inlined file: export.h ***/
  80914. #ifndef FLAC__EXPORT_H
  80915. #define FLAC__EXPORT_H
  80916. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80917. #define FLAC_API
  80918. #else
  80919. #ifdef FLAC_API_EXPORTS
  80920. #define FLAC_API _declspec(dllexport)
  80921. #else
  80922. #define FLAC_API _declspec(dllimport)
  80923. #endif
  80924. #endif
  80925. #define FLAC_API_VERSION_CURRENT 10
  80926. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80927. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80928. #ifdef __cplusplus
  80929. extern "C" {
  80930. #endif
  80931. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80932. #ifdef __cplusplus
  80933. }
  80934. #endif
  80935. #endif
  80936. /*** End of inlined file: export.h ***/
  80937. /*** Start of inlined file: assert.h ***/
  80938. #ifndef FLAC__ASSERT_H
  80939. #define FLAC__ASSERT_H
  80940. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80941. #ifdef DEBUG
  80942. #include <assert.h>
  80943. #define FLAC__ASSERT(x) assert(x)
  80944. #define FLAC__ASSERT_DECLARATION(x) x
  80945. #else
  80946. #define FLAC__ASSERT(x)
  80947. #define FLAC__ASSERT_DECLARATION(x)
  80948. #endif
  80949. #endif
  80950. /*** End of inlined file: assert.h ***/
  80951. /*** Start of inlined file: callback.h ***/
  80952. #ifndef FLAC__CALLBACK_H
  80953. #define FLAC__CALLBACK_H
  80954. /*** Start of inlined file: ordinals.h ***/
  80955. #ifndef FLAC__ORDINALS_H
  80956. #define FLAC__ORDINALS_H
  80957. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80958. #include <inttypes.h>
  80959. #endif
  80960. typedef signed char FLAC__int8;
  80961. typedef unsigned char FLAC__uint8;
  80962. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80963. typedef __int16 FLAC__int16;
  80964. typedef __int32 FLAC__int32;
  80965. typedef __int64 FLAC__int64;
  80966. typedef unsigned __int16 FLAC__uint16;
  80967. typedef unsigned __int32 FLAC__uint32;
  80968. typedef unsigned __int64 FLAC__uint64;
  80969. #elif defined(__EMX__)
  80970. typedef short FLAC__int16;
  80971. typedef long FLAC__int32;
  80972. typedef long long FLAC__int64;
  80973. typedef unsigned short FLAC__uint16;
  80974. typedef unsigned long FLAC__uint32;
  80975. typedef unsigned long long FLAC__uint64;
  80976. #else
  80977. typedef int16_t FLAC__int16;
  80978. typedef int32_t FLAC__int32;
  80979. typedef int64_t FLAC__int64;
  80980. typedef uint16_t FLAC__uint16;
  80981. typedef uint32_t FLAC__uint32;
  80982. typedef uint64_t FLAC__uint64;
  80983. #endif
  80984. typedef int FLAC__bool;
  80985. typedef FLAC__uint8 FLAC__byte;
  80986. #ifdef true
  80987. #undef true
  80988. #endif
  80989. #ifdef false
  80990. #undef false
  80991. #endif
  80992. #ifndef __cplusplus
  80993. #define true 1
  80994. #define false 0
  80995. #endif
  80996. #endif
  80997. /*** End of inlined file: ordinals.h ***/
  80998. #include <stdlib.h> /* for size_t */
  80999. #ifdef __cplusplus
  81000. extern "C" {
  81001. #endif
  81002. typedef void* FLAC__IOHandle;
  81003. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81004. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81005. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  81006. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  81007. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  81008. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  81009. typedef struct {
  81010. FLAC__IOCallback_Read read;
  81011. FLAC__IOCallback_Write write;
  81012. FLAC__IOCallback_Seek seek;
  81013. FLAC__IOCallback_Tell tell;
  81014. FLAC__IOCallback_Eof eof;
  81015. FLAC__IOCallback_Close close;
  81016. } FLAC__IOCallbacks;
  81017. #ifdef __cplusplus
  81018. }
  81019. #endif
  81020. #endif
  81021. /*** End of inlined file: callback.h ***/
  81022. /*** Start of inlined file: format.h ***/
  81023. #ifndef FLAC__FORMAT_H
  81024. #define FLAC__FORMAT_H
  81025. #ifdef __cplusplus
  81026. extern "C" {
  81027. #endif
  81028. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  81029. #define FLAC__MIN_BLOCK_SIZE (16u)
  81030. #define FLAC__MAX_BLOCK_SIZE (65535u)
  81031. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  81032. #define FLAC__MAX_CHANNELS (8u)
  81033. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  81034. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  81035. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  81036. #define FLAC__MAX_SAMPLE_RATE (655350u)
  81037. #define FLAC__MAX_LPC_ORDER (32u)
  81038. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  81039. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  81040. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  81041. #define FLAC__MAX_FIXED_ORDER (4u)
  81042. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  81043. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  81044. extern FLAC_API const char *FLAC__VERSION_STRING;
  81045. extern FLAC_API const char *FLAC__VENDOR_STRING;
  81046. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  81047. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  81048. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  81049. #define FLAC__STREAM_SYNC_LENGTH (4u)
  81050. typedef enum {
  81051. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  81052. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  81053. } FLAC__EntropyCodingMethodType;
  81054. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  81055. typedef struct {
  81056. unsigned *parameters;
  81057. unsigned *raw_bits;
  81058. unsigned capacity_by_order;
  81059. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  81060. typedef struct {
  81061. unsigned order;
  81062. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  81063. } FLAC__EntropyCodingMethod_PartitionedRice;
  81064. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  81065. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  81066. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  81067. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  81068. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  81069. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  81070. typedef struct {
  81071. FLAC__EntropyCodingMethodType type;
  81072. union {
  81073. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  81074. } data;
  81075. } FLAC__EntropyCodingMethod;
  81076. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  81077. typedef enum {
  81078. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  81079. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  81080. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  81081. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  81082. } FLAC__SubframeType;
  81083. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  81084. typedef struct {
  81085. FLAC__int32 value; /**< The constant signal value. */
  81086. } FLAC__Subframe_Constant;
  81087. typedef struct {
  81088. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  81089. } FLAC__Subframe_Verbatim;
  81090. typedef struct {
  81091. FLAC__EntropyCodingMethod entropy_coding_method;
  81092. unsigned order;
  81093. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  81094. const FLAC__int32 *residual;
  81095. } FLAC__Subframe_Fixed;
  81096. typedef struct {
  81097. FLAC__EntropyCodingMethod entropy_coding_method;
  81098. unsigned order;
  81099. unsigned qlp_coeff_precision;
  81100. int quantization_level;
  81101. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81102. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81103. const FLAC__int32 *residual;
  81104. } FLAC__Subframe_LPC;
  81105. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81106. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81107. typedef struct {
  81108. FLAC__SubframeType type;
  81109. union {
  81110. FLAC__Subframe_Constant constant;
  81111. FLAC__Subframe_Fixed fixed;
  81112. FLAC__Subframe_LPC lpc;
  81113. FLAC__Subframe_Verbatim verbatim;
  81114. } data;
  81115. unsigned wasted_bits;
  81116. } FLAC__Subframe;
  81117. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81118. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81119. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81120. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81121. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81122. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81123. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81124. typedef enum {
  81125. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81126. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81127. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81128. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81129. } FLAC__ChannelAssignment;
  81130. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81131. typedef enum {
  81132. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81133. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81134. } FLAC__FrameNumberType;
  81135. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81136. typedef struct {
  81137. unsigned blocksize;
  81138. unsigned sample_rate;
  81139. unsigned channels;
  81140. FLAC__ChannelAssignment channel_assignment;
  81141. unsigned bits_per_sample;
  81142. FLAC__FrameNumberType number_type;
  81143. union {
  81144. FLAC__uint32 frame_number;
  81145. FLAC__uint64 sample_number;
  81146. } number;
  81147. FLAC__uint8 crc;
  81148. } FLAC__FrameHeader;
  81149. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81150. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81151. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81152. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81153. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81154. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81155. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81156. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81157. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81158. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81159. typedef struct {
  81160. FLAC__uint16 crc;
  81161. } FLAC__FrameFooter;
  81162. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81163. typedef struct {
  81164. FLAC__FrameHeader header;
  81165. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81166. FLAC__FrameFooter footer;
  81167. } FLAC__Frame;
  81168. typedef enum {
  81169. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81170. FLAC__METADATA_TYPE_PADDING = 1,
  81171. FLAC__METADATA_TYPE_APPLICATION = 2,
  81172. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81173. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81174. FLAC__METADATA_TYPE_CUESHEET = 5,
  81175. FLAC__METADATA_TYPE_PICTURE = 6,
  81176. FLAC__METADATA_TYPE_UNDEFINED = 7
  81177. } FLAC__MetadataType;
  81178. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81179. typedef struct {
  81180. unsigned min_blocksize, max_blocksize;
  81181. unsigned min_framesize, max_framesize;
  81182. unsigned sample_rate;
  81183. unsigned channels;
  81184. unsigned bits_per_sample;
  81185. FLAC__uint64 total_samples;
  81186. FLAC__byte md5sum[16];
  81187. } FLAC__StreamMetadata_StreamInfo;
  81188. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81189. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81190. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81191. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81192. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81193. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81194. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81195. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81196. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81197. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81198. typedef struct {
  81199. int dummy;
  81200. } FLAC__StreamMetadata_Padding;
  81201. typedef struct {
  81202. FLAC__byte id[4];
  81203. FLAC__byte *data;
  81204. } FLAC__StreamMetadata_Application;
  81205. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81206. typedef struct {
  81207. FLAC__uint64 sample_number;
  81208. FLAC__uint64 stream_offset;
  81209. unsigned frame_samples;
  81210. } FLAC__StreamMetadata_SeekPoint;
  81211. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81212. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81213. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81214. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81215. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81216. typedef struct {
  81217. unsigned num_points;
  81218. FLAC__StreamMetadata_SeekPoint *points;
  81219. } FLAC__StreamMetadata_SeekTable;
  81220. typedef struct {
  81221. FLAC__uint32 length;
  81222. FLAC__byte *entry;
  81223. } FLAC__StreamMetadata_VorbisComment_Entry;
  81224. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81225. typedef struct {
  81226. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81227. FLAC__uint32 num_comments;
  81228. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81229. } FLAC__StreamMetadata_VorbisComment;
  81230. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81231. typedef struct {
  81232. FLAC__uint64 offset;
  81233. FLAC__byte number;
  81234. } FLAC__StreamMetadata_CueSheet_Index;
  81235. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81236. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81237. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81238. typedef struct {
  81239. FLAC__uint64 offset;
  81240. FLAC__byte number;
  81241. char isrc[13];
  81242. unsigned type:1;
  81243. unsigned pre_emphasis:1;
  81244. FLAC__byte num_indices;
  81245. FLAC__StreamMetadata_CueSheet_Index *indices;
  81246. } FLAC__StreamMetadata_CueSheet_Track;
  81247. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81248. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81249. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81250. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81251. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81252. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81253. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81254. typedef struct {
  81255. char media_catalog_number[129];
  81256. FLAC__uint64 lead_in;
  81257. FLAC__bool is_cd;
  81258. unsigned num_tracks;
  81259. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81260. } FLAC__StreamMetadata_CueSheet;
  81261. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81262. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81263. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81264. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81265. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81266. typedef enum {
  81267. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81268. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81269. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81270. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81271. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81272. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81273. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81274. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81275. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81276. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81277. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81278. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81279. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81280. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81281. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81282. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81283. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81284. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81285. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81286. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81287. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81288. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81289. } FLAC__StreamMetadata_Picture_Type;
  81290. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81291. typedef struct {
  81292. FLAC__StreamMetadata_Picture_Type type;
  81293. char *mime_type;
  81294. FLAC__byte *description;
  81295. FLAC__uint32 width;
  81296. FLAC__uint32 height;
  81297. FLAC__uint32 depth;
  81298. FLAC__uint32 colors;
  81299. FLAC__uint32 data_length;
  81300. FLAC__byte *data;
  81301. } FLAC__StreamMetadata_Picture;
  81302. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81303. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81304. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81305. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81306. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81307. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81308. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81309. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81310. typedef struct {
  81311. FLAC__byte *data;
  81312. } FLAC__StreamMetadata_Unknown;
  81313. typedef struct {
  81314. FLAC__MetadataType type;
  81315. FLAC__bool is_last;
  81316. unsigned length;
  81317. union {
  81318. FLAC__StreamMetadata_StreamInfo stream_info;
  81319. FLAC__StreamMetadata_Padding padding;
  81320. FLAC__StreamMetadata_Application application;
  81321. FLAC__StreamMetadata_SeekTable seek_table;
  81322. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81323. FLAC__StreamMetadata_CueSheet cue_sheet;
  81324. FLAC__StreamMetadata_Picture picture;
  81325. FLAC__StreamMetadata_Unknown unknown;
  81326. } data;
  81327. } FLAC__StreamMetadata;
  81328. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81329. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81330. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81331. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81332. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81333. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81334. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81335. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81336. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81337. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81338. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81339. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81340. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81341. #ifdef __cplusplus
  81342. }
  81343. #endif
  81344. #endif
  81345. /*** End of inlined file: format.h ***/
  81346. /*** Start of inlined file: metadata.h ***/
  81347. #ifndef FLAC__METADATA_H
  81348. #define FLAC__METADATA_H
  81349. #include <sys/types.h> /* for off_t */
  81350. #ifdef __cplusplus
  81351. extern "C" {
  81352. #endif
  81353. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81354. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81355. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81356. 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);
  81357. struct FLAC__Metadata_SimpleIterator;
  81358. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81359. typedef enum {
  81360. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81361. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81362. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81363. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81364. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81365. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81366. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81367. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81368. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81369. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81370. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81371. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81372. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81373. } FLAC__Metadata_SimpleIteratorStatus;
  81374. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81375. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81376. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81377. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81378. 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);
  81379. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81380. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81381. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81382. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81383. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81384. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81385. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81386. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81387. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81388. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81389. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81390. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81391. struct FLAC__Metadata_Chain;
  81392. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81393. struct FLAC__Metadata_Iterator;
  81394. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81395. typedef enum {
  81396. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81397. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81398. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81399. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81400. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81401. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81402. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81403. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81404. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81405. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81406. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81407. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81408. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81409. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81410. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81411. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81412. } FLAC__Metadata_ChainStatus;
  81413. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81414. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81415. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81416. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81417. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81418. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81419. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81420. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81421. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81422. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81423. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81424. 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);
  81425. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81426. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81427. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81428. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81429. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81430. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81431. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81432. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81433. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81434. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81435. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81436. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81437. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81438. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81439. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81440. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81441. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81442. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81443. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81444. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81445. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81446. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81447. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81448. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81449. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81450. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81451. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81452. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81453. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81454. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81455. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81456. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81457. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81458. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81459. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81460. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81461. 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);
  81462. 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);
  81463. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81464. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81465. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81466. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81467. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81468. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81469. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81470. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81471. 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);
  81472. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81473. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81474. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81475. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81476. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81477. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81478. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81479. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81480. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81481. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81482. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81483. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81484. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81485. #ifdef __cplusplus
  81486. }
  81487. #endif
  81488. #endif
  81489. /*** End of inlined file: metadata.h ***/
  81490. /*** Start of inlined file: stream_decoder.h ***/
  81491. #ifndef FLAC__STREAM_DECODER_H
  81492. #define FLAC__STREAM_DECODER_H
  81493. #include <stdio.h> /* for FILE */
  81494. #ifdef __cplusplus
  81495. extern "C" {
  81496. #endif
  81497. typedef enum {
  81498. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81499. FLAC__STREAM_DECODER_READ_METADATA,
  81500. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81501. FLAC__STREAM_DECODER_READ_FRAME,
  81502. FLAC__STREAM_DECODER_END_OF_STREAM,
  81503. FLAC__STREAM_DECODER_OGG_ERROR,
  81504. FLAC__STREAM_DECODER_SEEK_ERROR,
  81505. FLAC__STREAM_DECODER_ABORTED,
  81506. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81507. FLAC__STREAM_DECODER_UNINITIALIZED
  81508. } FLAC__StreamDecoderState;
  81509. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81510. typedef enum {
  81511. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81512. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81513. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81514. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81515. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81516. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81517. } FLAC__StreamDecoderInitStatus;
  81518. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81519. typedef enum {
  81520. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81521. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81522. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81523. } FLAC__StreamDecoderReadStatus;
  81524. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81525. typedef enum {
  81526. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81527. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81528. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81529. } FLAC__StreamDecoderSeekStatus;
  81530. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81531. typedef enum {
  81532. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81533. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81534. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81535. } FLAC__StreamDecoderTellStatus;
  81536. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81537. typedef enum {
  81538. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81539. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81540. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81541. } FLAC__StreamDecoderLengthStatus;
  81542. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81543. typedef enum {
  81544. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81545. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81546. } FLAC__StreamDecoderWriteStatus;
  81547. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81548. typedef enum {
  81549. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81550. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81551. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81552. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81553. } FLAC__StreamDecoderErrorStatus;
  81554. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81555. struct FLAC__StreamDecoderProtected;
  81556. struct FLAC__StreamDecoderPrivate;
  81557. typedef struct {
  81558. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81559. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81560. } FLAC__StreamDecoder;
  81561. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81562. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81563. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81564. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81565. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81566. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81567. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81568. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81569. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81570. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81571. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81572. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81573. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81574. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81575. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81576. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81577. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81578. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81579. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81580. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81581. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81582. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81583. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81584. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81585. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81586. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81587. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81588. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81589. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81590. FLAC__StreamDecoder *decoder,
  81591. FLAC__StreamDecoderReadCallback read_callback,
  81592. FLAC__StreamDecoderSeekCallback seek_callback,
  81593. FLAC__StreamDecoderTellCallback tell_callback,
  81594. FLAC__StreamDecoderLengthCallback length_callback,
  81595. FLAC__StreamDecoderEofCallback eof_callback,
  81596. FLAC__StreamDecoderWriteCallback write_callback,
  81597. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81598. FLAC__StreamDecoderErrorCallback error_callback,
  81599. void *client_data
  81600. );
  81601. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81602. FLAC__StreamDecoder *decoder,
  81603. FLAC__StreamDecoderReadCallback read_callback,
  81604. FLAC__StreamDecoderSeekCallback seek_callback,
  81605. FLAC__StreamDecoderTellCallback tell_callback,
  81606. FLAC__StreamDecoderLengthCallback length_callback,
  81607. FLAC__StreamDecoderEofCallback eof_callback,
  81608. FLAC__StreamDecoderWriteCallback write_callback,
  81609. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81610. FLAC__StreamDecoderErrorCallback error_callback,
  81611. void *client_data
  81612. );
  81613. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81614. FLAC__StreamDecoder *decoder,
  81615. FILE *file,
  81616. FLAC__StreamDecoderWriteCallback write_callback,
  81617. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81618. FLAC__StreamDecoderErrorCallback error_callback,
  81619. void *client_data
  81620. );
  81621. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81622. FLAC__StreamDecoder *decoder,
  81623. FILE *file,
  81624. FLAC__StreamDecoderWriteCallback write_callback,
  81625. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81626. FLAC__StreamDecoderErrorCallback error_callback,
  81627. void *client_data
  81628. );
  81629. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81630. FLAC__StreamDecoder *decoder,
  81631. const char *filename,
  81632. FLAC__StreamDecoderWriteCallback write_callback,
  81633. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81634. FLAC__StreamDecoderErrorCallback error_callback,
  81635. void *client_data
  81636. );
  81637. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81638. FLAC__StreamDecoder *decoder,
  81639. const char *filename,
  81640. FLAC__StreamDecoderWriteCallback write_callback,
  81641. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81642. FLAC__StreamDecoderErrorCallback error_callback,
  81643. void *client_data
  81644. );
  81645. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81646. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81647. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81648. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81649. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81650. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81651. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81652. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81653. #ifdef __cplusplus
  81654. }
  81655. #endif
  81656. #endif
  81657. /*** End of inlined file: stream_decoder.h ***/
  81658. /*** Start of inlined file: stream_encoder.h ***/
  81659. #ifndef FLAC__STREAM_ENCODER_H
  81660. #define FLAC__STREAM_ENCODER_H
  81661. #include <stdio.h> /* for FILE */
  81662. #ifdef __cplusplus
  81663. extern "C" {
  81664. #endif
  81665. typedef enum {
  81666. FLAC__STREAM_ENCODER_OK = 0,
  81667. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81668. FLAC__STREAM_ENCODER_OGG_ERROR,
  81669. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81670. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81671. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81672. FLAC__STREAM_ENCODER_IO_ERROR,
  81673. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81674. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81675. } FLAC__StreamEncoderState;
  81676. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81677. typedef enum {
  81678. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81679. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81680. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81681. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81682. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81683. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81684. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81685. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81686. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81687. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81688. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81689. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81690. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81691. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81692. } FLAC__StreamEncoderInitStatus;
  81693. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81694. typedef enum {
  81695. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81696. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81697. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81698. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81699. } FLAC__StreamEncoderReadStatus;
  81700. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81701. typedef enum {
  81702. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81703. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81704. } FLAC__StreamEncoderWriteStatus;
  81705. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81706. typedef enum {
  81707. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81708. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81709. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81710. } FLAC__StreamEncoderSeekStatus;
  81711. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81712. typedef enum {
  81713. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81714. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81715. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81716. } FLAC__StreamEncoderTellStatus;
  81717. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81718. struct FLAC__StreamEncoderProtected;
  81719. struct FLAC__StreamEncoderPrivate;
  81720. typedef struct {
  81721. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81722. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81723. } FLAC__StreamEncoder;
  81724. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81725. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81726. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81727. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81728. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81729. 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);
  81730. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81731. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81732. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81733. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81734. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81735. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81736. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81737. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81738. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81739. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81740. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81741. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81742. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81743. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81744. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81745. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81746. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81747. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81748. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81749. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81750. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81751. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81752. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81753. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81754. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81755. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81756. 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);
  81757. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81758. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81759. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81760. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81761. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81762. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81763. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81764. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81765. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81766. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81767. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81768. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81769. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81770. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81771. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81772. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81773. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81774. 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);
  81775. 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);
  81776. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81777. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81778. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81779. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81780. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81781. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81782. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81783. #ifdef __cplusplus
  81784. }
  81785. #endif
  81786. #endif
  81787. /*** End of inlined file: stream_encoder.h ***/
  81788. #ifdef _MSC_VER
  81789. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81790. {
  81791. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81792. return (x>>16) | (x<<16);
  81793. }
  81794. #endif
  81795. #if defined(_MSC_VER) && defined(_X86_)
  81796. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81797. {
  81798. __asm {
  81799. mov edx, start
  81800. mov ecx, len
  81801. test ecx, ecx
  81802. loop1:
  81803. jz done1
  81804. mov eax, [edx]
  81805. bswap eax
  81806. mov [edx], eax
  81807. add edx, 4
  81808. dec ecx
  81809. jmp short loop1
  81810. done1:
  81811. }
  81812. }
  81813. #endif
  81814. #endif
  81815. /*** End of inlined file: all.h ***/
  81816. /*** Start of inlined file: bitmath.c ***/
  81817. /*** Start of inlined file: juce_FlacHeader.h ***/
  81818. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81819. // tasks..
  81820. #define VERSION "1.2.1"
  81821. #define FLAC__NO_DLL 1
  81822. #if JUCE_MSVC
  81823. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81824. #endif
  81825. #if JUCE_MAC
  81826. #define FLAC__SYS_DARWIN 1
  81827. #endif
  81828. /*** End of inlined file: juce_FlacHeader.h ***/
  81829. #if JUCE_USE_FLAC
  81830. #if HAVE_CONFIG_H
  81831. # include <config.h>
  81832. #endif
  81833. /*** Start of inlined file: bitmath.h ***/
  81834. #ifndef FLAC__PRIVATE__BITMATH_H
  81835. #define FLAC__PRIVATE__BITMATH_H
  81836. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81837. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81838. unsigned FLAC__bitmath_silog2(int v);
  81839. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81840. #endif
  81841. /*** End of inlined file: bitmath.h ***/
  81842. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81843. {
  81844. unsigned l = 0;
  81845. FLAC__ASSERT(v > 0);
  81846. while(v >>= 1)
  81847. l++;
  81848. return l;
  81849. }
  81850. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81851. {
  81852. unsigned l = 0;
  81853. FLAC__ASSERT(v > 0);
  81854. while(v >>= 1)
  81855. l++;
  81856. return l;
  81857. }
  81858. unsigned FLAC__bitmath_silog2(int v)
  81859. {
  81860. while(1) {
  81861. if(v == 0) {
  81862. return 0;
  81863. }
  81864. else if(v > 0) {
  81865. unsigned l = 0;
  81866. while(v) {
  81867. l++;
  81868. v >>= 1;
  81869. }
  81870. return l+1;
  81871. }
  81872. else if(v == -1) {
  81873. return 2;
  81874. }
  81875. else {
  81876. v++;
  81877. v = -v;
  81878. }
  81879. }
  81880. }
  81881. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81882. {
  81883. while(1) {
  81884. if(v == 0) {
  81885. return 0;
  81886. }
  81887. else if(v > 0) {
  81888. unsigned l = 0;
  81889. while(v) {
  81890. l++;
  81891. v >>= 1;
  81892. }
  81893. return l+1;
  81894. }
  81895. else if(v == -1) {
  81896. return 2;
  81897. }
  81898. else {
  81899. v++;
  81900. v = -v;
  81901. }
  81902. }
  81903. }
  81904. #endif
  81905. /*** End of inlined file: bitmath.c ***/
  81906. /*** Start of inlined file: bitreader.c ***/
  81907. /*** Start of inlined file: juce_FlacHeader.h ***/
  81908. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81909. // tasks..
  81910. #define VERSION "1.2.1"
  81911. #define FLAC__NO_DLL 1
  81912. #if JUCE_MSVC
  81913. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81914. #endif
  81915. #if JUCE_MAC
  81916. #define FLAC__SYS_DARWIN 1
  81917. #endif
  81918. /*** End of inlined file: juce_FlacHeader.h ***/
  81919. #if JUCE_USE_FLAC
  81920. #if HAVE_CONFIG_H
  81921. # include <config.h>
  81922. #endif
  81923. #include <stdlib.h> /* for malloc() */
  81924. #include <string.h> /* for memcpy(), memset() */
  81925. #ifdef _MSC_VER
  81926. #include <winsock.h> /* for ntohl() */
  81927. #elif defined FLAC__SYS_DARWIN
  81928. #include <machine/endian.h> /* for ntohl() */
  81929. #elif defined __MINGW32__
  81930. #include <winsock.h> /* for ntohl() */
  81931. #else
  81932. #include <netinet/in.h> /* for ntohl() */
  81933. #endif
  81934. /*** Start of inlined file: bitreader.h ***/
  81935. #ifndef FLAC__PRIVATE__BITREADER_H
  81936. #define FLAC__PRIVATE__BITREADER_H
  81937. #include <stdio.h> /* for FILE */
  81938. /*** Start of inlined file: cpu.h ***/
  81939. #ifndef FLAC__PRIVATE__CPU_H
  81940. #define FLAC__PRIVATE__CPU_H
  81941. #ifdef HAVE_CONFIG_H
  81942. #include <config.h>
  81943. #endif
  81944. typedef enum {
  81945. FLAC__CPUINFO_TYPE_IA32,
  81946. FLAC__CPUINFO_TYPE_PPC,
  81947. FLAC__CPUINFO_TYPE_UNKNOWN
  81948. } FLAC__CPUInfo_Type;
  81949. typedef struct {
  81950. FLAC__bool cpuid;
  81951. FLAC__bool bswap;
  81952. FLAC__bool cmov;
  81953. FLAC__bool mmx;
  81954. FLAC__bool fxsr;
  81955. FLAC__bool sse;
  81956. FLAC__bool sse2;
  81957. FLAC__bool sse3;
  81958. FLAC__bool ssse3;
  81959. FLAC__bool _3dnow;
  81960. FLAC__bool ext3dnow;
  81961. FLAC__bool extmmx;
  81962. } FLAC__CPUInfo_IA32;
  81963. typedef struct {
  81964. FLAC__bool altivec;
  81965. FLAC__bool ppc64;
  81966. } FLAC__CPUInfo_PPC;
  81967. typedef struct {
  81968. FLAC__bool use_asm;
  81969. FLAC__CPUInfo_Type type;
  81970. union {
  81971. FLAC__CPUInfo_IA32 ia32;
  81972. FLAC__CPUInfo_PPC ppc;
  81973. } data;
  81974. } FLAC__CPUInfo;
  81975. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81976. #ifndef FLAC__NO_ASM
  81977. #ifdef FLAC__CPU_IA32
  81978. #ifdef FLAC__HAS_NASM
  81979. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81980. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81981. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81982. #endif
  81983. #endif
  81984. #endif
  81985. #endif
  81986. /*** End of inlined file: cpu.h ***/
  81987. struct FLAC__BitReader;
  81988. typedef struct FLAC__BitReader FLAC__BitReader;
  81989. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81990. FLAC__BitReader *FLAC__bitreader_new(void);
  81991. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81992. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81993. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81994. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81995. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81996. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81997. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81998. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81999. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  82000. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  82001. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  82002. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  82003. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  82004. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  82005. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  82006. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  82007. 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! */
  82008. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  82009. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82010. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82011. #ifndef FLAC__NO_ASM
  82012. # ifdef FLAC__CPU_IA32
  82013. # ifdef FLAC__HAS_NASM
  82014. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82015. # endif
  82016. # endif
  82017. #endif
  82018. #if 0 /* UNUSED */
  82019. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82020. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  82021. #endif
  82022. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  82023. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  82024. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  82025. #endif
  82026. /*** End of inlined file: bitreader.h ***/
  82027. /*** Start of inlined file: crc.h ***/
  82028. #ifndef FLAC__PRIVATE__CRC_H
  82029. #define FLAC__PRIVATE__CRC_H
  82030. extern FLAC__byte const FLAC__crc8_table[256];
  82031. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  82032. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  82033. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  82034. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  82035. extern unsigned FLAC__crc16_table[256];
  82036. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  82037. #if 0
  82038. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  82039. #endif
  82040. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  82041. #endif
  82042. /*** End of inlined file: crc.h ***/
  82043. typedef FLAC__uint32 brword;
  82044. #define FLAC__BYTES_PER_WORD 4
  82045. #define FLAC__BITS_PER_WORD 32
  82046. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82047. #if WORDS_BIGENDIAN
  82048. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82049. #else
  82050. #if defined (_MSC_VER) && defined (_X86_)
  82051. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82052. #else
  82053. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82054. #endif
  82055. #endif
  82056. #define COUNT_ZERO_MSBS(word) ( \
  82057. (word) <= 0xffff ? \
  82058. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  82059. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  82060. )
  82061. #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])) )
  82062. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  82063. static const unsigned char byte_to_unary_table[] = {
  82064. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  82065. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  82066. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82067. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82068. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82069. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82070. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82071. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  82080. };
  82081. #ifdef min
  82082. #undef min
  82083. #endif
  82084. #define min(x,y) ((x)<(y)?(x):(y))
  82085. #ifdef max
  82086. #undef max
  82087. #endif
  82088. #define max(x,y) ((x)>(y)?(x):(y))
  82089. #ifdef _MSC_VER
  82090. #define FLAC__U64L(x) x
  82091. #else
  82092. #define FLAC__U64L(x) x##LLU
  82093. #endif
  82094. #ifndef FLaC__INLINE
  82095. #define FLaC__INLINE
  82096. #endif
  82097. struct FLAC__BitReader {
  82098. brword *buffer;
  82099. unsigned capacity; /* in words */
  82100. unsigned words; /* # of completed words in buffer */
  82101. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82102. unsigned consumed_words; /* #words ... */
  82103. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82104. unsigned read_crc16; /* the running frame CRC */
  82105. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82106. FLAC__BitReaderReadCallback read_callback;
  82107. void *client_data;
  82108. FLAC__CPUInfo cpu_info;
  82109. };
  82110. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82111. {
  82112. register unsigned crc = br->read_crc16;
  82113. #if FLAC__BYTES_PER_WORD == 4
  82114. switch(br->crc16_align) {
  82115. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82116. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82117. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82118. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82119. }
  82120. #elif FLAC__BYTES_PER_WORD == 8
  82121. switch(br->crc16_align) {
  82122. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82123. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82124. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82125. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82126. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82127. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82128. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82129. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82130. }
  82131. #else
  82132. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82133. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82134. br->read_crc16 = crc;
  82135. #endif
  82136. br->crc16_align = 0;
  82137. }
  82138. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82139. {
  82140. unsigned start, end;
  82141. size_t bytes;
  82142. FLAC__byte *target;
  82143. if(br->consumed_words > 0) {
  82144. start = br->consumed_words;
  82145. end = br->words + (br->bytes? 1:0);
  82146. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82147. br->words -= start;
  82148. br->consumed_words = 0;
  82149. }
  82150. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82151. if(bytes == 0)
  82152. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82153. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82154. #if WORDS_BIGENDIAN
  82155. #else
  82156. if(br->bytes)
  82157. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82158. #endif
  82159. if(!br->read_callback(target, &bytes, br->client_data))
  82160. return false;
  82161. #if WORDS_BIGENDIAN
  82162. #else
  82163. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82164. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82165. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82166. start = br->words;
  82167. local_swap32_block_(br->buffer + start, end - start);
  82168. }
  82169. else
  82170. # endif
  82171. for(start = br->words; start < end; start++)
  82172. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82173. #endif
  82174. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82175. br->words = end / FLAC__BYTES_PER_WORD;
  82176. br->bytes = end % FLAC__BYTES_PER_WORD;
  82177. return true;
  82178. }
  82179. FLAC__BitReader *FLAC__bitreader_new(void)
  82180. {
  82181. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82182. return br;
  82183. }
  82184. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82185. {
  82186. FLAC__ASSERT(0 != br);
  82187. FLAC__bitreader_free(br);
  82188. free(br);
  82189. }
  82190. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82191. {
  82192. FLAC__ASSERT(0 != br);
  82193. br->words = br->bytes = 0;
  82194. br->consumed_words = br->consumed_bits = 0;
  82195. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82196. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82197. if(br->buffer == 0)
  82198. return false;
  82199. br->read_callback = rcb;
  82200. br->client_data = cd;
  82201. br->cpu_info = cpu;
  82202. return true;
  82203. }
  82204. void FLAC__bitreader_free(FLAC__BitReader *br)
  82205. {
  82206. FLAC__ASSERT(0 != br);
  82207. if(0 != br->buffer)
  82208. free(br->buffer);
  82209. br->buffer = 0;
  82210. br->capacity = 0;
  82211. br->words = br->bytes = 0;
  82212. br->consumed_words = br->consumed_bits = 0;
  82213. br->read_callback = 0;
  82214. br->client_data = 0;
  82215. }
  82216. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82217. {
  82218. br->words = br->bytes = 0;
  82219. br->consumed_words = br->consumed_bits = 0;
  82220. return true;
  82221. }
  82222. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82223. {
  82224. unsigned i, j;
  82225. if(br == 0) {
  82226. fprintf(out, "bitreader is NULL\n");
  82227. }
  82228. else {
  82229. 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);
  82230. for(i = 0; i < br->words; i++) {
  82231. fprintf(out, "%08X: ", i);
  82232. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82233. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82234. fprintf(out, ".");
  82235. else
  82236. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82237. fprintf(out, "\n");
  82238. }
  82239. if(br->bytes > 0) {
  82240. fprintf(out, "%08X: ", i);
  82241. for(j = 0; j < br->bytes*8; j++)
  82242. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82243. fprintf(out, ".");
  82244. else
  82245. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82246. fprintf(out, "\n");
  82247. }
  82248. }
  82249. }
  82250. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82251. {
  82252. FLAC__ASSERT(0 != br);
  82253. FLAC__ASSERT(0 != br->buffer);
  82254. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82255. br->read_crc16 = (unsigned)seed;
  82256. br->crc16_align = br->consumed_bits;
  82257. }
  82258. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82259. {
  82260. FLAC__ASSERT(0 != br);
  82261. FLAC__ASSERT(0 != br->buffer);
  82262. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82263. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82264. if(br->consumed_bits) {
  82265. const brword tail = br->buffer[br->consumed_words];
  82266. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82267. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82268. }
  82269. return br->read_crc16;
  82270. }
  82271. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82272. {
  82273. return ((br->consumed_bits & 7) == 0);
  82274. }
  82275. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82276. {
  82277. return 8 - (br->consumed_bits & 7);
  82278. }
  82279. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82280. {
  82281. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82282. }
  82283. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82284. {
  82285. FLAC__ASSERT(0 != br);
  82286. FLAC__ASSERT(0 != br->buffer);
  82287. FLAC__ASSERT(bits <= 32);
  82288. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82289. FLAC__ASSERT(br->consumed_words <= br->words);
  82290. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82291. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82292. *val = 0;
  82293. return true;
  82294. }
  82295. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82296. if(!bitreader_read_from_client_(br))
  82297. return false;
  82298. }
  82299. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82300. if(br->consumed_bits) {
  82301. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82302. const brword word = br->buffer[br->consumed_words];
  82303. if(bits < n) {
  82304. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82305. br->consumed_bits += bits;
  82306. return true;
  82307. }
  82308. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82309. bits -= n;
  82310. crc16_update_word_(br, word);
  82311. br->consumed_words++;
  82312. br->consumed_bits = 0;
  82313. 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 */
  82314. *val <<= bits;
  82315. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82316. br->consumed_bits = bits;
  82317. }
  82318. return true;
  82319. }
  82320. else {
  82321. const brword word = br->buffer[br->consumed_words];
  82322. if(bits < FLAC__BITS_PER_WORD) {
  82323. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82324. br->consumed_bits = bits;
  82325. return true;
  82326. }
  82327. *val = word;
  82328. crc16_update_word_(br, word);
  82329. br->consumed_words++;
  82330. return true;
  82331. }
  82332. }
  82333. else {
  82334. if(br->consumed_bits) {
  82335. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82336. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82337. br->consumed_bits += bits;
  82338. return true;
  82339. }
  82340. else {
  82341. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82342. br->consumed_bits += bits;
  82343. return true;
  82344. }
  82345. }
  82346. }
  82347. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82348. {
  82349. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82350. return false;
  82351. *val <<= (32-bits);
  82352. *val >>= (32-bits);
  82353. return true;
  82354. }
  82355. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82356. {
  82357. FLAC__uint32 hi, lo;
  82358. if(bits > 32) {
  82359. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82360. return false;
  82361. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82362. return false;
  82363. *val = hi;
  82364. *val <<= 32;
  82365. *val |= lo;
  82366. }
  82367. else {
  82368. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82369. return false;
  82370. *val = lo;
  82371. }
  82372. return true;
  82373. }
  82374. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82375. {
  82376. FLAC__uint32 x8, x32 = 0;
  82377. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82378. return false;
  82379. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82380. return false;
  82381. x32 |= (x8 << 8);
  82382. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82383. return false;
  82384. x32 |= (x8 << 16);
  82385. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82386. return false;
  82387. x32 |= (x8 << 24);
  82388. *val = x32;
  82389. return true;
  82390. }
  82391. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82392. {
  82393. FLAC__ASSERT(0 != br);
  82394. FLAC__ASSERT(0 != br->buffer);
  82395. if(bits > 0) {
  82396. const unsigned n = br->consumed_bits & 7;
  82397. unsigned m;
  82398. FLAC__uint32 x;
  82399. if(n != 0) {
  82400. m = min(8-n, bits);
  82401. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82402. return false;
  82403. bits -= m;
  82404. }
  82405. m = bits / 8;
  82406. if(m > 0) {
  82407. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82408. return false;
  82409. bits %= 8;
  82410. }
  82411. if(bits > 0) {
  82412. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82413. return false;
  82414. }
  82415. }
  82416. return true;
  82417. }
  82418. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82419. {
  82420. FLAC__uint32 x;
  82421. FLAC__ASSERT(0 != br);
  82422. FLAC__ASSERT(0 != br->buffer);
  82423. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82424. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82425. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82426. return false;
  82427. nvals--;
  82428. }
  82429. if(0 == nvals)
  82430. return true;
  82431. while(nvals >= FLAC__BYTES_PER_WORD) {
  82432. if(br->consumed_words < br->words) {
  82433. br->consumed_words++;
  82434. nvals -= FLAC__BYTES_PER_WORD;
  82435. }
  82436. else if(!bitreader_read_from_client_(br))
  82437. return false;
  82438. }
  82439. while(nvals) {
  82440. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82441. return false;
  82442. nvals--;
  82443. }
  82444. return true;
  82445. }
  82446. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82447. {
  82448. FLAC__uint32 x;
  82449. FLAC__ASSERT(0 != br);
  82450. FLAC__ASSERT(0 != br->buffer);
  82451. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82452. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82453. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82454. return false;
  82455. *val++ = (FLAC__byte)x;
  82456. nvals--;
  82457. }
  82458. if(0 == nvals)
  82459. return true;
  82460. while(nvals >= FLAC__BYTES_PER_WORD) {
  82461. if(br->consumed_words < br->words) {
  82462. const brword word = br->buffer[br->consumed_words++];
  82463. #if FLAC__BYTES_PER_WORD == 4
  82464. val[0] = (FLAC__byte)(word >> 24);
  82465. val[1] = (FLAC__byte)(word >> 16);
  82466. val[2] = (FLAC__byte)(word >> 8);
  82467. val[3] = (FLAC__byte)word;
  82468. #elif FLAC__BYTES_PER_WORD == 8
  82469. val[0] = (FLAC__byte)(word >> 56);
  82470. val[1] = (FLAC__byte)(word >> 48);
  82471. val[2] = (FLAC__byte)(word >> 40);
  82472. val[3] = (FLAC__byte)(word >> 32);
  82473. val[4] = (FLAC__byte)(word >> 24);
  82474. val[5] = (FLAC__byte)(word >> 16);
  82475. val[6] = (FLAC__byte)(word >> 8);
  82476. val[7] = (FLAC__byte)word;
  82477. #else
  82478. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82479. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82480. #endif
  82481. val += FLAC__BYTES_PER_WORD;
  82482. nvals -= FLAC__BYTES_PER_WORD;
  82483. }
  82484. else if(!bitreader_read_from_client_(br))
  82485. return false;
  82486. }
  82487. while(nvals) {
  82488. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82489. return false;
  82490. *val++ = (FLAC__byte)x;
  82491. nvals--;
  82492. }
  82493. return true;
  82494. }
  82495. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82496. #if 0 /* slow but readable version */
  82497. {
  82498. unsigned bit;
  82499. FLAC__ASSERT(0 != br);
  82500. FLAC__ASSERT(0 != br->buffer);
  82501. *val = 0;
  82502. while(1) {
  82503. if(!FLAC__bitreader_read_bit(br, &bit))
  82504. return false;
  82505. if(bit)
  82506. break;
  82507. else
  82508. *val++;
  82509. }
  82510. return true;
  82511. }
  82512. #else
  82513. {
  82514. unsigned i;
  82515. FLAC__ASSERT(0 != br);
  82516. FLAC__ASSERT(0 != br->buffer);
  82517. *val = 0;
  82518. while(1) {
  82519. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82520. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82521. if(b) {
  82522. i = COUNT_ZERO_MSBS(b);
  82523. *val += i;
  82524. i++;
  82525. br->consumed_bits += i;
  82526. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82527. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82528. br->consumed_words++;
  82529. br->consumed_bits = 0;
  82530. }
  82531. return true;
  82532. }
  82533. else {
  82534. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82535. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82536. br->consumed_words++;
  82537. br->consumed_bits = 0;
  82538. }
  82539. }
  82540. if(br->bytes) {
  82541. const unsigned end = br->bytes * 8;
  82542. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82543. if(b) {
  82544. i = COUNT_ZERO_MSBS(b);
  82545. *val += i;
  82546. i++;
  82547. br->consumed_bits += i;
  82548. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82549. return true;
  82550. }
  82551. else {
  82552. *val += end - br->consumed_bits;
  82553. br->consumed_bits += end;
  82554. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82555. }
  82556. }
  82557. if(!bitreader_read_from_client_(br))
  82558. return false;
  82559. }
  82560. }
  82561. #endif
  82562. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82563. {
  82564. FLAC__uint32 lsbs = 0, msbs = 0;
  82565. unsigned uval;
  82566. FLAC__ASSERT(0 != br);
  82567. FLAC__ASSERT(0 != br->buffer);
  82568. FLAC__ASSERT(parameter <= 31);
  82569. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82570. return false;
  82571. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82572. return false;
  82573. uval = (msbs << parameter) | lsbs;
  82574. if(uval & 1)
  82575. *val = -((int)(uval >> 1)) - 1;
  82576. else
  82577. *val = (int)(uval >> 1);
  82578. return true;
  82579. }
  82580. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82581. #ifdef _MSC_VER
  82582. {
  82583. unsigned i;
  82584. unsigned uval = 0;
  82585. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82586. register unsigned cwords;
  82587. register unsigned cbits;
  82588. FLAC__ASSERT(0 != br);
  82589. FLAC__ASSERT(0 != br->buffer);
  82590. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82591. FLAC__ASSERT(parameter < 32);
  82592. if(nvals == 0)
  82593. return true;
  82594. cbits = br->consumed_bits;
  82595. cwords = br->consumed_words;
  82596. while(1) {
  82597. while(1) {
  82598. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82599. brword b = br->buffer[cwords] << cbits;
  82600. if(b) {
  82601. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82602. __asm {
  82603. bsr eax, b
  82604. not eax
  82605. and eax, 31
  82606. mov i, eax
  82607. }
  82608. #else
  82609. i = COUNT_ZERO_MSBS(b);
  82610. #endif
  82611. uval += i;
  82612. bits = parameter;
  82613. i++;
  82614. cbits += i;
  82615. if(cbits == FLAC__BITS_PER_WORD) {
  82616. crc16_update_word_(br, br->buffer[cwords]);
  82617. cwords++;
  82618. cbits = 0;
  82619. }
  82620. goto break1;
  82621. }
  82622. else {
  82623. uval += FLAC__BITS_PER_WORD - cbits;
  82624. crc16_update_word_(br, br->buffer[cwords]);
  82625. cwords++;
  82626. cbits = 0;
  82627. }
  82628. }
  82629. if(br->bytes) {
  82630. const unsigned end = br->bytes * 8;
  82631. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82632. if(b) {
  82633. i = COUNT_ZERO_MSBS(b);
  82634. uval += i;
  82635. bits = parameter;
  82636. i++;
  82637. cbits += i;
  82638. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82639. goto break1;
  82640. }
  82641. else {
  82642. uval += end - cbits;
  82643. cbits += end;
  82644. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82645. }
  82646. }
  82647. br->consumed_bits = cbits;
  82648. br->consumed_words = cwords;
  82649. if(!bitreader_read_from_client_(br))
  82650. return false;
  82651. cwords = br->consumed_words;
  82652. }
  82653. break1:
  82654. FLAC__ASSERT(cwords <= br->words);
  82655. if(bits) {
  82656. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82657. br->consumed_bits = cbits;
  82658. br->consumed_words = cwords;
  82659. if(!bitreader_read_from_client_(br))
  82660. return false;
  82661. cwords = br->consumed_words;
  82662. }
  82663. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82664. if(cbits) {
  82665. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82666. const brword word = br->buffer[cwords];
  82667. if(bits < n) {
  82668. uval <<= bits;
  82669. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82670. cbits += bits;
  82671. goto break2;
  82672. }
  82673. uval <<= n;
  82674. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82675. bits -= n;
  82676. crc16_update_word_(br, word);
  82677. cwords++;
  82678. cbits = 0;
  82679. 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 */
  82680. uval <<= bits;
  82681. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82682. cbits = bits;
  82683. }
  82684. goto break2;
  82685. }
  82686. else {
  82687. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82688. uval <<= bits;
  82689. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82690. cbits = bits;
  82691. goto break2;
  82692. }
  82693. }
  82694. else {
  82695. uval <<= bits;
  82696. if(cbits) {
  82697. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82698. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82699. cbits += bits;
  82700. goto break2;
  82701. }
  82702. else {
  82703. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82704. cbits += bits;
  82705. goto break2;
  82706. }
  82707. }
  82708. }
  82709. break2:
  82710. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82711. --nvals;
  82712. if(nvals == 0) {
  82713. br->consumed_bits = cbits;
  82714. br->consumed_words = cwords;
  82715. return true;
  82716. }
  82717. uval = 0;
  82718. ++vals;
  82719. }
  82720. }
  82721. #else
  82722. {
  82723. unsigned i;
  82724. unsigned uval = 0;
  82725. register unsigned cwords;
  82726. register unsigned cbits;
  82727. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82728. FLAC__ASSERT(0 != br);
  82729. FLAC__ASSERT(0 != br->buffer);
  82730. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82731. FLAC__ASSERT(parameter < 32);
  82732. if(nvals == 0)
  82733. return true;
  82734. cbits = br->consumed_bits;
  82735. cwords = br->consumed_words;
  82736. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82737. while(1) {
  82738. while(1) {
  82739. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82740. brword b = br->buffer[cwords] << cbits;
  82741. if(b) {
  82742. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82743. asm volatile (
  82744. "bsrl %1, %0;"
  82745. "notl %0;"
  82746. "andl $31, %0;"
  82747. : "=r"(i)
  82748. : "r"(b)
  82749. );
  82750. #else
  82751. i = COUNT_ZERO_MSBS(b);
  82752. #endif
  82753. uval += i;
  82754. cbits += i;
  82755. cbits++; /* skip over stop bit */
  82756. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82757. crc16_update_word_(br, br->buffer[cwords]);
  82758. cwords++;
  82759. cbits = 0;
  82760. }
  82761. goto break1;
  82762. }
  82763. else {
  82764. uval += FLAC__BITS_PER_WORD - cbits;
  82765. crc16_update_word_(br, br->buffer[cwords]);
  82766. cwords++;
  82767. cbits = 0;
  82768. }
  82769. }
  82770. if(br->bytes) {
  82771. const unsigned end = br->bytes * 8;
  82772. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82773. if(b) {
  82774. i = COUNT_ZERO_MSBS(b);
  82775. uval += i;
  82776. cbits += i;
  82777. cbits++; /* skip over stop bit */
  82778. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82779. goto break1;
  82780. }
  82781. else {
  82782. uval += end - cbits;
  82783. cbits += end;
  82784. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82785. }
  82786. }
  82787. br->consumed_bits = cbits;
  82788. br->consumed_words = cwords;
  82789. if(!bitreader_read_from_client_(br))
  82790. return false;
  82791. cwords = br->consumed_words;
  82792. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82793. }
  82794. break1:
  82795. ucbits -= uval;
  82796. ucbits--; /* account for stop bit */
  82797. FLAC__ASSERT(cwords <= br->words);
  82798. if(parameter) {
  82799. while(ucbits < parameter) {
  82800. br->consumed_bits = cbits;
  82801. br->consumed_words = cwords;
  82802. if(!bitreader_read_from_client_(br))
  82803. return false;
  82804. cwords = br->consumed_words;
  82805. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82806. }
  82807. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82808. if(cbits) {
  82809. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82810. const brword word = br->buffer[cwords];
  82811. if(parameter < n) {
  82812. uval <<= parameter;
  82813. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82814. cbits += parameter;
  82815. }
  82816. else {
  82817. uval <<= n;
  82818. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82819. crc16_update_word_(br, word);
  82820. cwords++;
  82821. cbits = parameter - n;
  82822. 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 */
  82823. uval <<= cbits;
  82824. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82825. }
  82826. }
  82827. }
  82828. else {
  82829. cbits = parameter;
  82830. uval <<= parameter;
  82831. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82832. }
  82833. }
  82834. else {
  82835. uval <<= parameter;
  82836. if(cbits) {
  82837. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82838. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82839. cbits += parameter;
  82840. }
  82841. else {
  82842. cbits = parameter;
  82843. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82844. }
  82845. }
  82846. }
  82847. ucbits -= parameter;
  82848. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82849. --nvals;
  82850. if(nvals == 0) {
  82851. br->consumed_bits = cbits;
  82852. br->consumed_words = cwords;
  82853. return true;
  82854. }
  82855. uval = 0;
  82856. ++vals;
  82857. }
  82858. }
  82859. #endif
  82860. #if 0 /* UNUSED */
  82861. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82862. {
  82863. FLAC__uint32 lsbs = 0, msbs = 0;
  82864. unsigned bit, uval, k;
  82865. FLAC__ASSERT(0 != br);
  82866. FLAC__ASSERT(0 != br->buffer);
  82867. k = FLAC__bitmath_ilog2(parameter);
  82868. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82869. return false;
  82870. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82871. return false;
  82872. if(parameter == 1u<<k) {
  82873. uval = (msbs << k) | lsbs;
  82874. }
  82875. else {
  82876. unsigned d = (1 << (k+1)) - parameter;
  82877. if(lsbs >= d) {
  82878. if(!FLAC__bitreader_read_bit(br, &bit))
  82879. return false;
  82880. lsbs <<= 1;
  82881. lsbs |= bit;
  82882. lsbs -= d;
  82883. }
  82884. uval = msbs * parameter + lsbs;
  82885. }
  82886. if(uval & 1)
  82887. *val = -((int)(uval >> 1)) - 1;
  82888. else
  82889. *val = (int)(uval >> 1);
  82890. return true;
  82891. }
  82892. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82893. {
  82894. FLAC__uint32 lsbs, msbs = 0;
  82895. unsigned bit, k;
  82896. FLAC__ASSERT(0 != br);
  82897. FLAC__ASSERT(0 != br->buffer);
  82898. k = FLAC__bitmath_ilog2(parameter);
  82899. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82900. return false;
  82901. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82902. return false;
  82903. if(parameter == 1u<<k) {
  82904. *val = (msbs << k) | lsbs;
  82905. }
  82906. else {
  82907. unsigned d = (1 << (k+1)) - parameter;
  82908. if(lsbs >= d) {
  82909. if(!FLAC__bitreader_read_bit(br, &bit))
  82910. return false;
  82911. lsbs <<= 1;
  82912. lsbs |= bit;
  82913. lsbs -= d;
  82914. }
  82915. *val = msbs * parameter + lsbs;
  82916. }
  82917. return true;
  82918. }
  82919. #endif /* UNUSED */
  82920. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82921. {
  82922. FLAC__uint32 v = 0;
  82923. FLAC__uint32 x;
  82924. unsigned i;
  82925. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82926. return false;
  82927. if(raw)
  82928. raw[(*rawlen)++] = (FLAC__byte)x;
  82929. if(!(x & 0x80)) { /* 0xxxxxxx */
  82930. v = x;
  82931. i = 0;
  82932. }
  82933. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82934. v = x & 0x1F;
  82935. i = 1;
  82936. }
  82937. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82938. v = x & 0x0F;
  82939. i = 2;
  82940. }
  82941. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82942. v = x & 0x07;
  82943. i = 3;
  82944. }
  82945. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82946. v = x & 0x03;
  82947. i = 4;
  82948. }
  82949. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82950. v = x & 0x01;
  82951. i = 5;
  82952. }
  82953. else {
  82954. *val = 0xffffffff;
  82955. return true;
  82956. }
  82957. for( ; i; i--) {
  82958. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82959. return false;
  82960. if(raw)
  82961. raw[(*rawlen)++] = (FLAC__byte)x;
  82962. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82963. *val = 0xffffffff;
  82964. return true;
  82965. }
  82966. v <<= 6;
  82967. v |= (x & 0x3F);
  82968. }
  82969. *val = v;
  82970. return true;
  82971. }
  82972. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82973. {
  82974. FLAC__uint64 v = 0;
  82975. FLAC__uint32 x;
  82976. unsigned i;
  82977. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82978. return false;
  82979. if(raw)
  82980. raw[(*rawlen)++] = (FLAC__byte)x;
  82981. if(!(x & 0x80)) { /* 0xxxxxxx */
  82982. v = x;
  82983. i = 0;
  82984. }
  82985. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82986. v = x & 0x1F;
  82987. i = 1;
  82988. }
  82989. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82990. v = x & 0x0F;
  82991. i = 2;
  82992. }
  82993. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82994. v = x & 0x07;
  82995. i = 3;
  82996. }
  82997. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82998. v = x & 0x03;
  82999. i = 4;
  83000. }
  83001. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  83002. v = x & 0x01;
  83003. i = 5;
  83004. }
  83005. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  83006. v = 0;
  83007. i = 6;
  83008. }
  83009. else {
  83010. *val = FLAC__U64L(0xffffffffffffffff);
  83011. return true;
  83012. }
  83013. for( ; i; i--) {
  83014. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83015. return false;
  83016. if(raw)
  83017. raw[(*rawlen)++] = (FLAC__byte)x;
  83018. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  83019. *val = FLAC__U64L(0xffffffffffffffff);
  83020. return true;
  83021. }
  83022. v <<= 6;
  83023. v |= (x & 0x3F);
  83024. }
  83025. *val = v;
  83026. return true;
  83027. }
  83028. #endif
  83029. /*** End of inlined file: bitreader.c ***/
  83030. /*** Start of inlined file: bitwriter.c ***/
  83031. /*** Start of inlined file: juce_FlacHeader.h ***/
  83032. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83033. // tasks..
  83034. #define VERSION "1.2.1"
  83035. #define FLAC__NO_DLL 1
  83036. #if JUCE_MSVC
  83037. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83038. #endif
  83039. #if JUCE_MAC
  83040. #define FLAC__SYS_DARWIN 1
  83041. #endif
  83042. /*** End of inlined file: juce_FlacHeader.h ***/
  83043. #if JUCE_USE_FLAC
  83044. #if HAVE_CONFIG_H
  83045. # include <config.h>
  83046. #endif
  83047. #include <stdlib.h> /* for malloc() */
  83048. #include <string.h> /* for memcpy(), memset() */
  83049. #ifdef _MSC_VER
  83050. #include <winsock.h> /* for ntohl() */
  83051. #elif defined FLAC__SYS_DARWIN
  83052. #include <machine/endian.h> /* for ntohl() */
  83053. #elif defined __MINGW32__
  83054. #include <winsock.h> /* for ntohl() */
  83055. #else
  83056. #include <netinet/in.h> /* for ntohl() */
  83057. #endif
  83058. #if 0 /* UNUSED */
  83059. #endif
  83060. /*** Start of inlined file: bitwriter.h ***/
  83061. #ifndef FLAC__PRIVATE__BITWRITER_H
  83062. #define FLAC__PRIVATE__BITWRITER_H
  83063. #include <stdio.h> /* for FILE */
  83064. struct FLAC__BitWriter;
  83065. typedef struct FLAC__BitWriter FLAC__BitWriter;
  83066. FLAC__BitWriter *FLAC__bitwriter_new(void);
  83067. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  83068. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  83069. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  83070. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  83071. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  83072. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  83073. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  83074. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  83075. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  83076. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  83077. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  83078. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  83079. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  83080. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  83081. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  83082. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  83083. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  83084. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  83085. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  83086. #if 0 /* UNUSED */
  83087. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  83088. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  83089. #endif
  83090. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  83091. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  83092. #if 0 /* UNUSED */
  83093. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  83094. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  83095. #endif
  83096. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83097. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83098. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83099. #endif
  83100. /*** End of inlined file: bitwriter.h ***/
  83101. /*** Start of inlined file: alloc.h ***/
  83102. #ifndef FLAC__SHARE__ALLOC_H
  83103. #define FLAC__SHARE__ALLOC_H
  83104. #if HAVE_CONFIG_H
  83105. # include <config.h>
  83106. #endif
  83107. #include <limits.h> /* for SIZE_MAX */
  83108. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83109. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83110. #endif
  83111. #include <stdlib.h> /* for size_t, malloc(), etc */
  83112. #ifndef SIZE_MAX
  83113. # ifndef SIZE_T_MAX
  83114. # ifdef _MSC_VER
  83115. # define SIZE_T_MAX UINT_MAX
  83116. # else
  83117. # error
  83118. # endif
  83119. # endif
  83120. # define SIZE_MAX SIZE_T_MAX
  83121. #endif
  83122. #ifndef FLaC__INLINE
  83123. #define FLaC__INLINE
  83124. #endif
  83125. static FLaC__INLINE void *safe_malloc_(size_t size)
  83126. {
  83127. if(!size)
  83128. size++;
  83129. return malloc(size);
  83130. }
  83131. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83132. {
  83133. if(!nmemb || !size)
  83134. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83135. return calloc(nmemb, size);
  83136. }
  83137. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83138. {
  83139. size2 += size1;
  83140. if(size2 < size1)
  83141. return 0;
  83142. return safe_malloc_(size2);
  83143. }
  83144. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83145. {
  83146. size2 += size1;
  83147. if(size2 < size1)
  83148. return 0;
  83149. size3 += size2;
  83150. if(size3 < size2)
  83151. return 0;
  83152. return safe_malloc_(size3);
  83153. }
  83154. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83155. {
  83156. size2 += size1;
  83157. if(size2 < size1)
  83158. return 0;
  83159. size3 += size2;
  83160. if(size3 < size2)
  83161. return 0;
  83162. size4 += size3;
  83163. if(size4 < size3)
  83164. return 0;
  83165. return safe_malloc_(size4);
  83166. }
  83167. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83168. #if 0
  83169. needs support for cases where sizeof(size_t) != 4
  83170. {
  83171. if(sizeof(size_t) == 4) {
  83172. if ((double)size1 * (double)size2 < 4294967296.0)
  83173. return malloc(size1*size2);
  83174. }
  83175. return 0;
  83176. }
  83177. #else
  83178. {
  83179. if(!size1 || !size2)
  83180. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83181. if(size1 > SIZE_MAX / size2)
  83182. return 0;
  83183. return malloc(size1*size2);
  83184. }
  83185. #endif
  83186. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83187. {
  83188. if(!size1 || !size2 || !size3)
  83189. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83190. if(size1 > SIZE_MAX / size2)
  83191. return 0;
  83192. size1 *= size2;
  83193. if(size1 > SIZE_MAX / size3)
  83194. return 0;
  83195. return malloc(size1*size3);
  83196. }
  83197. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83198. {
  83199. if(!size1 || !size2)
  83200. return safe_malloc_(size3);
  83201. if(size1 > SIZE_MAX / size2)
  83202. return 0;
  83203. return safe_malloc_add_2op_(size1*size2, size3);
  83204. }
  83205. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83206. {
  83207. if(!size1 || (!size2 && !size3))
  83208. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83209. size2 += size3;
  83210. if(size2 < size3)
  83211. return 0;
  83212. return safe_malloc_mul_2op_(size1, size2);
  83213. }
  83214. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83215. {
  83216. size2 += size1;
  83217. if(size2 < size1)
  83218. return 0;
  83219. return realloc(ptr, size2);
  83220. }
  83221. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83222. {
  83223. size2 += size1;
  83224. if(size2 < size1)
  83225. return 0;
  83226. size3 += size2;
  83227. if(size3 < size2)
  83228. return 0;
  83229. return realloc(ptr, size3);
  83230. }
  83231. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83232. {
  83233. size2 += size1;
  83234. if(size2 < size1)
  83235. return 0;
  83236. size3 += size2;
  83237. if(size3 < size2)
  83238. return 0;
  83239. size4 += size3;
  83240. if(size4 < size3)
  83241. return 0;
  83242. return realloc(ptr, size4);
  83243. }
  83244. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83245. {
  83246. if(!size1 || !size2)
  83247. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83248. if(size1 > SIZE_MAX / size2)
  83249. return 0;
  83250. return realloc(ptr, size1*size2);
  83251. }
  83252. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83253. {
  83254. if(!size1 || (!size2 && !size3))
  83255. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83256. size2 += size3;
  83257. if(size2 < size3)
  83258. return 0;
  83259. return safe_realloc_mul_2op_(ptr, size1, size2);
  83260. }
  83261. #endif
  83262. /*** End of inlined file: alloc.h ***/
  83263. typedef FLAC__uint32 bwword;
  83264. #define FLAC__BYTES_PER_WORD 4
  83265. #define FLAC__BITS_PER_WORD 32
  83266. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83267. #if WORDS_BIGENDIAN
  83268. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83269. #else
  83270. #ifdef _MSC_VER
  83271. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83272. #else
  83273. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83274. #endif
  83275. #endif
  83276. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83277. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83278. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83279. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83280. #ifdef min
  83281. #undef min
  83282. #endif
  83283. #define min(x,y) ((x)<(y)?(x):(y))
  83284. #ifdef _MSC_VER
  83285. #define FLAC__U64L(x) x
  83286. #else
  83287. #define FLAC__U64L(x) x##LLU
  83288. #endif
  83289. #ifndef FLaC__INLINE
  83290. #define FLaC__INLINE
  83291. #endif
  83292. struct FLAC__BitWriter {
  83293. bwword *buffer;
  83294. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83295. unsigned capacity; /* capacity of buffer in words */
  83296. unsigned words; /* # of complete words in buffer */
  83297. unsigned bits; /* # of used bits in accum */
  83298. };
  83299. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83300. {
  83301. unsigned new_capacity;
  83302. bwword *new_buffer;
  83303. FLAC__ASSERT(0 != bw);
  83304. FLAC__ASSERT(0 != bw->buffer);
  83305. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83306. if(bw->capacity >= new_capacity)
  83307. return true;
  83308. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83309. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83310. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83311. FLAC__ASSERT(new_capacity > bw->capacity);
  83312. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83313. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83314. if(new_buffer == 0)
  83315. return false;
  83316. bw->buffer = new_buffer;
  83317. bw->capacity = new_capacity;
  83318. return true;
  83319. }
  83320. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83321. {
  83322. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83323. return bw;
  83324. }
  83325. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83326. {
  83327. FLAC__ASSERT(0 != bw);
  83328. FLAC__bitwriter_free(bw);
  83329. free(bw);
  83330. }
  83331. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83332. {
  83333. FLAC__ASSERT(0 != bw);
  83334. bw->words = bw->bits = 0;
  83335. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83336. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83337. if(bw->buffer == 0)
  83338. return false;
  83339. return true;
  83340. }
  83341. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83342. {
  83343. FLAC__ASSERT(0 != bw);
  83344. if(0 != bw->buffer)
  83345. free(bw->buffer);
  83346. bw->buffer = 0;
  83347. bw->capacity = 0;
  83348. bw->words = bw->bits = 0;
  83349. }
  83350. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83351. {
  83352. bw->words = bw->bits = 0;
  83353. }
  83354. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83355. {
  83356. unsigned i, j;
  83357. if(bw == 0) {
  83358. fprintf(out, "bitwriter is NULL\n");
  83359. }
  83360. else {
  83361. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83362. for(i = 0; i < bw->words; i++) {
  83363. fprintf(out, "%08X: ", i);
  83364. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83365. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83366. fprintf(out, "\n");
  83367. }
  83368. if(bw->bits > 0) {
  83369. fprintf(out, "%08X: ", i);
  83370. for(j = 0; j < bw->bits; j++)
  83371. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83372. fprintf(out, "\n");
  83373. }
  83374. }
  83375. }
  83376. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83377. {
  83378. const FLAC__byte *buffer;
  83379. size_t bytes;
  83380. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83381. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83382. return false;
  83383. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83384. FLAC__bitwriter_release_buffer(bw);
  83385. return true;
  83386. }
  83387. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83388. {
  83389. const FLAC__byte *buffer;
  83390. size_t bytes;
  83391. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83392. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83393. return false;
  83394. *crc = FLAC__crc8(buffer, bytes);
  83395. FLAC__bitwriter_release_buffer(bw);
  83396. return true;
  83397. }
  83398. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83399. {
  83400. return ((bw->bits & 7) == 0);
  83401. }
  83402. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83403. {
  83404. return FLAC__TOTAL_BITS(bw);
  83405. }
  83406. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83407. {
  83408. FLAC__ASSERT((bw->bits & 7) == 0);
  83409. if(bw->bits & 7)
  83410. return false;
  83411. if(bw->bits) {
  83412. FLAC__ASSERT(bw->words <= bw->capacity);
  83413. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83414. return false;
  83415. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83416. }
  83417. *buffer = (FLAC__byte*)bw->buffer;
  83418. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83419. return true;
  83420. }
  83421. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83422. {
  83423. (void)bw;
  83424. }
  83425. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83426. {
  83427. unsigned n;
  83428. FLAC__ASSERT(0 != bw);
  83429. FLAC__ASSERT(0 != bw->buffer);
  83430. if(bits == 0)
  83431. return true;
  83432. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83433. return false;
  83434. if(bw->bits) {
  83435. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83436. bw->accum <<= n;
  83437. bits -= n;
  83438. bw->bits += n;
  83439. if(bw->bits == FLAC__BITS_PER_WORD) {
  83440. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83441. bw->bits = 0;
  83442. }
  83443. else
  83444. return true;
  83445. }
  83446. while(bits >= FLAC__BITS_PER_WORD) {
  83447. bw->buffer[bw->words++] = 0;
  83448. bits -= FLAC__BITS_PER_WORD;
  83449. }
  83450. if(bits > 0) {
  83451. bw->accum = 0;
  83452. bw->bits = bits;
  83453. }
  83454. return true;
  83455. }
  83456. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83457. {
  83458. register unsigned left;
  83459. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83460. FLAC__ASSERT(0 != bw);
  83461. FLAC__ASSERT(0 != bw->buffer);
  83462. FLAC__ASSERT(bits <= 32);
  83463. if(bits == 0)
  83464. return true;
  83465. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83466. return false;
  83467. left = FLAC__BITS_PER_WORD - bw->bits;
  83468. if(bits < left) {
  83469. bw->accum <<= bits;
  83470. bw->accum |= val;
  83471. bw->bits += bits;
  83472. }
  83473. 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 */
  83474. bw->accum <<= left;
  83475. bw->accum |= val >> (bw->bits = bits - left);
  83476. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83477. bw->accum = val;
  83478. }
  83479. else {
  83480. bw->accum = val;
  83481. bw->bits = 0;
  83482. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83483. }
  83484. return true;
  83485. }
  83486. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83487. {
  83488. if(bits < 32)
  83489. val &= (~(0xffffffff << bits));
  83490. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83491. }
  83492. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83493. {
  83494. if(bits > 32) {
  83495. return
  83496. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83497. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83498. }
  83499. else
  83500. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83501. }
  83502. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83503. {
  83504. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83505. return false;
  83506. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83507. return false;
  83508. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83509. return false;
  83510. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83511. return false;
  83512. return true;
  83513. }
  83514. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83515. {
  83516. unsigned i;
  83517. for(i = 0; i < nvals; i++) {
  83518. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83519. return false;
  83520. }
  83521. return true;
  83522. }
  83523. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83524. {
  83525. if(val < 32)
  83526. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83527. else
  83528. return
  83529. FLAC__bitwriter_write_zeroes(bw, val) &&
  83530. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83531. }
  83532. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83533. {
  83534. FLAC__uint32 uval;
  83535. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83536. uval = (val<<1) ^ (val>>31);
  83537. return 1 + parameter + (uval >> parameter);
  83538. }
  83539. #if 0 /* UNUSED */
  83540. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83541. {
  83542. unsigned bits, msbs, uval;
  83543. unsigned k;
  83544. FLAC__ASSERT(parameter > 0);
  83545. if(val < 0)
  83546. uval = (unsigned)(((-(++val)) << 1) + 1);
  83547. else
  83548. uval = (unsigned)(val << 1);
  83549. k = FLAC__bitmath_ilog2(parameter);
  83550. if(parameter == 1u<<k) {
  83551. FLAC__ASSERT(k <= 30);
  83552. msbs = uval >> k;
  83553. bits = 1 + k + msbs;
  83554. }
  83555. else {
  83556. unsigned q, r, d;
  83557. d = (1 << (k+1)) - parameter;
  83558. q = uval / parameter;
  83559. r = uval - (q * parameter);
  83560. bits = 1 + q + k;
  83561. if(r >= d)
  83562. bits++;
  83563. }
  83564. return bits;
  83565. }
  83566. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83567. {
  83568. unsigned bits, msbs;
  83569. unsigned k;
  83570. FLAC__ASSERT(parameter > 0);
  83571. k = FLAC__bitmath_ilog2(parameter);
  83572. if(parameter == 1u<<k) {
  83573. FLAC__ASSERT(k <= 30);
  83574. msbs = uval >> k;
  83575. bits = 1 + k + msbs;
  83576. }
  83577. else {
  83578. unsigned q, r, d;
  83579. d = (1 << (k+1)) - parameter;
  83580. q = uval / parameter;
  83581. r = uval - (q * parameter);
  83582. bits = 1 + q + k;
  83583. if(r >= d)
  83584. bits++;
  83585. }
  83586. return bits;
  83587. }
  83588. #endif /* UNUSED */
  83589. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83590. {
  83591. unsigned total_bits, interesting_bits, msbs;
  83592. FLAC__uint32 uval, pattern;
  83593. FLAC__ASSERT(0 != bw);
  83594. FLAC__ASSERT(0 != bw->buffer);
  83595. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83596. uval = (val<<1) ^ (val>>31);
  83597. msbs = uval >> parameter;
  83598. interesting_bits = 1 + parameter;
  83599. total_bits = interesting_bits + msbs;
  83600. pattern = 1 << parameter; /* the unary end bit */
  83601. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83602. if(total_bits <= 32)
  83603. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83604. else
  83605. return
  83606. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83607. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83608. }
  83609. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83610. {
  83611. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83612. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83613. FLAC__uint32 uval;
  83614. unsigned left;
  83615. const unsigned lsbits = 1 + parameter;
  83616. unsigned msbits;
  83617. FLAC__ASSERT(0 != bw);
  83618. FLAC__ASSERT(0 != bw->buffer);
  83619. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83620. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83621. while(nvals) {
  83622. uval = (*vals<<1) ^ (*vals>>31);
  83623. msbits = uval >> parameter;
  83624. #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) */
  83625. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83626. bw->bits = bw->bits + msbits + lsbits;
  83627. uval |= mask1; /* set stop bit */
  83628. uval &= mask2; /* mask off unused top bits */
  83629. bw->accum <<= msbits;
  83630. bw->accum <<= lsbits;
  83631. bw->accum |= uval;
  83632. if(bw->bits == FLAC__BITS_PER_WORD) {
  83633. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83634. bw->bits = 0;
  83635. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83636. FLAC__ASSERT(bw->capacity == bw->words);
  83637. return false;
  83638. }
  83639. }
  83640. }
  83641. else {
  83642. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83643. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83644. bw->bits = bw->bits + msbits + lsbits;
  83645. uval |= mask1; /* set stop bit */
  83646. uval &= mask2; /* mask off unused top bits */
  83647. bw->accum <<= msbits + lsbits;
  83648. bw->accum |= uval;
  83649. }
  83650. else {
  83651. #endif
  83652. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83653. return false;
  83654. if(msbits) {
  83655. if(bw->bits) {
  83656. left = FLAC__BITS_PER_WORD - bw->bits;
  83657. if(msbits < left) {
  83658. bw->accum <<= msbits;
  83659. bw->bits += msbits;
  83660. goto break1;
  83661. }
  83662. else {
  83663. bw->accum <<= left;
  83664. msbits -= left;
  83665. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83666. bw->bits = 0;
  83667. }
  83668. }
  83669. while(msbits >= FLAC__BITS_PER_WORD) {
  83670. bw->buffer[bw->words++] = 0;
  83671. msbits -= FLAC__BITS_PER_WORD;
  83672. }
  83673. if(msbits > 0) {
  83674. bw->accum = 0;
  83675. bw->bits = msbits;
  83676. }
  83677. }
  83678. break1:
  83679. uval |= mask1; /* set stop bit */
  83680. uval &= mask2; /* mask off unused top bits */
  83681. left = FLAC__BITS_PER_WORD - bw->bits;
  83682. if(lsbits < left) {
  83683. bw->accum <<= lsbits;
  83684. bw->accum |= uval;
  83685. bw->bits += lsbits;
  83686. }
  83687. else {
  83688. FLAC__ASSERT(bw->bits);
  83689. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83690. bw->accum <<= left;
  83691. bw->accum |= uval >> (bw->bits = lsbits - left);
  83692. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83693. bw->accum = uval;
  83694. }
  83695. #if 1
  83696. }
  83697. #endif
  83698. vals++;
  83699. nvals--;
  83700. }
  83701. return true;
  83702. }
  83703. #if 0 /* UNUSED */
  83704. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83705. {
  83706. unsigned total_bits, msbs, uval;
  83707. unsigned k;
  83708. FLAC__ASSERT(0 != bw);
  83709. FLAC__ASSERT(0 != bw->buffer);
  83710. FLAC__ASSERT(parameter > 0);
  83711. if(val < 0)
  83712. uval = (unsigned)(((-(++val)) << 1) + 1);
  83713. else
  83714. uval = (unsigned)(val << 1);
  83715. k = FLAC__bitmath_ilog2(parameter);
  83716. if(parameter == 1u<<k) {
  83717. unsigned pattern;
  83718. FLAC__ASSERT(k <= 30);
  83719. msbs = uval >> k;
  83720. total_bits = 1 + k + msbs;
  83721. pattern = 1 << k; /* the unary end bit */
  83722. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83723. if(total_bits <= 32) {
  83724. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83725. return false;
  83726. }
  83727. else {
  83728. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83729. return false;
  83730. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83731. return false;
  83732. }
  83733. }
  83734. else {
  83735. unsigned q, r, d;
  83736. d = (1 << (k+1)) - parameter;
  83737. q = uval / parameter;
  83738. r = uval - (q * parameter);
  83739. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83740. return false;
  83741. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83742. return false;
  83743. if(r >= d) {
  83744. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83745. return false;
  83746. }
  83747. else {
  83748. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83749. return false;
  83750. }
  83751. }
  83752. return true;
  83753. }
  83754. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83755. {
  83756. unsigned total_bits, msbs;
  83757. unsigned k;
  83758. FLAC__ASSERT(0 != bw);
  83759. FLAC__ASSERT(0 != bw->buffer);
  83760. FLAC__ASSERT(parameter > 0);
  83761. k = FLAC__bitmath_ilog2(parameter);
  83762. if(parameter == 1u<<k) {
  83763. unsigned pattern;
  83764. FLAC__ASSERT(k <= 30);
  83765. msbs = uval >> k;
  83766. total_bits = 1 + k + msbs;
  83767. pattern = 1 << k; /* the unary end bit */
  83768. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83769. if(total_bits <= 32) {
  83770. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83771. return false;
  83772. }
  83773. else {
  83774. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83775. return false;
  83776. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83777. return false;
  83778. }
  83779. }
  83780. else {
  83781. unsigned q, r, d;
  83782. d = (1 << (k+1)) - parameter;
  83783. q = uval / parameter;
  83784. r = uval - (q * parameter);
  83785. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83786. return false;
  83787. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83788. return false;
  83789. if(r >= d) {
  83790. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83791. return false;
  83792. }
  83793. else {
  83794. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83795. return false;
  83796. }
  83797. }
  83798. return true;
  83799. }
  83800. #endif /* UNUSED */
  83801. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83802. {
  83803. FLAC__bool ok = 1;
  83804. FLAC__ASSERT(0 != bw);
  83805. FLAC__ASSERT(0 != bw->buffer);
  83806. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83807. if(val < 0x80) {
  83808. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83809. }
  83810. else if(val < 0x800) {
  83811. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83812. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83813. }
  83814. else if(val < 0x10000) {
  83815. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83816. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83817. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83818. }
  83819. else if(val < 0x200000) {
  83820. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83821. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83822. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83823. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83824. }
  83825. else if(val < 0x4000000) {
  83826. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83827. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83828. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83829. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83830. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83831. }
  83832. else {
  83833. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83834. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83835. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83836. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83837. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83838. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83839. }
  83840. return ok;
  83841. }
  83842. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83843. {
  83844. FLAC__bool ok = 1;
  83845. FLAC__ASSERT(0 != bw);
  83846. FLAC__ASSERT(0 != bw->buffer);
  83847. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83848. if(val < 0x80) {
  83849. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83850. }
  83851. else if(val < 0x800) {
  83852. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83853. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83854. }
  83855. else if(val < 0x10000) {
  83856. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83857. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83858. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83859. }
  83860. else if(val < 0x200000) {
  83861. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83862. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83863. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83864. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83865. }
  83866. else if(val < 0x4000000) {
  83867. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83868. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83869. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83870. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83871. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83872. }
  83873. else if(val < 0x80000000) {
  83874. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83875. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83876. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83877. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83878. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83879. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83880. }
  83881. else {
  83882. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83883. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83884. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83885. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83886. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83887. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83888. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83889. }
  83890. return ok;
  83891. }
  83892. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83893. {
  83894. if(bw->bits & 7u)
  83895. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83896. else
  83897. return true;
  83898. }
  83899. #endif
  83900. /*** End of inlined file: bitwriter.c ***/
  83901. /*** Start of inlined file: cpu.c ***/
  83902. /*** Start of inlined file: juce_FlacHeader.h ***/
  83903. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83904. // tasks..
  83905. #define VERSION "1.2.1"
  83906. #define FLAC__NO_DLL 1
  83907. #if JUCE_MSVC
  83908. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83909. #endif
  83910. #if JUCE_MAC
  83911. #define FLAC__SYS_DARWIN 1
  83912. #endif
  83913. /*** End of inlined file: juce_FlacHeader.h ***/
  83914. #if JUCE_USE_FLAC
  83915. #if HAVE_CONFIG_H
  83916. # include <config.h>
  83917. #endif
  83918. #include <stdlib.h>
  83919. #include <stdio.h>
  83920. #if defined FLAC__CPU_IA32
  83921. # include <signal.h>
  83922. #elif defined FLAC__CPU_PPC
  83923. # if !defined FLAC__NO_ASM
  83924. # if defined FLAC__SYS_DARWIN
  83925. # include <sys/sysctl.h>
  83926. # include <mach/mach.h>
  83927. # include <mach/mach_host.h>
  83928. # include <mach/host_info.h>
  83929. # include <mach/machine.h>
  83930. # ifndef CPU_SUBTYPE_POWERPC_970
  83931. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83932. # endif
  83933. # else /* FLAC__SYS_DARWIN */
  83934. # include <signal.h>
  83935. # include <setjmp.h>
  83936. static sigjmp_buf jmpbuf;
  83937. static volatile sig_atomic_t canjump = 0;
  83938. static void sigill_handler (int sig)
  83939. {
  83940. if (!canjump) {
  83941. signal (sig, SIG_DFL);
  83942. raise (sig);
  83943. }
  83944. canjump = 0;
  83945. siglongjmp (jmpbuf, 1);
  83946. }
  83947. # endif /* FLAC__SYS_DARWIN */
  83948. # endif /* FLAC__NO_ASM */
  83949. #endif /* FLAC__CPU_PPC */
  83950. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83951. #include <sys/param.h>
  83952. #include <sys/sysctl.h>
  83953. #include <machine/cpu.h>
  83954. #endif
  83955. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83956. #include <sys/types.h>
  83957. #include <sys/sysctl.h>
  83958. #endif
  83959. #if defined(__APPLE__)
  83960. #endif
  83961. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83962. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83963. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83964. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83965. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83966. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83967. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83968. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83969. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83970. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83971. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83972. # if defined(__linux__)
  83973. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83974. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83975. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83976. {
  83977. (void)signal;
  83978. sc.eip += 3 + 3 + 6;
  83979. }
  83980. # else
  83981. # include <sys/ucontext.h>
  83982. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83983. {
  83984. (void)signal, (void)si;
  83985. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83986. }
  83987. # endif
  83988. # elif defined(_MSC_VER)
  83989. # include <windows.h>
  83990. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83991. # ifdef USE_TRY_CATCH_FLAVOR
  83992. # else
  83993. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83994. {
  83995. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83996. ep->ContextRecord->Eip += 3 + 3 + 6;
  83997. return EXCEPTION_CONTINUE_EXECUTION;
  83998. }
  83999. return EXCEPTION_CONTINUE_SEARCH;
  84000. }
  84001. # endif
  84002. # endif
  84003. #endif
  84004. void FLAC__cpu_info(FLAC__CPUInfo *info)
  84005. {
  84006. #ifdef FLAC__CPU_IA32
  84007. info->type = FLAC__CPUINFO_TYPE_IA32;
  84008. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  84009. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  84010. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  84011. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  84012. info->data.ia32.cmov = false;
  84013. info->data.ia32.mmx = false;
  84014. info->data.ia32.fxsr = false;
  84015. info->data.ia32.sse = false;
  84016. info->data.ia32.sse2 = false;
  84017. info->data.ia32.sse3 = false;
  84018. info->data.ia32.ssse3 = false;
  84019. info->data.ia32._3dnow = false;
  84020. info->data.ia32.ext3dnow = false;
  84021. info->data.ia32.extmmx = false;
  84022. if(info->data.ia32.cpuid) {
  84023. FLAC__uint32 flags_edx, flags_ecx;
  84024. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  84025. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  84026. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  84027. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  84028. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  84029. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  84030. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  84031. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  84032. #ifdef FLAC__USE_3DNOW
  84033. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  84034. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  84035. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  84036. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  84037. #else
  84038. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  84039. #endif
  84040. #ifdef DEBUG
  84041. fprintf(stderr, "CPU info (IA-32):\n");
  84042. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  84043. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  84044. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  84045. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  84046. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  84047. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84048. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  84049. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  84050. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  84051. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  84052. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  84053. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  84054. #endif
  84055. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  84056. #if defined FLAC__NO_SSE_OS
  84057. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84058. #elif defined FLAC__SSE_OS
  84059. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  84060. int sse = 0;
  84061. size_t len;
  84062. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  84063. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  84064. if(!sse)
  84065. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84066. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  84067. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  84068. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  84069. size_t len = sizeof(val);
  84070. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84071. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84072. else { /* double-check SSE2 */
  84073. mib[1] = CPU_SSE2;
  84074. len = sizeof(val);
  84075. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84076. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84077. }
  84078. # else
  84079. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84080. # endif
  84081. #elif defined(__linux__)
  84082. int sse = 0;
  84083. struct sigaction sigill_save;
  84084. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84085. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  84086. #else
  84087. struct sigaction sigill_sse;
  84088. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  84089. __sigemptyset(&sigill_sse.sa_mask);
  84090. 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 */
  84091. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  84092. #endif
  84093. {
  84094. asm volatile (
  84095. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  84096. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84097. "incl %0\n\t" /* SIGILL handler will jump over this */
  84098. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84099. "nop\n\t"
  84100. "nop\n\t"
  84101. "nop\n\t"
  84102. "nop\n\t"
  84103. "nop\n\t"
  84104. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84105. "nop\n\t"
  84106. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84107. : "=r"(sse)
  84108. : "r"(sse)
  84109. );
  84110. sigaction(SIGILL, &sigill_save, NULL);
  84111. }
  84112. if(!sse)
  84113. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84114. #elif defined(_MSC_VER)
  84115. # ifdef USE_TRY_CATCH_FLAVOR
  84116. _try {
  84117. __asm {
  84118. # if _MSC_VER <= 1200
  84119. _emit 0x0F
  84120. _emit 0x57
  84121. _emit 0xC0
  84122. # else
  84123. xorps xmm0,xmm0
  84124. # endif
  84125. }
  84126. }
  84127. _except(EXCEPTION_EXECUTE_HANDLER) {
  84128. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84129. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84130. }
  84131. # else
  84132. int sse = 0;
  84133. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84134. __asm {
  84135. # if _MSC_VER <= 1200
  84136. _emit 0x0F
  84137. _emit 0x57
  84138. _emit 0xC0
  84139. # else
  84140. xorps xmm0,xmm0
  84141. # endif
  84142. inc sse
  84143. nop
  84144. nop
  84145. nop
  84146. nop
  84147. nop
  84148. nop
  84149. nop
  84150. nop
  84151. nop
  84152. }
  84153. SetUnhandledExceptionFilter(save);
  84154. if(!sse)
  84155. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84156. # endif
  84157. #else
  84158. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84159. #endif
  84160. #ifdef DEBUG
  84161. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84162. #endif
  84163. }
  84164. }
  84165. #else
  84166. info->use_asm = false;
  84167. #endif
  84168. #elif defined FLAC__CPU_PPC
  84169. info->type = FLAC__CPUINFO_TYPE_PPC;
  84170. # if !defined FLAC__NO_ASM
  84171. info->use_asm = true;
  84172. # ifdef FLAC__USE_ALTIVEC
  84173. # if defined FLAC__SYS_DARWIN
  84174. {
  84175. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84176. size_t len = sizeof(val);
  84177. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84178. }
  84179. {
  84180. host_basic_info_data_t hostInfo;
  84181. mach_msg_type_number_t infoCount;
  84182. infoCount = HOST_BASIC_INFO_COUNT;
  84183. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84184. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84185. }
  84186. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84187. {
  84188. info->data.ppc.altivec = 0;
  84189. info->data.ppc.ppc64 = 0;
  84190. signal (SIGILL, sigill_handler);
  84191. canjump = 0;
  84192. if (!sigsetjmp (jmpbuf, 1)) {
  84193. canjump = 1;
  84194. asm volatile (
  84195. "mtspr 256, %0\n\t"
  84196. "vand %%v0, %%v0, %%v0"
  84197. :
  84198. : "r" (-1)
  84199. );
  84200. info->data.ppc.altivec = 1;
  84201. }
  84202. canjump = 0;
  84203. if (!sigsetjmp (jmpbuf, 1)) {
  84204. int x = 0;
  84205. canjump = 1;
  84206. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84207. info->data.ppc.ppc64 = 1;
  84208. }
  84209. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84210. }
  84211. # endif
  84212. # else /* !FLAC__USE_ALTIVEC */
  84213. info->data.ppc.altivec = 0;
  84214. info->data.ppc.ppc64 = 0;
  84215. # endif
  84216. # else
  84217. info->use_asm = false;
  84218. # endif
  84219. #else
  84220. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84221. info->use_asm = false;
  84222. #endif
  84223. }
  84224. #endif
  84225. /*** End of inlined file: cpu.c ***/
  84226. /*** Start of inlined file: crc.c ***/
  84227. /*** Start of inlined file: juce_FlacHeader.h ***/
  84228. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84229. // tasks..
  84230. #define VERSION "1.2.1"
  84231. #define FLAC__NO_DLL 1
  84232. #if JUCE_MSVC
  84233. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84234. #endif
  84235. #if JUCE_MAC
  84236. #define FLAC__SYS_DARWIN 1
  84237. #endif
  84238. /*** End of inlined file: juce_FlacHeader.h ***/
  84239. #if JUCE_USE_FLAC
  84240. #if HAVE_CONFIG_H
  84241. # include <config.h>
  84242. #endif
  84243. FLAC__byte const FLAC__crc8_table[256] = {
  84244. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84245. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84246. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84247. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84248. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84249. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84250. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84251. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84252. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84253. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84254. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84255. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84256. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84257. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84258. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84259. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84260. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84261. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84262. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84263. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84264. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84265. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84266. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84267. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84268. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84269. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84270. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84271. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84272. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84273. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84274. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84275. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84276. };
  84277. unsigned FLAC__crc16_table[256] = {
  84278. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84279. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84280. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84281. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84282. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84283. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84284. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84285. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84286. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84287. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84288. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84289. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84290. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84291. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84292. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84293. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84294. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84295. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84296. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84297. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84298. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84299. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84300. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84301. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84302. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84303. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84304. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84305. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84306. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84307. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84308. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84309. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84310. };
  84311. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84312. {
  84313. *crc = FLAC__crc8_table[*crc ^ data];
  84314. }
  84315. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84316. {
  84317. while(len--)
  84318. *crc = FLAC__crc8_table[*crc ^ *data++];
  84319. }
  84320. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84321. {
  84322. FLAC__uint8 crc = 0;
  84323. while(len--)
  84324. crc = FLAC__crc8_table[crc ^ *data++];
  84325. return crc;
  84326. }
  84327. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84328. {
  84329. unsigned crc = 0;
  84330. while(len--)
  84331. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84332. return crc;
  84333. }
  84334. #endif
  84335. /*** End of inlined file: crc.c ***/
  84336. /*** Start of inlined file: fixed.c ***/
  84337. /*** Start of inlined file: juce_FlacHeader.h ***/
  84338. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84339. // tasks..
  84340. #define VERSION "1.2.1"
  84341. #define FLAC__NO_DLL 1
  84342. #if JUCE_MSVC
  84343. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84344. #endif
  84345. #if JUCE_MAC
  84346. #define FLAC__SYS_DARWIN 1
  84347. #endif
  84348. /*** End of inlined file: juce_FlacHeader.h ***/
  84349. #if JUCE_USE_FLAC
  84350. #if HAVE_CONFIG_H
  84351. # include <config.h>
  84352. #endif
  84353. #include <math.h>
  84354. #include <string.h>
  84355. /*** Start of inlined file: fixed.h ***/
  84356. #ifndef FLAC__PRIVATE__FIXED_H
  84357. #define FLAC__PRIVATE__FIXED_H
  84358. #ifdef HAVE_CONFIG_H
  84359. #include <config.h>
  84360. #endif
  84361. /*** Start of inlined file: float.h ***/
  84362. #ifndef FLAC__PRIVATE__FLOAT_H
  84363. #define FLAC__PRIVATE__FLOAT_H
  84364. #ifdef HAVE_CONFIG_H
  84365. #include <config.h>
  84366. #endif
  84367. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84368. typedef double FLAC__double;
  84369. typedef float FLAC__float;
  84370. typedef float FLAC__real;
  84371. #else
  84372. typedef FLAC__int32 FLAC__fixedpoint;
  84373. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84374. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84375. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84376. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84377. extern const FLAC__fixedpoint FLAC__FP_E;
  84378. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84379. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84380. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84381. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84382. #endif
  84383. #endif
  84384. /*** End of inlined file: float.h ***/
  84385. /*** Start of inlined file: format.h ***/
  84386. #ifndef FLAC__PRIVATE__FORMAT_H
  84387. #define FLAC__PRIVATE__FORMAT_H
  84388. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84389. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84390. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84391. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84392. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84393. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84394. #endif
  84395. /*** End of inlined file: format.h ***/
  84396. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84397. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84398. # ifndef FLAC__NO_ASM
  84399. # ifdef FLAC__CPU_IA32
  84400. # ifdef FLAC__HAS_NASM
  84401. 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]);
  84402. # endif
  84403. # endif
  84404. # endif
  84405. 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]);
  84406. #else
  84407. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84408. 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]);
  84409. #endif
  84410. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84411. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84412. #endif
  84413. /*** End of inlined file: fixed.h ***/
  84414. #ifndef M_LN2
  84415. #define M_LN2 0.69314718055994530942
  84416. #endif
  84417. #ifdef min
  84418. #undef min
  84419. #endif
  84420. #define min(x,y) ((x) < (y)? (x) : (y))
  84421. #ifdef local_abs
  84422. #undef local_abs
  84423. #endif
  84424. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84425. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84426. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84427. {
  84428. FLAC__uint32 rbps;
  84429. unsigned bits; /* the number of bits required to represent a number */
  84430. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84431. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84432. FLAC__ASSERT(err > 0);
  84433. FLAC__ASSERT(n > 0);
  84434. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84435. if(err <= n)
  84436. return 0;
  84437. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84438. err <<= fracbits;
  84439. err /= n;
  84440. FLAC__ASSERT(err > 0);
  84441. bits = FLAC__bitmath_ilog2(err)+1;
  84442. if(bits > 16) {
  84443. err >>= (bits-16);
  84444. fracbits -= (bits-16);
  84445. }
  84446. rbps = (FLAC__uint32)err;
  84447. rbps *= FLAC__FP_LN2;
  84448. fracbits += 16;
  84449. FLAC__ASSERT(fracbits >= 0);
  84450. {
  84451. const int f = fracbits & 3;
  84452. if(f) {
  84453. rbps >>= f;
  84454. fracbits -= f;
  84455. }
  84456. }
  84457. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84458. if(rbps == 0)
  84459. return 0;
  84460. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84461. FLAC__ASSERT(fracbits >= -3);
  84462. if(fracbits < 16)
  84463. return rbps << (16-fracbits);
  84464. else if(fracbits > 16)
  84465. return rbps >> (fracbits-16);
  84466. else
  84467. return rbps;
  84468. }
  84469. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84470. {
  84471. FLAC__uint32 rbps;
  84472. unsigned bits; /* the number of bits required to represent a number */
  84473. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84474. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84475. FLAC__ASSERT(err > 0);
  84476. FLAC__ASSERT(n > 0);
  84477. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84478. if(err <= n)
  84479. return 0;
  84480. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84481. err <<= fracbits;
  84482. err /= n;
  84483. FLAC__ASSERT(err > 0);
  84484. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84485. if(bits > 16) {
  84486. err >>= (bits-16);
  84487. fracbits -= (bits-16);
  84488. }
  84489. rbps = (FLAC__uint32)err;
  84490. rbps *= FLAC__FP_LN2;
  84491. fracbits += 16;
  84492. FLAC__ASSERT(fracbits >= 0);
  84493. {
  84494. const int f = fracbits & 3;
  84495. if(f) {
  84496. rbps >>= f;
  84497. fracbits -= f;
  84498. }
  84499. }
  84500. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84501. if(rbps == 0)
  84502. return 0;
  84503. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84504. FLAC__ASSERT(fracbits >= -3);
  84505. if(fracbits < 16)
  84506. return rbps << (16-fracbits);
  84507. else if(fracbits > 16)
  84508. return rbps >> (fracbits-16);
  84509. else
  84510. return rbps;
  84511. }
  84512. #endif
  84513. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84514. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84515. #else
  84516. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84517. #endif
  84518. {
  84519. FLAC__int32 last_error_0 = data[-1];
  84520. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84521. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84522. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84523. FLAC__int32 error, save;
  84524. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84525. unsigned i, order;
  84526. for(i = 0; i < data_len; i++) {
  84527. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84528. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84529. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84530. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84531. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84532. }
  84533. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84534. order = 0;
  84535. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84536. order = 1;
  84537. else if(total_error_2 < min(total_error_3, total_error_4))
  84538. order = 2;
  84539. else if(total_error_3 < total_error_4)
  84540. order = 3;
  84541. else
  84542. order = 4;
  84543. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84544. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84545. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84546. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84547. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84548. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84549. 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);
  84550. 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);
  84551. 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);
  84552. 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);
  84553. 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);
  84554. #else
  84555. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84556. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84557. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84558. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84559. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84560. #endif
  84561. return order;
  84562. }
  84563. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84564. 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])
  84565. #else
  84566. 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])
  84567. #endif
  84568. {
  84569. FLAC__int32 last_error_0 = data[-1];
  84570. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84571. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84572. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84573. FLAC__int32 error, save;
  84574. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84575. unsigned i, order;
  84576. for(i = 0; i < data_len; i++) {
  84577. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84578. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84579. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84580. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84581. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84582. }
  84583. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84584. order = 0;
  84585. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84586. order = 1;
  84587. else if(total_error_2 < min(total_error_3, total_error_4))
  84588. order = 2;
  84589. else if(total_error_3 < total_error_4)
  84590. order = 3;
  84591. else
  84592. order = 4;
  84593. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84594. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84595. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84596. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84597. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84598. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84599. #if defined _MSC_VER || defined __MINGW32__
  84600. 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);
  84601. 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);
  84602. 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);
  84603. 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);
  84604. 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);
  84605. #else
  84606. 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);
  84607. 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);
  84608. 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);
  84609. 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);
  84610. 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);
  84611. #endif
  84612. #else
  84613. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84614. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84615. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84616. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84617. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84618. #endif
  84619. return order;
  84620. }
  84621. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84622. {
  84623. const int idata_len = (int)data_len;
  84624. int i;
  84625. switch(order) {
  84626. case 0:
  84627. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84628. memcpy(residual, data, sizeof(residual[0])*data_len);
  84629. break;
  84630. case 1:
  84631. for(i = 0; i < idata_len; i++)
  84632. residual[i] = data[i] - data[i-1];
  84633. break;
  84634. case 2:
  84635. for(i = 0; i < idata_len; i++)
  84636. #if 1 /* OPT: may be faster with some compilers on some systems */
  84637. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84638. #else
  84639. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84640. #endif
  84641. break;
  84642. case 3:
  84643. for(i = 0; i < idata_len; i++)
  84644. #if 1 /* OPT: may be faster with some compilers on some systems */
  84645. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84646. #else
  84647. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84648. #endif
  84649. break;
  84650. case 4:
  84651. for(i = 0; i < idata_len; i++)
  84652. #if 1 /* OPT: may be faster with some compilers on some systems */
  84653. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84654. #else
  84655. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84656. #endif
  84657. break;
  84658. default:
  84659. FLAC__ASSERT(0);
  84660. }
  84661. }
  84662. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84663. {
  84664. int i, idata_len = (int)data_len;
  84665. switch(order) {
  84666. case 0:
  84667. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84668. memcpy(data, residual, sizeof(residual[0])*data_len);
  84669. break;
  84670. case 1:
  84671. for(i = 0; i < idata_len; i++)
  84672. data[i] = residual[i] + data[i-1];
  84673. break;
  84674. case 2:
  84675. for(i = 0; i < idata_len; i++)
  84676. #if 1 /* OPT: may be faster with some compilers on some systems */
  84677. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84678. #else
  84679. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84680. #endif
  84681. break;
  84682. case 3:
  84683. for(i = 0; i < idata_len; i++)
  84684. #if 1 /* OPT: may be faster with some compilers on some systems */
  84685. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84686. #else
  84687. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84688. #endif
  84689. break;
  84690. case 4:
  84691. for(i = 0; i < idata_len; i++)
  84692. #if 1 /* OPT: may be faster with some compilers on some systems */
  84693. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84694. #else
  84695. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84696. #endif
  84697. break;
  84698. default:
  84699. FLAC__ASSERT(0);
  84700. }
  84701. }
  84702. #endif
  84703. /*** End of inlined file: fixed.c ***/
  84704. /*** Start of inlined file: float.c ***/
  84705. /*** Start of inlined file: juce_FlacHeader.h ***/
  84706. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84707. // tasks..
  84708. #define VERSION "1.2.1"
  84709. #define FLAC__NO_DLL 1
  84710. #if JUCE_MSVC
  84711. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84712. #endif
  84713. #if JUCE_MAC
  84714. #define FLAC__SYS_DARWIN 1
  84715. #endif
  84716. /*** End of inlined file: juce_FlacHeader.h ***/
  84717. #if JUCE_USE_FLAC
  84718. #if HAVE_CONFIG_H
  84719. # include <config.h>
  84720. #endif
  84721. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84722. #ifdef _MSC_VER
  84723. #define FLAC__U64L(x) x
  84724. #else
  84725. #define FLAC__U64L(x) x##LLU
  84726. #endif
  84727. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84728. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84729. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84730. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84731. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84732. #define LOG2_LOOKUP_PRECISION 16
  84733. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84734. {
  84735. 0x00000000,
  84736. 0x00000001,
  84737. 0x00000000,
  84738. 0x00000000,
  84739. 0x00000000,
  84740. 0x00000000,
  84741. 0x00000000,
  84742. 0x00000000,
  84743. 0x00000000,
  84744. 0x00000000,
  84745. 0x00000000,
  84746. 0x00000000,
  84747. 0x00000000,
  84748. 0x00000000,
  84749. 0x00000000,
  84750. 0x00000000
  84751. },
  84752. {
  84753. 0x00000000,
  84754. 0x00000010,
  84755. 0x00000007,
  84756. 0x00000003,
  84757. 0x00000001,
  84758. 0x00000001,
  84759. 0x00000000,
  84760. 0x00000000,
  84761. 0x00000000,
  84762. 0x00000000,
  84763. 0x00000000,
  84764. 0x00000000,
  84765. 0x00000000,
  84766. 0x00000000,
  84767. 0x00000000,
  84768. 0x00000000
  84769. },
  84770. {
  84771. 0x00000000,
  84772. 0x00000100,
  84773. 0x0000006a,
  84774. 0x00000031,
  84775. 0x00000018,
  84776. 0x0000000c,
  84777. 0x00000006,
  84778. 0x00000003,
  84779. 0x00000001,
  84780. 0x00000001,
  84781. 0x00000000,
  84782. 0x00000000,
  84783. 0x00000000,
  84784. 0x00000000,
  84785. 0x00000000,
  84786. 0x00000000
  84787. },
  84788. {
  84789. 0x00000000,
  84790. 0x00001000,
  84791. 0x000006a4,
  84792. 0x00000315,
  84793. 0x0000017d,
  84794. 0x000000bc,
  84795. 0x0000005d,
  84796. 0x0000002e,
  84797. 0x00000017,
  84798. 0x0000000c,
  84799. 0x00000006,
  84800. 0x00000003,
  84801. 0x00000001,
  84802. 0x00000001,
  84803. 0x00000000,
  84804. 0x00000000
  84805. },
  84806. {
  84807. 0x00000000,
  84808. 0x00010000,
  84809. 0x00006a40,
  84810. 0x00003151,
  84811. 0x000017d6,
  84812. 0x00000bba,
  84813. 0x000005d1,
  84814. 0x000002e6,
  84815. 0x00000172,
  84816. 0x000000b9,
  84817. 0x0000005c,
  84818. 0x0000002e,
  84819. 0x00000017,
  84820. 0x0000000c,
  84821. 0x00000006,
  84822. 0x00000003
  84823. },
  84824. {
  84825. 0x00000000,
  84826. 0x00100000,
  84827. 0x0006a3fe,
  84828. 0x00031513,
  84829. 0x00017d60,
  84830. 0x0000bb9d,
  84831. 0x00005d10,
  84832. 0x00002e59,
  84833. 0x00001721,
  84834. 0x00000b8e,
  84835. 0x000005c6,
  84836. 0x000002e3,
  84837. 0x00000171,
  84838. 0x000000b9,
  84839. 0x0000005c,
  84840. 0x0000002e
  84841. },
  84842. {
  84843. 0x00000000,
  84844. 0x01000000,
  84845. 0x006a3fe6,
  84846. 0x00315130,
  84847. 0x0017d605,
  84848. 0x000bb9ca,
  84849. 0x0005d0fc,
  84850. 0x0002e58f,
  84851. 0x0001720e,
  84852. 0x0000b8d8,
  84853. 0x00005c61,
  84854. 0x00002e2d,
  84855. 0x00001716,
  84856. 0x00000b8b,
  84857. 0x000005c5,
  84858. 0x000002e3
  84859. },
  84860. {
  84861. 0x00000000,
  84862. 0x10000000,
  84863. 0x06a3fe5c,
  84864. 0x03151301,
  84865. 0x017d6049,
  84866. 0x00bb9ca6,
  84867. 0x005d0fba,
  84868. 0x002e58f7,
  84869. 0x001720da,
  84870. 0x000b8d87,
  84871. 0x0005c60b,
  84872. 0x0002e2d7,
  84873. 0x00017160,
  84874. 0x0000b8ad,
  84875. 0x00005c56,
  84876. 0x00002e2b
  84877. }
  84878. };
  84879. #if 0
  84880. static const FLAC__uint64 log2_lookup_wide[] = {
  84881. {
  84882. 0x00000000,
  84883. FLAC__U64L(0x100000000),
  84884. FLAC__U64L(0x6a3fe5c6),
  84885. FLAC__U64L(0x31513015),
  84886. FLAC__U64L(0x17d60497),
  84887. FLAC__U64L(0x0bb9ca65),
  84888. FLAC__U64L(0x05d0fba2),
  84889. FLAC__U64L(0x02e58f74),
  84890. FLAC__U64L(0x01720d9c),
  84891. FLAC__U64L(0x00b8d875),
  84892. FLAC__U64L(0x005c60aa),
  84893. FLAC__U64L(0x002e2d72),
  84894. FLAC__U64L(0x00171600),
  84895. FLAC__U64L(0x000b8ad2),
  84896. FLAC__U64L(0x0005c55d),
  84897. FLAC__U64L(0x0002e2ac)
  84898. },
  84899. {
  84900. 0x00000000,
  84901. FLAC__U64L(0x1000000000000),
  84902. FLAC__U64L(0x6a3fe5c60429),
  84903. FLAC__U64L(0x315130157f7a),
  84904. FLAC__U64L(0x17d60496cfbb),
  84905. FLAC__U64L(0xbb9ca64ecac),
  84906. FLAC__U64L(0x5d0fba187cd),
  84907. FLAC__U64L(0x2e58f7441ee),
  84908. FLAC__U64L(0x1720d9c06a8),
  84909. FLAC__U64L(0xb8d8752173),
  84910. FLAC__U64L(0x5c60aa252e),
  84911. FLAC__U64L(0x2e2d71b0d8),
  84912. FLAC__U64L(0x1716001719),
  84913. FLAC__U64L(0xb8ad1de1b),
  84914. FLAC__U64L(0x5c55d640d),
  84915. FLAC__U64L(0x2e2abcf52)
  84916. }
  84917. };
  84918. #endif
  84919. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84920. {
  84921. const FLAC__uint32 ONE = (1u << fracbits);
  84922. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84923. FLAC__ASSERT(fracbits < 32);
  84924. FLAC__ASSERT((fracbits & 0x3) == 0);
  84925. if(x < ONE)
  84926. return 0;
  84927. if(precision > LOG2_LOOKUP_PRECISION)
  84928. precision = LOG2_LOOKUP_PRECISION;
  84929. {
  84930. FLAC__uint32 y = 0;
  84931. FLAC__uint32 z = x >> 1, k = 1;
  84932. while (x > ONE && k < precision) {
  84933. if (x - z >= ONE) {
  84934. x -= z;
  84935. z = x >> k;
  84936. y += table[k];
  84937. }
  84938. else {
  84939. z >>= 1;
  84940. k++;
  84941. }
  84942. }
  84943. return y;
  84944. }
  84945. }
  84946. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84947. #endif
  84948. /*** End of inlined file: float.c ***/
  84949. /*** Start of inlined file: format.c ***/
  84950. /*** Start of inlined file: juce_FlacHeader.h ***/
  84951. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84952. // tasks..
  84953. #define VERSION "1.2.1"
  84954. #define FLAC__NO_DLL 1
  84955. #if JUCE_MSVC
  84956. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84957. #endif
  84958. #if JUCE_MAC
  84959. #define FLAC__SYS_DARWIN 1
  84960. #endif
  84961. /*** End of inlined file: juce_FlacHeader.h ***/
  84962. #if JUCE_USE_FLAC
  84963. #if HAVE_CONFIG_H
  84964. # include <config.h>
  84965. #endif
  84966. #include <stdio.h>
  84967. #include <stdlib.h> /* for qsort() */
  84968. #include <string.h> /* for memset() */
  84969. #ifndef FLaC__INLINE
  84970. #define FLaC__INLINE
  84971. #endif
  84972. #ifdef min
  84973. #undef min
  84974. #endif
  84975. #define min(a,b) ((a)<(b)?(a):(b))
  84976. #ifdef _MSC_VER
  84977. #define FLAC__U64L(x) x
  84978. #else
  84979. #define FLAC__U64L(x) x##LLU
  84980. #endif
  84981. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84982. ;
  84983. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84984. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84985. #else
  84986. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84987. #endif
  84988. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84989. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84990. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84991. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84992. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84993. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84994. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84995. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84996. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84997. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84998. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84999. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  85000. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  85001. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  85002. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  85003. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  85004. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  85005. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  85006. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  85007. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  85008. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  85009. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  85010. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  85011. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  85012. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  85013. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  85014. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  85015. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  85016. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  85017. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  85018. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  85019. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  85020. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  85021. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  85022. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  85023. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  85024. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  85025. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  85026. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  85027. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  85028. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  85029. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  85030. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  85031. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  85032. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  85033. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  85034. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  85035. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  85036. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  85037. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  85038. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  85039. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  85040. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  85041. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  85042. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  85043. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  85044. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  85045. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  85046. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  85047. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  85048. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  85049. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  85050. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  85051. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  85052. "PARTITIONED_RICE",
  85053. "PARTITIONED_RICE2"
  85054. };
  85055. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  85056. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  85057. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  85058. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  85059. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  85060. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  85061. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  85062. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  85063. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  85064. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  85065. "CONSTANT",
  85066. "VERBATIM",
  85067. "FIXED",
  85068. "LPC"
  85069. };
  85070. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  85071. "INDEPENDENT",
  85072. "LEFT_SIDE",
  85073. "RIGHT_SIDE",
  85074. "MID_SIDE"
  85075. };
  85076. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  85077. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  85078. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  85079. };
  85080. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  85081. "STREAMINFO",
  85082. "PADDING",
  85083. "APPLICATION",
  85084. "SEEKTABLE",
  85085. "VORBIS_COMMENT",
  85086. "CUESHEET",
  85087. "PICTURE"
  85088. };
  85089. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  85090. "Other",
  85091. "32x32 pixels 'file icon' (PNG only)",
  85092. "Other file icon",
  85093. "Cover (front)",
  85094. "Cover (back)",
  85095. "Leaflet page",
  85096. "Media (e.g. label side of CD)",
  85097. "Lead artist/lead performer/soloist",
  85098. "Artist/performer",
  85099. "Conductor",
  85100. "Band/Orchestra",
  85101. "Composer",
  85102. "Lyricist/text writer",
  85103. "Recording Location",
  85104. "During recording",
  85105. "During performance",
  85106. "Movie/video screen capture",
  85107. "A bright coloured fish",
  85108. "Illustration",
  85109. "Band/artist logotype",
  85110. "Publisher/Studio logotype"
  85111. };
  85112. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85113. {
  85114. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85115. return false;
  85116. }
  85117. else
  85118. return true;
  85119. }
  85120. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85121. {
  85122. if(
  85123. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85124. (
  85125. sample_rate >= (1u << 16) &&
  85126. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85127. )
  85128. ) {
  85129. return false;
  85130. }
  85131. else
  85132. return true;
  85133. }
  85134. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85135. {
  85136. unsigned i;
  85137. FLAC__uint64 prev_sample_number = 0;
  85138. FLAC__bool got_prev = false;
  85139. FLAC__ASSERT(0 != seek_table);
  85140. for(i = 0; i < seek_table->num_points; i++) {
  85141. if(got_prev) {
  85142. if(
  85143. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85144. seek_table->points[i].sample_number <= prev_sample_number
  85145. )
  85146. return false;
  85147. }
  85148. prev_sample_number = seek_table->points[i].sample_number;
  85149. got_prev = true;
  85150. }
  85151. return true;
  85152. }
  85153. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85154. {
  85155. if(l->sample_number == r->sample_number)
  85156. return 0;
  85157. else if(l->sample_number < r->sample_number)
  85158. return -1;
  85159. else
  85160. return 1;
  85161. }
  85162. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85163. {
  85164. unsigned i, j;
  85165. FLAC__bool first;
  85166. FLAC__ASSERT(0 != seek_table);
  85167. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85168. first = true;
  85169. for(i = j = 0; i < seek_table->num_points; i++) {
  85170. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85171. if(!first) {
  85172. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85173. continue;
  85174. }
  85175. }
  85176. first = false;
  85177. seek_table->points[j++] = seek_table->points[i];
  85178. }
  85179. for(i = j; i < seek_table->num_points; i++) {
  85180. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85181. seek_table->points[i].stream_offset = 0;
  85182. seek_table->points[i].frame_samples = 0;
  85183. }
  85184. return j;
  85185. }
  85186. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85187. {
  85188. FLAC__ASSERT(0 != utf8);
  85189. if ((utf8[0] & 0x80) == 0) {
  85190. return 1;
  85191. }
  85192. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85193. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85194. return 0;
  85195. return 2;
  85196. }
  85197. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85198. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85199. return 0;
  85200. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85201. return 0;
  85202. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85203. return 0;
  85204. return 3;
  85205. }
  85206. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85207. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85208. return 0;
  85209. return 4;
  85210. }
  85211. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85212. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85213. return 0;
  85214. return 5;
  85215. }
  85216. 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) {
  85217. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85218. return 0;
  85219. return 6;
  85220. }
  85221. else {
  85222. return 0;
  85223. }
  85224. }
  85225. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85226. {
  85227. char c;
  85228. for(c = *name; c; c = *(++name))
  85229. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85230. return false;
  85231. return true;
  85232. }
  85233. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85234. {
  85235. if(length == (unsigned)(-1)) {
  85236. while(*value) {
  85237. unsigned n = utf8len_(value);
  85238. if(n == 0)
  85239. return false;
  85240. value += n;
  85241. }
  85242. }
  85243. else {
  85244. const FLAC__byte *end = value + length;
  85245. while(value < end) {
  85246. unsigned n = utf8len_(value);
  85247. if(n == 0)
  85248. return false;
  85249. value += n;
  85250. }
  85251. if(value != end)
  85252. return false;
  85253. }
  85254. return true;
  85255. }
  85256. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85257. {
  85258. const FLAC__byte *s, *end;
  85259. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85260. if(*s < 0x20 || *s > 0x7D)
  85261. return false;
  85262. }
  85263. if(s == end)
  85264. return false;
  85265. s++; /* skip '=' */
  85266. while(s < end) {
  85267. unsigned n = utf8len_(s);
  85268. if(n == 0)
  85269. return false;
  85270. s += n;
  85271. }
  85272. if(s != end)
  85273. return false;
  85274. return true;
  85275. }
  85276. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85277. {
  85278. unsigned i, j;
  85279. if(check_cd_da_subset) {
  85280. if(cue_sheet->lead_in < 2 * 44100) {
  85281. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85282. return false;
  85283. }
  85284. if(cue_sheet->lead_in % 588 != 0) {
  85285. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85286. return false;
  85287. }
  85288. }
  85289. if(cue_sheet->num_tracks == 0) {
  85290. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85291. return false;
  85292. }
  85293. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85294. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85295. return false;
  85296. }
  85297. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85298. if(cue_sheet->tracks[i].number == 0) {
  85299. if(violation) *violation = "cue sheet may not have a track number 0";
  85300. return false;
  85301. }
  85302. if(check_cd_da_subset) {
  85303. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85304. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85305. return false;
  85306. }
  85307. }
  85308. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85309. if(violation) {
  85310. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85311. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85312. else
  85313. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85314. }
  85315. return false;
  85316. }
  85317. if(i < cue_sheet->num_tracks - 1) {
  85318. if(cue_sheet->tracks[i].num_indices == 0) {
  85319. if(violation) *violation = "cue sheet track must have at least one index point";
  85320. return false;
  85321. }
  85322. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85323. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85324. return false;
  85325. }
  85326. }
  85327. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85328. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85329. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85330. return false;
  85331. }
  85332. if(j > 0) {
  85333. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85334. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85335. return false;
  85336. }
  85337. }
  85338. }
  85339. }
  85340. return true;
  85341. }
  85342. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85343. {
  85344. char *p;
  85345. FLAC__byte *b;
  85346. for(p = picture->mime_type; *p; p++) {
  85347. if(*p < 0x20 || *p > 0x7e) {
  85348. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85349. return false;
  85350. }
  85351. }
  85352. for(b = picture->description; *b; ) {
  85353. unsigned n = utf8len_(b);
  85354. if(n == 0) {
  85355. if(violation) *violation = "description string must be valid UTF-8";
  85356. return false;
  85357. }
  85358. b += n;
  85359. }
  85360. return true;
  85361. }
  85362. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85363. {
  85364. return
  85365. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85366. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85367. blocksize,
  85368. predictor_order
  85369. );
  85370. }
  85371. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85372. {
  85373. unsigned max_rice_partition_order = 0;
  85374. while(!(blocksize & 1)) {
  85375. max_rice_partition_order++;
  85376. blocksize >>= 1;
  85377. }
  85378. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85379. }
  85380. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85381. {
  85382. unsigned max_rice_partition_order = limit;
  85383. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85384. max_rice_partition_order--;
  85385. FLAC__ASSERT(
  85386. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85387. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85388. );
  85389. return max_rice_partition_order;
  85390. }
  85391. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85392. {
  85393. FLAC__ASSERT(0 != object);
  85394. object->parameters = 0;
  85395. object->raw_bits = 0;
  85396. object->capacity_by_order = 0;
  85397. }
  85398. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85399. {
  85400. FLAC__ASSERT(0 != object);
  85401. if(0 != object->parameters)
  85402. free(object->parameters);
  85403. if(0 != object->raw_bits)
  85404. free(object->raw_bits);
  85405. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85406. }
  85407. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85408. {
  85409. FLAC__ASSERT(0 != object);
  85410. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85411. if(object->capacity_by_order < max_partition_order) {
  85412. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85413. return false;
  85414. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85415. return false;
  85416. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85417. object->capacity_by_order = max_partition_order;
  85418. }
  85419. return true;
  85420. }
  85421. #endif
  85422. /*** End of inlined file: format.c ***/
  85423. /*** Start of inlined file: lpc_flac.c ***/
  85424. /*** Start of inlined file: juce_FlacHeader.h ***/
  85425. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85426. // tasks..
  85427. #define VERSION "1.2.1"
  85428. #define FLAC__NO_DLL 1
  85429. #if JUCE_MSVC
  85430. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85431. #endif
  85432. #if JUCE_MAC
  85433. #define FLAC__SYS_DARWIN 1
  85434. #endif
  85435. /*** End of inlined file: juce_FlacHeader.h ***/
  85436. #if JUCE_USE_FLAC
  85437. #if HAVE_CONFIG_H
  85438. # include <config.h>
  85439. #endif
  85440. #include <math.h>
  85441. /*** Start of inlined file: lpc.h ***/
  85442. #ifndef FLAC__PRIVATE__LPC_H
  85443. #define FLAC__PRIVATE__LPC_H
  85444. #ifdef HAVE_CONFIG_H
  85445. #include <config.h>
  85446. #endif
  85447. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85448. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85449. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85450. #ifndef FLAC__NO_ASM
  85451. # ifdef FLAC__CPU_IA32
  85452. # ifdef FLAC__HAS_NASM
  85453. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85454. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85455. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85456. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85457. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85458. # endif
  85459. # endif
  85460. #endif
  85461. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85462. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85463. 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[]);
  85464. 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[]);
  85465. #ifndef FLAC__NO_ASM
  85466. # ifdef FLAC__CPU_IA32
  85467. # ifdef FLAC__HAS_NASM
  85468. 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[]);
  85469. 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[]);
  85470. # endif
  85471. # endif
  85472. #endif
  85473. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85474. 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[]);
  85475. 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[]);
  85476. #ifndef FLAC__NO_ASM
  85477. # ifdef FLAC__CPU_IA32
  85478. # ifdef FLAC__HAS_NASM
  85479. 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[]);
  85480. 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[]);
  85481. # endif /* FLAC__HAS_NASM */
  85482. # elif defined FLAC__CPU_PPC
  85483. 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[]);
  85484. 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[]);
  85485. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85486. #endif /* FLAC__NO_ASM */
  85487. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85488. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85489. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85490. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85491. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85492. #endif
  85493. /*** End of inlined file: lpc.h ***/
  85494. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85495. #include <stdio.h>
  85496. #endif
  85497. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85498. #ifndef M_LN2
  85499. #define M_LN2 0.69314718055994530942
  85500. #endif
  85501. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85502. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85503. {
  85504. unsigned i;
  85505. for(i = 0; i < data_len; i++)
  85506. out[i] = in[i] * window[i];
  85507. }
  85508. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85509. {
  85510. #if 0
  85511. FLAC__real d;
  85512. unsigned i;
  85513. FLAC__ASSERT(lag > 0);
  85514. FLAC__ASSERT(lag <= data_len);
  85515. while(lag--) {
  85516. for(i = lag, d = 0.0; i < data_len; i++)
  85517. d += data[i] * data[i - lag];
  85518. autoc[lag] = d;
  85519. }
  85520. #endif
  85521. FLAC__real d;
  85522. unsigned sample, coeff;
  85523. const unsigned limit = data_len - lag;
  85524. FLAC__ASSERT(lag > 0);
  85525. FLAC__ASSERT(lag <= data_len);
  85526. for(coeff = 0; coeff < lag; coeff++)
  85527. autoc[coeff] = 0.0;
  85528. for(sample = 0; sample <= limit; sample++) {
  85529. d = data[sample];
  85530. for(coeff = 0; coeff < lag; coeff++)
  85531. autoc[coeff] += d * data[sample+coeff];
  85532. }
  85533. for(; sample < data_len; sample++) {
  85534. d = data[sample];
  85535. for(coeff = 0; coeff < data_len - sample; coeff++)
  85536. autoc[coeff] += d * data[sample+coeff];
  85537. }
  85538. }
  85539. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85540. {
  85541. unsigned i, j;
  85542. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85543. FLAC__ASSERT(0 != max_order);
  85544. FLAC__ASSERT(0 < *max_order);
  85545. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85546. FLAC__ASSERT(autoc[0] != 0.0);
  85547. err = autoc[0];
  85548. for(i = 0; i < *max_order; i++) {
  85549. r = -autoc[i+1];
  85550. for(j = 0; j < i; j++)
  85551. r -= lpc[j] * autoc[i-j];
  85552. ref[i] = (r/=err);
  85553. lpc[i]=r;
  85554. for(j = 0; j < (i>>1); j++) {
  85555. FLAC__double tmp = lpc[j];
  85556. lpc[j] += r * lpc[i-1-j];
  85557. lpc[i-1-j] += r * tmp;
  85558. }
  85559. if(i & 1)
  85560. lpc[j] += lpc[j] * r;
  85561. err *= (1.0 - r * r);
  85562. for(j = 0; j <= i; j++)
  85563. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85564. error[i] = err;
  85565. if(err == 0.0) {
  85566. *max_order = i+1;
  85567. return;
  85568. }
  85569. }
  85570. }
  85571. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85572. {
  85573. unsigned i;
  85574. FLAC__double cmax;
  85575. FLAC__int32 qmax, qmin;
  85576. FLAC__ASSERT(precision > 0);
  85577. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85578. precision--;
  85579. qmax = 1 << precision;
  85580. qmin = -qmax;
  85581. qmax--;
  85582. cmax = 0.0;
  85583. for(i = 0; i < order; i++) {
  85584. const FLAC__double d = fabs(lp_coeff[i]);
  85585. if(d > cmax)
  85586. cmax = d;
  85587. }
  85588. if(cmax <= 0.0) {
  85589. return 2;
  85590. }
  85591. else {
  85592. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85593. const int min_shiftlimit = -max_shiftlimit - 1;
  85594. int log2cmax;
  85595. (void)frexp(cmax, &log2cmax);
  85596. log2cmax--;
  85597. *shift = (int)precision - log2cmax - 1;
  85598. if(*shift > max_shiftlimit)
  85599. *shift = max_shiftlimit;
  85600. else if(*shift < min_shiftlimit)
  85601. return 1;
  85602. }
  85603. if(*shift >= 0) {
  85604. FLAC__double error = 0.0;
  85605. FLAC__int32 q;
  85606. for(i = 0; i < order; i++) {
  85607. error += lp_coeff[i] * (1 << *shift);
  85608. #if 1 /* unfortunately lround() is C99 */
  85609. if(error >= 0.0)
  85610. q = (FLAC__int32)(error + 0.5);
  85611. else
  85612. q = (FLAC__int32)(error - 0.5);
  85613. #else
  85614. q = lround(error);
  85615. #endif
  85616. #ifdef FLAC__OVERFLOW_DETECT
  85617. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85618. 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]);
  85619. else if(q < qmin)
  85620. 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]);
  85621. #endif
  85622. if(q > qmax)
  85623. q = qmax;
  85624. else if(q < qmin)
  85625. q = qmin;
  85626. error -= q;
  85627. qlp_coeff[i] = q;
  85628. }
  85629. }
  85630. else {
  85631. const int nshift = -(*shift);
  85632. FLAC__double error = 0.0;
  85633. FLAC__int32 q;
  85634. #ifdef DEBUG
  85635. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85636. #endif
  85637. for(i = 0; i < order; i++) {
  85638. error += lp_coeff[i] / (1 << nshift);
  85639. #if 1 /* unfortunately lround() is C99 */
  85640. if(error >= 0.0)
  85641. q = (FLAC__int32)(error + 0.5);
  85642. else
  85643. q = (FLAC__int32)(error - 0.5);
  85644. #else
  85645. q = lround(error);
  85646. #endif
  85647. #ifdef FLAC__OVERFLOW_DETECT
  85648. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85649. 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]);
  85650. else if(q < qmin)
  85651. 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]);
  85652. #endif
  85653. if(q > qmax)
  85654. q = qmax;
  85655. else if(q < qmin)
  85656. q = qmin;
  85657. error -= q;
  85658. qlp_coeff[i] = q;
  85659. }
  85660. *shift = 0;
  85661. }
  85662. return 0;
  85663. }
  85664. 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[])
  85665. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85666. {
  85667. FLAC__int64 sumo;
  85668. unsigned i, j;
  85669. FLAC__int32 sum;
  85670. const FLAC__int32 *history;
  85671. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85672. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85673. for(i=0;i<order;i++)
  85674. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85675. fprintf(stderr,"\n");
  85676. #endif
  85677. FLAC__ASSERT(order > 0);
  85678. for(i = 0; i < data_len; i++) {
  85679. sumo = 0;
  85680. sum = 0;
  85681. history = data;
  85682. for(j = 0; j < order; j++) {
  85683. sum += qlp_coeff[j] * (*(--history));
  85684. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85685. #if defined _MSC_VER
  85686. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85687. 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);
  85688. #else
  85689. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85690. 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);
  85691. #endif
  85692. }
  85693. *(residual++) = *(data++) - (sum >> lp_quantization);
  85694. }
  85695. }
  85696. #else /* fully unrolled version for normal use */
  85697. {
  85698. int i;
  85699. FLAC__int32 sum;
  85700. FLAC__ASSERT(order > 0);
  85701. FLAC__ASSERT(order <= 32);
  85702. if(order <= 12) {
  85703. if(order > 8) {
  85704. if(order > 10) {
  85705. if(order == 12) {
  85706. for(i = 0; i < (int)data_len; i++) {
  85707. sum = 0;
  85708. sum += qlp_coeff[11] * data[i-12];
  85709. sum += qlp_coeff[10] * data[i-11];
  85710. sum += qlp_coeff[9] * data[i-10];
  85711. sum += qlp_coeff[8] * data[i-9];
  85712. sum += qlp_coeff[7] * data[i-8];
  85713. sum += qlp_coeff[6] * data[i-7];
  85714. sum += qlp_coeff[5] * data[i-6];
  85715. sum += qlp_coeff[4] * data[i-5];
  85716. sum += qlp_coeff[3] * data[i-4];
  85717. sum += qlp_coeff[2] * data[i-3];
  85718. sum += qlp_coeff[1] * data[i-2];
  85719. sum += qlp_coeff[0] * data[i-1];
  85720. residual[i] = data[i] - (sum >> lp_quantization);
  85721. }
  85722. }
  85723. else { /* order == 11 */
  85724. for(i = 0; i < (int)data_len; i++) {
  85725. sum = 0;
  85726. sum += qlp_coeff[10] * data[i-11];
  85727. sum += qlp_coeff[9] * data[i-10];
  85728. sum += qlp_coeff[8] * data[i-9];
  85729. sum += qlp_coeff[7] * data[i-8];
  85730. sum += qlp_coeff[6] * data[i-7];
  85731. sum += qlp_coeff[5] * data[i-6];
  85732. sum += qlp_coeff[4] * data[i-5];
  85733. sum += qlp_coeff[3] * data[i-4];
  85734. sum += qlp_coeff[2] * data[i-3];
  85735. sum += qlp_coeff[1] * data[i-2];
  85736. sum += qlp_coeff[0] * data[i-1];
  85737. residual[i] = data[i] - (sum >> lp_quantization);
  85738. }
  85739. }
  85740. }
  85741. else {
  85742. if(order == 10) {
  85743. for(i = 0; i < (int)data_len; i++) {
  85744. sum = 0;
  85745. sum += qlp_coeff[9] * data[i-10];
  85746. sum += qlp_coeff[8] * data[i-9];
  85747. sum += qlp_coeff[7] * data[i-8];
  85748. sum += qlp_coeff[6] * data[i-7];
  85749. sum += qlp_coeff[5] * data[i-6];
  85750. sum += qlp_coeff[4] * data[i-5];
  85751. sum += qlp_coeff[3] * data[i-4];
  85752. sum += qlp_coeff[2] * data[i-3];
  85753. sum += qlp_coeff[1] * data[i-2];
  85754. sum += qlp_coeff[0] * data[i-1];
  85755. residual[i] = data[i] - (sum >> lp_quantization);
  85756. }
  85757. }
  85758. else { /* order == 9 */
  85759. for(i = 0; i < (int)data_len; i++) {
  85760. sum = 0;
  85761. sum += qlp_coeff[8] * data[i-9];
  85762. sum += qlp_coeff[7] * data[i-8];
  85763. sum += qlp_coeff[6] * data[i-7];
  85764. sum += qlp_coeff[5] * data[i-6];
  85765. sum += qlp_coeff[4] * data[i-5];
  85766. sum += qlp_coeff[3] * data[i-4];
  85767. sum += qlp_coeff[2] * data[i-3];
  85768. sum += qlp_coeff[1] * data[i-2];
  85769. sum += qlp_coeff[0] * data[i-1];
  85770. residual[i] = data[i] - (sum >> lp_quantization);
  85771. }
  85772. }
  85773. }
  85774. }
  85775. else if(order > 4) {
  85776. if(order > 6) {
  85777. if(order == 8) {
  85778. for(i = 0; i < (int)data_len; i++) {
  85779. sum = 0;
  85780. sum += qlp_coeff[7] * data[i-8];
  85781. sum += qlp_coeff[6] * data[i-7];
  85782. sum += qlp_coeff[5] * data[i-6];
  85783. sum += qlp_coeff[4] * data[i-5];
  85784. sum += qlp_coeff[3] * data[i-4];
  85785. sum += qlp_coeff[2] * data[i-3];
  85786. sum += qlp_coeff[1] * data[i-2];
  85787. sum += qlp_coeff[0] * data[i-1];
  85788. residual[i] = data[i] - (sum >> lp_quantization);
  85789. }
  85790. }
  85791. else { /* order == 7 */
  85792. for(i = 0; i < (int)data_len; i++) {
  85793. sum = 0;
  85794. sum += qlp_coeff[6] * data[i-7];
  85795. sum += qlp_coeff[5] * data[i-6];
  85796. sum += qlp_coeff[4] * data[i-5];
  85797. sum += qlp_coeff[3] * data[i-4];
  85798. sum += qlp_coeff[2] * data[i-3];
  85799. sum += qlp_coeff[1] * data[i-2];
  85800. sum += qlp_coeff[0] * data[i-1];
  85801. residual[i] = data[i] - (sum >> lp_quantization);
  85802. }
  85803. }
  85804. }
  85805. else {
  85806. if(order == 6) {
  85807. for(i = 0; i < (int)data_len; i++) {
  85808. sum = 0;
  85809. sum += qlp_coeff[5] * data[i-6];
  85810. sum += qlp_coeff[4] * data[i-5];
  85811. sum += qlp_coeff[3] * data[i-4];
  85812. sum += qlp_coeff[2] * data[i-3];
  85813. sum += qlp_coeff[1] * data[i-2];
  85814. sum += qlp_coeff[0] * data[i-1];
  85815. residual[i] = data[i] - (sum >> lp_quantization);
  85816. }
  85817. }
  85818. else { /* order == 5 */
  85819. for(i = 0; i < (int)data_len; i++) {
  85820. sum = 0;
  85821. sum += qlp_coeff[4] * data[i-5];
  85822. sum += qlp_coeff[3] * data[i-4];
  85823. sum += qlp_coeff[2] * data[i-3];
  85824. sum += qlp_coeff[1] * data[i-2];
  85825. sum += qlp_coeff[0] * data[i-1];
  85826. residual[i] = data[i] - (sum >> lp_quantization);
  85827. }
  85828. }
  85829. }
  85830. }
  85831. else {
  85832. if(order > 2) {
  85833. if(order == 4) {
  85834. for(i = 0; i < (int)data_len; i++) {
  85835. sum = 0;
  85836. sum += qlp_coeff[3] * data[i-4];
  85837. sum += qlp_coeff[2] * data[i-3];
  85838. sum += qlp_coeff[1] * data[i-2];
  85839. sum += qlp_coeff[0] * data[i-1];
  85840. residual[i] = data[i] - (sum >> lp_quantization);
  85841. }
  85842. }
  85843. else { /* order == 3 */
  85844. for(i = 0; i < (int)data_len; i++) {
  85845. sum = 0;
  85846. sum += qlp_coeff[2] * data[i-3];
  85847. sum += qlp_coeff[1] * data[i-2];
  85848. sum += qlp_coeff[0] * data[i-1];
  85849. residual[i] = data[i] - (sum >> lp_quantization);
  85850. }
  85851. }
  85852. }
  85853. else {
  85854. if(order == 2) {
  85855. for(i = 0; i < (int)data_len; i++) {
  85856. sum = 0;
  85857. sum += qlp_coeff[1] * data[i-2];
  85858. sum += qlp_coeff[0] * data[i-1];
  85859. residual[i] = data[i] - (sum >> lp_quantization);
  85860. }
  85861. }
  85862. else { /* order == 1 */
  85863. for(i = 0; i < (int)data_len; i++)
  85864. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85865. }
  85866. }
  85867. }
  85868. }
  85869. else { /* order > 12 */
  85870. for(i = 0; i < (int)data_len; i++) {
  85871. sum = 0;
  85872. switch(order) {
  85873. case 32: sum += qlp_coeff[31] * data[i-32];
  85874. case 31: sum += qlp_coeff[30] * data[i-31];
  85875. case 30: sum += qlp_coeff[29] * data[i-30];
  85876. case 29: sum += qlp_coeff[28] * data[i-29];
  85877. case 28: sum += qlp_coeff[27] * data[i-28];
  85878. case 27: sum += qlp_coeff[26] * data[i-27];
  85879. case 26: sum += qlp_coeff[25] * data[i-26];
  85880. case 25: sum += qlp_coeff[24] * data[i-25];
  85881. case 24: sum += qlp_coeff[23] * data[i-24];
  85882. case 23: sum += qlp_coeff[22] * data[i-23];
  85883. case 22: sum += qlp_coeff[21] * data[i-22];
  85884. case 21: sum += qlp_coeff[20] * data[i-21];
  85885. case 20: sum += qlp_coeff[19] * data[i-20];
  85886. case 19: sum += qlp_coeff[18] * data[i-19];
  85887. case 18: sum += qlp_coeff[17] * data[i-18];
  85888. case 17: sum += qlp_coeff[16] * data[i-17];
  85889. case 16: sum += qlp_coeff[15] * data[i-16];
  85890. case 15: sum += qlp_coeff[14] * data[i-15];
  85891. case 14: sum += qlp_coeff[13] * data[i-14];
  85892. case 13: sum += qlp_coeff[12] * data[i-13];
  85893. sum += qlp_coeff[11] * data[i-12];
  85894. sum += qlp_coeff[10] * data[i-11];
  85895. sum += qlp_coeff[ 9] * data[i-10];
  85896. sum += qlp_coeff[ 8] * data[i- 9];
  85897. sum += qlp_coeff[ 7] * data[i- 8];
  85898. sum += qlp_coeff[ 6] * data[i- 7];
  85899. sum += qlp_coeff[ 5] * data[i- 6];
  85900. sum += qlp_coeff[ 4] * data[i- 5];
  85901. sum += qlp_coeff[ 3] * data[i- 4];
  85902. sum += qlp_coeff[ 2] * data[i- 3];
  85903. sum += qlp_coeff[ 1] * data[i- 2];
  85904. sum += qlp_coeff[ 0] * data[i- 1];
  85905. }
  85906. residual[i] = data[i] - (sum >> lp_quantization);
  85907. }
  85908. }
  85909. }
  85910. #endif
  85911. 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[])
  85912. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85913. {
  85914. unsigned i, j;
  85915. FLAC__int64 sum;
  85916. const FLAC__int32 *history;
  85917. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85918. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85919. for(i=0;i<order;i++)
  85920. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85921. fprintf(stderr,"\n");
  85922. #endif
  85923. FLAC__ASSERT(order > 0);
  85924. for(i = 0; i < data_len; i++) {
  85925. sum = 0;
  85926. history = data;
  85927. for(j = 0; j < order; j++)
  85928. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85929. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85930. #if defined _MSC_VER
  85931. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85932. #else
  85933. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85934. #endif
  85935. break;
  85936. }
  85937. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85938. #if defined _MSC_VER
  85939. 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));
  85940. #else
  85941. 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)));
  85942. #endif
  85943. break;
  85944. }
  85945. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85946. }
  85947. }
  85948. #else /* fully unrolled version for normal use */
  85949. {
  85950. int i;
  85951. FLAC__int64 sum;
  85952. FLAC__ASSERT(order > 0);
  85953. FLAC__ASSERT(order <= 32);
  85954. if(order <= 12) {
  85955. if(order > 8) {
  85956. if(order > 10) {
  85957. if(order == 12) {
  85958. for(i = 0; i < (int)data_len; i++) {
  85959. sum = 0;
  85960. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85961. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85962. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85963. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85964. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85965. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85966. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85967. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85968. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85969. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85970. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85971. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85972. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85973. }
  85974. }
  85975. else { /* order == 11 */
  85976. for(i = 0; i < (int)data_len; i++) {
  85977. sum = 0;
  85978. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85979. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85980. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85981. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85982. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85983. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85984. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85985. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85986. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85987. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85988. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85989. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85990. }
  85991. }
  85992. }
  85993. else {
  85994. if(order == 10) {
  85995. for(i = 0; i < (int)data_len; i++) {
  85996. sum = 0;
  85997. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85998. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85999. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86000. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86001. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86002. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86003. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86004. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86005. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86006. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86007. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86008. }
  86009. }
  86010. else { /* order == 9 */
  86011. for(i = 0; i < (int)data_len; i++) {
  86012. sum = 0;
  86013. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86014. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86015. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86016. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86017. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86018. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86019. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86020. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86021. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86022. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86023. }
  86024. }
  86025. }
  86026. }
  86027. else if(order > 4) {
  86028. if(order > 6) {
  86029. if(order == 8) {
  86030. for(i = 0; i < (int)data_len; i++) {
  86031. sum = 0;
  86032. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86033. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86034. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86035. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86036. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86037. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86038. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86039. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86040. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86041. }
  86042. }
  86043. else { /* order == 7 */
  86044. for(i = 0; i < (int)data_len; i++) {
  86045. sum = 0;
  86046. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86047. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86048. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86049. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86050. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86051. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86052. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86053. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86054. }
  86055. }
  86056. }
  86057. else {
  86058. if(order == 6) {
  86059. for(i = 0; i < (int)data_len; i++) {
  86060. sum = 0;
  86061. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86062. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86063. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86064. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86065. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86066. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86067. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86068. }
  86069. }
  86070. else { /* order == 5 */
  86071. for(i = 0; i < (int)data_len; i++) {
  86072. sum = 0;
  86073. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86074. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86075. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86076. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86077. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86078. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86079. }
  86080. }
  86081. }
  86082. }
  86083. else {
  86084. if(order > 2) {
  86085. if(order == 4) {
  86086. for(i = 0; i < (int)data_len; i++) {
  86087. sum = 0;
  86088. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86089. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86090. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86091. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86092. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86093. }
  86094. }
  86095. else { /* order == 3 */
  86096. for(i = 0; i < (int)data_len; i++) {
  86097. sum = 0;
  86098. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86099. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86100. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86101. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86102. }
  86103. }
  86104. }
  86105. else {
  86106. if(order == 2) {
  86107. for(i = 0; i < (int)data_len; i++) {
  86108. sum = 0;
  86109. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86110. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86111. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86112. }
  86113. }
  86114. else { /* order == 1 */
  86115. for(i = 0; i < (int)data_len; i++)
  86116. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86117. }
  86118. }
  86119. }
  86120. }
  86121. else { /* order > 12 */
  86122. for(i = 0; i < (int)data_len; i++) {
  86123. sum = 0;
  86124. switch(order) {
  86125. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86126. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86127. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86128. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86129. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86130. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86131. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86132. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86133. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86134. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86135. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86136. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86137. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86138. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86139. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86140. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86141. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86142. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86143. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86144. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86145. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86146. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86147. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86148. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86149. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86150. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86151. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86152. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86153. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86154. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86155. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86156. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86157. }
  86158. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86159. }
  86160. }
  86161. }
  86162. #endif
  86163. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86164. 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[])
  86165. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86166. {
  86167. FLAC__int64 sumo;
  86168. unsigned i, j;
  86169. FLAC__int32 sum;
  86170. const FLAC__int32 *r = residual, *history;
  86171. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86172. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86173. for(i=0;i<order;i++)
  86174. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86175. fprintf(stderr,"\n");
  86176. #endif
  86177. FLAC__ASSERT(order > 0);
  86178. for(i = 0; i < data_len; i++) {
  86179. sumo = 0;
  86180. sum = 0;
  86181. history = data;
  86182. for(j = 0; j < order; j++) {
  86183. sum += qlp_coeff[j] * (*(--history));
  86184. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86185. #if defined _MSC_VER
  86186. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86187. 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);
  86188. #else
  86189. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86190. 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);
  86191. #endif
  86192. }
  86193. *(data++) = *(r++) + (sum >> lp_quantization);
  86194. }
  86195. }
  86196. #else /* fully unrolled version for normal use */
  86197. {
  86198. int i;
  86199. FLAC__int32 sum;
  86200. FLAC__ASSERT(order > 0);
  86201. FLAC__ASSERT(order <= 32);
  86202. if(order <= 12) {
  86203. if(order > 8) {
  86204. if(order > 10) {
  86205. if(order == 12) {
  86206. for(i = 0; i < (int)data_len; i++) {
  86207. sum = 0;
  86208. sum += qlp_coeff[11] * data[i-12];
  86209. sum += qlp_coeff[10] * data[i-11];
  86210. sum += qlp_coeff[9] * data[i-10];
  86211. sum += qlp_coeff[8] * data[i-9];
  86212. sum += qlp_coeff[7] * data[i-8];
  86213. sum += qlp_coeff[6] * data[i-7];
  86214. sum += qlp_coeff[5] * data[i-6];
  86215. sum += qlp_coeff[4] * data[i-5];
  86216. sum += qlp_coeff[3] * data[i-4];
  86217. sum += qlp_coeff[2] * data[i-3];
  86218. sum += qlp_coeff[1] * data[i-2];
  86219. sum += qlp_coeff[0] * data[i-1];
  86220. data[i] = residual[i] + (sum >> lp_quantization);
  86221. }
  86222. }
  86223. else { /* order == 11 */
  86224. for(i = 0; i < (int)data_len; i++) {
  86225. sum = 0;
  86226. sum += qlp_coeff[10] * data[i-11];
  86227. sum += qlp_coeff[9] * data[i-10];
  86228. sum += qlp_coeff[8] * data[i-9];
  86229. sum += qlp_coeff[7] * data[i-8];
  86230. sum += qlp_coeff[6] * data[i-7];
  86231. sum += qlp_coeff[5] * data[i-6];
  86232. sum += qlp_coeff[4] * data[i-5];
  86233. sum += qlp_coeff[3] * data[i-4];
  86234. sum += qlp_coeff[2] * data[i-3];
  86235. sum += qlp_coeff[1] * data[i-2];
  86236. sum += qlp_coeff[0] * data[i-1];
  86237. data[i] = residual[i] + (sum >> lp_quantization);
  86238. }
  86239. }
  86240. }
  86241. else {
  86242. if(order == 10) {
  86243. for(i = 0; i < (int)data_len; i++) {
  86244. sum = 0;
  86245. sum += qlp_coeff[9] * data[i-10];
  86246. sum += qlp_coeff[8] * data[i-9];
  86247. sum += qlp_coeff[7] * data[i-8];
  86248. sum += qlp_coeff[6] * data[i-7];
  86249. sum += qlp_coeff[5] * data[i-6];
  86250. sum += qlp_coeff[4] * data[i-5];
  86251. sum += qlp_coeff[3] * data[i-4];
  86252. sum += qlp_coeff[2] * data[i-3];
  86253. sum += qlp_coeff[1] * data[i-2];
  86254. sum += qlp_coeff[0] * data[i-1];
  86255. data[i] = residual[i] + (sum >> lp_quantization);
  86256. }
  86257. }
  86258. else { /* order == 9 */
  86259. for(i = 0; i < (int)data_len; i++) {
  86260. sum = 0;
  86261. sum += qlp_coeff[8] * data[i-9];
  86262. sum += qlp_coeff[7] * data[i-8];
  86263. sum += qlp_coeff[6] * data[i-7];
  86264. sum += qlp_coeff[5] * data[i-6];
  86265. sum += qlp_coeff[4] * data[i-5];
  86266. sum += qlp_coeff[3] * data[i-4];
  86267. sum += qlp_coeff[2] * data[i-3];
  86268. sum += qlp_coeff[1] * data[i-2];
  86269. sum += qlp_coeff[0] * data[i-1];
  86270. data[i] = residual[i] + (sum >> lp_quantization);
  86271. }
  86272. }
  86273. }
  86274. }
  86275. else if(order > 4) {
  86276. if(order > 6) {
  86277. if(order == 8) {
  86278. for(i = 0; i < (int)data_len; i++) {
  86279. sum = 0;
  86280. sum += qlp_coeff[7] * data[i-8];
  86281. sum += qlp_coeff[6] * data[i-7];
  86282. sum += qlp_coeff[5] * data[i-6];
  86283. sum += qlp_coeff[4] * data[i-5];
  86284. sum += qlp_coeff[3] * data[i-4];
  86285. sum += qlp_coeff[2] * data[i-3];
  86286. sum += qlp_coeff[1] * data[i-2];
  86287. sum += qlp_coeff[0] * data[i-1];
  86288. data[i] = residual[i] + (sum >> lp_quantization);
  86289. }
  86290. }
  86291. else { /* order == 7 */
  86292. for(i = 0; i < (int)data_len; i++) {
  86293. sum = 0;
  86294. sum += qlp_coeff[6] * data[i-7];
  86295. sum += qlp_coeff[5] * data[i-6];
  86296. sum += qlp_coeff[4] * data[i-5];
  86297. sum += qlp_coeff[3] * data[i-4];
  86298. sum += qlp_coeff[2] * data[i-3];
  86299. sum += qlp_coeff[1] * data[i-2];
  86300. sum += qlp_coeff[0] * data[i-1];
  86301. data[i] = residual[i] + (sum >> lp_quantization);
  86302. }
  86303. }
  86304. }
  86305. else {
  86306. if(order == 6) {
  86307. for(i = 0; i < (int)data_len; i++) {
  86308. sum = 0;
  86309. sum += qlp_coeff[5] * data[i-6];
  86310. sum += qlp_coeff[4] * data[i-5];
  86311. sum += qlp_coeff[3] * data[i-4];
  86312. sum += qlp_coeff[2] * data[i-3];
  86313. sum += qlp_coeff[1] * data[i-2];
  86314. sum += qlp_coeff[0] * data[i-1];
  86315. data[i] = residual[i] + (sum >> lp_quantization);
  86316. }
  86317. }
  86318. else { /* order == 5 */
  86319. for(i = 0; i < (int)data_len; i++) {
  86320. sum = 0;
  86321. sum += qlp_coeff[4] * data[i-5];
  86322. sum += qlp_coeff[3] * data[i-4];
  86323. sum += qlp_coeff[2] * data[i-3];
  86324. sum += qlp_coeff[1] * data[i-2];
  86325. sum += qlp_coeff[0] * data[i-1];
  86326. data[i] = residual[i] + (sum >> lp_quantization);
  86327. }
  86328. }
  86329. }
  86330. }
  86331. else {
  86332. if(order > 2) {
  86333. if(order == 4) {
  86334. for(i = 0; i < (int)data_len; i++) {
  86335. sum = 0;
  86336. sum += qlp_coeff[3] * data[i-4];
  86337. sum += qlp_coeff[2] * data[i-3];
  86338. sum += qlp_coeff[1] * data[i-2];
  86339. sum += qlp_coeff[0] * data[i-1];
  86340. data[i] = residual[i] + (sum >> lp_quantization);
  86341. }
  86342. }
  86343. else { /* order == 3 */
  86344. for(i = 0; i < (int)data_len; i++) {
  86345. sum = 0;
  86346. sum += qlp_coeff[2] * data[i-3];
  86347. sum += qlp_coeff[1] * data[i-2];
  86348. sum += qlp_coeff[0] * data[i-1];
  86349. data[i] = residual[i] + (sum >> lp_quantization);
  86350. }
  86351. }
  86352. }
  86353. else {
  86354. if(order == 2) {
  86355. for(i = 0; i < (int)data_len; i++) {
  86356. sum = 0;
  86357. sum += qlp_coeff[1] * data[i-2];
  86358. sum += qlp_coeff[0] * data[i-1];
  86359. data[i] = residual[i] + (sum >> lp_quantization);
  86360. }
  86361. }
  86362. else { /* order == 1 */
  86363. for(i = 0; i < (int)data_len; i++)
  86364. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86365. }
  86366. }
  86367. }
  86368. }
  86369. else { /* order > 12 */
  86370. for(i = 0; i < (int)data_len; i++) {
  86371. sum = 0;
  86372. switch(order) {
  86373. case 32: sum += qlp_coeff[31] * data[i-32];
  86374. case 31: sum += qlp_coeff[30] * data[i-31];
  86375. case 30: sum += qlp_coeff[29] * data[i-30];
  86376. case 29: sum += qlp_coeff[28] * data[i-29];
  86377. case 28: sum += qlp_coeff[27] * data[i-28];
  86378. case 27: sum += qlp_coeff[26] * data[i-27];
  86379. case 26: sum += qlp_coeff[25] * data[i-26];
  86380. case 25: sum += qlp_coeff[24] * data[i-25];
  86381. case 24: sum += qlp_coeff[23] * data[i-24];
  86382. case 23: sum += qlp_coeff[22] * data[i-23];
  86383. case 22: sum += qlp_coeff[21] * data[i-22];
  86384. case 21: sum += qlp_coeff[20] * data[i-21];
  86385. case 20: sum += qlp_coeff[19] * data[i-20];
  86386. case 19: sum += qlp_coeff[18] * data[i-19];
  86387. case 18: sum += qlp_coeff[17] * data[i-18];
  86388. case 17: sum += qlp_coeff[16] * data[i-17];
  86389. case 16: sum += qlp_coeff[15] * data[i-16];
  86390. case 15: sum += qlp_coeff[14] * data[i-15];
  86391. case 14: sum += qlp_coeff[13] * data[i-14];
  86392. case 13: sum += qlp_coeff[12] * data[i-13];
  86393. sum += qlp_coeff[11] * data[i-12];
  86394. sum += qlp_coeff[10] * data[i-11];
  86395. sum += qlp_coeff[ 9] * data[i-10];
  86396. sum += qlp_coeff[ 8] * data[i- 9];
  86397. sum += qlp_coeff[ 7] * data[i- 8];
  86398. sum += qlp_coeff[ 6] * data[i- 7];
  86399. sum += qlp_coeff[ 5] * data[i- 6];
  86400. sum += qlp_coeff[ 4] * data[i- 5];
  86401. sum += qlp_coeff[ 3] * data[i- 4];
  86402. sum += qlp_coeff[ 2] * data[i- 3];
  86403. sum += qlp_coeff[ 1] * data[i- 2];
  86404. sum += qlp_coeff[ 0] * data[i- 1];
  86405. }
  86406. data[i] = residual[i] + (sum >> lp_quantization);
  86407. }
  86408. }
  86409. }
  86410. #endif
  86411. 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[])
  86412. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86413. {
  86414. unsigned i, j;
  86415. FLAC__int64 sum;
  86416. const FLAC__int32 *r = residual, *history;
  86417. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86418. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86419. for(i=0;i<order;i++)
  86420. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86421. fprintf(stderr,"\n");
  86422. #endif
  86423. FLAC__ASSERT(order > 0);
  86424. for(i = 0; i < data_len; i++) {
  86425. sum = 0;
  86426. history = data;
  86427. for(j = 0; j < order; j++)
  86428. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86429. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86430. #ifdef _MSC_VER
  86431. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86432. #else
  86433. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86434. #endif
  86435. break;
  86436. }
  86437. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86438. #ifdef _MSC_VER
  86439. 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));
  86440. #else
  86441. 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)));
  86442. #endif
  86443. break;
  86444. }
  86445. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86446. }
  86447. }
  86448. #else /* fully unrolled version for normal use */
  86449. {
  86450. int i;
  86451. FLAC__int64 sum;
  86452. FLAC__ASSERT(order > 0);
  86453. FLAC__ASSERT(order <= 32);
  86454. if(order <= 12) {
  86455. if(order > 8) {
  86456. if(order > 10) {
  86457. if(order == 12) {
  86458. for(i = 0; i < (int)data_len; i++) {
  86459. sum = 0;
  86460. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86461. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86462. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86463. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86464. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86465. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86466. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86467. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86468. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86469. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86470. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86471. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86472. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86473. }
  86474. }
  86475. else { /* order == 11 */
  86476. for(i = 0; i < (int)data_len; i++) {
  86477. sum = 0;
  86478. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86479. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86480. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86481. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86482. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86483. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86484. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86485. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86486. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86487. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86488. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86489. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86490. }
  86491. }
  86492. }
  86493. else {
  86494. if(order == 10) {
  86495. for(i = 0; i < (int)data_len; i++) {
  86496. sum = 0;
  86497. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86498. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86499. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86500. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86501. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86502. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86503. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86504. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86505. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86506. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86507. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86508. }
  86509. }
  86510. else { /* order == 9 */
  86511. for(i = 0; i < (int)data_len; i++) {
  86512. sum = 0;
  86513. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86514. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86515. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86516. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86517. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86518. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86519. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86520. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86521. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86522. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86523. }
  86524. }
  86525. }
  86526. }
  86527. else if(order > 4) {
  86528. if(order > 6) {
  86529. if(order == 8) {
  86530. for(i = 0; i < (int)data_len; i++) {
  86531. sum = 0;
  86532. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86533. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86534. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86535. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86536. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86537. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86538. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86539. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86540. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86541. }
  86542. }
  86543. else { /* order == 7 */
  86544. for(i = 0; i < (int)data_len; i++) {
  86545. sum = 0;
  86546. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86547. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86548. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86549. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86550. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86551. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86552. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86553. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86554. }
  86555. }
  86556. }
  86557. else {
  86558. if(order == 6) {
  86559. for(i = 0; i < (int)data_len; i++) {
  86560. sum = 0;
  86561. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86562. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86563. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86564. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86565. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86566. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86567. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86568. }
  86569. }
  86570. else { /* order == 5 */
  86571. for(i = 0; i < (int)data_len; i++) {
  86572. sum = 0;
  86573. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86574. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86575. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86576. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86577. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86578. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86579. }
  86580. }
  86581. }
  86582. }
  86583. else {
  86584. if(order > 2) {
  86585. if(order == 4) {
  86586. for(i = 0; i < (int)data_len; i++) {
  86587. sum = 0;
  86588. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86589. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86590. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86591. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86592. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86593. }
  86594. }
  86595. else { /* order == 3 */
  86596. for(i = 0; i < (int)data_len; i++) {
  86597. sum = 0;
  86598. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86599. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86600. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86601. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86602. }
  86603. }
  86604. }
  86605. else {
  86606. if(order == 2) {
  86607. for(i = 0; i < (int)data_len; i++) {
  86608. sum = 0;
  86609. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86610. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86611. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86612. }
  86613. }
  86614. else { /* order == 1 */
  86615. for(i = 0; i < (int)data_len; i++)
  86616. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86617. }
  86618. }
  86619. }
  86620. }
  86621. else { /* order > 12 */
  86622. for(i = 0; i < (int)data_len; i++) {
  86623. sum = 0;
  86624. switch(order) {
  86625. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86626. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86627. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86628. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86629. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86630. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86631. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86632. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86633. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86634. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86635. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86636. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86637. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86638. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86639. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86640. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86641. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86642. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86643. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86644. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86645. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86646. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86647. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86648. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86649. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86650. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86651. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86652. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86653. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86654. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86655. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86656. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86657. }
  86658. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86659. }
  86660. }
  86661. }
  86662. #endif
  86663. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86664. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86665. {
  86666. FLAC__double error_scale;
  86667. FLAC__ASSERT(total_samples > 0);
  86668. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86669. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86670. }
  86671. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86672. {
  86673. if(lpc_error > 0.0) {
  86674. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86675. if(bps >= 0.0)
  86676. return bps;
  86677. else
  86678. return 0.0;
  86679. }
  86680. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86681. return 1e32;
  86682. }
  86683. else {
  86684. return 0.0;
  86685. }
  86686. }
  86687. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86688. {
  86689. 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 */
  86690. FLAC__double bits, best_bits, error_scale;
  86691. FLAC__ASSERT(max_order > 0);
  86692. FLAC__ASSERT(total_samples > 0);
  86693. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86694. best_index = 0;
  86695. best_bits = (unsigned)(-1);
  86696. for(index = 0, order = 1; index < max_order; index++, order++) {
  86697. 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);
  86698. if(bits < best_bits) {
  86699. best_index = index;
  86700. best_bits = bits;
  86701. }
  86702. }
  86703. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86704. }
  86705. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86706. #endif
  86707. /*** End of inlined file: lpc_flac.c ***/
  86708. /*** Start of inlined file: md5.c ***/
  86709. /*** Start of inlined file: juce_FlacHeader.h ***/
  86710. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86711. // tasks..
  86712. #define VERSION "1.2.1"
  86713. #define FLAC__NO_DLL 1
  86714. #if JUCE_MSVC
  86715. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86716. #endif
  86717. #if JUCE_MAC
  86718. #define FLAC__SYS_DARWIN 1
  86719. #endif
  86720. /*** End of inlined file: juce_FlacHeader.h ***/
  86721. #if JUCE_USE_FLAC
  86722. #if HAVE_CONFIG_H
  86723. # include <config.h>
  86724. #endif
  86725. #include <stdlib.h> /* for malloc() */
  86726. #include <string.h> /* for memcpy() */
  86727. /*** Start of inlined file: md5.h ***/
  86728. #ifndef FLAC__PRIVATE__MD5_H
  86729. #define FLAC__PRIVATE__MD5_H
  86730. typedef struct {
  86731. FLAC__uint32 in[16];
  86732. FLAC__uint32 buf[4];
  86733. FLAC__uint32 bytes[2];
  86734. FLAC__byte *internal_buf;
  86735. size_t capacity;
  86736. } FLAC__MD5Context;
  86737. void FLAC__MD5Init(FLAC__MD5Context *context);
  86738. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86739. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86740. #endif
  86741. /*** End of inlined file: md5.h ***/
  86742. #ifndef FLaC__INLINE
  86743. #define FLaC__INLINE
  86744. #endif
  86745. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86746. #define F2(x, y, z) F1(z, x, y)
  86747. #define F3(x, y, z) (x ^ y ^ z)
  86748. #define F4(x, y, z) (y ^ (x | ~z))
  86749. #define MD5STEP(f,w,x,y,z,in,s) \
  86750. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86751. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86752. {
  86753. register FLAC__uint32 a, b, c, d;
  86754. a = buf[0];
  86755. b = buf[1];
  86756. c = buf[2];
  86757. d = buf[3];
  86758. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86759. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86760. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86761. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86762. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86763. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86764. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86765. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86766. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86767. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86768. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86769. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86770. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86771. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86772. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86773. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86774. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86775. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86776. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86777. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86778. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86779. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86780. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86781. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86782. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86783. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86784. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86785. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86786. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86787. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86788. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86789. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86790. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86791. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86792. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86793. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86794. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86795. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86796. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86797. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86798. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86799. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86800. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86801. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86802. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86803. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86804. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86805. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86806. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86807. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86808. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86809. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86810. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86811. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86812. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86813. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86814. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86815. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86816. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86817. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86818. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86819. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86820. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86821. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86822. buf[0] += a;
  86823. buf[1] += b;
  86824. buf[2] += c;
  86825. buf[3] += d;
  86826. }
  86827. #if WORDS_BIGENDIAN
  86828. //@@@@@@ OPT: use bswap/intrinsics
  86829. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86830. {
  86831. register FLAC__uint32 x;
  86832. do {
  86833. x = *buf;
  86834. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86835. *buf++ = (x >> 16) | (x << 16);
  86836. } while (--words);
  86837. }
  86838. static void byteSwapX16(FLAC__uint32 *buf)
  86839. {
  86840. register FLAC__uint32 x;
  86841. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86842. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86843. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86844. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86845. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86846. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86847. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86848. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86849. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86850. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86851. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86852. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86853. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86854. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86855. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86856. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86857. }
  86858. #else
  86859. #define byteSwap(buf, words)
  86860. #define byteSwapX16(buf)
  86861. #endif
  86862. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86863. {
  86864. FLAC__uint32 t;
  86865. t = ctx->bytes[0];
  86866. if ((ctx->bytes[0] = t + len) < t)
  86867. ctx->bytes[1]++; /* Carry from low to high */
  86868. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86869. if (t > len) {
  86870. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86871. return;
  86872. }
  86873. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86874. byteSwapX16(ctx->in);
  86875. FLAC__MD5Transform(ctx->buf, ctx->in);
  86876. buf += t;
  86877. len -= t;
  86878. while (len >= 64) {
  86879. memcpy(ctx->in, buf, 64);
  86880. byteSwapX16(ctx->in);
  86881. FLAC__MD5Transform(ctx->buf, ctx->in);
  86882. buf += 64;
  86883. len -= 64;
  86884. }
  86885. memcpy(ctx->in, buf, len);
  86886. }
  86887. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86888. {
  86889. ctx->buf[0] = 0x67452301;
  86890. ctx->buf[1] = 0xefcdab89;
  86891. ctx->buf[2] = 0x98badcfe;
  86892. ctx->buf[3] = 0x10325476;
  86893. ctx->bytes[0] = 0;
  86894. ctx->bytes[1] = 0;
  86895. ctx->internal_buf = 0;
  86896. ctx->capacity = 0;
  86897. }
  86898. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86899. {
  86900. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86901. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86902. *p++ = 0x80;
  86903. count = 56 - 1 - count;
  86904. if (count < 0) { /* Padding forces an extra block */
  86905. memset(p, 0, count + 8);
  86906. byteSwapX16(ctx->in);
  86907. FLAC__MD5Transform(ctx->buf, ctx->in);
  86908. p = (FLAC__byte *)ctx->in;
  86909. count = 56;
  86910. }
  86911. memset(p, 0, count);
  86912. byteSwap(ctx->in, 14);
  86913. ctx->in[14] = ctx->bytes[0] << 3;
  86914. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86915. FLAC__MD5Transform(ctx->buf, ctx->in);
  86916. byteSwap(ctx->buf, 4);
  86917. memcpy(digest, ctx->buf, 16);
  86918. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86919. if(0 != ctx->internal_buf) {
  86920. free(ctx->internal_buf);
  86921. ctx->internal_buf = 0;
  86922. ctx->capacity = 0;
  86923. }
  86924. }
  86925. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86926. {
  86927. unsigned channel, sample;
  86928. register FLAC__int32 a_word;
  86929. register FLAC__byte *buf_ = buf;
  86930. #if WORDS_BIGENDIAN
  86931. #else
  86932. if(channels == 2 && bytes_per_sample == 2) {
  86933. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86934. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86935. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86936. *buf1_ = (FLAC__int16)signal[1][sample];
  86937. }
  86938. else if(channels == 1 && bytes_per_sample == 2) {
  86939. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86940. for(sample = 0; sample < samples; sample++)
  86941. *buf1_++ = (FLAC__int16)signal[0][sample];
  86942. }
  86943. else
  86944. #endif
  86945. if(bytes_per_sample == 2) {
  86946. if(channels == 2) {
  86947. for(sample = 0; sample < samples; sample++) {
  86948. a_word = signal[0][sample];
  86949. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86950. *buf_++ = (FLAC__byte)a_word;
  86951. a_word = signal[1][sample];
  86952. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86953. *buf_++ = (FLAC__byte)a_word;
  86954. }
  86955. }
  86956. else if(channels == 1) {
  86957. for(sample = 0; sample < samples; sample++) {
  86958. a_word = signal[0][sample];
  86959. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86960. *buf_++ = (FLAC__byte)a_word;
  86961. }
  86962. }
  86963. else {
  86964. for(sample = 0; sample < samples; sample++) {
  86965. for(channel = 0; channel < channels; channel++) {
  86966. a_word = signal[channel][sample];
  86967. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86968. *buf_++ = (FLAC__byte)a_word;
  86969. }
  86970. }
  86971. }
  86972. }
  86973. else if(bytes_per_sample == 3) {
  86974. if(channels == 2) {
  86975. for(sample = 0; sample < samples; sample++) {
  86976. a_word = signal[0][sample];
  86977. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86978. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86979. *buf_++ = (FLAC__byte)a_word;
  86980. a_word = signal[1][sample];
  86981. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86982. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86983. *buf_++ = (FLAC__byte)a_word;
  86984. }
  86985. }
  86986. else if(channels == 1) {
  86987. for(sample = 0; sample < samples; sample++) {
  86988. a_word = signal[0][sample];
  86989. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86990. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86991. *buf_++ = (FLAC__byte)a_word;
  86992. }
  86993. }
  86994. else {
  86995. for(sample = 0; sample < samples; sample++) {
  86996. for(channel = 0; channel < channels; channel++) {
  86997. a_word = signal[channel][sample];
  86998. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86999. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87000. *buf_++ = (FLAC__byte)a_word;
  87001. }
  87002. }
  87003. }
  87004. }
  87005. else if(bytes_per_sample == 1) {
  87006. if(channels == 2) {
  87007. for(sample = 0; sample < samples; sample++) {
  87008. a_word = signal[0][sample];
  87009. *buf_++ = (FLAC__byte)a_word;
  87010. a_word = signal[1][sample];
  87011. *buf_++ = (FLAC__byte)a_word;
  87012. }
  87013. }
  87014. else if(channels == 1) {
  87015. for(sample = 0; sample < samples; sample++) {
  87016. a_word = signal[0][sample];
  87017. *buf_++ = (FLAC__byte)a_word;
  87018. }
  87019. }
  87020. else {
  87021. for(sample = 0; sample < samples; sample++) {
  87022. for(channel = 0; channel < channels; channel++) {
  87023. a_word = signal[channel][sample];
  87024. *buf_++ = (FLAC__byte)a_word;
  87025. }
  87026. }
  87027. }
  87028. }
  87029. else { /* bytes_per_sample == 4, maybe optimize more later */
  87030. for(sample = 0; sample < samples; sample++) {
  87031. for(channel = 0; channel < channels; channel++) {
  87032. a_word = signal[channel][sample];
  87033. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87034. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87035. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87036. *buf_++ = (FLAC__byte)a_word;
  87037. }
  87038. }
  87039. }
  87040. }
  87041. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  87042. {
  87043. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  87044. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  87045. return false;
  87046. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  87047. return false;
  87048. if(ctx->capacity < bytes_needed) {
  87049. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  87050. if(0 == tmp) {
  87051. free(ctx->internal_buf);
  87052. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  87053. return false;
  87054. }
  87055. ctx->internal_buf = tmp;
  87056. ctx->capacity = bytes_needed;
  87057. }
  87058. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  87059. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  87060. return true;
  87061. }
  87062. #endif
  87063. /*** End of inlined file: md5.c ***/
  87064. /*** Start of inlined file: memory.c ***/
  87065. /*** Start of inlined file: juce_FlacHeader.h ***/
  87066. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87067. // tasks..
  87068. #define VERSION "1.2.1"
  87069. #define FLAC__NO_DLL 1
  87070. #if JUCE_MSVC
  87071. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87072. #endif
  87073. #if JUCE_MAC
  87074. #define FLAC__SYS_DARWIN 1
  87075. #endif
  87076. /*** End of inlined file: juce_FlacHeader.h ***/
  87077. #if JUCE_USE_FLAC
  87078. #if HAVE_CONFIG_H
  87079. # include <config.h>
  87080. #endif
  87081. /*** Start of inlined file: memory.h ***/
  87082. #ifndef FLAC__PRIVATE__MEMORY_H
  87083. #define FLAC__PRIVATE__MEMORY_H
  87084. #ifdef HAVE_CONFIG_H
  87085. #include <config.h>
  87086. #endif
  87087. #include <stdlib.h> /* for size_t */
  87088. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  87089. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  87090. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  87091. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  87092. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  87093. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87094. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  87095. #endif
  87096. #endif
  87097. /*** End of inlined file: memory.h ***/
  87098. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87099. {
  87100. void *x;
  87101. FLAC__ASSERT(0 != aligned_address);
  87102. #ifdef FLAC__ALIGN_MALLOC_DATA
  87103. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87104. #ifdef SIZEOF_VOIDP
  87105. #if SIZEOF_VOIDP == 4
  87106. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87107. #elif SIZEOF_VOIDP == 8
  87108. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87109. #else
  87110. # error Unsupported sizeof(void*)
  87111. #endif
  87112. #else
  87113. if(sizeof(void*) == sizeof(unsigned))
  87114. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87115. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87116. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87117. else
  87118. return 0;
  87119. #endif
  87120. #else
  87121. x = safe_malloc_(bytes);
  87122. *aligned_address = x;
  87123. #endif
  87124. return x;
  87125. }
  87126. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87127. {
  87128. FLAC__int32 *pu; /* unaligned pointer */
  87129. union { /* union needed to comply with C99 pointer aliasing rules */
  87130. FLAC__int32 *pa; /* aligned pointer */
  87131. void *pv; /* aligned pointer alias */
  87132. } u;
  87133. FLAC__ASSERT(elements > 0);
  87134. FLAC__ASSERT(0 != unaligned_pointer);
  87135. FLAC__ASSERT(0 != aligned_pointer);
  87136. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87137. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87138. if(0 == pu) {
  87139. return false;
  87140. }
  87141. else {
  87142. if(*unaligned_pointer != 0)
  87143. free(*unaligned_pointer);
  87144. *unaligned_pointer = pu;
  87145. *aligned_pointer = u.pa;
  87146. return true;
  87147. }
  87148. }
  87149. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87150. {
  87151. FLAC__uint32 *pu; /* unaligned pointer */
  87152. union { /* union needed to comply with C99 pointer aliasing rules */
  87153. FLAC__uint32 *pa; /* aligned pointer */
  87154. void *pv; /* aligned pointer alias */
  87155. } u;
  87156. FLAC__ASSERT(elements > 0);
  87157. FLAC__ASSERT(0 != unaligned_pointer);
  87158. FLAC__ASSERT(0 != aligned_pointer);
  87159. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87160. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87161. if(0 == pu) {
  87162. return false;
  87163. }
  87164. else {
  87165. if(*unaligned_pointer != 0)
  87166. free(*unaligned_pointer);
  87167. *unaligned_pointer = pu;
  87168. *aligned_pointer = u.pa;
  87169. return true;
  87170. }
  87171. }
  87172. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87173. {
  87174. FLAC__uint64 *pu; /* unaligned pointer */
  87175. union { /* union needed to comply with C99 pointer aliasing rules */
  87176. FLAC__uint64 *pa; /* aligned pointer */
  87177. void *pv; /* aligned pointer alias */
  87178. } u;
  87179. FLAC__ASSERT(elements > 0);
  87180. FLAC__ASSERT(0 != unaligned_pointer);
  87181. FLAC__ASSERT(0 != aligned_pointer);
  87182. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87183. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87184. if(0 == pu) {
  87185. return false;
  87186. }
  87187. else {
  87188. if(*unaligned_pointer != 0)
  87189. free(*unaligned_pointer);
  87190. *unaligned_pointer = pu;
  87191. *aligned_pointer = u.pa;
  87192. return true;
  87193. }
  87194. }
  87195. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87196. {
  87197. unsigned *pu; /* unaligned pointer */
  87198. union { /* union needed to comply with C99 pointer aliasing rules */
  87199. unsigned *pa; /* aligned pointer */
  87200. void *pv; /* aligned pointer alias */
  87201. } u;
  87202. FLAC__ASSERT(elements > 0);
  87203. FLAC__ASSERT(0 != unaligned_pointer);
  87204. FLAC__ASSERT(0 != aligned_pointer);
  87205. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87206. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87207. if(0 == pu) {
  87208. return false;
  87209. }
  87210. else {
  87211. if(*unaligned_pointer != 0)
  87212. free(*unaligned_pointer);
  87213. *unaligned_pointer = pu;
  87214. *aligned_pointer = u.pa;
  87215. return true;
  87216. }
  87217. }
  87218. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87219. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87220. {
  87221. FLAC__real *pu; /* unaligned pointer */
  87222. union { /* union needed to comply with C99 pointer aliasing rules */
  87223. FLAC__real *pa; /* aligned pointer */
  87224. void *pv; /* aligned pointer alias */
  87225. } u;
  87226. FLAC__ASSERT(elements > 0);
  87227. FLAC__ASSERT(0 != unaligned_pointer);
  87228. FLAC__ASSERT(0 != aligned_pointer);
  87229. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87230. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87231. if(0 == pu) {
  87232. return false;
  87233. }
  87234. else {
  87235. if(*unaligned_pointer != 0)
  87236. free(*unaligned_pointer);
  87237. *unaligned_pointer = pu;
  87238. *aligned_pointer = u.pa;
  87239. return true;
  87240. }
  87241. }
  87242. #endif
  87243. #endif
  87244. /*** End of inlined file: memory.c ***/
  87245. /*** Start of inlined file: stream_decoder.c ***/
  87246. /*** Start of inlined file: juce_FlacHeader.h ***/
  87247. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87248. // tasks..
  87249. #define VERSION "1.2.1"
  87250. #define FLAC__NO_DLL 1
  87251. #if JUCE_MSVC
  87252. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87253. #endif
  87254. #if JUCE_MAC
  87255. #define FLAC__SYS_DARWIN 1
  87256. #endif
  87257. /*** End of inlined file: juce_FlacHeader.h ***/
  87258. #if JUCE_USE_FLAC
  87259. #if HAVE_CONFIG_H
  87260. # include <config.h>
  87261. #endif
  87262. #if defined _MSC_VER || defined __MINGW32__
  87263. #include <io.h> /* for _setmode() */
  87264. #include <fcntl.h> /* for _O_BINARY */
  87265. #endif
  87266. #if defined __CYGWIN__ || defined __EMX__
  87267. #include <io.h> /* for setmode(), O_BINARY */
  87268. #include <fcntl.h> /* for _O_BINARY */
  87269. #endif
  87270. #include <stdio.h>
  87271. #include <stdlib.h> /* for malloc() */
  87272. #include <string.h> /* for memset/memcpy() */
  87273. #include <sys/stat.h> /* for stat() */
  87274. #include <sys/types.h> /* for off_t */
  87275. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87276. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87277. #define fseeko fseek
  87278. #define ftello ftell
  87279. #endif
  87280. #endif
  87281. /*** Start of inlined file: stream_decoder.h ***/
  87282. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87283. #define FLAC__PROTECTED__STREAM_DECODER_H
  87284. #if FLAC__HAS_OGG
  87285. #include "include/private/ogg_decoder_aspect.h"
  87286. #endif
  87287. typedef struct FLAC__StreamDecoderProtected {
  87288. FLAC__StreamDecoderState state;
  87289. unsigned channels;
  87290. FLAC__ChannelAssignment channel_assignment;
  87291. unsigned bits_per_sample;
  87292. unsigned sample_rate; /* in Hz */
  87293. unsigned blocksize; /* in samples (per channel) */
  87294. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87295. #if FLAC__HAS_OGG
  87296. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87297. #endif
  87298. } FLAC__StreamDecoderProtected;
  87299. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87300. #endif
  87301. /*** End of inlined file: stream_decoder.h ***/
  87302. #ifdef max
  87303. #undef max
  87304. #endif
  87305. #define max(a,b) ((a)>(b)?(a):(b))
  87306. #ifdef _MSC_VER
  87307. #define FLAC__U64L(x) x
  87308. #else
  87309. #define FLAC__U64L(x) x##LLU
  87310. #endif
  87311. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87312. #if FLAC__HAS_OGG
  87313. 1
  87314. #else
  87315. 0
  87316. #endif
  87317. ;
  87318. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87319. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87320. static FILE *get_binary_stdin_(void);
  87321. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87322. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87323. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87324. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87325. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87326. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87327. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87328. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87329. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87330. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87331. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87332. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87333. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87334. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87335. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87336. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87337. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87338. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87339. 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);
  87340. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87341. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87342. #if FLAC__HAS_OGG
  87343. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87344. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87345. #endif
  87346. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87347. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87348. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87349. #if FLAC__HAS_OGG
  87350. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87351. #endif
  87352. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87353. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87354. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87355. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87356. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87357. typedef struct FLAC__StreamDecoderPrivate {
  87358. #if FLAC__HAS_OGG
  87359. FLAC__bool is_ogg;
  87360. #endif
  87361. FLAC__StreamDecoderReadCallback read_callback;
  87362. FLAC__StreamDecoderSeekCallback seek_callback;
  87363. FLAC__StreamDecoderTellCallback tell_callback;
  87364. FLAC__StreamDecoderLengthCallback length_callback;
  87365. FLAC__StreamDecoderEofCallback eof_callback;
  87366. FLAC__StreamDecoderWriteCallback write_callback;
  87367. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87368. FLAC__StreamDecoderErrorCallback error_callback;
  87369. 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[]);
  87370. 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[]);
  87371. 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[]);
  87372. 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[]);
  87373. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87374. void *client_data;
  87375. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87376. FLAC__BitReader *input;
  87377. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87378. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87379. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87380. unsigned output_capacity, output_channels;
  87381. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87382. FLAC__uint64 samples_decoded;
  87383. FLAC__bool has_stream_info, has_seek_table;
  87384. FLAC__StreamMetadata stream_info;
  87385. FLAC__StreamMetadata seek_table;
  87386. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87387. FLAC__byte *metadata_filter_ids;
  87388. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87389. FLAC__Frame frame;
  87390. FLAC__bool cached; /* true if there is a byte in lookahead */
  87391. FLAC__CPUInfo cpuinfo;
  87392. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87393. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87394. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87395. 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 */
  87396. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87397. FLAC__bool is_seeking;
  87398. FLAC__MD5Context md5context;
  87399. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87400. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87401. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87402. FLAC__uint64 target_sample;
  87403. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87404. #if FLAC__HAS_OGG
  87405. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87406. #endif
  87407. } FLAC__StreamDecoderPrivate;
  87408. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87409. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87410. "FLAC__STREAM_DECODER_READ_METADATA",
  87411. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87412. "FLAC__STREAM_DECODER_READ_FRAME",
  87413. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87414. "FLAC__STREAM_DECODER_OGG_ERROR",
  87415. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87416. "FLAC__STREAM_DECODER_ABORTED",
  87417. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87418. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87419. };
  87420. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87421. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87422. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87423. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87424. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87425. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87426. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87427. };
  87428. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87429. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87430. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87431. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87432. };
  87433. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87434. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87435. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87436. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87437. };
  87438. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87439. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87440. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87441. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87442. };
  87443. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87444. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87445. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87446. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87447. };
  87448. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87449. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87450. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87451. };
  87452. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87453. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87454. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87455. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87456. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87457. };
  87458. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87459. {
  87460. FLAC__StreamDecoder *decoder;
  87461. unsigned i;
  87462. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87463. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87464. if(decoder == 0) {
  87465. return 0;
  87466. }
  87467. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87468. if(decoder->protected_ == 0) {
  87469. free(decoder);
  87470. return 0;
  87471. }
  87472. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87473. if(decoder->private_ == 0) {
  87474. free(decoder->protected_);
  87475. free(decoder);
  87476. return 0;
  87477. }
  87478. decoder->private_->input = FLAC__bitreader_new();
  87479. if(decoder->private_->input == 0) {
  87480. free(decoder->private_);
  87481. free(decoder->protected_);
  87482. free(decoder);
  87483. return 0;
  87484. }
  87485. decoder->private_->metadata_filter_ids_capacity = 16;
  87486. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87487. FLAC__bitreader_delete(decoder->private_->input);
  87488. free(decoder->private_);
  87489. free(decoder->protected_);
  87490. free(decoder);
  87491. return 0;
  87492. }
  87493. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87494. decoder->private_->output[i] = 0;
  87495. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87496. }
  87497. decoder->private_->output_capacity = 0;
  87498. decoder->private_->output_channels = 0;
  87499. decoder->private_->has_seek_table = false;
  87500. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87501. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87502. decoder->private_->file = 0;
  87503. set_defaults_dec(decoder);
  87504. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87505. return decoder;
  87506. }
  87507. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87508. {
  87509. unsigned i;
  87510. FLAC__ASSERT(0 != decoder);
  87511. FLAC__ASSERT(0 != decoder->protected_);
  87512. FLAC__ASSERT(0 != decoder->private_);
  87513. FLAC__ASSERT(0 != decoder->private_->input);
  87514. (void)FLAC__stream_decoder_finish(decoder);
  87515. if(0 != decoder->private_->metadata_filter_ids)
  87516. free(decoder->private_->metadata_filter_ids);
  87517. FLAC__bitreader_delete(decoder->private_->input);
  87518. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87519. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87520. free(decoder->private_);
  87521. free(decoder->protected_);
  87522. free(decoder);
  87523. }
  87524. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87525. FLAC__StreamDecoder *decoder,
  87526. FLAC__StreamDecoderReadCallback read_callback,
  87527. FLAC__StreamDecoderSeekCallback seek_callback,
  87528. FLAC__StreamDecoderTellCallback tell_callback,
  87529. FLAC__StreamDecoderLengthCallback length_callback,
  87530. FLAC__StreamDecoderEofCallback eof_callback,
  87531. FLAC__StreamDecoderWriteCallback write_callback,
  87532. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87533. FLAC__StreamDecoderErrorCallback error_callback,
  87534. void *client_data,
  87535. FLAC__bool is_ogg
  87536. )
  87537. {
  87538. FLAC__ASSERT(0 != decoder);
  87539. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87540. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87541. #if !FLAC__HAS_OGG
  87542. if(is_ogg)
  87543. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87544. #endif
  87545. if(
  87546. 0 == read_callback ||
  87547. 0 == write_callback ||
  87548. 0 == error_callback ||
  87549. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87550. )
  87551. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87552. #if FLAC__HAS_OGG
  87553. decoder->private_->is_ogg = is_ogg;
  87554. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87555. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87556. #endif
  87557. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87558. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87559. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87560. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87561. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87562. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87563. #ifndef FLAC__NO_ASM
  87564. if(decoder->private_->cpuinfo.use_asm) {
  87565. #ifdef FLAC__CPU_IA32
  87566. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87567. #ifdef FLAC__HAS_NASM
  87568. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87569. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87570. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87571. #endif
  87572. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87573. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87574. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87575. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87576. }
  87577. else {
  87578. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87579. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87580. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87581. }
  87582. #endif
  87583. #elif defined FLAC__CPU_PPC
  87584. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87585. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87586. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87587. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87588. }
  87589. #endif
  87590. }
  87591. #endif
  87592. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87593. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87594. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87595. }
  87596. decoder->private_->read_callback = read_callback;
  87597. decoder->private_->seek_callback = seek_callback;
  87598. decoder->private_->tell_callback = tell_callback;
  87599. decoder->private_->length_callback = length_callback;
  87600. decoder->private_->eof_callback = eof_callback;
  87601. decoder->private_->write_callback = write_callback;
  87602. decoder->private_->metadata_callback = metadata_callback;
  87603. decoder->private_->error_callback = error_callback;
  87604. decoder->private_->client_data = client_data;
  87605. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87606. decoder->private_->samples_decoded = 0;
  87607. decoder->private_->has_stream_info = false;
  87608. decoder->private_->cached = false;
  87609. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87610. decoder->private_->is_seeking = false;
  87611. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87612. if(!FLAC__stream_decoder_reset(decoder)) {
  87613. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87614. }
  87615. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87616. }
  87617. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87618. FLAC__StreamDecoder *decoder,
  87619. FLAC__StreamDecoderReadCallback read_callback,
  87620. FLAC__StreamDecoderSeekCallback seek_callback,
  87621. FLAC__StreamDecoderTellCallback tell_callback,
  87622. FLAC__StreamDecoderLengthCallback length_callback,
  87623. FLAC__StreamDecoderEofCallback eof_callback,
  87624. FLAC__StreamDecoderWriteCallback write_callback,
  87625. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87626. FLAC__StreamDecoderErrorCallback error_callback,
  87627. void *client_data
  87628. )
  87629. {
  87630. return init_stream_internal_dec(
  87631. decoder,
  87632. read_callback,
  87633. seek_callback,
  87634. tell_callback,
  87635. length_callback,
  87636. eof_callback,
  87637. write_callback,
  87638. metadata_callback,
  87639. error_callback,
  87640. client_data,
  87641. false
  87642. );
  87643. }
  87644. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87645. FLAC__StreamDecoder *decoder,
  87646. FLAC__StreamDecoderReadCallback read_callback,
  87647. FLAC__StreamDecoderSeekCallback seek_callback,
  87648. FLAC__StreamDecoderTellCallback tell_callback,
  87649. FLAC__StreamDecoderLengthCallback length_callback,
  87650. FLAC__StreamDecoderEofCallback eof_callback,
  87651. FLAC__StreamDecoderWriteCallback write_callback,
  87652. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87653. FLAC__StreamDecoderErrorCallback error_callback,
  87654. void *client_data
  87655. )
  87656. {
  87657. return init_stream_internal_dec(
  87658. decoder,
  87659. read_callback,
  87660. seek_callback,
  87661. tell_callback,
  87662. length_callback,
  87663. eof_callback,
  87664. write_callback,
  87665. metadata_callback,
  87666. error_callback,
  87667. client_data,
  87668. true
  87669. );
  87670. }
  87671. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87672. FLAC__StreamDecoder *decoder,
  87673. FILE *file,
  87674. FLAC__StreamDecoderWriteCallback write_callback,
  87675. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87676. FLAC__StreamDecoderErrorCallback error_callback,
  87677. void *client_data,
  87678. FLAC__bool is_ogg
  87679. )
  87680. {
  87681. FLAC__ASSERT(0 != decoder);
  87682. FLAC__ASSERT(0 != file);
  87683. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87684. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87685. if(0 == write_callback || 0 == error_callback)
  87686. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87687. if(file == stdin)
  87688. file = get_binary_stdin_(); /* just to be safe */
  87689. decoder->private_->file = file;
  87690. return init_stream_internal_dec(
  87691. decoder,
  87692. file_read_callback_dec,
  87693. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87694. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87695. decoder->private_->file == stdin? 0: file_length_callback_,
  87696. file_eof_callback_,
  87697. write_callback,
  87698. metadata_callback,
  87699. error_callback,
  87700. client_data,
  87701. is_ogg
  87702. );
  87703. }
  87704. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87705. FLAC__StreamDecoder *decoder,
  87706. FILE *file,
  87707. FLAC__StreamDecoderWriteCallback write_callback,
  87708. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87709. FLAC__StreamDecoderErrorCallback error_callback,
  87710. void *client_data
  87711. )
  87712. {
  87713. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87714. }
  87715. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87716. FLAC__StreamDecoder *decoder,
  87717. FILE *file,
  87718. FLAC__StreamDecoderWriteCallback write_callback,
  87719. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87720. FLAC__StreamDecoderErrorCallback error_callback,
  87721. void *client_data
  87722. )
  87723. {
  87724. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87725. }
  87726. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87727. FLAC__StreamDecoder *decoder,
  87728. const char *filename,
  87729. FLAC__StreamDecoderWriteCallback write_callback,
  87730. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87731. FLAC__StreamDecoderErrorCallback error_callback,
  87732. void *client_data,
  87733. FLAC__bool is_ogg
  87734. )
  87735. {
  87736. FILE *file;
  87737. FLAC__ASSERT(0 != decoder);
  87738. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87739. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87740. if(0 == write_callback || 0 == error_callback)
  87741. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87742. file = filename? fopen(filename, "rb") : stdin;
  87743. if(0 == file)
  87744. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87745. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87746. }
  87747. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87748. FLAC__StreamDecoder *decoder,
  87749. const char *filename,
  87750. FLAC__StreamDecoderWriteCallback write_callback,
  87751. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87752. FLAC__StreamDecoderErrorCallback error_callback,
  87753. void *client_data
  87754. )
  87755. {
  87756. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87757. }
  87758. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87759. FLAC__StreamDecoder *decoder,
  87760. const char *filename,
  87761. FLAC__StreamDecoderWriteCallback write_callback,
  87762. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87763. FLAC__StreamDecoderErrorCallback error_callback,
  87764. void *client_data
  87765. )
  87766. {
  87767. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87768. }
  87769. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87770. {
  87771. FLAC__bool md5_failed = false;
  87772. unsigned i;
  87773. FLAC__ASSERT(0 != decoder);
  87774. FLAC__ASSERT(0 != decoder->private_);
  87775. FLAC__ASSERT(0 != decoder->protected_);
  87776. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87777. return true;
  87778. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87779. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87780. free(decoder->private_->seek_table.data.seek_table.points);
  87781. decoder->private_->seek_table.data.seek_table.points = 0;
  87782. decoder->private_->has_seek_table = false;
  87783. }
  87784. FLAC__bitreader_free(decoder->private_->input);
  87785. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87786. if(0 != decoder->private_->output[i]) {
  87787. free(decoder->private_->output[i]-4);
  87788. decoder->private_->output[i] = 0;
  87789. }
  87790. if(0 != decoder->private_->residual_unaligned[i]) {
  87791. free(decoder->private_->residual_unaligned[i]);
  87792. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87793. }
  87794. }
  87795. decoder->private_->output_capacity = 0;
  87796. decoder->private_->output_channels = 0;
  87797. #if FLAC__HAS_OGG
  87798. if(decoder->private_->is_ogg)
  87799. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87800. #endif
  87801. if(0 != decoder->private_->file) {
  87802. if(decoder->private_->file != stdin)
  87803. fclose(decoder->private_->file);
  87804. decoder->private_->file = 0;
  87805. }
  87806. if(decoder->private_->do_md5_checking) {
  87807. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87808. md5_failed = true;
  87809. }
  87810. decoder->private_->is_seeking = false;
  87811. set_defaults_dec(decoder);
  87812. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87813. return !md5_failed;
  87814. }
  87815. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87816. {
  87817. FLAC__ASSERT(0 != decoder);
  87818. FLAC__ASSERT(0 != decoder->private_);
  87819. FLAC__ASSERT(0 != decoder->protected_);
  87820. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87821. return false;
  87822. #if FLAC__HAS_OGG
  87823. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87824. return true;
  87825. #else
  87826. (void)value;
  87827. return false;
  87828. #endif
  87829. }
  87830. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87831. {
  87832. FLAC__ASSERT(0 != decoder);
  87833. FLAC__ASSERT(0 != decoder->protected_);
  87834. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87835. return false;
  87836. decoder->protected_->md5_checking = value;
  87837. return true;
  87838. }
  87839. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87840. {
  87841. FLAC__ASSERT(0 != decoder);
  87842. FLAC__ASSERT(0 != decoder->private_);
  87843. FLAC__ASSERT(0 != decoder->protected_);
  87844. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87845. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87846. return false;
  87847. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87848. return false;
  87849. decoder->private_->metadata_filter[type] = true;
  87850. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87851. decoder->private_->metadata_filter_ids_count = 0;
  87852. return true;
  87853. }
  87854. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87855. {
  87856. FLAC__ASSERT(0 != decoder);
  87857. FLAC__ASSERT(0 != decoder->private_);
  87858. FLAC__ASSERT(0 != decoder->protected_);
  87859. FLAC__ASSERT(0 != id);
  87860. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87861. return false;
  87862. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87863. return true;
  87864. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87865. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87866. 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))) {
  87867. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87868. return false;
  87869. }
  87870. decoder->private_->metadata_filter_ids_capacity *= 2;
  87871. }
  87872. 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));
  87873. decoder->private_->metadata_filter_ids_count++;
  87874. return true;
  87875. }
  87876. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87877. {
  87878. unsigned i;
  87879. FLAC__ASSERT(0 != decoder);
  87880. FLAC__ASSERT(0 != decoder->private_);
  87881. FLAC__ASSERT(0 != decoder->protected_);
  87882. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87883. return false;
  87884. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87885. decoder->private_->metadata_filter[i] = true;
  87886. decoder->private_->metadata_filter_ids_count = 0;
  87887. return true;
  87888. }
  87889. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87890. {
  87891. FLAC__ASSERT(0 != decoder);
  87892. FLAC__ASSERT(0 != decoder->private_);
  87893. FLAC__ASSERT(0 != decoder->protected_);
  87894. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87895. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87896. return false;
  87897. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87898. return false;
  87899. decoder->private_->metadata_filter[type] = false;
  87900. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87901. decoder->private_->metadata_filter_ids_count = 0;
  87902. return true;
  87903. }
  87904. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87905. {
  87906. FLAC__ASSERT(0 != decoder);
  87907. FLAC__ASSERT(0 != decoder->private_);
  87908. FLAC__ASSERT(0 != decoder->protected_);
  87909. FLAC__ASSERT(0 != id);
  87910. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87911. return false;
  87912. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87913. return true;
  87914. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87915. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87916. 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))) {
  87917. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87918. return false;
  87919. }
  87920. decoder->private_->metadata_filter_ids_capacity *= 2;
  87921. }
  87922. 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));
  87923. decoder->private_->metadata_filter_ids_count++;
  87924. return true;
  87925. }
  87926. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87927. {
  87928. FLAC__ASSERT(0 != decoder);
  87929. FLAC__ASSERT(0 != decoder->private_);
  87930. FLAC__ASSERT(0 != decoder->protected_);
  87931. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87932. return false;
  87933. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87934. decoder->private_->metadata_filter_ids_count = 0;
  87935. return true;
  87936. }
  87937. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87938. {
  87939. FLAC__ASSERT(0 != decoder);
  87940. FLAC__ASSERT(0 != decoder->protected_);
  87941. return decoder->protected_->state;
  87942. }
  87943. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87944. {
  87945. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87946. }
  87947. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87948. {
  87949. FLAC__ASSERT(0 != decoder);
  87950. FLAC__ASSERT(0 != decoder->protected_);
  87951. return decoder->protected_->md5_checking;
  87952. }
  87953. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87954. {
  87955. FLAC__ASSERT(0 != decoder);
  87956. FLAC__ASSERT(0 != decoder->protected_);
  87957. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87958. }
  87959. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87960. {
  87961. FLAC__ASSERT(0 != decoder);
  87962. FLAC__ASSERT(0 != decoder->protected_);
  87963. return decoder->protected_->channels;
  87964. }
  87965. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87966. {
  87967. FLAC__ASSERT(0 != decoder);
  87968. FLAC__ASSERT(0 != decoder->protected_);
  87969. return decoder->protected_->channel_assignment;
  87970. }
  87971. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87972. {
  87973. FLAC__ASSERT(0 != decoder);
  87974. FLAC__ASSERT(0 != decoder->protected_);
  87975. return decoder->protected_->bits_per_sample;
  87976. }
  87977. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87978. {
  87979. FLAC__ASSERT(0 != decoder);
  87980. FLAC__ASSERT(0 != decoder->protected_);
  87981. return decoder->protected_->sample_rate;
  87982. }
  87983. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87984. {
  87985. FLAC__ASSERT(0 != decoder);
  87986. FLAC__ASSERT(0 != decoder->protected_);
  87987. return decoder->protected_->blocksize;
  87988. }
  87989. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87990. {
  87991. FLAC__ASSERT(0 != decoder);
  87992. FLAC__ASSERT(0 != decoder->private_);
  87993. FLAC__ASSERT(0 != position);
  87994. #if FLAC__HAS_OGG
  87995. if(decoder->private_->is_ogg)
  87996. return false;
  87997. #endif
  87998. if(0 == decoder->private_->tell_callback)
  87999. return false;
  88000. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  88001. return false;
  88002. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  88003. return false;
  88004. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  88005. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  88006. return true;
  88007. }
  88008. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  88009. {
  88010. FLAC__ASSERT(0 != decoder);
  88011. FLAC__ASSERT(0 != decoder->private_);
  88012. FLAC__ASSERT(0 != decoder->protected_);
  88013. decoder->private_->samples_decoded = 0;
  88014. decoder->private_->do_md5_checking = false;
  88015. #if FLAC__HAS_OGG
  88016. if(decoder->private_->is_ogg)
  88017. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  88018. #endif
  88019. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  88020. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88021. return false;
  88022. }
  88023. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88024. return true;
  88025. }
  88026. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  88027. {
  88028. FLAC__ASSERT(0 != decoder);
  88029. FLAC__ASSERT(0 != decoder->private_);
  88030. FLAC__ASSERT(0 != decoder->protected_);
  88031. if(!FLAC__stream_decoder_flush(decoder)) {
  88032. return false;
  88033. }
  88034. #if FLAC__HAS_OGG
  88035. if(decoder->private_->is_ogg)
  88036. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  88037. #endif
  88038. if(!decoder->private_->internal_reset_hack) {
  88039. if(decoder->private_->file == stdin)
  88040. return false; /* can't rewind stdin, reset fails */
  88041. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  88042. return false; /* seekable and seek fails, reset fails */
  88043. }
  88044. else
  88045. decoder->private_->internal_reset_hack = false;
  88046. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  88047. decoder->private_->has_stream_info = false;
  88048. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  88049. free(decoder->private_->seek_table.data.seek_table.points);
  88050. decoder->private_->seek_table.data.seek_table.points = 0;
  88051. decoder->private_->has_seek_table = false;
  88052. }
  88053. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  88054. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  88055. FLAC__MD5Init(&decoder->private_->md5context);
  88056. decoder->private_->first_frame_offset = 0;
  88057. decoder->private_->unparseable_frame_count = 0;
  88058. return true;
  88059. }
  88060. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  88061. {
  88062. FLAC__bool got_a_frame;
  88063. FLAC__ASSERT(0 != decoder);
  88064. FLAC__ASSERT(0 != decoder->protected_);
  88065. while(1) {
  88066. switch(decoder->protected_->state) {
  88067. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88068. if(!find_metadata_(decoder))
  88069. return false; /* above function sets the status for us */
  88070. break;
  88071. case FLAC__STREAM_DECODER_READ_METADATA:
  88072. if(!read_metadata_(decoder))
  88073. return false; /* above function sets the status for us */
  88074. else
  88075. return true;
  88076. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88077. if(!frame_sync_(decoder))
  88078. return true; /* above function sets the status for us */
  88079. break;
  88080. case FLAC__STREAM_DECODER_READ_FRAME:
  88081. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  88082. return false; /* above function sets the status for us */
  88083. if(got_a_frame)
  88084. return true; /* above function sets the status for us */
  88085. break;
  88086. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88087. case FLAC__STREAM_DECODER_ABORTED:
  88088. return true;
  88089. default:
  88090. FLAC__ASSERT(0);
  88091. return false;
  88092. }
  88093. }
  88094. }
  88095. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  88096. {
  88097. FLAC__ASSERT(0 != decoder);
  88098. FLAC__ASSERT(0 != decoder->protected_);
  88099. while(1) {
  88100. switch(decoder->protected_->state) {
  88101. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88102. if(!find_metadata_(decoder))
  88103. return false; /* above function sets the status for us */
  88104. break;
  88105. case FLAC__STREAM_DECODER_READ_METADATA:
  88106. if(!read_metadata_(decoder))
  88107. return false; /* above function sets the status for us */
  88108. break;
  88109. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88110. case FLAC__STREAM_DECODER_READ_FRAME:
  88111. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88112. case FLAC__STREAM_DECODER_ABORTED:
  88113. return true;
  88114. default:
  88115. FLAC__ASSERT(0);
  88116. return false;
  88117. }
  88118. }
  88119. }
  88120. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88121. {
  88122. FLAC__bool dummy;
  88123. FLAC__ASSERT(0 != decoder);
  88124. FLAC__ASSERT(0 != decoder->protected_);
  88125. while(1) {
  88126. switch(decoder->protected_->state) {
  88127. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88128. if(!find_metadata_(decoder))
  88129. return false; /* above function sets the status for us */
  88130. break;
  88131. case FLAC__STREAM_DECODER_READ_METADATA:
  88132. if(!read_metadata_(decoder))
  88133. return false; /* above function sets the status for us */
  88134. break;
  88135. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88136. if(!frame_sync_(decoder))
  88137. return true; /* above function sets the status for us */
  88138. break;
  88139. case FLAC__STREAM_DECODER_READ_FRAME:
  88140. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88141. return false; /* above function sets the status for us */
  88142. break;
  88143. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88144. case FLAC__STREAM_DECODER_ABORTED:
  88145. return true;
  88146. default:
  88147. FLAC__ASSERT(0);
  88148. return false;
  88149. }
  88150. }
  88151. }
  88152. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  88153. {
  88154. FLAC__bool got_a_frame;
  88155. FLAC__ASSERT(0 != decoder);
  88156. FLAC__ASSERT(0 != decoder->protected_);
  88157. while(1) {
  88158. switch(decoder->protected_->state) {
  88159. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88160. case FLAC__STREAM_DECODER_READ_METADATA:
  88161. return false; /* above function sets the status for us */
  88162. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88163. if(!frame_sync_(decoder))
  88164. return true; /* above function sets the status for us */
  88165. break;
  88166. case FLAC__STREAM_DECODER_READ_FRAME:
  88167. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88168. return false; /* above function sets the status for us */
  88169. if(got_a_frame)
  88170. return true; /* above function sets the status for us */
  88171. break;
  88172. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88173. case FLAC__STREAM_DECODER_ABORTED:
  88174. return true;
  88175. default:
  88176. FLAC__ASSERT(0);
  88177. return false;
  88178. }
  88179. }
  88180. }
  88181. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88182. {
  88183. FLAC__uint64 length;
  88184. FLAC__ASSERT(0 != decoder);
  88185. if(
  88186. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88187. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88188. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88189. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88190. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88191. )
  88192. return false;
  88193. if(0 == decoder->private_->seek_callback)
  88194. return false;
  88195. FLAC__ASSERT(decoder->private_->seek_callback);
  88196. FLAC__ASSERT(decoder->private_->tell_callback);
  88197. FLAC__ASSERT(decoder->private_->length_callback);
  88198. FLAC__ASSERT(decoder->private_->eof_callback);
  88199. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88200. return false;
  88201. decoder->private_->is_seeking = true;
  88202. decoder->private_->do_md5_checking = false;
  88203. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88204. decoder->private_->is_seeking = false;
  88205. return false;
  88206. }
  88207. if(
  88208. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88209. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88210. ) {
  88211. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88212. decoder->private_->is_seeking = false;
  88213. return false;
  88214. }
  88215. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88216. decoder->private_->is_seeking = false;
  88217. return false;
  88218. }
  88219. }
  88220. {
  88221. const FLAC__bool ok =
  88222. #if FLAC__HAS_OGG
  88223. decoder->private_->is_ogg?
  88224. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88225. #endif
  88226. seek_to_absolute_sample_(decoder, length, sample)
  88227. ;
  88228. decoder->private_->is_seeking = false;
  88229. return ok;
  88230. }
  88231. }
  88232. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88233. {
  88234. FLAC__ASSERT(0 != decoder);
  88235. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88236. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88237. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88238. }
  88239. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88240. {
  88241. #if FLAC__HAS_OGG
  88242. decoder->private_->is_ogg = false;
  88243. #endif
  88244. decoder->private_->read_callback = 0;
  88245. decoder->private_->seek_callback = 0;
  88246. decoder->private_->tell_callback = 0;
  88247. decoder->private_->length_callback = 0;
  88248. decoder->private_->eof_callback = 0;
  88249. decoder->private_->write_callback = 0;
  88250. decoder->private_->metadata_callback = 0;
  88251. decoder->private_->error_callback = 0;
  88252. decoder->private_->client_data = 0;
  88253. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88254. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88255. decoder->private_->metadata_filter_ids_count = 0;
  88256. decoder->protected_->md5_checking = false;
  88257. #if FLAC__HAS_OGG
  88258. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88259. #endif
  88260. }
  88261. FILE *get_binary_stdin_(void)
  88262. {
  88263. #if defined _MSC_VER || defined __MINGW32__
  88264. _setmode(_fileno(stdin), _O_BINARY);
  88265. #elif defined __CYGWIN__
  88266. setmode(_fileno(stdin), _O_BINARY);
  88267. #elif defined __EMX__
  88268. setmode(fileno(stdin), O_BINARY);
  88269. #endif
  88270. return stdin;
  88271. }
  88272. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88273. {
  88274. unsigned i;
  88275. FLAC__int32 *tmp;
  88276. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88277. return true;
  88278. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88279. if(0 != decoder->private_->output[i]) {
  88280. free(decoder->private_->output[i]-4);
  88281. decoder->private_->output[i] = 0;
  88282. }
  88283. if(0 != decoder->private_->residual_unaligned[i]) {
  88284. free(decoder->private_->residual_unaligned[i]);
  88285. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88286. }
  88287. }
  88288. for(i = 0; i < channels; i++) {
  88289. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88290. if(tmp == 0) {
  88291. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88292. return false;
  88293. }
  88294. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88295. decoder->private_->output[i] = tmp + 4;
  88296. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88297. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88298. return false;
  88299. }
  88300. }
  88301. decoder->private_->output_capacity = size;
  88302. decoder->private_->output_channels = channels;
  88303. return true;
  88304. }
  88305. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88306. {
  88307. size_t i;
  88308. FLAC__ASSERT(0 != decoder);
  88309. FLAC__ASSERT(0 != decoder->private_);
  88310. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88311. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88312. return true;
  88313. return false;
  88314. }
  88315. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88316. {
  88317. FLAC__uint32 x;
  88318. unsigned i, id_;
  88319. FLAC__bool first = true;
  88320. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88321. for(i = id_ = 0; i < 4; ) {
  88322. if(decoder->private_->cached) {
  88323. x = (FLAC__uint32)decoder->private_->lookahead;
  88324. decoder->private_->cached = false;
  88325. }
  88326. else {
  88327. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88328. return false; /* read_callback_ sets the state for us */
  88329. }
  88330. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88331. first = true;
  88332. i++;
  88333. id_ = 0;
  88334. continue;
  88335. }
  88336. if(x == ID3V2_TAG_[id_]) {
  88337. id_++;
  88338. i = 0;
  88339. if(id_ == 3) {
  88340. if(!skip_id3v2_tag_(decoder))
  88341. return false; /* skip_id3v2_tag_ sets the state for us */
  88342. }
  88343. continue;
  88344. }
  88345. id_ = 0;
  88346. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88347. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88348. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88349. return false; /* read_callback_ sets the state for us */
  88350. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88351. decoder->private_->lookahead = (FLAC__byte)x;
  88352. decoder->private_->cached = true;
  88353. }
  88354. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88355. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88356. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88357. return true;
  88358. }
  88359. }
  88360. i = 0;
  88361. if(first) {
  88362. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88363. first = false;
  88364. }
  88365. }
  88366. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88367. return true;
  88368. }
  88369. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88370. {
  88371. FLAC__bool is_last;
  88372. FLAC__uint32 i, x, type, length;
  88373. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88374. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88375. return false; /* read_callback_ sets the state for us */
  88376. is_last = x? true : false;
  88377. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88378. return false; /* read_callback_ sets the state for us */
  88379. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88380. return false; /* read_callback_ sets the state for us */
  88381. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88382. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88383. return false;
  88384. decoder->private_->has_stream_info = true;
  88385. 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))
  88386. decoder->private_->do_md5_checking = false;
  88387. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88388. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88389. }
  88390. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88391. if(!read_metadata_seektable_(decoder, is_last, length))
  88392. return false;
  88393. decoder->private_->has_seek_table = true;
  88394. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88395. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88396. }
  88397. else {
  88398. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88399. unsigned real_length = length;
  88400. FLAC__StreamMetadata block;
  88401. block.is_last = is_last;
  88402. block.type = (FLAC__MetadataType)type;
  88403. block.length = length;
  88404. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88405. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88406. return false; /* read_callback_ sets the state for us */
  88407. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88408. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88409. return false;
  88410. }
  88411. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88412. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88413. skip_it = !skip_it;
  88414. }
  88415. if(skip_it) {
  88416. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88417. return false; /* read_callback_ sets the state for us */
  88418. }
  88419. else {
  88420. switch(type) {
  88421. case FLAC__METADATA_TYPE_PADDING:
  88422. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88423. return false; /* read_callback_ sets the state for us */
  88424. break;
  88425. case FLAC__METADATA_TYPE_APPLICATION:
  88426. if(real_length > 0) {
  88427. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88428. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88429. return false;
  88430. }
  88431. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88432. return false; /* read_callback_ sets the state for us */
  88433. }
  88434. else
  88435. block.data.application.data = 0;
  88436. break;
  88437. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88438. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88439. return false;
  88440. break;
  88441. case FLAC__METADATA_TYPE_CUESHEET:
  88442. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88443. return false;
  88444. break;
  88445. case FLAC__METADATA_TYPE_PICTURE:
  88446. if(!read_metadata_picture_(decoder, &block.data.picture))
  88447. return false;
  88448. break;
  88449. case FLAC__METADATA_TYPE_STREAMINFO:
  88450. case FLAC__METADATA_TYPE_SEEKTABLE:
  88451. FLAC__ASSERT(0);
  88452. break;
  88453. default:
  88454. if(real_length > 0) {
  88455. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88456. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88457. return false;
  88458. }
  88459. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88460. return false; /* read_callback_ sets the state for us */
  88461. }
  88462. else
  88463. block.data.unknown.data = 0;
  88464. break;
  88465. }
  88466. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88467. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88468. switch(type) {
  88469. case FLAC__METADATA_TYPE_PADDING:
  88470. break;
  88471. case FLAC__METADATA_TYPE_APPLICATION:
  88472. if(0 != block.data.application.data)
  88473. free(block.data.application.data);
  88474. break;
  88475. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88476. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88477. free(block.data.vorbis_comment.vendor_string.entry);
  88478. if(block.data.vorbis_comment.num_comments > 0)
  88479. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88480. if(0 != block.data.vorbis_comment.comments[i].entry)
  88481. free(block.data.vorbis_comment.comments[i].entry);
  88482. if(0 != block.data.vorbis_comment.comments)
  88483. free(block.data.vorbis_comment.comments);
  88484. break;
  88485. case FLAC__METADATA_TYPE_CUESHEET:
  88486. if(block.data.cue_sheet.num_tracks > 0)
  88487. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88488. if(0 != block.data.cue_sheet.tracks[i].indices)
  88489. free(block.data.cue_sheet.tracks[i].indices);
  88490. if(0 != block.data.cue_sheet.tracks)
  88491. free(block.data.cue_sheet.tracks);
  88492. break;
  88493. case FLAC__METADATA_TYPE_PICTURE:
  88494. if(0 != block.data.picture.mime_type)
  88495. free(block.data.picture.mime_type);
  88496. if(0 != block.data.picture.description)
  88497. free(block.data.picture.description);
  88498. if(0 != block.data.picture.data)
  88499. free(block.data.picture.data);
  88500. break;
  88501. case FLAC__METADATA_TYPE_STREAMINFO:
  88502. case FLAC__METADATA_TYPE_SEEKTABLE:
  88503. FLAC__ASSERT(0);
  88504. default:
  88505. if(0 != block.data.unknown.data)
  88506. free(block.data.unknown.data);
  88507. break;
  88508. }
  88509. }
  88510. }
  88511. if(is_last) {
  88512. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88513. decoder->private_->first_frame_offset = 0;
  88514. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88515. }
  88516. return true;
  88517. }
  88518. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88519. {
  88520. FLAC__uint32 x;
  88521. unsigned bits, used_bits = 0;
  88522. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88523. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88524. decoder->private_->stream_info.is_last = is_last;
  88525. decoder->private_->stream_info.length = length;
  88526. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88527. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88528. return false; /* read_callback_ sets the state for us */
  88529. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88530. used_bits += bits;
  88531. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88532. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88533. return false; /* read_callback_ sets the state for us */
  88534. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88535. used_bits += bits;
  88536. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88537. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88538. return false; /* read_callback_ sets the state for us */
  88539. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88540. used_bits += bits;
  88541. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88542. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88543. return false; /* read_callback_ sets the state for us */
  88544. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88545. used_bits += bits;
  88546. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88547. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88548. return false; /* read_callback_ sets the state for us */
  88549. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88550. used_bits += bits;
  88551. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88552. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88553. return false; /* read_callback_ sets the state for us */
  88554. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88555. used_bits += bits;
  88556. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88557. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88558. return false; /* read_callback_ sets the state for us */
  88559. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88560. used_bits += bits;
  88561. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88562. 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))
  88563. return false; /* read_callback_ sets the state for us */
  88564. used_bits += bits;
  88565. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88566. return false; /* read_callback_ sets the state for us */
  88567. used_bits += 16*8;
  88568. FLAC__ASSERT(used_bits % 8 == 0);
  88569. length -= (used_bits / 8);
  88570. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88571. return false; /* read_callback_ sets the state for us */
  88572. return true;
  88573. }
  88574. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88575. {
  88576. FLAC__uint32 i, x;
  88577. FLAC__uint64 xx;
  88578. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88579. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88580. decoder->private_->seek_table.is_last = is_last;
  88581. decoder->private_->seek_table.length = length;
  88582. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88583. 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)))) {
  88584. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88585. return false;
  88586. }
  88587. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88588. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88589. return false; /* read_callback_ sets the state for us */
  88590. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88591. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88592. return false; /* read_callback_ sets the state for us */
  88593. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88594. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88595. return false; /* read_callback_ sets the state for us */
  88596. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88597. }
  88598. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88599. if(length > 0) {
  88600. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88601. return false; /* read_callback_ sets the state for us */
  88602. }
  88603. return true;
  88604. }
  88605. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88606. {
  88607. FLAC__uint32 i;
  88608. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88609. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88610. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88611. return false; /* read_callback_ sets the state for us */
  88612. if(obj->vendor_string.length > 0) {
  88613. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88614. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88615. return false;
  88616. }
  88617. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88618. return false; /* read_callback_ sets the state for us */
  88619. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88620. }
  88621. else
  88622. obj->vendor_string.entry = 0;
  88623. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88624. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88625. return false; /* read_callback_ sets the state for us */
  88626. if(obj->num_comments > 0) {
  88627. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88628. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88629. return false;
  88630. }
  88631. for(i = 0; i < obj->num_comments; i++) {
  88632. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88633. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88634. return false; /* read_callback_ sets the state for us */
  88635. if(obj->comments[i].length > 0) {
  88636. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88637. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88638. return false;
  88639. }
  88640. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88641. return false; /* read_callback_ sets the state for us */
  88642. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88643. }
  88644. else
  88645. obj->comments[i].entry = 0;
  88646. }
  88647. }
  88648. else {
  88649. obj->comments = 0;
  88650. }
  88651. return true;
  88652. }
  88653. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88654. {
  88655. FLAC__uint32 i, j, x;
  88656. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88657. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88658. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88659. 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))
  88660. return false; /* read_callback_ sets the state for us */
  88661. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88662. return false; /* read_callback_ sets the state for us */
  88663. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88664. return false; /* read_callback_ sets the state for us */
  88665. obj->is_cd = x? true : false;
  88666. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88667. return false; /* read_callback_ sets the state for us */
  88668. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88669. return false; /* read_callback_ sets the state for us */
  88670. obj->num_tracks = x;
  88671. if(obj->num_tracks > 0) {
  88672. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88673. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88674. return false;
  88675. }
  88676. for(i = 0; i < obj->num_tracks; i++) {
  88677. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88678. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88679. return false; /* read_callback_ sets the state for us */
  88680. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88681. return false; /* read_callback_ sets the state for us */
  88682. track->number = (FLAC__byte)x;
  88683. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88684. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88685. return false; /* read_callback_ sets the state for us */
  88686. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88687. return false; /* read_callback_ sets the state for us */
  88688. track->type = x;
  88689. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88690. return false; /* read_callback_ sets the state for us */
  88691. track->pre_emphasis = x;
  88692. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88693. return false; /* read_callback_ sets the state for us */
  88694. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88695. return false; /* read_callback_ sets the state for us */
  88696. track->num_indices = (FLAC__byte)x;
  88697. if(track->num_indices > 0) {
  88698. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88699. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88700. return false;
  88701. }
  88702. for(j = 0; j < track->num_indices; j++) {
  88703. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88704. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88705. return false; /* read_callback_ sets the state for us */
  88706. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88707. return false; /* read_callback_ sets the state for us */
  88708. index->number = (FLAC__byte)x;
  88709. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88710. return false; /* read_callback_ sets the state for us */
  88711. }
  88712. }
  88713. }
  88714. }
  88715. return true;
  88716. }
  88717. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88718. {
  88719. FLAC__uint32 x;
  88720. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88721. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88722. return false; /* read_callback_ sets the state for us */
  88723. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88724. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88725. return false; /* read_callback_ sets the state for us */
  88726. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88727. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88728. return false;
  88729. }
  88730. if(x > 0) {
  88731. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88732. return false; /* read_callback_ sets the state for us */
  88733. }
  88734. obj->mime_type[x] = '\0';
  88735. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88736. return false; /* read_callback_ sets the state for us */
  88737. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88738. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88739. return false;
  88740. }
  88741. if(x > 0) {
  88742. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88743. return false; /* read_callback_ sets the state for us */
  88744. }
  88745. obj->description[x] = '\0';
  88746. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88747. return false; /* read_callback_ sets the state for us */
  88748. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88749. return false; /* read_callback_ sets the state for us */
  88750. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88751. return false; /* read_callback_ sets the state for us */
  88752. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88753. return false; /* read_callback_ sets the state for us */
  88754. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88755. return false; /* read_callback_ sets the state for us */
  88756. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88757. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88758. return false;
  88759. }
  88760. if(obj->data_length > 0) {
  88761. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88762. return false; /* read_callback_ sets the state for us */
  88763. }
  88764. return true;
  88765. }
  88766. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88767. {
  88768. FLAC__uint32 x;
  88769. unsigned i, skip;
  88770. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88771. return false; /* read_callback_ sets the state for us */
  88772. skip = 0;
  88773. for(i = 0; i < 4; i++) {
  88774. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88775. return false; /* read_callback_ sets the state for us */
  88776. skip <<= 7;
  88777. skip |= (x & 0x7f);
  88778. }
  88779. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88780. return false; /* read_callback_ sets the state for us */
  88781. return true;
  88782. }
  88783. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88784. {
  88785. FLAC__uint32 x;
  88786. FLAC__bool first = true;
  88787. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88788. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88789. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88790. return true;
  88791. }
  88792. }
  88793. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88794. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88795. return false; /* read_callback_ sets the state for us */
  88796. }
  88797. while(1) {
  88798. if(decoder->private_->cached) {
  88799. x = (FLAC__uint32)decoder->private_->lookahead;
  88800. decoder->private_->cached = false;
  88801. }
  88802. else {
  88803. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88804. return false; /* read_callback_ sets the state for us */
  88805. }
  88806. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88807. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88808. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88809. return false; /* read_callback_ sets the state for us */
  88810. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88811. decoder->private_->lookahead = (FLAC__byte)x;
  88812. decoder->private_->cached = true;
  88813. }
  88814. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88815. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88816. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88817. return true;
  88818. }
  88819. }
  88820. if(first) {
  88821. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88822. first = false;
  88823. }
  88824. }
  88825. return true;
  88826. }
  88827. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88828. {
  88829. unsigned channel;
  88830. unsigned i;
  88831. FLAC__int32 mid, side;
  88832. unsigned frame_crc; /* the one we calculate from the input stream */
  88833. FLAC__uint32 x;
  88834. *got_a_frame = false;
  88835. frame_crc = 0;
  88836. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88837. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88838. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88839. if(!read_frame_header_(decoder))
  88840. return false;
  88841. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88842. return true;
  88843. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88844. return false;
  88845. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88846. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88847. switch(decoder->private_->frame.header.channel_assignment) {
  88848. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88849. break;
  88850. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88851. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88852. if(channel == 1)
  88853. bps++;
  88854. break;
  88855. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88856. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88857. if(channel == 0)
  88858. bps++;
  88859. break;
  88860. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88861. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88862. if(channel == 1)
  88863. bps++;
  88864. break;
  88865. default:
  88866. FLAC__ASSERT(0);
  88867. }
  88868. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88869. return false;
  88870. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88871. return true;
  88872. }
  88873. if(!read_zero_padding_(decoder))
  88874. return false;
  88875. 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) */
  88876. return true;
  88877. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88878. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88879. return false; /* read_callback_ sets the state for us */
  88880. if(frame_crc == x) {
  88881. if(do_full_decode) {
  88882. switch(decoder->private_->frame.header.channel_assignment) {
  88883. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88884. break;
  88885. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88886. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88887. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88888. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88889. break;
  88890. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88891. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88892. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88893. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88894. break;
  88895. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88896. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88897. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88898. #if 1
  88899. mid = decoder->private_->output[0][i];
  88900. side = decoder->private_->output[1][i];
  88901. mid <<= 1;
  88902. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88903. decoder->private_->output[0][i] = (mid + side) >> 1;
  88904. decoder->private_->output[1][i] = (mid - side) >> 1;
  88905. #else
  88906. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88907. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88908. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88909. #endif
  88910. }
  88911. break;
  88912. default:
  88913. FLAC__ASSERT(0);
  88914. break;
  88915. }
  88916. }
  88917. }
  88918. else {
  88919. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88920. if(do_full_decode) {
  88921. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88922. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88923. }
  88924. }
  88925. }
  88926. *got_a_frame = true;
  88927. if(decoder->private_->next_fixed_block_size)
  88928. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88929. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88930. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88931. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88932. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88933. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88934. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88935. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88936. if(do_full_decode) {
  88937. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88938. return false;
  88939. }
  88940. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88941. return true;
  88942. }
  88943. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88944. {
  88945. FLAC__uint32 x;
  88946. FLAC__uint64 xx;
  88947. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88948. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88949. unsigned raw_header_len;
  88950. FLAC__bool is_unparseable = false;
  88951. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88952. raw_header[0] = decoder->private_->header_warmup[0];
  88953. raw_header[1] = decoder->private_->header_warmup[1];
  88954. raw_header_len = 2;
  88955. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88956. is_unparseable = true;
  88957. for(i = 0; i < 2; i++) {
  88958. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88959. return false; /* read_callback_ sets the state for us */
  88960. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88961. decoder->private_->lookahead = (FLAC__byte)x;
  88962. decoder->private_->cached = true;
  88963. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88964. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88965. return true;
  88966. }
  88967. raw_header[raw_header_len++] = (FLAC__byte)x;
  88968. }
  88969. switch(x = raw_header[2] >> 4) {
  88970. case 0:
  88971. is_unparseable = true;
  88972. break;
  88973. case 1:
  88974. decoder->private_->frame.header.blocksize = 192;
  88975. break;
  88976. case 2:
  88977. case 3:
  88978. case 4:
  88979. case 5:
  88980. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88981. break;
  88982. case 6:
  88983. case 7:
  88984. blocksize_hint = x;
  88985. break;
  88986. case 8:
  88987. case 9:
  88988. case 10:
  88989. case 11:
  88990. case 12:
  88991. case 13:
  88992. case 14:
  88993. case 15:
  88994. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88995. break;
  88996. default:
  88997. FLAC__ASSERT(0);
  88998. break;
  88999. }
  89000. switch(x = raw_header[2] & 0x0f) {
  89001. case 0:
  89002. if(decoder->private_->has_stream_info)
  89003. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  89004. else
  89005. is_unparseable = true;
  89006. break;
  89007. case 1:
  89008. decoder->private_->frame.header.sample_rate = 88200;
  89009. break;
  89010. case 2:
  89011. decoder->private_->frame.header.sample_rate = 176400;
  89012. break;
  89013. case 3:
  89014. decoder->private_->frame.header.sample_rate = 192000;
  89015. break;
  89016. case 4:
  89017. decoder->private_->frame.header.sample_rate = 8000;
  89018. break;
  89019. case 5:
  89020. decoder->private_->frame.header.sample_rate = 16000;
  89021. break;
  89022. case 6:
  89023. decoder->private_->frame.header.sample_rate = 22050;
  89024. break;
  89025. case 7:
  89026. decoder->private_->frame.header.sample_rate = 24000;
  89027. break;
  89028. case 8:
  89029. decoder->private_->frame.header.sample_rate = 32000;
  89030. break;
  89031. case 9:
  89032. decoder->private_->frame.header.sample_rate = 44100;
  89033. break;
  89034. case 10:
  89035. decoder->private_->frame.header.sample_rate = 48000;
  89036. break;
  89037. case 11:
  89038. decoder->private_->frame.header.sample_rate = 96000;
  89039. break;
  89040. case 12:
  89041. case 13:
  89042. case 14:
  89043. sample_rate_hint = x;
  89044. break;
  89045. case 15:
  89046. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89047. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89048. return true;
  89049. default:
  89050. FLAC__ASSERT(0);
  89051. }
  89052. x = (unsigned)(raw_header[3] >> 4);
  89053. if(x & 8) {
  89054. decoder->private_->frame.header.channels = 2;
  89055. switch(x & 7) {
  89056. case 0:
  89057. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  89058. break;
  89059. case 1:
  89060. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  89061. break;
  89062. case 2:
  89063. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  89064. break;
  89065. default:
  89066. is_unparseable = true;
  89067. break;
  89068. }
  89069. }
  89070. else {
  89071. decoder->private_->frame.header.channels = (unsigned)x + 1;
  89072. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  89073. }
  89074. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  89075. case 0:
  89076. if(decoder->private_->has_stream_info)
  89077. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89078. else
  89079. is_unparseable = true;
  89080. break;
  89081. case 1:
  89082. decoder->private_->frame.header.bits_per_sample = 8;
  89083. break;
  89084. case 2:
  89085. decoder->private_->frame.header.bits_per_sample = 12;
  89086. break;
  89087. case 4:
  89088. decoder->private_->frame.header.bits_per_sample = 16;
  89089. break;
  89090. case 5:
  89091. decoder->private_->frame.header.bits_per_sample = 20;
  89092. break;
  89093. case 6:
  89094. decoder->private_->frame.header.bits_per_sample = 24;
  89095. break;
  89096. case 3:
  89097. case 7:
  89098. is_unparseable = true;
  89099. break;
  89100. default:
  89101. FLAC__ASSERT(0);
  89102. break;
  89103. }
  89104. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89105. is_unparseable = true;
  89106. if(
  89107. raw_header[1] & 0x01 ||
  89108. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89109. ) { /* variable blocksize */
  89110. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89111. return false; /* read_callback_ sets the state for us */
  89112. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89113. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89114. decoder->private_->cached = true;
  89115. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89116. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89117. return true;
  89118. }
  89119. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89120. decoder->private_->frame.header.number.sample_number = xx;
  89121. }
  89122. else { /* fixed blocksize */
  89123. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89124. return false; /* read_callback_ sets the state for us */
  89125. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89126. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89127. decoder->private_->cached = true;
  89128. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89129. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89130. return true;
  89131. }
  89132. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89133. decoder->private_->frame.header.number.frame_number = x;
  89134. }
  89135. if(blocksize_hint) {
  89136. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89137. return false; /* read_callback_ sets the state for us */
  89138. raw_header[raw_header_len++] = (FLAC__byte)x;
  89139. if(blocksize_hint == 7) {
  89140. FLAC__uint32 _x;
  89141. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89142. return false; /* read_callback_ sets the state for us */
  89143. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89144. x = (x << 8) | _x;
  89145. }
  89146. decoder->private_->frame.header.blocksize = x+1;
  89147. }
  89148. if(sample_rate_hint) {
  89149. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89150. return false; /* read_callback_ sets the state for us */
  89151. raw_header[raw_header_len++] = (FLAC__byte)x;
  89152. if(sample_rate_hint != 12) {
  89153. FLAC__uint32 _x;
  89154. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89155. return false; /* read_callback_ sets the state for us */
  89156. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89157. x = (x << 8) | _x;
  89158. }
  89159. if(sample_rate_hint == 12)
  89160. decoder->private_->frame.header.sample_rate = x*1000;
  89161. else if(sample_rate_hint == 13)
  89162. decoder->private_->frame.header.sample_rate = x;
  89163. else
  89164. decoder->private_->frame.header.sample_rate = x*10;
  89165. }
  89166. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89167. return false; /* read_callback_ sets the state for us */
  89168. crc8 = (FLAC__byte)x;
  89169. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89170. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89171. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89172. return true;
  89173. }
  89174. decoder->private_->next_fixed_block_size = 0;
  89175. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89176. x = decoder->private_->frame.header.number.frame_number;
  89177. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89178. if(decoder->private_->fixed_block_size)
  89179. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89180. else if(decoder->private_->has_stream_info) {
  89181. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89182. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89183. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89184. }
  89185. else
  89186. is_unparseable = true;
  89187. }
  89188. else if(x == 0) {
  89189. decoder->private_->frame.header.number.sample_number = 0;
  89190. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89191. }
  89192. else {
  89193. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89194. }
  89195. }
  89196. if(is_unparseable) {
  89197. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89198. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89199. return true;
  89200. }
  89201. return true;
  89202. }
  89203. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89204. {
  89205. FLAC__uint32 x;
  89206. FLAC__bool wasted_bits;
  89207. unsigned i;
  89208. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89209. return false; /* read_callback_ sets the state for us */
  89210. wasted_bits = (x & 1);
  89211. x &= 0xfe;
  89212. if(wasted_bits) {
  89213. unsigned u;
  89214. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89215. return false; /* read_callback_ sets the state for us */
  89216. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89217. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89218. }
  89219. else
  89220. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89221. if(x & 0x80) {
  89222. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89223. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89224. return true;
  89225. }
  89226. else if(x == 0) {
  89227. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89228. return false;
  89229. }
  89230. else if(x == 2) {
  89231. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89232. return false;
  89233. }
  89234. else if(x < 16) {
  89235. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89236. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89237. return true;
  89238. }
  89239. else if(x <= 24) {
  89240. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89241. return false;
  89242. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89243. return true;
  89244. }
  89245. else if(x < 64) {
  89246. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89247. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89248. return true;
  89249. }
  89250. else {
  89251. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89252. return false;
  89253. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89254. return true;
  89255. }
  89256. if(wasted_bits && do_full_decode) {
  89257. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89258. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89259. decoder->private_->output[channel][i] <<= x;
  89260. }
  89261. return true;
  89262. }
  89263. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89264. {
  89265. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89266. FLAC__int32 x;
  89267. unsigned i;
  89268. FLAC__int32 *output = decoder->private_->output[channel];
  89269. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89270. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89271. return false; /* read_callback_ sets the state for us */
  89272. subframe->value = x;
  89273. if(do_full_decode) {
  89274. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89275. output[i] = x;
  89276. }
  89277. return true;
  89278. }
  89279. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89280. {
  89281. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89282. FLAC__int32 i32;
  89283. FLAC__uint32 u32;
  89284. unsigned u;
  89285. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89286. subframe->residual = decoder->private_->residual[channel];
  89287. subframe->order = order;
  89288. for(u = 0; u < order; u++) {
  89289. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89290. return false; /* read_callback_ sets the state for us */
  89291. subframe->warmup[u] = i32;
  89292. }
  89293. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89294. return false; /* read_callback_ sets the state for us */
  89295. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89296. switch(subframe->entropy_coding_method.type) {
  89297. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89298. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89299. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89300. return false; /* read_callback_ sets the state for us */
  89301. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89302. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89303. break;
  89304. default:
  89305. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89306. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89307. return true;
  89308. }
  89309. switch(subframe->entropy_coding_method.type) {
  89310. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89311. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89312. 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))
  89313. return false;
  89314. break;
  89315. default:
  89316. FLAC__ASSERT(0);
  89317. }
  89318. if(do_full_decode) {
  89319. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89320. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89321. }
  89322. return true;
  89323. }
  89324. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89325. {
  89326. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89327. FLAC__int32 i32;
  89328. FLAC__uint32 u32;
  89329. unsigned u;
  89330. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89331. subframe->residual = decoder->private_->residual[channel];
  89332. subframe->order = order;
  89333. for(u = 0; u < order; u++) {
  89334. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89335. return false; /* read_callback_ sets the state for us */
  89336. subframe->warmup[u] = i32;
  89337. }
  89338. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89339. return false; /* read_callback_ sets the state for us */
  89340. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89341. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89342. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89343. return true;
  89344. }
  89345. subframe->qlp_coeff_precision = u32+1;
  89346. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89347. return false; /* read_callback_ sets the state for us */
  89348. subframe->quantization_level = i32;
  89349. for(u = 0; u < order; u++) {
  89350. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89351. return false; /* read_callback_ sets the state for us */
  89352. subframe->qlp_coeff[u] = i32;
  89353. }
  89354. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89355. return false; /* read_callback_ sets the state for us */
  89356. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89357. switch(subframe->entropy_coding_method.type) {
  89358. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89359. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89360. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89361. return false; /* read_callback_ sets the state for us */
  89362. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89363. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89364. break;
  89365. default:
  89366. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89367. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89368. return true;
  89369. }
  89370. switch(subframe->entropy_coding_method.type) {
  89371. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89372. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89373. 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))
  89374. return false;
  89375. break;
  89376. default:
  89377. FLAC__ASSERT(0);
  89378. }
  89379. if(do_full_decode) {
  89380. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89381. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89382. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89383. if(order <= 8)
  89384. 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);
  89385. else
  89386. 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);
  89387. }
  89388. else
  89389. 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);
  89390. else
  89391. 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);
  89392. }
  89393. return true;
  89394. }
  89395. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89396. {
  89397. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89398. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89399. unsigned i;
  89400. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89401. subframe->data = residual;
  89402. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89403. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89404. return false; /* read_callback_ sets the state for us */
  89405. residual[i] = x;
  89406. }
  89407. if(do_full_decode)
  89408. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89409. return true;
  89410. }
  89411. 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)
  89412. {
  89413. FLAC__uint32 rice_parameter;
  89414. int i;
  89415. unsigned partition, sample, u;
  89416. const unsigned partitions = 1u << partition_order;
  89417. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89418. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89419. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89420. if(partition_order == 0) {
  89421. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89422. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89423. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89424. return true;
  89425. }
  89426. }
  89427. else {
  89428. if(partition_samples < predictor_order) {
  89429. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89430. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89431. return true;
  89432. }
  89433. }
  89434. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89435. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89436. return false;
  89437. }
  89438. sample = 0;
  89439. for(partition = 0; partition < partitions; partition++) {
  89440. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89441. return false; /* read_callback_ sets the state for us */
  89442. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89443. if(rice_parameter < pesc) {
  89444. partitioned_rice_contents->raw_bits[partition] = 0;
  89445. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89446. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89447. return false; /* read_callback_ sets the state for us */
  89448. sample += u;
  89449. }
  89450. else {
  89451. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89452. return false; /* read_callback_ sets the state for us */
  89453. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89454. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89455. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89456. return false; /* read_callback_ sets the state for us */
  89457. residual[sample] = i;
  89458. }
  89459. }
  89460. }
  89461. return true;
  89462. }
  89463. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89464. {
  89465. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89466. FLAC__uint32 zero = 0;
  89467. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89468. return false; /* read_callback_ sets the state for us */
  89469. if(zero != 0) {
  89470. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89471. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89472. }
  89473. }
  89474. return true;
  89475. }
  89476. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89477. {
  89478. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89479. if(
  89480. #if FLAC__HAS_OGG
  89481. !decoder->private_->is_ogg &&
  89482. #endif
  89483. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89484. ) {
  89485. *bytes = 0;
  89486. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89487. return false;
  89488. }
  89489. else if(*bytes > 0) {
  89490. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89491. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89492. return false;
  89493. }
  89494. else {
  89495. const FLAC__StreamDecoderReadStatus status =
  89496. #if FLAC__HAS_OGG
  89497. decoder->private_->is_ogg?
  89498. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89499. #endif
  89500. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89501. ;
  89502. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89503. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89504. return false;
  89505. }
  89506. else if(*bytes == 0) {
  89507. if(
  89508. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89509. (
  89510. #if FLAC__HAS_OGG
  89511. !decoder->private_->is_ogg &&
  89512. #endif
  89513. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89514. )
  89515. ) {
  89516. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89517. return false;
  89518. }
  89519. else
  89520. return true;
  89521. }
  89522. else
  89523. return true;
  89524. }
  89525. }
  89526. else {
  89527. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89528. return false;
  89529. }
  89530. }
  89531. #if FLAC__HAS_OGG
  89532. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89533. {
  89534. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89535. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89536. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89537. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89538. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89539. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89540. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89541. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89542. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89543. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89544. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89545. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89546. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89547. default:
  89548. FLAC__ASSERT(0);
  89549. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89550. }
  89551. }
  89552. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89553. {
  89554. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89555. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89556. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89557. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89558. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89559. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89560. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89561. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89562. default:
  89563. FLAC__ASSERT(0);
  89564. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89565. }
  89566. }
  89567. #endif
  89568. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89569. {
  89570. if(decoder->private_->is_seeking) {
  89571. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89572. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89573. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89574. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89575. #if FLAC__HAS_OGG
  89576. decoder->private_->got_a_frame = true;
  89577. #endif
  89578. decoder->private_->last_frame = *frame; /* save the frame */
  89579. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89580. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89581. decoder->private_->is_seeking = false;
  89582. if(delta > 0) {
  89583. unsigned channel;
  89584. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89585. for(channel = 0; channel < frame->header.channels; channel++)
  89586. newbuffer[channel] = buffer[channel] + delta;
  89587. decoder->private_->last_frame.header.blocksize -= delta;
  89588. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89589. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89590. }
  89591. else {
  89592. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89593. }
  89594. }
  89595. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89596. }
  89597. if(!decoder->private_->has_stream_info)
  89598. decoder->private_->do_md5_checking = false;
  89599. if(decoder->private_->do_md5_checking) {
  89600. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89601. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89602. }
  89603. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89604. }
  89605. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89606. {
  89607. if(!decoder->private_->is_seeking)
  89608. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89609. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89610. decoder->private_->unparseable_frame_count++;
  89611. }
  89612. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89613. {
  89614. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89615. FLAC__int64 pos = -1;
  89616. int i;
  89617. unsigned approx_bytes_per_frame;
  89618. FLAC__bool first_seek = true;
  89619. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89620. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89621. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89622. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89623. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89624. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89625. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89626. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89627. if(channels == 0)
  89628. channels = decoder->private_->stream_info.data.stream_info.channels;
  89629. if(bps == 0)
  89630. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89631. if(max_framesize > 0)
  89632. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89633. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89634. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89635. }
  89636. else
  89637. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89638. lower_bound = first_frame_offset;
  89639. lower_bound_sample = 0;
  89640. upper_bound = stream_length;
  89641. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89642. if(seek_table) {
  89643. FLAC__uint64 new_lower_bound = lower_bound;
  89644. FLAC__uint64 new_upper_bound = upper_bound;
  89645. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89646. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89647. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89648. if(
  89649. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89650. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89651. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89652. seek_table->points[i].sample_number <= target_sample
  89653. )
  89654. break;
  89655. }
  89656. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89657. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89658. new_lower_bound_sample = seek_table->points[i].sample_number;
  89659. }
  89660. for(i = 0; i < (int)seek_table->num_points; i++) {
  89661. if(
  89662. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89663. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89664. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89665. seek_table->points[i].sample_number > target_sample
  89666. )
  89667. break;
  89668. }
  89669. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89670. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89671. new_upper_bound_sample = seek_table->points[i].sample_number;
  89672. }
  89673. if(new_upper_bound >= new_lower_bound) {
  89674. lower_bound = new_lower_bound;
  89675. upper_bound = new_upper_bound;
  89676. lower_bound_sample = new_lower_bound_sample;
  89677. upper_bound_sample = new_upper_bound_sample;
  89678. }
  89679. }
  89680. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89681. if(upper_bound_sample == lower_bound_sample)
  89682. upper_bound_sample++;
  89683. decoder->private_->target_sample = target_sample;
  89684. while(1) {
  89685. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89686. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89687. return false;
  89688. }
  89689. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89690. #if defined _MSC_VER || defined __MINGW32__
  89691. 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;
  89692. #else
  89693. 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;
  89694. #endif
  89695. #else
  89696. if(upper_bound - lower_bound < 0xffffffff)
  89697. 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;
  89698. else /* @@@ WATCHOUT, ~2TB limit */
  89699. 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;
  89700. #endif
  89701. if(pos >= (FLAC__int64)upper_bound)
  89702. pos = (FLAC__int64)upper_bound - 1;
  89703. if(pos < (FLAC__int64)lower_bound)
  89704. pos = (FLAC__int64)lower_bound;
  89705. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89706. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89707. return false;
  89708. }
  89709. if(!FLAC__stream_decoder_flush(decoder)) {
  89710. return false;
  89711. }
  89712. decoder->private_->unparseable_frame_count = 0;
  89713. if(!FLAC__stream_decoder_process_single(decoder)) {
  89714. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89715. return false;
  89716. }
  89717. #if 0
  89718. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89719. break;
  89720. #endif
  89721. if(!decoder->private_->is_seeking)
  89722. break;
  89723. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89724. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89725. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89726. if (pos == (FLAC__int64)lower_bound) {
  89727. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89728. return false;
  89729. }
  89730. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89731. continue;
  89732. }
  89733. first_seek = false;
  89734. if (this_frame_sample < lower_bound_sample) {
  89735. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89736. return false;
  89737. }
  89738. if(target_sample < this_frame_sample) {
  89739. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89740. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89741. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89742. return false;
  89743. }
  89744. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89745. }
  89746. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89747. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89748. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89749. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89750. return false;
  89751. }
  89752. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89753. }
  89754. }
  89755. return true;
  89756. }
  89757. #if FLAC__HAS_OGG
  89758. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89759. {
  89760. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89761. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89762. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89763. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89764. FLAC__bool did_a_seek;
  89765. unsigned iteration = 0;
  89766. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89767. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89768. if(right_sample == 0) {
  89769. right_sample = (FLAC__uint64)(-1);
  89770. BINARY_SEARCH_AFTER_ITERATION = 0;
  89771. }
  89772. decoder->private_->target_sample = target_sample;
  89773. for( ; ; iteration++) {
  89774. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89775. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89776. pos = (right_pos + left_pos) / 2;
  89777. }
  89778. else {
  89779. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89780. #if defined _MSC_VER || defined __MINGW32__
  89781. 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));
  89782. #else
  89783. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89784. #endif
  89785. #else
  89786. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89787. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89788. else /* @@@ WATCHOUT, ~2TB limit */
  89789. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89790. #endif
  89791. }
  89792. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89793. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89794. return false;
  89795. }
  89796. if(!FLAC__stream_decoder_flush(decoder)) {
  89797. return false;
  89798. }
  89799. did_a_seek = true;
  89800. }
  89801. else
  89802. did_a_seek = false;
  89803. decoder->private_->got_a_frame = false;
  89804. if(!FLAC__stream_decoder_process_single(decoder)) {
  89805. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89806. return false;
  89807. }
  89808. if(!decoder->private_->got_a_frame) {
  89809. if(did_a_seek) {
  89810. right_pos = pos;
  89811. BINARY_SEARCH_AFTER_ITERATION = 0;
  89812. }
  89813. else {
  89814. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89815. return false;
  89816. }
  89817. }
  89818. else if(!decoder->private_->is_seeking) {
  89819. break;
  89820. }
  89821. else {
  89822. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89823. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89824. if (did_a_seek) {
  89825. if (this_frame_sample <= target_sample) {
  89826. FLAC__ASSERT(this_frame_sample != target_sample);
  89827. left_sample = this_frame_sample;
  89828. if (left_pos == pos) {
  89829. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89830. return false;
  89831. }
  89832. left_pos = pos;
  89833. }
  89834. else if(this_frame_sample > target_sample) {
  89835. right_sample = this_frame_sample;
  89836. if (right_pos == pos) {
  89837. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89838. return false;
  89839. }
  89840. right_pos = pos;
  89841. }
  89842. }
  89843. }
  89844. }
  89845. return true;
  89846. }
  89847. #endif
  89848. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89849. {
  89850. (void)client_data;
  89851. if(*bytes > 0) {
  89852. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89853. if(ferror(decoder->private_->file))
  89854. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89855. else if(*bytes == 0)
  89856. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89857. else
  89858. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89859. }
  89860. else
  89861. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89862. }
  89863. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89864. {
  89865. (void)client_data;
  89866. if(decoder->private_->file == stdin)
  89867. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89868. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89869. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89870. else
  89871. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89872. }
  89873. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89874. {
  89875. off_t pos;
  89876. (void)client_data;
  89877. if(decoder->private_->file == stdin)
  89878. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89879. else if((pos = ftello(decoder->private_->file)) < 0)
  89880. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89881. else {
  89882. *absolute_byte_offset = (FLAC__uint64)pos;
  89883. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89884. }
  89885. }
  89886. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89887. {
  89888. struct stat filestats;
  89889. (void)client_data;
  89890. if(decoder->private_->file == stdin)
  89891. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89892. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89893. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89894. else {
  89895. *stream_length = (FLAC__uint64)filestats.st_size;
  89896. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89897. }
  89898. }
  89899. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89900. {
  89901. (void)client_data;
  89902. return feof(decoder->private_->file)? true : false;
  89903. }
  89904. #endif
  89905. /*** End of inlined file: stream_decoder.c ***/
  89906. /*** Start of inlined file: stream_encoder.c ***/
  89907. /*** Start of inlined file: juce_FlacHeader.h ***/
  89908. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89909. // tasks..
  89910. #define VERSION "1.2.1"
  89911. #define FLAC__NO_DLL 1
  89912. #if JUCE_MSVC
  89913. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89914. #endif
  89915. #if JUCE_MAC
  89916. #define FLAC__SYS_DARWIN 1
  89917. #endif
  89918. /*** End of inlined file: juce_FlacHeader.h ***/
  89919. #if JUCE_USE_FLAC
  89920. #if HAVE_CONFIG_H
  89921. # include <config.h>
  89922. #endif
  89923. #if defined _MSC_VER || defined __MINGW32__
  89924. #include <io.h> /* for _setmode() */
  89925. #include <fcntl.h> /* for _O_BINARY */
  89926. #endif
  89927. #if defined __CYGWIN__ || defined __EMX__
  89928. #include <io.h> /* for setmode(), O_BINARY */
  89929. #include <fcntl.h> /* for _O_BINARY */
  89930. #endif
  89931. #include <limits.h>
  89932. #include <stdio.h>
  89933. #include <stdlib.h> /* for malloc() */
  89934. #include <string.h> /* for memcpy() */
  89935. #include <sys/types.h> /* for off_t */
  89936. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89937. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89938. #define fseeko fseek
  89939. #define ftello ftell
  89940. #endif
  89941. #endif
  89942. /*** Start of inlined file: stream_encoder.h ***/
  89943. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89944. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89945. #if FLAC__HAS_OGG
  89946. #include "private/ogg_encoder_aspect.h"
  89947. #endif
  89948. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89949. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89950. typedef enum {
  89951. FLAC__APODIZATION_BARTLETT,
  89952. FLAC__APODIZATION_BARTLETT_HANN,
  89953. FLAC__APODIZATION_BLACKMAN,
  89954. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89955. FLAC__APODIZATION_CONNES,
  89956. FLAC__APODIZATION_FLATTOP,
  89957. FLAC__APODIZATION_GAUSS,
  89958. FLAC__APODIZATION_HAMMING,
  89959. FLAC__APODIZATION_HANN,
  89960. FLAC__APODIZATION_KAISER_BESSEL,
  89961. FLAC__APODIZATION_NUTTALL,
  89962. FLAC__APODIZATION_RECTANGLE,
  89963. FLAC__APODIZATION_TRIANGLE,
  89964. FLAC__APODIZATION_TUKEY,
  89965. FLAC__APODIZATION_WELCH
  89966. } FLAC__ApodizationFunction;
  89967. typedef struct {
  89968. FLAC__ApodizationFunction type;
  89969. union {
  89970. struct {
  89971. FLAC__real stddev;
  89972. } gauss;
  89973. struct {
  89974. FLAC__real p;
  89975. } tukey;
  89976. } parameters;
  89977. } FLAC__ApodizationSpecification;
  89978. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89979. typedef struct FLAC__StreamEncoderProtected {
  89980. FLAC__StreamEncoderState state;
  89981. FLAC__bool verify;
  89982. FLAC__bool streamable_subset;
  89983. FLAC__bool do_md5;
  89984. FLAC__bool do_mid_side_stereo;
  89985. FLAC__bool loose_mid_side_stereo;
  89986. unsigned channels;
  89987. unsigned bits_per_sample;
  89988. unsigned sample_rate;
  89989. unsigned blocksize;
  89990. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89991. unsigned num_apodizations;
  89992. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89993. #endif
  89994. unsigned max_lpc_order;
  89995. unsigned qlp_coeff_precision;
  89996. FLAC__bool do_qlp_coeff_prec_search;
  89997. FLAC__bool do_exhaustive_model_search;
  89998. FLAC__bool do_escape_coding;
  89999. unsigned min_residual_partition_order;
  90000. unsigned max_residual_partition_order;
  90001. unsigned rice_parameter_search_dist;
  90002. FLAC__uint64 total_samples_estimate;
  90003. FLAC__StreamMetadata **metadata;
  90004. unsigned num_metadata_blocks;
  90005. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  90006. #if FLAC__HAS_OGG
  90007. FLAC__OggEncoderAspect ogg_encoder_aspect;
  90008. #endif
  90009. } FLAC__StreamEncoderProtected;
  90010. #endif
  90011. /*** End of inlined file: stream_encoder.h ***/
  90012. #if FLAC__HAS_OGG
  90013. #include "include/private/ogg_helper.h"
  90014. #include "include/private/ogg_mapping.h"
  90015. #endif
  90016. /*** Start of inlined file: stream_encoder_framing.h ***/
  90017. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90018. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90019. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  90020. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  90021. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90022. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90023. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90024. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90025. #endif
  90026. /*** End of inlined file: stream_encoder_framing.h ***/
  90027. /*** Start of inlined file: window.h ***/
  90028. #ifndef FLAC__PRIVATE__WINDOW_H
  90029. #define FLAC__PRIVATE__WINDOW_H
  90030. #ifdef HAVE_CONFIG_H
  90031. #include <config.h>
  90032. #endif
  90033. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90034. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  90035. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  90036. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  90037. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  90038. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  90039. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  90040. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  90041. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  90042. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  90043. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  90044. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  90045. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  90046. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  90047. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  90048. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  90049. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  90050. #endif
  90051. /*** End of inlined file: window.h ***/
  90052. #ifndef FLaC__INLINE
  90053. #define FLaC__INLINE
  90054. #endif
  90055. #ifdef min
  90056. #undef min
  90057. #endif
  90058. #define min(x,y) ((x)<(y)?(x):(y))
  90059. #ifdef max
  90060. #undef max
  90061. #endif
  90062. #define max(x,y) ((x)>(y)?(x):(y))
  90063. #undef EXACT_RICE_BITS_CALCULATION
  90064. #undef ENABLE_RICE_PARAMETER_SEARCH
  90065. typedef struct {
  90066. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  90067. unsigned size; /* of each data[] in samples */
  90068. unsigned tail;
  90069. } verify_input_fifo;
  90070. typedef struct {
  90071. const FLAC__byte *data;
  90072. unsigned capacity;
  90073. unsigned bytes;
  90074. } verify_output;
  90075. typedef enum {
  90076. ENCODER_IN_MAGIC = 0,
  90077. ENCODER_IN_METADATA = 1,
  90078. ENCODER_IN_AUDIO = 2
  90079. } EncoderStateHint;
  90080. static struct CompressionLevels {
  90081. FLAC__bool do_mid_side_stereo;
  90082. FLAC__bool loose_mid_side_stereo;
  90083. unsigned max_lpc_order;
  90084. unsigned qlp_coeff_precision;
  90085. FLAC__bool do_qlp_coeff_prec_search;
  90086. FLAC__bool do_escape_coding;
  90087. FLAC__bool do_exhaustive_model_search;
  90088. unsigned min_residual_partition_order;
  90089. unsigned max_residual_partition_order;
  90090. unsigned rice_parameter_search_dist;
  90091. } compression_levels_[] = {
  90092. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  90093. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  90094. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  90095. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  90096. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90097. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90098. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90099. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90100. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90101. };
  90102. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90103. static void free_(FLAC__StreamEncoder *encoder);
  90104. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90105. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90106. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90107. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90108. #if FLAC__HAS_OGG
  90109. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90110. #endif
  90111. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90112. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90113. static FLAC__bool process_subframe_(
  90114. FLAC__StreamEncoder *encoder,
  90115. unsigned min_partition_order,
  90116. unsigned max_partition_order,
  90117. const FLAC__FrameHeader *frame_header,
  90118. unsigned subframe_bps,
  90119. const FLAC__int32 integer_signal[],
  90120. FLAC__Subframe *subframe[2],
  90121. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90122. FLAC__int32 *residual[2],
  90123. unsigned *best_subframe,
  90124. unsigned *best_bits
  90125. );
  90126. static FLAC__bool add_subframe_(
  90127. FLAC__StreamEncoder *encoder,
  90128. unsigned blocksize,
  90129. unsigned subframe_bps,
  90130. const FLAC__Subframe *subframe,
  90131. FLAC__BitWriter *frame
  90132. );
  90133. static unsigned evaluate_constant_subframe_(
  90134. FLAC__StreamEncoder *encoder,
  90135. const FLAC__int32 signal,
  90136. unsigned blocksize,
  90137. unsigned subframe_bps,
  90138. FLAC__Subframe *subframe
  90139. );
  90140. static unsigned evaluate_fixed_subframe_(
  90141. FLAC__StreamEncoder *encoder,
  90142. const FLAC__int32 signal[],
  90143. FLAC__int32 residual[],
  90144. FLAC__uint64 abs_residual_partition_sums[],
  90145. unsigned raw_bits_per_partition[],
  90146. unsigned blocksize,
  90147. unsigned subframe_bps,
  90148. unsigned order,
  90149. unsigned rice_parameter,
  90150. unsigned rice_parameter_limit,
  90151. unsigned min_partition_order,
  90152. unsigned max_partition_order,
  90153. FLAC__bool do_escape_coding,
  90154. unsigned rice_parameter_search_dist,
  90155. FLAC__Subframe *subframe,
  90156. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90157. );
  90158. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90159. static unsigned evaluate_lpc_subframe_(
  90160. FLAC__StreamEncoder *encoder,
  90161. const FLAC__int32 signal[],
  90162. FLAC__int32 residual[],
  90163. FLAC__uint64 abs_residual_partition_sums[],
  90164. unsigned raw_bits_per_partition[],
  90165. const FLAC__real lp_coeff[],
  90166. unsigned blocksize,
  90167. unsigned subframe_bps,
  90168. unsigned order,
  90169. unsigned qlp_coeff_precision,
  90170. unsigned rice_parameter,
  90171. unsigned rice_parameter_limit,
  90172. unsigned min_partition_order,
  90173. unsigned max_partition_order,
  90174. FLAC__bool do_escape_coding,
  90175. unsigned rice_parameter_search_dist,
  90176. FLAC__Subframe *subframe,
  90177. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90178. );
  90179. #endif
  90180. static unsigned evaluate_verbatim_subframe_(
  90181. FLAC__StreamEncoder *encoder,
  90182. const FLAC__int32 signal[],
  90183. unsigned blocksize,
  90184. unsigned subframe_bps,
  90185. FLAC__Subframe *subframe
  90186. );
  90187. static unsigned find_best_partition_order_(
  90188. struct FLAC__StreamEncoderPrivate *private_,
  90189. const FLAC__int32 residual[],
  90190. FLAC__uint64 abs_residual_partition_sums[],
  90191. unsigned raw_bits_per_partition[],
  90192. unsigned residual_samples,
  90193. unsigned predictor_order,
  90194. unsigned rice_parameter,
  90195. unsigned rice_parameter_limit,
  90196. unsigned min_partition_order,
  90197. unsigned max_partition_order,
  90198. unsigned bps,
  90199. FLAC__bool do_escape_coding,
  90200. unsigned rice_parameter_search_dist,
  90201. FLAC__EntropyCodingMethod *best_ecm
  90202. );
  90203. static void precompute_partition_info_sums_(
  90204. const FLAC__int32 residual[],
  90205. FLAC__uint64 abs_residual_partition_sums[],
  90206. unsigned residual_samples,
  90207. unsigned predictor_order,
  90208. unsigned min_partition_order,
  90209. unsigned max_partition_order,
  90210. unsigned bps
  90211. );
  90212. static void precompute_partition_info_escapes_(
  90213. const FLAC__int32 residual[],
  90214. unsigned raw_bits_per_partition[],
  90215. unsigned residual_samples,
  90216. unsigned predictor_order,
  90217. unsigned min_partition_order,
  90218. unsigned max_partition_order
  90219. );
  90220. static FLAC__bool set_partitioned_rice_(
  90221. #ifdef EXACT_RICE_BITS_CALCULATION
  90222. const FLAC__int32 residual[],
  90223. #endif
  90224. const FLAC__uint64 abs_residual_partition_sums[],
  90225. const unsigned raw_bits_per_partition[],
  90226. const unsigned residual_samples,
  90227. const unsigned predictor_order,
  90228. const unsigned suggested_rice_parameter,
  90229. const unsigned rice_parameter_limit,
  90230. const unsigned rice_parameter_search_dist,
  90231. const unsigned partition_order,
  90232. const FLAC__bool search_for_escapes,
  90233. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90234. unsigned *bits
  90235. );
  90236. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90237. static void append_to_verify_fifo_(
  90238. verify_input_fifo *fifo,
  90239. const FLAC__int32 * const input[],
  90240. unsigned input_offset,
  90241. unsigned channels,
  90242. unsigned wide_samples
  90243. );
  90244. static void append_to_verify_fifo_interleaved_(
  90245. verify_input_fifo *fifo,
  90246. const FLAC__int32 input[],
  90247. unsigned input_offset,
  90248. unsigned channels,
  90249. unsigned wide_samples
  90250. );
  90251. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90252. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90253. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90254. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90255. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90256. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90257. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90258. 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);
  90259. static FILE *get_binary_stdout_(void);
  90260. typedef struct FLAC__StreamEncoderPrivate {
  90261. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90262. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90263. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90264. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90265. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90266. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90267. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90268. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90269. #endif
  90270. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90271. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90272. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90273. FLAC__int32 *residual_workspace_mid_side[2][2];
  90274. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90275. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90276. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90277. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90278. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90279. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90280. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90281. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90282. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90283. unsigned best_subframe_mid_side[2];
  90284. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90285. unsigned best_subframe_bits_mid_side[2];
  90286. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90287. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90288. FLAC__BitWriter *frame; /* the current frame being worked on */
  90289. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90290. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90291. FLAC__ChannelAssignment last_channel_assignment;
  90292. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90293. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90294. unsigned current_sample_number;
  90295. unsigned current_frame_number;
  90296. FLAC__MD5Context md5context;
  90297. FLAC__CPUInfo cpuinfo;
  90298. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90299. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90300. #else
  90301. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90302. #endif
  90303. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90304. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90305. 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[]);
  90306. 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[]);
  90307. 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[]);
  90308. #endif
  90309. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90310. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90311. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90312. FLAC__bool disable_constant_subframes;
  90313. FLAC__bool disable_fixed_subframes;
  90314. FLAC__bool disable_verbatim_subframes;
  90315. #if FLAC__HAS_OGG
  90316. FLAC__bool is_ogg;
  90317. #endif
  90318. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90319. FLAC__StreamEncoderSeekCallback seek_callback;
  90320. FLAC__StreamEncoderTellCallback tell_callback;
  90321. FLAC__StreamEncoderWriteCallback write_callback;
  90322. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90323. FLAC__StreamEncoderProgressCallback progress_callback;
  90324. void *client_data;
  90325. unsigned first_seekpoint_to_check;
  90326. FILE *file; /* only used when encoding to a file */
  90327. FLAC__uint64 bytes_written;
  90328. FLAC__uint64 samples_written;
  90329. unsigned frames_written;
  90330. unsigned total_frames_estimate;
  90331. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90332. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90333. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90334. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90335. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90336. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90337. FLAC__real *windowed_signal_unaligned;
  90338. #endif
  90339. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90340. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90341. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90342. unsigned *raw_bits_per_partition_unaligned;
  90343. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90344. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90345. #endif
  90346. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90347. struct {
  90348. FLAC__StreamDecoder *decoder;
  90349. EncoderStateHint state_hint;
  90350. FLAC__bool needs_magic_hack;
  90351. verify_input_fifo input_fifo;
  90352. verify_output output;
  90353. struct {
  90354. FLAC__uint64 absolute_sample;
  90355. unsigned frame_number;
  90356. unsigned channel;
  90357. unsigned sample;
  90358. FLAC__int32 expected;
  90359. FLAC__int32 got;
  90360. } error_stats;
  90361. } verify;
  90362. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90363. } FLAC__StreamEncoderPrivate;
  90364. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90365. "FLAC__STREAM_ENCODER_OK",
  90366. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90367. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90368. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90369. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90370. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90371. "FLAC__STREAM_ENCODER_IO_ERROR",
  90372. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90373. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90374. };
  90375. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90376. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90377. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90378. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90379. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90380. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90381. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90382. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90383. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90384. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90385. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90386. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90387. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90388. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90389. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90390. };
  90391. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90392. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90393. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90394. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90395. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90396. };
  90397. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90398. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90399. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90400. };
  90401. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90402. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90403. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90404. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90405. };
  90406. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90407. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90408. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90409. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90410. };
  90411. static const unsigned OVERREAD_ = 1;
  90412. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90413. {
  90414. FLAC__StreamEncoder *encoder;
  90415. unsigned i;
  90416. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90417. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90418. if(encoder == 0) {
  90419. return 0;
  90420. }
  90421. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90422. if(encoder->protected_ == 0) {
  90423. free(encoder);
  90424. return 0;
  90425. }
  90426. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90427. if(encoder->private_ == 0) {
  90428. free(encoder->protected_);
  90429. free(encoder);
  90430. return 0;
  90431. }
  90432. encoder->private_->frame = FLAC__bitwriter_new();
  90433. if(encoder->private_->frame == 0) {
  90434. free(encoder->private_);
  90435. free(encoder->protected_);
  90436. free(encoder);
  90437. return 0;
  90438. }
  90439. encoder->private_->file = 0;
  90440. set_defaults_enc(encoder);
  90441. encoder->private_->is_being_deleted = false;
  90442. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90443. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90444. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90445. }
  90446. for(i = 0; i < 2; i++) {
  90447. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90448. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90449. }
  90450. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90451. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90452. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90453. }
  90454. for(i = 0; i < 2; i++) {
  90455. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90456. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90457. }
  90458. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90459. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90460. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90461. }
  90462. for(i = 0; i < 2; i++) {
  90463. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90464. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90465. }
  90466. for(i = 0; i < 2; i++)
  90467. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90468. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90469. return encoder;
  90470. }
  90471. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90472. {
  90473. unsigned i;
  90474. FLAC__ASSERT(0 != encoder);
  90475. FLAC__ASSERT(0 != encoder->protected_);
  90476. FLAC__ASSERT(0 != encoder->private_);
  90477. FLAC__ASSERT(0 != encoder->private_->frame);
  90478. encoder->private_->is_being_deleted = true;
  90479. (void)FLAC__stream_encoder_finish(encoder);
  90480. if(0 != encoder->private_->verify.decoder)
  90481. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90482. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90483. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90484. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90485. }
  90486. for(i = 0; i < 2; i++) {
  90487. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90488. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90489. }
  90490. for(i = 0; i < 2; i++)
  90491. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90492. FLAC__bitwriter_delete(encoder->private_->frame);
  90493. free(encoder->private_);
  90494. free(encoder->protected_);
  90495. free(encoder);
  90496. }
  90497. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90498. FLAC__StreamEncoder *encoder,
  90499. FLAC__StreamEncoderReadCallback read_callback,
  90500. FLAC__StreamEncoderWriteCallback write_callback,
  90501. FLAC__StreamEncoderSeekCallback seek_callback,
  90502. FLAC__StreamEncoderTellCallback tell_callback,
  90503. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90504. void *client_data,
  90505. FLAC__bool is_ogg
  90506. )
  90507. {
  90508. unsigned i;
  90509. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90510. FLAC__ASSERT(0 != encoder);
  90511. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90512. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90513. #if !FLAC__HAS_OGG
  90514. if(is_ogg)
  90515. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90516. #endif
  90517. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90518. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90519. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90520. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90521. if(encoder->protected_->channels != 2) {
  90522. encoder->protected_->do_mid_side_stereo = false;
  90523. encoder->protected_->loose_mid_side_stereo = false;
  90524. }
  90525. else if(!encoder->protected_->do_mid_side_stereo)
  90526. encoder->protected_->loose_mid_side_stereo = false;
  90527. if(encoder->protected_->bits_per_sample >= 32)
  90528. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90529. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90530. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90531. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90532. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90533. if(encoder->protected_->blocksize == 0) {
  90534. if(encoder->protected_->max_lpc_order == 0)
  90535. encoder->protected_->blocksize = 1152;
  90536. else
  90537. encoder->protected_->blocksize = 4096;
  90538. }
  90539. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90540. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90541. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90542. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90543. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90544. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90545. if(encoder->protected_->qlp_coeff_precision == 0) {
  90546. if(encoder->protected_->bits_per_sample < 16) {
  90547. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90548. }
  90549. else if(encoder->protected_->bits_per_sample == 16) {
  90550. if(encoder->protected_->blocksize <= 192)
  90551. encoder->protected_->qlp_coeff_precision = 7;
  90552. else if(encoder->protected_->blocksize <= 384)
  90553. encoder->protected_->qlp_coeff_precision = 8;
  90554. else if(encoder->protected_->blocksize <= 576)
  90555. encoder->protected_->qlp_coeff_precision = 9;
  90556. else if(encoder->protected_->blocksize <= 1152)
  90557. encoder->protected_->qlp_coeff_precision = 10;
  90558. else if(encoder->protected_->blocksize <= 2304)
  90559. encoder->protected_->qlp_coeff_precision = 11;
  90560. else if(encoder->protected_->blocksize <= 4608)
  90561. encoder->protected_->qlp_coeff_precision = 12;
  90562. else
  90563. encoder->protected_->qlp_coeff_precision = 13;
  90564. }
  90565. else {
  90566. if(encoder->protected_->blocksize <= 384)
  90567. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90568. else if(encoder->protected_->blocksize <= 1152)
  90569. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90570. else
  90571. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90572. }
  90573. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90574. }
  90575. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90576. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90577. if(encoder->protected_->streamable_subset) {
  90578. if(
  90579. encoder->protected_->blocksize != 192 &&
  90580. encoder->protected_->blocksize != 576 &&
  90581. encoder->protected_->blocksize != 1152 &&
  90582. encoder->protected_->blocksize != 2304 &&
  90583. encoder->protected_->blocksize != 4608 &&
  90584. encoder->protected_->blocksize != 256 &&
  90585. encoder->protected_->blocksize != 512 &&
  90586. encoder->protected_->blocksize != 1024 &&
  90587. encoder->protected_->blocksize != 2048 &&
  90588. encoder->protected_->blocksize != 4096 &&
  90589. encoder->protected_->blocksize != 8192 &&
  90590. encoder->protected_->blocksize != 16384
  90591. )
  90592. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90593. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90594. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90595. if(
  90596. encoder->protected_->bits_per_sample != 8 &&
  90597. encoder->protected_->bits_per_sample != 12 &&
  90598. encoder->protected_->bits_per_sample != 16 &&
  90599. encoder->protected_->bits_per_sample != 20 &&
  90600. encoder->protected_->bits_per_sample != 24
  90601. )
  90602. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90603. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90604. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90605. if(
  90606. encoder->protected_->sample_rate <= 48000 &&
  90607. (
  90608. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90609. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90610. )
  90611. ) {
  90612. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90613. }
  90614. }
  90615. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90616. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90617. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90618. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90619. #if FLAC__HAS_OGG
  90620. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90621. unsigned i;
  90622. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90623. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90624. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90625. for( ; i > 0; i--)
  90626. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90627. encoder->protected_->metadata[0] = vc;
  90628. break;
  90629. }
  90630. }
  90631. }
  90632. #endif
  90633. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90634. unsigned i;
  90635. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90636. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90637. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90638. break; /* take only the first one */
  90639. }
  90640. }
  90641. }
  90642. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90643. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90644. metadata_has_seektable = false;
  90645. metadata_has_vorbis_comment = false;
  90646. metadata_picture_has_type1 = false;
  90647. metadata_picture_has_type2 = false;
  90648. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90649. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90650. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90651. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90652. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90653. if(metadata_has_seektable) /* only one is allowed */
  90654. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90655. metadata_has_seektable = true;
  90656. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90657. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90658. }
  90659. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90660. if(metadata_has_vorbis_comment) /* only one is allowed */
  90661. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90662. metadata_has_vorbis_comment = true;
  90663. }
  90664. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90665. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90666. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90667. }
  90668. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90669. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90670. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90671. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90672. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90673. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90674. metadata_picture_has_type1 = true;
  90675. if(
  90676. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90677. (
  90678. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90679. m->data.picture.width != 32 ||
  90680. m->data.picture.height != 32
  90681. )
  90682. )
  90683. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90684. }
  90685. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90686. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90687. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90688. metadata_picture_has_type2 = true;
  90689. }
  90690. }
  90691. }
  90692. encoder->private_->input_capacity = 0;
  90693. for(i = 0; i < encoder->protected_->channels; i++) {
  90694. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90695. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90696. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90697. #endif
  90698. }
  90699. for(i = 0; i < 2; i++) {
  90700. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90701. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90702. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90703. #endif
  90704. }
  90705. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90706. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90707. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90708. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90709. #endif
  90710. for(i = 0; i < encoder->protected_->channels; i++) {
  90711. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90712. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90713. encoder->private_->best_subframe[i] = 0;
  90714. }
  90715. for(i = 0; i < 2; i++) {
  90716. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90717. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90718. encoder->private_->best_subframe_mid_side[i] = 0;
  90719. }
  90720. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90721. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90722. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90723. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90724. #else
  90725. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90726. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90727. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90728. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90729. 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);
  90730. #endif
  90731. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90732. encoder->private_->loose_mid_side_stereo_frames = 1;
  90733. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90734. encoder->private_->current_sample_number = 0;
  90735. encoder->private_->current_frame_number = 0;
  90736. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90737. 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? */
  90738. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90739. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90740. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90741. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90742. #endif
  90743. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90744. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90745. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90746. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90747. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90748. #endif
  90749. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90750. # ifndef FLAC__NO_ASM
  90751. if(encoder->private_->cpuinfo.use_asm) {
  90752. # ifdef FLAC__CPU_IA32
  90753. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90754. # ifdef FLAC__HAS_NASM
  90755. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90756. if(encoder->protected_->max_lpc_order < 4)
  90757. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90758. else if(encoder->protected_->max_lpc_order < 8)
  90759. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90760. else if(encoder->protected_->max_lpc_order < 12)
  90761. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90762. else
  90763. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90764. }
  90765. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90766. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90767. else
  90768. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90769. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90770. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90771. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90772. }
  90773. else {
  90774. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90775. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90776. }
  90777. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90778. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90779. # endif /* FLAC__HAS_NASM */
  90780. # endif /* FLAC__CPU_IA32 */
  90781. }
  90782. # endif /* !FLAC__NO_ASM */
  90783. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90784. if(encoder->private_->use_wide_by_block) {
  90785. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90786. }
  90787. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90788. #if FLAC__HAS_OGG
  90789. encoder->private_->is_ogg = is_ogg;
  90790. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90791. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90792. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90793. }
  90794. #endif
  90795. encoder->private_->read_callback = read_callback;
  90796. encoder->private_->write_callback = write_callback;
  90797. encoder->private_->seek_callback = seek_callback;
  90798. encoder->private_->tell_callback = tell_callback;
  90799. encoder->private_->metadata_callback = metadata_callback;
  90800. encoder->private_->client_data = client_data;
  90801. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90802. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90803. }
  90804. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90805. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90806. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90807. }
  90808. if(encoder->protected_->verify) {
  90809. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90810. for(i = 0; i < encoder->protected_->channels; i++) {
  90811. 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))) {
  90812. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90813. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90814. }
  90815. }
  90816. encoder->private_->verify.input_fifo.tail = 0;
  90817. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90818. if(0 == encoder->private_->verify.decoder) {
  90819. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90820. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90821. }
  90822. 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) {
  90823. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90824. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90825. }
  90826. }
  90827. encoder->private_->verify.error_stats.absolute_sample = 0;
  90828. encoder->private_->verify.error_stats.frame_number = 0;
  90829. encoder->private_->verify.error_stats.channel = 0;
  90830. encoder->private_->verify.error_stats.sample = 0;
  90831. encoder->private_->verify.error_stats.expected = 0;
  90832. encoder->private_->verify.error_stats.got = 0;
  90833. encoder->private_->first_seekpoint_to_check = 0;
  90834. encoder->private_->samples_written = 0;
  90835. encoder->protected_->streaminfo_offset = 0;
  90836. encoder->protected_->seektable_offset = 0;
  90837. encoder->protected_->audio_offset = 0;
  90838. if(encoder->protected_->verify)
  90839. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90840. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90841. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90842. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90843. }
  90844. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90845. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90846. }
  90847. if(encoder->protected_->verify)
  90848. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90849. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90850. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90851. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90852. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90853. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90854. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90855. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90856. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90857. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90858. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90859. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90860. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90861. if(encoder->protected_->do_md5)
  90862. FLAC__MD5Init(&encoder->private_->md5context);
  90863. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90864. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90865. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90866. }
  90867. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90868. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90869. }
  90870. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90871. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90872. if(!metadata_has_vorbis_comment) {
  90873. FLAC__StreamMetadata vorbis_comment;
  90874. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90875. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90876. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90877. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90878. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90879. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90880. vorbis_comment.data.vorbis_comment.comments = 0;
  90881. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90882. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90883. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90884. }
  90885. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90886. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90887. }
  90888. }
  90889. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90890. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90891. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90892. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90893. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90894. }
  90895. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90896. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90897. }
  90898. }
  90899. 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 */
  90900. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90901. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90902. }
  90903. if(encoder->protected_->verify)
  90904. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90905. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90906. }
  90907. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90908. FLAC__StreamEncoder *encoder,
  90909. FLAC__StreamEncoderWriteCallback write_callback,
  90910. FLAC__StreamEncoderSeekCallback seek_callback,
  90911. FLAC__StreamEncoderTellCallback tell_callback,
  90912. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90913. void *client_data
  90914. )
  90915. {
  90916. return init_stream_internal_enc(
  90917. encoder,
  90918. 0,
  90919. write_callback,
  90920. seek_callback,
  90921. tell_callback,
  90922. metadata_callback,
  90923. client_data,
  90924. false
  90925. );
  90926. }
  90927. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90928. FLAC__StreamEncoder *encoder,
  90929. FLAC__StreamEncoderReadCallback read_callback,
  90930. FLAC__StreamEncoderWriteCallback write_callback,
  90931. FLAC__StreamEncoderSeekCallback seek_callback,
  90932. FLAC__StreamEncoderTellCallback tell_callback,
  90933. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90934. void *client_data
  90935. )
  90936. {
  90937. return init_stream_internal_enc(
  90938. encoder,
  90939. read_callback,
  90940. write_callback,
  90941. seek_callback,
  90942. tell_callback,
  90943. metadata_callback,
  90944. client_data,
  90945. true
  90946. );
  90947. }
  90948. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90949. FLAC__StreamEncoder *encoder,
  90950. FILE *file,
  90951. FLAC__StreamEncoderProgressCallback progress_callback,
  90952. void *client_data,
  90953. FLAC__bool is_ogg
  90954. )
  90955. {
  90956. FLAC__StreamEncoderInitStatus init_status;
  90957. FLAC__ASSERT(0 != encoder);
  90958. FLAC__ASSERT(0 != file);
  90959. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90960. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90961. if(file == 0) {
  90962. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90963. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90964. }
  90965. if(file == stdout)
  90966. file = get_binary_stdout_(); /* just to be safe */
  90967. encoder->private_->file = file;
  90968. encoder->private_->progress_callback = progress_callback;
  90969. encoder->private_->bytes_written = 0;
  90970. encoder->private_->samples_written = 0;
  90971. encoder->private_->frames_written = 0;
  90972. init_status = init_stream_internal_enc(
  90973. encoder,
  90974. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90975. file_write_callback_,
  90976. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90977. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90978. 0,
  90979. client_data,
  90980. is_ogg
  90981. );
  90982. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90983. return init_status;
  90984. }
  90985. {
  90986. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90987. FLAC__ASSERT(blocksize != 0);
  90988. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90989. }
  90990. return init_status;
  90991. }
  90992. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90993. FLAC__StreamEncoder *encoder,
  90994. FILE *file,
  90995. FLAC__StreamEncoderProgressCallback progress_callback,
  90996. void *client_data
  90997. )
  90998. {
  90999. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  91000. }
  91001. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  91002. FLAC__StreamEncoder *encoder,
  91003. FILE *file,
  91004. FLAC__StreamEncoderProgressCallback progress_callback,
  91005. void *client_data
  91006. )
  91007. {
  91008. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  91009. }
  91010. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  91011. FLAC__StreamEncoder *encoder,
  91012. const char *filename,
  91013. FLAC__StreamEncoderProgressCallback progress_callback,
  91014. void *client_data,
  91015. FLAC__bool is_ogg
  91016. )
  91017. {
  91018. FILE *file;
  91019. FLAC__ASSERT(0 != encoder);
  91020. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91021. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  91022. file = filename? fopen(filename, "w+b") : stdout;
  91023. if(file == 0) {
  91024. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  91025. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91026. }
  91027. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  91028. }
  91029. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  91030. FLAC__StreamEncoder *encoder,
  91031. const char *filename,
  91032. FLAC__StreamEncoderProgressCallback progress_callback,
  91033. void *client_data
  91034. )
  91035. {
  91036. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  91037. }
  91038. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  91039. FLAC__StreamEncoder *encoder,
  91040. const char *filename,
  91041. FLAC__StreamEncoderProgressCallback progress_callback,
  91042. void *client_data
  91043. )
  91044. {
  91045. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  91046. }
  91047. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  91048. {
  91049. FLAC__bool error = false;
  91050. FLAC__ASSERT(0 != encoder);
  91051. FLAC__ASSERT(0 != encoder->private_);
  91052. FLAC__ASSERT(0 != encoder->protected_);
  91053. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  91054. return true;
  91055. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  91056. if(encoder->private_->current_sample_number != 0) {
  91057. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  91058. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  91059. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  91060. error = true;
  91061. }
  91062. }
  91063. if(encoder->protected_->do_md5)
  91064. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  91065. if(!encoder->private_->is_being_deleted) {
  91066. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  91067. if(encoder->private_->seek_callback) {
  91068. #if FLAC__HAS_OGG
  91069. if(encoder->private_->is_ogg)
  91070. update_ogg_metadata_(encoder);
  91071. else
  91072. #endif
  91073. update_metadata_(encoder);
  91074. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  91075. error = true;
  91076. }
  91077. if(encoder->private_->metadata_callback)
  91078. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  91079. }
  91080. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  91081. if(!error)
  91082. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  91083. error = true;
  91084. }
  91085. }
  91086. if(0 != encoder->private_->file) {
  91087. if(encoder->private_->file != stdout)
  91088. fclose(encoder->private_->file);
  91089. encoder->private_->file = 0;
  91090. }
  91091. #if FLAC__HAS_OGG
  91092. if(encoder->private_->is_ogg)
  91093. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  91094. #endif
  91095. free_(encoder);
  91096. set_defaults_enc(encoder);
  91097. if(!error)
  91098. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91099. return !error;
  91100. }
  91101. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91102. {
  91103. FLAC__ASSERT(0 != encoder);
  91104. FLAC__ASSERT(0 != encoder->private_);
  91105. FLAC__ASSERT(0 != encoder->protected_);
  91106. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91107. return false;
  91108. #if FLAC__HAS_OGG
  91109. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91110. return true;
  91111. #else
  91112. (void)value;
  91113. return false;
  91114. #endif
  91115. }
  91116. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91117. {
  91118. FLAC__ASSERT(0 != encoder);
  91119. FLAC__ASSERT(0 != encoder->private_);
  91120. FLAC__ASSERT(0 != encoder->protected_);
  91121. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91122. return false;
  91123. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91124. encoder->protected_->verify = value;
  91125. #endif
  91126. return true;
  91127. }
  91128. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91129. {
  91130. FLAC__ASSERT(0 != encoder);
  91131. FLAC__ASSERT(0 != encoder->private_);
  91132. FLAC__ASSERT(0 != encoder->protected_);
  91133. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91134. return false;
  91135. encoder->protected_->streamable_subset = value;
  91136. return true;
  91137. }
  91138. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91139. {
  91140. FLAC__ASSERT(0 != encoder);
  91141. FLAC__ASSERT(0 != encoder->private_);
  91142. FLAC__ASSERT(0 != encoder->protected_);
  91143. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91144. return false;
  91145. encoder->protected_->do_md5 = value;
  91146. return true;
  91147. }
  91148. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  91149. {
  91150. FLAC__ASSERT(0 != encoder);
  91151. FLAC__ASSERT(0 != encoder->private_);
  91152. FLAC__ASSERT(0 != encoder->protected_);
  91153. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91154. return false;
  91155. encoder->protected_->channels = value;
  91156. return true;
  91157. }
  91158. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  91159. {
  91160. FLAC__ASSERT(0 != encoder);
  91161. FLAC__ASSERT(0 != encoder->private_);
  91162. FLAC__ASSERT(0 != encoder->protected_);
  91163. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91164. return false;
  91165. encoder->protected_->bits_per_sample = value;
  91166. return true;
  91167. }
  91168. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  91169. {
  91170. FLAC__ASSERT(0 != encoder);
  91171. FLAC__ASSERT(0 != encoder->private_);
  91172. FLAC__ASSERT(0 != encoder->protected_);
  91173. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91174. return false;
  91175. encoder->protected_->sample_rate = value;
  91176. return true;
  91177. }
  91178. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91179. {
  91180. FLAC__bool ok = true;
  91181. FLAC__ASSERT(0 != encoder);
  91182. FLAC__ASSERT(0 != encoder->private_);
  91183. FLAC__ASSERT(0 != encoder->protected_);
  91184. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91185. return false;
  91186. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91187. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91188. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91189. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91190. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91191. #if 0
  91192. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91193. #else
  91194. encoder->protected_->num_apodizations = 1;
  91195. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91196. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91197. #endif
  91198. #endif
  91199. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91200. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91201. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91202. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91203. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91204. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91205. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91206. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91207. return ok;
  91208. }
  91209. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91210. {
  91211. FLAC__ASSERT(0 != encoder);
  91212. FLAC__ASSERT(0 != encoder->private_);
  91213. FLAC__ASSERT(0 != encoder->protected_);
  91214. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91215. return false;
  91216. encoder->protected_->blocksize = value;
  91217. return true;
  91218. }
  91219. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91220. {
  91221. FLAC__ASSERT(0 != encoder);
  91222. FLAC__ASSERT(0 != encoder->private_);
  91223. FLAC__ASSERT(0 != encoder->protected_);
  91224. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91225. return false;
  91226. encoder->protected_->do_mid_side_stereo = value;
  91227. return true;
  91228. }
  91229. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91230. {
  91231. FLAC__ASSERT(0 != encoder);
  91232. FLAC__ASSERT(0 != encoder->private_);
  91233. FLAC__ASSERT(0 != encoder->protected_);
  91234. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91235. return false;
  91236. encoder->protected_->loose_mid_side_stereo = value;
  91237. return true;
  91238. }
  91239. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91240. {
  91241. FLAC__ASSERT(0 != encoder);
  91242. FLAC__ASSERT(0 != encoder->private_);
  91243. FLAC__ASSERT(0 != encoder->protected_);
  91244. FLAC__ASSERT(0 != specification);
  91245. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91246. return false;
  91247. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91248. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91249. #else
  91250. encoder->protected_->num_apodizations = 0;
  91251. while(1) {
  91252. const char *s = strchr(specification, ';');
  91253. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91254. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91255. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91256. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91257. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91258. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91259. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91260. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91261. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91262. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91263. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91264. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91265. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91266. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91267. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91268. if (stddev > 0.0 && stddev <= 0.5) {
  91269. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91270. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91271. }
  91272. }
  91273. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91274. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91275. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91276. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91277. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91278. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91279. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91280. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91281. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91282. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91283. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91284. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91285. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91286. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91287. if (p >= 0.0 && p <= 1.0) {
  91288. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91289. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91290. }
  91291. }
  91292. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91293. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91294. if (encoder->protected_->num_apodizations == 32)
  91295. break;
  91296. if (s)
  91297. specification = s+1;
  91298. else
  91299. break;
  91300. }
  91301. if(encoder->protected_->num_apodizations == 0) {
  91302. encoder->protected_->num_apodizations = 1;
  91303. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91304. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91305. }
  91306. #endif
  91307. return true;
  91308. }
  91309. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91310. {
  91311. FLAC__ASSERT(0 != encoder);
  91312. FLAC__ASSERT(0 != encoder->private_);
  91313. FLAC__ASSERT(0 != encoder->protected_);
  91314. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91315. return false;
  91316. encoder->protected_->max_lpc_order = value;
  91317. return true;
  91318. }
  91319. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91320. {
  91321. FLAC__ASSERT(0 != encoder);
  91322. FLAC__ASSERT(0 != encoder->private_);
  91323. FLAC__ASSERT(0 != encoder->protected_);
  91324. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91325. return false;
  91326. encoder->protected_->qlp_coeff_precision = value;
  91327. return true;
  91328. }
  91329. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91330. {
  91331. FLAC__ASSERT(0 != encoder);
  91332. FLAC__ASSERT(0 != encoder->private_);
  91333. FLAC__ASSERT(0 != encoder->protected_);
  91334. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91335. return false;
  91336. encoder->protected_->do_qlp_coeff_prec_search = value;
  91337. return true;
  91338. }
  91339. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91340. {
  91341. FLAC__ASSERT(0 != encoder);
  91342. FLAC__ASSERT(0 != encoder->private_);
  91343. FLAC__ASSERT(0 != encoder->protected_);
  91344. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91345. return false;
  91346. #if 0
  91347. encoder->protected_->do_escape_coding = value;
  91348. #else
  91349. (void)value;
  91350. #endif
  91351. return true;
  91352. }
  91353. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91354. {
  91355. FLAC__ASSERT(0 != encoder);
  91356. FLAC__ASSERT(0 != encoder->private_);
  91357. FLAC__ASSERT(0 != encoder->protected_);
  91358. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91359. return false;
  91360. encoder->protected_->do_exhaustive_model_search = value;
  91361. return true;
  91362. }
  91363. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91364. {
  91365. FLAC__ASSERT(0 != encoder);
  91366. FLAC__ASSERT(0 != encoder->private_);
  91367. FLAC__ASSERT(0 != encoder->protected_);
  91368. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91369. return false;
  91370. encoder->protected_->min_residual_partition_order = value;
  91371. return true;
  91372. }
  91373. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91374. {
  91375. FLAC__ASSERT(0 != encoder);
  91376. FLAC__ASSERT(0 != encoder->private_);
  91377. FLAC__ASSERT(0 != encoder->protected_);
  91378. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91379. return false;
  91380. encoder->protected_->max_residual_partition_order = value;
  91381. return true;
  91382. }
  91383. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91384. {
  91385. FLAC__ASSERT(0 != encoder);
  91386. FLAC__ASSERT(0 != encoder->private_);
  91387. FLAC__ASSERT(0 != encoder->protected_);
  91388. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91389. return false;
  91390. #if 0
  91391. encoder->protected_->rice_parameter_search_dist = value;
  91392. #else
  91393. (void)value;
  91394. #endif
  91395. return true;
  91396. }
  91397. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91398. {
  91399. FLAC__ASSERT(0 != encoder);
  91400. FLAC__ASSERT(0 != encoder->private_);
  91401. FLAC__ASSERT(0 != encoder->protected_);
  91402. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91403. return false;
  91404. encoder->protected_->total_samples_estimate = value;
  91405. return true;
  91406. }
  91407. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91408. {
  91409. FLAC__ASSERT(0 != encoder);
  91410. FLAC__ASSERT(0 != encoder->private_);
  91411. FLAC__ASSERT(0 != encoder->protected_);
  91412. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91413. return false;
  91414. if(0 == metadata)
  91415. num_blocks = 0;
  91416. if(0 == num_blocks)
  91417. metadata = 0;
  91418. if(encoder->protected_->metadata) {
  91419. free(encoder->protected_->metadata);
  91420. encoder->protected_->metadata = 0;
  91421. encoder->protected_->num_metadata_blocks = 0;
  91422. }
  91423. if(num_blocks) {
  91424. FLAC__StreamMetadata **m;
  91425. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91426. return false;
  91427. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91428. encoder->protected_->metadata = m;
  91429. encoder->protected_->num_metadata_blocks = num_blocks;
  91430. }
  91431. #if FLAC__HAS_OGG
  91432. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91433. return false;
  91434. #endif
  91435. return true;
  91436. }
  91437. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91438. {
  91439. FLAC__ASSERT(0 != encoder);
  91440. FLAC__ASSERT(0 != encoder->private_);
  91441. FLAC__ASSERT(0 != encoder->protected_);
  91442. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91443. return false;
  91444. encoder->private_->disable_constant_subframes = value;
  91445. return true;
  91446. }
  91447. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91448. {
  91449. FLAC__ASSERT(0 != encoder);
  91450. FLAC__ASSERT(0 != encoder->private_);
  91451. FLAC__ASSERT(0 != encoder->protected_);
  91452. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91453. return false;
  91454. encoder->private_->disable_fixed_subframes = value;
  91455. return true;
  91456. }
  91457. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91458. {
  91459. FLAC__ASSERT(0 != encoder);
  91460. FLAC__ASSERT(0 != encoder->private_);
  91461. FLAC__ASSERT(0 != encoder->protected_);
  91462. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91463. return false;
  91464. encoder->private_->disable_verbatim_subframes = value;
  91465. return true;
  91466. }
  91467. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91468. {
  91469. FLAC__ASSERT(0 != encoder);
  91470. FLAC__ASSERT(0 != encoder->private_);
  91471. FLAC__ASSERT(0 != encoder->protected_);
  91472. return encoder->protected_->state;
  91473. }
  91474. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91475. {
  91476. FLAC__ASSERT(0 != encoder);
  91477. FLAC__ASSERT(0 != encoder->private_);
  91478. FLAC__ASSERT(0 != encoder->protected_);
  91479. if(encoder->protected_->verify)
  91480. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91481. else
  91482. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91483. }
  91484. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91485. {
  91486. FLAC__ASSERT(0 != encoder);
  91487. FLAC__ASSERT(0 != encoder->private_);
  91488. FLAC__ASSERT(0 != encoder->protected_);
  91489. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91490. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91491. else
  91492. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91493. }
  91494. 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)
  91495. {
  91496. FLAC__ASSERT(0 != encoder);
  91497. FLAC__ASSERT(0 != encoder->private_);
  91498. FLAC__ASSERT(0 != encoder->protected_);
  91499. if(0 != absolute_sample)
  91500. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91501. if(0 != frame_number)
  91502. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91503. if(0 != channel)
  91504. *channel = encoder->private_->verify.error_stats.channel;
  91505. if(0 != sample)
  91506. *sample = encoder->private_->verify.error_stats.sample;
  91507. if(0 != expected)
  91508. *expected = encoder->private_->verify.error_stats.expected;
  91509. if(0 != got)
  91510. *got = encoder->private_->verify.error_stats.got;
  91511. }
  91512. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91513. {
  91514. FLAC__ASSERT(0 != encoder);
  91515. FLAC__ASSERT(0 != encoder->private_);
  91516. FLAC__ASSERT(0 != encoder->protected_);
  91517. return encoder->protected_->verify;
  91518. }
  91519. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91520. {
  91521. FLAC__ASSERT(0 != encoder);
  91522. FLAC__ASSERT(0 != encoder->private_);
  91523. FLAC__ASSERT(0 != encoder->protected_);
  91524. return encoder->protected_->streamable_subset;
  91525. }
  91526. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91527. {
  91528. FLAC__ASSERT(0 != encoder);
  91529. FLAC__ASSERT(0 != encoder->private_);
  91530. FLAC__ASSERT(0 != encoder->protected_);
  91531. return encoder->protected_->do_md5;
  91532. }
  91533. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91534. {
  91535. FLAC__ASSERT(0 != encoder);
  91536. FLAC__ASSERT(0 != encoder->private_);
  91537. FLAC__ASSERT(0 != encoder->protected_);
  91538. return encoder->protected_->channels;
  91539. }
  91540. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91541. {
  91542. FLAC__ASSERT(0 != encoder);
  91543. FLAC__ASSERT(0 != encoder->private_);
  91544. FLAC__ASSERT(0 != encoder->protected_);
  91545. return encoder->protected_->bits_per_sample;
  91546. }
  91547. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91548. {
  91549. FLAC__ASSERT(0 != encoder);
  91550. FLAC__ASSERT(0 != encoder->private_);
  91551. FLAC__ASSERT(0 != encoder->protected_);
  91552. return encoder->protected_->sample_rate;
  91553. }
  91554. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91555. {
  91556. FLAC__ASSERT(0 != encoder);
  91557. FLAC__ASSERT(0 != encoder->private_);
  91558. FLAC__ASSERT(0 != encoder->protected_);
  91559. return encoder->protected_->blocksize;
  91560. }
  91561. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91562. {
  91563. FLAC__ASSERT(0 != encoder);
  91564. FLAC__ASSERT(0 != encoder->private_);
  91565. FLAC__ASSERT(0 != encoder->protected_);
  91566. return encoder->protected_->do_mid_side_stereo;
  91567. }
  91568. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91569. {
  91570. FLAC__ASSERT(0 != encoder);
  91571. FLAC__ASSERT(0 != encoder->private_);
  91572. FLAC__ASSERT(0 != encoder->protected_);
  91573. return encoder->protected_->loose_mid_side_stereo;
  91574. }
  91575. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91576. {
  91577. FLAC__ASSERT(0 != encoder);
  91578. FLAC__ASSERT(0 != encoder->private_);
  91579. FLAC__ASSERT(0 != encoder->protected_);
  91580. return encoder->protected_->max_lpc_order;
  91581. }
  91582. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91583. {
  91584. FLAC__ASSERT(0 != encoder);
  91585. FLAC__ASSERT(0 != encoder->private_);
  91586. FLAC__ASSERT(0 != encoder->protected_);
  91587. return encoder->protected_->qlp_coeff_precision;
  91588. }
  91589. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91590. {
  91591. FLAC__ASSERT(0 != encoder);
  91592. FLAC__ASSERT(0 != encoder->private_);
  91593. FLAC__ASSERT(0 != encoder->protected_);
  91594. return encoder->protected_->do_qlp_coeff_prec_search;
  91595. }
  91596. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91597. {
  91598. FLAC__ASSERT(0 != encoder);
  91599. FLAC__ASSERT(0 != encoder->private_);
  91600. FLAC__ASSERT(0 != encoder->protected_);
  91601. return encoder->protected_->do_escape_coding;
  91602. }
  91603. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91604. {
  91605. FLAC__ASSERT(0 != encoder);
  91606. FLAC__ASSERT(0 != encoder->private_);
  91607. FLAC__ASSERT(0 != encoder->protected_);
  91608. return encoder->protected_->do_exhaustive_model_search;
  91609. }
  91610. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91611. {
  91612. FLAC__ASSERT(0 != encoder);
  91613. FLAC__ASSERT(0 != encoder->private_);
  91614. FLAC__ASSERT(0 != encoder->protected_);
  91615. return encoder->protected_->min_residual_partition_order;
  91616. }
  91617. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91618. {
  91619. FLAC__ASSERT(0 != encoder);
  91620. FLAC__ASSERT(0 != encoder->private_);
  91621. FLAC__ASSERT(0 != encoder->protected_);
  91622. return encoder->protected_->max_residual_partition_order;
  91623. }
  91624. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91625. {
  91626. FLAC__ASSERT(0 != encoder);
  91627. FLAC__ASSERT(0 != encoder->private_);
  91628. FLAC__ASSERT(0 != encoder->protected_);
  91629. return encoder->protected_->rice_parameter_search_dist;
  91630. }
  91631. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91632. {
  91633. FLAC__ASSERT(0 != encoder);
  91634. FLAC__ASSERT(0 != encoder->private_);
  91635. FLAC__ASSERT(0 != encoder->protected_);
  91636. return encoder->protected_->total_samples_estimate;
  91637. }
  91638. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91639. {
  91640. unsigned i, j = 0, channel;
  91641. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91642. FLAC__ASSERT(0 != encoder);
  91643. FLAC__ASSERT(0 != encoder->private_);
  91644. FLAC__ASSERT(0 != encoder->protected_);
  91645. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91646. do {
  91647. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91648. if(encoder->protected_->verify)
  91649. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91650. for(channel = 0; channel < channels; channel++)
  91651. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91652. if(encoder->protected_->do_mid_side_stereo) {
  91653. FLAC__ASSERT(channels == 2);
  91654. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91655. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91656. 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' ! */
  91657. }
  91658. }
  91659. else
  91660. j += n;
  91661. encoder->private_->current_sample_number += n;
  91662. if(encoder->private_->current_sample_number > blocksize) {
  91663. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91664. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91665. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91666. return false;
  91667. for(channel = 0; channel < channels; channel++)
  91668. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91669. if(encoder->protected_->do_mid_side_stereo) {
  91670. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91671. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91672. }
  91673. encoder->private_->current_sample_number = 1;
  91674. }
  91675. } while(j < samples);
  91676. return true;
  91677. }
  91678. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91679. {
  91680. unsigned i, j, k, channel;
  91681. FLAC__int32 x, mid, side;
  91682. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91683. FLAC__ASSERT(0 != encoder);
  91684. FLAC__ASSERT(0 != encoder->private_);
  91685. FLAC__ASSERT(0 != encoder->protected_);
  91686. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91687. j = k = 0;
  91688. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91689. do {
  91690. if(encoder->protected_->verify)
  91691. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91692. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91693. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91694. x = buffer[k++];
  91695. encoder->private_->integer_signal[1][i] = x;
  91696. mid += x;
  91697. side -= x;
  91698. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91699. encoder->private_->integer_signal_mid_side[1][i] = side;
  91700. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91701. }
  91702. encoder->private_->current_sample_number = i;
  91703. if(i > blocksize) {
  91704. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91705. return false;
  91706. /* move unprocessed overread samples to beginnings of arrays */
  91707. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91708. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91709. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91710. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91711. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91712. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91713. encoder->private_->current_sample_number = 1;
  91714. }
  91715. } while(j < samples);
  91716. }
  91717. else {
  91718. do {
  91719. if(encoder->protected_->verify)
  91720. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91721. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91722. for(channel = 0; channel < channels; channel++)
  91723. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91724. }
  91725. encoder->private_->current_sample_number = i;
  91726. if(i > blocksize) {
  91727. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91728. return false;
  91729. /* move unprocessed overread samples to beginnings of arrays */
  91730. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91731. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91732. for(channel = 0; channel < channels; channel++)
  91733. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91734. encoder->private_->current_sample_number = 1;
  91735. }
  91736. } while(j < samples);
  91737. }
  91738. return true;
  91739. }
  91740. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91741. {
  91742. FLAC__ASSERT(0 != encoder);
  91743. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91744. encoder->protected_->verify = true;
  91745. #else
  91746. encoder->protected_->verify = false;
  91747. #endif
  91748. encoder->protected_->streamable_subset = true;
  91749. encoder->protected_->do_md5 = true;
  91750. encoder->protected_->do_mid_side_stereo = false;
  91751. encoder->protected_->loose_mid_side_stereo = false;
  91752. encoder->protected_->channels = 2;
  91753. encoder->protected_->bits_per_sample = 16;
  91754. encoder->protected_->sample_rate = 44100;
  91755. encoder->protected_->blocksize = 0;
  91756. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91757. encoder->protected_->num_apodizations = 1;
  91758. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91759. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91760. #endif
  91761. encoder->protected_->max_lpc_order = 0;
  91762. encoder->protected_->qlp_coeff_precision = 0;
  91763. encoder->protected_->do_qlp_coeff_prec_search = false;
  91764. encoder->protected_->do_exhaustive_model_search = false;
  91765. encoder->protected_->do_escape_coding = false;
  91766. encoder->protected_->min_residual_partition_order = 0;
  91767. encoder->protected_->max_residual_partition_order = 0;
  91768. encoder->protected_->rice_parameter_search_dist = 0;
  91769. encoder->protected_->total_samples_estimate = 0;
  91770. encoder->protected_->metadata = 0;
  91771. encoder->protected_->num_metadata_blocks = 0;
  91772. encoder->private_->seek_table = 0;
  91773. encoder->private_->disable_constant_subframes = false;
  91774. encoder->private_->disable_fixed_subframes = false;
  91775. encoder->private_->disable_verbatim_subframes = false;
  91776. #if FLAC__HAS_OGG
  91777. encoder->private_->is_ogg = false;
  91778. #endif
  91779. encoder->private_->read_callback = 0;
  91780. encoder->private_->write_callback = 0;
  91781. encoder->private_->seek_callback = 0;
  91782. encoder->private_->tell_callback = 0;
  91783. encoder->private_->metadata_callback = 0;
  91784. encoder->private_->progress_callback = 0;
  91785. encoder->private_->client_data = 0;
  91786. #if FLAC__HAS_OGG
  91787. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91788. #endif
  91789. }
  91790. void free_(FLAC__StreamEncoder *encoder)
  91791. {
  91792. unsigned i, channel;
  91793. FLAC__ASSERT(0 != encoder);
  91794. if(encoder->protected_->metadata) {
  91795. free(encoder->protected_->metadata);
  91796. encoder->protected_->metadata = 0;
  91797. encoder->protected_->num_metadata_blocks = 0;
  91798. }
  91799. for(i = 0; i < encoder->protected_->channels; i++) {
  91800. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91801. free(encoder->private_->integer_signal_unaligned[i]);
  91802. encoder->private_->integer_signal_unaligned[i] = 0;
  91803. }
  91804. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91805. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91806. free(encoder->private_->real_signal_unaligned[i]);
  91807. encoder->private_->real_signal_unaligned[i] = 0;
  91808. }
  91809. #endif
  91810. }
  91811. for(i = 0; i < 2; i++) {
  91812. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91813. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91814. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91815. }
  91816. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91817. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91818. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91819. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91820. }
  91821. #endif
  91822. }
  91823. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91824. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91825. if(0 != encoder->private_->window_unaligned[i]) {
  91826. free(encoder->private_->window_unaligned[i]);
  91827. encoder->private_->window_unaligned[i] = 0;
  91828. }
  91829. }
  91830. if(0 != encoder->private_->windowed_signal_unaligned) {
  91831. free(encoder->private_->windowed_signal_unaligned);
  91832. encoder->private_->windowed_signal_unaligned = 0;
  91833. }
  91834. #endif
  91835. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91836. for(i = 0; i < 2; i++) {
  91837. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91838. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91839. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91840. }
  91841. }
  91842. }
  91843. for(channel = 0; channel < 2; channel++) {
  91844. for(i = 0; i < 2; i++) {
  91845. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91846. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91847. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91848. }
  91849. }
  91850. }
  91851. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91852. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91853. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91854. }
  91855. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91856. free(encoder->private_->raw_bits_per_partition_unaligned);
  91857. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91858. }
  91859. if(encoder->protected_->verify) {
  91860. for(i = 0; i < encoder->protected_->channels; i++) {
  91861. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91862. free(encoder->private_->verify.input_fifo.data[i]);
  91863. encoder->private_->verify.input_fifo.data[i] = 0;
  91864. }
  91865. }
  91866. }
  91867. FLAC__bitwriter_free(encoder->private_->frame);
  91868. }
  91869. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91870. {
  91871. FLAC__bool ok;
  91872. unsigned i, channel;
  91873. FLAC__ASSERT(new_blocksize > 0);
  91874. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91875. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91876. if(new_blocksize <= encoder->private_->input_capacity)
  91877. return true;
  91878. ok = true;
  91879. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91880. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91881. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91882. encoder->private_->integer_signal[i] += 4;
  91883. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91884. #if 0 /* @@@ currently unused */
  91885. if(encoder->protected_->max_lpc_order > 0)
  91886. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91887. #endif
  91888. #endif
  91889. }
  91890. for(i = 0; ok && i < 2; i++) {
  91891. 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]);
  91892. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91893. encoder->private_->integer_signal_mid_side[i] += 4;
  91894. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91895. #if 0 /* @@@ currently unused */
  91896. if(encoder->protected_->max_lpc_order > 0)
  91897. 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]);
  91898. #endif
  91899. #endif
  91900. }
  91901. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91902. if(ok && encoder->protected_->max_lpc_order > 0) {
  91903. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91904. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91905. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91906. }
  91907. #endif
  91908. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91909. for(i = 0; ok && i < 2; i++) {
  91910. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91911. }
  91912. }
  91913. for(channel = 0; ok && channel < 2; channel++) {
  91914. for(i = 0; ok && i < 2; i++) {
  91915. 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]);
  91916. }
  91917. }
  91918. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91919. if(encoder->protected_->do_escape_coding)
  91920. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91921. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91922. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91923. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91924. switch(encoder->protected_->apodizations[i].type) {
  91925. case FLAC__APODIZATION_BARTLETT:
  91926. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91927. break;
  91928. case FLAC__APODIZATION_BARTLETT_HANN:
  91929. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91930. break;
  91931. case FLAC__APODIZATION_BLACKMAN:
  91932. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91933. break;
  91934. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91935. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91936. break;
  91937. case FLAC__APODIZATION_CONNES:
  91938. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91939. break;
  91940. case FLAC__APODIZATION_FLATTOP:
  91941. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91942. break;
  91943. case FLAC__APODIZATION_GAUSS:
  91944. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91945. break;
  91946. case FLAC__APODIZATION_HAMMING:
  91947. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91948. break;
  91949. case FLAC__APODIZATION_HANN:
  91950. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91951. break;
  91952. case FLAC__APODIZATION_KAISER_BESSEL:
  91953. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91954. break;
  91955. case FLAC__APODIZATION_NUTTALL:
  91956. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91957. break;
  91958. case FLAC__APODIZATION_RECTANGLE:
  91959. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91960. break;
  91961. case FLAC__APODIZATION_TRIANGLE:
  91962. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91963. break;
  91964. case FLAC__APODIZATION_TUKEY:
  91965. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91966. break;
  91967. case FLAC__APODIZATION_WELCH:
  91968. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91969. break;
  91970. default:
  91971. FLAC__ASSERT(0);
  91972. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91973. break;
  91974. }
  91975. }
  91976. }
  91977. #endif
  91978. if(ok)
  91979. encoder->private_->input_capacity = new_blocksize;
  91980. else
  91981. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91982. return ok;
  91983. }
  91984. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91985. {
  91986. const FLAC__byte *buffer;
  91987. size_t bytes;
  91988. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91989. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91990. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91991. return false;
  91992. }
  91993. if(encoder->protected_->verify) {
  91994. encoder->private_->verify.output.data = buffer;
  91995. encoder->private_->verify.output.bytes = bytes;
  91996. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91997. encoder->private_->verify.needs_magic_hack = true;
  91998. }
  91999. else {
  92000. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  92001. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92002. FLAC__bitwriter_clear(encoder->private_->frame);
  92003. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  92004. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92005. return false;
  92006. }
  92007. }
  92008. }
  92009. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92010. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92011. FLAC__bitwriter_clear(encoder->private_->frame);
  92012. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92013. return false;
  92014. }
  92015. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92016. FLAC__bitwriter_clear(encoder->private_->frame);
  92017. if(samples > 0) {
  92018. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  92019. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  92020. }
  92021. return true;
  92022. }
  92023. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  92024. {
  92025. FLAC__StreamEncoderWriteStatus status;
  92026. FLAC__uint64 output_position = 0;
  92027. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  92028. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92029. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92030. }
  92031. if(samples == 0) {
  92032. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  92033. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  92034. encoder->protected_->streaminfo_offset = output_position;
  92035. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  92036. encoder->protected_->seektable_offset = output_position;
  92037. }
  92038. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  92039. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  92040. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  92041. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  92042. FLAC__uint64 test_sample;
  92043. unsigned i;
  92044. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  92045. test_sample = encoder->private_->seek_table->points[i].sample_number;
  92046. if(test_sample > frame_last_sample) {
  92047. break;
  92048. }
  92049. else if(test_sample >= frame_first_sample) {
  92050. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  92051. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  92052. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  92053. encoder->private_->first_seekpoint_to_check++;
  92054. }
  92055. else {
  92056. encoder->private_->first_seekpoint_to_check++;
  92057. }
  92058. }
  92059. }
  92060. #if FLAC__HAS_OGG
  92061. if(encoder->private_->is_ogg) {
  92062. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  92063. &encoder->protected_->ogg_encoder_aspect,
  92064. buffer,
  92065. bytes,
  92066. samples,
  92067. encoder->private_->current_frame_number,
  92068. is_last_block,
  92069. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  92070. encoder,
  92071. encoder->private_->client_data
  92072. );
  92073. }
  92074. else
  92075. #endif
  92076. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  92077. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92078. encoder->private_->bytes_written += bytes;
  92079. encoder->private_->samples_written += samples;
  92080. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  92081. }
  92082. else
  92083. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92084. return status;
  92085. }
  92086. void update_metadata_(const FLAC__StreamEncoder *encoder)
  92087. {
  92088. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92089. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92090. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92091. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92092. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92093. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  92094. FLAC__StreamEncoderSeekStatus seek_status;
  92095. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92096. {
  92097. const unsigned md5_offset =
  92098. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92099. (
  92100. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92101. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92102. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92103. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92104. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92105. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92106. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92107. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92108. ) / 8;
  92109. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92110. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92111. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92112. return;
  92113. }
  92114. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92115. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92116. return;
  92117. }
  92118. }
  92119. {
  92120. const unsigned total_samples_byte_offset =
  92121. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92122. (
  92123. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92124. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92125. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92126. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92127. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92128. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92129. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92130. - 4
  92131. ) / 8;
  92132. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92133. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92134. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92135. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92136. b[4] = (FLAC__byte)(samples & 0xFF);
  92137. 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) {
  92138. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92139. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92140. return;
  92141. }
  92142. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92143. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92144. return;
  92145. }
  92146. }
  92147. {
  92148. const unsigned min_framesize_offset =
  92149. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92150. (
  92151. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92152. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92153. ) / 8;
  92154. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92155. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92156. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92157. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92158. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92159. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92160. 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) {
  92161. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92162. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92163. return;
  92164. }
  92165. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92166. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92167. return;
  92168. }
  92169. }
  92170. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92171. unsigned i;
  92172. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92173. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92174. 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) {
  92175. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92176. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92177. return;
  92178. }
  92179. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92180. FLAC__uint64 xx;
  92181. unsigned x;
  92182. xx = encoder->private_->seek_table->points[i].sample_number;
  92183. b[7] = (FLAC__byte)xx; xx >>= 8;
  92184. b[6] = (FLAC__byte)xx; xx >>= 8;
  92185. b[5] = (FLAC__byte)xx; xx >>= 8;
  92186. b[4] = (FLAC__byte)xx; xx >>= 8;
  92187. b[3] = (FLAC__byte)xx; xx >>= 8;
  92188. b[2] = (FLAC__byte)xx; xx >>= 8;
  92189. b[1] = (FLAC__byte)xx; xx >>= 8;
  92190. b[0] = (FLAC__byte)xx; xx >>= 8;
  92191. xx = encoder->private_->seek_table->points[i].stream_offset;
  92192. b[15] = (FLAC__byte)xx; xx >>= 8;
  92193. b[14] = (FLAC__byte)xx; xx >>= 8;
  92194. b[13] = (FLAC__byte)xx; xx >>= 8;
  92195. b[12] = (FLAC__byte)xx; xx >>= 8;
  92196. b[11] = (FLAC__byte)xx; xx >>= 8;
  92197. b[10] = (FLAC__byte)xx; xx >>= 8;
  92198. b[9] = (FLAC__byte)xx; xx >>= 8;
  92199. b[8] = (FLAC__byte)xx; xx >>= 8;
  92200. x = encoder->private_->seek_table->points[i].frame_samples;
  92201. b[17] = (FLAC__byte)x; x >>= 8;
  92202. b[16] = (FLAC__byte)x; x >>= 8;
  92203. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92204. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92205. return;
  92206. }
  92207. }
  92208. }
  92209. }
  92210. #if FLAC__HAS_OGG
  92211. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92212. {
  92213. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92214. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92215. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92216. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92217. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92218. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92219. FLAC__STREAM_SYNC_LENGTH
  92220. ;
  92221. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92222. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92223. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92224. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92225. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92226. ogg_page page;
  92227. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92228. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92229. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92230. return;
  92231. simple_ogg_page__init(&page);
  92232. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92233. simple_ogg_page__clear(&page);
  92234. return; /* state already set */
  92235. }
  92236. {
  92237. const unsigned md5_offset =
  92238. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92239. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92240. (
  92241. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92242. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92243. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92244. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92245. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92246. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92247. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92248. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92249. ) / 8;
  92250. if(md5_offset + 16 > (unsigned)page.body_len) {
  92251. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92252. simple_ogg_page__clear(&page);
  92253. return;
  92254. }
  92255. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92256. }
  92257. {
  92258. const unsigned total_samples_byte_offset =
  92259. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92260. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92261. (
  92262. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92263. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92264. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92265. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92266. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92267. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92268. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92269. - 4
  92270. ) / 8;
  92271. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92272. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92273. simple_ogg_page__clear(&page);
  92274. return;
  92275. }
  92276. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92277. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92278. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92279. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92280. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92281. b[4] = (FLAC__byte)(samples & 0xFF);
  92282. memcpy(page.body + total_samples_byte_offset, b, 5);
  92283. }
  92284. {
  92285. const unsigned min_framesize_offset =
  92286. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92287. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92288. (
  92289. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92290. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92291. ) / 8;
  92292. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92293. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92294. simple_ogg_page__clear(&page);
  92295. return;
  92296. }
  92297. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92298. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92299. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92300. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92301. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92302. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92303. memcpy(page.body + min_framesize_offset, b, 6);
  92304. }
  92305. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92306. simple_ogg_page__clear(&page);
  92307. return; /* state already set */
  92308. }
  92309. simple_ogg_page__clear(&page);
  92310. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92311. unsigned i;
  92312. FLAC__byte *p;
  92313. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92314. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92315. simple_ogg_page__init(&page);
  92316. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92317. simple_ogg_page__clear(&page);
  92318. return; /* state already set */
  92319. }
  92320. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92321. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92322. simple_ogg_page__clear(&page);
  92323. return;
  92324. }
  92325. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92326. FLAC__uint64 xx;
  92327. unsigned x;
  92328. xx = encoder->private_->seek_table->points[i].sample_number;
  92329. b[7] = (FLAC__byte)xx; xx >>= 8;
  92330. b[6] = (FLAC__byte)xx; xx >>= 8;
  92331. b[5] = (FLAC__byte)xx; xx >>= 8;
  92332. b[4] = (FLAC__byte)xx; xx >>= 8;
  92333. b[3] = (FLAC__byte)xx; xx >>= 8;
  92334. b[2] = (FLAC__byte)xx; xx >>= 8;
  92335. b[1] = (FLAC__byte)xx; xx >>= 8;
  92336. b[0] = (FLAC__byte)xx; xx >>= 8;
  92337. xx = encoder->private_->seek_table->points[i].stream_offset;
  92338. b[15] = (FLAC__byte)xx; xx >>= 8;
  92339. b[14] = (FLAC__byte)xx; xx >>= 8;
  92340. b[13] = (FLAC__byte)xx; xx >>= 8;
  92341. b[12] = (FLAC__byte)xx; xx >>= 8;
  92342. b[11] = (FLAC__byte)xx; xx >>= 8;
  92343. b[10] = (FLAC__byte)xx; xx >>= 8;
  92344. b[9] = (FLAC__byte)xx; xx >>= 8;
  92345. b[8] = (FLAC__byte)xx; xx >>= 8;
  92346. x = encoder->private_->seek_table->points[i].frame_samples;
  92347. b[17] = (FLAC__byte)x; x >>= 8;
  92348. b[16] = (FLAC__byte)x; x >>= 8;
  92349. memcpy(p, b, 18);
  92350. }
  92351. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92352. simple_ogg_page__clear(&page);
  92353. return; /* state already set */
  92354. }
  92355. simple_ogg_page__clear(&page);
  92356. }
  92357. }
  92358. #endif
  92359. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92360. {
  92361. FLAC__uint16 crc;
  92362. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92363. 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)) {
  92364. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92365. return false;
  92366. }
  92367. if(!process_subframes_(encoder, is_fractional_block)) {
  92368. return false;
  92369. }
  92370. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92371. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92372. return false;
  92373. }
  92374. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92375. if(
  92376. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92377. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92378. ) {
  92379. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92380. return false;
  92381. }
  92382. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92383. return false;
  92384. }
  92385. encoder->private_->current_sample_number = 0;
  92386. encoder->private_->current_frame_number++;
  92387. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92388. return true;
  92389. }
  92390. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92391. {
  92392. FLAC__FrameHeader frame_header;
  92393. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92394. FLAC__bool do_independent, do_mid_side;
  92395. if(is_fractional_block) {
  92396. max_partition_order = 0;
  92397. }
  92398. else {
  92399. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92400. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92401. }
  92402. min_partition_order = min(min_partition_order, max_partition_order);
  92403. frame_header.blocksize = encoder->protected_->blocksize;
  92404. frame_header.sample_rate = encoder->protected_->sample_rate;
  92405. frame_header.channels = encoder->protected_->channels;
  92406. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92407. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92408. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92409. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92410. if(encoder->protected_->do_mid_side_stereo) {
  92411. if(encoder->protected_->loose_mid_side_stereo) {
  92412. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92413. do_independent = true;
  92414. do_mid_side = true;
  92415. }
  92416. else {
  92417. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92418. do_mid_side = !do_independent;
  92419. }
  92420. }
  92421. else {
  92422. do_independent = true;
  92423. do_mid_side = true;
  92424. }
  92425. }
  92426. else {
  92427. do_independent = true;
  92428. do_mid_side = false;
  92429. }
  92430. FLAC__ASSERT(do_independent || do_mid_side);
  92431. if(do_independent) {
  92432. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92433. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92434. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92435. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92436. }
  92437. }
  92438. if(do_mid_side) {
  92439. FLAC__ASSERT(encoder->protected_->channels == 2);
  92440. for(channel = 0; channel < 2; channel++) {
  92441. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92442. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92443. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92444. }
  92445. }
  92446. if(do_independent) {
  92447. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92448. if(!
  92449. process_subframe_(
  92450. encoder,
  92451. min_partition_order,
  92452. max_partition_order,
  92453. &frame_header,
  92454. encoder->private_->subframe_bps[channel],
  92455. encoder->private_->integer_signal[channel],
  92456. encoder->private_->subframe_workspace_ptr[channel],
  92457. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92458. encoder->private_->residual_workspace[channel],
  92459. encoder->private_->best_subframe+channel,
  92460. encoder->private_->best_subframe_bits+channel
  92461. )
  92462. )
  92463. return false;
  92464. }
  92465. }
  92466. if(do_mid_side) {
  92467. FLAC__ASSERT(encoder->protected_->channels == 2);
  92468. for(channel = 0; channel < 2; channel++) {
  92469. if(!
  92470. process_subframe_(
  92471. encoder,
  92472. min_partition_order,
  92473. max_partition_order,
  92474. &frame_header,
  92475. encoder->private_->subframe_bps_mid_side[channel],
  92476. encoder->private_->integer_signal_mid_side[channel],
  92477. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92478. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92479. encoder->private_->residual_workspace_mid_side[channel],
  92480. encoder->private_->best_subframe_mid_side+channel,
  92481. encoder->private_->best_subframe_bits_mid_side+channel
  92482. )
  92483. )
  92484. return false;
  92485. }
  92486. }
  92487. if(do_mid_side) {
  92488. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92489. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92490. FLAC__ChannelAssignment channel_assignment;
  92491. FLAC__ASSERT(encoder->protected_->channels == 2);
  92492. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92493. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92494. }
  92495. else {
  92496. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92497. unsigned min_bits;
  92498. int ca;
  92499. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92500. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92501. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92502. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92503. FLAC__ASSERT(do_independent && do_mid_side);
  92504. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92505. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92506. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92507. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92508. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92509. min_bits = bits[channel_assignment];
  92510. for(ca = 1; ca <= 3; ca++) {
  92511. if(bits[ca] < min_bits) {
  92512. min_bits = bits[ca];
  92513. channel_assignment = (FLAC__ChannelAssignment)ca;
  92514. }
  92515. }
  92516. }
  92517. frame_header.channel_assignment = channel_assignment;
  92518. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92519. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92520. return false;
  92521. }
  92522. switch(channel_assignment) {
  92523. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92524. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92525. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92526. break;
  92527. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92528. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92529. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92530. break;
  92531. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92532. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92533. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92534. break;
  92535. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92536. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92537. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92538. break;
  92539. default:
  92540. FLAC__ASSERT(0);
  92541. }
  92542. switch(channel_assignment) {
  92543. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92544. left_bps = encoder->private_->subframe_bps [0];
  92545. right_bps = encoder->private_->subframe_bps [1];
  92546. break;
  92547. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92548. left_bps = encoder->private_->subframe_bps [0];
  92549. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92550. break;
  92551. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92552. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92553. right_bps = encoder->private_->subframe_bps [1];
  92554. break;
  92555. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92556. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92557. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92558. break;
  92559. default:
  92560. FLAC__ASSERT(0);
  92561. }
  92562. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92563. return false;
  92564. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92565. return false;
  92566. }
  92567. else {
  92568. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92569. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92570. return false;
  92571. }
  92572. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92573. 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)) {
  92574. return false;
  92575. }
  92576. }
  92577. }
  92578. if(encoder->protected_->loose_mid_side_stereo) {
  92579. encoder->private_->loose_mid_side_stereo_frame_count++;
  92580. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92581. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92582. }
  92583. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92584. return true;
  92585. }
  92586. FLAC__bool process_subframe_(
  92587. FLAC__StreamEncoder *encoder,
  92588. unsigned min_partition_order,
  92589. unsigned max_partition_order,
  92590. const FLAC__FrameHeader *frame_header,
  92591. unsigned subframe_bps,
  92592. const FLAC__int32 integer_signal[],
  92593. FLAC__Subframe *subframe[2],
  92594. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92595. FLAC__int32 *residual[2],
  92596. unsigned *best_subframe,
  92597. unsigned *best_bits
  92598. )
  92599. {
  92600. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92601. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92602. #else
  92603. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92604. #endif
  92605. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92606. FLAC__double lpc_residual_bits_per_sample;
  92607. 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 */
  92608. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92609. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92610. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92611. #endif
  92612. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92613. unsigned rice_parameter;
  92614. unsigned _candidate_bits, _best_bits;
  92615. unsigned _best_subframe;
  92616. 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;
  92617. FLAC__ASSERT(frame_header->blocksize > 0);
  92618. _best_subframe = 0;
  92619. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92620. _best_bits = UINT_MAX;
  92621. else
  92622. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92623. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92624. unsigned signal_is_constant = false;
  92625. 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);
  92626. if(
  92627. !encoder->private_->disable_constant_subframes &&
  92628. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92629. fixed_residual_bits_per_sample[1] == 0.0
  92630. #else
  92631. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92632. #endif
  92633. ) {
  92634. unsigned i;
  92635. signal_is_constant = true;
  92636. for(i = 1; i < frame_header->blocksize; i++) {
  92637. if(integer_signal[0] != integer_signal[i]) {
  92638. signal_is_constant = false;
  92639. break;
  92640. }
  92641. }
  92642. }
  92643. if(signal_is_constant) {
  92644. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92645. if(_candidate_bits < _best_bits) {
  92646. _best_subframe = !_best_subframe;
  92647. _best_bits = _candidate_bits;
  92648. }
  92649. }
  92650. else {
  92651. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92652. if(encoder->protected_->do_exhaustive_model_search) {
  92653. min_fixed_order = 0;
  92654. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92655. }
  92656. else {
  92657. min_fixed_order = max_fixed_order = guess_fixed_order;
  92658. }
  92659. if(max_fixed_order >= frame_header->blocksize)
  92660. max_fixed_order = frame_header->blocksize - 1;
  92661. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92662. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92663. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92664. continue; /* don't even try */
  92665. 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 */
  92666. #else
  92667. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92668. continue; /* don't even try */
  92669. 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 */
  92670. #endif
  92671. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92672. if(rice_parameter >= rice_parameter_limit) {
  92673. #ifdef DEBUG_VERBOSE
  92674. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92675. #endif
  92676. rice_parameter = rice_parameter_limit - 1;
  92677. }
  92678. _candidate_bits =
  92679. evaluate_fixed_subframe_(
  92680. encoder,
  92681. integer_signal,
  92682. residual[!_best_subframe],
  92683. encoder->private_->abs_residual_partition_sums,
  92684. encoder->private_->raw_bits_per_partition,
  92685. frame_header->blocksize,
  92686. subframe_bps,
  92687. fixed_order,
  92688. rice_parameter,
  92689. rice_parameter_limit,
  92690. min_partition_order,
  92691. max_partition_order,
  92692. encoder->protected_->do_escape_coding,
  92693. encoder->protected_->rice_parameter_search_dist,
  92694. subframe[!_best_subframe],
  92695. partitioned_rice_contents[!_best_subframe]
  92696. );
  92697. if(_candidate_bits < _best_bits) {
  92698. _best_subframe = !_best_subframe;
  92699. _best_bits = _candidate_bits;
  92700. }
  92701. }
  92702. }
  92703. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92704. if(encoder->protected_->max_lpc_order > 0) {
  92705. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92706. max_lpc_order = frame_header->blocksize-1;
  92707. else
  92708. max_lpc_order = encoder->protected_->max_lpc_order;
  92709. if(max_lpc_order > 0) {
  92710. unsigned a;
  92711. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92712. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92713. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92714. if(autoc[0] != 0.0) {
  92715. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92716. if(encoder->protected_->do_exhaustive_model_search) {
  92717. min_lpc_order = 1;
  92718. }
  92719. else {
  92720. const unsigned guess_lpc_order =
  92721. FLAC__lpc_compute_best_order(
  92722. lpc_error,
  92723. max_lpc_order,
  92724. frame_header->blocksize,
  92725. subframe_bps + (
  92726. encoder->protected_->do_qlp_coeff_prec_search?
  92727. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92728. encoder->protected_->qlp_coeff_precision
  92729. )
  92730. );
  92731. min_lpc_order = max_lpc_order = guess_lpc_order;
  92732. }
  92733. if(max_lpc_order >= frame_header->blocksize)
  92734. max_lpc_order = frame_header->blocksize - 1;
  92735. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92736. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92737. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92738. continue; /* don't even try */
  92739. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92740. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92741. if(rice_parameter >= rice_parameter_limit) {
  92742. #ifdef DEBUG_VERBOSE
  92743. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92744. #endif
  92745. rice_parameter = rice_parameter_limit - 1;
  92746. }
  92747. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92748. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92749. if(subframe_bps <= 17) {
  92750. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92751. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92752. }
  92753. else
  92754. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92755. }
  92756. else {
  92757. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92758. }
  92759. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92760. _candidate_bits =
  92761. evaluate_lpc_subframe_(
  92762. encoder,
  92763. integer_signal,
  92764. residual[!_best_subframe],
  92765. encoder->private_->abs_residual_partition_sums,
  92766. encoder->private_->raw_bits_per_partition,
  92767. encoder->private_->lp_coeff[lpc_order-1],
  92768. frame_header->blocksize,
  92769. subframe_bps,
  92770. lpc_order,
  92771. qlp_coeff_precision,
  92772. rice_parameter,
  92773. rice_parameter_limit,
  92774. min_partition_order,
  92775. max_partition_order,
  92776. encoder->protected_->do_escape_coding,
  92777. encoder->protected_->rice_parameter_search_dist,
  92778. subframe[!_best_subframe],
  92779. partitioned_rice_contents[!_best_subframe]
  92780. );
  92781. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92782. if(_candidate_bits < _best_bits) {
  92783. _best_subframe = !_best_subframe;
  92784. _best_bits = _candidate_bits;
  92785. }
  92786. }
  92787. }
  92788. }
  92789. }
  92790. }
  92791. }
  92792. }
  92793. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92794. }
  92795. }
  92796. if(_best_bits == UINT_MAX) {
  92797. FLAC__ASSERT(_best_subframe == 0);
  92798. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92799. }
  92800. *best_subframe = _best_subframe;
  92801. *best_bits = _best_bits;
  92802. return true;
  92803. }
  92804. FLAC__bool add_subframe_(
  92805. FLAC__StreamEncoder *encoder,
  92806. unsigned blocksize,
  92807. unsigned subframe_bps,
  92808. const FLAC__Subframe *subframe,
  92809. FLAC__BitWriter *frame
  92810. )
  92811. {
  92812. switch(subframe->type) {
  92813. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92814. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92815. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92816. return false;
  92817. }
  92818. break;
  92819. case FLAC__SUBFRAME_TYPE_FIXED:
  92820. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92821. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92822. return false;
  92823. }
  92824. break;
  92825. case FLAC__SUBFRAME_TYPE_LPC:
  92826. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92827. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92828. return false;
  92829. }
  92830. break;
  92831. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92832. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92833. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92834. return false;
  92835. }
  92836. break;
  92837. default:
  92838. FLAC__ASSERT(0);
  92839. }
  92840. return true;
  92841. }
  92842. #define SPOTCHECK_ESTIMATE 0
  92843. #if SPOTCHECK_ESTIMATE
  92844. static void spotcheck_subframe_estimate_(
  92845. FLAC__StreamEncoder *encoder,
  92846. unsigned blocksize,
  92847. unsigned subframe_bps,
  92848. const FLAC__Subframe *subframe,
  92849. unsigned estimate
  92850. )
  92851. {
  92852. FLAC__bool ret;
  92853. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92854. if(frame == 0) {
  92855. fprintf(stderr, "EST: can't allocate frame\n");
  92856. return;
  92857. }
  92858. if(!FLAC__bitwriter_init(frame)) {
  92859. fprintf(stderr, "EST: can't init frame\n");
  92860. return;
  92861. }
  92862. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92863. FLAC__ASSERT(ret);
  92864. {
  92865. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92866. if(estimate != actual)
  92867. 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);
  92868. }
  92869. FLAC__bitwriter_delete(frame);
  92870. }
  92871. #endif
  92872. unsigned evaluate_constant_subframe_(
  92873. FLAC__StreamEncoder *encoder,
  92874. const FLAC__int32 signal,
  92875. unsigned blocksize,
  92876. unsigned subframe_bps,
  92877. FLAC__Subframe *subframe
  92878. )
  92879. {
  92880. unsigned estimate;
  92881. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92882. subframe->data.constant.value = signal;
  92883. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92884. #if SPOTCHECK_ESTIMATE
  92885. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92886. #else
  92887. (void)encoder, (void)blocksize;
  92888. #endif
  92889. return estimate;
  92890. }
  92891. unsigned evaluate_fixed_subframe_(
  92892. FLAC__StreamEncoder *encoder,
  92893. const FLAC__int32 signal[],
  92894. FLAC__int32 residual[],
  92895. FLAC__uint64 abs_residual_partition_sums[],
  92896. unsigned raw_bits_per_partition[],
  92897. unsigned blocksize,
  92898. unsigned subframe_bps,
  92899. unsigned order,
  92900. unsigned rice_parameter,
  92901. unsigned rice_parameter_limit,
  92902. unsigned min_partition_order,
  92903. unsigned max_partition_order,
  92904. FLAC__bool do_escape_coding,
  92905. unsigned rice_parameter_search_dist,
  92906. FLAC__Subframe *subframe,
  92907. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92908. )
  92909. {
  92910. unsigned i, residual_bits, estimate;
  92911. const unsigned residual_samples = blocksize - order;
  92912. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92913. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92914. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92915. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92916. subframe->data.fixed.residual = residual;
  92917. residual_bits =
  92918. find_best_partition_order_(
  92919. encoder->private_,
  92920. residual,
  92921. abs_residual_partition_sums,
  92922. raw_bits_per_partition,
  92923. residual_samples,
  92924. order,
  92925. rice_parameter,
  92926. rice_parameter_limit,
  92927. min_partition_order,
  92928. max_partition_order,
  92929. subframe_bps,
  92930. do_escape_coding,
  92931. rice_parameter_search_dist,
  92932. &subframe->data.fixed.entropy_coding_method
  92933. );
  92934. subframe->data.fixed.order = order;
  92935. for(i = 0; i < order; i++)
  92936. subframe->data.fixed.warmup[i] = signal[i];
  92937. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92938. #if SPOTCHECK_ESTIMATE
  92939. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92940. #endif
  92941. return estimate;
  92942. }
  92943. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92944. unsigned evaluate_lpc_subframe_(
  92945. FLAC__StreamEncoder *encoder,
  92946. const FLAC__int32 signal[],
  92947. FLAC__int32 residual[],
  92948. FLAC__uint64 abs_residual_partition_sums[],
  92949. unsigned raw_bits_per_partition[],
  92950. const FLAC__real lp_coeff[],
  92951. unsigned blocksize,
  92952. unsigned subframe_bps,
  92953. unsigned order,
  92954. unsigned qlp_coeff_precision,
  92955. unsigned rice_parameter,
  92956. unsigned rice_parameter_limit,
  92957. unsigned min_partition_order,
  92958. unsigned max_partition_order,
  92959. FLAC__bool do_escape_coding,
  92960. unsigned rice_parameter_search_dist,
  92961. FLAC__Subframe *subframe,
  92962. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92963. )
  92964. {
  92965. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92966. unsigned i, residual_bits, estimate;
  92967. int quantization, ret;
  92968. const unsigned residual_samples = blocksize - order;
  92969. if(subframe_bps <= 16) {
  92970. FLAC__ASSERT(order > 0);
  92971. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92972. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92973. }
  92974. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92975. if(ret != 0)
  92976. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92977. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92978. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92979. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92980. else
  92981. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92982. else
  92983. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92984. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92985. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92986. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92987. subframe->data.lpc.residual = residual;
  92988. residual_bits =
  92989. find_best_partition_order_(
  92990. encoder->private_,
  92991. residual,
  92992. abs_residual_partition_sums,
  92993. raw_bits_per_partition,
  92994. residual_samples,
  92995. order,
  92996. rice_parameter,
  92997. rice_parameter_limit,
  92998. min_partition_order,
  92999. max_partition_order,
  93000. subframe_bps,
  93001. do_escape_coding,
  93002. rice_parameter_search_dist,
  93003. &subframe->data.lpc.entropy_coding_method
  93004. );
  93005. subframe->data.lpc.order = order;
  93006. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  93007. subframe->data.lpc.quantization_level = quantization;
  93008. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  93009. for(i = 0; i < order; i++)
  93010. subframe->data.lpc.warmup[i] = signal[i];
  93011. 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;
  93012. #if SPOTCHECK_ESTIMATE
  93013. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93014. #endif
  93015. return estimate;
  93016. }
  93017. #endif
  93018. unsigned evaluate_verbatim_subframe_(
  93019. FLAC__StreamEncoder *encoder,
  93020. const FLAC__int32 signal[],
  93021. unsigned blocksize,
  93022. unsigned subframe_bps,
  93023. FLAC__Subframe *subframe
  93024. )
  93025. {
  93026. unsigned estimate;
  93027. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  93028. subframe->data.verbatim.data = signal;
  93029. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  93030. #if SPOTCHECK_ESTIMATE
  93031. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93032. #else
  93033. (void)encoder;
  93034. #endif
  93035. return estimate;
  93036. }
  93037. unsigned find_best_partition_order_(
  93038. FLAC__StreamEncoderPrivate *private_,
  93039. const FLAC__int32 residual[],
  93040. FLAC__uint64 abs_residual_partition_sums[],
  93041. unsigned raw_bits_per_partition[],
  93042. unsigned residual_samples,
  93043. unsigned predictor_order,
  93044. unsigned rice_parameter,
  93045. unsigned rice_parameter_limit,
  93046. unsigned min_partition_order,
  93047. unsigned max_partition_order,
  93048. unsigned bps,
  93049. FLAC__bool do_escape_coding,
  93050. unsigned rice_parameter_search_dist,
  93051. FLAC__EntropyCodingMethod *best_ecm
  93052. )
  93053. {
  93054. unsigned residual_bits, best_residual_bits = 0;
  93055. unsigned best_parameters_index = 0;
  93056. unsigned best_partition_order = 0;
  93057. const unsigned blocksize = residual_samples + predictor_order;
  93058. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  93059. min_partition_order = min(min_partition_order, max_partition_order);
  93060. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  93061. if(do_escape_coding)
  93062. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  93063. {
  93064. int partition_order;
  93065. unsigned sum;
  93066. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  93067. if(!
  93068. set_partitioned_rice_(
  93069. #ifdef EXACT_RICE_BITS_CALCULATION
  93070. residual,
  93071. #endif
  93072. abs_residual_partition_sums+sum,
  93073. raw_bits_per_partition+sum,
  93074. residual_samples,
  93075. predictor_order,
  93076. rice_parameter,
  93077. rice_parameter_limit,
  93078. rice_parameter_search_dist,
  93079. (unsigned)partition_order,
  93080. do_escape_coding,
  93081. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  93082. &residual_bits
  93083. )
  93084. )
  93085. {
  93086. FLAC__ASSERT(best_residual_bits != 0);
  93087. break;
  93088. }
  93089. sum += 1u << partition_order;
  93090. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  93091. best_residual_bits = residual_bits;
  93092. best_parameters_index = !best_parameters_index;
  93093. best_partition_order = partition_order;
  93094. }
  93095. }
  93096. }
  93097. best_ecm->data.partitioned_rice.order = best_partition_order;
  93098. {
  93099. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93100. unsigned partition;
  93101. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93102. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93103. if(do_escape_coding)
  93104. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93105. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93106. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93107. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93108. break;
  93109. }
  93110. }
  93111. }
  93112. return best_residual_bits;
  93113. }
  93114. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93115. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93116. const FLAC__int32 residual[],
  93117. FLAC__uint64 abs_residual_partition_sums[],
  93118. unsigned blocksize,
  93119. unsigned predictor_order,
  93120. unsigned min_partition_order,
  93121. unsigned max_partition_order
  93122. );
  93123. #endif
  93124. void precompute_partition_info_sums_(
  93125. const FLAC__int32 residual[],
  93126. FLAC__uint64 abs_residual_partition_sums[],
  93127. unsigned residual_samples,
  93128. unsigned predictor_order,
  93129. unsigned min_partition_order,
  93130. unsigned max_partition_order,
  93131. unsigned bps
  93132. )
  93133. {
  93134. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93135. unsigned partitions = 1u << max_partition_order;
  93136. FLAC__ASSERT(default_partition_samples > predictor_order);
  93137. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93138. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93139. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93140. return;
  93141. }
  93142. #endif
  93143. {
  93144. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93145. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93146. FLAC__uint32 abs_residual_partition_sum;
  93147. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93148. end += default_partition_samples;
  93149. abs_residual_partition_sum = 0;
  93150. for( ; residual_sample < end; residual_sample++)
  93151. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93152. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93153. }
  93154. }
  93155. else { /* have to pessimistically use 64 bits for accumulator */
  93156. FLAC__uint64 abs_residual_partition_sum;
  93157. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93158. end += default_partition_samples;
  93159. abs_residual_partition_sum = 0;
  93160. for( ; residual_sample < end; residual_sample++)
  93161. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93162. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93163. }
  93164. }
  93165. }
  93166. {
  93167. unsigned from_partition = 0, to_partition = partitions;
  93168. int partition_order;
  93169. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93170. unsigned i;
  93171. partitions >>= 1;
  93172. for(i = 0; i < partitions; i++) {
  93173. abs_residual_partition_sums[to_partition++] =
  93174. abs_residual_partition_sums[from_partition ] +
  93175. abs_residual_partition_sums[from_partition+1];
  93176. from_partition += 2;
  93177. }
  93178. }
  93179. }
  93180. }
  93181. void precompute_partition_info_escapes_(
  93182. const FLAC__int32 residual[],
  93183. unsigned raw_bits_per_partition[],
  93184. unsigned residual_samples,
  93185. unsigned predictor_order,
  93186. unsigned min_partition_order,
  93187. unsigned max_partition_order
  93188. )
  93189. {
  93190. int partition_order;
  93191. unsigned from_partition, to_partition = 0;
  93192. const unsigned blocksize = residual_samples + predictor_order;
  93193. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93194. FLAC__int32 r;
  93195. FLAC__uint32 rmax;
  93196. unsigned partition, partition_sample, partition_samples, residual_sample;
  93197. const unsigned partitions = 1u << partition_order;
  93198. const unsigned default_partition_samples = blocksize >> partition_order;
  93199. FLAC__ASSERT(default_partition_samples > predictor_order);
  93200. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93201. partition_samples = default_partition_samples;
  93202. if(partition == 0)
  93203. partition_samples -= predictor_order;
  93204. rmax = 0;
  93205. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93206. r = residual[residual_sample++];
  93207. if(r < 0)
  93208. rmax |= ~r;
  93209. else
  93210. rmax |= r;
  93211. }
  93212. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93213. }
  93214. to_partition = partitions;
  93215. break; /*@@@ yuck, should remove the 'for' loop instead */
  93216. }
  93217. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93218. unsigned m;
  93219. unsigned i;
  93220. const unsigned partitions = 1u << partition_order;
  93221. for(i = 0; i < partitions; i++) {
  93222. m = raw_bits_per_partition[from_partition];
  93223. from_partition++;
  93224. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93225. from_partition++;
  93226. to_partition++;
  93227. }
  93228. }
  93229. }
  93230. #ifdef EXACT_RICE_BITS_CALCULATION
  93231. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93232. const unsigned rice_parameter,
  93233. const unsigned partition_samples,
  93234. const FLAC__int32 *residual
  93235. )
  93236. {
  93237. unsigned i, partition_bits =
  93238. 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 */
  93239. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93240. ;
  93241. for(i = 0; i < partition_samples; i++)
  93242. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93243. return partition_bits;
  93244. }
  93245. #else
  93246. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93247. const unsigned rice_parameter,
  93248. const unsigned partition_samples,
  93249. const FLAC__uint64 abs_residual_partition_sum
  93250. )
  93251. {
  93252. return
  93253. 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 */
  93254. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93255. (
  93256. rice_parameter?
  93257. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93258. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93259. )
  93260. - (partition_samples >> 1)
  93261. ;
  93262. }
  93263. #endif
  93264. FLAC__bool set_partitioned_rice_(
  93265. #ifdef EXACT_RICE_BITS_CALCULATION
  93266. const FLAC__int32 residual[],
  93267. #endif
  93268. const FLAC__uint64 abs_residual_partition_sums[],
  93269. const unsigned raw_bits_per_partition[],
  93270. const unsigned residual_samples,
  93271. const unsigned predictor_order,
  93272. const unsigned suggested_rice_parameter,
  93273. const unsigned rice_parameter_limit,
  93274. const unsigned rice_parameter_search_dist,
  93275. const unsigned partition_order,
  93276. const FLAC__bool search_for_escapes,
  93277. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93278. unsigned *bits
  93279. )
  93280. {
  93281. unsigned rice_parameter, partition_bits;
  93282. unsigned best_partition_bits, best_rice_parameter = 0;
  93283. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93284. unsigned *parameters, *raw_bits;
  93285. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93286. unsigned min_rice_parameter, max_rice_parameter;
  93287. #else
  93288. (void)rice_parameter_search_dist;
  93289. #endif
  93290. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93291. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93292. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93293. parameters = partitioned_rice_contents->parameters;
  93294. raw_bits = partitioned_rice_contents->raw_bits;
  93295. if(partition_order == 0) {
  93296. best_partition_bits = (unsigned)(-1);
  93297. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93298. if(rice_parameter_search_dist) {
  93299. if(suggested_rice_parameter < rice_parameter_search_dist)
  93300. min_rice_parameter = 0;
  93301. else
  93302. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93303. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93304. if(max_rice_parameter >= rice_parameter_limit) {
  93305. #ifdef DEBUG_VERBOSE
  93306. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93307. #endif
  93308. max_rice_parameter = rice_parameter_limit - 1;
  93309. }
  93310. }
  93311. else
  93312. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93313. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93314. #else
  93315. rice_parameter = suggested_rice_parameter;
  93316. #endif
  93317. #ifdef EXACT_RICE_BITS_CALCULATION
  93318. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93319. #else
  93320. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93321. #endif
  93322. if(partition_bits < best_partition_bits) {
  93323. best_rice_parameter = rice_parameter;
  93324. best_partition_bits = partition_bits;
  93325. }
  93326. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93327. }
  93328. #endif
  93329. if(search_for_escapes) {
  93330. 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;
  93331. if(partition_bits <= best_partition_bits) {
  93332. raw_bits[0] = raw_bits_per_partition[0];
  93333. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93334. best_partition_bits = partition_bits;
  93335. }
  93336. else
  93337. raw_bits[0] = 0;
  93338. }
  93339. parameters[0] = best_rice_parameter;
  93340. bits_ += best_partition_bits;
  93341. }
  93342. else {
  93343. unsigned partition, residual_sample;
  93344. unsigned partition_samples;
  93345. FLAC__uint64 mean, k;
  93346. const unsigned partitions = 1u << partition_order;
  93347. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93348. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93349. if(partition == 0) {
  93350. if(partition_samples <= predictor_order)
  93351. return false;
  93352. else
  93353. partition_samples -= predictor_order;
  93354. }
  93355. mean = abs_residual_partition_sums[partition];
  93356. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93357. ;
  93358. if(rice_parameter >= rice_parameter_limit) {
  93359. #ifdef DEBUG_VERBOSE
  93360. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93361. #endif
  93362. rice_parameter = rice_parameter_limit - 1;
  93363. }
  93364. best_partition_bits = (unsigned)(-1);
  93365. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93366. if(rice_parameter_search_dist) {
  93367. if(rice_parameter < rice_parameter_search_dist)
  93368. min_rice_parameter = 0;
  93369. else
  93370. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93371. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93372. if(max_rice_parameter >= rice_parameter_limit) {
  93373. #ifdef DEBUG_VERBOSE
  93374. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93375. #endif
  93376. max_rice_parameter = rice_parameter_limit - 1;
  93377. }
  93378. }
  93379. else
  93380. min_rice_parameter = max_rice_parameter = rice_parameter;
  93381. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93382. #endif
  93383. #ifdef EXACT_RICE_BITS_CALCULATION
  93384. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93385. #else
  93386. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93387. #endif
  93388. if(partition_bits < best_partition_bits) {
  93389. best_rice_parameter = rice_parameter;
  93390. best_partition_bits = partition_bits;
  93391. }
  93392. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93393. }
  93394. #endif
  93395. if(search_for_escapes) {
  93396. 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;
  93397. if(partition_bits <= best_partition_bits) {
  93398. raw_bits[partition] = raw_bits_per_partition[partition];
  93399. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93400. best_partition_bits = partition_bits;
  93401. }
  93402. else
  93403. raw_bits[partition] = 0;
  93404. }
  93405. parameters[partition] = best_rice_parameter;
  93406. bits_ += best_partition_bits;
  93407. residual_sample += partition_samples;
  93408. }
  93409. }
  93410. *bits = bits_;
  93411. return true;
  93412. }
  93413. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93414. {
  93415. unsigned i, shift;
  93416. FLAC__int32 x = 0;
  93417. for(i = 0; i < samples && !(x&1); i++)
  93418. x |= signal[i];
  93419. if(x == 0) {
  93420. shift = 0;
  93421. }
  93422. else {
  93423. for(shift = 0; !(x&1); shift++)
  93424. x >>= 1;
  93425. }
  93426. if(shift > 0) {
  93427. for(i = 0; i < samples; i++)
  93428. signal[i] >>= shift;
  93429. }
  93430. return shift;
  93431. }
  93432. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93433. {
  93434. unsigned channel;
  93435. for(channel = 0; channel < channels; channel++)
  93436. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93437. fifo->tail += wide_samples;
  93438. FLAC__ASSERT(fifo->tail <= fifo->size);
  93439. }
  93440. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93441. {
  93442. unsigned channel;
  93443. unsigned sample, wide_sample;
  93444. unsigned tail = fifo->tail;
  93445. sample = input_offset * channels;
  93446. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93447. for(channel = 0; channel < channels; channel++)
  93448. fifo->data[channel][tail] = input[sample++];
  93449. tail++;
  93450. }
  93451. fifo->tail = tail;
  93452. FLAC__ASSERT(fifo->tail <= fifo->size);
  93453. }
  93454. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93455. {
  93456. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93457. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93458. (void)decoder;
  93459. if(encoder->private_->verify.needs_magic_hack) {
  93460. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93461. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93462. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93463. encoder->private_->verify.needs_magic_hack = false;
  93464. }
  93465. else {
  93466. if(encoded_bytes == 0) {
  93467. FLAC__ASSERT(0);
  93468. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93469. }
  93470. else if(encoded_bytes < *bytes)
  93471. *bytes = encoded_bytes;
  93472. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93473. encoder->private_->verify.output.data += *bytes;
  93474. encoder->private_->verify.output.bytes -= *bytes;
  93475. }
  93476. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93477. }
  93478. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93479. {
  93480. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93481. unsigned channel;
  93482. const unsigned channels = frame->header.channels;
  93483. const unsigned blocksize = frame->header.blocksize;
  93484. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93485. (void)decoder;
  93486. for(channel = 0; channel < channels; channel++) {
  93487. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93488. unsigned i, sample = 0;
  93489. FLAC__int32 expect = 0, got = 0;
  93490. for(i = 0; i < blocksize; i++) {
  93491. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93492. sample = i;
  93493. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93494. got = (FLAC__int32)buffer[channel][i];
  93495. break;
  93496. }
  93497. }
  93498. FLAC__ASSERT(i < blocksize);
  93499. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93500. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93501. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93502. encoder->private_->verify.error_stats.channel = channel;
  93503. encoder->private_->verify.error_stats.sample = sample;
  93504. encoder->private_->verify.error_stats.expected = expect;
  93505. encoder->private_->verify.error_stats.got = got;
  93506. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93507. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93508. }
  93509. }
  93510. encoder->private_->verify.input_fifo.tail -= blocksize;
  93511. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93512. for(channel = 0; channel < channels; channel++)
  93513. 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]));
  93514. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93515. }
  93516. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93517. {
  93518. (void)decoder, (void)metadata, (void)client_data;
  93519. }
  93520. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93521. {
  93522. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93523. (void)decoder, (void)status;
  93524. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93525. }
  93526. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93527. {
  93528. (void)client_data;
  93529. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93530. if (*bytes == 0) {
  93531. if (feof(encoder->private_->file))
  93532. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93533. else if (ferror(encoder->private_->file))
  93534. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93535. }
  93536. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93537. }
  93538. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93539. {
  93540. (void)client_data;
  93541. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93542. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93543. else
  93544. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93545. }
  93546. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93547. {
  93548. off_t offset;
  93549. (void)client_data;
  93550. offset = ftello(encoder->private_->file);
  93551. if(offset < 0) {
  93552. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93553. }
  93554. else {
  93555. *absolute_byte_offset = (FLAC__uint64)offset;
  93556. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93557. }
  93558. }
  93559. #ifdef FLAC__VALGRIND_TESTING
  93560. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93561. {
  93562. size_t ret = fwrite(ptr, size, nmemb, stream);
  93563. if(!ferror(stream))
  93564. fflush(stream);
  93565. return ret;
  93566. }
  93567. #else
  93568. #define local__fwrite fwrite
  93569. #endif
  93570. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93571. {
  93572. (void)client_data, (void)current_frame;
  93573. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93574. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93575. #if FLAC__HAS_OGG
  93576. encoder->private_->is_ogg? true :
  93577. #endif
  93578. samples > 0
  93579. );
  93580. if(call_it) {
  93581. 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);
  93582. }
  93583. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93584. }
  93585. else
  93586. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93587. }
  93588. FILE *get_binary_stdout_(void)
  93589. {
  93590. #if defined _MSC_VER || defined __MINGW32__
  93591. _setmode(_fileno(stdout), _O_BINARY);
  93592. #elif defined __CYGWIN__
  93593. setmode(_fileno(stdout), _O_BINARY);
  93594. #elif defined __EMX__
  93595. setmode(fileno(stdout), O_BINARY);
  93596. #endif
  93597. return stdout;
  93598. }
  93599. #endif
  93600. /*** End of inlined file: stream_encoder.c ***/
  93601. /*** Start of inlined file: stream_encoder_framing.c ***/
  93602. /*** Start of inlined file: juce_FlacHeader.h ***/
  93603. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93604. // tasks..
  93605. #define VERSION "1.2.1"
  93606. #define FLAC__NO_DLL 1
  93607. #if JUCE_MSVC
  93608. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93609. #endif
  93610. #if JUCE_MAC
  93611. #define FLAC__SYS_DARWIN 1
  93612. #endif
  93613. /*** End of inlined file: juce_FlacHeader.h ***/
  93614. #if JUCE_USE_FLAC
  93615. #if HAVE_CONFIG_H
  93616. # include <config.h>
  93617. #endif
  93618. #include <stdio.h>
  93619. #include <string.h> /* for strlen() */
  93620. #ifdef max
  93621. #undef max
  93622. #endif
  93623. #define max(x,y) ((x)>(y)?(x):(y))
  93624. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93625. 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);
  93626. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93627. {
  93628. unsigned i, j;
  93629. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93630. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93631. return false;
  93632. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93633. return false;
  93634. i = metadata->length;
  93635. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93636. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93637. i -= metadata->data.vorbis_comment.vendor_string.length;
  93638. i += vendor_string_length;
  93639. }
  93640. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93641. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93642. return false;
  93643. switch(metadata->type) {
  93644. case FLAC__METADATA_TYPE_STREAMINFO:
  93645. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93646. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93647. return false;
  93648. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93649. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93650. return false;
  93651. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93652. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93653. return false;
  93654. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93655. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93656. return false;
  93657. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93658. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93659. return false;
  93660. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93661. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93662. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93663. return false;
  93664. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93665. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93666. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93667. return false;
  93668. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93669. return false;
  93670. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93671. return false;
  93672. break;
  93673. case FLAC__METADATA_TYPE_PADDING:
  93674. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93675. return false;
  93676. break;
  93677. case FLAC__METADATA_TYPE_APPLICATION:
  93678. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93679. return false;
  93680. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93681. return false;
  93682. break;
  93683. case FLAC__METADATA_TYPE_SEEKTABLE:
  93684. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93685. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93686. return false;
  93687. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93688. return false;
  93689. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93690. return false;
  93691. }
  93692. break;
  93693. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93694. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93695. return false;
  93696. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93697. return false;
  93698. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93699. return false;
  93700. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93701. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93702. return false;
  93703. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93704. return false;
  93705. }
  93706. break;
  93707. case FLAC__METADATA_TYPE_CUESHEET:
  93708. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93709. 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))
  93710. return false;
  93711. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93712. return false;
  93713. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93714. return false;
  93715. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93716. return false;
  93717. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93718. return false;
  93719. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93720. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93721. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93722. return false;
  93723. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93724. return false;
  93725. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93726. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93727. return false;
  93728. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93729. return false;
  93730. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93731. return false;
  93732. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93733. return false;
  93734. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93735. return false;
  93736. for(j = 0; j < track->num_indices; j++) {
  93737. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93738. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93739. return false;
  93740. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93741. return false;
  93742. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93743. return false;
  93744. }
  93745. }
  93746. break;
  93747. case FLAC__METADATA_TYPE_PICTURE:
  93748. {
  93749. size_t len;
  93750. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93751. return false;
  93752. len = strlen(metadata->data.picture.mime_type);
  93753. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93754. return false;
  93755. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93756. return false;
  93757. len = strlen((const char *)metadata->data.picture.description);
  93758. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93759. return false;
  93760. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93761. return false;
  93762. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93763. return false;
  93764. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93765. return false;
  93766. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93767. return false;
  93768. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93769. return false;
  93770. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93771. return false;
  93772. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93773. return false;
  93774. }
  93775. break;
  93776. default:
  93777. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93778. return false;
  93779. break;
  93780. }
  93781. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93782. return true;
  93783. }
  93784. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93785. {
  93786. unsigned u, blocksize_hint, sample_rate_hint;
  93787. FLAC__byte crc;
  93788. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93789. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93790. return false;
  93791. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93792. return false;
  93793. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93794. return false;
  93795. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93796. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93797. blocksize_hint = 0;
  93798. switch(header->blocksize) {
  93799. case 192: u = 1; break;
  93800. case 576: u = 2; break;
  93801. case 1152: u = 3; break;
  93802. case 2304: u = 4; break;
  93803. case 4608: u = 5; break;
  93804. case 256: u = 8; break;
  93805. case 512: u = 9; break;
  93806. case 1024: u = 10; break;
  93807. case 2048: u = 11; break;
  93808. case 4096: u = 12; break;
  93809. case 8192: u = 13; break;
  93810. case 16384: u = 14; break;
  93811. case 32768: u = 15; break;
  93812. default:
  93813. if(header->blocksize <= 0x100)
  93814. blocksize_hint = u = 6;
  93815. else
  93816. blocksize_hint = u = 7;
  93817. break;
  93818. }
  93819. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93820. return false;
  93821. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93822. sample_rate_hint = 0;
  93823. switch(header->sample_rate) {
  93824. case 88200: u = 1; break;
  93825. case 176400: u = 2; break;
  93826. case 192000: u = 3; break;
  93827. case 8000: u = 4; break;
  93828. case 16000: u = 5; break;
  93829. case 22050: u = 6; break;
  93830. case 24000: u = 7; break;
  93831. case 32000: u = 8; break;
  93832. case 44100: u = 9; break;
  93833. case 48000: u = 10; break;
  93834. case 96000: u = 11; break;
  93835. default:
  93836. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93837. sample_rate_hint = u = 12;
  93838. else if(header->sample_rate % 10 == 0)
  93839. sample_rate_hint = u = 14;
  93840. else if(header->sample_rate <= 0xffff)
  93841. sample_rate_hint = u = 13;
  93842. else
  93843. u = 0;
  93844. break;
  93845. }
  93846. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93847. return false;
  93848. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93849. switch(header->channel_assignment) {
  93850. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93851. u = header->channels - 1;
  93852. break;
  93853. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93854. FLAC__ASSERT(header->channels == 2);
  93855. u = 8;
  93856. break;
  93857. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93858. FLAC__ASSERT(header->channels == 2);
  93859. u = 9;
  93860. break;
  93861. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93862. FLAC__ASSERT(header->channels == 2);
  93863. u = 10;
  93864. break;
  93865. default:
  93866. FLAC__ASSERT(0);
  93867. }
  93868. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93869. return false;
  93870. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93871. switch(header->bits_per_sample) {
  93872. case 8 : u = 1; break;
  93873. case 12: u = 2; break;
  93874. case 16: u = 4; break;
  93875. case 20: u = 5; break;
  93876. case 24: u = 6; break;
  93877. default: u = 0; break;
  93878. }
  93879. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93880. return false;
  93881. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93882. return false;
  93883. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93884. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93885. return false;
  93886. }
  93887. else {
  93888. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93889. return false;
  93890. }
  93891. if(blocksize_hint)
  93892. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93893. return false;
  93894. switch(sample_rate_hint) {
  93895. case 12:
  93896. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93897. return false;
  93898. break;
  93899. case 13:
  93900. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93901. return false;
  93902. break;
  93903. case 14:
  93904. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93905. return false;
  93906. break;
  93907. }
  93908. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93909. return false;
  93910. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93911. return false;
  93912. return true;
  93913. }
  93914. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93915. {
  93916. FLAC__bool ok;
  93917. ok =
  93918. 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) &&
  93919. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93920. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93921. ;
  93922. return ok;
  93923. }
  93924. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93925. {
  93926. unsigned i;
  93927. 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))
  93928. return false;
  93929. if(wasted_bits)
  93930. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93931. return false;
  93932. for(i = 0; i < subframe->order; i++)
  93933. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93934. return false;
  93935. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93936. return false;
  93937. switch(subframe->entropy_coding_method.type) {
  93938. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93939. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93940. if(!add_residual_partitioned_rice_(
  93941. bw,
  93942. subframe->residual,
  93943. residual_samples,
  93944. subframe->order,
  93945. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93946. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93947. subframe->entropy_coding_method.data.partitioned_rice.order,
  93948. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93949. ))
  93950. return false;
  93951. break;
  93952. default:
  93953. FLAC__ASSERT(0);
  93954. }
  93955. return true;
  93956. }
  93957. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93958. {
  93959. unsigned i;
  93960. 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))
  93961. return false;
  93962. if(wasted_bits)
  93963. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93964. return false;
  93965. for(i = 0; i < subframe->order; i++)
  93966. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93967. return false;
  93968. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93969. return false;
  93970. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93971. return false;
  93972. for(i = 0; i < subframe->order; i++)
  93973. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93974. return false;
  93975. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93976. return false;
  93977. switch(subframe->entropy_coding_method.type) {
  93978. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93979. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93980. if(!add_residual_partitioned_rice_(
  93981. bw,
  93982. subframe->residual,
  93983. residual_samples,
  93984. subframe->order,
  93985. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93986. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93987. subframe->entropy_coding_method.data.partitioned_rice.order,
  93988. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93989. ))
  93990. return false;
  93991. break;
  93992. default:
  93993. FLAC__ASSERT(0);
  93994. }
  93995. return true;
  93996. }
  93997. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93998. {
  93999. unsigned i;
  94000. const FLAC__int32 *signal = subframe->data;
  94001. 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))
  94002. return false;
  94003. if(wasted_bits)
  94004. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94005. return false;
  94006. for(i = 0; i < samples; i++)
  94007. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  94008. return false;
  94009. return true;
  94010. }
  94011. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  94012. {
  94013. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  94014. return false;
  94015. switch(method->type) {
  94016. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94017. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94018. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  94019. return false;
  94020. break;
  94021. default:
  94022. FLAC__ASSERT(0);
  94023. }
  94024. return true;
  94025. }
  94026. 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)
  94027. {
  94028. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  94029. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  94030. if(partition_order == 0) {
  94031. unsigned i;
  94032. if(raw_bits[0] == 0) {
  94033. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  94034. return false;
  94035. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  94036. return false;
  94037. }
  94038. else {
  94039. FLAC__ASSERT(rice_parameters[0] == 0);
  94040. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94041. return false;
  94042. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94043. return false;
  94044. for(i = 0; i < residual_samples; i++) {
  94045. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  94046. return false;
  94047. }
  94048. }
  94049. return true;
  94050. }
  94051. else {
  94052. unsigned i, j, k = 0, k_last = 0;
  94053. unsigned partition_samples;
  94054. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  94055. for(i = 0; i < (1u<<partition_order); i++) {
  94056. partition_samples = default_partition_samples;
  94057. if(i == 0)
  94058. partition_samples -= predictor_order;
  94059. k += partition_samples;
  94060. if(raw_bits[i] == 0) {
  94061. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  94062. return false;
  94063. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  94064. return false;
  94065. }
  94066. else {
  94067. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94068. return false;
  94069. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94070. return false;
  94071. for(j = k_last; j < k; j++) {
  94072. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  94073. return false;
  94074. }
  94075. }
  94076. k_last = k;
  94077. }
  94078. return true;
  94079. }
  94080. }
  94081. #endif
  94082. /*** End of inlined file: stream_encoder_framing.c ***/
  94083. /*** Start of inlined file: window_flac.c ***/
  94084. /*** Start of inlined file: juce_FlacHeader.h ***/
  94085. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  94086. // tasks..
  94087. #define VERSION "1.2.1"
  94088. #define FLAC__NO_DLL 1
  94089. #if JUCE_MSVC
  94090. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  94091. #endif
  94092. #if JUCE_MAC
  94093. #define FLAC__SYS_DARWIN 1
  94094. #endif
  94095. /*** End of inlined file: juce_FlacHeader.h ***/
  94096. #if JUCE_USE_FLAC
  94097. #if HAVE_CONFIG_H
  94098. # include <config.h>
  94099. #endif
  94100. #include <math.h>
  94101. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94102. #ifndef M_PI
  94103. #define M_PI 3.14159265358979323846
  94104. #endif
  94105. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94106. {
  94107. const FLAC__int32 N = L - 1;
  94108. FLAC__int32 n;
  94109. if (L & 1) {
  94110. for (n = 0; n <= N/2; n++)
  94111. window[n] = 2.0f * n / (float)N;
  94112. for (; n <= N; n++)
  94113. window[n] = 2.0f - 2.0f * n / (float)N;
  94114. }
  94115. else {
  94116. for (n = 0; n <= L/2-1; n++)
  94117. window[n] = 2.0f * n / (float)N;
  94118. for (; n <= N; n++)
  94119. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94120. }
  94121. }
  94122. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94123. {
  94124. const FLAC__int32 N = L - 1;
  94125. FLAC__int32 n;
  94126. for (n = 0; n < L; n++)
  94127. 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)));
  94128. }
  94129. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94130. {
  94131. const FLAC__int32 N = L - 1;
  94132. FLAC__int32 n;
  94133. for (n = 0; n < L; n++)
  94134. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94135. }
  94136. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94137. {
  94138. const FLAC__int32 N = L - 1;
  94139. FLAC__int32 n;
  94140. for (n = 0; n <= N; n++)
  94141. 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));
  94142. }
  94143. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94144. {
  94145. const FLAC__int32 N = L - 1;
  94146. const double N2 = (double)N / 2.;
  94147. FLAC__int32 n;
  94148. for (n = 0; n <= N; n++) {
  94149. double k = ((double)n - N2) / N2;
  94150. k = 1.0f - k * k;
  94151. window[n] = (FLAC__real)(k * k);
  94152. }
  94153. }
  94154. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94155. {
  94156. const FLAC__int32 N = L - 1;
  94157. FLAC__int32 n;
  94158. for (n = 0; n < L; n++)
  94159. 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));
  94160. }
  94161. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94162. {
  94163. const FLAC__int32 N = L - 1;
  94164. const double N2 = (double)N / 2.;
  94165. FLAC__int32 n;
  94166. for (n = 0; n <= N; n++) {
  94167. const double k = ((double)n - N2) / (stddev * N2);
  94168. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94169. }
  94170. }
  94171. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94172. {
  94173. const FLAC__int32 N = L - 1;
  94174. FLAC__int32 n;
  94175. for (n = 0; n < L; n++)
  94176. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94177. }
  94178. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94179. {
  94180. const FLAC__int32 N = L - 1;
  94181. FLAC__int32 n;
  94182. for (n = 0; n < L; n++)
  94183. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94184. }
  94185. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94186. {
  94187. const FLAC__int32 N = L - 1;
  94188. FLAC__int32 n;
  94189. for (n = 0; n < L; n++)
  94190. 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));
  94191. }
  94192. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94193. {
  94194. const FLAC__int32 N = L - 1;
  94195. FLAC__int32 n;
  94196. for (n = 0; n < L; n++)
  94197. 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));
  94198. }
  94199. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94200. {
  94201. FLAC__int32 n;
  94202. for (n = 0; n < L; n++)
  94203. window[n] = 1.0f;
  94204. }
  94205. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94206. {
  94207. FLAC__int32 n;
  94208. if (L & 1) {
  94209. for (n = 1; n <= L+1/2; n++)
  94210. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94211. for (; n <= L; n++)
  94212. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94213. }
  94214. else {
  94215. for (n = 1; n <= L/2; n++)
  94216. window[n-1] = 2.0f * n / (float)L;
  94217. for (; n <= L; n++)
  94218. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94219. }
  94220. }
  94221. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94222. {
  94223. if (p <= 0.0)
  94224. FLAC__window_rectangle(window, L);
  94225. else if (p >= 1.0)
  94226. FLAC__window_hann(window, L);
  94227. else {
  94228. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94229. FLAC__int32 n;
  94230. FLAC__window_rectangle(window, L);
  94231. if (Np > 0) {
  94232. for (n = 0; n <= Np; n++) {
  94233. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94234. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94235. }
  94236. }
  94237. }
  94238. }
  94239. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94240. {
  94241. const FLAC__int32 N = L - 1;
  94242. const double N2 = (double)N / 2.;
  94243. FLAC__int32 n;
  94244. for (n = 0; n <= N; n++) {
  94245. const double k = ((double)n - N2) / N2;
  94246. window[n] = (FLAC__real)(1.0f - k * k);
  94247. }
  94248. }
  94249. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94250. #endif
  94251. /*** End of inlined file: window_flac.c ***/
  94252. #else
  94253. #include <FLAC/all.h>
  94254. #endif
  94255. }
  94256. #ifdef _MSC_VER
  94257. #pragma warning (pop)
  94258. #endif
  94259. BEGIN_JUCE_NAMESPACE
  94260. using namespace FlacNamespace;
  94261. static const char* const flacFormatName = "FLAC file";
  94262. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94263. class FlacReader : public AudioFormatReader
  94264. {
  94265. FLAC__StreamDecoder* decoder;
  94266. AudioSampleBuffer reservoir;
  94267. int reservoirStart, samplesInReservoir;
  94268. bool ok, scanningForLength;
  94269. public:
  94270. FlacReader (InputStream* const in)
  94271. : AudioFormatReader (in, TRANS (flacFormatName)),
  94272. reservoir (2, 0),
  94273. reservoirStart (0),
  94274. samplesInReservoir (0),
  94275. scanningForLength (false)
  94276. {
  94277. using namespace FlacNamespace;
  94278. lengthInSamples = 0;
  94279. decoder = FLAC__stream_decoder_new();
  94280. ok = FLAC__stream_decoder_init_stream (decoder,
  94281. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94282. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94283. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94284. if (ok)
  94285. {
  94286. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94287. if (lengthInSamples == 0 && sampleRate > 0)
  94288. {
  94289. // the length hasn't been stored in the metadata, so we'll need to
  94290. // work it out the length the hard way, by scanning the whole file..
  94291. scanningForLength = true;
  94292. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94293. scanningForLength = false;
  94294. const int64 tempLength = lengthInSamples;
  94295. FLAC__stream_decoder_reset (decoder);
  94296. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94297. lengthInSamples = tempLength;
  94298. }
  94299. }
  94300. }
  94301. ~FlacReader()
  94302. {
  94303. FLAC__stream_decoder_delete (decoder);
  94304. }
  94305. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94306. {
  94307. sampleRate = info.sample_rate;
  94308. bitsPerSample = info.bits_per_sample;
  94309. lengthInSamples = (unsigned int) info.total_samples;
  94310. numChannels = info.channels;
  94311. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94312. }
  94313. // returns the number of samples read
  94314. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94315. int64 startSampleInFile, int numSamples)
  94316. {
  94317. using namespace FlacNamespace;
  94318. if (! ok)
  94319. return false;
  94320. while (numSamples > 0)
  94321. {
  94322. if (startSampleInFile >= reservoirStart
  94323. && startSampleInFile < reservoirStart + samplesInReservoir)
  94324. {
  94325. const int num = (int) jmin ((int64) numSamples,
  94326. reservoirStart + samplesInReservoir - startSampleInFile);
  94327. jassert (num > 0);
  94328. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94329. if (destSamples[i] != 0)
  94330. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94331. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94332. sizeof (int) * num);
  94333. startOffsetInDestBuffer += num;
  94334. startSampleInFile += num;
  94335. numSamples -= num;
  94336. }
  94337. else
  94338. {
  94339. if (startSampleInFile >= (int) lengthInSamples)
  94340. {
  94341. samplesInReservoir = 0;
  94342. }
  94343. else if (startSampleInFile < reservoirStart
  94344. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94345. {
  94346. // had some problems with flac crashing if the read pos is aligned more
  94347. // accurately than this. Probably fixed in newer versions of the library, though.
  94348. reservoirStart = (int) (startSampleInFile & ~511);
  94349. samplesInReservoir = 0;
  94350. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94351. }
  94352. else
  94353. {
  94354. reservoirStart += samplesInReservoir;
  94355. samplesInReservoir = 0;
  94356. FLAC__stream_decoder_process_single (decoder);
  94357. }
  94358. if (samplesInReservoir == 0)
  94359. break;
  94360. }
  94361. }
  94362. if (numSamples > 0)
  94363. {
  94364. for (int i = numDestChannels; --i >= 0;)
  94365. if (destSamples[i] != 0)
  94366. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94367. sizeof (int) * numSamples);
  94368. }
  94369. return true;
  94370. }
  94371. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94372. {
  94373. if (scanningForLength)
  94374. {
  94375. lengthInSamples += numSamples;
  94376. }
  94377. else
  94378. {
  94379. if (numSamples > reservoir.getNumSamples())
  94380. reservoir.setSize (numChannels, numSamples, false, false, true);
  94381. const int bitsToShift = 32 - bitsPerSample;
  94382. for (int i = 0; i < (int) numChannels; ++i)
  94383. {
  94384. const FLAC__int32* src = buffer[i];
  94385. int n = i;
  94386. while (src == 0 && n > 0)
  94387. src = buffer [--n];
  94388. if (src != 0)
  94389. {
  94390. int* dest = (int*) reservoir.getSampleData(i);
  94391. for (int j = 0; j < numSamples; ++j)
  94392. dest[j] = src[j] << bitsToShift;
  94393. }
  94394. }
  94395. samplesInReservoir = numSamples;
  94396. }
  94397. }
  94398. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94399. {
  94400. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94401. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94402. }
  94403. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94404. {
  94405. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94406. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94407. }
  94408. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94409. {
  94410. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94411. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94412. }
  94413. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94414. {
  94415. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94416. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94417. }
  94418. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94419. {
  94420. return ((const FlacReader*) client_data)->input->isExhausted();
  94421. }
  94422. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94423. const FLAC__Frame* frame,
  94424. const FLAC__int32* const buffer[],
  94425. void* client_data)
  94426. {
  94427. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94428. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94429. }
  94430. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94431. const FLAC__StreamMetadata* metadata,
  94432. void* client_data)
  94433. {
  94434. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94435. }
  94436. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94437. {
  94438. }
  94439. juce_UseDebuggingNewOperator
  94440. };
  94441. class FlacWriter : public AudioFormatWriter
  94442. {
  94443. FLAC__StreamEncoder* encoder;
  94444. MemoryBlock temp;
  94445. public:
  94446. bool ok;
  94447. FlacWriter (OutputStream* const out,
  94448. const double sampleRate_,
  94449. const int numChannels_,
  94450. const int bitsPerSample_)
  94451. : AudioFormatWriter (out, TRANS (flacFormatName),
  94452. sampleRate_,
  94453. numChannels_,
  94454. bitsPerSample_)
  94455. {
  94456. using namespace FlacNamespace;
  94457. encoder = FLAC__stream_encoder_new();
  94458. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94459. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94460. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94461. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94462. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94463. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94464. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94465. ok = FLAC__stream_encoder_init_stream (encoder,
  94466. encodeWriteCallback, encodeSeekCallback,
  94467. encodeTellCallback, encodeMetadataCallback,
  94468. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94469. }
  94470. ~FlacWriter()
  94471. {
  94472. if (ok)
  94473. {
  94474. FLAC__stream_encoder_finish (encoder);
  94475. output->flush();
  94476. }
  94477. else
  94478. {
  94479. output = 0; // to stop the base class deleting this, as it needs to be returned
  94480. // to the caller of createWriter()
  94481. }
  94482. FLAC__stream_encoder_delete (encoder);
  94483. }
  94484. bool write (const int** samplesToWrite, int numSamples)
  94485. {
  94486. if (! ok)
  94487. return false;
  94488. int* buf[3];
  94489. const int bitsToShift = 32 - bitsPerSample;
  94490. if (bitsToShift > 0)
  94491. {
  94492. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94493. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94494. buf[0] = (int*) temp.getData();
  94495. buf[1] = buf[0] + numSamples;
  94496. buf[2] = 0;
  94497. for (int i = numChannelsToWrite; --i >= 0;)
  94498. {
  94499. if (samplesToWrite[i] != 0)
  94500. {
  94501. for (int j = 0; j < numSamples; ++j)
  94502. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94503. }
  94504. }
  94505. samplesToWrite = (const int**) buf;
  94506. }
  94507. return FLAC__stream_encoder_process (encoder,
  94508. (const FLAC__int32**) samplesToWrite,
  94509. numSamples) != 0;
  94510. }
  94511. bool writeData (const void* const data, const int size) const
  94512. {
  94513. return output->write (data, size);
  94514. }
  94515. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94516. {
  94517. b += bytes;
  94518. for (int i = 0; i < bytes; ++i)
  94519. {
  94520. *(--b) = (FLAC__byte) (val & 0xff);
  94521. val >>= 8;
  94522. }
  94523. }
  94524. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94525. {
  94526. using namespace FlacNamespace;
  94527. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94528. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94529. const unsigned int channelsMinus1 = info.channels - 1;
  94530. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94531. packUint32 (info.min_blocksize, buffer, 2);
  94532. packUint32 (info.max_blocksize, buffer + 2, 2);
  94533. packUint32 (info.min_framesize, buffer + 4, 3);
  94534. packUint32 (info.max_framesize, buffer + 7, 3);
  94535. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94536. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94537. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94538. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94539. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94540. memcpy (buffer + 18, info.md5sum, 16);
  94541. const bool seekOk = output->setPosition (4);
  94542. (void) seekOk;
  94543. // if this fails, you've given it an output stream that can't seek! It needs
  94544. // to be able to seek back to write the header
  94545. jassert (seekOk);
  94546. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94547. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94548. }
  94549. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94550. const FLAC__byte buffer[],
  94551. size_t bytes,
  94552. unsigned int /*samples*/,
  94553. unsigned int /*current_frame*/,
  94554. void* client_data)
  94555. {
  94556. using namespace FlacNamespace;
  94557. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94558. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94559. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94560. }
  94561. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94562. {
  94563. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94564. }
  94565. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94566. {
  94567. if (client_data == 0)
  94568. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94569. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94570. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94571. }
  94572. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94573. const FLAC__StreamMetadata* metadata,
  94574. void* client_data)
  94575. {
  94576. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94577. }
  94578. juce_UseDebuggingNewOperator
  94579. };
  94580. FlacAudioFormat::FlacAudioFormat()
  94581. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94582. {
  94583. }
  94584. FlacAudioFormat::~FlacAudioFormat()
  94585. {
  94586. }
  94587. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94588. {
  94589. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94590. return Array <int> (rates);
  94591. }
  94592. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94593. {
  94594. const int depths[] = { 16, 24, 0 };
  94595. return Array <int> (depths);
  94596. }
  94597. bool FlacAudioFormat::canDoStereo()
  94598. {
  94599. return true;
  94600. }
  94601. bool FlacAudioFormat::canDoMono()
  94602. {
  94603. return true;
  94604. }
  94605. bool FlacAudioFormat::isCompressed()
  94606. {
  94607. return true;
  94608. }
  94609. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94610. const bool deleteStreamIfOpeningFails)
  94611. {
  94612. ScopedPointer <FlacReader> r (new FlacReader (in));
  94613. if (r->sampleRate != 0)
  94614. return r.release();
  94615. if (! deleteStreamIfOpeningFails)
  94616. r->input = 0;
  94617. return 0;
  94618. }
  94619. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94620. double sampleRate,
  94621. unsigned int numberOfChannels,
  94622. int bitsPerSample,
  94623. const StringPairArray& /*metadataValues*/,
  94624. int /*qualityOptionIndex*/)
  94625. {
  94626. if (getPossibleBitDepths().contains (bitsPerSample))
  94627. {
  94628. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94629. sampleRate,
  94630. numberOfChannels,
  94631. bitsPerSample));
  94632. if (w->ok)
  94633. return w.release();
  94634. }
  94635. return 0;
  94636. }
  94637. END_JUCE_NAMESPACE
  94638. #endif
  94639. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94640. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94641. #if JUCE_USE_OGGVORBIS
  94642. #if JUCE_MAC
  94643. #define __MACOSX__ 1
  94644. #endif
  94645. namespace OggVorbisNamespace
  94646. {
  94647. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94648. /*** Start of inlined file: vorbisenc.h ***/
  94649. #ifndef _OV_ENC_H_
  94650. #define _OV_ENC_H_
  94651. #ifdef __cplusplus
  94652. extern "C"
  94653. {
  94654. #endif /* __cplusplus */
  94655. /*** Start of inlined file: codec.h ***/
  94656. #ifndef _vorbis_codec_h_
  94657. #define _vorbis_codec_h_
  94658. #ifdef __cplusplus
  94659. extern "C"
  94660. {
  94661. #endif /* __cplusplus */
  94662. /*** Start of inlined file: ogg.h ***/
  94663. #ifndef _OGG_H
  94664. #define _OGG_H
  94665. #ifdef __cplusplus
  94666. extern "C" {
  94667. #endif
  94668. /*** Start of inlined file: os_types.h ***/
  94669. #ifndef _OS_TYPES_H
  94670. #define _OS_TYPES_H
  94671. #define _ogg_malloc malloc
  94672. #define _ogg_calloc calloc
  94673. #define _ogg_realloc realloc
  94674. #define _ogg_free free
  94675. #if defined(_WIN32)
  94676. # if defined(__CYGWIN__)
  94677. # include <_G_config.h>
  94678. typedef _G_int64_t ogg_int64_t;
  94679. typedef _G_int32_t ogg_int32_t;
  94680. typedef _G_uint32_t ogg_uint32_t;
  94681. typedef _G_int16_t ogg_int16_t;
  94682. typedef _G_uint16_t ogg_uint16_t;
  94683. # elif defined(__MINGW32__)
  94684. typedef short ogg_int16_t;
  94685. typedef unsigned short ogg_uint16_t;
  94686. typedef int ogg_int32_t;
  94687. typedef unsigned int ogg_uint32_t;
  94688. typedef long long ogg_int64_t;
  94689. typedef unsigned long long ogg_uint64_t;
  94690. # elif defined(__MWERKS__)
  94691. typedef long long ogg_int64_t;
  94692. typedef int ogg_int32_t;
  94693. typedef unsigned int ogg_uint32_t;
  94694. typedef short ogg_int16_t;
  94695. typedef unsigned short ogg_uint16_t;
  94696. # else
  94697. typedef __int64 ogg_int64_t;
  94698. typedef __int32 ogg_int32_t;
  94699. typedef unsigned __int32 ogg_uint32_t;
  94700. typedef __int16 ogg_int16_t;
  94701. typedef unsigned __int16 ogg_uint16_t;
  94702. # endif
  94703. #elif defined(__MACOS__)
  94704. # include <sys/types.h>
  94705. typedef SInt16 ogg_int16_t;
  94706. typedef UInt16 ogg_uint16_t;
  94707. typedef SInt32 ogg_int32_t;
  94708. typedef UInt32 ogg_uint32_t;
  94709. typedef SInt64 ogg_int64_t;
  94710. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94711. # include <sys/types.h>
  94712. typedef int16_t ogg_int16_t;
  94713. typedef u_int16_t ogg_uint16_t;
  94714. typedef int32_t ogg_int32_t;
  94715. typedef u_int32_t ogg_uint32_t;
  94716. typedef int64_t ogg_int64_t;
  94717. #elif defined(__BEOS__)
  94718. # include <inttypes.h>
  94719. typedef int16_t ogg_int16_t;
  94720. typedef u_int16_t ogg_uint16_t;
  94721. typedef int32_t ogg_int32_t;
  94722. typedef u_int32_t ogg_uint32_t;
  94723. typedef int64_t ogg_int64_t;
  94724. #elif defined (__EMX__)
  94725. typedef short ogg_int16_t;
  94726. typedef unsigned short ogg_uint16_t;
  94727. typedef int ogg_int32_t;
  94728. typedef unsigned int ogg_uint32_t;
  94729. typedef long long ogg_int64_t;
  94730. #elif defined (DJGPP)
  94731. typedef short ogg_int16_t;
  94732. typedef int ogg_int32_t;
  94733. typedef unsigned int ogg_uint32_t;
  94734. typedef long long ogg_int64_t;
  94735. #elif defined(R5900)
  94736. typedef long ogg_int64_t;
  94737. typedef int ogg_int32_t;
  94738. typedef unsigned ogg_uint32_t;
  94739. typedef short ogg_int16_t;
  94740. #elif defined(__SYMBIAN32__)
  94741. typedef signed short ogg_int16_t;
  94742. typedef unsigned short ogg_uint16_t;
  94743. typedef signed int ogg_int32_t;
  94744. typedef unsigned int ogg_uint32_t;
  94745. typedef long long int ogg_int64_t;
  94746. #else
  94747. # include <sys/types.h>
  94748. /*** Start of inlined file: config_types.h ***/
  94749. #ifndef __CONFIG_TYPES_H__
  94750. #define __CONFIG_TYPES_H__
  94751. typedef int16_t ogg_int16_t;
  94752. typedef unsigned short ogg_uint16_t;
  94753. typedef int32_t ogg_int32_t;
  94754. typedef unsigned int ogg_uint32_t;
  94755. typedef int64_t ogg_int64_t;
  94756. #endif
  94757. /*** End of inlined file: config_types.h ***/
  94758. #endif
  94759. #endif /* _OS_TYPES_H */
  94760. /*** End of inlined file: os_types.h ***/
  94761. typedef struct {
  94762. long endbyte;
  94763. int endbit;
  94764. unsigned char *buffer;
  94765. unsigned char *ptr;
  94766. long storage;
  94767. } oggpack_buffer;
  94768. typedef struct {
  94769. unsigned char *header;
  94770. long header_len;
  94771. unsigned char *body;
  94772. long body_len;
  94773. } ogg_page;
  94774. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94775. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94776. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94777. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94778. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94779. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94780. }
  94781. typedef struct {
  94782. unsigned char *body_data; /* bytes from packet bodies */
  94783. long body_storage; /* storage elements allocated */
  94784. long body_fill; /* elements stored; fill mark */
  94785. long body_returned; /* elements of fill returned */
  94786. int *lacing_vals; /* The values that will go to the segment table */
  94787. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94788. this way, but it is simple coupled to the
  94789. lacing fifo */
  94790. long lacing_storage;
  94791. long lacing_fill;
  94792. long lacing_packet;
  94793. long lacing_returned;
  94794. unsigned char header[282]; /* working space for header encode */
  94795. int header_fill;
  94796. int e_o_s; /* set when we have buffered the last packet in the
  94797. logical bitstream */
  94798. int b_o_s; /* set after we've written the initial page
  94799. of a logical bitstream */
  94800. long serialno;
  94801. long pageno;
  94802. ogg_int64_t packetno; /* sequence number for decode; the framing
  94803. knows where there's a hole in the data,
  94804. but we need coupling so that the codec
  94805. (which is in a seperate abstraction
  94806. layer) also knows about the gap */
  94807. ogg_int64_t granulepos;
  94808. } ogg_stream_state;
  94809. typedef struct {
  94810. unsigned char *packet;
  94811. long bytes;
  94812. long b_o_s;
  94813. long e_o_s;
  94814. ogg_int64_t granulepos;
  94815. ogg_int64_t packetno; /* sequence number for decode; the framing
  94816. knows where there's a hole in the data,
  94817. but we need coupling so that the codec
  94818. (which is in a seperate abstraction
  94819. layer) also knows about the gap */
  94820. } ogg_packet;
  94821. typedef struct {
  94822. unsigned char *data;
  94823. int storage;
  94824. int fill;
  94825. int returned;
  94826. int unsynced;
  94827. int headerbytes;
  94828. int bodybytes;
  94829. } ogg_sync_state;
  94830. extern void oggpack_writeinit(oggpack_buffer *b);
  94831. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94832. extern void oggpack_writealign(oggpack_buffer *b);
  94833. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94834. extern void oggpack_reset(oggpack_buffer *b);
  94835. extern void oggpack_writeclear(oggpack_buffer *b);
  94836. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94837. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94838. extern long oggpack_look(oggpack_buffer *b,int bits);
  94839. extern long oggpack_look1(oggpack_buffer *b);
  94840. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94841. extern void oggpack_adv1(oggpack_buffer *b);
  94842. extern long oggpack_read(oggpack_buffer *b,int bits);
  94843. extern long oggpack_read1(oggpack_buffer *b);
  94844. extern long oggpack_bytes(oggpack_buffer *b);
  94845. extern long oggpack_bits(oggpack_buffer *b);
  94846. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94847. extern void oggpackB_writeinit(oggpack_buffer *b);
  94848. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94849. extern void oggpackB_writealign(oggpack_buffer *b);
  94850. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94851. extern void oggpackB_reset(oggpack_buffer *b);
  94852. extern void oggpackB_writeclear(oggpack_buffer *b);
  94853. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94854. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94855. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94856. extern long oggpackB_look1(oggpack_buffer *b);
  94857. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94858. extern void oggpackB_adv1(oggpack_buffer *b);
  94859. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94860. extern long oggpackB_read1(oggpack_buffer *b);
  94861. extern long oggpackB_bytes(oggpack_buffer *b);
  94862. extern long oggpackB_bits(oggpack_buffer *b);
  94863. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94864. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94865. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94866. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94867. extern int ogg_sync_init(ogg_sync_state *oy);
  94868. extern int ogg_sync_clear(ogg_sync_state *oy);
  94869. extern int ogg_sync_reset(ogg_sync_state *oy);
  94870. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94871. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94872. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94873. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94874. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94875. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94876. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94877. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94878. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94879. extern int ogg_stream_clear(ogg_stream_state *os);
  94880. extern int ogg_stream_reset(ogg_stream_state *os);
  94881. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94882. extern int ogg_stream_destroy(ogg_stream_state *os);
  94883. extern int ogg_stream_eos(ogg_stream_state *os);
  94884. extern void ogg_page_checksum_set(ogg_page *og);
  94885. extern int ogg_page_version(ogg_page *og);
  94886. extern int ogg_page_continued(ogg_page *og);
  94887. extern int ogg_page_bos(ogg_page *og);
  94888. extern int ogg_page_eos(ogg_page *og);
  94889. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94890. extern int ogg_page_serialno(ogg_page *og);
  94891. extern long ogg_page_pageno(ogg_page *og);
  94892. extern int ogg_page_packets(ogg_page *og);
  94893. extern void ogg_packet_clear(ogg_packet *op);
  94894. #ifdef __cplusplus
  94895. }
  94896. #endif
  94897. #endif /* _OGG_H */
  94898. /*** End of inlined file: ogg.h ***/
  94899. typedef struct vorbis_info{
  94900. int version;
  94901. int channels;
  94902. long rate;
  94903. long bitrate_upper;
  94904. long bitrate_nominal;
  94905. long bitrate_lower;
  94906. long bitrate_window;
  94907. void *codec_setup;
  94908. } vorbis_info;
  94909. typedef struct vorbis_dsp_state{
  94910. int analysisp;
  94911. vorbis_info *vi;
  94912. float **pcm;
  94913. float **pcmret;
  94914. int pcm_storage;
  94915. int pcm_current;
  94916. int pcm_returned;
  94917. int preextrapolate;
  94918. int eofflag;
  94919. long lW;
  94920. long W;
  94921. long nW;
  94922. long centerW;
  94923. ogg_int64_t granulepos;
  94924. ogg_int64_t sequence;
  94925. ogg_int64_t glue_bits;
  94926. ogg_int64_t time_bits;
  94927. ogg_int64_t floor_bits;
  94928. ogg_int64_t res_bits;
  94929. void *backend_state;
  94930. } vorbis_dsp_state;
  94931. typedef struct vorbis_block{
  94932. float **pcm; /* this is a pointer into local storage */
  94933. oggpack_buffer opb;
  94934. long lW;
  94935. long W;
  94936. long nW;
  94937. int pcmend;
  94938. int mode;
  94939. int eofflag;
  94940. ogg_int64_t granulepos;
  94941. ogg_int64_t sequence;
  94942. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94943. void *localstore;
  94944. long localtop;
  94945. long localalloc;
  94946. long totaluse;
  94947. struct alloc_chain *reap;
  94948. long glue_bits;
  94949. long time_bits;
  94950. long floor_bits;
  94951. long res_bits;
  94952. void *internal;
  94953. } vorbis_block;
  94954. struct alloc_chain{
  94955. void *ptr;
  94956. struct alloc_chain *next;
  94957. };
  94958. typedef struct vorbis_comment{
  94959. char **user_comments;
  94960. int *comment_lengths;
  94961. int comments;
  94962. char *vendor;
  94963. } vorbis_comment;
  94964. extern void vorbis_info_init(vorbis_info *vi);
  94965. extern void vorbis_info_clear(vorbis_info *vi);
  94966. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94967. extern void vorbis_comment_init(vorbis_comment *vc);
  94968. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94969. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94970. const char *tag, char *contents);
  94971. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94972. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94973. extern void vorbis_comment_clear(vorbis_comment *vc);
  94974. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94975. extern int vorbis_block_clear(vorbis_block *vb);
  94976. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94977. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94978. ogg_int64_t granulepos);
  94979. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94980. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94981. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94982. vorbis_comment *vc,
  94983. ogg_packet *op,
  94984. ogg_packet *op_comm,
  94985. ogg_packet *op_code);
  94986. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94987. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94988. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94989. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94990. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94991. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94992. ogg_packet *op);
  94993. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94994. ogg_packet *op);
  94995. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94996. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94997. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94998. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94999. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  95000. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  95001. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  95002. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  95003. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  95004. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  95005. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  95006. #define OV_FALSE -1
  95007. #define OV_EOF -2
  95008. #define OV_HOLE -3
  95009. #define OV_EREAD -128
  95010. #define OV_EFAULT -129
  95011. #define OV_EIMPL -130
  95012. #define OV_EINVAL -131
  95013. #define OV_ENOTVORBIS -132
  95014. #define OV_EBADHEADER -133
  95015. #define OV_EVERSION -134
  95016. #define OV_ENOTAUDIO -135
  95017. #define OV_EBADPACKET -136
  95018. #define OV_EBADLINK -137
  95019. #define OV_ENOSEEK -138
  95020. #ifdef __cplusplus
  95021. }
  95022. #endif /* __cplusplus */
  95023. #endif
  95024. /*** End of inlined file: codec.h ***/
  95025. extern int vorbis_encode_init(vorbis_info *vi,
  95026. long channels,
  95027. long rate,
  95028. long max_bitrate,
  95029. long nominal_bitrate,
  95030. long min_bitrate);
  95031. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  95032. long channels,
  95033. long rate,
  95034. long max_bitrate,
  95035. long nominal_bitrate,
  95036. long min_bitrate);
  95037. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  95038. long channels,
  95039. long rate,
  95040. float quality /* quality level from 0. (lo) to 1. (hi) */
  95041. );
  95042. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  95043. long channels,
  95044. long rate,
  95045. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  95046. );
  95047. extern int vorbis_encode_setup_init(vorbis_info *vi);
  95048. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  95049. #define OV_ECTL_RATEMANAGE_GET 0x10
  95050. #define OV_ECTL_RATEMANAGE_SET 0x11
  95051. #define OV_ECTL_RATEMANAGE_AVG 0x12
  95052. #define OV_ECTL_RATEMANAGE_HARD 0x13
  95053. struct ovectl_ratemanage_arg {
  95054. int management_active;
  95055. long bitrate_hard_min;
  95056. long bitrate_hard_max;
  95057. double bitrate_hard_window;
  95058. long bitrate_av_lo;
  95059. long bitrate_av_hi;
  95060. double bitrate_av_window;
  95061. double bitrate_av_window_center;
  95062. };
  95063. #define OV_ECTL_RATEMANAGE2_GET 0x14
  95064. #define OV_ECTL_RATEMANAGE2_SET 0x15
  95065. struct ovectl_ratemanage2_arg {
  95066. int management_active;
  95067. long bitrate_limit_min_kbps;
  95068. long bitrate_limit_max_kbps;
  95069. long bitrate_limit_reservoir_bits;
  95070. double bitrate_limit_reservoir_bias;
  95071. long bitrate_average_kbps;
  95072. double bitrate_average_damping;
  95073. };
  95074. #define OV_ECTL_LOWPASS_GET 0x20
  95075. #define OV_ECTL_LOWPASS_SET 0x21
  95076. #define OV_ECTL_IBLOCK_GET 0x30
  95077. #define OV_ECTL_IBLOCK_SET 0x31
  95078. #ifdef __cplusplus
  95079. }
  95080. #endif /* __cplusplus */
  95081. #endif
  95082. /*** End of inlined file: vorbisenc.h ***/
  95083. /*** Start of inlined file: vorbisfile.h ***/
  95084. #ifndef _OV_FILE_H_
  95085. #define _OV_FILE_H_
  95086. #ifdef __cplusplus
  95087. extern "C"
  95088. {
  95089. #endif /* __cplusplus */
  95090. #include <stdio.h>
  95091. typedef struct {
  95092. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  95093. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  95094. int (*close_func) (void *datasource);
  95095. long (*tell_func) (void *datasource);
  95096. } ov_callbacks;
  95097. #define NOTOPEN 0
  95098. #define PARTOPEN 1
  95099. #define OPENED 2
  95100. #define STREAMSET 3
  95101. #define INITSET 4
  95102. typedef struct OggVorbis_File {
  95103. void *datasource; /* Pointer to a FILE *, etc. */
  95104. int seekable;
  95105. ogg_int64_t offset;
  95106. ogg_int64_t end;
  95107. ogg_sync_state oy;
  95108. int links;
  95109. ogg_int64_t *offsets;
  95110. ogg_int64_t *dataoffsets;
  95111. long *serialnos;
  95112. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95113. compatability; x2 size, stores both
  95114. beginning and end values */
  95115. vorbis_info *vi;
  95116. vorbis_comment *vc;
  95117. ogg_int64_t pcm_offset;
  95118. int ready_state;
  95119. long current_serialno;
  95120. int current_link;
  95121. double bittrack;
  95122. double samptrack;
  95123. ogg_stream_state os; /* take physical pages, weld into a logical
  95124. stream of packets */
  95125. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95126. vorbis_block vb; /* local working space for packet->PCM decode */
  95127. ov_callbacks callbacks;
  95128. } OggVorbis_File;
  95129. extern int ov_clear(OggVorbis_File *vf);
  95130. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95131. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95132. char *initial, long ibytes, ov_callbacks callbacks);
  95133. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95134. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95135. char *initial, long ibytes, ov_callbacks callbacks);
  95136. extern int ov_test_open(OggVorbis_File *vf);
  95137. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95138. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95139. extern long ov_streams(OggVorbis_File *vf);
  95140. extern long ov_seekable(OggVorbis_File *vf);
  95141. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95142. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95143. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95144. extern double ov_time_total(OggVorbis_File *vf,int i);
  95145. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95146. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95147. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95148. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95149. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95150. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95151. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95152. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95153. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95154. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95155. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95156. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95157. extern double ov_time_tell(OggVorbis_File *vf);
  95158. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95159. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95160. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95161. int *bitstream);
  95162. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95163. int bigendianp,int word,int sgned,int *bitstream);
  95164. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95165. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95166. extern int ov_halfrate_p(OggVorbis_File *vf);
  95167. #ifdef __cplusplus
  95168. }
  95169. #endif /* __cplusplus */
  95170. #endif
  95171. /*** End of inlined file: vorbisfile.h ***/
  95172. /*** Start of inlined file: bitwise.c ***/
  95173. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95174. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95175. // tasks..
  95176. #if JUCE_MSVC
  95177. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95178. #endif
  95179. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95180. #if JUCE_USE_OGGVORBIS
  95181. #include <string.h>
  95182. #include <stdlib.h>
  95183. #define BUFFER_INCREMENT 256
  95184. static const unsigned long mask[]=
  95185. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95186. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95187. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95188. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95189. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95190. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95191. 0x3fffffff,0x7fffffff,0xffffffff };
  95192. static const unsigned int mask8B[]=
  95193. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95194. void oggpack_writeinit(oggpack_buffer *b){
  95195. memset(b,0,sizeof(*b));
  95196. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95197. b->buffer[0]='\0';
  95198. b->storage=BUFFER_INCREMENT;
  95199. }
  95200. void oggpackB_writeinit(oggpack_buffer *b){
  95201. oggpack_writeinit(b);
  95202. }
  95203. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95204. long bytes=bits>>3;
  95205. bits-=bytes*8;
  95206. b->ptr=b->buffer+bytes;
  95207. b->endbit=bits;
  95208. b->endbyte=bytes;
  95209. *b->ptr&=mask[bits];
  95210. }
  95211. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95212. long bytes=bits>>3;
  95213. bits-=bytes*8;
  95214. b->ptr=b->buffer+bytes;
  95215. b->endbit=bits;
  95216. b->endbyte=bytes;
  95217. *b->ptr&=mask8B[bits];
  95218. }
  95219. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95220. if(b->endbyte+4>=b->storage){
  95221. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95222. b->storage+=BUFFER_INCREMENT;
  95223. b->ptr=b->buffer+b->endbyte;
  95224. }
  95225. value&=mask[bits];
  95226. bits+=b->endbit;
  95227. b->ptr[0]|=value<<b->endbit;
  95228. if(bits>=8){
  95229. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95230. if(bits>=16){
  95231. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95232. if(bits>=24){
  95233. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95234. if(bits>=32){
  95235. if(b->endbit)
  95236. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95237. else
  95238. b->ptr[4]=0;
  95239. }
  95240. }
  95241. }
  95242. }
  95243. b->endbyte+=bits/8;
  95244. b->ptr+=bits/8;
  95245. b->endbit=bits&7;
  95246. }
  95247. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95248. if(b->endbyte+4>=b->storage){
  95249. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95250. b->storage+=BUFFER_INCREMENT;
  95251. b->ptr=b->buffer+b->endbyte;
  95252. }
  95253. value=(value&mask[bits])<<(32-bits);
  95254. bits+=b->endbit;
  95255. b->ptr[0]|=value>>(24+b->endbit);
  95256. if(bits>=8){
  95257. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95258. if(bits>=16){
  95259. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95260. if(bits>=24){
  95261. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95262. if(bits>=32){
  95263. if(b->endbit)
  95264. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95265. else
  95266. b->ptr[4]=0;
  95267. }
  95268. }
  95269. }
  95270. }
  95271. b->endbyte+=bits/8;
  95272. b->ptr+=bits/8;
  95273. b->endbit=bits&7;
  95274. }
  95275. void oggpack_writealign(oggpack_buffer *b){
  95276. int bits=8-b->endbit;
  95277. if(bits<8)
  95278. oggpack_write(b,0,bits);
  95279. }
  95280. void oggpackB_writealign(oggpack_buffer *b){
  95281. int bits=8-b->endbit;
  95282. if(bits<8)
  95283. oggpackB_write(b,0,bits);
  95284. }
  95285. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95286. void *source,
  95287. long bits,
  95288. void (*w)(oggpack_buffer *,
  95289. unsigned long,
  95290. int),
  95291. int msb){
  95292. unsigned char *ptr=(unsigned char *)source;
  95293. long bytes=bits/8;
  95294. bits-=bytes*8;
  95295. if(b->endbit){
  95296. int i;
  95297. for(i=0;i<bytes;i++)
  95298. w(b,(unsigned long)(ptr[i]),8);
  95299. }else{
  95300. if(b->endbyte+bytes+1>=b->storage){
  95301. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95302. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95303. b->ptr=b->buffer+b->endbyte;
  95304. }
  95305. memmove(b->ptr,source,bytes);
  95306. b->ptr+=bytes;
  95307. b->endbyte+=bytes;
  95308. *b->ptr=0;
  95309. }
  95310. if(bits){
  95311. if(msb)
  95312. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95313. else
  95314. w(b,(unsigned long)(ptr[bytes]),bits);
  95315. }
  95316. }
  95317. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95318. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95319. }
  95320. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95321. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95322. }
  95323. void oggpack_reset(oggpack_buffer *b){
  95324. b->ptr=b->buffer;
  95325. b->buffer[0]=0;
  95326. b->endbit=b->endbyte=0;
  95327. }
  95328. void oggpackB_reset(oggpack_buffer *b){
  95329. oggpack_reset(b);
  95330. }
  95331. void oggpack_writeclear(oggpack_buffer *b){
  95332. _ogg_free(b->buffer);
  95333. memset(b,0,sizeof(*b));
  95334. }
  95335. void oggpackB_writeclear(oggpack_buffer *b){
  95336. oggpack_writeclear(b);
  95337. }
  95338. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95339. memset(b,0,sizeof(*b));
  95340. b->buffer=b->ptr=buf;
  95341. b->storage=bytes;
  95342. }
  95343. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95344. oggpack_readinit(b,buf,bytes);
  95345. }
  95346. long oggpack_look(oggpack_buffer *b,int bits){
  95347. unsigned long ret;
  95348. unsigned long m=mask[bits];
  95349. bits+=b->endbit;
  95350. if(b->endbyte+4>=b->storage){
  95351. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95352. }
  95353. ret=b->ptr[0]>>b->endbit;
  95354. if(bits>8){
  95355. ret|=b->ptr[1]<<(8-b->endbit);
  95356. if(bits>16){
  95357. ret|=b->ptr[2]<<(16-b->endbit);
  95358. if(bits>24){
  95359. ret|=b->ptr[3]<<(24-b->endbit);
  95360. if(bits>32 && b->endbit)
  95361. ret|=b->ptr[4]<<(32-b->endbit);
  95362. }
  95363. }
  95364. }
  95365. return(m&ret);
  95366. }
  95367. long oggpackB_look(oggpack_buffer *b,int bits){
  95368. unsigned long ret;
  95369. int m=32-bits;
  95370. bits+=b->endbit;
  95371. if(b->endbyte+4>=b->storage){
  95372. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95373. }
  95374. ret=b->ptr[0]<<(24+b->endbit);
  95375. if(bits>8){
  95376. ret|=b->ptr[1]<<(16+b->endbit);
  95377. if(bits>16){
  95378. ret|=b->ptr[2]<<(8+b->endbit);
  95379. if(bits>24){
  95380. ret|=b->ptr[3]<<(b->endbit);
  95381. if(bits>32 && b->endbit)
  95382. ret|=b->ptr[4]>>(8-b->endbit);
  95383. }
  95384. }
  95385. }
  95386. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95387. }
  95388. long oggpack_look1(oggpack_buffer *b){
  95389. if(b->endbyte>=b->storage)return(-1);
  95390. return((b->ptr[0]>>b->endbit)&1);
  95391. }
  95392. long oggpackB_look1(oggpack_buffer *b){
  95393. if(b->endbyte>=b->storage)return(-1);
  95394. return((b->ptr[0]>>(7-b->endbit))&1);
  95395. }
  95396. void oggpack_adv(oggpack_buffer *b,int bits){
  95397. bits+=b->endbit;
  95398. b->ptr+=bits/8;
  95399. b->endbyte+=bits/8;
  95400. b->endbit=bits&7;
  95401. }
  95402. void oggpackB_adv(oggpack_buffer *b,int bits){
  95403. oggpack_adv(b,bits);
  95404. }
  95405. void oggpack_adv1(oggpack_buffer *b){
  95406. if(++(b->endbit)>7){
  95407. b->endbit=0;
  95408. b->ptr++;
  95409. b->endbyte++;
  95410. }
  95411. }
  95412. void oggpackB_adv1(oggpack_buffer *b){
  95413. oggpack_adv1(b);
  95414. }
  95415. long oggpack_read(oggpack_buffer *b,int bits){
  95416. long ret;
  95417. unsigned long m=mask[bits];
  95418. bits+=b->endbit;
  95419. if(b->endbyte+4>=b->storage){
  95420. ret=-1L;
  95421. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95422. }
  95423. ret=b->ptr[0]>>b->endbit;
  95424. if(bits>8){
  95425. ret|=b->ptr[1]<<(8-b->endbit);
  95426. if(bits>16){
  95427. ret|=b->ptr[2]<<(16-b->endbit);
  95428. if(bits>24){
  95429. ret|=b->ptr[3]<<(24-b->endbit);
  95430. if(bits>32 && b->endbit){
  95431. ret|=b->ptr[4]<<(32-b->endbit);
  95432. }
  95433. }
  95434. }
  95435. }
  95436. ret&=m;
  95437. overflow:
  95438. b->ptr+=bits/8;
  95439. b->endbyte+=bits/8;
  95440. b->endbit=bits&7;
  95441. return(ret);
  95442. }
  95443. long oggpackB_read(oggpack_buffer *b,int bits){
  95444. long ret;
  95445. long m=32-bits;
  95446. bits+=b->endbit;
  95447. if(b->endbyte+4>=b->storage){
  95448. ret=-1L;
  95449. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95450. }
  95451. ret=b->ptr[0]<<(24+b->endbit);
  95452. if(bits>8){
  95453. ret|=b->ptr[1]<<(16+b->endbit);
  95454. if(bits>16){
  95455. ret|=b->ptr[2]<<(8+b->endbit);
  95456. if(bits>24){
  95457. ret|=b->ptr[3]<<(b->endbit);
  95458. if(bits>32 && b->endbit)
  95459. ret|=b->ptr[4]>>(8-b->endbit);
  95460. }
  95461. }
  95462. }
  95463. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95464. overflow:
  95465. b->ptr+=bits/8;
  95466. b->endbyte+=bits/8;
  95467. b->endbit=bits&7;
  95468. return(ret);
  95469. }
  95470. long oggpack_read1(oggpack_buffer *b){
  95471. long ret;
  95472. if(b->endbyte>=b->storage){
  95473. ret=-1L;
  95474. goto overflow;
  95475. }
  95476. ret=(b->ptr[0]>>b->endbit)&1;
  95477. overflow:
  95478. b->endbit++;
  95479. if(b->endbit>7){
  95480. b->endbit=0;
  95481. b->ptr++;
  95482. b->endbyte++;
  95483. }
  95484. return(ret);
  95485. }
  95486. long oggpackB_read1(oggpack_buffer *b){
  95487. long ret;
  95488. if(b->endbyte>=b->storage){
  95489. ret=-1L;
  95490. goto overflow;
  95491. }
  95492. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95493. overflow:
  95494. b->endbit++;
  95495. if(b->endbit>7){
  95496. b->endbit=0;
  95497. b->ptr++;
  95498. b->endbyte++;
  95499. }
  95500. return(ret);
  95501. }
  95502. long oggpack_bytes(oggpack_buffer *b){
  95503. return(b->endbyte+(b->endbit+7)/8);
  95504. }
  95505. long oggpack_bits(oggpack_buffer *b){
  95506. return(b->endbyte*8+b->endbit);
  95507. }
  95508. long oggpackB_bytes(oggpack_buffer *b){
  95509. return oggpack_bytes(b);
  95510. }
  95511. long oggpackB_bits(oggpack_buffer *b){
  95512. return oggpack_bits(b);
  95513. }
  95514. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95515. return(b->buffer);
  95516. }
  95517. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95518. return oggpack_get_buffer(b);
  95519. }
  95520. #ifdef _V_SELFTEST
  95521. #include <stdio.h>
  95522. static int ilog(unsigned int v){
  95523. int ret=0;
  95524. while(v){
  95525. ret++;
  95526. v>>=1;
  95527. }
  95528. return(ret);
  95529. }
  95530. oggpack_buffer o;
  95531. oggpack_buffer r;
  95532. void report(char *in){
  95533. fprintf(stderr,"%s",in);
  95534. exit(1);
  95535. }
  95536. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95537. long bytes,i;
  95538. unsigned char *buffer;
  95539. oggpack_reset(&o);
  95540. for(i=0;i<vals;i++)
  95541. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95542. buffer=oggpack_get_buffer(&o);
  95543. bytes=oggpack_bytes(&o);
  95544. if(bytes!=compsize)report("wrong number of bytes!\n");
  95545. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95546. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95547. report("wrote incorrect value!\n");
  95548. }
  95549. oggpack_readinit(&r,buffer,bytes);
  95550. for(i=0;i<vals;i++){
  95551. int tbit=bits?bits:ilog(b[i]);
  95552. if(oggpack_look(&r,tbit)==-1)
  95553. report("out of data!\n");
  95554. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95555. report("looked at incorrect value!\n");
  95556. if(tbit==1)
  95557. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95558. report("looked at single bit incorrect value!\n");
  95559. if(tbit==1){
  95560. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95561. report("read incorrect single bit value!\n");
  95562. }else{
  95563. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95564. report("read incorrect value!\n");
  95565. }
  95566. }
  95567. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95568. }
  95569. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95570. long bytes,i;
  95571. unsigned char *buffer;
  95572. oggpackB_reset(&o);
  95573. for(i=0;i<vals;i++)
  95574. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95575. buffer=oggpackB_get_buffer(&o);
  95576. bytes=oggpackB_bytes(&o);
  95577. if(bytes!=compsize)report("wrong number of bytes!\n");
  95578. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95579. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95580. report("wrote incorrect value!\n");
  95581. }
  95582. oggpackB_readinit(&r,buffer,bytes);
  95583. for(i=0;i<vals;i++){
  95584. int tbit=bits?bits:ilog(b[i]);
  95585. if(oggpackB_look(&r,tbit)==-1)
  95586. report("out of data!\n");
  95587. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95588. report("looked at incorrect value!\n");
  95589. if(tbit==1)
  95590. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95591. report("looked at single bit incorrect value!\n");
  95592. if(tbit==1){
  95593. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95594. report("read incorrect single bit value!\n");
  95595. }else{
  95596. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95597. report("read incorrect value!\n");
  95598. }
  95599. }
  95600. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95601. }
  95602. int main(void){
  95603. unsigned char *buffer;
  95604. long bytes,i;
  95605. static unsigned long testbuffer1[]=
  95606. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95607. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95608. int test1size=43;
  95609. static unsigned long testbuffer2[]=
  95610. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95611. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95612. 85525151,0,12321,1,349528352};
  95613. int test2size=21;
  95614. static unsigned long testbuffer3[]=
  95615. {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,
  95616. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95617. int test3size=56;
  95618. static unsigned long large[]=
  95619. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95620. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95621. 85525151,0,12321,1,2146528352};
  95622. int onesize=33;
  95623. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95624. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95625. 223,4};
  95626. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95627. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95628. 245,251,128};
  95629. int twosize=6;
  95630. static int two[6]={61,255,255,251,231,29};
  95631. static int twoB[6]={247,63,255,253,249,120};
  95632. int threesize=54;
  95633. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95634. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95635. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95636. 100,52,4,14,18,86,77,1};
  95637. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95638. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95639. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95640. 200,20,254,4,58,106,176,144,0};
  95641. int foursize=38;
  95642. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95643. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95644. 28,2,133,0,1};
  95645. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95646. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95647. 129,10,4,32};
  95648. int fivesize=45;
  95649. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95650. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95651. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95652. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95653. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95654. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95655. int sixsize=7;
  95656. static int six[7]={17,177,170,242,169,19,148};
  95657. static int sixB[7]={136,141,85,79,149,200,41};
  95658. oggpack_writeinit(&o);
  95659. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95660. cliptest(testbuffer1,test1size,0,one,onesize);
  95661. fprintf(stderr,"ok.");
  95662. fprintf(stderr,"\nNull bit call (LSb): ");
  95663. cliptest(testbuffer3,test3size,0,two,twosize);
  95664. fprintf(stderr,"ok.");
  95665. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95666. cliptest(testbuffer2,test2size,0,three,threesize);
  95667. fprintf(stderr,"ok.");
  95668. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95669. oggpack_reset(&o);
  95670. for(i=0;i<test2size;i++)
  95671. oggpack_write(&o,large[i],32);
  95672. buffer=oggpack_get_buffer(&o);
  95673. bytes=oggpack_bytes(&o);
  95674. oggpack_readinit(&r,buffer,bytes);
  95675. for(i=0;i<test2size;i++){
  95676. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95677. if(oggpack_look(&r,32)!=large[i]){
  95678. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95679. oggpack_look(&r,32),large[i]);
  95680. report("read incorrect value!\n");
  95681. }
  95682. oggpack_adv(&r,32);
  95683. }
  95684. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95685. fprintf(stderr,"ok.");
  95686. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95687. cliptest(testbuffer1,test1size,7,four,foursize);
  95688. fprintf(stderr,"ok.");
  95689. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95690. cliptest(testbuffer2,test2size,17,five,fivesize);
  95691. fprintf(stderr,"ok.");
  95692. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95693. cliptest(testbuffer3,test3size,1,six,sixsize);
  95694. fprintf(stderr,"ok.");
  95695. fprintf(stderr,"\nTesting read past end (LSb): ");
  95696. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95697. for(i=0;i<64;i++){
  95698. if(oggpack_read(&r,1)!=0){
  95699. fprintf(stderr,"failed; got -1 prematurely.\n");
  95700. exit(1);
  95701. }
  95702. }
  95703. if(oggpack_look(&r,1)!=-1 ||
  95704. oggpack_read(&r,1)!=-1){
  95705. fprintf(stderr,"failed; read past end without -1.\n");
  95706. exit(1);
  95707. }
  95708. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95709. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95710. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95711. exit(1);
  95712. }
  95713. if(oggpack_look(&r,18)!=0 ||
  95714. oggpack_look(&r,18)!=0){
  95715. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95716. exit(1);
  95717. }
  95718. if(oggpack_look(&r,19)!=-1 ||
  95719. oggpack_look(&r,19)!=-1){
  95720. fprintf(stderr,"failed; read past end without -1.\n");
  95721. exit(1);
  95722. }
  95723. if(oggpack_look(&r,32)!=-1 ||
  95724. oggpack_look(&r,32)!=-1){
  95725. fprintf(stderr,"failed; read past end without -1.\n");
  95726. exit(1);
  95727. }
  95728. oggpack_writeclear(&o);
  95729. fprintf(stderr,"ok.\n");
  95730. oggpackB_writeinit(&o);
  95731. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95732. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95733. fprintf(stderr,"ok.");
  95734. fprintf(stderr,"\nNull bit call (MSb): ");
  95735. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95736. fprintf(stderr,"ok.");
  95737. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95738. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95739. fprintf(stderr,"ok.");
  95740. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95741. oggpackB_reset(&o);
  95742. for(i=0;i<test2size;i++)
  95743. oggpackB_write(&o,large[i],32);
  95744. buffer=oggpackB_get_buffer(&o);
  95745. bytes=oggpackB_bytes(&o);
  95746. oggpackB_readinit(&r,buffer,bytes);
  95747. for(i=0;i<test2size;i++){
  95748. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95749. if(oggpackB_look(&r,32)!=large[i]){
  95750. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95751. oggpackB_look(&r,32),large[i]);
  95752. report("read incorrect value!\n");
  95753. }
  95754. oggpackB_adv(&r,32);
  95755. }
  95756. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95757. fprintf(stderr,"ok.");
  95758. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95759. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95760. fprintf(stderr,"ok.");
  95761. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95762. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95763. fprintf(stderr,"ok.");
  95764. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95765. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95766. fprintf(stderr,"ok.");
  95767. fprintf(stderr,"\nTesting read past end (MSb): ");
  95768. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95769. for(i=0;i<64;i++){
  95770. if(oggpackB_read(&r,1)!=0){
  95771. fprintf(stderr,"failed; got -1 prematurely.\n");
  95772. exit(1);
  95773. }
  95774. }
  95775. if(oggpackB_look(&r,1)!=-1 ||
  95776. oggpackB_read(&r,1)!=-1){
  95777. fprintf(stderr,"failed; read past end without -1.\n");
  95778. exit(1);
  95779. }
  95780. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95781. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95782. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95783. exit(1);
  95784. }
  95785. if(oggpackB_look(&r,18)!=0 ||
  95786. oggpackB_look(&r,18)!=0){
  95787. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95788. exit(1);
  95789. }
  95790. if(oggpackB_look(&r,19)!=-1 ||
  95791. oggpackB_look(&r,19)!=-1){
  95792. fprintf(stderr,"failed; read past end without -1.\n");
  95793. exit(1);
  95794. }
  95795. if(oggpackB_look(&r,32)!=-1 ||
  95796. oggpackB_look(&r,32)!=-1){
  95797. fprintf(stderr,"failed; read past end without -1.\n");
  95798. exit(1);
  95799. }
  95800. oggpackB_writeclear(&o);
  95801. fprintf(stderr,"ok.\n\n");
  95802. return(0);
  95803. }
  95804. #endif /* _V_SELFTEST */
  95805. #undef BUFFER_INCREMENT
  95806. #endif
  95807. /*** End of inlined file: bitwise.c ***/
  95808. /*** Start of inlined file: framing.c ***/
  95809. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95810. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95811. // tasks..
  95812. #if JUCE_MSVC
  95813. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95814. #endif
  95815. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95816. #if JUCE_USE_OGGVORBIS
  95817. #include <stdlib.h>
  95818. #include <string.h>
  95819. int ogg_page_version(ogg_page *og){
  95820. return((int)(og->header[4]));
  95821. }
  95822. int ogg_page_continued(ogg_page *og){
  95823. return((int)(og->header[5]&0x01));
  95824. }
  95825. int ogg_page_bos(ogg_page *og){
  95826. return((int)(og->header[5]&0x02));
  95827. }
  95828. int ogg_page_eos(ogg_page *og){
  95829. return((int)(og->header[5]&0x04));
  95830. }
  95831. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95832. unsigned char *page=og->header;
  95833. ogg_int64_t granulepos=page[13]&(0xff);
  95834. granulepos= (granulepos<<8)|(page[12]&0xff);
  95835. granulepos= (granulepos<<8)|(page[11]&0xff);
  95836. granulepos= (granulepos<<8)|(page[10]&0xff);
  95837. granulepos= (granulepos<<8)|(page[9]&0xff);
  95838. granulepos= (granulepos<<8)|(page[8]&0xff);
  95839. granulepos= (granulepos<<8)|(page[7]&0xff);
  95840. granulepos= (granulepos<<8)|(page[6]&0xff);
  95841. return(granulepos);
  95842. }
  95843. int ogg_page_serialno(ogg_page *og){
  95844. return(og->header[14] |
  95845. (og->header[15]<<8) |
  95846. (og->header[16]<<16) |
  95847. (og->header[17]<<24));
  95848. }
  95849. long ogg_page_pageno(ogg_page *og){
  95850. return(og->header[18] |
  95851. (og->header[19]<<8) |
  95852. (og->header[20]<<16) |
  95853. (og->header[21]<<24));
  95854. }
  95855. int ogg_page_packets(ogg_page *og){
  95856. int i,n=og->header[26],count=0;
  95857. for(i=0;i<n;i++)
  95858. if(og->header[27+i]<255)count++;
  95859. return(count);
  95860. }
  95861. #if 0
  95862. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95863. int i;
  95864. unsigned long r;
  95865. r = index << 24;
  95866. for (i=0; i<8; i++)
  95867. if (r & 0x80000000UL)
  95868. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95869. polynomial, although we use an
  95870. unreflected alg and an init/final
  95871. of 0, not 0xffffffff */
  95872. else
  95873. r<<=1;
  95874. return (r & 0xffffffffUL);
  95875. }
  95876. #endif
  95877. static const ogg_uint32_t crc_lookup[256]={
  95878. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95879. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95880. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95881. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95882. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95883. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95884. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95885. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95886. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95887. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95888. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95889. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95890. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95891. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95892. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95893. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95894. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95895. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95896. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95897. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95898. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95899. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95900. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95901. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95902. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95903. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95904. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95905. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95906. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95907. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95908. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95909. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95910. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95911. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95912. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95913. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95914. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95915. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95916. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95917. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95918. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95919. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95920. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95921. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95922. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95923. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95924. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95925. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95926. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95927. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95928. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95929. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95930. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95931. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95932. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95933. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95934. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95935. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95936. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95937. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95938. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95939. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95940. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95941. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95942. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95943. if(os){
  95944. memset(os,0,sizeof(*os));
  95945. os->body_storage=16*1024;
  95946. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95947. os->lacing_storage=1024;
  95948. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95949. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95950. os->serialno=serialno;
  95951. return(0);
  95952. }
  95953. return(-1);
  95954. }
  95955. int ogg_stream_clear(ogg_stream_state *os){
  95956. if(os){
  95957. if(os->body_data)_ogg_free(os->body_data);
  95958. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95959. if(os->granule_vals)_ogg_free(os->granule_vals);
  95960. memset(os,0,sizeof(*os));
  95961. }
  95962. return(0);
  95963. }
  95964. int ogg_stream_destroy(ogg_stream_state *os){
  95965. if(os){
  95966. ogg_stream_clear(os);
  95967. _ogg_free(os);
  95968. }
  95969. return(0);
  95970. }
  95971. static void _os_body_expand(ogg_stream_state *os,int needed){
  95972. if(os->body_storage<=os->body_fill+needed){
  95973. os->body_storage+=(needed+1024);
  95974. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95975. }
  95976. }
  95977. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95978. if(os->lacing_storage<=os->lacing_fill+needed){
  95979. os->lacing_storage+=(needed+32);
  95980. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95981. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95982. }
  95983. }
  95984. void ogg_page_checksum_set(ogg_page *og){
  95985. if(og){
  95986. ogg_uint32_t crc_reg=0;
  95987. int i;
  95988. og->header[22]=0;
  95989. og->header[23]=0;
  95990. og->header[24]=0;
  95991. og->header[25]=0;
  95992. for(i=0;i<og->header_len;i++)
  95993. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95994. for(i=0;i<og->body_len;i++)
  95995. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95996. og->header[22]=(unsigned char)(crc_reg&0xff);
  95997. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95998. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95999. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  96000. }
  96001. }
  96002. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  96003. int lacing_vals=op->bytes/255+1,i;
  96004. if(os->body_returned){
  96005. os->body_fill-=os->body_returned;
  96006. if(os->body_fill)
  96007. memmove(os->body_data,os->body_data+os->body_returned,
  96008. os->body_fill);
  96009. os->body_returned=0;
  96010. }
  96011. _os_body_expand(os,op->bytes);
  96012. _os_lacing_expand(os,lacing_vals);
  96013. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  96014. os->body_fill+=op->bytes;
  96015. for(i=0;i<lacing_vals-1;i++){
  96016. os->lacing_vals[os->lacing_fill+i]=255;
  96017. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  96018. }
  96019. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  96020. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  96021. os->lacing_vals[os->lacing_fill]|= 0x100;
  96022. os->lacing_fill+=lacing_vals;
  96023. os->packetno++;
  96024. if(op->e_o_s)os->e_o_s=1;
  96025. return(0);
  96026. }
  96027. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  96028. int i;
  96029. int vals=0;
  96030. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  96031. int bytes=0;
  96032. long acc=0;
  96033. ogg_int64_t granule_pos=-1;
  96034. if(maxvals==0)return(0);
  96035. if(os->b_o_s==0){ /* 'initial header page' case */
  96036. granule_pos=0;
  96037. for(vals=0;vals<maxvals;vals++){
  96038. if((os->lacing_vals[vals]&0x0ff)<255){
  96039. vals++;
  96040. break;
  96041. }
  96042. }
  96043. }else{
  96044. for(vals=0;vals<maxvals;vals++){
  96045. if(acc>4096)break;
  96046. acc+=os->lacing_vals[vals]&0x0ff;
  96047. if((os->lacing_vals[vals]&0xff)<255)
  96048. granule_pos=os->granule_vals[vals];
  96049. }
  96050. }
  96051. memcpy(os->header,"OggS",4);
  96052. os->header[4]=0x00;
  96053. os->header[5]=0x00;
  96054. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  96055. if(os->b_o_s==0)os->header[5]|=0x02;
  96056. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  96057. os->b_o_s=1;
  96058. for(i=6;i<14;i++){
  96059. os->header[i]=(unsigned char)(granule_pos&0xff);
  96060. granule_pos>>=8;
  96061. }
  96062. {
  96063. long serialno=os->serialno;
  96064. for(i=14;i<18;i++){
  96065. os->header[i]=(unsigned char)(serialno&0xff);
  96066. serialno>>=8;
  96067. }
  96068. }
  96069. if(os->pageno==-1)os->pageno=0; /* because someone called
  96070. stream_reset; this would be a
  96071. strange thing to do in an
  96072. encode stream, but it has
  96073. plausible uses */
  96074. {
  96075. long pageno=os->pageno++;
  96076. for(i=18;i<22;i++){
  96077. os->header[i]=(unsigned char)(pageno&0xff);
  96078. pageno>>=8;
  96079. }
  96080. }
  96081. os->header[22]=0;
  96082. os->header[23]=0;
  96083. os->header[24]=0;
  96084. os->header[25]=0;
  96085. os->header[26]=(unsigned char)(vals&0xff);
  96086. for(i=0;i<vals;i++)
  96087. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  96088. og->header=os->header;
  96089. og->header_len=os->header_fill=vals+27;
  96090. og->body=os->body_data+os->body_returned;
  96091. og->body_len=bytes;
  96092. os->lacing_fill-=vals;
  96093. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  96094. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  96095. os->body_returned+=bytes;
  96096. ogg_page_checksum_set(og);
  96097. return(1);
  96098. }
  96099. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96100. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96101. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96102. os->lacing_fill>=255 || /* 'segment table full' case */
  96103. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96104. return(ogg_stream_flush(os,og));
  96105. }
  96106. return(0);
  96107. }
  96108. int ogg_stream_eos(ogg_stream_state *os){
  96109. return os->e_o_s;
  96110. }
  96111. int ogg_sync_init(ogg_sync_state *oy){
  96112. if(oy){
  96113. memset(oy,0,sizeof(*oy));
  96114. }
  96115. return(0);
  96116. }
  96117. int ogg_sync_clear(ogg_sync_state *oy){
  96118. if(oy){
  96119. if(oy->data)_ogg_free(oy->data);
  96120. ogg_sync_init(oy);
  96121. }
  96122. return(0);
  96123. }
  96124. int ogg_sync_destroy(ogg_sync_state *oy){
  96125. if(oy){
  96126. ogg_sync_clear(oy);
  96127. _ogg_free(oy);
  96128. }
  96129. return(0);
  96130. }
  96131. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96132. if(oy->returned){
  96133. oy->fill-=oy->returned;
  96134. if(oy->fill>0)
  96135. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96136. oy->returned=0;
  96137. }
  96138. if(size>oy->storage-oy->fill){
  96139. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96140. if(oy->data)
  96141. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96142. else
  96143. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96144. oy->storage=newsize;
  96145. }
  96146. return((char *)oy->data+oy->fill);
  96147. }
  96148. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96149. if(oy->fill+bytes>oy->storage)return(-1);
  96150. oy->fill+=bytes;
  96151. return(0);
  96152. }
  96153. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96154. unsigned char *page=oy->data+oy->returned;
  96155. unsigned char *next;
  96156. long bytes=oy->fill-oy->returned;
  96157. if(oy->headerbytes==0){
  96158. int headerbytes,i;
  96159. if(bytes<27)return(0); /* not enough for a header */
  96160. if(memcmp(page,"OggS",4))goto sync_fail;
  96161. headerbytes=page[26]+27;
  96162. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96163. for(i=0;i<page[26];i++)
  96164. oy->bodybytes+=page[27+i];
  96165. oy->headerbytes=headerbytes;
  96166. }
  96167. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96168. {
  96169. char chksum[4];
  96170. ogg_page log;
  96171. memcpy(chksum,page+22,4);
  96172. memset(page+22,0,4);
  96173. log.header=page;
  96174. log.header_len=oy->headerbytes;
  96175. log.body=page+oy->headerbytes;
  96176. log.body_len=oy->bodybytes;
  96177. ogg_page_checksum_set(&log);
  96178. if(memcmp(chksum,page+22,4)){
  96179. memcpy(page+22,chksum,4);
  96180. goto sync_fail;
  96181. }
  96182. }
  96183. {
  96184. unsigned char *page=oy->data+oy->returned;
  96185. long bytes;
  96186. if(og){
  96187. og->header=page;
  96188. og->header_len=oy->headerbytes;
  96189. og->body=page+oy->headerbytes;
  96190. og->body_len=oy->bodybytes;
  96191. }
  96192. oy->unsynced=0;
  96193. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96194. oy->headerbytes=0;
  96195. oy->bodybytes=0;
  96196. return(bytes);
  96197. }
  96198. sync_fail:
  96199. oy->headerbytes=0;
  96200. oy->bodybytes=0;
  96201. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96202. if(!next)
  96203. next=oy->data+oy->fill;
  96204. oy->returned=next-oy->data;
  96205. return(-(next-page));
  96206. }
  96207. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96208. for(;;){
  96209. long ret=ogg_sync_pageseek(oy,og);
  96210. if(ret>0){
  96211. return(1);
  96212. }
  96213. if(ret==0){
  96214. return(0);
  96215. }
  96216. if(!oy->unsynced){
  96217. oy->unsynced=1;
  96218. return(-1);
  96219. }
  96220. }
  96221. }
  96222. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96223. unsigned char *header=og->header;
  96224. unsigned char *body=og->body;
  96225. long bodysize=og->body_len;
  96226. int segptr=0;
  96227. int version=ogg_page_version(og);
  96228. int continued=ogg_page_continued(og);
  96229. int bos=ogg_page_bos(og);
  96230. int eos=ogg_page_eos(og);
  96231. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96232. int serialno=ogg_page_serialno(og);
  96233. long pageno=ogg_page_pageno(og);
  96234. int segments=header[26];
  96235. {
  96236. long lr=os->lacing_returned;
  96237. long br=os->body_returned;
  96238. if(br){
  96239. os->body_fill-=br;
  96240. if(os->body_fill)
  96241. memmove(os->body_data,os->body_data+br,os->body_fill);
  96242. os->body_returned=0;
  96243. }
  96244. if(lr){
  96245. if(os->lacing_fill-lr){
  96246. memmove(os->lacing_vals,os->lacing_vals+lr,
  96247. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96248. memmove(os->granule_vals,os->granule_vals+lr,
  96249. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96250. }
  96251. os->lacing_fill-=lr;
  96252. os->lacing_packet-=lr;
  96253. os->lacing_returned=0;
  96254. }
  96255. }
  96256. if(serialno!=os->serialno)return(-1);
  96257. if(version>0)return(-1);
  96258. _os_lacing_expand(os,segments+1);
  96259. if(pageno!=os->pageno){
  96260. int i;
  96261. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96262. os->body_fill-=os->lacing_vals[i]&0xff;
  96263. os->lacing_fill=os->lacing_packet;
  96264. if(os->pageno!=-1){
  96265. os->lacing_vals[os->lacing_fill++]=0x400;
  96266. os->lacing_packet++;
  96267. }
  96268. }
  96269. if(continued){
  96270. if(os->lacing_fill<1 ||
  96271. os->lacing_vals[os->lacing_fill-1]==0x400){
  96272. bos=0;
  96273. for(;segptr<segments;segptr++){
  96274. int val=header[27+segptr];
  96275. body+=val;
  96276. bodysize-=val;
  96277. if(val<255){
  96278. segptr++;
  96279. break;
  96280. }
  96281. }
  96282. }
  96283. }
  96284. if(bodysize){
  96285. _os_body_expand(os,bodysize);
  96286. memcpy(os->body_data+os->body_fill,body,bodysize);
  96287. os->body_fill+=bodysize;
  96288. }
  96289. {
  96290. int saved=-1;
  96291. while(segptr<segments){
  96292. int val=header[27+segptr];
  96293. os->lacing_vals[os->lacing_fill]=val;
  96294. os->granule_vals[os->lacing_fill]=-1;
  96295. if(bos){
  96296. os->lacing_vals[os->lacing_fill]|=0x100;
  96297. bos=0;
  96298. }
  96299. if(val<255)saved=os->lacing_fill;
  96300. os->lacing_fill++;
  96301. segptr++;
  96302. if(val<255)os->lacing_packet=os->lacing_fill;
  96303. }
  96304. if(saved!=-1){
  96305. os->granule_vals[saved]=granulepos;
  96306. }
  96307. }
  96308. if(eos){
  96309. os->e_o_s=1;
  96310. if(os->lacing_fill>0)
  96311. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96312. }
  96313. os->pageno=pageno+1;
  96314. return(0);
  96315. }
  96316. int ogg_sync_reset(ogg_sync_state *oy){
  96317. oy->fill=0;
  96318. oy->returned=0;
  96319. oy->unsynced=0;
  96320. oy->headerbytes=0;
  96321. oy->bodybytes=0;
  96322. return(0);
  96323. }
  96324. int ogg_stream_reset(ogg_stream_state *os){
  96325. os->body_fill=0;
  96326. os->body_returned=0;
  96327. os->lacing_fill=0;
  96328. os->lacing_packet=0;
  96329. os->lacing_returned=0;
  96330. os->header_fill=0;
  96331. os->e_o_s=0;
  96332. os->b_o_s=0;
  96333. os->pageno=-1;
  96334. os->packetno=0;
  96335. os->granulepos=0;
  96336. return(0);
  96337. }
  96338. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96339. ogg_stream_reset(os);
  96340. os->serialno=serialno;
  96341. return(0);
  96342. }
  96343. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96344. int ptr=os->lacing_returned;
  96345. if(os->lacing_packet<=ptr)return(0);
  96346. if(os->lacing_vals[ptr]&0x400){
  96347. os->lacing_returned++;
  96348. os->packetno++;
  96349. return(-1);
  96350. }
  96351. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96352. to ask if there's a whole packet
  96353. waiting */
  96354. {
  96355. int size=os->lacing_vals[ptr]&0xff;
  96356. int bytes=size;
  96357. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96358. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96359. while(size==255){
  96360. int val=os->lacing_vals[++ptr];
  96361. size=val&0xff;
  96362. if(val&0x200)eos=0x200;
  96363. bytes+=size;
  96364. }
  96365. if(op){
  96366. op->e_o_s=eos;
  96367. op->b_o_s=bos;
  96368. op->packet=os->body_data+os->body_returned;
  96369. op->packetno=os->packetno;
  96370. op->granulepos=os->granule_vals[ptr];
  96371. op->bytes=bytes;
  96372. }
  96373. if(adv){
  96374. os->body_returned+=bytes;
  96375. os->lacing_returned=ptr+1;
  96376. os->packetno++;
  96377. }
  96378. }
  96379. return(1);
  96380. }
  96381. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96382. return _packetout(os,op,1);
  96383. }
  96384. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96385. return _packetout(os,op,0);
  96386. }
  96387. void ogg_packet_clear(ogg_packet *op) {
  96388. _ogg_free(op->packet);
  96389. memset(op, 0, sizeof(*op));
  96390. }
  96391. #ifdef _V_SELFTEST
  96392. #include <stdio.h>
  96393. ogg_stream_state os_en, os_de;
  96394. ogg_sync_state oy;
  96395. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96396. long j;
  96397. static int sequence=0;
  96398. static int lastno=0;
  96399. if(op->bytes!=len){
  96400. fprintf(stderr,"incorrect packet length!\n");
  96401. exit(1);
  96402. }
  96403. if(op->granulepos!=pos){
  96404. fprintf(stderr,"incorrect packet position!\n");
  96405. exit(1);
  96406. }
  96407. if(no==0){
  96408. sequence=0;
  96409. }else{
  96410. sequence++;
  96411. if(no>lastno+1)
  96412. sequence++;
  96413. }
  96414. lastno=no;
  96415. if(op->packetno!=sequence){
  96416. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96417. (long)(op->packetno),sequence);
  96418. exit(1);
  96419. }
  96420. for(j=0;j<op->bytes;j++)
  96421. if(op->packet[j]!=((j+no)&0xff)){
  96422. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96423. j,op->packet[j],(j+no)&0xff);
  96424. exit(1);
  96425. }
  96426. }
  96427. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96428. long j;
  96429. for(j=0;j<og->body_len;j++)
  96430. if(og->body[j]!=data[j]){
  96431. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96432. j,data[j],og->body[j]);
  96433. exit(1);
  96434. }
  96435. for(j=0;j<og->header_len;j++){
  96436. if(og->header[j]!=header[j]){
  96437. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96438. for(j=0;j<header[26]+27;j++)
  96439. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96440. fprintf(stderr,"\n");
  96441. exit(1);
  96442. }
  96443. }
  96444. if(og->header_len!=header[26]+27){
  96445. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96446. og->header_len,header[26]+27);
  96447. exit(1);
  96448. }
  96449. }
  96450. void print_header(ogg_page *og){
  96451. int j;
  96452. fprintf(stderr,"\nHEADER:\n");
  96453. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96454. og->header[0],og->header[1],og->header[2],og->header[3],
  96455. (int)og->header[4],(int)og->header[5]);
  96456. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96457. (og->header[9]<<24)|(og->header[8]<<16)|
  96458. (og->header[7]<<8)|og->header[6],
  96459. (og->header[17]<<24)|(og->header[16]<<16)|
  96460. (og->header[15]<<8)|og->header[14],
  96461. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96462. (og->header[19]<<8)|og->header[18]);
  96463. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96464. (int)og->header[22],(int)og->header[23],
  96465. (int)og->header[24],(int)og->header[25],
  96466. (int)og->header[26]);
  96467. for(j=27;j<og->header_len;j++)
  96468. fprintf(stderr,"%d ",(int)og->header[j]);
  96469. fprintf(stderr,")\n\n");
  96470. }
  96471. void copy_page(ogg_page *og){
  96472. unsigned char *temp=_ogg_malloc(og->header_len);
  96473. memcpy(temp,og->header,og->header_len);
  96474. og->header=temp;
  96475. temp=_ogg_malloc(og->body_len);
  96476. memcpy(temp,og->body,og->body_len);
  96477. og->body=temp;
  96478. }
  96479. void free_page(ogg_page *og){
  96480. _ogg_free (og->header);
  96481. _ogg_free (og->body);
  96482. }
  96483. void error(void){
  96484. fprintf(stderr,"error!\n");
  96485. exit(1);
  96486. }
  96487. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96488. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96489. 0x01,0x02,0x03,0x04,0,0,0,0,
  96490. 0x15,0xed,0xec,0x91,
  96491. 1,
  96492. 17};
  96493. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96494. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96495. 0x01,0x02,0x03,0x04,0,0,0,0,
  96496. 0x59,0x10,0x6c,0x2c,
  96497. 1,
  96498. 17};
  96499. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96500. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96501. 0x01,0x02,0x03,0x04,1,0,0,0,
  96502. 0x89,0x33,0x85,0xce,
  96503. 13,
  96504. 254,255,0,255,1,255,245,255,255,0,
  96505. 255,255,90};
  96506. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96507. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96508. 0x01,0x02,0x03,0x04,0,0,0,0,
  96509. 0xff,0x7b,0x23,0x17,
  96510. 1,
  96511. 0};
  96512. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96513. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96514. 0x01,0x02,0x03,0x04,1,0,0,0,
  96515. 0x5c,0x3f,0x66,0xcb,
  96516. 17,
  96517. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96518. 255,255,90,0};
  96519. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96520. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96521. 0x01,0x02,0x03,0x04,0,0,0,0,
  96522. 0x01,0x27,0x31,0xaa,
  96523. 18,
  96524. 255,255,255,255,255,255,255,255,
  96525. 255,255,255,255,255,255,255,255,255,10};
  96526. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96527. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96528. 0x01,0x02,0x03,0x04,1,0,0,0,
  96529. 0x7f,0x4e,0x8a,0xd2,
  96530. 4,
  96531. 255,4,255,0};
  96532. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96533. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96534. 0x01,0x02,0x03,0x04,0,0,0,0,
  96535. 0xff,0x7b,0x23,0x17,
  96536. 1,
  96537. 0};
  96538. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96539. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96540. 0x01,0x02,0x03,0x04,1,0,0,0,
  96541. 0x54,0x05,0x51,0xc8,
  96542. 17,
  96543. 255,255,255,255,255,255,255,255,
  96544. 255,255,255,255,255,255,255,255,255};
  96545. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96546. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96547. 0x01,0x02,0x03,0x04,2,0,0,0,
  96548. 0xc8,0xc3,0xcb,0xed,
  96549. 5,
  96550. 10,255,4,255,0};
  96551. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96552. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96553. 0x01,0x02,0x03,0x04,0,0,0,0,
  96554. 0xff,0x7b,0x23,0x17,
  96555. 1,
  96556. 0};
  96557. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96558. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96559. 0x01,0x02,0x03,0x04,1,0,0,0,
  96560. 0xed,0x2a,0x2e,0xa7,
  96561. 255,
  96562. 10,10,10,10,10,10,10,10,
  96563. 10,10,10,10,10,10,10,10,
  96564. 10,10,10,10,10,10,10,10,
  96565. 10,10,10,10,10,10,10,10,
  96566. 10,10,10,10,10,10,10,10,
  96567. 10,10,10,10,10,10,10,10,
  96568. 10,10,10,10,10,10,10,10,
  96569. 10,10,10,10,10,10,10,10,
  96570. 10,10,10,10,10,10,10,10,
  96571. 10,10,10,10,10,10,10,10,
  96572. 10,10,10,10,10,10,10,10,
  96573. 10,10,10,10,10,10,10,10,
  96574. 10,10,10,10,10,10,10,10,
  96575. 10,10,10,10,10,10,10,10,
  96576. 10,10,10,10,10,10,10,10,
  96577. 10,10,10,10,10,10,10,10,
  96578. 10,10,10,10,10,10,10,10,
  96579. 10,10,10,10,10,10,10,10,
  96580. 10,10,10,10,10,10,10,10,
  96581. 10,10,10,10,10,10,10,10,
  96582. 10,10,10,10,10,10,10,10,
  96583. 10,10,10,10,10,10,10,10,
  96584. 10,10,10,10,10,10,10,10,
  96585. 10,10,10,10,10,10,10,10,
  96586. 10,10,10,10,10,10,10,10,
  96587. 10,10,10,10,10,10,10,10,
  96588. 10,10,10,10,10,10,10,10,
  96589. 10,10,10,10,10,10,10,10,
  96590. 10,10,10,10,10,10,10,10,
  96591. 10,10,10,10,10,10,10,10,
  96592. 10,10,10,10,10,10,10,10,
  96593. 10,10,10,10,10,10,10};
  96594. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96595. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96596. 0x01,0x02,0x03,0x04,2,0,0,0,
  96597. 0x6c,0x3b,0x82,0x3d,
  96598. 1,
  96599. 50};
  96600. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96601. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96602. 0x01,0x02,0x03,0x04,0,0,0,0,
  96603. 0xff,0x7b,0x23,0x17,
  96604. 1,
  96605. 0};
  96606. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96607. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96608. 0x01,0x02,0x03,0x04,1,0,0,0,
  96609. 0x3c,0xd9,0x4d,0x3f,
  96610. 17,
  96611. 100,255,255,255,255,255,255,255,255,
  96612. 255,255,255,255,255,255,255,255};
  96613. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96614. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96615. 0x01,0x02,0x03,0x04,2,0,0,0,
  96616. 0x01,0xd2,0xe5,0xe5,
  96617. 17,
  96618. 255,255,255,255,255,255,255,255,
  96619. 255,255,255,255,255,255,255,255,255};
  96620. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96621. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96622. 0x01,0x02,0x03,0x04,3,0,0,0,
  96623. 0xef,0xdd,0x88,0xde,
  96624. 7,
  96625. 255,255,75,255,4,255,0};
  96626. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96627. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96628. 0x01,0x02,0x03,0x04,0,0,0,0,
  96629. 0xff,0x7b,0x23,0x17,
  96630. 1,
  96631. 0};
  96632. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96633. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96634. 0x01,0x02,0x03,0x04,1,0,0,0,
  96635. 0x3c,0xd9,0x4d,0x3f,
  96636. 17,
  96637. 100,255,255,255,255,255,255,255,255,
  96638. 255,255,255,255,255,255,255,255};
  96639. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96640. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96641. 0x01,0x02,0x03,0x04,2,0,0,0,
  96642. 0xd4,0xe0,0x60,0xe5,
  96643. 1,0};
  96644. void test_pack(const int *pl, const int **headers, int byteskip,
  96645. int pageskip, int packetskip){
  96646. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96647. long inptr=0;
  96648. long outptr=0;
  96649. long deptr=0;
  96650. long depacket=0;
  96651. long granule_pos=7,pageno=0;
  96652. int i,j,packets,pageout=pageskip;
  96653. int eosflag=0;
  96654. int bosflag=0;
  96655. int byteskipcount=0;
  96656. ogg_stream_reset(&os_en);
  96657. ogg_stream_reset(&os_de);
  96658. ogg_sync_reset(&oy);
  96659. for(packets=0;packets<packetskip;packets++)
  96660. depacket+=pl[packets];
  96661. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96662. for(i=0;i<packets;i++){
  96663. ogg_packet op;
  96664. int len=pl[i];
  96665. op.packet=data+inptr;
  96666. op.bytes=len;
  96667. op.e_o_s=(pl[i+1]<0?1:0);
  96668. op.granulepos=granule_pos;
  96669. granule_pos+=1024;
  96670. for(j=0;j<len;j++)data[inptr++]=i+j;
  96671. ogg_stream_packetin(&os_en,&op);
  96672. {
  96673. ogg_page og;
  96674. while(ogg_stream_pageout(&os_en,&og)){
  96675. fprintf(stderr,"%ld, ",pageno);
  96676. if(headers[pageno]==NULL){
  96677. fprintf(stderr,"coded too many pages!\n");
  96678. exit(1);
  96679. }
  96680. check_page(data+outptr,headers[pageno],&og);
  96681. outptr+=og.body_len;
  96682. pageno++;
  96683. if(pageskip){
  96684. bosflag=1;
  96685. pageskip--;
  96686. deptr+=og.body_len;
  96687. }
  96688. {
  96689. ogg_page og_de;
  96690. ogg_packet op_de,op_de2;
  96691. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96692. char *next=buf;
  96693. byteskipcount+=og.header_len;
  96694. if(byteskipcount>byteskip){
  96695. memcpy(next,og.header,byteskipcount-byteskip);
  96696. next+=byteskipcount-byteskip;
  96697. byteskipcount=byteskip;
  96698. }
  96699. byteskipcount+=og.body_len;
  96700. if(byteskipcount>byteskip){
  96701. memcpy(next,og.body,byteskipcount-byteskip);
  96702. next+=byteskipcount-byteskip;
  96703. byteskipcount=byteskip;
  96704. }
  96705. ogg_sync_wrote(&oy,next-buf);
  96706. while(1){
  96707. int ret=ogg_sync_pageout(&oy,&og_de);
  96708. if(ret==0)break;
  96709. if(ret<0)continue;
  96710. fprintf(stderr,"(%ld), ",pageout);
  96711. check_page(data+deptr,headers[pageout],&og_de);
  96712. deptr+=og_de.body_len;
  96713. pageout++;
  96714. ogg_stream_pagein(&os_de,&og_de);
  96715. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96716. ogg_stream_packetpeek(&os_de,NULL);
  96717. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96718. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96719. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96720. depacket);
  96721. exit(1);
  96722. }
  96723. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96724. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96725. depacket);
  96726. exit(1);
  96727. }
  96728. if(bosflag==0 && op_de.b_o_s==0){
  96729. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96730. exit(1);
  96731. }
  96732. if(bosflag && op_de.b_o_s){
  96733. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96734. exit(1);
  96735. }
  96736. bosflag=1;
  96737. depacket+=op_de.bytes;
  96738. if(eosflag){
  96739. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96740. exit(1);
  96741. }
  96742. if(op_de.e_o_s)eosflag=1;
  96743. if(op_de.granulepos!=-1){
  96744. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96745. }
  96746. }
  96747. }
  96748. }
  96749. }
  96750. }
  96751. }
  96752. _ogg_free(data);
  96753. if(headers[pageno]!=NULL){
  96754. fprintf(stderr,"did not write last page!\n");
  96755. exit(1);
  96756. }
  96757. if(headers[pageout]!=NULL){
  96758. fprintf(stderr,"did not decode last page!\n");
  96759. exit(1);
  96760. }
  96761. if(inptr!=outptr){
  96762. fprintf(stderr,"encoded page data incomplete!\n");
  96763. exit(1);
  96764. }
  96765. if(inptr!=deptr){
  96766. fprintf(stderr,"decoded page data incomplete!\n");
  96767. exit(1);
  96768. }
  96769. if(inptr!=depacket){
  96770. fprintf(stderr,"decoded packet data incomplete!\n");
  96771. exit(1);
  96772. }
  96773. if(!eosflag){
  96774. fprintf(stderr,"Never got a packet with EOS set!\n");
  96775. exit(1);
  96776. }
  96777. fprintf(stderr,"ok.\n");
  96778. }
  96779. int main(void){
  96780. ogg_stream_init(&os_en,0x04030201);
  96781. ogg_stream_init(&os_de,0x04030201);
  96782. ogg_sync_init(&oy);
  96783. {
  96784. const int packets[]={17, -1};
  96785. const int *headret[]={head1_0,NULL};
  96786. fprintf(stderr,"testing single page encoding... ");
  96787. test_pack(packets,headret,0,0,0);
  96788. }
  96789. {
  96790. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96791. const int *headret[]={head1_1,head2_1,NULL};
  96792. fprintf(stderr,"testing basic page encoding... ");
  96793. test_pack(packets,headret,0,0,0);
  96794. }
  96795. {
  96796. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96797. const int *headret[]={head1_2,head2_2,NULL};
  96798. fprintf(stderr,"testing basic nil packets... ");
  96799. test_pack(packets,headret,0,0,0);
  96800. }
  96801. {
  96802. const int packets[]={4345,259,255,-1};
  96803. const int *headret[]={head1_3,head2_3,NULL};
  96804. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96805. test_pack(packets,headret,0,0,0);
  96806. }
  96807. {
  96808. const int packets[]={0,4345,259,255,-1};
  96809. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96810. fprintf(stderr,"testing single packet page span... ");
  96811. test_pack(packets,headret,0,0,0);
  96812. }
  96813. {
  96814. const int packets[]={0,10,10,10,10,10,10,10,10,
  96815. 10,10,10,10,10,10,10,10,
  96816. 10,10,10,10,10,10,10,10,
  96817. 10,10,10,10,10,10,10,10,
  96818. 10,10,10,10,10,10,10,10,
  96819. 10,10,10,10,10,10,10,10,
  96820. 10,10,10,10,10,10,10,10,
  96821. 10,10,10,10,10,10,10,10,
  96822. 10,10,10,10,10,10,10,10,
  96823. 10,10,10,10,10,10,10,10,
  96824. 10,10,10,10,10,10,10,10,
  96825. 10,10,10,10,10,10,10,10,
  96826. 10,10,10,10,10,10,10,10,
  96827. 10,10,10,10,10,10,10,10,
  96828. 10,10,10,10,10,10,10,10,
  96829. 10,10,10,10,10,10,10,10,
  96830. 10,10,10,10,10,10,10,10,
  96831. 10,10,10,10,10,10,10,10,
  96832. 10,10,10,10,10,10,10,10,
  96833. 10,10,10,10,10,10,10,10,
  96834. 10,10,10,10,10,10,10,10,
  96835. 10,10,10,10,10,10,10,10,
  96836. 10,10,10,10,10,10,10,10,
  96837. 10,10,10,10,10,10,10,10,
  96838. 10,10,10,10,10,10,10,10,
  96839. 10,10,10,10,10,10,10,10,
  96840. 10,10,10,10,10,10,10,10,
  96841. 10,10,10,10,10,10,10,10,
  96842. 10,10,10,10,10,10,10,10,
  96843. 10,10,10,10,10,10,10,10,
  96844. 10,10,10,10,10,10,10,10,
  96845. 10,10,10,10,10,10,10,50,-1};
  96846. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96847. fprintf(stderr,"testing max packet segments... ");
  96848. test_pack(packets,headret,0,0,0);
  96849. }
  96850. {
  96851. const int packets[]={0,100,9000,259,255,-1};
  96852. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96853. fprintf(stderr,"testing very large packets... ");
  96854. test_pack(packets,headret,0,0,0);
  96855. }
  96856. {
  96857. const int packets[]={0,100,9000,259,255,-1};
  96858. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96859. fprintf(stderr,"testing continuation resync in very large packets... ");
  96860. test_pack(packets,headret,100,2,3);
  96861. }
  96862. {
  96863. const int packets[]={0,100,4080,-1};
  96864. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96865. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96866. test_pack(packets,headret,0,0,0);
  96867. }
  96868. {
  96869. unsigned char *data=_ogg_malloc(1024*1024);
  96870. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96871. int inptr=0,i,j;
  96872. ogg_page og[5];
  96873. ogg_stream_reset(&os_en);
  96874. for(i=0;pl[i]!=-1;i++){
  96875. ogg_packet op;
  96876. int len=pl[i];
  96877. op.packet=data+inptr;
  96878. op.bytes=len;
  96879. op.e_o_s=(pl[i+1]<0?1:0);
  96880. op.granulepos=(i+1)*1000;
  96881. for(j=0;j<len;j++)data[inptr++]=i+j;
  96882. ogg_stream_packetin(&os_en,&op);
  96883. }
  96884. _ogg_free(data);
  96885. for(i=0;i<5;i++){
  96886. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96887. fprintf(stderr,"Too few pages output building sync tests!\n");
  96888. exit(1);
  96889. }
  96890. copy_page(&og[i]);
  96891. }
  96892. {
  96893. ogg_page temp;
  96894. ogg_packet test;
  96895. fprintf(stderr,"Testing loss of pages... ");
  96896. ogg_sync_reset(&oy);
  96897. ogg_stream_reset(&os_de);
  96898. for(i=0;i<5;i++){
  96899. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96900. og[i].header_len);
  96901. ogg_sync_wrote(&oy,og[i].header_len);
  96902. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96903. ogg_sync_wrote(&oy,og[i].body_len);
  96904. }
  96905. ogg_sync_pageout(&oy,&temp);
  96906. ogg_stream_pagein(&os_de,&temp);
  96907. ogg_sync_pageout(&oy,&temp);
  96908. ogg_stream_pagein(&os_de,&temp);
  96909. ogg_sync_pageout(&oy,&temp);
  96910. ogg_sync_pageout(&oy,&temp);
  96911. ogg_stream_pagein(&os_de,&temp);
  96912. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96913. checkpacket(&test,0,0,0);
  96914. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96915. checkpacket(&test,100,1,-1);
  96916. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96917. checkpacket(&test,4079,2,3000);
  96918. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96919. fprintf(stderr,"Error: loss of page did not return error\n");
  96920. exit(1);
  96921. }
  96922. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96923. checkpacket(&test,76,5,-1);
  96924. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96925. checkpacket(&test,34,6,-1);
  96926. fprintf(stderr,"ok.\n");
  96927. }
  96928. {
  96929. ogg_page temp;
  96930. ogg_packet test;
  96931. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96932. ogg_sync_reset(&oy);
  96933. ogg_stream_reset(&os_de);
  96934. for(i=0;i<5;i++){
  96935. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96936. og[i].header_len);
  96937. ogg_sync_wrote(&oy,og[i].header_len);
  96938. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96939. ogg_sync_wrote(&oy,og[i].body_len);
  96940. }
  96941. ogg_sync_pageout(&oy,&temp);
  96942. ogg_stream_pagein(&os_de,&temp);
  96943. ogg_sync_pageout(&oy,&temp);
  96944. ogg_stream_pagein(&os_de,&temp);
  96945. ogg_sync_pageout(&oy,&temp);
  96946. ogg_stream_pagein(&os_de,&temp);
  96947. ogg_sync_pageout(&oy,&temp);
  96948. ogg_sync_pageout(&oy,&temp);
  96949. ogg_stream_pagein(&os_de,&temp);
  96950. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96951. checkpacket(&test,0,0,0);
  96952. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96953. checkpacket(&test,100,1,-1);
  96954. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96955. checkpacket(&test,4079,2,3000);
  96956. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96957. checkpacket(&test,2956,3,4000);
  96958. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96959. fprintf(stderr,"Error: loss of page did not return error\n");
  96960. exit(1);
  96961. }
  96962. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96963. checkpacket(&test,300,13,14000);
  96964. fprintf(stderr,"ok.\n");
  96965. }
  96966. {
  96967. ogg_page og_de;
  96968. fprintf(stderr,"Testing sync on partial inputs... ");
  96969. ogg_sync_reset(&oy);
  96970. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96971. 3);
  96972. ogg_sync_wrote(&oy,3);
  96973. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96974. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96975. 20);
  96976. ogg_sync_wrote(&oy,20);
  96977. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96978. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96979. 5);
  96980. ogg_sync_wrote(&oy,5);
  96981. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96982. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96983. og[1].header_len-28);
  96984. ogg_sync_wrote(&oy,og[1].header_len-28);
  96985. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96986. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96987. ogg_sync_wrote(&oy,1000);
  96988. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96989. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96990. og[1].body_len-1000);
  96991. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96992. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96993. fprintf(stderr,"ok.\n");
  96994. }
  96995. {
  96996. ogg_page og_de;
  96997. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96998. ogg_sync_reset(&oy);
  96999. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97000. og[1].header_len);
  97001. ogg_sync_wrote(&oy,og[1].header_len);
  97002. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97003. og[1].body_len);
  97004. ogg_sync_wrote(&oy,og[1].body_len);
  97005. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97006. 20);
  97007. ogg_sync_wrote(&oy,20);
  97008. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97009. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97010. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  97011. og[1].header_len-20);
  97012. ogg_sync_wrote(&oy,og[1].header_len-20);
  97013. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97014. og[1].body_len);
  97015. ogg_sync_wrote(&oy,og[1].body_len);
  97016. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97017. fprintf(stderr,"ok.\n");
  97018. }
  97019. {
  97020. ogg_page og_de;
  97021. fprintf(stderr,"Testing search for capture... ");
  97022. ogg_sync_reset(&oy);
  97023. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97024. og[1].body_len);
  97025. ogg_sync_wrote(&oy,og[1].body_len);
  97026. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97027. og[1].header_len);
  97028. ogg_sync_wrote(&oy,og[1].header_len);
  97029. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97030. og[1].body_len);
  97031. ogg_sync_wrote(&oy,og[1].body_len);
  97032. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97033. 20);
  97034. ogg_sync_wrote(&oy,20);
  97035. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97036. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97037. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97038. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  97039. og[2].header_len-20);
  97040. ogg_sync_wrote(&oy,og[2].header_len-20);
  97041. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97042. og[2].body_len);
  97043. ogg_sync_wrote(&oy,og[2].body_len);
  97044. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97045. fprintf(stderr,"ok.\n");
  97046. }
  97047. {
  97048. ogg_page og_de;
  97049. fprintf(stderr,"Testing recapture... ");
  97050. ogg_sync_reset(&oy);
  97051. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97052. og[1].header_len);
  97053. ogg_sync_wrote(&oy,og[1].header_len);
  97054. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97055. og[1].body_len);
  97056. ogg_sync_wrote(&oy,og[1].body_len);
  97057. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97058. og[2].header_len);
  97059. ogg_sync_wrote(&oy,og[2].header_len);
  97060. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97061. og[2].header_len);
  97062. ogg_sync_wrote(&oy,og[2].header_len);
  97063. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97064. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97065. og[2].body_len-5);
  97066. ogg_sync_wrote(&oy,og[2].body_len-5);
  97067. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  97068. og[3].header_len);
  97069. ogg_sync_wrote(&oy,og[3].header_len);
  97070. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  97071. og[3].body_len);
  97072. ogg_sync_wrote(&oy,og[3].body_len);
  97073. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97074. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97075. fprintf(stderr,"ok.\n");
  97076. }
  97077. {
  97078. for(i=0;i<5;i++){
  97079. free_page(&og[i]);
  97080. }
  97081. }
  97082. }
  97083. return(0);
  97084. }
  97085. #endif
  97086. #endif
  97087. /*** End of inlined file: framing.c ***/
  97088. /*** Start of inlined file: analysis.c ***/
  97089. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97090. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97091. // tasks..
  97092. #if JUCE_MSVC
  97093. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97094. #endif
  97095. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97096. #if JUCE_USE_OGGVORBIS
  97097. #include <stdio.h>
  97098. #include <string.h>
  97099. #include <math.h>
  97100. /*** Start of inlined file: codec_internal.h ***/
  97101. #ifndef _V_CODECI_H_
  97102. #define _V_CODECI_H_
  97103. /*** Start of inlined file: envelope.h ***/
  97104. #ifndef _V_ENVELOPE_
  97105. #define _V_ENVELOPE_
  97106. /*** Start of inlined file: mdct.h ***/
  97107. #ifndef _OGG_mdct_H_
  97108. #define _OGG_mdct_H_
  97109. #ifdef MDCT_INTEGERIZED
  97110. #define DATA_TYPE int
  97111. #define REG_TYPE register int
  97112. #define TRIGBITS 14
  97113. #define cPI3_8 6270
  97114. #define cPI2_8 11585
  97115. #define cPI1_8 15137
  97116. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97117. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97118. #define HALVE(x) ((x)>>1)
  97119. #else
  97120. #define DATA_TYPE float
  97121. #define REG_TYPE float
  97122. #define cPI3_8 .38268343236508977175F
  97123. #define cPI2_8 .70710678118654752441F
  97124. #define cPI1_8 .92387953251128675613F
  97125. #define FLOAT_CONV(x) (x)
  97126. #define MULT_NORM(x) (x)
  97127. #define HALVE(x) ((x)*.5f)
  97128. #endif
  97129. typedef struct {
  97130. int n;
  97131. int log2n;
  97132. DATA_TYPE *trig;
  97133. int *bitrev;
  97134. DATA_TYPE scale;
  97135. } mdct_lookup;
  97136. extern void mdct_init(mdct_lookup *lookup,int n);
  97137. extern void mdct_clear(mdct_lookup *l);
  97138. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97139. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97140. #endif
  97141. /*** End of inlined file: mdct.h ***/
  97142. #define VE_PRE 16
  97143. #define VE_WIN 4
  97144. #define VE_POST 2
  97145. #define VE_AMP (VE_PRE+VE_POST-1)
  97146. #define VE_BANDS 7
  97147. #define VE_NEARDC 15
  97148. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97149. #define VE_MAXSTRETCH 12 /* one-third full block */
  97150. typedef struct {
  97151. float ampbuf[VE_AMP];
  97152. int ampptr;
  97153. float nearDC[VE_NEARDC];
  97154. float nearDC_acc;
  97155. float nearDC_partialacc;
  97156. int nearptr;
  97157. } envelope_filter_state;
  97158. typedef struct {
  97159. int begin;
  97160. int end;
  97161. float *window;
  97162. float total;
  97163. } envelope_band;
  97164. typedef struct {
  97165. int ch;
  97166. int winlength;
  97167. int searchstep;
  97168. float minenergy;
  97169. mdct_lookup mdct;
  97170. float *mdct_win;
  97171. envelope_band band[VE_BANDS];
  97172. envelope_filter_state *filter;
  97173. int stretch;
  97174. int *mark;
  97175. long storage;
  97176. long current;
  97177. long curmark;
  97178. long cursor;
  97179. } envelope_lookup;
  97180. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97181. extern void _ve_envelope_clear(envelope_lookup *e);
  97182. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97183. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97184. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97185. #endif
  97186. /*** End of inlined file: envelope.h ***/
  97187. /*** Start of inlined file: codebook.h ***/
  97188. #ifndef _V_CODEBOOK_H_
  97189. #define _V_CODEBOOK_H_
  97190. typedef struct static_codebook{
  97191. long dim; /* codebook dimensions (elements per vector) */
  97192. long entries; /* codebook entries */
  97193. long *lengthlist; /* codeword lengths in bits */
  97194. int maptype; /* 0=none
  97195. 1=implicitly populated values from map column
  97196. 2=listed arbitrary values */
  97197. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97198. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97199. int q_quant; /* bits: 0 < quant <= 16 */
  97200. int q_sequencep; /* bitflag */
  97201. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97202. map == 2: list of dim*entries quantized entry vals
  97203. */
  97204. struct encode_aux_nearestmatch *nearest_tree;
  97205. struct encode_aux_threshmatch *thresh_tree;
  97206. struct encode_aux_pigeonhole *pigeon_tree;
  97207. int allocedp;
  97208. } static_codebook;
  97209. typedef struct encode_aux_nearestmatch{
  97210. long *ptr0;
  97211. long *ptr1;
  97212. long *p; /* decision points (each is an entry) */
  97213. long *q; /* decision points (each is an entry) */
  97214. long aux; /* number of tree entries */
  97215. long alloc;
  97216. } encode_aux_nearestmatch;
  97217. typedef struct encode_aux_threshmatch{
  97218. float *quantthresh;
  97219. long *quantmap;
  97220. int quantvals;
  97221. int threshvals;
  97222. } encode_aux_threshmatch;
  97223. typedef struct encode_aux_pigeonhole{
  97224. float min;
  97225. float del;
  97226. int mapentries;
  97227. int quantvals;
  97228. long *pigeonmap;
  97229. long fittotal;
  97230. long *fitlist;
  97231. long *fitmap;
  97232. long *fitlength;
  97233. } encode_aux_pigeonhole;
  97234. typedef struct codebook{
  97235. long dim; /* codebook dimensions (elements per vector) */
  97236. long entries; /* codebook entries */
  97237. long used_entries; /* populated codebook entries */
  97238. const static_codebook *c;
  97239. float *valuelist; /* list of dim*entries actual entry values */
  97240. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97241. int *dec_index; /* only used if sparseness collapsed */
  97242. char *dec_codelengths;
  97243. ogg_uint32_t *dec_firsttable;
  97244. int dec_firsttablen;
  97245. int dec_maxlength;
  97246. } codebook;
  97247. extern void vorbis_staticbook_clear(static_codebook *b);
  97248. extern void vorbis_staticbook_destroy(static_codebook *b);
  97249. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97250. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97251. extern void vorbis_book_clear(codebook *b);
  97252. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97253. extern float *_book_logdist(const static_codebook *b,float *vals);
  97254. extern float _float32_unpack(long val);
  97255. extern long _float32_pack(float val);
  97256. extern int _best(codebook *book, float *a, int step);
  97257. extern int _ilog(unsigned int v);
  97258. extern long _book_maptype1_quantvals(const static_codebook *b);
  97259. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97260. extern long vorbis_book_codeword(codebook *book,int entry);
  97261. extern long vorbis_book_codelen(codebook *book,int entry);
  97262. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97263. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97264. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97265. extern int vorbis_book_errorv(codebook *book, float *a);
  97266. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97267. oggpack_buffer *b);
  97268. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97269. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97270. oggpack_buffer *b,int n);
  97271. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97272. oggpack_buffer *b,int n);
  97273. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97274. oggpack_buffer *b,int n);
  97275. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97276. long off,int ch,
  97277. oggpack_buffer *b,int n);
  97278. #endif
  97279. /*** End of inlined file: codebook.h ***/
  97280. #define BLOCKTYPE_IMPULSE 0
  97281. #define BLOCKTYPE_PADDING 1
  97282. #define BLOCKTYPE_TRANSITION 0
  97283. #define BLOCKTYPE_LONG 1
  97284. #define PACKETBLOBS 15
  97285. typedef struct vorbis_block_internal{
  97286. float **pcmdelay; /* this is a pointer into local storage */
  97287. float ampmax;
  97288. int blocktype;
  97289. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97290. blob [PACKETBLOBS/2] points to
  97291. the oggpack_buffer in the
  97292. main vorbis_block */
  97293. } vorbis_block_internal;
  97294. typedef void vorbis_look_floor;
  97295. typedef void vorbis_look_residue;
  97296. typedef void vorbis_look_transform;
  97297. typedef struct {
  97298. int blockflag;
  97299. int windowtype;
  97300. int transformtype;
  97301. int mapping;
  97302. } vorbis_info_mode;
  97303. typedef void vorbis_info_floor;
  97304. typedef void vorbis_info_residue;
  97305. typedef void vorbis_info_mapping;
  97306. /*** Start of inlined file: psy.h ***/
  97307. #ifndef _V_PSY_H_
  97308. #define _V_PSY_H_
  97309. /*** Start of inlined file: smallft.h ***/
  97310. #ifndef _V_SMFT_H_
  97311. #define _V_SMFT_H_
  97312. typedef struct {
  97313. int n;
  97314. float *trigcache;
  97315. int *splitcache;
  97316. } drft_lookup;
  97317. extern void drft_forward(drft_lookup *l,float *data);
  97318. extern void drft_backward(drft_lookup *l,float *data);
  97319. extern void drft_init(drft_lookup *l,int n);
  97320. extern void drft_clear(drft_lookup *l);
  97321. #endif
  97322. /*** End of inlined file: smallft.h ***/
  97323. /*** Start of inlined file: backends.h ***/
  97324. #ifndef _vorbis_backend_h_
  97325. #define _vorbis_backend_h_
  97326. typedef struct{
  97327. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97328. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97329. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97330. void (*free_info) (vorbis_info_floor *);
  97331. void (*free_look) (vorbis_look_floor *);
  97332. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97333. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97334. void *buffer,float *);
  97335. } vorbis_func_floor;
  97336. typedef struct{
  97337. int order;
  97338. long rate;
  97339. long barkmap;
  97340. int ampbits;
  97341. int ampdB;
  97342. int numbooks; /* <= 16 */
  97343. int books[16];
  97344. float lessthan; /* encode-only config setting hacks for libvorbis */
  97345. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97346. } vorbis_info_floor0;
  97347. #define VIF_POSIT 63
  97348. #define VIF_CLASS 16
  97349. #define VIF_PARTS 31
  97350. typedef struct{
  97351. int partitions; /* 0 to 31 */
  97352. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97353. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97354. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97355. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97356. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97357. int mult; /* 1 2 3 or 4 */
  97358. int postlist[VIF_POSIT+2]; /* first two implicit */
  97359. float maxover;
  97360. float maxunder;
  97361. float maxerr;
  97362. float twofitweight;
  97363. float twofitatten;
  97364. int n;
  97365. } vorbis_info_floor1;
  97366. typedef struct{
  97367. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97368. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97369. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97370. vorbis_info_residue *);
  97371. void (*free_info) (vorbis_info_residue *);
  97372. void (*free_look) (vorbis_look_residue *);
  97373. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97374. float **,int *,int);
  97375. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97376. vorbis_look_residue *,
  97377. float **,float **,int *,int,long **);
  97378. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97379. float **,int *,int);
  97380. } vorbis_func_residue;
  97381. typedef struct vorbis_info_residue0{
  97382. long begin;
  97383. long end;
  97384. int grouping; /* group n vectors per partition */
  97385. int partitions; /* possible codebooks for a partition */
  97386. int groupbook; /* huffbook for partitioning */
  97387. int secondstages[64]; /* expanded out to pointers in lookup */
  97388. int booklist[256]; /* list of second stage books */
  97389. float classmetric1[64];
  97390. float classmetric2[64];
  97391. } vorbis_info_residue0;
  97392. typedef struct{
  97393. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97394. oggpack_buffer *);
  97395. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97396. void (*free_info) (vorbis_info_mapping *);
  97397. int (*forward) (struct vorbis_block *vb);
  97398. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97399. } vorbis_func_mapping;
  97400. typedef struct vorbis_info_mapping0{
  97401. int submaps; /* <= 16 */
  97402. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97403. int floorsubmap[16]; /* [mux] submap to floors */
  97404. int residuesubmap[16]; /* [mux] submap to residue */
  97405. int coupling_steps;
  97406. int coupling_mag[256];
  97407. int coupling_ang[256];
  97408. } vorbis_info_mapping0;
  97409. #endif
  97410. /*** End of inlined file: backends.h ***/
  97411. #ifndef EHMER_MAX
  97412. #define EHMER_MAX 56
  97413. #endif
  97414. #define P_BANDS 17 /* 62Hz to 16kHz */
  97415. #define P_LEVELS 8 /* 30dB to 100dB */
  97416. #define P_LEVEL_0 30. /* 30 dB */
  97417. #define P_NOISECURVES 3
  97418. #define NOISE_COMPAND_LEVELS 40
  97419. typedef struct vorbis_info_psy{
  97420. int blockflag;
  97421. float ath_adjatt;
  97422. float ath_maxatt;
  97423. float tone_masteratt[P_NOISECURVES];
  97424. float tone_centerboost;
  97425. float tone_decay;
  97426. float tone_abs_limit;
  97427. float toneatt[P_BANDS];
  97428. int noisemaskp;
  97429. float noisemaxsupp;
  97430. float noisewindowlo;
  97431. float noisewindowhi;
  97432. int noisewindowlomin;
  97433. int noisewindowhimin;
  97434. int noisewindowfixed;
  97435. float noiseoff[P_NOISECURVES][P_BANDS];
  97436. float noisecompand[NOISE_COMPAND_LEVELS];
  97437. float max_curve_dB;
  97438. int normal_channel_p;
  97439. int normal_point_p;
  97440. int normal_start;
  97441. int normal_partition;
  97442. double normal_thresh;
  97443. } vorbis_info_psy;
  97444. typedef struct{
  97445. int eighth_octave_lines;
  97446. float preecho_thresh[VE_BANDS];
  97447. float postecho_thresh[VE_BANDS];
  97448. float stretch_penalty;
  97449. float preecho_minenergy;
  97450. float ampmax_att_per_sec;
  97451. int coupling_pkHz[PACKETBLOBS];
  97452. int coupling_pointlimit[2][PACKETBLOBS];
  97453. int coupling_prepointamp[PACKETBLOBS];
  97454. int coupling_postpointamp[PACKETBLOBS];
  97455. int sliding_lowpass[2][PACKETBLOBS];
  97456. } vorbis_info_psy_global;
  97457. typedef struct {
  97458. float ampmax;
  97459. int channels;
  97460. vorbis_info_psy_global *gi;
  97461. int coupling_pointlimit[2][P_NOISECURVES];
  97462. } vorbis_look_psy_global;
  97463. typedef struct {
  97464. int n;
  97465. struct vorbis_info_psy *vi;
  97466. float ***tonecurves;
  97467. float **noiseoffset;
  97468. float *ath;
  97469. long *octave; /* in n.ocshift format */
  97470. long *bark;
  97471. long firstoc;
  97472. long shiftoc;
  97473. int eighth_octave_lines; /* power of two, please */
  97474. int total_octave_lines;
  97475. long rate; /* cache it */
  97476. float m_val; /* Masking compensation value */
  97477. } vorbis_look_psy;
  97478. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97479. vorbis_info_psy_global *gi,int n,long rate);
  97480. extern void _vp_psy_clear(vorbis_look_psy *p);
  97481. extern void *_vi_psy_dup(void *source);
  97482. extern void _vi_psy_free(vorbis_info_psy *i);
  97483. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97484. extern void _vp_remove_floor(vorbis_look_psy *p,
  97485. float *mdct,
  97486. int *icodedflr,
  97487. float *residue,
  97488. int sliding_lowpass);
  97489. extern void _vp_noisemask(vorbis_look_psy *p,
  97490. float *logmdct,
  97491. float *logmask);
  97492. extern void _vp_tonemask(vorbis_look_psy *p,
  97493. float *logfft,
  97494. float *logmask,
  97495. float global_specmax,
  97496. float local_specmax);
  97497. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97498. float *noise,
  97499. float *tone,
  97500. int offset_select,
  97501. float *logmask,
  97502. float *mdct,
  97503. float *logmdct);
  97504. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97505. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97506. vorbis_info_psy_global *g,
  97507. vorbis_look_psy *p,
  97508. vorbis_info_mapping0 *vi,
  97509. float **mdct);
  97510. extern void _vp_couple(int blobno,
  97511. vorbis_info_psy_global *g,
  97512. vorbis_look_psy *p,
  97513. vorbis_info_mapping0 *vi,
  97514. float **res,
  97515. float **mag_memo,
  97516. int **mag_sort,
  97517. int **ifloor,
  97518. int *nonzero,
  97519. int sliding_lowpass);
  97520. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97521. float *in,float *out,int *sortedindex);
  97522. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97523. float *magnitudes,int *sortedindex);
  97524. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97525. vorbis_look_psy *p,
  97526. vorbis_info_mapping0 *vi,
  97527. float **mags);
  97528. extern void hf_reduction(vorbis_info_psy_global *g,
  97529. vorbis_look_psy *p,
  97530. vorbis_info_mapping0 *vi,
  97531. float **mdct);
  97532. #endif
  97533. /*** End of inlined file: psy.h ***/
  97534. /*** Start of inlined file: bitrate.h ***/
  97535. #ifndef _V_BITRATE_H_
  97536. #define _V_BITRATE_H_
  97537. /*** Start of inlined file: os.h ***/
  97538. #ifndef _OS_H
  97539. #define _OS_H
  97540. #ifdef HAVE_CONFIG_H
  97541. #include "config.h"
  97542. #endif
  97543. #include <math.h>
  97544. /*** Start of inlined file: misc.h ***/
  97545. #ifndef _V_RANDOM_H_
  97546. #define _V_RANDOM_H_
  97547. extern int analysis_noisy;
  97548. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97549. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97550. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97551. ogg_int64_t off);
  97552. #ifdef DEBUG_MALLOC
  97553. #define _VDBG_GRAPHFILE "malloc.m"
  97554. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97555. extern void _VDBG_free(void *ptr,char *file,long line);
  97556. #ifndef MISC_C
  97557. #undef _ogg_malloc
  97558. #undef _ogg_calloc
  97559. #undef _ogg_realloc
  97560. #undef _ogg_free
  97561. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97562. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97563. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97564. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97565. #endif
  97566. #endif
  97567. #endif
  97568. /*** End of inlined file: misc.h ***/
  97569. #ifndef _V_IFDEFJAIL_H_
  97570. # define _V_IFDEFJAIL_H_
  97571. # ifdef __GNUC__
  97572. # define STIN static __inline__
  97573. # elif _WIN32
  97574. # define STIN static __inline
  97575. # else
  97576. # define STIN static
  97577. # endif
  97578. #ifdef DJGPP
  97579. # define rint(x) (floor((x)+0.5f))
  97580. #endif
  97581. #ifndef M_PI
  97582. # define M_PI (3.1415926536f)
  97583. #endif
  97584. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97585. # include <malloc.h>
  97586. # define rint(x) (floor((x)+0.5f))
  97587. # define NO_FLOAT_MATH_LIB
  97588. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97589. #endif
  97590. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97591. void *_alloca(size_t size);
  97592. # define alloca _alloca
  97593. #endif
  97594. #ifndef FAST_HYPOT
  97595. # define FAST_HYPOT hypot
  97596. #endif
  97597. #endif
  97598. #ifdef HAVE_ALLOCA_H
  97599. # include <alloca.h>
  97600. #endif
  97601. #ifdef USE_MEMORY_H
  97602. # include <memory.h>
  97603. #endif
  97604. #ifndef min
  97605. # define min(x,y) ((x)>(y)?(y):(x))
  97606. #endif
  97607. #ifndef max
  97608. # define max(x,y) ((x)<(y)?(y):(x))
  97609. #endif
  97610. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97611. # define VORBIS_FPU_CONTROL
  97612. typedef ogg_int16_t vorbis_fpu_control;
  97613. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97614. ogg_int16_t ret;
  97615. ogg_int16_t temp;
  97616. __asm__ __volatile__("fnstcw %0\n\t"
  97617. "movw %0,%%dx\n\t"
  97618. "orw $62463,%%dx\n\t"
  97619. "movw %%dx,%1\n\t"
  97620. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97621. *fpu=ret;
  97622. }
  97623. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97624. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97625. }
  97626. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97627. we get extra fst/fld to
  97628. truncate precision */
  97629. int i;
  97630. __asm__("fistl %0": "=m"(i) : "t"(f));
  97631. return(i);
  97632. }
  97633. #endif
  97634. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97635. # define VORBIS_FPU_CONTROL
  97636. typedef ogg_int16_t vorbis_fpu_control;
  97637. static __inline int vorbis_ftoi(double f){
  97638. int i;
  97639. __asm{
  97640. fld f
  97641. fistp i
  97642. }
  97643. return i;
  97644. }
  97645. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97646. }
  97647. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97648. }
  97649. #endif
  97650. #ifndef VORBIS_FPU_CONTROL
  97651. typedef int vorbis_fpu_control;
  97652. static int vorbis_ftoi(double f){
  97653. return (int)(f+.5);
  97654. }
  97655. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97656. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97657. #endif
  97658. #endif /* _OS_H */
  97659. /*** End of inlined file: os.h ***/
  97660. typedef struct bitrate_manager_state {
  97661. int managed;
  97662. long avg_reservoir;
  97663. long minmax_reservoir;
  97664. long avg_bitsper;
  97665. long min_bitsper;
  97666. long max_bitsper;
  97667. long short_per_long;
  97668. double avgfloat;
  97669. vorbis_block *vb;
  97670. int choice;
  97671. } bitrate_manager_state;
  97672. typedef struct bitrate_manager_info{
  97673. long avg_rate;
  97674. long min_rate;
  97675. long max_rate;
  97676. long reservoir_bits;
  97677. double reservoir_bias;
  97678. double slew_damp;
  97679. } bitrate_manager_info;
  97680. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97681. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97682. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97683. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97684. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97685. #endif
  97686. /*** End of inlined file: bitrate.h ***/
  97687. static int ilog(unsigned int v){
  97688. int ret=0;
  97689. while(v){
  97690. ret++;
  97691. v>>=1;
  97692. }
  97693. return(ret);
  97694. }
  97695. static int ilog2(unsigned int v){
  97696. int ret=0;
  97697. if(v)--v;
  97698. while(v){
  97699. ret++;
  97700. v>>=1;
  97701. }
  97702. return(ret);
  97703. }
  97704. typedef struct private_state {
  97705. envelope_lookup *ve; /* envelope lookup */
  97706. int window[2];
  97707. vorbis_look_transform **transform[2]; /* block, type */
  97708. drft_lookup fft_look[2];
  97709. int modebits;
  97710. vorbis_look_floor **flr;
  97711. vorbis_look_residue **residue;
  97712. vorbis_look_psy *psy;
  97713. vorbis_look_psy_global *psy_g_look;
  97714. unsigned char *header;
  97715. unsigned char *header1;
  97716. unsigned char *header2;
  97717. bitrate_manager_state bms;
  97718. ogg_int64_t sample_count;
  97719. } private_state;
  97720. /*** Start of inlined file: highlevel.h ***/
  97721. typedef struct highlevel_byblocktype {
  97722. double tone_mask_setting;
  97723. double tone_peaklimit_setting;
  97724. double noise_bias_setting;
  97725. double noise_compand_setting;
  97726. } highlevel_byblocktype;
  97727. typedef struct highlevel_encode_setup {
  97728. void *setup;
  97729. int set_in_stone;
  97730. double base_setting;
  97731. double long_setting;
  97732. double short_setting;
  97733. double impulse_noisetune;
  97734. int managed;
  97735. long bitrate_min;
  97736. long bitrate_av;
  97737. double bitrate_av_damp;
  97738. long bitrate_max;
  97739. long bitrate_reservoir;
  97740. double bitrate_reservoir_bias;
  97741. int impulse_block_p;
  97742. int noise_normalize_p;
  97743. double stereo_point_setting;
  97744. double lowpass_kHz;
  97745. double ath_floating_dB;
  97746. double ath_absolute_dB;
  97747. double amplitude_track_dBpersec;
  97748. double trigger_setting;
  97749. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97750. } highlevel_encode_setup;
  97751. /*** End of inlined file: highlevel.h ***/
  97752. typedef struct codec_setup_info {
  97753. long blocksizes[2];
  97754. int modes;
  97755. int maps;
  97756. int floors;
  97757. int residues;
  97758. int books;
  97759. int psys; /* encode only */
  97760. vorbis_info_mode *mode_param[64];
  97761. int map_type[64];
  97762. vorbis_info_mapping *map_param[64];
  97763. int floor_type[64];
  97764. vorbis_info_floor *floor_param[64];
  97765. int residue_type[64];
  97766. vorbis_info_residue *residue_param[64];
  97767. static_codebook *book_param[256];
  97768. codebook *fullbooks;
  97769. vorbis_info_psy *psy_param[4]; /* encode only */
  97770. vorbis_info_psy_global psy_g_param;
  97771. bitrate_manager_info bi;
  97772. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97773. highly redundant structure, but
  97774. improves clarity of program flow. */
  97775. int halfrate_flag; /* painless downsample for decode */
  97776. } codec_setup_info;
  97777. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97778. extern void _vp_global_free(vorbis_look_psy_global *look);
  97779. #endif
  97780. /*** End of inlined file: codec_internal.h ***/
  97781. /*** Start of inlined file: registry.h ***/
  97782. #ifndef _V_REG_H_
  97783. #define _V_REG_H_
  97784. #define VI_TRANSFORMB 1
  97785. #define VI_WINDOWB 1
  97786. #define VI_TIMEB 1
  97787. #define VI_FLOORB 2
  97788. #define VI_RESB 3
  97789. #define VI_MAPB 1
  97790. extern vorbis_func_floor *_floor_P[];
  97791. extern vorbis_func_residue *_residue_P[];
  97792. extern vorbis_func_mapping *_mapping_P[];
  97793. #endif
  97794. /*** End of inlined file: registry.h ***/
  97795. /*** Start of inlined file: scales.h ***/
  97796. #ifndef _V_SCALES_H_
  97797. #define _V_SCALES_H_
  97798. #include <math.h>
  97799. #define VORBIS_IEEE_FLOAT32 1
  97800. #ifdef VORBIS_IEEE_FLOAT32
  97801. static float unitnorm(float x){
  97802. union {
  97803. ogg_uint32_t i;
  97804. float f;
  97805. } ix;
  97806. ix.f = x;
  97807. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97808. return ix.f;
  97809. }
  97810. static float todB(const float *x){
  97811. union {
  97812. ogg_uint32_t i;
  97813. float f;
  97814. } ix;
  97815. ix.f = *x;
  97816. ix.i = ix.i&0x7fffffff;
  97817. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97818. }
  97819. #define todB_nn(x) todB(x)
  97820. #else
  97821. static float unitnorm(float x){
  97822. if(x<0)return(-1.f);
  97823. return(1.f);
  97824. }
  97825. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97826. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97827. #endif
  97828. #define fromdB(x) (exp((x)*.11512925f))
  97829. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97830. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97831. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97832. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97833. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97834. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97835. #endif
  97836. /*** End of inlined file: scales.h ***/
  97837. int analysis_noisy=1;
  97838. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97839. int ret,i;
  97840. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97841. vb->glue_bits=0;
  97842. vb->time_bits=0;
  97843. vb->floor_bits=0;
  97844. vb->res_bits=0;
  97845. for(i=0;i<PACKETBLOBS;i++)
  97846. oggpack_reset(vbi->packetblob[i]);
  97847. if((ret=_mapping_P[0]->forward(vb)))
  97848. return(ret);
  97849. if(op){
  97850. if(vorbis_bitrate_managed(vb))
  97851. return(OV_EINVAL);
  97852. op->packet=oggpack_get_buffer(&vb->opb);
  97853. op->bytes=oggpack_bytes(&vb->opb);
  97854. op->b_o_s=0;
  97855. op->e_o_s=vb->eofflag;
  97856. op->granulepos=vb->granulepos;
  97857. op->packetno=vb->sequence; /* for sake of completeness */
  97858. }
  97859. return(0);
  97860. }
  97861. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97862. int j;
  97863. FILE *of;
  97864. char buffer[80];
  97865. sprintf(buffer,"%s_%d.m",base,i);
  97866. of=fopen(buffer,"w");
  97867. if(!of)perror("failed to open data dump file");
  97868. for(j=0;j<n;j++){
  97869. if(bark){
  97870. float b=toBARK((4000.f*j/n)+.25);
  97871. fprintf(of,"%f ",b);
  97872. }else
  97873. if(off!=0)
  97874. fprintf(of,"%f ",(double)(j+off)/8000.);
  97875. else
  97876. fprintf(of,"%f ",(double)j);
  97877. if(dB){
  97878. float val;
  97879. if(v[j]==0.)
  97880. val=-140.;
  97881. else
  97882. val=todB(v+j);
  97883. fprintf(of,"%f\n",val);
  97884. }else{
  97885. fprintf(of,"%f\n",v[j]);
  97886. }
  97887. }
  97888. fclose(of);
  97889. }
  97890. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97891. ogg_int64_t off){
  97892. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97893. }
  97894. #endif
  97895. /*** End of inlined file: analysis.c ***/
  97896. /*** Start of inlined file: bitrate.c ***/
  97897. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97898. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97899. // tasks..
  97900. #if JUCE_MSVC
  97901. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97902. #endif
  97903. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97904. #if JUCE_USE_OGGVORBIS
  97905. #include <stdlib.h>
  97906. #include <string.h>
  97907. #include <math.h>
  97908. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97909. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97910. bitrate_manager_info *bi=&ci->bi;
  97911. memset(bm,0,sizeof(*bm));
  97912. if(bi && (bi->reservoir_bits>0)){
  97913. long ratesamples=vi->rate;
  97914. int halfsamples=ci->blocksizes[0]>>1;
  97915. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97916. bm->managed=1;
  97917. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97918. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97919. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97920. bm->avgfloat=PACKETBLOBS/2;
  97921. {
  97922. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97923. bm->minmax_reservoir=desired_fill;
  97924. bm->avg_reservoir=desired_fill;
  97925. }
  97926. }
  97927. }
  97928. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97929. memset(bm,0,sizeof(*bm));
  97930. return;
  97931. }
  97932. int vorbis_bitrate_managed(vorbis_block *vb){
  97933. vorbis_dsp_state *vd=vb->vd;
  97934. private_state *b=(private_state*)vd->backend_state;
  97935. bitrate_manager_state *bm=&b->bms;
  97936. if(bm && bm->managed)return(1);
  97937. return(0);
  97938. }
  97939. int vorbis_bitrate_addblock(vorbis_block *vb){
  97940. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97941. vorbis_dsp_state *vd=vb->vd;
  97942. private_state *b=(private_state*)vd->backend_state;
  97943. bitrate_manager_state *bm=&b->bms;
  97944. vorbis_info *vi=vd->vi;
  97945. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97946. bitrate_manager_info *bi=&ci->bi;
  97947. int choice=rint(bm->avgfloat);
  97948. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97949. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97950. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97951. int samples=ci->blocksizes[vb->W]>>1;
  97952. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97953. if(!bm->managed){
  97954. if(bm->vb)return(-1); /* one has been submitted without
  97955. being claimed */
  97956. bm->vb=vb;
  97957. return(0);
  97958. }
  97959. bm->vb=vb;
  97960. if(bm->avg_bitsper>0){
  97961. double slew=0.;
  97962. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97963. double slewlimit= 15./bi->slew_damp;
  97964. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97965. while(choice>0 && this_bits>avg_target_bits &&
  97966. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97967. choice--;
  97968. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97969. }
  97970. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97971. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97972. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97973. choice++;
  97974. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97975. }
  97976. }
  97977. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97978. if(slew<-slewlimit)slew=-slewlimit;
  97979. if(slew>slewlimit)slew=slewlimit;
  97980. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97981. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97982. }
  97983. if(bm->min_bitsper>0){
  97984. if(this_bits<min_target_bits){
  97985. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97986. choice++;
  97987. if(choice>=PACKETBLOBS)break;
  97988. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97989. }
  97990. }
  97991. }
  97992. if(bm->max_bitsper>0){
  97993. if(this_bits>max_target_bits){
  97994. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97995. choice--;
  97996. if(choice<0)break;
  97997. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97998. }
  97999. }
  98000. }
  98001. if(choice<0){
  98002. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  98003. bm->choice=choice=0;
  98004. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  98005. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  98006. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98007. }
  98008. }else{
  98009. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  98010. if(choice>=PACKETBLOBS)
  98011. choice=PACKETBLOBS-1;
  98012. bm->choice=choice;
  98013. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  98014. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  98015. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98016. }
  98017. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  98018. if(max_target_bits>0 && this_bits>max_target_bits){
  98019. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98020. }else if(min_target_bits>0 && this_bits<min_target_bits){
  98021. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98022. }else{
  98023. if(bm->minmax_reservoir>desired_fill){
  98024. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  98025. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98026. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  98027. }else{
  98028. bm->minmax_reservoir=desired_fill;
  98029. }
  98030. }else{
  98031. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  98032. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98033. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  98034. }else{
  98035. bm->minmax_reservoir=desired_fill;
  98036. }
  98037. }
  98038. }
  98039. }
  98040. if(bm->avg_bitsper>0){
  98041. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  98042. bm->avg_reservoir+=this_bits-avg_target_bits;
  98043. }
  98044. return(0);
  98045. }
  98046. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  98047. private_state *b=(private_state*)vd->backend_state;
  98048. bitrate_manager_state *bm=&b->bms;
  98049. vorbis_block *vb=bm->vb;
  98050. int choice=PACKETBLOBS/2;
  98051. if(!vb)return 0;
  98052. if(op){
  98053. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98054. if(vorbis_bitrate_managed(vb))
  98055. choice=bm->choice;
  98056. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  98057. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  98058. op->b_o_s=0;
  98059. op->e_o_s=vb->eofflag;
  98060. op->granulepos=vb->granulepos;
  98061. op->packetno=vb->sequence; /* for sake of completeness */
  98062. }
  98063. bm->vb=0;
  98064. return(1);
  98065. }
  98066. #endif
  98067. /*** End of inlined file: bitrate.c ***/
  98068. /*** Start of inlined file: block.c ***/
  98069. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98070. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98071. // tasks..
  98072. #if JUCE_MSVC
  98073. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98074. #endif
  98075. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98076. #if JUCE_USE_OGGVORBIS
  98077. #include <stdio.h>
  98078. #include <stdlib.h>
  98079. #include <string.h>
  98080. /*** Start of inlined file: window.h ***/
  98081. #ifndef _V_WINDOW_
  98082. #define _V_WINDOW_
  98083. extern float *_vorbis_window_get(int n);
  98084. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  98085. int lW,int W,int nW);
  98086. #endif
  98087. /*** End of inlined file: window.h ***/
  98088. /*** Start of inlined file: lpc.h ***/
  98089. #ifndef _V_LPC_H_
  98090. #define _V_LPC_H_
  98091. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  98092. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  98093. float *data,long n);
  98094. #endif
  98095. /*** End of inlined file: lpc.h ***/
  98096. #ifndef WORD_ALIGN
  98097. #define WORD_ALIGN 8
  98098. #endif
  98099. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98100. int i;
  98101. memset(vb,0,sizeof(*vb));
  98102. vb->vd=v;
  98103. vb->localalloc=0;
  98104. vb->localstore=NULL;
  98105. if(v->analysisp){
  98106. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98107. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98108. vbi->ampmax=-9999;
  98109. for(i=0;i<PACKETBLOBS;i++){
  98110. if(i==PACKETBLOBS/2){
  98111. vbi->packetblob[i]=&vb->opb;
  98112. }else{
  98113. vbi->packetblob[i]=
  98114. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98115. }
  98116. oggpack_writeinit(vbi->packetblob[i]);
  98117. }
  98118. }
  98119. return(0);
  98120. }
  98121. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98122. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98123. if(bytes+vb->localtop>vb->localalloc){
  98124. if(vb->localstore){
  98125. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98126. vb->totaluse+=vb->localtop;
  98127. link->next=vb->reap;
  98128. link->ptr=vb->localstore;
  98129. vb->reap=link;
  98130. }
  98131. vb->localalloc=bytes;
  98132. vb->localstore=_ogg_malloc(vb->localalloc);
  98133. vb->localtop=0;
  98134. }
  98135. {
  98136. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98137. vb->localtop+=bytes;
  98138. return ret;
  98139. }
  98140. }
  98141. void _vorbis_block_ripcord(vorbis_block *vb){
  98142. struct alloc_chain *reap=vb->reap;
  98143. while(reap){
  98144. struct alloc_chain *next=reap->next;
  98145. _ogg_free(reap->ptr);
  98146. memset(reap,0,sizeof(*reap));
  98147. _ogg_free(reap);
  98148. reap=next;
  98149. }
  98150. if(vb->totaluse){
  98151. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98152. vb->localalloc+=vb->totaluse;
  98153. vb->totaluse=0;
  98154. }
  98155. vb->localtop=0;
  98156. vb->reap=NULL;
  98157. }
  98158. int vorbis_block_clear(vorbis_block *vb){
  98159. int i;
  98160. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98161. _vorbis_block_ripcord(vb);
  98162. if(vb->localstore)_ogg_free(vb->localstore);
  98163. if(vbi){
  98164. for(i=0;i<PACKETBLOBS;i++){
  98165. oggpack_writeclear(vbi->packetblob[i]);
  98166. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98167. }
  98168. _ogg_free(vbi);
  98169. }
  98170. memset(vb,0,sizeof(*vb));
  98171. return(0);
  98172. }
  98173. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98174. int i;
  98175. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98176. private_state *b=NULL;
  98177. int hs;
  98178. if(ci==NULL) return 1;
  98179. hs=ci->halfrate_flag;
  98180. memset(v,0,sizeof(*v));
  98181. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98182. v->vi=vi;
  98183. b->modebits=ilog2(ci->modes);
  98184. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98185. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98186. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98187. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98188. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98189. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98190. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98191. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98192. if(encp){ /* encode/decode differ here */
  98193. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98194. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98195. if(!ci->fullbooks){
  98196. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98197. for(i=0;i<ci->books;i++)
  98198. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98199. }
  98200. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98201. for(i=0;i<ci->psys;i++){
  98202. _vp_psy_init(b->psy+i,
  98203. ci->psy_param[i],
  98204. &ci->psy_g_param,
  98205. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98206. vi->rate);
  98207. }
  98208. v->analysisp=1;
  98209. }else{
  98210. if(!ci->fullbooks){
  98211. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98212. for(i=0;i<ci->books;i++){
  98213. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98214. vorbis_staticbook_destroy(ci->book_param[i]);
  98215. ci->book_param[i]=NULL;
  98216. }
  98217. }
  98218. }
  98219. v->pcm_storage=ci->blocksizes[1];
  98220. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98221. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98222. {
  98223. int i;
  98224. for(i=0;i<vi->channels;i++)
  98225. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98226. }
  98227. v->lW=0; /* previous window size */
  98228. v->W=0; /* current window size */
  98229. v->centerW=ci->blocksizes[1]/2;
  98230. v->pcm_current=v->centerW;
  98231. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98232. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98233. for(i=0;i<ci->floors;i++)
  98234. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98235. look(v,ci->floor_param[i]);
  98236. for(i=0;i<ci->residues;i++)
  98237. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98238. look(v,ci->residue_param[i]);
  98239. return 0;
  98240. }
  98241. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98242. private_state *b=NULL;
  98243. if(_vds_shared_init(v,vi,1))return 1;
  98244. b=(private_state*)v->backend_state;
  98245. b->psy_g_look=_vp_global_look(vi);
  98246. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98247. _ve_envelope_init(b->ve,vi);
  98248. vorbis_bitrate_init(vi,&b->bms);
  98249. v->sequence=3;
  98250. return(0);
  98251. }
  98252. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98253. int i;
  98254. if(v){
  98255. vorbis_info *vi=v->vi;
  98256. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98257. private_state *b=(private_state*)v->backend_state;
  98258. if(b){
  98259. if(b->ve){
  98260. _ve_envelope_clear(b->ve);
  98261. _ogg_free(b->ve);
  98262. }
  98263. if(b->transform[0]){
  98264. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98265. _ogg_free(b->transform[0][0]);
  98266. _ogg_free(b->transform[0]);
  98267. }
  98268. if(b->transform[1]){
  98269. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98270. _ogg_free(b->transform[1][0]);
  98271. _ogg_free(b->transform[1]);
  98272. }
  98273. if(b->flr){
  98274. for(i=0;i<ci->floors;i++)
  98275. _floor_P[ci->floor_type[i]]->
  98276. free_look(b->flr[i]);
  98277. _ogg_free(b->flr);
  98278. }
  98279. if(b->residue){
  98280. for(i=0;i<ci->residues;i++)
  98281. _residue_P[ci->residue_type[i]]->
  98282. free_look(b->residue[i]);
  98283. _ogg_free(b->residue);
  98284. }
  98285. if(b->psy){
  98286. for(i=0;i<ci->psys;i++)
  98287. _vp_psy_clear(b->psy+i);
  98288. _ogg_free(b->psy);
  98289. }
  98290. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98291. vorbis_bitrate_clear(&b->bms);
  98292. drft_clear(&b->fft_look[0]);
  98293. drft_clear(&b->fft_look[1]);
  98294. }
  98295. if(v->pcm){
  98296. for(i=0;i<vi->channels;i++)
  98297. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98298. _ogg_free(v->pcm);
  98299. if(v->pcmret)_ogg_free(v->pcmret);
  98300. }
  98301. if(b){
  98302. if(b->header)_ogg_free(b->header);
  98303. if(b->header1)_ogg_free(b->header1);
  98304. if(b->header2)_ogg_free(b->header2);
  98305. _ogg_free(b);
  98306. }
  98307. memset(v,0,sizeof(*v));
  98308. }
  98309. }
  98310. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98311. int i;
  98312. vorbis_info *vi=v->vi;
  98313. private_state *b=(private_state*)v->backend_state;
  98314. if(b->header)_ogg_free(b->header);b->header=NULL;
  98315. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98316. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98317. if(v->pcm_current+vals>=v->pcm_storage){
  98318. v->pcm_storage=v->pcm_current+vals*2;
  98319. for(i=0;i<vi->channels;i++){
  98320. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98321. }
  98322. }
  98323. for(i=0;i<vi->channels;i++)
  98324. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98325. return(v->pcmret);
  98326. }
  98327. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98328. int i;
  98329. int order=32;
  98330. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98331. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98332. long j;
  98333. v->preextrapolate=1;
  98334. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98335. for(i=0;i<v->vi->channels;i++){
  98336. for(j=0;j<v->pcm_current;j++)
  98337. work[j]=v->pcm[i][v->pcm_current-j-1];
  98338. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98339. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98340. order,
  98341. work+v->pcm_current-v->centerW,
  98342. v->centerW);
  98343. for(j=0;j<v->pcm_current;j++)
  98344. v->pcm[i][v->pcm_current-j-1]=work[j];
  98345. }
  98346. }
  98347. }
  98348. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98349. vorbis_info *vi=v->vi;
  98350. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98351. if(vals<=0){
  98352. int order=32;
  98353. int i;
  98354. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98355. if(!v->preextrapolate)
  98356. _preextrapolate_helper(v);
  98357. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98358. v->eofflag=v->pcm_current;
  98359. v->pcm_current+=ci->blocksizes[1]*3;
  98360. for(i=0;i<vi->channels;i++){
  98361. if(v->eofflag>order*2){
  98362. long n;
  98363. n=v->eofflag;
  98364. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98365. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98366. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98367. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98368. }else{
  98369. memset(v->pcm[i]+v->eofflag,0,
  98370. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98371. }
  98372. }
  98373. }else{
  98374. if(v->pcm_current+vals>v->pcm_storage)
  98375. return(OV_EINVAL);
  98376. v->pcm_current+=vals;
  98377. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98378. _preextrapolate_helper(v);
  98379. }
  98380. return(0);
  98381. }
  98382. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98383. int i;
  98384. vorbis_info *vi=v->vi;
  98385. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98386. private_state *b=(private_state*)v->backend_state;
  98387. vorbis_look_psy_global *g=b->psy_g_look;
  98388. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98389. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98390. if(!v->preextrapolate)return(0);
  98391. if(v->eofflag==-1)return(0);
  98392. {
  98393. long bp=_ve_envelope_search(v);
  98394. if(bp==-1){
  98395. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98396. full long block */
  98397. v->nW=0;
  98398. }else{
  98399. if(ci->blocksizes[0]==ci->blocksizes[1])
  98400. v->nW=0;
  98401. else
  98402. v->nW=bp;
  98403. }
  98404. }
  98405. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98406. {
  98407. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98408. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98409. although this check is
  98410. less strict that the
  98411. _ve_envelope_search,
  98412. the search is not run
  98413. if we only use one
  98414. block size */
  98415. }
  98416. _vorbis_block_ripcord(vb);
  98417. vb->lW=v->lW;
  98418. vb->W=v->W;
  98419. vb->nW=v->nW;
  98420. if(v->W){
  98421. if(!v->lW || !v->nW){
  98422. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98423. }else{
  98424. vbi->blocktype=BLOCKTYPE_LONG;
  98425. }
  98426. }else{
  98427. if(_ve_envelope_mark(v)){
  98428. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98429. }else{
  98430. vbi->blocktype=BLOCKTYPE_PADDING;
  98431. }
  98432. }
  98433. vb->vd=v;
  98434. vb->sequence=v->sequence++;
  98435. vb->granulepos=v->granulepos;
  98436. vb->pcmend=ci->blocksizes[v->W];
  98437. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98438. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98439. vbi->ampmax=g->ampmax;
  98440. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98441. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98442. for(i=0;i<vi->channels;i++){
  98443. vbi->pcmdelay[i]=
  98444. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98445. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98446. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98447. }
  98448. if(v->eofflag){
  98449. if(v->centerW>=v->eofflag){
  98450. v->eofflag=-1;
  98451. vb->eofflag=1;
  98452. return(1);
  98453. }
  98454. }
  98455. {
  98456. int new_centerNext=ci->blocksizes[1]/2;
  98457. int movementW=centerNext-new_centerNext;
  98458. if(movementW>0){
  98459. _ve_envelope_shift(b->ve,movementW);
  98460. v->pcm_current-=movementW;
  98461. for(i=0;i<vi->channels;i++)
  98462. memmove(v->pcm[i],v->pcm[i]+movementW,
  98463. v->pcm_current*sizeof(*v->pcm[i]));
  98464. v->lW=v->W;
  98465. v->W=v->nW;
  98466. v->centerW=new_centerNext;
  98467. if(v->eofflag){
  98468. v->eofflag-=movementW;
  98469. if(v->eofflag<=0)v->eofflag=-1;
  98470. if(v->centerW>=v->eofflag){
  98471. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98472. }else{
  98473. v->granulepos+=movementW;
  98474. }
  98475. }else{
  98476. v->granulepos+=movementW;
  98477. }
  98478. }
  98479. }
  98480. return(1);
  98481. }
  98482. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98483. vorbis_info *vi=v->vi;
  98484. codec_setup_info *ci;
  98485. int hs;
  98486. if(!v->backend_state)return -1;
  98487. if(!vi)return -1;
  98488. ci=(codec_setup_info*) vi->codec_setup;
  98489. if(!ci)return -1;
  98490. hs=ci->halfrate_flag;
  98491. v->centerW=ci->blocksizes[1]>>(hs+1);
  98492. v->pcm_current=v->centerW>>hs;
  98493. v->pcm_returned=-1;
  98494. v->granulepos=-1;
  98495. v->sequence=-1;
  98496. v->eofflag=0;
  98497. ((private_state *)(v->backend_state))->sample_count=-1;
  98498. return(0);
  98499. }
  98500. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98501. if(_vds_shared_init(v,vi,0)) return 1;
  98502. vorbis_synthesis_restart(v);
  98503. return 0;
  98504. }
  98505. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98506. vorbis_info *vi=v->vi;
  98507. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98508. private_state *b=(private_state*)v->backend_state;
  98509. int hs=ci->halfrate_flag;
  98510. int i,j;
  98511. if(!vb)return(OV_EINVAL);
  98512. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98513. v->lW=v->W;
  98514. v->W=vb->W;
  98515. v->nW=-1;
  98516. if((v->sequence==-1)||
  98517. (v->sequence+1 != vb->sequence)){
  98518. v->granulepos=-1; /* out of sequence; lose count */
  98519. b->sample_count=-1;
  98520. }
  98521. v->sequence=vb->sequence;
  98522. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98523. was called on block */
  98524. int n=ci->blocksizes[v->W]>>(hs+1);
  98525. int n0=ci->blocksizes[0]>>(hs+1);
  98526. int n1=ci->blocksizes[1]>>(hs+1);
  98527. int thisCenter;
  98528. int prevCenter;
  98529. v->glue_bits+=vb->glue_bits;
  98530. v->time_bits+=vb->time_bits;
  98531. v->floor_bits+=vb->floor_bits;
  98532. v->res_bits+=vb->res_bits;
  98533. if(v->centerW){
  98534. thisCenter=n1;
  98535. prevCenter=0;
  98536. }else{
  98537. thisCenter=0;
  98538. prevCenter=n1;
  98539. }
  98540. for(j=0;j<vi->channels;j++){
  98541. if(v->lW){
  98542. if(v->W){
  98543. float *w=_vorbis_window_get(b->window[1]-hs);
  98544. float *pcm=v->pcm[j]+prevCenter;
  98545. float *p=vb->pcm[j];
  98546. for(i=0;i<n1;i++)
  98547. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98548. }else{
  98549. float *w=_vorbis_window_get(b->window[0]-hs);
  98550. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98551. float *p=vb->pcm[j];
  98552. for(i=0;i<n0;i++)
  98553. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98554. }
  98555. }else{
  98556. if(v->W){
  98557. float *w=_vorbis_window_get(b->window[0]-hs);
  98558. float *pcm=v->pcm[j]+prevCenter;
  98559. float *p=vb->pcm[j]+n1/2-n0/2;
  98560. for(i=0;i<n0;i++)
  98561. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98562. for(;i<n1/2+n0/2;i++)
  98563. pcm[i]=p[i];
  98564. }else{
  98565. float *w=_vorbis_window_get(b->window[0]-hs);
  98566. float *pcm=v->pcm[j]+prevCenter;
  98567. float *p=vb->pcm[j];
  98568. for(i=0;i<n0;i++)
  98569. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98570. }
  98571. }
  98572. {
  98573. float *pcm=v->pcm[j]+thisCenter;
  98574. float *p=vb->pcm[j]+n;
  98575. for(i=0;i<n;i++)
  98576. pcm[i]=p[i];
  98577. }
  98578. }
  98579. if(v->centerW)
  98580. v->centerW=0;
  98581. else
  98582. v->centerW=n1;
  98583. if(v->pcm_returned==-1){
  98584. v->pcm_returned=thisCenter;
  98585. v->pcm_current=thisCenter;
  98586. }else{
  98587. v->pcm_returned=prevCenter;
  98588. v->pcm_current=prevCenter+
  98589. ((ci->blocksizes[v->lW]/4+
  98590. ci->blocksizes[v->W]/4)>>hs);
  98591. }
  98592. }
  98593. if(b->sample_count==-1){
  98594. b->sample_count=0;
  98595. }else{
  98596. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98597. }
  98598. if(v->granulepos==-1){
  98599. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98600. v->granulepos=vb->granulepos;
  98601. if(b->sample_count>v->granulepos){
  98602. if(vb->eofflag){
  98603. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98604. }else{
  98605. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98606. if(v->pcm_returned>v->pcm_current)
  98607. v->pcm_returned=v->pcm_current;
  98608. }
  98609. }
  98610. }
  98611. }else{
  98612. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98613. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98614. if(v->granulepos>vb->granulepos){
  98615. long extra=v->granulepos-vb->granulepos;
  98616. if(extra)
  98617. if(vb->eofflag){
  98618. v->pcm_current-=extra>>hs;
  98619. } /* else {Shouldn't happen *unless* the bitstream is out of
  98620. spec. Either way, believe the bitstream } */
  98621. } /* else {Shouldn't happen *unless* the bitstream is out of
  98622. spec. Either way, believe the bitstream } */
  98623. v->granulepos=vb->granulepos;
  98624. }
  98625. }
  98626. if(vb->eofflag)v->eofflag=1;
  98627. return(0);
  98628. }
  98629. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98630. vorbis_info *vi=v->vi;
  98631. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98632. if(pcm){
  98633. int i;
  98634. for(i=0;i<vi->channels;i++)
  98635. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98636. *pcm=v->pcmret;
  98637. }
  98638. return(v->pcm_current-v->pcm_returned);
  98639. }
  98640. return(0);
  98641. }
  98642. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98643. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98644. v->pcm_returned+=n;
  98645. return(0);
  98646. }
  98647. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98648. vorbis_info *vi=v->vi;
  98649. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98650. int hs=ci->halfrate_flag;
  98651. int n=ci->blocksizes[v->W]>>(hs+1);
  98652. int n0=ci->blocksizes[0]>>(hs+1);
  98653. int n1=ci->blocksizes[1]>>(hs+1);
  98654. int i,j;
  98655. if(v->pcm_returned<0)return 0;
  98656. if(v->centerW==n1){
  98657. for(j=0;j<vi->channels;j++){
  98658. float *p=v->pcm[j];
  98659. for(i=0;i<n1;i++){
  98660. float temp=p[i];
  98661. p[i]=p[i+n1];
  98662. p[i+n1]=temp;
  98663. }
  98664. }
  98665. v->pcm_current-=n1;
  98666. v->pcm_returned-=n1;
  98667. v->centerW=0;
  98668. }
  98669. if((v->lW^v->W)==1){
  98670. for(j=0;j<vi->channels;j++){
  98671. float *s=v->pcm[j];
  98672. float *d=v->pcm[j]+(n1-n0)/2;
  98673. for(i=(n1+n0)/2-1;i>=0;--i)
  98674. d[i]=s[i];
  98675. }
  98676. v->pcm_returned+=(n1-n0)/2;
  98677. v->pcm_current+=(n1-n0)/2;
  98678. }else{
  98679. if(v->lW==0){
  98680. for(j=0;j<vi->channels;j++){
  98681. float *s=v->pcm[j];
  98682. float *d=v->pcm[j]+n1-n0;
  98683. for(i=n0-1;i>=0;--i)
  98684. d[i]=s[i];
  98685. }
  98686. v->pcm_returned+=n1-n0;
  98687. v->pcm_current+=n1-n0;
  98688. }
  98689. }
  98690. if(pcm){
  98691. int i;
  98692. for(i=0;i<vi->channels;i++)
  98693. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98694. *pcm=v->pcmret;
  98695. }
  98696. return(n1+n-v->pcm_returned);
  98697. }
  98698. float *vorbis_window(vorbis_dsp_state *v,int W){
  98699. vorbis_info *vi=v->vi;
  98700. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98701. int hs=ci->halfrate_flag;
  98702. private_state *b=(private_state*)v->backend_state;
  98703. if(b->window[W]-1<0)return NULL;
  98704. return _vorbis_window_get(b->window[W]-hs);
  98705. }
  98706. #endif
  98707. /*** End of inlined file: block.c ***/
  98708. /*** Start of inlined file: codebook.c ***/
  98709. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98710. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98711. // tasks..
  98712. #if JUCE_MSVC
  98713. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98714. #endif
  98715. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98716. #if JUCE_USE_OGGVORBIS
  98717. #include <stdlib.h>
  98718. #include <string.h>
  98719. #include <math.h>
  98720. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98721. long i,j;
  98722. int ordered=0;
  98723. oggpack_write(opb,0x564342,24);
  98724. oggpack_write(opb,c->dim,16);
  98725. oggpack_write(opb,c->entries,24);
  98726. for(i=1;i<c->entries;i++)
  98727. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98728. if(i==c->entries)ordered=1;
  98729. if(ordered){
  98730. long count=0;
  98731. oggpack_write(opb,1,1); /* ordered */
  98732. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98733. for(i=1;i<c->entries;i++){
  98734. long thisx=c->lengthlist[i];
  98735. long last=c->lengthlist[i-1];
  98736. if(thisx>last){
  98737. for(j=last;j<thisx;j++){
  98738. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98739. count=i;
  98740. }
  98741. }
  98742. }
  98743. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98744. }else{
  98745. oggpack_write(opb,0,1); /* unordered */
  98746. for(i=0;i<c->entries;i++)
  98747. if(c->lengthlist[i]==0)break;
  98748. if(i==c->entries){
  98749. oggpack_write(opb,0,1); /* no unused entries */
  98750. for(i=0;i<c->entries;i++)
  98751. oggpack_write(opb,c->lengthlist[i]-1,5);
  98752. }else{
  98753. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98754. for(i=0;i<c->entries;i++){
  98755. if(c->lengthlist[i]==0){
  98756. oggpack_write(opb,0,1);
  98757. }else{
  98758. oggpack_write(opb,1,1);
  98759. oggpack_write(opb,c->lengthlist[i]-1,5);
  98760. }
  98761. }
  98762. }
  98763. }
  98764. oggpack_write(opb,c->maptype,4);
  98765. switch(c->maptype){
  98766. case 0:
  98767. break;
  98768. case 1:case 2:
  98769. if(!c->quantlist){
  98770. return(-1);
  98771. }
  98772. oggpack_write(opb,c->q_min,32);
  98773. oggpack_write(opb,c->q_delta,32);
  98774. oggpack_write(opb,c->q_quant-1,4);
  98775. oggpack_write(opb,c->q_sequencep,1);
  98776. {
  98777. int quantvals;
  98778. switch(c->maptype){
  98779. case 1:
  98780. quantvals=_book_maptype1_quantvals(c);
  98781. break;
  98782. case 2:
  98783. quantvals=c->entries*c->dim;
  98784. break;
  98785. default: /* NOT_REACHABLE */
  98786. quantvals=-1;
  98787. }
  98788. for(i=0;i<quantvals;i++)
  98789. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98790. }
  98791. break;
  98792. default:
  98793. return(-1);
  98794. }
  98795. return(0);
  98796. }
  98797. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98798. long i,j;
  98799. memset(s,0,sizeof(*s));
  98800. s->allocedp=1;
  98801. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98802. s->dim=oggpack_read(opb,16);
  98803. s->entries=oggpack_read(opb,24);
  98804. if(s->entries==-1)goto _eofout;
  98805. switch((int)oggpack_read(opb,1)){
  98806. case 0:
  98807. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98808. if(oggpack_read(opb,1)){
  98809. for(i=0;i<s->entries;i++){
  98810. if(oggpack_read(opb,1)){
  98811. long num=oggpack_read(opb,5);
  98812. if(num==-1)goto _eofout;
  98813. s->lengthlist[i]=num+1;
  98814. }else
  98815. s->lengthlist[i]=0;
  98816. }
  98817. }else{
  98818. for(i=0;i<s->entries;i++){
  98819. long num=oggpack_read(opb,5);
  98820. if(num==-1)goto _eofout;
  98821. s->lengthlist[i]=num+1;
  98822. }
  98823. }
  98824. break;
  98825. case 1:
  98826. {
  98827. long length=oggpack_read(opb,5)+1;
  98828. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98829. for(i=0;i<s->entries;){
  98830. long num=oggpack_read(opb,_ilog(s->entries-i));
  98831. if(num==-1)goto _eofout;
  98832. for(j=0;j<num && i<s->entries;j++,i++)
  98833. s->lengthlist[i]=length;
  98834. length++;
  98835. }
  98836. }
  98837. break;
  98838. default:
  98839. return(-1);
  98840. }
  98841. switch((s->maptype=oggpack_read(opb,4))){
  98842. case 0:
  98843. break;
  98844. case 1: case 2:
  98845. s->q_min=oggpack_read(opb,32);
  98846. s->q_delta=oggpack_read(opb,32);
  98847. s->q_quant=oggpack_read(opb,4)+1;
  98848. s->q_sequencep=oggpack_read(opb,1);
  98849. {
  98850. int quantvals=0;
  98851. switch(s->maptype){
  98852. case 1:
  98853. quantvals=_book_maptype1_quantvals(s);
  98854. break;
  98855. case 2:
  98856. quantvals=s->entries*s->dim;
  98857. break;
  98858. }
  98859. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98860. for(i=0;i<quantvals;i++)
  98861. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98862. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98863. }
  98864. break;
  98865. default:
  98866. goto _errout;
  98867. }
  98868. return(0);
  98869. _errout:
  98870. _eofout:
  98871. vorbis_staticbook_clear(s);
  98872. return(-1);
  98873. }
  98874. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98875. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98876. return(book->c->lengthlist[a]);
  98877. }
  98878. int vorbis_book_errorv(codebook *book,float *a){
  98879. int dim=book->dim,k;
  98880. int best=_best(book,a,1);
  98881. for(k=0;k<dim;k++)
  98882. a[k]=(book->valuelist+best*dim)[k];
  98883. return(best);
  98884. }
  98885. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98886. int k,dim=book->dim;
  98887. for(k=0;k<dim;k++)
  98888. a[k]=(book->valuelist+best*dim)[k];
  98889. return(vorbis_book_encode(book,best,b));
  98890. }
  98891. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98892. int read=book->dec_maxlength;
  98893. long lo,hi;
  98894. long lok = oggpack_look(b,book->dec_firsttablen);
  98895. if (lok >= 0) {
  98896. long entry = book->dec_firsttable[lok];
  98897. if(entry&0x80000000UL){
  98898. lo=(entry>>15)&0x7fff;
  98899. hi=book->used_entries-(entry&0x7fff);
  98900. }else{
  98901. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98902. return(entry-1);
  98903. }
  98904. }else{
  98905. lo=0;
  98906. hi=book->used_entries;
  98907. }
  98908. lok = oggpack_look(b, read);
  98909. while(lok<0 && read>1)
  98910. lok = oggpack_look(b, --read);
  98911. if(lok<0)return -1;
  98912. {
  98913. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98914. while(hi-lo>1){
  98915. long p=(hi-lo)>>1;
  98916. long test=book->codelist[lo+p]>testword;
  98917. lo+=p&(test-1);
  98918. hi-=p&(-test);
  98919. }
  98920. if(book->dec_codelengths[lo]<=read){
  98921. oggpack_adv(b, book->dec_codelengths[lo]);
  98922. return(lo);
  98923. }
  98924. }
  98925. oggpack_adv(b, read);
  98926. return(-1);
  98927. }
  98928. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98929. long packed_entry=decode_packed_entry_number(book,b);
  98930. if(packed_entry>=0)
  98931. return(book->dec_index[packed_entry]);
  98932. return(packed_entry);
  98933. }
  98934. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98935. int step=n/book->dim;
  98936. long *entry = (long*)alloca(sizeof(*entry)*step);
  98937. float **t = (float**)alloca(sizeof(*t)*step);
  98938. int i,j,o;
  98939. for (i = 0; i < step; i++) {
  98940. entry[i]=decode_packed_entry_number(book,b);
  98941. if(entry[i]==-1)return(-1);
  98942. t[i] = book->valuelist+entry[i]*book->dim;
  98943. }
  98944. for(i=0,o=0;i<book->dim;i++,o+=step)
  98945. for (j=0;j<step;j++)
  98946. a[o+j]+=t[j][i];
  98947. return(0);
  98948. }
  98949. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98950. int i,j,entry;
  98951. float *t;
  98952. if(book->dim>8){
  98953. for(i=0;i<n;){
  98954. entry = decode_packed_entry_number(book,b);
  98955. if(entry==-1)return(-1);
  98956. t = book->valuelist+entry*book->dim;
  98957. for (j=0;j<book->dim;)
  98958. a[i++]+=t[j++];
  98959. }
  98960. }else{
  98961. for(i=0;i<n;){
  98962. entry = decode_packed_entry_number(book,b);
  98963. if(entry==-1)return(-1);
  98964. t = book->valuelist+entry*book->dim;
  98965. j=0;
  98966. switch((int)book->dim){
  98967. case 8:
  98968. a[i++]+=t[j++];
  98969. case 7:
  98970. a[i++]+=t[j++];
  98971. case 6:
  98972. a[i++]+=t[j++];
  98973. case 5:
  98974. a[i++]+=t[j++];
  98975. case 4:
  98976. a[i++]+=t[j++];
  98977. case 3:
  98978. a[i++]+=t[j++];
  98979. case 2:
  98980. a[i++]+=t[j++];
  98981. case 1:
  98982. a[i++]+=t[j++];
  98983. case 0:
  98984. break;
  98985. }
  98986. }
  98987. }
  98988. return(0);
  98989. }
  98990. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98991. int i,j,entry;
  98992. float *t;
  98993. for(i=0;i<n;){
  98994. entry = decode_packed_entry_number(book,b);
  98995. if(entry==-1)return(-1);
  98996. t = book->valuelist+entry*book->dim;
  98997. for (j=0;j<book->dim;)
  98998. a[i++]=t[j++];
  98999. }
  99000. return(0);
  99001. }
  99002. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  99003. oggpack_buffer *b,int n){
  99004. long i,j,entry;
  99005. int chptr=0;
  99006. for(i=offset/ch;i<(offset+n)/ch;){
  99007. entry = decode_packed_entry_number(book,b);
  99008. if(entry==-1)return(-1);
  99009. {
  99010. const float *t = book->valuelist+entry*book->dim;
  99011. for (j=0;j<book->dim;j++){
  99012. a[chptr++][i]+=t[j];
  99013. if(chptr==ch){
  99014. chptr=0;
  99015. i++;
  99016. }
  99017. }
  99018. }
  99019. }
  99020. return(0);
  99021. }
  99022. #ifdef _V_SELFTEST
  99023. #include <stdio.h>
  99024. #include "vorbis/book/lsp20_0.vqh"
  99025. #include "vorbis/book/res0a_13.vqh"
  99026. #define TESTSIZE 40
  99027. float test1[TESTSIZE]={
  99028. 0.105939f,
  99029. 0.215373f,
  99030. 0.429117f,
  99031. 0.587974f,
  99032. 0.181173f,
  99033. 0.296583f,
  99034. 0.515707f,
  99035. 0.715261f,
  99036. 0.162327f,
  99037. 0.263834f,
  99038. 0.342876f,
  99039. 0.406025f,
  99040. 0.103571f,
  99041. 0.223561f,
  99042. 0.368513f,
  99043. 0.540313f,
  99044. 0.136672f,
  99045. 0.395882f,
  99046. 0.587183f,
  99047. 0.652476f,
  99048. 0.114338f,
  99049. 0.417300f,
  99050. 0.525486f,
  99051. 0.698679f,
  99052. 0.147492f,
  99053. 0.324481f,
  99054. 0.643089f,
  99055. 0.757582f,
  99056. 0.139556f,
  99057. 0.215795f,
  99058. 0.324559f,
  99059. 0.399387f,
  99060. 0.120236f,
  99061. 0.267420f,
  99062. 0.446940f,
  99063. 0.608760f,
  99064. 0.115587f,
  99065. 0.287234f,
  99066. 0.571081f,
  99067. 0.708603f,
  99068. };
  99069. float test3[TESTSIZE]={
  99070. 0,1,-2,3,4,-5,6,7,8,9,
  99071. 8,-2,7,-1,4,6,8,3,1,-9,
  99072. 10,11,12,13,14,15,26,17,18,19,
  99073. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  99074. static_codebook *testlist[]={&_vq_book_lsp20_0,
  99075. &_vq_book_res0a_13,NULL};
  99076. float *testvec[]={test1,test3};
  99077. int main(){
  99078. oggpack_buffer write;
  99079. oggpack_buffer read;
  99080. long ptr=0,i;
  99081. oggpack_writeinit(&write);
  99082. fprintf(stderr,"Testing codebook abstraction...:\n");
  99083. while(testlist[ptr]){
  99084. codebook c;
  99085. static_codebook s;
  99086. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  99087. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  99088. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  99089. memset(iv,0,sizeof(*iv)*TESTSIZE);
  99090. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  99091. oggpack_reset(&write);
  99092. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  99093. we can write */
  99094. vorbis_staticbook_pack(testlist[ptr],&write);
  99095. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  99096. for(i=0;i<TESTSIZE;i+=c.dim){
  99097. int best=_best(&c,qv+i,1);
  99098. vorbis_book_encodev(&c,best,qv+i,&write);
  99099. }
  99100. vorbis_book_clear(&c);
  99101. fprintf(stderr,"OK.\n");
  99102. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99103. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99104. if(vorbis_staticbook_unpack(&read,&s)){
  99105. fprintf(stderr,"Error unpacking codebook.\n");
  99106. exit(1);
  99107. }
  99108. if(vorbis_book_init_decode(&c,&s)){
  99109. fprintf(stderr,"Error initializing codebook.\n");
  99110. exit(1);
  99111. }
  99112. for(i=0;i<TESTSIZE;i+=c.dim)
  99113. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99114. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99115. exit(1);
  99116. }
  99117. for(i=0;i<TESTSIZE;i++)
  99118. if(fabs(qv[i]-iv[i])>.000001){
  99119. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99120. iv[i],qv[i],i);
  99121. exit(1);
  99122. }
  99123. fprintf(stderr,"OK\n");
  99124. ptr++;
  99125. }
  99126. exit(0);
  99127. }
  99128. #endif
  99129. #endif
  99130. /*** End of inlined file: codebook.c ***/
  99131. /*** Start of inlined file: envelope.c ***/
  99132. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99133. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99134. // tasks..
  99135. #if JUCE_MSVC
  99136. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99137. #endif
  99138. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99139. #if JUCE_USE_OGGVORBIS
  99140. #include <stdlib.h>
  99141. #include <string.h>
  99142. #include <stdio.h>
  99143. #include <math.h>
  99144. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99145. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99146. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99147. int ch=vi->channels;
  99148. int i,j;
  99149. int n=e->winlength=128;
  99150. e->searchstep=64; /* not random */
  99151. e->minenergy=gi->preecho_minenergy;
  99152. e->ch=ch;
  99153. e->storage=128;
  99154. e->cursor=ci->blocksizes[1]/2;
  99155. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99156. mdct_init(&e->mdct,n);
  99157. for(i=0;i<n;i++){
  99158. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99159. e->mdct_win[i]*=e->mdct_win[i];
  99160. }
  99161. e->band[0].begin=2; e->band[0].end=4;
  99162. e->band[1].begin=4; e->band[1].end=5;
  99163. e->band[2].begin=6; e->band[2].end=6;
  99164. e->band[3].begin=9; e->band[3].end=8;
  99165. e->band[4].begin=13; e->band[4].end=8;
  99166. e->band[5].begin=17; e->band[5].end=8;
  99167. e->band[6].begin=22; e->band[6].end=8;
  99168. for(j=0;j<VE_BANDS;j++){
  99169. n=e->band[j].end;
  99170. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99171. for(i=0;i<n;i++){
  99172. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99173. e->band[j].total+=e->band[j].window[i];
  99174. }
  99175. e->band[j].total=1./e->band[j].total;
  99176. }
  99177. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99178. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99179. }
  99180. void _ve_envelope_clear(envelope_lookup *e){
  99181. int i;
  99182. mdct_clear(&e->mdct);
  99183. for(i=0;i<VE_BANDS;i++)
  99184. _ogg_free(e->band[i].window);
  99185. _ogg_free(e->mdct_win);
  99186. _ogg_free(e->filter);
  99187. _ogg_free(e->mark);
  99188. memset(e,0,sizeof(*e));
  99189. }
  99190. static int _ve_amp(envelope_lookup *ve,
  99191. vorbis_info_psy_global *gi,
  99192. float *data,
  99193. envelope_band *bands,
  99194. envelope_filter_state *filters,
  99195. long pos){
  99196. long n=ve->winlength;
  99197. int ret=0;
  99198. long i,j;
  99199. float decay;
  99200. float minV=ve->minenergy;
  99201. float *vec=(float*) alloca(n*sizeof(*vec));
  99202. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99203. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99204. if(penalty<0.f)penalty=0.f;
  99205. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99206. for(i=0;i<n;i++)
  99207. vec[i]=data[i]*ve->mdct_win[i];
  99208. mdct_forward(&ve->mdct,vec,vec);
  99209. {
  99210. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99211. int ptr=filters->nearptr;
  99212. if(ptr==0){
  99213. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99214. filters->nearDC_partialacc=temp;
  99215. }else{
  99216. decay=filters->nearDC_acc+=temp;
  99217. filters->nearDC_partialacc+=temp;
  99218. }
  99219. filters->nearDC_acc-=filters->nearDC[ptr];
  99220. filters->nearDC[ptr]=temp;
  99221. decay*=(1./(VE_NEARDC+1));
  99222. filters->nearptr++;
  99223. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99224. decay=todB(&decay)*.5-15.f;
  99225. }
  99226. for(i=0;i<n/2;i+=2){
  99227. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99228. val=todB(&val)*.5f;
  99229. if(val<decay)val=decay;
  99230. if(val<minV)val=minV;
  99231. vec[i>>1]=val;
  99232. decay-=8.;
  99233. }
  99234. for(j=0;j<VE_BANDS;j++){
  99235. float acc=0.;
  99236. float valmax,valmin;
  99237. for(i=0;i<bands[j].end;i++)
  99238. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99239. acc*=bands[j].total;
  99240. {
  99241. int p,thisx=filters[j].ampptr;
  99242. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99243. p=thisx;
  99244. p--;
  99245. if(p<0)p+=VE_AMP;
  99246. postmax=max(acc,filters[j].ampbuf[p]);
  99247. postmin=min(acc,filters[j].ampbuf[p]);
  99248. for(i=0;i<stretch;i++){
  99249. p--;
  99250. if(p<0)p+=VE_AMP;
  99251. premax=max(premax,filters[j].ampbuf[p]);
  99252. premin=min(premin,filters[j].ampbuf[p]);
  99253. }
  99254. valmin=postmin-premin;
  99255. valmax=postmax-premax;
  99256. filters[j].ampbuf[thisx]=acc;
  99257. filters[j].ampptr++;
  99258. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99259. }
  99260. if(valmax>gi->preecho_thresh[j]+penalty){
  99261. ret|=1;
  99262. ret|=4;
  99263. }
  99264. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99265. }
  99266. return(ret);
  99267. }
  99268. #if 0
  99269. static int seq=0;
  99270. static ogg_int64_t totalshift=-1024;
  99271. #endif
  99272. long _ve_envelope_search(vorbis_dsp_state *v){
  99273. vorbis_info *vi=v->vi;
  99274. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99275. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99276. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99277. long i,j;
  99278. int first=ve->current/ve->searchstep;
  99279. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99280. if(first<0)first=0;
  99281. if(last+VE_WIN+VE_POST>ve->storage){
  99282. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99283. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99284. }
  99285. for(j=first;j<last;j++){
  99286. int ret=0;
  99287. ve->stretch++;
  99288. if(ve->stretch>VE_MAXSTRETCH*2)
  99289. ve->stretch=VE_MAXSTRETCH*2;
  99290. for(i=0;i<ve->ch;i++){
  99291. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99292. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99293. }
  99294. ve->mark[j+VE_POST]=0;
  99295. if(ret&1){
  99296. ve->mark[j]=1;
  99297. ve->mark[j+1]=1;
  99298. }
  99299. if(ret&2){
  99300. ve->mark[j]=1;
  99301. if(j>0)ve->mark[j-1]=1;
  99302. }
  99303. if(ret&4)ve->stretch=-1;
  99304. }
  99305. ve->current=last*ve->searchstep;
  99306. {
  99307. long centerW=v->centerW;
  99308. long testW=
  99309. centerW+
  99310. ci->blocksizes[v->W]/4+
  99311. ci->blocksizes[1]/2+
  99312. ci->blocksizes[0]/4;
  99313. j=ve->cursor;
  99314. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99315. working back one window */
  99316. if(j>=testW)return(1);
  99317. ve->cursor=j;
  99318. if(ve->mark[j/ve->searchstep]){
  99319. if(j>centerW){
  99320. #if 0
  99321. if(j>ve->curmark){
  99322. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99323. int l,m;
  99324. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99325. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99326. seq,
  99327. (totalshift+ve->cursor)/44100.,
  99328. (totalshift+j)/44100.);
  99329. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99330. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99331. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99332. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99333. for(m=0;m<VE_BANDS;m++){
  99334. char buf[80];
  99335. sprintf(buf,"delL%d",m);
  99336. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99337. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99338. }
  99339. for(m=0;m<VE_BANDS;m++){
  99340. char buf[80];
  99341. sprintf(buf,"delR%d",m);
  99342. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99343. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99344. }
  99345. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99346. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99347. seq++;
  99348. }
  99349. #endif
  99350. ve->curmark=j;
  99351. if(j>=testW)return(1);
  99352. return(0);
  99353. }
  99354. }
  99355. j+=ve->searchstep;
  99356. }
  99357. }
  99358. return(-1);
  99359. }
  99360. int _ve_envelope_mark(vorbis_dsp_state *v){
  99361. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99362. vorbis_info *vi=v->vi;
  99363. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99364. long centerW=v->centerW;
  99365. long beginW=centerW-ci->blocksizes[v->W]/4;
  99366. long endW=centerW+ci->blocksizes[v->W]/4;
  99367. if(v->W){
  99368. beginW-=ci->blocksizes[v->lW]/4;
  99369. endW+=ci->blocksizes[v->nW]/4;
  99370. }else{
  99371. beginW-=ci->blocksizes[0]/4;
  99372. endW+=ci->blocksizes[0]/4;
  99373. }
  99374. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99375. {
  99376. long first=beginW/ve->searchstep;
  99377. long last=endW/ve->searchstep;
  99378. long i;
  99379. for(i=first;i<last;i++)
  99380. if(ve->mark[i])return(1);
  99381. }
  99382. return(0);
  99383. }
  99384. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99385. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99386. ahead of ve->current */
  99387. int smallshift=shift/e->searchstep;
  99388. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99389. #if 0
  99390. for(i=0;i<VE_BANDS*e->ch;i++)
  99391. memmove(e->filter[i].markers,
  99392. e->filter[i].markers+smallshift,
  99393. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99394. totalshift+=shift;
  99395. #endif
  99396. e->current-=shift;
  99397. if(e->curmark>=0)
  99398. e->curmark-=shift;
  99399. e->cursor-=shift;
  99400. }
  99401. #endif
  99402. /*** End of inlined file: envelope.c ***/
  99403. /*** Start of inlined file: floor0.c ***/
  99404. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99405. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99406. // tasks..
  99407. #if JUCE_MSVC
  99408. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99409. #endif
  99410. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99411. #if JUCE_USE_OGGVORBIS
  99412. #include <stdlib.h>
  99413. #include <string.h>
  99414. #include <math.h>
  99415. /*** Start of inlined file: lsp.h ***/
  99416. #ifndef _V_LSP_H_
  99417. #define _V_LSP_H_
  99418. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99419. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99420. float *lsp,int m,
  99421. float amp,float ampoffset);
  99422. #endif
  99423. /*** End of inlined file: lsp.h ***/
  99424. #include <stdio.h>
  99425. typedef struct {
  99426. int ln;
  99427. int m;
  99428. int **linearmap;
  99429. int n[2];
  99430. vorbis_info_floor0 *vi;
  99431. long bits;
  99432. long frames;
  99433. } vorbis_look_floor0;
  99434. static void floor0_free_info(vorbis_info_floor *i){
  99435. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99436. if(info){
  99437. memset(info,0,sizeof(*info));
  99438. _ogg_free(info);
  99439. }
  99440. }
  99441. static void floor0_free_look(vorbis_look_floor *i){
  99442. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99443. if(look){
  99444. if(look->linearmap){
  99445. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99446. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99447. _ogg_free(look->linearmap);
  99448. }
  99449. memset(look,0,sizeof(*look));
  99450. _ogg_free(look);
  99451. }
  99452. }
  99453. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99454. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99455. int j;
  99456. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99457. info->order=oggpack_read(opb,8);
  99458. info->rate=oggpack_read(opb,16);
  99459. info->barkmap=oggpack_read(opb,16);
  99460. info->ampbits=oggpack_read(opb,6);
  99461. info->ampdB=oggpack_read(opb,8);
  99462. info->numbooks=oggpack_read(opb,4)+1;
  99463. if(info->order<1)goto err_out;
  99464. if(info->rate<1)goto err_out;
  99465. if(info->barkmap<1)goto err_out;
  99466. if(info->numbooks<1)goto err_out;
  99467. for(j=0;j<info->numbooks;j++){
  99468. info->books[j]=oggpack_read(opb,8);
  99469. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99470. }
  99471. return(info);
  99472. err_out:
  99473. floor0_free_info(info);
  99474. return(NULL);
  99475. }
  99476. static void floor0_map_lazy_init(vorbis_block *vb,
  99477. vorbis_info_floor *infoX,
  99478. vorbis_look_floor0 *look){
  99479. if(!look->linearmap[vb->W]){
  99480. vorbis_dsp_state *vd=vb->vd;
  99481. vorbis_info *vi=vd->vi;
  99482. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99483. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99484. int W=vb->W;
  99485. int n=ci->blocksizes[W]/2,j;
  99486. float scale=look->ln/toBARK(info->rate/2.f);
  99487. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99488. for(j=0;j<n;j++){
  99489. int val=floor( toBARK((info->rate/2.f)/n*j)
  99490. *scale); /* bark numbers represent band edges */
  99491. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99492. look->linearmap[W][j]=val;
  99493. }
  99494. look->linearmap[W][j]=-1;
  99495. look->n[W]=n;
  99496. }
  99497. }
  99498. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99499. vorbis_info_floor *i){
  99500. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99501. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99502. look->m=info->order;
  99503. look->ln=info->barkmap;
  99504. look->vi=info;
  99505. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99506. return look;
  99507. }
  99508. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99509. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99510. vorbis_info_floor0 *info=look->vi;
  99511. int j,k;
  99512. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99513. if(ampraw>0){ /* also handles the -1 out of data case */
  99514. long maxval=(1<<info->ampbits)-1;
  99515. float amp=(float)ampraw/maxval*info->ampdB;
  99516. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99517. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99518. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99519. codebook *b=ci->fullbooks+info->books[booknum];
  99520. float last=0.f;
  99521. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99522. for(j=0;j<look->m;j+=b->dim)
  99523. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99524. for(j=0;j<look->m;){
  99525. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99526. last=lsp[j-1];
  99527. }
  99528. lsp[look->m]=amp;
  99529. return(lsp);
  99530. }
  99531. }
  99532. eop:
  99533. return(NULL);
  99534. }
  99535. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99536. void *memo,float *out){
  99537. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99538. vorbis_info_floor0 *info=look->vi;
  99539. floor0_map_lazy_init(vb,info,look);
  99540. if(memo){
  99541. float *lsp=(float *)memo;
  99542. float amp=lsp[look->m];
  99543. vorbis_lsp_to_curve(out,
  99544. look->linearmap[vb->W],
  99545. look->n[vb->W],
  99546. look->ln,
  99547. lsp,look->m,amp,(float)info->ampdB);
  99548. return(1);
  99549. }
  99550. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99551. return(0);
  99552. }
  99553. vorbis_func_floor floor0_exportbundle={
  99554. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99555. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99556. };
  99557. #endif
  99558. /*** End of inlined file: floor0.c ***/
  99559. /*** Start of inlined file: floor1.c ***/
  99560. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99561. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99562. // tasks..
  99563. #if JUCE_MSVC
  99564. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99565. #endif
  99566. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99567. #if JUCE_USE_OGGVORBIS
  99568. #include <stdlib.h>
  99569. #include <string.h>
  99570. #include <math.h>
  99571. #include <stdio.h>
  99572. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99573. typedef struct {
  99574. int sorted_index[VIF_POSIT+2];
  99575. int forward_index[VIF_POSIT+2];
  99576. int reverse_index[VIF_POSIT+2];
  99577. int hineighbor[VIF_POSIT];
  99578. int loneighbor[VIF_POSIT];
  99579. int posts;
  99580. int n;
  99581. int quant_q;
  99582. vorbis_info_floor1 *vi;
  99583. long phrasebits;
  99584. long postbits;
  99585. long frames;
  99586. } vorbis_look_floor1;
  99587. typedef struct lsfit_acc{
  99588. long x0;
  99589. long x1;
  99590. long xa;
  99591. long ya;
  99592. long x2a;
  99593. long y2a;
  99594. long xya;
  99595. long an;
  99596. } lsfit_acc;
  99597. static void floor1_free_info(vorbis_info_floor *i){
  99598. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99599. if(info){
  99600. memset(info,0,sizeof(*info));
  99601. _ogg_free(info);
  99602. }
  99603. }
  99604. static void floor1_free_look(vorbis_look_floor *i){
  99605. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99606. if(look){
  99607. memset(look,0,sizeof(*look));
  99608. _ogg_free(look);
  99609. }
  99610. }
  99611. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99612. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99613. int j,k;
  99614. int count=0;
  99615. int rangebits;
  99616. int maxposit=info->postlist[1];
  99617. int maxclass=-1;
  99618. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99619. for(j=0;j<info->partitions;j++){
  99620. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99621. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99622. }
  99623. for(j=0;j<maxclass+1;j++){
  99624. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99625. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99626. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99627. for(k=0;k<(1<<info->class_subs[j]);k++)
  99628. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99629. }
  99630. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99631. oggpack_write(opb,ilog2(maxposit),4);
  99632. rangebits=ilog2(maxposit);
  99633. for(j=0,k=0;j<info->partitions;j++){
  99634. count+=info->class_dim[info->partitionclass[j]];
  99635. for(;k<count;k++)
  99636. oggpack_write(opb,info->postlist[k+2],rangebits);
  99637. }
  99638. }
  99639. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99640. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99641. int j,k,count=0,maxclass=-1,rangebits;
  99642. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99643. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99644. for(j=0;j<info->partitions;j++){
  99645. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99646. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99647. }
  99648. for(j=0;j<maxclass+1;j++){
  99649. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99650. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99651. if(info->class_subs[j]<0)
  99652. goto err_out;
  99653. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99654. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99655. goto err_out;
  99656. for(k=0;k<(1<<info->class_subs[j]);k++){
  99657. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99658. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99659. goto err_out;
  99660. }
  99661. }
  99662. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99663. rangebits=oggpack_read(opb,4);
  99664. for(j=0,k=0;j<info->partitions;j++){
  99665. count+=info->class_dim[info->partitionclass[j]];
  99666. for(;k<count;k++){
  99667. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99668. if(t<0 || t>=(1<<rangebits))
  99669. goto err_out;
  99670. }
  99671. }
  99672. info->postlist[0]=0;
  99673. info->postlist[1]=1<<rangebits;
  99674. return(info);
  99675. err_out:
  99676. floor1_free_info(info);
  99677. return(NULL);
  99678. }
  99679. static int icomp(const void *a,const void *b){
  99680. return(**(int **)a-**(int **)b);
  99681. }
  99682. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99683. vorbis_info_floor *in){
  99684. int *sortpointer[VIF_POSIT+2];
  99685. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99686. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99687. int i,j,n=0;
  99688. look->vi=info;
  99689. look->n=info->postlist[1];
  99690. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99691. n+=2;
  99692. look->posts=n;
  99693. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99694. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99695. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99696. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99697. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99698. switch(info->mult){
  99699. case 1: /* 1024 -> 256 */
  99700. look->quant_q=256;
  99701. break;
  99702. case 2: /* 1024 -> 128 */
  99703. look->quant_q=128;
  99704. break;
  99705. case 3: /* 1024 -> 86 */
  99706. look->quant_q=86;
  99707. break;
  99708. case 4: /* 1024 -> 64 */
  99709. look->quant_q=64;
  99710. break;
  99711. }
  99712. for(i=0;i<n-2;i++){
  99713. int lo=0;
  99714. int hi=1;
  99715. int lx=0;
  99716. int hx=look->n;
  99717. int currentx=info->postlist[i+2];
  99718. for(j=0;j<i+2;j++){
  99719. int x=info->postlist[j];
  99720. if(x>lx && x<currentx){
  99721. lo=j;
  99722. lx=x;
  99723. }
  99724. if(x<hx && x>currentx){
  99725. hi=j;
  99726. hx=x;
  99727. }
  99728. }
  99729. look->loneighbor[i]=lo;
  99730. look->hineighbor[i]=hi;
  99731. }
  99732. return(look);
  99733. }
  99734. static int render_point(int x0,int x1,int y0,int y1,int x){
  99735. y0&=0x7fff; /* mask off flag */
  99736. y1&=0x7fff;
  99737. {
  99738. int dy=y1-y0;
  99739. int adx=x1-x0;
  99740. int ady=abs(dy);
  99741. int err=ady*(x-x0);
  99742. int off=err/adx;
  99743. if(dy<0)return(y0-off);
  99744. return(y0+off);
  99745. }
  99746. }
  99747. static int vorbis_dBquant(const float *x){
  99748. int i= *x*7.3142857f+1023.5f;
  99749. if(i>1023)return(1023);
  99750. if(i<0)return(0);
  99751. return i;
  99752. }
  99753. static float FLOOR1_fromdB_LOOKUP[256]={
  99754. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99755. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99756. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99757. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99758. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99759. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99760. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99761. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99762. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99763. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99764. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99765. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99766. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99767. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99768. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99769. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99770. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99771. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99772. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99773. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99774. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99775. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99776. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99777. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99778. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99779. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99780. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99781. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99782. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99783. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99784. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99785. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99786. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99787. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99788. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99789. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99790. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99791. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99792. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99793. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99794. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99795. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99796. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99797. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99798. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99799. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99800. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99801. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99802. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99803. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99804. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99805. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99806. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99807. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99808. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99809. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99810. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99811. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99812. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99813. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99814. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99815. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99816. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99817. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99818. };
  99819. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99820. int dy=y1-y0;
  99821. int adx=x1-x0;
  99822. int ady=abs(dy);
  99823. int base=dy/adx;
  99824. int sy=(dy<0?base-1:base+1);
  99825. int x=x0;
  99826. int y=y0;
  99827. int err=0;
  99828. ady-=abs(base*adx);
  99829. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99830. while(++x<x1){
  99831. err=err+ady;
  99832. if(err>=adx){
  99833. err-=adx;
  99834. y+=sy;
  99835. }else{
  99836. y+=base;
  99837. }
  99838. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99839. }
  99840. }
  99841. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99842. int dy=y1-y0;
  99843. int adx=x1-x0;
  99844. int ady=abs(dy);
  99845. int base=dy/adx;
  99846. int sy=(dy<0?base-1:base+1);
  99847. int x=x0;
  99848. int y=y0;
  99849. int err=0;
  99850. ady-=abs(base*adx);
  99851. d[x]=y;
  99852. while(++x<x1){
  99853. err=err+ady;
  99854. if(err>=adx){
  99855. err-=adx;
  99856. y+=sy;
  99857. }else{
  99858. y+=base;
  99859. }
  99860. d[x]=y;
  99861. }
  99862. }
  99863. static int accumulate_fit(const float *flr,const float *mdct,
  99864. int x0, int x1,lsfit_acc *a,
  99865. int n,vorbis_info_floor1 *info){
  99866. long i;
  99867. 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;
  99868. memset(a,0,sizeof(*a));
  99869. a->x0=x0;
  99870. a->x1=x1;
  99871. if(x1>=n)x1=n-1;
  99872. for(i=x0;i<=x1;i++){
  99873. int quantized=vorbis_dBquant(flr+i);
  99874. if(quantized){
  99875. if(mdct[i]+info->twofitatten>=flr[i]){
  99876. xa += i;
  99877. ya += quantized;
  99878. x2a += i*i;
  99879. y2a += quantized*quantized;
  99880. xya += i*quantized;
  99881. na++;
  99882. }else{
  99883. xb += i;
  99884. yb += quantized;
  99885. x2b += i*i;
  99886. y2b += quantized*quantized;
  99887. xyb += i*quantized;
  99888. nb++;
  99889. }
  99890. }
  99891. }
  99892. xb+=xa;
  99893. yb+=ya;
  99894. x2b+=x2a;
  99895. y2b+=y2a;
  99896. xyb+=xya;
  99897. nb+=na;
  99898. {
  99899. int weight=nb*info->twofitweight/(na+1);
  99900. a->xa=xa*weight+xb;
  99901. a->ya=ya*weight+yb;
  99902. a->x2a=x2a*weight+x2b;
  99903. a->y2a=y2a*weight+y2b;
  99904. a->xya=xya*weight+xyb;
  99905. a->an=na*weight+nb;
  99906. }
  99907. return(na);
  99908. }
  99909. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99910. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99911. long x0=a[0].x0;
  99912. long x1=a[fits-1].x1;
  99913. for(i=0;i<fits;i++){
  99914. x+=a[i].xa;
  99915. y+=a[i].ya;
  99916. x2+=a[i].x2a;
  99917. y2+=a[i].y2a;
  99918. xy+=a[i].xya;
  99919. an+=a[i].an;
  99920. }
  99921. if(*y0>=0){
  99922. x+= x0;
  99923. y+= *y0;
  99924. x2+= x0 * x0;
  99925. y2+= *y0 * *y0;
  99926. xy+= *y0 * x0;
  99927. an++;
  99928. }
  99929. if(*y1>=0){
  99930. x+= x1;
  99931. y+= *y1;
  99932. x2+= x1 * x1;
  99933. y2+= *y1 * *y1;
  99934. xy+= *y1 * x1;
  99935. an++;
  99936. }
  99937. if(an){
  99938. double fx=x;
  99939. double fy=y;
  99940. double fx2=x2;
  99941. double fxy=xy;
  99942. double denom=1./(an*fx2-fx*fx);
  99943. double a=(fy*fx2-fxy*fx)*denom;
  99944. double b=(an*fxy-fx*fy)*denom;
  99945. *y0=rint(a+b*x0);
  99946. *y1=rint(a+b*x1);
  99947. if(*y0>1023)*y0=1023;
  99948. if(*y1>1023)*y1=1023;
  99949. if(*y0<0)*y0=0;
  99950. if(*y1<0)*y1=0;
  99951. }else{
  99952. *y0=0;
  99953. *y1=0;
  99954. }
  99955. }
  99956. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99957. const float *mdct,
  99958. vorbis_info_floor1 *info){
  99959. int dy=y1-y0;
  99960. int adx=x1-x0;
  99961. int ady=abs(dy);
  99962. int base=dy/adx;
  99963. int sy=(dy<0?base-1:base+1);
  99964. int x=x0;
  99965. int y=y0;
  99966. int err=0;
  99967. int val=vorbis_dBquant(mask+x);
  99968. int mse=0;
  99969. int n=0;
  99970. ady-=abs(base*adx);
  99971. mse=(y-val);
  99972. mse*=mse;
  99973. n++;
  99974. if(mdct[x]+info->twofitatten>=mask[x]){
  99975. if(y+info->maxover<val)return(1);
  99976. if(y-info->maxunder>val)return(1);
  99977. }
  99978. while(++x<x1){
  99979. err=err+ady;
  99980. if(err>=adx){
  99981. err-=adx;
  99982. y+=sy;
  99983. }else{
  99984. y+=base;
  99985. }
  99986. val=vorbis_dBquant(mask+x);
  99987. mse+=((y-val)*(y-val));
  99988. n++;
  99989. if(mdct[x]+info->twofitatten>=mask[x]){
  99990. if(val){
  99991. if(y+info->maxover<val)return(1);
  99992. if(y-info->maxunder>val)return(1);
  99993. }
  99994. }
  99995. }
  99996. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99997. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99998. if(mse/n>info->maxerr)return(1);
  99999. return(0);
  100000. }
  100001. static int post_Y(int *A,int *B,int pos){
  100002. if(A[pos]<0)
  100003. return B[pos];
  100004. if(B[pos]<0)
  100005. return A[pos];
  100006. return (A[pos]+B[pos])>>1;
  100007. }
  100008. int *floor1_fit(vorbis_block *vb,void *look_,
  100009. const float *logmdct, /* in */
  100010. const float *logmask){
  100011. long i,j;
  100012. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  100013. vorbis_info_floor1 *info=look->vi;
  100014. long n=look->n;
  100015. long posts=look->posts;
  100016. long nonzero=0;
  100017. lsfit_acc fits[VIF_POSIT+1];
  100018. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  100019. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  100020. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  100021. int hineighbor[VIF_POSIT+2];
  100022. int *output=NULL;
  100023. int memo[VIF_POSIT+2];
  100024. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  100025. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  100026. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  100027. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  100028. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  100029. if(posts==0){
  100030. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  100031. }else{
  100032. for(i=0;i<posts-1;i++)
  100033. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  100034. look->sorted_index[i+1],fits+i,
  100035. n,info);
  100036. }
  100037. if(nonzero){
  100038. int y0=-200;
  100039. int y1=-200;
  100040. fit_line(fits,posts-1,&y0,&y1);
  100041. fit_valueA[0]=y0;
  100042. fit_valueB[0]=y0;
  100043. fit_valueB[1]=y1;
  100044. fit_valueA[1]=y1;
  100045. for(i=2;i<posts;i++){
  100046. int sortpos=look->reverse_index[i];
  100047. int ln=loneighbor[sortpos];
  100048. int hn=hineighbor[sortpos];
  100049. if(memo[ln]!=hn){
  100050. int lsortpos=look->reverse_index[ln];
  100051. int hsortpos=look->reverse_index[hn];
  100052. memo[ln]=hn;
  100053. {
  100054. int lx=info->postlist[ln];
  100055. int hx=info->postlist[hn];
  100056. int ly=post_Y(fit_valueA,fit_valueB,ln);
  100057. int hy=post_Y(fit_valueA,fit_valueB,hn);
  100058. if(ly==-1 || hy==-1){
  100059. exit(1);
  100060. }
  100061. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  100062. int ly0=-200;
  100063. int ly1=-200;
  100064. int hy0=-200;
  100065. int hy1=-200;
  100066. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  100067. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  100068. fit_valueB[ln]=ly0;
  100069. if(ln==0)fit_valueA[ln]=ly0;
  100070. fit_valueA[i]=ly1;
  100071. fit_valueB[i]=hy0;
  100072. fit_valueA[hn]=hy1;
  100073. if(hn==1)fit_valueB[hn]=hy1;
  100074. if(ly1>=0 || hy0>=0){
  100075. for(j=sortpos-1;j>=0;j--)
  100076. if(hineighbor[j]==hn)
  100077. hineighbor[j]=i;
  100078. else
  100079. break;
  100080. for(j=sortpos+1;j<posts;j++)
  100081. if(loneighbor[j]==ln)
  100082. loneighbor[j]=i;
  100083. else
  100084. break;
  100085. }
  100086. }else{
  100087. fit_valueA[i]=-200;
  100088. fit_valueB[i]=-200;
  100089. }
  100090. }
  100091. }
  100092. }
  100093. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100094. output[0]=post_Y(fit_valueA,fit_valueB,0);
  100095. output[1]=post_Y(fit_valueA,fit_valueB,1);
  100096. for(i=2;i<posts;i++){
  100097. int ln=look->loneighbor[i-2];
  100098. int hn=look->hineighbor[i-2];
  100099. int x0=info->postlist[ln];
  100100. int x1=info->postlist[hn];
  100101. int y0=output[ln];
  100102. int y1=output[hn];
  100103. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100104. int vx=post_Y(fit_valueA,fit_valueB,i);
  100105. if(vx>=0 && predicted!=vx){
  100106. output[i]=vx;
  100107. }else{
  100108. output[i]= predicted|0x8000;
  100109. }
  100110. }
  100111. }
  100112. return(output);
  100113. }
  100114. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100115. int *A,int *B,
  100116. int del){
  100117. long i;
  100118. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100119. long posts=look->posts;
  100120. int *output=NULL;
  100121. if(A && B){
  100122. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100123. for(i=0;i<posts;i++){
  100124. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100125. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100126. }
  100127. }
  100128. return(output);
  100129. }
  100130. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100131. void*look_,
  100132. int *post,int *ilogmask){
  100133. long i,j;
  100134. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100135. vorbis_info_floor1 *info=look->vi;
  100136. long posts=look->posts;
  100137. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100138. int out[VIF_POSIT+2];
  100139. static_codebook **sbooks=ci->book_param;
  100140. codebook *books=ci->fullbooks;
  100141. static long seq=0;
  100142. if(post){
  100143. for(i=0;i<posts;i++){
  100144. int val=post[i]&0x7fff;
  100145. switch(info->mult){
  100146. case 1: /* 1024 -> 256 */
  100147. val>>=2;
  100148. break;
  100149. case 2: /* 1024 -> 128 */
  100150. val>>=3;
  100151. break;
  100152. case 3: /* 1024 -> 86 */
  100153. val/=12;
  100154. break;
  100155. case 4: /* 1024 -> 64 */
  100156. val>>=4;
  100157. break;
  100158. }
  100159. post[i]=val | (post[i]&0x8000);
  100160. }
  100161. out[0]=post[0];
  100162. out[1]=post[1];
  100163. for(i=2;i<posts;i++){
  100164. int ln=look->loneighbor[i-2];
  100165. int hn=look->hineighbor[i-2];
  100166. int x0=info->postlist[ln];
  100167. int x1=info->postlist[hn];
  100168. int y0=post[ln];
  100169. int y1=post[hn];
  100170. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100171. if((post[i]&0x8000) || (predicted==post[i])){
  100172. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100173. in interpolation */
  100174. out[i]=0;
  100175. }else{
  100176. int headroom=(look->quant_q-predicted<predicted?
  100177. look->quant_q-predicted:predicted);
  100178. int val=post[i]-predicted;
  100179. if(val<0)
  100180. if(val<-headroom)
  100181. val=headroom-val-1;
  100182. else
  100183. val=-1-(val<<1);
  100184. else
  100185. if(val>=headroom)
  100186. val= val+headroom;
  100187. else
  100188. val<<=1;
  100189. out[i]=val;
  100190. post[ln]&=0x7fff;
  100191. post[hn]&=0x7fff;
  100192. }
  100193. }
  100194. oggpack_write(opb,1,1);
  100195. look->frames++;
  100196. look->postbits+=ilog(look->quant_q-1)*2;
  100197. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100198. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100199. for(i=0,j=2;i<info->partitions;i++){
  100200. int classx=info->partitionclass[i];
  100201. int cdim=info->class_dim[classx];
  100202. int csubbits=info->class_subs[classx];
  100203. int csub=1<<csubbits;
  100204. int bookas[8]={0,0,0,0,0,0,0,0};
  100205. int cval=0;
  100206. int cshift=0;
  100207. int k,l;
  100208. if(csubbits){
  100209. int maxval[8];
  100210. for(k=0;k<csub;k++){
  100211. int booknum=info->class_subbook[classx][k];
  100212. if(booknum<0){
  100213. maxval[k]=1;
  100214. }else{
  100215. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100216. }
  100217. }
  100218. for(k=0;k<cdim;k++){
  100219. for(l=0;l<csub;l++){
  100220. int val=out[j+k];
  100221. if(val<maxval[l]){
  100222. bookas[k]=l;
  100223. break;
  100224. }
  100225. }
  100226. cval|= bookas[k]<<cshift;
  100227. cshift+=csubbits;
  100228. }
  100229. look->phrasebits+=
  100230. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100231. #ifdef TRAIN_FLOOR1
  100232. {
  100233. FILE *of;
  100234. char buffer[80];
  100235. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100236. vb->pcmend/2,posts-2,class);
  100237. of=fopen(buffer,"a");
  100238. fprintf(of,"%d\n",cval);
  100239. fclose(of);
  100240. }
  100241. #endif
  100242. }
  100243. for(k=0;k<cdim;k++){
  100244. int book=info->class_subbook[classx][bookas[k]];
  100245. if(book>=0){
  100246. if(out[j+k]<(books+book)->entries)
  100247. look->postbits+=vorbis_book_encode(books+book,
  100248. out[j+k],opb);
  100249. #ifdef TRAIN_FLOOR1
  100250. {
  100251. FILE *of;
  100252. char buffer[80];
  100253. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100254. vb->pcmend/2,posts-2,class,bookas[k]);
  100255. of=fopen(buffer,"a");
  100256. fprintf(of,"%d\n",out[j+k]);
  100257. fclose(of);
  100258. }
  100259. #endif
  100260. }
  100261. }
  100262. j+=cdim;
  100263. }
  100264. {
  100265. int hx=0;
  100266. int lx=0;
  100267. int ly=post[0]*info->mult;
  100268. for(j=1;j<look->posts;j++){
  100269. int current=look->forward_index[j];
  100270. int hy=post[current]&0x7fff;
  100271. if(hy==post[current]){
  100272. hy*=info->mult;
  100273. hx=info->postlist[current];
  100274. render_line0(lx,hx,ly,hy,ilogmask);
  100275. lx=hx;
  100276. ly=hy;
  100277. }
  100278. }
  100279. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100280. seq++;
  100281. return(1);
  100282. }
  100283. }else{
  100284. oggpack_write(opb,0,1);
  100285. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100286. seq++;
  100287. return(0);
  100288. }
  100289. }
  100290. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100291. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100292. vorbis_info_floor1 *info=look->vi;
  100293. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100294. int i,j,k;
  100295. codebook *books=ci->fullbooks;
  100296. if(oggpack_read(&vb->opb,1)==1){
  100297. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100298. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100299. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100300. for(i=0,j=2;i<info->partitions;i++){
  100301. int classx=info->partitionclass[i];
  100302. int cdim=info->class_dim[classx];
  100303. int csubbits=info->class_subs[classx];
  100304. int csub=1<<csubbits;
  100305. int cval=0;
  100306. if(csubbits){
  100307. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100308. if(cval==-1)goto eop;
  100309. }
  100310. for(k=0;k<cdim;k++){
  100311. int book=info->class_subbook[classx][cval&(csub-1)];
  100312. cval>>=csubbits;
  100313. if(book>=0){
  100314. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100315. goto eop;
  100316. }else{
  100317. fit_value[j+k]=0;
  100318. }
  100319. }
  100320. j+=cdim;
  100321. }
  100322. for(i=2;i<look->posts;i++){
  100323. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100324. info->postlist[look->hineighbor[i-2]],
  100325. fit_value[look->loneighbor[i-2]],
  100326. fit_value[look->hineighbor[i-2]],
  100327. info->postlist[i]);
  100328. int hiroom=look->quant_q-predicted;
  100329. int loroom=predicted;
  100330. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100331. int val=fit_value[i];
  100332. if(val){
  100333. if(val>=room){
  100334. if(hiroom>loroom){
  100335. val = val-loroom;
  100336. }else{
  100337. val = -1-(val-hiroom);
  100338. }
  100339. }else{
  100340. if(val&1){
  100341. val= -((val+1)>>1);
  100342. }else{
  100343. val>>=1;
  100344. }
  100345. }
  100346. fit_value[i]=val+predicted;
  100347. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100348. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100349. }else{
  100350. fit_value[i]=predicted|0x8000;
  100351. }
  100352. }
  100353. return(fit_value);
  100354. }
  100355. eop:
  100356. return(NULL);
  100357. }
  100358. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100359. float *out){
  100360. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100361. vorbis_info_floor1 *info=look->vi;
  100362. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100363. int n=ci->blocksizes[vb->W]/2;
  100364. int j;
  100365. if(memo){
  100366. int *fit_value=(int *)memo;
  100367. int hx=0;
  100368. int lx=0;
  100369. int ly=fit_value[0]*info->mult;
  100370. for(j=1;j<look->posts;j++){
  100371. int current=look->forward_index[j];
  100372. int hy=fit_value[current]&0x7fff;
  100373. if(hy==fit_value[current]){
  100374. hy*=info->mult;
  100375. hx=info->postlist[current];
  100376. render_line(lx,hx,ly,hy,out);
  100377. lx=hx;
  100378. ly=hy;
  100379. }
  100380. }
  100381. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100382. return(1);
  100383. }
  100384. memset(out,0,sizeof(*out)*n);
  100385. return(0);
  100386. }
  100387. vorbis_func_floor floor1_exportbundle={
  100388. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100389. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100390. };
  100391. #endif
  100392. /*** End of inlined file: floor1.c ***/
  100393. /*** Start of inlined file: info.c ***/
  100394. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100395. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100396. // tasks..
  100397. #if JUCE_MSVC
  100398. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100399. #endif
  100400. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100401. #if JUCE_USE_OGGVORBIS
  100402. #include <stdlib.h>
  100403. #include <string.h>
  100404. #include <ctype.h>
  100405. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100406. while(bytes--){
  100407. oggpack_write(o,*s++,8);
  100408. }
  100409. }
  100410. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100411. while(bytes--){
  100412. *buf++=oggpack_read(o,8);
  100413. }
  100414. }
  100415. void vorbis_comment_init(vorbis_comment *vc){
  100416. memset(vc,0,sizeof(*vc));
  100417. }
  100418. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100419. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100420. (vc->comments+2)*sizeof(*vc->user_comments));
  100421. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100422. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100423. vc->comment_lengths[vc->comments]=strlen(comment);
  100424. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100425. strcpy(vc->user_comments[vc->comments], comment);
  100426. vc->comments++;
  100427. vc->user_comments[vc->comments]=NULL;
  100428. }
  100429. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100430. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100431. strcpy(comment, tag);
  100432. strcat(comment, "=");
  100433. strcat(comment, contents);
  100434. vorbis_comment_add(vc, comment);
  100435. }
  100436. static int tagcompare(const char *s1, const char *s2, int n){
  100437. int c=0;
  100438. while(c < n){
  100439. if(toupper(s1[c]) != toupper(s2[c]))
  100440. return !0;
  100441. c++;
  100442. }
  100443. return 0;
  100444. }
  100445. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100446. long i;
  100447. int found = 0;
  100448. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100449. char *fulltag = (char*)alloca(taglen+ 1);
  100450. strcpy(fulltag, tag);
  100451. strcat(fulltag, "=");
  100452. for(i=0;i<vc->comments;i++){
  100453. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100454. if(count == found)
  100455. return vc->user_comments[i] + taglen;
  100456. else
  100457. found++;
  100458. }
  100459. }
  100460. return NULL; /* didn't find anything */
  100461. }
  100462. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100463. int i,count=0;
  100464. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100465. char *fulltag = (char*)alloca(taglen+1);
  100466. strcpy(fulltag,tag);
  100467. strcat(fulltag, "=");
  100468. for(i=0;i<vc->comments;i++){
  100469. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100470. count++;
  100471. }
  100472. return count;
  100473. }
  100474. void vorbis_comment_clear(vorbis_comment *vc){
  100475. if(vc){
  100476. long i;
  100477. for(i=0;i<vc->comments;i++)
  100478. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100479. if(vc->user_comments)_ogg_free(vc->user_comments);
  100480. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100481. if(vc->vendor)_ogg_free(vc->vendor);
  100482. }
  100483. memset(vc,0,sizeof(*vc));
  100484. }
  100485. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100486. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100487. return ci ? ci->blocksizes[zo] : -1;
  100488. }
  100489. void vorbis_info_init(vorbis_info *vi){
  100490. memset(vi,0,sizeof(*vi));
  100491. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100492. }
  100493. void vorbis_info_clear(vorbis_info *vi){
  100494. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100495. int i;
  100496. if(ci){
  100497. for(i=0;i<ci->modes;i++)
  100498. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100499. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100500. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100501. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100502. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100503. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100504. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100505. for(i=0;i<ci->books;i++){
  100506. if(ci->book_param[i]){
  100507. vorbis_staticbook_destroy(ci->book_param[i]);
  100508. }
  100509. if(ci->fullbooks)
  100510. vorbis_book_clear(ci->fullbooks+i);
  100511. }
  100512. if(ci->fullbooks)
  100513. _ogg_free(ci->fullbooks);
  100514. for(i=0;i<ci->psys;i++)
  100515. _vi_psy_free(ci->psy_param[i]);
  100516. _ogg_free(ci);
  100517. }
  100518. memset(vi,0,sizeof(*vi));
  100519. }
  100520. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100521. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100522. if(!ci)return(OV_EFAULT);
  100523. vi->version=oggpack_read(opb,32);
  100524. if(vi->version!=0)return(OV_EVERSION);
  100525. vi->channels=oggpack_read(opb,8);
  100526. vi->rate=oggpack_read(opb,32);
  100527. vi->bitrate_upper=oggpack_read(opb,32);
  100528. vi->bitrate_nominal=oggpack_read(opb,32);
  100529. vi->bitrate_lower=oggpack_read(opb,32);
  100530. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100531. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100532. if(vi->rate<1)goto err_out;
  100533. if(vi->channels<1)goto err_out;
  100534. if(ci->blocksizes[0]<8)goto err_out;
  100535. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100536. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100537. return(0);
  100538. err_out:
  100539. vorbis_info_clear(vi);
  100540. return(OV_EBADHEADER);
  100541. }
  100542. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100543. int i;
  100544. int vendorlen=oggpack_read(opb,32);
  100545. if(vendorlen<0)goto err_out;
  100546. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100547. _v_readstring(opb,vc->vendor,vendorlen);
  100548. vc->comments=oggpack_read(opb,32);
  100549. if(vc->comments<0)goto err_out;
  100550. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100551. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100552. for(i=0;i<vc->comments;i++){
  100553. int len=oggpack_read(opb,32);
  100554. if(len<0)goto err_out;
  100555. vc->comment_lengths[i]=len;
  100556. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100557. _v_readstring(opb,vc->user_comments[i],len);
  100558. }
  100559. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100560. return(0);
  100561. err_out:
  100562. vorbis_comment_clear(vc);
  100563. return(OV_EBADHEADER);
  100564. }
  100565. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100566. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100567. int i;
  100568. if(!ci)return(OV_EFAULT);
  100569. ci->books=oggpack_read(opb,8)+1;
  100570. for(i=0;i<ci->books;i++){
  100571. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100572. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100573. }
  100574. {
  100575. int times=oggpack_read(opb,6)+1;
  100576. for(i=0;i<times;i++){
  100577. int test=oggpack_read(opb,16);
  100578. if(test<0 || test>=VI_TIMEB)goto err_out;
  100579. }
  100580. }
  100581. ci->floors=oggpack_read(opb,6)+1;
  100582. for(i=0;i<ci->floors;i++){
  100583. ci->floor_type[i]=oggpack_read(opb,16);
  100584. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100585. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100586. if(!ci->floor_param[i])goto err_out;
  100587. }
  100588. ci->residues=oggpack_read(opb,6)+1;
  100589. for(i=0;i<ci->residues;i++){
  100590. ci->residue_type[i]=oggpack_read(opb,16);
  100591. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100592. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100593. if(!ci->residue_param[i])goto err_out;
  100594. }
  100595. ci->maps=oggpack_read(opb,6)+1;
  100596. for(i=0;i<ci->maps;i++){
  100597. ci->map_type[i]=oggpack_read(opb,16);
  100598. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100599. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100600. if(!ci->map_param[i])goto err_out;
  100601. }
  100602. ci->modes=oggpack_read(opb,6)+1;
  100603. for(i=0;i<ci->modes;i++){
  100604. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100605. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100606. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100607. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100608. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100609. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100610. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100611. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100612. }
  100613. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100614. return(0);
  100615. err_out:
  100616. vorbis_info_clear(vi);
  100617. return(OV_EBADHEADER);
  100618. }
  100619. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100620. oggpack_buffer opb;
  100621. if(op){
  100622. oggpack_readinit(&opb,op->packet,op->bytes);
  100623. {
  100624. char buffer[6];
  100625. int packtype=oggpack_read(&opb,8);
  100626. memset(buffer,0,6);
  100627. _v_readstring(&opb,buffer,6);
  100628. if(memcmp(buffer,"vorbis",6)){
  100629. return(OV_ENOTVORBIS);
  100630. }
  100631. switch(packtype){
  100632. case 0x01: /* least significant *bit* is read first */
  100633. if(!op->b_o_s){
  100634. return(OV_EBADHEADER);
  100635. }
  100636. if(vi->rate!=0){
  100637. return(OV_EBADHEADER);
  100638. }
  100639. return(_vorbis_unpack_info(vi,&opb));
  100640. case 0x03: /* least significant *bit* is read first */
  100641. if(vi->rate==0){
  100642. return(OV_EBADHEADER);
  100643. }
  100644. return(_vorbis_unpack_comment(vc,&opb));
  100645. case 0x05: /* least significant *bit* is read first */
  100646. if(vi->rate==0 || vc->vendor==NULL){
  100647. return(OV_EBADHEADER);
  100648. }
  100649. return(_vorbis_unpack_books(vi,&opb));
  100650. default:
  100651. return(OV_EBADHEADER);
  100652. break;
  100653. }
  100654. }
  100655. }
  100656. return(OV_EBADHEADER);
  100657. }
  100658. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100659. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100660. if(!ci)return(OV_EFAULT);
  100661. oggpack_write(opb,0x01,8);
  100662. _v_writestring(opb,"vorbis", 6);
  100663. oggpack_write(opb,0x00,32);
  100664. oggpack_write(opb,vi->channels,8);
  100665. oggpack_write(opb,vi->rate,32);
  100666. oggpack_write(opb,vi->bitrate_upper,32);
  100667. oggpack_write(opb,vi->bitrate_nominal,32);
  100668. oggpack_write(opb,vi->bitrate_lower,32);
  100669. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100670. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100671. oggpack_write(opb,1,1);
  100672. return(0);
  100673. }
  100674. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100675. char temp[]="Xiph.Org libVorbis I 20050304";
  100676. int bytes = strlen(temp);
  100677. oggpack_write(opb,0x03,8);
  100678. _v_writestring(opb,"vorbis", 6);
  100679. oggpack_write(opb,bytes,32);
  100680. _v_writestring(opb,temp, bytes);
  100681. oggpack_write(opb,vc->comments,32);
  100682. if(vc->comments){
  100683. int i;
  100684. for(i=0;i<vc->comments;i++){
  100685. if(vc->user_comments[i]){
  100686. oggpack_write(opb,vc->comment_lengths[i],32);
  100687. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100688. }else{
  100689. oggpack_write(opb,0,32);
  100690. }
  100691. }
  100692. }
  100693. oggpack_write(opb,1,1);
  100694. return(0);
  100695. }
  100696. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100697. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100698. int i;
  100699. if(!ci)return(OV_EFAULT);
  100700. oggpack_write(opb,0x05,8);
  100701. _v_writestring(opb,"vorbis", 6);
  100702. oggpack_write(opb,ci->books-1,8);
  100703. for(i=0;i<ci->books;i++)
  100704. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100705. oggpack_write(opb,0,6);
  100706. oggpack_write(opb,0,16);
  100707. oggpack_write(opb,ci->floors-1,6);
  100708. for(i=0;i<ci->floors;i++){
  100709. oggpack_write(opb,ci->floor_type[i],16);
  100710. if(_floor_P[ci->floor_type[i]]->pack)
  100711. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100712. else
  100713. goto err_out;
  100714. }
  100715. oggpack_write(opb,ci->residues-1,6);
  100716. for(i=0;i<ci->residues;i++){
  100717. oggpack_write(opb,ci->residue_type[i],16);
  100718. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100719. }
  100720. oggpack_write(opb,ci->maps-1,6);
  100721. for(i=0;i<ci->maps;i++){
  100722. oggpack_write(opb,ci->map_type[i],16);
  100723. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100724. }
  100725. oggpack_write(opb,ci->modes-1,6);
  100726. for(i=0;i<ci->modes;i++){
  100727. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100728. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100729. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100730. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100731. }
  100732. oggpack_write(opb,1,1);
  100733. return(0);
  100734. err_out:
  100735. return(-1);
  100736. }
  100737. int vorbis_commentheader_out(vorbis_comment *vc,
  100738. ogg_packet *op){
  100739. oggpack_buffer opb;
  100740. oggpack_writeinit(&opb);
  100741. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100742. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100743. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100744. op->bytes=oggpack_bytes(&opb);
  100745. op->b_o_s=0;
  100746. op->e_o_s=0;
  100747. op->granulepos=0;
  100748. op->packetno=1;
  100749. return 0;
  100750. }
  100751. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100752. vorbis_comment *vc,
  100753. ogg_packet *op,
  100754. ogg_packet *op_comm,
  100755. ogg_packet *op_code){
  100756. int ret=OV_EIMPL;
  100757. vorbis_info *vi=v->vi;
  100758. oggpack_buffer opb;
  100759. private_state *b=(private_state*)v->backend_state;
  100760. if(!b){
  100761. ret=OV_EFAULT;
  100762. goto err_out;
  100763. }
  100764. oggpack_writeinit(&opb);
  100765. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100766. if(b->header)_ogg_free(b->header);
  100767. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100768. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100769. op->packet=b->header;
  100770. op->bytes=oggpack_bytes(&opb);
  100771. op->b_o_s=1;
  100772. op->e_o_s=0;
  100773. op->granulepos=0;
  100774. op->packetno=0;
  100775. oggpack_reset(&opb);
  100776. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100777. if(b->header1)_ogg_free(b->header1);
  100778. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100779. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100780. op_comm->packet=b->header1;
  100781. op_comm->bytes=oggpack_bytes(&opb);
  100782. op_comm->b_o_s=0;
  100783. op_comm->e_o_s=0;
  100784. op_comm->granulepos=0;
  100785. op_comm->packetno=1;
  100786. oggpack_reset(&opb);
  100787. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100788. if(b->header2)_ogg_free(b->header2);
  100789. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100790. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100791. op_code->packet=b->header2;
  100792. op_code->bytes=oggpack_bytes(&opb);
  100793. op_code->b_o_s=0;
  100794. op_code->e_o_s=0;
  100795. op_code->granulepos=0;
  100796. op_code->packetno=2;
  100797. oggpack_writeclear(&opb);
  100798. return(0);
  100799. err_out:
  100800. oggpack_writeclear(&opb);
  100801. memset(op,0,sizeof(*op));
  100802. memset(op_comm,0,sizeof(*op_comm));
  100803. memset(op_code,0,sizeof(*op_code));
  100804. if(b->header)_ogg_free(b->header);
  100805. if(b->header1)_ogg_free(b->header1);
  100806. if(b->header2)_ogg_free(b->header2);
  100807. b->header=NULL;
  100808. b->header1=NULL;
  100809. b->header2=NULL;
  100810. return(ret);
  100811. }
  100812. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100813. if(granulepos>=0)
  100814. return((double)granulepos/v->vi->rate);
  100815. return(-1);
  100816. }
  100817. #endif
  100818. /*** End of inlined file: info.c ***/
  100819. /*** Start of inlined file: lpc.c ***/
  100820. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100821. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100822. // tasks..
  100823. #if JUCE_MSVC
  100824. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100825. #endif
  100826. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100827. #if JUCE_USE_OGGVORBIS
  100828. #include <stdlib.h>
  100829. #include <string.h>
  100830. #include <math.h>
  100831. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100832. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100833. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100834. double error;
  100835. int i,j;
  100836. j=m+1;
  100837. while(j--){
  100838. double d=0; /* double needed for accumulator depth */
  100839. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100840. aut[j]=d;
  100841. }
  100842. error=aut[0];
  100843. for(i=0;i<m;i++){
  100844. double r= -aut[i+1];
  100845. if(error==0){
  100846. memset(lpci,0,m*sizeof(*lpci));
  100847. return 0;
  100848. }
  100849. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100850. r/=error;
  100851. lpc[i]=r;
  100852. for(j=0;j<i/2;j++){
  100853. double tmp=lpc[j];
  100854. lpc[j]+=r*lpc[i-1-j];
  100855. lpc[i-1-j]+=r*tmp;
  100856. }
  100857. if(i%2)lpc[j]+=lpc[j]*r;
  100858. error*=1.f-r*r;
  100859. }
  100860. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100861. return error;
  100862. }
  100863. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100864. float *data,long n){
  100865. long i,j,o,p;
  100866. float y;
  100867. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100868. if(!prime)
  100869. for(i=0;i<m;i++)
  100870. work[i]=0.f;
  100871. else
  100872. for(i=0;i<m;i++)
  100873. work[i]=prime[i];
  100874. for(i=0;i<n;i++){
  100875. y=0;
  100876. o=i;
  100877. p=m;
  100878. for(j=0;j<m;j++)
  100879. y-=work[o++]*coeff[--p];
  100880. data[i]=work[o]=y;
  100881. }
  100882. }
  100883. #endif
  100884. /*** End of inlined file: lpc.c ***/
  100885. /*** Start of inlined file: lsp.c ***/
  100886. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100887. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100888. // tasks..
  100889. #if JUCE_MSVC
  100890. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100891. #endif
  100892. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100893. #if JUCE_USE_OGGVORBIS
  100894. #include <math.h>
  100895. #include <string.h>
  100896. #include <stdlib.h>
  100897. /*** Start of inlined file: lookup.h ***/
  100898. #ifndef _V_LOOKUP_H_
  100899. #ifdef FLOAT_LOOKUP
  100900. extern float vorbis_coslook(float a);
  100901. extern float vorbis_invsqlook(float a);
  100902. extern float vorbis_invsq2explook(int a);
  100903. extern float vorbis_fromdBlook(float a);
  100904. #endif
  100905. #ifdef INT_LOOKUP
  100906. extern long vorbis_invsqlook_i(long a,long e);
  100907. extern long vorbis_coslook_i(long a);
  100908. extern float vorbis_fromdBlook_i(long a);
  100909. #endif
  100910. #endif
  100911. /*** End of inlined file: lookup.h ***/
  100912. #define FLOAT_LOOKUP
  100913. #undef INT_LOOKUP
  100914. #ifdef FLOAT_LOOKUP
  100915. /*** Start of inlined file: lookup.c ***/
  100916. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100917. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100918. // tasks..
  100919. #if JUCE_MSVC
  100920. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100921. #endif
  100922. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100923. #if JUCE_USE_OGGVORBIS
  100924. #include <math.h>
  100925. /*** Start of inlined file: lookup.h ***/
  100926. #ifndef _V_LOOKUP_H_
  100927. #ifdef FLOAT_LOOKUP
  100928. extern float vorbis_coslook(float a);
  100929. extern float vorbis_invsqlook(float a);
  100930. extern float vorbis_invsq2explook(int a);
  100931. extern float vorbis_fromdBlook(float a);
  100932. #endif
  100933. #ifdef INT_LOOKUP
  100934. extern long vorbis_invsqlook_i(long a,long e);
  100935. extern long vorbis_coslook_i(long a);
  100936. extern float vorbis_fromdBlook_i(long a);
  100937. #endif
  100938. #endif
  100939. /*** End of inlined file: lookup.h ***/
  100940. /*** Start of inlined file: lookup_data.h ***/
  100941. #ifndef _V_LOOKUP_DATA_H_
  100942. #ifdef FLOAT_LOOKUP
  100943. #define COS_LOOKUP_SZ 128
  100944. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100945. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100946. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100947. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100948. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100949. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100950. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100951. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100952. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100953. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100954. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100955. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100956. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100957. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100958. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100959. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100960. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100961. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100962. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100963. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100964. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100965. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100966. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100967. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100968. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100969. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100970. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100971. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100972. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100973. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100974. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100975. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100976. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100977. -1.0000000000000f,
  100978. };
  100979. #define INVSQ_LOOKUP_SZ 32
  100980. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100981. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100982. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100983. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100984. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100985. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100986. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100987. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100988. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100989. 1.000000000000f,
  100990. };
  100991. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100992. #define INVSQ2EXP_LOOKUP_MAX 32
  100993. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100994. INVSQ2EXP_LOOKUP_MIN+1]={
  100995. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100996. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100997. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100998. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100999. 256.f, 181.019336f, 128.f, 90.50966799f,
  101000. 64.f, 45.254834f, 32.f, 22.627417f,
  101001. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101002. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101003. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101004. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101005. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101006. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101007. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101008. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101009. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101010. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101011. 1.525878906e-05f,
  101012. };
  101013. #endif
  101014. #define FROMdB_LOOKUP_SZ 35
  101015. #define FROMdB2_LOOKUP_SZ 32
  101016. #define FROMdB_SHIFT 5
  101017. #define FROMdB2_SHIFT 3
  101018. #define FROMdB2_MASK 31
  101019. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101020. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101021. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101022. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101023. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101024. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101025. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101026. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101027. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101028. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101029. };
  101030. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101031. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101032. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101033. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101034. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101035. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101036. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101037. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101038. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101039. };
  101040. #ifdef INT_LOOKUP
  101041. #define INVSQ_LOOKUP_I_SHIFT 10
  101042. #define INVSQ_LOOKUP_I_MASK 1023
  101043. static long INVSQ_LOOKUP_I[64+1]={
  101044. 92682l, 91966l, 91267l, 90583l,
  101045. 89915l, 89261l, 88621l, 87995l,
  101046. 87381l, 86781l, 86192l, 85616l,
  101047. 85051l, 84497l, 83953l, 83420l,
  101048. 82897l, 82384l, 81880l, 81385l,
  101049. 80899l, 80422l, 79953l, 79492l,
  101050. 79039l, 78594l, 78156l, 77726l,
  101051. 77302l, 76885l, 76475l, 76072l,
  101052. 75674l, 75283l, 74898l, 74519l,
  101053. 74146l, 73778l, 73415l, 73058l,
  101054. 72706l, 72359l, 72016l, 71679l,
  101055. 71347l, 71019l, 70695l, 70376l,
  101056. 70061l, 69750l, 69444l, 69141l,
  101057. 68842l, 68548l, 68256l, 67969l,
  101058. 67685l, 67405l, 67128l, 66855l,
  101059. 66585l, 66318l, 66054l, 65794l,
  101060. 65536l,
  101061. };
  101062. #define COS_LOOKUP_I_SHIFT 9
  101063. #define COS_LOOKUP_I_MASK 511
  101064. #define COS_LOOKUP_I_SZ 128
  101065. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101066. 16384l, 16379l, 16364l, 16340l,
  101067. 16305l, 16261l, 16207l, 16143l,
  101068. 16069l, 15986l, 15893l, 15791l,
  101069. 15679l, 15557l, 15426l, 15286l,
  101070. 15137l, 14978l, 14811l, 14635l,
  101071. 14449l, 14256l, 14053l, 13842l,
  101072. 13623l, 13395l, 13160l, 12916l,
  101073. 12665l, 12406l, 12140l, 11866l,
  101074. 11585l, 11297l, 11003l, 10702l,
  101075. 10394l, 10080l, 9760l, 9434l,
  101076. 9102l, 8765l, 8423l, 8076l,
  101077. 7723l, 7366l, 7005l, 6639l,
  101078. 6270l, 5897l, 5520l, 5139l,
  101079. 4756l, 4370l, 3981l, 3590l,
  101080. 3196l, 2801l, 2404l, 2006l,
  101081. 1606l, 1205l, 804l, 402l,
  101082. 0l, -401l, -803l, -1204l,
  101083. -1605l, -2005l, -2403l, -2800l,
  101084. -3195l, -3589l, -3980l, -4369l,
  101085. -4755l, -5138l, -5519l, -5896l,
  101086. -6269l, -6638l, -7004l, -7365l,
  101087. -7722l, -8075l, -8422l, -8764l,
  101088. -9101l, -9433l, -9759l, -10079l,
  101089. -10393l, -10701l, -11002l, -11296l,
  101090. -11584l, -11865l, -12139l, -12405l,
  101091. -12664l, -12915l, -13159l, -13394l,
  101092. -13622l, -13841l, -14052l, -14255l,
  101093. -14448l, -14634l, -14810l, -14977l,
  101094. -15136l, -15285l, -15425l, -15556l,
  101095. -15678l, -15790l, -15892l, -15985l,
  101096. -16068l, -16142l, -16206l, -16260l,
  101097. -16304l, -16339l, -16363l, -16378l,
  101098. -16383l,
  101099. };
  101100. #endif
  101101. #endif
  101102. /*** End of inlined file: lookup_data.h ***/
  101103. #ifdef FLOAT_LOOKUP
  101104. float vorbis_coslook(float a){
  101105. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101106. int i=vorbis_ftoi(d-.5);
  101107. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101108. }
  101109. float vorbis_invsqlook(float a){
  101110. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101111. int i=vorbis_ftoi(d-.5f);
  101112. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101113. }
  101114. float vorbis_invsq2explook(int a){
  101115. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101116. }
  101117. #include <stdio.h>
  101118. float vorbis_fromdBlook(float a){
  101119. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101120. return (i<0)?1.f:
  101121. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101122. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101123. }
  101124. #endif
  101125. #ifdef INT_LOOKUP
  101126. long vorbis_invsqlook_i(long a,long e){
  101127. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101128. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101129. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101130. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101131. d)>>16); /* result 1.16 */
  101132. e+=32;
  101133. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101134. e=(e>>1)-8;
  101135. return(val>>e);
  101136. }
  101137. float vorbis_fromdBlook_i(long a){
  101138. int i=(-a)>>(12-FROMdB2_SHIFT);
  101139. return (i<0)?1.f:
  101140. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101141. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101142. }
  101143. long vorbis_coslook_i(long a){
  101144. int i=a>>COS_LOOKUP_I_SHIFT;
  101145. int d=a&COS_LOOKUP_I_MASK;
  101146. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101147. COS_LOOKUP_I_SHIFT);
  101148. }
  101149. #endif
  101150. #endif
  101151. /*** End of inlined file: lookup.c ***/
  101152. /* catch this in the build system; we #include for
  101153. compilers (like gcc) that can't inline across
  101154. modules */
  101155. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101156. float amp,float ampoffset){
  101157. int i;
  101158. float wdel=M_PI/ln;
  101159. vorbis_fpu_control fpu;
  101160. (void) fpu; // to avoid an unused variable warning
  101161. vorbis_fpu_setround(&fpu);
  101162. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101163. i=0;
  101164. while(i<n){
  101165. int k=map[i];
  101166. int qexp;
  101167. float p=.7071067812f;
  101168. float q=.7071067812f;
  101169. float w=vorbis_coslook(wdel*k);
  101170. float *ftmp=lsp;
  101171. int c=m>>1;
  101172. do{
  101173. q*=ftmp[0]-w;
  101174. p*=ftmp[1]-w;
  101175. ftmp+=2;
  101176. }while(--c);
  101177. if(m&1){
  101178. q*=ftmp[0]-w;
  101179. q*=q;
  101180. p*=p*(1.f-w*w);
  101181. }else{
  101182. q*=q*(1.f+w);
  101183. p*=p*(1.f-w);
  101184. }
  101185. q=frexp(p+q,&qexp);
  101186. q=vorbis_fromdBlook(amp*
  101187. vorbis_invsqlook(q)*
  101188. vorbis_invsq2explook(qexp+m)-
  101189. ampoffset);
  101190. do{
  101191. curve[i++]*=q;
  101192. }while(map[i]==k);
  101193. }
  101194. vorbis_fpu_restore(fpu);
  101195. }
  101196. #else
  101197. #ifdef INT_LOOKUP
  101198. /*** Start of inlined file: lookup.c ***/
  101199. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101200. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101201. // tasks..
  101202. #if JUCE_MSVC
  101203. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101204. #endif
  101205. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101206. #if JUCE_USE_OGGVORBIS
  101207. #include <math.h>
  101208. /*** Start of inlined file: lookup.h ***/
  101209. #ifndef _V_LOOKUP_H_
  101210. #ifdef FLOAT_LOOKUP
  101211. extern float vorbis_coslook(float a);
  101212. extern float vorbis_invsqlook(float a);
  101213. extern float vorbis_invsq2explook(int a);
  101214. extern float vorbis_fromdBlook(float a);
  101215. #endif
  101216. #ifdef INT_LOOKUP
  101217. extern long vorbis_invsqlook_i(long a,long e);
  101218. extern long vorbis_coslook_i(long a);
  101219. extern float vorbis_fromdBlook_i(long a);
  101220. #endif
  101221. #endif
  101222. /*** End of inlined file: lookup.h ***/
  101223. /*** Start of inlined file: lookup_data.h ***/
  101224. #ifndef _V_LOOKUP_DATA_H_
  101225. #ifdef FLOAT_LOOKUP
  101226. #define COS_LOOKUP_SZ 128
  101227. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101228. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101229. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101230. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101231. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101232. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101233. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101234. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101235. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101236. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101237. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101238. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101239. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101240. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101241. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101242. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101243. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101244. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101245. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101246. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101247. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101248. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101249. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101250. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101251. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101252. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101253. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101254. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101255. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101256. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101257. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101258. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101259. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101260. -1.0000000000000f,
  101261. };
  101262. #define INVSQ_LOOKUP_SZ 32
  101263. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101264. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101265. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101266. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101267. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101268. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101269. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101270. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101271. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101272. 1.000000000000f,
  101273. };
  101274. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101275. #define INVSQ2EXP_LOOKUP_MAX 32
  101276. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101277. INVSQ2EXP_LOOKUP_MIN+1]={
  101278. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101279. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101280. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101281. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101282. 256.f, 181.019336f, 128.f, 90.50966799f,
  101283. 64.f, 45.254834f, 32.f, 22.627417f,
  101284. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101285. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101286. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101287. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101288. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101289. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101290. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101291. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101292. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101293. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101294. 1.525878906e-05f,
  101295. };
  101296. #endif
  101297. #define FROMdB_LOOKUP_SZ 35
  101298. #define FROMdB2_LOOKUP_SZ 32
  101299. #define FROMdB_SHIFT 5
  101300. #define FROMdB2_SHIFT 3
  101301. #define FROMdB2_MASK 31
  101302. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101303. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101304. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101305. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101306. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101307. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101308. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101309. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101310. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101311. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101312. };
  101313. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101314. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101315. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101316. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101317. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101318. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101319. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101320. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101321. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101322. };
  101323. #ifdef INT_LOOKUP
  101324. #define INVSQ_LOOKUP_I_SHIFT 10
  101325. #define INVSQ_LOOKUP_I_MASK 1023
  101326. static long INVSQ_LOOKUP_I[64+1]={
  101327. 92682l, 91966l, 91267l, 90583l,
  101328. 89915l, 89261l, 88621l, 87995l,
  101329. 87381l, 86781l, 86192l, 85616l,
  101330. 85051l, 84497l, 83953l, 83420l,
  101331. 82897l, 82384l, 81880l, 81385l,
  101332. 80899l, 80422l, 79953l, 79492l,
  101333. 79039l, 78594l, 78156l, 77726l,
  101334. 77302l, 76885l, 76475l, 76072l,
  101335. 75674l, 75283l, 74898l, 74519l,
  101336. 74146l, 73778l, 73415l, 73058l,
  101337. 72706l, 72359l, 72016l, 71679l,
  101338. 71347l, 71019l, 70695l, 70376l,
  101339. 70061l, 69750l, 69444l, 69141l,
  101340. 68842l, 68548l, 68256l, 67969l,
  101341. 67685l, 67405l, 67128l, 66855l,
  101342. 66585l, 66318l, 66054l, 65794l,
  101343. 65536l,
  101344. };
  101345. #define COS_LOOKUP_I_SHIFT 9
  101346. #define COS_LOOKUP_I_MASK 511
  101347. #define COS_LOOKUP_I_SZ 128
  101348. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101349. 16384l, 16379l, 16364l, 16340l,
  101350. 16305l, 16261l, 16207l, 16143l,
  101351. 16069l, 15986l, 15893l, 15791l,
  101352. 15679l, 15557l, 15426l, 15286l,
  101353. 15137l, 14978l, 14811l, 14635l,
  101354. 14449l, 14256l, 14053l, 13842l,
  101355. 13623l, 13395l, 13160l, 12916l,
  101356. 12665l, 12406l, 12140l, 11866l,
  101357. 11585l, 11297l, 11003l, 10702l,
  101358. 10394l, 10080l, 9760l, 9434l,
  101359. 9102l, 8765l, 8423l, 8076l,
  101360. 7723l, 7366l, 7005l, 6639l,
  101361. 6270l, 5897l, 5520l, 5139l,
  101362. 4756l, 4370l, 3981l, 3590l,
  101363. 3196l, 2801l, 2404l, 2006l,
  101364. 1606l, 1205l, 804l, 402l,
  101365. 0l, -401l, -803l, -1204l,
  101366. -1605l, -2005l, -2403l, -2800l,
  101367. -3195l, -3589l, -3980l, -4369l,
  101368. -4755l, -5138l, -5519l, -5896l,
  101369. -6269l, -6638l, -7004l, -7365l,
  101370. -7722l, -8075l, -8422l, -8764l,
  101371. -9101l, -9433l, -9759l, -10079l,
  101372. -10393l, -10701l, -11002l, -11296l,
  101373. -11584l, -11865l, -12139l, -12405l,
  101374. -12664l, -12915l, -13159l, -13394l,
  101375. -13622l, -13841l, -14052l, -14255l,
  101376. -14448l, -14634l, -14810l, -14977l,
  101377. -15136l, -15285l, -15425l, -15556l,
  101378. -15678l, -15790l, -15892l, -15985l,
  101379. -16068l, -16142l, -16206l, -16260l,
  101380. -16304l, -16339l, -16363l, -16378l,
  101381. -16383l,
  101382. };
  101383. #endif
  101384. #endif
  101385. /*** End of inlined file: lookup_data.h ***/
  101386. #ifdef FLOAT_LOOKUP
  101387. float vorbis_coslook(float a){
  101388. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101389. int i=vorbis_ftoi(d-.5);
  101390. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101391. }
  101392. float vorbis_invsqlook(float a){
  101393. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101394. int i=vorbis_ftoi(d-.5f);
  101395. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101396. }
  101397. float vorbis_invsq2explook(int a){
  101398. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101399. }
  101400. #include <stdio.h>
  101401. float vorbis_fromdBlook(float a){
  101402. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101403. return (i<0)?1.f:
  101404. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101405. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101406. }
  101407. #endif
  101408. #ifdef INT_LOOKUP
  101409. long vorbis_invsqlook_i(long a,long e){
  101410. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101411. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101412. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101413. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101414. d)>>16); /* result 1.16 */
  101415. e+=32;
  101416. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101417. e=(e>>1)-8;
  101418. return(val>>e);
  101419. }
  101420. float vorbis_fromdBlook_i(long a){
  101421. int i=(-a)>>(12-FROMdB2_SHIFT);
  101422. return (i<0)?1.f:
  101423. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101424. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101425. }
  101426. long vorbis_coslook_i(long a){
  101427. int i=a>>COS_LOOKUP_I_SHIFT;
  101428. int d=a&COS_LOOKUP_I_MASK;
  101429. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101430. COS_LOOKUP_I_SHIFT);
  101431. }
  101432. #endif
  101433. #endif
  101434. /*** End of inlined file: lookup.c ***/
  101435. /* catch this in the build system; we #include for
  101436. compilers (like gcc) that can't inline across
  101437. modules */
  101438. static int MLOOP_1[64]={
  101439. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101440. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101441. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101442. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101443. };
  101444. static int MLOOP_2[64]={
  101445. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101446. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101447. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101448. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101449. };
  101450. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101451. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101452. float amp,float ampoffset){
  101453. int i;
  101454. int ampoffseti=rint(ampoffset*4096.f);
  101455. int ampi=rint(amp*16.f);
  101456. long *ilsp=alloca(m*sizeof(*ilsp));
  101457. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101458. i=0;
  101459. while(i<n){
  101460. int j,k=map[i];
  101461. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101462. unsigned long qi=46341;
  101463. int qexp=0,shift;
  101464. long wi=vorbis_coslook_i(k*65536/ln);
  101465. qi*=labs(ilsp[0]-wi);
  101466. pi*=labs(ilsp[1]-wi);
  101467. for(j=3;j<m;j+=2){
  101468. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101469. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101470. shift=MLOOP_3[(pi|qi)>>16];
  101471. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101472. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101473. qexp+=shift;
  101474. }
  101475. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101476. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101477. shift=MLOOP_3[(pi|qi)>>16];
  101478. if(m&1){
  101479. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101480. pi=(pi>>shift)<<14;
  101481. qexp+=shift;
  101482. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101483. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101484. shift=MLOOP_3[(pi|qi)>>16];
  101485. pi>>=shift;
  101486. qi>>=shift;
  101487. qexp+=shift-14*((m+1)>>1);
  101488. pi=((pi*pi)>>16);
  101489. qi=((qi*qi)>>16);
  101490. qexp=qexp*2+m;
  101491. pi*=(1<<14)-((wi*wi)>>14);
  101492. qi+=pi>>14;
  101493. }else{
  101494. pi>>=shift;
  101495. qi>>=shift;
  101496. qexp+=shift-7*m;
  101497. pi=((pi*pi)>>16);
  101498. qi=((qi*qi)>>16);
  101499. qexp=qexp*2+m;
  101500. pi*=(1<<14)-wi;
  101501. qi*=(1<<14)+wi;
  101502. qi=(qi+pi)>>14;
  101503. }
  101504. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101505. qi>>=1; qexp++;
  101506. }else
  101507. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101508. qi<<=1; qexp--;
  101509. }
  101510. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101511. vorbis_invsqlook_i(qi,qexp)-
  101512. ampoffseti); /* 8.12[0] */
  101513. curve[i]*=amp;
  101514. while(map[++i]==k)curve[i]*=amp;
  101515. }
  101516. }
  101517. #else
  101518. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101519. float amp,float ampoffset){
  101520. int i;
  101521. float wdel=M_PI/ln;
  101522. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101523. i=0;
  101524. while(i<n){
  101525. int j,k=map[i];
  101526. float p=.5f;
  101527. float q=.5f;
  101528. float w=2.f*cos(wdel*k);
  101529. for(j=1;j<m;j+=2){
  101530. q *= w-lsp[j-1];
  101531. p *= w-lsp[j];
  101532. }
  101533. if(j==m){
  101534. q*=w-lsp[j-1];
  101535. p*=p*(4.f-w*w);
  101536. q*=q;
  101537. }else{
  101538. p*=p*(2.f-w);
  101539. q*=q*(2.f+w);
  101540. }
  101541. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101542. curve[i]*=q;
  101543. while(map[++i]==k)curve[i]*=q;
  101544. }
  101545. }
  101546. #endif
  101547. #endif
  101548. static void cheby(float *g, int ord) {
  101549. int i, j;
  101550. g[0] *= .5f;
  101551. for(i=2; i<= ord; i++) {
  101552. for(j=ord; j >= i; j--) {
  101553. g[j-2] -= g[j];
  101554. g[j] += g[j];
  101555. }
  101556. }
  101557. }
  101558. static int comp(const void *a,const void *b){
  101559. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101560. }
  101561. #define EPSILON 10e-7
  101562. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101563. int i,m;
  101564. double lastdelta=0.f;
  101565. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101566. for(i=0;i<=ord;i++)defl[i]=a[i];
  101567. for(m=ord;m>0;m--){
  101568. double newx=0.f,delta;
  101569. while(1){
  101570. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101571. for(i=m;i>0;i--){
  101572. ppp = newx*ppp + pp;
  101573. pp = newx*pp + p;
  101574. p = newx*p + defl[i-1];
  101575. }
  101576. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101577. if(denom<0)
  101578. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101579. if(pp>0){
  101580. denom = pp + sqrt(denom);
  101581. if(denom<EPSILON)denom=EPSILON;
  101582. }else{
  101583. denom = pp - sqrt(denom);
  101584. if(denom>-(EPSILON))denom=-(EPSILON);
  101585. }
  101586. delta = m*p/denom;
  101587. newx -= delta;
  101588. if(delta<0.f)delta*=-1;
  101589. if(fabs(delta/newx)<10e-12)break;
  101590. lastdelta=delta;
  101591. }
  101592. r[m-1]=newx;
  101593. for(i=m;i>0;i--)
  101594. defl[i-1]+=newx*defl[i];
  101595. defl++;
  101596. }
  101597. return(0);
  101598. }
  101599. static int Newton_Raphson(float *a,int ord,float *r){
  101600. int i, k, count=0;
  101601. double error=1.f;
  101602. double *root=(double*)alloca(ord*sizeof(*root));
  101603. for(i=0; i<ord;i++) root[i] = r[i];
  101604. while(error>1e-20){
  101605. error=0;
  101606. for(i=0; i<ord; i++) { /* Update each point. */
  101607. double pp=0.,delta;
  101608. double rooti=root[i];
  101609. double p=a[ord];
  101610. for(k=ord-1; k>= 0; k--) {
  101611. pp= pp* rooti + p;
  101612. p = p * rooti + a[k];
  101613. }
  101614. delta = p/pp;
  101615. root[i] -= delta;
  101616. error+= delta*delta;
  101617. }
  101618. if(count>40)return(-1);
  101619. count++;
  101620. }
  101621. for(i=0; i<ord;i++) r[i] = root[i];
  101622. return(0);
  101623. }
  101624. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101625. int order2=(m+1)>>1;
  101626. int g1_order,g2_order;
  101627. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101628. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101629. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101630. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101631. int i;
  101632. g1_order=(m+1)>>1;
  101633. g2_order=(m) >>1;
  101634. g1[g1_order] = 1.f;
  101635. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101636. g2[g2_order] = 1.f;
  101637. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101638. if(g1_order>g2_order){
  101639. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101640. }else{
  101641. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101642. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101643. }
  101644. cheby(g1,g1_order);
  101645. cheby(g2,g2_order);
  101646. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101647. Laguerre_With_Deflation(g2,g2_order,g2r))
  101648. return(-1);
  101649. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101650. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101651. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101652. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101653. for(i=0;i<g1_order;i++)
  101654. lsp[i*2] = acos(g1r[i]);
  101655. for(i=0;i<g2_order;i++)
  101656. lsp[i*2+1] = acos(g2r[i]);
  101657. return(0);
  101658. }
  101659. #endif
  101660. /*** End of inlined file: lsp.c ***/
  101661. /*** Start of inlined file: mapping0.c ***/
  101662. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101663. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101664. // tasks..
  101665. #if JUCE_MSVC
  101666. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101667. #endif
  101668. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101669. #if JUCE_USE_OGGVORBIS
  101670. #include <stdlib.h>
  101671. #include <stdio.h>
  101672. #include <string.h>
  101673. #include <math.h>
  101674. static void mapping0_free_info(vorbis_info_mapping *i){
  101675. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101676. if(info){
  101677. memset(info,0,sizeof(*info));
  101678. _ogg_free(info);
  101679. }
  101680. }
  101681. static int ilog3(unsigned int v){
  101682. int ret=0;
  101683. if(v)--v;
  101684. while(v){
  101685. ret++;
  101686. v>>=1;
  101687. }
  101688. return(ret);
  101689. }
  101690. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101691. oggpack_buffer *opb){
  101692. int i;
  101693. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101694. if(info->submaps>1){
  101695. oggpack_write(opb,1,1);
  101696. oggpack_write(opb,info->submaps-1,4);
  101697. }else
  101698. oggpack_write(opb,0,1);
  101699. if(info->coupling_steps>0){
  101700. oggpack_write(opb,1,1);
  101701. oggpack_write(opb,info->coupling_steps-1,8);
  101702. for(i=0;i<info->coupling_steps;i++){
  101703. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101704. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101705. }
  101706. }else
  101707. oggpack_write(opb,0,1);
  101708. oggpack_write(opb,0,2); /* 2,3:reserved */
  101709. if(info->submaps>1){
  101710. for(i=0;i<vi->channels;i++)
  101711. oggpack_write(opb,info->chmuxlist[i],4);
  101712. }
  101713. for(i=0;i<info->submaps;i++){
  101714. oggpack_write(opb,0,8); /* time submap unused */
  101715. oggpack_write(opb,info->floorsubmap[i],8);
  101716. oggpack_write(opb,info->residuesubmap[i],8);
  101717. }
  101718. }
  101719. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101720. int i;
  101721. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101722. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101723. memset(info,0,sizeof(*info));
  101724. if(oggpack_read(opb,1))
  101725. info->submaps=oggpack_read(opb,4)+1;
  101726. else
  101727. info->submaps=1;
  101728. if(oggpack_read(opb,1)){
  101729. info->coupling_steps=oggpack_read(opb,8)+1;
  101730. for(i=0;i<info->coupling_steps;i++){
  101731. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101732. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101733. if(testM<0 ||
  101734. testA<0 ||
  101735. testM==testA ||
  101736. testM>=vi->channels ||
  101737. testA>=vi->channels) goto err_out;
  101738. }
  101739. }
  101740. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101741. if(info->submaps>1){
  101742. for(i=0;i<vi->channels;i++){
  101743. info->chmuxlist[i]=oggpack_read(opb,4);
  101744. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101745. }
  101746. }
  101747. for(i=0;i<info->submaps;i++){
  101748. oggpack_read(opb,8); /* time submap unused */
  101749. info->floorsubmap[i]=oggpack_read(opb,8);
  101750. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101751. info->residuesubmap[i]=oggpack_read(opb,8);
  101752. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101753. }
  101754. return info;
  101755. err_out:
  101756. mapping0_free_info(info);
  101757. return(NULL);
  101758. }
  101759. #if 0
  101760. static long seq=0;
  101761. static ogg_int64_t total=0;
  101762. static float FLOOR1_fromdB_LOOKUP[256]={
  101763. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101764. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101765. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101766. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101767. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101768. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101769. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101770. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101771. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101772. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101773. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101774. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101775. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101776. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101777. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101778. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101779. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101780. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101781. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101782. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101783. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101784. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101785. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101786. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101787. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101788. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101789. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101790. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101791. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101792. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101793. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101794. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101795. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101796. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101797. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101798. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101799. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101800. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101801. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101802. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101803. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101804. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101805. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101806. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101807. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101808. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101809. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101810. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101811. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101812. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101813. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101814. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101815. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101816. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101817. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101818. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101819. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101820. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101821. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101822. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101823. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101824. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101825. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101826. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101827. };
  101828. #endif
  101829. extern int *floor1_fit(vorbis_block *vb,void *look,
  101830. const float *logmdct, /* in */
  101831. const float *logmask);
  101832. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101833. int *A,int *B,
  101834. int del);
  101835. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101836. void*look,
  101837. int *post,int *ilogmask);
  101838. static int mapping0_forward(vorbis_block *vb){
  101839. vorbis_dsp_state *vd=vb->vd;
  101840. vorbis_info *vi=vd->vi;
  101841. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101842. private_state *b=(private_state*)vb->vd->backend_state;
  101843. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101844. int n=vb->pcmend;
  101845. int i,j,k;
  101846. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101847. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101848. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101849. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101850. float global_ampmax=vbi->ampmax;
  101851. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101852. int blocktype=vbi->blocktype;
  101853. int modenumber=vb->W;
  101854. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101855. vorbis_look_psy *psy_look=
  101856. b->psy+blocktype+(vb->W?2:0);
  101857. vb->mode=modenumber;
  101858. for(i=0;i<vi->channels;i++){
  101859. float scale=4.f/n;
  101860. float scale_dB;
  101861. float *pcm =vb->pcm[i];
  101862. float *logfft =pcm;
  101863. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101864. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101865. todB estimation used on IEEE 754
  101866. compliant machines had a bug that
  101867. returned dB values about a third
  101868. of a decibel too high. The bug
  101869. was harmless because tunings
  101870. implicitly took that into
  101871. account. However, fixing the bug
  101872. in the estimator requires
  101873. changing all the tunings as well.
  101874. For now, it's easier to sync
  101875. things back up here, and
  101876. recalibrate the tunings in the
  101877. next major model upgrade. */
  101878. #if 0
  101879. if(vi->channels==2)
  101880. if(i==0)
  101881. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101882. else
  101883. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101884. #endif
  101885. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101886. #if 0
  101887. if(vi->channels==2)
  101888. if(i==0)
  101889. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101890. else
  101891. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101892. #endif
  101893. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101894. drft_forward(&b->fft_look[vb->W],pcm);
  101895. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101896. original todB estimation used on
  101897. IEEE 754 compliant machines had a
  101898. bug that returned dB values about
  101899. a third of a decibel too high.
  101900. The bug was harmless because
  101901. tunings implicitly took that into
  101902. account. However, fixing the bug
  101903. in the estimator requires
  101904. changing all the tunings as well.
  101905. For now, it's easier to sync
  101906. things back up here, and
  101907. recalibrate the tunings in the
  101908. next major model upgrade. */
  101909. local_ampmax[i]=logfft[0];
  101910. for(j=1;j<n-1;j+=2){
  101911. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101912. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101913. .345 is a hack; the original todB
  101914. estimation used on IEEE 754
  101915. compliant machines had a bug that
  101916. returned dB values about a third
  101917. of a decibel too high. The bug
  101918. was harmless because tunings
  101919. implicitly took that into
  101920. account. However, fixing the bug
  101921. in the estimator requires
  101922. changing all the tunings as well.
  101923. For now, it's easier to sync
  101924. things back up here, and
  101925. recalibrate the tunings in the
  101926. next major model upgrade. */
  101927. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101928. }
  101929. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101930. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101931. #if 0
  101932. if(vi->channels==2){
  101933. if(i==0){
  101934. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101935. }else{
  101936. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101937. }
  101938. }
  101939. #endif
  101940. }
  101941. {
  101942. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101943. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101944. for(i=0;i<vi->channels;i++){
  101945. int submap=info->chmuxlist[i];
  101946. float *mdct =gmdct[i];
  101947. float *logfft =vb->pcm[i];
  101948. float *logmdct =logfft+n/2;
  101949. float *logmask =logfft;
  101950. vb->mode=modenumber;
  101951. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101952. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101953. for(j=0;j<n/2;j++)
  101954. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101955. todB estimation used on IEEE 754
  101956. compliant machines had a bug that
  101957. returned dB values about a third
  101958. of a decibel too high. The bug
  101959. was harmless because tunings
  101960. implicitly took that into
  101961. account. However, fixing the bug
  101962. in the estimator requires
  101963. changing all the tunings as well.
  101964. For now, it's easier to sync
  101965. things back up here, and
  101966. recalibrate the tunings in the
  101967. next major model upgrade. */
  101968. #if 0
  101969. if(vi->channels==2){
  101970. if(i==0)
  101971. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101972. else
  101973. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101974. }else{
  101975. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101976. }
  101977. #endif
  101978. _vp_noisemask(psy_look,
  101979. logmdct,
  101980. noise); /* noise does not have by-frequency offset
  101981. bias applied yet */
  101982. #if 0
  101983. if(vi->channels==2){
  101984. if(i==0)
  101985. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101986. else
  101987. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101988. }
  101989. #endif
  101990. _vp_tonemask(psy_look,
  101991. logfft,
  101992. tone,
  101993. global_ampmax,
  101994. local_ampmax[i]);
  101995. #if 0
  101996. if(vi->channels==2){
  101997. if(i==0)
  101998. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101999. else
  102000. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  102001. }
  102002. #endif
  102003. #if 0
  102004. {
  102005. float aotuv[psy_look->n];
  102006. #endif
  102007. _vp_offset_and_mix(psy_look,
  102008. noise,
  102009. tone,
  102010. 1,
  102011. logmask,
  102012. mdct,
  102013. logmdct);
  102014. #if 0
  102015. if(vi->channels==2){
  102016. if(i==0)
  102017. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  102018. else
  102019. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  102020. }
  102021. }
  102022. #endif
  102023. #if 0
  102024. if(vi->channels==2){
  102025. if(i==0)
  102026. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  102027. else
  102028. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  102029. }
  102030. #endif
  102031. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  102032. floor_posts[i][PACKETBLOBS/2]=
  102033. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102034. logmdct,
  102035. logmask);
  102036. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  102037. _vp_offset_and_mix(psy_look,
  102038. noise,
  102039. tone,
  102040. 2,
  102041. logmask,
  102042. mdct,
  102043. logmdct);
  102044. #if 0
  102045. if(vi->channels==2){
  102046. if(i==0)
  102047. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  102048. else
  102049. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  102050. }
  102051. #endif
  102052. floor_posts[i][PACKETBLOBS-1]=
  102053. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102054. logmdct,
  102055. logmask);
  102056. _vp_offset_and_mix(psy_look,
  102057. noise,
  102058. tone,
  102059. 0,
  102060. logmask,
  102061. mdct,
  102062. logmdct);
  102063. #if 0
  102064. if(vi->channels==2)
  102065. if(i==0)
  102066. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  102067. else
  102068. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  102069. #endif
  102070. floor_posts[i][0]=
  102071. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102072. logmdct,
  102073. logmask);
  102074. for(k=1;k<PACKETBLOBS/2;k++)
  102075. floor_posts[i][k]=
  102076. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102077. floor_posts[i][0],
  102078. floor_posts[i][PACKETBLOBS/2],
  102079. k*65536/(PACKETBLOBS/2));
  102080. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  102081. floor_posts[i][k]=
  102082. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102083. floor_posts[i][PACKETBLOBS/2],
  102084. floor_posts[i][PACKETBLOBS-1],
  102085. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  102086. }
  102087. }
  102088. }
  102089. vbi->ampmax=global_ampmax;
  102090. {
  102091. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  102092. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  102093. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102094. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  102095. float **mag_memo;
  102096. int **mag_sort;
  102097. if(info->coupling_steps){
  102098. mag_memo=_vp_quantize_couple_memo(vb,
  102099. &ci->psy_g_param,
  102100. psy_look,
  102101. info,
  102102. gmdct);
  102103. mag_sort=_vp_quantize_couple_sort(vb,
  102104. psy_look,
  102105. info,
  102106. mag_memo);
  102107. hf_reduction(&ci->psy_g_param,
  102108. psy_look,
  102109. info,
  102110. mag_memo);
  102111. }
  102112. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102113. if(psy_look->vi->normal_channel_p){
  102114. for(i=0;i<vi->channels;i++){
  102115. float *mdct =gmdct[i];
  102116. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102117. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102118. }
  102119. }
  102120. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102121. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102122. k++){
  102123. oggpack_buffer *opb=vbi->packetblob[k];
  102124. oggpack_write(opb,0,1);
  102125. oggpack_write(opb,modenumber,b->modebits);
  102126. if(vb->W){
  102127. oggpack_write(opb,vb->lW,1);
  102128. oggpack_write(opb,vb->nW,1);
  102129. }
  102130. for(i=0;i<vi->channels;i++){
  102131. int submap=info->chmuxlist[i];
  102132. float *mdct =gmdct[i];
  102133. float *res =vb->pcm[i];
  102134. int *ilogmask=ilogmaskch[i]=
  102135. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102136. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102137. floor_posts[i][k],
  102138. ilogmask);
  102139. #if 0
  102140. {
  102141. char buf[80];
  102142. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102143. float work[n/2];
  102144. for(j=0;j<n/2;j++)
  102145. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102146. _analysis_output(buf,seq,work,n/2,1,1,0);
  102147. }
  102148. #endif
  102149. _vp_remove_floor(psy_look,
  102150. mdct,
  102151. ilogmask,
  102152. res,
  102153. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102154. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102155. #if 0
  102156. {
  102157. char buf[80];
  102158. float work[n/2];
  102159. for(j=0;j<n/2;j++)
  102160. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102161. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102162. _analysis_output(buf,seq,work,n/2,1,1,0);
  102163. }
  102164. #endif
  102165. }
  102166. if(info->coupling_steps){
  102167. _vp_couple(k,
  102168. &ci->psy_g_param,
  102169. psy_look,
  102170. info,
  102171. vb->pcm,
  102172. mag_memo,
  102173. mag_sort,
  102174. ilogmaskch,
  102175. nonzero,
  102176. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102177. }
  102178. for(i=0;i<info->submaps;i++){
  102179. int ch_in_bundle=0;
  102180. long **classifications;
  102181. int resnum=info->residuesubmap[i];
  102182. for(j=0;j<vi->channels;j++){
  102183. if(info->chmuxlist[j]==i){
  102184. zerobundle[ch_in_bundle]=0;
  102185. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102186. res_bundle[ch_in_bundle]=vb->pcm[j];
  102187. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102188. }
  102189. }
  102190. classifications=_residue_P[ci->residue_type[resnum]]->
  102191. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102192. _residue_P[ci->residue_type[resnum]]->
  102193. forward(opb,vb,b->residue[resnum],
  102194. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102195. }
  102196. }
  102197. }
  102198. #if 0
  102199. seq++;
  102200. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102201. #endif
  102202. return(0);
  102203. }
  102204. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102205. vorbis_dsp_state *vd=vb->vd;
  102206. vorbis_info *vi=vd->vi;
  102207. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102208. private_state *b=(private_state*)vd->backend_state;
  102209. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102210. int i,j;
  102211. long n=vb->pcmend=ci->blocksizes[vb->W];
  102212. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102213. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102214. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102215. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102216. for(i=0;i<vi->channels;i++){
  102217. int submap=info->chmuxlist[i];
  102218. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102219. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102220. if(floormemo[i])
  102221. nonzero[i]=1;
  102222. else
  102223. nonzero[i]=0;
  102224. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102225. }
  102226. for(i=0;i<info->coupling_steps;i++){
  102227. if(nonzero[info->coupling_mag[i]] ||
  102228. nonzero[info->coupling_ang[i]]){
  102229. nonzero[info->coupling_mag[i]]=1;
  102230. nonzero[info->coupling_ang[i]]=1;
  102231. }
  102232. }
  102233. for(i=0;i<info->submaps;i++){
  102234. int ch_in_bundle=0;
  102235. for(j=0;j<vi->channels;j++){
  102236. if(info->chmuxlist[j]==i){
  102237. if(nonzero[j])
  102238. zerobundle[ch_in_bundle]=1;
  102239. else
  102240. zerobundle[ch_in_bundle]=0;
  102241. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102242. }
  102243. }
  102244. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102245. inverse(vb,b->residue[info->residuesubmap[i]],
  102246. pcmbundle,zerobundle,ch_in_bundle);
  102247. }
  102248. for(i=info->coupling_steps-1;i>=0;i--){
  102249. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102250. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102251. for(j=0;j<n/2;j++){
  102252. float mag=pcmM[j];
  102253. float ang=pcmA[j];
  102254. if(mag>0)
  102255. if(ang>0){
  102256. pcmM[j]=mag;
  102257. pcmA[j]=mag-ang;
  102258. }else{
  102259. pcmA[j]=mag;
  102260. pcmM[j]=mag+ang;
  102261. }
  102262. else
  102263. if(ang>0){
  102264. pcmM[j]=mag;
  102265. pcmA[j]=mag+ang;
  102266. }else{
  102267. pcmA[j]=mag;
  102268. pcmM[j]=mag-ang;
  102269. }
  102270. }
  102271. }
  102272. for(i=0;i<vi->channels;i++){
  102273. float *pcm=vb->pcm[i];
  102274. int submap=info->chmuxlist[i];
  102275. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102276. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102277. floormemo[i],pcm);
  102278. }
  102279. for(i=0;i<vi->channels;i++){
  102280. float *pcm=vb->pcm[i];
  102281. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102282. }
  102283. return(0);
  102284. }
  102285. vorbis_func_mapping mapping0_exportbundle={
  102286. &mapping0_pack,
  102287. &mapping0_unpack,
  102288. &mapping0_free_info,
  102289. &mapping0_forward,
  102290. &mapping0_inverse
  102291. };
  102292. #endif
  102293. /*** End of inlined file: mapping0.c ***/
  102294. /*** Start of inlined file: mdct.c ***/
  102295. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102296. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102297. // tasks..
  102298. #if JUCE_MSVC
  102299. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102300. #endif
  102301. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102302. #if JUCE_USE_OGGVORBIS
  102303. #include <stdio.h>
  102304. #include <stdlib.h>
  102305. #include <string.h>
  102306. #include <math.h>
  102307. void mdct_init(mdct_lookup *lookup,int n){
  102308. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102309. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102310. int i;
  102311. int n2=n>>1;
  102312. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102313. lookup->n=n;
  102314. lookup->trig=T;
  102315. lookup->bitrev=bitrev;
  102316. for(i=0;i<n/4;i++){
  102317. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102318. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102319. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102320. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102321. }
  102322. for(i=0;i<n/8;i++){
  102323. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102324. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102325. }
  102326. {
  102327. int mask=(1<<(log2n-1))-1,i,j;
  102328. int msb=1<<(log2n-2);
  102329. for(i=0;i<n/8;i++){
  102330. int acc=0;
  102331. for(j=0;msb>>j;j++)
  102332. if((msb>>j)&i)acc|=1<<j;
  102333. bitrev[i*2]=((~acc)&mask)-1;
  102334. bitrev[i*2+1]=acc;
  102335. }
  102336. }
  102337. lookup->scale=FLOAT_CONV(4.f/n);
  102338. }
  102339. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102340. REG_TYPE r0 = x[6] + x[2];
  102341. REG_TYPE r1 = x[6] - x[2];
  102342. REG_TYPE r2 = x[4] + x[0];
  102343. REG_TYPE r3 = x[4] - x[0];
  102344. x[6] = r0 + r2;
  102345. x[4] = r0 - r2;
  102346. r0 = x[5] - x[1];
  102347. r2 = x[7] - x[3];
  102348. x[0] = r1 + r0;
  102349. x[2] = r1 - r0;
  102350. r0 = x[5] + x[1];
  102351. r1 = x[7] + x[3];
  102352. x[3] = r2 + r3;
  102353. x[1] = r2 - r3;
  102354. x[7] = r1 + r0;
  102355. x[5] = r1 - r0;
  102356. }
  102357. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102358. REG_TYPE r0 = x[1] - x[9];
  102359. REG_TYPE r1 = x[0] - x[8];
  102360. x[8] += x[0];
  102361. x[9] += x[1];
  102362. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102363. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102364. r0 = x[3] - x[11];
  102365. r1 = x[10] - x[2];
  102366. x[10] += x[2];
  102367. x[11] += x[3];
  102368. x[2] = r0;
  102369. x[3] = r1;
  102370. r0 = x[12] - x[4];
  102371. r1 = x[13] - x[5];
  102372. x[12] += x[4];
  102373. x[13] += x[5];
  102374. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102375. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102376. r0 = x[14] - x[6];
  102377. r1 = x[15] - x[7];
  102378. x[14] += x[6];
  102379. x[15] += x[7];
  102380. x[6] = r0;
  102381. x[7] = r1;
  102382. mdct_butterfly_8(x);
  102383. mdct_butterfly_8(x+8);
  102384. }
  102385. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102386. REG_TYPE r0 = x[30] - x[14];
  102387. REG_TYPE r1 = x[31] - x[15];
  102388. x[30] += x[14];
  102389. x[31] += x[15];
  102390. x[14] = r0;
  102391. x[15] = r1;
  102392. r0 = x[28] - x[12];
  102393. r1 = x[29] - x[13];
  102394. x[28] += x[12];
  102395. x[29] += x[13];
  102396. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102397. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102398. r0 = x[26] - x[10];
  102399. r1 = x[27] - x[11];
  102400. x[26] += x[10];
  102401. x[27] += x[11];
  102402. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102403. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102404. r0 = x[24] - x[8];
  102405. r1 = x[25] - x[9];
  102406. x[24] += x[8];
  102407. x[25] += x[9];
  102408. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102409. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102410. r0 = x[22] - x[6];
  102411. r1 = x[7] - x[23];
  102412. x[22] += x[6];
  102413. x[23] += x[7];
  102414. x[6] = r1;
  102415. x[7] = r0;
  102416. r0 = x[4] - x[20];
  102417. r1 = x[5] - x[21];
  102418. x[20] += x[4];
  102419. x[21] += x[5];
  102420. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102421. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102422. r0 = x[2] - x[18];
  102423. r1 = x[3] - x[19];
  102424. x[18] += x[2];
  102425. x[19] += x[3];
  102426. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102427. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102428. r0 = x[0] - x[16];
  102429. r1 = x[1] - x[17];
  102430. x[16] += x[0];
  102431. x[17] += x[1];
  102432. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102433. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102434. mdct_butterfly_16(x);
  102435. mdct_butterfly_16(x+16);
  102436. }
  102437. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102438. DATA_TYPE *x,
  102439. int points){
  102440. DATA_TYPE *x1 = x + points - 8;
  102441. DATA_TYPE *x2 = x + (points>>1) - 8;
  102442. REG_TYPE r0;
  102443. REG_TYPE r1;
  102444. do{
  102445. r0 = x1[6] - x2[6];
  102446. r1 = x1[7] - x2[7];
  102447. x1[6] += x2[6];
  102448. x1[7] += x2[7];
  102449. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102450. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102451. r0 = x1[4] - x2[4];
  102452. r1 = x1[5] - x2[5];
  102453. x1[4] += x2[4];
  102454. x1[5] += x2[5];
  102455. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102456. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102457. r0 = x1[2] - x2[2];
  102458. r1 = x1[3] - x2[3];
  102459. x1[2] += x2[2];
  102460. x1[3] += x2[3];
  102461. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102462. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102463. r0 = x1[0] - x2[0];
  102464. r1 = x1[1] - x2[1];
  102465. x1[0] += x2[0];
  102466. x1[1] += x2[1];
  102467. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102468. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102469. x1-=8;
  102470. x2-=8;
  102471. T+=16;
  102472. }while(x2>=x);
  102473. }
  102474. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102475. DATA_TYPE *x,
  102476. int points,
  102477. int trigint){
  102478. DATA_TYPE *x1 = x + points - 8;
  102479. DATA_TYPE *x2 = x + (points>>1) - 8;
  102480. REG_TYPE r0;
  102481. REG_TYPE r1;
  102482. do{
  102483. r0 = x1[6] - x2[6];
  102484. r1 = x1[7] - x2[7];
  102485. x1[6] += x2[6];
  102486. x1[7] += x2[7];
  102487. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102488. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102489. T+=trigint;
  102490. r0 = x1[4] - x2[4];
  102491. r1 = x1[5] - x2[5];
  102492. x1[4] += x2[4];
  102493. x1[5] += x2[5];
  102494. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102495. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102496. T+=trigint;
  102497. r0 = x1[2] - x2[2];
  102498. r1 = x1[3] - x2[3];
  102499. x1[2] += x2[2];
  102500. x1[3] += x2[3];
  102501. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102502. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102503. T+=trigint;
  102504. r0 = x1[0] - x2[0];
  102505. r1 = x1[1] - x2[1];
  102506. x1[0] += x2[0];
  102507. x1[1] += x2[1];
  102508. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102509. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102510. T+=trigint;
  102511. x1-=8;
  102512. x2-=8;
  102513. }while(x2>=x);
  102514. }
  102515. STIN void mdct_butterflies(mdct_lookup *init,
  102516. DATA_TYPE *x,
  102517. int points){
  102518. DATA_TYPE *T=init->trig;
  102519. int stages=init->log2n-5;
  102520. int i,j;
  102521. if(--stages>0){
  102522. mdct_butterfly_first(T,x,points);
  102523. }
  102524. for(i=1;--stages>0;i++){
  102525. for(j=0;j<(1<<i);j++)
  102526. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102527. }
  102528. for(j=0;j<points;j+=32)
  102529. mdct_butterfly_32(x+j);
  102530. }
  102531. void mdct_clear(mdct_lookup *l){
  102532. if(l){
  102533. if(l->trig)_ogg_free(l->trig);
  102534. if(l->bitrev)_ogg_free(l->bitrev);
  102535. memset(l,0,sizeof(*l));
  102536. }
  102537. }
  102538. STIN void mdct_bitreverse(mdct_lookup *init,
  102539. DATA_TYPE *x){
  102540. int n = init->n;
  102541. int *bit = init->bitrev;
  102542. DATA_TYPE *w0 = x;
  102543. DATA_TYPE *w1 = x = w0+(n>>1);
  102544. DATA_TYPE *T = init->trig+n;
  102545. do{
  102546. DATA_TYPE *x0 = x+bit[0];
  102547. DATA_TYPE *x1 = x+bit[1];
  102548. REG_TYPE r0 = x0[1] - x1[1];
  102549. REG_TYPE r1 = x0[0] + x1[0];
  102550. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102551. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102552. w1 -= 4;
  102553. r0 = HALVE(x0[1] + x1[1]);
  102554. r1 = HALVE(x0[0] - x1[0]);
  102555. w0[0] = r0 + r2;
  102556. w1[2] = r0 - r2;
  102557. w0[1] = r1 + r3;
  102558. w1[3] = r3 - r1;
  102559. x0 = x+bit[2];
  102560. x1 = x+bit[3];
  102561. r0 = x0[1] - x1[1];
  102562. r1 = x0[0] + x1[0];
  102563. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102564. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102565. r0 = HALVE(x0[1] + x1[1]);
  102566. r1 = HALVE(x0[0] - x1[0]);
  102567. w0[2] = r0 + r2;
  102568. w1[0] = r0 - r2;
  102569. w0[3] = r1 + r3;
  102570. w1[1] = r3 - r1;
  102571. T += 4;
  102572. bit += 4;
  102573. w0 += 4;
  102574. }while(w0<w1);
  102575. }
  102576. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102577. int n=init->n;
  102578. int n2=n>>1;
  102579. int n4=n>>2;
  102580. DATA_TYPE *iX = in+n2-7;
  102581. DATA_TYPE *oX = out+n2+n4;
  102582. DATA_TYPE *T = init->trig+n4;
  102583. do{
  102584. oX -= 4;
  102585. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102586. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102587. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102588. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102589. iX -= 8;
  102590. T += 4;
  102591. }while(iX>=in);
  102592. iX = in+n2-8;
  102593. oX = out+n2+n4;
  102594. T = init->trig+n4;
  102595. do{
  102596. T -= 4;
  102597. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102598. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102599. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102600. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102601. iX -= 8;
  102602. oX += 4;
  102603. }while(iX>=in);
  102604. mdct_butterflies(init,out+n2,n2);
  102605. mdct_bitreverse(init,out);
  102606. {
  102607. DATA_TYPE *oX1=out+n2+n4;
  102608. DATA_TYPE *oX2=out+n2+n4;
  102609. DATA_TYPE *iX =out;
  102610. T =init->trig+n2;
  102611. do{
  102612. oX1-=4;
  102613. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102614. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102615. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102616. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102617. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102618. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102619. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102620. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102621. oX2+=4;
  102622. iX += 8;
  102623. T += 8;
  102624. }while(iX<oX1);
  102625. iX=out+n2+n4;
  102626. oX1=out+n4;
  102627. oX2=oX1;
  102628. do{
  102629. oX1-=4;
  102630. iX-=4;
  102631. oX2[0] = -(oX1[3] = iX[3]);
  102632. oX2[1] = -(oX1[2] = iX[2]);
  102633. oX2[2] = -(oX1[1] = iX[1]);
  102634. oX2[3] = -(oX1[0] = iX[0]);
  102635. oX2+=4;
  102636. }while(oX2<iX);
  102637. iX=out+n2+n4;
  102638. oX1=out+n2+n4;
  102639. oX2=out+n2;
  102640. do{
  102641. oX1-=4;
  102642. oX1[0]= iX[3];
  102643. oX1[1]= iX[2];
  102644. oX1[2]= iX[1];
  102645. oX1[3]= iX[0];
  102646. iX+=4;
  102647. }while(oX1>oX2);
  102648. }
  102649. }
  102650. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102651. int n=init->n;
  102652. int n2=n>>1;
  102653. int n4=n>>2;
  102654. int n8=n>>3;
  102655. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102656. DATA_TYPE *w2=w+n2;
  102657. REG_TYPE r0;
  102658. REG_TYPE r1;
  102659. DATA_TYPE *x0=in+n2+n4;
  102660. DATA_TYPE *x1=x0+1;
  102661. DATA_TYPE *T=init->trig+n2;
  102662. int i=0;
  102663. for(i=0;i<n8;i+=2){
  102664. x0 -=4;
  102665. T-=2;
  102666. r0= x0[2] + x1[0];
  102667. r1= x0[0] + x1[2];
  102668. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102669. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102670. x1 +=4;
  102671. }
  102672. x1=in+1;
  102673. for(;i<n2-n8;i+=2){
  102674. T-=2;
  102675. x0 -=4;
  102676. r0= x0[2] - x1[0];
  102677. r1= x0[0] - x1[2];
  102678. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102679. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102680. x1 +=4;
  102681. }
  102682. x0=in+n;
  102683. for(;i<n2;i+=2){
  102684. T-=2;
  102685. x0 -=4;
  102686. r0= -x0[2] - x1[0];
  102687. r1= -x0[0] - x1[2];
  102688. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102689. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102690. x1 +=4;
  102691. }
  102692. mdct_butterflies(init,w+n2,n2);
  102693. mdct_bitreverse(init,w);
  102694. T=init->trig+n2;
  102695. x0=out+n2;
  102696. for(i=0;i<n4;i++){
  102697. x0--;
  102698. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102699. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102700. w+=2;
  102701. T+=2;
  102702. }
  102703. }
  102704. #endif
  102705. /*** End of inlined file: mdct.c ***/
  102706. /*** Start of inlined file: psy.c ***/
  102707. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102708. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102709. // tasks..
  102710. #if JUCE_MSVC
  102711. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102712. #endif
  102713. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102714. #if JUCE_USE_OGGVORBIS
  102715. #include <stdlib.h>
  102716. #include <math.h>
  102717. #include <string.h>
  102718. /*** Start of inlined file: masking.h ***/
  102719. #ifndef _V_MASKING_H_
  102720. #define _V_MASKING_H_
  102721. #define MAX_ATH 88
  102722. static float ATH[]={
  102723. -51, -52, -53, -54, -55, -56, -57, -58,
  102724. -59, -60, -61, -62, -63, -64, -65, -66,
  102725. -67, -68, -69, -70, -71, -72, -73, -74,
  102726. -75, -76, -77, -78, -80, -81, -82, -83,
  102727. -84, -85, -86, -87, -88, -88, -89, -89,
  102728. -90, -91, -91, -92, -93, -94, -95, -96,
  102729. -96, -97, -98, -98, -99, -99,-100,-100,
  102730. -101,-102,-103,-104,-106,-107,-107,-107,
  102731. -107,-105,-103,-102,-101, -99, -98, -96,
  102732. -95, -95, -96, -97, -96, -95, -93, -90,
  102733. -80, -70, -50, -40, -30, -30, -30, -30
  102734. };
  102735. #define EHMER_OFFSET 16
  102736. #define EHMER_MAX 56
  102737. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102738. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102739. -60, -60, -60, -60, -62, -62, -65, -73,
  102740. -69, -68, -68, -67, -70, -70, -72, -74,
  102741. -75, -79, -79, -80, -83, -88, -93, -100,
  102742. -110, -999, -999, -999, -999, -999, -999, -999,
  102743. -999, -999, -999, -999, -999, -999, -999, -999,
  102744. -999, -999, -999, -999, -999, -999, -999, -999},
  102745. { -48, -48, -48, -48, -48, -48, -48, -48,
  102746. -48, -48, -48, -48, -48, -53, -61, -66,
  102747. -66, -68, -67, -70, -76, -76, -72, -73,
  102748. -75, -76, -78, -79, -83, -88, -93, -100,
  102749. -110, -999, -999, -999, -999, -999, -999, -999,
  102750. -999, -999, -999, -999, -999, -999, -999, -999,
  102751. -999, -999, -999, -999, -999, -999, -999, -999},
  102752. { -37, -37, -37, -37, -37, -37, -37, -37,
  102753. -38, -40, -42, -46, -48, -53, -55, -62,
  102754. -65, -58, -56, -56, -61, -60, -65, -67,
  102755. -69, -71, -77, -77, -78, -80, -82, -84,
  102756. -88, -93, -98, -106, -112, -999, -999, -999,
  102757. -999, -999, -999, -999, -999, -999, -999, -999,
  102758. -999, -999, -999, -999, -999, -999, -999, -999},
  102759. { -25, -25, -25, -25, -25, -25, -25, -25,
  102760. -25, -26, -27, -29, -32, -38, -48, -52,
  102761. -52, -50, -48, -48, -51, -52, -54, -60,
  102762. -67, -67, -66, -68, -69, -73, -73, -76,
  102763. -80, -81, -81, -85, -85, -86, -88, -93,
  102764. -100, -110, -999, -999, -999, -999, -999, -999,
  102765. -999, -999, -999, -999, -999, -999, -999, -999},
  102766. { -16, -16, -16, -16, -16, -16, -16, -16,
  102767. -17, -19, -20, -22, -26, -28, -31, -40,
  102768. -47, -39, -39, -40, -42, -43, -47, -51,
  102769. -57, -52, -55, -55, -60, -58, -62, -63,
  102770. -70, -67, -69, -72, -73, -77, -80, -82,
  102771. -83, -87, -90, -94, -98, -104, -115, -999,
  102772. -999, -999, -999, -999, -999, -999, -999, -999},
  102773. { -8, -8, -8, -8, -8, -8, -8, -8,
  102774. -8, -8, -10, -11, -15, -19, -25, -30,
  102775. -34, -31, -30, -31, -29, -32, -35, -42,
  102776. -48, -42, -44, -46, -50, -50, -51, -52,
  102777. -59, -54, -55, -55, -58, -62, -63, -66,
  102778. -72, -73, -76, -75, -78, -80, -80, -81,
  102779. -84, -88, -90, -94, -98, -101, -106, -110}},
  102780. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102781. -66, -66, -66, -66, -66, -67, -67, -67,
  102782. -76, -72, -71, -74, -76, -76, -75, -78,
  102783. -79, -79, -81, -83, -86, -89, -93, -97,
  102784. -100, -105, -110, -999, -999, -999, -999, -999,
  102785. -999, -999, -999, -999, -999, -999, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999},
  102787. { -47, -47, -47, -47, -47, -47, -47, -47,
  102788. -47, -47, -47, -48, -51, -55, -59, -66,
  102789. -66, -66, -67, -66, -68, -69, -70, -74,
  102790. -79, -77, -77, -78, -80, -81, -82, -84,
  102791. -86, -88, -91, -95, -100, -108, -116, -999,
  102792. -999, -999, -999, -999, -999, -999, -999, -999,
  102793. -999, -999, -999, -999, -999, -999, -999, -999},
  102794. { -36, -36, -36, -36, -36, -36, -36, -36,
  102795. -36, -37, -37, -41, -44, -48, -51, -58,
  102796. -62, -60, -57, -59, -59, -60, -63, -65,
  102797. -72, -71, -70, -72, -74, -77, -76, -78,
  102798. -81, -81, -80, -83, -86, -91, -96, -100,
  102799. -105, -110, -999, -999, -999, -999, -999, -999,
  102800. -999, -999, -999, -999, -999, -999, -999, -999},
  102801. { -28, -28, -28, -28, -28, -28, -28, -28,
  102802. -28, -30, -32, -32, -33, -35, -41, -49,
  102803. -50, -49, -47, -48, -48, -52, -51, -57,
  102804. -65, -61, -59, -61, -64, -69, -70, -74,
  102805. -77, -77, -78, -81, -84, -85, -87, -90,
  102806. -92, -96, -100, -107, -112, -999, -999, -999,
  102807. -999, -999, -999, -999, -999, -999, -999, -999},
  102808. { -19, -19, -19, -19, -19, -19, -19, -19,
  102809. -20, -21, -23, -27, -30, -35, -36, -41,
  102810. -46, -44, -42, -40, -41, -41, -43, -48,
  102811. -55, -53, -52, -53, -56, -59, -58, -60,
  102812. -67, -66, -69, -71, -72, -75, -79, -81,
  102813. -84, -87, -90, -93, -97, -101, -107, -114,
  102814. -999, -999, -999, -999, -999, -999, -999, -999},
  102815. { -9, -9, -9, -9, -9, -9, -9, -9,
  102816. -11, -12, -12, -15, -16, -20, -23, -30,
  102817. -37, -34, -33, -34, -31, -32, -32, -38,
  102818. -47, -44, -41, -40, -47, -49, -46, -46,
  102819. -58, -50, -50, -54, -58, -62, -64, -67,
  102820. -67, -70, -72, -76, -79, -83, -87, -91,
  102821. -96, -100, -104, -110, -999, -999, -999, -999}},
  102822. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102823. -62, -62, -63, -64, -66, -67, -66, -68,
  102824. -75, -72, -76, -75, -76, -78, -79, -82,
  102825. -84, -85, -90, -94, -101, -110, -999, -999,
  102826. -999, -999, -999, -999, -999, -999, -999, -999,
  102827. -999, -999, -999, -999, -999, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999},
  102829. { -59, -59, -59, -59, -59, -59, -59, -59,
  102830. -59, -59, -59, -60, -60, -61, -63, -66,
  102831. -71, -68, -70, -70, -71, -72, -72, -75,
  102832. -81, -78, -79, -82, -83, -86, -90, -97,
  102833. -103, -113, -999, -999, -999, -999, -999, -999,
  102834. -999, -999, -999, -999, -999, -999, -999, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999},
  102836. { -53, -53, -53, -53, -53, -53, -53, -53,
  102837. -53, -54, -55, -57, -56, -57, -55, -61,
  102838. -65, -60, -60, -62, -63, -63, -66, -68,
  102839. -74, -73, -75, -75, -78, -80, -80, -82,
  102840. -85, -90, -96, -101, -108, -999, -999, -999,
  102841. -999, -999, -999, -999, -999, -999, -999, -999,
  102842. -999, -999, -999, -999, -999, -999, -999, -999},
  102843. { -46, -46, -46, -46, -46, -46, -46, -46,
  102844. -46, -46, -47, -47, -47, -47, -48, -51,
  102845. -57, -51, -49, -50, -51, -53, -54, -59,
  102846. -66, -60, -62, -67, -67, -70, -72, -75,
  102847. -76, -78, -81, -85, -88, -94, -97, -104,
  102848. -112, -999, -999, -999, -999, -999, -999, -999,
  102849. -999, -999, -999, -999, -999, -999, -999, -999},
  102850. { -36, -36, -36, -36, -36, -36, -36, -36,
  102851. -39, -41, -42, -42, -39, -38, -41, -43,
  102852. -52, -44, -40, -39, -37, -37, -40, -47,
  102853. -54, -50, -48, -50, -55, -61, -59, -62,
  102854. -66, -66, -66, -69, -69, -73, -74, -74,
  102855. -75, -77, -79, -82, -87, -91, -95, -100,
  102856. -108, -115, -999, -999, -999, -999, -999, -999},
  102857. { -28, -26, -24, -22, -20, -20, -23, -29,
  102858. -30, -31, -28, -27, -28, -28, -28, -35,
  102859. -40, -33, -32, -29, -30, -30, -30, -37,
  102860. -45, -41, -37, -38, -45, -47, -47, -48,
  102861. -53, -49, -48, -50, -49, -49, -51, -52,
  102862. -58, -56, -57, -56, -60, -61, -62, -70,
  102863. -72, -74, -78, -83, -88, -93, -100, -106}},
  102864. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102865. -999, -110, -105, -100, -95, -91, -87, -83,
  102866. -80, -78, -76, -78, -78, -81, -83, -85,
  102867. -86, -85, -86, -87, -90, -97, -107, -999,
  102868. -999, -999, -999, -999, -999, -999, -999, -999,
  102869. -999, -999, -999, -999, -999, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999},
  102871. {-999, -999, -999, -110, -105, -100, -95, -90,
  102872. -85, -81, -77, -73, -70, -67, -67, -68,
  102873. -75, -73, -70, -69, -70, -72, -75, -79,
  102874. -84, -83, -84, -86, -88, -89, -89, -93,
  102875. -98, -105, -112, -999, -999, -999, -999, -999,
  102876. -999, -999, -999, -999, -999, -999, -999, -999,
  102877. -999, -999, -999, -999, -999, -999, -999, -999},
  102878. {-105, -100, -95, -90, -85, -80, -76, -71,
  102879. -68, -68, -65, -63, -63, -62, -62, -64,
  102880. -65, -64, -61, -62, -63, -64, -66, -68,
  102881. -73, -73, -74, -75, -76, -81, -83, -85,
  102882. -88, -89, -92, -95, -100, -108, -999, -999,
  102883. -999, -999, -999, -999, -999, -999, -999, -999,
  102884. -999, -999, -999, -999, -999, -999, -999, -999},
  102885. { -80, -75, -71, -68, -65, -63, -62, -61,
  102886. -61, -61, -61, -59, -56, -57, -53, -50,
  102887. -58, -52, -50, -50, -52, -53, -54, -58,
  102888. -67, -63, -67, -68, -72, -75, -78, -80,
  102889. -81, -81, -82, -85, -89, -90, -93, -97,
  102890. -101, -107, -114, -999, -999, -999, -999, -999,
  102891. -999, -999, -999, -999, -999, -999, -999, -999},
  102892. { -65, -61, -59, -57, -56, -55, -55, -56,
  102893. -56, -57, -55, -53, -52, -47, -44, -44,
  102894. -50, -44, -41, -39, -39, -42, -40, -46,
  102895. -51, -49, -50, -53, -54, -63, -60, -61,
  102896. -62, -66, -66, -66, -70, -73, -74, -75,
  102897. -76, -75, -79, -85, -89, -91, -96, -102,
  102898. -110, -999, -999, -999, -999, -999, -999, -999},
  102899. { -52, -50, -49, -49, -48, -48, -48, -49,
  102900. -50, -50, -49, -46, -43, -39, -35, -33,
  102901. -38, -36, -32, -29, -32, -32, -32, -35,
  102902. -44, -39, -38, -38, -46, -50, -45, -46,
  102903. -53, -50, -50, -50, -54, -54, -53, -53,
  102904. -56, -57, -59, -66, -70, -72, -74, -79,
  102905. -83, -85, -90, -97, -114, -999, -999, -999}},
  102906. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102907. -100, -95, -90, -86, -80, -75, -75, -79,
  102908. -80, -79, -80, -81, -82, -88, -95, -103,
  102909. -110, -999, -999, -999, -999, -999, -999, -999,
  102910. -999, -999, -999, -999, -999, -999, -999, -999,
  102911. -999, -999, -999, -999, -999, -999, -999, -999,
  102912. -999, -999, -999, -999, -999, -999, -999, -999},
  102913. {-999, -999, -999, -999, -108, -103, -98, -93,
  102914. -88, -83, -79, -78, -75, -71, -67, -68,
  102915. -73, -73, -72, -73, -75, -77, -80, -82,
  102916. -88, -93, -100, -107, -114, -999, -999, -999,
  102917. -999, -999, -999, -999, -999, -999, -999, -999,
  102918. -999, -999, -999, -999, -999, -999, -999, -999,
  102919. -999, -999, -999, -999, -999, -999, -999, -999},
  102920. {-999, -999, -999, -110, -105, -101, -96, -90,
  102921. -86, -81, -77, -73, -69, -66, -61, -62,
  102922. -66, -64, -62, -65, -66, -70, -72, -76,
  102923. -81, -80, -84, -90, -95, -102, -110, -999,
  102924. -999, -999, -999, -999, -999, -999, -999, -999,
  102925. -999, -999, -999, -999, -999, -999, -999, -999,
  102926. -999, -999, -999, -999, -999, -999, -999, -999},
  102927. {-999, -999, -999, -107, -103, -97, -92, -88,
  102928. -83, -79, -74, -70, -66, -59, -53, -58,
  102929. -62, -55, -54, -54, -54, -58, -61, -62,
  102930. -72, -70, -72, -75, -78, -80, -81, -80,
  102931. -83, -83, -88, -93, -100, -107, -115, -999,
  102932. -999, -999, -999, -999, -999, -999, -999, -999,
  102933. -999, -999, -999, -999, -999, -999, -999, -999},
  102934. {-999, -999, -999, -105, -100, -95, -90, -85,
  102935. -80, -75, -70, -66, -62, -56, -48, -44,
  102936. -48, -46, -46, -43, -46, -48, -48, -51,
  102937. -58, -58, -59, -60, -62, -62, -61, -61,
  102938. -65, -64, -65, -68, -70, -74, -75, -78,
  102939. -81, -86, -95, -110, -999, -999, -999, -999,
  102940. -999, -999, -999, -999, -999, -999, -999, -999},
  102941. {-999, -999, -105, -100, -95, -90, -85, -80,
  102942. -75, -70, -65, -61, -55, -49, -39, -33,
  102943. -40, -35, -32, -38, -40, -33, -35, -37,
  102944. -46, -41, -45, -44, -46, -42, -45, -46,
  102945. -52, -50, -50, -50, -54, -54, -55, -57,
  102946. -62, -64, -66, -68, -70, -76, -81, -90,
  102947. -100, -110, -999, -999, -999, -999, -999, -999}},
  102948. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102949. -105, -98, -90, -85, -82, -83, -80, -78,
  102950. -84, -79, -80, -83, -87, -89, -91, -93,
  102951. -99, -106, -117, -999, -999, -999, -999, -999,
  102952. -999, -999, -999, -999, -999, -999, -999, -999,
  102953. -999, -999, -999, -999, -999, -999, -999, -999,
  102954. -999, -999, -999, -999, -999, -999, -999, -999},
  102955. {-999, -999, -999, -999, -999, -999, -999, -999,
  102956. -105, -98, -90, -85, -80, -75, -70, -68,
  102957. -74, -72, -74, -77, -80, -82, -85, -87,
  102958. -92, -89, -91, -95, -100, -106, -112, -999,
  102959. -999, -999, -999, -999, -999, -999, -999, -999,
  102960. -999, -999, -999, -999, -999, -999, -999, -999,
  102961. -999, -999, -999, -999, -999, -999, -999, -999},
  102962. {-999, -999, -999, -999, -999, -999, -999, -999,
  102963. -105, -98, -90, -83, -75, -71, -63, -64,
  102964. -67, -62, -64, -67, -70, -73, -77, -81,
  102965. -84, -83, -85, -89, -90, -93, -98, -104,
  102966. -109, -114, -999, -999, -999, -999, -999, -999,
  102967. -999, -999, -999, -999, -999, -999, -999, -999,
  102968. -999, -999, -999, -999, -999, -999, -999, -999},
  102969. {-999, -999, -999, -999, -999, -999, -999, -999,
  102970. -103, -96, -88, -81, -75, -68, -58, -54,
  102971. -56, -54, -56, -56, -58, -60, -63, -66,
  102972. -74, -69, -72, -72, -75, -74, -77, -81,
  102973. -81, -82, -84, -87, -93, -96, -99, -104,
  102974. -110, -999, -999, -999, -999, -999, -999, -999,
  102975. -999, -999, -999, -999, -999, -999, -999, -999},
  102976. {-999, -999, -999, -999, -999, -108, -102, -96,
  102977. -91, -85, -80, -74, -68, -60, -51, -46,
  102978. -48, -46, -43, -45, -47, -47, -49, -48,
  102979. -56, -53, -55, -58, -57, -63, -58, -60,
  102980. -66, -64, -67, -70, -70, -74, -77, -84,
  102981. -86, -89, -91, -93, -94, -101, -109, -118,
  102982. -999, -999, -999, -999, -999, -999, -999, -999},
  102983. {-999, -999, -999, -108, -103, -98, -93, -88,
  102984. -83, -78, -73, -68, -60, -53, -44, -35,
  102985. -38, -38, -34, -34, -36, -40, -41, -44,
  102986. -51, -45, -46, -47, -46, -54, -50, -49,
  102987. -50, -50, -50, -51, -54, -57, -58, -60,
  102988. -66, -66, -66, -64, -65, -68, -77, -82,
  102989. -87, -95, -110, -999, -999, -999, -999, -999}},
  102990. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102991. -107, -102, -97, -92, -87, -83, -78, -75,
  102992. -82, -79, -83, -85, -89, -92, -95, -98,
  102993. -101, -105, -109, -113, -999, -999, -999, -999,
  102994. -999, -999, -999, -999, -999, -999, -999, -999,
  102995. -999, -999, -999, -999, -999, -999, -999, -999,
  102996. -999, -999, -999, -999, -999, -999, -999, -999},
  102997. {-999, -999, -999, -999, -999, -999, -999, -106,
  102998. -100, -95, -90, -86, -81, -78, -74, -69,
  102999. -74, -74, -76, -79, -83, -84, -86, -89,
  103000. -92, -97, -93, -100, -103, -107, -110, -999,
  103001. -999, -999, -999, -999, -999, -999, -999, -999,
  103002. -999, -999, -999, -999, -999, -999, -999, -999,
  103003. -999, -999, -999, -999, -999, -999, -999, -999},
  103004. {-999, -999, -999, -999, -999, -999, -106, -100,
  103005. -95, -90, -87, -83, -80, -75, -69, -60,
  103006. -66, -66, -68, -70, -74, -78, -79, -81,
  103007. -81, -83, -84, -87, -93, -96, -99, -103,
  103008. -107, -110, -999, -999, -999, -999, -999, -999,
  103009. -999, -999, -999, -999, -999, -999, -999, -999,
  103010. -999, -999, -999, -999, -999, -999, -999, -999},
  103011. {-999, -999, -999, -999, -999, -108, -103, -98,
  103012. -93, -89, -85, -82, -78, -71, -62, -55,
  103013. -58, -58, -54, -54, -55, -59, -61, -62,
  103014. -70, -66, -66, -67, -70, -72, -75, -78,
  103015. -84, -84, -84, -88, -91, -90, -95, -98,
  103016. -102, -103, -106, -110, -999, -999, -999, -999,
  103017. -999, -999, -999, -999, -999, -999, -999, -999},
  103018. {-999, -999, -999, -999, -108, -103, -98, -94,
  103019. -90, -87, -82, -79, -73, -67, -58, -47,
  103020. -50, -45, -41, -45, -48, -44, -44, -49,
  103021. -54, -51, -48, -47, -49, -50, -51, -57,
  103022. -58, -60, -63, -69, -70, -69, -71, -74,
  103023. -78, -82, -90, -95, -101, -105, -110, -999,
  103024. -999, -999, -999, -999, -999, -999, -999, -999},
  103025. {-999, -999, -999, -105, -101, -97, -93, -90,
  103026. -85, -80, -77, -72, -65, -56, -48, -37,
  103027. -40, -36, -34, -40, -50, -47, -38, -41,
  103028. -47, -38, -35, -39, -38, -43, -40, -45,
  103029. -50, -45, -44, -47, -50, -55, -48, -48,
  103030. -52, -66, -70, -76, -82, -90, -97, -105,
  103031. -110, -999, -999, -999, -999, -999, -999, -999}},
  103032. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103033. -999, -108, -103, -98, -93, -86, -79, -76,
  103034. -83, -81, -85, -87, -89, -93, -98, -102,
  103035. -107, -112, -999, -999, -999, -999, -999, -999,
  103036. -999, -999, -999, -999, -999, -999, -999, -999,
  103037. -999, -999, -999, -999, -999, -999, -999, -999,
  103038. -999, -999, -999, -999, -999, -999, -999, -999},
  103039. {-999, -999, -999, -999, -999, -999, -999, -999,
  103040. -999, -108, -103, -98, -93, -86, -79, -71,
  103041. -77, -74, -77, -79, -81, -84, -85, -90,
  103042. -92, -93, -92, -98, -101, -108, -112, -999,
  103043. -999, -999, -999, -999, -999, -999, -999, -999,
  103044. -999, -999, -999, -999, -999, -999, -999, -999,
  103045. -999, -999, -999, -999, -999, -999, -999, -999},
  103046. {-999, -999, -999, -999, -999, -999, -999, -999,
  103047. -108, -103, -98, -93, -87, -78, -68, -65,
  103048. -66, -62, -65, -67, -70, -73, -75, -78,
  103049. -82, -82, -83, -84, -91, -93, -98, -102,
  103050. -106, -110, -999, -999, -999, -999, -999, -999,
  103051. -999, -999, -999, -999, -999, -999, -999, -999,
  103052. -999, -999, -999, -999, -999, -999, -999, -999},
  103053. {-999, -999, -999, -999, -999, -999, -999, -999,
  103054. -105, -100, -95, -90, -82, -74, -62, -57,
  103055. -58, -56, -51, -52, -52, -54, -54, -58,
  103056. -66, -59, -60, -63, -66, -69, -73, -79,
  103057. -83, -84, -80, -81, -81, -82, -88, -92,
  103058. -98, -105, -113, -999, -999, -999, -999, -999,
  103059. -999, -999, -999, -999, -999, -999, -999, -999},
  103060. {-999, -999, -999, -999, -999, -999, -999, -107,
  103061. -102, -97, -92, -84, -79, -69, -57, -47,
  103062. -52, -47, -44, -45, -50, -52, -42, -42,
  103063. -53, -43, -43, -48, -51, -56, -55, -52,
  103064. -57, -59, -61, -62, -67, -71, -78, -83,
  103065. -86, -94, -98, -103, -110, -999, -999, -999,
  103066. -999, -999, -999, -999, -999, -999, -999, -999},
  103067. {-999, -999, -999, -999, -999, -999, -105, -100,
  103068. -95, -90, -84, -78, -70, -61, -51, -41,
  103069. -40, -38, -40, -46, -52, -51, -41, -40,
  103070. -46, -40, -38, -38, -41, -46, -41, -46,
  103071. -47, -43, -43, -45, -41, -45, -56, -67,
  103072. -68, -83, -87, -90, -95, -102, -107, -113,
  103073. -999, -999, -999, -999, -999, -999, -999, -999}},
  103074. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103075. -999, -109, -105, -101, -96, -91, -84, -77,
  103076. -82, -82, -85, -89, -94, -100, -106, -110,
  103077. -999, -999, -999, -999, -999, -999, -999, -999,
  103078. -999, -999, -999, -999, -999, -999, -999, -999,
  103079. -999, -999, -999, -999, -999, -999, -999, -999,
  103080. -999, -999, -999, -999, -999, -999, -999, -999},
  103081. {-999, -999, -999, -999, -999, -999, -999, -999,
  103082. -999, -106, -103, -98, -92, -85, -80, -71,
  103083. -75, -72, -76, -80, -84, -86, -89, -93,
  103084. -100, -107, -113, -999, -999, -999, -999, -999,
  103085. -999, -999, -999, -999, -999, -999, -999, -999,
  103086. -999, -999, -999, -999, -999, -999, -999, -999,
  103087. -999, -999, -999, -999, -999, -999, -999, -999},
  103088. {-999, -999, -999, -999, -999, -999, -999, -107,
  103089. -104, -101, -97, -92, -88, -84, -80, -64,
  103090. -66, -63, -64, -66, -69, -73, -77, -83,
  103091. -83, -86, -91, -98, -104, -111, -999, -999,
  103092. -999, -999, -999, -999, -999, -999, -999, -999,
  103093. -999, -999, -999, -999, -999, -999, -999, -999,
  103094. -999, -999, -999, -999, -999, -999, -999, -999},
  103095. {-999, -999, -999, -999, -999, -999, -999, -107,
  103096. -104, -101, -97, -92, -90, -84, -74, -57,
  103097. -58, -52, -55, -54, -50, -52, -50, -52,
  103098. -63, -62, -69, -76, -77, -78, -78, -79,
  103099. -82, -88, -94, -100, -106, -111, -999, -999,
  103100. -999, -999, -999, -999, -999, -999, -999, -999,
  103101. -999, -999, -999, -999, -999, -999, -999, -999},
  103102. {-999, -999, -999, -999, -999, -999, -106, -102,
  103103. -98, -95, -90, -85, -83, -78, -70, -50,
  103104. -50, -41, -44, -49, -47, -50, -50, -44,
  103105. -55, -46, -47, -48, -48, -54, -49, -49,
  103106. -58, -62, -71, -81, -87, -92, -97, -102,
  103107. -108, -114, -999, -999, -999, -999, -999, -999,
  103108. -999, -999, -999, -999, -999, -999, -999, -999},
  103109. {-999, -999, -999, -999, -999, -999, -106, -102,
  103110. -98, -95, -90, -85, -83, -78, -70, -45,
  103111. -43, -41, -47, -50, -51, -50, -49, -45,
  103112. -47, -41, -44, -41, -39, -43, -38, -37,
  103113. -40, -41, -44, -50, -58, -65, -73, -79,
  103114. -85, -92, -97, -101, -105, -109, -113, -999,
  103115. -999, -999, -999, -999, -999, -999, -999, -999}},
  103116. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103117. -999, -999, -999, -107, -100, -95, -87, -81,
  103118. -85, -83, -88, -93, -100, -107, -114, -999,
  103119. -999, -999, -999, -999, -999, -999, -999, -999,
  103120. -999, -999, -999, -999, -999, -999, -999, -999,
  103121. -999, -999, -999, -999, -999, -999, -999, -999,
  103122. -999, -999, -999, -999, -999, -999, -999, -999},
  103123. {-999, -999, -999, -999, -999, -999, -999, -999,
  103124. -999, -999, -107, -101, -95, -88, -83, -76,
  103125. -73, -72, -79, -84, -90, -95, -100, -105,
  103126. -110, -115, -999, -999, -999, -999, -999, -999,
  103127. -999, -999, -999, -999, -999, -999, -999, -999,
  103128. -999, -999, -999, -999, -999, -999, -999, -999,
  103129. -999, -999, -999, -999, -999, -999, -999, -999},
  103130. {-999, -999, -999, -999, -999, -999, -999, -999,
  103131. -999, -999, -104, -98, -92, -87, -81, -70,
  103132. -65, -62, -67, -71, -74, -80, -85, -91,
  103133. -95, -99, -103, -108, -111, -114, -999, -999,
  103134. -999, -999, -999, -999, -999, -999, -999, -999,
  103135. -999, -999, -999, -999, -999, -999, -999, -999,
  103136. -999, -999, -999, -999, -999, -999, -999, -999},
  103137. {-999, -999, -999, -999, -999, -999, -999, -999,
  103138. -999, -999, -103, -97, -90, -85, -76, -60,
  103139. -56, -54, -60, -62, -61, -56, -63, -65,
  103140. -73, -74, -77, -75, -78, -81, -86, -87,
  103141. -88, -91, -94, -98, -103, -110, -999, -999,
  103142. -999, -999, -999, -999, -999, -999, -999, -999,
  103143. -999, -999, -999, -999, -999, -999, -999, -999},
  103144. {-999, -999, -999, -999, -999, -999, -999, -105,
  103145. -100, -97, -92, -86, -81, -79, -70, -57,
  103146. -51, -47, -51, -58, -60, -56, -53, -50,
  103147. -58, -52, -50, -50, -53, -55, -64, -69,
  103148. -71, -85, -82, -78, -81, -85, -95, -102,
  103149. -112, -999, -999, -999, -999, -999, -999, -999,
  103150. -999, -999, -999, -999, -999, -999, -999, -999},
  103151. {-999, -999, -999, -999, -999, -999, -999, -105,
  103152. -100, -97, -92, -85, -83, -79, -72, -49,
  103153. -40, -43, -43, -54, -56, -51, -50, -40,
  103154. -43, -38, -36, -35, -37, -38, -37, -44,
  103155. -54, -60, -57, -60, -70, -75, -84, -92,
  103156. -103, -112, -999, -999, -999, -999, -999, -999,
  103157. -999, -999, -999, -999, -999, -999, -999, -999}},
  103158. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103159. -999, -999, -999, -110, -102, -95, -89, -82,
  103160. -83, -84, -90, -92, -99, -107, -113, -999,
  103161. -999, -999, -999, -999, -999, -999, -999, -999,
  103162. -999, -999, -999, -999, -999, -999, -999, -999,
  103163. -999, -999, -999, -999, -999, -999, -999, -999,
  103164. -999, -999, -999, -999, -999, -999, -999, -999},
  103165. {-999, -999, -999, -999, -999, -999, -999, -999,
  103166. -999, -999, -107, -101, -95, -89, -83, -72,
  103167. -74, -78, -85, -88, -88, -90, -92, -98,
  103168. -105, -111, -999, -999, -999, -999, -999, -999,
  103169. -999, -999, -999, -999, -999, -999, -999, -999,
  103170. -999, -999, -999, -999, -999, -999, -999, -999,
  103171. -999, -999, -999, -999, -999, -999, -999, -999},
  103172. {-999, -999, -999, -999, -999, -999, -999, -999,
  103173. -999, -109, -103, -97, -93, -87, -81, -70,
  103174. -70, -67, -75, -73, -76, -79, -81, -83,
  103175. -88, -89, -97, -103, -110, -999, -999, -999,
  103176. -999, -999, -999, -999, -999, -999, -999, -999,
  103177. -999, -999, -999, -999, -999, -999, -999, -999,
  103178. -999, -999, -999, -999, -999, -999, -999, -999},
  103179. {-999, -999, -999, -999, -999, -999, -999, -999,
  103180. -999, -107, -100, -94, -88, -83, -75, -63,
  103181. -59, -59, -63, -66, -60, -62, -67, -67,
  103182. -77, -76, -81, -88, -86, -92, -96, -102,
  103183. -109, -116, -999, -999, -999, -999, -999, -999,
  103184. -999, -999, -999, -999, -999, -999, -999, -999,
  103185. -999, -999, -999, -999, -999, -999, -999, -999},
  103186. {-999, -999, -999, -999, -999, -999, -999, -999,
  103187. -999, -105, -98, -92, -86, -81, -73, -56,
  103188. -52, -47, -55, -60, -58, -52, -51, -45,
  103189. -49, -50, -53, -54, -61, -71, -70, -69,
  103190. -78, -79, -87, -90, -96, -104, -112, -999,
  103191. -999, -999, -999, -999, -999, -999, -999, -999,
  103192. -999, -999, -999, -999, -999, -999, -999, -999},
  103193. {-999, -999, -999, -999, -999, -999, -999, -999,
  103194. -999, -103, -96, -90, -86, -78, -70, -51,
  103195. -42, -47, -48, -55, -54, -54, -53, -42,
  103196. -35, -28, -33, -38, -37, -44, -47, -49,
  103197. -54, -63, -68, -78, -82, -89, -94, -99,
  103198. -104, -109, -114, -999, -999, -999, -999, -999,
  103199. -999, -999, -999, -999, -999, -999, -999, -999}},
  103200. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103201. -999, -999, -999, -999, -110, -100, -90, -79,
  103202. -85, -81, -82, -82, -89, -94, -99, -103,
  103203. -109, -115, -999, -999, -999, -999, -999, -999,
  103204. -999, -999, -999, -999, -999, -999, -999, -999,
  103205. -999, -999, -999, -999, -999, -999, -999, -999,
  103206. -999, -999, -999, -999, -999, -999, -999, -999},
  103207. {-999, -999, -999, -999, -999, -999, -999, -999,
  103208. -999, -999, -999, -999, -105, -97, -85, -72,
  103209. -74, -70, -70, -70, -76, -85, -91, -93,
  103210. -97, -103, -109, -115, -999, -999, -999, -999,
  103211. -999, -999, -999, -999, -999, -999, -999, -999,
  103212. -999, -999, -999, -999, -999, -999, -999, -999,
  103213. -999, -999, -999, -999, -999, -999, -999, -999},
  103214. {-999, -999, -999, -999, -999, -999, -999, -999,
  103215. -999, -999, -999, -999, -112, -93, -81, -68,
  103216. -62, -60, -60, -57, -63, -70, -77, -82,
  103217. -90, -93, -98, -104, -109, -113, -999, -999,
  103218. -999, -999, -999, -999, -999, -999, -999, -999,
  103219. -999, -999, -999, -999, -999, -999, -999, -999,
  103220. -999, -999, -999, -999, -999, -999, -999, -999},
  103221. {-999, -999, -999, -999, -999, -999, -999, -999,
  103222. -999, -999, -999, -113, -100, -93, -84, -63,
  103223. -58, -48, -53, -54, -52, -52, -57, -64,
  103224. -66, -76, -83, -81, -85, -85, -90, -95,
  103225. -98, -101, -103, -106, -108, -111, -999, -999,
  103226. -999, -999, -999, -999, -999, -999, -999, -999,
  103227. -999, -999, -999, -999, -999, -999, -999, -999},
  103228. {-999, -999, -999, -999, -999, -999, -999, -999,
  103229. -999, -999, -999, -105, -95, -86, -74, -53,
  103230. -50, -38, -43, -49, -43, -42, -39, -39,
  103231. -46, -52, -57, -56, -72, -69, -74, -81,
  103232. -87, -92, -94, -97, -99, -102, -105, -108,
  103233. -999, -999, -999, -999, -999, -999, -999, -999,
  103234. -999, -999, -999, -999, -999, -999, -999, -999},
  103235. {-999, -999, -999, -999, -999, -999, -999, -999,
  103236. -999, -999, -108, -99, -90, -76, -66, -45,
  103237. -43, -41, -44, -47, -43, -47, -40, -30,
  103238. -31, -31, -39, -33, -40, -41, -43, -53,
  103239. -59, -70, -73, -77, -79, -82, -84, -87,
  103240. -999, -999, -999, -999, -999, -999, -999, -999,
  103241. -999, -999, -999, -999, -999, -999, -999, -999}},
  103242. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103243. -999, -999, -999, -999, -999, -110, -91, -76,
  103244. -75, -85, -93, -98, -104, -110, -999, -999,
  103245. -999, -999, -999, -999, -999, -999, -999, -999,
  103246. -999, -999, -999, -999, -999, -999, -999, -999,
  103247. -999, -999, -999, -999, -999, -999, -999, -999,
  103248. -999, -999, -999, -999, -999, -999, -999, -999},
  103249. {-999, -999, -999, -999, -999, -999, -999, -999,
  103250. -999, -999, -999, -999, -999, -110, -91, -70,
  103251. -70, -75, -86, -89, -94, -98, -101, -106,
  103252. -110, -999, -999, -999, -999, -999, -999, -999,
  103253. -999, -999, -999, -999, -999, -999, -999, -999,
  103254. -999, -999, -999, -999, -999, -999, -999, -999,
  103255. -999, -999, -999, -999, -999, -999, -999, -999},
  103256. {-999, -999, -999, -999, -999, -999, -999, -999,
  103257. -999, -999, -999, -999, -110, -95, -80, -60,
  103258. -65, -64, -74, -83, -88, -91, -95, -99,
  103259. -103, -107, -110, -999, -999, -999, -999, -999,
  103260. -999, -999, -999, -999, -999, -999, -999, -999,
  103261. -999, -999, -999, -999, -999, -999, -999, -999,
  103262. -999, -999, -999, -999, -999, -999, -999, -999},
  103263. {-999, -999, -999, -999, -999, -999, -999, -999,
  103264. -999, -999, -999, -999, -110, -95, -80, -58,
  103265. -55, -49, -66, -68, -71, -78, -78, -80,
  103266. -88, -85, -89, -97, -100, -105, -110, -999,
  103267. -999, -999, -999, -999, -999, -999, -999, -999,
  103268. -999, -999, -999, -999, -999, -999, -999, -999,
  103269. -999, -999, -999, -999, -999, -999, -999, -999},
  103270. {-999, -999, -999, -999, -999, -999, -999, -999,
  103271. -999, -999, -999, -999, -110, -95, -80, -53,
  103272. -52, -41, -59, -59, -49, -58, -56, -63,
  103273. -86, -79, -90, -93, -98, -103, -107, -112,
  103274. -999, -999, -999, -999, -999, -999, -999, -999,
  103275. -999, -999, -999, -999, -999, -999, -999, -999,
  103276. -999, -999, -999, -999, -999, -999, -999, -999},
  103277. {-999, -999, -999, -999, -999, -999, -999, -999,
  103278. -999, -999, -999, -110, -97, -91, -73, -45,
  103279. -40, -33, -53, -61, -49, -54, -50, -50,
  103280. -60, -52, -67, -74, -81, -92, -96, -100,
  103281. -105, -110, -999, -999, -999, -999, -999, -999,
  103282. -999, -999, -999, -999, -999, -999, -999, -999,
  103283. -999, -999, -999, -999, -999, -999, -999, -999}},
  103284. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103285. -999, -999, -999, -113, -106, -99, -92, -77,
  103286. -80, -88, -97, -106, -115, -999, -999, -999,
  103287. -999, -999, -999, -999, -999, -999, -999, -999,
  103288. -999, -999, -999, -999, -999, -999, -999, -999,
  103289. -999, -999, -999, -999, -999, -999, -999, -999,
  103290. -999, -999, -999, -999, -999, -999, -999, -999},
  103291. {-999, -999, -999, -999, -999, -999, -999, -999,
  103292. -999, -999, -116, -109, -102, -95, -89, -74,
  103293. -72, -88, -87, -95, -102, -109, -116, -999,
  103294. -999, -999, -999, -999, -999, -999, -999, -999,
  103295. -999, -999, -999, -999, -999, -999, -999, -999,
  103296. -999, -999, -999, -999, -999, -999, -999, -999,
  103297. -999, -999, -999, -999, -999, -999, -999, -999},
  103298. {-999, -999, -999, -999, -999, -999, -999, -999,
  103299. -999, -999, -116, -109, -102, -95, -89, -75,
  103300. -66, -74, -77, -78, -86, -87, -90, -96,
  103301. -105, -115, -999, -999, -999, -999, -999, -999,
  103302. -999, -999, -999, -999, -999, -999, -999, -999,
  103303. -999, -999, -999, -999, -999, -999, -999, -999,
  103304. -999, -999, -999, -999, -999, -999, -999, -999},
  103305. {-999, -999, -999, -999, -999, -999, -999, -999,
  103306. -999, -999, -115, -108, -101, -94, -88, -66,
  103307. -56, -61, -70, -65, -78, -72, -83, -84,
  103308. -93, -98, -105, -110, -999, -999, -999, -999,
  103309. -999, -999, -999, -999, -999, -999, -999, -999,
  103310. -999, -999, -999, -999, -999, -999, -999, -999,
  103311. -999, -999, -999, -999, -999, -999, -999, -999},
  103312. {-999, -999, -999, -999, -999, -999, -999, -999,
  103313. -999, -999, -110, -105, -95, -89, -82, -57,
  103314. -52, -52, -59, -56, -59, -58, -69, -67,
  103315. -88, -82, -82, -89, -94, -100, -108, -999,
  103316. -999, -999, -999, -999, -999, -999, -999, -999,
  103317. -999, -999, -999, -999, -999, -999, -999, -999,
  103318. -999, -999, -999, -999, -999, -999, -999, -999},
  103319. {-999, -999, -999, -999, -999, -999, -999, -999,
  103320. -999, -110, -101, -96, -90, -83, -77, -54,
  103321. -43, -38, -50, -48, -52, -48, -42, -42,
  103322. -51, -52, -53, -59, -65, -71, -78, -85,
  103323. -95, -999, -999, -999, -999, -999, -999, -999,
  103324. -999, -999, -999, -999, -999, -999, -999, -999,
  103325. -999, -999, -999, -999, -999, -999, -999, -999}},
  103326. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103327. -999, -999, -999, -999, -120, -105, -86, -68,
  103328. -78, -79, -90, -100, -110, -999, -999, -999,
  103329. -999, -999, -999, -999, -999, -999, -999, -999,
  103330. -999, -999, -999, -999, -999, -999, -999, -999,
  103331. -999, -999, -999, -999, -999, -999, -999, -999,
  103332. -999, -999, -999, -999, -999, -999, -999, -999},
  103333. {-999, -999, -999, -999, -999, -999, -999, -999,
  103334. -999, -999, -999, -999, -120, -105, -86, -66,
  103335. -73, -77, -88, -96, -105, -115, -999, -999,
  103336. -999, -999, -999, -999, -999, -999, -999, -999,
  103337. -999, -999, -999, -999, -999, -999, -999, -999,
  103338. -999, -999, -999, -999, -999, -999, -999, -999,
  103339. -999, -999, -999, -999, -999, -999, -999, -999},
  103340. {-999, -999, -999, -999, -999, -999, -999, -999,
  103341. -999, -999, -999, -120, -105, -92, -80, -61,
  103342. -64, -68, -80, -87, -92, -100, -110, -999,
  103343. -999, -999, -999, -999, -999, -999, -999, -999,
  103344. -999, -999, -999, -999, -999, -999, -999, -999,
  103345. -999, -999, -999, -999, -999, -999, -999, -999,
  103346. -999, -999, -999, -999, -999, -999, -999, -999},
  103347. {-999, -999, -999, -999, -999, -999, -999, -999,
  103348. -999, -999, -999, -120, -104, -91, -79, -52,
  103349. -60, -54, -64, -69, -77, -80, -82, -84,
  103350. -85, -87, -88, -90, -999, -999, -999, -999,
  103351. -999, -999, -999, -999, -999, -999, -999, -999,
  103352. -999, -999, -999, -999, -999, -999, -999, -999,
  103353. -999, -999, -999, -999, -999, -999, -999, -999},
  103354. {-999, -999, -999, -999, -999, -999, -999, -999,
  103355. -999, -999, -999, -118, -100, -87, -77, -49,
  103356. -50, -44, -58, -61, -61, -67, -65, -62,
  103357. -62, -62, -65, -68, -999, -999, -999, -999,
  103358. -999, -999, -999, -999, -999, -999, -999, -999,
  103359. -999, -999, -999, -999, -999, -999, -999, -999,
  103360. -999, -999, -999, -999, -999, -999, -999, -999},
  103361. {-999, -999, -999, -999, -999, -999, -999, -999,
  103362. -999, -999, -999, -115, -98, -84, -62, -49,
  103363. -44, -38, -46, -49, -49, -46, -39, -37,
  103364. -39, -40, -42, -43, -999, -999, -999, -999,
  103365. -999, -999, -999, -999, -999, -999, -999, -999,
  103366. -999, -999, -999, -999, -999, -999, -999, -999,
  103367. -999, -999, -999, -999, -999, -999, -999, -999}},
  103368. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103369. -999, -999, -999, -999, -999, -110, -88, -74,
  103370. -77, -82, -82, -85, -90, -94, -99, -104,
  103371. -999, -999, -999, -999, -999, -999, -999, -999,
  103372. -999, -999, -999, -999, -999, -999, -999, -999,
  103373. -999, -999, -999, -999, -999, -999, -999, -999,
  103374. -999, -999, -999, -999, -999, -999, -999, -999},
  103375. {-999, -999, -999, -999, -999, -999, -999, -999,
  103376. -999, -999, -999, -999, -999, -110, -88, -66,
  103377. -70, -81, -80, -81, -84, -88, -91, -93,
  103378. -999, -999, -999, -999, -999, -999, -999, -999,
  103379. -999, -999, -999, -999, -999, -999, -999, -999,
  103380. -999, -999, -999, -999, -999, -999, -999, -999,
  103381. -999, -999, -999, -999, -999, -999, -999, -999},
  103382. {-999, -999, -999, -999, -999, -999, -999, -999,
  103383. -999, -999, -999, -999, -999, -110, -88, -61,
  103384. -63, -70, -71, -74, -77, -80, -83, -85,
  103385. -999, -999, -999, -999, -999, -999, -999, -999,
  103386. -999, -999, -999, -999, -999, -999, -999, -999,
  103387. -999, -999, -999, -999, -999, -999, -999, -999,
  103388. -999, -999, -999, -999, -999, -999, -999, -999},
  103389. {-999, -999, -999, -999, -999, -999, -999, -999,
  103390. -999, -999, -999, -999, -999, -110, -86, -62,
  103391. -63, -62, -62, -58, -52, -50, -50, -52,
  103392. -54, -999, -999, -999, -999, -999, -999, -999,
  103393. -999, -999, -999, -999, -999, -999, -999, -999,
  103394. -999, -999, -999, -999, -999, -999, -999, -999,
  103395. -999, -999, -999, -999, -999, -999, -999, -999},
  103396. {-999, -999, -999, -999, -999, -999, -999, -999,
  103397. -999, -999, -999, -999, -118, -108, -84, -53,
  103398. -50, -50, -50, -55, -47, -45, -40, -40,
  103399. -40, -999, -999, -999, -999, -999, -999, -999,
  103400. -999, -999, -999, -999, -999, -999, -999, -999,
  103401. -999, -999, -999, -999, -999, -999, -999, -999,
  103402. -999, -999, -999, -999, -999, -999, -999, -999},
  103403. {-999, -999, -999, -999, -999, -999, -999, -999,
  103404. -999, -999, -999, -999, -118, -100, -73, -43,
  103405. -37, -42, -43, -53, -38, -37, -35, -35,
  103406. -38, -999, -999, -999, -999, -999, -999, -999,
  103407. -999, -999, -999, -999, -999, -999, -999, -999,
  103408. -999, -999, -999, -999, -999, -999, -999, -999,
  103409. -999, -999, -999, -999, -999, -999, -999, -999}},
  103410. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103411. -999, -999, -999, -110, -100, -91, -84, -74,
  103412. -80, -80, -80, -80, -80, -999, -999, -999,
  103413. -999, -999, -999, -999, -999, -999, -999, -999,
  103414. -999, -999, -999, -999, -999, -999, -999, -999,
  103415. -999, -999, -999, -999, -999, -999, -999, -999,
  103416. -999, -999, -999, -999, -999, -999, -999, -999},
  103417. {-999, -999, -999, -999, -999, -999, -999, -999,
  103418. -999, -999, -999, -110, -100, -91, -84, -74,
  103419. -68, -68, -68, -68, -68, -999, -999, -999,
  103420. -999, -999, -999, -999, -999, -999, -999, -999,
  103421. -999, -999, -999, -999, -999, -999, -999, -999,
  103422. -999, -999, -999, -999, -999, -999, -999, -999,
  103423. -999, -999, -999, -999, -999, -999, -999, -999},
  103424. {-999, -999, -999, -999, -999, -999, -999, -999,
  103425. -999, -999, -999, -110, -100, -86, -78, -70,
  103426. -60, -45, -30, -21, -999, -999, -999, -999,
  103427. -999, -999, -999, -999, -999, -999, -999, -999,
  103428. -999, -999, -999, -999, -999, -999, -999, -999,
  103429. -999, -999, -999, -999, -999, -999, -999, -999,
  103430. -999, -999, -999, -999, -999, -999, -999, -999},
  103431. {-999, -999, -999, -999, -999, -999, -999, -999,
  103432. -999, -999, -999, -110, -100, -87, -78, -67,
  103433. -48, -38, -29, -21, -999, -999, -999, -999,
  103434. -999, -999, -999, -999, -999, -999, -999, -999,
  103435. -999, -999, -999, -999, -999, -999, -999, -999,
  103436. -999, -999, -999, -999, -999, -999, -999, -999,
  103437. -999, -999, -999, -999, -999, -999, -999, -999},
  103438. {-999, -999, -999, -999, -999, -999, -999, -999,
  103439. -999, -999, -999, -110, -100, -86, -69, -56,
  103440. -45, -35, -33, -29, -999, -999, -999, -999,
  103441. -999, -999, -999, -999, -999, -999, -999, -999,
  103442. -999, -999, -999, -999, -999, -999, -999, -999,
  103443. -999, -999, -999, -999, -999, -999, -999, -999,
  103444. -999, -999, -999, -999, -999, -999, -999, -999},
  103445. {-999, -999, -999, -999, -999, -999, -999, -999,
  103446. -999, -999, -999, -110, -100, -83, -71, -48,
  103447. -27, -38, -37, -34, -999, -999, -999, -999,
  103448. -999, -999, -999, -999, -999, -999, -999, -999,
  103449. -999, -999, -999, -999, -999, -999, -999, -999,
  103450. -999, -999, -999, -999, -999, -999, -999, -999,
  103451. -999, -999, -999, -999, -999, -999, -999, -999}}
  103452. };
  103453. #endif
  103454. /*** End of inlined file: masking.h ***/
  103455. #define NEGINF -9999.f
  103456. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103457. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103458. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103459. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103460. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103461. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103462. look->channels=vi->channels;
  103463. look->ampmax=-9999.;
  103464. look->gi=gi;
  103465. return(look);
  103466. }
  103467. void _vp_global_free(vorbis_look_psy_global *look){
  103468. if(look){
  103469. memset(look,0,sizeof(*look));
  103470. _ogg_free(look);
  103471. }
  103472. }
  103473. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103474. if(i){
  103475. memset(i,0,sizeof(*i));
  103476. _ogg_free(i);
  103477. }
  103478. }
  103479. void _vi_psy_free(vorbis_info_psy *i){
  103480. if(i){
  103481. memset(i,0,sizeof(*i));
  103482. _ogg_free(i);
  103483. }
  103484. }
  103485. static void min_curve(float *c,
  103486. float *c2){
  103487. int i;
  103488. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103489. }
  103490. static void max_curve(float *c,
  103491. float *c2){
  103492. int i;
  103493. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103494. }
  103495. static void attenuate_curve(float *c,float att){
  103496. int i;
  103497. for(i=0;i<EHMER_MAX;i++)
  103498. c[i]+=att;
  103499. }
  103500. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103501. float center_boost, float center_decay_rate){
  103502. int i,j,k,m;
  103503. float ath[EHMER_MAX];
  103504. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103505. float athc[P_LEVELS][EHMER_MAX];
  103506. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103507. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103508. memset(workc,0,sizeof(workc));
  103509. for(i=0;i<P_BANDS;i++){
  103510. int ath_offset=i*4;
  103511. for(j=0;j<EHMER_MAX;j++){
  103512. float min=999.;
  103513. for(k=0;k<4;k++)
  103514. if(j+k+ath_offset<MAX_ATH){
  103515. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103516. }else{
  103517. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103518. }
  103519. ath[j]=min;
  103520. }
  103521. for(j=0;j<6;j++)
  103522. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103523. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103524. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103525. for(j=0;j<P_LEVELS;j++){
  103526. for(k=0;k<EHMER_MAX;k++){
  103527. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103528. if(adj<0. && center_boost>0)adj=0.;
  103529. if(adj>0. && center_boost<0)adj=0.;
  103530. workc[i][j][k]+=adj;
  103531. }
  103532. }
  103533. for(j=0;j<P_LEVELS;j++){
  103534. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103535. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103536. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103537. max_curve(athc[j],workc[i][j]);
  103538. }
  103539. for(j=1;j<P_LEVELS;j++){
  103540. min_curve(athc[j],athc[j-1]);
  103541. min_curve(workc[i][j],athc[j]);
  103542. }
  103543. }
  103544. for(i=0;i<P_BANDS;i++){
  103545. int hi_curve,lo_curve,bin;
  103546. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103547. bin=floor(fromOC(i*.5)/binHz);
  103548. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103549. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103550. if(lo_curve>i)lo_curve=i;
  103551. if(lo_curve<0)lo_curve=0;
  103552. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103553. for(m=0;m<P_LEVELS;m++){
  103554. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103555. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103556. for(k=lo_curve;k<=hi_curve;k++){
  103557. int l=0;
  103558. for(j=0;j<EHMER_MAX;j++){
  103559. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103560. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103561. if(lo_bin<0)lo_bin=0;
  103562. if(lo_bin>n)lo_bin=n;
  103563. if(lo_bin<l)l=lo_bin;
  103564. if(hi_bin<0)hi_bin=0;
  103565. if(hi_bin>n)hi_bin=n;
  103566. for(;l<hi_bin && l<n;l++)
  103567. if(brute_buffer[l]>workc[k][m][j])
  103568. brute_buffer[l]=workc[k][m][j];
  103569. }
  103570. for(;l<n;l++)
  103571. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103572. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103573. }
  103574. if(i+1<P_BANDS){
  103575. int l=0;
  103576. k=i+1;
  103577. for(j=0;j<EHMER_MAX;j++){
  103578. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103579. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103580. if(lo_bin<0)lo_bin=0;
  103581. if(lo_bin>n)lo_bin=n;
  103582. if(lo_bin<l)l=lo_bin;
  103583. if(hi_bin<0)hi_bin=0;
  103584. if(hi_bin>n)hi_bin=n;
  103585. for(;l<hi_bin && l<n;l++)
  103586. if(brute_buffer[l]>workc[k][m][j])
  103587. brute_buffer[l]=workc[k][m][j];
  103588. }
  103589. for(;l<n;l++)
  103590. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103591. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103592. }
  103593. for(j=0;j<EHMER_MAX;j++){
  103594. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103595. if(bin<0){
  103596. ret[i][m][j+2]=-999.;
  103597. }else{
  103598. if(bin>=n){
  103599. ret[i][m][j+2]=-999.;
  103600. }else{
  103601. ret[i][m][j+2]=brute_buffer[bin];
  103602. }
  103603. }
  103604. }
  103605. for(j=0;j<EHMER_OFFSET;j++)
  103606. if(ret[i][m][j+2]>-200.f)break;
  103607. ret[i][m][0]=j;
  103608. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103609. if(ret[i][m][j+2]>-200.f)
  103610. break;
  103611. ret[i][m][1]=j;
  103612. }
  103613. }
  103614. return(ret);
  103615. }
  103616. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103617. vorbis_info_psy_global *gi,int n,long rate){
  103618. long i,j,lo=-99,hi=1;
  103619. long maxoc;
  103620. memset(p,0,sizeof(*p));
  103621. p->eighth_octave_lines=gi->eighth_octave_lines;
  103622. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103623. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103624. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103625. p->total_octave_lines=maxoc-p->firstoc+1;
  103626. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103627. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103628. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103629. p->vi=vi;
  103630. p->n=n;
  103631. p->rate=rate;
  103632. p->m_val = 1.;
  103633. if(rate < 26000) p->m_val = 0;
  103634. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103635. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103636. for(i=0,j=0;i<MAX_ATH-1;i++){
  103637. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103638. float base=ATH[i];
  103639. if(j<endpos){
  103640. float delta=(ATH[i+1]-base)/(endpos-j);
  103641. for(;j<endpos && j<n;j++){
  103642. p->ath[j]=base+100.;
  103643. base+=delta;
  103644. }
  103645. }
  103646. }
  103647. for(i=0;i<n;i++){
  103648. float bark=toBARK(rate/(2*n)*i);
  103649. for(;lo+vi->noisewindowlomin<i &&
  103650. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103651. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103652. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103653. p->bark[i]=((lo-1)<<16)+(hi-1);
  103654. }
  103655. for(i=0;i<n;i++)
  103656. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103657. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103658. vi->tone_centerboost,vi->tone_decay);
  103659. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103660. for(i=0;i<P_NOISECURVES;i++)
  103661. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103662. for(i=0;i<n;i++){
  103663. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103664. int inthalfoc;
  103665. float del;
  103666. if(halfoc<0)halfoc=0;
  103667. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103668. inthalfoc=(int)halfoc;
  103669. del=halfoc-inthalfoc;
  103670. for(j=0;j<P_NOISECURVES;j++)
  103671. p->noiseoffset[j][i]=
  103672. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103673. p->vi->noiseoff[j][inthalfoc+1]*del;
  103674. }
  103675. #if 0
  103676. {
  103677. static int ls=0;
  103678. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103679. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103680. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103681. }
  103682. #endif
  103683. }
  103684. void _vp_psy_clear(vorbis_look_psy *p){
  103685. int i,j;
  103686. if(p){
  103687. if(p->ath)_ogg_free(p->ath);
  103688. if(p->octave)_ogg_free(p->octave);
  103689. if(p->bark)_ogg_free(p->bark);
  103690. if(p->tonecurves){
  103691. for(i=0;i<P_BANDS;i++){
  103692. for(j=0;j<P_LEVELS;j++){
  103693. _ogg_free(p->tonecurves[i][j]);
  103694. }
  103695. _ogg_free(p->tonecurves[i]);
  103696. }
  103697. _ogg_free(p->tonecurves);
  103698. }
  103699. if(p->noiseoffset){
  103700. for(i=0;i<P_NOISECURVES;i++){
  103701. _ogg_free(p->noiseoffset[i]);
  103702. }
  103703. _ogg_free(p->noiseoffset);
  103704. }
  103705. memset(p,0,sizeof(*p));
  103706. }
  103707. }
  103708. static void seed_curve(float *seed,
  103709. const float **curves,
  103710. float amp,
  103711. int oc, int n,
  103712. int linesper,float dBoffset){
  103713. int i,post1;
  103714. int seedptr;
  103715. const float *posts,*curve;
  103716. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103717. choice=max(choice,0);
  103718. choice=min(choice,P_LEVELS-1);
  103719. posts=curves[choice];
  103720. curve=posts+2;
  103721. post1=(int)posts[1];
  103722. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103723. for(i=posts[0];i<post1;i++){
  103724. if(seedptr>0){
  103725. float lin=amp+curve[i];
  103726. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103727. }
  103728. seedptr+=linesper;
  103729. if(seedptr>=n)break;
  103730. }
  103731. }
  103732. static void seed_loop(vorbis_look_psy *p,
  103733. const float ***curves,
  103734. const float *f,
  103735. const float *flr,
  103736. float *seed,
  103737. float specmax){
  103738. vorbis_info_psy *vi=p->vi;
  103739. long n=p->n,i;
  103740. float dBoffset=vi->max_curve_dB-specmax;
  103741. for(i=0;i<n;i++){
  103742. float max=f[i];
  103743. long oc=p->octave[i];
  103744. while(i+1<n && p->octave[i+1]==oc){
  103745. i++;
  103746. if(f[i]>max)max=f[i];
  103747. }
  103748. if(max+6.f>flr[i]){
  103749. oc=oc>>p->shiftoc;
  103750. if(oc>=P_BANDS)oc=P_BANDS-1;
  103751. if(oc<0)oc=0;
  103752. seed_curve(seed,
  103753. curves[oc],
  103754. max,
  103755. p->octave[i]-p->firstoc,
  103756. p->total_octave_lines,
  103757. p->eighth_octave_lines,
  103758. dBoffset);
  103759. }
  103760. }
  103761. }
  103762. static void seed_chase(float *seeds, int linesper, long n){
  103763. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103764. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103765. long stack=0;
  103766. long pos=0;
  103767. long i;
  103768. for(i=0;i<n;i++){
  103769. if(stack<2){
  103770. posstack[stack]=i;
  103771. ampstack[stack++]=seeds[i];
  103772. }else{
  103773. while(1){
  103774. if(seeds[i]<ampstack[stack-1]){
  103775. posstack[stack]=i;
  103776. ampstack[stack++]=seeds[i];
  103777. break;
  103778. }else{
  103779. if(i<posstack[stack-1]+linesper){
  103780. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103781. i<posstack[stack-2]+linesper){
  103782. stack--;
  103783. continue;
  103784. }
  103785. }
  103786. posstack[stack]=i;
  103787. ampstack[stack++]=seeds[i];
  103788. break;
  103789. }
  103790. }
  103791. }
  103792. }
  103793. for(i=0;i<stack;i++){
  103794. long endpos;
  103795. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103796. endpos=posstack[i+1];
  103797. }else{
  103798. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103799. discarded in short frames */
  103800. }
  103801. if(endpos>n)endpos=n;
  103802. for(;pos<endpos;pos++)
  103803. seeds[pos]=ampstack[i];
  103804. }
  103805. }
  103806. #include<stdio.h>
  103807. static void max_seeds(vorbis_look_psy *p,
  103808. float *seed,
  103809. float *flr){
  103810. long n=p->total_octave_lines;
  103811. int linesper=p->eighth_octave_lines;
  103812. long linpos=0;
  103813. long pos;
  103814. seed_chase(seed,linesper,n); /* for masking */
  103815. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103816. while(linpos+1<p->n){
  103817. float minV=seed[pos];
  103818. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103819. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103820. while(pos+1<=end){
  103821. pos++;
  103822. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103823. minV=seed[pos];
  103824. }
  103825. end=pos+p->firstoc;
  103826. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103827. if(flr[linpos]<minV)flr[linpos]=minV;
  103828. }
  103829. {
  103830. float minV=seed[p->total_octave_lines-1];
  103831. for(;linpos<p->n;linpos++)
  103832. if(flr[linpos]<minV)flr[linpos]=minV;
  103833. }
  103834. }
  103835. static void bark_noise_hybridmp(int n,const long *b,
  103836. const float *f,
  103837. float *noise,
  103838. const float offset,
  103839. const int fixed){
  103840. float *N=(float*) alloca(n*sizeof(*N));
  103841. float *X=(float*) alloca(n*sizeof(*N));
  103842. float *XX=(float*) alloca(n*sizeof(*N));
  103843. float *Y=(float*) alloca(n*sizeof(*N));
  103844. float *XY=(float*) alloca(n*sizeof(*N));
  103845. float tN, tX, tXX, tY, tXY;
  103846. int i;
  103847. int lo, hi;
  103848. float R, A, B, D;
  103849. float w, x, y;
  103850. tN = tX = tXX = tY = tXY = 0.f;
  103851. y = f[0] + offset;
  103852. if (y < 1.f) y = 1.f;
  103853. w = y * y * .5;
  103854. tN += w;
  103855. tX += w;
  103856. tY += w * y;
  103857. N[0] = tN;
  103858. X[0] = tX;
  103859. XX[0] = tXX;
  103860. Y[0] = tY;
  103861. XY[0] = tXY;
  103862. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103863. y = f[i] + offset;
  103864. if (y < 1.f) y = 1.f;
  103865. w = y * y;
  103866. tN += w;
  103867. tX += w * x;
  103868. tXX += w * x * x;
  103869. tY += w * y;
  103870. tXY += w * x * y;
  103871. N[i] = tN;
  103872. X[i] = tX;
  103873. XX[i] = tXX;
  103874. Y[i] = tY;
  103875. XY[i] = tXY;
  103876. }
  103877. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103878. lo = b[i] >> 16;
  103879. if( lo>=0 ) break;
  103880. hi = b[i] & 0xffff;
  103881. tN = N[hi] + N[-lo];
  103882. tX = X[hi] - X[-lo];
  103883. tXX = XX[hi] + XX[-lo];
  103884. tY = Y[hi] + Y[-lo];
  103885. tXY = XY[hi] - XY[-lo];
  103886. A = tY * tXX - tX * tXY;
  103887. B = tN * tXY - tX * tY;
  103888. D = tN * tXX - tX * tX;
  103889. R = (A + x * B) / D;
  103890. if (R < 0.f)
  103891. R = 0.f;
  103892. noise[i] = R - offset;
  103893. }
  103894. for ( ;; i++, x += 1.f) {
  103895. lo = b[i] >> 16;
  103896. hi = b[i] & 0xffff;
  103897. if(hi>=n)break;
  103898. tN = N[hi] - N[lo];
  103899. tX = X[hi] - X[lo];
  103900. tXX = XX[hi] - XX[lo];
  103901. tY = Y[hi] - Y[lo];
  103902. tXY = XY[hi] - XY[lo];
  103903. A = tY * tXX - tX * tXY;
  103904. B = tN * tXY - tX * tY;
  103905. D = tN * tXX - tX * tX;
  103906. R = (A + x * B) / D;
  103907. if (R < 0.f) R = 0.f;
  103908. noise[i] = R - offset;
  103909. }
  103910. for ( ; i < n; i++, x += 1.f) {
  103911. R = (A + x * B) / D;
  103912. if (R < 0.f) R = 0.f;
  103913. noise[i] = R - offset;
  103914. }
  103915. if (fixed <= 0) return;
  103916. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103917. hi = i + fixed / 2;
  103918. lo = hi - fixed;
  103919. if(lo>=0)break;
  103920. tN = N[hi] + N[-lo];
  103921. tX = X[hi] - X[-lo];
  103922. tXX = XX[hi] + XX[-lo];
  103923. tY = Y[hi] + Y[-lo];
  103924. tXY = XY[hi] - XY[-lo];
  103925. A = tY * tXX - tX * tXY;
  103926. B = tN * tXY - tX * tY;
  103927. D = tN * tXX - tX * tX;
  103928. R = (A + x * B) / D;
  103929. if (R - offset < noise[i]) noise[i] = R - offset;
  103930. }
  103931. for ( ;; i++, x += 1.f) {
  103932. hi = i + fixed / 2;
  103933. lo = hi - fixed;
  103934. if(hi>=n)break;
  103935. tN = N[hi] - N[lo];
  103936. tX = X[hi] - X[lo];
  103937. tXX = XX[hi] - XX[lo];
  103938. tY = Y[hi] - Y[lo];
  103939. tXY = XY[hi] - XY[lo];
  103940. A = tY * tXX - tX * tXY;
  103941. B = tN * tXY - tX * tY;
  103942. D = tN * tXX - tX * tX;
  103943. R = (A + x * B) / D;
  103944. if (R - offset < noise[i]) noise[i] = R - offset;
  103945. }
  103946. for ( ; i < n; i++, x += 1.f) {
  103947. R = (A + x * B) / D;
  103948. if (R - offset < noise[i]) noise[i] = R - offset;
  103949. }
  103950. }
  103951. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103952. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103953. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103954. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103955. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103956. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103957. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103958. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103959. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103960. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103961. 973377.F, 913981.F, 858210.F, 805842.F,
  103962. 756669.F, 710497.F, 667142.F, 626433.F,
  103963. 588208.F, 552316.F, 518613.F, 486967.F,
  103964. 457252.F, 429351.F, 403152.F, 378551.F,
  103965. 355452.F, 333762.F, 313396.F, 294273.F,
  103966. 276316.F, 259455.F, 243623.F, 228757.F,
  103967. 214798.F, 201691.F, 189384.F, 177828.F,
  103968. 166977.F, 156788.F, 147221.F, 138237.F,
  103969. 129802.F, 121881.F, 114444.F, 107461.F,
  103970. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103971. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103972. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103973. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103974. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103975. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103976. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103977. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103978. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103979. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103980. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103981. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103982. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103983. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103984. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103985. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103986. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103987. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103988. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103989. 842.910F, 791.475F, 743.179F, 697.830F,
  103990. 655.249F, 615.265F, 577.722F, 542.469F,
  103991. 509.367F, 478.286F, 449.101F, 421.696F,
  103992. 395.964F, 371.803F, 349.115F, 327.812F,
  103993. 307.809F, 289.026F, 271.390F, 254.830F,
  103994. 239.280F, 224.679F, 210.969F, 198.096F,
  103995. 186.008F, 174.658F, 164.000F, 153.993F,
  103996. 144.596F, 135.773F, 127.488F, 119.708F,
  103997. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103998. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103999. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  104000. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  104001. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  104002. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  104003. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  104004. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  104005. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  104006. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  104007. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  104008. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  104009. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  104010. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  104011. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  104012. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  104013. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  104014. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  104015. 1.20790F, 1.13419F, 1.06499F, 1.F
  104016. };
  104017. void _vp_remove_floor(vorbis_look_psy *p,
  104018. float *mdct,
  104019. int *codedflr,
  104020. float *residue,
  104021. int sliding_lowpass){
  104022. int i,n=p->n;
  104023. if(sliding_lowpass>n)sliding_lowpass=n;
  104024. for(i=0;i<sliding_lowpass;i++){
  104025. residue[i]=
  104026. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  104027. }
  104028. for(;i<n;i++)
  104029. residue[i]=0.;
  104030. }
  104031. void _vp_noisemask(vorbis_look_psy *p,
  104032. float *logmdct,
  104033. float *logmask){
  104034. int i,n=p->n;
  104035. float *work=(float*) alloca(n*sizeof(*work));
  104036. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  104037. 140.,-1);
  104038. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  104039. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  104040. p->vi->noisewindowfixed);
  104041. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  104042. #if 0
  104043. {
  104044. static int seq=0;
  104045. float work2[n];
  104046. for(i=0;i<n;i++){
  104047. work2[i]=logmask[i]+work[i];
  104048. }
  104049. if(seq&1)
  104050. _analysis_output("median2R",seq/2,work,n,1,0,0);
  104051. else
  104052. _analysis_output("median2L",seq/2,work,n,1,0,0);
  104053. if(seq&1)
  104054. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  104055. else
  104056. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  104057. seq++;
  104058. }
  104059. #endif
  104060. for(i=0;i<n;i++){
  104061. int dB=logmask[i]+.5;
  104062. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  104063. if(dB<0)dB=0;
  104064. logmask[i]= work[i]+p->vi->noisecompand[dB];
  104065. }
  104066. }
  104067. void _vp_tonemask(vorbis_look_psy *p,
  104068. float *logfft,
  104069. float *logmask,
  104070. float global_specmax,
  104071. float local_specmax){
  104072. int i,n=p->n;
  104073. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  104074. float att=local_specmax+p->vi->ath_adjatt;
  104075. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  104076. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  104077. for(i=0;i<n;i++)
  104078. logmask[i]=p->ath[i]+att;
  104079. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  104080. max_seeds(p,seed,logmask);
  104081. }
  104082. void _vp_offset_and_mix(vorbis_look_psy *p,
  104083. float *noise,
  104084. float *tone,
  104085. int offset_select,
  104086. float *logmask,
  104087. float *mdct,
  104088. float *logmdct){
  104089. int i,n=p->n;
  104090. float de, coeffi, cx;/* AoTuV */
  104091. float toneatt=p->vi->tone_masteratt[offset_select];
  104092. cx = p->m_val;
  104093. for(i=0;i<n;i++){
  104094. float val= noise[i]+p->noiseoffset[offset_select][i];
  104095. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  104096. logmask[i]=max(val,tone[i]+toneatt);
  104097. if(offset_select == 1) {
  104098. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104099. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104100. if(val > coeffi){
  104101. de = 1.0-((val-coeffi)*0.005*cx);
  104102. if(de < 0) de = 0.0001;
  104103. }else
  104104. de = 1.0-((val-coeffi)*0.0003*cx);
  104105. mdct[i] *= de;
  104106. }
  104107. }
  104108. }
  104109. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104110. vorbis_info *vi=vd->vi;
  104111. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104112. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104113. int n=ci->blocksizes[vd->W]/2;
  104114. float secs=(float)n/vi->rate;
  104115. amp+=secs*gi->ampmax_att_per_sec;
  104116. if(amp<-9999)amp=-9999;
  104117. return(amp);
  104118. }
  104119. static void couple_lossless(float A, float B,
  104120. float *qA, float *qB){
  104121. int test1=fabs(*qA)>fabs(*qB);
  104122. test1-= fabs(*qA)<fabs(*qB);
  104123. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104124. if(test1==1){
  104125. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104126. }else{
  104127. float temp=*qB;
  104128. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104129. *qA=temp;
  104130. }
  104131. if(*qB>fabs(*qA)*1.9999f){
  104132. *qB= -fabs(*qA)*2.f;
  104133. *qA= -*qA;
  104134. }
  104135. }
  104136. static float hypot_lookup[32]={
  104137. -0.009935, -0.011245, -0.012726, -0.014397,
  104138. -0.016282, -0.018407, -0.020800, -0.023494,
  104139. -0.026522, -0.029923, -0.033737, -0.038010,
  104140. -0.042787, -0.048121, -0.054064, -0.060671,
  104141. -0.068000, -0.076109, -0.085054, -0.094892,
  104142. -0.105675, -0.117451, -0.130260, -0.144134,
  104143. -0.159093, -0.175146, -0.192286, -0.210490,
  104144. -0.229718, -0.249913, -0.271001, -0.292893};
  104145. static void precomputed_couple_point(float premag,
  104146. int floorA,int floorB,
  104147. float *mag, float *ang){
  104148. int test=(floorA>floorB)-1;
  104149. int offset=31-abs(floorA-floorB);
  104150. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104151. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104152. *mag=premag*floormag;
  104153. *ang=0.f;
  104154. }
  104155. static float dipole_hypot(float a, float b){
  104156. if(a>0.){
  104157. if(b>0.)return sqrt(a*a+b*b);
  104158. if(a>-b)return sqrt(a*a-b*b);
  104159. return -sqrt(b*b-a*a);
  104160. }
  104161. if(b<0.)return -sqrt(a*a+b*b);
  104162. if(-a>b)return -sqrt(a*a-b*b);
  104163. return sqrt(b*b-a*a);
  104164. }
  104165. static float round_hypot(float a, float b){
  104166. if(a>0.){
  104167. if(b>0.)return sqrt(a*a+b*b);
  104168. if(a>-b)return sqrt(a*a+b*b);
  104169. return -sqrt(b*b+a*a);
  104170. }
  104171. if(b<0.)return -sqrt(a*a+b*b);
  104172. if(-a>b)return -sqrt(a*a+b*b);
  104173. return sqrt(b*b+a*a);
  104174. }
  104175. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104176. vorbis_info_psy_global *g,
  104177. vorbis_look_psy *p,
  104178. vorbis_info_mapping0 *vi,
  104179. float **mdct){
  104180. int i,j,n=p->n;
  104181. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104182. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104183. for(i=0;i<vi->coupling_steps;i++){
  104184. float *mdctM=mdct[vi->coupling_mag[i]];
  104185. float *mdctA=mdct[vi->coupling_ang[i]];
  104186. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104187. for(j=0;j<limit;j++)
  104188. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104189. for(;j<n;j++)
  104190. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104191. }
  104192. return(ret);
  104193. }
  104194. static int apsort(const void *a, const void *b){
  104195. float f1=fabs(**(float**)a);
  104196. float f2=fabs(**(float**)b);
  104197. return (f1<f2)-(f1>f2);
  104198. }
  104199. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104200. vorbis_look_psy *p,
  104201. vorbis_info_mapping0 *vi,
  104202. float **mags){
  104203. if(p->vi->normal_point_p){
  104204. int i,j,k,n=p->n;
  104205. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104206. int partition=p->vi->normal_partition;
  104207. float **work=(float**) alloca(sizeof(*work)*partition);
  104208. for(i=0;i<vi->coupling_steps;i++){
  104209. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104210. for(j=0;j<n;j+=partition){
  104211. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104212. qsort(work,partition,sizeof(*work),apsort);
  104213. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104214. }
  104215. }
  104216. return(ret);
  104217. }
  104218. return(NULL);
  104219. }
  104220. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104221. float *magnitudes,int *sortedindex){
  104222. int i,j,n=p->n;
  104223. vorbis_info_psy *vi=p->vi;
  104224. int partition=vi->normal_partition;
  104225. float **work=(float**) alloca(sizeof(*work)*partition);
  104226. int start=vi->normal_start;
  104227. for(j=start;j<n;j+=partition){
  104228. if(j+partition>n)partition=n-j;
  104229. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104230. qsort(work,partition,sizeof(*work),apsort);
  104231. for(i=0;i<partition;i++){
  104232. sortedindex[i+j-start]=work[i]-magnitudes;
  104233. }
  104234. }
  104235. }
  104236. void _vp_noise_normalize(vorbis_look_psy *p,
  104237. float *in,float *out,int *sortedindex){
  104238. int flag=0,i,j=0,n=p->n;
  104239. vorbis_info_psy *vi=p->vi;
  104240. int partition=vi->normal_partition;
  104241. int start=vi->normal_start;
  104242. if(start>n)start=n;
  104243. if(vi->normal_channel_p){
  104244. for(;j<start;j++)
  104245. out[j]=rint(in[j]);
  104246. for(;j+partition<=n;j+=partition){
  104247. float acc=0.;
  104248. int k;
  104249. for(i=j;i<j+partition;i++)
  104250. acc+=in[i]*in[i];
  104251. for(i=0;i<partition;i++){
  104252. k=sortedindex[i+j-start];
  104253. if(in[k]*in[k]>=.25f){
  104254. out[k]=rint(in[k]);
  104255. acc-=in[k]*in[k];
  104256. flag=1;
  104257. }else{
  104258. if(acc<vi->normal_thresh)break;
  104259. out[k]=unitnorm(in[k]);
  104260. acc-=1.;
  104261. }
  104262. }
  104263. for(;i<partition;i++){
  104264. k=sortedindex[i+j-start];
  104265. out[k]=0.;
  104266. }
  104267. }
  104268. }
  104269. for(;j<n;j++)
  104270. out[j]=rint(in[j]);
  104271. }
  104272. void _vp_couple(int blobno,
  104273. vorbis_info_psy_global *g,
  104274. vorbis_look_psy *p,
  104275. vorbis_info_mapping0 *vi,
  104276. float **res,
  104277. float **mag_memo,
  104278. int **mag_sort,
  104279. int **ifloor,
  104280. int *nonzero,
  104281. int sliding_lowpass){
  104282. int i,j,k,n=p->n;
  104283. for(i=0;i<vi->coupling_steps;i++){
  104284. if(nonzero[vi->coupling_mag[i]] ||
  104285. nonzero[vi->coupling_ang[i]]){
  104286. float *rM=res[vi->coupling_mag[i]];
  104287. float *rA=res[vi->coupling_ang[i]];
  104288. float *qM=rM+n;
  104289. float *qA=rA+n;
  104290. int *floorM=ifloor[vi->coupling_mag[i]];
  104291. int *floorA=ifloor[vi->coupling_ang[i]];
  104292. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104293. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104294. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104295. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104296. int pointlimit=limit;
  104297. nonzero[vi->coupling_mag[i]]=1;
  104298. nonzero[vi->coupling_ang[i]]=1;
  104299. if(n > 1000)
  104300. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104301. for(j=0;j<p->n;j+=partition){
  104302. float acc=0.f;
  104303. for(k=0;k<partition;k++){
  104304. int l=k+j;
  104305. if(l<sliding_lowpass){
  104306. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104307. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104308. precomputed_couple_point(mag_memo[i][l],
  104309. floorM[l],floorA[l],
  104310. qM+l,qA+l);
  104311. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104312. }else{
  104313. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104314. }
  104315. }else{
  104316. qM[l]=0.;
  104317. qA[l]=0.;
  104318. }
  104319. }
  104320. if(p->vi->normal_point_p){
  104321. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104322. int l=mag_sort[i][j+k];
  104323. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104324. qM[l]=unitnorm(qM[l]);
  104325. acc-=1.f;
  104326. }
  104327. }
  104328. }
  104329. }
  104330. }
  104331. }
  104332. }
  104333. void hf_reduction(vorbis_info_psy_global *g,
  104334. vorbis_look_psy *p,
  104335. vorbis_info_mapping0 *vi,
  104336. float **mdct){
  104337. int i,j,n=p->n, de=0.3*p->m_val;
  104338. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104339. for(i=0; i<vi->coupling_steps; i++){
  104340. for(j=limit; j<n; j++)
  104341. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104342. }
  104343. }
  104344. #endif
  104345. /*** End of inlined file: psy.c ***/
  104346. /*** Start of inlined file: registry.c ***/
  104347. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104348. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104349. // tasks..
  104350. #if JUCE_MSVC
  104351. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104352. #endif
  104353. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104354. #if JUCE_USE_OGGVORBIS
  104355. extern vorbis_func_floor floor0_exportbundle;
  104356. extern vorbis_func_floor floor1_exportbundle;
  104357. extern vorbis_func_residue residue0_exportbundle;
  104358. extern vorbis_func_residue residue1_exportbundle;
  104359. extern vorbis_func_residue residue2_exportbundle;
  104360. extern vorbis_func_mapping mapping0_exportbundle;
  104361. vorbis_func_floor *_floor_P[]={
  104362. &floor0_exportbundle,
  104363. &floor1_exportbundle,
  104364. };
  104365. vorbis_func_residue *_residue_P[]={
  104366. &residue0_exportbundle,
  104367. &residue1_exportbundle,
  104368. &residue2_exportbundle,
  104369. };
  104370. vorbis_func_mapping *_mapping_P[]={
  104371. &mapping0_exportbundle,
  104372. };
  104373. #endif
  104374. /*** End of inlined file: registry.c ***/
  104375. /*** Start of inlined file: res0.c ***/
  104376. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104377. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104378. // tasks..
  104379. #if JUCE_MSVC
  104380. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104381. #endif
  104382. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104383. #if JUCE_USE_OGGVORBIS
  104384. #include <stdlib.h>
  104385. #include <string.h>
  104386. #include <math.h>
  104387. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104388. #include <stdio.h>
  104389. #endif
  104390. typedef struct {
  104391. vorbis_info_residue0 *info;
  104392. int parts;
  104393. int stages;
  104394. codebook *fullbooks;
  104395. codebook *phrasebook;
  104396. codebook ***partbooks;
  104397. int partvals;
  104398. int **decodemap;
  104399. long postbits;
  104400. long phrasebits;
  104401. long frames;
  104402. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104403. int train_seq;
  104404. long *training_data[8][64];
  104405. float training_max[8][64];
  104406. float training_min[8][64];
  104407. float tmin;
  104408. float tmax;
  104409. #endif
  104410. } vorbis_look_residue0;
  104411. void res0_free_info(vorbis_info_residue *i){
  104412. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104413. if(info){
  104414. memset(info,0,sizeof(*info));
  104415. _ogg_free(info);
  104416. }
  104417. }
  104418. void res0_free_look(vorbis_look_residue *i){
  104419. int j;
  104420. if(i){
  104421. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104422. #ifdef TRAIN_RES
  104423. {
  104424. int j,k,l;
  104425. for(j=0;j<look->parts;j++){
  104426. for(k=0;k<8;k++)
  104427. if(look->training_data[k][j]){
  104428. char buffer[80];
  104429. FILE *of;
  104430. codebook *statebook=look->partbooks[j][k];
  104431. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104432. of=fopen(buffer,"a");
  104433. for(l=0;l<statebook->entries;l++)
  104434. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104435. fclose(of);
  104436. _ogg_free(look->training_data[k][j]);
  104437. look->training_data[k][j]=NULL;
  104438. }
  104439. }
  104440. }
  104441. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104442. #endif
  104443. for(j=0;j<look->parts;j++)
  104444. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104445. _ogg_free(look->partbooks);
  104446. for(j=0;j<look->partvals;j++)
  104447. _ogg_free(look->decodemap[j]);
  104448. _ogg_free(look->decodemap);
  104449. memset(look,0,sizeof(*look));
  104450. _ogg_free(look);
  104451. }
  104452. }
  104453. static int icount(unsigned int v){
  104454. int ret=0;
  104455. while(v){
  104456. ret+=v&1;
  104457. v>>=1;
  104458. }
  104459. return(ret);
  104460. }
  104461. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104462. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104463. int j,acc=0;
  104464. oggpack_write(opb,info->begin,24);
  104465. oggpack_write(opb,info->end,24);
  104466. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104467. code with a partitioned book */
  104468. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104469. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104470. for(j=0;j<info->partitions;j++){
  104471. if(ilog(info->secondstages[j])>3){
  104472. oggpack_write(opb,info->secondstages[j],3);
  104473. oggpack_write(opb,1,1);
  104474. oggpack_write(opb,info->secondstages[j]>>3,5);
  104475. }else
  104476. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104477. acc+=icount(info->secondstages[j]);
  104478. }
  104479. for(j=0;j<acc;j++)
  104480. oggpack_write(opb,info->booklist[j],8);
  104481. }
  104482. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104483. int j,acc=0;
  104484. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104485. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104486. info->begin=oggpack_read(opb,24);
  104487. info->end=oggpack_read(opb,24);
  104488. info->grouping=oggpack_read(opb,24)+1;
  104489. info->partitions=oggpack_read(opb,6)+1;
  104490. info->groupbook=oggpack_read(opb,8);
  104491. for(j=0;j<info->partitions;j++){
  104492. int cascade=oggpack_read(opb,3);
  104493. if(oggpack_read(opb,1))
  104494. cascade|=(oggpack_read(opb,5)<<3);
  104495. info->secondstages[j]=cascade;
  104496. acc+=icount(cascade);
  104497. }
  104498. for(j=0;j<acc;j++)
  104499. info->booklist[j]=oggpack_read(opb,8);
  104500. if(info->groupbook>=ci->books)goto errout;
  104501. for(j=0;j<acc;j++)
  104502. if(info->booklist[j]>=ci->books)goto errout;
  104503. return(info);
  104504. errout:
  104505. res0_free_info(info);
  104506. return(NULL);
  104507. }
  104508. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104509. vorbis_info_residue *vr){
  104510. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104511. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104512. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104513. int j,k,acc=0;
  104514. int dim;
  104515. int maxstage=0;
  104516. look->info=info;
  104517. look->parts=info->partitions;
  104518. look->fullbooks=ci->fullbooks;
  104519. look->phrasebook=ci->fullbooks+info->groupbook;
  104520. dim=look->phrasebook->dim;
  104521. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104522. for(j=0;j<look->parts;j++){
  104523. int stages=ilog(info->secondstages[j]);
  104524. if(stages){
  104525. if(stages>maxstage)maxstage=stages;
  104526. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104527. for(k=0;k<stages;k++)
  104528. if(info->secondstages[j]&(1<<k)){
  104529. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104530. #ifdef TRAIN_RES
  104531. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104532. sizeof(***look->training_data));
  104533. #endif
  104534. }
  104535. }
  104536. }
  104537. look->partvals=rint(pow((float)look->parts,(float)dim));
  104538. look->stages=maxstage;
  104539. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104540. for(j=0;j<look->partvals;j++){
  104541. long val=j;
  104542. long mult=look->partvals/look->parts;
  104543. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104544. for(k=0;k<dim;k++){
  104545. long deco=val/mult;
  104546. val-=deco*mult;
  104547. mult/=look->parts;
  104548. look->decodemap[j][k]=deco;
  104549. }
  104550. }
  104551. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104552. {
  104553. static int train_seq=0;
  104554. look->train_seq=train_seq++;
  104555. }
  104556. #endif
  104557. return(look);
  104558. }
  104559. static int local_book_besterror(codebook *book,float *a){
  104560. int dim=book->dim,i,k,o;
  104561. int best=0;
  104562. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104563. for(k=0,o=dim;k<dim;++k){
  104564. float val=a[--o];
  104565. i=tt->threshvals>>1;
  104566. if(val<tt->quantthresh[i]){
  104567. if(val<tt->quantthresh[i-1]){
  104568. for(--i;i>0;--i)
  104569. if(val>=tt->quantthresh[i-1])
  104570. break;
  104571. }
  104572. }else{
  104573. for(++i;i<tt->threshvals-1;++i)
  104574. if(val<tt->quantthresh[i])break;
  104575. }
  104576. best=(best*tt->quantvals)+tt->quantmap[i];
  104577. }
  104578. if(book->c->lengthlist[best]<=0){
  104579. const static_codebook *c=book->c;
  104580. int i,j;
  104581. float bestf=0.f;
  104582. float *e=book->valuelist;
  104583. best=-1;
  104584. for(i=0;i<book->entries;i++){
  104585. if(c->lengthlist[i]>0){
  104586. float thisx=0.f;
  104587. for(j=0;j<dim;j++){
  104588. float val=(e[j]-a[j]);
  104589. thisx+=val*val;
  104590. }
  104591. if(best==-1 || thisx<bestf){
  104592. bestf=thisx;
  104593. best=i;
  104594. }
  104595. }
  104596. e+=dim;
  104597. }
  104598. }
  104599. {
  104600. float *ptr=book->valuelist+best*dim;
  104601. for(i=0;i<dim;i++)
  104602. *a++ -= *ptr++;
  104603. }
  104604. return(best);
  104605. }
  104606. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104607. codebook *book,long *acc){
  104608. int i,bits=0;
  104609. int dim=book->dim;
  104610. int step=n/dim;
  104611. for(i=0;i<step;i++){
  104612. int entry=local_book_besterror(book,vec+i*dim);
  104613. #ifdef TRAIN_RES
  104614. acc[entry]++;
  104615. #endif
  104616. bits+=vorbis_book_encode(book,entry,opb);
  104617. }
  104618. return(bits);
  104619. }
  104620. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104621. float **in,int ch){
  104622. long i,j,k;
  104623. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104624. vorbis_info_residue0 *info=look->info;
  104625. int samples_per_partition=info->grouping;
  104626. int possible_partitions=info->partitions;
  104627. int n=info->end-info->begin;
  104628. int partvals=n/samples_per_partition;
  104629. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104630. float scale=100./samples_per_partition;
  104631. for(i=0;i<ch;i++){
  104632. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104633. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104634. }
  104635. for(i=0;i<partvals;i++){
  104636. int offset=i*samples_per_partition+info->begin;
  104637. for(j=0;j<ch;j++){
  104638. float max=0.;
  104639. float ent=0.;
  104640. for(k=0;k<samples_per_partition;k++){
  104641. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104642. ent+=fabs(rint(in[j][offset+k]));
  104643. }
  104644. ent*=scale;
  104645. for(k=0;k<possible_partitions-1;k++)
  104646. if(max<=info->classmetric1[k] &&
  104647. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104648. break;
  104649. partword[j][i]=k;
  104650. }
  104651. }
  104652. #ifdef TRAIN_RESAUX
  104653. {
  104654. FILE *of;
  104655. char buffer[80];
  104656. for(i=0;i<ch;i++){
  104657. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104658. of=fopen(buffer,"a");
  104659. for(j=0;j<partvals;j++)
  104660. fprintf(of,"%ld, ",partword[i][j]);
  104661. fprintf(of,"\n");
  104662. fclose(of);
  104663. }
  104664. }
  104665. #endif
  104666. look->frames++;
  104667. return(partword);
  104668. }
  104669. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104670. int ch){
  104671. long i,j,k,l;
  104672. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104673. vorbis_info_residue0 *info=look->info;
  104674. int samples_per_partition=info->grouping;
  104675. int possible_partitions=info->partitions;
  104676. int n=info->end-info->begin;
  104677. int partvals=n/samples_per_partition;
  104678. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104679. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104680. FILE *of;
  104681. char buffer[80];
  104682. #endif
  104683. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104684. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104685. for(i=0,l=info->begin/ch;i<partvals;i++){
  104686. float magmax=0.f;
  104687. float angmax=0.f;
  104688. for(j=0;j<samples_per_partition;j+=ch){
  104689. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104690. for(k=1;k<ch;k++)
  104691. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104692. l++;
  104693. }
  104694. for(j=0;j<possible_partitions-1;j++)
  104695. if(magmax<=info->classmetric1[j] &&
  104696. angmax<=info->classmetric2[j])
  104697. break;
  104698. partword[0][i]=j;
  104699. }
  104700. #ifdef TRAIN_RESAUX
  104701. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104702. of=fopen(buffer,"a");
  104703. for(i=0;i<partvals;i++)
  104704. fprintf(of,"%ld, ",partword[0][i]);
  104705. fprintf(of,"\n");
  104706. fclose(of);
  104707. #endif
  104708. look->frames++;
  104709. return(partword);
  104710. }
  104711. static int _01forward(oggpack_buffer *opb,
  104712. vorbis_block *vb,vorbis_look_residue *vl,
  104713. float **in,int ch,
  104714. long **partword,
  104715. int (*encode)(oggpack_buffer *,float *,int,
  104716. codebook *,long *)){
  104717. long i,j,k,s;
  104718. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104719. vorbis_info_residue0 *info=look->info;
  104720. int samples_per_partition=info->grouping;
  104721. int possible_partitions=info->partitions;
  104722. int partitions_per_word=look->phrasebook->dim;
  104723. int n=info->end-info->begin;
  104724. int partvals=n/samples_per_partition;
  104725. long resbits[128];
  104726. long resvals[128];
  104727. #ifdef TRAIN_RES
  104728. for(i=0;i<ch;i++)
  104729. for(j=info->begin;j<info->end;j++){
  104730. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104731. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104732. }
  104733. #endif
  104734. memset(resbits,0,sizeof(resbits));
  104735. memset(resvals,0,sizeof(resvals));
  104736. for(s=0;s<look->stages;s++){
  104737. for(i=0;i<partvals;){
  104738. if(s==0){
  104739. for(j=0;j<ch;j++){
  104740. long val=partword[j][i];
  104741. for(k=1;k<partitions_per_word;k++){
  104742. val*=possible_partitions;
  104743. if(i+k<partvals)
  104744. val+=partword[j][i+k];
  104745. }
  104746. if(val<look->phrasebook->entries)
  104747. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104748. #if 0 /*def TRAIN_RES*/
  104749. else
  104750. fprintf(stderr,"!");
  104751. #endif
  104752. }
  104753. }
  104754. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104755. long offset=i*samples_per_partition+info->begin;
  104756. for(j=0;j<ch;j++){
  104757. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104758. if(info->secondstages[partword[j][i]]&(1<<s)){
  104759. codebook *statebook=look->partbooks[partword[j][i]][s];
  104760. if(statebook){
  104761. int ret;
  104762. long *accumulator=NULL;
  104763. #ifdef TRAIN_RES
  104764. accumulator=look->training_data[s][partword[j][i]];
  104765. {
  104766. int l;
  104767. float *samples=in[j]+offset;
  104768. for(l=0;l<samples_per_partition;l++){
  104769. if(samples[l]<look->training_min[s][partword[j][i]])
  104770. look->training_min[s][partword[j][i]]=samples[l];
  104771. if(samples[l]>look->training_max[s][partword[j][i]])
  104772. look->training_max[s][partword[j][i]]=samples[l];
  104773. }
  104774. }
  104775. #endif
  104776. ret=encode(opb,in[j]+offset,samples_per_partition,
  104777. statebook,accumulator);
  104778. look->postbits+=ret;
  104779. resbits[partword[j][i]]+=ret;
  104780. }
  104781. }
  104782. }
  104783. }
  104784. }
  104785. }
  104786. return(0);
  104787. }
  104788. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104789. float **in,int ch,
  104790. long (*decodepart)(codebook *, float *,
  104791. oggpack_buffer *,int)){
  104792. long i,j,k,l,s;
  104793. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104794. vorbis_info_residue0 *info=look->info;
  104795. int samples_per_partition=info->grouping;
  104796. int partitions_per_word=look->phrasebook->dim;
  104797. int n=info->end-info->begin;
  104798. int partvals=n/samples_per_partition;
  104799. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104800. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104801. for(j=0;j<ch;j++)
  104802. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104803. for(s=0;s<look->stages;s++){
  104804. for(i=0,l=0;i<partvals;l++){
  104805. if(s==0){
  104806. for(j=0;j<ch;j++){
  104807. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104808. if(temp==-1)goto eopbreak;
  104809. partword[j][l]=look->decodemap[temp];
  104810. if(partword[j][l]==NULL)goto errout;
  104811. }
  104812. }
  104813. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104814. for(j=0;j<ch;j++){
  104815. long offset=info->begin+i*samples_per_partition;
  104816. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104817. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104818. if(stagebook){
  104819. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104820. samples_per_partition)==-1)goto eopbreak;
  104821. }
  104822. }
  104823. }
  104824. }
  104825. }
  104826. errout:
  104827. eopbreak:
  104828. return(0);
  104829. }
  104830. #if 0
  104831. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104832. float **in,int *nonzero,int ch){
  104833. int i,used=0;
  104834. for(i=0;i<ch;i++)
  104835. if(nonzero[i])
  104836. in[used++]=in[i];
  104837. if(used)
  104838. return(_01class(vb,vl,in,used));
  104839. else
  104840. return(0);
  104841. }
  104842. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104843. float **in,float **out,int *nonzero,int ch,
  104844. long **partword){
  104845. int i,j,used=0,n=vb->pcmend/2;
  104846. for(i=0;i<ch;i++)
  104847. if(nonzero[i]){
  104848. if(out)
  104849. for(j=0;j<n;j++)
  104850. out[i][j]+=in[i][j];
  104851. in[used++]=in[i];
  104852. }
  104853. if(used){
  104854. int ret=_01forward(vb,vl,in,used,partword,
  104855. _interleaved_encodepart);
  104856. if(out){
  104857. used=0;
  104858. for(i=0;i<ch;i++)
  104859. if(nonzero[i]){
  104860. for(j=0;j<n;j++)
  104861. out[i][j]-=in[used][j];
  104862. used++;
  104863. }
  104864. }
  104865. return(ret);
  104866. }else{
  104867. return(0);
  104868. }
  104869. }
  104870. #endif
  104871. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104872. float **in,int *nonzero,int ch){
  104873. int i,used=0;
  104874. for(i=0;i<ch;i++)
  104875. if(nonzero[i])
  104876. in[used++]=in[i];
  104877. if(used)
  104878. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104879. else
  104880. return(0);
  104881. }
  104882. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104883. float **in,float **out,int *nonzero,int ch,
  104884. long **partword){
  104885. int i,j,used=0,n=vb->pcmend/2;
  104886. for(i=0;i<ch;i++)
  104887. if(nonzero[i]){
  104888. if(out)
  104889. for(j=0;j<n;j++)
  104890. out[i][j]+=in[i][j];
  104891. in[used++]=in[i];
  104892. }
  104893. if(used){
  104894. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104895. if(out){
  104896. used=0;
  104897. for(i=0;i<ch;i++)
  104898. if(nonzero[i]){
  104899. for(j=0;j<n;j++)
  104900. out[i][j]-=in[used][j];
  104901. used++;
  104902. }
  104903. }
  104904. return(ret);
  104905. }else{
  104906. return(0);
  104907. }
  104908. }
  104909. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104910. float **in,int *nonzero,int ch){
  104911. int i,used=0;
  104912. for(i=0;i<ch;i++)
  104913. if(nonzero[i])
  104914. in[used++]=in[i];
  104915. if(used)
  104916. return(_01class(vb,vl,in,used));
  104917. else
  104918. return(0);
  104919. }
  104920. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104921. float **in,int *nonzero,int ch){
  104922. int i,used=0;
  104923. for(i=0;i<ch;i++)
  104924. if(nonzero[i])
  104925. in[used++]=in[i];
  104926. if(used)
  104927. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104928. else
  104929. return(0);
  104930. }
  104931. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104932. float **in,int *nonzero,int ch){
  104933. int i,used=0;
  104934. for(i=0;i<ch;i++)
  104935. if(nonzero[i])used++;
  104936. if(used)
  104937. return(_2class(vb,vl,in,ch));
  104938. else
  104939. return(0);
  104940. }
  104941. int res2_forward(oggpack_buffer *opb,
  104942. vorbis_block *vb,vorbis_look_residue *vl,
  104943. float **in,float **out,int *nonzero,int ch,
  104944. long **partword){
  104945. long i,j,k,n=vb->pcmend/2,used=0;
  104946. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104947. for(i=0;i<ch;i++){
  104948. float *pcm=in[i];
  104949. if(nonzero[i])used++;
  104950. for(j=0,k=i;j<n;j++,k+=ch)
  104951. work[k]=pcm[j];
  104952. }
  104953. if(used){
  104954. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104955. if(out){
  104956. for(i=0;i<ch;i++){
  104957. float *pcm=in[i];
  104958. float *sofar=out[i];
  104959. for(j=0,k=i;j<n;j++,k+=ch)
  104960. sofar[j]+=pcm[j]-work[k];
  104961. }
  104962. }
  104963. return(ret);
  104964. }else{
  104965. return(0);
  104966. }
  104967. }
  104968. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104969. float **in,int *nonzero,int ch){
  104970. long i,k,l,s;
  104971. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104972. vorbis_info_residue0 *info=look->info;
  104973. int samples_per_partition=info->grouping;
  104974. int partitions_per_word=look->phrasebook->dim;
  104975. int n=info->end-info->begin;
  104976. int partvals=n/samples_per_partition;
  104977. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104978. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104979. for(i=0;i<ch;i++)if(nonzero[i])break;
  104980. if(i==ch)return(0); /* no nonzero vectors */
  104981. for(s=0;s<look->stages;s++){
  104982. for(i=0,l=0;i<partvals;l++){
  104983. if(s==0){
  104984. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104985. if(temp==-1)goto eopbreak;
  104986. partword[l]=look->decodemap[temp];
  104987. if(partword[l]==NULL)goto errout;
  104988. }
  104989. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104990. if(info->secondstages[partword[l][k]]&(1<<s)){
  104991. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104992. if(stagebook){
  104993. if(vorbis_book_decodevv_add(stagebook,in,
  104994. i*samples_per_partition+info->begin,ch,
  104995. &vb->opb,samples_per_partition)==-1)
  104996. goto eopbreak;
  104997. }
  104998. }
  104999. }
  105000. }
  105001. errout:
  105002. eopbreak:
  105003. return(0);
  105004. }
  105005. vorbis_func_residue residue0_exportbundle={
  105006. NULL,
  105007. &res0_unpack,
  105008. &res0_look,
  105009. &res0_free_info,
  105010. &res0_free_look,
  105011. NULL,
  105012. NULL,
  105013. &res0_inverse
  105014. };
  105015. vorbis_func_residue residue1_exportbundle={
  105016. &res0_pack,
  105017. &res0_unpack,
  105018. &res0_look,
  105019. &res0_free_info,
  105020. &res0_free_look,
  105021. &res1_class,
  105022. &res1_forward,
  105023. &res1_inverse
  105024. };
  105025. vorbis_func_residue residue2_exportbundle={
  105026. &res0_pack,
  105027. &res0_unpack,
  105028. &res0_look,
  105029. &res0_free_info,
  105030. &res0_free_look,
  105031. &res2_class,
  105032. &res2_forward,
  105033. &res2_inverse
  105034. };
  105035. #endif
  105036. /*** End of inlined file: res0.c ***/
  105037. /*** Start of inlined file: sharedbook.c ***/
  105038. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105039. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105040. // tasks..
  105041. #if JUCE_MSVC
  105042. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105043. #endif
  105044. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105045. #if JUCE_USE_OGGVORBIS
  105046. #include <stdlib.h>
  105047. #include <math.h>
  105048. #include <string.h>
  105049. int _ilog(unsigned int v){
  105050. int ret=0;
  105051. while(v){
  105052. ret++;
  105053. v>>=1;
  105054. }
  105055. return(ret);
  105056. }
  105057. #define VQ_FEXP 10
  105058. #define VQ_FMAN 21
  105059. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  105060. long _float32_pack(float val){
  105061. int sign=0;
  105062. long exp;
  105063. long mant;
  105064. if(val<0){
  105065. sign=0x80000000;
  105066. val= -val;
  105067. }
  105068. exp= floor(log(val)/log(2.f));
  105069. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  105070. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  105071. return(sign|exp|mant);
  105072. }
  105073. float _float32_unpack(long val){
  105074. double mant=val&0x1fffff;
  105075. int sign=val&0x80000000;
  105076. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  105077. if(sign)mant= -mant;
  105078. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  105079. }
  105080. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  105081. long i,j,count=0;
  105082. ogg_uint32_t marker[33];
  105083. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  105084. memset(marker,0,sizeof(marker));
  105085. for(i=0;i<n;i++){
  105086. long length=l[i];
  105087. if(length>0){
  105088. ogg_uint32_t entry=marker[length];
  105089. if(length<32 && (entry>>length)){
  105090. _ogg_free(r);
  105091. return(NULL);
  105092. }
  105093. r[count++]=entry;
  105094. {
  105095. for(j=length;j>0;j--){
  105096. if(marker[j]&1){
  105097. if(j==1)
  105098. marker[1]++;
  105099. else
  105100. marker[j]=marker[j-1]<<1;
  105101. break; /* invariant says next upper marker would already
  105102. have been moved if it was on the same path */
  105103. }
  105104. marker[j]++;
  105105. }
  105106. }
  105107. for(j=length+1;j<33;j++)
  105108. if((marker[j]>>1) == entry){
  105109. entry=marker[j];
  105110. marker[j]=marker[j-1]<<1;
  105111. }else
  105112. break;
  105113. }else
  105114. if(sparsecount==0)count++;
  105115. }
  105116. for(i=0,count=0;i<n;i++){
  105117. ogg_uint32_t temp=0;
  105118. for(j=0;j<l[i];j++){
  105119. temp<<=1;
  105120. temp|=(r[count]>>j)&1;
  105121. }
  105122. if(sparsecount){
  105123. if(l[i])
  105124. r[count++]=temp;
  105125. }else
  105126. r[count++]=temp;
  105127. }
  105128. return(r);
  105129. }
  105130. long _book_maptype1_quantvals(const static_codebook *b){
  105131. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105132. while(1){
  105133. long acc=1;
  105134. long acc1=1;
  105135. int i;
  105136. for(i=0;i<b->dim;i++){
  105137. acc*=vals;
  105138. acc1*=vals+1;
  105139. }
  105140. if(acc<=b->entries && acc1>b->entries){
  105141. return(vals);
  105142. }else{
  105143. if(acc>b->entries){
  105144. vals--;
  105145. }else{
  105146. vals++;
  105147. }
  105148. }
  105149. }
  105150. }
  105151. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105152. long j,k,count=0;
  105153. if(b->maptype==1 || b->maptype==2){
  105154. int quantvals;
  105155. float mindel=_float32_unpack(b->q_min);
  105156. float delta=_float32_unpack(b->q_delta);
  105157. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105158. switch(b->maptype){
  105159. case 1:
  105160. quantvals=_book_maptype1_quantvals(b);
  105161. for(j=0;j<b->entries;j++){
  105162. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105163. float last=0.f;
  105164. int indexdiv=1;
  105165. for(k=0;k<b->dim;k++){
  105166. int index= (j/indexdiv)%quantvals;
  105167. float val=b->quantlist[index];
  105168. val=fabs(val)*delta+mindel+last;
  105169. if(b->q_sequencep)last=val;
  105170. if(sparsemap)
  105171. r[sparsemap[count]*b->dim+k]=val;
  105172. else
  105173. r[count*b->dim+k]=val;
  105174. indexdiv*=quantvals;
  105175. }
  105176. count++;
  105177. }
  105178. }
  105179. break;
  105180. case 2:
  105181. for(j=0;j<b->entries;j++){
  105182. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105183. float last=0.f;
  105184. for(k=0;k<b->dim;k++){
  105185. float val=b->quantlist[j*b->dim+k];
  105186. val=fabs(val)*delta+mindel+last;
  105187. if(b->q_sequencep)last=val;
  105188. if(sparsemap)
  105189. r[sparsemap[count]*b->dim+k]=val;
  105190. else
  105191. r[count*b->dim+k]=val;
  105192. }
  105193. count++;
  105194. }
  105195. }
  105196. break;
  105197. }
  105198. return(r);
  105199. }
  105200. return(NULL);
  105201. }
  105202. void vorbis_staticbook_clear(static_codebook *b){
  105203. if(b->allocedp){
  105204. if(b->quantlist)_ogg_free(b->quantlist);
  105205. if(b->lengthlist)_ogg_free(b->lengthlist);
  105206. if(b->nearest_tree){
  105207. _ogg_free(b->nearest_tree->ptr0);
  105208. _ogg_free(b->nearest_tree->ptr1);
  105209. _ogg_free(b->nearest_tree->p);
  105210. _ogg_free(b->nearest_tree->q);
  105211. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105212. _ogg_free(b->nearest_tree);
  105213. }
  105214. if(b->thresh_tree){
  105215. _ogg_free(b->thresh_tree->quantthresh);
  105216. _ogg_free(b->thresh_tree->quantmap);
  105217. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105218. _ogg_free(b->thresh_tree);
  105219. }
  105220. memset(b,0,sizeof(*b));
  105221. }
  105222. }
  105223. void vorbis_staticbook_destroy(static_codebook *b){
  105224. if(b->allocedp){
  105225. vorbis_staticbook_clear(b);
  105226. _ogg_free(b);
  105227. }
  105228. }
  105229. void vorbis_book_clear(codebook *b){
  105230. if(b->valuelist)_ogg_free(b->valuelist);
  105231. if(b->codelist)_ogg_free(b->codelist);
  105232. if(b->dec_index)_ogg_free(b->dec_index);
  105233. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105234. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105235. memset(b,0,sizeof(*b));
  105236. }
  105237. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105238. memset(c,0,sizeof(*c));
  105239. c->c=s;
  105240. c->entries=s->entries;
  105241. c->used_entries=s->entries;
  105242. c->dim=s->dim;
  105243. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105244. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105245. return(0);
  105246. }
  105247. static int sort32a(const void *a,const void *b){
  105248. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105249. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105250. }
  105251. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105252. int i,j,n=0,tabn;
  105253. int *sortindex;
  105254. memset(c,0,sizeof(*c));
  105255. for(i=0;i<s->entries;i++)
  105256. if(s->lengthlist[i]>0)
  105257. n++;
  105258. c->entries=s->entries;
  105259. c->used_entries=n;
  105260. c->dim=s->dim;
  105261. {
  105262. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105263. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105264. if(codes==NULL)goto err_out;
  105265. for(i=0;i<n;i++){
  105266. codes[i]=ogg_bitreverse(codes[i]);
  105267. codep[i]=codes+i;
  105268. }
  105269. qsort(codep,n,sizeof(*codep),sort32a);
  105270. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105271. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105272. for(i=0;i<n;i++){
  105273. int position=codep[i]-codes;
  105274. sortindex[position]=i;
  105275. }
  105276. for(i=0;i<n;i++)
  105277. c->codelist[sortindex[i]]=codes[i];
  105278. _ogg_free(codes);
  105279. }
  105280. c->valuelist=_book_unquantize(s,n,sortindex);
  105281. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105282. for(n=0,i=0;i<s->entries;i++)
  105283. if(s->lengthlist[i]>0)
  105284. c->dec_index[sortindex[n++]]=i;
  105285. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105286. for(n=0,i=0;i<s->entries;i++)
  105287. if(s->lengthlist[i]>0)
  105288. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105289. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105290. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105291. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105292. tabn=1<<c->dec_firsttablen;
  105293. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105294. c->dec_maxlength=0;
  105295. for(i=0;i<n;i++){
  105296. if(c->dec_maxlength<c->dec_codelengths[i])
  105297. c->dec_maxlength=c->dec_codelengths[i];
  105298. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105299. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105300. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105301. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105302. }
  105303. }
  105304. {
  105305. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105306. long lo=0,hi=0;
  105307. for(i=0;i<tabn;i++){
  105308. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105309. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105310. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105311. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105312. {
  105313. unsigned long loval=lo;
  105314. unsigned long hival=n-hi;
  105315. if(loval>0x7fff)loval=0x7fff;
  105316. if(hival>0x7fff)hival=0x7fff;
  105317. c->dec_firsttable[ogg_bitreverse(word)]=
  105318. 0x80000000UL | (loval<<15) | hival;
  105319. }
  105320. }
  105321. }
  105322. }
  105323. return(0);
  105324. err_out:
  105325. vorbis_book_clear(c);
  105326. return(-1);
  105327. }
  105328. static float _dist(int el,float *ref, float *b,int step){
  105329. int i;
  105330. float acc=0.f;
  105331. for(i=0;i<el;i++){
  105332. float val=(ref[i]-b[i*step]);
  105333. acc+=val*val;
  105334. }
  105335. return(acc);
  105336. }
  105337. int _best(codebook *book, float *a, int step){
  105338. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105339. #if 0
  105340. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105341. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105342. #endif
  105343. int dim=book->dim;
  105344. int k,o;
  105345. if(tt){
  105346. int index=0,i;
  105347. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105348. i=tt->threshvals>>1;
  105349. if(a[o]<tt->quantthresh[i]){
  105350. for(;i>0;i--)
  105351. if(a[o]>=tt->quantthresh[i-1])
  105352. break;
  105353. }else{
  105354. for(i++;i<tt->threshvals-1;i++)
  105355. if(a[o]<tt->quantthresh[i])break;
  105356. }
  105357. index=(index*tt->quantvals)+tt->quantmap[i];
  105358. }
  105359. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105360. use a decision tree after all
  105361. and fall through*/
  105362. return(index);
  105363. }
  105364. #if 0
  105365. if(pt){
  105366. const static_codebook *c=book->c;
  105367. int i,besti=-1;
  105368. float best=0.f;
  105369. int entry=0;
  105370. if(c->q_sequencep){
  105371. int pv;
  105372. long mul=1;
  105373. float qlast=0;
  105374. for(k=0,o=0;k<dim;k++,o+=step){
  105375. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105376. if(pv<0 || pv>=pt->mapentries)break;
  105377. entry+=pt->pigeonmap[pv]*mul;
  105378. mul*=pt->quantvals;
  105379. qlast+=pv*pt->del+pt->min;
  105380. }
  105381. }else{
  105382. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105383. int pv=(int)((a[o]-pt->min)/pt->del);
  105384. if(pv<0 || pv>=pt->mapentries)break;
  105385. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105386. }
  105387. }
  105388. if(k==dim && pt->fitlength[entry]){
  105389. long *list=pt->fitlist+pt->fitmap[entry];
  105390. for(i=0;i<pt->fitlength[entry];i++){
  105391. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105392. if(besti==-1 || this<best){
  105393. best=this;
  105394. besti=list[i];
  105395. }
  105396. }
  105397. return(besti);
  105398. }
  105399. }
  105400. if(nt){
  105401. while(1){
  105402. float c=0.f;
  105403. float *p=book->valuelist+nt->p[ptr];
  105404. float *q=book->valuelist+nt->q[ptr];
  105405. for(k=0,o=0;k<dim;k++,o+=step)
  105406. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105407. if(c>0.f) /* in A */
  105408. ptr= -nt->ptr0[ptr];
  105409. else /* in B */
  105410. ptr= -nt->ptr1[ptr];
  105411. if(ptr<=0)break;
  105412. }
  105413. return(-ptr);
  105414. }
  105415. #endif
  105416. {
  105417. const static_codebook *c=book->c;
  105418. int i,besti=-1;
  105419. float best=0.f;
  105420. float *e=book->valuelist;
  105421. for(i=0;i<book->entries;i++){
  105422. if(c->lengthlist[i]>0){
  105423. float thisx=_dist(dim,e,a,step);
  105424. if(besti==-1 || thisx<best){
  105425. best=thisx;
  105426. besti=i;
  105427. }
  105428. }
  105429. e+=dim;
  105430. }
  105431. return(besti);
  105432. }
  105433. }
  105434. long vorbis_book_codeword(codebook *book,int entry){
  105435. if(book->c) /* only use with encode; decode optimizations are
  105436. allowed to break this */
  105437. return book->codelist[entry];
  105438. return -1;
  105439. }
  105440. long vorbis_book_codelen(codebook *book,int entry){
  105441. if(book->c) /* only use with encode; decode optimizations are
  105442. allowed to break this */
  105443. return book->c->lengthlist[entry];
  105444. return -1;
  105445. }
  105446. #ifdef _V_SELFTEST
  105447. #include <stdio.h>
  105448. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105449. static long partial_quantlist1[]={0,7,2};
  105450. static_codebook test1={
  105451. 4,16,
  105452. NULL,
  105453. 0,
  105454. 0,0,0,0,
  105455. NULL,
  105456. NULL,NULL
  105457. };
  105458. static float *test1_result=NULL;
  105459. static_codebook test2={
  105460. 4,3,
  105461. NULL,
  105462. 2,
  105463. -533200896,1611661312,4,0,
  105464. full_quantlist1,
  105465. NULL,NULL
  105466. };
  105467. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105468. static_codebook test3={
  105469. 4,3,
  105470. NULL,
  105471. 2,
  105472. -533200896,1611661312,4,1,
  105473. full_quantlist1,
  105474. NULL,NULL
  105475. };
  105476. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105477. static_codebook test4={
  105478. 3,27,
  105479. NULL,
  105480. 1,
  105481. -533200896,1611661312,4,0,
  105482. partial_quantlist1,
  105483. NULL,NULL
  105484. };
  105485. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105486. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105487. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105488. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105489. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105490. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105491. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105492. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105493. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105494. static_codebook test5={
  105495. 3,27,
  105496. NULL,
  105497. 1,
  105498. -533200896,1611661312,4,1,
  105499. partial_quantlist1,
  105500. NULL,NULL
  105501. };
  105502. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105503. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105504. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105505. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105506. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105507. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105508. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105509. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105510. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105511. void run_test(static_codebook *b,float *comp){
  105512. float *out=_book_unquantize(b,b->entries,NULL);
  105513. int i;
  105514. if(comp){
  105515. if(!out){
  105516. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105517. exit(1);
  105518. }
  105519. for(i=0;i<b->entries*b->dim;i++)
  105520. if(fabs(out[i]-comp[i])>.0001){
  105521. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105522. "position %d, %g != %g\n",i,out[i],comp[i]);
  105523. exit(1);
  105524. }
  105525. }else{
  105526. if(out){
  105527. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105528. " correct result should have been NULL\n");
  105529. exit(1);
  105530. }
  105531. }
  105532. }
  105533. int main(){
  105534. fprintf(stderr,"Dequant test 1... ");
  105535. run_test(&test1,test1_result);
  105536. fprintf(stderr,"OK\nDequant test 2... ");
  105537. run_test(&test2,test2_result);
  105538. fprintf(stderr,"OK\nDequant test 3... ");
  105539. run_test(&test3,test3_result);
  105540. fprintf(stderr,"OK\nDequant test 4... ");
  105541. run_test(&test4,test4_result);
  105542. fprintf(stderr,"OK\nDequant test 5... ");
  105543. run_test(&test5,test5_result);
  105544. fprintf(stderr,"OK\n\n");
  105545. return(0);
  105546. }
  105547. #endif
  105548. #endif
  105549. /*** End of inlined file: sharedbook.c ***/
  105550. /*** Start of inlined file: smallft.c ***/
  105551. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105552. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105553. // tasks..
  105554. #if JUCE_MSVC
  105555. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105556. #endif
  105557. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105558. #if JUCE_USE_OGGVORBIS
  105559. #include <stdlib.h>
  105560. #include <string.h>
  105561. #include <math.h>
  105562. static void drfti1(int n, float *wa, int *ifac){
  105563. static int ntryh[4] = { 4,2,3,5 };
  105564. static float tpi = 6.28318530717958648f;
  105565. float arg,argh,argld,fi;
  105566. int ntry=0,i,j=-1;
  105567. int k1, l1, l2, ib;
  105568. int ld, ii, ip, is, nq, nr;
  105569. int ido, ipm, nfm1;
  105570. int nl=n;
  105571. int nf=0;
  105572. L101:
  105573. j++;
  105574. if (j < 4)
  105575. ntry=ntryh[j];
  105576. else
  105577. ntry+=2;
  105578. L104:
  105579. nq=nl/ntry;
  105580. nr=nl-ntry*nq;
  105581. if (nr!=0) goto L101;
  105582. nf++;
  105583. ifac[nf+1]=ntry;
  105584. nl=nq;
  105585. if(ntry!=2)goto L107;
  105586. if(nf==1)goto L107;
  105587. for (i=1;i<nf;i++){
  105588. ib=nf-i+1;
  105589. ifac[ib+1]=ifac[ib];
  105590. }
  105591. ifac[2] = 2;
  105592. L107:
  105593. if(nl!=1)goto L104;
  105594. ifac[0]=n;
  105595. ifac[1]=nf;
  105596. argh=tpi/n;
  105597. is=0;
  105598. nfm1=nf-1;
  105599. l1=1;
  105600. if(nfm1==0)return;
  105601. for (k1=0;k1<nfm1;k1++){
  105602. ip=ifac[k1+2];
  105603. ld=0;
  105604. l2=l1*ip;
  105605. ido=n/l2;
  105606. ipm=ip-1;
  105607. for (j=0;j<ipm;j++){
  105608. ld+=l1;
  105609. i=is;
  105610. argld=(float)ld*argh;
  105611. fi=0.f;
  105612. for (ii=2;ii<ido;ii+=2){
  105613. fi+=1.f;
  105614. arg=fi*argld;
  105615. wa[i++]=cos(arg);
  105616. wa[i++]=sin(arg);
  105617. }
  105618. is+=ido;
  105619. }
  105620. l1=l2;
  105621. }
  105622. }
  105623. static void fdrffti(int n, float *wsave, int *ifac){
  105624. if (n == 1) return;
  105625. drfti1(n, wsave+n, ifac);
  105626. }
  105627. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105628. int i,k;
  105629. float ti2,tr2;
  105630. int t0,t1,t2,t3,t4,t5,t6;
  105631. t1=0;
  105632. t0=(t2=l1*ido);
  105633. t3=ido<<1;
  105634. for(k=0;k<l1;k++){
  105635. ch[t1<<1]=cc[t1]+cc[t2];
  105636. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105637. t1+=ido;
  105638. t2+=ido;
  105639. }
  105640. if(ido<2)return;
  105641. if(ido==2)goto L105;
  105642. t1=0;
  105643. t2=t0;
  105644. for(k=0;k<l1;k++){
  105645. t3=t2;
  105646. t4=(t1<<1)+(ido<<1);
  105647. t5=t1;
  105648. t6=t1+t1;
  105649. for(i=2;i<ido;i+=2){
  105650. t3+=2;
  105651. t4-=2;
  105652. t5+=2;
  105653. t6+=2;
  105654. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105655. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105656. ch[t6]=cc[t5]+ti2;
  105657. ch[t4]=ti2-cc[t5];
  105658. ch[t6-1]=cc[t5-1]+tr2;
  105659. ch[t4-1]=cc[t5-1]-tr2;
  105660. }
  105661. t1+=ido;
  105662. t2+=ido;
  105663. }
  105664. if(ido%2==1)return;
  105665. L105:
  105666. t3=(t2=(t1=ido)-1);
  105667. t2+=t0;
  105668. for(k=0;k<l1;k++){
  105669. ch[t1]=-cc[t2];
  105670. ch[t1-1]=cc[t3];
  105671. t1+=ido<<1;
  105672. t2+=ido;
  105673. t3+=ido;
  105674. }
  105675. }
  105676. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105677. float *wa2,float *wa3){
  105678. static float hsqt2 = .70710678118654752f;
  105679. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105680. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105681. t0=l1*ido;
  105682. t1=t0;
  105683. t4=t1<<1;
  105684. t2=t1+(t1<<1);
  105685. t3=0;
  105686. for(k=0;k<l1;k++){
  105687. tr1=cc[t1]+cc[t2];
  105688. tr2=cc[t3]+cc[t4];
  105689. ch[t5=t3<<2]=tr1+tr2;
  105690. ch[(ido<<2)+t5-1]=tr2-tr1;
  105691. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105692. ch[t5]=cc[t2]-cc[t1];
  105693. t1+=ido;
  105694. t2+=ido;
  105695. t3+=ido;
  105696. t4+=ido;
  105697. }
  105698. if(ido<2)return;
  105699. if(ido==2)goto L105;
  105700. t1=0;
  105701. for(k=0;k<l1;k++){
  105702. t2=t1;
  105703. t4=t1<<2;
  105704. t5=(t6=ido<<1)+t4;
  105705. for(i=2;i<ido;i+=2){
  105706. t3=(t2+=2);
  105707. t4+=2;
  105708. t5-=2;
  105709. t3+=t0;
  105710. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105711. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105712. t3+=t0;
  105713. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105714. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105715. t3+=t0;
  105716. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105717. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105718. tr1=cr2+cr4;
  105719. tr4=cr4-cr2;
  105720. ti1=ci2+ci4;
  105721. ti4=ci2-ci4;
  105722. ti2=cc[t2]+ci3;
  105723. ti3=cc[t2]-ci3;
  105724. tr2=cc[t2-1]+cr3;
  105725. tr3=cc[t2-1]-cr3;
  105726. ch[t4-1]=tr1+tr2;
  105727. ch[t4]=ti1+ti2;
  105728. ch[t5-1]=tr3-ti4;
  105729. ch[t5]=tr4-ti3;
  105730. ch[t4+t6-1]=ti4+tr3;
  105731. ch[t4+t6]=tr4+ti3;
  105732. ch[t5+t6-1]=tr2-tr1;
  105733. ch[t5+t6]=ti1-ti2;
  105734. }
  105735. t1+=ido;
  105736. }
  105737. if(ido&1)return;
  105738. L105:
  105739. t2=(t1=t0+ido-1)+(t0<<1);
  105740. t3=ido<<2;
  105741. t4=ido;
  105742. t5=ido<<1;
  105743. t6=ido;
  105744. for(k=0;k<l1;k++){
  105745. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105746. tr1=hsqt2*(cc[t1]-cc[t2]);
  105747. ch[t4-1]=tr1+cc[t6-1];
  105748. ch[t4+t5-1]=cc[t6-1]-tr1;
  105749. ch[t4]=ti1-cc[t1+t0];
  105750. ch[t4+t5]=ti1+cc[t1+t0];
  105751. t1+=ido;
  105752. t2+=ido;
  105753. t4+=t3;
  105754. t6+=ido;
  105755. }
  105756. }
  105757. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105758. float *c2,float *ch,float *ch2,float *wa){
  105759. static float tpi=6.283185307179586f;
  105760. int idij,ipph,i,j,k,l,ic,ik,is;
  105761. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105762. float dc2,ai1,ai2,ar1,ar2,ds2;
  105763. int nbd;
  105764. float dcp,arg,dsp,ar1h,ar2h;
  105765. int idp2,ipp2;
  105766. arg=tpi/(float)ip;
  105767. dcp=cos(arg);
  105768. dsp=sin(arg);
  105769. ipph=(ip+1)>>1;
  105770. ipp2=ip;
  105771. idp2=ido;
  105772. nbd=(ido-1)>>1;
  105773. t0=l1*ido;
  105774. t10=ip*ido;
  105775. if(ido==1)goto L119;
  105776. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105777. t1=0;
  105778. for(j=1;j<ip;j++){
  105779. t1+=t0;
  105780. t2=t1;
  105781. for(k=0;k<l1;k++){
  105782. ch[t2]=c1[t2];
  105783. t2+=ido;
  105784. }
  105785. }
  105786. is=-ido;
  105787. t1=0;
  105788. if(nbd>l1){
  105789. for(j=1;j<ip;j++){
  105790. t1+=t0;
  105791. is+=ido;
  105792. t2= -ido+t1;
  105793. for(k=0;k<l1;k++){
  105794. idij=is-1;
  105795. t2+=ido;
  105796. t3=t2;
  105797. for(i=2;i<ido;i+=2){
  105798. idij+=2;
  105799. t3+=2;
  105800. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105801. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105802. }
  105803. }
  105804. }
  105805. }else{
  105806. for(j=1;j<ip;j++){
  105807. is+=ido;
  105808. idij=is-1;
  105809. t1+=t0;
  105810. t2=t1;
  105811. for(i=2;i<ido;i+=2){
  105812. idij+=2;
  105813. t2+=2;
  105814. t3=t2;
  105815. for(k=0;k<l1;k++){
  105816. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105817. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105818. t3+=ido;
  105819. }
  105820. }
  105821. }
  105822. }
  105823. t1=0;
  105824. t2=ipp2*t0;
  105825. if(nbd<l1){
  105826. for(j=1;j<ipph;j++){
  105827. t1+=t0;
  105828. t2-=t0;
  105829. t3=t1;
  105830. t4=t2;
  105831. for(i=2;i<ido;i+=2){
  105832. t3+=2;
  105833. t4+=2;
  105834. t5=t3-ido;
  105835. t6=t4-ido;
  105836. for(k=0;k<l1;k++){
  105837. t5+=ido;
  105838. t6+=ido;
  105839. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105840. c1[t6-1]=ch[t5]-ch[t6];
  105841. c1[t5]=ch[t5]+ch[t6];
  105842. c1[t6]=ch[t6-1]-ch[t5-1];
  105843. }
  105844. }
  105845. }
  105846. }else{
  105847. for(j=1;j<ipph;j++){
  105848. t1+=t0;
  105849. t2-=t0;
  105850. t3=t1;
  105851. t4=t2;
  105852. for(k=0;k<l1;k++){
  105853. t5=t3;
  105854. t6=t4;
  105855. for(i=2;i<ido;i+=2){
  105856. t5+=2;
  105857. t6+=2;
  105858. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105859. c1[t6-1]=ch[t5]-ch[t6];
  105860. c1[t5]=ch[t5]+ch[t6];
  105861. c1[t6]=ch[t6-1]-ch[t5-1];
  105862. }
  105863. t3+=ido;
  105864. t4+=ido;
  105865. }
  105866. }
  105867. }
  105868. L119:
  105869. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105870. t1=0;
  105871. t2=ipp2*idl1;
  105872. for(j=1;j<ipph;j++){
  105873. t1+=t0;
  105874. t2-=t0;
  105875. t3=t1-ido;
  105876. t4=t2-ido;
  105877. for(k=0;k<l1;k++){
  105878. t3+=ido;
  105879. t4+=ido;
  105880. c1[t3]=ch[t3]+ch[t4];
  105881. c1[t4]=ch[t4]-ch[t3];
  105882. }
  105883. }
  105884. ar1=1.f;
  105885. ai1=0.f;
  105886. t1=0;
  105887. t2=ipp2*idl1;
  105888. t3=(ip-1)*idl1;
  105889. for(l=1;l<ipph;l++){
  105890. t1+=idl1;
  105891. t2-=idl1;
  105892. ar1h=dcp*ar1-dsp*ai1;
  105893. ai1=dcp*ai1+dsp*ar1;
  105894. ar1=ar1h;
  105895. t4=t1;
  105896. t5=t2;
  105897. t6=t3;
  105898. t7=idl1;
  105899. for(ik=0;ik<idl1;ik++){
  105900. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105901. ch2[t5++]=ai1*c2[t6++];
  105902. }
  105903. dc2=ar1;
  105904. ds2=ai1;
  105905. ar2=ar1;
  105906. ai2=ai1;
  105907. t4=idl1;
  105908. t5=(ipp2-1)*idl1;
  105909. for(j=2;j<ipph;j++){
  105910. t4+=idl1;
  105911. t5-=idl1;
  105912. ar2h=dc2*ar2-ds2*ai2;
  105913. ai2=dc2*ai2+ds2*ar2;
  105914. ar2=ar2h;
  105915. t6=t1;
  105916. t7=t2;
  105917. t8=t4;
  105918. t9=t5;
  105919. for(ik=0;ik<idl1;ik++){
  105920. ch2[t6++]+=ar2*c2[t8++];
  105921. ch2[t7++]+=ai2*c2[t9++];
  105922. }
  105923. }
  105924. }
  105925. t1=0;
  105926. for(j=1;j<ipph;j++){
  105927. t1+=idl1;
  105928. t2=t1;
  105929. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105930. }
  105931. if(ido<l1)goto L132;
  105932. t1=0;
  105933. t2=0;
  105934. for(k=0;k<l1;k++){
  105935. t3=t1;
  105936. t4=t2;
  105937. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105938. t1+=ido;
  105939. t2+=t10;
  105940. }
  105941. goto L135;
  105942. L132:
  105943. for(i=0;i<ido;i++){
  105944. t1=i;
  105945. t2=i;
  105946. for(k=0;k<l1;k++){
  105947. cc[t2]=ch[t1];
  105948. t1+=ido;
  105949. t2+=t10;
  105950. }
  105951. }
  105952. L135:
  105953. t1=0;
  105954. t2=ido<<1;
  105955. t3=0;
  105956. t4=ipp2*t0;
  105957. for(j=1;j<ipph;j++){
  105958. t1+=t2;
  105959. t3+=t0;
  105960. t4-=t0;
  105961. t5=t1;
  105962. t6=t3;
  105963. t7=t4;
  105964. for(k=0;k<l1;k++){
  105965. cc[t5-1]=ch[t6];
  105966. cc[t5]=ch[t7];
  105967. t5+=t10;
  105968. t6+=ido;
  105969. t7+=ido;
  105970. }
  105971. }
  105972. if(ido==1)return;
  105973. if(nbd<l1)goto L141;
  105974. t1=-ido;
  105975. t3=0;
  105976. t4=0;
  105977. t5=ipp2*t0;
  105978. for(j=1;j<ipph;j++){
  105979. t1+=t2;
  105980. t3+=t2;
  105981. t4+=t0;
  105982. t5-=t0;
  105983. t6=t1;
  105984. t7=t3;
  105985. t8=t4;
  105986. t9=t5;
  105987. for(k=0;k<l1;k++){
  105988. for(i=2;i<ido;i+=2){
  105989. ic=idp2-i;
  105990. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105991. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105992. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105993. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105994. }
  105995. t6+=t10;
  105996. t7+=t10;
  105997. t8+=ido;
  105998. t9+=ido;
  105999. }
  106000. }
  106001. return;
  106002. L141:
  106003. t1=-ido;
  106004. t3=0;
  106005. t4=0;
  106006. t5=ipp2*t0;
  106007. for(j=1;j<ipph;j++){
  106008. t1+=t2;
  106009. t3+=t2;
  106010. t4+=t0;
  106011. t5-=t0;
  106012. for(i=2;i<ido;i+=2){
  106013. t6=idp2+t1-i;
  106014. t7=i+t3;
  106015. t8=i+t4;
  106016. t9=i+t5;
  106017. for(k=0;k<l1;k++){
  106018. cc[t7-1]=ch[t8-1]+ch[t9-1];
  106019. cc[t6-1]=ch[t8-1]-ch[t9-1];
  106020. cc[t7]=ch[t8]+ch[t9];
  106021. cc[t6]=ch[t9]-ch[t8];
  106022. t6+=t10;
  106023. t7+=t10;
  106024. t8+=ido;
  106025. t9+=ido;
  106026. }
  106027. }
  106028. }
  106029. }
  106030. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  106031. int i,k1,l1,l2;
  106032. int na,kh,nf;
  106033. int ip,iw,ido,idl1,ix2,ix3;
  106034. nf=ifac[1];
  106035. na=1;
  106036. l2=n;
  106037. iw=n;
  106038. for(k1=0;k1<nf;k1++){
  106039. kh=nf-k1;
  106040. ip=ifac[kh+1];
  106041. l1=l2/ip;
  106042. ido=n/l2;
  106043. idl1=ido*l1;
  106044. iw-=(ip-1)*ido;
  106045. na=1-na;
  106046. if(ip!=4)goto L102;
  106047. ix2=iw+ido;
  106048. ix3=ix2+ido;
  106049. if(na!=0)
  106050. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106051. else
  106052. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106053. goto L110;
  106054. L102:
  106055. if(ip!=2)goto L104;
  106056. if(na!=0)goto L103;
  106057. dradf2(ido,l1,c,ch,wa+iw-1);
  106058. goto L110;
  106059. L103:
  106060. dradf2(ido,l1,ch,c,wa+iw-1);
  106061. goto L110;
  106062. L104:
  106063. if(ido==1)na=1-na;
  106064. if(na!=0)goto L109;
  106065. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106066. na=1;
  106067. goto L110;
  106068. L109:
  106069. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106070. na=0;
  106071. L110:
  106072. l2=l1;
  106073. }
  106074. if(na==1)return;
  106075. for(i=0;i<n;i++)c[i]=ch[i];
  106076. }
  106077. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  106078. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106079. float ti2,tr2;
  106080. t0=l1*ido;
  106081. t1=0;
  106082. t2=0;
  106083. t3=(ido<<1)-1;
  106084. for(k=0;k<l1;k++){
  106085. ch[t1]=cc[t2]+cc[t3+t2];
  106086. ch[t1+t0]=cc[t2]-cc[t3+t2];
  106087. t2=(t1+=ido)<<1;
  106088. }
  106089. if(ido<2)return;
  106090. if(ido==2)goto L105;
  106091. t1=0;
  106092. t2=0;
  106093. for(k=0;k<l1;k++){
  106094. t3=t1;
  106095. t5=(t4=t2)+(ido<<1);
  106096. t6=t0+t1;
  106097. for(i=2;i<ido;i+=2){
  106098. t3+=2;
  106099. t4+=2;
  106100. t5-=2;
  106101. t6+=2;
  106102. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106103. tr2=cc[t4-1]-cc[t5-1];
  106104. ch[t3]=cc[t4]-cc[t5];
  106105. ti2=cc[t4]+cc[t5];
  106106. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106107. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106108. }
  106109. t2=(t1+=ido)<<1;
  106110. }
  106111. if(ido%2==1)return;
  106112. L105:
  106113. t1=ido-1;
  106114. t2=ido-1;
  106115. for(k=0;k<l1;k++){
  106116. ch[t1]=cc[t2]+cc[t2];
  106117. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106118. t1+=ido;
  106119. t2+=ido<<1;
  106120. }
  106121. }
  106122. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106123. float *wa2){
  106124. static float taur = -.5f;
  106125. static float taui = .8660254037844386f;
  106126. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106127. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106128. t0=l1*ido;
  106129. t1=0;
  106130. t2=t0<<1;
  106131. t3=ido<<1;
  106132. t4=ido+(ido<<1);
  106133. t5=0;
  106134. for(k=0;k<l1;k++){
  106135. tr2=cc[t3-1]+cc[t3-1];
  106136. cr2=cc[t5]+(taur*tr2);
  106137. ch[t1]=cc[t5]+tr2;
  106138. ci3=taui*(cc[t3]+cc[t3]);
  106139. ch[t1+t0]=cr2-ci3;
  106140. ch[t1+t2]=cr2+ci3;
  106141. t1+=ido;
  106142. t3+=t4;
  106143. t5+=t4;
  106144. }
  106145. if(ido==1)return;
  106146. t1=0;
  106147. t3=ido<<1;
  106148. for(k=0;k<l1;k++){
  106149. t7=t1+(t1<<1);
  106150. t6=(t5=t7+t3);
  106151. t8=t1;
  106152. t10=(t9=t1+t0)+t0;
  106153. for(i=2;i<ido;i+=2){
  106154. t5+=2;
  106155. t6-=2;
  106156. t7+=2;
  106157. t8+=2;
  106158. t9+=2;
  106159. t10+=2;
  106160. tr2=cc[t5-1]+cc[t6-1];
  106161. cr2=cc[t7-1]+(taur*tr2);
  106162. ch[t8-1]=cc[t7-1]+tr2;
  106163. ti2=cc[t5]-cc[t6];
  106164. ci2=cc[t7]+(taur*ti2);
  106165. ch[t8]=cc[t7]+ti2;
  106166. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106167. ci3=taui*(cc[t5]+cc[t6]);
  106168. dr2=cr2-ci3;
  106169. dr3=cr2+ci3;
  106170. di2=ci2+cr3;
  106171. di3=ci2-cr3;
  106172. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106173. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106174. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106175. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106176. }
  106177. t1+=ido;
  106178. }
  106179. }
  106180. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106181. float *wa2,float *wa3){
  106182. static float sqrt2=1.414213562373095f;
  106183. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106184. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106185. t0=l1*ido;
  106186. t1=0;
  106187. t2=ido<<2;
  106188. t3=0;
  106189. t6=ido<<1;
  106190. for(k=0;k<l1;k++){
  106191. t4=t3+t6;
  106192. t5=t1;
  106193. tr3=cc[t4-1]+cc[t4-1];
  106194. tr4=cc[t4]+cc[t4];
  106195. tr1=cc[t3]-cc[(t4+=t6)-1];
  106196. tr2=cc[t3]+cc[t4-1];
  106197. ch[t5]=tr2+tr3;
  106198. ch[t5+=t0]=tr1-tr4;
  106199. ch[t5+=t0]=tr2-tr3;
  106200. ch[t5+=t0]=tr1+tr4;
  106201. t1+=ido;
  106202. t3+=t2;
  106203. }
  106204. if(ido<2)return;
  106205. if(ido==2)goto L105;
  106206. t1=0;
  106207. for(k=0;k<l1;k++){
  106208. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106209. t7=t1;
  106210. for(i=2;i<ido;i+=2){
  106211. t2+=2;
  106212. t3+=2;
  106213. t4-=2;
  106214. t5-=2;
  106215. t7+=2;
  106216. ti1=cc[t2]+cc[t5];
  106217. ti2=cc[t2]-cc[t5];
  106218. ti3=cc[t3]-cc[t4];
  106219. tr4=cc[t3]+cc[t4];
  106220. tr1=cc[t2-1]-cc[t5-1];
  106221. tr2=cc[t2-1]+cc[t5-1];
  106222. ti4=cc[t3-1]-cc[t4-1];
  106223. tr3=cc[t3-1]+cc[t4-1];
  106224. ch[t7-1]=tr2+tr3;
  106225. cr3=tr2-tr3;
  106226. ch[t7]=ti2+ti3;
  106227. ci3=ti2-ti3;
  106228. cr2=tr1-tr4;
  106229. cr4=tr1+tr4;
  106230. ci2=ti1+ti4;
  106231. ci4=ti1-ti4;
  106232. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106233. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106234. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106235. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106236. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106237. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106238. }
  106239. t1+=ido;
  106240. }
  106241. if(ido%2 == 1)return;
  106242. L105:
  106243. t1=ido;
  106244. t2=ido<<2;
  106245. t3=ido-1;
  106246. t4=ido+(ido<<1);
  106247. for(k=0;k<l1;k++){
  106248. t5=t3;
  106249. ti1=cc[t1]+cc[t4];
  106250. ti2=cc[t4]-cc[t1];
  106251. tr1=cc[t1-1]-cc[t4-1];
  106252. tr2=cc[t1-1]+cc[t4-1];
  106253. ch[t5]=tr2+tr2;
  106254. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106255. ch[t5+=t0]=ti2+ti2;
  106256. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106257. t3+=ido;
  106258. t1+=t2;
  106259. t4+=t2;
  106260. }
  106261. }
  106262. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106263. float *c2,float *ch,float *ch2,float *wa){
  106264. static float tpi=6.283185307179586f;
  106265. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106266. t11,t12;
  106267. float dc2,ai1,ai2,ar1,ar2,ds2;
  106268. int nbd;
  106269. float dcp,arg,dsp,ar1h,ar2h;
  106270. int ipp2;
  106271. t10=ip*ido;
  106272. t0=l1*ido;
  106273. arg=tpi/(float)ip;
  106274. dcp=cos(arg);
  106275. dsp=sin(arg);
  106276. nbd=(ido-1)>>1;
  106277. ipp2=ip;
  106278. ipph=(ip+1)>>1;
  106279. if(ido<l1)goto L103;
  106280. t1=0;
  106281. t2=0;
  106282. for(k=0;k<l1;k++){
  106283. t3=t1;
  106284. t4=t2;
  106285. for(i=0;i<ido;i++){
  106286. ch[t3]=cc[t4];
  106287. t3++;
  106288. t4++;
  106289. }
  106290. t1+=ido;
  106291. t2+=t10;
  106292. }
  106293. goto L106;
  106294. L103:
  106295. t1=0;
  106296. for(i=0;i<ido;i++){
  106297. t2=t1;
  106298. t3=t1;
  106299. for(k=0;k<l1;k++){
  106300. ch[t2]=cc[t3];
  106301. t2+=ido;
  106302. t3+=t10;
  106303. }
  106304. t1++;
  106305. }
  106306. L106:
  106307. t1=0;
  106308. t2=ipp2*t0;
  106309. t7=(t5=ido<<1);
  106310. for(j=1;j<ipph;j++){
  106311. t1+=t0;
  106312. t2-=t0;
  106313. t3=t1;
  106314. t4=t2;
  106315. t6=t5;
  106316. for(k=0;k<l1;k++){
  106317. ch[t3]=cc[t6-1]+cc[t6-1];
  106318. ch[t4]=cc[t6]+cc[t6];
  106319. t3+=ido;
  106320. t4+=ido;
  106321. t6+=t10;
  106322. }
  106323. t5+=t7;
  106324. }
  106325. if (ido == 1)goto L116;
  106326. if(nbd<l1)goto L112;
  106327. t1=0;
  106328. t2=ipp2*t0;
  106329. t7=0;
  106330. for(j=1;j<ipph;j++){
  106331. t1+=t0;
  106332. t2-=t0;
  106333. t3=t1;
  106334. t4=t2;
  106335. t7+=(ido<<1);
  106336. t8=t7;
  106337. for(k=0;k<l1;k++){
  106338. t5=t3;
  106339. t6=t4;
  106340. t9=t8;
  106341. t11=t8;
  106342. for(i=2;i<ido;i+=2){
  106343. t5+=2;
  106344. t6+=2;
  106345. t9+=2;
  106346. t11-=2;
  106347. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106348. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106349. ch[t5]=cc[t9]-cc[t11];
  106350. ch[t6]=cc[t9]+cc[t11];
  106351. }
  106352. t3+=ido;
  106353. t4+=ido;
  106354. t8+=t10;
  106355. }
  106356. }
  106357. goto L116;
  106358. L112:
  106359. t1=0;
  106360. t2=ipp2*t0;
  106361. t7=0;
  106362. for(j=1;j<ipph;j++){
  106363. t1+=t0;
  106364. t2-=t0;
  106365. t3=t1;
  106366. t4=t2;
  106367. t7+=(ido<<1);
  106368. t8=t7;
  106369. t9=t7;
  106370. for(i=2;i<ido;i+=2){
  106371. t3+=2;
  106372. t4+=2;
  106373. t8+=2;
  106374. t9-=2;
  106375. t5=t3;
  106376. t6=t4;
  106377. t11=t8;
  106378. t12=t9;
  106379. for(k=0;k<l1;k++){
  106380. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106381. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106382. ch[t5]=cc[t11]-cc[t12];
  106383. ch[t6]=cc[t11]+cc[t12];
  106384. t5+=ido;
  106385. t6+=ido;
  106386. t11+=t10;
  106387. t12+=t10;
  106388. }
  106389. }
  106390. }
  106391. L116:
  106392. ar1=1.f;
  106393. ai1=0.f;
  106394. t1=0;
  106395. t9=(t2=ipp2*idl1);
  106396. t3=(ip-1)*idl1;
  106397. for(l=1;l<ipph;l++){
  106398. t1+=idl1;
  106399. t2-=idl1;
  106400. ar1h=dcp*ar1-dsp*ai1;
  106401. ai1=dcp*ai1+dsp*ar1;
  106402. ar1=ar1h;
  106403. t4=t1;
  106404. t5=t2;
  106405. t6=0;
  106406. t7=idl1;
  106407. t8=t3;
  106408. for(ik=0;ik<idl1;ik++){
  106409. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106410. c2[t5++]=ai1*ch2[t8++];
  106411. }
  106412. dc2=ar1;
  106413. ds2=ai1;
  106414. ar2=ar1;
  106415. ai2=ai1;
  106416. t6=idl1;
  106417. t7=t9-idl1;
  106418. for(j=2;j<ipph;j++){
  106419. t6+=idl1;
  106420. t7-=idl1;
  106421. ar2h=dc2*ar2-ds2*ai2;
  106422. ai2=dc2*ai2+ds2*ar2;
  106423. ar2=ar2h;
  106424. t4=t1;
  106425. t5=t2;
  106426. t11=t6;
  106427. t12=t7;
  106428. for(ik=0;ik<idl1;ik++){
  106429. c2[t4++]+=ar2*ch2[t11++];
  106430. c2[t5++]+=ai2*ch2[t12++];
  106431. }
  106432. }
  106433. }
  106434. t1=0;
  106435. for(j=1;j<ipph;j++){
  106436. t1+=idl1;
  106437. t2=t1;
  106438. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106439. }
  106440. t1=0;
  106441. t2=ipp2*t0;
  106442. for(j=1;j<ipph;j++){
  106443. t1+=t0;
  106444. t2-=t0;
  106445. t3=t1;
  106446. t4=t2;
  106447. for(k=0;k<l1;k++){
  106448. ch[t3]=c1[t3]-c1[t4];
  106449. ch[t4]=c1[t3]+c1[t4];
  106450. t3+=ido;
  106451. t4+=ido;
  106452. }
  106453. }
  106454. if(ido==1)goto L132;
  106455. if(nbd<l1)goto L128;
  106456. t1=0;
  106457. t2=ipp2*t0;
  106458. for(j=1;j<ipph;j++){
  106459. t1+=t0;
  106460. t2-=t0;
  106461. t3=t1;
  106462. t4=t2;
  106463. for(k=0;k<l1;k++){
  106464. t5=t3;
  106465. t6=t4;
  106466. for(i=2;i<ido;i+=2){
  106467. t5+=2;
  106468. t6+=2;
  106469. ch[t5-1]=c1[t5-1]-c1[t6];
  106470. ch[t6-1]=c1[t5-1]+c1[t6];
  106471. ch[t5]=c1[t5]+c1[t6-1];
  106472. ch[t6]=c1[t5]-c1[t6-1];
  106473. }
  106474. t3+=ido;
  106475. t4+=ido;
  106476. }
  106477. }
  106478. goto L132;
  106479. L128:
  106480. t1=0;
  106481. t2=ipp2*t0;
  106482. for(j=1;j<ipph;j++){
  106483. t1+=t0;
  106484. t2-=t0;
  106485. t3=t1;
  106486. t4=t2;
  106487. for(i=2;i<ido;i+=2){
  106488. t3+=2;
  106489. t4+=2;
  106490. t5=t3;
  106491. t6=t4;
  106492. for(k=0;k<l1;k++){
  106493. ch[t5-1]=c1[t5-1]-c1[t6];
  106494. ch[t6-1]=c1[t5-1]+c1[t6];
  106495. ch[t5]=c1[t5]+c1[t6-1];
  106496. ch[t6]=c1[t5]-c1[t6-1];
  106497. t5+=ido;
  106498. t6+=ido;
  106499. }
  106500. }
  106501. }
  106502. L132:
  106503. if(ido==1)return;
  106504. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106505. t1=0;
  106506. for(j=1;j<ip;j++){
  106507. t2=(t1+=t0);
  106508. for(k=0;k<l1;k++){
  106509. c1[t2]=ch[t2];
  106510. t2+=ido;
  106511. }
  106512. }
  106513. if(nbd>l1)goto L139;
  106514. is= -ido-1;
  106515. t1=0;
  106516. for(j=1;j<ip;j++){
  106517. is+=ido;
  106518. t1+=t0;
  106519. idij=is;
  106520. t2=t1;
  106521. for(i=2;i<ido;i+=2){
  106522. t2+=2;
  106523. idij+=2;
  106524. t3=t2;
  106525. for(k=0;k<l1;k++){
  106526. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106527. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106528. t3+=ido;
  106529. }
  106530. }
  106531. }
  106532. return;
  106533. L139:
  106534. is= -ido-1;
  106535. t1=0;
  106536. for(j=1;j<ip;j++){
  106537. is+=ido;
  106538. t1+=t0;
  106539. t2=t1;
  106540. for(k=0;k<l1;k++){
  106541. idij=is;
  106542. t3=t2;
  106543. for(i=2;i<ido;i+=2){
  106544. idij+=2;
  106545. t3+=2;
  106546. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106547. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106548. }
  106549. t2+=ido;
  106550. }
  106551. }
  106552. }
  106553. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106554. int i,k1,l1,l2;
  106555. int na;
  106556. int nf,ip,iw,ix2,ix3,ido,idl1;
  106557. nf=ifac[1];
  106558. na=0;
  106559. l1=1;
  106560. iw=1;
  106561. for(k1=0;k1<nf;k1++){
  106562. ip=ifac[k1 + 2];
  106563. l2=ip*l1;
  106564. ido=n/l2;
  106565. idl1=ido*l1;
  106566. if(ip!=4)goto L103;
  106567. ix2=iw+ido;
  106568. ix3=ix2+ido;
  106569. if(na!=0)
  106570. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106571. else
  106572. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106573. na=1-na;
  106574. goto L115;
  106575. L103:
  106576. if(ip!=2)goto L106;
  106577. if(na!=0)
  106578. dradb2(ido,l1,ch,c,wa+iw-1);
  106579. else
  106580. dradb2(ido,l1,c,ch,wa+iw-1);
  106581. na=1-na;
  106582. goto L115;
  106583. L106:
  106584. if(ip!=3)goto L109;
  106585. ix2=iw+ido;
  106586. if(na!=0)
  106587. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106588. else
  106589. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106590. na=1-na;
  106591. goto L115;
  106592. L109:
  106593. if(na!=0)
  106594. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106595. else
  106596. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106597. if(ido==1)na=1-na;
  106598. L115:
  106599. l1=l2;
  106600. iw+=(ip-1)*ido;
  106601. }
  106602. if(na==0)return;
  106603. for(i=0;i<n;i++)c[i]=ch[i];
  106604. }
  106605. void drft_forward(drft_lookup *l,float *data){
  106606. if(l->n==1)return;
  106607. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106608. }
  106609. void drft_backward(drft_lookup *l,float *data){
  106610. if (l->n==1)return;
  106611. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106612. }
  106613. void drft_init(drft_lookup *l,int n){
  106614. l->n=n;
  106615. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106616. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106617. fdrffti(n, l->trigcache, l->splitcache);
  106618. }
  106619. void drft_clear(drft_lookup *l){
  106620. if(l){
  106621. if(l->trigcache)_ogg_free(l->trigcache);
  106622. if(l->splitcache)_ogg_free(l->splitcache);
  106623. memset(l,0,sizeof(*l));
  106624. }
  106625. }
  106626. #endif
  106627. /*** End of inlined file: smallft.c ***/
  106628. /*** Start of inlined file: synthesis.c ***/
  106629. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106630. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106631. // tasks..
  106632. #if JUCE_MSVC
  106633. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106634. #endif
  106635. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106636. #if JUCE_USE_OGGVORBIS
  106637. #include <stdio.h>
  106638. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106639. vorbis_dsp_state *vd=vb->vd;
  106640. private_state *b=(private_state*)vd->backend_state;
  106641. vorbis_info *vi=vd->vi;
  106642. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106643. oggpack_buffer *opb=&vb->opb;
  106644. int type,mode,i;
  106645. _vorbis_block_ripcord(vb);
  106646. oggpack_readinit(opb,op->packet,op->bytes);
  106647. if(oggpack_read(opb,1)!=0){
  106648. return(OV_ENOTAUDIO);
  106649. }
  106650. mode=oggpack_read(opb,b->modebits);
  106651. if(mode==-1)return(OV_EBADPACKET);
  106652. vb->mode=mode;
  106653. vb->W=ci->mode_param[mode]->blockflag;
  106654. if(vb->W){
  106655. vb->lW=oggpack_read(opb,1);
  106656. vb->nW=oggpack_read(opb,1);
  106657. if(vb->nW==-1) return(OV_EBADPACKET);
  106658. }else{
  106659. vb->lW=0;
  106660. vb->nW=0;
  106661. }
  106662. vb->granulepos=op->granulepos;
  106663. vb->sequence=op->packetno;
  106664. vb->eofflag=op->e_o_s;
  106665. vb->pcmend=ci->blocksizes[vb->W];
  106666. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106667. for(i=0;i<vi->channels;i++)
  106668. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106669. type=ci->map_type[ci->mode_param[mode]->mapping];
  106670. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106671. mapping]));
  106672. }
  106673. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106674. vorbis_dsp_state *vd=vb->vd;
  106675. private_state *b=(private_state*)vd->backend_state;
  106676. vorbis_info *vi=vd->vi;
  106677. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106678. oggpack_buffer *opb=&vb->opb;
  106679. int mode;
  106680. _vorbis_block_ripcord(vb);
  106681. oggpack_readinit(opb,op->packet,op->bytes);
  106682. if(oggpack_read(opb,1)!=0){
  106683. return(OV_ENOTAUDIO);
  106684. }
  106685. mode=oggpack_read(opb,b->modebits);
  106686. if(mode==-1)return(OV_EBADPACKET);
  106687. vb->mode=mode;
  106688. vb->W=ci->mode_param[mode]->blockflag;
  106689. if(vb->W){
  106690. vb->lW=oggpack_read(opb,1);
  106691. vb->nW=oggpack_read(opb,1);
  106692. if(vb->nW==-1) return(OV_EBADPACKET);
  106693. }else{
  106694. vb->lW=0;
  106695. vb->nW=0;
  106696. }
  106697. vb->granulepos=op->granulepos;
  106698. vb->sequence=op->packetno;
  106699. vb->eofflag=op->e_o_s;
  106700. vb->pcmend=0;
  106701. vb->pcm=NULL;
  106702. return(0);
  106703. }
  106704. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106705. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106706. oggpack_buffer opb;
  106707. int mode;
  106708. oggpack_readinit(&opb,op->packet,op->bytes);
  106709. if(oggpack_read(&opb,1)!=0){
  106710. return(OV_ENOTAUDIO);
  106711. }
  106712. {
  106713. int modebits=0;
  106714. int v=ci->modes;
  106715. while(v>1){
  106716. modebits++;
  106717. v>>=1;
  106718. }
  106719. mode=oggpack_read(&opb,modebits);
  106720. }
  106721. if(mode==-1)return(OV_EBADPACKET);
  106722. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106723. }
  106724. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106725. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106726. if(ci->blocksizes[0]<=64 && flag)return -1;
  106727. ci->halfrate_flag=(flag?1:0);
  106728. return 0;
  106729. }
  106730. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106731. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106732. return ci->halfrate_flag;
  106733. }
  106734. #endif
  106735. /*** End of inlined file: synthesis.c ***/
  106736. /*** Start of inlined file: vorbisenc.c ***/
  106737. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106738. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106739. // tasks..
  106740. #if JUCE_MSVC
  106741. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106742. #endif
  106743. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106744. #if JUCE_USE_OGGVORBIS
  106745. #include <stdlib.h>
  106746. #include <string.h>
  106747. #include <math.h>
  106748. typedef struct {
  106749. static_codebook *books[12][3];
  106750. } static_bookblock;
  106751. typedef struct {
  106752. int res_type;
  106753. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106754. vorbis_info_residue0 *res;
  106755. static_codebook *book_aux;
  106756. static_codebook *book_aux_managed;
  106757. static_bookblock *books_base;
  106758. static_bookblock *books_base_managed;
  106759. } vorbis_residue_template;
  106760. typedef struct {
  106761. vorbis_info_mapping0 *map;
  106762. vorbis_residue_template *res;
  106763. } vorbis_mapping_template;
  106764. typedef struct vp_adjblock{
  106765. int block[P_BANDS];
  106766. } vp_adjblock;
  106767. typedef struct {
  106768. int data[NOISE_COMPAND_LEVELS];
  106769. } compandblock;
  106770. typedef struct {
  106771. int att[P_NOISECURVES];
  106772. float boost;
  106773. float decay;
  106774. } att3;
  106775. typedef struct { int data[P_NOISECURVES]; } adj3;
  106776. typedef struct {
  106777. int pre[PACKETBLOBS];
  106778. int post[PACKETBLOBS];
  106779. float kHz[PACKETBLOBS];
  106780. float lowpasskHz[PACKETBLOBS];
  106781. } adj_stereo;
  106782. typedef struct {
  106783. int lo;
  106784. int hi;
  106785. int fixed;
  106786. } noiseguard;
  106787. typedef struct {
  106788. int data[P_NOISECURVES][17];
  106789. } noise3;
  106790. typedef struct {
  106791. int mappings;
  106792. double *rate_mapping;
  106793. double *quality_mapping;
  106794. int coupling_restriction;
  106795. long samplerate_min_restriction;
  106796. long samplerate_max_restriction;
  106797. int *blocksize_short;
  106798. int *blocksize_long;
  106799. att3 *psy_tone_masteratt;
  106800. int *psy_tone_0dB;
  106801. int *psy_tone_dBsuppress;
  106802. vp_adjblock *psy_tone_adj_impulse;
  106803. vp_adjblock *psy_tone_adj_long;
  106804. vp_adjblock *psy_tone_adj_other;
  106805. noiseguard *psy_noiseguards;
  106806. noise3 *psy_noise_bias_impulse;
  106807. noise3 *psy_noise_bias_padding;
  106808. noise3 *psy_noise_bias_trans;
  106809. noise3 *psy_noise_bias_long;
  106810. int *psy_noise_dBsuppress;
  106811. compandblock *psy_noise_compand;
  106812. double *psy_noise_compand_short_mapping;
  106813. double *psy_noise_compand_long_mapping;
  106814. int *psy_noise_normal_start[2];
  106815. int *psy_noise_normal_partition[2];
  106816. double *psy_noise_normal_thresh;
  106817. int *psy_ath_float;
  106818. int *psy_ath_abs;
  106819. double *psy_lowpass;
  106820. vorbis_info_psy_global *global_params;
  106821. double *global_mapping;
  106822. adj_stereo *stereo_modes;
  106823. static_codebook ***floor_books;
  106824. vorbis_info_floor1 *floor_params;
  106825. int *floor_short_mapping;
  106826. int *floor_long_mapping;
  106827. vorbis_mapping_template *maps;
  106828. } ve_setup_data_template;
  106829. static vorbis_info_mode _mode_template[2]={
  106830. {0,0,0,0},
  106831. {1,0,0,1}
  106832. };
  106833. static vorbis_info_mapping0 _map_nominal[2]={
  106834. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106835. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106836. };
  106837. /*** Start of inlined file: setup_44.h ***/
  106838. /*** Start of inlined file: floor_all.h ***/
  106839. /*** Start of inlined file: floor_books.h ***/
  106840. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106841. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106842. };
  106843. static static_codebook _huff_book_line_256x7_0sub1 = {
  106844. 1, 9,
  106845. _huff_lengthlist_line_256x7_0sub1,
  106846. 0, 0, 0, 0, 0,
  106847. NULL,
  106848. NULL,
  106849. NULL,
  106850. NULL,
  106851. 0
  106852. };
  106853. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106855. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106856. };
  106857. static static_codebook _huff_book_line_256x7_0sub2 = {
  106858. 1, 25,
  106859. _huff_lengthlist_line_256x7_0sub2,
  106860. 0, 0, 0, 0, 0,
  106861. NULL,
  106862. NULL,
  106863. NULL,
  106864. NULL,
  106865. 0
  106866. };
  106867. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106870. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106871. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106872. };
  106873. static static_codebook _huff_book_line_256x7_0sub3 = {
  106874. 1, 64,
  106875. _huff_lengthlist_line_256x7_0sub3,
  106876. 0, 0, 0, 0, 0,
  106877. NULL,
  106878. NULL,
  106879. NULL,
  106880. NULL,
  106881. 0
  106882. };
  106883. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106884. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106885. };
  106886. static static_codebook _huff_book_line_256x7_1sub1 = {
  106887. 1, 9,
  106888. _huff_lengthlist_line_256x7_1sub1,
  106889. 0, 0, 0, 0, 0,
  106890. NULL,
  106891. NULL,
  106892. NULL,
  106893. NULL,
  106894. 0
  106895. };
  106896. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106898. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106899. };
  106900. static static_codebook _huff_book_line_256x7_1sub2 = {
  106901. 1, 25,
  106902. _huff_lengthlist_line_256x7_1sub2,
  106903. 0, 0, 0, 0, 0,
  106904. NULL,
  106905. NULL,
  106906. NULL,
  106907. NULL,
  106908. 0
  106909. };
  106910. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106913. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106914. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106915. };
  106916. static static_codebook _huff_book_line_256x7_1sub3 = {
  106917. 1, 64,
  106918. _huff_lengthlist_line_256x7_1sub3,
  106919. 0, 0, 0, 0, 0,
  106920. NULL,
  106921. NULL,
  106922. NULL,
  106923. NULL,
  106924. 0
  106925. };
  106926. static long _huff_lengthlist_line_256x7_class0[] = {
  106927. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106928. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106929. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106930. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106931. };
  106932. static static_codebook _huff_book_line_256x7_class0 = {
  106933. 1, 64,
  106934. _huff_lengthlist_line_256x7_class0,
  106935. 0, 0, 0, 0, 0,
  106936. NULL,
  106937. NULL,
  106938. NULL,
  106939. NULL,
  106940. 0
  106941. };
  106942. static long _huff_lengthlist_line_256x7_class1[] = {
  106943. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106944. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106945. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106946. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106947. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106948. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106949. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106950. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106951. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106952. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106953. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106954. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106955. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106956. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106957. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106958. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106959. };
  106960. static static_codebook _huff_book_line_256x7_class1 = {
  106961. 1, 256,
  106962. _huff_lengthlist_line_256x7_class1,
  106963. 0, 0, 0, 0, 0,
  106964. NULL,
  106965. NULL,
  106966. NULL,
  106967. NULL,
  106968. 0
  106969. };
  106970. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106971. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106972. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106973. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106974. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106975. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106976. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106977. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106978. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106979. };
  106980. static static_codebook _huff_book_line_512x17_0sub0 = {
  106981. 1, 128,
  106982. _huff_lengthlist_line_512x17_0sub0,
  106983. 0, 0, 0, 0, 0,
  106984. NULL,
  106985. NULL,
  106986. NULL,
  106987. NULL,
  106988. 0
  106989. };
  106990. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106991. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106992. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106993. };
  106994. static static_codebook _huff_book_line_512x17_1sub0 = {
  106995. 1, 32,
  106996. _huff_lengthlist_line_512x17_1sub0,
  106997. 0, 0, 0, 0, 0,
  106998. NULL,
  106999. NULL,
  107000. NULL,
  107001. NULL,
  107002. 0
  107003. };
  107004. static long _huff_lengthlist_line_512x17_1sub1[] = {
  107005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107007. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  107008. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  107009. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  107010. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  107011. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  107012. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107013. };
  107014. static static_codebook _huff_book_line_512x17_1sub1 = {
  107015. 1, 128,
  107016. _huff_lengthlist_line_512x17_1sub1,
  107017. 0, 0, 0, 0, 0,
  107018. NULL,
  107019. NULL,
  107020. NULL,
  107021. NULL,
  107022. 0
  107023. };
  107024. static long _huff_lengthlist_line_512x17_2sub1[] = {
  107025. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  107026. 5, 3,
  107027. };
  107028. static static_codebook _huff_book_line_512x17_2sub1 = {
  107029. 1, 18,
  107030. _huff_lengthlist_line_512x17_2sub1,
  107031. 0, 0, 0, 0, 0,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. NULL,
  107036. 0
  107037. };
  107038. static long _huff_lengthlist_line_512x17_2sub2[] = {
  107039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107040. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  107041. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  107042. 9, 8,
  107043. };
  107044. static static_codebook _huff_book_line_512x17_2sub2 = {
  107045. 1, 50,
  107046. _huff_lengthlist_line_512x17_2sub2,
  107047. 0, 0, 0, 0, 0,
  107048. NULL,
  107049. NULL,
  107050. NULL,
  107051. NULL,
  107052. 0
  107053. };
  107054. static long _huff_lengthlist_line_512x17_2sub3[] = {
  107055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107058. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  107059. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  107060. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107061. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107062. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107063. };
  107064. static static_codebook _huff_book_line_512x17_2sub3 = {
  107065. 1, 128,
  107066. _huff_lengthlist_line_512x17_2sub3,
  107067. 0, 0, 0, 0, 0,
  107068. NULL,
  107069. NULL,
  107070. NULL,
  107071. NULL,
  107072. 0
  107073. };
  107074. static long _huff_lengthlist_line_512x17_3sub1[] = {
  107075. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  107076. 5, 5,
  107077. };
  107078. static static_codebook _huff_book_line_512x17_3sub1 = {
  107079. 1, 18,
  107080. _huff_lengthlist_line_512x17_3sub1,
  107081. 0, 0, 0, 0, 0,
  107082. NULL,
  107083. NULL,
  107084. NULL,
  107085. NULL,
  107086. 0
  107087. };
  107088. static long _huff_lengthlist_line_512x17_3sub2[] = {
  107089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107090. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  107091. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  107092. 11,14,
  107093. };
  107094. static static_codebook _huff_book_line_512x17_3sub2 = {
  107095. 1, 50,
  107096. _huff_lengthlist_line_512x17_3sub2,
  107097. 0, 0, 0, 0, 0,
  107098. NULL,
  107099. NULL,
  107100. NULL,
  107101. NULL,
  107102. 0
  107103. };
  107104. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107108. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107109. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107110. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107111. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107112. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107113. };
  107114. static static_codebook _huff_book_line_512x17_3sub3 = {
  107115. 1, 128,
  107116. _huff_lengthlist_line_512x17_3sub3,
  107117. 0, 0, 0, 0, 0,
  107118. NULL,
  107119. NULL,
  107120. NULL,
  107121. NULL,
  107122. 0
  107123. };
  107124. static long _huff_lengthlist_line_512x17_class1[] = {
  107125. 1, 2, 3, 6, 5, 4, 7, 7,
  107126. };
  107127. static static_codebook _huff_book_line_512x17_class1 = {
  107128. 1, 8,
  107129. _huff_lengthlist_line_512x17_class1,
  107130. 0, 0, 0, 0, 0,
  107131. NULL,
  107132. NULL,
  107133. NULL,
  107134. NULL,
  107135. 0
  107136. };
  107137. static long _huff_lengthlist_line_512x17_class2[] = {
  107138. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107139. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107140. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107141. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107142. };
  107143. static static_codebook _huff_book_line_512x17_class2 = {
  107144. 1, 64,
  107145. _huff_lengthlist_line_512x17_class2,
  107146. 0, 0, 0, 0, 0,
  107147. NULL,
  107148. NULL,
  107149. NULL,
  107150. NULL,
  107151. 0
  107152. };
  107153. static long _huff_lengthlist_line_512x17_class3[] = {
  107154. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107155. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107156. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107157. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107158. };
  107159. static static_codebook _huff_book_line_512x17_class3 = {
  107160. 1, 64,
  107161. _huff_lengthlist_line_512x17_class3,
  107162. 0, 0, 0, 0, 0,
  107163. NULL,
  107164. NULL,
  107165. NULL,
  107166. NULL,
  107167. 0
  107168. };
  107169. static long _huff_lengthlist_line_128x4_class0[] = {
  107170. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107171. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107172. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107173. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107174. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107175. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107176. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107177. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107178. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107179. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107180. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107181. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107182. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107183. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107184. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107185. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107186. };
  107187. static static_codebook _huff_book_line_128x4_class0 = {
  107188. 1, 256,
  107189. _huff_lengthlist_line_128x4_class0,
  107190. 0, 0, 0, 0, 0,
  107191. NULL,
  107192. NULL,
  107193. NULL,
  107194. NULL,
  107195. 0
  107196. };
  107197. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107198. 2, 2, 2, 2,
  107199. };
  107200. static static_codebook _huff_book_line_128x4_0sub0 = {
  107201. 1, 4,
  107202. _huff_lengthlist_line_128x4_0sub0,
  107203. 0, 0, 0, 0, 0,
  107204. NULL,
  107205. NULL,
  107206. NULL,
  107207. NULL,
  107208. 0
  107209. };
  107210. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107211. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107212. };
  107213. static static_codebook _huff_book_line_128x4_0sub1 = {
  107214. 1, 10,
  107215. _huff_lengthlist_line_128x4_0sub1,
  107216. 0, 0, 0, 0, 0,
  107217. NULL,
  107218. NULL,
  107219. NULL,
  107220. NULL,
  107221. 0
  107222. };
  107223. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107225. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107226. };
  107227. static static_codebook _huff_book_line_128x4_0sub2 = {
  107228. 1, 25,
  107229. _huff_lengthlist_line_128x4_0sub2,
  107230. 0, 0, 0, 0, 0,
  107231. NULL,
  107232. NULL,
  107233. NULL,
  107234. NULL,
  107235. 0
  107236. };
  107237. static long _huff_lengthlist_line_128x4_0sub3[] = {
  107238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107240. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107241. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107242. };
  107243. static static_codebook _huff_book_line_128x4_0sub3 = {
  107244. 1, 64,
  107245. _huff_lengthlist_line_128x4_0sub3,
  107246. 0, 0, 0, 0, 0,
  107247. NULL,
  107248. NULL,
  107249. NULL,
  107250. NULL,
  107251. 0
  107252. };
  107253. static long _huff_lengthlist_line_256x4_class0[] = {
  107254. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107255. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107256. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107257. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107258. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107259. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107260. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107261. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107262. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107263. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107264. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107265. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107266. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107267. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107268. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107269. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107270. };
  107271. static static_codebook _huff_book_line_256x4_class0 = {
  107272. 1, 256,
  107273. _huff_lengthlist_line_256x4_class0,
  107274. 0, 0, 0, 0, 0,
  107275. NULL,
  107276. NULL,
  107277. NULL,
  107278. NULL,
  107279. 0
  107280. };
  107281. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107282. 2, 2, 2, 2,
  107283. };
  107284. static static_codebook _huff_book_line_256x4_0sub0 = {
  107285. 1, 4,
  107286. _huff_lengthlist_line_256x4_0sub0,
  107287. 0, 0, 0, 0, 0,
  107288. NULL,
  107289. NULL,
  107290. NULL,
  107291. NULL,
  107292. 0
  107293. };
  107294. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107295. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107296. };
  107297. static static_codebook _huff_book_line_256x4_0sub1 = {
  107298. 1, 10,
  107299. _huff_lengthlist_line_256x4_0sub1,
  107300. 0, 0, 0, 0, 0,
  107301. NULL,
  107302. NULL,
  107303. NULL,
  107304. NULL,
  107305. 0
  107306. };
  107307. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107309. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107310. };
  107311. static static_codebook _huff_book_line_256x4_0sub2 = {
  107312. 1, 25,
  107313. _huff_lengthlist_line_256x4_0sub2,
  107314. 0, 0, 0, 0, 0,
  107315. NULL,
  107316. NULL,
  107317. NULL,
  107318. NULL,
  107319. 0
  107320. };
  107321. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107324. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107325. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107326. };
  107327. static static_codebook _huff_book_line_256x4_0sub3 = {
  107328. 1, 64,
  107329. _huff_lengthlist_line_256x4_0sub3,
  107330. 0, 0, 0, 0, 0,
  107331. NULL,
  107332. NULL,
  107333. NULL,
  107334. NULL,
  107335. 0
  107336. };
  107337. static long _huff_lengthlist_line_128x7_class0[] = {
  107338. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107339. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107340. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107341. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107342. };
  107343. static static_codebook _huff_book_line_128x7_class0 = {
  107344. 1, 64,
  107345. _huff_lengthlist_line_128x7_class0,
  107346. 0, 0, 0, 0, 0,
  107347. NULL,
  107348. NULL,
  107349. NULL,
  107350. NULL,
  107351. 0
  107352. };
  107353. static long _huff_lengthlist_line_128x7_class1[] = {
  107354. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107355. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107356. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107357. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107358. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107359. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107360. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107361. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107362. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107363. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107364. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107365. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107366. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107367. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107368. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107369. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107370. };
  107371. static static_codebook _huff_book_line_128x7_class1 = {
  107372. 1, 256,
  107373. _huff_lengthlist_line_128x7_class1,
  107374. 0, 0, 0, 0, 0,
  107375. NULL,
  107376. NULL,
  107377. NULL,
  107378. NULL,
  107379. 0
  107380. };
  107381. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107382. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107383. };
  107384. static static_codebook _huff_book_line_128x7_0sub1 = {
  107385. 1, 9,
  107386. _huff_lengthlist_line_128x7_0sub1,
  107387. 0, 0, 0, 0, 0,
  107388. NULL,
  107389. NULL,
  107390. NULL,
  107391. NULL,
  107392. 0
  107393. };
  107394. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107396. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107397. };
  107398. static static_codebook _huff_book_line_128x7_0sub2 = {
  107399. 1, 25,
  107400. _huff_lengthlist_line_128x7_0sub2,
  107401. 0, 0, 0, 0, 0,
  107402. NULL,
  107403. NULL,
  107404. NULL,
  107405. NULL,
  107406. 0
  107407. };
  107408. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107411. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107412. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107413. };
  107414. static static_codebook _huff_book_line_128x7_0sub3 = {
  107415. 1, 64,
  107416. _huff_lengthlist_line_128x7_0sub3,
  107417. 0, 0, 0, 0, 0,
  107418. NULL,
  107419. NULL,
  107420. NULL,
  107421. NULL,
  107422. 0
  107423. };
  107424. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107425. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107426. };
  107427. static static_codebook _huff_book_line_128x7_1sub1 = {
  107428. 1, 9,
  107429. _huff_lengthlist_line_128x7_1sub1,
  107430. 0, 0, 0, 0, 0,
  107431. NULL,
  107432. NULL,
  107433. NULL,
  107434. NULL,
  107435. 0
  107436. };
  107437. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107439. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107440. };
  107441. static static_codebook _huff_book_line_128x7_1sub2 = {
  107442. 1, 25,
  107443. _huff_lengthlist_line_128x7_1sub2,
  107444. 0, 0, 0, 0, 0,
  107445. NULL,
  107446. NULL,
  107447. NULL,
  107448. NULL,
  107449. 0
  107450. };
  107451. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107454. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107455. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107456. };
  107457. static static_codebook _huff_book_line_128x7_1sub3 = {
  107458. 1, 64,
  107459. _huff_lengthlist_line_128x7_1sub3,
  107460. 0, 0, 0, 0, 0,
  107461. NULL,
  107462. NULL,
  107463. NULL,
  107464. NULL,
  107465. 0
  107466. };
  107467. static long _huff_lengthlist_line_128x11_class1[] = {
  107468. 1, 6, 3, 7, 2, 4, 5, 7,
  107469. };
  107470. static static_codebook _huff_book_line_128x11_class1 = {
  107471. 1, 8,
  107472. _huff_lengthlist_line_128x11_class1,
  107473. 0, 0, 0, 0, 0,
  107474. NULL,
  107475. NULL,
  107476. NULL,
  107477. NULL,
  107478. 0
  107479. };
  107480. static long _huff_lengthlist_line_128x11_class2[] = {
  107481. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107482. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107483. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107484. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107485. };
  107486. static static_codebook _huff_book_line_128x11_class2 = {
  107487. 1, 64,
  107488. _huff_lengthlist_line_128x11_class2,
  107489. 0, 0, 0, 0, 0,
  107490. NULL,
  107491. NULL,
  107492. NULL,
  107493. NULL,
  107494. 0
  107495. };
  107496. static long _huff_lengthlist_line_128x11_class3[] = {
  107497. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107498. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107499. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107500. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107501. };
  107502. static static_codebook _huff_book_line_128x11_class3 = {
  107503. 1, 64,
  107504. _huff_lengthlist_line_128x11_class3,
  107505. 0, 0, 0, 0, 0,
  107506. NULL,
  107507. NULL,
  107508. NULL,
  107509. NULL,
  107510. 0
  107511. };
  107512. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107513. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107514. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107515. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107516. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107517. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107518. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107519. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107520. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107521. };
  107522. static static_codebook _huff_book_line_128x11_0sub0 = {
  107523. 1, 128,
  107524. _huff_lengthlist_line_128x11_0sub0,
  107525. 0, 0, 0, 0, 0,
  107526. NULL,
  107527. NULL,
  107528. NULL,
  107529. NULL,
  107530. 0
  107531. };
  107532. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107533. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107534. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107535. };
  107536. static static_codebook _huff_book_line_128x11_1sub0 = {
  107537. 1, 32,
  107538. _huff_lengthlist_line_128x11_1sub0,
  107539. 0, 0, 0, 0, 0,
  107540. NULL,
  107541. NULL,
  107542. NULL,
  107543. NULL,
  107544. 0
  107545. };
  107546. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107549. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107550. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107551. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107552. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107553. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107554. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107555. };
  107556. static static_codebook _huff_book_line_128x11_1sub1 = {
  107557. 1, 128,
  107558. _huff_lengthlist_line_128x11_1sub1,
  107559. 0, 0, 0, 0, 0,
  107560. NULL,
  107561. NULL,
  107562. NULL,
  107563. NULL,
  107564. 0
  107565. };
  107566. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107567. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107568. 5, 5,
  107569. };
  107570. static static_codebook _huff_book_line_128x11_2sub1 = {
  107571. 1, 18,
  107572. _huff_lengthlist_line_128x11_2sub1,
  107573. 0, 0, 0, 0, 0,
  107574. NULL,
  107575. NULL,
  107576. NULL,
  107577. NULL,
  107578. 0
  107579. };
  107580. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107582. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107583. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107584. 8,11,
  107585. };
  107586. static static_codebook _huff_book_line_128x11_2sub2 = {
  107587. 1, 50,
  107588. _huff_lengthlist_line_128x11_2sub2,
  107589. 0, 0, 0, 0, 0,
  107590. NULL,
  107591. NULL,
  107592. NULL,
  107593. NULL,
  107594. 0
  107595. };
  107596. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107600. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107601. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107602. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107603. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107604. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107605. };
  107606. static static_codebook _huff_book_line_128x11_2sub3 = {
  107607. 1, 128,
  107608. _huff_lengthlist_line_128x11_2sub3,
  107609. 0, 0, 0, 0, 0,
  107610. NULL,
  107611. NULL,
  107612. NULL,
  107613. NULL,
  107614. 0
  107615. };
  107616. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107617. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107618. 5, 4,
  107619. };
  107620. static static_codebook _huff_book_line_128x11_3sub1 = {
  107621. 1, 18,
  107622. _huff_lengthlist_line_128x11_3sub1,
  107623. 0, 0, 0, 0, 0,
  107624. NULL,
  107625. NULL,
  107626. NULL,
  107627. NULL,
  107628. 0
  107629. };
  107630. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107632. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107633. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107634. 12, 6,
  107635. };
  107636. static static_codebook _huff_book_line_128x11_3sub2 = {
  107637. 1, 50,
  107638. _huff_lengthlist_line_128x11_3sub2,
  107639. 0, 0, 0, 0, 0,
  107640. NULL,
  107641. NULL,
  107642. NULL,
  107643. NULL,
  107644. 0
  107645. };
  107646. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107650. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107651. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107652. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107653. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107654. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107655. };
  107656. static static_codebook _huff_book_line_128x11_3sub3 = {
  107657. 1, 128,
  107658. _huff_lengthlist_line_128x11_3sub3,
  107659. 0, 0, 0, 0, 0,
  107660. NULL,
  107661. NULL,
  107662. NULL,
  107663. NULL,
  107664. 0
  107665. };
  107666. static long _huff_lengthlist_line_128x17_class1[] = {
  107667. 1, 3, 4, 7, 2, 5, 6, 7,
  107668. };
  107669. static static_codebook _huff_book_line_128x17_class1 = {
  107670. 1, 8,
  107671. _huff_lengthlist_line_128x17_class1,
  107672. 0, 0, 0, 0, 0,
  107673. NULL,
  107674. NULL,
  107675. NULL,
  107676. NULL,
  107677. 0
  107678. };
  107679. static long _huff_lengthlist_line_128x17_class2[] = {
  107680. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107681. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107682. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107683. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107684. };
  107685. static static_codebook _huff_book_line_128x17_class2 = {
  107686. 1, 64,
  107687. _huff_lengthlist_line_128x17_class2,
  107688. 0, 0, 0, 0, 0,
  107689. NULL,
  107690. NULL,
  107691. NULL,
  107692. NULL,
  107693. 0
  107694. };
  107695. static long _huff_lengthlist_line_128x17_class3[] = {
  107696. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107697. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107698. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107699. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107700. };
  107701. static static_codebook _huff_book_line_128x17_class3 = {
  107702. 1, 64,
  107703. _huff_lengthlist_line_128x17_class3,
  107704. 0, 0, 0, 0, 0,
  107705. NULL,
  107706. NULL,
  107707. NULL,
  107708. NULL,
  107709. 0
  107710. };
  107711. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107712. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107713. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107714. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107715. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107716. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107717. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107718. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107719. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107720. };
  107721. static static_codebook _huff_book_line_128x17_0sub0 = {
  107722. 1, 128,
  107723. _huff_lengthlist_line_128x17_0sub0,
  107724. 0, 0, 0, 0, 0,
  107725. NULL,
  107726. NULL,
  107727. NULL,
  107728. NULL,
  107729. 0
  107730. };
  107731. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107732. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107733. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107734. };
  107735. static static_codebook _huff_book_line_128x17_1sub0 = {
  107736. 1, 32,
  107737. _huff_lengthlist_line_128x17_1sub0,
  107738. 0, 0, 0, 0, 0,
  107739. NULL,
  107740. NULL,
  107741. NULL,
  107742. NULL,
  107743. 0
  107744. };
  107745. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107748. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107749. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107750. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107751. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107752. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107753. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107754. };
  107755. static static_codebook _huff_book_line_128x17_1sub1 = {
  107756. 1, 128,
  107757. _huff_lengthlist_line_128x17_1sub1,
  107758. 0, 0, 0, 0, 0,
  107759. NULL,
  107760. NULL,
  107761. NULL,
  107762. NULL,
  107763. 0
  107764. };
  107765. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107766. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107767. 9, 4,
  107768. };
  107769. static static_codebook _huff_book_line_128x17_2sub1 = {
  107770. 1, 18,
  107771. _huff_lengthlist_line_128x17_2sub1,
  107772. 0, 0, 0, 0, 0,
  107773. NULL,
  107774. NULL,
  107775. NULL,
  107776. NULL,
  107777. 0
  107778. };
  107779. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107781. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107782. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107783. 13,13,
  107784. };
  107785. static static_codebook _huff_book_line_128x17_2sub2 = {
  107786. 1, 50,
  107787. _huff_lengthlist_line_128x17_2sub2,
  107788. 0, 0, 0, 0, 0,
  107789. NULL,
  107790. NULL,
  107791. NULL,
  107792. NULL,
  107793. 0
  107794. };
  107795. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107799. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107800. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107801. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107802. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107803. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107804. };
  107805. static static_codebook _huff_book_line_128x17_2sub3 = {
  107806. 1, 128,
  107807. _huff_lengthlist_line_128x17_2sub3,
  107808. 0, 0, 0, 0, 0,
  107809. NULL,
  107810. NULL,
  107811. NULL,
  107812. NULL,
  107813. 0
  107814. };
  107815. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107816. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107817. 6, 4,
  107818. };
  107819. static static_codebook _huff_book_line_128x17_3sub1 = {
  107820. 1, 18,
  107821. _huff_lengthlist_line_128x17_3sub1,
  107822. 0, 0, 0, 0, 0,
  107823. NULL,
  107824. NULL,
  107825. NULL,
  107826. NULL,
  107827. 0
  107828. };
  107829. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107831. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107832. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107833. 10, 8,
  107834. };
  107835. static static_codebook _huff_book_line_128x17_3sub2 = {
  107836. 1, 50,
  107837. _huff_lengthlist_line_128x17_3sub2,
  107838. 0, 0, 0, 0, 0,
  107839. NULL,
  107840. NULL,
  107841. NULL,
  107842. NULL,
  107843. 0
  107844. };
  107845. static long _huff_lengthlist_line_128x17_3sub3[] = {
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107849. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107850. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107851. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107852. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107853. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107854. };
  107855. static static_codebook _huff_book_line_128x17_3sub3 = {
  107856. 1, 128,
  107857. _huff_lengthlist_line_128x17_3sub3,
  107858. 0, 0, 0, 0, 0,
  107859. NULL,
  107860. NULL,
  107861. NULL,
  107862. NULL,
  107863. 0
  107864. };
  107865. static long _huff_lengthlist_line_1024x27_class1[] = {
  107866. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107867. };
  107868. static static_codebook _huff_book_line_1024x27_class1 = {
  107869. 1, 16,
  107870. _huff_lengthlist_line_1024x27_class1,
  107871. 0, 0, 0, 0, 0,
  107872. NULL,
  107873. NULL,
  107874. NULL,
  107875. NULL,
  107876. 0
  107877. };
  107878. static long _huff_lengthlist_line_1024x27_class2[] = {
  107879. 1, 4, 2, 6, 3, 7, 5, 7,
  107880. };
  107881. static static_codebook _huff_book_line_1024x27_class2 = {
  107882. 1, 8,
  107883. _huff_lengthlist_line_1024x27_class2,
  107884. 0, 0, 0, 0, 0,
  107885. NULL,
  107886. NULL,
  107887. NULL,
  107888. NULL,
  107889. 0
  107890. };
  107891. static long _huff_lengthlist_line_1024x27_class3[] = {
  107892. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107893. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107894. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107895. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107896. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107897. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107898. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107899. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107900. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107901. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107902. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107903. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107904. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107905. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107906. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107907. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107908. };
  107909. static static_codebook _huff_book_line_1024x27_class3 = {
  107910. 1, 256,
  107911. _huff_lengthlist_line_1024x27_class3,
  107912. 0, 0, 0, 0, 0,
  107913. NULL,
  107914. NULL,
  107915. NULL,
  107916. NULL,
  107917. 0
  107918. };
  107919. static long _huff_lengthlist_line_1024x27_class4[] = {
  107920. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107921. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107922. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107923. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107924. };
  107925. static static_codebook _huff_book_line_1024x27_class4 = {
  107926. 1, 64,
  107927. _huff_lengthlist_line_1024x27_class4,
  107928. 0, 0, 0, 0, 0,
  107929. NULL,
  107930. NULL,
  107931. NULL,
  107932. NULL,
  107933. 0
  107934. };
  107935. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107936. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107937. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107938. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107939. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107940. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107941. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107942. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107943. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107944. };
  107945. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107946. 1, 128,
  107947. _huff_lengthlist_line_1024x27_0sub0,
  107948. 0, 0, 0, 0, 0,
  107949. NULL,
  107950. NULL,
  107951. NULL,
  107952. NULL,
  107953. 0
  107954. };
  107955. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107956. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107957. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107958. };
  107959. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107960. 1, 32,
  107961. _huff_lengthlist_line_1024x27_1sub0,
  107962. 0, 0, 0, 0, 0,
  107963. NULL,
  107964. NULL,
  107965. NULL,
  107966. NULL,
  107967. 0
  107968. };
  107969. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107972. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107973. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107974. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107975. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107976. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107977. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107978. };
  107979. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107980. 1, 128,
  107981. _huff_lengthlist_line_1024x27_1sub1,
  107982. 0, 0, 0, 0, 0,
  107983. NULL,
  107984. NULL,
  107985. NULL,
  107986. NULL,
  107987. 0
  107988. };
  107989. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107990. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107991. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107992. };
  107993. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107994. 1, 32,
  107995. _huff_lengthlist_line_1024x27_2sub0,
  107996. 0, 0, 0, 0, 0,
  107997. NULL,
  107998. NULL,
  107999. NULL,
  108000. NULL,
  108001. 0
  108002. };
  108003. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  108004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108006. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  108007. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  108008. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  108009. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  108010. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  108011. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  108012. };
  108013. static static_codebook _huff_book_line_1024x27_2sub1 = {
  108014. 1, 128,
  108015. _huff_lengthlist_line_1024x27_2sub1,
  108016. 0, 0, 0, 0, 0,
  108017. NULL,
  108018. NULL,
  108019. NULL,
  108020. NULL,
  108021. 0
  108022. };
  108023. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  108024. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  108025. 5, 5,
  108026. };
  108027. static static_codebook _huff_book_line_1024x27_3sub1 = {
  108028. 1, 18,
  108029. _huff_lengthlist_line_1024x27_3sub1,
  108030. 0, 0, 0, 0, 0,
  108031. NULL,
  108032. NULL,
  108033. NULL,
  108034. NULL,
  108035. 0
  108036. };
  108037. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  108038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108039. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  108040. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  108041. 9,11,
  108042. };
  108043. static static_codebook _huff_book_line_1024x27_3sub2 = {
  108044. 1, 50,
  108045. _huff_lengthlist_line_1024x27_3sub2,
  108046. 0, 0, 0, 0, 0,
  108047. NULL,
  108048. NULL,
  108049. NULL,
  108050. NULL,
  108051. 0
  108052. };
  108053. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  108054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108057. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  108058. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  108059. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108060. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108061. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108062. };
  108063. static static_codebook _huff_book_line_1024x27_3sub3 = {
  108064. 1, 128,
  108065. _huff_lengthlist_line_1024x27_3sub3,
  108066. 0, 0, 0, 0, 0,
  108067. NULL,
  108068. NULL,
  108069. NULL,
  108070. NULL,
  108071. 0
  108072. };
  108073. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  108074. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  108075. 5, 4,
  108076. };
  108077. static static_codebook _huff_book_line_1024x27_4sub1 = {
  108078. 1, 18,
  108079. _huff_lengthlist_line_1024x27_4sub1,
  108080. 0, 0, 0, 0, 0,
  108081. NULL,
  108082. NULL,
  108083. NULL,
  108084. NULL,
  108085. 0
  108086. };
  108087. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  108088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108089. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  108090. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  108091. 9,12,
  108092. };
  108093. static static_codebook _huff_book_line_1024x27_4sub2 = {
  108094. 1, 50,
  108095. _huff_lengthlist_line_1024x27_4sub2,
  108096. 0, 0, 0, 0, 0,
  108097. NULL,
  108098. NULL,
  108099. NULL,
  108100. NULL,
  108101. 0
  108102. };
  108103. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108107. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108108. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108109. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108110. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108111. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108112. };
  108113. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108114. 1, 128,
  108115. _huff_lengthlist_line_1024x27_4sub3,
  108116. 0, 0, 0, 0, 0,
  108117. NULL,
  108118. NULL,
  108119. NULL,
  108120. NULL,
  108121. 0
  108122. };
  108123. static long _huff_lengthlist_line_2048x27_class1[] = {
  108124. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108125. };
  108126. static static_codebook _huff_book_line_2048x27_class1 = {
  108127. 1, 16,
  108128. _huff_lengthlist_line_2048x27_class1,
  108129. 0, 0, 0, 0, 0,
  108130. NULL,
  108131. NULL,
  108132. NULL,
  108133. NULL,
  108134. 0
  108135. };
  108136. static long _huff_lengthlist_line_2048x27_class2[] = {
  108137. 1, 2, 3, 6, 4, 7, 5, 7,
  108138. };
  108139. static static_codebook _huff_book_line_2048x27_class2 = {
  108140. 1, 8,
  108141. _huff_lengthlist_line_2048x27_class2,
  108142. 0, 0, 0, 0, 0,
  108143. NULL,
  108144. NULL,
  108145. NULL,
  108146. NULL,
  108147. 0
  108148. };
  108149. static long _huff_lengthlist_line_2048x27_class3[] = {
  108150. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108151. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108152. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108153. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108154. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108155. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108156. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108157. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108158. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108159. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108160. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108161. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108162. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108163. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108164. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108165. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108166. };
  108167. static static_codebook _huff_book_line_2048x27_class3 = {
  108168. 1, 256,
  108169. _huff_lengthlist_line_2048x27_class3,
  108170. 0, 0, 0, 0, 0,
  108171. NULL,
  108172. NULL,
  108173. NULL,
  108174. NULL,
  108175. 0
  108176. };
  108177. static long _huff_lengthlist_line_2048x27_class4[] = {
  108178. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108179. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108180. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108181. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108182. };
  108183. static static_codebook _huff_book_line_2048x27_class4 = {
  108184. 1, 64,
  108185. _huff_lengthlist_line_2048x27_class4,
  108186. 0, 0, 0, 0, 0,
  108187. NULL,
  108188. NULL,
  108189. NULL,
  108190. NULL,
  108191. 0
  108192. };
  108193. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108194. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108195. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108196. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108197. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108198. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108199. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108200. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108201. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108202. };
  108203. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108204. 1, 128,
  108205. _huff_lengthlist_line_2048x27_0sub0,
  108206. 0, 0, 0, 0, 0,
  108207. NULL,
  108208. NULL,
  108209. NULL,
  108210. NULL,
  108211. 0
  108212. };
  108213. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108214. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108215. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108216. };
  108217. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108218. 1, 32,
  108219. _huff_lengthlist_line_2048x27_1sub0,
  108220. 0, 0, 0, 0, 0,
  108221. NULL,
  108222. NULL,
  108223. NULL,
  108224. NULL,
  108225. 0
  108226. };
  108227. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  108228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108230. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108231. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108232. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108233. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108234. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108235. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108236. };
  108237. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108238. 1, 128,
  108239. _huff_lengthlist_line_2048x27_1sub1,
  108240. 0, 0, 0, 0, 0,
  108241. NULL,
  108242. NULL,
  108243. NULL,
  108244. NULL,
  108245. 0
  108246. };
  108247. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108248. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108249. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108250. };
  108251. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108252. 1, 32,
  108253. _huff_lengthlist_line_2048x27_2sub0,
  108254. 0, 0, 0, 0, 0,
  108255. NULL,
  108256. NULL,
  108257. NULL,
  108258. NULL,
  108259. 0
  108260. };
  108261. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108264. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108265. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108266. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108267. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108268. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108269. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108270. };
  108271. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108272. 1, 128,
  108273. _huff_lengthlist_line_2048x27_2sub1,
  108274. 0, 0, 0, 0, 0,
  108275. NULL,
  108276. NULL,
  108277. NULL,
  108278. NULL,
  108279. 0
  108280. };
  108281. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108282. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108283. 5, 5,
  108284. };
  108285. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108286. 1, 18,
  108287. _huff_lengthlist_line_2048x27_3sub1,
  108288. 0, 0, 0, 0, 0,
  108289. NULL,
  108290. NULL,
  108291. NULL,
  108292. NULL,
  108293. 0
  108294. };
  108295. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108297. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108298. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108299. 10,12,
  108300. };
  108301. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108302. 1, 50,
  108303. _huff_lengthlist_line_2048x27_3sub2,
  108304. 0, 0, 0, 0, 0,
  108305. NULL,
  108306. NULL,
  108307. NULL,
  108308. NULL,
  108309. 0
  108310. };
  108311. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  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, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108316. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108317. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108318. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108319. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108320. };
  108321. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108322. 1, 128,
  108323. _huff_lengthlist_line_2048x27_3sub3,
  108324. 0, 0, 0, 0, 0,
  108325. NULL,
  108326. NULL,
  108327. NULL,
  108328. NULL,
  108329. 0
  108330. };
  108331. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108332. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108333. 4, 5,
  108334. };
  108335. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108336. 1, 18,
  108337. _huff_lengthlist_line_2048x27_4sub1,
  108338. 0, 0, 0, 0, 0,
  108339. NULL,
  108340. NULL,
  108341. NULL,
  108342. NULL,
  108343. 0
  108344. };
  108345. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108347. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108348. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108349. 10,10,
  108350. };
  108351. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108352. 1, 50,
  108353. _huff_lengthlist_line_2048x27_4sub2,
  108354. 0, 0, 0, 0, 0,
  108355. NULL,
  108356. NULL,
  108357. NULL,
  108358. NULL,
  108359. 0
  108360. };
  108361. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  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, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108366. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108367. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108368. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108369. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108370. };
  108371. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108372. 1, 128,
  108373. _huff_lengthlist_line_2048x27_4sub3,
  108374. 0, 0, 0, 0, 0,
  108375. NULL,
  108376. NULL,
  108377. NULL,
  108378. NULL,
  108379. 0
  108380. };
  108381. static long _huff_lengthlist_line_256x4low_class0[] = {
  108382. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108383. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108384. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108385. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108386. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108387. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108388. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108389. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108390. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108391. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108392. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108393. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108394. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108395. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108396. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108397. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108398. };
  108399. static static_codebook _huff_book_line_256x4low_class0 = {
  108400. 1, 256,
  108401. _huff_lengthlist_line_256x4low_class0,
  108402. 0, 0, 0, 0, 0,
  108403. NULL,
  108404. NULL,
  108405. NULL,
  108406. NULL,
  108407. 0
  108408. };
  108409. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108410. 1, 3, 2, 3,
  108411. };
  108412. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108413. 1, 4,
  108414. _huff_lengthlist_line_256x4low_0sub0,
  108415. 0, 0, 0, 0, 0,
  108416. NULL,
  108417. NULL,
  108418. NULL,
  108419. NULL,
  108420. 0
  108421. };
  108422. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108423. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108424. };
  108425. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108426. 1, 10,
  108427. _huff_lengthlist_line_256x4low_0sub1,
  108428. 0, 0, 0, 0, 0,
  108429. NULL,
  108430. NULL,
  108431. NULL,
  108432. NULL,
  108433. 0
  108434. };
  108435. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108437. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108438. };
  108439. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108440. 1, 25,
  108441. _huff_lengthlist_line_256x4low_0sub2,
  108442. 0, 0, 0, 0, 0,
  108443. NULL,
  108444. NULL,
  108445. NULL,
  108446. NULL,
  108447. 0
  108448. };
  108449. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  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, 3, 4, 2, 4, 3, 5, 4,
  108452. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108453. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108454. };
  108455. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108456. 1, 64,
  108457. _huff_lengthlist_line_256x4low_0sub3,
  108458. 0, 0, 0, 0, 0,
  108459. NULL,
  108460. NULL,
  108461. NULL,
  108462. NULL,
  108463. 0
  108464. };
  108465. /*** End of inlined file: floor_books.h ***/
  108466. static static_codebook *_floor_128x4_books[]={
  108467. &_huff_book_line_128x4_class0,
  108468. &_huff_book_line_128x4_0sub0,
  108469. &_huff_book_line_128x4_0sub1,
  108470. &_huff_book_line_128x4_0sub2,
  108471. &_huff_book_line_128x4_0sub3,
  108472. };
  108473. static static_codebook *_floor_256x4_books[]={
  108474. &_huff_book_line_256x4_class0,
  108475. &_huff_book_line_256x4_0sub0,
  108476. &_huff_book_line_256x4_0sub1,
  108477. &_huff_book_line_256x4_0sub2,
  108478. &_huff_book_line_256x4_0sub3,
  108479. };
  108480. static static_codebook *_floor_128x7_books[]={
  108481. &_huff_book_line_128x7_class0,
  108482. &_huff_book_line_128x7_class1,
  108483. &_huff_book_line_128x7_0sub1,
  108484. &_huff_book_line_128x7_0sub2,
  108485. &_huff_book_line_128x7_0sub3,
  108486. &_huff_book_line_128x7_1sub1,
  108487. &_huff_book_line_128x7_1sub2,
  108488. &_huff_book_line_128x7_1sub3,
  108489. };
  108490. static static_codebook *_floor_256x7_books[]={
  108491. &_huff_book_line_256x7_class0,
  108492. &_huff_book_line_256x7_class1,
  108493. &_huff_book_line_256x7_0sub1,
  108494. &_huff_book_line_256x7_0sub2,
  108495. &_huff_book_line_256x7_0sub3,
  108496. &_huff_book_line_256x7_1sub1,
  108497. &_huff_book_line_256x7_1sub2,
  108498. &_huff_book_line_256x7_1sub3,
  108499. };
  108500. static static_codebook *_floor_128x11_books[]={
  108501. &_huff_book_line_128x11_class1,
  108502. &_huff_book_line_128x11_class2,
  108503. &_huff_book_line_128x11_class3,
  108504. &_huff_book_line_128x11_0sub0,
  108505. &_huff_book_line_128x11_1sub0,
  108506. &_huff_book_line_128x11_1sub1,
  108507. &_huff_book_line_128x11_2sub1,
  108508. &_huff_book_line_128x11_2sub2,
  108509. &_huff_book_line_128x11_2sub3,
  108510. &_huff_book_line_128x11_3sub1,
  108511. &_huff_book_line_128x11_3sub2,
  108512. &_huff_book_line_128x11_3sub3,
  108513. };
  108514. static static_codebook *_floor_128x17_books[]={
  108515. &_huff_book_line_128x17_class1,
  108516. &_huff_book_line_128x17_class2,
  108517. &_huff_book_line_128x17_class3,
  108518. &_huff_book_line_128x17_0sub0,
  108519. &_huff_book_line_128x17_1sub0,
  108520. &_huff_book_line_128x17_1sub1,
  108521. &_huff_book_line_128x17_2sub1,
  108522. &_huff_book_line_128x17_2sub2,
  108523. &_huff_book_line_128x17_2sub3,
  108524. &_huff_book_line_128x17_3sub1,
  108525. &_huff_book_line_128x17_3sub2,
  108526. &_huff_book_line_128x17_3sub3,
  108527. };
  108528. static static_codebook *_floor_256x4low_books[]={
  108529. &_huff_book_line_256x4low_class0,
  108530. &_huff_book_line_256x4low_0sub0,
  108531. &_huff_book_line_256x4low_0sub1,
  108532. &_huff_book_line_256x4low_0sub2,
  108533. &_huff_book_line_256x4low_0sub3,
  108534. };
  108535. static static_codebook *_floor_1024x27_books[]={
  108536. &_huff_book_line_1024x27_class1,
  108537. &_huff_book_line_1024x27_class2,
  108538. &_huff_book_line_1024x27_class3,
  108539. &_huff_book_line_1024x27_class4,
  108540. &_huff_book_line_1024x27_0sub0,
  108541. &_huff_book_line_1024x27_1sub0,
  108542. &_huff_book_line_1024x27_1sub1,
  108543. &_huff_book_line_1024x27_2sub0,
  108544. &_huff_book_line_1024x27_2sub1,
  108545. &_huff_book_line_1024x27_3sub1,
  108546. &_huff_book_line_1024x27_3sub2,
  108547. &_huff_book_line_1024x27_3sub3,
  108548. &_huff_book_line_1024x27_4sub1,
  108549. &_huff_book_line_1024x27_4sub2,
  108550. &_huff_book_line_1024x27_4sub3,
  108551. };
  108552. static static_codebook *_floor_2048x27_books[]={
  108553. &_huff_book_line_2048x27_class1,
  108554. &_huff_book_line_2048x27_class2,
  108555. &_huff_book_line_2048x27_class3,
  108556. &_huff_book_line_2048x27_class4,
  108557. &_huff_book_line_2048x27_0sub0,
  108558. &_huff_book_line_2048x27_1sub0,
  108559. &_huff_book_line_2048x27_1sub1,
  108560. &_huff_book_line_2048x27_2sub0,
  108561. &_huff_book_line_2048x27_2sub1,
  108562. &_huff_book_line_2048x27_3sub1,
  108563. &_huff_book_line_2048x27_3sub2,
  108564. &_huff_book_line_2048x27_3sub3,
  108565. &_huff_book_line_2048x27_4sub1,
  108566. &_huff_book_line_2048x27_4sub2,
  108567. &_huff_book_line_2048x27_4sub3,
  108568. };
  108569. static static_codebook *_floor_512x17_books[]={
  108570. &_huff_book_line_512x17_class1,
  108571. &_huff_book_line_512x17_class2,
  108572. &_huff_book_line_512x17_class3,
  108573. &_huff_book_line_512x17_0sub0,
  108574. &_huff_book_line_512x17_1sub0,
  108575. &_huff_book_line_512x17_1sub1,
  108576. &_huff_book_line_512x17_2sub1,
  108577. &_huff_book_line_512x17_2sub2,
  108578. &_huff_book_line_512x17_2sub3,
  108579. &_huff_book_line_512x17_3sub1,
  108580. &_huff_book_line_512x17_3sub2,
  108581. &_huff_book_line_512x17_3sub3,
  108582. };
  108583. static static_codebook **_floor_books[10]={
  108584. _floor_128x4_books,
  108585. _floor_256x4_books,
  108586. _floor_128x7_books,
  108587. _floor_256x7_books,
  108588. _floor_128x11_books,
  108589. _floor_128x17_books,
  108590. _floor_256x4low_books,
  108591. _floor_1024x27_books,
  108592. _floor_2048x27_books,
  108593. _floor_512x17_books,
  108594. };
  108595. static vorbis_info_floor1 _floor[10]={
  108596. {
  108597. 1,{0},{4},{2},{0},
  108598. {{1,2,3,4}},
  108599. 4,{0,128, 33,8,16,70},
  108600. 60,30,500, 1.,18., -1
  108601. },
  108602. {
  108603. 1,{0},{4},{2},{0},
  108604. {{1,2,3,4}},
  108605. 4,{0,256, 66,16,32,140},
  108606. 60,30,500, 1.,18., -1
  108607. },
  108608. {
  108609. 2,{0,1},{3,4},{2,2},{0,1},
  108610. {{-1,2,3,4},{-1,5,6,7}},
  108611. 4,{0,128, 14,4,58, 2,8,28,90},
  108612. 60,30,500, 1.,18., -1
  108613. },
  108614. {
  108615. 2,{0,1},{3,4},{2,2},{0,1},
  108616. {{-1,2,3,4},{-1,5,6,7}},
  108617. 4,{0,256, 28,8,116, 4,16,56,180},
  108618. 60,30,500, 1.,18., -1
  108619. },
  108620. {
  108621. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108622. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108623. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108624. 60,30,500, 1,18., -1
  108625. },
  108626. {
  108627. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108628. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108629. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108630. 60,30,500, 1,18., -1
  108631. },
  108632. {
  108633. 1,{0},{4},{2},{0},
  108634. {{1,2,3,4}},
  108635. 4,{0,256, 66,16,32,140},
  108636. 60,30,500, 1.,18., -1
  108637. },
  108638. {
  108639. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108640. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108641. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108642. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108643. 60,30,500, 3,18., -1 /* lowpass */
  108644. },
  108645. {
  108646. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108647. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108648. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108649. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108650. 60,30,500, 3,18., -1 /* lowpass */
  108651. },
  108652. {
  108653. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108654. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108655. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108656. 7,23,39, 55,79,110, 156,232,360},
  108657. 60,30,500, 1,18., -1 /* lowpass! */
  108658. },
  108659. };
  108660. /*** End of inlined file: floor_all.h ***/
  108661. /*** Start of inlined file: residue_44.h ***/
  108662. /*** Start of inlined file: res_books_stereo.h ***/
  108663. static long _vq_quantlist__16c0_s_p1_0[] = {
  108664. 1,
  108665. 0,
  108666. 2,
  108667. };
  108668. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108669. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108670. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108675. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108680. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108715. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108720. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108725. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108760. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108761. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108766. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 0,
  108767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108770. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108771. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109079. 0,
  109080. };
  109081. static float _vq_quantthresh__16c0_s_p1_0[] = {
  109082. -0.5, 0.5,
  109083. };
  109084. static long _vq_quantmap__16c0_s_p1_0[] = {
  109085. 1, 0, 2,
  109086. };
  109087. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  109088. _vq_quantthresh__16c0_s_p1_0,
  109089. _vq_quantmap__16c0_s_p1_0,
  109090. 3,
  109091. 3
  109092. };
  109093. static static_codebook _16c0_s_p1_0 = {
  109094. 8, 6561,
  109095. _vq_lengthlist__16c0_s_p1_0,
  109096. 1, -535822336, 1611661312, 2, 0,
  109097. _vq_quantlist__16c0_s_p1_0,
  109098. NULL,
  109099. &_vq_auxt__16c0_s_p1_0,
  109100. NULL,
  109101. 0
  109102. };
  109103. static long _vq_quantlist__16c0_s_p2_0[] = {
  109104. 2,
  109105. 1,
  109106. 3,
  109107. 0,
  109108. 4,
  109109. };
  109110. static long _vq_lengthlist__16c0_s_p2_0[] = {
  109111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109150. 0,
  109151. };
  109152. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109153. -1.5, -0.5, 0.5, 1.5,
  109154. };
  109155. static long _vq_quantmap__16c0_s_p2_0[] = {
  109156. 3, 1, 0, 2, 4,
  109157. };
  109158. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109159. _vq_quantthresh__16c0_s_p2_0,
  109160. _vq_quantmap__16c0_s_p2_0,
  109161. 5,
  109162. 5
  109163. };
  109164. static static_codebook _16c0_s_p2_0 = {
  109165. 4, 625,
  109166. _vq_lengthlist__16c0_s_p2_0,
  109167. 1, -533725184, 1611661312, 3, 0,
  109168. _vq_quantlist__16c0_s_p2_0,
  109169. NULL,
  109170. &_vq_auxt__16c0_s_p2_0,
  109171. NULL,
  109172. 0
  109173. };
  109174. static long _vq_quantlist__16c0_s_p3_0[] = {
  109175. 2,
  109176. 1,
  109177. 3,
  109178. 0,
  109179. 4,
  109180. };
  109181. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109182. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109185. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109188. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109221. 0,
  109222. };
  109223. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109224. -1.5, -0.5, 0.5, 1.5,
  109225. };
  109226. static long _vq_quantmap__16c0_s_p3_0[] = {
  109227. 3, 1, 0, 2, 4,
  109228. };
  109229. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109230. _vq_quantthresh__16c0_s_p3_0,
  109231. _vq_quantmap__16c0_s_p3_0,
  109232. 5,
  109233. 5
  109234. };
  109235. static static_codebook _16c0_s_p3_0 = {
  109236. 4, 625,
  109237. _vq_lengthlist__16c0_s_p3_0,
  109238. 1, -533725184, 1611661312, 3, 0,
  109239. _vq_quantlist__16c0_s_p3_0,
  109240. NULL,
  109241. &_vq_auxt__16c0_s_p3_0,
  109242. NULL,
  109243. 0
  109244. };
  109245. static long _vq_quantlist__16c0_s_p4_0[] = {
  109246. 4,
  109247. 3,
  109248. 5,
  109249. 2,
  109250. 6,
  109251. 1,
  109252. 7,
  109253. 0,
  109254. 8,
  109255. };
  109256. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109257. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109258. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109259. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109260. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109261. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109262. 0,
  109263. };
  109264. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109265. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109266. };
  109267. static long _vq_quantmap__16c0_s_p4_0[] = {
  109268. 7, 5, 3, 1, 0, 2, 4, 6,
  109269. 8,
  109270. };
  109271. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109272. _vq_quantthresh__16c0_s_p4_0,
  109273. _vq_quantmap__16c0_s_p4_0,
  109274. 9,
  109275. 9
  109276. };
  109277. static static_codebook _16c0_s_p4_0 = {
  109278. 2, 81,
  109279. _vq_lengthlist__16c0_s_p4_0,
  109280. 1, -531628032, 1611661312, 4, 0,
  109281. _vq_quantlist__16c0_s_p4_0,
  109282. NULL,
  109283. &_vq_auxt__16c0_s_p4_0,
  109284. NULL,
  109285. 0
  109286. };
  109287. static long _vq_quantlist__16c0_s_p5_0[] = {
  109288. 4,
  109289. 3,
  109290. 5,
  109291. 2,
  109292. 6,
  109293. 1,
  109294. 7,
  109295. 0,
  109296. 8,
  109297. };
  109298. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109299. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109300. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109301. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109302. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109303. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109304. 10,
  109305. };
  109306. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109307. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109308. };
  109309. static long _vq_quantmap__16c0_s_p5_0[] = {
  109310. 7, 5, 3, 1, 0, 2, 4, 6,
  109311. 8,
  109312. };
  109313. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109314. _vq_quantthresh__16c0_s_p5_0,
  109315. _vq_quantmap__16c0_s_p5_0,
  109316. 9,
  109317. 9
  109318. };
  109319. static static_codebook _16c0_s_p5_0 = {
  109320. 2, 81,
  109321. _vq_lengthlist__16c0_s_p5_0,
  109322. 1, -531628032, 1611661312, 4, 0,
  109323. _vq_quantlist__16c0_s_p5_0,
  109324. NULL,
  109325. &_vq_auxt__16c0_s_p5_0,
  109326. NULL,
  109327. 0
  109328. };
  109329. static long _vq_quantlist__16c0_s_p6_0[] = {
  109330. 8,
  109331. 7,
  109332. 9,
  109333. 6,
  109334. 10,
  109335. 5,
  109336. 11,
  109337. 4,
  109338. 12,
  109339. 3,
  109340. 13,
  109341. 2,
  109342. 14,
  109343. 1,
  109344. 15,
  109345. 0,
  109346. 16,
  109347. };
  109348. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109349. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109350. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109351. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109352. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109353. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109354. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109355. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109356. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109357. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109358. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109359. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109360. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109361. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109362. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109363. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109364. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109365. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109366. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109367. 14,
  109368. };
  109369. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109370. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109371. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109372. };
  109373. static long _vq_quantmap__16c0_s_p6_0[] = {
  109374. 15, 13, 11, 9, 7, 5, 3, 1,
  109375. 0, 2, 4, 6, 8, 10, 12, 14,
  109376. 16,
  109377. };
  109378. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109379. _vq_quantthresh__16c0_s_p6_0,
  109380. _vq_quantmap__16c0_s_p6_0,
  109381. 17,
  109382. 17
  109383. };
  109384. static static_codebook _16c0_s_p6_0 = {
  109385. 2, 289,
  109386. _vq_lengthlist__16c0_s_p6_0,
  109387. 1, -529530880, 1611661312, 5, 0,
  109388. _vq_quantlist__16c0_s_p6_0,
  109389. NULL,
  109390. &_vq_auxt__16c0_s_p6_0,
  109391. NULL,
  109392. 0
  109393. };
  109394. static long _vq_quantlist__16c0_s_p7_0[] = {
  109395. 1,
  109396. 0,
  109397. 2,
  109398. };
  109399. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109400. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109401. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109402. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109403. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109404. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109405. 13,
  109406. };
  109407. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109408. -5.5, 5.5,
  109409. };
  109410. static long _vq_quantmap__16c0_s_p7_0[] = {
  109411. 1, 0, 2,
  109412. };
  109413. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109414. _vq_quantthresh__16c0_s_p7_0,
  109415. _vq_quantmap__16c0_s_p7_0,
  109416. 3,
  109417. 3
  109418. };
  109419. static static_codebook _16c0_s_p7_0 = {
  109420. 4, 81,
  109421. _vq_lengthlist__16c0_s_p7_0,
  109422. 1, -529137664, 1618345984, 2, 0,
  109423. _vq_quantlist__16c0_s_p7_0,
  109424. NULL,
  109425. &_vq_auxt__16c0_s_p7_0,
  109426. NULL,
  109427. 0
  109428. };
  109429. static long _vq_quantlist__16c0_s_p7_1[] = {
  109430. 5,
  109431. 4,
  109432. 6,
  109433. 3,
  109434. 7,
  109435. 2,
  109436. 8,
  109437. 1,
  109438. 9,
  109439. 0,
  109440. 10,
  109441. };
  109442. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109443. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109444. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109445. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109446. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109447. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109448. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109449. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109450. 11,11,11, 9, 9, 9, 9,10,10,
  109451. };
  109452. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109453. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109454. 3.5, 4.5,
  109455. };
  109456. static long _vq_quantmap__16c0_s_p7_1[] = {
  109457. 9, 7, 5, 3, 1, 0, 2, 4,
  109458. 6, 8, 10,
  109459. };
  109460. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109461. _vq_quantthresh__16c0_s_p7_1,
  109462. _vq_quantmap__16c0_s_p7_1,
  109463. 11,
  109464. 11
  109465. };
  109466. static static_codebook _16c0_s_p7_1 = {
  109467. 2, 121,
  109468. _vq_lengthlist__16c0_s_p7_1,
  109469. 1, -531365888, 1611661312, 4, 0,
  109470. _vq_quantlist__16c0_s_p7_1,
  109471. NULL,
  109472. &_vq_auxt__16c0_s_p7_1,
  109473. NULL,
  109474. 0
  109475. };
  109476. static long _vq_quantlist__16c0_s_p8_0[] = {
  109477. 6,
  109478. 5,
  109479. 7,
  109480. 4,
  109481. 8,
  109482. 3,
  109483. 9,
  109484. 2,
  109485. 10,
  109486. 1,
  109487. 11,
  109488. 0,
  109489. 12,
  109490. };
  109491. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109492. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109493. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109494. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109495. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109496. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109497. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109498. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109499. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109500. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109501. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109502. 0,12,13,13,12,13,14,14,14,
  109503. };
  109504. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109505. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109506. 12.5, 17.5, 22.5, 27.5,
  109507. };
  109508. static long _vq_quantmap__16c0_s_p8_0[] = {
  109509. 11, 9, 7, 5, 3, 1, 0, 2,
  109510. 4, 6, 8, 10, 12,
  109511. };
  109512. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109513. _vq_quantthresh__16c0_s_p8_0,
  109514. _vq_quantmap__16c0_s_p8_0,
  109515. 13,
  109516. 13
  109517. };
  109518. static static_codebook _16c0_s_p8_0 = {
  109519. 2, 169,
  109520. _vq_lengthlist__16c0_s_p8_0,
  109521. 1, -526516224, 1616117760, 4, 0,
  109522. _vq_quantlist__16c0_s_p8_0,
  109523. NULL,
  109524. &_vq_auxt__16c0_s_p8_0,
  109525. NULL,
  109526. 0
  109527. };
  109528. static long _vq_quantlist__16c0_s_p8_1[] = {
  109529. 2,
  109530. 1,
  109531. 3,
  109532. 0,
  109533. 4,
  109534. };
  109535. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109536. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109537. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109538. };
  109539. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109540. -1.5, -0.5, 0.5, 1.5,
  109541. };
  109542. static long _vq_quantmap__16c0_s_p8_1[] = {
  109543. 3, 1, 0, 2, 4,
  109544. };
  109545. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109546. _vq_quantthresh__16c0_s_p8_1,
  109547. _vq_quantmap__16c0_s_p8_1,
  109548. 5,
  109549. 5
  109550. };
  109551. static static_codebook _16c0_s_p8_1 = {
  109552. 2, 25,
  109553. _vq_lengthlist__16c0_s_p8_1,
  109554. 1, -533725184, 1611661312, 3, 0,
  109555. _vq_quantlist__16c0_s_p8_1,
  109556. NULL,
  109557. &_vq_auxt__16c0_s_p8_1,
  109558. NULL,
  109559. 0
  109560. };
  109561. static long _vq_quantlist__16c0_s_p9_0[] = {
  109562. 1,
  109563. 0,
  109564. 2,
  109565. };
  109566. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109567. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109568. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109569. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109570. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109571. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109572. 7,
  109573. };
  109574. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109575. -157.5, 157.5,
  109576. };
  109577. static long _vq_quantmap__16c0_s_p9_0[] = {
  109578. 1, 0, 2,
  109579. };
  109580. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109581. _vq_quantthresh__16c0_s_p9_0,
  109582. _vq_quantmap__16c0_s_p9_0,
  109583. 3,
  109584. 3
  109585. };
  109586. static static_codebook _16c0_s_p9_0 = {
  109587. 4, 81,
  109588. _vq_lengthlist__16c0_s_p9_0,
  109589. 1, -518803456, 1628680192, 2, 0,
  109590. _vq_quantlist__16c0_s_p9_0,
  109591. NULL,
  109592. &_vq_auxt__16c0_s_p9_0,
  109593. NULL,
  109594. 0
  109595. };
  109596. static long _vq_quantlist__16c0_s_p9_1[] = {
  109597. 7,
  109598. 6,
  109599. 8,
  109600. 5,
  109601. 9,
  109602. 4,
  109603. 10,
  109604. 3,
  109605. 11,
  109606. 2,
  109607. 12,
  109608. 1,
  109609. 13,
  109610. 0,
  109611. 14,
  109612. };
  109613. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109614. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109615. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109616. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109617. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109618. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109619. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109620. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109621. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109622. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109623. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109624. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109625. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109626. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109627. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109628. 10,
  109629. };
  109630. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109631. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109632. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109633. };
  109634. static long _vq_quantmap__16c0_s_p9_1[] = {
  109635. 13, 11, 9, 7, 5, 3, 1, 0,
  109636. 2, 4, 6, 8, 10, 12, 14,
  109637. };
  109638. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109639. _vq_quantthresh__16c0_s_p9_1,
  109640. _vq_quantmap__16c0_s_p9_1,
  109641. 15,
  109642. 15
  109643. };
  109644. static static_codebook _16c0_s_p9_1 = {
  109645. 2, 225,
  109646. _vq_lengthlist__16c0_s_p9_1,
  109647. 1, -520986624, 1620377600, 4, 0,
  109648. _vq_quantlist__16c0_s_p9_1,
  109649. NULL,
  109650. &_vq_auxt__16c0_s_p9_1,
  109651. NULL,
  109652. 0
  109653. };
  109654. static long _vq_quantlist__16c0_s_p9_2[] = {
  109655. 10,
  109656. 9,
  109657. 11,
  109658. 8,
  109659. 12,
  109660. 7,
  109661. 13,
  109662. 6,
  109663. 14,
  109664. 5,
  109665. 15,
  109666. 4,
  109667. 16,
  109668. 3,
  109669. 17,
  109670. 2,
  109671. 18,
  109672. 1,
  109673. 19,
  109674. 0,
  109675. 20,
  109676. };
  109677. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109678. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109679. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109680. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109681. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109682. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109683. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109684. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109685. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109686. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109687. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109688. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109689. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109690. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109691. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109692. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109693. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109694. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109695. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109696. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109697. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109698. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109699. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109700. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109701. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109702. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109703. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109704. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109705. 10,11,10,10,11, 9,10,10,10,
  109706. };
  109707. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109708. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109709. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109710. 6.5, 7.5, 8.5, 9.5,
  109711. };
  109712. static long _vq_quantmap__16c0_s_p9_2[] = {
  109713. 19, 17, 15, 13, 11, 9, 7, 5,
  109714. 3, 1, 0, 2, 4, 6, 8, 10,
  109715. 12, 14, 16, 18, 20,
  109716. };
  109717. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109718. _vq_quantthresh__16c0_s_p9_2,
  109719. _vq_quantmap__16c0_s_p9_2,
  109720. 21,
  109721. 21
  109722. };
  109723. static static_codebook _16c0_s_p9_2 = {
  109724. 2, 441,
  109725. _vq_lengthlist__16c0_s_p9_2,
  109726. 1, -529268736, 1611661312, 5, 0,
  109727. _vq_quantlist__16c0_s_p9_2,
  109728. NULL,
  109729. &_vq_auxt__16c0_s_p9_2,
  109730. NULL,
  109731. 0
  109732. };
  109733. static long _huff_lengthlist__16c0_s_single[] = {
  109734. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109735. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109736. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109737. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109738. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109739. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109740. 16,16,18,18,
  109741. };
  109742. static static_codebook _huff_book__16c0_s_single = {
  109743. 2, 100,
  109744. _huff_lengthlist__16c0_s_single,
  109745. 0, 0, 0, 0, 0,
  109746. NULL,
  109747. NULL,
  109748. NULL,
  109749. NULL,
  109750. 0
  109751. };
  109752. static long _huff_lengthlist__16c1_s_long[] = {
  109753. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109754. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109755. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109756. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109757. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109758. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109759. 12,11,11,13,
  109760. };
  109761. static static_codebook _huff_book__16c1_s_long = {
  109762. 2, 100,
  109763. _huff_lengthlist__16c1_s_long,
  109764. 0, 0, 0, 0, 0,
  109765. NULL,
  109766. NULL,
  109767. NULL,
  109768. NULL,
  109769. 0
  109770. };
  109771. static long _vq_quantlist__16c1_s_p1_0[] = {
  109772. 1,
  109773. 0,
  109774. 2,
  109775. };
  109776. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109777. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109778. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109783. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109788. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109823. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109828. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109833. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109868. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109869. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109874. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  109875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109878. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109879. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110187. 0,
  110188. };
  110189. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110190. -0.5, 0.5,
  110191. };
  110192. static long _vq_quantmap__16c1_s_p1_0[] = {
  110193. 1, 0, 2,
  110194. };
  110195. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110196. _vq_quantthresh__16c1_s_p1_0,
  110197. _vq_quantmap__16c1_s_p1_0,
  110198. 3,
  110199. 3
  110200. };
  110201. static static_codebook _16c1_s_p1_0 = {
  110202. 8, 6561,
  110203. _vq_lengthlist__16c1_s_p1_0,
  110204. 1, -535822336, 1611661312, 2, 0,
  110205. _vq_quantlist__16c1_s_p1_0,
  110206. NULL,
  110207. &_vq_auxt__16c1_s_p1_0,
  110208. NULL,
  110209. 0
  110210. };
  110211. static long _vq_quantlist__16c1_s_p2_0[] = {
  110212. 2,
  110213. 1,
  110214. 3,
  110215. 0,
  110216. 4,
  110217. };
  110218. static long _vq_lengthlist__16c1_s_p2_0[] = {
  110219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110258. 0,
  110259. };
  110260. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110261. -1.5, -0.5, 0.5, 1.5,
  110262. };
  110263. static long _vq_quantmap__16c1_s_p2_0[] = {
  110264. 3, 1, 0, 2, 4,
  110265. };
  110266. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110267. _vq_quantthresh__16c1_s_p2_0,
  110268. _vq_quantmap__16c1_s_p2_0,
  110269. 5,
  110270. 5
  110271. };
  110272. static static_codebook _16c1_s_p2_0 = {
  110273. 4, 625,
  110274. _vq_lengthlist__16c1_s_p2_0,
  110275. 1, -533725184, 1611661312, 3, 0,
  110276. _vq_quantlist__16c1_s_p2_0,
  110277. NULL,
  110278. &_vq_auxt__16c1_s_p2_0,
  110279. NULL,
  110280. 0
  110281. };
  110282. static long _vq_quantlist__16c1_s_p3_0[] = {
  110283. 2,
  110284. 1,
  110285. 3,
  110286. 0,
  110287. 4,
  110288. };
  110289. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110290. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110293. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110296. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110329. 0,
  110330. };
  110331. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110332. -1.5, -0.5, 0.5, 1.5,
  110333. };
  110334. static long _vq_quantmap__16c1_s_p3_0[] = {
  110335. 3, 1, 0, 2, 4,
  110336. };
  110337. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110338. _vq_quantthresh__16c1_s_p3_0,
  110339. _vq_quantmap__16c1_s_p3_0,
  110340. 5,
  110341. 5
  110342. };
  110343. static static_codebook _16c1_s_p3_0 = {
  110344. 4, 625,
  110345. _vq_lengthlist__16c1_s_p3_0,
  110346. 1, -533725184, 1611661312, 3, 0,
  110347. _vq_quantlist__16c1_s_p3_0,
  110348. NULL,
  110349. &_vq_auxt__16c1_s_p3_0,
  110350. NULL,
  110351. 0
  110352. };
  110353. static long _vq_quantlist__16c1_s_p4_0[] = {
  110354. 4,
  110355. 3,
  110356. 5,
  110357. 2,
  110358. 6,
  110359. 1,
  110360. 7,
  110361. 0,
  110362. 8,
  110363. };
  110364. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110365. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110366. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110367. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110368. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110369. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110370. 0,
  110371. };
  110372. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110373. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110374. };
  110375. static long _vq_quantmap__16c1_s_p4_0[] = {
  110376. 7, 5, 3, 1, 0, 2, 4, 6,
  110377. 8,
  110378. };
  110379. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110380. _vq_quantthresh__16c1_s_p4_0,
  110381. _vq_quantmap__16c1_s_p4_0,
  110382. 9,
  110383. 9
  110384. };
  110385. static static_codebook _16c1_s_p4_0 = {
  110386. 2, 81,
  110387. _vq_lengthlist__16c1_s_p4_0,
  110388. 1, -531628032, 1611661312, 4, 0,
  110389. _vq_quantlist__16c1_s_p4_0,
  110390. NULL,
  110391. &_vq_auxt__16c1_s_p4_0,
  110392. NULL,
  110393. 0
  110394. };
  110395. static long _vq_quantlist__16c1_s_p5_0[] = {
  110396. 4,
  110397. 3,
  110398. 5,
  110399. 2,
  110400. 6,
  110401. 1,
  110402. 7,
  110403. 0,
  110404. 8,
  110405. };
  110406. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110407. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110408. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110409. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110410. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110411. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110412. 10,
  110413. };
  110414. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110415. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110416. };
  110417. static long _vq_quantmap__16c1_s_p5_0[] = {
  110418. 7, 5, 3, 1, 0, 2, 4, 6,
  110419. 8,
  110420. };
  110421. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110422. _vq_quantthresh__16c1_s_p5_0,
  110423. _vq_quantmap__16c1_s_p5_0,
  110424. 9,
  110425. 9
  110426. };
  110427. static static_codebook _16c1_s_p5_0 = {
  110428. 2, 81,
  110429. _vq_lengthlist__16c1_s_p5_0,
  110430. 1, -531628032, 1611661312, 4, 0,
  110431. _vq_quantlist__16c1_s_p5_0,
  110432. NULL,
  110433. &_vq_auxt__16c1_s_p5_0,
  110434. NULL,
  110435. 0
  110436. };
  110437. static long _vq_quantlist__16c1_s_p6_0[] = {
  110438. 8,
  110439. 7,
  110440. 9,
  110441. 6,
  110442. 10,
  110443. 5,
  110444. 11,
  110445. 4,
  110446. 12,
  110447. 3,
  110448. 13,
  110449. 2,
  110450. 14,
  110451. 1,
  110452. 15,
  110453. 0,
  110454. 16,
  110455. };
  110456. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110457. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110458. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110459. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110460. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110461. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110462. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110463. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110464. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110465. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110466. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110467. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110468. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110469. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110470. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110471. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110472. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110473. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110474. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110475. 14,
  110476. };
  110477. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110478. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110479. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110480. };
  110481. static long _vq_quantmap__16c1_s_p6_0[] = {
  110482. 15, 13, 11, 9, 7, 5, 3, 1,
  110483. 0, 2, 4, 6, 8, 10, 12, 14,
  110484. 16,
  110485. };
  110486. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110487. _vq_quantthresh__16c1_s_p6_0,
  110488. _vq_quantmap__16c1_s_p6_0,
  110489. 17,
  110490. 17
  110491. };
  110492. static static_codebook _16c1_s_p6_0 = {
  110493. 2, 289,
  110494. _vq_lengthlist__16c1_s_p6_0,
  110495. 1, -529530880, 1611661312, 5, 0,
  110496. _vq_quantlist__16c1_s_p6_0,
  110497. NULL,
  110498. &_vq_auxt__16c1_s_p6_0,
  110499. NULL,
  110500. 0
  110501. };
  110502. static long _vq_quantlist__16c1_s_p7_0[] = {
  110503. 1,
  110504. 0,
  110505. 2,
  110506. };
  110507. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110508. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110509. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110510. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110511. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110512. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110513. 11,
  110514. };
  110515. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110516. -5.5, 5.5,
  110517. };
  110518. static long _vq_quantmap__16c1_s_p7_0[] = {
  110519. 1, 0, 2,
  110520. };
  110521. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110522. _vq_quantthresh__16c1_s_p7_0,
  110523. _vq_quantmap__16c1_s_p7_0,
  110524. 3,
  110525. 3
  110526. };
  110527. static static_codebook _16c1_s_p7_0 = {
  110528. 4, 81,
  110529. _vq_lengthlist__16c1_s_p7_0,
  110530. 1, -529137664, 1618345984, 2, 0,
  110531. _vq_quantlist__16c1_s_p7_0,
  110532. NULL,
  110533. &_vq_auxt__16c1_s_p7_0,
  110534. NULL,
  110535. 0
  110536. };
  110537. static long _vq_quantlist__16c1_s_p7_1[] = {
  110538. 5,
  110539. 4,
  110540. 6,
  110541. 3,
  110542. 7,
  110543. 2,
  110544. 8,
  110545. 1,
  110546. 9,
  110547. 0,
  110548. 10,
  110549. };
  110550. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110551. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110552. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110553. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110554. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110555. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110556. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110557. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110558. 10,10,10, 8, 8, 8, 8, 9, 9,
  110559. };
  110560. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110561. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110562. 3.5, 4.5,
  110563. };
  110564. static long _vq_quantmap__16c1_s_p7_1[] = {
  110565. 9, 7, 5, 3, 1, 0, 2, 4,
  110566. 6, 8, 10,
  110567. };
  110568. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110569. _vq_quantthresh__16c1_s_p7_1,
  110570. _vq_quantmap__16c1_s_p7_1,
  110571. 11,
  110572. 11
  110573. };
  110574. static static_codebook _16c1_s_p7_1 = {
  110575. 2, 121,
  110576. _vq_lengthlist__16c1_s_p7_1,
  110577. 1, -531365888, 1611661312, 4, 0,
  110578. _vq_quantlist__16c1_s_p7_1,
  110579. NULL,
  110580. &_vq_auxt__16c1_s_p7_1,
  110581. NULL,
  110582. 0
  110583. };
  110584. static long _vq_quantlist__16c1_s_p8_0[] = {
  110585. 6,
  110586. 5,
  110587. 7,
  110588. 4,
  110589. 8,
  110590. 3,
  110591. 9,
  110592. 2,
  110593. 10,
  110594. 1,
  110595. 11,
  110596. 0,
  110597. 12,
  110598. };
  110599. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110600. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110601. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110602. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110603. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110604. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110605. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110606. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110607. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110608. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110609. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110610. 0,12,12,12,12,13,13,14,15,
  110611. };
  110612. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110613. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110614. 12.5, 17.5, 22.5, 27.5,
  110615. };
  110616. static long _vq_quantmap__16c1_s_p8_0[] = {
  110617. 11, 9, 7, 5, 3, 1, 0, 2,
  110618. 4, 6, 8, 10, 12,
  110619. };
  110620. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110621. _vq_quantthresh__16c1_s_p8_0,
  110622. _vq_quantmap__16c1_s_p8_0,
  110623. 13,
  110624. 13
  110625. };
  110626. static static_codebook _16c1_s_p8_0 = {
  110627. 2, 169,
  110628. _vq_lengthlist__16c1_s_p8_0,
  110629. 1, -526516224, 1616117760, 4, 0,
  110630. _vq_quantlist__16c1_s_p8_0,
  110631. NULL,
  110632. &_vq_auxt__16c1_s_p8_0,
  110633. NULL,
  110634. 0
  110635. };
  110636. static long _vq_quantlist__16c1_s_p8_1[] = {
  110637. 2,
  110638. 1,
  110639. 3,
  110640. 0,
  110641. 4,
  110642. };
  110643. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110644. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110645. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110646. };
  110647. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110648. -1.5, -0.5, 0.5, 1.5,
  110649. };
  110650. static long _vq_quantmap__16c1_s_p8_1[] = {
  110651. 3, 1, 0, 2, 4,
  110652. };
  110653. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110654. _vq_quantthresh__16c1_s_p8_1,
  110655. _vq_quantmap__16c1_s_p8_1,
  110656. 5,
  110657. 5
  110658. };
  110659. static static_codebook _16c1_s_p8_1 = {
  110660. 2, 25,
  110661. _vq_lengthlist__16c1_s_p8_1,
  110662. 1, -533725184, 1611661312, 3, 0,
  110663. _vq_quantlist__16c1_s_p8_1,
  110664. NULL,
  110665. &_vq_auxt__16c1_s_p8_1,
  110666. NULL,
  110667. 0
  110668. };
  110669. static long _vq_quantlist__16c1_s_p9_0[] = {
  110670. 6,
  110671. 5,
  110672. 7,
  110673. 4,
  110674. 8,
  110675. 3,
  110676. 9,
  110677. 2,
  110678. 10,
  110679. 1,
  110680. 11,
  110681. 0,
  110682. 12,
  110683. };
  110684. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110685. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110686. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110687. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110688. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110689. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110690. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110691. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110692. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110693. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110694. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110695. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110696. };
  110697. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110698. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110699. 787.5, 1102.5, 1417.5, 1732.5,
  110700. };
  110701. static long _vq_quantmap__16c1_s_p9_0[] = {
  110702. 11, 9, 7, 5, 3, 1, 0, 2,
  110703. 4, 6, 8, 10, 12,
  110704. };
  110705. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110706. _vq_quantthresh__16c1_s_p9_0,
  110707. _vq_quantmap__16c1_s_p9_0,
  110708. 13,
  110709. 13
  110710. };
  110711. static static_codebook _16c1_s_p9_0 = {
  110712. 2, 169,
  110713. _vq_lengthlist__16c1_s_p9_0,
  110714. 1, -513964032, 1628680192, 4, 0,
  110715. _vq_quantlist__16c1_s_p9_0,
  110716. NULL,
  110717. &_vq_auxt__16c1_s_p9_0,
  110718. NULL,
  110719. 0
  110720. };
  110721. static long _vq_quantlist__16c1_s_p9_1[] = {
  110722. 7,
  110723. 6,
  110724. 8,
  110725. 5,
  110726. 9,
  110727. 4,
  110728. 10,
  110729. 3,
  110730. 11,
  110731. 2,
  110732. 12,
  110733. 1,
  110734. 13,
  110735. 0,
  110736. 14,
  110737. };
  110738. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110739. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110740. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110741. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110742. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110743. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110744. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110745. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110746. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110747. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110748. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110749. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110750. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110751. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110752. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110753. 13,
  110754. };
  110755. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110756. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110757. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110758. };
  110759. static long _vq_quantmap__16c1_s_p9_1[] = {
  110760. 13, 11, 9, 7, 5, 3, 1, 0,
  110761. 2, 4, 6, 8, 10, 12, 14,
  110762. };
  110763. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110764. _vq_quantthresh__16c1_s_p9_1,
  110765. _vq_quantmap__16c1_s_p9_1,
  110766. 15,
  110767. 15
  110768. };
  110769. static static_codebook _16c1_s_p9_1 = {
  110770. 2, 225,
  110771. _vq_lengthlist__16c1_s_p9_1,
  110772. 1, -520986624, 1620377600, 4, 0,
  110773. _vq_quantlist__16c1_s_p9_1,
  110774. NULL,
  110775. &_vq_auxt__16c1_s_p9_1,
  110776. NULL,
  110777. 0
  110778. };
  110779. static long _vq_quantlist__16c1_s_p9_2[] = {
  110780. 10,
  110781. 9,
  110782. 11,
  110783. 8,
  110784. 12,
  110785. 7,
  110786. 13,
  110787. 6,
  110788. 14,
  110789. 5,
  110790. 15,
  110791. 4,
  110792. 16,
  110793. 3,
  110794. 17,
  110795. 2,
  110796. 18,
  110797. 1,
  110798. 19,
  110799. 0,
  110800. 20,
  110801. };
  110802. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110803. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110804. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110805. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110806. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110807. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110808. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110809. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110810. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110811. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110812. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110813. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110814. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110815. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110816. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110817. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110818. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110819. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110820. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110821. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110822. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110823. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110824. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110825. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110826. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110827. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110828. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110829. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110830. 11,11,11,11,12,11,11,12,11,
  110831. };
  110832. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110833. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110834. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110835. 6.5, 7.5, 8.5, 9.5,
  110836. };
  110837. static long _vq_quantmap__16c1_s_p9_2[] = {
  110838. 19, 17, 15, 13, 11, 9, 7, 5,
  110839. 3, 1, 0, 2, 4, 6, 8, 10,
  110840. 12, 14, 16, 18, 20,
  110841. };
  110842. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110843. _vq_quantthresh__16c1_s_p9_2,
  110844. _vq_quantmap__16c1_s_p9_2,
  110845. 21,
  110846. 21
  110847. };
  110848. static static_codebook _16c1_s_p9_2 = {
  110849. 2, 441,
  110850. _vq_lengthlist__16c1_s_p9_2,
  110851. 1, -529268736, 1611661312, 5, 0,
  110852. _vq_quantlist__16c1_s_p9_2,
  110853. NULL,
  110854. &_vq_auxt__16c1_s_p9_2,
  110855. NULL,
  110856. 0
  110857. };
  110858. static long _huff_lengthlist__16c1_s_short[] = {
  110859. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110860. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110861. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110862. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110863. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110864. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110865. 9, 9,10,13,
  110866. };
  110867. static static_codebook _huff_book__16c1_s_short = {
  110868. 2, 100,
  110869. _huff_lengthlist__16c1_s_short,
  110870. 0, 0, 0, 0, 0,
  110871. NULL,
  110872. NULL,
  110873. NULL,
  110874. NULL,
  110875. 0
  110876. };
  110877. static long _huff_lengthlist__16c2_s_long[] = {
  110878. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110879. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110880. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110881. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110882. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110883. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110884. 14,14,16,18,
  110885. };
  110886. static static_codebook _huff_book__16c2_s_long = {
  110887. 2, 100,
  110888. _huff_lengthlist__16c2_s_long,
  110889. 0, 0, 0, 0, 0,
  110890. NULL,
  110891. NULL,
  110892. NULL,
  110893. NULL,
  110894. 0
  110895. };
  110896. static long _vq_quantlist__16c2_s_p1_0[] = {
  110897. 1,
  110898. 0,
  110899. 2,
  110900. };
  110901. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110902. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110903. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110907. 0,
  110908. };
  110909. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110910. -0.5, 0.5,
  110911. };
  110912. static long _vq_quantmap__16c2_s_p1_0[] = {
  110913. 1, 0, 2,
  110914. };
  110915. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110916. _vq_quantthresh__16c2_s_p1_0,
  110917. _vq_quantmap__16c2_s_p1_0,
  110918. 3,
  110919. 3
  110920. };
  110921. static static_codebook _16c2_s_p1_0 = {
  110922. 4, 81,
  110923. _vq_lengthlist__16c2_s_p1_0,
  110924. 1, -535822336, 1611661312, 2, 0,
  110925. _vq_quantlist__16c2_s_p1_0,
  110926. NULL,
  110927. &_vq_auxt__16c2_s_p1_0,
  110928. NULL,
  110929. 0
  110930. };
  110931. static long _vq_quantlist__16c2_s_p2_0[] = {
  110932. 2,
  110933. 1,
  110934. 3,
  110935. 0,
  110936. 4,
  110937. };
  110938. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110939. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110940. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110941. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110942. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110943. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110944. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110945. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110946. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110951. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110952. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110953. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110954. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110959. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110960. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110961. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110962. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110967. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110968. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110969. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110970. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110975. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110976. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110977. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110978. 13,
  110979. };
  110980. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110981. -1.5, -0.5, 0.5, 1.5,
  110982. };
  110983. static long _vq_quantmap__16c2_s_p2_0[] = {
  110984. 3, 1, 0, 2, 4,
  110985. };
  110986. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110987. _vq_quantthresh__16c2_s_p2_0,
  110988. _vq_quantmap__16c2_s_p2_0,
  110989. 5,
  110990. 5
  110991. };
  110992. static static_codebook _16c2_s_p2_0 = {
  110993. 4, 625,
  110994. _vq_lengthlist__16c2_s_p2_0,
  110995. 1, -533725184, 1611661312, 3, 0,
  110996. _vq_quantlist__16c2_s_p2_0,
  110997. NULL,
  110998. &_vq_auxt__16c2_s_p2_0,
  110999. NULL,
  111000. 0
  111001. };
  111002. static long _vq_quantlist__16c2_s_p3_0[] = {
  111003. 4,
  111004. 3,
  111005. 5,
  111006. 2,
  111007. 6,
  111008. 1,
  111009. 7,
  111010. 0,
  111011. 8,
  111012. };
  111013. static long _vq_lengthlist__16c2_s_p3_0[] = {
  111014. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  111015. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  111016. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  111017. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  111018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111019. 0,
  111020. };
  111021. static float _vq_quantthresh__16c2_s_p3_0[] = {
  111022. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111023. };
  111024. static long _vq_quantmap__16c2_s_p3_0[] = {
  111025. 7, 5, 3, 1, 0, 2, 4, 6,
  111026. 8,
  111027. };
  111028. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  111029. _vq_quantthresh__16c2_s_p3_0,
  111030. _vq_quantmap__16c2_s_p3_0,
  111031. 9,
  111032. 9
  111033. };
  111034. static static_codebook _16c2_s_p3_0 = {
  111035. 2, 81,
  111036. _vq_lengthlist__16c2_s_p3_0,
  111037. 1, -531628032, 1611661312, 4, 0,
  111038. _vq_quantlist__16c2_s_p3_0,
  111039. NULL,
  111040. &_vq_auxt__16c2_s_p3_0,
  111041. NULL,
  111042. 0
  111043. };
  111044. static long _vq_quantlist__16c2_s_p4_0[] = {
  111045. 8,
  111046. 7,
  111047. 9,
  111048. 6,
  111049. 10,
  111050. 5,
  111051. 11,
  111052. 4,
  111053. 12,
  111054. 3,
  111055. 13,
  111056. 2,
  111057. 14,
  111058. 1,
  111059. 15,
  111060. 0,
  111061. 16,
  111062. };
  111063. static long _vq_lengthlist__16c2_s_p4_0[] = {
  111064. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  111065. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  111066. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  111067. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  111068. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  111069. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  111070. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  111071. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  111072. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  111073. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  111074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111082. 0,
  111083. };
  111084. static float _vq_quantthresh__16c2_s_p4_0[] = {
  111085. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111086. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111087. };
  111088. static long _vq_quantmap__16c2_s_p4_0[] = {
  111089. 15, 13, 11, 9, 7, 5, 3, 1,
  111090. 0, 2, 4, 6, 8, 10, 12, 14,
  111091. 16,
  111092. };
  111093. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  111094. _vq_quantthresh__16c2_s_p4_0,
  111095. _vq_quantmap__16c2_s_p4_0,
  111096. 17,
  111097. 17
  111098. };
  111099. static static_codebook _16c2_s_p4_0 = {
  111100. 2, 289,
  111101. _vq_lengthlist__16c2_s_p4_0,
  111102. 1, -529530880, 1611661312, 5, 0,
  111103. _vq_quantlist__16c2_s_p4_0,
  111104. NULL,
  111105. &_vq_auxt__16c2_s_p4_0,
  111106. NULL,
  111107. 0
  111108. };
  111109. static long _vq_quantlist__16c2_s_p5_0[] = {
  111110. 1,
  111111. 0,
  111112. 2,
  111113. };
  111114. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111115. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111116. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111117. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111118. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111119. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111120. 12,
  111121. };
  111122. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111123. -5.5, 5.5,
  111124. };
  111125. static long _vq_quantmap__16c2_s_p5_0[] = {
  111126. 1, 0, 2,
  111127. };
  111128. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111129. _vq_quantthresh__16c2_s_p5_0,
  111130. _vq_quantmap__16c2_s_p5_0,
  111131. 3,
  111132. 3
  111133. };
  111134. static static_codebook _16c2_s_p5_0 = {
  111135. 4, 81,
  111136. _vq_lengthlist__16c2_s_p5_0,
  111137. 1, -529137664, 1618345984, 2, 0,
  111138. _vq_quantlist__16c2_s_p5_0,
  111139. NULL,
  111140. &_vq_auxt__16c2_s_p5_0,
  111141. NULL,
  111142. 0
  111143. };
  111144. static long _vq_quantlist__16c2_s_p5_1[] = {
  111145. 5,
  111146. 4,
  111147. 6,
  111148. 3,
  111149. 7,
  111150. 2,
  111151. 8,
  111152. 1,
  111153. 9,
  111154. 0,
  111155. 10,
  111156. };
  111157. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111158. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111159. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111160. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111161. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111162. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111163. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111164. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111165. 11,11,11, 7, 7, 8, 8, 8, 8,
  111166. };
  111167. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111168. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111169. 3.5, 4.5,
  111170. };
  111171. static long _vq_quantmap__16c2_s_p5_1[] = {
  111172. 9, 7, 5, 3, 1, 0, 2, 4,
  111173. 6, 8, 10,
  111174. };
  111175. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111176. _vq_quantthresh__16c2_s_p5_1,
  111177. _vq_quantmap__16c2_s_p5_1,
  111178. 11,
  111179. 11
  111180. };
  111181. static static_codebook _16c2_s_p5_1 = {
  111182. 2, 121,
  111183. _vq_lengthlist__16c2_s_p5_1,
  111184. 1, -531365888, 1611661312, 4, 0,
  111185. _vq_quantlist__16c2_s_p5_1,
  111186. NULL,
  111187. &_vq_auxt__16c2_s_p5_1,
  111188. NULL,
  111189. 0
  111190. };
  111191. static long _vq_quantlist__16c2_s_p6_0[] = {
  111192. 6,
  111193. 5,
  111194. 7,
  111195. 4,
  111196. 8,
  111197. 3,
  111198. 9,
  111199. 2,
  111200. 10,
  111201. 1,
  111202. 11,
  111203. 0,
  111204. 12,
  111205. };
  111206. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111207. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111208. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111209. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111210. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111211. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111212. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111217. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111218. };
  111219. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111220. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111221. 12.5, 17.5, 22.5, 27.5,
  111222. };
  111223. static long _vq_quantmap__16c2_s_p6_0[] = {
  111224. 11, 9, 7, 5, 3, 1, 0, 2,
  111225. 4, 6, 8, 10, 12,
  111226. };
  111227. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111228. _vq_quantthresh__16c2_s_p6_0,
  111229. _vq_quantmap__16c2_s_p6_0,
  111230. 13,
  111231. 13
  111232. };
  111233. static static_codebook _16c2_s_p6_0 = {
  111234. 2, 169,
  111235. _vq_lengthlist__16c2_s_p6_0,
  111236. 1, -526516224, 1616117760, 4, 0,
  111237. _vq_quantlist__16c2_s_p6_0,
  111238. NULL,
  111239. &_vq_auxt__16c2_s_p6_0,
  111240. NULL,
  111241. 0
  111242. };
  111243. static long _vq_quantlist__16c2_s_p6_1[] = {
  111244. 2,
  111245. 1,
  111246. 3,
  111247. 0,
  111248. 4,
  111249. };
  111250. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111251. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111252. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111253. };
  111254. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111255. -1.5, -0.5, 0.5, 1.5,
  111256. };
  111257. static long _vq_quantmap__16c2_s_p6_1[] = {
  111258. 3, 1, 0, 2, 4,
  111259. };
  111260. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111261. _vq_quantthresh__16c2_s_p6_1,
  111262. _vq_quantmap__16c2_s_p6_1,
  111263. 5,
  111264. 5
  111265. };
  111266. static static_codebook _16c2_s_p6_1 = {
  111267. 2, 25,
  111268. _vq_lengthlist__16c2_s_p6_1,
  111269. 1, -533725184, 1611661312, 3, 0,
  111270. _vq_quantlist__16c2_s_p6_1,
  111271. NULL,
  111272. &_vq_auxt__16c2_s_p6_1,
  111273. NULL,
  111274. 0
  111275. };
  111276. static long _vq_quantlist__16c2_s_p7_0[] = {
  111277. 6,
  111278. 5,
  111279. 7,
  111280. 4,
  111281. 8,
  111282. 3,
  111283. 9,
  111284. 2,
  111285. 10,
  111286. 1,
  111287. 11,
  111288. 0,
  111289. 12,
  111290. };
  111291. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111292. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111293. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111294. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111295. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111296. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111297. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111298. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111299. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111300. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111301. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111302. 18,13,14,13,13,14,13,15,14,
  111303. };
  111304. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111305. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111306. 27.5, 38.5, 49.5, 60.5,
  111307. };
  111308. static long _vq_quantmap__16c2_s_p7_0[] = {
  111309. 11, 9, 7, 5, 3, 1, 0, 2,
  111310. 4, 6, 8, 10, 12,
  111311. };
  111312. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111313. _vq_quantthresh__16c2_s_p7_0,
  111314. _vq_quantmap__16c2_s_p7_0,
  111315. 13,
  111316. 13
  111317. };
  111318. static static_codebook _16c2_s_p7_0 = {
  111319. 2, 169,
  111320. _vq_lengthlist__16c2_s_p7_0,
  111321. 1, -523206656, 1618345984, 4, 0,
  111322. _vq_quantlist__16c2_s_p7_0,
  111323. NULL,
  111324. &_vq_auxt__16c2_s_p7_0,
  111325. NULL,
  111326. 0
  111327. };
  111328. static long _vq_quantlist__16c2_s_p7_1[] = {
  111329. 5,
  111330. 4,
  111331. 6,
  111332. 3,
  111333. 7,
  111334. 2,
  111335. 8,
  111336. 1,
  111337. 9,
  111338. 0,
  111339. 10,
  111340. };
  111341. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111342. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111343. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111344. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111345. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111346. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111347. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111348. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111349. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111350. };
  111351. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111352. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111353. 3.5, 4.5,
  111354. };
  111355. static long _vq_quantmap__16c2_s_p7_1[] = {
  111356. 9, 7, 5, 3, 1, 0, 2, 4,
  111357. 6, 8, 10,
  111358. };
  111359. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111360. _vq_quantthresh__16c2_s_p7_1,
  111361. _vq_quantmap__16c2_s_p7_1,
  111362. 11,
  111363. 11
  111364. };
  111365. static static_codebook _16c2_s_p7_1 = {
  111366. 2, 121,
  111367. _vq_lengthlist__16c2_s_p7_1,
  111368. 1, -531365888, 1611661312, 4, 0,
  111369. _vq_quantlist__16c2_s_p7_1,
  111370. NULL,
  111371. &_vq_auxt__16c2_s_p7_1,
  111372. NULL,
  111373. 0
  111374. };
  111375. static long _vq_quantlist__16c2_s_p8_0[] = {
  111376. 7,
  111377. 6,
  111378. 8,
  111379. 5,
  111380. 9,
  111381. 4,
  111382. 10,
  111383. 3,
  111384. 11,
  111385. 2,
  111386. 12,
  111387. 1,
  111388. 13,
  111389. 0,
  111390. 14,
  111391. };
  111392. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111393. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111394. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111395. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111396. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111397. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111398. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111399. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111400. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111401. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111402. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111403. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111404. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111405. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111406. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111407. 13,
  111408. };
  111409. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111410. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111411. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111412. };
  111413. static long _vq_quantmap__16c2_s_p8_0[] = {
  111414. 13, 11, 9, 7, 5, 3, 1, 0,
  111415. 2, 4, 6, 8, 10, 12, 14,
  111416. };
  111417. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111418. _vq_quantthresh__16c2_s_p8_0,
  111419. _vq_quantmap__16c2_s_p8_0,
  111420. 15,
  111421. 15
  111422. };
  111423. static static_codebook _16c2_s_p8_0 = {
  111424. 2, 225,
  111425. _vq_lengthlist__16c2_s_p8_0,
  111426. 1, -520986624, 1620377600, 4, 0,
  111427. _vq_quantlist__16c2_s_p8_0,
  111428. NULL,
  111429. &_vq_auxt__16c2_s_p8_0,
  111430. NULL,
  111431. 0
  111432. };
  111433. static long _vq_quantlist__16c2_s_p8_1[] = {
  111434. 10,
  111435. 9,
  111436. 11,
  111437. 8,
  111438. 12,
  111439. 7,
  111440. 13,
  111441. 6,
  111442. 14,
  111443. 5,
  111444. 15,
  111445. 4,
  111446. 16,
  111447. 3,
  111448. 17,
  111449. 2,
  111450. 18,
  111451. 1,
  111452. 19,
  111453. 0,
  111454. 20,
  111455. };
  111456. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111457. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111458. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111459. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111460. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111461. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111462. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111463. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111464. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111465. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111466. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111467. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111468. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111469. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111470. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111471. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111472. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111473. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111474. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111475. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111476. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111477. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111478. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111479. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111480. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111481. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111482. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111483. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111484. 10,11,10,10,10,10,10,10,10,
  111485. };
  111486. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111487. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111488. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111489. 6.5, 7.5, 8.5, 9.5,
  111490. };
  111491. static long _vq_quantmap__16c2_s_p8_1[] = {
  111492. 19, 17, 15, 13, 11, 9, 7, 5,
  111493. 3, 1, 0, 2, 4, 6, 8, 10,
  111494. 12, 14, 16, 18, 20,
  111495. };
  111496. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111497. _vq_quantthresh__16c2_s_p8_1,
  111498. _vq_quantmap__16c2_s_p8_1,
  111499. 21,
  111500. 21
  111501. };
  111502. static static_codebook _16c2_s_p8_1 = {
  111503. 2, 441,
  111504. _vq_lengthlist__16c2_s_p8_1,
  111505. 1, -529268736, 1611661312, 5, 0,
  111506. _vq_quantlist__16c2_s_p8_1,
  111507. NULL,
  111508. &_vq_auxt__16c2_s_p8_1,
  111509. NULL,
  111510. 0
  111511. };
  111512. static long _vq_quantlist__16c2_s_p9_0[] = {
  111513. 6,
  111514. 5,
  111515. 7,
  111516. 4,
  111517. 8,
  111518. 3,
  111519. 9,
  111520. 2,
  111521. 10,
  111522. 1,
  111523. 11,
  111524. 0,
  111525. 12,
  111526. };
  111527. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111528. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111529. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111530. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111531. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111532. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111533. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111534. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111535. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111536. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111537. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111538. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111539. };
  111540. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111541. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111542. 2327.5, 3258.5, 4189.5, 5120.5,
  111543. };
  111544. static long _vq_quantmap__16c2_s_p9_0[] = {
  111545. 11, 9, 7, 5, 3, 1, 0, 2,
  111546. 4, 6, 8, 10, 12,
  111547. };
  111548. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111549. _vq_quantthresh__16c2_s_p9_0,
  111550. _vq_quantmap__16c2_s_p9_0,
  111551. 13,
  111552. 13
  111553. };
  111554. static static_codebook _16c2_s_p9_0 = {
  111555. 2, 169,
  111556. _vq_lengthlist__16c2_s_p9_0,
  111557. 1, -510275072, 1631393792, 4, 0,
  111558. _vq_quantlist__16c2_s_p9_0,
  111559. NULL,
  111560. &_vq_auxt__16c2_s_p9_0,
  111561. NULL,
  111562. 0
  111563. };
  111564. static long _vq_quantlist__16c2_s_p9_1[] = {
  111565. 8,
  111566. 7,
  111567. 9,
  111568. 6,
  111569. 10,
  111570. 5,
  111571. 11,
  111572. 4,
  111573. 12,
  111574. 3,
  111575. 13,
  111576. 2,
  111577. 14,
  111578. 1,
  111579. 15,
  111580. 0,
  111581. 16,
  111582. };
  111583. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111584. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111585. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111586. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111587. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111588. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111589. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111590. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111591. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111592. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111593. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111594. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111595. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111596. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111597. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111598. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111599. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111600. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111601. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111602. 10,
  111603. };
  111604. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111605. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111606. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111607. };
  111608. static long _vq_quantmap__16c2_s_p9_1[] = {
  111609. 15, 13, 11, 9, 7, 5, 3, 1,
  111610. 0, 2, 4, 6, 8, 10, 12, 14,
  111611. 16,
  111612. };
  111613. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111614. _vq_quantthresh__16c2_s_p9_1,
  111615. _vq_quantmap__16c2_s_p9_1,
  111616. 17,
  111617. 17
  111618. };
  111619. static static_codebook _16c2_s_p9_1 = {
  111620. 2, 289,
  111621. _vq_lengthlist__16c2_s_p9_1,
  111622. 1, -518488064, 1622704128, 5, 0,
  111623. _vq_quantlist__16c2_s_p9_1,
  111624. NULL,
  111625. &_vq_auxt__16c2_s_p9_1,
  111626. NULL,
  111627. 0
  111628. };
  111629. static long _vq_quantlist__16c2_s_p9_2[] = {
  111630. 13,
  111631. 12,
  111632. 14,
  111633. 11,
  111634. 15,
  111635. 10,
  111636. 16,
  111637. 9,
  111638. 17,
  111639. 8,
  111640. 18,
  111641. 7,
  111642. 19,
  111643. 6,
  111644. 20,
  111645. 5,
  111646. 21,
  111647. 4,
  111648. 22,
  111649. 3,
  111650. 23,
  111651. 2,
  111652. 24,
  111653. 1,
  111654. 25,
  111655. 0,
  111656. 26,
  111657. };
  111658. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111659. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111660. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111661. };
  111662. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111663. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111664. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111665. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111666. 11.5, 12.5,
  111667. };
  111668. static long _vq_quantmap__16c2_s_p9_2[] = {
  111669. 25, 23, 21, 19, 17, 15, 13, 11,
  111670. 9, 7, 5, 3, 1, 0, 2, 4,
  111671. 6, 8, 10, 12, 14, 16, 18, 20,
  111672. 22, 24, 26,
  111673. };
  111674. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111675. _vq_quantthresh__16c2_s_p9_2,
  111676. _vq_quantmap__16c2_s_p9_2,
  111677. 27,
  111678. 27
  111679. };
  111680. static static_codebook _16c2_s_p9_2 = {
  111681. 1, 27,
  111682. _vq_lengthlist__16c2_s_p9_2,
  111683. 1, -528875520, 1611661312, 5, 0,
  111684. _vq_quantlist__16c2_s_p9_2,
  111685. NULL,
  111686. &_vq_auxt__16c2_s_p9_2,
  111687. NULL,
  111688. 0
  111689. };
  111690. static long _huff_lengthlist__16c2_s_short[] = {
  111691. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111692. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111693. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111694. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111695. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111696. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111697. 15,12,14,14,
  111698. };
  111699. static static_codebook _huff_book__16c2_s_short = {
  111700. 2, 100,
  111701. _huff_lengthlist__16c2_s_short,
  111702. 0, 0, 0, 0, 0,
  111703. NULL,
  111704. NULL,
  111705. NULL,
  111706. NULL,
  111707. 0
  111708. };
  111709. static long _vq_quantlist__8c0_s_p1_0[] = {
  111710. 1,
  111711. 0,
  111712. 2,
  111713. };
  111714. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111715. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111716. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111721. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111726. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111761. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111766. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111771. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111806. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111807. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111812. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 0,
  111813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111816. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111817. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112125. 0,
  112126. };
  112127. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112128. -0.5, 0.5,
  112129. };
  112130. static long _vq_quantmap__8c0_s_p1_0[] = {
  112131. 1, 0, 2,
  112132. };
  112133. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112134. _vq_quantthresh__8c0_s_p1_0,
  112135. _vq_quantmap__8c0_s_p1_0,
  112136. 3,
  112137. 3
  112138. };
  112139. static static_codebook _8c0_s_p1_0 = {
  112140. 8, 6561,
  112141. _vq_lengthlist__8c0_s_p1_0,
  112142. 1, -535822336, 1611661312, 2, 0,
  112143. _vq_quantlist__8c0_s_p1_0,
  112144. NULL,
  112145. &_vq_auxt__8c0_s_p1_0,
  112146. NULL,
  112147. 0
  112148. };
  112149. static long _vq_quantlist__8c0_s_p2_0[] = {
  112150. 2,
  112151. 1,
  112152. 3,
  112153. 0,
  112154. 4,
  112155. };
  112156. static long _vq_lengthlist__8c0_s_p2_0[] = {
  112157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112196. 0,
  112197. };
  112198. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112199. -1.5, -0.5, 0.5, 1.5,
  112200. };
  112201. static long _vq_quantmap__8c0_s_p2_0[] = {
  112202. 3, 1, 0, 2, 4,
  112203. };
  112204. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112205. _vq_quantthresh__8c0_s_p2_0,
  112206. _vq_quantmap__8c0_s_p2_0,
  112207. 5,
  112208. 5
  112209. };
  112210. static static_codebook _8c0_s_p2_0 = {
  112211. 4, 625,
  112212. _vq_lengthlist__8c0_s_p2_0,
  112213. 1, -533725184, 1611661312, 3, 0,
  112214. _vq_quantlist__8c0_s_p2_0,
  112215. NULL,
  112216. &_vq_auxt__8c0_s_p2_0,
  112217. NULL,
  112218. 0
  112219. };
  112220. static long _vq_quantlist__8c0_s_p3_0[] = {
  112221. 2,
  112222. 1,
  112223. 3,
  112224. 0,
  112225. 4,
  112226. };
  112227. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112228. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112231. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112234. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  112235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112267. 0,
  112268. };
  112269. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112270. -1.5, -0.5, 0.5, 1.5,
  112271. };
  112272. static long _vq_quantmap__8c0_s_p3_0[] = {
  112273. 3, 1, 0, 2, 4,
  112274. };
  112275. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112276. _vq_quantthresh__8c0_s_p3_0,
  112277. _vq_quantmap__8c0_s_p3_0,
  112278. 5,
  112279. 5
  112280. };
  112281. static static_codebook _8c0_s_p3_0 = {
  112282. 4, 625,
  112283. _vq_lengthlist__8c0_s_p3_0,
  112284. 1, -533725184, 1611661312, 3, 0,
  112285. _vq_quantlist__8c0_s_p3_0,
  112286. NULL,
  112287. &_vq_auxt__8c0_s_p3_0,
  112288. NULL,
  112289. 0
  112290. };
  112291. static long _vq_quantlist__8c0_s_p4_0[] = {
  112292. 4,
  112293. 3,
  112294. 5,
  112295. 2,
  112296. 6,
  112297. 1,
  112298. 7,
  112299. 0,
  112300. 8,
  112301. };
  112302. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112303. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112304. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112305. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112306. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112307. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112308. 0,
  112309. };
  112310. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112311. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112312. };
  112313. static long _vq_quantmap__8c0_s_p4_0[] = {
  112314. 7, 5, 3, 1, 0, 2, 4, 6,
  112315. 8,
  112316. };
  112317. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112318. _vq_quantthresh__8c0_s_p4_0,
  112319. _vq_quantmap__8c0_s_p4_0,
  112320. 9,
  112321. 9
  112322. };
  112323. static static_codebook _8c0_s_p4_0 = {
  112324. 2, 81,
  112325. _vq_lengthlist__8c0_s_p4_0,
  112326. 1, -531628032, 1611661312, 4, 0,
  112327. _vq_quantlist__8c0_s_p4_0,
  112328. NULL,
  112329. &_vq_auxt__8c0_s_p4_0,
  112330. NULL,
  112331. 0
  112332. };
  112333. static long _vq_quantlist__8c0_s_p5_0[] = {
  112334. 4,
  112335. 3,
  112336. 5,
  112337. 2,
  112338. 6,
  112339. 1,
  112340. 7,
  112341. 0,
  112342. 8,
  112343. };
  112344. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112345. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112346. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112347. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112348. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112349. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112350. 10,
  112351. };
  112352. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112353. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112354. };
  112355. static long _vq_quantmap__8c0_s_p5_0[] = {
  112356. 7, 5, 3, 1, 0, 2, 4, 6,
  112357. 8,
  112358. };
  112359. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112360. _vq_quantthresh__8c0_s_p5_0,
  112361. _vq_quantmap__8c0_s_p5_0,
  112362. 9,
  112363. 9
  112364. };
  112365. static static_codebook _8c0_s_p5_0 = {
  112366. 2, 81,
  112367. _vq_lengthlist__8c0_s_p5_0,
  112368. 1, -531628032, 1611661312, 4, 0,
  112369. _vq_quantlist__8c0_s_p5_0,
  112370. NULL,
  112371. &_vq_auxt__8c0_s_p5_0,
  112372. NULL,
  112373. 0
  112374. };
  112375. static long _vq_quantlist__8c0_s_p6_0[] = {
  112376. 8,
  112377. 7,
  112378. 9,
  112379. 6,
  112380. 10,
  112381. 5,
  112382. 11,
  112383. 4,
  112384. 12,
  112385. 3,
  112386. 13,
  112387. 2,
  112388. 14,
  112389. 1,
  112390. 15,
  112391. 0,
  112392. 16,
  112393. };
  112394. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112395. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112396. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112397. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112398. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112399. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112400. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112401. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112402. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112403. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112404. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112405. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112406. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112407. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112408. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112409. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112410. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112411. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112412. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112413. 14,
  112414. };
  112415. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112416. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112417. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112418. };
  112419. static long _vq_quantmap__8c0_s_p6_0[] = {
  112420. 15, 13, 11, 9, 7, 5, 3, 1,
  112421. 0, 2, 4, 6, 8, 10, 12, 14,
  112422. 16,
  112423. };
  112424. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112425. _vq_quantthresh__8c0_s_p6_0,
  112426. _vq_quantmap__8c0_s_p6_0,
  112427. 17,
  112428. 17
  112429. };
  112430. static static_codebook _8c0_s_p6_0 = {
  112431. 2, 289,
  112432. _vq_lengthlist__8c0_s_p6_0,
  112433. 1, -529530880, 1611661312, 5, 0,
  112434. _vq_quantlist__8c0_s_p6_0,
  112435. NULL,
  112436. &_vq_auxt__8c0_s_p6_0,
  112437. NULL,
  112438. 0
  112439. };
  112440. static long _vq_quantlist__8c0_s_p7_0[] = {
  112441. 1,
  112442. 0,
  112443. 2,
  112444. };
  112445. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112446. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112447. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112448. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112449. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112450. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112451. 10,
  112452. };
  112453. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112454. -5.5, 5.5,
  112455. };
  112456. static long _vq_quantmap__8c0_s_p7_0[] = {
  112457. 1, 0, 2,
  112458. };
  112459. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112460. _vq_quantthresh__8c0_s_p7_0,
  112461. _vq_quantmap__8c0_s_p7_0,
  112462. 3,
  112463. 3
  112464. };
  112465. static static_codebook _8c0_s_p7_0 = {
  112466. 4, 81,
  112467. _vq_lengthlist__8c0_s_p7_0,
  112468. 1, -529137664, 1618345984, 2, 0,
  112469. _vq_quantlist__8c0_s_p7_0,
  112470. NULL,
  112471. &_vq_auxt__8c0_s_p7_0,
  112472. NULL,
  112473. 0
  112474. };
  112475. static long _vq_quantlist__8c0_s_p7_1[] = {
  112476. 5,
  112477. 4,
  112478. 6,
  112479. 3,
  112480. 7,
  112481. 2,
  112482. 8,
  112483. 1,
  112484. 9,
  112485. 0,
  112486. 10,
  112487. };
  112488. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112489. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112490. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112491. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112492. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112493. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112494. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112495. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112496. 10,10,10, 9, 9, 9,10,10,10,
  112497. };
  112498. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112499. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112500. 3.5, 4.5,
  112501. };
  112502. static long _vq_quantmap__8c0_s_p7_1[] = {
  112503. 9, 7, 5, 3, 1, 0, 2, 4,
  112504. 6, 8, 10,
  112505. };
  112506. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112507. _vq_quantthresh__8c0_s_p7_1,
  112508. _vq_quantmap__8c0_s_p7_1,
  112509. 11,
  112510. 11
  112511. };
  112512. static static_codebook _8c0_s_p7_1 = {
  112513. 2, 121,
  112514. _vq_lengthlist__8c0_s_p7_1,
  112515. 1, -531365888, 1611661312, 4, 0,
  112516. _vq_quantlist__8c0_s_p7_1,
  112517. NULL,
  112518. &_vq_auxt__8c0_s_p7_1,
  112519. NULL,
  112520. 0
  112521. };
  112522. static long _vq_quantlist__8c0_s_p8_0[] = {
  112523. 6,
  112524. 5,
  112525. 7,
  112526. 4,
  112527. 8,
  112528. 3,
  112529. 9,
  112530. 2,
  112531. 10,
  112532. 1,
  112533. 11,
  112534. 0,
  112535. 12,
  112536. };
  112537. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112538. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112539. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112540. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112541. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112542. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112543. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112544. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112545. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112546. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112547. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112548. 0, 0,13,13,11,13,13,11,12,
  112549. };
  112550. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112551. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112552. 12.5, 17.5, 22.5, 27.5,
  112553. };
  112554. static long _vq_quantmap__8c0_s_p8_0[] = {
  112555. 11, 9, 7, 5, 3, 1, 0, 2,
  112556. 4, 6, 8, 10, 12,
  112557. };
  112558. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112559. _vq_quantthresh__8c0_s_p8_0,
  112560. _vq_quantmap__8c0_s_p8_0,
  112561. 13,
  112562. 13
  112563. };
  112564. static static_codebook _8c0_s_p8_0 = {
  112565. 2, 169,
  112566. _vq_lengthlist__8c0_s_p8_0,
  112567. 1, -526516224, 1616117760, 4, 0,
  112568. _vq_quantlist__8c0_s_p8_0,
  112569. NULL,
  112570. &_vq_auxt__8c0_s_p8_0,
  112571. NULL,
  112572. 0
  112573. };
  112574. static long _vq_quantlist__8c0_s_p8_1[] = {
  112575. 2,
  112576. 1,
  112577. 3,
  112578. 0,
  112579. 4,
  112580. };
  112581. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112582. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112583. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112584. };
  112585. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112586. -1.5, -0.5, 0.5, 1.5,
  112587. };
  112588. static long _vq_quantmap__8c0_s_p8_1[] = {
  112589. 3, 1, 0, 2, 4,
  112590. };
  112591. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112592. _vq_quantthresh__8c0_s_p8_1,
  112593. _vq_quantmap__8c0_s_p8_1,
  112594. 5,
  112595. 5
  112596. };
  112597. static static_codebook _8c0_s_p8_1 = {
  112598. 2, 25,
  112599. _vq_lengthlist__8c0_s_p8_1,
  112600. 1, -533725184, 1611661312, 3, 0,
  112601. _vq_quantlist__8c0_s_p8_1,
  112602. NULL,
  112603. &_vq_auxt__8c0_s_p8_1,
  112604. NULL,
  112605. 0
  112606. };
  112607. static long _vq_quantlist__8c0_s_p9_0[] = {
  112608. 1,
  112609. 0,
  112610. 2,
  112611. };
  112612. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112613. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112614. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112615. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112616. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112617. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112618. 7,
  112619. };
  112620. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112621. -157.5, 157.5,
  112622. };
  112623. static long _vq_quantmap__8c0_s_p9_0[] = {
  112624. 1, 0, 2,
  112625. };
  112626. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112627. _vq_quantthresh__8c0_s_p9_0,
  112628. _vq_quantmap__8c0_s_p9_0,
  112629. 3,
  112630. 3
  112631. };
  112632. static static_codebook _8c0_s_p9_0 = {
  112633. 4, 81,
  112634. _vq_lengthlist__8c0_s_p9_0,
  112635. 1, -518803456, 1628680192, 2, 0,
  112636. _vq_quantlist__8c0_s_p9_0,
  112637. NULL,
  112638. &_vq_auxt__8c0_s_p9_0,
  112639. NULL,
  112640. 0
  112641. };
  112642. static long _vq_quantlist__8c0_s_p9_1[] = {
  112643. 7,
  112644. 6,
  112645. 8,
  112646. 5,
  112647. 9,
  112648. 4,
  112649. 10,
  112650. 3,
  112651. 11,
  112652. 2,
  112653. 12,
  112654. 1,
  112655. 13,
  112656. 0,
  112657. 14,
  112658. };
  112659. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112660. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112661. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112662. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112663. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112664. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112665. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112666. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112667. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112668. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112669. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112670. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112671. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112672. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112673. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112674. 11,
  112675. };
  112676. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112677. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112678. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112679. };
  112680. static long _vq_quantmap__8c0_s_p9_1[] = {
  112681. 13, 11, 9, 7, 5, 3, 1, 0,
  112682. 2, 4, 6, 8, 10, 12, 14,
  112683. };
  112684. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112685. _vq_quantthresh__8c0_s_p9_1,
  112686. _vq_quantmap__8c0_s_p9_1,
  112687. 15,
  112688. 15
  112689. };
  112690. static static_codebook _8c0_s_p9_1 = {
  112691. 2, 225,
  112692. _vq_lengthlist__8c0_s_p9_1,
  112693. 1, -520986624, 1620377600, 4, 0,
  112694. _vq_quantlist__8c0_s_p9_1,
  112695. NULL,
  112696. &_vq_auxt__8c0_s_p9_1,
  112697. NULL,
  112698. 0
  112699. };
  112700. static long _vq_quantlist__8c0_s_p9_2[] = {
  112701. 10,
  112702. 9,
  112703. 11,
  112704. 8,
  112705. 12,
  112706. 7,
  112707. 13,
  112708. 6,
  112709. 14,
  112710. 5,
  112711. 15,
  112712. 4,
  112713. 16,
  112714. 3,
  112715. 17,
  112716. 2,
  112717. 18,
  112718. 1,
  112719. 19,
  112720. 0,
  112721. 20,
  112722. };
  112723. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112724. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112725. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112726. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112727. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112728. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112729. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112730. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112731. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112732. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112733. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112734. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112735. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112736. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112737. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112738. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112739. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112740. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112741. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112742. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112743. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112744. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112745. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112746. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112747. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112748. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112749. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112750. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112751. 10,11, 9,11,10, 9,10, 9,10,
  112752. };
  112753. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112754. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112755. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112756. 6.5, 7.5, 8.5, 9.5,
  112757. };
  112758. static long _vq_quantmap__8c0_s_p9_2[] = {
  112759. 19, 17, 15, 13, 11, 9, 7, 5,
  112760. 3, 1, 0, 2, 4, 6, 8, 10,
  112761. 12, 14, 16, 18, 20,
  112762. };
  112763. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112764. _vq_quantthresh__8c0_s_p9_2,
  112765. _vq_quantmap__8c0_s_p9_2,
  112766. 21,
  112767. 21
  112768. };
  112769. static static_codebook _8c0_s_p9_2 = {
  112770. 2, 441,
  112771. _vq_lengthlist__8c0_s_p9_2,
  112772. 1, -529268736, 1611661312, 5, 0,
  112773. _vq_quantlist__8c0_s_p9_2,
  112774. NULL,
  112775. &_vq_auxt__8c0_s_p9_2,
  112776. NULL,
  112777. 0
  112778. };
  112779. static long _huff_lengthlist__8c0_s_single[] = {
  112780. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112781. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112782. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112783. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112784. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112785. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112786. 17,16,17,17,
  112787. };
  112788. static static_codebook _huff_book__8c0_s_single = {
  112789. 2, 100,
  112790. _huff_lengthlist__8c0_s_single,
  112791. 0, 0, 0, 0, 0,
  112792. NULL,
  112793. NULL,
  112794. NULL,
  112795. NULL,
  112796. 0
  112797. };
  112798. static long _vq_quantlist__8c1_s_p1_0[] = {
  112799. 1,
  112800. 0,
  112801. 2,
  112802. };
  112803. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112804. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112805. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112810. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112815. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112850. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112855. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112860. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112895. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112896. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112901. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  112902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112905. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112906. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113214. 0,
  113215. };
  113216. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113217. -0.5, 0.5,
  113218. };
  113219. static long _vq_quantmap__8c1_s_p1_0[] = {
  113220. 1, 0, 2,
  113221. };
  113222. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113223. _vq_quantthresh__8c1_s_p1_0,
  113224. _vq_quantmap__8c1_s_p1_0,
  113225. 3,
  113226. 3
  113227. };
  113228. static static_codebook _8c1_s_p1_0 = {
  113229. 8, 6561,
  113230. _vq_lengthlist__8c1_s_p1_0,
  113231. 1, -535822336, 1611661312, 2, 0,
  113232. _vq_quantlist__8c1_s_p1_0,
  113233. NULL,
  113234. &_vq_auxt__8c1_s_p1_0,
  113235. NULL,
  113236. 0
  113237. };
  113238. static long _vq_quantlist__8c1_s_p2_0[] = {
  113239. 2,
  113240. 1,
  113241. 3,
  113242. 0,
  113243. 4,
  113244. };
  113245. static long _vq_lengthlist__8c1_s_p2_0[] = {
  113246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113285. 0,
  113286. };
  113287. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113288. -1.5, -0.5, 0.5, 1.5,
  113289. };
  113290. static long _vq_quantmap__8c1_s_p2_0[] = {
  113291. 3, 1, 0, 2, 4,
  113292. };
  113293. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113294. _vq_quantthresh__8c1_s_p2_0,
  113295. _vq_quantmap__8c1_s_p2_0,
  113296. 5,
  113297. 5
  113298. };
  113299. static static_codebook _8c1_s_p2_0 = {
  113300. 4, 625,
  113301. _vq_lengthlist__8c1_s_p2_0,
  113302. 1, -533725184, 1611661312, 3, 0,
  113303. _vq_quantlist__8c1_s_p2_0,
  113304. NULL,
  113305. &_vq_auxt__8c1_s_p2_0,
  113306. NULL,
  113307. 0
  113308. };
  113309. static long _vq_quantlist__8c1_s_p3_0[] = {
  113310. 2,
  113311. 1,
  113312. 3,
  113313. 0,
  113314. 4,
  113315. };
  113316. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113317. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113320. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113323. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113356. 0,
  113357. };
  113358. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113359. -1.5, -0.5, 0.5, 1.5,
  113360. };
  113361. static long _vq_quantmap__8c1_s_p3_0[] = {
  113362. 3, 1, 0, 2, 4,
  113363. };
  113364. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113365. _vq_quantthresh__8c1_s_p3_0,
  113366. _vq_quantmap__8c1_s_p3_0,
  113367. 5,
  113368. 5
  113369. };
  113370. static static_codebook _8c1_s_p3_0 = {
  113371. 4, 625,
  113372. _vq_lengthlist__8c1_s_p3_0,
  113373. 1, -533725184, 1611661312, 3, 0,
  113374. _vq_quantlist__8c1_s_p3_0,
  113375. NULL,
  113376. &_vq_auxt__8c1_s_p3_0,
  113377. NULL,
  113378. 0
  113379. };
  113380. static long _vq_quantlist__8c1_s_p4_0[] = {
  113381. 4,
  113382. 3,
  113383. 5,
  113384. 2,
  113385. 6,
  113386. 1,
  113387. 7,
  113388. 0,
  113389. 8,
  113390. };
  113391. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113392. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113393. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113394. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113395. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113396. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113397. 0,
  113398. };
  113399. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113400. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113401. };
  113402. static long _vq_quantmap__8c1_s_p4_0[] = {
  113403. 7, 5, 3, 1, 0, 2, 4, 6,
  113404. 8,
  113405. };
  113406. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113407. _vq_quantthresh__8c1_s_p4_0,
  113408. _vq_quantmap__8c1_s_p4_0,
  113409. 9,
  113410. 9
  113411. };
  113412. static static_codebook _8c1_s_p4_0 = {
  113413. 2, 81,
  113414. _vq_lengthlist__8c1_s_p4_0,
  113415. 1, -531628032, 1611661312, 4, 0,
  113416. _vq_quantlist__8c1_s_p4_0,
  113417. NULL,
  113418. &_vq_auxt__8c1_s_p4_0,
  113419. NULL,
  113420. 0
  113421. };
  113422. static long _vq_quantlist__8c1_s_p5_0[] = {
  113423. 4,
  113424. 3,
  113425. 5,
  113426. 2,
  113427. 6,
  113428. 1,
  113429. 7,
  113430. 0,
  113431. 8,
  113432. };
  113433. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113434. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113435. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113436. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113437. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113438. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113439. 10,
  113440. };
  113441. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113442. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113443. };
  113444. static long _vq_quantmap__8c1_s_p5_0[] = {
  113445. 7, 5, 3, 1, 0, 2, 4, 6,
  113446. 8,
  113447. };
  113448. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113449. _vq_quantthresh__8c1_s_p5_0,
  113450. _vq_quantmap__8c1_s_p5_0,
  113451. 9,
  113452. 9
  113453. };
  113454. static static_codebook _8c1_s_p5_0 = {
  113455. 2, 81,
  113456. _vq_lengthlist__8c1_s_p5_0,
  113457. 1, -531628032, 1611661312, 4, 0,
  113458. _vq_quantlist__8c1_s_p5_0,
  113459. NULL,
  113460. &_vq_auxt__8c1_s_p5_0,
  113461. NULL,
  113462. 0
  113463. };
  113464. static long _vq_quantlist__8c1_s_p6_0[] = {
  113465. 8,
  113466. 7,
  113467. 9,
  113468. 6,
  113469. 10,
  113470. 5,
  113471. 11,
  113472. 4,
  113473. 12,
  113474. 3,
  113475. 13,
  113476. 2,
  113477. 14,
  113478. 1,
  113479. 15,
  113480. 0,
  113481. 16,
  113482. };
  113483. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113484. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113485. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113486. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113487. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113488. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113489. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113490. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113491. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113492. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113493. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113494. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113495. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113496. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113497. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113498. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113499. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113500. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113501. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113502. 14,
  113503. };
  113504. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113505. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113506. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113507. };
  113508. static long _vq_quantmap__8c1_s_p6_0[] = {
  113509. 15, 13, 11, 9, 7, 5, 3, 1,
  113510. 0, 2, 4, 6, 8, 10, 12, 14,
  113511. 16,
  113512. };
  113513. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113514. _vq_quantthresh__8c1_s_p6_0,
  113515. _vq_quantmap__8c1_s_p6_0,
  113516. 17,
  113517. 17
  113518. };
  113519. static static_codebook _8c1_s_p6_0 = {
  113520. 2, 289,
  113521. _vq_lengthlist__8c1_s_p6_0,
  113522. 1, -529530880, 1611661312, 5, 0,
  113523. _vq_quantlist__8c1_s_p6_0,
  113524. NULL,
  113525. &_vq_auxt__8c1_s_p6_0,
  113526. NULL,
  113527. 0
  113528. };
  113529. static long _vq_quantlist__8c1_s_p7_0[] = {
  113530. 1,
  113531. 0,
  113532. 2,
  113533. };
  113534. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113535. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113536. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113537. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113538. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113539. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113540. 9,
  113541. };
  113542. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113543. -5.5, 5.5,
  113544. };
  113545. static long _vq_quantmap__8c1_s_p7_0[] = {
  113546. 1, 0, 2,
  113547. };
  113548. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113549. _vq_quantthresh__8c1_s_p7_0,
  113550. _vq_quantmap__8c1_s_p7_0,
  113551. 3,
  113552. 3
  113553. };
  113554. static static_codebook _8c1_s_p7_0 = {
  113555. 4, 81,
  113556. _vq_lengthlist__8c1_s_p7_0,
  113557. 1, -529137664, 1618345984, 2, 0,
  113558. _vq_quantlist__8c1_s_p7_0,
  113559. NULL,
  113560. &_vq_auxt__8c1_s_p7_0,
  113561. NULL,
  113562. 0
  113563. };
  113564. static long _vq_quantlist__8c1_s_p7_1[] = {
  113565. 5,
  113566. 4,
  113567. 6,
  113568. 3,
  113569. 7,
  113570. 2,
  113571. 8,
  113572. 1,
  113573. 9,
  113574. 0,
  113575. 10,
  113576. };
  113577. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113578. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113579. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113580. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113581. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113582. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113583. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113584. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113585. 10,10,10, 8, 8, 8, 8, 8, 8,
  113586. };
  113587. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113588. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113589. 3.5, 4.5,
  113590. };
  113591. static long _vq_quantmap__8c1_s_p7_1[] = {
  113592. 9, 7, 5, 3, 1, 0, 2, 4,
  113593. 6, 8, 10,
  113594. };
  113595. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113596. _vq_quantthresh__8c1_s_p7_1,
  113597. _vq_quantmap__8c1_s_p7_1,
  113598. 11,
  113599. 11
  113600. };
  113601. static static_codebook _8c1_s_p7_1 = {
  113602. 2, 121,
  113603. _vq_lengthlist__8c1_s_p7_1,
  113604. 1, -531365888, 1611661312, 4, 0,
  113605. _vq_quantlist__8c1_s_p7_1,
  113606. NULL,
  113607. &_vq_auxt__8c1_s_p7_1,
  113608. NULL,
  113609. 0
  113610. };
  113611. static long _vq_quantlist__8c1_s_p8_0[] = {
  113612. 6,
  113613. 5,
  113614. 7,
  113615. 4,
  113616. 8,
  113617. 3,
  113618. 9,
  113619. 2,
  113620. 10,
  113621. 1,
  113622. 11,
  113623. 0,
  113624. 12,
  113625. };
  113626. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113627. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113628. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113629. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113630. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113631. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113632. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113633. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113634. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113635. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113636. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113637. 0,12,12,11,10,12,11,13,12,
  113638. };
  113639. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113640. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113641. 12.5, 17.5, 22.5, 27.5,
  113642. };
  113643. static long _vq_quantmap__8c1_s_p8_0[] = {
  113644. 11, 9, 7, 5, 3, 1, 0, 2,
  113645. 4, 6, 8, 10, 12,
  113646. };
  113647. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113648. _vq_quantthresh__8c1_s_p8_0,
  113649. _vq_quantmap__8c1_s_p8_0,
  113650. 13,
  113651. 13
  113652. };
  113653. static static_codebook _8c1_s_p8_0 = {
  113654. 2, 169,
  113655. _vq_lengthlist__8c1_s_p8_0,
  113656. 1, -526516224, 1616117760, 4, 0,
  113657. _vq_quantlist__8c1_s_p8_0,
  113658. NULL,
  113659. &_vq_auxt__8c1_s_p8_0,
  113660. NULL,
  113661. 0
  113662. };
  113663. static long _vq_quantlist__8c1_s_p8_1[] = {
  113664. 2,
  113665. 1,
  113666. 3,
  113667. 0,
  113668. 4,
  113669. };
  113670. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113671. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113672. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113673. };
  113674. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113675. -1.5, -0.5, 0.5, 1.5,
  113676. };
  113677. static long _vq_quantmap__8c1_s_p8_1[] = {
  113678. 3, 1, 0, 2, 4,
  113679. };
  113680. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113681. _vq_quantthresh__8c1_s_p8_1,
  113682. _vq_quantmap__8c1_s_p8_1,
  113683. 5,
  113684. 5
  113685. };
  113686. static static_codebook _8c1_s_p8_1 = {
  113687. 2, 25,
  113688. _vq_lengthlist__8c1_s_p8_1,
  113689. 1, -533725184, 1611661312, 3, 0,
  113690. _vq_quantlist__8c1_s_p8_1,
  113691. NULL,
  113692. &_vq_auxt__8c1_s_p8_1,
  113693. NULL,
  113694. 0
  113695. };
  113696. static long _vq_quantlist__8c1_s_p9_0[] = {
  113697. 6,
  113698. 5,
  113699. 7,
  113700. 4,
  113701. 8,
  113702. 3,
  113703. 9,
  113704. 2,
  113705. 10,
  113706. 1,
  113707. 11,
  113708. 0,
  113709. 12,
  113710. };
  113711. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113712. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113713. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113714. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113715. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113716. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113717. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113718. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113719. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113720. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113721. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113722. 10,10,10,10,10, 9, 9, 9, 9,
  113723. };
  113724. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113725. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113726. 787.5, 1102.5, 1417.5, 1732.5,
  113727. };
  113728. static long _vq_quantmap__8c1_s_p9_0[] = {
  113729. 11, 9, 7, 5, 3, 1, 0, 2,
  113730. 4, 6, 8, 10, 12,
  113731. };
  113732. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113733. _vq_quantthresh__8c1_s_p9_0,
  113734. _vq_quantmap__8c1_s_p9_0,
  113735. 13,
  113736. 13
  113737. };
  113738. static static_codebook _8c1_s_p9_0 = {
  113739. 2, 169,
  113740. _vq_lengthlist__8c1_s_p9_0,
  113741. 1, -513964032, 1628680192, 4, 0,
  113742. _vq_quantlist__8c1_s_p9_0,
  113743. NULL,
  113744. &_vq_auxt__8c1_s_p9_0,
  113745. NULL,
  113746. 0
  113747. };
  113748. static long _vq_quantlist__8c1_s_p9_1[] = {
  113749. 7,
  113750. 6,
  113751. 8,
  113752. 5,
  113753. 9,
  113754. 4,
  113755. 10,
  113756. 3,
  113757. 11,
  113758. 2,
  113759. 12,
  113760. 1,
  113761. 13,
  113762. 0,
  113763. 14,
  113764. };
  113765. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113766. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113767. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113768. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113769. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113770. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113771. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113772. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113773. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113774. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113775. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113776. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113777. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113778. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113779. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113780. 15,
  113781. };
  113782. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113783. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113784. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113785. };
  113786. static long _vq_quantmap__8c1_s_p9_1[] = {
  113787. 13, 11, 9, 7, 5, 3, 1, 0,
  113788. 2, 4, 6, 8, 10, 12, 14,
  113789. };
  113790. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113791. _vq_quantthresh__8c1_s_p9_1,
  113792. _vq_quantmap__8c1_s_p9_1,
  113793. 15,
  113794. 15
  113795. };
  113796. static static_codebook _8c1_s_p9_1 = {
  113797. 2, 225,
  113798. _vq_lengthlist__8c1_s_p9_1,
  113799. 1, -520986624, 1620377600, 4, 0,
  113800. _vq_quantlist__8c1_s_p9_1,
  113801. NULL,
  113802. &_vq_auxt__8c1_s_p9_1,
  113803. NULL,
  113804. 0
  113805. };
  113806. static long _vq_quantlist__8c1_s_p9_2[] = {
  113807. 10,
  113808. 9,
  113809. 11,
  113810. 8,
  113811. 12,
  113812. 7,
  113813. 13,
  113814. 6,
  113815. 14,
  113816. 5,
  113817. 15,
  113818. 4,
  113819. 16,
  113820. 3,
  113821. 17,
  113822. 2,
  113823. 18,
  113824. 1,
  113825. 19,
  113826. 0,
  113827. 20,
  113828. };
  113829. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113830. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113831. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113832. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113833. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113834. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113835. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113836. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113837. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113838. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113839. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113840. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113841. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113842. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113843. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113844. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113845. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113846. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113847. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113848. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113849. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113850. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113851. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113852. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113853. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113854. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113855. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113856. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113857. 10,10,10,10,10,10,10,10,10,
  113858. };
  113859. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113860. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113861. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113862. 6.5, 7.5, 8.5, 9.5,
  113863. };
  113864. static long _vq_quantmap__8c1_s_p9_2[] = {
  113865. 19, 17, 15, 13, 11, 9, 7, 5,
  113866. 3, 1, 0, 2, 4, 6, 8, 10,
  113867. 12, 14, 16, 18, 20,
  113868. };
  113869. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113870. _vq_quantthresh__8c1_s_p9_2,
  113871. _vq_quantmap__8c1_s_p9_2,
  113872. 21,
  113873. 21
  113874. };
  113875. static static_codebook _8c1_s_p9_2 = {
  113876. 2, 441,
  113877. _vq_lengthlist__8c1_s_p9_2,
  113878. 1, -529268736, 1611661312, 5, 0,
  113879. _vq_quantlist__8c1_s_p9_2,
  113880. NULL,
  113881. &_vq_auxt__8c1_s_p9_2,
  113882. NULL,
  113883. 0
  113884. };
  113885. static long _huff_lengthlist__8c1_s_single[] = {
  113886. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113887. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113888. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113889. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113890. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113891. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113892. 9, 7, 7, 8,
  113893. };
  113894. static static_codebook _huff_book__8c1_s_single = {
  113895. 2, 100,
  113896. _huff_lengthlist__8c1_s_single,
  113897. 0, 0, 0, 0, 0,
  113898. NULL,
  113899. NULL,
  113900. NULL,
  113901. NULL,
  113902. 0
  113903. };
  113904. static long _huff_lengthlist__44c2_s_long[] = {
  113905. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113906. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113907. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113908. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113909. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113910. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113911. 10, 8, 8, 9,
  113912. };
  113913. static static_codebook _huff_book__44c2_s_long = {
  113914. 2, 100,
  113915. _huff_lengthlist__44c2_s_long,
  113916. 0, 0, 0, 0, 0,
  113917. NULL,
  113918. NULL,
  113919. NULL,
  113920. NULL,
  113921. 0
  113922. };
  113923. static long _vq_quantlist__44c2_s_p1_0[] = {
  113924. 1,
  113925. 0,
  113926. 2,
  113927. };
  113928. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113929. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113930. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113935. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113940. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113975. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113980. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113985. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114020. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114021. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114026. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  114027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114030. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114031. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114339. 0,
  114340. };
  114341. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114342. -0.5, 0.5,
  114343. };
  114344. static long _vq_quantmap__44c2_s_p1_0[] = {
  114345. 1, 0, 2,
  114346. };
  114347. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114348. _vq_quantthresh__44c2_s_p1_0,
  114349. _vq_quantmap__44c2_s_p1_0,
  114350. 3,
  114351. 3
  114352. };
  114353. static static_codebook _44c2_s_p1_0 = {
  114354. 8, 6561,
  114355. _vq_lengthlist__44c2_s_p1_0,
  114356. 1, -535822336, 1611661312, 2, 0,
  114357. _vq_quantlist__44c2_s_p1_0,
  114358. NULL,
  114359. &_vq_auxt__44c2_s_p1_0,
  114360. NULL,
  114361. 0
  114362. };
  114363. static long _vq_quantlist__44c2_s_p2_0[] = {
  114364. 2,
  114365. 1,
  114366. 3,
  114367. 0,
  114368. 4,
  114369. };
  114370. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114371. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114372. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114373. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114374. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114375. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114380. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114381. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114382. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114383. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114388. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114389. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114390. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114396. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114397. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114398. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114410. 0,
  114411. };
  114412. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114413. -1.5, -0.5, 0.5, 1.5,
  114414. };
  114415. static long _vq_quantmap__44c2_s_p2_0[] = {
  114416. 3, 1, 0, 2, 4,
  114417. };
  114418. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114419. _vq_quantthresh__44c2_s_p2_0,
  114420. _vq_quantmap__44c2_s_p2_0,
  114421. 5,
  114422. 5
  114423. };
  114424. static static_codebook _44c2_s_p2_0 = {
  114425. 4, 625,
  114426. _vq_lengthlist__44c2_s_p2_0,
  114427. 1, -533725184, 1611661312, 3, 0,
  114428. _vq_quantlist__44c2_s_p2_0,
  114429. NULL,
  114430. &_vq_auxt__44c2_s_p2_0,
  114431. NULL,
  114432. 0
  114433. };
  114434. static long _vq_quantlist__44c2_s_p3_0[] = {
  114435. 2,
  114436. 1,
  114437. 3,
  114438. 0,
  114439. 4,
  114440. };
  114441. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114442. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114445. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114448. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114481. 0,
  114482. };
  114483. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114484. -1.5, -0.5, 0.5, 1.5,
  114485. };
  114486. static long _vq_quantmap__44c2_s_p3_0[] = {
  114487. 3, 1, 0, 2, 4,
  114488. };
  114489. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114490. _vq_quantthresh__44c2_s_p3_0,
  114491. _vq_quantmap__44c2_s_p3_0,
  114492. 5,
  114493. 5
  114494. };
  114495. static static_codebook _44c2_s_p3_0 = {
  114496. 4, 625,
  114497. _vq_lengthlist__44c2_s_p3_0,
  114498. 1, -533725184, 1611661312, 3, 0,
  114499. _vq_quantlist__44c2_s_p3_0,
  114500. NULL,
  114501. &_vq_auxt__44c2_s_p3_0,
  114502. NULL,
  114503. 0
  114504. };
  114505. static long _vq_quantlist__44c2_s_p4_0[] = {
  114506. 4,
  114507. 3,
  114508. 5,
  114509. 2,
  114510. 6,
  114511. 1,
  114512. 7,
  114513. 0,
  114514. 8,
  114515. };
  114516. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114517. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114518. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114519. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114520. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114521. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114522. 0,
  114523. };
  114524. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114525. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114526. };
  114527. static long _vq_quantmap__44c2_s_p4_0[] = {
  114528. 7, 5, 3, 1, 0, 2, 4, 6,
  114529. 8,
  114530. };
  114531. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114532. _vq_quantthresh__44c2_s_p4_0,
  114533. _vq_quantmap__44c2_s_p4_0,
  114534. 9,
  114535. 9
  114536. };
  114537. static static_codebook _44c2_s_p4_0 = {
  114538. 2, 81,
  114539. _vq_lengthlist__44c2_s_p4_0,
  114540. 1, -531628032, 1611661312, 4, 0,
  114541. _vq_quantlist__44c2_s_p4_0,
  114542. NULL,
  114543. &_vq_auxt__44c2_s_p4_0,
  114544. NULL,
  114545. 0
  114546. };
  114547. static long _vq_quantlist__44c2_s_p5_0[] = {
  114548. 4,
  114549. 3,
  114550. 5,
  114551. 2,
  114552. 6,
  114553. 1,
  114554. 7,
  114555. 0,
  114556. 8,
  114557. };
  114558. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114559. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114560. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114561. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114562. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114563. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114564. 11,
  114565. };
  114566. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114567. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114568. };
  114569. static long _vq_quantmap__44c2_s_p5_0[] = {
  114570. 7, 5, 3, 1, 0, 2, 4, 6,
  114571. 8,
  114572. };
  114573. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114574. _vq_quantthresh__44c2_s_p5_0,
  114575. _vq_quantmap__44c2_s_p5_0,
  114576. 9,
  114577. 9
  114578. };
  114579. static static_codebook _44c2_s_p5_0 = {
  114580. 2, 81,
  114581. _vq_lengthlist__44c2_s_p5_0,
  114582. 1, -531628032, 1611661312, 4, 0,
  114583. _vq_quantlist__44c2_s_p5_0,
  114584. NULL,
  114585. &_vq_auxt__44c2_s_p5_0,
  114586. NULL,
  114587. 0
  114588. };
  114589. static long _vq_quantlist__44c2_s_p6_0[] = {
  114590. 8,
  114591. 7,
  114592. 9,
  114593. 6,
  114594. 10,
  114595. 5,
  114596. 11,
  114597. 4,
  114598. 12,
  114599. 3,
  114600. 13,
  114601. 2,
  114602. 14,
  114603. 1,
  114604. 15,
  114605. 0,
  114606. 16,
  114607. };
  114608. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114609. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114610. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114611. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114612. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114613. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114614. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114615. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114616. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114617. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114618. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114619. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114620. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114621. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114622. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114623. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114624. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114625. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114626. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114627. 14,
  114628. };
  114629. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114630. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114631. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114632. };
  114633. static long _vq_quantmap__44c2_s_p6_0[] = {
  114634. 15, 13, 11, 9, 7, 5, 3, 1,
  114635. 0, 2, 4, 6, 8, 10, 12, 14,
  114636. 16,
  114637. };
  114638. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114639. _vq_quantthresh__44c2_s_p6_0,
  114640. _vq_quantmap__44c2_s_p6_0,
  114641. 17,
  114642. 17
  114643. };
  114644. static static_codebook _44c2_s_p6_0 = {
  114645. 2, 289,
  114646. _vq_lengthlist__44c2_s_p6_0,
  114647. 1, -529530880, 1611661312, 5, 0,
  114648. _vq_quantlist__44c2_s_p6_0,
  114649. NULL,
  114650. &_vq_auxt__44c2_s_p6_0,
  114651. NULL,
  114652. 0
  114653. };
  114654. static long _vq_quantlist__44c2_s_p7_0[] = {
  114655. 1,
  114656. 0,
  114657. 2,
  114658. };
  114659. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114660. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114661. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114662. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114663. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114664. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114665. 11,
  114666. };
  114667. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114668. -5.5, 5.5,
  114669. };
  114670. static long _vq_quantmap__44c2_s_p7_0[] = {
  114671. 1, 0, 2,
  114672. };
  114673. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114674. _vq_quantthresh__44c2_s_p7_0,
  114675. _vq_quantmap__44c2_s_p7_0,
  114676. 3,
  114677. 3
  114678. };
  114679. static static_codebook _44c2_s_p7_0 = {
  114680. 4, 81,
  114681. _vq_lengthlist__44c2_s_p7_0,
  114682. 1, -529137664, 1618345984, 2, 0,
  114683. _vq_quantlist__44c2_s_p7_0,
  114684. NULL,
  114685. &_vq_auxt__44c2_s_p7_0,
  114686. NULL,
  114687. 0
  114688. };
  114689. static long _vq_quantlist__44c2_s_p7_1[] = {
  114690. 5,
  114691. 4,
  114692. 6,
  114693. 3,
  114694. 7,
  114695. 2,
  114696. 8,
  114697. 1,
  114698. 9,
  114699. 0,
  114700. 10,
  114701. };
  114702. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114703. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114704. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114705. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114706. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114707. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114708. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114709. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114710. 10,10,10, 8, 8, 8, 8, 8, 8,
  114711. };
  114712. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114713. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114714. 3.5, 4.5,
  114715. };
  114716. static long _vq_quantmap__44c2_s_p7_1[] = {
  114717. 9, 7, 5, 3, 1, 0, 2, 4,
  114718. 6, 8, 10,
  114719. };
  114720. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114721. _vq_quantthresh__44c2_s_p7_1,
  114722. _vq_quantmap__44c2_s_p7_1,
  114723. 11,
  114724. 11
  114725. };
  114726. static static_codebook _44c2_s_p7_1 = {
  114727. 2, 121,
  114728. _vq_lengthlist__44c2_s_p7_1,
  114729. 1, -531365888, 1611661312, 4, 0,
  114730. _vq_quantlist__44c2_s_p7_1,
  114731. NULL,
  114732. &_vq_auxt__44c2_s_p7_1,
  114733. NULL,
  114734. 0
  114735. };
  114736. static long _vq_quantlist__44c2_s_p8_0[] = {
  114737. 6,
  114738. 5,
  114739. 7,
  114740. 4,
  114741. 8,
  114742. 3,
  114743. 9,
  114744. 2,
  114745. 10,
  114746. 1,
  114747. 11,
  114748. 0,
  114749. 12,
  114750. };
  114751. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114752. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114753. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114754. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114755. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114756. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114757. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114758. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114759. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114760. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114761. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114762. 0,12,12,12,12,13,12,14,14,
  114763. };
  114764. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114765. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114766. 12.5, 17.5, 22.5, 27.5,
  114767. };
  114768. static long _vq_quantmap__44c2_s_p8_0[] = {
  114769. 11, 9, 7, 5, 3, 1, 0, 2,
  114770. 4, 6, 8, 10, 12,
  114771. };
  114772. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114773. _vq_quantthresh__44c2_s_p8_0,
  114774. _vq_quantmap__44c2_s_p8_0,
  114775. 13,
  114776. 13
  114777. };
  114778. static static_codebook _44c2_s_p8_0 = {
  114779. 2, 169,
  114780. _vq_lengthlist__44c2_s_p8_0,
  114781. 1, -526516224, 1616117760, 4, 0,
  114782. _vq_quantlist__44c2_s_p8_0,
  114783. NULL,
  114784. &_vq_auxt__44c2_s_p8_0,
  114785. NULL,
  114786. 0
  114787. };
  114788. static long _vq_quantlist__44c2_s_p8_1[] = {
  114789. 2,
  114790. 1,
  114791. 3,
  114792. 0,
  114793. 4,
  114794. };
  114795. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114796. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114797. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114798. };
  114799. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114800. -1.5, -0.5, 0.5, 1.5,
  114801. };
  114802. static long _vq_quantmap__44c2_s_p8_1[] = {
  114803. 3, 1, 0, 2, 4,
  114804. };
  114805. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114806. _vq_quantthresh__44c2_s_p8_1,
  114807. _vq_quantmap__44c2_s_p8_1,
  114808. 5,
  114809. 5
  114810. };
  114811. static static_codebook _44c2_s_p8_1 = {
  114812. 2, 25,
  114813. _vq_lengthlist__44c2_s_p8_1,
  114814. 1, -533725184, 1611661312, 3, 0,
  114815. _vq_quantlist__44c2_s_p8_1,
  114816. NULL,
  114817. &_vq_auxt__44c2_s_p8_1,
  114818. NULL,
  114819. 0
  114820. };
  114821. static long _vq_quantlist__44c2_s_p9_0[] = {
  114822. 6,
  114823. 5,
  114824. 7,
  114825. 4,
  114826. 8,
  114827. 3,
  114828. 9,
  114829. 2,
  114830. 10,
  114831. 1,
  114832. 11,
  114833. 0,
  114834. 12,
  114835. };
  114836. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114837. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114838. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114839. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114840. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114841. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114842. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114843. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114844. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114845. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114846. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114847. 11,11,11,11,11,11,11,11,11,
  114848. };
  114849. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114850. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114851. 552.5, 773.5, 994.5, 1215.5,
  114852. };
  114853. static long _vq_quantmap__44c2_s_p9_0[] = {
  114854. 11, 9, 7, 5, 3, 1, 0, 2,
  114855. 4, 6, 8, 10, 12,
  114856. };
  114857. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114858. _vq_quantthresh__44c2_s_p9_0,
  114859. _vq_quantmap__44c2_s_p9_0,
  114860. 13,
  114861. 13
  114862. };
  114863. static static_codebook _44c2_s_p9_0 = {
  114864. 2, 169,
  114865. _vq_lengthlist__44c2_s_p9_0,
  114866. 1, -514541568, 1627103232, 4, 0,
  114867. _vq_quantlist__44c2_s_p9_0,
  114868. NULL,
  114869. &_vq_auxt__44c2_s_p9_0,
  114870. NULL,
  114871. 0
  114872. };
  114873. static long _vq_quantlist__44c2_s_p9_1[] = {
  114874. 6,
  114875. 5,
  114876. 7,
  114877. 4,
  114878. 8,
  114879. 3,
  114880. 9,
  114881. 2,
  114882. 10,
  114883. 1,
  114884. 11,
  114885. 0,
  114886. 12,
  114887. };
  114888. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114889. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114890. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114891. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114892. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114893. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114894. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114895. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114896. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114897. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114898. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114899. 17,13,12,12,10,13,11,14,14,
  114900. };
  114901. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114902. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114903. 42.5, 59.5, 76.5, 93.5,
  114904. };
  114905. static long _vq_quantmap__44c2_s_p9_1[] = {
  114906. 11, 9, 7, 5, 3, 1, 0, 2,
  114907. 4, 6, 8, 10, 12,
  114908. };
  114909. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114910. _vq_quantthresh__44c2_s_p9_1,
  114911. _vq_quantmap__44c2_s_p9_1,
  114912. 13,
  114913. 13
  114914. };
  114915. static static_codebook _44c2_s_p9_1 = {
  114916. 2, 169,
  114917. _vq_lengthlist__44c2_s_p9_1,
  114918. 1, -522616832, 1620115456, 4, 0,
  114919. _vq_quantlist__44c2_s_p9_1,
  114920. NULL,
  114921. &_vq_auxt__44c2_s_p9_1,
  114922. NULL,
  114923. 0
  114924. };
  114925. static long _vq_quantlist__44c2_s_p9_2[] = {
  114926. 8,
  114927. 7,
  114928. 9,
  114929. 6,
  114930. 10,
  114931. 5,
  114932. 11,
  114933. 4,
  114934. 12,
  114935. 3,
  114936. 13,
  114937. 2,
  114938. 14,
  114939. 1,
  114940. 15,
  114941. 0,
  114942. 16,
  114943. };
  114944. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114945. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114946. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114947. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114948. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114949. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114950. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114951. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114952. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114953. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114954. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114955. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114956. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114957. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114958. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114959. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114960. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114961. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114962. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114963. 10,
  114964. };
  114965. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114966. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114967. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114968. };
  114969. static long _vq_quantmap__44c2_s_p9_2[] = {
  114970. 15, 13, 11, 9, 7, 5, 3, 1,
  114971. 0, 2, 4, 6, 8, 10, 12, 14,
  114972. 16,
  114973. };
  114974. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114975. _vq_quantthresh__44c2_s_p9_2,
  114976. _vq_quantmap__44c2_s_p9_2,
  114977. 17,
  114978. 17
  114979. };
  114980. static static_codebook _44c2_s_p9_2 = {
  114981. 2, 289,
  114982. _vq_lengthlist__44c2_s_p9_2,
  114983. 1, -529530880, 1611661312, 5, 0,
  114984. _vq_quantlist__44c2_s_p9_2,
  114985. NULL,
  114986. &_vq_auxt__44c2_s_p9_2,
  114987. NULL,
  114988. 0
  114989. };
  114990. static long _huff_lengthlist__44c2_s_short[] = {
  114991. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114992. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114993. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114994. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114995. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114996. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114997. 6, 8, 9,12,
  114998. };
  114999. static static_codebook _huff_book__44c2_s_short = {
  115000. 2, 100,
  115001. _huff_lengthlist__44c2_s_short,
  115002. 0, 0, 0, 0, 0,
  115003. NULL,
  115004. NULL,
  115005. NULL,
  115006. NULL,
  115007. 0
  115008. };
  115009. static long _huff_lengthlist__44c3_s_long[] = {
  115010. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  115011. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  115012. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  115013. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  115014. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  115015. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  115016. 9, 8, 8, 8,
  115017. };
  115018. static static_codebook _huff_book__44c3_s_long = {
  115019. 2, 100,
  115020. _huff_lengthlist__44c3_s_long,
  115021. 0, 0, 0, 0, 0,
  115022. NULL,
  115023. NULL,
  115024. NULL,
  115025. NULL,
  115026. 0
  115027. };
  115028. static long _vq_quantlist__44c3_s_p1_0[] = {
  115029. 1,
  115030. 0,
  115031. 2,
  115032. };
  115033. static long _vq_lengthlist__44c3_s_p1_0[] = {
  115034. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115035. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115040. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115045. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115080. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115085. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115090. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115125. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115126. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115131. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115135. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115136. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  115137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115444. 0,
  115445. };
  115446. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115447. -0.5, 0.5,
  115448. };
  115449. static long _vq_quantmap__44c3_s_p1_0[] = {
  115450. 1, 0, 2,
  115451. };
  115452. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115453. _vq_quantthresh__44c3_s_p1_0,
  115454. _vq_quantmap__44c3_s_p1_0,
  115455. 3,
  115456. 3
  115457. };
  115458. static static_codebook _44c3_s_p1_0 = {
  115459. 8, 6561,
  115460. _vq_lengthlist__44c3_s_p1_0,
  115461. 1, -535822336, 1611661312, 2, 0,
  115462. _vq_quantlist__44c3_s_p1_0,
  115463. NULL,
  115464. &_vq_auxt__44c3_s_p1_0,
  115465. NULL,
  115466. 0
  115467. };
  115468. static long _vq_quantlist__44c3_s_p2_0[] = {
  115469. 2,
  115470. 1,
  115471. 3,
  115472. 0,
  115473. 4,
  115474. };
  115475. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115476. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115477. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115478. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115479. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115480. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115485. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115486. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115487. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115488. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115493. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115494. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115495. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115501. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115502. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115503. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115515. 0,
  115516. };
  115517. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115518. -1.5, -0.5, 0.5, 1.5,
  115519. };
  115520. static long _vq_quantmap__44c3_s_p2_0[] = {
  115521. 3, 1, 0, 2, 4,
  115522. };
  115523. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115524. _vq_quantthresh__44c3_s_p2_0,
  115525. _vq_quantmap__44c3_s_p2_0,
  115526. 5,
  115527. 5
  115528. };
  115529. static static_codebook _44c3_s_p2_0 = {
  115530. 4, 625,
  115531. _vq_lengthlist__44c3_s_p2_0,
  115532. 1, -533725184, 1611661312, 3, 0,
  115533. _vq_quantlist__44c3_s_p2_0,
  115534. NULL,
  115535. &_vq_auxt__44c3_s_p2_0,
  115536. NULL,
  115537. 0
  115538. };
  115539. static long _vq_quantlist__44c3_s_p3_0[] = {
  115540. 2,
  115541. 1,
  115542. 3,
  115543. 0,
  115544. 4,
  115545. };
  115546. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115547. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115550. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115553. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115586. 0,
  115587. };
  115588. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115589. -1.5, -0.5, 0.5, 1.5,
  115590. };
  115591. static long _vq_quantmap__44c3_s_p3_0[] = {
  115592. 3, 1, 0, 2, 4,
  115593. };
  115594. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115595. _vq_quantthresh__44c3_s_p3_0,
  115596. _vq_quantmap__44c3_s_p3_0,
  115597. 5,
  115598. 5
  115599. };
  115600. static static_codebook _44c3_s_p3_0 = {
  115601. 4, 625,
  115602. _vq_lengthlist__44c3_s_p3_0,
  115603. 1, -533725184, 1611661312, 3, 0,
  115604. _vq_quantlist__44c3_s_p3_0,
  115605. NULL,
  115606. &_vq_auxt__44c3_s_p3_0,
  115607. NULL,
  115608. 0
  115609. };
  115610. static long _vq_quantlist__44c3_s_p4_0[] = {
  115611. 4,
  115612. 3,
  115613. 5,
  115614. 2,
  115615. 6,
  115616. 1,
  115617. 7,
  115618. 0,
  115619. 8,
  115620. };
  115621. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115622. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115623. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115624. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115625. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115626. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115627. 0,
  115628. };
  115629. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115630. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115631. };
  115632. static long _vq_quantmap__44c3_s_p4_0[] = {
  115633. 7, 5, 3, 1, 0, 2, 4, 6,
  115634. 8,
  115635. };
  115636. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115637. _vq_quantthresh__44c3_s_p4_0,
  115638. _vq_quantmap__44c3_s_p4_0,
  115639. 9,
  115640. 9
  115641. };
  115642. static static_codebook _44c3_s_p4_0 = {
  115643. 2, 81,
  115644. _vq_lengthlist__44c3_s_p4_0,
  115645. 1, -531628032, 1611661312, 4, 0,
  115646. _vq_quantlist__44c3_s_p4_0,
  115647. NULL,
  115648. &_vq_auxt__44c3_s_p4_0,
  115649. NULL,
  115650. 0
  115651. };
  115652. static long _vq_quantlist__44c3_s_p5_0[] = {
  115653. 4,
  115654. 3,
  115655. 5,
  115656. 2,
  115657. 6,
  115658. 1,
  115659. 7,
  115660. 0,
  115661. 8,
  115662. };
  115663. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115664. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115665. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115666. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115667. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115668. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115669. 11,
  115670. };
  115671. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115672. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115673. };
  115674. static long _vq_quantmap__44c3_s_p5_0[] = {
  115675. 7, 5, 3, 1, 0, 2, 4, 6,
  115676. 8,
  115677. };
  115678. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115679. _vq_quantthresh__44c3_s_p5_0,
  115680. _vq_quantmap__44c3_s_p5_0,
  115681. 9,
  115682. 9
  115683. };
  115684. static static_codebook _44c3_s_p5_0 = {
  115685. 2, 81,
  115686. _vq_lengthlist__44c3_s_p5_0,
  115687. 1, -531628032, 1611661312, 4, 0,
  115688. _vq_quantlist__44c3_s_p5_0,
  115689. NULL,
  115690. &_vq_auxt__44c3_s_p5_0,
  115691. NULL,
  115692. 0
  115693. };
  115694. static long _vq_quantlist__44c3_s_p6_0[] = {
  115695. 8,
  115696. 7,
  115697. 9,
  115698. 6,
  115699. 10,
  115700. 5,
  115701. 11,
  115702. 4,
  115703. 12,
  115704. 3,
  115705. 13,
  115706. 2,
  115707. 14,
  115708. 1,
  115709. 15,
  115710. 0,
  115711. 16,
  115712. };
  115713. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115714. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115715. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115716. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115717. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115718. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115719. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115720. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115721. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115722. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115723. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115724. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115725. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115726. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115727. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115728. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115729. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115730. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115731. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115732. 13,
  115733. };
  115734. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115735. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115736. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115737. };
  115738. static long _vq_quantmap__44c3_s_p6_0[] = {
  115739. 15, 13, 11, 9, 7, 5, 3, 1,
  115740. 0, 2, 4, 6, 8, 10, 12, 14,
  115741. 16,
  115742. };
  115743. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115744. _vq_quantthresh__44c3_s_p6_0,
  115745. _vq_quantmap__44c3_s_p6_0,
  115746. 17,
  115747. 17
  115748. };
  115749. static static_codebook _44c3_s_p6_0 = {
  115750. 2, 289,
  115751. _vq_lengthlist__44c3_s_p6_0,
  115752. 1, -529530880, 1611661312, 5, 0,
  115753. _vq_quantlist__44c3_s_p6_0,
  115754. NULL,
  115755. &_vq_auxt__44c3_s_p6_0,
  115756. NULL,
  115757. 0
  115758. };
  115759. static long _vq_quantlist__44c3_s_p7_0[] = {
  115760. 1,
  115761. 0,
  115762. 2,
  115763. };
  115764. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115765. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115766. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115767. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115768. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115769. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115770. 10,
  115771. };
  115772. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115773. -5.5, 5.5,
  115774. };
  115775. static long _vq_quantmap__44c3_s_p7_0[] = {
  115776. 1, 0, 2,
  115777. };
  115778. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115779. _vq_quantthresh__44c3_s_p7_0,
  115780. _vq_quantmap__44c3_s_p7_0,
  115781. 3,
  115782. 3
  115783. };
  115784. static static_codebook _44c3_s_p7_0 = {
  115785. 4, 81,
  115786. _vq_lengthlist__44c3_s_p7_0,
  115787. 1, -529137664, 1618345984, 2, 0,
  115788. _vq_quantlist__44c3_s_p7_0,
  115789. NULL,
  115790. &_vq_auxt__44c3_s_p7_0,
  115791. NULL,
  115792. 0
  115793. };
  115794. static long _vq_quantlist__44c3_s_p7_1[] = {
  115795. 5,
  115796. 4,
  115797. 6,
  115798. 3,
  115799. 7,
  115800. 2,
  115801. 8,
  115802. 1,
  115803. 9,
  115804. 0,
  115805. 10,
  115806. };
  115807. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115808. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115809. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115810. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115811. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115812. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115813. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115814. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115815. 10,10,10, 8, 8, 8, 8, 8, 8,
  115816. };
  115817. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115818. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115819. 3.5, 4.5,
  115820. };
  115821. static long _vq_quantmap__44c3_s_p7_1[] = {
  115822. 9, 7, 5, 3, 1, 0, 2, 4,
  115823. 6, 8, 10,
  115824. };
  115825. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115826. _vq_quantthresh__44c3_s_p7_1,
  115827. _vq_quantmap__44c3_s_p7_1,
  115828. 11,
  115829. 11
  115830. };
  115831. static static_codebook _44c3_s_p7_1 = {
  115832. 2, 121,
  115833. _vq_lengthlist__44c3_s_p7_1,
  115834. 1, -531365888, 1611661312, 4, 0,
  115835. _vq_quantlist__44c3_s_p7_1,
  115836. NULL,
  115837. &_vq_auxt__44c3_s_p7_1,
  115838. NULL,
  115839. 0
  115840. };
  115841. static long _vq_quantlist__44c3_s_p8_0[] = {
  115842. 6,
  115843. 5,
  115844. 7,
  115845. 4,
  115846. 8,
  115847. 3,
  115848. 9,
  115849. 2,
  115850. 10,
  115851. 1,
  115852. 11,
  115853. 0,
  115854. 12,
  115855. };
  115856. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115857. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115858. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115859. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115860. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115861. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115862. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115863. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115864. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115865. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115866. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115867. 0,13,13,12,12,13,12,14,13,
  115868. };
  115869. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115870. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115871. 12.5, 17.5, 22.5, 27.5,
  115872. };
  115873. static long _vq_quantmap__44c3_s_p8_0[] = {
  115874. 11, 9, 7, 5, 3, 1, 0, 2,
  115875. 4, 6, 8, 10, 12,
  115876. };
  115877. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115878. _vq_quantthresh__44c3_s_p8_0,
  115879. _vq_quantmap__44c3_s_p8_0,
  115880. 13,
  115881. 13
  115882. };
  115883. static static_codebook _44c3_s_p8_0 = {
  115884. 2, 169,
  115885. _vq_lengthlist__44c3_s_p8_0,
  115886. 1, -526516224, 1616117760, 4, 0,
  115887. _vq_quantlist__44c3_s_p8_0,
  115888. NULL,
  115889. &_vq_auxt__44c3_s_p8_0,
  115890. NULL,
  115891. 0
  115892. };
  115893. static long _vq_quantlist__44c3_s_p8_1[] = {
  115894. 2,
  115895. 1,
  115896. 3,
  115897. 0,
  115898. 4,
  115899. };
  115900. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115901. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115902. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115903. };
  115904. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115905. -1.5, -0.5, 0.5, 1.5,
  115906. };
  115907. static long _vq_quantmap__44c3_s_p8_1[] = {
  115908. 3, 1, 0, 2, 4,
  115909. };
  115910. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115911. _vq_quantthresh__44c3_s_p8_1,
  115912. _vq_quantmap__44c3_s_p8_1,
  115913. 5,
  115914. 5
  115915. };
  115916. static static_codebook _44c3_s_p8_1 = {
  115917. 2, 25,
  115918. _vq_lengthlist__44c3_s_p8_1,
  115919. 1, -533725184, 1611661312, 3, 0,
  115920. _vq_quantlist__44c3_s_p8_1,
  115921. NULL,
  115922. &_vq_auxt__44c3_s_p8_1,
  115923. NULL,
  115924. 0
  115925. };
  115926. static long _vq_quantlist__44c3_s_p9_0[] = {
  115927. 6,
  115928. 5,
  115929. 7,
  115930. 4,
  115931. 8,
  115932. 3,
  115933. 9,
  115934. 2,
  115935. 10,
  115936. 1,
  115937. 11,
  115938. 0,
  115939. 12,
  115940. };
  115941. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115942. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115943. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115944. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115945. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115946. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115947. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115948. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115949. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115950. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115951. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115952. 11,11,11,11,11,11,11,11,11,
  115953. };
  115954. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115955. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115956. 637.5, 892.5, 1147.5, 1402.5,
  115957. };
  115958. static long _vq_quantmap__44c3_s_p9_0[] = {
  115959. 11, 9, 7, 5, 3, 1, 0, 2,
  115960. 4, 6, 8, 10, 12,
  115961. };
  115962. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115963. _vq_quantthresh__44c3_s_p9_0,
  115964. _vq_quantmap__44c3_s_p9_0,
  115965. 13,
  115966. 13
  115967. };
  115968. static static_codebook _44c3_s_p9_0 = {
  115969. 2, 169,
  115970. _vq_lengthlist__44c3_s_p9_0,
  115971. 1, -514332672, 1627381760, 4, 0,
  115972. _vq_quantlist__44c3_s_p9_0,
  115973. NULL,
  115974. &_vq_auxt__44c3_s_p9_0,
  115975. NULL,
  115976. 0
  115977. };
  115978. static long _vq_quantlist__44c3_s_p9_1[] = {
  115979. 7,
  115980. 6,
  115981. 8,
  115982. 5,
  115983. 9,
  115984. 4,
  115985. 10,
  115986. 3,
  115987. 11,
  115988. 2,
  115989. 12,
  115990. 1,
  115991. 13,
  115992. 0,
  115993. 14,
  115994. };
  115995. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115996. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115997. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115998. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115999. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  116000. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  116001. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  116002. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  116003. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  116004. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  116005. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  116006. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  116007. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  116008. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  116009. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  116010. 15,
  116011. };
  116012. static float _vq_quantthresh__44c3_s_p9_1[] = {
  116013. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  116014. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  116015. };
  116016. static long _vq_quantmap__44c3_s_p9_1[] = {
  116017. 13, 11, 9, 7, 5, 3, 1, 0,
  116018. 2, 4, 6, 8, 10, 12, 14,
  116019. };
  116020. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  116021. _vq_quantthresh__44c3_s_p9_1,
  116022. _vq_quantmap__44c3_s_p9_1,
  116023. 15,
  116024. 15
  116025. };
  116026. static static_codebook _44c3_s_p9_1 = {
  116027. 2, 225,
  116028. _vq_lengthlist__44c3_s_p9_1,
  116029. 1, -522338304, 1620115456, 4, 0,
  116030. _vq_quantlist__44c3_s_p9_1,
  116031. NULL,
  116032. &_vq_auxt__44c3_s_p9_1,
  116033. NULL,
  116034. 0
  116035. };
  116036. static long _vq_quantlist__44c3_s_p9_2[] = {
  116037. 8,
  116038. 7,
  116039. 9,
  116040. 6,
  116041. 10,
  116042. 5,
  116043. 11,
  116044. 4,
  116045. 12,
  116046. 3,
  116047. 13,
  116048. 2,
  116049. 14,
  116050. 1,
  116051. 15,
  116052. 0,
  116053. 16,
  116054. };
  116055. static long _vq_lengthlist__44c3_s_p9_2[] = {
  116056. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  116057. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  116058. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  116059. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  116060. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  116061. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  116062. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  116063. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  116064. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  116065. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  116066. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  116067. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  116068. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  116069. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  116070. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  116071. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  116072. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  116073. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  116074. 10,
  116075. };
  116076. static float _vq_quantthresh__44c3_s_p9_2[] = {
  116077. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116078. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116079. };
  116080. static long _vq_quantmap__44c3_s_p9_2[] = {
  116081. 15, 13, 11, 9, 7, 5, 3, 1,
  116082. 0, 2, 4, 6, 8, 10, 12, 14,
  116083. 16,
  116084. };
  116085. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  116086. _vq_quantthresh__44c3_s_p9_2,
  116087. _vq_quantmap__44c3_s_p9_2,
  116088. 17,
  116089. 17
  116090. };
  116091. static static_codebook _44c3_s_p9_2 = {
  116092. 2, 289,
  116093. _vq_lengthlist__44c3_s_p9_2,
  116094. 1, -529530880, 1611661312, 5, 0,
  116095. _vq_quantlist__44c3_s_p9_2,
  116096. NULL,
  116097. &_vq_auxt__44c3_s_p9_2,
  116098. NULL,
  116099. 0
  116100. };
  116101. static long _huff_lengthlist__44c3_s_short[] = {
  116102. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116103. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116104. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116105. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116106. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116107. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116108. 6, 8, 9,11,
  116109. };
  116110. static static_codebook _huff_book__44c3_s_short = {
  116111. 2, 100,
  116112. _huff_lengthlist__44c3_s_short,
  116113. 0, 0, 0, 0, 0,
  116114. NULL,
  116115. NULL,
  116116. NULL,
  116117. NULL,
  116118. 0
  116119. };
  116120. static long _huff_lengthlist__44c4_s_long[] = {
  116121. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116122. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116123. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116124. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116125. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116126. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116127. 9, 8, 7, 7,
  116128. };
  116129. static static_codebook _huff_book__44c4_s_long = {
  116130. 2, 100,
  116131. _huff_lengthlist__44c4_s_long,
  116132. 0, 0, 0, 0, 0,
  116133. NULL,
  116134. NULL,
  116135. NULL,
  116136. NULL,
  116137. 0
  116138. };
  116139. static long _vq_quantlist__44c4_s_p1_0[] = {
  116140. 1,
  116141. 0,
  116142. 2,
  116143. };
  116144. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116145. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116146. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116151. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116156. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  116191. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116196. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  116201. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116236. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116237. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116242. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  116243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116246. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116247. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116555. 0,
  116556. };
  116557. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116558. -0.5, 0.5,
  116559. };
  116560. static long _vq_quantmap__44c4_s_p1_0[] = {
  116561. 1, 0, 2,
  116562. };
  116563. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116564. _vq_quantthresh__44c4_s_p1_0,
  116565. _vq_quantmap__44c4_s_p1_0,
  116566. 3,
  116567. 3
  116568. };
  116569. static static_codebook _44c4_s_p1_0 = {
  116570. 8, 6561,
  116571. _vq_lengthlist__44c4_s_p1_0,
  116572. 1, -535822336, 1611661312, 2, 0,
  116573. _vq_quantlist__44c4_s_p1_0,
  116574. NULL,
  116575. &_vq_auxt__44c4_s_p1_0,
  116576. NULL,
  116577. 0
  116578. };
  116579. static long _vq_quantlist__44c4_s_p2_0[] = {
  116580. 2,
  116581. 1,
  116582. 3,
  116583. 0,
  116584. 4,
  116585. };
  116586. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116587. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116588. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116589. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116590. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116591. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116596. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116597. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116598. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116599. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116604. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116605. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116606. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116612. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116613. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116614. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116626. 0,
  116627. };
  116628. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116629. -1.5, -0.5, 0.5, 1.5,
  116630. };
  116631. static long _vq_quantmap__44c4_s_p2_0[] = {
  116632. 3, 1, 0, 2, 4,
  116633. };
  116634. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116635. _vq_quantthresh__44c4_s_p2_0,
  116636. _vq_quantmap__44c4_s_p2_0,
  116637. 5,
  116638. 5
  116639. };
  116640. static static_codebook _44c4_s_p2_0 = {
  116641. 4, 625,
  116642. _vq_lengthlist__44c4_s_p2_0,
  116643. 1, -533725184, 1611661312, 3, 0,
  116644. _vq_quantlist__44c4_s_p2_0,
  116645. NULL,
  116646. &_vq_auxt__44c4_s_p2_0,
  116647. NULL,
  116648. 0
  116649. };
  116650. static long _vq_quantlist__44c4_s_p3_0[] = {
  116651. 2,
  116652. 1,
  116653. 3,
  116654. 0,
  116655. 4,
  116656. };
  116657. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116658. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116661. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116664. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116697. 0,
  116698. };
  116699. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116700. -1.5, -0.5, 0.5, 1.5,
  116701. };
  116702. static long _vq_quantmap__44c4_s_p3_0[] = {
  116703. 3, 1, 0, 2, 4,
  116704. };
  116705. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116706. _vq_quantthresh__44c4_s_p3_0,
  116707. _vq_quantmap__44c4_s_p3_0,
  116708. 5,
  116709. 5
  116710. };
  116711. static static_codebook _44c4_s_p3_0 = {
  116712. 4, 625,
  116713. _vq_lengthlist__44c4_s_p3_0,
  116714. 1, -533725184, 1611661312, 3, 0,
  116715. _vq_quantlist__44c4_s_p3_0,
  116716. NULL,
  116717. &_vq_auxt__44c4_s_p3_0,
  116718. NULL,
  116719. 0
  116720. };
  116721. static long _vq_quantlist__44c4_s_p4_0[] = {
  116722. 4,
  116723. 3,
  116724. 5,
  116725. 2,
  116726. 6,
  116727. 1,
  116728. 7,
  116729. 0,
  116730. 8,
  116731. };
  116732. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116733. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116734. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116735. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116736. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116737. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116738. 0,
  116739. };
  116740. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116741. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116742. };
  116743. static long _vq_quantmap__44c4_s_p4_0[] = {
  116744. 7, 5, 3, 1, 0, 2, 4, 6,
  116745. 8,
  116746. };
  116747. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116748. _vq_quantthresh__44c4_s_p4_0,
  116749. _vq_quantmap__44c4_s_p4_0,
  116750. 9,
  116751. 9
  116752. };
  116753. static static_codebook _44c4_s_p4_0 = {
  116754. 2, 81,
  116755. _vq_lengthlist__44c4_s_p4_0,
  116756. 1, -531628032, 1611661312, 4, 0,
  116757. _vq_quantlist__44c4_s_p4_0,
  116758. NULL,
  116759. &_vq_auxt__44c4_s_p4_0,
  116760. NULL,
  116761. 0
  116762. };
  116763. static long _vq_quantlist__44c4_s_p5_0[] = {
  116764. 4,
  116765. 3,
  116766. 5,
  116767. 2,
  116768. 6,
  116769. 1,
  116770. 7,
  116771. 0,
  116772. 8,
  116773. };
  116774. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116775. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116776. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116777. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116778. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116779. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116780. 10,
  116781. };
  116782. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116783. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116784. };
  116785. static long _vq_quantmap__44c4_s_p5_0[] = {
  116786. 7, 5, 3, 1, 0, 2, 4, 6,
  116787. 8,
  116788. };
  116789. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116790. _vq_quantthresh__44c4_s_p5_0,
  116791. _vq_quantmap__44c4_s_p5_0,
  116792. 9,
  116793. 9
  116794. };
  116795. static static_codebook _44c4_s_p5_0 = {
  116796. 2, 81,
  116797. _vq_lengthlist__44c4_s_p5_0,
  116798. 1, -531628032, 1611661312, 4, 0,
  116799. _vq_quantlist__44c4_s_p5_0,
  116800. NULL,
  116801. &_vq_auxt__44c4_s_p5_0,
  116802. NULL,
  116803. 0
  116804. };
  116805. static long _vq_quantlist__44c4_s_p6_0[] = {
  116806. 8,
  116807. 7,
  116808. 9,
  116809. 6,
  116810. 10,
  116811. 5,
  116812. 11,
  116813. 4,
  116814. 12,
  116815. 3,
  116816. 13,
  116817. 2,
  116818. 14,
  116819. 1,
  116820. 15,
  116821. 0,
  116822. 16,
  116823. };
  116824. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116825. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116826. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116827. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116828. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116829. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116830. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116831. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116832. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116833. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116834. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116835. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116836. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116837. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116838. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116839. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116840. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116841. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116842. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116843. 13,
  116844. };
  116845. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116846. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116847. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116848. };
  116849. static long _vq_quantmap__44c4_s_p6_0[] = {
  116850. 15, 13, 11, 9, 7, 5, 3, 1,
  116851. 0, 2, 4, 6, 8, 10, 12, 14,
  116852. 16,
  116853. };
  116854. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116855. _vq_quantthresh__44c4_s_p6_0,
  116856. _vq_quantmap__44c4_s_p6_0,
  116857. 17,
  116858. 17
  116859. };
  116860. static static_codebook _44c4_s_p6_0 = {
  116861. 2, 289,
  116862. _vq_lengthlist__44c4_s_p6_0,
  116863. 1, -529530880, 1611661312, 5, 0,
  116864. _vq_quantlist__44c4_s_p6_0,
  116865. NULL,
  116866. &_vq_auxt__44c4_s_p6_0,
  116867. NULL,
  116868. 0
  116869. };
  116870. static long _vq_quantlist__44c4_s_p7_0[] = {
  116871. 1,
  116872. 0,
  116873. 2,
  116874. };
  116875. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116876. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116877. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116878. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116879. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116880. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116881. 10,
  116882. };
  116883. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116884. -5.5, 5.5,
  116885. };
  116886. static long _vq_quantmap__44c4_s_p7_0[] = {
  116887. 1, 0, 2,
  116888. };
  116889. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116890. _vq_quantthresh__44c4_s_p7_0,
  116891. _vq_quantmap__44c4_s_p7_0,
  116892. 3,
  116893. 3
  116894. };
  116895. static static_codebook _44c4_s_p7_0 = {
  116896. 4, 81,
  116897. _vq_lengthlist__44c4_s_p7_0,
  116898. 1, -529137664, 1618345984, 2, 0,
  116899. _vq_quantlist__44c4_s_p7_0,
  116900. NULL,
  116901. &_vq_auxt__44c4_s_p7_0,
  116902. NULL,
  116903. 0
  116904. };
  116905. static long _vq_quantlist__44c4_s_p7_1[] = {
  116906. 5,
  116907. 4,
  116908. 6,
  116909. 3,
  116910. 7,
  116911. 2,
  116912. 8,
  116913. 1,
  116914. 9,
  116915. 0,
  116916. 10,
  116917. };
  116918. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116919. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116920. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116921. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116922. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116923. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116924. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116925. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116926. 10,10,10, 8, 8, 8, 8, 9, 9,
  116927. };
  116928. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116929. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116930. 3.5, 4.5,
  116931. };
  116932. static long _vq_quantmap__44c4_s_p7_1[] = {
  116933. 9, 7, 5, 3, 1, 0, 2, 4,
  116934. 6, 8, 10,
  116935. };
  116936. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116937. _vq_quantthresh__44c4_s_p7_1,
  116938. _vq_quantmap__44c4_s_p7_1,
  116939. 11,
  116940. 11
  116941. };
  116942. static static_codebook _44c4_s_p7_1 = {
  116943. 2, 121,
  116944. _vq_lengthlist__44c4_s_p7_1,
  116945. 1, -531365888, 1611661312, 4, 0,
  116946. _vq_quantlist__44c4_s_p7_1,
  116947. NULL,
  116948. &_vq_auxt__44c4_s_p7_1,
  116949. NULL,
  116950. 0
  116951. };
  116952. static long _vq_quantlist__44c4_s_p8_0[] = {
  116953. 6,
  116954. 5,
  116955. 7,
  116956. 4,
  116957. 8,
  116958. 3,
  116959. 9,
  116960. 2,
  116961. 10,
  116962. 1,
  116963. 11,
  116964. 0,
  116965. 12,
  116966. };
  116967. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116968. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116969. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116970. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116971. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116972. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116973. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116974. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116975. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116976. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116977. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116978. 0,13,12,12,12,12,12,13,13,
  116979. };
  116980. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116981. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116982. 12.5, 17.5, 22.5, 27.5,
  116983. };
  116984. static long _vq_quantmap__44c4_s_p8_0[] = {
  116985. 11, 9, 7, 5, 3, 1, 0, 2,
  116986. 4, 6, 8, 10, 12,
  116987. };
  116988. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116989. _vq_quantthresh__44c4_s_p8_0,
  116990. _vq_quantmap__44c4_s_p8_0,
  116991. 13,
  116992. 13
  116993. };
  116994. static static_codebook _44c4_s_p8_0 = {
  116995. 2, 169,
  116996. _vq_lengthlist__44c4_s_p8_0,
  116997. 1, -526516224, 1616117760, 4, 0,
  116998. _vq_quantlist__44c4_s_p8_0,
  116999. NULL,
  117000. &_vq_auxt__44c4_s_p8_0,
  117001. NULL,
  117002. 0
  117003. };
  117004. static long _vq_quantlist__44c4_s_p8_1[] = {
  117005. 2,
  117006. 1,
  117007. 3,
  117008. 0,
  117009. 4,
  117010. };
  117011. static long _vq_lengthlist__44c4_s_p8_1[] = {
  117012. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  117013. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117014. };
  117015. static float _vq_quantthresh__44c4_s_p8_1[] = {
  117016. -1.5, -0.5, 0.5, 1.5,
  117017. };
  117018. static long _vq_quantmap__44c4_s_p8_1[] = {
  117019. 3, 1, 0, 2, 4,
  117020. };
  117021. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  117022. _vq_quantthresh__44c4_s_p8_1,
  117023. _vq_quantmap__44c4_s_p8_1,
  117024. 5,
  117025. 5
  117026. };
  117027. static static_codebook _44c4_s_p8_1 = {
  117028. 2, 25,
  117029. _vq_lengthlist__44c4_s_p8_1,
  117030. 1, -533725184, 1611661312, 3, 0,
  117031. _vq_quantlist__44c4_s_p8_1,
  117032. NULL,
  117033. &_vq_auxt__44c4_s_p8_1,
  117034. NULL,
  117035. 0
  117036. };
  117037. static long _vq_quantlist__44c4_s_p9_0[] = {
  117038. 6,
  117039. 5,
  117040. 7,
  117041. 4,
  117042. 8,
  117043. 3,
  117044. 9,
  117045. 2,
  117046. 10,
  117047. 1,
  117048. 11,
  117049. 0,
  117050. 12,
  117051. };
  117052. static long _vq_lengthlist__44c4_s_p9_0[] = {
  117053. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  117054. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  117055. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117056. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117057. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117058. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117059. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117060. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117061. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117062. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117063. 12,12,12,12,12,12,12,12,12,
  117064. };
  117065. static float _vq_quantthresh__44c4_s_p9_0[] = {
  117066. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  117067. 787.5, 1102.5, 1417.5, 1732.5,
  117068. };
  117069. static long _vq_quantmap__44c4_s_p9_0[] = {
  117070. 11, 9, 7, 5, 3, 1, 0, 2,
  117071. 4, 6, 8, 10, 12,
  117072. };
  117073. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  117074. _vq_quantthresh__44c4_s_p9_0,
  117075. _vq_quantmap__44c4_s_p9_0,
  117076. 13,
  117077. 13
  117078. };
  117079. static static_codebook _44c4_s_p9_0 = {
  117080. 2, 169,
  117081. _vq_lengthlist__44c4_s_p9_0,
  117082. 1, -513964032, 1628680192, 4, 0,
  117083. _vq_quantlist__44c4_s_p9_0,
  117084. NULL,
  117085. &_vq_auxt__44c4_s_p9_0,
  117086. NULL,
  117087. 0
  117088. };
  117089. static long _vq_quantlist__44c4_s_p9_1[] = {
  117090. 7,
  117091. 6,
  117092. 8,
  117093. 5,
  117094. 9,
  117095. 4,
  117096. 10,
  117097. 3,
  117098. 11,
  117099. 2,
  117100. 12,
  117101. 1,
  117102. 13,
  117103. 0,
  117104. 14,
  117105. };
  117106. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117107. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117108. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117109. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117110. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117111. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117112. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117113. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117114. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117115. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117116. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117117. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117118. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117119. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117120. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117121. 15,
  117122. };
  117123. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117124. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117125. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117126. };
  117127. static long _vq_quantmap__44c4_s_p9_1[] = {
  117128. 13, 11, 9, 7, 5, 3, 1, 0,
  117129. 2, 4, 6, 8, 10, 12, 14,
  117130. };
  117131. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117132. _vq_quantthresh__44c4_s_p9_1,
  117133. _vq_quantmap__44c4_s_p9_1,
  117134. 15,
  117135. 15
  117136. };
  117137. static static_codebook _44c4_s_p9_1 = {
  117138. 2, 225,
  117139. _vq_lengthlist__44c4_s_p9_1,
  117140. 1, -520986624, 1620377600, 4, 0,
  117141. _vq_quantlist__44c4_s_p9_1,
  117142. NULL,
  117143. &_vq_auxt__44c4_s_p9_1,
  117144. NULL,
  117145. 0
  117146. };
  117147. static long _vq_quantlist__44c4_s_p9_2[] = {
  117148. 10,
  117149. 9,
  117150. 11,
  117151. 8,
  117152. 12,
  117153. 7,
  117154. 13,
  117155. 6,
  117156. 14,
  117157. 5,
  117158. 15,
  117159. 4,
  117160. 16,
  117161. 3,
  117162. 17,
  117163. 2,
  117164. 18,
  117165. 1,
  117166. 19,
  117167. 0,
  117168. 20,
  117169. };
  117170. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117171. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117172. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117173. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117174. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117175. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117176. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117177. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117178. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117179. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117180. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117181. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117182. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117183. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117184. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117185. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117186. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117187. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117188. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117189. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117190. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117191. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117192. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117193. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117194. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117195. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117196. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117197. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117198. 10,10,10,10,10,10,10,10,10,
  117199. };
  117200. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117201. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117202. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117203. 6.5, 7.5, 8.5, 9.5,
  117204. };
  117205. static long _vq_quantmap__44c4_s_p9_2[] = {
  117206. 19, 17, 15, 13, 11, 9, 7, 5,
  117207. 3, 1, 0, 2, 4, 6, 8, 10,
  117208. 12, 14, 16, 18, 20,
  117209. };
  117210. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117211. _vq_quantthresh__44c4_s_p9_2,
  117212. _vq_quantmap__44c4_s_p9_2,
  117213. 21,
  117214. 21
  117215. };
  117216. static static_codebook _44c4_s_p9_2 = {
  117217. 2, 441,
  117218. _vq_lengthlist__44c4_s_p9_2,
  117219. 1, -529268736, 1611661312, 5, 0,
  117220. _vq_quantlist__44c4_s_p9_2,
  117221. NULL,
  117222. &_vq_auxt__44c4_s_p9_2,
  117223. NULL,
  117224. 0
  117225. };
  117226. static long _huff_lengthlist__44c4_s_short[] = {
  117227. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117228. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117229. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117230. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117231. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117232. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117233. 7, 9,12,17,
  117234. };
  117235. static static_codebook _huff_book__44c4_s_short = {
  117236. 2, 100,
  117237. _huff_lengthlist__44c4_s_short,
  117238. 0, 0, 0, 0, 0,
  117239. NULL,
  117240. NULL,
  117241. NULL,
  117242. NULL,
  117243. 0
  117244. };
  117245. static long _huff_lengthlist__44c5_s_long[] = {
  117246. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117247. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117248. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117249. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117250. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117251. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117252. 9, 8, 7, 7,
  117253. };
  117254. static static_codebook _huff_book__44c5_s_long = {
  117255. 2, 100,
  117256. _huff_lengthlist__44c5_s_long,
  117257. 0, 0, 0, 0, 0,
  117258. NULL,
  117259. NULL,
  117260. NULL,
  117261. NULL,
  117262. 0
  117263. };
  117264. static long _vq_quantlist__44c5_s_p1_0[] = {
  117265. 1,
  117266. 0,
  117267. 2,
  117268. };
  117269. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117270. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117271. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117276. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117281. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117316. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117321. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  117322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117326. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  117327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117361. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117362. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117367. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  117368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117371. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117372. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  117373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117680. 0,
  117681. };
  117682. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117683. -0.5, 0.5,
  117684. };
  117685. static long _vq_quantmap__44c5_s_p1_0[] = {
  117686. 1, 0, 2,
  117687. };
  117688. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117689. _vq_quantthresh__44c5_s_p1_0,
  117690. _vq_quantmap__44c5_s_p1_0,
  117691. 3,
  117692. 3
  117693. };
  117694. static static_codebook _44c5_s_p1_0 = {
  117695. 8, 6561,
  117696. _vq_lengthlist__44c5_s_p1_0,
  117697. 1, -535822336, 1611661312, 2, 0,
  117698. _vq_quantlist__44c5_s_p1_0,
  117699. NULL,
  117700. &_vq_auxt__44c5_s_p1_0,
  117701. NULL,
  117702. 0
  117703. };
  117704. static long _vq_quantlist__44c5_s_p2_0[] = {
  117705. 2,
  117706. 1,
  117707. 3,
  117708. 0,
  117709. 4,
  117710. };
  117711. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117712. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117713. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117714. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117715. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117716. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117721. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117722. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117723. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117724. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117729. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117730. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117731. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117737. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117738. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117739. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117751. 0,
  117752. };
  117753. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117754. -1.5, -0.5, 0.5, 1.5,
  117755. };
  117756. static long _vq_quantmap__44c5_s_p2_0[] = {
  117757. 3, 1, 0, 2, 4,
  117758. };
  117759. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117760. _vq_quantthresh__44c5_s_p2_0,
  117761. _vq_quantmap__44c5_s_p2_0,
  117762. 5,
  117763. 5
  117764. };
  117765. static static_codebook _44c5_s_p2_0 = {
  117766. 4, 625,
  117767. _vq_lengthlist__44c5_s_p2_0,
  117768. 1, -533725184, 1611661312, 3, 0,
  117769. _vq_quantlist__44c5_s_p2_0,
  117770. NULL,
  117771. &_vq_auxt__44c5_s_p2_0,
  117772. NULL,
  117773. 0
  117774. };
  117775. static long _vq_quantlist__44c5_s_p3_0[] = {
  117776. 2,
  117777. 1,
  117778. 3,
  117779. 0,
  117780. 4,
  117781. };
  117782. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117783. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117786. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117789. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117822. 0,
  117823. };
  117824. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117825. -1.5, -0.5, 0.5, 1.5,
  117826. };
  117827. static long _vq_quantmap__44c5_s_p3_0[] = {
  117828. 3, 1, 0, 2, 4,
  117829. };
  117830. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117831. _vq_quantthresh__44c5_s_p3_0,
  117832. _vq_quantmap__44c5_s_p3_0,
  117833. 5,
  117834. 5
  117835. };
  117836. static static_codebook _44c5_s_p3_0 = {
  117837. 4, 625,
  117838. _vq_lengthlist__44c5_s_p3_0,
  117839. 1, -533725184, 1611661312, 3, 0,
  117840. _vq_quantlist__44c5_s_p3_0,
  117841. NULL,
  117842. &_vq_auxt__44c5_s_p3_0,
  117843. NULL,
  117844. 0
  117845. };
  117846. static long _vq_quantlist__44c5_s_p4_0[] = {
  117847. 4,
  117848. 3,
  117849. 5,
  117850. 2,
  117851. 6,
  117852. 1,
  117853. 7,
  117854. 0,
  117855. 8,
  117856. };
  117857. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117858. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117859. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117860. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117861. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117862. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117863. 0,
  117864. };
  117865. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117866. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117867. };
  117868. static long _vq_quantmap__44c5_s_p4_0[] = {
  117869. 7, 5, 3, 1, 0, 2, 4, 6,
  117870. 8,
  117871. };
  117872. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117873. _vq_quantthresh__44c5_s_p4_0,
  117874. _vq_quantmap__44c5_s_p4_0,
  117875. 9,
  117876. 9
  117877. };
  117878. static static_codebook _44c5_s_p4_0 = {
  117879. 2, 81,
  117880. _vq_lengthlist__44c5_s_p4_0,
  117881. 1, -531628032, 1611661312, 4, 0,
  117882. _vq_quantlist__44c5_s_p4_0,
  117883. NULL,
  117884. &_vq_auxt__44c5_s_p4_0,
  117885. NULL,
  117886. 0
  117887. };
  117888. static long _vq_quantlist__44c5_s_p5_0[] = {
  117889. 4,
  117890. 3,
  117891. 5,
  117892. 2,
  117893. 6,
  117894. 1,
  117895. 7,
  117896. 0,
  117897. 8,
  117898. };
  117899. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117900. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117901. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117902. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117903. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117904. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117905. 10,
  117906. };
  117907. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117908. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117909. };
  117910. static long _vq_quantmap__44c5_s_p5_0[] = {
  117911. 7, 5, 3, 1, 0, 2, 4, 6,
  117912. 8,
  117913. };
  117914. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117915. _vq_quantthresh__44c5_s_p5_0,
  117916. _vq_quantmap__44c5_s_p5_0,
  117917. 9,
  117918. 9
  117919. };
  117920. static static_codebook _44c5_s_p5_0 = {
  117921. 2, 81,
  117922. _vq_lengthlist__44c5_s_p5_0,
  117923. 1, -531628032, 1611661312, 4, 0,
  117924. _vq_quantlist__44c5_s_p5_0,
  117925. NULL,
  117926. &_vq_auxt__44c5_s_p5_0,
  117927. NULL,
  117928. 0
  117929. };
  117930. static long _vq_quantlist__44c5_s_p6_0[] = {
  117931. 8,
  117932. 7,
  117933. 9,
  117934. 6,
  117935. 10,
  117936. 5,
  117937. 11,
  117938. 4,
  117939. 12,
  117940. 3,
  117941. 13,
  117942. 2,
  117943. 14,
  117944. 1,
  117945. 15,
  117946. 0,
  117947. 16,
  117948. };
  117949. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117950. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117951. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117952. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117953. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117954. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117955. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117956. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117957. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117958. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117959. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117960. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117961. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117962. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117963. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117964. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117965. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117966. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117967. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117968. 13,
  117969. };
  117970. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117971. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117972. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117973. };
  117974. static long _vq_quantmap__44c5_s_p6_0[] = {
  117975. 15, 13, 11, 9, 7, 5, 3, 1,
  117976. 0, 2, 4, 6, 8, 10, 12, 14,
  117977. 16,
  117978. };
  117979. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117980. _vq_quantthresh__44c5_s_p6_0,
  117981. _vq_quantmap__44c5_s_p6_0,
  117982. 17,
  117983. 17
  117984. };
  117985. static static_codebook _44c5_s_p6_0 = {
  117986. 2, 289,
  117987. _vq_lengthlist__44c5_s_p6_0,
  117988. 1, -529530880, 1611661312, 5, 0,
  117989. _vq_quantlist__44c5_s_p6_0,
  117990. NULL,
  117991. &_vq_auxt__44c5_s_p6_0,
  117992. NULL,
  117993. 0
  117994. };
  117995. static long _vq_quantlist__44c5_s_p7_0[] = {
  117996. 1,
  117997. 0,
  117998. 2,
  117999. };
  118000. static long _vq_lengthlist__44c5_s_p7_0[] = {
  118001. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  118002. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  118003. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  118004. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  118005. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  118006. 10,
  118007. };
  118008. static float _vq_quantthresh__44c5_s_p7_0[] = {
  118009. -5.5, 5.5,
  118010. };
  118011. static long _vq_quantmap__44c5_s_p7_0[] = {
  118012. 1, 0, 2,
  118013. };
  118014. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  118015. _vq_quantthresh__44c5_s_p7_0,
  118016. _vq_quantmap__44c5_s_p7_0,
  118017. 3,
  118018. 3
  118019. };
  118020. static static_codebook _44c5_s_p7_0 = {
  118021. 4, 81,
  118022. _vq_lengthlist__44c5_s_p7_0,
  118023. 1, -529137664, 1618345984, 2, 0,
  118024. _vq_quantlist__44c5_s_p7_0,
  118025. NULL,
  118026. &_vq_auxt__44c5_s_p7_0,
  118027. NULL,
  118028. 0
  118029. };
  118030. static long _vq_quantlist__44c5_s_p7_1[] = {
  118031. 5,
  118032. 4,
  118033. 6,
  118034. 3,
  118035. 7,
  118036. 2,
  118037. 8,
  118038. 1,
  118039. 9,
  118040. 0,
  118041. 10,
  118042. };
  118043. static long _vq_lengthlist__44c5_s_p7_1[] = {
  118044. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  118045. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  118046. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  118047. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  118048. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  118049. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  118050. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  118051. 10,10,10, 8, 8, 8, 8, 8, 8,
  118052. };
  118053. static float _vq_quantthresh__44c5_s_p7_1[] = {
  118054. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118055. 3.5, 4.5,
  118056. };
  118057. static long _vq_quantmap__44c5_s_p7_1[] = {
  118058. 9, 7, 5, 3, 1, 0, 2, 4,
  118059. 6, 8, 10,
  118060. };
  118061. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  118062. _vq_quantthresh__44c5_s_p7_1,
  118063. _vq_quantmap__44c5_s_p7_1,
  118064. 11,
  118065. 11
  118066. };
  118067. static static_codebook _44c5_s_p7_1 = {
  118068. 2, 121,
  118069. _vq_lengthlist__44c5_s_p7_1,
  118070. 1, -531365888, 1611661312, 4, 0,
  118071. _vq_quantlist__44c5_s_p7_1,
  118072. NULL,
  118073. &_vq_auxt__44c5_s_p7_1,
  118074. NULL,
  118075. 0
  118076. };
  118077. static long _vq_quantlist__44c5_s_p8_0[] = {
  118078. 6,
  118079. 5,
  118080. 7,
  118081. 4,
  118082. 8,
  118083. 3,
  118084. 9,
  118085. 2,
  118086. 10,
  118087. 1,
  118088. 11,
  118089. 0,
  118090. 12,
  118091. };
  118092. static long _vq_lengthlist__44c5_s_p8_0[] = {
  118093. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  118094. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  118095. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  118096. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118097. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118098. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118099. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118100. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118101. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118102. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118103. 0,12,12,12,12,12,12,13,13,
  118104. };
  118105. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118106. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118107. 12.5, 17.5, 22.5, 27.5,
  118108. };
  118109. static long _vq_quantmap__44c5_s_p8_0[] = {
  118110. 11, 9, 7, 5, 3, 1, 0, 2,
  118111. 4, 6, 8, 10, 12,
  118112. };
  118113. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118114. _vq_quantthresh__44c5_s_p8_0,
  118115. _vq_quantmap__44c5_s_p8_0,
  118116. 13,
  118117. 13
  118118. };
  118119. static static_codebook _44c5_s_p8_0 = {
  118120. 2, 169,
  118121. _vq_lengthlist__44c5_s_p8_0,
  118122. 1, -526516224, 1616117760, 4, 0,
  118123. _vq_quantlist__44c5_s_p8_0,
  118124. NULL,
  118125. &_vq_auxt__44c5_s_p8_0,
  118126. NULL,
  118127. 0
  118128. };
  118129. static long _vq_quantlist__44c5_s_p8_1[] = {
  118130. 2,
  118131. 1,
  118132. 3,
  118133. 0,
  118134. 4,
  118135. };
  118136. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118137. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118138. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118139. };
  118140. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118141. -1.5, -0.5, 0.5, 1.5,
  118142. };
  118143. static long _vq_quantmap__44c5_s_p8_1[] = {
  118144. 3, 1, 0, 2, 4,
  118145. };
  118146. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118147. _vq_quantthresh__44c5_s_p8_1,
  118148. _vq_quantmap__44c5_s_p8_1,
  118149. 5,
  118150. 5
  118151. };
  118152. static static_codebook _44c5_s_p8_1 = {
  118153. 2, 25,
  118154. _vq_lengthlist__44c5_s_p8_1,
  118155. 1, -533725184, 1611661312, 3, 0,
  118156. _vq_quantlist__44c5_s_p8_1,
  118157. NULL,
  118158. &_vq_auxt__44c5_s_p8_1,
  118159. NULL,
  118160. 0
  118161. };
  118162. static long _vq_quantlist__44c5_s_p9_0[] = {
  118163. 7,
  118164. 6,
  118165. 8,
  118166. 5,
  118167. 9,
  118168. 4,
  118169. 10,
  118170. 3,
  118171. 11,
  118172. 2,
  118173. 12,
  118174. 1,
  118175. 13,
  118176. 0,
  118177. 14,
  118178. };
  118179. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118180. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118181. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118182. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118183. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118184. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118185. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118186. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118187. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118188. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118189. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118190. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118191. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118192. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118193. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  118194. 12,
  118195. };
  118196. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118197. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118198. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118199. };
  118200. static long _vq_quantmap__44c5_s_p9_0[] = {
  118201. 13, 11, 9, 7, 5, 3, 1, 0,
  118202. 2, 4, 6, 8, 10, 12, 14,
  118203. };
  118204. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118205. _vq_quantthresh__44c5_s_p9_0,
  118206. _vq_quantmap__44c5_s_p9_0,
  118207. 15,
  118208. 15
  118209. };
  118210. static static_codebook _44c5_s_p9_0 = {
  118211. 2, 225,
  118212. _vq_lengthlist__44c5_s_p9_0,
  118213. 1, -512522752, 1628852224, 4, 0,
  118214. _vq_quantlist__44c5_s_p9_0,
  118215. NULL,
  118216. &_vq_auxt__44c5_s_p9_0,
  118217. NULL,
  118218. 0
  118219. };
  118220. static long _vq_quantlist__44c5_s_p9_1[] = {
  118221. 8,
  118222. 7,
  118223. 9,
  118224. 6,
  118225. 10,
  118226. 5,
  118227. 11,
  118228. 4,
  118229. 12,
  118230. 3,
  118231. 13,
  118232. 2,
  118233. 14,
  118234. 1,
  118235. 15,
  118236. 0,
  118237. 16,
  118238. };
  118239. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118240. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118241. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118242. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118243. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118244. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118245. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118246. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118247. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118248. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118249. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118250. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118251. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118252. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118253. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118254. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118255. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118256. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118257. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118258. 15,
  118259. };
  118260. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118261. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118262. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118263. };
  118264. static long _vq_quantmap__44c5_s_p9_1[] = {
  118265. 15, 13, 11, 9, 7, 5, 3, 1,
  118266. 0, 2, 4, 6, 8, 10, 12, 14,
  118267. 16,
  118268. };
  118269. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118270. _vq_quantthresh__44c5_s_p9_1,
  118271. _vq_quantmap__44c5_s_p9_1,
  118272. 17,
  118273. 17
  118274. };
  118275. static static_codebook _44c5_s_p9_1 = {
  118276. 2, 289,
  118277. _vq_lengthlist__44c5_s_p9_1,
  118278. 1, -520814592, 1620377600, 5, 0,
  118279. _vq_quantlist__44c5_s_p9_1,
  118280. NULL,
  118281. &_vq_auxt__44c5_s_p9_1,
  118282. NULL,
  118283. 0
  118284. };
  118285. static long _vq_quantlist__44c5_s_p9_2[] = {
  118286. 10,
  118287. 9,
  118288. 11,
  118289. 8,
  118290. 12,
  118291. 7,
  118292. 13,
  118293. 6,
  118294. 14,
  118295. 5,
  118296. 15,
  118297. 4,
  118298. 16,
  118299. 3,
  118300. 17,
  118301. 2,
  118302. 18,
  118303. 1,
  118304. 19,
  118305. 0,
  118306. 20,
  118307. };
  118308. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118309. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118310. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118311. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118312. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118313. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118314. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118315. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118316. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118317. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118318. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118319. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118320. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118321. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118322. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118323. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118324. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118325. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118326. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118327. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118328. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118329. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118330. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118331. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118332. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118333. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118334. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118335. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118336. 10,10,10,10,10,10,10,10,10,
  118337. };
  118338. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118339. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118340. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118341. 6.5, 7.5, 8.5, 9.5,
  118342. };
  118343. static long _vq_quantmap__44c5_s_p9_2[] = {
  118344. 19, 17, 15, 13, 11, 9, 7, 5,
  118345. 3, 1, 0, 2, 4, 6, 8, 10,
  118346. 12, 14, 16, 18, 20,
  118347. };
  118348. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118349. _vq_quantthresh__44c5_s_p9_2,
  118350. _vq_quantmap__44c5_s_p9_2,
  118351. 21,
  118352. 21
  118353. };
  118354. static static_codebook _44c5_s_p9_2 = {
  118355. 2, 441,
  118356. _vq_lengthlist__44c5_s_p9_2,
  118357. 1, -529268736, 1611661312, 5, 0,
  118358. _vq_quantlist__44c5_s_p9_2,
  118359. NULL,
  118360. &_vq_auxt__44c5_s_p9_2,
  118361. NULL,
  118362. 0
  118363. };
  118364. static long _huff_lengthlist__44c5_s_short[] = {
  118365. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118366. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118367. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118368. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118369. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118370. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118371. 6, 8,11,16,
  118372. };
  118373. static static_codebook _huff_book__44c5_s_short = {
  118374. 2, 100,
  118375. _huff_lengthlist__44c5_s_short,
  118376. 0, 0, 0, 0, 0,
  118377. NULL,
  118378. NULL,
  118379. NULL,
  118380. NULL,
  118381. 0
  118382. };
  118383. static long _huff_lengthlist__44c6_s_long[] = {
  118384. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118385. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118386. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118387. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118388. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118389. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118390. 11,10,10,12,
  118391. };
  118392. static static_codebook _huff_book__44c6_s_long = {
  118393. 2, 100,
  118394. _huff_lengthlist__44c6_s_long,
  118395. 0, 0, 0, 0, 0,
  118396. NULL,
  118397. NULL,
  118398. NULL,
  118399. NULL,
  118400. 0
  118401. };
  118402. static long _vq_quantlist__44c6_s_p1_0[] = {
  118403. 1,
  118404. 0,
  118405. 2,
  118406. };
  118407. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118408. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118409. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118410. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118411. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118412. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118413. 8,
  118414. };
  118415. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118416. -0.5, 0.5,
  118417. };
  118418. static long _vq_quantmap__44c6_s_p1_0[] = {
  118419. 1, 0, 2,
  118420. };
  118421. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118422. _vq_quantthresh__44c6_s_p1_0,
  118423. _vq_quantmap__44c6_s_p1_0,
  118424. 3,
  118425. 3
  118426. };
  118427. static static_codebook _44c6_s_p1_0 = {
  118428. 4, 81,
  118429. _vq_lengthlist__44c6_s_p1_0,
  118430. 1, -535822336, 1611661312, 2, 0,
  118431. _vq_quantlist__44c6_s_p1_0,
  118432. NULL,
  118433. &_vq_auxt__44c6_s_p1_0,
  118434. NULL,
  118435. 0
  118436. };
  118437. static long _vq_quantlist__44c6_s_p2_0[] = {
  118438. 2,
  118439. 1,
  118440. 3,
  118441. 0,
  118442. 4,
  118443. };
  118444. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118445. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118446. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118447. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118448. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118449. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118450. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118451. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118452. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118454. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118455. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118456. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118457. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118458. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118459. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118460. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118462. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118463. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118464. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118465. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118466. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118467. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118468. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118470. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118471. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118472. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118473. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118474. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118475. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118476. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118481. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118482. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118483. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118484. 13,
  118485. };
  118486. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118487. -1.5, -0.5, 0.5, 1.5,
  118488. };
  118489. static long _vq_quantmap__44c6_s_p2_0[] = {
  118490. 3, 1, 0, 2, 4,
  118491. };
  118492. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118493. _vq_quantthresh__44c6_s_p2_0,
  118494. _vq_quantmap__44c6_s_p2_0,
  118495. 5,
  118496. 5
  118497. };
  118498. static static_codebook _44c6_s_p2_0 = {
  118499. 4, 625,
  118500. _vq_lengthlist__44c6_s_p2_0,
  118501. 1, -533725184, 1611661312, 3, 0,
  118502. _vq_quantlist__44c6_s_p2_0,
  118503. NULL,
  118504. &_vq_auxt__44c6_s_p2_0,
  118505. NULL,
  118506. 0
  118507. };
  118508. static long _vq_quantlist__44c6_s_p3_0[] = {
  118509. 4,
  118510. 3,
  118511. 5,
  118512. 2,
  118513. 6,
  118514. 1,
  118515. 7,
  118516. 0,
  118517. 8,
  118518. };
  118519. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118520. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118521. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118522. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118523. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118525. 0,
  118526. };
  118527. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118528. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118529. };
  118530. static long _vq_quantmap__44c6_s_p3_0[] = {
  118531. 7, 5, 3, 1, 0, 2, 4, 6,
  118532. 8,
  118533. };
  118534. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118535. _vq_quantthresh__44c6_s_p3_0,
  118536. _vq_quantmap__44c6_s_p3_0,
  118537. 9,
  118538. 9
  118539. };
  118540. static static_codebook _44c6_s_p3_0 = {
  118541. 2, 81,
  118542. _vq_lengthlist__44c6_s_p3_0,
  118543. 1, -531628032, 1611661312, 4, 0,
  118544. _vq_quantlist__44c6_s_p3_0,
  118545. NULL,
  118546. &_vq_auxt__44c6_s_p3_0,
  118547. NULL,
  118548. 0
  118549. };
  118550. static long _vq_quantlist__44c6_s_p4_0[] = {
  118551. 8,
  118552. 7,
  118553. 9,
  118554. 6,
  118555. 10,
  118556. 5,
  118557. 11,
  118558. 4,
  118559. 12,
  118560. 3,
  118561. 13,
  118562. 2,
  118563. 14,
  118564. 1,
  118565. 15,
  118566. 0,
  118567. 16,
  118568. };
  118569. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118570. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118571. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118572. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118573. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118574. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118575. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118576. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118577. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118578. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118579. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118588. 0,
  118589. };
  118590. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118591. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118592. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118593. };
  118594. static long _vq_quantmap__44c6_s_p4_0[] = {
  118595. 15, 13, 11, 9, 7, 5, 3, 1,
  118596. 0, 2, 4, 6, 8, 10, 12, 14,
  118597. 16,
  118598. };
  118599. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118600. _vq_quantthresh__44c6_s_p4_0,
  118601. _vq_quantmap__44c6_s_p4_0,
  118602. 17,
  118603. 17
  118604. };
  118605. static static_codebook _44c6_s_p4_0 = {
  118606. 2, 289,
  118607. _vq_lengthlist__44c6_s_p4_0,
  118608. 1, -529530880, 1611661312, 5, 0,
  118609. _vq_quantlist__44c6_s_p4_0,
  118610. NULL,
  118611. &_vq_auxt__44c6_s_p4_0,
  118612. NULL,
  118613. 0
  118614. };
  118615. static long _vq_quantlist__44c6_s_p5_0[] = {
  118616. 1,
  118617. 0,
  118618. 2,
  118619. };
  118620. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118621. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118622. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118623. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118624. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118625. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118626. 12,
  118627. };
  118628. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118629. -5.5, 5.5,
  118630. };
  118631. static long _vq_quantmap__44c6_s_p5_0[] = {
  118632. 1, 0, 2,
  118633. };
  118634. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118635. _vq_quantthresh__44c6_s_p5_0,
  118636. _vq_quantmap__44c6_s_p5_0,
  118637. 3,
  118638. 3
  118639. };
  118640. static static_codebook _44c6_s_p5_0 = {
  118641. 4, 81,
  118642. _vq_lengthlist__44c6_s_p5_0,
  118643. 1, -529137664, 1618345984, 2, 0,
  118644. _vq_quantlist__44c6_s_p5_0,
  118645. NULL,
  118646. &_vq_auxt__44c6_s_p5_0,
  118647. NULL,
  118648. 0
  118649. };
  118650. static long _vq_quantlist__44c6_s_p5_1[] = {
  118651. 5,
  118652. 4,
  118653. 6,
  118654. 3,
  118655. 7,
  118656. 2,
  118657. 8,
  118658. 1,
  118659. 9,
  118660. 0,
  118661. 10,
  118662. };
  118663. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118664. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118665. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118666. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118667. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118668. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118669. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118670. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118671. 11,10,10, 7, 7, 8, 8, 8, 8,
  118672. };
  118673. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118674. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118675. 3.5, 4.5,
  118676. };
  118677. static long _vq_quantmap__44c6_s_p5_1[] = {
  118678. 9, 7, 5, 3, 1, 0, 2, 4,
  118679. 6, 8, 10,
  118680. };
  118681. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118682. _vq_quantthresh__44c6_s_p5_1,
  118683. _vq_quantmap__44c6_s_p5_1,
  118684. 11,
  118685. 11
  118686. };
  118687. static static_codebook _44c6_s_p5_1 = {
  118688. 2, 121,
  118689. _vq_lengthlist__44c6_s_p5_1,
  118690. 1, -531365888, 1611661312, 4, 0,
  118691. _vq_quantlist__44c6_s_p5_1,
  118692. NULL,
  118693. &_vq_auxt__44c6_s_p5_1,
  118694. NULL,
  118695. 0
  118696. };
  118697. static long _vq_quantlist__44c6_s_p6_0[] = {
  118698. 6,
  118699. 5,
  118700. 7,
  118701. 4,
  118702. 8,
  118703. 3,
  118704. 9,
  118705. 2,
  118706. 10,
  118707. 1,
  118708. 11,
  118709. 0,
  118710. 12,
  118711. };
  118712. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118713. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118714. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118715. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118716. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118717. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118718. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118723. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118724. };
  118725. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118726. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118727. 12.5, 17.5, 22.5, 27.5,
  118728. };
  118729. static long _vq_quantmap__44c6_s_p6_0[] = {
  118730. 11, 9, 7, 5, 3, 1, 0, 2,
  118731. 4, 6, 8, 10, 12,
  118732. };
  118733. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118734. _vq_quantthresh__44c6_s_p6_0,
  118735. _vq_quantmap__44c6_s_p6_0,
  118736. 13,
  118737. 13
  118738. };
  118739. static static_codebook _44c6_s_p6_0 = {
  118740. 2, 169,
  118741. _vq_lengthlist__44c6_s_p6_0,
  118742. 1, -526516224, 1616117760, 4, 0,
  118743. _vq_quantlist__44c6_s_p6_0,
  118744. NULL,
  118745. &_vq_auxt__44c6_s_p6_0,
  118746. NULL,
  118747. 0
  118748. };
  118749. static long _vq_quantlist__44c6_s_p6_1[] = {
  118750. 2,
  118751. 1,
  118752. 3,
  118753. 0,
  118754. 4,
  118755. };
  118756. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118757. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118758. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118759. };
  118760. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118761. -1.5, -0.5, 0.5, 1.5,
  118762. };
  118763. static long _vq_quantmap__44c6_s_p6_1[] = {
  118764. 3, 1, 0, 2, 4,
  118765. };
  118766. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118767. _vq_quantthresh__44c6_s_p6_1,
  118768. _vq_quantmap__44c6_s_p6_1,
  118769. 5,
  118770. 5
  118771. };
  118772. static static_codebook _44c6_s_p6_1 = {
  118773. 2, 25,
  118774. _vq_lengthlist__44c6_s_p6_1,
  118775. 1, -533725184, 1611661312, 3, 0,
  118776. _vq_quantlist__44c6_s_p6_1,
  118777. NULL,
  118778. &_vq_auxt__44c6_s_p6_1,
  118779. NULL,
  118780. 0
  118781. };
  118782. static long _vq_quantlist__44c6_s_p7_0[] = {
  118783. 6,
  118784. 5,
  118785. 7,
  118786. 4,
  118787. 8,
  118788. 3,
  118789. 9,
  118790. 2,
  118791. 10,
  118792. 1,
  118793. 11,
  118794. 0,
  118795. 12,
  118796. };
  118797. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118798. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118799. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118800. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118801. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118802. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118803. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118804. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118805. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118806. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118807. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118808. 20,13,13,13,13,13,13,14,14,
  118809. };
  118810. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118811. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118812. 27.5, 38.5, 49.5, 60.5,
  118813. };
  118814. static long _vq_quantmap__44c6_s_p7_0[] = {
  118815. 11, 9, 7, 5, 3, 1, 0, 2,
  118816. 4, 6, 8, 10, 12,
  118817. };
  118818. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118819. _vq_quantthresh__44c6_s_p7_0,
  118820. _vq_quantmap__44c6_s_p7_0,
  118821. 13,
  118822. 13
  118823. };
  118824. static static_codebook _44c6_s_p7_0 = {
  118825. 2, 169,
  118826. _vq_lengthlist__44c6_s_p7_0,
  118827. 1, -523206656, 1618345984, 4, 0,
  118828. _vq_quantlist__44c6_s_p7_0,
  118829. NULL,
  118830. &_vq_auxt__44c6_s_p7_0,
  118831. NULL,
  118832. 0
  118833. };
  118834. static long _vq_quantlist__44c6_s_p7_1[] = {
  118835. 5,
  118836. 4,
  118837. 6,
  118838. 3,
  118839. 7,
  118840. 2,
  118841. 8,
  118842. 1,
  118843. 9,
  118844. 0,
  118845. 10,
  118846. };
  118847. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118848. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118849. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118850. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118851. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118852. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118853. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118854. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118855. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118856. };
  118857. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118858. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118859. 3.5, 4.5,
  118860. };
  118861. static long _vq_quantmap__44c6_s_p7_1[] = {
  118862. 9, 7, 5, 3, 1, 0, 2, 4,
  118863. 6, 8, 10,
  118864. };
  118865. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118866. _vq_quantthresh__44c6_s_p7_1,
  118867. _vq_quantmap__44c6_s_p7_1,
  118868. 11,
  118869. 11
  118870. };
  118871. static static_codebook _44c6_s_p7_1 = {
  118872. 2, 121,
  118873. _vq_lengthlist__44c6_s_p7_1,
  118874. 1, -531365888, 1611661312, 4, 0,
  118875. _vq_quantlist__44c6_s_p7_1,
  118876. NULL,
  118877. &_vq_auxt__44c6_s_p7_1,
  118878. NULL,
  118879. 0
  118880. };
  118881. static long _vq_quantlist__44c6_s_p8_0[] = {
  118882. 7,
  118883. 6,
  118884. 8,
  118885. 5,
  118886. 9,
  118887. 4,
  118888. 10,
  118889. 3,
  118890. 11,
  118891. 2,
  118892. 12,
  118893. 1,
  118894. 13,
  118895. 0,
  118896. 14,
  118897. };
  118898. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118899. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118900. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118901. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118902. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118903. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118904. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118905. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118906. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118907. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118908. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118909. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118910. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118911. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118912. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118913. 14,
  118914. };
  118915. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118916. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118917. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118918. };
  118919. static long _vq_quantmap__44c6_s_p8_0[] = {
  118920. 13, 11, 9, 7, 5, 3, 1, 0,
  118921. 2, 4, 6, 8, 10, 12, 14,
  118922. };
  118923. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118924. _vq_quantthresh__44c6_s_p8_0,
  118925. _vq_quantmap__44c6_s_p8_0,
  118926. 15,
  118927. 15
  118928. };
  118929. static static_codebook _44c6_s_p8_0 = {
  118930. 2, 225,
  118931. _vq_lengthlist__44c6_s_p8_0,
  118932. 1, -520986624, 1620377600, 4, 0,
  118933. _vq_quantlist__44c6_s_p8_0,
  118934. NULL,
  118935. &_vq_auxt__44c6_s_p8_0,
  118936. NULL,
  118937. 0
  118938. };
  118939. static long _vq_quantlist__44c6_s_p8_1[] = {
  118940. 10,
  118941. 9,
  118942. 11,
  118943. 8,
  118944. 12,
  118945. 7,
  118946. 13,
  118947. 6,
  118948. 14,
  118949. 5,
  118950. 15,
  118951. 4,
  118952. 16,
  118953. 3,
  118954. 17,
  118955. 2,
  118956. 18,
  118957. 1,
  118958. 19,
  118959. 0,
  118960. 20,
  118961. };
  118962. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118963. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118964. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118965. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118966. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118967. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118968. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118969. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118970. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118971. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118972. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118973. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118974. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118975. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118976. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118977. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118978. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118979. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118980. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118981. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118982. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118983. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118984. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118985. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118986. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118987. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118988. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118989. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118990. 10,10,10,10,10,10,10,10,10,
  118991. };
  118992. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118993. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118994. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118995. 6.5, 7.5, 8.5, 9.5,
  118996. };
  118997. static long _vq_quantmap__44c6_s_p8_1[] = {
  118998. 19, 17, 15, 13, 11, 9, 7, 5,
  118999. 3, 1, 0, 2, 4, 6, 8, 10,
  119000. 12, 14, 16, 18, 20,
  119001. };
  119002. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  119003. _vq_quantthresh__44c6_s_p8_1,
  119004. _vq_quantmap__44c6_s_p8_1,
  119005. 21,
  119006. 21
  119007. };
  119008. static static_codebook _44c6_s_p8_1 = {
  119009. 2, 441,
  119010. _vq_lengthlist__44c6_s_p8_1,
  119011. 1, -529268736, 1611661312, 5, 0,
  119012. _vq_quantlist__44c6_s_p8_1,
  119013. NULL,
  119014. &_vq_auxt__44c6_s_p8_1,
  119015. NULL,
  119016. 0
  119017. };
  119018. static long _vq_quantlist__44c6_s_p9_0[] = {
  119019. 6,
  119020. 5,
  119021. 7,
  119022. 4,
  119023. 8,
  119024. 3,
  119025. 9,
  119026. 2,
  119027. 10,
  119028. 1,
  119029. 11,
  119030. 0,
  119031. 12,
  119032. };
  119033. static long _vq_lengthlist__44c6_s_p9_0[] = {
  119034. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  119035. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  119036. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119037. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119038. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119039. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119040. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119041. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119042. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119043. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119044. 10,10,10,10,10,10,10,10,10,
  119045. };
  119046. static float _vq_quantthresh__44c6_s_p9_0[] = {
  119047. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119048. 1592.5, 2229.5, 2866.5, 3503.5,
  119049. };
  119050. static long _vq_quantmap__44c6_s_p9_0[] = {
  119051. 11, 9, 7, 5, 3, 1, 0, 2,
  119052. 4, 6, 8, 10, 12,
  119053. };
  119054. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  119055. _vq_quantthresh__44c6_s_p9_0,
  119056. _vq_quantmap__44c6_s_p9_0,
  119057. 13,
  119058. 13
  119059. };
  119060. static static_codebook _44c6_s_p9_0 = {
  119061. 2, 169,
  119062. _vq_lengthlist__44c6_s_p9_0,
  119063. 1, -511845376, 1630791680, 4, 0,
  119064. _vq_quantlist__44c6_s_p9_0,
  119065. NULL,
  119066. &_vq_auxt__44c6_s_p9_0,
  119067. NULL,
  119068. 0
  119069. };
  119070. static long _vq_quantlist__44c6_s_p9_1[] = {
  119071. 6,
  119072. 5,
  119073. 7,
  119074. 4,
  119075. 8,
  119076. 3,
  119077. 9,
  119078. 2,
  119079. 10,
  119080. 1,
  119081. 11,
  119082. 0,
  119083. 12,
  119084. };
  119085. static long _vq_lengthlist__44c6_s_p9_1[] = {
  119086. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119087. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  119088. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  119089. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  119090. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  119091. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  119092. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  119093. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  119094. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  119095. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  119096. 15,12,10,11,11,13,11,12,13,
  119097. };
  119098. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119099. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119100. 122.5, 171.5, 220.5, 269.5,
  119101. };
  119102. static long _vq_quantmap__44c6_s_p9_1[] = {
  119103. 11, 9, 7, 5, 3, 1, 0, 2,
  119104. 4, 6, 8, 10, 12,
  119105. };
  119106. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119107. _vq_quantthresh__44c6_s_p9_1,
  119108. _vq_quantmap__44c6_s_p9_1,
  119109. 13,
  119110. 13
  119111. };
  119112. static static_codebook _44c6_s_p9_1 = {
  119113. 2, 169,
  119114. _vq_lengthlist__44c6_s_p9_1,
  119115. 1, -518889472, 1622704128, 4, 0,
  119116. _vq_quantlist__44c6_s_p9_1,
  119117. NULL,
  119118. &_vq_auxt__44c6_s_p9_1,
  119119. NULL,
  119120. 0
  119121. };
  119122. static long _vq_quantlist__44c6_s_p9_2[] = {
  119123. 24,
  119124. 23,
  119125. 25,
  119126. 22,
  119127. 26,
  119128. 21,
  119129. 27,
  119130. 20,
  119131. 28,
  119132. 19,
  119133. 29,
  119134. 18,
  119135. 30,
  119136. 17,
  119137. 31,
  119138. 16,
  119139. 32,
  119140. 15,
  119141. 33,
  119142. 14,
  119143. 34,
  119144. 13,
  119145. 35,
  119146. 12,
  119147. 36,
  119148. 11,
  119149. 37,
  119150. 10,
  119151. 38,
  119152. 9,
  119153. 39,
  119154. 8,
  119155. 40,
  119156. 7,
  119157. 41,
  119158. 6,
  119159. 42,
  119160. 5,
  119161. 43,
  119162. 4,
  119163. 44,
  119164. 3,
  119165. 45,
  119166. 2,
  119167. 46,
  119168. 1,
  119169. 47,
  119170. 0,
  119171. 48,
  119172. };
  119173. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119174. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119175. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119176. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119177. 7,
  119178. };
  119179. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119180. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119181. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119182. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119183. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119184. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119185. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119186. };
  119187. static long _vq_quantmap__44c6_s_p9_2[] = {
  119188. 47, 45, 43, 41, 39, 37, 35, 33,
  119189. 31, 29, 27, 25, 23, 21, 19, 17,
  119190. 15, 13, 11, 9, 7, 5, 3, 1,
  119191. 0, 2, 4, 6, 8, 10, 12, 14,
  119192. 16, 18, 20, 22, 24, 26, 28, 30,
  119193. 32, 34, 36, 38, 40, 42, 44, 46,
  119194. 48,
  119195. };
  119196. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119197. _vq_quantthresh__44c6_s_p9_2,
  119198. _vq_quantmap__44c6_s_p9_2,
  119199. 49,
  119200. 49
  119201. };
  119202. static static_codebook _44c6_s_p9_2 = {
  119203. 1, 49,
  119204. _vq_lengthlist__44c6_s_p9_2,
  119205. 1, -526909440, 1611661312, 6, 0,
  119206. _vq_quantlist__44c6_s_p9_2,
  119207. NULL,
  119208. &_vq_auxt__44c6_s_p9_2,
  119209. NULL,
  119210. 0
  119211. };
  119212. static long _huff_lengthlist__44c6_s_short[] = {
  119213. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119214. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119215. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119216. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119217. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119218. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119219. 9,10,17,18,
  119220. };
  119221. static static_codebook _huff_book__44c6_s_short = {
  119222. 2, 100,
  119223. _huff_lengthlist__44c6_s_short,
  119224. 0, 0, 0, 0, 0,
  119225. NULL,
  119226. NULL,
  119227. NULL,
  119228. NULL,
  119229. 0
  119230. };
  119231. static long _huff_lengthlist__44c7_s_long[] = {
  119232. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119233. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119234. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119235. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119236. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119237. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119238. 11,10,10,12,
  119239. };
  119240. static static_codebook _huff_book__44c7_s_long = {
  119241. 2, 100,
  119242. _huff_lengthlist__44c7_s_long,
  119243. 0, 0, 0, 0, 0,
  119244. NULL,
  119245. NULL,
  119246. NULL,
  119247. NULL,
  119248. 0
  119249. };
  119250. static long _vq_quantlist__44c7_s_p1_0[] = {
  119251. 1,
  119252. 0,
  119253. 2,
  119254. };
  119255. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119256. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119257. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119258. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119259. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119260. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119261. 8,
  119262. };
  119263. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119264. -0.5, 0.5,
  119265. };
  119266. static long _vq_quantmap__44c7_s_p1_0[] = {
  119267. 1, 0, 2,
  119268. };
  119269. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119270. _vq_quantthresh__44c7_s_p1_0,
  119271. _vq_quantmap__44c7_s_p1_0,
  119272. 3,
  119273. 3
  119274. };
  119275. static static_codebook _44c7_s_p1_0 = {
  119276. 4, 81,
  119277. _vq_lengthlist__44c7_s_p1_0,
  119278. 1, -535822336, 1611661312, 2, 0,
  119279. _vq_quantlist__44c7_s_p1_0,
  119280. NULL,
  119281. &_vq_auxt__44c7_s_p1_0,
  119282. NULL,
  119283. 0
  119284. };
  119285. static long _vq_quantlist__44c7_s_p2_0[] = {
  119286. 2,
  119287. 1,
  119288. 3,
  119289. 0,
  119290. 4,
  119291. };
  119292. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119293. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119294. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119295. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119296. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119297. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119298. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119299. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119300. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119302. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119303. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119304. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119305. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119306. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119307. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119308. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119310. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119311. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119312. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119313. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119314. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119315. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119316. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119318. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119319. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119320. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119321. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119322. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119323. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119324. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119329. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119330. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119331. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119332. 13,
  119333. };
  119334. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119335. -1.5, -0.5, 0.5, 1.5,
  119336. };
  119337. static long _vq_quantmap__44c7_s_p2_0[] = {
  119338. 3, 1, 0, 2, 4,
  119339. };
  119340. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119341. _vq_quantthresh__44c7_s_p2_0,
  119342. _vq_quantmap__44c7_s_p2_0,
  119343. 5,
  119344. 5
  119345. };
  119346. static static_codebook _44c7_s_p2_0 = {
  119347. 4, 625,
  119348. _vq_lengthlist__44c7_s_p2_0,
  119349. 1, -533725184, 1611661312, 3, 0,
  119350. _vq_quantlist__44c7_s_p2_0,
  119351. NULL,
  119352. &_vq_auxt__44c7_s_p2_0,
  119353. NULL,
  119354. 0
  119355. };
  119356. static long _vq_quantlist__44c7_s_p3_0[] = {
  119357. 4,
  119358. 3,
  119359. 5,
  119360. 2,
  119361. 6,
  119362. 1,
  119363. 7,
  119364. 0,
  119365. 8,
  119366. };
  119367. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119368. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119369. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119370. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119371. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119373. 0,
  119374. };
  119375. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119376. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119377. };
  119378. static long _vq_quantmap__44c7_s_p3_0[] = {
  119379. 7, 5, 3, 1, 0, 2, 4, 6,
  119380. 8,
  119381. };
  119382. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119383. _vq_quantthresh__44c7_s_p3_0,
  119384. _vq_quantmap__44c7_s_p3_0,
  119385. 9,
  119386. 9
  119387. };
  119388. static static_codebook _44c7_s_p3_0 = {
  119389. 2, 81,
  119390. _vq_lengthlist__44c7_s_p3_0,
  119391. 1, -531628032, 1611661312, 4, 0,
  119392. _vq_quantlist__44c7_s_p3_0,
  119393. NULL,
  119394. &_vq_auxt__44c7_s_p3_0,
  119395. NULL,
  119396. 0
  119397. };
  119398. static long _vq_quantlist__44c7_s_p4_0[] = {
  119399. 8,
  119400. 7,
  119401. 9,
  119402. 6,
  119403. 10,
  119404. 5,
  119405. 11,
  119406. 4,
  119407. 12,
  119408. 3,
  119409. 13,
  119410. 2,
  119411. 14,
  119412. 1,
  119413. 15,
  119414. 0,
  119415. 16,
  119416. };
  119417. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119418. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119419. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119420. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119421. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119422. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119423. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119424. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119425. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119426. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119427. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119436. 0,
  119437. };
  119438. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119439. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119440. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119441. };
  119442. static long _vq_quantmap__44c7_s_p4_0[] = {
  119443. 15, 13, 11, 9, 7, 5, 3, 1,
  119444. 0, 2, 4, 6, 8, 10, 12, 14,
  119445. 16,
  119446. };
  119447. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119448. _vq_quantthresh__44c7_s_p4_0,
  119449. _vq_quantmap__44c7_s_p4_0,
  119450. 17,
  119451. 17
  119452. };
  119453. static static_codebook _44c7_s_p4_0 = {
  119454. 2, 289,
  119455. _vq_lengthlist__44c7_s_p4_0,
  119456. 1, -529530880, 1611661312, 5, 0,
  119457. _vq_quantlist__44c7_s_p4_0,
  119458. NULL,
  119459. &_vq_auxt__44c7_s_p4_0,
  119460. NULL,
  119461. 0
  119462. };
  119463. static long _vq_quantlist__44c7_s_p5_0[] = {
  119464. 1,
  119465. 0,
  119466. 2,
  119467. };
  119468. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119469. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119470. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119471. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119472. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119473. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119474. 12,
  119475. };
  119476. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119477. -5.5, 5.5,
  119478. };
  119479. static long _vq_quantmap__44c7_s_p5_0[] = {
  119480. 1, 0, 2,
  119481. };
  119482. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119483. _vq_quantthresh__44c7_s_p5_0,
  119484. _vq_quantmap__44c7_s_p5_0,
  119485. 3,
  119486. 3
  119487. };
  119488. static static_codebook _44c7_s_p5_0 = {
  119489. 4, 81,
  119490. _vq_lengthlist__44c7_s_p5_0,
  119491. 1, -529137664, 1618345984, 2, 0,
  119492. _vq_quantlist__44c7_s_p5_0,
  119493. NULL,
  119494. &_vq_auxt__44c7_s_p5_0,
  119495. NULL,
  119496. 0
  119497. };
  119498. static long _vq_quantlist__44c7_s_p5_1[] = {
  119499. 5,
  119500. 4,
  119501. 6,
  119502. 3,
  119503. 7,
  119504. 2,
  119505. 8,
  119506. 1,
  119507. 9,
  119508. 0,
  119509. 10,
  119510. };
  119511. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119512. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119513. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119514. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119515. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119516. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119517. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119518. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119519. 11,11,11, 7, 7, 8, 8, 8, 8,
  119520. };
  119521. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119522. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119523. 3.5, 4.5,
  119524. };
  119525. static long _vq_quantmap__44c7_s_p5_1[] = {
  119526. 9, 7, 5, 3, 1, 0, 2, 4,
  119527. 6, 8, 10,
  119528. };
  119529. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119530. _vq_quantthresh__44c7_s_p5_1,
  119531. _vq_quantmap__44c7_s_p5_1,
  119532. 11,
  119533. 11
  119534. };
  119535. static static_codebook _44c7_s_p5_1 = {
  119536. 2, 121,
  119537. _vq_lengthlist__44c7_s_p5_1,
  119538. 1, -531365888, 1611661312, 4, 0,
  119539. _vq_quantlist__44c7_s_p5_1,
  119540. NULL,
  119541. &_vq_auxt__44c7_s_p5_1,
  119542. NULL,
  119543. 0
  119544. };
  119545. static long _vq_quantlist__44c7_s_p6_0[] = {
  119546. 6,
  119547. 5,
  119548. 7,
  119549. 4,
  119550. 8,
  119551. 3,
  119552. 9,
  119553. 2,
  119554. 10,
  119555. 1,
  119556. 11,
  119557. 0,
  119558. 12,
  119559. };
  119560. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119561. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119562. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119563. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119564. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119565. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119566. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119571. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119572. };
  119573. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119574. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119575. 12.5, 17.5, 22.5, 27.5,
  119576. };
  119577. static long _vq_quantmap__44c7_s_p6_0[] = {
  119578. 11, 9, 7, 5, 3, 1, 0, 2,
  119579. 4, 6, 8, 10, 12,
  119580. };
  119581. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119582. _vq_quantthresh__44c7_s_p6_0,
  119583. _vq_quantmap__44c7_s_p6_0,
  119584. 13,
  119585. 13
  119586. };
  119587. static static_codebook _44c7_s_p6_0 = {
  119588. 2, 169,
  119589. _vq_lengthlist__44c7_s_p6_0,
  119590. 1, -526516224, 1616117760, 4, 0,
  119591. _vq_quantlist__44c7_s_p6_0,
  119592. NULL,
  119593. &_vq_auxt__44c7_s_p6_0,
  119594. NULL,
  119595. 0
  119596. };
  119597. static long _vq_quantlist__44c7_s_p6_1[] = {
  119598. 2,
  119599. 1,
  119600. 3,
  119601. 0,
  119602. 4,
  119603. };
  119604. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119605. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119606. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119607. };
  119608. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119609. -1.5, -0.5, 0.5, 1.5,
  119610. };
  119611. static long _vq_quantmap__44c7_s_p6_1[] = {
  119612. 3, 1, 0, 2, 4,
  119613. };
  119614. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119615. _vq_quantthresh__44c7_s_p6_1,
  119616. _vq_quantmap__44c7_s_p6_1,
  119617. 5,
  119618. 5
  119619. };
  119620. static static_codebook _44c7_s_p6_1 = {
  119621. 2, 25,
  119622. _vq_lengthlist__44c7_s_p6_1,
  119623. 1, -533725184, 1611661312, 3, 0,
  119624. _vq_quantlist__44c7_s_p6_1,
  119625. NULL,
  119626. &_vq_auxt__44c7_s_p6_1,
  119627. NULL,
  119628. 0
  119629. };
  119630. static long _vq_quantlist__44c7_s_p7_0[] = {
  119631. 6,
  119632. 5,
  119633. 7,
  119634. 4,
  119635. 8,
  119636. 3,
  119637. 9,
  119638. 2,
  119639. 10,
  119640. 1,
  119641. 11,
  119642. 0,
  119643. 12,
  119644. };
  119645. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119646. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119647. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119648. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119649. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119650. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119651. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119652. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119653. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119654. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119655. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119656. 19,13,13,13,13,14,14,15,15,
  119657. };
  119658. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119659. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119660. 27.5, 38.5, 49.5, 60.5,
  119661. };
  119662. static long _vq_quantmap__44c7_s_p7_0[] = {
  119663. 11, 9, 7, 5, 3, 1, 0, 2,
  119664. 4, 6, 8, 10, 12,
  119665. };
  119666. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119667. _vq_quantthresh__44c7_s_p7_0,
  119668. _vq_quantmap__44c7_s_p7_0,
  119669. 13,
  119670. 13
  119671. };
  119672. static static_codebook _44c7_s_p7_0 = {
  119673. 2, 169,
  119674. _vq_lengthlist__44c7_s_p7_0,
  119675. 1, -523206656, 1618345984, 4, 0,
  119676. _vq_quantlist__44c7_s_p7_0,
  119677. NULL,
  119678. &_vq_auxt__44c7_s_p7_0,
  119679. NULL,
  119680. 0
  119681. };
  119682. static long _vq_quantlist__44c7_s_p7_1[] = {
  119683. 5,
  119684. 4,
  119685. 6,
  119686. 3,
  119687. 7,
  119688. 2,
  119689. 8,
  119690. 1,
  119691. 9,
  119692. 0,
  119693. 10,
  119694. };
  119695. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119696. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119697. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119698. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119699. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119700. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119701. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119702. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119703. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119704. };
  119705. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119706. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119707. 3.5, 4.5,
  119708. };
  119709. static long _vq_quantmap__44c7_s_p7_1[] = {
  119710. 9, 7, 5, 3, 1, 0, 2, 4,
  119711. 6, 8, 10,
  119712. };
  119713. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119714. _vq_quantthresh__44c7_s_p7_1,
  119715. _vq_quantmap__44c7_s_p7_1,
  119716. 11,
  119717. 11
  119718. };
  119719. static static_codebook _44c7_s_p7_1 = {
  119720. 2, 121,
  119721. _vq_lengthlist__44c7_s_p7_1,
  119722. 1, -531365888, 1611661312, 4, 0,
  119723. _vq_quantlist__44c7_s_p7_1,
  119724. NULL,
  119725. &_vq_auxt__44c7_s_p7_1,
  119726. NULL,
  119727. 0
  119728. };
  119729. static long _vq_quantlist__44c7_s_p8_0[] = {
  119730. 7,
  119731. 6,
  119732. 8,
  119733. 5,
  119734. 9,
  119735. 4,
  119736. 10,
  119737. 3,
  119738. 11,
  119739. 2,
  119740. 12,
  119741. 1,
  119742. 13,
  119743. 0,
  119744. 14,
  119745. };
  119746. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119747. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119748. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119749. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119750. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119751. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119752. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119753. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119754. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119755. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119756. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119757. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119758. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119759. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119760. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119761. 14,
  119762. };
  119763. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119764. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119765. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119766. };
  119767. static long _vq_quantmap__44c7_s_p8_0[] = {
  119768. 13, 11, 9, 7, 5, 3, 1, 0,
  119769. 2, 4, 6, 8, 10, 12, 14,
  119770. };
  119771. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119772. _vq_quantthresh__44c7_s_p8_0,
  119773. _vq_quantmap__44c7_s_p8_0,
  119774. 15,
  119775. 15
  119776. };
  119777. static static_codebook _44c7_s_p8_0 = {
  119778. 2, 225,
  119779. _vq_lengthlist__44c7_s_p8_0,
  119780. 1, -520986624, 1620377600, 4, 0,
  119781. _vq_quantlist__44c7_s_p8_0,
  119782. NULL,
  119783. &_vq_auxt__44c7_s_p8_0,
  119784. NULL,
  119785. 0
  119786. };
  119787. static long _vq_quantlist__44c7_s_p8_1[] = {
  119788. 10,
  119789. 9,
  119790. 11,
  119791. 8,
  119792. 12,
  119793. 7,
  119794. 13,
  119795. 6,
  119796. 14,
  119797. 5,
  119798. 15,
  119799. 4,
  119800. 16,
  119801. 3,
  119802. 17,
  119803. 2,
  119804. 18,
  119805. 1,
  119806. 19,
  119807. 0,
  119808. 20,
  119809. };
  119810. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119811. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119812. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119813. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119814. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119815. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119816. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119817. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119818. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119819. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119820. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119821. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119822. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119823. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119824. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119825. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119826. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119827. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119828. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119829. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119830. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119831. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119832. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119833. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119834. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119835. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119836. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119837. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119838. 10,10,10,10,10,10,10,10,10,
  119839. };
  119840. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119841. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119842. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119843. 6.5, 7.5, 8.5, 9.5,
  119844. };
  119845. static long _vq_quantmap__44c7_s_p8_1[] = {
  119846. 19, 17, 15, 13, 11, 9, 7, 5,
  119847. 3, 1, 0, 2, 4, 6, 8, 10,
  119848. 12, 14, 16, 18, 20,
  119849. };
  119850. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119851. _vq_quantthresh__44c7_s_p8_1,
  119852. _vq_quantmap__44c7_s_p8_1,
  119853. 21,
  119854. 21
  119855. };
  119856. static static_codebook _44c7_s_p8_1 = {
  119857. 2, 441,
  119858. _vq_lengthlist__44c7_s_p8_1,
  119859. 1, -529268736, 1611661312, 5, 0,
  119860. _vq_quantlist__44c7_s_p8_1,
  119861. NULL,
  119862. &_vq_auxt__44c7_s_p8_1,
  119863. NULL,
  119864. 0
  119865. };
  119866. static long _vq_quantlist__44c7_s_p9_0[] = {
  119867. 6,
  119868. 5,
  119869. 7,
  119870. 4,
  119871. 8,
  119872. 3,
  119873. 9,
  119874. 2,
  119875. 10,
  119876. 1,
  119877. 11,
  119878. 0,
  119879. 12,
  119880. };
  119881. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119882. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119883. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119884. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119885. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119886. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119887. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119888. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119889. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119890. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119891. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119892. 11,11,11,11,11,11,11,11,11,
  119893. };
  119894. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119895. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119896. 1592.5, 2229.5, 2866.5, 3503.5,
  119897. };
  119898. static long _vq_quantmap__44c7_s_p9_0[] = {
  119899. 11, 9, 7, 5, 3, 1, 0, 2,
  119900. 4, 6, 8, 10, 12,
  119901. };
  119902. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119903. _vq_quantthresh__44c7_s_p9_0,
  119904. _vq_quantmap__44c7_s_p9_0,
  119905. 13,
  119906. 13
  119907. };
  119908. static static_codebook _44c7_s_p9_0 = {
  119909. 2, 169,
  119910. _vq_lengthlist__44c7_s_p9_0,
  119911. 1, -511845376, 1630791680, 4, 0,
  119912. _vq_quantlist__44c7_s_p9_0,
  119913. NULL,
  119914. &_vq_auxt__44c7_s_p9_0,
  119915. NULL,
  119916. 0
  119917. };
  119918. static long _vq_quantlist__44c7_s_p9_1[] = {
  119919. 6,
  119920. 5,
  119921. 7,
  119922. 4,
  119923. 8,
  119924. 3,
  119925. 9,
  119926. 2,
  119927. 10,
  119928. 1,
  119929. 11,
  119930. 0,
  119931. 12,
  119932. };
  119933. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119934. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119935. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119936. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119937. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119938. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119939. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119940. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119941. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119942. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119943. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119944. 15,11,11,10,10,12,12,12,12,
  119945. };
  119946. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119947. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119948. 122.5, 171.5, 220.5, 269.5,
  119949. };
  119950. static long _vq_quantmap__44c7_s_p9_1[] = {
  119951. 11, 9, 7, 5, 3, 1, 0, 2,
  119952. 4, 6, 8, 10, 12,
  119953. };
  119954. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119955. _vq_quantthresh__44c7_s_p9_1,
  119956. _vq_quantmap__44c7_s_p9_1,
  119957. 13,
  119958. 13
  119959. };
  119960. static static_codebook _44c7_s_p9_1 = {
  119961. 2, 169,
  119962. _vq_lengthlist__44c7_s_p9_1,
  119963. 1, -518889472, 1622704128, 4, 0,
  119964. _vq_quantlist__44c7_s_p9_1,
  119965. NULL,
  119966. &_vq_auxt__44c7_s_p9_1,
  119967. NULL,
  119968. 0
  119969. };
  119970. static long _vq_quantlist__44c7_s_p9_2[] = {
  119971. 24,
  119972. 23,
  119973. 25,
  119974. 22,
  119975. 26,
  119976. 21,
  119977. 27,
  119978. 20,
  119979. 28,
  119980. 19,
  119981. 29,
  119982. 18,
  119983. 30,
  119984. 17,
  119985. 31,
  119986. 16,
  119987. 32,
  119988. 15,
  119989. 33,
  119990. 14,
  119991. 34,
  119992. 13,
  119993. 35,
  119994. 12,
  119995. 36,
  119996. 11,
  119997. 37,
  119998. 10,
  119999. 38,
  120000. 9,
  120001. 39,
  120002. 8,
  120003. 40,
  120004. 7,
  120005. 41,
  120006. 6,
  120007. 42,
  120008. 5,
  120009. 43,
  120010. 4,
  120011. 44,
  120012. 3,
  120013. 45,
  120014. 2,
  120015. 46,
  120016. 1,
  120017. 47,
  120018. 0,
  120019. 48,
  120020. };
  120021. static long _vq_lengthlist__44c7_s_p9_2[] = {
  120022. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  120023. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120024. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120025. 7,
  120026. };
  120027. static float _vq_quantthresh__44c7_s_p9_2[] = {
  120028. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120029. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120030. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120031. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120032. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120033. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120034. };
  120035. static long _vq_quantmap__44c7_s_p9_2[] = {
  120036. 47, 45, 43, 41, 39, 37, 35, 33,
  120037. 31, 29, 27, 25, 23, 21, 19, 17,
  120038. 15, 13, 11, 9, 7, 5, 3, 1,
  120039. 0, 2, 4, 6, 8, 10, 12, 14,
  120040. 16, 18, 20, 22, 24, 26, 28, 30,
  120041. 32, 34, 36, 38, 40, 42, 44, 46,
  120042. 48,
  120043. };
  120044. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  120045. _vq_quantthresh__44c7_s_p9_2,
  120046. _vq_quantmap__44c7_s_p9_2,
  120047. 49,
  120048. 49
  120049. };
  120050. static static_codebook _44c7_s_p9_2 = {
  120051. 1, 49,
  120052. _vq_lengthlist__44c7_s_p9_2,
  120053. 1, -526909440, 1611661312, 6, 0,
  120054. _vq_quantlist__44c7_s_p9_2,
  120055. NULL,
  120056. &_vq_auxt__44c7_s_p9_2,
  120057. NULL,
  120058. 0
  120059. };
  120060. static long _huff_lengthlist__44c7_s_short[] = {
  120061. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  120062. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  120063. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  120064. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  120065. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  120066. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  120067. 10, 9,11,14,
  120068. };
  120069. static static_codebook _huff_book__44c7_s_short = {
  120070. 2, 100,
  120071. _huff_lengthlist__44c7_s_short,
  120072. 0, 0, 0, 0, 0,
  120073. NULL,
  120074. NULL,
  120075. NULL,
  120076. NULL,
  120077. 0
  120078. };
  120079. static long _huff_lengthlist__44c8_s_long[] = {
  120080. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  120081. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  120082. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  120083. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  120084. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  120085. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  120086. 11, 9, 9,10,
  120087. };
  120088. static static_codebook _huff_book__44c8_s_long = {
  120089. 2, 100,
  120090. _huff_lengthlist__44c8_s_long,
  120091. 0, 0, 0, 0, 0,
  120092. NULL,
  120093. NULL,
  120094. NULL,
  120095. NULL,
  120096. 0
  120097. };
  120098. static long _vq_quantlist__44c8_s_p1_0[] = {
  120099. 1,
  120100. 0,
  120101. 2,
  120102. };
  120103. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120104. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120105. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120106. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120107. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120108. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120109. 8,
  120110. };
  120111. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120112. -0.5, 0.5,
  120113. };
  120114. static long _vq_quantmap__44c8_s_p1_0[] = {
  120115. 1, 0, 2,
  120116. };
  120117. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120118. _vq_quantthresh__44c8_s_p1_0,
  120119. _vq_quantmap__44c8_s_p1_0,
  120120. 3,
  120121. 3
  120122. };
  120123. static static_codebook _44c8_s_p1_0 = {
  120124. 4, 81,
  120125. _vq_lengthlist__44c8_s_p1_0,
  120126. 1, -535822336, 1611661312, 2, 0,
  120127. _vq_quantlist__44c8_s_p1_0,
  120128. NULL,
  120129. &_vq_auxt__44c8_s_p1_0,
  120130. NULL,
  120131. 0
  120132. };
  120133. static long _vq_quantlist__44c8_s_p2_0[] = {
  120134. 2,
  120135. 1,
  120136. 3,
  120137. 0,
  120138. 4,
  120139. };
  120140. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120141. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120142. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120143. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120144. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120145. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120146. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120147. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120148. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  120149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120150. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120151. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120152. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120153. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120154. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120155. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120156. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120158. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120159. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120160. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120161. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120162. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120163. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120164. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120166. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120167. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120168. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120169. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120170. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120171. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120172. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120177. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120178. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120179. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120180. 13,
  120181. };
  120182. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120183. -1.5, -0.5, 0.5, 1.5,
  120184. };
  120185. static long _vq_quantmap__44c8_s_p2_0[] = {
  120186. 3, 1, 0, 2, 4,
  120187. };
  120188. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120189. _vq_quantthresh__44c8_s_p2_0,
  120190. _vq_quantmap__44c8_s_p2_0,
  120191. 5,
  120192. 5
  120193. };
  120194. static static_codebook _44c8_s_p2_0 = {
  120195. 4, 625,
  120196. _vq_lengthlist__44c8_s_p2_0,
  120197. 1, -533725184, 1611661312, 3, 0,
  120198. _vq_quantlist__44c8_s_p2_0,
  120199. NULL,
  120200. &_vq_auxt__44c8_s_p2_0,
  120201. NULL,
  120202. 0
  120203. };
  120204. static long _vq_quantlist__44c8_s_p3_0[] = {
  120205. 4,
  120206. 3,
  120207. 5,
  120208. 2,
  120209. 6,
  120210. 1,
  120211. 7,
  120212. 0,
  120213. 8,
  120214. };
  120215. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120216. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120217. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120218. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120219. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120221. 0,
  120222. };
  120223. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120224. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120225. };
  120226. static long _vq_quantmap__44c8_s_p3_0[] = {
  120227. 7, 5, 3, 1, 0, 2, 4, 6,
  120228. 8,
  120229. };
  120230. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120231. _vq_quantthresh__44c8_s_p3_0,
  120232. _vq_quantmap__44c8_s_p3_0,
  120233. 9,
  120234. 9
  120235. };
  120236. static static_codebook _44c8_s_p3_0 = {
  120237. 2, 81,
  120238. _vq_lengthlist__44c8_s_p3_0,
  120239. 1, -531628032, 1611661312, 4, 0,
  120240. _vq_quantlist__44c8_s_p3_0,
  120241. NULL,
  120242. &_vq_auxt__44c8_s_p3_0,
  120243. NULL,
  120244. 0
  120245. };
  120246. static long _vq_quantlist__44c8_s_p4_0[] = {
  120247. 8,
  120248. 7,
  120249. 9,
  120250. 6,
  120251. 10,
  120252. 5,
  120253. 11,
  120254. 4,
  120255. 12,
  120256. 3,
  120257. 13,
  120258. 2,
  120259. 14,
  120260. 1,
  120261. 15,
  120262. 0,
  120263. 16,
  120264. };
  120265. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120266. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120267. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120268. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120269. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120270. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120271. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120272. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120273. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120274. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120275. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120284. 0,
  120285. };
  120286. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120287. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120288. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120289. };
  120290. static long _vq_quantmap__44c8_s_p4_0[] = {
  120291. 15, 13, 11, 9, 7, 5, 3, 1,
  120292. 0, 2, 4, 6, 8, 10, 12, 14,
  120293. 16,
  120294. };
  120295. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120296. _vq_quantthresh__44c8_s_p4_0,
  120297. _vq_quantmap__44c8_s_p4_0,
  120298. 17,
  120299. 17
  120300. };
  120301. static static_codebook _44c8_s_p4_0 = {
  120302. 2, 289,
  120303. _vq_lengthlist__44c8_s_p4_0,
  120304. 1, -529530880, 1611661312, 5, 0,
  120305. _vq_quantlist__44c8_s_p4_0,
  120306. NULL,
  120307. &_vq_auxt__44c8_s_p4_0,
  120308. NULL,
  120309. 0
  120310. };
  120311. static long _vq_quantlist__44c8_s_p5_0[] = {
  120312. 1,
  120313. 0,
  120314. 2,
  120315. };
  120316. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120317. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120318. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120319. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120320. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120321. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120322. 12,
  120323. };
  120324. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120325. -5.5, 5.5,
  120326. };
  120327. static long _vq_quantmap__44c8_s_p5_0[] = {
  120328. 1, 0, 2,
  120329. };
  120330. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120331. _vq_quantthresh__44c8_s_p5_0,
  120332. _vq_quantmap__44c8_s_p5_0,
  120333. 3,
  120334. 3
  120335. };
  120336. static static_codebook _44c8_s_p5_0 = {
  120337. 4, 81,
  120338. _vq_lengthlist__44c8_s_p5_0,
  120339. 1, -529137664, 1618345984, 2, 0,
  120340. _vq_quantlist__44c8_s_p5_0,
  120341. NULL,
  120342. &_vq_auxt__44c8_s_p5_0,
  120343. NULL,
  120344. 0
  120345. };
  120346. static long _vq_quantlist__44c8_s_p5_1[] = {
  120347. 5,
  120348. 4,
  120349. 6,
  120350. 3,
  120351. 7,
  120352. 2,
  120353. 8,
  120354. 1,
  120355. 9,
  120356. 0,
  120357. 10,
  120358. };
  120359. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120360. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120361. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120362. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120363. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120364. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120365. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120366. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120367. 11,11,11, 7, 7, 7, 7, 8, 8,
  120368. };
  120369. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120370. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120371. 3.5, 4.5,
  120372. };
  120373. static long _vq_quantmap__44c8_s_p5_1[] = {
  120374. 9, 7, 5, 3, 1, 0, 2, 4,
  120375. 6, 8, 10,
  120376. };
  120377. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120378. _vq_quantthresh__44c8_s_p5_1,
  120379. _vq_quantmap__44c8_s_p5_1,
  120380. 11,
  120381. 11
  120382. };
  120383. static static_codebook _44c8_s_p5_1 = {
  120384. 2, 121,
  120385. _vq_lengthlist__44c8_s_p5_1,
  120386. 1, -531365888, 1611661312, 4, 0,
  120387. _vq_quantlist__44c8_s_p5_1,
  120388. NULL,
  120389. &_vq_auxt__44c8_s_p5_1,
  120390. NULL,
  120391. 0
  120392. };
  120393. static long _vq_quantlist__44c8_s_p6_0[] = {
  120394. 6,
  120395. 5,
  120396. 7,
  120397. 4,
  120398. 8,
  120399. 3,
  120400. 9,
  120401. 2,
  120402. 10,
  120403. 1,
  120404. 11,
  120405. 0,
  120406. 12,
  120407. };
  120408. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120409. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120410. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120411. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120412. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120413. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120414. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120419. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120420. };
  120421. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120422. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120423. 12.5, 17.5, 22.5, 27.5,
  120424. };
  120425. static long _vq_quantmap__44c8_s_p6_0[] = {
  120426. 11, 9, 7, 5, 3, 1, 0, 2,
  120427. 4, 6, 8, 10, 12,
  120428. };
  120429. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120430. _vq_quantthresh__44c8_s_p6_0,
  120431. _vq_quantmap__44c8_s_p6_0,
  120432. 13,
  120433. 13
  120434. };
  120435. static static_codebook _44c8_s_p6_0 = {
  120436. 2, 169,
  120437. _vq_lengthlist__44c8_s_p6_0,
  120438. 1, -526516224, 1616117760, 4, 0,
  120439. _vq_quantlist__44c8_s_p6_0,
  120440. NULL,
  120441. &_vq_auxt__44c8_s_p6_0,
  120442. NULL,
  120443. 0
  120444. };
  120445. static long _vq_quantlist__44c8_s_p6_1[] = {
  120446. 2,
  120447. 1,
  120448. 3,
  120449. 0,
  120450. 4,
  120451. };
  120452. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120453. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120454. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120455. };
  120456. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120457. -1.5, -0.5, 0.5, 1.5,
  120458. };
  120459. static long _vq_quantmap__44c8_s_p6_1[] = {
  120460. 3, 1, 0, 2, 4,
  120461. };
  120462. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120463. _vq_quantthresh__44c8_s_p6_1,
  120464. _vq_quantmap__44c8_s_p6_1,
  120465. 5,
  120466. 5
  120467. };
  120468. static static_codebook _44c8_s_p6_1 = {
  120469. 2, 25,
  120470. _vq_lengthlist__44c8_s_p6_1,
  120471. 1, -533725184, 1611661312, 3, 0,
  120472. _vq_quantlist__44c8_s_p6_1,
  120473. NULL,
  120474. &_vq_auxt__44c8_s_p6_1,
  120475. NULL,
  120476. 0
  120477. };
  120478. static long _vq_quantlist__44c8_s_p7_0[] = {
  120479. 6,
  120480. 5,
  120481. 7,
  120482. 4,
  120483. 8,
  120484. 3,
  120485. 9,
  120486. 2,
  120487. 10,
  120488. 1,
  120489. 11,
  120490. 0,
  120491. 12,
  120492. };
  120493. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120494. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120495. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120496. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120497. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120498. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120499. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120500. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120501. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120502. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120503. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120504. 20,13,13,13,13,14,13,15,15,
  120505. };
  120506. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120507. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120508. 27.5, 38.5, 49.5, 60.5,
  120509. };
  120510. static long _vq_quantmap__44c8_s_p7_0[] = {
  120511. 11, 9, 7, 5, 3, 1, 0, 2,
  120512. 4, 6, 8, 10, 12,
  120513. };
  120514. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120515. _vq_quantthresh__44c8_s_p7_0,
  120516. _vq_quantmap__44c8_s_p7_0,
  120517. 13,
  120518. 13
  120519. };
  120520. static static_codebook _44c8_s_p7_0 = {
  120521. 2, 169,
  120522. _vq_lengthlist__44c8_s_p7_0,
  120523. 1, -523206656, 1618345984, 4, 0,
  120524. _vq_quantlist__44c8_s_p7_0,
  120525. NULL,
  120526. &_vq_auxt__44c8_s_p7_0,
  120527. NULL,
  120528. 0
  120529. };
  120530. static long _vq_quantlist__44c8_s_p7_1[] = {
  120531. 5,
  120532. 4,
  120533. 6,
  120534. 3,
  120535. 7,
  120536. 2,
  120537. 8,
  120538. 1,
  120539. 9,
  120540. 0,
  120541. 10,
  120542. };
  120543. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120544. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120545. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120546. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120547. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120548. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120549. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120550. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120551. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120552. };
  120553. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120554. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120555. 3.5, 4.5,
  120556. };
  120557. static long _vq_quantmap__44c8_s_p7_1[] = {
  120558. 9, 7, 5, 3, 1, 0, 2, 4,
  120559. 6, 8, 10,
  120560. };
  120561. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120562. _vq_quantthresh__44c8_s_p7_1,
  120563. _vq_quantmap__44c8_s_p7_1,
  120564. 11,
  120565. 11
  120566. };
  120567. static static_codebook _44c8_s_p7_1 = {
  120568. 2, 121,
  120569. _vq_lengthlist__44c8_s_p7_1,
  120570. 1, -531365888, 1611661312, 4, 0,
  120571. _vq_quantlist__44c8_s_p7_1,
  120572. NULL,
  120573. &_vq_auxt__44c8_s_p7_1,
  120574. NULL,
  120575. 0
  120576. };
  120577. static long _vq_quantlist__44c8_s_p8_0[] = {
  120578. 7,
  120579. 6,
  120580. 8,
  120581. 5,
  120582. 9,
  120583. 4,
  120584. 10,
  120585. 3,
  120586. 11,
  120587. 2,
  120588. 12,
  120589. 1,
  120590. 13,
  120591. 0,
  120592. 14,
  120593. };
  120594. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120595. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120596. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120597. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120598. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120599. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120600. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120601. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120602. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120603. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120604. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120605. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120606. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120607. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120608. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120609. 15,
  120610. };
  120611. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120612. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120613. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120614. };
  120615. static long _vq_quantmap__44c8_s_p8_0[] = {
  120616. 13, 11, 9, 7, 5, 3, 1, 0,
  120617. 2, 4, 6, 8, 10, 12, 14,
  120618. };
  120619. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120620. _vq_quantthresh__44c8_s_p8_0,
  120621. _vq_quantmap__44c8_s_p8_0,
  120622. 15,
  120623. 15
  120624. };
  120625. static static_codebook _44c8_s_p8_0 = {
  120626. 2, 225,
  120627. _vq_lengthlist__44c8_s_p8_0,
  120628. 1, -520986624, 1620377600, 4, 0,
  120629. _vq_quantlist__44c8_s_p8_0,
  120630. NULL,
  120631. &_vq_auxt__44c8_s_p8_0,
  120632. NULL,
  120633. 0
  120634. };
  120635. static long _vq_quantlist__44c8_s_p8_1[] = {
  120636. 10,
  120637. 9,
  120638. 11,
  120639. 8,
  120640. 12,
  120641. 7,
  120642. 13,
  120643. 6,
  120644. 14,
  120645. 5,
  120646. 15,
  120647. 4,
  120648. 16,
  120649. 3,
  120650. 17,
  120651. 2,
  120652. 18,
  120653. 1,
  120654. 19,
  120655. 0,
  120656. 20,
  120657. };
  120658. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120659. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120660. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120661. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120662. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120663. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120664. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120665. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120666. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120667. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120668. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120669. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120670. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120671. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120672. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120673. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120674. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120675. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120676. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120677. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120678. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120679. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120680. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120681. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120682. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120683. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120684. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120685. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120686. 10, 9, 9,10,10, 9,10, 9, 9,
  120687. };
  120688. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120689. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120690. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120691. 6.5, 7.5, 8.5, 9.5,
  120692. };
  120693. static long _vq_quantmap__44c8_s_p8_1[] = {
  120694. 19, 17, 15, 13, 11, 9, 7, 5,
  120695. 3, 1, 0, 2, 4, 6, 8, 10,
  120696. 12, 14, 16, 18, 20,
  120697. };
  120698. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120699. _vq_quantthresh__44c8_s_p8_1,
  120700. _vq_quantmap__44c8_s_p8_1,
  120701. 21,
  120702. 21
  120703. };
  120704. static static_codebook _44c8_s_p8_1 = {
  120705. 2, 441,
  120706. _vq_lengthlist__44c8_s_p8_1,
  120707. 1, -529268736, 1611661312, 5, 0,
  120708. _vq_quantlist__44c8_s_p8_1,
  120709. NULL,
  120710. &_vq_auxt__44c8_s_p8_1,
  120711. NULL,
  120712. 0
  120713. };
  120714. static long _vq_quantlist__44c8_s_p9_0[] = {
  120715. 8,
  120716. 7,
  120717. 9,
  120718. 6,
  120719. 10,
  120720. 5,
  120721. 11,
  120722. 4,
  120723. 12,
  120724. 3,
  120725. 13,
  120726. 2,
  120727. 14,
  120728. 1,
  120729. 15,
  120730. 0,
  120731. 16,
  120732. };
  120733. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120734. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120735. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120736. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120737. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120738. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120739. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120740. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120741. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120742. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120743. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120744. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120745. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120746. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120747. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120748. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120749. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120750. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120751. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120752. 10,
  120753. };
  120754. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120755. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120756. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120757. };
  120758. static long _vq_quantmap__44c8_s_p9_0[] = {
  120759. 15, 13, 11, 9, 7, 5, 3, 1,
  120760. 0, 2, 4, 6, 8, 10, 12, 14,
  120761. 16,
  120762. };
  120763. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120764. _vq_quantthresh__44c8_s_p9_0,
  120765. _vq_quantmap__44c8_s_p9_0,
  120766. 17,
  120767. 17
  120768. };
  120769. static static_codebook _44c8_s_p9_0 = {
  120770. 2, 289,
  120771. _vq_lengthlist__44c8_s_p9_0,
  120772. 1, -509798400, 1631393792, 5, 0,
  120773. _vq_quantlist__44c8_s_p9_0,
  120774. NULL,
  120775. &_vq_auxt__44c8_s_p9_0,
  120776. NULL,
  120777. 0
  120778. };
  120779. static long _vq_quantlist__44c8_s_p9_1[] = {
  120780. 9,
  120781. 8,
  120782. 10,
  120783. 7,
  120784. 11,
  120785. 6,
  120786. 12,
  120787. 5,
  120788. 13,
  120789. 4,
  120790. 14,
  120791. 3,
  120792. 15,
  120793. 2,
  120794. 16,
  120795. 1,
  120796. 17,
  120797. 0,
  120798. 18,
  120799. };
  120800. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120801. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120802. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120803. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120804. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120805. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120806. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120807. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120808. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120809. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120810. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120811. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120812. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120813. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120814. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120815. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120816. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120817. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120818. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120819. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120820. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120821. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120822. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120823. 14,13,13,14,14,15,14,15,14,
  120824. };
  120825. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120826. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120827. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120828. 367.5, 416.5,
  120829. };
  120830. static long _vq_quantmap__44c8_s_p9_1[] = {
  120831. 17, 15, 13, 11, 9, 7, 5, 3,
  120832. 1, 0, 2, 4, 6, 8, 10, 12,
  120833. 14, 16, 18,
  120834. };
  120835. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120836. _vq_quantthresh__44c8_s_p9_1,
  120837. _vq_quantmap__44c8_s_p9_1,
  120838. 19,
  120839. 19
  120840. };
  120841. static static_codebook _44c8_s_p9_1 = {
  120842. 2, 361,
  120843. _vq_lengthlist__44c8_s_p9_1,
  120844. 1, -518287360, 1622704128, 5, 0,
  120845. _vq_quantlist__44c8_s_p9_1,
  120846. NULL,
  120847. &_vq_auxt__44c8_s_p9_1,
  120848. NULL,
  120849. 0
  120850. };
  120851. static long _vq_quantlist__44c8_s_p9_2[] = {
  120852. 24,
  120853. 23,
  120854. 25,
  120855. 22,
  120856. 26,
  120857. 21,
  120858. 27,
  120859. 20,
  120860. 28,
  120861. 19,
  120862. 29,
  120863. 18,
  120864. 30,
  120865. 17,
  120866. 31,
  120867. 16,
  120868. 32,
  120869. 15,
  120870. 33,
  120871. 14,
  120872. 34,
  120873. 13,
  120874. 35,
  120875. 12,
  120876. 36,
  120877. 11,
  120878. 37,
  120879. 10,
  120880. 38,
  120881. 9,
  120882. 39,
  120883. 8,
  120884. 40,
  120885. 7,
  120886. 41,
  120887. 6,
  120888. 42,
  120889. 5,
  120890. 43,
  120891. 4,
  120892. 44,
  120893. 3,
  120894. 45,
  120895. 2,
  120896. 46,
  120897. 1,
  120898. 47,
  120899. 0,
  120900. 48,
  120901. };
  120902. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120903. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120904. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120905. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120906. 7,
  120907. };
  120908. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120909. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120910. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120911. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120912. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120913. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120914. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120915. };
  120916. static long _vq_quantmap__44c8_s_p9_2[] = {
  120917. 47, 45, 43, 41, 39, 37, 35, 33,
  120918. 31, 29, 27, 25, 23, 21, 19, 17,
  120919. 15, 13, 11, 9, 7, 5, 3, 1,
  120920. 0, 2, 4, 6, 8, 10, 12, 14,
  120921. 16, 18, 20, 22, 24, 26, 28, 30,
  120922. 32, 34, 36, 38, 40, 42, 44, 46,
  120923. 48,
  120924. };
  120925. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120926. _vq_quantthresh__44c8_s_p9_2,
  120927. _vq_quantmap__44c8_s_p9_2,
  120928. 49,
  120929. 49
  120930. };
  120931. static static_codebook _44c8_s_p9_2 = {
  120932. 1, 49,
  120933. _vq_lengthlist__44c8_s_p9_2,
  120934. 1, -526909440, 1611661312, 6, 0,
  120935. _vq_quantlist__44c8_s_p9_2,
  120936. NULL,
  120937. &_vq_auxt__44c8_s_p9_2,
  120938. NULL,
  120939. 0
  120940. };
  120941. static long _huff_lengthlist__44c8_s_short[] = {
  120942. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120943. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120944. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120945. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120946. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120947. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120948. 10, 9,11,14,
  120949. };
  120950. static static_codebook _huff_book__44c8_s_short = {
  120951. 2, 100,
  120952. _huff_lengthlist__44c8_s_short,
  120953. 0, 0, 0, 0, 0,
  120954. NULL,
  120955. NULL,
  120956. NULL,
  120957. NULL,
  120958. 0
  120959. };
  120960. static long _huff_lengthlist__44c9_s_long[] = {
  120961. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120962. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120963. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120964. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120965. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120966. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120967. 10, 9, 8, 9,
  120968. };
  120969. static static_codebook _huff_book__44c9_s_long = {
  120970. 2, 100,
  120971. _huff_lengthlist__44c9_s_long,
  120972. 0, 0, 0, 0, 0,
  120973. NULL,
  120974. NULL,
  120975. NULL,
  120976. NULL,
  120977. 0
  120978. };
  120979. static long _vq_quantlist__44c9_s_p1_0[] = {
  120980. 1,
  120981. 0,
  120982. 2,
  120983. };
  120984. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120985. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120986. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120987. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120988. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120989. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120990. 7,
  120991. };
  120992. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120993. -0.5, 0.5,
  120994. };
  120995. static long _vq_quantmap__44c9_s_p1_0[] = {
  120996. 1, 0, 2,
  120997. };
  120998. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120999. _vq_quantthresh__44c9_s_p1_0,
  121000. _vq_quantmap__44c9_s_p1_0,
  121001. 3,
  121002. 3
  121003. };
  121004. static static_codebook _44c9_s_p1_0 = {
  121005. 4, 81,
  121006. _vq_lengthlist__44c9_s_p1_0,
  121007. 1, -535822336, 1611661312, 2, 0,
  121008. _vq_quantlist__44c9_s_p1_0,
  121009. NULL,
  121010. &_vq_auxt__44c9_s_p1_0,
  121011. NULL,
  121012. 0
  121013. };
  121014. static long _vq_quantlist__44c9_s_p2_0[] = {
  121015. 2,
  121016. 1,
  121017. 3,
  121018. 0,
  121019. 4,
  121020. };
  121021. static long _vq_lengthlist__44c9_s_p2_0[] = {
  121022. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  121023. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  121024. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  121025. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  121026. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  121027. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  121028. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  121029. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  121030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121031. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  121032. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  121033. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  121034. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  121035. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  121036. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  121037. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  121038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121039. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  121040. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  121041. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  121042. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  121043. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  121044. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  121045. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121047. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  121048. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  121049. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  121050. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  121051. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  121052. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  121053. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  121058. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  121059. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  121060. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  121061. 12,
  121062. };
  121063. static float _vq_quantthresh__44c9_s_p2_0[] = {
  121064. -1.5, -0.5, 0.5, 1.5,
  121065. };
  121066. static long _vq_quantmap__44c9_s_p2_0[] = {
  121067. 3, 1, 0, 2, 4,
  121068. };
  121069. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  121070. _vq_quantthresh__44c9_s_p2_0,
  121071. _vq_quantmap__44c9_s_p2_0,
  121072. 5,
  121073. 5
  121074. };
  121075. static static_codebook _44c9_s_p2_0 = {
  121076. 4, 625,
  121077. _vq_lengthlist__44c9_s_p2_0,
  121078. 1, -533725184, 1611661312, 3, 0,
  121079. _vq_quantlist__44c9_s_p2_0,
  121080. NULL,
  121081. &_vq_auxt__44c9_s_p2_0,
  121082. NULL,
  121083. 0
  121084. };
  121085. static long _vq_quantlist__44c9_s_p3_0[] = {
  121086. 4,
  121087. 3,
  121088. 5,
  121089. 2,
  121090. 6,
  121091. 1,
  121092. 7,
  121093. 0,
  121094. 8,
  121095. };
  121096. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121097. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121098. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121099. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121100. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121102. 0,
  121103. };
  121104. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121105. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121106. };
  121107. static long _vq_quantmap__44c9_s_p3_0[] = {
  121108. 7, 5, 3, 1, 0, 2, 4, 6,
  121109. 8,
  121110. };
  121111. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121112. _vq_quantthresh__44c9_s_p3_0,
  121113. _vq_quantmap__44c9_s_p3_0,
  121114. 9,
  121115. 9
  121116. };
  121117. static static_codebook _44c9_s_p3_0 = {
  121118. 2, 81,
  121119. _vq_lengthlist__44c9_s_p3_0,
  121120. 1, -531628032, 1611661312, 4, 0,
  121121. _vq_quantlist__44c9_s_p3_0,
  121122. NULL,
  121123. &_vq_auxt__44c9_s_p3_0,
  121124. NULL,
  121125. 0
  121126. };
  121127. static long _vq_quantlist__44c9_s_p4_0[] = {
  121128. 8,
  121129. 7,
  121130. 9,
  121131. 6,
  121132. 10,
  121133. 5,
  121134. 11,
  121135. 4,
  121136. 12,
  121137. 3,
  121138. 13,
  121139. 2,
  121140. 14,
  121141. 1,
  121142. 15,
  121143. 0,
  121144. 16,
  121145. };
  121146. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121147. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121148. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121149. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121150. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121151. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121152. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121153. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121154. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121155. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121156. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121165. 0,
  121166. };
  121167. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121168. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121169. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121170. };
  121171. static long _vq_quantmap__44c9_s_p4_0[] = {
  121172. 15, 13, 11, 9, 7, 5, 3, 1,
  121173. 0, 2, 4, 6, 8, 10, 12, 14,
  121174. 16,
  121175. };
  121176. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121177. _vq_quantthresh__44c9_s_p4_0,
  121178. _vq_quantmap__44c9_s_p4_0,
  121179. 17,
  121180. 17
  121181. };
  121182. static static_codebook _44c9_s_p4_0 = {
  121183. 2, 289,
  121184. _vq_lengthlist__44c9_s_p4_0,
  121185. 1, -529530880, 1611661312, 5, 0,
  121186. _vq_quantlist__44c9_s_p4_0,
  121187. NULL,
  121188. &_vq_auxt__44c9_s_p4_0,
  121189. NULL,
  121190. 0
  121191. };
  121192. static long _vq_quantlist__44c9_s_p5_0[] = {
  121193. 1,
  121194. 0,
  121195. 2,
  121196. };
  121197. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121198. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121199. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121200. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121201. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121202. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121203. 12,
  121204. };
  121205. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121206. -5.5, 5.5,
  121207. };
  121208. static long _vq_quantmap__44c9_s_p5_0[] = {
  121209. 1, 0, 2,
  121210. };
  121211. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121212. _vq_quantthresh__44c9_s_p5_0,
  121213. _vq_quantmap__44c9_s_p5_0,
  121214. 3,
  121215. 3
  121216. };
  121217. static static_codebook _44c9_s_p5_0 = {
  121218. 4, 81,
  121219. _vq_lengthlist__44c9_s_p5_0,
  121220. 1, -529137664, 1618345984, 2, 0,
  121221. _vq_quantlist__44c9_s_p5_0,
  121222. NULL,
  121223. &_vq_auxt__44c9_s_p5_0,
  121224. NULL,
  121225. 0
  121226. };
  121227. static long _vq_quantlist__44c9_s_p5_1[] = {
  121228. 5,
  121229. 4,
  121230. 6,
  121231. 3,
  121232. 7,
  121233. 2,
  121234. 8,
  121235. 1,
  121236. 9,
  121237. 0,
  121238. 10,
  121239. };
  121240. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121241. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121242. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121243. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121244. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121245. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121246. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121247. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121248. 11,11,11, 7, 7, 7, 7, 7, 7,
  121249. };
  121250. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121251. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121252. 3.5, 4.5,
  121253. };
  121254. static long _vq_quantmap__44c9_s_p5_1[] = {
  121255. 9, 7, 5, 3, 1, 0, 2, 4,
  121256. 6, 8, 10,
  121257. };
  121258. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121259. _vq_quantthresh__44c9_s_p5_1,
  121260. _vq_quantmap__44c9_s_p5_1,
  121261. 11,
  121262. 11
  121263. };
  121264. static static_codebook _44c9_s_p5_1 = {
  121265. 2, 121,
  121266. _vq_lengthlist__44c9_s_p5_1,
  121267. 1, -531365888, 1611661312, 4, 0,
  121268. _vq_quantlist__44c9_s_p5_1,
  121269. NULL,
  121270. &_vq_auxt__44c9_s_p5_1,
  121271. NULL,
  121272. 0
  121273. };
  121274. static long _vq_quantlist__44c9_s_p6_0[] = {
  121275. 6,
  121276. 5,
  121277. 7,
  121278. 4,
  121279. 8,
  121280. 3,
  121281. 9,
  121282. 2,
  121283. 10,
  121284. 1,
  121285. 11,
  121286. 0,
  121287. 12,
  121288. };
  121289. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121290. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121291. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121292. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121293. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121294. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121295. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121300. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121301. };
  121302. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121303. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121304. 12.5, 17.5, 22.5, 27.5,
  121305. };
  121306. static long _vq_quantmap__44c9_s_p6_0[] = {
  121307. 11, 9, 7, 5, 3, 1, 0, 2,
  121308. 4, 6, 8, 10, 12,
  121309. };
  121310. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121311. _vq_quantthresh__44c9_s_p6_0,
  121312. _vq_quantmap__44c9_s_p6_0,
  121313. 13,
  121314. 13
  121315. };
  121316. static static_codebook _44c9_s_p6_0 = {
  121317. 2, 169,
  121318. _vq_lengthlist__44c9_s_p6_0,
  121319. 1, -526516224, 1616117760, 4, 0,
  121320. _vq_quantlist__44c9_s_p6_0,
  121321. NULL,
  121322. &_vq_auxt__44c9_s_p6_0,
  121323. NULL,
  121324. 0
  121325. };
  121326. static long _vq_quantlist__44c9_s_p6_1[] = {
  121327. 2,
  121328. 1,
  121329. 3,
  121330. 0,
  121331. 4,
  121332. };
  121333. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121334. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121335. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121336. };
  121337. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121338. -1.5, -0.5, 0.5, 1.5,
  121339. };
  121340. static long _vq_quantmap__44c9_s_p6_1[] = {
  121341. 3, 1, 0, 2, 4,
  121342. };
  121343. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121344. _vq_quantthresh__44c9_s_p6_1,
  121345. _vq_quantmap__44c9_s_p6_1,
  121346. 5,
  121347. 5
  121348. };
  121349. static static_codebook _44c9_s_p6_1 = {
  121350. 2, 25,
  121351. _vq_lengthlist__44c9_s_p6_1,
  121352. 1, -533725184, 1611661312, 3, 0,
  121353. _vq_quantlist__44c9_s_p6_1,
  121354. NULL,
  121355. &_vq_auxt__44c9_s_p6_1,
  121356. NULL,
  121357. 0
  121358. };
  121359. static long _vq_quantlist__44c9_s_p7_0[] = {
  121360. 6,
  121361. 5,
  121362. 7,
  121363. 4,
  121364. 8,
  121365. 3,
  121366. 9,
  121367. 2,
  121368. 10,
  121369. 1,
  121370. 11,
  121371. 0,
  121372. 12,
  121373. };
  121374. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121375. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121376. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121377. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121378. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121379. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121380. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121381. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121382. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121383. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121384. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121385. 19,12,12,12,12,13,13,14,14,
  121386. };
  121387. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121388. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121389. 27.5, 38.5, 49.5, 60.5,
  121390. };
  121391. static long _vq_quantmap__44c9_s_p7_0[] = {
  121392. 11, 9, 7, 5, 3, 1, 0, 2,
  121393. 4, 6, 8, 10, 12,
  121394. };
  121395. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121396. _vq_quantthresh__44c9_s_p7_0,
  121397. _vq_quantmap__44c9_s_p7_0,
  121398. 13,
  121399. 13
  121400. };
  121401. static static_codebook _44c9_s_p7_0 = {
  121402. 2, 169,
  121403. _vq_lengthlist__44c9_s_p7_0,
  121404. 1, -523206656, 1618345984, 4, 0,
  121405. _vq_quantlist__44c9_s_p7_0,
  121406. NULL,
  121407. &_vq_auxt__44c9_s_p7_0,
  121408. NULL,
  121409. 0
  121410. };
  121411. static long _vq_quantlist__44c9_s_p7_1[] = {
  121412. 5,
  121413. 4,
  121414. 6,
  121415. 3,
  121416. 7,
  121417. 2,
  121418. 8,
  121419. 1,
  121420. 9,
  121421. 0,
  121422. 10,
  121423. };
  121424. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121425. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121426. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121427. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121428. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121429. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121430. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121431. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121432. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121433. };
  121434. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121435. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121436. 3.5, 4.5,
  121437. };
  121438. static long _vq_quantmap__44c9_s_p7_1[] = {
  121439. 9, 7, 5, 3, 1, 0, 2, 4,
  121440. 6, 8, 10,
  121441. };
  121442. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121443. _vq_quantthresh__44c9_s_p7_1,
  121444. _vq_quantmap__44c9_s_p7_1,
  121445. 11,
  121446. 11
  121447. };
  121448. static static_codebook _44c9_s_p7_1 = {
  121449. 2, 121,
  121450. _vq_lengthlist__44c9_s_p7_1,
  121451. 1, -531365888, 1611661312, 4, 0,
  121452. _vq_quantlist__44c9_s_p7_1,
  121453. NULL,
  121454. &_vq_auxt__44c9_s_p7_1,
  121455. NULL,
  121456. 0
  121457. };
  121458. static long _vq_quantlist__44c9_s_p8_0[] = {
  121459. 7,
  121460. 6,
  121461. 8,
  121462. 5,
  121463. 9,
  121464. 4,
  121465. 10,
  121466. 3,
  121467. 11,
  121468. 2,
  121469. 12,
  121470. 1,
  121471. 13,
  121472. 0,
  121473. 14,
  121474. };
  121475. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121476. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121477. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121478. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121479. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121480. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121481. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121482. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121483. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121484. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121485. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121486. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121487. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121488. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121489. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121490. 14,
  121491. };
  121492. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121493. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121494. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121495. };
  121496. static long _vq_quantmap__44c9_s_p8_0[] = {
  121497. 13, 11, 9, 7, 5, 3, 1, 0,
  121498. 2, 4, 6, 8, 10, 12, 14,
  121499. };
  121500. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121501. _vq_quantthresh__44c9_s_p8_0,
  121502. _vq_quantmap__44c9_s_p8_0,
  121503. 15,
  121504. 15
  121505. };
  121506. static static_codebook _44c9_s_p8_0 = {
  121507. 2, 225,
  121508. _vq_lengthlist__44c9_s_p8_0,
  121509. 1, -520986624, 1620377600, 4, 0,
  121510. _vq_quantlist__44c9_s_p8_0,
  121511. NULL,
  121512. &_vq_auxt__44c9_s_p8_0,
  121513. NULL,
  121514. 0
  121515. };
  121516. static long _vq_quantlist__44c9_s_p8_1[] = {
  121517. 10,
  121518. 9,
  121519. 11,
  121520. 8,
  121521. 12,
  121522. 7,
  121523. 13,
  121524. 6,
  121525. 14,
  121526. 5,
  121527. 15,
  121528. 4,
  121529. 16,
  121530. 3,
  121531. 17,
  121532. 2,
  121533. 18,
  121534. 1,
  121535. 19,
  121536. 0,
  121537. 20,
  121538. };
  121539. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121540. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121541. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121542. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121543. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121544. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121545. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121546. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121547. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121548. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121549. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121550. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121551. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121552. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121553. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121554. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121555. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121556. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121557. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121558. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121559. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121560. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121561. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121562. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121563. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121564. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121565. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121566. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121567. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121568. };
  121569. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121570. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121571. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121572. 6.5, 7.5, 8.5, 9.5,
  121573. };
  121574. static long _vq_quantmap__44c9_s_p8_1[] = {
  121575. 19, 17, 15, 13, 11, 9, 7, 5,
  121576. 3, 1, 0, 2, 4, 6, 8, 10,
  121577. 12, 14, 16, 18, 20,
  121578. };
  121579. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121580. _vq_quantthresh__44c9_s_p8_1,
  121581. _vq_quantmap__44c9_s_p8_1,
  121582. 21,
  121583. 21
  121584. };
  121585. static static_codebook _44c9_s_p8_1 = {
  121586. 2, 441,
  121587. _vq_lengthlist__44c9_s_p8_1,
  121588. 1, -529268736, 1611661312, 5, 0,
  121589. _vq_quantlist__44c9_s_p8_1,
  121590. NULL,
  121591. &_vq_auxt__44c9_s_p8_1,
  121592. NULL,
  121593. 0
  121594. };
  121595. static long _vq_quantlist__44c9_s_p9_0[] = {
  121596. 9,
  121597. 8,
  121598. 10,
  121599. 7,
  121600. 11,
  121601. 6,
  121602. 12,
  121603. 5,
  121604. 13,
  121605. 4,
  121606. 14,
  121607. 3,
  121608. 15,
  121609. 2,
  121610. 16,
  121611. 1,
  121612. 17,
  121613. 0,
  121614. 18,
  121615. };
  121616. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121617. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121618. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121619. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121620. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121621. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121622. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121623. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121624. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121625. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121626. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121627. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121628. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121629. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121630. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121631. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121632. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121633. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121634. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121635. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121636. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121637. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121638. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121639. 11,11,11,11,11,11,11,11,11,
  121640. };
  121641. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121642. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121643. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121644. 6982.5, 7913.5,
  121645. };
  121646. static long _vq_quantmap__44c9_s_p9_0[] = {
  121647. 17, 15, 13, 11, 9, 7, 5, 3,
  121648. 1, 0, 2, 4, 6, 8, 10, 12,
  121649. 14, 16, 18,
  121650. };
  121651. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121652. _vq_quantthresh__44c9_s_p9_0,
  121653. _vq_quantmap__44c9_s_p9_0,
  121654. 19,
  121655. 19
  121656. };
  121657. static static_codebook _44c9_s_p9_0 = {
  121658. 2, 361,
  121659. _vq_lengthlist__44c9_s_p9_0,
  121660. 1, -508535424, 1631393792, 5, 0,
  121661. _vq_quantlist__44c9_s_p9_0,
  121662. NULL,
  121663. &_vq_auxt__44c9_s_p9_0,
  121664. NULL,
  121665. 0
  121666. };
  121667. static long _vq_quantlist__44c9_s_p9_1[] = {
  121668. 9,
  121669. 8,
  121670. 10,
  121671. 7,
  121672. 11,
  121673. 6,
  121674. 12,
  121675. 5,
  121676. 13,
  121677. 4,
  121678. 14,
  121679. 3,
  121680. 15,
  121681. 2,
  121682. 16,
  121683. 1,
  121684. 17,
  121685. 0,
  121686. 18,
  121687. };
  121688. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121689. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121690. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121691. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121692. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121693. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121694. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121695. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121696. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121697. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121698. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121699. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121700. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121701. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121702. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121703. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121704. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121705. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121706. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121707. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121708. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121709. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121710. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121711. 13,13,13,14,13,14,15,15,15,
  121712. };
  121713. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121714. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121715. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121716. 367.5, 416.5,
  121717. };
  121718. static long _vq_quantmap__44c9_s_p9_1[] = {
  121719. 17, 15, 13, 11, 9, 7, 5, 3,
  121720. 1, 0, 2, 4, 6, 8, 10, 12,
  121721. 14, 16, 18,
  121722. };
  121723. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121724. _vq_quantthresh__44c9_s_p9_1,
  121725. _vq_quantmap__44c9_s_p9_1,
  121726. 19,
  121727. 19
  121728. };
  121729. static static_codebook _44c9_s_p9_1 = {
  121730. 2, 361,
  121731. _vq_lengthlist__44c9_s_p9_1,
  121732. 1, -518287360, 1622704128, 5, 0,
  121733. _vq_quantlist__44c9_s_p9_1,
  121734. NULL,
  121735. &_vq_auxt__44c9_s_p9_1,
  121736. NULL,
  121737. 0
  121738. };
  121739. static long _vq_quantlist__44c9_s_p9_2[] = {
  121740. 24,
  121741. 23,
  121742. 25,
  121743. 22,
  121744. 26,
  121745. 21,
  121746. 27,
  121747. 20,
  121748. 28,
  121749. 19,
  121750. 29,
  121751. 18,
  121752. 30,
  121753. 17,
  121754. 31,
  121755. 16,
  121756. 32,
  121757. 15,
  121758. 33,
  121759. 14,
  121760. 34,
  121761. 13,
  121762. 35,
  121763. 12,
  121764. 36,
  121765. 11,
  121766. 37,
  121767. 10,
  121768. 38,
  121769. 9,
  121770. 39,
  121771. 8,
  121772. 40,
  121773. 7,
  121774. 41,
  121775. 6,
  121776. 42,
  121777. 5,
  121778. 43,
  121779. 4,
  121780. 44,
  121781. 3,
  121782. 45,
  121783. 2,
  121784. 46,
  121785. 1,
  121786. 47,
  121787. 0,
  121788. 48,
  121789. };
  121790. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121791. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121792. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121793. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121794. 7,
  121795. };
  121796. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121797. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121798. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121799. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121800. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121801. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121802. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121803. };
  121804. static long _vq_quantmap__44c9_s_p9_2[] = {
  121805. 47, 45, 43, 41, 39, 37, 35, 33,
  121806. 31, 29, 27, 25, 23, 21, 19, 17,
  121807. 15, 13, 11, 9, 7, 5, 3, 1,
  121808. 0, 2, 4, 6, 8, 10, 12, 14,
  121809. 16, 18, 20, 22, 24, 26, 28, 30,
  121810. 32, 34, 36, 38, 40, 42, 44, 46,
  121811. 48,
  121812. };
  121813. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121814. _vq_quantthresh__44c9_s_p9_2,
  121815. _vq_quantmap__44c9_s_p9_2,
  121816. 49,
  121817. 49
  121818. };
  121819. static static_codebook _44c9_s_p9_2 = {
  121820. 1, 49,
  121821. _vq_lengthlist__44c9_s_p9_2,
  121822. 1, -526909440, 1611661312, 6, 0,
  121823. _vq_quantlist__44c9_s_p9_2,
  121824. NULL,
  121825. &_vq_auxt__44c9_s_p9_2,
  121826. NULL,
  121827. 0
  121828. };
  121829. static long _huff_lengthlist__44c9_s_short[] = {
  121830. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121831. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121832. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121833. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121834. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121835. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121836. 9, 8,10,13,
  121837. };
  121838. static static_codebook _huff_book__44c9_s_short = {
  121839. 2, 100,
  121840. _huff_lengthlist__44c9_s_short,
  121841. 0, 0, 0, 0, 0,
  121842. NULL,
  121843. NULL,
  121844. NULL,
  121845. NULL,
  121846. 0
  121847. };
  121848. static long _huff_lengthlist__44c0_s_long[] = {
  121849. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121850. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121851. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121852. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121853. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121854. 12,
  121855. };
  121856. static static_codebook _huff_book__44c0_s_long = {
  121857. 2, 81,
  121858. _huff_lengthlist__44c0_s_long,
  121859. 0, 0, 0, 0, 0,
  121860. NULL,
  121861. NULL,
  121862. NULL,
  121863. NULL,
  121864. 0
  121865. };
  121866. static long _vq_quantlist__44c0_s_p1_0[] = {
  121867. 1,
  121868. 0,
  121869. 2,
  121870. };
  121871. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121872. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121873. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121878. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121883. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121918. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121923. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121928. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121963. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121964. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121969. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  121970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121973. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121974. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122282. 0,
  122283. };
  122284. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122285. -0.5, 0.5,
  122286. };
  122287. static long _vq_quantmap__44c0_s_p1_0[] = {
  122288. 1, 0, 2,
  122289. };
  122290. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122291. _vq_quantthresh__44c0_s_p1_0,
  122292. _vq_quantmap__44c0_s_p1_0,
  122293. 3,
  122294. 3
  122295. };
  122296. static static_codebook _44c0_s_p1_0 = {
  122297. 8, 6561,
  122298. _vq_lengthlist__44c0_s_p1_0,
  122299. 1, -535822336, 1611661312, 2, 0,
  122300. _vq_quantlist__44c0_s_p1_0,
  122301. NULL,
  122302. &_vq_auxt__44c0_s_p1_0,
  122303. NULL,
  122304. 0
  122305. };
  122306. static long _vq_quantlist__44c0_s_p2_0[] = {
  122307. 2,
  122308. 1,
  122309. 3,
  122310. 0,
  122311. 4,
  122312. };
  122313. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122314. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122317. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122320. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122353. 0,
  122354. };
  122355. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122356. -1.5, -0.5, 0.5, 1.5,
  122357. };
  122358. static long _vq_quantmap__44c0_s_p2_0[] = {
  122359. 3, 1, 0, 2, 4,
  122360. };
  122361. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122362. _vq_quantthresh__44c0_s_p2_0,
  122363. _vq_quantmap__44c0_s_p2_0,
  122364. 5,
  122365. 5
  122366. };
  122367. static static_codebook _44c0_s_p2_0 = {
  122368. 4, 625,
  122369. _vq_lengthlist__44c0_s_p2_0,
  122370. 1, -533725184, 1611661312, 3, 0,
  122371. _vq_quantlist__44c0_s_p2_0,
  122372. NULL,
  122373. &_vq_auxt__44c0_s_p2_0,
  122374. NULL,
  122375. 0
  122376. };
  122377. static long _vq_quantlist__44c0_s_p3_0[] = {
  122378. 4,
  122379. 3,
  122380. 5,
  122381. 2,
  122382. 6,
  122383. 1,
  122384. 7,
  122385. 0,
  122386. 8,
  122387. };
  122388. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122389. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122390. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122391. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122392. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122393. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122394. 0,
  122395. };
  122396. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122397. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122398. };
  122399. static long _vq_quantmap__44c0_s_p3_0[] = {
  122400. 7, 5, 3, 1, 0, 2, 4, 6,
  122401. 8,
  122402. };
  122403. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122404. _vq_quantthresh__44c0_s_p3_0,
  122405. _vq_quantmap__44c0_s_p3_0,
  122406. 9,
  122407. 9
  122408. };
  122409. static static_codebook _44c0_s_p3_0 = {
  122410. 2, 81,
  122411. _vq_lengthlist__44c0_s_p3_0,
  122412. 1, -531628032, 1611661312, 4, 0,
  122413. _vq_quantlist__44c0_s_p3_0,
  122414. NULL,
  122415. &_vq_auxt__44c0_s_p3_0,
  122416. NULL,
  122417. 0
  122418. };
  122419. static long _vq_quantlist__44c0_s_p4_0[] = {
  122420. 4,
  122421. 3,
  122422. 5,
  122423. 2,
  122424. 6,
  122425. 1,
  122426. 7,
  122427. 0,
  122428. 8,
  122429. };
  122430. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122431. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122432. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122433. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122434. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122435. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122436. 10,
  122437. };
  122438. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122439. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122440. };
  122441. static long _vq_quantmap__44c0_s_p4_0[] = {
  122442. 7, 5, 3, 1, 0, 2, 4, 6,
  122443. 8,
  122444. };
  122445. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122446. _vq_quantthresh__44c0_s_p4_0,
  122447. _vq_quantmap__44c0_s_p4_0,
  122448. 9,
  122449. 9
  122450. };
  122451. static static_codebook _44c0_s_p4_0 = {
  122452. 2, 81,
  122453. _vq_lengthlist__44c0_s_p4_0,
  122454. 1, -531628032, 1611661312, 4, 0,
  122455. _vq_quantlist__44c0_s_p4_0,
  122456. NULL,
  122457. &_vq_auxt__44c0_s_p4_0,
  122458. NULL,
  122459. 0
  122460. };
  122461. static long _vq_quantlist__44c0_s_p5_0[] = {
  122462. 8,
  122463. 7,
  122464. 9,
  122465. 6,
  122466. 10,
  122467. 5,
  122468. 11,
  122469. 4,
  122470. 12,
  122471. 3,
  122472. 13,
  122473. 2,
  122474. 14,
  122475. 1,
  122476. 15,
  122477. 0,
  122478. 16,
  122479. };
  122480. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122481. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122482. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122483. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122484. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122485. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122486. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122487. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122488. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122489. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122490. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122491. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122492. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122493. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122494. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122495. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122496. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122497. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122498. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122499. 14,
  122500. };
  122501. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122502. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122503. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122504. };
  122505. static long _vq_quantmap__44c0_s_p5_0[] = {
  122506. 15, 13, 11, 9, 7, 5, 3, 1,
  122507. 0, 2, 4, 6, 8, 10, 12, 14,
  122508. 16,
  122509. };
  122510. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122511. _vq_quantthresh__44c0_s_p5_0,
  122512. _vq_quantmap__44c0_s_p5_0,
  122513. 17,
  122514. 17
  122515. };
  122516. static static_codebook _44c0_s_p5_0 = {
  122517. 2, 289,
  122518. _vq_lengthlist__44c0_s_p5_0,
  122519. 1, -529530880, 1611661312, 5, 0,
  122520. _vq_quantlist__44c0_s_p5_0,
  122521. NULL,
  122522. &_vq_auxt__44c0_s_p5_0,
  122523. NULL,
  122524. 0
  122525. };
  122526. static long _vq_quantlist__44c0_s_p6_0[] = {
  122527. 1,
  122528. 0,
  122529. 2,
  122530. };
  122531. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122532. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122533. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122534. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122535. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122536. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122537. 10,
  122538. };
  122539. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122540. -5.5, 5.5,
  122541. };
  122542. static long _vq_quantmap__44c0_s_p6_0[] = {
  122543. 1, 0, 2,
  122544. };
  122545. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122546. _vq_quantthresh__44c0_s_p6_0,
  122547. _vq_quantmap__44c0_s_p6_0,
  122548. 3,
  122549. 3
  122550. };
  122551. static static_codebook _44c0_s_p6_0 = {
  122552. 4, 81,
  122553. _vq_lengthlist__44c0_s_p6_0,
  122554. 1, -529137664, 1618345984, 2, 0,
  122555. _vq_quantlist__44c0_s_p6_0,
  122556. NULL,
  122557. &_vq_auxt__44c0_s_p6_0,
  122558. NULL,
  122559. 0
  122560. };
  122561. static long _vq_quantlist__44c0_s_p6_1[] = {
  122562. 5,
  122563. 4,
  122564. 6,
  122565. 3,
  122566. 7,
  122567. 2,
  122568. 8,
  122569. 1,
  122570. 9,
  122571. 0,
  122572. 10,
  122573. };
  122574. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122575. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122576. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122577. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122578. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122579. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122580. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122581. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122582. 10,10,10, 8, 8, 8, 8, 8, 8,
  122583. };
  122584. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122585. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122586. 3.5, 4.5,
  122587. };
  122588. static long _vq_quantmap__44c0_s_p6_1[] = {
  122589. 9, 7, 5, 3, 1, 0, 2, 4,
  122590. 6, 8, 10,
  122591. };
  122592. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122593. _vq_quantthresh__44c0_s_p6_1,
  122594. _vq_quantmap__44c0_s_p6_1,
  122595. 11,
  122596. 11
  122597. };
  122598. static static_codebook _44c0_s_p6_1 = {
  122599. 2, 121,
  122600. _vq_lengthlist__44c0_s_p6_1,
  122601. 1, -531365888, 1611661312, 4, 0,
  122602. _vq_quantlist__44c0_s_p6_1,
  122603. NULL,
  122604. &_vq_auxt__44c0_s_p6_1,
  122605. NULL,
  122606. 0
  122607. };
  122608. static long _vq_quantlist__44c0_s_p7_0[] = {
  122609. 6,
  122610. 5,
  122611. 7,
  122612. 4,
  122613. 8,
  122614. 3,
  122615. 9,
  122616. 2,
  122617. 10,
  122618. 1,
  122619. 11,
  122620. 0,
  122621. 12,
  122622. };
  122623. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122624. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122625. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122626. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122627. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122628. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122629. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122630. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122631. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122632. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122633. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122634. 0,12,12,11,11,12,12,13,13,
  122635. };
  122636. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122637. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122638. 12.5, 17.5, 22.5, 27.5,
  122639. };
  122640. static long _vq_quantmap__44c0_s_p7_0[] = {
  122641. 11, 9, 7, 5, 3, 1, 0, 2,
  122642. 4, 6, 8, 10, 12,
  122643. };
  122644. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122645. _vq_quantthresh__44c0_s_p7_0,
  122646. _vq_quantmap__44c0_s_p7_0,
  122647. 13,
  122648. 13
  122649. };
  122650. static static_codebook _44c0_s_p7_0 = {
  122651. 2, 169,
  122652. _vq_lengthlist__44c0_s_p7_0,
  122653. 1, -526516224, 1616117760, 4, 0,
  122654. _vq_quantlist__44c0_s_p7_0,
  122655. NULL,
  122656. &_vq_auxt__44c0_s_p7_0,
  122657. NULL,
  122658. 0
  122659. };
  122660. static long _vq_quantlist__44c0_s_p7_1[] = {
  122661. 2,
  122662. 1,
  122663. 3,
  122664. 0,
  122665. 4,
  122666. };
  122667. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122668. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122669. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122670. };
  122671. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122672. -1.5, -0.5, 0.5, 1.5,
  122673. };
  122674. static long _vq_quantmap__44c0_s_p7_1[] = {
  122675. 3, 1, 0, 2, 4,
  122676. };
  122677. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122678. _vq_quantthresh__44c0_s_p7_1,
  122679. _vq_quantmap__44c0_s_p7_1,
  122680. 5,
  122681. 5
  122682. };
  122683. static static_codebook _44c0_s_p7_1 = {
  122684. 2, 25,
  122685. _vq_lengthlist__44c0_s_p7_1,
  122686. 1, -533725184, 1611661312, 3, 0,
  122687. _vq_quantlist__44c0_s_p7_1,
  122688. NULL,
  122689. &_vq_auxt__44c0_s_p7_1,
  122690. NULL,
  122691. 0
  122692. };
  122693. static long _vq_quantlist__44c0_s_p8_0[] = {
  122694. 2,
  122695. 1,
  122696. 3,
  122697. 0,
  122698. 4,
  122699. };
  122700. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122701. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122702. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122703. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122704. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122705. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122706. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122707. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122708. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122709. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122710. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122711. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122712. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122713. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122714. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122715. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122716. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122717. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122718. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122719. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122720. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122721. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122722. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122723. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122724. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122725. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122726. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122727. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122728. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122729. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122730. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122731. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122732. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122733. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122734. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122735. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122736. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122737. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122738. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122739. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122740. 11,
  122741. };
  122742. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122743. -331.5, -110.5, 110.5, 331.5,
  122744. };
  122745. static long _vq_quantmap__44c0_s_p8_0[] = {
  122746. 3, 1, 0, 2, 4,
  122747. };
  122748. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122749. _vq_quantthresh__44c0_s_p8_0,
  122750. _vq_quantmap__44c0_s_p8_0,
  122751. 5,
  122752. 5
  122753. };
  122754. static static_codebook _44c0_s_p8_0 = {
  122755. 4, 625,
  122756. _vq_lengthlist__44c0_s_p8_0,
  122757. 1, -518283264, 1627103232, 3, 0,
  122758. _vq_quantlist__44c0_s_p8_0,
  122759. NULL,
  122760. &_vq_auxt__44c0_s_p8_0,
  122761. NULL,
  122762. 0
  122763. };
  122764. static long _vq_quantlist__44c0_s_p8_1[] = {
  122765. 6,
  122766. 5,
  122767. 7,
  122768. 4,
  122769. 8,
  122770. 3,
  122771. 9,
  122772. 2,
  122773. 10,
  122774. 1,
  122775. 11,
  122776. 0,
  122777. 12,
  122778. };
  122779. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122780. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122781. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122782. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122783. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122784. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122785. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122786. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122787. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122788. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122789. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122790. 16,13,13,12,12,14,14,15,13,
  122791. };
  122792. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122793. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122794. 42.5, 59.5, 76.5, 93.5,
  122795. };
  122796. static long _vq_quantmap__44c0_s_p8_1[] = {
  122797. 11, 9, 7, 5, 3, 1, 0, 2,
  122798. 4, 6, 8, 10, 12,
  122799. };
  122800. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122801. _vq_quantthresh__44c0_s_p8_1,
  122802. _vq_quantmap__44c0_s_p8_1,
  122803. 13,
  122804. 13
  122805. };
  122806. static static_codebook _44c0_s_p8_1 = {
  122807. 2, 169,
  122808. _vq_lengthlist__44c0_s_p8_1,
  122809. 1, -522616832, 1620115456, 4, 0,
  122810. _vq_quantlist__44c0_s_p8_1,
  122811. NULL,
  122812. &_vq_auxt__44c0_s_p8_1,
  122813. NULL,
  122814. 0
  122815. };
  122816. static long _vq_quantlist__44c0_s_p8_2[] = {
  122817. 8,
  122818. 7,
  122819. 9,
  122820. 6,
  122821. 10,
  122822. 5,
  122823. 11,
  122824. 4,
  122825. 12,
  122826. 3,
  122827. 13,
  122828. 2,
  122829. 14,
  122830. 1,
  122831. 15,
  122832. 0,
  122833. 16,
  122834. };
  122835. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122836. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122837. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122838. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122839. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122840. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122841. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122842. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122843. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122844. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122845. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122846. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122847. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122848. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122849. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122850. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122851. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122852. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122853. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122854. 10,
  122855. };
  122856. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122857. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122858. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122859. };
  122860. static long _vq_quantmap__44c0_s_p8_2[] = {
  122861. 15, 13, 11, 9, 7, 5, 3, 1,
  122862. 0, 2, 4, 6, 8, 10, 12, 14,
  122863. 16,
  122864. };
  122865. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122866. _vq_quantthresh__44c0_s_p8_2,
  122867. _vq_quantmap__44c0_s_p8_2,
  122868. 17,
  122869. 17
  122870. };
  122871. static static_codebook _44c0_s_p8_2 = {
  122872. 2, 289,
  122873. _vq_lengthlist__44c0_s_p8_2,
  122874. 1, -529530880, 1611661312, 5, 0,
  122875. _vq_quantlist__44c0_s_p8_2,
  122876. NULL,
  122877. &_vq_auxt__44c0_s_p8_2,
  122878. NULL,
  122879. 0
  122880. };
  122881. static long _huff_lengthlist__44c0_s_short[] = {
  122882. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122883. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122884. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122885. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122886. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122887. 12,
  122888. };
  122889. static static_codebook _huff_book__44c0_s_short = {
  122890. 2, 81,
  122891. _huff_lengthlist__44c0_s_short,
  122892. 0, 0, 0, 0, 0,
  122893. NULL,
  122894. NULL,
  122895. NULL,
  122896. NULL,
  122897. 0
  122898. };
  122899. static long _huff_lengthlist__44c0_sm_long[] = {
  122900. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122901. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122902. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122903. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122904. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122905. 13,
  122906. };
  122907. static static_codebook _huff_book__44c0_sm_long = {
  122908. 2, 81,
  122909. _huff_lengthlist__44c0_sm_long,
  122910. 0, 0, 0, 0, 0,
  122911. NULL,
  122912. NULL,
  122913. NULL,
  122914. NULL,
  122915. 0
  122916. };
  122917. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122918. 1,
  122919. 0,
  122920. 2,
  122921. };
  122922. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122923. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122924. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122929. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122934. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122969. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122974. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122979. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123014. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  123015. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  123020. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  123021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123024. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  123025. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  123026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123333. 0,
  123334. };
  123335. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123336. -0.5, 0.5,
  123337. };
  123338. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123339. 1, 0, 2,
  123340. };
  123341. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123342. _vq_quantthresh__44c0_sm_p1_0,
  123343. _vq_quantmap__44c0_sm_p1_0,
  123344. 3,
  123345. 3
  123346. };
  123347. static static_codebook _44c0_sm_p1_0 = {
  123348. 8, 6561,
  123349. _vq_lengthlist__44c0_sm_p1_0,
  123350. 1, -535822336, 1611661312, 2, 0,
  123351. _vq_quantlist__44c0_sm_p1_0,
  123352. NULL,
  123353. &_vq_auxt__44c0_sm_p1_0,
  123354. NULL,
  123355. 0
  123356. };
  123357. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123358. 2,
  123359. 1,
  123360. 3,
  123361. 0,
  123362. 4,
  123363. };
  123364. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123365. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123368. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123371. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123404. 0,
  123405. };
  123406. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123407. -1.5, -0.5, 0.5, 1.5,
  123408. };
  123409. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123410. 3, 1, 0, 2, 4,
  123411. };
  123412. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123413. _vq_quantthresh__44c0_sm_p2_0,
  123414. _vq_quantmap__44c0_sm_p2_0,
  123415. 5,
  123416. 5
  123417. };
  123418. static static_codebook _44c0_sm_p2_0 = {
  123419. 4, 625,
  123420. _vq_lengthlist__44c0_sm_p2_0,
  123421. 1, -533725184, 1611661312, 3, 0,
  123422. _vq_quantlist__44c0_sm_p2_0,
  123423. NULL,
  123424. &_vq_auxt__44c0_sm_p2_0,
  123425. NULL,
  123426. 0
  123427. };
  123428. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123429. 4,
  123430. 3,
  123431. 5,
  123432. 2,
  123433. 6,
  123434. 1,
  123435. 7,
  123436. 0,
  123437. 8,
  123438. };
  123439. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123440. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123441. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123442. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123443. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123444. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123445. 0,
  123446. };
  123447. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123448. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123449. };
  123450. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123451. 7, 5, 3, 1, 0, 2, 4, 6,
  123452. 8,
  123453. };
  123454. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123455. _vq_quantthresh__44c0_sm_p3_0,
  123456. _vq_quantmap__44c0_sm_p3_0,
  123457. 9,
  123458. 9
  123459. };
  123460. static static_codebook _44c0_sm_p3_0 = {
  123461. 2, 81,
  123462. _vq_lengthlist__44c0_sm_p3_0,
  123463. 1, -531628032, 1611661312, 4, 0,
  123464. _vq_quantlist__44c0_sm_p3_0,
  123465. NULL,
  123466. &_vq_auxt__44c0_sm_p3_0,
  123467. NULL,
  123468. 0
  123469. };
  123470. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123471. 4,
  123472. 3,
  123473. 5,
  123474. 2,
  123475. 6,
  123476. 1,
  123477. 7,
  123478. 0,
  123479. 8,
  123480. };
  123481. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123482. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123483. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123484. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123485. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123486. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123487. 11,
  123488. };
  123489. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123490. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123491. };
  123492. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123493. 7, 5, 3, 1, 0, 2, 4, 6,
  123494. 8,
  123495. };
  123496. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123497. _vq_quantthresh__44c0_sm_p4_0,
  123498. _vq_quantmap__44c0_sm_p4_0,
  123499. 9,
  123500. 9
  123501. };
  123502. static static_codebook _44c0_sm_p4_0 = {
  123503. 2, 81,
  123504. _vq_lengthlist__44c0_sm_p4_0,
  123505. 1, -531628032, 1611661312, 4, 0,
  123506. _vq_quantlist__44c0_sm_p4_0,
  123507. NULL,
  123508. &_vq_auxt__44c0_sm_p4_0,
  123509. NULL,
  123510. 0
  123511. };
  123512. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123513. 8,
  123514. 7,
  123515. 9,
  123516. 6,
  123517. 10,
  123518. 5,
  123519. 11,
  123520. 4,
  123521. 12,
  123522. 3,
  123523. 13,
  123524. 2,
  123525. 14,
  123526. 1,
  123527. 15,
  123528. 0,
  123529. 16,
  123530. };
  123531. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123532. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123533. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123534. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123535. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123536. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123537. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123538. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123539. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123540. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123541. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123542. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123543. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123544. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123545. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123546. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123547. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123548. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123549. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123550. 14,
  123551. };
  123552. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123553. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123554. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123555. };
  123556. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123557. 15, 13, 11, 9, 7, 5, 3, 1,
  123558. 0, 2, 4, 6, 8, 10, 12, 14,
  123559. 16,
  123560. };
  123561. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123562. _vq_quantthresh__44c0_sm_p5_0,
  123563. _vq_quantmap__44c0_sm_p5_0,
  123564. 17,
  123565. 17
  123566. };
  123567. static static_codebook _44c0_sm_p5_0 = {
  123568. 2, 289,
  123569. _vq_lengthlist__44c0_sm_p5_0,
  123570. 1, -529530880, 1611661312, 5, 0,
  123571. _vq_quantlist__44c0_sm_p5_0,
  123572. NULL,
  123573. &_vq_auxt__44c0_sm_p5_0,
  123574. NULL,
  123575. 0
  123576. };
  123577. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123578. 1,
  123579. 0,
  123580. 2,
  123581. };
  123582. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123583. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123584. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123585. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123586. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123587. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123588. 11,
  123589. };
  123590. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123591. -5.5, 5.5,
  123592. };
  123593. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123594. 1, 0, 2,
  123595. };
  123596. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123597. _vq_quantthresh__44c0_sm_p6_0,
  123598. _vq_quantmap__44c0_sm_p6_0,
  123599. 3,
  123600. 3
  123601. };
  123602. static static_codebook _44c0_sm_p6_0 = {
  123603. 4, 81,
  123604. _vq_lengthlist__44c0_sm_p6_0,
  123605. 1, -529137664, 1618345984, 2, 0,
  123606. _vq_quantlist__44c0_sm_p6_0,
  123607. NULL,
  123608. &_vq_auxt__44c0_sm_p6_0,
  123609. NULL,
  123610. 0
  123611. };
  123612. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123613. 5,
  123614. 4,
  123615. 6,
  123616. 3,
  123617. 7,
  123618. 2,
  123619. 8,
  123620. 1,
  123621. 9,
  123622. 0,
  123623. 10,
  123624. };
  123625. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123626. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123627. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123628. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123629. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123630. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123631. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123632. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123633. 10,10,10, 8, 8, 8, 8, 8, 8,
  123634. };
  123635. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123636. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123637. 3.5, 4.5,
  123638. };
  123639. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123640. 9, 7, 5, 3, 1, 0, 2, 4,
  123641. 6, 8, 10,
  123642. };
  123643. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123644. _vq_quantthresh__44c0_sm_p6_1,
  123645. _vq_quantmap__44c0_sm_p6_1,
  123646. 11,
  123647. 11
  123648. };
  123649. static static_codebook _44c0_sm_p6_1 = {
  123650. 2, 121,
  123651. _vq_lengthlist__44c0_sm_p6_1,
  123652. 1, -531365888, 1611661312, 4, 0,
  123653. _vq_quantlist__44c0_sm_p6_1,
  123654. NULL,
  123655. &_vq_auxt__44c0_sm_p6_1,
  123656. NULL,
  123657. 0
  123658. };
  123659. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123660. 6,
  123661. 5,
  123662. 7,
  123663. 4,
  123664. 8,
  123665. 3,
  123666. 9,
  123667. 2,
  123668. 10,
  123669. 1,
  123670. 11,
  123671. 0,
  123672. 12,
  123673. };
  123674. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123675. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123676. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123677. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123678. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123679. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123680. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123681. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123682. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123683. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123684. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123685. 0,12,12,11,11,13,12,14,14,
  123686. };
  123687. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123688. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123689. 12.5, 17.5, 22.5, 27.5,
  123690. };
  123691. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123692. 11, 9, 7, 5, 3, 1, 0, 2,
  123693. 4, 6, 8, 10, 12,
  123694. };
  123695. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123696. _vq_quantthresh__44c0_sm_p7_0,
  123697. _vq_quantmap__44c0_sm_p7_0,
  123698. 13,
  123699. 13
  123700. };
  123701. static static_codebook _44c0_sm_p7_0 = {
  123702. 2, 169,
  123703. _vq_lengthlist__44c0_sm_p7_0,
  123704. 1, -526516224, 1616117760, 4, 0,
  123705. _vq_quantlist__44c0_sm_p7_0,
  123706. NULL,
  123707. &_vq_auxt__44c0_sm_p7_0,
  123708. NULL,
  123709. 0
  123710. };
  123711. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123712. 2,
  123713. 1,
  123714. 3,
  123715. 0,
  123716. 4,
  123717. };
  123718. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123719. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123720. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123721. };
  123722. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123723. -1.5, -0.5, 0.5, 1.5,
  123724. };
  123725. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123726. 3, 1, 0, 2, 4,
  123727. };
  123728. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123729. _vq_quantthresh__44c0_sm_p7_1,
  123730. _vq_quantmap__44c0_sm_p7_1,
  123731. 5,
  123732. 5
  123733. };
  123734. static static_codebook _44c0_sm_p7_1 = {
  123735. 2, 25,
  123736. _vq_lengthlist__44c0_sm_p7_1,
  123737. 1, -533725184, 1611661312, 3, 0,
  123738. _vq_quantlist__44c0_sm_p7_1,
  123739. NULL,
  123740. &_vq_auxt__44c0_sm_p7_1,
  123741. NULL,
  123742. 0
  123743. };
  123744. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123745. 4,
  123746. 3,
  123747. 5,
  123748. 2,
  123749. 6,
  123750. 1,
  123751. 7,
  123752. 0,
  123753. 8,
  123754. };
  123755. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123756. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123757. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123758. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123759. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123760. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123761. 12,
  123762. };
  123763. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123764. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123765. };
  123766. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123767. 7, 5, 3, 1, 0, 2, 4, 6,
  123768. 8,
  123769. };
  123770. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123771. _vq_quantthresh__44c0_sm_p8_0,
  123772. _vq_quantmap__44c0_sm_p8_0,
  123773. 9,
  123774. 9
  123775. };
  123776. static static_codebook _44c0_sm_p8_0 = {
  123777. 2, 81,
  123778. _vq_lengthlist__44c0_sm_p8_0,
  123779. 1, -516186112, 1627103232, 4, 0,
  123780. _vq_quantlist__44c0_sm_p8_0,
  123781. NULL,
  123782. &_vq_auxt__44c0_sm_p8_0,
  123783. NULL,
  123784. 0
  123785. };
  123786. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123787. 6,
  123788. 5,
  123789. 7,
  123790. 4,
  123791. 8,
  123792. 3,
  123793. 9,
  123794. 2,
  123795. 10,
  123796. 1,
  123797. 11,
  123798. 0,
  123799. 12,
  123800. };
  123801. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123802. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123803. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123804. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123805. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123806. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123807. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123808. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123809. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123810. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123811. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123812. 20,13,13,12,12,16,13,15,13,
  123813. };
  123814. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123815. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123816. 42.5, 59.5, 76.5, 93.5,
  123817. };
  123818. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123819. 11, 9, 7, 5, 3, 1, 0, 2,
  123820. 4, 6, 8, 10, 12,
  123821. };
  123822. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123823. _vq_quantthresh__44c0_sm_p8_1,
  123824. _vq_quantmap__44c0_sm_p8_1,
  123825. 13,
  123826. 13
  123827. };
  123828. static static_codebook _44c0_sm_p8_1 = {
  123829. 2, 169,
  123830. _vq_lengthlist__44c0_sm_p8_1,
  123831. 1, -522616832, 1620115456, 4, 0,
  123832. _vq_quantlist__44c0_sm_p8_1,
  123833. NULL,
  123834. &_vq_auxt__44c0_sm_p8_1,
  123835. NULL,
  123836. 0
  123837. };
  123838. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123839. 8,
  123840. 7,
  123841. 9,
  123842. 6,
  123843. 10,
  123844. 5,
  123845. 11,
  123846. 4,
  123847. 12,
  123848. 3,
  123849. 13,
  123850. 2,
  123851. 14,
  123852. 1,
  123853. 15,
  123854. 0,
  123855. 16,
  123856. };
  123857. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123858. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123859. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123860. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123861. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123862. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123863. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123864. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123865. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123866. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123867. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123868. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123869. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123870. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123871. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123872. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123873. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123874. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123875. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123876. 9,
  123877. };
  123878. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123879. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123880. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123881. };
  123882. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123883. 15, 13, 11, 9, 7, 5, 3, 1,
  123884. 0, 2, 4, 6, 8, 10, 12, 14,
  123885. 16,
  123886. };
  123887. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123888. _vq_quantthresh__44c0_sm_p8_2,
  123889. _vq_quantmap__44c0_sm_p8_2,
  123890. 17,
  123891. 17
  123892. };
  123893. static static_codebook _44c0_sm_p8_2 = {
  123894. 2, 289,
  123895. _vq_lengthlist__44c0_sm_p8_2,
  123896. 1, -529530880, 1611661312, 5, 0,
  123897. _vq_quantlist__44c0_sm_p8_2,
  123898. NULL,
  123899. &_vq_auxt__44c0_sm_p8_2,
  123900. NULL,
  123901. 0
  123902. };
  123903. static long _huff_lengthlist__44c0_sm_short[] = {
  123904. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123905. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123906. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123907. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123908. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123909. 12,
  123910. };
  123911. static static_codebook _huff_book__44c0_sm_short = {
  123912. 2, 81,
  123913. _huff_lengthlist__44c0_sm_short,
  123914. 0, 0, 0, 0, 0,
  123915. NULL,
  123916. NULL,
  123917. NULL,
  123918. NULL,
  123919. 0
  123920. };
  123921. static long _huff_lengthlist__44c1_s_long[] = {
  123922. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123923. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123924. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123925. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123926. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123927. 11,
  123928. };
  123929. static static_codebook _huff_book__44c1_s_long = {
  123930. 2, 81,
  123931. _huff_lengthlist__44c1_s_long,
  123932. 0, 0, 0, 0, 0,
  123933. NULL,
  123934. NULL,
  123935. NULL,
  123936. NULL,
  123937. 0
  123938. };
  123939. static long _vq_quantlist__44c1_s_p1_0[] = {
  123940. 1,
  123941. 0,
  123942. 2,
  123943. };
  123944. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123945. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123946. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123951. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123956. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123991. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123996. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  124001. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124036. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124037. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  124042. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  124043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124046. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124047. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124355. 0,
  124356. };
  124357. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124358. -0.5, 0.5,
  124359. };
  124360. static long _vq_quantmap__44c1_s_p1_0[] = {
  124361. 1, 0, 2,
  124362. };
  124363. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124364. _vq_quantthresh__44c1_s_p1_0,
  124365. _vq_quantmap__44c1_s_p1_0,
  124366. 3,
  124367. 3
  124368. };
  124369. static static_codebook _44c1_s_p1_0 = {
  124370. 8, 6561,
  124371. _vq_lengthlist__44c1_s_p1_0,
  124372. 1, -535822336, 1611661312, 2, 0,
  124373. _vq_quantlist__44c1_s_p1_0,
  124374. NULL,
  124375. &_vq_auxt__44c1_s_p1_0,
  124376. NULL,
  124377. 0
  124378. };
  124379. static long _vq_quantlist__44c1_s_p2_0[] = {
  124380. 2,
  124381. 1,
  124382. 3,
  124383. 0,
  124384. 4,
  124385. };
  124386. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124387. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124390. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124393. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124426. 0,
  124427. };
  124428. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124429. -1.5, -0.5, 0.5, 1.5,
  124430. };
  124431. static long _vq_quantmap__44c1_s_p2_0[] = {
  124432. 3, 1, 0, 2, 4,
  124433. };
  124434. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124435. _vq_quantthresh__44c1_s_p2_0,
  124436. _vq_quantmap__44c1_s_p2_0,
  124437. 5,
  124438. 5
  124439. };
  124440. static static_codebook _44c1_s_p2_0 = {
  124441. 4, 625,
  124442. _vq_lengthlist__44c1_s_p2_0,
  124443. 1, -533725184, 1611661312, 3, 0,
  124444. _vq_quantlist__44c1_s_p2_0,
  124445. NULL,
  124446. &_vq_auxt__44c1_s_p2_0,
  124447. NULL,
  124448. 0
  124449. };
  124450. static long _vq_quantlist__44c1_s_p3_0[] = {
  124451. 4,
  124452. 3,
  124453. 5,
  124454. 2,
  124455. 6,
  124456. 1,
  124457. 7,
  124458. 0,
  124459. 8,
  124460. };
  124461. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124462. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124463. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124464. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124465. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124466. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124467. 0,
  124468. };
  124469. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124470. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124471. };
  124472. static long _vq_quantmap__44c1_s_p3_0[] = {
  124473. 7, 5, 3, 1, 0, 2, 4, 6,
  124474. 8,
  124475. };
  124476. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124477. _vq_quantthresh__44c1_s_p3_0,
  124478. _vq_quantmap__44c1_s_p3_0,
  124479. 9,
  124480. 9
  124481. };
  124482. static static_codebook _44c1_s_p3_0 = {
  124483. 2, 81,
  124484. _vq_lengthlist__44c1_s_p3_0,
  124485. 1, -531628032, 1611661312, 4, 0,
  124486. _vq_quantlist__44c1_s_p3_0,
  124487. NULL,
  124488. &_vq_auxt__44c1_s_p3_0,
  124489. NULL,
  124490. 0
  124491. };
  124492. static long _vq_quantlist__44c1_s_p4_0[] = {
  124493. 4,
  124494. 3,
  124495. 5,
  124496. 2,
  124497. 6,
  124498. 1,
  124499. 7,
  124500. 0,
  124501. 8,
  124502. };
  124503. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124504. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124505. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124506. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124507. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124508. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124509. 11,
  124510. };
  124511. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124512. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124513. };
  124514. static long _vq_quantmap__44c1_s_p4_0[] = {
  124515. 7, 5, 3, 1, 0, 2, 4, 6,
  124516. 8,
  124517. };
  124518. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124519. _vq_quantthresh__44c1_s_p4_0,
  124520. _vq_quantmap__44c1_s_p4_0,
  124521. 9,
  124522. 9
  124523. };
  124524. static static_codebook _44c1_s_p4_0 = {
  124525. 2, 81,
  124526. _vq_lengthlist__44c1_s_p4_0,
  124527. 1, -531628032, 1611661312, 4, 0,
  124528. _vq_quantlist__44c1_s_p4_0,
  124529. NULL,
  124530. &_vq_auxt__44c1_s_p4_0,
  124531. NULL,
  124532. 0
  124533. };
  124534. static long _vq_quantlist__44c1_s_p5_0[] = {
  124535. 8,
  124536. 7,
  124537. 9,
  124538. 6,
  124539. 10,
  124540. 5,
  124541. 11,
  124542. 4,
  124543. 12,
  124544. 3,
  124545. 13,
  124546. 2,
  124547. 14,
  124548. 1,
  124549. 15,
  124550. 0,
  124551. 16,
  124552. };
  124553. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124554. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124555. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124556. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124557. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124558. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124559. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124560. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124561. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124562. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124563. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124564. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124565. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124566. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124567. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124568. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124569. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124570. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124571. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124572. 14,
  124573. };
  124574. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124575. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124576. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124577. };
  124578. static long _vq_quantmap__44c1_s_p5_0[] = {
  124579. 15, 13, 11, 9, 7, 5, 3, 1,
  124580. 0, 2, 4, 6, 8, 10, 12, 14,
  124581. 16,
  124582. };
  124583. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124584. _vq_quantthresh__44c1_s_p5_0,
  124585. _vq_quantmap__44c1_s_p5_0,
  124586. 17,
  124587. 17
  124588. };
  124589. static static_codebook _44c1_s_p5_0 = {
  124590. 2, 289,
  124591. _vq_lengthlist__44c1_s_p5_0,
  124592. 1, -529530880, 1611661312, 5, 0,
  124593. _vq_quantlist__44c1_s_p5_0,
  124594. NULL,
  124595. &_vq_auxt__44c1_s_p5_0,
  124596. NULL,
  124597. 0
  124598. };
  124599. static long _vq_quantlist__44c1_s_p6_0[] = {
  124600. 1,
  124601. 0,
  124602. 2,
  124603. };
  124604. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124605. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124606. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124607. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124608. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124609. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124610. 11,
  124611. };
  124612. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124613. -5.5, 5.5,
  124614. };
  124615. static long _vq_quantmap__44c1_s_p6_0[] = {
  124616. 1, 0, 2,
  124617. };
  124618. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124619. _vq_quantthresh__44c1_s_p6_0,
  124620. _vq_quantmap__44c1_s_p6_0,
  124621. 3,
  124622. 3
  124623. };
  124624. static static_codebook _44c1_s_p6_0 = {
  124625. 4, 81,
  124626. _vq_lengthlist__44c1_s_p6_0,
  124627. 1, -529137664, 1618345984, 2, 0,
  124628. _vq_quantlist__44c1_s_p6_0,
  124629. NULL,
  124630. &_vq_auxt__44c1_s_p6_0,
  124631. NULL,
  124632. 0
  124633. };
  124634. static long _vq_quantlist__44c1_s_p6_1[] = {
  124635. 5,
  124636. 4,
  124637. 6,
  124638. 3,
  124639. 7,
  124640. 2,
  124641. 8,
  124642. 1,
  124643. 9,
  124644. 0,
  124645. 10,
  124646. };
  124647. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124648. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124649. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124650. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124651. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124652. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124653. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124654. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124655. 10,10,10, 8, 8, 8, 8, 8, 8,
  124656. };
  124657. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124658. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124659. 3.5, 4.5,
  124660. };
  124661. static long _vq_quantmap__44c1_s_p6_1[] = {
  124662. 9, 7, 5, 3, 1, 0, 2, 4,
  124663. 6, 8, 10,
  124664. };
  124665. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124666. _vq_quantthresh__44c1_s_p6_1,
  124667. _vq_quantmap__44c1_s_p6_1,
  124668. 11,
  124669. 11
  124670. };
  124671. static static_codebook _44c1_s_p6_1 = {
  124672. 2, 121,
  124673. _vq_lengthlist__44c1_s_p6_1,
  124674. 1, -531365888, 1611661312, 4, 0,
  124675. _vq_quantlist__44c1_s_p6_1,
  124676. NULL,
  124677. &_vq_auxt__44c1_s_p6_1,
  124678. NULL,
  124679. 0
  124680. };
  124681. static long _vq_quantlist__44c1_s_p7_0[] = {
  124682. 6,
  124683. 5,
  124684. 7,
  124685. 4,
  124686. 8,
  124687. 3,
  124688. 9,
  124689. 2,
  124690. 10,
  124691. 1,
  124692. 11,
  124693. 0,
  124694. 12,
  124695. };
  124696. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124697. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124698. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124699. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124700. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124701. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124702. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124703. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124704. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124705. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124706. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124707. 0,12,11,11,11,13,10,14,13,
  124708. };
  124709. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124710. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124711. 12.5, 17.5, 22.5, 27.5,
  124712. };
  124713. static long _vq_quantmap__44c1_s_p7_0[] = {
  124714. 11, 9, 7, 5, 3, 1, 0, 2,
  124715. 4, 6, 8, 10, 12,
  124716. };
  124717. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124718. _vq_quantthresh__44c1_s_p7_0,
  124719. _vq_quantmap__44c1_s_p7_0,
  124720. 13,
  124721. 13
  124722. };
  124723. static static_codebook _44c1_s_p7_0 = {
  124724. 2, 169,
  124725. _vq_lengthlist__44c1_s_p7_0,
  124726. 1, -526516224, 1616117760, 4, 0,
  124727. _vq_quantlist__44c1_s_p7_0,
  124728. NULL,
  124729. &_vq_auxt__44c1_s_p7_0,
  124730. NULL,
  124731. 0
  124732. };
  124733. static long _vq_quantlist__44c1_s_p7_1[] = {
  124734. 2,
  124735. 1,
  124736. 3,
  124737. 0,
  124738. 4,
  124739. };
  124740. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124741. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124742. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124743. };
  124744. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124745. -1.5, -0.5, 0.5, 1.5,
  124746. };
  124747. static long _vq_quantmap__44c1_s_p7_1[] = {
  124748. 3, 1, 0, 2, 4,
  124749. };
  124750. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124751. _vq_quantthresh__44c1_s_p7_1,
  124752. _vq_quantmap__44c1_s_p7_1,
  124753. 5,
  124754. 5
  124755. };
  124756. static static_codebook _44c1_s_p7_1 = {
  124757. 2, 25,
  124758. _vq_lengthlist__44c1_s_p7_1,
  124759. 1, -533725184, 1611661312, 3, 0,
  124760. _vq_quantlist__44c1_s_p7_1,
  124761. NULL,
  124762. &_vq_auxt__44c1_s_p7_1,
  124763. NULL,
  124764. 0
  124765. };
  124766. static long _vq_quantlist__44c1_s_p8_0[] = {
  124767. 6,
  124768. 5,
  124769. 7,
  124770. 4,
  124771. 8,
  124772. 3,
  124773. 9,
  124774. 2,
  124775. 10,
  124776. 1,
  124777. 11,
  124778. 0,
  124779. 12,
  124780. };
  124781. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124782. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124783. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124784. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124785. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124786. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124787. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124788. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124789. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124790. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124791. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124792. 10,10,10,10,10,10,10,10,10,
  124793. };
  124794. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124795. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124796. 552.5, 773.5, 994.5, 1215.5,
  124797. };
  124798. static long _vq_quantmap__44c1_s_p8_0[] = {
  124799. 11, 9, 7, 5, 3, 1, 0, 2,
  124800. 4, 6, 8, 10, 12,
  124801. };
  124802. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124803. _vq_quantthresh__44c1_s_p8_0,
  124804. _vq_quantmap__44c1_s_p8_0,
  124805. 13,
  124806. 13
  124807. };
  124808. static static_codebook _44c1_s_p8_0 = {
  124809. 2, 169,
  124810. _vq_lengthlist__44c1_s_p8_0,
  124811. 1, -514541568, 1627103232, 4, 0,
  124812. _vq_quantlist__44c1_s_p8_0,
  124813. NULL,
  124814. &_vq_auxt__44c1_s_p8_0,
  124815. NULL,
  124816. 0
  124817. };
  124818. static long _vq_quantlist__44c1_s_p8_1[] = {
  124819. 6,
  124820. 5,
  124821. 7,
  124822. 4,
  124823. 8,
  124824. 3,
  124825. 9,
  124826. 2,
  124827. 10,
  124828. 1,
  124829. 11,
  124830. 0,
  124831. 12,
  124832. };
  124833. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124834. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124835. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124836. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124837. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124838. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124839. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124840. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124841. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124842. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124843. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124844. 16,13,12,12,11,14,12,15,13,
  124845. };
  124846. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124847. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124848. 42.5, 59.5, 76.5, 93.5,
  124849. };
  124850. static long _vq_quantmap__44c1_s_p8_1[] = {
  124851. 11, 9, 7, 5, 3, 1, 0, 2,
  124852. 4, 6, 8, 10, 12,
  124853. };
  124854. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124855. _vq_quantthresh__44c1_s_p8_1,
  124856. _vq_quantmap__44c1_s_p8_1,
  124857. 13,
  124858. 13
  124859. };
  124860. static static_codebook _44c1_s_p8_1 = {
  124861. 2, 169,
  124862. _vq_lengthlist__44c1_s_p8_1,
  124863. 1, -522616832, 1620115456, 4, 0,
  124864. _vq_quantlist__44c1_s_p8_1,
  124865. NULL,
  124866. &_vq_auxt__44c1_s_p8_1,
  124867. NULL,
  124868. 0
  124869. };
  124870. static long _vq_quantlist__44c1_s_p8_2[] = {
  124871. 8,
  124872. 7,
  124873. 9,
  124874. 6,
  124875. 10,
  124876. 5,
  124877. 11,
  124878. 4,
  124879. 12,
  124880. 3,
  124881. 13,
  124882. 2,
  124883. 14,
  124884. 1,
  124885. 15,
  124886. 0,
  124887. 16,
  124888. };
  124889. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124890. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124891. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124892. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124893. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124894. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124895. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124896. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124897. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124898. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124899. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124900. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124901. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124902. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124903. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124904. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124905. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124906. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124907. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124908. 9,
  124909. };
  124910. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124911. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124912. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124913. };
  124914. static long _vq_quantmap__44c1_s_p8_2[] = {
  124915. 15, 13, 11, 9, 7, 5, 3, 1,
  124916. 0, 2, 4, 6, 8, 10, 12, 14,
  124917. 16,
  124918. };
  124919. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124920. _vq_quantthresh__44c1_s_p8_2,
  124921. _vq_quantmap__44c1_s_p8_2,
  124922. 17,
  124923. 17
  124924. };
  124925. static static_codebook _44c1_s_p8_2 = {
  124926. 2, 289,
  124927. _vq_lengthlist__44c1_s_p8_2,
  124928. 1, -529530880, 1611661312, 5, 0,
  124929. _vq_quantlist__44c1_s_p8_2,
  124930. NULL,
  124931. &_vq_auxt__44c1_s_p8_2,
  124932. NULL,
  124933. 0
  124934. };
  124935. static long _huff_lengthlist__44c1_s_short[] = {
  124936. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124937. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124938. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124939. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124940. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124941. 11,
  124942. };
  124943. static static_codebook _huff_book__44c1_s_short = {
  124944. 2, 81,
  124945. _huff_lengthlist__44c1_s_short,
  124946. 0, 0, 0, 0, 0,
  124947. NULL,
  124948. NULL,
  124949. NULL,
  124950. NULL,
  124951. 0
  124952. };
  124953. static long _huff_lengthlist__44c1_sm_long[] = {
  124954. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124955. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124956. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124957. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124958. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124959. 11,
  124960. };
  124961. static static_codebook _huff_book__44c1_sm_long = {
  124962. 2, 81,
  124963. _huff_lengthlist__44c1_sm_long,
  124964. 0, 0, 0, 0, 0,
  124965. NULL,
  124966. NULL,
  124967. NULL,
  124968. NULL,
  124969. 0
  124970. };
  124971. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124972. 1,
  124973. 0,
  124974. 2,
  124975. };
  124976. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124977. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124978. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124983. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124988. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  125023. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  125028. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  125033. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125068. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125069. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125074. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  125075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125078. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125079. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  125080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125387. 0,
  125388. };
  125389. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125390. -0.5, 0.5,
  125391. };
  125392. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125393. 1, 0, 2,
  125394. };
  125395. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125396. _vq_quantthresh__44c1_sm_p1_0,
  125397. _vq_quantmap__44c1_sm_p1_0,
  125398. 3,
  125399. 3
  125400. };
  125401. static static_codebook _44c1_sm_p1_0 = {
  125402. 8, 6561,
  125403. _vq_lengthlist__44c1_sm_p1_0,
  125404. 1, -535822336, 1611661312, 2, 0,
  125405. _vq_quantlist__44c1_sm_p1_0,
  125406. NULL,
  125407. &_vq_auxt__44c1_sm_p1_0,
  125408. NULL,
  125409. 0
  125410. };
  125411. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125412. 2,
  125413. 1,
  125414. 3,
  125415. 0,
  125416. 4,
  125417. };
  125418. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125419. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125422. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125425. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125458. 0,
  125459. };
  125460. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125461. -1.5, -0.5, 0.5, 1.5,
  125462. };
  125463. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125464. 3, 1, 0, 2, 4,
  125465. };
  125466. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125467. _vq_quantthresh__44c1_sm_p2_0,
  125468. _vq_quantmap__44c1_sm_p2_0,
  125469. 5,
  125470. 5
  125471. };
  125472. static static_codebook _44c1_sm_p2_0 = {
  125473. 4, 625,
  125474. _vq_lengthlist__44c1_sm_p2_0,
  125475. 1, -533725184, 1611661312, 3, 0,
  125476. _vq_quantlist__44c1_sm_p2_0,
  125477. NULL,
  125478. &_vq_auxt__44c1_sm_p2_0,
  125479. NULL,
  125480. 0
  125481. };
  125482. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125483. 4,
  125484. 3,
  125485. 5,
  125486. 2,
  125487. 6,
  125488. 1,
  125489. 7,
  125490. 0,
  125491. 8,
  125492. };
  125493. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125494. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125495. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125496. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125497. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125498. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125499. 0,
  125500. };
  125501. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125502. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125503. };
  125504. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125505. 7, 5, 3, 1, 0, 2, 4, 6,
  125506. 8,
  125507. };
  125508. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125509. _vq_quantthresh__44c1_sm_p3_0,
  125510. _vq_quantmap__44c1_sm_p3_0,
  125511. 9,
  125512. 9
  125513. };
  125514. static static_codebook _44c1_sm_p3_0 = {
  125515. 2, 81,
  125516. _vq_lengthlist__44c1_sm_p3_0,
  125517. 1, -531628032, 1611661312, 4, 0,
  125518. _vq_quantlist__44c1_sm_p3_0,
  125519. NULL,
  125520. &_vq_auxt__44c1_sm_p3_0,
  125521. NULL,
  125522. 0
  125523. };
  125524. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125525. 4,
  125526. 3,
  125527. 5,
  125528. 2,
  125529. 6,
  125530. 1,
  125531. 7,
  125532. 0,
  125533. 8,
  125534. };
  125535. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125536. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125537. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125538. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125539. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125540. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125541. 11,
  125542. };
  125543. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125544. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125545. };
  125546. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125547. 7, 5, 3, 1, 0, 2, 4, 6,
  125548. 8,
  125549. };
  125550. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125551. _vq_quantthresh__44c1_sm_p4_0,
  125552. _vq_quantmap__44c1_sm_p4_0,
  125553. 9,
  125554. 9
  125555. };
  125556. static static_codebook _44c1_sm_p4_0 = {
  125557. 2, 81,
  125558. _vq_lengthlist__44c1_sm_p4_0,
  125559. 1, -531628032, 1611661312, 4, 0,
  125560. _vq_quantlist__44c1_sm_p4_0,
  125561. NULL,
  125562. &_vq_auxt__44c1_sm_p4_0,
  125563. NULL,
  125564. 0
  125565. };
  125566. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125567. 8,
  125568. 7,
  125569. 9,
  125570. 6,
  125571. 10,
  125572. 5,
  125573. 11,
  125574. 4,
  125575. 12,
  125576. 3,
  125577. 13,
  125578. 2,
  125579. 14,
  125580. 1,
  125581. 15,
  125582. 0,
  125583. 16,
  125584. };
  125585. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125586. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125587. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125588. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125589. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125590. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125591. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125592. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125593. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125594. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125595. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125596. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125597. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125598. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125599. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125600. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125601. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125602. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125603. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125604. 14,
  125605. };
  125606. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125607. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125608. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125609. };
  125610. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125611. 15, 13, 11, 9, 7, 5, 3, 1,
  125612. 0, 2, 4, 6, 8, 10, 12, 14,
  125613. 16,
  125614. };
  125615. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125616. _vq_quantthresh__44c1_sm_p5_0,
  125617. _vq_quantmap__44c1_sm_p5_0,
  125618. 17,
  125619. 17
  125620. };
  125621. static static_codebook _44c1_sm_p5_0 = {
  125622. 2, 289,
  125623. _vq_lengthlist__44c1_sm_p5_0,
  125624. 1, -529530880, 1611661312, 5, 0,
  125625. _vq_quantlist__44c1_sm_p5_0,
  125626. NULL,
  125627. &_vq_auxt__44c1_sm_p5_0,
  125628. NULL,
  125629. 0
  125630. };
  125631. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125632. 1,
  125633. 0,
  125634. 2,
  125635. };
  125636. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125637. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125638. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125639. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125640. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125641. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125642. 11,
  125643. };
  125644. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125645. -5.5, 5.5,
  125646. };
  125647. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125648. 1, 0, 2,
  125649. };
  125650. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125651. _vq_quantthresh__44c1_sm_p6_0,
  125652. _vq_quantmap__44c1_sm_p6_0,
  125653. 3,
  125654. 3
  125655. };
  125656. static static_codebook _44c1_sm_p6_0 = {
  125657. 4, 81,
  125658. _vq_lengthlist__44c1_sm_p6_0,
  125659. 1, -529137664, 1618345984, 2, 0,
  125660. _vq_quantlist__44c1_sm_p6_0,
  125661. NULL,
  125662. &_vq_auxt__44c1_sm_p6_0,
  125663. NULL,
  125664. 0
  125665. };
  125666. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125667. 5,
  125668. 4,
  125669. 6,
  125670. 3,
  125671. 7,
  125672. 2,
  125673. 8,
  125674. 1,
  125675. 9,
  125676. 0,
  125677. 10,
  125678. };
  125679. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125680. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125681. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125682. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125683. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125684. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125685. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125686. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125687. 10,10,10, 8, 8, 8, 8, 8, 8,
  125688. };
  125689. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125690. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125691. 3.5, 4.5,
  125692. };
  125693. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125694. 9, 7, 5, 3, 1, 0, 2, 4,
  125695. 6, 8, 10,
  125696. };
  125697. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125698. _vq_quantthresh__44c1_sm_p6_1,
  125699. _vq_quantmap__44c1_sm_p6_1,
  125700. 11,
  125701. 11
  125702. };
  125703. static static_codebook _44c1_sm_p6_1 = {
  125704. 2, 121,
  125705. _vq_lengthlist__44c1_sm_p6_1,
  125706. 1, -531365888, 1611661312, 4, 0,
  125707. _vq_quantlist__44c1_sm_p6_1,
  125708. NULL,
  125709. &_vq_auxt__44c1_sm_p6_1,
  125710. NULL,
  125711. 0
  125712. };
  125713. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125714. 6,
  125715. 5,
  125716. 7,
  125717. 4,
  125718. 8,
  125719. 3,
  125720. 9,
  125721. 2,
  125722. 10,
  125723. 1,
  125724. 11,
  125725. 0,
  125726. 12,
  125727. };
  125728. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125729. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125730. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125731. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125732. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125733. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125734. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125735. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125736. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125737. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125738. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125739. 0,12,12,11,11,13,12,14,13,
  125740. };
  125741. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125742. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125743. 12.5, 17.5, 22.5, 27.5,
  125744. };
  125745. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125746. 11, 9, 7, 5, 3, 1, 0, 2,
  125747. 4, 6, 8, 10, 12,
  125748. };
  125749. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125750. _vq_quantthresh__44c1_sm_p7_0,
  125751. _vq_quantmap__44c1_sm_p7_0,
  125752. 13,
  125753. 13
  125754. };
  125755. static static_codebook _44c1_sm_p7_0 = {
  125756. 2, 169,
  125757. _vq_lengthlist__44c1_sm_p7_0,
  125758. 1, -526516224, 1616117760, 4, 0,
  125759. _vq_quantlist__44c1_sm_p7_0,
  125760. NULL,
  125761. &_vq_auxt__44c1_sm_p7_0,
  125762. NULL,
  125763. 0
  125764. };
  125765. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125766. 2,
  125767. 1,
  125768. 3,
  125769. 0,
  125770. 4,
  125771. };
  125772. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125773. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125774. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125775. };
  125776. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125777. -1.5, -0.5, 0.5, 1.5,
  125778. };
  125779. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125780. 3, 1, 0, 2, 4,
  125781. };
  125782. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125783. _vq_quantthresh__44c1_sm_p7_1,
  125784. _vq_quantmap__44c1_sm_p7_1,
  125785. 5,
  125786. 5
  125787. };
  125788. static static_codebook _44c1_sm_p7_1 = {
  125789. 2, 25,
  125790. _vq_lengthlist__44c1_sm_p7_1,
  125791. 1, -533725184, 1611661312, 3, 0,
  125792. _vq_quantlist__44c1_sm_p7_1,
  125793. NULL,
  125794. &_vq_auxt__44c1_sm_p7_1,
  125795. NULL,
  125796. 0
  125797. };
  125798. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125799. 6,
  125800. 5,
  125801. 7,
  125802. 4,
  125803. 8,
  125804. 3,
  125805. 9,
  125806. 2,
  125807. 10,
  125808. 1,
  125809. 11,
  125810. 0,
  125811. 12,
  125812. };
  125813. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125814. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125815. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125816. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125817. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125818. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125819. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125820. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125821. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125822. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125823. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125824. 13,13,13,13,13,13,13,13,13,
  125825. };
  125826. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125827. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125828. 552.5, 773.5, 994.5, 1215.5,
  125829. };
  125830. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125831. 11, 9, 7, 5, 3, 1, 0, 2,
  125832. 4, 6, 8, 10, 12,
  125833. };
  125834. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125835. _vq_quantthresh__44c1_sm_p8_0,
  125836. _vq_quantmap__44c1_sm_p8_0,
  125837. 13,
  125838. 13
  125839. };
  125840. static static_codebook _44c1_sm_p8_0 = {
  125841. 2, 169,
  125842. _vq_lengthlist__44c1_sm_p8_0,
  125843. 1, -514541568, 1627103232, 4, 0,
  125844. _vq_quantlist__44c1_sm_p8_0,
  125845. NULL,
  125846. &_vq_auxt__44c1_sm_p8_0,
  125847. NULL,
  125848. 0
  125849. };
  125850. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125851. 6,
  125852. 5,
  125853. 7,
  125854. 4,
  125855. 8,
  125856. 3,
  125857. 9,
  125858. 2,
  125859. 10,
  125860. 1,
  125861. 11,
  125862. 0,
  125863. 12,
  125864. };
  125865. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125866. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125867. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125868. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125869. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125870. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125871. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125872. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125873. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125874. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125875. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125876. 20,13,12,12,12,14,12,14,13,
  125877. };
  125878. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125879. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125880. 42.5, 59.5, 76.5, 93.5,
  125881. };
  125882. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125883. 11, 9, 7, 5, 3, 1, 0, 2,
  125884. 4, 6, 8, 10, 12,
  125885. };
  125886. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125887. _vq_quantthresh__44c1_sm_p8_1,
  125888. _vq_quantmap__44c1_sm_p8_1,
  125889. 13,
  125890. 13
  125891. };
  125892. static static_codebook _44c1_sm_p8_1 = {
  125893. 2, 169,
  125894. _vq_lengthlist__44c1_sm_p8_1,
  125895. 1, -522616832, 1620115456, 4, 0,
  125896. _vq_quantlist__44c1_sm_p8_1,
  125897. NULL,
  125898. &_vq_auxt__44c1_sm_p8_1,
  125899. NULL,
  125900. 0
  125901. };
  125902. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125903. 8,
  125904. 7,
  125905. 9,
  125906. 6,
  125907. 10,
  125908. 5,
  125909. 11,
  125910. 4,
  125911. 12,
  125912. 3,
  125913. 13,
  125914. 2,
  125915. 14,
  125916. 1,
  125917. 15,
  125918. 0,
  125919. 16,
  125920. };
  125921. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125922. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125923. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125924. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125925. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125926. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125927. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125928. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125929. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125930. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125931. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125932. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125933. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125934. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125935. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125936. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125937. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125938. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125939. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125940. 9,
  125941. };
  125942. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125943. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125944. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125945. };
  125946. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125947. 15, 13, 11, 9, 7, 5, 3, 1,
  125948. 0, 2, 4, 6, 8, 10, 12, 14,
  125949. 16,
  125950. };
  125951. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125952. _vq_quantthresh__44c1_sm_p8_2,
  125953. _vq_quantmap__44c1_sm_p8_2,
  125954. 17,
  125955. 17
  125956. };
  125957. static static_codebook _44c1_sm_p8_2 = {
  125958. 2, 289,
  125959. _vq_lengthlist__44c1_sm_p8_2,
  125960. 1, -529530880, 1611661312, 5, 0,
  125961. _vq_quantlist__44c1_sm_p8_2,
  125962. NULL,
  125963. &_vq_auxt__44c1_sm_p8_2,
  125964. NULL,
  125965. 0
  125966. };
  125967. static long _huff_lengthlist__44c1_sm_short[] = {
  125968. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125969. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125970. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125971. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125972. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125973. 11,
  125974. };
  125975. static static_codebook _huff_book__44c1_sm_short = {
  125976. 2, 81,
  125977. _huff_lengthlist__44c1_sm_short,
  125978. 0, 0, 0, 0, 0,
  125979. NULL,
  125980. NULL,
  125981. NULL,
  125982. NULL,
  125983. 0
  125984. };
  125985. static long _huff_lengthlist__44cn1_s_long[] = {
  125986. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125987. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125988. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125989. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125990. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125991. 20,
  125992. };
  125993. static static_codebook _huff_book__44cn1_s_long = {
  125994. 2, 81,
  125995. _huff_lengthlist__44cn1_s_long,
  125996. 0, 0, 0, 0, 0,
  125997. NULL,
  125998. NULL,
  125999. NULL,
  126000. NULL,
  126001. 0
  126002. };
  126003. static long _vq_quantlist__44cn1_s_p1_0[] = {
  126004. 1,
  126005. 0,
  126006. 2,
  126007. };
  126008. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  126009. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126010. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126015. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  126020. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126055. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  126056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  126060. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  126065. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  126066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126100. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126101. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126106. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  126107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126110. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126111. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  126112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126419. 0,
  126420. };
  126421. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126422. -0.5, 0.5,
  126423. };
  126424. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126425. 1, 0, 2,
  126426. };
  126427. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126428. _vq_quantthresh__44cn1_s_p1_0,
  126429. _vq_quantmap__44cn1_s_p1_0,
  126430. 3,
  126431. 3
  126432. };
  126433. static static_codebook _44cn1_s_p1_0 = {
  126434. 8, 6561,
  126435. _vq_lengthlist__44cn1_s_p1_0,
  126436. 1, -535822336, 1611661312, 2, 0,
  126437. _vq_quantlist__44cn1_s_p1_0,
  126438. NULL,
  126439. &_vq_auxt__44cn1_s_p1_0,
  126440. NULL,
  126441. 0
  126442. };
  126443. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126444. 2,
  126445. 1,
  126446. 3,
  126447. 0,
  126448. 4,
  126449. };
  126450. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126451. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126454. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126457. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126490. 0,
  126491. };
  126492. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126493. -1.5, -0.5, 0.5, 1.5,
  126494. };
  126495. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126496. 3, 1, 0, 2, 4,
  126497. };
  126498. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126499. _vq_quantthresh__44cn1_s_p2_0,
  126500. _vq_quantmap__44cn1_s_p2_0,
  126501. 5,
  126502. 5
  126503. };
  126504. static static_codebook _44cn1_s_p2_0 = {
  126505. 4, 625,
  126506. _vq_lengthlist__44cn1_s_p2_0,
  126507. 1, -533725184, 1611661312, 3, 0,
  126508. _vq_quantlist__44cn1_s_p2_0,
  126509. NULL,
  126510. &_vq_auxt__44cn1_s_p2_0,
  126511. NULL,
  126512. 0
  126513. };
  126514. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126515. 4,
  126516. 3,
  126517. 5,
  126518. 2,
  126519. 6,
  126520. 1,
  126521. 7,
  126522. 0,
  126523. 8,
  126524. };
  126525. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126526. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126527. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126528. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126529. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126530. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126531. 0,
  126532. };
  126533. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126534. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126535. };
  126536. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126537. 7, 5, 3, 1, 0, 2, 4, 6,
  126538. 8,
  126539. };
  126540. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126541. _vq_quantthresh__44cn1_s_p3_0,
  126542. _vq_quantmap__44cn1_s_p3_0,
  126543. 9,
  126544. 9
  126545. };
  126546. static static_codebook _44cn1_s_p3_0 = {
  126547. 2, 81,
  126548. _vq_lengthlist__44cn1_s_p3_0,
  126549. 1, -531628032, 1611661312, 4, 0,
  126550. _vq_quantlist__44cn1_s_p3_0,
  126551. NULL,
  126552. &_vq_auxt__44cn1_s_p3_0,
  126553. NULL,
  126554. 0
  126555. };
  126556. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126557. 4,
  126558. 3,
  126559. 5,
  126560. 2,
  126561. 6,
  126562. 1,
  126563. 7,
  126564. 0,
  126565. 8,
  126566. };
  126567. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126568. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126569. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126570. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126571. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126572. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126573. 11,
  126574. };
  126575. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126576. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126577. };
  126578. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126579. 7, 5, 3, 1, 0, 2, 4, 6,
  126580. 8,
  126581. };
  126582. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126583. _vq_quantthresh__44cn1_s_p4_0,
  126584. _vq_quantmap__44cn1_s_p4_0,
  126585. 9,
  126586. 9
  126587. };
  126588. static static_codebook _44cn1_s_p4_0 = {
  126589. 2, 81,
  126590. _vq_lengthlist__44cn1_s_p4_0,
  126591. 1, -531628032, 1611661312, 4, 0,
  126592. _vq_quantlist__44cn1_s_p4_0,
  126593. NULL,
  126594. &_vq_auxt__44cn1_s_p4_0,
  126595. NULL,
  126596. 0
  126597. };
  126598. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126599. 8,
  126600. 7,
  126601. 9,
  126602. 6,
  126603. 10,
  126604. 5,
  126605. 11,
  126606. 4,
  126607. 12,
  126608. 3,
  126609. 13,
  126610. 2,
  126611. 14,
  126612. 1,
  126613. 15,
  126614. 0,
  126615. 16,
  126616. };
  126617. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126618. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126619. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126620. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126621. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126622. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126623. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126624. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126625. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126626. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126627. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126628. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126629. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126630. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126631. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126632. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126633. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126634. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126635. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126636. 14,
  126637. };
  126638. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126639. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126640. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126641. };
  126642. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126643. 15, 13, 11, 9, 7, 5, 3, 1,
  126644. 0, 2, 4, 6, 8, 10, 12, 14,
  126645. 16,
  126646. };
  126647. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126648. _vq_quantthresh__44cn1_s_p5_0,
  126649. _vq_quantmap__44cn1_s_p5_0,
  126650. 17,
  126651. 17
  126652. };
  126653. static static_codebook _44cn1_s_p5_0 = {
  126654. 2, 289,
  126655. _vq_lengthlist__44cn1_s_p5_0,
  126656. 1, -529530880, 1611661312, 5, 0,
  126657. _vq_quantlist__44cn1_s_p5_0,
  126658. NULL,
  126659. &_vq_auxt__44cn1_s_p5_0,
  126660. NULL,
  126661. 0
  126662. };
  126663. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126664. 1,
  126665. 0,
  126666. 2,
  126667. };
  126668. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126669. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126670. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126671. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126672. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126673. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126674. 10,
  126675. };
  126676. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126677. -5.5, 5.5,
  126678. };
  126679. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126680. 1, 0, 2,
  126681. };
  126682. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126683. _vq_quantthresh__44cn1_s_p6_0,
  126684. _vq_quantmap__44cn1_s_p6_0,
  126685. 3,
  126686. 3
  126687. };
  126688. static static_codebook _44cn1_s_p6_0 = {
  126689. 4, 81,
  126690. _vq_lengthlist__44cn1_s_p6_0,
  126691. 1, -529137664, 1618345984, 2, 0,
  126692. _vq_quantlist__44cn1_s_p6_0,
  126693. NULL,
  126694. &_vq_auxt__44cn1_s_p6_0,
  126695. NULL,
  126696. 0
  126697. };
  126698. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126699. 5,
  126700. 4,
  126701. 6,
  126702. 3,
  126703. 7,
  126704. 2,
  126705. 8,
  126706. 1,
  126707. 9,
  126708. 0,
  126709. 10,
  126710. };
  126711. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126712. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126713. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126714. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126715. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126716. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126717. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126718. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126719. 10,10,10, 9, 9, 9, 9, 9, 9,
  126720. };
  126721. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126722. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126723. 3.5, 4.5,
  126724. };
  126725. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126726. 9, 7, 5, 3, 1, 0, 2, 4,
  126727. 6, 8, 10,
  126728. };
  126729. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126730. _vq_quantthresh__44cn1_s_p6_1,
  126731. _vq_quantmap__44cn1_s_p6_1,
  126732. 11,
  126733. 11
  126734. };
  126735. static static_codebook _44cn1_s_p6_1 = {
  126736. 2, 121,
  126737. _vq_lengthlist__44cn1_s_p6_1,
  126738. 1, -531365888, 1611661312, 4, 0,
  126739. _vq_quantlist__44cn1_s_p6_1,
  126740. NULL,
  126741. &_vq_auxt__44cn1_s_p6_1,
  126742. NULL,
  126743. 0
  126744. };
  126745. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126746. 6,
  126747. 5,
  126748. 7,
  126749. 4,
  126750. 8,
  126751. 3,
  126752. 9,
  126753. 2,
  126754. 10,
  126755. 1,
  126756. 11,
  126757. 0,
  126758. 12,
  126759. };
  126760. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126761. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126762. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126763. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126764. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126765. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126766. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126767. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126768. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126769. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126770. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126771. 0,13,13,12,12,13,13,13,14,
  126772. };
  126773. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126774. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126775. 12.5, 17.5, 22.5, 27.5,
  126776. };
  126777. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126778. 11, 9, 7, 5, 3, 1, 0, 2,
  126779. 4, 6, 8, 10, 12,
  126780. };
  126781. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126782. _vq_quantthresh__44cn1_s_p7_0,
  126783. _vq_quantmap__44cn1_s_p7_0,
  126784. 13,
  126785. 13
  126786. };
  126787. static static_codebook _44cn1_s_p7_0 = {
  126788. 2, 169,
  126789. _vq_lengthlist__44cn1_s_p7_0,
  126790. 1, -526516224, 1616117760, 4, 0,
  126791. _vq_quantlist__44cn1_s_p7_0,
  126792. NULL,
  126793. &_vq_auxt__44cn1_s_p7_0,
  126794. NULL,
  126795. 0
  126796. };
  126797. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126798. 2,
  126799. 1,
  126800. 3,
  126801. 0,
  126802. 4,
  126803. };
  126804. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126805. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126806. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126807. };
  126808. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126809. -1.5, -0.5, 0.5, 1.5,
  126810. };
  126811. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126812. 3, 1, 0, 2, 4,
  126813. };
  126814. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126815. _vq_quantthresh__44cn1_s_p7_1,
  126816. _vq_quantmap__44cn1_s_p7_1,
  126817. 5,
  126818. 5
  126819. };
  126820. static static_codebook _44cn1_s_p7_1 = {
  126821. 2, 25,
  126822. _vq_lengthlist__44cn1_s_p7_1,
  126823. 1, -533725184, 1611661312, 3, 0,
  126824. _vq_quantlist__44cn1_s_p7_1,
  126825. NULL,
  126826. &_vq_auxt__44cn1_s_p7_1,
  126827. NULL,
  126828. 0
  126829. };
  126830. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126831. 2,
  126832. 1,
  126833. 3,
  126834. 0,
  126835. 4,
  126836. };
  126837. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126838. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126839. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126840. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126841. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126842. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126843. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126844. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126845. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126846. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126847. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126848. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126849. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126850. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126851. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126852. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126853. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126854. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126855. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126856. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126857. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126858. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126859. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126860. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126861. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126862. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126863. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126864. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126865. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126866. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126867. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126868. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126869. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126870. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126871. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126872. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126873. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126874. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126875. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126876. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126877. 12,
  126878. };
  126879. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126880. -331.5, -110.5, 110.5, 331.5,
  126881. };
  126882. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126883. 3, 1, 0, 2, 4,
  126884. };
  126885. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126886. _vq_quantthresh__44cn1_s_p8_0,
  126887. _vq_quantmap__44cn1_s_p8_0,
  126888. 5,
  126889. 5
  126890. };
  126891. static static_codebook _44cn1_s_p8_0 = {
  126892. 4, 625,
  126893. _vq_lengthlist__44cn1_s_p8_0,
  126894. 1, -518283264, 1627103232, 3, 0,
  126895. _vq_quantlist__44cn1_s_p8_0,
  126896. NULL,
  126897. &_vq_auxt__44cn1_s_p8_0,
  126898. NULL,
  126899. 0
  126900. };
  126901. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126902. 6,
  126903. 5,
  126904. 7,
  126905. 4,
  126906. 8,
  126907. 3,
  126908. 9,
  126909. 2,
  126910. 10,
  126911. 1,
  126912. 11,
  126913. 0,
  126914. 12,
  126915. };
  126916. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126917. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126918. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126919. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126920. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126921. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126922. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126923. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126924. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126925. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126926. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126927. 15,12,12,11,11,14,12,13,14,
  126928. };
  126929. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126930. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126931. 42.5, 59.5, 76.5, 93.5,
  126932. };
  126933. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126934. 11, 9, 7, 5, 3, 1, 0, 2,
  126935. 4, 6, 8, 10, 12,
  126936. };
  126937. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126938. _vq_quantthresh__44cn1_s_p8_1,
  126939. _vq_quantmap__44cn1_s_p8_1,
  126940. 13,
  126941. 13
  126942. };
  126943. static static_codebook _44cn1_s_p8_1 = {
  126944. 2, 169,
  126945. _vq_lengthlist__44cn1_s_p8_1,
  126946. 1, -522616832, 1620115456, 4, 0,
  126947. _vq_quantlist__44cn1_s_p8_1,
  126948. NULL,
  126949. &_vq_auxt__44cn1_s_p8_1,
  126950. NULL,
  126951. 0
  126952. };
  126953. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126954. 8,
  126955. 7,
  126956. 9,
  126957. 6,
  126958. 10,
  126959. 5,
  126960. 11,
  126961. 4,
  126962. 12,
  126963. 3,
  126964. 13,
  126965. 2,
  126966. 14,
  126967. 1,
  126968. 15,
  126969. 0,
  126970. 16,
  126971. };
  126972. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126973. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126974. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126975. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126976. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126977. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126978. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126979. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126980. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126981. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126982. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126983. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126984. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126985. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126986. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126987. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126988. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126989. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126990. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126991. 9,
  126992. };
  126993. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126994. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126995. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126996. };
  126997. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126998. 15, 13, 11, 9, 7, 5, 3, 1,
  126999. 0, 2, 4, 6, 8, 10, 12, 14,
  127000. 16,
  127001. };
  127002. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  127003. _vq_quantthresh__44cn1_s_p8_2,
  127004. _vq_quantmap__44cn1_s_p8_2,
  127005. 17,
  127006. 17
  127007. };
  127008. static static_codebook _44cn1_s_p8_2 = {
  127009. 2, 289,
  127010. _vq_lengthlist__44cn1_s_p8_2,
  127011. 1, -529530880, 1611661312, 5, 0,
  127012. _vq_quantlist__44cn1_s_p8_2,
  127013. NULL,
  127014. &_vq_auxt__44cn1_s_p8_2,
  127015. NULL,
  127016. 0
  127017. };
  127018. static long _huff_lengthlist__44cn1_s_short[] = {
  127019. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  127020. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  127021. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  127022. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  127023. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  127024. 10,
  127025. };
  127026. static static_codebook _huff_book__44cn1_s_short = {
  127027. 2, 81,
  127028. _huff_lengthlist__44cn1_s_short,
  127029. 0, 0, 0, 0, 0,
  127030. NULL,
  127031. NULL,
  127032. NULL,
  127033. NULL,
  127034. 0
  127035. };
  127036. static long _huff_lengthlist__44cn1_sm_long[] = {
  127037. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  127038. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  127039. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  127040. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  127041. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  127042. 17,
  127043. };
  127044. static static_codebook _huff_book__44cn1_sm_long = {
  127045. 2, 81,
  127046. _huff_lengthlist__44cn1_sm_long,
  127047. 0, 0, 0, 0, 0,
  127048. NULL,
  127049. NULL,
  127050. NULL,
  127051. NULL,
  127052. 0
  127053. };
  127054. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  127055. 1,
  127056. 0,
  127057. 2,
  127058. };
  127059. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  127060. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  127061. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  127066. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  127071. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  127106. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  127111. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  127116. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  127117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127151. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127152. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127157. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  127158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127161. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127162. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  127163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127470. 0,
  127471. };
  127472. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127473. -0.5, 0.5,
  127474. };
  127475. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127476. 1, 0, 2,
  127477. };
  127478. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127479. _vq_quantthresh__44cn1_sm_p1_0,
  127480. _vq_quantmap__44cn1_sm_p1_0,
  127481. 3,
  127482. 3
  127483. };
  127484. static static_codebook _44cn1_sm_p1_0 = {
  127485. 8, 6561,
  127486. _vq_lengthlist__44cn1_sm_p1_0,
  127487. 1, -535822336, 1611661312, 2, 0,
  127488. _vq_quantlist__44cn1_sm_p1_0,
  127489. NULL,
  127490. &_vq_auxt__44cn1_sm_p1_0,
  127491. NULL,
  127492. 0
  127493. };
  127494. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127495. 2,
  127496. 1,
  127497. 3,
  127498. 0,
  127499. 4,
  127500. };
  127501. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127502. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127505. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127508. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127541. 0,
  127542. };
  127543. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127544. -1.5, -0.5, 0.5, 1.5,
  127545. };
  127546. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127547. 3, 1, 0, 2, 4,
  127548. };
  127549. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127550. _vq_quantthresh__44cn1_sm_p2_0,
  127551. _vq_quantmap__44cn1_sm_p2_0,
  127552. 5,
  127553. 5
  127554. };
  127555. static static_codebook _44cn1_sm_p2_0 = {
  127556. 4, 625,
  127557. _vq_lengthlist__44cn1_sm_p2_0,
  127558. 1, -533725184, 1611661312, 3, 0,
  127559. _vq_quantlist__44cn1_sm_p2_0,
  127560. NULL,
  127561. &_vq_auxt__44cn1_sm_p2_0,
  127562. NULL,
  127563. 0
  127564. };
  127565. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127566. 4,
  127567. 3,
  127568. 5,
  127569. 2,
  127570. 6,
  127571. 1,
  127572. 7,
  127573. 0,
  127574. 8,
  127575. };
  127576. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127577. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127578. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127579. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127580. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127581. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127582. 0,
  127583. };
  127584. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127585. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127586. };
  127587. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127588. 7, 5, 3, 1, 0, 2, 4, 6,
  127589. 8,
  127590. };
  127591. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127592. _vq_quantthresh__44cn1_sm_p3_0,
  127593. _vq_quantmap__44cn1_sm_p3_0,
  127594. 9,
  127595. 9
  127596. };
  127597. static static_codebook _44cn1_sm_p3_0 = {
  127598. 2, 81,
  127599. _vq_lengthlist__44cn1_sm_p3_0,
  127600. 1, -531628032, 1611661312, 4, 0,
  127601. _vq_quantlist__44cn1_sm_p3_0,
  127602. NULL,
  127603. &_vq_auxt__44cn1_sm_p3_0,
  127604. NULL,
  127605. 0
  127606. };
  127607. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127608. 4,
  127609. 3,
  127610. 5,
  127611. 2,
  127612. 6,
  127613. 1,
  127614. 7,
  127615. 0,
  127616. 8,
  127617. };
  127618. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127619. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127620. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127621. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127622. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127623. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127624. 11,
  127625. };
  127626. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127627. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127628. };
  127629. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127630. 7, 5, 3, 1, 0, 2, 4, 6,
  127631. 8,
  127632. };
  127633. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127634. _vq_quantthresh__44cn1_sm_p4_0,
  127635. _vq_quantmap__44cn1_sm_p4_0,
  127636. 9,
  127637. 9
  127638. };
  127639. static static_codebook _44cn1_sm_p4_0 = {
  127640. 2, 81,
  127641. _vq_lengthlist__44cn1_sm_p4_0,
  127642. 1, -531628032, 1611661312, 4, 0,
  127643. _vq_quantlist__44cn1_sm_p4_0,
  127644. NULL,
  127645. &_vq_auxt__44cn1_sm_p4_0,
  127646. NULL,
  127647. 0
  127648. };
  127649. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127650. 8,
  127651. 7,
  127652. 9,
  127653. 6,
  127654. 10,
  127655. 5,
  127656. 11,
  127657. 4,
  127658. 12,
  127659. 3,
  127660. 13,
  127661. 2,
  127662. 14,
  127663. 1,
  127664. 15,
  127665. 0,
  127666. 16,
  127667. };
  127668. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127669. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127670. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127671. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127672. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127673. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127674. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127675. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127676. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127677. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127678. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127679. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127680. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127681. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127682. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127683. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127684. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127685. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127686. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127687. 14,
  127688. };
  127689. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127690. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127691. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127692. };
  127693. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127694. 15, 13, 11, 9, 7, 5, 3, 1,
  127695. 0, 2, 4, 6, 8, 10, 12, 14,
  127696. 16,
  127697. };
  127698. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127699. _vq_quantthresh__44cn1_sm_p5_0,
  127700. _vq_quantmap__44cn1_sm_p5_0,
  127701. 17,
  127702. 17
  127703. };
  127704. static static_codebook _44cn1_sm_p5_0 = {
  127705. 2, 289,
  127706. _vq_lengthlist__44cn1_sm_p5_0,
  127707. 1, -529530880, 1611661312, 5, 0,
  127708. _vq_quantlist__44cn1_sm_p5_0,
  127709. NULL,
  127710. &_vq_auxt__44cn1_sm_p5_0,
  127711. NULL,
  127712. 0
  127713. };
  127714. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127715. 1,
  127716. 0,
  127717. 2,
  127718. };
  127719. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127720. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127721. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127722. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127723. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127724. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127725. 10,
  127726. };
  127727. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127728. -5.5, 5.5,
  127729. };
  127730. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127731. 1, 0, 2,
  127732. };
  127733. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127734. _vq_quantthresh__44cn1_sm_p6_0,
  127735. _vq_quantmap__44cn1_sm_p6_0,
  127736. 3,
  127737. 3
  127738. };
  127739. static static_codebook _44cn1_sm_p6_0 = {
  127740. 4, 81,
  127741. _vq_lengthlist__44cn1_sm_p6_0,
  127742. 1, -529137664, 1618345984, 2, 0,
  127743. _vq_quantlist__44cn1_sm_p6_0,
  127744. NULL,
  127745. &_vq_auxt__44cn1_sm_p6_0,
  127746. NULL,
  127747. 0
  127748. };
  127749. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127750. 5,
  127751. 4,
  127752. 6,
  127753. 3,
  127754. 7,
  127755. 2,
  127756. 8,
  127757. 1,
  127758. 9,
  127759. 0,
  127760. 10,
  127761. };
  127762. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127763. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127764. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127765. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127766. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127767. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127768. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127769. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127770. 10,10,10, 8, 9, 8, 8, 9, 8,
  127771. };
  127772. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127773. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127774. 3.5, 4.5,
  127775. };
  127776. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127777. 9, 7, 5, 3, 1, 0, 2, 4,
  127778. 6, 8, 10,
  127779. };
  127780. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127781. _vq_quantthresh__44cn1_sm_p6_1,
  127782. _vq_quantmap__44cn1_sm_p6_1,
  127783. 11,
  127784. 11
  127785. };
  127786. static static_codebook _44cn1_sm_p6_1 = {
  127787. 2, 121,
  127788. _vq_lengthlist__44cn1_sm_p6_1,
  127789. 1, -531365888, 1611661312, 4, 0,
  127790. _vq_quantlist__44cn1_sm_p6_1,
  127791. NULL,
  127792. &_vq_auxt__44cn1_sm_p6_1,
  127793. NULL,
  127794. 0
  127795. };
  127796. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127797. 6,
  127798. 5,
  127799. 7,
  127800. 4,
  127801. 8,
  127802. 3,
  127803. 9,
  127804. 2,
  127805. 10,
  127806. 1,
  127807. 11,
  127808. 0,
  127809. 12,
  127810. };
  127811. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127812. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127813. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127814. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127815. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127816. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127817. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127818. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127819. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127820. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127821. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127822. 0,13,12,12,12,13,13,13,14,
  127823. };
  127824. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127825. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127826. 12.5, 17.5, 22.5, 27.5,
  127827. };
  127828. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127829. 11, 9, 7, 5, 3, 1, 0, 2,
  127830. 4, 6, 8, 10, 12,
  127831. };
  127832. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127833. _vq_quantthresh__44cn1_sm_p7_0,
  127834. _vq_quantmap__44cn1_sm_p7_0,
  127835. 13,
  127836. 13
  127837. };
  127838. static static_codebook _44cn1_sm_p7_0 = {
  127839. 2, 169,
  127840. _vq_lengthlist__44cn1_sm_p7_0,
  127841. 1, -526516224, 1616117760, 4, 0,
  127842. _vq_quantlist__44cn1_sm_p7_0,
  127843. NULL,
  127844. &_vq_auxt__44cn1_sm_p7_0,
  127845. NULL,
  127846. 0
  127847. };
  127848. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127849. 2,
  127850. 1,
  127851. 3,
  127852. 0,
  127853. 4,
  127854. };
  127855. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127856. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127857. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127858. };
  127859. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127860. -1.5, -0.5, 0.5, 1.5,
  127861. };
  127862. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127863. 3, 1, 0, 2, 4,
  127864. };
  127865. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127866. _vq_quantthresh__44cn1_sm_p7_1,
  127867. _vq_quantmap__44cn1_sm_p7_1,
  127868. 5,
  127869. 5
  127870. };
  127871. static static_codebook _44cn1_sm_p7_1 = {
  127872. 2, 25,
  127873. _vq_lengthlist__44cn1_sm_p7_1,
  127874. 1, -533725184, 1611661312, 3, 0,
  127875. _vq_quantlist__44cn1_sm_p7_1,
  127876. NULL,
  127877. &_vq_auxt__44cn1_sm_p7_1,
  127878. NULL,
  127879. 0
  127880. };
  127881. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127882. 4,
  127883. 3,
  127884. 5,
  127885. 2,
  127886. 6,
  127887. 1,
  127888. 7,
  127889. 0,
  127890. 8,
  127891. };
  127892. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127893. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127894. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127895. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127896. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127897. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127898. 14,
  127899. };
  127900. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127901. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127902. };
  127903. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127904. 7, 5, 3, 1, 0, 2, 4, 6,
  127905. 8,
  127906. };
  127907. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127908. _vq_quantthresh__44cn1_sm_p8_0,
  127909. _vq_quantmap__44cn1_sm_p8_0,
  127910. 9,
  127911. 9
  127912. };
  127913. static static_codebook _44cn1_sm_p8_0 = {
  127914. 2, 81,
  127915. _vq_lengthlist__44cn1_sm_p8_0,
  127916. 1, -516186112, 1627103232, 4, 0,
  127917. _vq_quantlist__44cn1_sm_p8_0,
  127918. NULL,
  127919. &_vq_auxt__44cn1_sm_p8_0,
  127920. NULL,
  127921. 0
  127922. };
  127923. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127924. 6,
  127925. 5,
  127926. 7,
  127927. 4,
  127928. 8,
  127929. 3,
  127930. 9,
  127931. 2,
  127932. 10,
  127933. 1,
  127934. 11,
  127935. 0,
  127936. 12,
  127937. };
  127938. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127939. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127940. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127941. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127942. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127943. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127944. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127945. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127946. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127947. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127948. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127949. 17,12,12,11,10,13,11,13,13,
  127950. };
  127951. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127952. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127953. 42.5, 59.5, 76.5, 93.5,
  127954. };
  127955. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127956. 11, 9, 7, 5, 3, 1, 0, 2,
  127957. 4, 6, 8, 10, 12,
  127958. };
  127959. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127960. _vq_quantthresh__44cn1_sm_p8_1,
  127961. _vq_quantmap__44cn1_sm_p8_1,
  127962. 13,
  127963. 13
  127964. };
  127965. static static_codebook _44cn1_sm_p8_1 = {
  127966. 2, 169,
  127967. _vq_lengthlist__44cn1_sm_p8_1,
  127968. 1, -522616832, 1620115456, 4, 0,
  127969. _vq_quantlist__44cn1_sm_p8_1,
  127970. NULL,
  127971. &_vq_auxt__44cn1_sm_p8_1,
  127972. NULL,
  127973. 0
  127974. };
  127975. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127976. 8,
  127977. 7,
  127978. 9,
  127979. 6,
  127980. 10,
  127981. 5,
  127982. 11,
  127983. 4,
  127984. 12,
  127985. 3,
  127986. 13,
  127987. 2,
  127988. 14,
  127989. 1,
  127990. 15,
  127991. 0,
  127992. 16,
  127993. };
  127994. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127995. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127996. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127997. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127998. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127999. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  128000. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  128001. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  128002. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  128003. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  128004. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  128005. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  128006. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  128007. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  128008. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  128009. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  128010. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  128011. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  128012. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  128013. 9,
  128014. };
  128015. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  128016. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  128017. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  128018. };
  128019. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  128020. 15, 13, 11, 9, 7, 5, 3, 1,
  128021. 0, 2, 4, 6, 8, 10, 12, 14,
  128022. 16,
  128023. };
  128024. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  128025. _vq_quantthresh__44cn1_sm_p8_2,
  128026. _vq_quantmap__44cn1_sm_p8_2,
  128027. 17,
  128028. 17
  128029. };
  128030. static static_codebook _44cn1_sm_p8_2 = {
  128031. 2, 289,
  128032. _vq_lengthlist__44cn1_sm_p8_2,
  128033. 1, -529530880, 1611661312, 5, 0,
  128034. _vq_quantlist__44cn1_sm_p8_2,
  128035. NULL,
  128036. &_vq_auxt__44cn1_sm_p8_2,
  128037. NULL,
  128038. 0
  128039. };
  128040. static long _huff_lengthlist__44cn1_sm_short[] = {
  128041. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  128042. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  128043. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  128044. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  128045. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  128046. 9,
  128047. };
  128048. static static_codebook _huff_book__44cn1_sm_short = {
  128049. 2, 81,
  128050. _huff_lengthlist__44cn1_sm_short,
  128051. 0, 0, 0, 0, 0,
  128052. NULL,
  128053. NULL,
  128054. NULL,
  128055. NULL,
  128056. 0
  128057. };
  128058. /*** End of inlined file: res_books_stereo.h ***/
  128059. static vorbis_info_residue0 _residue_44_low={
  128060. 0,-1, -1, 9,-1,
  128061. {0},
  128062. {-1},
  128063. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128064. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  128065. };
  128066. static vorbis_info_residue0 _residue_44_mid={
  128067. 0,-1, -1, 10,-1,
  128068. {0},
  128069. {-1},
  128070. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128071. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  128072. };
  128073. static vorbis_info_residue0 _residue_44_high={
  128074. 0,-1, -1, 10,-1,
  128075. {0},
  128076. {-1},
  128077. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  128078. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  128079. };
  128080. static static_bookblock _resbook_44s_n1={
  128081. {
  128082. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  128083. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  128084. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  128085. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  128086. }
  128087. };
  128088. static static_bookblock _resbook_44sm_n1={
  128089. {
  128090. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  128091. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  128092. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  128093. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  128094. }
  128095. };
  128096. static static_bookblock _resbook_44s_0={
  128097. {
  128098. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128099. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128100. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128101. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128102. }
  128103. };
  128104. static static_bookblock _resbook_44sm_0={
  128105. {
  128106. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128107. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128108. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128109. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128110. }
  128111. };
  128112. static static_bookblock _resbook_44s_1={
  128113. {
  128114. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128115. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128116. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128117. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128118. }
  128119. };
  128120. static static_bookblock _resbook_44sm_1={
  128121. {
  128122. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128123. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128124. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128125. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128126. }
  128127. };
  128128. static static_bookblock _resbook_44s_2={
  128129. {
  128130. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128131. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128132. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128133. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128134. }
  128135. };
  128136. static static_bookblock _resbook_44s_3={
  128137. {
  128138. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128139. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128140. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128141. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128142. }
  128143. };
  128144. static static_bookblock _resbook_44s_4={
  128145. {
  128146. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128147. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128148. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128149. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128150. }
  128151. };
  128152. static static_bookblock _resbook_44s_5={
  128153. {
  128154. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128155. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128156. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128157. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128158. }
  128159. };
  128160. static static_bookblock _resbook_44s_6={
  128161. {
  128162. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128163. {0,0,&_44c6_s_p4_0},
  128164. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128165. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128166. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128167. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128168. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128169. }
  128170. };
  128171. static static_bookblock _resbook_44s_7={
  128172. {
  128173. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128174. {0,0,&_44c7_s_p4_0},
  128175. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128176. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128177. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128178. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128179. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128180. }
  128181. };
  128182. static static_bookblock _resbook_44s_8={
  128183. {
  128184. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128185. {0,0,&_44c8_s_p4_0},
  128186. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128187. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128188. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128189. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128190. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128191. }
  128192. };
  128193. static static_bookblock _resbook_44s_9={
  128194. {
  128195. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128196. {0,0,&_44c9_s_p4_0},
  128197. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128198. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128199. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128200. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128201. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128202. }
  128203. };
  128204. static vorbis_residue_template _res_44s_n1[]={
  128205. {2,0, &_residue_44_low,
  128206. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128207. &_resbook_44s_n1,&_resbook_44sm_n1},
  128208. {2,0, &_residue_44_low,
  128209. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128210. &_resbook_44s_n1,&_resbook_44sm_n1}
  128211. };
  128212. static vorbis_residue_template _res_44s_0[]={
  128213. {2,0, &_residue_44_low,
  128214. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128215. &_resbook_44s_0,&_resbook_44sm_0},
  128216. {2,0, &_residue_44_low,
  128217. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128218. &_resbook_44s_0,&_resbook_44sm_0}
  128219. };
  128220. static vorbis_residue_template _res_44s_1[]={
  128221. {2,0, &_residue_44_low,
  128222. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128223. &_resbook_44s_1,&_resbook_44sm_1},
  128224. {2,0, &_residue_44_low,
  128225. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128226. &_resbook_44s_1,&_resbook_44sm_1}
  128227. };
  128228. static vorbis_residue_template _res_44s_2[]={
  128229. {2,0, &_residue_44_mid,
  128230. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128231. &_resbook_44s_2,&_resbook_44s_2},
  128232. {2,0, &_residue_44_mid,
  128233. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128234. &_resbook_44s_2,&_resbook_44s_2}
  128235. };
  128236. static vorbis_residue_template _res_44s_3[]={
  128237. {2,0, &_residue_44_mid,
  128238. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128239. &_resbook_44s_3,&_resbook_44s_3},
  128240. {2,0, &_residue_44_mid,
  128241. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128242. &_resbook_44s_3,&_resbook_44s_3}
  128243. };
  128244. static vorbis_residue_template _res_44s_4[]={
  128245. {2,0, &_residue_44_mid,
  128246. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128247. &_resbook_44s_4,&_resbook_44s_4},
  128248. {2,0, &_residue_44_mid,
  128249. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128250. &_resbook_44s_4,&_resbook_44s_4}
  128251. };
  128252. static vorbis_residue_template _res_44s_5[]={
  128253. {2,0, &_residue_44_mid,
  128254. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128255. &_resbook_44s_5,&_resbook_44s_5},
  128256. {2,0, &_residue_44_mid,
  128257. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128258. &_resbook_44s_5,&_resbook_44s_5}
  128259. };
  128260. static vorbis_residue_template _res_44s_6[]={
  128261. {2,0, &_residue_44_high,
  128262. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128263. &_resbook_44s_6,&_resbook_44s_6},
  128264. {2,0, &_residue_44_high,
  128265. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128266. &_resbook_44s_6,&_resbook_44s_6}
  128267. };
  128268. static vorbis_residue_template _res_44s_7[]={
  128269. {2,0, &_residue_44_high,
  128270. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128271. &_resbook_44s_7,&_resbook_44s_7},
  128272. {2,0, &_residue_44_high,
  128273. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128274. &_resbook_44s_7,&_resbook_44s_7}
  128275. };
  128276. static vorbis_residue_template _res_44s_8[]={
  128277. {2,0, &_residue_44_high,
  128278. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128279. &_resbook_44s_8,&_resbook_44s_8},
  128280. {2,0, &_residue_44_high,
  128281. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128282. &_resbook_44s_8,&_resbook_44s_8}
  128283. };
  128284. static vorbis_residue_template _res_44s_9[]={
  128285. {2,0, &_residue_44_high,
  128286. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128287. &_resbook_44s_9,&_resbook_44s_9},
  128288. {2,0, &_residue_44_high,
  128289. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128290. &_resbook_44s_9,&_resbook_44s_9}
  128291. };
  128292. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128293. { _map_nominal, _res_44s_n1 }, /* -1 */
  128294. { _map_nominal, _res_44s_0 }, /* 0 */
  128295. { _map_nominal, _res_44s_1 }, /* 1 */
  128296. { _map_nominal, _res_44s_2 }, /* 2 */
  128297. { _map_nominal, _res_44s_3 }, /* 3 */
  128298. { _map_nominal, _res_44s_4 }, /* 4 */
  128299. { _map_nominal, _res_44s_5 }, /* 5 */
  128300. { _map_nominal, _res_44s_6 }, /* 6 */
  128301. { _map_nominal, _res_44s_7 }, /* 7 */
  128302. { _map_nominal, _res_44s_8 }, /* 8 */
  128303. { _map_nominal, _res_44s_9 }, /* 9 */
  128304. };
  128305. /*** End of inlined file: residue_44.h ***/
  128306. /*** Start of inlined file: psych_44.h ***/
  128307. static vorbis_info_psy_global _psy_global_44[5]={
  128308. {8, /* lines per eighth octave */
  128309. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128310. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128311. -6.f,
  128312. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128313. },
  128314. {8, /* lines per eighth octave */
  128315. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128316. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128317. -6.f,
  128318. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128319. },
  128320. {8, /* lines per eighth octave */
  128321. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128322. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128323. -6.f,
  128324. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128325. },
  128326. {8, /* lines per eighth octave */
  128327. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128328. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128329. -6.f,
  128330. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128331. },
  128332. {8, /* lines per eighth octave */
  128333. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128334. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128335. -6.f,
  128336. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128337. },
  128338. };
  128339. static compandblock _psy_compand_44[6]={
  128340. {{
  128341. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128342. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128343. 16,17,18,19,20,21,22, 23, /* 23dB */
  128344. 24,25,26,27,28,29,30, 31, /* 31dB */
  128345. 32,33,34,35,36,37,38, 39, /* 39dB */
  128346. }},
  128347. {{
  128348. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128349. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128350. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128351. 15,16,17,17,17,18,18, 19, /* 31dB */
  128352. 19,19,20,21,22,23,24, 25, /* 39dB */
  128353. }},
  128354. {{
  128355. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128356. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128357. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128358. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128359. 11,12,13,14,15,16,17, 18, /* 39dB */
  128360. }},
  128361. {{
  128362. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128363. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128364. 16,17,18,19,20,21,22, 23, /* 23dB */
  128365. 24,25,26,27,28,29,30, 31, /* 31dB */
  128366. 32,33,34,35,36,37,38, 39, /* 39dB */
  128367. }},
  128368. {{
  128369. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128370. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128371. 13,14,14,14,15,15,15, 15, /* 23dB */
  128372. 16,16,17,17,17,18,18, 19, /* 31dB */
  128373. 19,19,20,21,22,23,24, 25, /* 39dB */
  128374. }},
  128375. {{
  128376. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128377. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128378. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128379. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128380. 11,12,13,14,15,16,17, 18, /* 39dB */
  128381. }}
  128382. };
  128383. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128384. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128385. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128386. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128387. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128388. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128389. /* 4 */
  128390. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128391. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128392. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128393. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128394. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128395. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128396. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128397. };
  128398. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128399. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128400. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128401. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128402. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128403. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128404. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128405. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128406. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128407. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128408. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128409. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128410. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128411. };
  128412. static noise3 _psy_noisebias_trans[12]={
  128413. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128414. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128415. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128416. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128417. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128418. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128419. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128420. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128421. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128422. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128423. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128424. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128425. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128426. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128427. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128428. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128429. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128430. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128431. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128432. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128433. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128434. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128435. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128436. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128437. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128438. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128439. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128440. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128441. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128442. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128443. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128444. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128445. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128446. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128447. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128448. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128449. };
  128450. static noise3 _psy_noisebias_long[12]={
  128451. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128452. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128453. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128454. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128455. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128456. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128457. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128458. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128459. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128460. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128461. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128462. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128463. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128464. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128465. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128466. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128467. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128468. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128469. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128470. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128471. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128472. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128473. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128474. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128475. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128476. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128477. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128478. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128479. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128480. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128481. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128482. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128483. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128484. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128485. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128486. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128487. };
  128488. static noise3 _psy_noisebias_impulse[12]={
  128489. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128490. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128491. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128492. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128493. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128494. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128495. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128496. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128497. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128498. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128499. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128500. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128501. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128502. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128503. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128504. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128505. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128506. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128507. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128508. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128509. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128510. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128511. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128512. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128513. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128514. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128515. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128516. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128517. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128518. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128519. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128520. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128521. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128522. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128523. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128524. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128525. };
  128526. static noise3 _psy_noisebias_padding[12]={
  128527. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128528. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128529. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128530. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128531. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128532. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128533. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128534. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128535. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128536. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128537. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128538. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128539. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128540. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128541. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128542. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128543. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128544. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128545. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128546. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128547. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128548. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128549. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128550. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128551. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128552. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128553. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128554. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128555. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128556. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128557. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128558. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128559. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128560. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128561. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128562. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128563. };
  128564. static noiseguard _psy_noiseguards_44[4]={
  128565. {3,3,15},
  128566. {3,3,15},
  128567. {10,10,100},
  128568. {10,10,100},
  128569. };
  128570. static int _psy_tone_suppress[12]={
  128571. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128572. };
  128573. static int _psy_tone_0dB[12]={
  128574. 90,90,95,95,95,95,105,105,105,105,105,105,
  128575. };
  128576. static int _psy_noise_suppress[12]={
  128577. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128578. };
  128579. static vorbis_info_psy _psy_info_template={
  128580. -1,
  128581. -140.,-140.,
  128582. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128583. 1, -0.f, .5f, .5f, 0,0,0,
  128584. {{-1},{-1},{-1}},{-1},105.f,
  128585. 0,0,-1,-1,0.,
  128586. };
  128587. static int _psy_ath_floater[12]={
  128588. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128589. };
  128590. static int _psy_ath_abs[12]={
  128591. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128592. };
  128593. static adj_stereo _psy_stereo_modes_44[12]={
  128594. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128595. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128596. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128597. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128598. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128599. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128600. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128601. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128602. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128603. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128604. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128605. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128606. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128607. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128608. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128609. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128610. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128611. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128612. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128613. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128614. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128615. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128616. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128617. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128618. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128619. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128620. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128621. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128622. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128623. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128624. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128625. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128626. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128627. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128628. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128629. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128630. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128631. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128632. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128633. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128634. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128635. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128636. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128637. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128638. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128639. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128640. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128641. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128642. };
  128643. static att3 _psy_tone_masteratt_44[12]={
  128644. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128645. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128646. /* 1 */
  128647. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128648. /* 2 */
  128649. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128650. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128651. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128652. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128653. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128654. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128655. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128656. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128657. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128658. };
  128659. static double _psy_lowpass_44[12]={
  128660. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128661. };
  128662. static int _noise_start_short_44[11]={
  128663. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128664. };
  128665. static int _noise_start_long_44[11]={
  128666. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128667. };
  128668. static int _noise_part_short_44[11]={
  128669. 8,8,8,8,8,8,8,8,8,8,8
  128670. };
  128671. static int _noise_part_long_44[11]={
  128672. 32,32,32,32,32,32,32,32,32,32,32
  128673. };
  128674. static double _noise_thresh_44[11]={
  128675. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128676. };
  128677. static double _noise_thresh_5only[2]={
  128678. .5,.5,
  128679. };
  128680. /*** End of inlined file: psych_44.h ***/
  128681. static double rate_mapping_44_stereo[12]={
  128682. 22500.,32000.,40000.,48000.,56000.,64000.,
  128683. 80000.,96000.,112000.,128000.,160000.,250001.
  128684. };
  128685. static double quality_mapping_44[12]={
  128686. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128687. };
  128688. static int blocksize_short_44[11]={
  128689. 512,256,256,256,256,256,256,256,256,256,256
  128690. };
  128691. static int blocksize_long_44[11]={
  128692. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128693. };
  128694. static double _psy_compand_short_mapping[12]={
  128695. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128696. };
  128697. static double _psy_compand_long_mapping[12]={
  128698. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128699. };
  128700. static double _global_mapping_44[12]={
  128701. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128702. };
  128703. static int _floor_short_mapping_44[11]={
  128704. 1,0,0,2,2,4,5,5,5,5,5
  128705. };
  128706. static int _floor_long_mapping_44[11]={
  128707. 8,7,7,7,7,7,7,7,7,7,7
  128708. };
  128709. ve_setup_data_template ve_setup_44_stereo={
  128710. 11,
  128711. rate_mapping_44_stereo,
  128712. quality_mapping_44,
  128713. 2,
  128714. 40000,
  128715. 50000,
  128716. blocksize_short_44,
  128717. blocksize_long_44,
  128718. _psy_tone_masteratt_44,
  128719. _psy_tone_0dB,
  128720. _psy_tone_suppress,
  128721. _vp_tonemask_adj_otherblock,
  128722. _vp_tonemask_adj_longblock,
  128723. _vp_tonemask_adj_otherblock,
  128724. _psy_noiseguards_44,
  128725. _psy_noisebias_impulse,
  128726. _psy_noisebias_padding,
  128727. _psy_noisebias_trans,
  128728. _psy_noisebias_long,
  128729. _psy_noise_suppress,
  128730. _psy_compand_44,
  128731. _psy_compand_short_mapping,
  128732. _psy_compand_long_mapping,
  128733. {_noise_start_short_44,_noise_start_long_44},
  128734. {_noise_part_short_44,_noise_part_long_44},
  128735. _noise_thresh_44,
  128736. _psy_ath_floater,
  128737. _psy_ath_abs,
  128738. _psy_lowpass_44,
  128739. _psy_global_44,
  128740. _global_mapping_44,
  128741. _psy_stereo_modes_44,
  128742. _floor_books,
  128743. _floor,
  128744. _floor_short_mapping_44,
  128745. _floor_long_mapping_44,
  128746. _mapres_template_44_stereo
  128747. };
  128748. /*** End of inlined file: setup_44.h ***/
  128749. /*** Start of inlined file: setup_44u.h ***/
  128750. /*** Start of inlined file: residue_44u.h ***/
  128751. /*** Start of inlined file: res_books_uncoupled.h ***/
  128752. static long _vq_quantlist__16u0__p1_0[] = {
  128753. 1,
  128754. 0,
  128755. 2,
  128756. };
  128757. static long _vq_lengthlist__16u0__p1_0[] = {
  128758. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128759. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128760. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128761. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128762. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128763. 12,
  128764. };
  128765. static float _vq_quantthresh__16u0__p1_0[] = {
  128766. -0.5, 0.5,
  128767. };
  128768. static long _vq_quantmap__16u0__p1_0[] = {
  128769. 1, 0, 2,
  128770. };
  128771. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128772. _vq_quantthresh__16u0__p1_0,
  128773. _vq_quantmap__16u0__p1_0,
  128774. 3,
  128775. 3
  128776. };
  128777. static static_codebook _16u0__p1_0 = {
  128778. 4, 81,
  128779. _vq_lengthlist__16u0__p1_0,
  128780. 1, -535822336, 1611661312, 2, 0,
  128781. _vq_quantlist__16u0__p1_0,
  128782. NULL,
  128783. &_vq_auxt__16u0__p1_0,
  128784. NULL,
  128785. 0
  128786. };
  128787. static long _vq_quantlist__16u0__p2_0[] = {
  128788. 1,
  128789. 0,
  128790. 2,
  128791. };
  128792. static long _vq_lengthlist__16u0__p2_0[] = {
  128793. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128794. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128795. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128796. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128797. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128798. 8,
  128799. };
  128800. static float _vq_quantthresh__16u0__p2_0[] = {
  128801. -0.5, 0.5,
  128802. };
  128803. static long _vq_quantmap__16u0__p2_0[] = {
  128804. 1, 0, 2,
  128805. };
  128806. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128807. _vq_quantthresh__16u0__p2_0,
  128808. _vq_quantmap__16u0__p2_0,
  128809. 3,
  128810. 3
  128811. };
  128812. static static_codebook _16u0__p2_0 = {
  128813. 4, 81,
  128814. _vq_lengthlist__16u0__p2_0,
  128815. 1, -535822336, 1611661312, 2, 0,
  128816. _vq_quantlist__16u0__p2_0,
  128817. NULL,
  128818. &_vq_auxt__16u0__p2_0,
  128819. NULL,
  128820. 0
  128821. };
  128822. static long _vq_quantlist__16u0__p3_0[] = {
  128823. 2,
  128824. 1,
  128825. 3,
  128826. 0,
  128827. 4,
  128828. };
  128829. static long _vq_lengthlist__16u0__p3_0[] = {
  128830. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128831. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128832. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128833. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128834. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128835. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128836. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128837. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128838. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128839. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128840. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128841. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128842. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128843. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128844. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128845. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128846. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128847. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128848. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128849. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128850. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128851. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128852. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128853. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128854. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128855. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128856. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128857. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128858. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128859. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128860. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128861. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128862. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128863. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128864. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128865. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128866. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128867. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128868. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128869. 18,
  128870. };
  128871. static float _vq_quantthresh__16u0__p3_0[] = {
  128872. -1.5, -0.5, 0.5, 1.5,
  128873. };
  128874. static long _vq_quantmap__16u0__p3_0[] = {
  128875. 3, 1, 0, 2, 4,
  128876. };
  128877. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128878. _vq_quantthresh__16u0__p3_0,
  128879. _vq_quantmap__16u0__p3_0,
  128880. 5,
  128881. 5
  128882. };
  128883. static static_codebook _16u0__p3_0 = {
  128884. 4, 625,
  128885. _vq_lengthlist__16u0__p3_0,
  128886. 1, -533725184, 1611661312, 3, 0,
  128887. _vq_quantlist__16u0__p3_0,
  128888. NULL,
  128889. &_vq_auxt__16u0__p3_0,
  128890. NULL,
  128891. 0
  128892. };
  128893. static long _vq_quantlist__16u0__p4_0[] = {
  128894. 2,
  128895. 1,
  128896. 3,
  128897. 0,
  128898. 4,
  128899. };
  128900. static long _vq_lengthlist__16u0__p4_0[] = {
  128901. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128902. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128903. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128904. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128905. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128906. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128907. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128908. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128909. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128910. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128911. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128912. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128913. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128914. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128915. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128916. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128917. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128918. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128919. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128920. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128921. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128922. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128923. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128924. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128925. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128926. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128927. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128928. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128929. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128930. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128931. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128932. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128933. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128934. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128935. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128936. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128937. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128938. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128939. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128940. 11,
  128941. };
  128942. static float _vq_quantthresh__16u0__p4_0[] = {
  128943. -1.5, -0.5, 0.5, 1.5,
  128944. };
  128945. static long _vq_quantmap__16u0__p4_0[] = {
  128946. 3, 1, 0, 2, 4,
  128947. };
  128948. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128949. _vq_quantthresh__16u0__p4_0,
  128950. _vq_quantmap__16u0__p4_0,
  128951. 5,
  128952. 5
  128953. };
  128954. static static_codebook _16u0__p4_0 = {
  128955. 4, 625,
  128956. _vq_lengthlist__16u0__p4_0,
  128957. 1, -533725184, 1611661312, 3, 0,
  128958. _vq_quantlist__16u0__p4_0,
  128959. NULL,
  128960. &_vq_auxt__16u0__p4_0,
  128961. NULL,
  128962. 0
  128963. };
  128964. static long _vq_quantlist__16u0__p5_0[] = {
  128965. 4,
  128966. 3,
  128967. 5,
  128968. 2,
  128969. 6,
  128970. 1,
  128971. 7,
  128972. 0,
  128973. 8,
  128974. };
  128975. static long _vq_lengthlist__16u0__p5_0[] = {
  128976. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128977. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128978. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128979. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128980. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128981. 12,
  128982. };
  128983. static float _vq_quantthresh__16u0__p5_0[] = {
  128984. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128985. };
  128986. static long _vq_quantmap__16u0__p5_0[] = {
  128987. 7, 5, 3, 1, 0, 2, 4, 6,
  128988. 8,
  128989. };
  128990. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128991. _vq_quantthresh__16u0__p5_0,
  128992. _vq_quantmap__16u0__p5_0,
  128993. 9,
  128994. 9
  128995. };
  128996. static static_codebook _16u0__p5_0 = {
  128997. 2, 81,
  128998. _vq_lengthlist__16u0__p5_0,
  128999. 1, -531628032, 1611661312, 4, 0,
  129000. _vq_quantlist__16u0__p5_0,
  129001. NULL,
  129002. &_vq_auxt__16u0__p5_0,
  129003. NULL,
  129004. 0
  129005. };
  129006. static long _vq_quantlist__16u0__p6_0[] = {
  129007. 6,
  129008. 5,
  129009. 7,
  129010. 4,
  129011. 8,
  129012. 3,
  129013. 9,
  129014. 2,
  129015. 10,
  129016. 1,
  129017. 11,
  129018. 0,
  129019. 12,
  129020. };
  129021. static long _vq_lengthlist__16u0__p6_0[] = {
  129022. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  129023. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  129024. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  129025. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  129026. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  129027. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  129028. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  129029. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  129030. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  129031. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  129032. 18, 0,19, 0, 0, 0, 0, 0, 0,
  129033. };
  129034. static float _vq_quantthresh__16u0__p6_0[] = {
  129035. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129036. 12.5, 17.5, 22.5, 27.5,
  129037. };
  129038. static long _vq_quantmap__16u0__p6_0[] = {
  129039. 11, 9, 7, 5, 3, 1, 0, 2,
  129040. 4, 6, 8, 10, 12,
  129041. };
  129042. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  129043. _vq_quantthresh__16u0__p6_0,
  129044. _vq_quantmap__16u0__p6_0,
  129045. 13,
  129046. 13
  129047. };
  129048. static static_codebook _16u0__p6_0 = {
  129049. 2, 169,
  129050. _vq_lengthlist__16u0__p6_0,
  129051. 1, -526516224, 1616117760, 4, 0,
  129052. _vq_quantlist__16u0__p6_0,
  129053. NULL,
  129054. &_vq_auxt__16u0__p6_0,
  129055. NULL,
  129056. 0
  129057. };
  129058. static long _vq_quantlist__16u0__p6_1[] = {
  129059. 2,
  129060. 1,
  129061. 3,
  129062. 0,
  129063. 4,
  129064. };
  129065. static long _vq_lengthlist__16u0__p6_1[] = {
  129066. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  129067. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  129068. };
  129069. static float _vq_quantthresh__16u0__p6_1[] = {
  129070. -1.5, -0.5, 0.5, 1.5,
  129071. };
  129072. static long _vq_quantmap__16u0__p6_1[] = {
  129073. 3, 1, 0, 2, 4,
  129074. };
  129075. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  129076. _vq_quantthresh__16u0__p6_1,
  129077. _vq_quantmap__16u0__p6_1,
  129078. 5,
  129079. 5
  129080. };
  129081. static static_codebook _16u0__p6_1 = {
  129082. 2, 25,
  129083. _vq_lengthlist__16u0__p6_1,
  129084. 1, -533725184, 1611661312, 3, 0,
  129085. _vq_quantlist__16u0__p6_1,
  129086. NULL,
  129087. &_vq_auxt__16u0__p6_1,
  129088. NULL,
  129089. 0
  129090. };
  129091. static long _vq_quantlist__16u0__p7_0[] = {
  129092. 1,
  129093. 0,
  129094. 2,
  129095. };
  129096. static long _vq_lengthlist__16u0__p7_0[] = {
  129097. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129098. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129099. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129100. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129101. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129102. 7,
  129103. };
  129104. static float _vq_quantthresh__16u0__p7_0[] = {
  129105. -157.5, 157.5,
  129106. };
  129107. static long _vq_quantmap__16u0__p7_0[] = {
  129108. 1, 0, 2,
  129109. };
  129110. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129111. _vq_quantthresh__16u0__p7_0,
  129112. _vq_quantmap__16u0__p7_0,
  129113. 3,
  129114. 3
  129115. };
  129116. static static_codebook _16u0__p7_0 = {
  129117. 4, 81,
  129118. _vq_lengthlist__16u0__p7_0,
  129119. 1, -518803456, 1628680192, 2, 0,
  129120. _vq_quantlist__16u0__p7_0,
  129121. NULL,
  129122. &_vq_auxt__16u0__p7_0,
  129123. NULL,
  129124. 0
  129125. };
  129126. static long _vq_quantlist__16u0__p7_1[] = {
  129127. 7,
  129128. 6,
  129129. 8,
  129130. 5,
  129131. 9,
  129132. 4,
  129133. 10,
  129134. 3,
  129135. 11,
  129136. 2,
  129137. 12,
  129138. 1,
  129139. 13,
  129140. 0,
  129141. 14,
  129142. };
  129143. static long _vq_lengthlist__16u0__p7_1[] = {
  129144. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129145. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129146. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129147. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129148. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129149. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129150. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129151. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129152. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129153. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129154. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129155. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129156. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129157. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129158. 10,
  129159. };
  129160. static float _vq_quantthresh__16u0__p7_1[] = {
  129161. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129162. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129163. };
  129164. static long _vq_quantmap__16u0__p7_1[] = {
  129165. 13, 11, 9, 7, 5, 3, 1, 0,
  129166. 2, 4, 6, 8, 10, 12, 14,
  129167. };
  129168. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129169. _vq_quantthresh__16u0__p7_1,
  129170. _vq_quantmap__16u0__p7_1,
  129171. 15,
  129172. 15
  129173. };
  129174. static static_codebook _16u0__p7_1 = {
  129175. 2, 225,
  129176. _vq_lengthlist__16u0__p7_1,
  129177. 1, -520986624, 1620377600, 4, 0,
  129178. _vq_quantlist__16u0__p7_1,
  129179. NULL,
  129180. &_vq_auxt__16u0__p7_1,
  129181. NULL,
  129182. 0
  129183. };
  129184. static long _vq_quantlist__16u0__p7_2[] = {
  129185. 10,
  129186. 9,
  129187. 11,
  129188. 8,
  129189. 12,
  129190. 7,
  129191. 13,
  129192. 6,
  129193. 14,
  129194. 5,
  129195. 15,
  129196. 4,
  129197. 16,
  129198. 3,
  129199. 17,
  129200. 2,
  129201. 18,
  129202. 1,
  129203. 19,
  129204. 0,
  129205. 20,
  129206. };
  129207. static long _vq_lengthlist__16u0__p7_2[] = {
  129208. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129209. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129210. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129211. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129212. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129213. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129214. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129215. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129216. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129217. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129218. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129219. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129220. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129221. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129222. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129223. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129224. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129225. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129226. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129227. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129228. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129229. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129230. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129231. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129232. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129233. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129234. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129235. 10,10,12,11,10,11,11,11,10,
  129236. };
  129237. static float _vq_quantthresh__16u0__p7_2[] = {
  129238. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129239. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129240. 6.5, 7.5, 8.5, 9.5,
  129241. };
  129242. static long _vq_quantmap__16u0__p7_2[] = {
  129243. 19, 17, 15, 13, 11, 9, 7, 5,
  129244. 3, 1, 0, 2, 4, 6, 8, 10,
  129245. 12, 14, 16, 18, 20,
  129246. };
  129247. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129248. _vq_quantthresh__16u0__p7_2,
  129249. _vq_quantmap__16u0__p7_2,
  129250. 21,
  129251. 21
  129252. };
  129253. static static_codebook _16u0__p7_2 = {
  129254. 2, 441,
  129255. _vq_lengthlist__16u0__p7_2,
  129256. 1, -529268736, 1611661312, 5, 0,
  129257. _vq_quantlist__16u0__p7_2,
  129258. NULL,
  129259. &_vq_auxt__16u0__p7_2,
  129260. NULL,
  129261. 0
  129262. };
  129263. static long _huff_lengthlist__16u0__single[] = {
  129264. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129265. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129266. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129267. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129268. };
  129269. static static_codebook _huff_book__16u0__single = {
  129270. 2, 64,
  129271. _huff_lengthlist__16u0__single,
  129272. 0, 0, 0, 0, 0,
  129273. NULL,
  129274. NULL,
  129275. NULL,
  129276. NULL,
  129277. 0
  129278. };
  129279. static long _huff_lengthlist__16u1__long[] = {
  129280. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129281. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129282. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129283. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129284. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129285. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129286. 16,13,16,18,
  129287. };
  129288. static static_codebook _huff_book__16u1__long = {
  129289. 2, 100,
  129290. _huff_lengthlist__16u1__long,
  129291. 0, 0, 0, 0, 0,
  129292. NULL,
  129293. NULL,
  129294. NULL,
  129295. NULL,
  129296. 0
  129297. };
  129298. static long _vq_quantlist__16u1__p1_0[] = {
  129299. 1,
  129300. 0,
  129301. 2,
  129302. };
  129303. static long _vq_lengthlist__16u1__p1_0[] = {
  129304. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129305. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129306. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129307. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129308. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129309. 11,
  129310. };
  129311. static float _vq_quantthresh__16u1__p1_0[] = {
  129312. -0.5, 0.5,
  129313. };
  129314. static long _vq_quantmap__16u1__p1_0[] = {
  129315. 1, 0, 2,
  129316. };
  129317. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129318. _vq_quantthresh__16u1__p1_0,
  129319. _vq_quantmap__16u1__p1_0,
  129320. 3,
  129321. 3
  129322. };
  129323. static static_codebook _16u1__p1_0 = {
  129324. 4, 81,
  129325. _vq_lengthlist__16u1__p1_0,
  129326. 1, -535822336, 1611661312, 2, 0,
  129327. _vq_quantlist__16u1__p1_0,
  129328. NULL,
  129329. &_vq_auxt__16u1__p1_0,
  129330. NULL,
  129331. 0
  129332. };
  129333. static long _vq_quantlist__16u1__p2_0[] = {
  129334. 1,
  129335. 0,
  129336. 2,
  129337. };
  129338. static long _vq_lengthlist__16u1__p2_0[] = {
  129339. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129340. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129341. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129342. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129343. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129344. 8,
  129345. };
  129346. static float _vq_quantthresh__16u1__p2_0[] = {
  129347. -0.5, 0.5,
  129348. };
  129349. static long _vq_quantmap__16u1__p2_0[] = {
  129350. 1, 0, 2,
  129351. };
  129352. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129353. _vq_quantthresh__16u1__p2_0,
  129354. _vq_quantmap__16u1__p2_0,
  129355. 3,
  129356. 3
  129357. };
  129358. static static_codebook _16u1__p2_0 = {
  129359. 4, 81,
  129360. _vq_lengthlist__16u1__p2_0,
  129361. 1, -535822336, 1611661312, 2, 0,
  129362. _vq_quantlist__16u1__p2_0,
  129363. NULL,
  129364. &_vq_auxt__16u1__p2_0,
  129365. NULL,
  129366. 0
  129367. };
  129368. static long _vq_quantlist__16u1__p3_0[] = {
  129369. 2,
  129370. 1,
  129371. 3,
  129372. 0,
  129373. 4,
  129374. };
  129375. static long _vq_lengthlist__16u1__p3_0[] = {
  129376. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129377. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129378. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129379. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129380. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129381. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129382. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129383. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129384. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129385. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129386. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129387. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129388. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129389. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129390. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129391. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129392. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129393. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129394. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129395. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129396. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129397. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129398. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129399. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129400. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129401. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129402. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129403. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129404. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129405. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129406. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129407. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129408. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129409. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129410. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129411. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129412. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129413. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129414. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129415. 16,
  129416. };
  129417. static float _vq_quantthresh__16u1__p3_0[] = {
  129418. -1.5, -0.5, 0.5, 1.5,
  129419. };
  129420. static long _vq_quantmap__16u1__p3_0[] = {
  129421. 3, 1, 0, 2, 4,
  129422. };
  129423. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129424. _vq_quantthresh__16u1__p3_0,
  129425. _vq_quantmap__16u1__p3_0,
  129426. 5,
  129427. 5
  129428. };
  129429. static static_codebook _16u1__p3_0 = {
  129430. 4, 625,
  129431. _vq_lengthlist__16u1__p3_0,
  129432. 1, -533725184, 1611661312, 3, 0,
  129433. _vq_quantlist__16u1__p3_0,
  129434. NULL,
  129435. &_vq_auxt__16u1__p3_0,
  129436. NULL,
  129437. 0
  129438. };
  129439. static long _vq_quantlist__16u1__p4_0[] = {
  129440. 2,
  129441. 1,
  129442. 3,
  129443. 0,
  129444. 4,
  129445. };
  129446. static long _vq_lengthlist__16u1__p4_0[] = {
  129447. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129448. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129449. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129450. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129451. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129452. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129453. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129454. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129455. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129456. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129457. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129458. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129459. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129460. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129461. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129462. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129463. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129464. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129465. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129466. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129467. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129468. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129469. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129470. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129471. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129472. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129473. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129474. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129475. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129476. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129477. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129478. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129479. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129480. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129481. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129482. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129483. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129484. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129485. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129486. 11,
  129487. };
  129488. static float _vq_quantthresh__16u1__p4_0[] = {
  129489. -1.5, -0.5, 0.5, 1.5,
  129490. };
  129491. static long _vq_quantmap__16u1__p4_0[] = {
  129492. 3, 1, 0, 2, 4,
  129493. };
  129494. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129495. _vq_quantthresh__16u1__p4_0,
  129496. _vq_quantmap__16u1__p4_0,
  129497. 5,
  129498. 5
  129499. };
  129500. static static_codebook _16u1__p4_0 = {
  129501. 4, 625,
  129502. _vq_lengthlist__16u1__p4_0,
  129503. 1, -533725184, 1611661312, 3, 0,
  129504. _vq_quantlist__16u1__p4_0,
  129505. NULL,
  129506. &_vq_auxt__16u1__p4_0,
  129507. NULL,
  129508. 0
  129509. };
  129510. static long _vq_quantlist__16u1__p5_0[] = {
  129511. 4,
  129512. 3,
  129513. 5,
  129514. 2,
  129515. 6,
  129516. 1,
  129517. 7,
  129518. 0,
  129519. 8,
  129520. };
  129521. static long _vq_lengthlist__16u1__p5_0[] = {
  129522. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129523. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129524. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129525. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129526. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129527. 13,
  129528. };
  129529. static float _vq_quantthresh__16u1__p5_0[] = {
  129530. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129531. };
  129532. static long _vq_quantmap__16u1__p5_0[] = {
  129533. 7, 5, 3, 1, 0, 2, 4, 6,
  129534. 8,
  129535. };
  129536. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129537. _vq_quantthresh__16u1__p5_0,
  129538. _vq_quantmap__16u1__p5_0,
  129539. 9,
  129540. 9
  129541. };
  129542. static static_codebook _16u1__p5_0 = {
  129543. 2, 81,
  129544. _vq_lengthlist__16u1__p5_0,
  129545. 1, -531628032, 1611661312, 4, 0,
  129546. _vq_quantlist__16u1__p5_0,
  129547. NULL,
  129548. &_vq_auxt__16u1__p5_0,
  129549. NULL,
  129550. 0
  129551. };
  129552. static long _vq_quantlist__16u1__p6_0[] = {
  129553. 4,
  129554. 3,
  129555. 5,
  129556. 2,
  129557. 6,
  129558. 1,
  129559. 7,
  129560. 0,
  129561. 8,
  129562. };
  129563. static long _vq_lengthlist__16u1__p6_0[] = {
  129564. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129565. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129566. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129567. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129568. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129569. 11,
  129570. };
  129571. static float _vq_quantthresh__16u1__p6_0[] = {
  129572. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129573. };
  129574. static long _vq_quantmap__16u1__p6_0[] = {
  129575. 7, 5, 3, 1, 0, 2, 4, 6,
  129576. 8,
  129577. };
  129578. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129579. _vq_quantthresh__16u1__p6_0,
  129580. _vq_quantmap__16u1__p6_0,
  129581. 9,
  129582. 9
  129583. };
  129584. static static_codebook _16u1__p6_0 = {
  129585. 2, 81,
  129586. _vq_lengthlist__16u1__p6_0,
  129587. 1, -531628032, 1611661312, 4, 0,
  129588. _vq_quantlist__16u1__p6_0,
  129589. NULL,
  129590. &_vq_auxt__16u1__p6_0,
  129591. NULL,
  129592. 0
  129593. };
  129594. static long _vq_quantlist__16u1__p7_0[] = {
  129595. 1,
  129596. 0,
  129597. 2,
  129598. };
  129599. static long _vq_lengthlist__16u1__p7_0[] = {
  129600. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129601. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129602. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129603. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129604. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129605. 13,
  129606. };
  129607. static float _vq_quantthresh__16u1__p7_0[] = {
  129608. -5.5, 5.5,
  129609. };
  129610. static long _vq_quantmap__16u1__p7_0[] = {
  129611. 1, 0, 2,
  129612. };
  129613. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129614. _vq_quantthresh__16u1__p7_0,
  129615. _vq_quantmap__16u1__p7_0,
  129616. 3,
  129617. 3
  129618. };
  129619. static static_codebook _16u1__p7_0 = {
  129620. 4, 81,
  129621. _vq_lengthlist__16u1__p7_0,
  129622. 1, -529137664, 1618345984, 2, 0,
  129623. _vq_quantlist__16u1__p7_0,
  129624. NULL,
  129625. &_vq_auxt__16u1__p7_0,
  129626. NULL,
  129627. 0
  129628. };
  129629. static long _vq_quantlist__16u1__p7_1[] = {
  129630. 5,
  129631. 4,
  129632. 6,
  129633. 3,
  129634. 7,
  129635. 2,
  129636. 8,
  129637. 1,
  129638. 9,
  129639. 0,
  129640. 10,
  129641. };
  129642. static long _vq_lengthlist__16u1__p7_1[] = {
  129643. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129644. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129645. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129646. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129647. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129648. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129649. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129650. 8, 9, 9,10,10,10,10,10,10,
  129651. };
  129652. static float _vq_quantthresh__16u1__p7_1[] = {
  129653. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129654. 3.5, 4.5,
  129655. };
  129656. static long _vq_quantmap__16u1__p7_1[] = {
  129657. 9, 7, 5, 3, 1, 0, 2, 4,
  129658. 6, 8, 10,
  129659. };
  129660. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129661. _vq_quantthresh__16u1__p7_1,
  129662. _vq_quantmap__16u1__p7_1,
  129663. 11,
  129664. 11
  129665. };
  129666. static static_codebook _16u1__p7_1 = {
  129667. 2, 121,
  129668. _vq_lengthlist__16u1__p7_1,
  129669. 1, -531365888, 1611661312, 4, 0,
  129670. _vq_quantlist__16u1__p7_1,
  129671. NULL,
  129672. &_vq_auxt__16u1__p7_1,
  129673. NULL,
  129674. 0
  129675. };
  129676. static long _vq_quantlist__16u1__p8_0[] = {
  129677. 5,
  129678. 4,
  129679. 6,
  129680. 3,
  129681. 7,
  129682. 2,
  129683. 8,
  129684. 1,
  129685. 9,
  129686. 0,
  129687. 10,
  129688. };
  129689. static long _vq_lengthlist__16u1__p8_0[] = {
  129690. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129691. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129692. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129693. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129694. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129695. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129696. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129697. 13,14,14,15,15,16,16,15,16,
  129698. };
  129699. static float _vq_quantthresh__16u1__p8_0[] = {
  129700. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129701. 38.5, 49.5,
  129702. };
  129703. static long _vq_quantmap__16u1__p8_0[] = {
  129704. 9, 7, 5, 3, 1, 0, 2, 4,
  129705. 6, 8, 10,
  129706. };
  129707. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129708. _vq_quantthresh__16u1__p8_0,
  129709. _vq_quantmap__16u1__p8_0,
  129710. 11,
  129711. 11
  129712. };
  129713. static static_codebook _16u1__p8_0 = {
  129714. 2, 121,
  129715. _vq_lengthlist__16u1__p8_0,
  129716. 1, -524582912, 1618345984, 4, 0,
  129717. _vq_quantlist__16u1__p8_0,
  129718. NULL,
  129719. &_vq_auxt__16u1__p8_0,
  129720. NULL,
  129721. 0
  129722. };
  129723. static long _vq_quantlist__16u1__p8_1[] = {
  129724. 5,
  129725. 4,
  129726. 6,
  129727. 3,
  129728. 7,
  129729. 2,
  129730. 8,
  129731. 1,
  129732. 9,
  129733. 0,
  129734. 10,
  129735. };
  129736. static long _vq_lengthlist__16u1__p8_1[] = {
  129737. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129738. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129739. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129740. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129741. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129742. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129743. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129744. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129745. };
  129746. static float _vq_quantthresh__16u1__p8_1[] = {
  129747. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129748. 3.5, 4.5,
  129749. };
  129750. static long _vq_quantmap__16u1__p8_1[] = {
  129751. 9, 7, 5, 3, 1, 0, 2, 4,
  129752. 6, 8, 10,
  129753. };
  129754. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129755. _vq_quantthresh__16u1__p8_1,
  129756. _vq_quantmap__16u1__p8_1,
  129757. 11,
  129758. 11
  129759. };
  129760. static static_codebook _16u1__p8_1 = {
  129761. 2, 121,
  129762. _vq_lengthlist__16u1__p8_1,
  129763. 1, -531365888, 1611661312, 4, 0,
  129764. _vq_quantlist__16u1__p8_1,
  129765. NULL,
  129766. &_vq_auxt__16u1__p8_1,
  129767. NULL,
  129768. 0
  129769. };
  129770. static long _vq_quantlist__16u1__p9_0[] = {
  129771. 7,
  129772. 6,
  129773. 8,
  129774. 5,
  129775. 9,
  129776. 4,
  129777. 10,
  129778. 3,
  129779. 11,
  129780. 2,
  129781. 12,
  129782. 1,
  129783. 13,
  129784. 0,
  129785. 14,
  129786. };
  129787. static long _vq_lengthlist__16u1__p9_0[] = {
  129788. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129789. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129790. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129791. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129792. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129793. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129794. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129795. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129796. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129797. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129798. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129799. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129800. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129801. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129802. 8,
  129803. };
  129804. static float _vq_quantthresh__16u1__p9_0[] = {
  129805. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129806. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129807. };
  129808. static long _vq_quantmap__16u1__p9_0[] = {
  129809. 13, 11, 9, 7, 5, 3, 1, 0,
  129810. 2, 4, 6, 8, 10, 12, 14,
  129811. };
  129812. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129813. _vq_quantthresh__16u1__p9_0,
  129814. _vq_quantmap__16u1__p9_0,
  129815. 15,
  129816. 15
  129817. };
  129818. static static_codebook _16u1__p9_0 = {
  129819. 2, 225,
  129820. _vq_lengthlist__16u1__p9_0,
  129821. 1, -514071552, 1627381760, 4, 0,
  129822. _vq_quantlist__16u1__p9_0,
  129823. NULL,
  129824. &_vq_auxt__16u1__p9_0,
  129825. NULL,
  129826. 0
  129827. };
  129828. static long _vq_quantlist__16u1__p9_1[] = {
  129829. 7,
  129830. 6,
  129831. 8,
  129832. 5,
  129833. 9,
  129834. 4,
  129835. 10,
  129836. 3,
  129837. 11,
  129838. 2,
  129839. 12,
  129840. 1,
  129841. 13,
  129842. 0,
  129843. 14,
  129844. };
  129845. static long _vq_lengthlist__16u1__p9_1[] = {
  129846. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129847. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129848. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129849. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129850. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129851. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129852. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129853. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129854. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129855. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129856. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129857. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129858. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129859. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129860. 9,
  129861. };
  129862. static float _vq_quantthresh__16u1__p9_1[] = {
  129863. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129864. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129865. };
  129866. static long _vq_quantmap__16u1__p9_1[] = {
  129867. 13, 11, 9, 7, 5, 3, 1, 0,
  129868. 2, 4, 6, 8, 10, 12, 14,
  129869. };
  129870. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129871. _vq_quantthresh__16u1__p9_1,
  129872. _vq_quantmap__16u1__p9_1,
  129873. 15,
  129874. 15
  129875. };
  129876. static static_codebook _16u1__p9_1 = {
  129877. 2, 225,
  129878. _vq_lengthlist__16u1__p9_1,
  129879. 1, -522338304, 1620115456, 4, 0,
  129880. _vq_quantlist__16u1__p9_1,
  129881. NULL,
  129882. &_vq_auxt__16u1__p9_1,
  129883. NULL,
  129884. 0
  129885. };
  129886. static long _vq_quantlist__16u1__p9_2[] = {
  129887. 8,
  129888. 7,
  129889. 9,
  129890. 6,
  129891. 10,
  129892. 5,
  129893. 11,
  129894. 4,
  129895. 12,
  129896. 3,
  129897. 13,
  129898. 2,
  129899. 14,
  129900. 1,
  129901. 15,
  129902. 0,
  129903. 16,
  129904. };
  129905. static long _vq_lengthlist__16u1__p9_2[] = {
  129906. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129907. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129908. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129909. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129910. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129911. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129912. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129913. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129914. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129915. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129916. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129917. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129918. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129919. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129920. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129921. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129922. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129923. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129924. 10,
  129925. };
  129926. static float _vq_quantthresh__16u1__p9_2[] = {
  129927. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129928. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129929. };
  129930. static long _vq_quantmap__16u1__p9_2[] = {
  129931. 15, 13, 11, 9, 7, 5, 3, 1,
  129932. 0, 2, 4, 6, 8, 10, 12, 14,
  129933. 16,
  129934. };
  129935. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129936. _vq_quantthresh__16u1__p9_2,
  129937. _vq_quantmap__16u1__p9_2,
  129938. 17,
  129939. 17
  129940. };
  129941. static static_codebook _16u1__p9_2 = {
  129942. 2, 289,
  129943. _vq_lengthlist__16u1__p9_2,
  129944. 1, -529530880, 1611661312, 5, 0,
  129945. _vq_quantlist__16u1__p9_2,
  129946. NULL,
  129947. &_vq_auxt__16u1__p9_2,
  129948. NULL,
  129949. 0
  129950. };
  129951. static long _huff_lengthlist__16u1__short[] = {
  129952. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129953. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129954. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129955. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129956. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129957. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129958. 16,16,16,16,
  129959. };
  129960. static static_codebook _huff_book__16u1__short = {
  129961. 2, 100,
  129962. _huff_lengthlist__16u1__short,
  129963. 0, 0, 0, 0, 0,
  129964. NULL,
  129965. NULL,
  129966. NULL,
  129967. NULL,
  129968. 0
  129969. };
  129970. static long _huff_lengthlist__16u2__long[] = {
  129971. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129972. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129973. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129974. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129975. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129976. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129977. 13,14,18,18,
  129978. };
  129979. static static_codebook _huff_book__16u2__long = {
  129980. 2, 100,
  129981. _huff_lengthlist__16u2__long,
  129982. 0, 0, 0, 0, 0,
  129983. NULL,
  129984. NULL,
  129985. NULL,
  129986. NULL,
  129987. 0
  129988. };
  129989. static long _huff_lengthlist__16u2__short[] = {
  129990. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129991. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129992. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129993. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129994. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129995. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129996. 16,16,16,16,
  129997. };
  129998. static static_codebook _huff_book__16u2__short = {
  129999. 2, 100,
  130000. _huff_lengthlist__16u2__short,
  130001. 0, 0, 0, 0, 0,
  130002. NULL,
  130003. NULL,
  130004. NULL,
  130005. NULL,
  130006. 0
  130007. };
  130008. static long _vq_quantlist__16u2_p1_0[] = {
  130009. 1,
  130010. 0,
  130011. 2,
  130012. };
  130013. static long _vq_lengthlist__16u2_p1_0[] = {
  130014. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  130015. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  130016. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  130017. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  130018. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  130019. 10,
  130020. };
  130021. static float _vq_quantthresh__16u2_p1_0[] = {
  130022. -0.5, 0.5,
  130023. };
  130024. static long _vq_quantmap__16u2_p1_0[] = {
  130025. 1, 0, 2,
  130026. };
  130027. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  130028. _vq_quantthresh__16u2_p1_0,
  130029. _vq_quantmap__16u2_p1_0,
  130030. 3,
  130031. 3
  130032. };
  130033. static static_codebook _16u2_p1_0 = {
  130034. 4, 81,
  130035. _vq_lengthlist__16u2_p1_0,
  130036. 1, -535822336, 1611661312, 2, 0,
  130037. _vq_quantlist__16u2_p1_0,
  130038. NULL,
  130039. &_vq_auxt__16u2_p1_0,
  130040. NULL,
  130041. 0
  130042. };
  130043. static long _vq_quantlist__16u2_p2_0[] = {
  130044. 2,
  130045. 1,
  130046. 3,
  130047. 0,
  130048. 4,
  130049. };
  130050. static long _vq_lengthlist__16u2_p2_0[] = {
  130051. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  130052. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  130053. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  130054. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  130055. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  130056. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  130057. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  130058. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  130059. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  130060. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  130061. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  130062. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  130063. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  130064. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  130065. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  130066. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  130067. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  130068. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  130069. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  130070. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  130071. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  130072. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  130073. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  130074. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  130075. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  130076. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  130077. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  130078. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  130079. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  130080. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  130081. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  130082. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  130083. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  130084. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  130085. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  130086. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  130087. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  130088. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  130089. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  130090. 13,
  130091. };
  130092. static float _vq_quantthresh__16u2_p2_0[] = {
  130093. -1.5, -0.5, 0.5, 1.5,
  130094. };
  130095. static long _vq_quantmap__16u2_p2_0[] = {
  130096. 3, 1, 0, 2, 4,
  130097. };
  130098. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130099. _vq_quantthresh__16u2_p2_0,
  130100. _vq_quantmap__16u2_p2_0,
  130101. 5,
  130102. 5
  130103. };
  130104. static static_codebook _16u2_p2_0 = {
  130105. 4, 625,
  130106. _vq_lengthlist__16u2_p2_0,
  130107. 1, -533725184, 1611661312, 3, 0,
  130108. _vq_quantlist__16u2_p2_0,
  130109. NULL,
  130110. &_vq_auxt__16u2_p2_0,
  130111. NULL,
  130112. 0
  130113. };
  130114. static long _vq_quantlist__16u2_p3_0[] = {
  130115. 4,
  130116. 3,
  130117. 5,
  130118. 2,
  130119. 6,
  130120. 1,
  130121. 7,
  130122. 0,
  130123. 8,
  130124. };
  130125. static long _vq_lengthlist__16u2_p3_0[] = {
  130126. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130127. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130128. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130129. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130130. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130131. 11,
  130132. };
  130133. static float _vq_quantthresh__16u2_p3_0[] = {
  130134. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130135. };
  130136. static long _vq_quantmap__16u2_p3_0[] = {
  130137. 7, 5, 3, 1, 0, 2, 4, 6,
  130138. 8,
  130139. };
  130140. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130141. _vq_quantthresh__16u2_p3_0,
  130142. _vq_quantmap__16u2_p3_0,
  130143. 9,
  130144. 9
  130145. };
  130146. static static_codebook _16u2_p3_0 = {
  130147. 2, 81,
  130148. _vq_lengthlist__16u2_p3_0,
  130149. 1, -531628032, 1611661312, 4, 0,
  130150. _vq_quantlist__16u2_p3_0,
  130151. NULL,
  130152. &_vq_auxt__16u2_p3_0,
  130153. NULL,
  130154. 0
  130155. };
  130156. static long _vq_quantlist__16u2_p4_0[] = {
  130157. 8,
  130158. 7,
  130159. 9,
  130160. 6,
  130161. 10,
  130162. 5,
  130163. 11,
  130164. 4,
  130165. 12,
  130166. 3,
  130167. 13,
  130168. 2,
  130169. 14,
  130170. 1,
  130171. 15,
  130172. 0,
  130173. 16,
  130174. };
  130175. static long _vq_lengthlist__16u2_p4_0[] = {
  130176. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130177. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130178. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130179. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130180. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130181. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130182. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130183. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130184. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130185. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130186. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130187. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130188. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130189. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130190. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130191. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130192. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130193. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130194. 14,
  130195. };
  130196. static float _vq_quantthresh__16u2_p4_0[] = {
  130197. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130198. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130199. };
  130200. static long _vq_quantmap__16u2_p4_0[] = {
  130201. 15, 13, 11, 9, 7, 5, 3, 1,
  130202. 0, 2, 4, 6, 8, 10, 12, 14,
  130203. 16,
  130204. };
  130205. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130206. _vq_quantthresh__16u2_p4_0,
  130207. _vq_quantmap__16u2_p4_0,
  130208. 17,
  130209. 17
  130210. };
  130211. static static_codebook _16u2_p4_0 = {
  130212. 2, 289,
  130213. _vq_lengthlist__16u2_p4_0,
  130214. 1, -529530880, 1611661312, 5, 0,
  130215. _vq_quantlist__16u2_p4_0,
  130216. NULL,
  130217. &_vq_auxt__16u2_p4_0,
  130218. NULL,
  130219. 0
  130220. };
  130221. static long _vq_quantlist__16u2_p5_0[] = {
  130222. 1,
  130223. 0,
  130224. 2,
  130225. };
  130226. static long _vq_lengthlist__16u2_p5_0[] = {
  130227. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130228. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130229. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130230. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130231. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130232. 10,
  130233. };
  130234. static float _vq_quantthresh__16u2_p5_0[] = {
  130235. -5.5, 5.5,
  130236. };
  130237. static long _vq_quantmap__16u2_p5_0[] = {
  130238. 1, 0, 2,
  130239. };
  130240. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130241. _vq_quantthresh__16u2_p5_0,
  130242. _vq_quantmap__16u2_p5_0,
  130243. 3,
  130244. 3
  130245. };
  130246. static static_codebook _16u2_p5_0 = {
  130247. 4, 81,
  130248. _vq_lengthlist__16u2_p5_0,
  130249. 1, -529137664, 1618345984, 2, 0,
  130250. _vq_quantlist__16u2_p5_0,
  130251. NULL,
  130252. &_vq_auxt__16u2_p5_0,
  130253. NULL,
  130254. 0
  130255. };
  130256. static long _vq_quantlist__16u2_p5_1[] = {
  130257. 5,
  130258. 4,
  130259. 6,
  130260. 3,
  130261. 7,
  130262. 2,
  130263. 8,
  130264. 1,
  130265. 9,
  130266. 0,
  130267. 10,
  130268. };
  130269. static long _vq_lengthlist__16u2_p5_1[] = {
  130270. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130271. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130272. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130273. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130274. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130275. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130276. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130277. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130278. };
  130279. static float _vq_quantthresh__16u2_p5_1[] = {
  130280. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130281. 3.5, 4.5,
  130282. };
  130283. static long _vq_quantmap__16u2_p5_1[] = {
  130284. 9, 7, 5, 3, 1, 0, 2, 4,
  130285. 6, 8, 10,
  130286. };
  130287. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130288. _vq_quantthresh__16u2_p5_1,
  130289. _vq_quantmap__16u2_p5_1,
  130290. 11,
  130291. 11
  130292. };
  130293. static static_codebook _16u2_p5_1 = {
  130294. 2, 121,
  130295. _vq_lengthlist__16u2_p5_1,
  130296. 1, -531365888, 1611661312, 4, 0,
  130297. _vq_quantlist__16u2_p5_1,
  130298. NULL,
  130299. &_vq_auxt__16u2_p5_1,
  130300. NULL,
  130301. 0
  130302. };
  130303. static long _vq_quantlist__16u2_p6_0[] = {
  130304. 6,
  130305. 5,
  130306. 7,
  130307. 4,
  130308. 8,
  130309. 3,
  130310. 9,
  130311. 2,
  130312. 10,
  130313. 1,
  130314. 11,
  130315. 0,
  130316. 12,
  130317. };
  130318. static long _vq_lengthlist__16u2_p6_0[] = {
  130319. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130320. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130321. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130322. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130323. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130324. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130325. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130326. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130327. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130328. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130329. 12,13,13,14,14,14,14,15,15,
  130330. };
  130331. static float _vq_quantthresh__16u2_p6_0[] = {
  130332. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130333. 12.5, 17.5, 22.5, 27.5,
  130334. };
  130335. static long _vq_quantmap__16u2_p6_0[] = {
  130336. 11, 9, 7, 5, 3, 1, 0, 2,
  130337. 4, 6, 8, 10, 12,
  130338. };
  130339. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130340. _vq_quantthresh__16u2_p6_0,
  130341. _vq_quantmap__16u2_p6_0,
  130342. 13,
  130343. 13
  130344. };
  130345. static static_codebook _16u2_p6_0 = {
  130346. 2, 169,
  130347. _vq_lengthlist__16u2_p6_0,
  130348. 1, -526516224, 1616117760, 4, 0,
  130349. _vq_quantlist__16u2_p6_0,
  130350. NULL,
  130351. &_vq_auxt__16u2_p6_0,
  130352. NULL,
  130353. 0
  130354. };
  130355. static long _vq_quantlist__16u2_p6_1[] = {
  130356. 2,
  130357. 1,
  130358. 3,
  130359. 0,
  130360. 4,
  130361. };
  130362. static long _vq_lengthlist__16u2_p6_1[] = {
  130363. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130364. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130365. };
  130366. static float _vq_quantthresh__16u2_p6_1[] = {
  130367. -1.5, -0.5, 0.5, 1.5,
  130368. };
  130369. static long _vq_quantmap__16u2_p6_1[] = {
  130370. 3, 1, 0, 2, 4,
  130371. };
  130372. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130373. _vq_quantthresh__16u2_p6_1,
  130374. _vq_quantmap__16u2_p6_1,
  130375. 5,
  130376. 5
  130377. };
  130378. static static_codebook _16u2_p6_1 = {
  130379. 2, 25,
  130380. _vq_lengthlist__16u2_p6_1,
  130381. 1, -533725184, 1611661312, 3, 0,
  130382. _vq_quantlist__16u2_p6_1,
  130383. NULL,
  130384. &_vq_auxt__16u2_p6_1,
  130385. NULL,
  130386. 0
  130387. };
  130388. static long _vq_quantlist__16u2_p7_0[] = {
  130389. 6,
  130390. 5,
  130391. 7,
  130392. 4,
  130393. 8,
  130394. 3,
  130395. 9,
  130396. 2,
  130397. 10,
  130398. 1,
  130399. 11,
  130400. 0,
  130401. 12,
  130402. };
  130403. static long _vq_lengthlist__16u2_p7_0[] = {
  130404. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130405. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130406. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130407. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130408. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130409. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130410. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130411. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130412. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130413. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130414. 12,13,13,13,14,14,14,15,14,
  130415. };
  130416. static float _vq_quantthresh__16u2_p7_0[] = {
  130417. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130418. 27.5, 38.5, 49.5, 60.5,
  130419. };
  130420. static long _vq_quantmap__16u2_p7_0[] = {
  130421. 11, 9, 7, 5, 3, 1, 0, 2,
  130422. 4, 6, 8, 10, 12,
  130423. };
  130424. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130425. _vq_quantthresh__16u2_p7_0,
  130426. _vq_quantmap__16u2_p7_0,
  130427. 13,
  130428. 13
  130429. };
  130430. static static_codebook _16u2_p7_0 = {
  130431. 2, 169,
  130432. _vq_lengthlist__16u2_p7_0,
  130433. 1, -523206656, 1618345984, 4, 0,
  130434. _vq_quantlist__16u2_p7_0,
  130435. NULL,
  130436. &_vq_auxt__16u2_p7_0,
  130437. NULL,
  130438. 0
  130439. };
  130440. static long _vq_quantlist__16u2_p7_1[] = {
  130441. 5,
  130442. 4,
  130443. 6,
  130444. 3,
  130445. 7,
  130446. 2,
  130447. 8,
  130448. 1,
  130449. 9,
  130450. 0,
  130451. 10,
  130452. };
  130453. static long _vq_lengthlist__16u2_p7_1[] = {
  130454. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130455. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130456. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130457. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130458. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130459. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130460. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130461. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130462. };
  130463. static float _vq_quantthresh__16u2_p7_1[] = {
  130464. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130465. 3.5, 4.5,
  130466. };
  130467. static long _vq_quantmap__16u2_p7_1[] = {
  130468. 9, 7, 5, 3, 1, 0, 2, 4,
  130469. 6, 8, 10,
  130470. };
  130471. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130472. _vq_quantthresh__16u2_p7_1,
  130473. _vq_quantmap__16u2_p7_1,
  130474. 11,
  130475. 11
  130476. };
  130477. static static_codebook _16u2_p7_1 = {
  130478. 2, 121,
  130479. _vq_lengthlist__16u2_p7_1,
  130480. 1, -531365888, 1611661312, 4, 0,
  130481. _vq_quantlist__16u2_p7_1,
  130482. NULL,
  130483. &_vq_auxt__16u2_p7_1,
  130484. NULL,
  130485. 0
  130486. };
  130487. static long _vq_quantlist__16u2_p8_0[] = {
  130488. 7,
  130489. 6,
  130490. 8,
  130491. 5,
  130492. 9,
  130493. 4,
  130494. 10,
  130495. 3,
  130496. 11,
  130497. 2,
  130498. 12,
  130499. 1,
  130500. 13,
  130501. 0,
  130502. 14,
  130503. };
  130504. static long _vq_lengthlist__16u2_p8_0[] = {
  130505. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130506. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130507. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130508. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130509. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130510. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130511. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130512. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130513. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130514. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130515. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130516. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130517. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130518. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130519. 14,
  130520. };
  130521. static float _vq_quantthresh__16u2_p8_0[] = {
  130522. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130523. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130524. };
  130525. static long _vq_quantmap__16u2_p8_0[] = {
  130526. 13, 11, 9, 7, 5, 3, 1, 0,
  130527. 2, 4, 6, 8, 10, 12, 14,
  130528. };
  130529. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130530. _vq_quantthresh__16u2_p8_0,
  130531. _vq_quantmap__16u2_p8_0,
  130532. 15,
  130533. 15
  130534. };
  130535. static static_codebook _16u2_p8_0 = {
  130536. 2, 225,
  130537. _vq_lengthlist__16u2_p8_0,
  130538. 1, -520986624, 1620377600, 4, 0,
  130539. _vq_quantlist__16u2_p8_0,
  130540. NULL,
  130541. &_vq_auxt__16u2_p8_0,
  130542. NULL,
  130543. 0
  130544. };
  130545. static long _vq_quantlist__16u2_p8_1[] = {
  130546. 10,
  130547. 9,
  130548. 11,
  130549. 8,
  130550. 12,
  130551. 7,
  130552. 13,
  130553. 6,
  130554. 14,
  130555. 5,
  130556. 15,
  130557. 4,
  130558. 16,
  130559. 3,
  130560. 17,
  130561. 2,
  130562. 18,
  130563. 1,
  130564. 19,
  130565. 0,
  130566. 20,
  130567. };
  130568. static long _vq_lengthlist__16u2_p8_1[] = {
  130569. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130570. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130571. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130572. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130573. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130574. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130575. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130576. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130577. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130578. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130579. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130580. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130581. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130582. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130583. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130584. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130585. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130586. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130587. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130588. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130589. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130590. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130591. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130592. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130593. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130594. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130595. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130596. 11,11,10,11,11,11,10,11,11,
  130597. };
  130598. static float _vq_quantthresh__16u2_p8_1[] = {
  130599. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130600. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130601. 6.5, 7.5, 8.5, 9.5,
  130602. };
  130603. static long _vq_quantmap__16u2_p8_1[] = {
  130604. 19, 17, 15, 13, 11, 9, 7, 5,
  130605. 3, 1, 0, 2, 4, 6, 8, 10,
  130606. 12, 14, 16, 18, 20,
  130607. };
  130608. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130609. _vq_quantthresh__16u2_p8_1,
  130610. _vq_quantmap__16u2_p8_1,
  130611. 21,
  130612. 21
  130613. };
  130614. static static_codebook _16u2_p8_1 = {
  130615. 2, 441,
  130616. _vq_lengthlist__16u2_p8_1,
  130617. 1, -529268736, 1611661312, 5, 0,
  130618. _vq_quantlist__16u2_p8_1,
  130619. NULL,
  130620. &_vq_auxt__16u2_p8_1,
  130621. NULL,
  130622. 0
  130623. };
  130624. static long _vq_quantlist__16u2_p9_0[] = {
  130625. 5586,
  130626. 4655,
  130627. 6517,
  130628. 3724,
  130629. 7448,
  130630. 2793,
  130631. 8379,
  130632. 1862,
  130633. 9310,
  130634. 931,
  130635. 10241,
  130636. 0,
  130637. 11172,
  130638. 5521,
  130639. 5651,
  130640. };
  130641. static long _vq_lengthlist__16u2_p9_0[] = {
  130642. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130643. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130644. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130645. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130646. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130647. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130648. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130649. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130650. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130651. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130652. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130653. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130654. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130655. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130656. 5,
  130657. };
  130658. static float _vq_quantthresh__16u2_p9_0[] = {
  130659. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130660. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130661. };
  130662. static long _vq_quantmap__16u2_p9_0[] = {
  130663. 11, 9, 7, 5, 3, 1, 13, 0,
  130664. 14, 2, 4, 6, 8, 10, 12,
  130665. };
  130666. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130667. _vq_quantthresh__16u2_p9_0,
  130668. _vq_quantmap__16u2_p9_0,
  130669. 15,
  130670. 15
  130671. };
  130672. static static_codebook _16u2_p9_0 = {
  130673. 2, 225,
  130674. _vq_lengthlist__16u2_p9_0,
  130675. 1, -510275072, 1611661312, 14, 0,
  130676. _vq_quantlist__16u2_p9_0,
  130677. NULL,
  130678. &_vq_auxt__16u2_p9_0,
  130679. NULL,
  130680. 0
  130681. };
  130682. static long _vq_quantlist__16u2_p9_1[] = {
  130683. 392,
  130684. 343,
  130685. 441,
  130686. 294,
  130687. 490,
  130688. 245,
  130689. 539,
  130690. 196,
  130691. 588,
  130692. 147,
  130693. 637,
  130694. 98,
  130695. 686,
  130696. 49,
  130697. 735,
  130698. 0,
  130699. 784,
  130700. 388,
  130701. 396,
  130702. };
  130703. static long _vq_lengthlist__16u2_p9_1[] = {
  130704. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130705. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130706. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130707. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130708. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130709. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130710. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130711. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130712. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130713. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130714. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130715. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130716. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130717. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130718. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130719. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130720. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130721. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130722. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130723. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130724. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130725. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130726. 11,11,11,11,11,11,11, 5, 4,
  130727. };
  130728. static float _vq_quantthresh__16u2_p9_1[] = {
  130729. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130730. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130731. 318.5, 367.5,
  130732. };
  130733. static long _vq_quantmap__16u2_p9_1[] = {
  130734. 15, 13, 11, 9, 7, 5, 3, 1,
  130735. 17, 0, 18, 2, 4, 6, 8, 10,
  130736. 12, 14, 16,
  130737. };
  130738. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130739. _vq_quantthresh__16u2_p9_1,
  130740. _vq_quantmap__16u2_p9_1,
  130741. 19,
  130742. 19
  130743. };
  130744. static static_codebook _16u2_p9_1 = {
  130745. 2, 361,
  130746. _vq_lengthlist__16u2_p9_1,
  130747. 1, -518488064, 1611661312, 10, 0,
  130748. _vq_quantlist__16u2_p9_1,
  130749. NULL,
  130750. &_vq_auxt__16u2_p9_1,
  130751. NULL,
  130752. 0
  130753. };
  130754. static long _vq_quantlist__16u2_p9_2[] = {
  130755. 24,
  130756. 23,
  130757. 25,
  130758. 22,
  130759. 26,
  130760. 21,
  130761. 27,
  130762. 20,
  130763. 28,
  130764. 19,
  130765. 29,
  130766. 18,
  130767. 30,
  130768. 17,
  130769. 31,
  130770. 16,
  130771. 32,
  130772. 15,
  130773. 33,
  130774. 14,
  130775. 34,
  130776. 13,
  130777. 35,
  130778. 12,
  130779. 36,
  130780. 11,
  130781. 37,
  130782. 10,
  130783. 38,
  130784. 9,
  130785. 39,
  130786. 8,
  130787. 40,
  130788. 7,
  130789. 41,
  130790. 6,
  130791. 42,
  130792. 5,
  130793. 43,
  130794. 4,
  130795. 44,
  130796. 3,
  130797. 45,
  130798. 2,
  130799. 46,
  130800. 1,
  130801. 47,
  130802. 0,
  130803. 48,
  130804. };
  130805. static long _vq_lengthlist__16u2_p9_2[] = {
  130806. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130807. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130808. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130809. 11,
  130810. };
  130811. static float _vq_quantthresh__16u2_p9_2[] = {
  130812. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130813. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130814. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130815. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130816. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130817. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130818. };
  130819. static long _vq_quantmap__16u2_p9_2[] = {
  130820. 47, 45, 43, 41, 39, 37, 35, 33,
  130821. 31, 29, 27, 25, 23, 21, 19, 17,
  130822. 15, 13, 11, 9, 7, 5, 3, 1,
  130823. 0, 2, 4, 6, 8, 10, 12, 14,
  130824. 16, 18, 20, 22, 24, 26, 28, 30,
  130825. 32, 34, 36, 38, 40, 42, 44, 46,
  130826. 48,
  130827. };
  130828. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130829. _vq_quantthresh__16u2_p9_2,
  130830. _vq_quantmap__16u2_p9_2,
  130831. 49,
  130832. 49
  130833. };
  130834. static static_codebook _16u2_p9_2 = {
  130835. 1, 49,
  130836. _vq_lengthlist__16u2_p9_2,
  130837. 1, -526909440, 1611661312, 6, 0,
  130838. _vq_quantlist__16u2_p9_2,
  130839. NULL,
  130840. &_vq_auxt__16u2_p9_2,
  130841. NULL,
  130842. 0
  130843. };
  130844. static long _vq_quantlist__8u0__p1_0[] = {
  130845. 1,
  130846. 0,
  130847. 2,
  130848. };
  130849. static long _vq_lengthlist__8u0__p1_0[] = {
  130850. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130851. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130852. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130853. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130854. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130855. 11,
  130856. };
  130857. static float _vq_quantthresh__8u0__p1_0[] = {
  130858. -0.5, 0.5,
  130859. };
  130860. static long _vq_quantmap__8u0__p1_0[] = {
  130861. 1, 0, 2,
  130862. };
  130863. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130864. _vq_quantthresh__8u0__p1_0,
  130865. _vq_quantmap__8u0__p1_0,
  130866. 3,
  130867. 3
  130868. };
  130869. static static_codebook _8u0__p1_0 = {
  130870. 4, 81,
  130871. _vq_lengthlist__8u0__p1_0,
  130872. 1, -535822336, 1611661312, 2, 0,
  130873. _vq_quantlist__8u0__p1_0,
  130874. NULL,
  130875. &_vq_auxt__8u0__p1_0,
  130876. NULL,
  130877. 0
  130878. };
  130879. static long _vq_quantlist__8u0__p2_0[] = {
  130880. 1,
  130881. 0,
  130882. 2,
  130883. };
  130884. static long _vq_lengthlist__8u0__p2_0[] = {
  130885. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130886. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130887. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130888. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130889. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130890. 8,
  130891. };
  130892. static float _vq_quantthresh__8u0__p2_0[] = {
  130893. -0.5, 0.5,
  130894. };
  130895. static long _vq_quantmap__8u0__p2_0[] = {
  130896. 1, 0, 2,
  130897. };
  130898. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130899. _vq_quantthresh__8u0__p2_0,
  130900. _vq_quantmap__8u0__p2_0,
  130901. 3,
  130902. 3
  130903. };
  130904. static static_codebook _8u0__p2_0 = {
  130905. 4, 81,
  130906. _vq_lengthlist__8u0__p2_0,
  130907. 1, -535822336, 1611661312, 2, 0,
  130908. _vq_quantlist__8u0__p2_0,
  130909. NULL,
  130910. &_vq_auxt__8u0__p2_0,
  130911. NULL,
  130912. 0
  130913. };
  130914. static long _vq_quantlist__8u0__p3_0[] = {
  130915. 2,
  130916. 1,
  130917. 3,
  130918. 0,
  130919. 4,
  130920. };
  130921. static long _vq_lengthlist__8u0__p3_0[] = {
  130922. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130923. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130924. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130925. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130926. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130927. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130928. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130929. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130930. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130931. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130932. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130933. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130934. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130935. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130936. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130937. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130938. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130939. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130940. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130941. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130942. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130943. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130944. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130945. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130946. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130947. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130948. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130949. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130950. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130951. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130952. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130953. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130954. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130955. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130956. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130957. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130958. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130959. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130960. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130961. 16,
  130962. };
  130963. static float _vq_quantthresh__8u0__p3_0[] = {
  130964. -1.5, -0.5, 0.5, 1.5,
  130965. };
  130966. static long _vq_quantmap__8u0__p3_0[] = {
  130967. 3, 1, 0, 2, 4,
  130968. };
  130969. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130970. _vq_quantthresh__8u0__p3_0,
  130971. _vq_quantmap__8u0__p3_0,
  130972. 5,
  130973. 5
  130974. };
  130975. static static_codebook _8u0__p3_0 = {
  130976. 4, 625,
  130977. _vq_lengthlist__8u0__p3_0,
  130978. 1, -533725184, 1611661312, 3, 0,
  130979. _vq_quantlist__8u0__p3_0,
  130980. NULL,
  130981. &_vq_auxt__8u0__p3_0,
  130982. NULL,
  130983. 0
  130984. };
  130985. static long _vq_quantlist__8u0__p4_0[] = {
  130986. 2,
  130987. 1,
  130988. 3,
  130989. 0,
  130990. 4,
  130991. };
  130992. static long _vq_lengthlist__8u0__p4_0[] = {
  130993. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130994. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130995. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130996. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130997. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130998. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130999. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  131000. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  131001. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  131002. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  131003. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  131004. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  131005. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  131006. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  131007. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  131008. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  131009. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  131010. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  131011. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  131012. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  131013. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  131014. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  131015. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  131016. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  131017. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  131018. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  131019. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  131020. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  131021. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  131022. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  131023. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  131024. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  131025. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  131026. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  131027. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  131028. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  131029. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  131030. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  131031. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  131032. 12,
  131033. };
  131034. static float _vq_quantthresh__8u0__p4_0[] = {
  131035. -1.5, -0.5, 0.5, 1.5,
  131036. };
  131037. static long _vq_quantmap__8u0__p4_0[] = {
  131038. 3, 1, 0, 2, 4,
  131039. };
  131040. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  131041. _vq_quantthresh__8u0__p4_0,
  131042. _vq_quantmap__8u0__p4_0,
  131043. 5,
  131044. 5
  131045. };
  131046. static static_codebook _8u0__p4_0 = {
  131047. 4, 625,
  131048. _vq_lengthlist__8u0__p4_0,
  131049. 1, -533725184, 1611661312, 3, 0,
  131050. _vq_quantlist__8u0__p4_0,
  131051. NULL,
  131052. &_vq_auxt__8u0__p4_0,
  131053. NULL,
  131054. 0
  131055. };
  131056. static long _vq_quantlist__8u0__p5_0[] = {
  131057. 4,
  131058. 3,
  131059. 5,
  131060. 2,
  131061. 6,
  131062. 1,
  131063. 7,
  131064. 0,
  131065. 8,
  131066. };
  131067. static long _vq_lengthlist__8u0__p5_0[] = {
  131068. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  131069. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  131070. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  131071. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131072. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  131073. 12,
  131074. };
  131075. static float _vq_quantthresh__8u0__p5_0[] = {
  131076. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131077. };
  131078. static long _vq_quantmap__8u0__p5_0[] = {
  131079. 7, 5, 3, 1, 0, 2, 4, 6,
  131080. 8,
  131081. };
  131082. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  131083. _vq_quantthresh__8u0__p5_0,
  131084. _vq_quantmap__8u0__p5_0,
  131085. 9,
  131086. 9
  131087. };
  131088. static static_codebook _8u0__p5_0 = {
  131089. 2, 81,
  131090. _vq_lengthlist__8u0__p5_0,
  131091. 1, -531628032, 1611661312, 4, 0,
  131092. _vq_quantlist__8u0__p5_0,
  131093. NULL,
  131094. &_vq_auxt__8u0__p5_0,
  131095. NULL,
  131096. 0
  131097. };
  131098. static long _vq_quantlist__8u0__p6_0[] = {
  131099. 6,
  131100. 5,
  131101. 7,
  131102. 4,
  131103. 8,
  131104. 3,
  131105. 9,
  131106. 2,
  131107. 10,
  131108. 1,
  131109. 11,
  131110. 0,
  131111. 12,
  131112. };
  131113. static long _vq_lengthlist__8u0__p6_0[] = {
  131114. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131115. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131116. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131117. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131118. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131119. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131120. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131121. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131122. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131123. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131124. 16, 0,15, 0,17, 0, 0, 0, 0,
  131125. };
  131126. static float _vq_quantthresh__8u0__p6_0[] = {
  131127. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131128. 12.5, 17.5, 22.5, 27.5,
  131129. };
  131130. static long _vq_quantmap__8u0__p6_0[] = {
  131131. 11, 9, 7, 5, 3, 1, 0, 2,
  131132. 4, 6, 8, 10, 12,
  131133. };
  131134. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131135. _vq_quantthresh__8u0__p6_0,
  131136. _vq_quantmap__8u0__p6_0,
  131137. 13,
  131138. 13
  131139. };
  131140. static static_codebook _8u0__p6_0 = {
  131141. 2, 169,
  131142. _vq_lengthlist__8u0__p6_0,
  131143. 1, -526516224, 1616117760, 4, 0,
  131144. _vq_quantlist__8u0__p6_0,
  131145. NULL,
  131146. &_vq_auxt__8u0__p6_0,
  131147. NULL,
  131148. 0
  131149. };
  131150. static long _vq_quantlist__8u0__p6_1[] = {
  131151. 2,
  131152. 1,
  131153. 3,
  131154. 0,
  131155. 4,
  131156. };
  131157. static long _vq_lengthlist__8u0__p6_1[] = {
  131158. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131159. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131160. };
  131161. static float _vq_quantthresh__8u0__p6_1[] = {
  131162. -1.5, -0.5, 0.5, 1.5,
  131163. };
  131164. static long _vq_quantmap__8u0__p6_1[] = {
  131165. 3, 1, 0, 2, 4,
  131166. };
  131167. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131168. _vq_quantthresh__8u0__p6_1,
  131169. _vq_quantmap__8u0__p6_1,
  131170. 5,
  131171. 5
  131172. };
  131173. static static_codebook _8u0__p6_1 = {
  131174. 2, 25,
  131175. _vq_lengthlist__8u0__p6_1,
  131176. 1, -533725184, 1611661312, 3, 0,
  131177. _vq_quantlist__8u0__p6_1,
  131178. NULL,
  131179. &_vq_auxt__8u0__p6_1,
  131180. NULL,
  131181. 0
  131182. };
  131183. static long _vq_quantlist__8u0__p7_0[] = {
  131184. 1,
  131185. 0,
  131186. 2,
  131187. };
  131188. static long _vq_lengthlist__8u0__p7_0[] = {
  131189. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131190. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131191. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131192. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131193. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131194. 7,
  131195. };
  131196. static float _vq_quantthresh__8u0__p7_0[] = {
  131197. -157.5, 157.5,
  131198. };
  131199. static long _vq_quantmap__8u0__p7_0[] = {
  131200. 1, 0, 2,
  131201. };
  131202. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131203. _vq_quantthresh__8u0__p7_0,
  131204. _vq_quantmap__8u0__p7_0,
  131205. 3,
  131206. 3
  131207. };
  131208. static static_codebook _8u0__p7_0 = {
  131209. 4, 81,
  131210. _vq_lengthlist__8u0__p7_0,
  131211. 1, -518803456, 1628680192, 2, 0,
  131212. _vq_quantlist__8u0__p7_0,
  131213. NULL,
  131214. &_vq_auxt__8u0__p7_0,
  131215. NULL,
  131216. 0
  131217. };
  131218. static long _vq_quantlist__8u0__p7_1[] = {
  131219. 7,
  131220. 6,
  131221. 8,
  131222. 5,
  131223. 9,
  131224. 4,
  131225. 10,
  131226. 3,
  131227. 11,
  131228. 2,
  131229. 12,
  131230. 1,
  131231. 13,
  131232. 0,
  131233. 14,
  131234. };
  131235. static long _vq_lengthlist__8u0__p7_1[] = {
  131236. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131237. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131238. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131239. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131240. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131241. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131242. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131243. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131244. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131245. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131246. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131248. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131249. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131250. 10,
  131251. };
  131252. static float _vq_quantthresh__8u0__p7_1[] = {
  131253. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131254. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131255. };
  131256. static long _vq_quantmap__8u0__p7_1[] = {
  131257. 13, 11, 9, 7, 5, 3, 1, 0,
  131258. 2, 4, 6, 8, 10, 12, 14,
  131259. };
  131260. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131261. _vq_quantthresh__8u0__p7_1,
  131262. _vq_quantmap__8u0__p7_1,
  131263. 15,
  131264. 15
  131265. };
  131266. static static_codebook _8u0__p7_1 = {
  131267. 2, 225,
  131268. _vq_lengthlist__8u0__p7_1,
  131269. 1, -520986624, 1620377600, 4, 0,
  131270. _vq_quantlist__8u0__p7_1,
  131271. NULL,
  131272. &_vq_auxt__8u0__p7_1,
  131273. NULL,
  131274. 0
  131275. };
  131276. static long _vq_quantlist__8u0__p7_2[] = {
  131277. 10,
  131278. 9,
  131279. 11,
  131280. 8,
  131281. 12,
  131282. 7,
  131283. 13,
  131284. 6,
  131285. 14,
  131286. 5,
  131287. 15,
  131288. 4,
  131289. 16,
  131290. 3,
  131291. 17,
  131292. 2,
  131293. 18,
  131294. 1,
  131295. 19,
  131296. 0,
  131297. 20,
  131298. };
  131299. static long _vq_lengthlist__8u0__p7_2[] = {
  131300. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131301. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131302. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131303. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131304. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131305. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131306. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131307. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131308. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131309. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131310. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131311. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131312. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131313. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131314. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131315. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131316. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131317. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131318. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131319. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131320. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131321. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131322. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131323. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131324. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131325. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131326. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131327. 11,12,11,11,11,10,10,11,11,
  131328. };
  131329. static float _vq_quantthresh__8u0__p7_2[] = {
  131330. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131331. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131332. 6.5, 7.5, 8.5, 9.5,
  131333. };
  131334. static long _vq_quantmap__8u0__p7_2[] = {
  131335. 19, 17, 15, 13, 11, 9, 7, 5,
  131336. 3, 1, 0, 2, 4, 6, 8, 10,
  131337. 12, 14, 16, 18, 20,
  131338. };
  131339. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131340. _vq_quantthresh__8u0__p7_2,
  131341. _vq_quantmap__8u0__p7_2,
  131342. 21,
  131343. 21
  131344. };
  131345. static static_codebook _8u0__p7_2 = {
  131346. 2, 441,
  131347. _vq_lengthlist__8u0__p7_2,
  131348. 1, -529268736, 1611661312, 5, 0,
  131349. _vq_quantlist__8u0__p7_2,
  131350. NULL,
  131351. &_vq_auxt__8u0__p7_2,
  131352. NULL,
  131353. 0
  131354. };
  131355. static long _huff_lengthlist__8u0__single[] = {
  131356. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131357. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131358. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131359. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131360. };
  131361. static static_codebook _huff_book__8u0__single = {
  131362. 2, 64,
  131363. _huff_lengthlist__8u0__single,
  131364. 0, 0, 0, 0, 0,
  131365. NULL,
  131366. NULL,
  131367. NULL,
  131368. NULL,
  131369. 0
  131370. };
  131371. static long _vq_quantlist__8u1__p1_0[] = {
  131372. 1,
  131373. 0,
  131374. 2,
  131375. };
  131376. static long _vq_lengthlist__8u1__p1_0[] = {
  131377. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131378. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131379. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131380. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131381. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131382. 10,
  131383. };
  131384. static float _vq_quantthresh__8u1__p1_0[] = {
  131385. -0.5, 0.5,
  131386. };
  131387. static long _vq_quantmap__8u1__p1_0[] = {
  131388. 1, 0, 2,
  131389. };
  131390. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131391. _vq_quantthresh__8u1__p1_0,
  131392. _vq_quantmap__8u1__p1_0,
  131393. 3,
  131394. 3
  131395. };
  131396. static static_codebook _8u1__p1_0 = {
  131397. 4, 81,
  131398. _vq_lengthlist__8u1__p1_0,
  131399. 1, -535822336, 1611661312, 2, 0,
  131400. _vq_quantlist__8u1__p1_0,
  131401. NULL,
  131402. &_vq_auxt__8u1__p1_0,
  131403. NULL,
  131404. 0
  131405. };
  131406. static long _vq_quantlist__8u1__p2_0[] = {
  131407. 1,
  131408. 0,
  131409. 2,
  131410. };
  131411. static long _vq_lengthlist__8u1__p2_0[] = {
  131412. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131413. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131414. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131415. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131416. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131417. 7,
  131418. };
  131419. static float _vq_quantthresh__8u1__p2_0[] = {
  131420. -0.5, 0.5,
  131421. };
  131422. static long _vq_quantmap__8u1__p2_0[] = {
  131423. 1, 0, 2,
  131424. };
  131425. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131426. _vq_quantthresh__8u1__p2_0,
  131427. _vq_quantmap__8u1__p2_0,
  131428. 3,
  131429. 3
  131430. };
  131431. static static_codebook _8u1__p2_0 = {
  131432. 4, 81,
  131433. _vq_lengthlist__8u1__p2_0,
  131434. 1, -535822336, 1611661312, 2, 0,
  131435. _vq_quantlist__8u1__p2_0,
  131436. NULL,
  131437. &_vq_auxt__8u1__p2_0,
  131438. NULL,
  131439. 0
  131440. };
  131441. static long _vq_quantlist__8u1__p3_0[] = {
  131442. 2,
  131443. 1,
  131444. 3,
  131445. 0,
  131446. 4,
  131447. };
  131448. static long _vq_lengthlist__8u1__p3_0[] = {
  131449. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131450. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131451. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131452. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131453. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131454. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131455. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131456. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131457. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131458. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131459. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131460. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131461. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131462. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131463. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131464. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131465. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131466. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131467. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131468. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131469. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131470. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131471. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131472. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131473. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131474. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131475. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131476. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131477. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131478. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131479. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131480. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131481. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131482. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131483. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131484. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131485. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131486. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131487. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131488. 16,
  131489. };
  131490. static float _vq_quantthresh__8u1__p3_0[] = {
  131491. -1.5, -0.5, 0.5, 1.5,
  131492. };
  131493. static long _vq_quantmap__8u1__p3_0[] = {
  131494. 3, 1, 0, 2, 4,
  131495. };
  131496. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131497. _vq_quantthresh__8u1__p3_0,
  131498. _vq_quantmap__8u1__p3_0,
  131499. 5,
  131500. 5
  131501. };
  131502. static static_codebook _8u1__p3_0 = {
  131503. 4, 625,
  131504. _vq_lengthlist__8u1__p3_0,
  131505. 1, -533725184, 1611661312, 3, 0,
  131506. _vq_quantlist__8u1__p3_0,
  131507. NULL,
  131508. &_vq_auxt__8u1__p3_0,
  131509. NULL,
  131510. 0
  131511. };
  131512. static long _vq_quantlist__8u1__p4_0[] = {
  131513. 2,
  131514. 1,
  131515. 3,
  131516. 0,
  131517. 4,
  131518. };
  131519. static long _vq_lengthlist__8u1__p4_0[] = {
  131520. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131521. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131522. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131523. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131524. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131525. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131526. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131527. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131528. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131529. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131530. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131531. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131532. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131533. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131534. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131535. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131536. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131537. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131538. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131539. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131540. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131541. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131542. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131543. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131544. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131545. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131546. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131547. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131548. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131549. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131550. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131551. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131552. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131553. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131554. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131555. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131556. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131557. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131558. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131559. 10,
  131560. };
  131561. static float _vq_quantthresh__8u1__p4_0[] = {
  131562. -1.5, -0.5, 0.5, 1.5,
  131563. };
  131564. static long _vq_quantmap__8u1__p4_0[] = {
  131565. 3, 1, 0, 2, 4,
  131566. };
  131567. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131568. _vq_quantthresh__8u1__p4_0,
  131569. _vq_quantmap__8u1__p4_0,
  131570. 5,
  131571. 5
  131572. };
  131573. static static_codebook _8u1__p4_0 = {
  131574. 4, 625,
  131575. _vq_lengthlist__8u1__p4_0,
  131576. 1, -533725184, 1611661312, 3, 0,
  131577. _vq_quantlist__8u1__p4_0,
  131578. NULL,
  131579. &_vq_auxt__8u1__p4_0,
  131580. NULL,
  131581. 0
  131582. };
  131583. static long _vq_quantlist__8u1__p5_0[] = {
  131584. 4,
  131585. 3,
  131586. 5,
  131587. 2,
  131588. 6,
  131589. 1,
  131590. 7,
  131591. 0,
  131592. 8,
  131593. };
  131594. static long _vq_lengthlist__8u1__p5_0[] = {
  131595. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131596. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131597. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131598. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131599. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131600. 13,
  131601. };
  131602. static float _vq_quantthresh__8u1__p5_0[] = {
  131603. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131604. };
  131605. static long _vq_quantmap__8u1__p5_0[] = {
  131606. 7, 5, 3, 1, 0, 2, 4, 6,
  131607. 8,
  131608. };
  131609. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131610. _vq_quantthresh__8u1__p5_0,
  131611. _vq_quantmap__8u1__p5_0,
  131612. 9,
  131613. 9
  131614. };
  131615. static static_codebook _8u1__p5_0 = {
  131616. 2, 81,
  131617. _vq_lengthlist__8u1__p5_0,
  131618. 1, -531628032, 1611661312, 4, 0,
  131619. _vq_quantlist__8u1__p5_0,
  131620. NULL,
  131621. &_vq_auxt__8u1__p5_0,
  131622. NULL,
  131623. 0
  131624. };
  131625. static long _vq_quantlist__8u1__p6_0[] = {
  131626. 4,
  131627. 3,
  131628. 5,
  131629. 2,
  131630. 6,
  131631. 1,
  131632. 7,
  131633. 0,
  131634. 8,
  131635. };
  131636. static long _vq_lengthlist__8u1__p6_0[] = {
  131637. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131638. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131639. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131640. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131641. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131642. 10,
  131643. };
  131644. static float _vq_quantthresh__8u1__p6_0[] = {
  131645. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131646. };
  131647. static long _vq_quantmap__8u1__p6_0[] = {
  131648. 7, 5, 3, 1, 0, 2, 4, 6,
  131649. 8,
  131650. };
  131651. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131652. _vq_quantthresh__8u1__p6_0,
  131653. _vq_quantmap__8u1__p6_0,
  131654. 9,
  131655. 9
  131656. };
  131657. static static_codebook _8u1__p6_0 = {
  131658. 2, 81,
  131659. _vq_lengthlist__8u1__p6_0,
  131660. 1, -531628032, 1611661312, 4, 0,
  131661. _vq_quantlist__8u1__p6_0,
  131662. NULL,
  131663. &_vq_auxt__8u1__p6_0,
  131664. NULL,
  131665. 0
  131666. };
  131667. static long _vq_quantlist__8u1__p7_0[] = {
  131668. 1,
  131669. 0,
  131670. 2,
  131671. };
  131672. static long _vq_lengthlist__8u1__p7_0[] = {
  131673. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131674. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131675. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131676. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131677. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131678. 11,
  131679. };
  131680. static float _vq_quantthresh__8u1__p7_0[] = {
  131681. -5.5, 5.5,
  131682. };
  131683. static long _vq_quantmap__8u1__p7_0[] = {
  131684. 1, 0, 2,
  131685. };
  131686. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131687. _vq_quantthresh__8u1__p7_0,
  131688. _vq_quantmap__8u1__p7_0,
  131689. 3,
  131690. 3
  131691. };
  131692. static static_codebook _8u1__p7_0 = {
  131693. 4, 81,
  131694. _vq_lengthlist__8u1__p7_0,
  131695. 1, -529137664, 1618345984, 2, 0,
  131696. _vq_quantlist__8u1__p7_0,
  131697. NULL,
  131698. &_vq_auxt__8u1__p7_0,
  131699. NULL,
  131700. 0
  131701. };
  131702. static long _vq_quantlist__8u1__p7_1[] = {
  131703. 5,
  131704. 4,
  131705. 6,
  131706. 3,
  131707. 7,
  131708. 2,
  131709. 8,
  131710. 1,
  131711. 9,
  131712. 0,
  131713. 10,
  131714. };
  131715. static long _vq_lengthlist__8u1__p7_1[] = {
  131716. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131717. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131718. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131719. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131720. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131721. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131722. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131723. 9, 9, 9, 9, 9,10,10,10,10,
  131724. };
  131725. static float _vq_quantthresh__8u1__p7_1[] = {
  131726. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131727. 3.5, 4.5,
  131728. };
  131729. static long _vq_quantmap__8u1__p7_1[] = {
  131730. 9, 7, 5, 3, 1, 0, 2, 4,
  131731. 6, 8, 10,
  131732. };
  131733. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131734. _vq_quantthresh__8u1__p7_1,
  131735. _vq_quantmap__8u1__p7_1,
  131736. 11,
  131737. 11
  131738. };
  131739. static static_codebook _8u1__p7_1 = {
  131740. 2, 121,
  131741. _vq_lengthlist__8u1__p7_1,
  131742. 1, -531365888, 1611661312, 4, 0,
  131743. _vq_quantlist__8u1__p7_1,
  131744. NULL,
  131745. &_vq_auxt__8u1__p7_1,
  131746. NULL,
  131747. 0
  131748. };
  131749. static long _vq_quantlist__8u1__p8_0[] = {
  131750. 5,
  131751. 4,
  131752. 6,
  131753. 3,
  131754. 7,
  131755. 2,
  131756. 8,
  131757. 1,
  131758. 9,
  131759. 0,
  131760. 10,
  131761. };
  131762. static long _vq_lengthlist__8u1__p8_0[] = {
  131763. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131764. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131765. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131766. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131767. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131768. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131769. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131770. 12,13,13,14,14,15,15,15,15,
  131771. };
  131772. static float _vq_quantthresh__8u1__p8_0[] = {
  131773. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131774. 38.5, 49.5,
  131775. };
  131776. static long _vq_quantmap__8u1__p8_0[] = {
  131777. 9, 7, 5, 3, 1, 0, 2, 4,
  131778. 6, 8, 10,
  131779. };
  131780. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131781. _vq_quantthresh__8u1__p8_0,
  131782. _vq_quantmap__8u1__p8_0,
  131783. 11,
  131784. 11
  131785. };
  131786. static static_codebook _8u1__p8_0 = {
  131787. 2, 121,
  131788. _vq_lengthlist__8u1__p8_0,
  131789. 1, -524582912, 1618345984, 4, 0,
  131790. _vq_quantlist__8u1__p8_0,
  131791. NULL,
  131792. &_vq_auxt__8u1__p8_0,
  131793. NULL,
  131794. 0
  131795. };
  131796. static long _vq_quantlist__8u1__p8_1[] = {
  131797. 5,
  131798. 4,
  131799. 6,
  131800. 3,
  131801. 7,
  131802. 2,
  131803. 8,
  131804. 1,
  131805. 9,
  131806. 0,
  131807. 10,
  131808. };
  131809. static long _vq_lengthlist__8u1__p8_1[] = {
  131810. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131811. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131812. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131813. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131814. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131815. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131816. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131817. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131818. };
  131819. static float _vq_quantthresh__8u1__p8_1[] = {
  131820. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131821. 3.5, 4.5,
  131822. };
  131823. static long _vq_quantmap__8u1__p8_1[] = {
  131824. 9, 7, 5, 3, 1, 0, 2, 4,
  131825. 6, 8, 10,
  131826. };
  131827. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131828. _vq_quantthresh__8u1__p8_1,
  131829. _vq_quantmap__8u1__p8_1,
  131830. 11,
  131831. 11
  131832. };
  131833. static static_codebook _8u1__p8_1 = {
  131834. 2, 121,
  131835. _vq_lengthlist__8u1__p8_1,
  131836. 1, -531365888, 1611661312, 4, 0,
  131837. _vq_quantlist__8u1__p8_1,
  131838. NULL,
  131839. &_vq_auxt__8u1__p8_1,
  131840. NULL,
  131841. 0
  131842. };
  131843. static long _vq_quantlist__8u1__p9_0[] = {
  131844. 7,
  131845. 6,
  131846. 8,
  131847. 5,
  131848. 9,
  131849. 4,
  131850. 10,
  131851. 3,
  131852. 11,
  131853. 2,
  131854. 12,
  131855. 1,
  131856. 13,
  131857. 0,
  131858. 14,
  131859. };
  131860. static long _vq_lengthlist__8u1__p9_0[] = {
  131861. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131862. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131863. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131864. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131865. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131866. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131867. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131868. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131869. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131870. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131871. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131872. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131873. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131874. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131875. 10,
  131876. };
  131877. static float _vq_quantthresh__8u1__p9_0[] = {
  131878. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131879. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131880. };
  131881. static long _vq_quantmap__8u1__p9_0[] = {
  131882. 13, 11, 9, 7, 5, 3, 1, 0,
  131883. 2, 4, 6, 8, 10, 12, 14,
  131884. };
  131885. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131886. _vq_quantthresh__8u1__p9_0,
  131887. _vq_quantmap__8u1__p9_0,
  131888. 15,
  131889. 15
  131890. };
  131891. static static_codebook _8u1__p9_0 = {
  131892. 2, 225,
  131893. _vq_lengthlist__8u1__p9_0,
  131894. 1, -514071552, 1627381760, 4, 0,
  131895. _vq_quantlist__8u1__p9_0,
  131896. NULL,
  131897. &_vq_auxt__8u1__p9_0,
  131898. NULL,
  131899. 0
  131900. };
  131901. static long _vq_quantlist__8u1__p9_1[] = {
  131902. 7,
  131903. 6,
  131904. 8,
  131905. 5,
  131906. 9,
  131907. 4,
  131908. 10,
  131909. 3,
  131910. 11,
  131911. 2,
  131912. 12,
  131913. 1,
  131914. 13,
  131915. 0,
  131916. 14,
  131917. };
  131918. static long _vq_lengthlist__8u1__p9_1[] = {
  131919. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131920. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131921. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131922. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131923. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131924. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131925. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131926. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131927. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131928. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131929. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131930. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131931. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131932. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131933. 13,
  131934. };
  131935. static float _vq_quantthresh__8u1__p9_1[] = {
  131936. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131937. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131938. };
  131939. static long _vq_quantmap__8u1__p9_1[] = {
  131940. 13, 11, 9, 7, 5, 3, 1, 0,
  131941. 2, 4, 6, 8, 10, 12, 14,
  131942. };
  131943. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131944. _vq_quantthresh__8u1__p9_1,
  131945. _vq_quantmap__8u1__p9_1,
  131946. 15,
  131947. 15
  131948. };
  131949. static static_codebook _8u1__p9_1 = {
  131950. 2, 225,
  131951. _vq_lengthlist__8u1__p9_1,
  131952. 1, -522338304, 1620115456, 4, 0,
  131953. _vq_quantlist__8u1__p9_1,
  131954. NULL,
  131955. &_vq_auxt__8u1__p9_1,
  131956. NULL,
  131957. 0
  131958. };
  131959. static long _vq_quantlist__8u1__p9_2[] = {
  131960. 8,
  131961. 7,
  131962. 9,
  131963. 6,
  131964. 10,
  131965. 5,
  131966. 11,
  131967. 4,
  131968. 12,
  131969. 3,
  131970. 13,
  131971. 2,
  131972. 14,
  131973. 1,
  131974. 15,
  131975. 0,
  131976. 16,
  131977. };
  131978. static long _vq_lengthlist__8u1__p9_2[] = {
  131979. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131980. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131981. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131982. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131983. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131984. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131985. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131986. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131987. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131988. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131989. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131990. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131991. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131992. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131993. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131994. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131995. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131996. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131997. 10,
  131998. };
  131999. static float _vq_quantthresh__8u1__p9_2[] = {
  132000. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  132001. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  132002. };
  132003. static long _vq_quantmap__8u1__p9_2[] = {
  132004. 15, 13, 11, 9, 7, 5, 3, 1,
  132005. 0, 2, 4, 6, 8, 10, 12, 14,
  132006. 16,
  132007. };
  132008. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  132009. _vq_quantthresh__8u1__p9_2,
  132010. _vq_quantmap__8u1__p9_2,
  132011. 17,
  132012. 17
  132013. };
  132014. static static_codebook _8u1__p9_2 = {
  132015. 2, 289,
  132016. _vq_lengthlist__8u1__p9_2,
  132017. 1, -529530880, 1611661312, 5, 0,
  132018. _vq_quantlist__8u1__p9_2,
  132019. NULL,
  132020. &_vq_auxt__8u1__p9_2,
  132021. NULL,
  132022. 0
  132023. };
  132024. static long _huff_lengthlist__8u1__single[] = {
  132025. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  132026. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  132027. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  132028. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  132029. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  132030. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  132031. 13, 8, 8,15,
  132032. };
  132033. static static_codebook _huff_book__8u1__single = {
  132034. 2, 100,
  132035. _huff_lengthlist__8u1__single,
  132036. 0, 0, 0, 0, 0,
  132037. NULL,
  132038. NULL,
  132039. NULL,
  132040. NULL,
  132041. 0
  132042. };
  132043. static long _huff_lengthlist__44u0__long[] = {
  132044. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132045. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132046. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132047. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132048. };
  132049. static static_codebook _huff_book__44u0__long = {
  132050. 2, 64,
  132051. _huff_lengthlist__44u0__long,
  132052. 0, 0, 0, 0, 0,
  132053. NULL,
  132054. NULL,
  132055. NULL,
  132056. NULL,
  132057. 0
  132058. };
  132059. static long _vq_quantlist__44u0__p1_0[] = {
  132060. 1,
  132061. 0,
  132062. 2,
  132063. };
  132064. static long _vq_lengthlist__44u0__p1_0[] = {
  132065. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132066. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132067. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132068. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132069. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132070. 13,
  132071. };
  132072. static float _vq_quantthresh__44u0__p1_0[] = {
  132073. -0.5, 0.5,
  132074. };
  132075. static long _vq_quantmap__44u0__p1_0[] = {
  132076. 1, 0, 2,
  132077. };
  132078. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  132079. _vq_quantthresh__44u0__p1_0,
  132080. _vq_quantmap__44u0__p1_0,
  132081. 3,
  132082. 3
  132083. };
  132084. static static_codebook _44u0__p1_0 = {
  132085. 4, 81,
  132086. _vq_lengthlist__44u0__p1_0,
  132087. 1, -535822336, 1611661312, 2, 0,
  132088. _vq_quantlist__44u0__p1_0,
  132089. NULL,
  132090. &_vq_auxt__44u0__p1_0,
  132091. NULL,
  132092. 0
  132093. };
  132094. static long _vq_quantlist__44u0__p2_0[] = {
  132095. 1,
  132096. 0,
  132097. 2,
  132098. };
  132099. static long _vq_lengthlist__44u0__p2_0[] = {
  132100. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132101. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132102. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132103. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132104. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132105. 9,
  132106. };
  132107. static float _vq_quantthresh__44u0__p2_0[] = {
  132108. -0.5, 0.5,
  132109. };
  132110. static long _vq_quantmap__44u0__p2_0[] = {
  132111. 1, 0, 2,
  132112. };
  132113. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132114. _vq_quantthresh__44u0__p2_0,
  132115. _vq_quantmap__44u0__p2_0,
  132116. 3,
  132117. 3
  132118. };
  132119. static static_codebook _44u0__p2_0 = {
  132120. 4, 81,
  132121. _vq_lengthlist__44u0__p2_0,
  132122. 1, -535822336, 1611661312, 2, 0,
  132123. _vq_quantlist__44u0__p2_0,
  132124. NULL,
  132125. &_vq_auxt__44u0__p2_0,
  132126. NULL,
  132127. 0
  132128. };
  132129. static long _vq_quantlist__44u0__p3_0[] = {
  132130. 2,
  132131. 1,
  132132. 3,
  132133. 0,
  132134. 4,
  132135. };
  132136. static long _vq_lengthlist__44u0__p3_0[] = {
  132137. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132138. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132139. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132140. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132141. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132142. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132143. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132144. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132145. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132146. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132147. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132148. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132149. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132150. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132151. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132152. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132153. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132154. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132155. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132156. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132157. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132158. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132159. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132160. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132161. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132162. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132163. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132164. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132165. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132166. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132167. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132168. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132169. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132170. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132171. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132172. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132173. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132174. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132175. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132176. 19,
  132177. };
  132178. static float _vq_quantthresh__44u0__p3_0[] = {
  132179. -1.5, -0.5, 0.5, 1.5,
  132180. };
  132181. static long _vq_quantmap__44u0__p3_0[] = {
  132182. 3, 1, 0, 2, 4,
  132183. };
  132184. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132185. _vq_quantthresh__44u0__p3_0,
  132186. _vq_quantmap__44u0__p3_0,
  132187. 5,
  132188. 5
  132189. };
  132190. static static_codebook _44u0__p3_0 = {
  132191. 4, 625,
  132192. _vq_lengthlist__44u0__p3_0,
  132193. 1, -533725184, 1611661312, 3, 0,
  132194. _vq_quantlist__44u0__p3_0,
  132195. NULL,
  132196. &_vq_auxt__44u0__p3_0,
  132197. NULL,
  132198. 0
  132199. };
  132200. static long _vq_quantlist__44u0__p4_0[] = {
  132201. 2,
  132202. 1,
  132203. 3,
  132204. 0,
  132205. 4,
  132206. };
  132207. static long _vq_lengthlist__44u0__p4_0[] = {
  132208. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132209. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132210. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132211. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132212. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132213. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132214. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132215. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132216. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132217. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132218. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132219. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132220. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132221. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132222. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132223. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132224. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132225. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132226. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132227. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132228. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132229. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132230. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132231. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132232. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132233. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132234. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132235. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132236. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132237. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132238. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132239. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132240. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132241. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132242. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132243. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132244. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132245. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132246. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132247. 12,
  132248. };
  132249. static float _vq_quantthresh__44u0__p4_0[] = {
  132250. -1.5, -0.5, 0.5, 1.5,
  132251. };
  132252. static long _vq_quantmap__44u0__p4_0[] = {
  132253. 3, 1, 0, 2, 4,
  132254. };
  132255. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132256. _vq_quantthresh__44u0__p4_0,
  132257. _vq_quantmap__44u0__p4_0,
  132258. 5,
  132259. 5
  132260. };
  132261. static static_codebook _44u0__p4_0 = {
  132262. 4, 625,
  132263. _vq_lengthlist__44u0__p4_0,
  132264. 1, -533725184, 1611661312, 3, 0,
  132265. _vq_quantlist__44u0__p4_0,
  132266. NULL,
  132267. &_vq_auxt__44u0__p4_0,
  132268. NULL,
  132269. 0
  132270. };
  132271. static long _vq_quantlist__44u0__p5_0[] = {
  132272. 4,
  132273. 3,
  132274. 5,
  132275. 2,
  132276. 6,
  132277. 1,
  132278. 7,
  132279. 0,
  132280. 8,
  132281. };
  132282. static long _vq_lengthlist__44u0__p5_0[] = {
  132283. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132284. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132285. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132286. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132287. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132288. 12,
  132289. };
  132290. static float _vq_quantthresh__44u0__p5_0[] = {
  132291. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132292. };
  132293. static long _vq_quantmap__44u0__p5_0[] = {
  132294. 7, 5, 3, 1, 0, 2, 4, 6,
  132295. 8,
  132296. };
  132297. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132298. _vq_quantthresh__44u0__p5_0,
  132299. _vq_quantmap__44u0__p5_0,
  132300. 9,
  132301. 9
  132302. };
  132303. static static_codebook _44u0__p5_0 = {
  132304. 2, 81,
  132305. _vq_lengthlist__44u0__p5_0,
  132306. 1, -531628032, 1611661312, 4, 0,
  132307. _vq_quantlist__44u0__p5_0,
  132308. NULL,
  132309. &_vq_auxt__44u0__p5_0,
  132310. NULL,
  132311. 0
  132312. };
  132313. static long _vq_quantlist__44u0__p6_0[] = {
  132314. 6,
  132315. 5,
  132316. 7,
  132317. 4,
  132318. 8,
  132319. 3,
  132320. 9,
  132321. 2,
  132322. 10,
  132323. 1,
  132324. 11,
  132325. 0,
  132326. 12,
  132327. };
  132328. static long _vq_lengthlist__44u0__p6_0[] = {
  132329. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132330. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132331. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132332. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132333. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132334. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132335. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132336. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132337. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132338. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132339. 15,17,16,17,18,17,17,18, 0,
  132340. };
  132341. static float _vq_quantthresh__44u0__p6_0[] = {
  132342. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132343. 12.5, 17.5, 22.5, 27.5,
  132344. };
  132345. static long _vq_quantmap__44u0__p6_0[] = {
  132346. 11, 9, 7, 5, 3, 1, 0, 2,
  132347. 4, 6, 8, 10, 12,
  132348. };
  132349. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132350. _vq_quantthresh__44u0__p6_0,
  132351. _vq_quantmap__44u0__p6_0,
  132352. 13,
  132353. 13
  132354. };
  132355. static static_codebook _44u0__p6_0 = {
  132356. 2, 169,
  132357. _vq_lengthlist__44u0__p6_0,
  132358. 1, -526516224, 1616117760, 4, 0,
  132359. _vq_quantlist__44u0__p6_0,
  132360. NULL,
  132361. &_vq_auxt__44u0__p6_0,
  132362. NULL,
  132363. 0
  132364. };
  132365. static long _vq_quantlist__44u0__p6_1[] = {
  132366. 2,
  132367. 1,
  132368. 3,
  132369. 0,
  132370. 4,
  132371. };
  132372. static long _vq_lengthlist__44u0__p6_1[] = {
  132373. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132374. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132375. };
  132376. static float _vq_quantthresh__44u0__p6_1[] = {
  132377. -1.5, -0.5, 0.5, 1.5,
  132378. };
  132379. static long _vq_quantmap__44u0__p6_1[] = {
  132380. 3, 1, 0, 2, 4,
  132381. };
  132382. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132383. _vq_quantthresh__44u0__p6_1,
  132384. _vq_quantmap__44u0__p6_1,
  132385. 5,
  132386. 5
  132387. };
  132388. static static_codebook _44u0__p6_1 = {
  132389. 2, 25,
  132390. _vq_lengthlist__44u0__p6_1,
  132391. 1, -533725184, 1611661312, 3, 0,
  132392. _vq_quantlist__44u0__p6_1,
  132393. NULL,
  132394. &_vq_auxt__44u0__p6_1,
  132395. NULL,
  132396. 0
  132397. };
  132398. static long _vq_quantlist__44u0__p7_0[] = {
  132399. 2,
  132400. 1,
  132401. 3,
  132402. 0,
  132403. 4,
  132404. };
  132405. static long _vq_lengthlist__44u0__p7_0[] = {
  132406. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132407. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132408. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132409. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132410. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132411. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132412. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132413. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132414. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132415. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132416. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132417. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132418. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132419. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132420. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132421. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132422. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132423. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132424. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132426. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132428. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132429. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132430. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132431. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132432. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132433. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132434. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132435. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132436. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132437. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132438. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132439. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132440. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132441. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132442. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132443. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132444. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132445. 10,
  132446. };
  132447. static float _vq_quantthresh__44u0__p7_0[] = {
  132448. -253.5, -84.5, 84.5, 253.5,
  132449. };
  132450. static long _vq_quantmap__44u0__p7_0[] = {
  132451. 3, 1, 0, 2, 4,
  132452. };
  132453. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132454. _vq_quantthresh__44u0__p7_0,
  132455. _vq_quantmap__44u0__p7_0,
  132456. 5,
  132457. 5
  132458. };
  132459. static static_codebook _44u0__p7_0 = {
  132460. 4, 625,
  132461. _vq_lengthlist__44u0__p7_0,
  132462. 1, -518709248, 1626677248, 3, 0,
  132463. _vq_quantlist__44u0__p7_0,
  132464. NULL,
  132465. &_vq_auxt__44u0__p7_0,
  132466. NULL,
  132467. 0
  132468. };
  132469. static long _vq_quantlist__44u0__p7_1[] = {
  132470. 6,
  132471. 5,
  132472. 7,
  132473. 4,
  132474. 8,
  132475. 3,
  132476. 9,
  132477. 2,
  132478. 10,
  132479. 1,
  132480. 11,
  132481. 0,
  132482. 12,
  132483. };
  132484. static long _vq_lengthlist__44u0__p7_1[] = {
  132485. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132486. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132487. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132488. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132489. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132490. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132491. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132492. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132493. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132494. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132495. 15,15,15,15,15,15,15,15,15,
  132496. };
  132497. static float _vq_quantthresh__44u0__p7_1[] = {
  132498. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132499. 32.5, 45.5, 58.5, 71.5,
  132500. };
  132501. static long _vq_quantmap__44u0__p7_1[] = {
  132502. 11, 9, 7, 5, 3, 1, 0, 2,
  132503. 4, 6, 8, 10, 12,
  132504. };
  132505. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132506. _vq_quantthresh__44u0__p7_1,
  132507. _vq_quantmap__44u0__p7_1,
  132508. 13,
  132509. 13
  132510. };
  132511. static static_codebook _44u0__p7_1 = {
  132512. 2, 169,
  132513. _vq_lengthlist__44u0__p7_1,
  132514. 1, -523010048, 1618608128, 4, 0,
  132515. _vq_quantlist__44u0__p7_1,
  132516. NULL,
  132517. &_vq_auxt__44u0__p7_1,
  132518. NULL,
  132519. 0
  132520. };
  132521. static long _vq_quantlist__44u0__p7_2[] = {
  132522. 6,
  132523. 5,
  132524. 7,
  132525. 4,
  132526. 8,
  132527. 3,
  132528. 9,
  132529. 2,
  132530. 10,
  132531. 1,
  132532. 11,
  132533. 0,
  132534. 12,
  132535. };
  132536. static long _vq_lengthlist__44u0__p7_2[] = {
  132537. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132538. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132539. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132540. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132541. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132542. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132543. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132544. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132545. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132546. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132547. 9, 9, 9,10, 9, 9,10,10, 9,
  132548. };
  132549. static float _vq_quantthresh__44u0__p7_2[] = {
  132550. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132551. 2.5, 3.5, 4.5, 5.5,
  132552. };
  132553. static long _vq_quantmap__44u0__p7_2[] = {
  132554. 11, 9, 7, 5, 3, 1, 0, 2,
  132555. 4, 6, 8, 10, 12,
  132556. };
  132557. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132558. _vq_quantthresh__44u0__p7_2,
  132559. _vq_quantmap__44u0__p7_2,
  132560. 13,
  132561. 13
  132562. };
  132563. static static_codebook _44u0__p7_2 = {
  132564. 2, 169,
  132565. _vq_lengthlist__44u0__p7_2,
  132566. 1, -531103744, 1611661312, 4, 0,
  132567. _vq_quantlist__44u0__p7_2,
  132568. NULL,
  132569. &_vq_auxt__44u0__p7_2,
  132570. NULL,
  132571. 0
  132572. };
  132573. static long _huff_lengthlist__44u0__short[] = {
  132574. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132575. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132576. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132577. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132578. };
  132579. static static_codebook _huff_book__44u0__short = {
  132580. 2, 64,
  132581. _huff_lengthlist__44u0__short,
  132582. 0, 0, 0, 0, 0,
  132583. NULL,
  132584. NULL,
  132585. NULL,
  132586. NULL,
  132587. 0
  132588. };
  132589. static long _huff_lengthlist__44u1__long[] = {
  132590. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132591. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132592. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132593. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132594. };
  132595. static static_codebook _huff_book__44u1__long = {
  132596. 2, 64,
  132597. _huff_lengthlist__44u1__long,
  132598. 0, 0, 0, 0, 0,
  132599. NULL,
  132600. NULL,
  132601. NULL,
  132602. NULL,
  132603. 0
  132604. };
  132605. static long _vq_quantlist__44u1__p1_0[] = {
  132606. 1,
  132607. 0,
  132608. 2,
  132609. };
  132610. static long _vq_lengthlist__44u1__p1_0[] = {
  132611. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132612. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132613. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132614. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132615. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132616. 13,
  132617. };
  132618. static float _vq_quantthresh__44u1__p1_0[] = {
  132619. -0.5, 0.5,
  132620. };
  132621. static long _vq_quantmap__44u1__p1_0[] = {
  132622. 1, 0, 2,
  132623. };
  132624. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132625. _vq_quantthresh__44u1__p1_0,
  132626. _vq_quantmap__44u1__p1_0,
  132627. 3,
  132628. 3
  132629. };
  132630. static static_codebook _44u1__p1_0 = {
  132631. 4, 81,
  132632. _vq_lengthlist__44u1__p1_0,
  132633. 1, -535822336, 1611661312, 2, 0,
  132634. _vq_quantlist__44u1__p1_0,
  132635. NULL,
  132636. &_vq_auxt__44u1__p1_0,
  132637. NULL,
  132638. 0
  132639. };
  132640. static long _vq_quantlist__44u1__p2_0[] = {
  132641. 1,
  132642. 0,
  132643. 2,
  132644. };
  132645. static long _vq_lengthlist__44u1__p2_0[] = {
  132646. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132647. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132648. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132649. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132650. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132651. 9,
  132652. };
  132653. static float _vq_quantthresh__44u1__p2_0[] = {
  132654. -0.5, 0.5,
  132655. };
  132656. static long _vq_quantmap__44u1__p2_0[] = {
  132657. 1, 0, 2,
  132658. };
  132659. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132660. _vq_quantthresh__44u1__p2_0,
  132661. _vq_quantmap__44u1__p2_0,
  132662. 3,
  132663. 3
  132664. };
  132665. static static_codebook _44u1__p2_0 = {
  132666. 4, 81,
  132667. _vq_lengthlist__44u1__p2_0,
  132668. 1, -535822336, 1611661312, 2, 0,
  132669. _vq_quantlist__44u1__p2_0,
  132670. NULL,
  132671. &_vq_auxt__44u1__p2_0,
  132672. NULL,
  132673. 0
  132674. };
  132675. static long _vq_quantlist__44u1__p3_0[] = {
  132676. 2,
  132677. 1,
  132678. 3,
  132679. 0,
  132680. 4,
  132681. };
  132682. static long _vq_lengthlist__44u1__p3_0[] = {
  132683. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132684. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132685. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132686. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132687. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132688. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132689. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132690. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132691. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132692. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132693. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132694. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132695. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132696. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132697. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132698. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132699. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132700. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132701. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132702. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132703. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132704. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132705. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132706. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132707. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132708. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132709. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132710. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132711. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132712. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132713. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132714. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132715. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132716. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132717. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132718. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132719. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132720. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132721. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132722. 19,
  132723. };
  132724. static float _vq_quantthresh__44u1__p3_0[] = {
  132725. -1.5, -0.5, 0.5, 1.5,
  132726. };
  132727. static long _vq_quantmap__44u1__p3_0[] = {
  132728. 3, 1, 0, 2, 4,
  132729. };
  132730. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132731. _vq_quantthresh__44u1__p3_0,
  132732. _vq_quantmap__44u1__p3_0,
  132733. 5,
  132734. 5
  132735. };
  132736. static static_codebook _44u1__p3_0 = {
  132737. 4, 625,
  132738. _vq_lengthlist__44u1__p3_0,
  132739. 1, -533725184, 1611661312, 3, 0,
  132740. _vq_quantlist__44u1__p3_0,
  132741. NULL,
  132742. &_vq_auxt__44u1__p3_0,
  132743. NULL,
  132744. 0
  132745. };
  132746. static long _vq_quantlist__44u1__p4_0[] = {
  132747. 2,
  132748. 1,
  132749. 3,
  132750. 0,
  132751. 4,
  132752. };
  132753. static long _vq_lengthlist__44u1__p4_0[] = {
  132754. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132755. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132756. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132757. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132758. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132759. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132760. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132761. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132762. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132763. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132764. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132765. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132766. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132767. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132768. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132769. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132770. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132771. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132772. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132773. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132774. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132775. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132776. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132777. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132778. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132779. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132780. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132781. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132782. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132783. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132784. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132785. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132786. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132787. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132788. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132789. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132790. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132791. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132792. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132793. 12,
  132794. };
  132795. static float _vq_quantthresh__44u1__p4_0[] = {
  132796. -1.5, -0.5, 0.5, 1.5,
  132797. };
  132798. static long _vq_quantmap__44u1__p4_0[] = {
  132799. 3, 1, 0, 2, 4,
  132800. };
  132801. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132802. _vq_quantthresh__44u1__p4_0,
  132803. _vq_quantmap__44u1__p4_0,
  132804. 5,
  132805. 5
  132806. };
  132807. static static_codebook _44u1__p4_0 = {
  132808. 4, 625,
  132809. _vq_lengthlist__44u1__p4_0,
  132810. 1, -533725184, 1611661312, 3, 0,
  132811. _vq_quantlist__44u1__p4_0,
  132812. NULL,
  132813. &_vq_auxt__44u1__p4_0,
  132814. NULL,
  132815. 0
  132816. };
  132817. static long _vq_quantlist__44u1__p5_0[] = {
  132818. 4,
  132819. 3,
  132820. 5,
  132821. 2,
  132822. 6,
  132823. 1,
  132824. 7,
  132825. 0,
  132826. 8,
  132827. };
  132828. static long _vq_lengthlist__44u1__p5_0[] = {
  132829. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132830. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132831. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132832. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132833. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132834. 12,
  132835. };
  132836. static float _vq_quantthresh__44u1__p5_0[] = {
  132837. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132838. };
  132839. static long _vq_quantmap__44u1__p5_0[] = {
  132840. 7, 5, 3, 1, 0, 2, 4, 6,
  132841. 8,
  132842. };
  132843. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132844. _vq_quantthresh__44u1__p5_0,
  132845. _vq_quantmap__44u1__p5_0,
  132846. 9,
  132847. 9
  132848. };
  132849. static static_codebook _44u1__p5_0 = {
  132850. 2, 81,
  132851. _vq_lengthlist__44u1__p5_0,
  132852. 1, -531628032, 1611661312, 4, 0,
  132853. _vq_quantlist__44u1__p5_0,
  132854. NULL,
  132855. &_vq_auxt__44u1__p5_0,
  132856. NULL,
  132857. 0
  132858. };
  132859. static long _vq_quantlist__44u1__p6_0[] = {
  132860. 6,
  132861. 5,
  132862. 7,
  132863. 4,
  132864. 8,
  132865. 3,
  132866. 9,
  132867. 2,
  132868. 10,
  132869. 1,
  132870. 11,
  132871. 0,
  132872. 12,
  132873. };
  132874. static long _vq_lengthlist__44u1__p6_0[] = {
  132875. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132876. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132877. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132878. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132879. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132880. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132881. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132882. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132883. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132884. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132885. 15,17,16,17,18,17,17,18, 0,
  132886. };
  132887. static float _vq_quantthresh__44u1__p6_0[] = {
  132888. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132889. 12.5, 17.5, 22.5, 27.5,
  132890. };
  132891. static long _vq_quantmap__44u1__p6_0[] = {
  132892. 11, 9, 7, 5, 3, 1, 0, 2,
  132893. 4, 6, 8, 10, 12,
  132894. };
  132895. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132896. _vq_quantthresh__44u1__p6_0,
  132897. _vq_quantmap__44u1__p6_0,
  132898. 13,
  132899. 13
  132900. };
  132901. static static_codebook _44u1__p6_0 = {
  132902. 2, 169,
  132903. _vq_lengthlist__44u1__p6_0,
  132904. 1, -526516224, 1616117760, 4, 0,
  132905. _vq_quantlist__44u1__p6_0,
  132906. NULL,
  132907. &_vq_auxt__44u1__p6_0,
  132908. NULL,
  132909. 0
  132910. };
  132911. static long _vq_quantlist__44u1__p6_1[] = {
  132912. 2,
  132913. 1,
  132914. 3,
  132915. 0,
  132916. 4,
  132917. };
  132918. static long _vq_lengthlist__44u1__p6_1[] = {
  132919. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132920. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132921. };
  132922. static float _vq_quantthresh__44u1__p6_1[] = {
  132923. -1.5, -0.5, 0.5, 1.5,
  132924. };
  132925. static long _vq_quantmap__44u1__p6_1[] = {
  132926. 3, 1, 0, 2, 4,
  132927. };
  132928. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132929. _vq_quantthresh__44u1__p6_1,
  132930. _vq_quantmap__44u1__p6_1,
  132931. 5,
  132932. 5
  132933. };
  132934. static static_codebook _44u1__p6_1 = {
  132935. 2, 25,
  132936. _vq_lengthlist__44u1__p6_1,
  132937. 1, -533725184, 1611661312, 3, 0,
  132938. _vq_quantlist__44u1__p6_1,
  132939. NULL,
  132940. &_vq_auxt__44u1__p6_1,
  132941. NULL,
  132942. 0
  132943. };
  132944. static long _vq_quantlist__44u1__p7_0[] = {
  132945. 3,
  132946. 2,
  132947. 4,
  132948. 1,
  132949. 5,
  132950. 0,
  132951. 6,
  132952. };
  132953. static long _vq_lengthlist__44u1__p7_0[] = {
  132954. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132955. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132956. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132957. 8,
  132958. };
  132959. static float _vq_quantthresh__44u1__p7_0[] = {
  132960. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132961. };
  132962. static long _vq_quantmap__44u1__p7_0[] = {
  132963. 5, 3, 1, 0, 2, 4, 6,
  132964. };
  132965. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132966. _vq_quantthresh__44u1__p7_0,
  132967. _vq_quantmap__44u1__p7_0,
  132968. 7,
  132969. 7
  132970. };
  132971. static static_codebook _44u1__p7_0 = {
  132972. 2, 49,
  132973. _vq_lengthlist__44u1__p7_0,
  132974. 1, -518017024, 1626677248, 3, 0,
  132975. _vq_quantlist__44u1__p7_0,
  132976. NULL,
  132977. &_vq_auxt__44u1__p7_0,
  132978. NULL,
  132979. 0
  132980. };
  132981. static long _vq_quantlist__44u1__p7_1[] = {
  132982. 6,
  132983. 5,
  132984. 7,
  132985. 4,
  132986. 8,
  132987. 3,
  132988. 9,
  132989. 2,
  132990. 10,
  132991. 1,
  132992. 11,
  132993. 0,
  132994. 12,
  132995. };
  132996. static long _vq_lengthlist__44u1__p7_1[] = {
  132997. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132998. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132999. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  133000. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  133001. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  133002. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  133003. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  133004. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  133005. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  133006. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  133007. 15,15,15,15,15,15,15,15,15,
  133008. };
  133009. static float _vq_quantthresh__44u1__p7_1[] = {
  133010. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133011. 32.5, 45.5, 58.5, 71.5,
  133012. };
  133013. static long _vq_quantmap__44u1__p7_1[] = {
  133014. 11, 9, 7, 5, 3, 1, 0, 2,
  133015. 4, 6, 8, 10, 12,
  133016. };
  133017. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  133018. _vq_quantthresh__44u1__p7_1,
  133019. _vq_quantmap__44u1__p7_1,
  133020. 13,
  133021. 13
  133022. };
  133023. static static_codebook _44u1__p7_1 = {
  133024. 2, 169,
  133025. _vq_lengthlist__44u1__p7_1,
  133026. 1, -523010048, 1618608128, 4, 0,
  133027. _vq_quantlist__44u1__p7_1,
  133028. NULL,
  133029. &_vq_auxt__44u1__p7_1,
  133030. NULL,
  133031. 0
  133032. };
  133033. static long _vq_quantlist__44u1__p7_2[] = {
  133034. 6,
  133035. 5,
  133036. 7,
  133037. 4,
  133038. 8,
  133039. 3,
  133040. 9,
  133041. 2,
  133042. 10,
  133043. 1,
  133044. 11,
  133045. 0,
  133046. 12,
  133047. };
  133048. static long _vq_lengthlist__44u1__p7_2[] = {
  133049. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  133050. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  133051. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  133052. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133053. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  133054. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  133055. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  133056. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133057. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133058. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  133059. 9, 9, 9,10, 9, 9,10,10, 9,
  133060. };
  133061. static float _vq_quantthresh__44u1__p7_2[] = {
  133062. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133063. 2.5, 3.5, 4.5, 5.5,
  133064. };
  133065. static long _vq_quantmap__44u1__p7_2[] = {
  133066. 11, 9, 7, 5, 3, 1, 0, 2,
  133067. 4, 6, 8, 10, 12,
  133068. };
  133069. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  133070. _vq_quantthresh__44u1__p7_2,
  133071. _vq_quantmap__44u1__p7_2,
  133072. 13,
  133073. 13
  133074. };
  133075. static static_codebook _44u1__p7_2 = {
  133076. 2, 169,
  133077. _vq_lengthlist__44u1__p7_2,
  133078. 1, -531103744, 1611661312, 4, 0,
  133079. _vq_quantlist__44u1__p7_2,
  133080. NULL,
  133081. &_vq_auxt__44u1__p7_2,
  133082. NULL,
  133083. 0
  133084. };
  133085. static long _huff_lengthlist__44u1__short[] = {
  133086. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  133087. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  133088. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  133089. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  133090. };
  133091. static static_codebook _huff_book__44u1__short = {
  133092. 2, 64,
  133093. _huff_lengthlist__44u1__short,
  133094. 0, 0, 0, 0, 0,
  133095. NULL,
  133096. NULL,
  133097. NULL,
  133098. NULL,
  133099. 0
  133100. };
  133101. static long _huff_lengthlist__44u2__long[] = {
  133102. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133103. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133104. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133105. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133106. };
  133107. static static_codebook _huff_book__44u2__long = {
  133108. 2, 64,
  133109. _huff_lengthlist__44u2__long,
  133110. 0, 0, 0, 0, 0,
  133111. NULL,
  133112. NULL,
  133113. NULL,
  133114. NULL,
  133115. 0
  133116. };
  133117. static long _vq_quantlist__44u2__p1_0[] = {
  133118. 1,
  133119. 0,
  133120. 2,
  133121. };
  133122. static long _vq_lengthlist__44u2__p1_0[] = {
  133123. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133124. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133125. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133126. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133127. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133128. 13,
  133129. };
  133130. static float _vq_quantthresh__44u2__p1_0[] = {
  133131. -0.5, 0.5,
  133132. };
  133133. static long _vq_quantmap__44u2__p1_0[] = {
  133134. 1, 0, 2,
  133135. };
  133136. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133137. _vq_quantthresh__44u2__p1_0,
  133138. _vq_quantmap__44u2__p1_0,
  133139. 3,
  133140. 3
  133141. };
  133142. static static_codebook _44u2__p1_0 = {
  133143. 4, 81,
  133144. _vq_lengthlist__44u2__p1_0,
  133145. 1, -535822336, 1611661312, 2, 0,
  133146. _vq_quantlist__44u2__p1_0,
  133147. NULL,
  133148. &_vq_auxt__44u2__p1_0,
  133149. NULL,
  133150. 0
  133151. };
  133152. static long _vq_quantlist__44u2__p2_0[] = {
  133153. 1,
  133154. 0,
  133155. 2,
  133156. };
  133157. static long _vq_lengthlist__44u2__p2_0[] = {
  133158. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133159. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133160. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133161. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133162. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133163. 9,
  133164. };
  133165. static float _vq_quantthresh__44u2__p2_0[] = {
  133166. -0.5, 0.5,
  133167. };
  133168. static long _vq_quantmap__44u2__p2_0[] = {
  133169. 1, 0, 2,
  133170. };
  133171. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133172. _vq_quantthresh__44u2__p2_0,
  133173. _vq_quantmap__44u2__p2_0,
  133174. 3,
  133175. 3
  133176. };
  133177. static static_codebook _44u2__p2_0 = {
  133178. 4, 81,
  133179. _vq_lengthlist__44u2__p2_0,
  133180. 1, -535822336, 1611661312, 2, 0,
  133181. _vq_quantlist__44u2__p2_0,
  133182. NULL,
  133183. &_vq_auxt__44u2__p2_0,
  133184. NULL,
  133185. 0
  133186. };
  133187. static long _vq_quantlist__44u2__p3_0[] = {
  133188. 2,
  133189. 1,
  133190. 3,
  133191. 0,
  133192. 4,
  133193. };
  133194. static long _vq_lengthlist__44u2__p3_0[] = {
  133195. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133196. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133197. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133198. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133199. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133200. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133201. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133202. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133203. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133204. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133205. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133206. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133207. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133208. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133209. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133210. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133211. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133212. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133213. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133214. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133215. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133216. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133217. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133218. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133219. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133220. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133221. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133222. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133223. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133224. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133225. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133226. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133227. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133228. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133229. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133230. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133231. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133232. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133233. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133234. 0,
  133235. };
  133236. static float _vq_quantthresh__44u2__p3_0[] = {
  133237. -1.5, -0.5, 0.5, 1.5,
  133238. };
  133239. static long _vq_quantmap__44u2__p3_0[] = {
  133240. 3, 1, 0, 2, 4,
  133241. };
  133242. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133243. _vq_quantthresh__44u2__p3_0,
  133244. _vq_quantmap__44u2__p3_0,
  133245. 5,
  133246. 5
  133247. };
  133248. static static_codebook _44u2__p3_0 = {
  133249. 4, 625,
  133250. _vq_lengthlist__44u2__p3_0,
  133251. 1, -533725184, 1611661312, 3, 0,
  133252. _vq_quantlist__44u2__p3_0,
  133253. NULL,
  133254. &_vq_auxt__44u2__p3_0,
  133255. NULL,
  133256. 0
  133257. };
  133258. static long _vq_quantlist__44u2__p4_0[] = {
  133259. 2,
  133260. 1,
  133261. 3,
  133262. 0,
  133263. 4,
  133264. };
  133265. static long _vq_lengthlist__44u2__p4_0[] = {
  133266. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133267. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133268. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133269. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133270. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133271. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133272. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133273. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133274. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133275. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133276. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133277. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133278. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133279. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133280. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133281. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133282. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133283. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133284. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133285. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133286. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133287. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133288. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133289. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133290. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133291. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133292. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133293. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133294. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133295. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133296. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133297. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133298. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133299. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133300. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133301. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133302. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133303. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133304. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133305. 13,
  133306. };
  133307. static float _vq_quantthresh__44u2__p4_0[] = {
  133308. -1.5, -0.5, 0.5, 1.5,
  133309. };
  133310. static long _vq_quantmap__44u2__p4_0[] = {
  133311. 3, 1, 0, 2, 4,
  133312. };
  133313. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133314. _vq_quantthresh__44u2__p4_0,
  133315. _vq_quantmap__44u2__p4_0,
  133316. 5,
  133317. 5
  133318. };
  133319. static static_codebook _44u2__p4_0 = {
  133320. 4, 625,
  133321. _vq_lengthlist__44u2__p4_0,
  133322. 1, -533725184, 1611661312, 3, 0,
  133323. _vq_quantlist__44u2__p4_0,
  133324. NULL,
  133325. &_vq_auxt__44u2__p4_0,
  133326. NULL,
  133327. 0
  133328. };
  133329. static long _vq_quantlist__44u2__p5_0[] = {
  133330. 4,
  133331. 3,
  133332. 5,
  133333. 2,
  133334. 6,
  133335. 1,
  133336. 7,
  133337. 0,
  133338. 8,
  133339. };
  133340. static long _vq_lengthlist__44u2__p5_0[] = {
  133341. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133342. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133343. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133344. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133345. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133346. 13,
  133347. };
  133348. static float _vq_quantthresh__44u2__p5_0[] = {
  133349. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133350. };
  133351. static long _vq_quantmap__44u2__p5_0[] = {
  133352. 7, 5, 3, 1, 0, 2, 4, 6,
  133353. 8,
  133354. };
  133355. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133356. _vq_quantthresh__44u2__p5_0,
  133357. _vq_quantmap__44u2__p5_0,
  133358. 9,
  133359. 9
  133360. };
  133361. static static_codebook _44u2__p5_0 = {
  133362. 2, 81,
  133363. _vq_lengthlist__44u2__p5_0,
  133364. 1, -531628032, 1611661312, 4, 0,
  133365. _vq_quantlist__44u2__p5_0,
  133366. NULL,
  133367. &_vq_auxt__44u2__p5_0,
  133368. NULL,
  133369. 0
  133370. };
  133371. static long _vq_quantlist__44u2__p6_0[] = {
  133372. 6,
  133373. 5,
  133374. 7,
  133375. 4,
  133376. 8,
  133377. 3,
  133378. 9,
  133379. 2,
  133380. 10,
  133381. 1,
  133382. 11,
  133383. 0,
  133384. 12,
  133385. };
  133386. static long _vq_lengthlist__44u2__p6_0[] = {
  133387. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133388. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133389. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133390. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133391. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133392. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133393. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133394. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133395. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133396. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133397. 15,17,17,16,18,17,18, 0, 0,
  133398. };
  133399. static float _vq_quantthresh__44u2__p6_0[] = {
  133400. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133401. 12.5, 17.5, 22.5, 27.5,
  133402. };
  133403. static long _vq_quantmap__44u2__p6_0[] = {
  133404. 11, 9, 7, 5, 3, 1, 0, 2,
  133405. 4, 6, 8, 10, 12,
  133406. };
  133407. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133408. _vq_quantthresh__44u2__p6_0,
  133409. _vq_quantmap__44u2__p6_0,
  133410. 13,
  133411. 13
  133412. };
  133413. static static_codebook _44u2__p6_0 = {
  133414. 2, 169,
  133415. _vq_lengthlist__44u2__p6_0,
  133416. 1, -526516224, 1616117760, 4, 0,
  133417. _vq_quantlist__44u2__p6_0,
  133418. NULL,
  133419. &_vq_auxt__44u2__p6_0,
  133420. NULL,
  133421. 0
  133422. };
  133423. static long _vq_quantlist__44u2__p6_1[] = {
  133424. 2,
  133425. 1,
  133426. 3,
  133427. 0,
  133428. 4,
  133429. };
  133430. static long _vq_lengthlist__44u2__p6_1[] = {
  133431. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133432. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133433. };
  133434. static float _vq_quantthresh__44u2__p6_1[] = {
  133435. -1.5, -0.5, 0.5, 1.5,
  133436. };
  133437. static long _vq_quantmap__44u2__p6_1[] = {
  133438. 3, 1, 0, 2, 4,
  133439. };
  133440. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133441. _vq_quantthresh__44u2__p6_1,
  133442. _vq_quantmap__44u2__p6_1,
  133443. 5,
  133444. 5
  133445. };
  133446. static static_codebook _44u2__p6_1 = {
  133447. 2, 25,
  133448. _vq_lengthlist__44u2__p6_1,
  133449. 1, -533725184, 1611661312, 3, 0,
  133450. _vq_quantlist__44u2__p6_1,
  133451. NULL,
  133452. &_vq_auxt__44u2__p6_1,
  133453. NULL,
  133454. 0
  133455. };
  133456. static long _vq_quantlist__44u2__p7_0[] = {
  133457. 4,
  133458. 3,
  133459. 5,
  133460. 2,
  133461. 6,
  133462. 1,
  133463. 7,
  133464. 0,
  133465. 8,
  133466. };
  133467. static long _vq_lengthlist__44u2__p7_0[] = {
  133468. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133469. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133470. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133471. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133472. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133473. 11,
  133474. };
  133475. static float _vq_quantthresh__44u2__p7_0[] = {
  133476. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133477. };
  133478. static long _vq_quantmap__44u2__p7_0[] = {
  133479. 7, 5, 3, 1, 0, 2, 4, 6,
  133480. 8,
  133481. };
  133482. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133483. _vq_quantthresh__44u2__p7_0,
  133484. _vq_quantmap__44u2__p7_0,
  133485. 9,
  133486. 9
  133487. };
  133488. static static_codebook _44u2__p7_0 = {
  133489. 2, 81,
  133490. _vq_lengthlist__44u2__p7_0,
  133491. 1, -516612096, 1626677248, 4, 0,
  133492. _vq_quantlist__44u2__p7_0,
  133493. NULL,
  133494. &_vq_auxt__44u2__p7_0,
  133495. NULL,
  133496. 0
  133497. };
  133498. static long _vq_quantlist__44u2__p7_1[] = {
  133499. 6,
  133500. 5,
  133501. 7,
  133502. 4,
  133503. 8,
  133504. 3,
  133505. 9,
  133506. 2,
  133507. 10,
  133508. 1,
  133509. 11,
  133510. 0,
  133511. 12,
  133512. };
  133513. static long _vq_lengthlist__44u2__p7_1[] = {
  133514. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133515. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133516. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133517. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133518. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133519. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133520. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133521. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133522. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133523. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133524. 14,14,14,17,15,17,17,17,17,
  133525. };
  133526. static float _vq_quantthresh__44u2__p7_1[] = {
  133527. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133528. 32.5, 45.5, 58.5, 71.5,
  133529. };
  133530. static long _vq_quantmap__44u2__p7_1[] = {
  133531. 11, 9, 7, 5, 3, 1, 0, 2,
  133532. 4, 6, 8, 10, 12,
  133533. };
  133534. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133535. _vq_quantthresh__44u2__p7_1,
  133536. _vq_quantmap__44u2__p7_1,
  133537. 13,
  133538. 13
  133539. };
  133540. static static_codebook _44u2__p7_1 = {
  133541. 2, 169,
  133542. _vq_lengthlist__44u2__p7_1,
  133543. 1, -523010048, 1618608128, 4, 0,
  133544. _vq_quantlist__44u2__p7_1,
  133545. NULL,
  133546. &_vq_auxt__44u2__p7_1,
  133547. NULL,
  133548. 0
  133549. };
  133550. static long _vq_quantlist__44u2__p7_2[] = {
  133551. 6,
  133552. 5,
  133553. 7,
  133554. 4,
  133555. 8,
  133556. 3,
  133557. 9,
  133558. 2,
  133559. 10,
  133560. 1,
  133561. 11,
  133562. 0,
  133563. 12,
  133564. };
  133565. static long _vq_lengthlist__44u2__p7_2[] = {
  133566. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133567. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133568. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133569. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133570. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133571. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133572. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133573. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133574. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133575. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133576. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133577. };
  133578. static float _vq_quantthresh__44u2__p7_2[] = {
  133579. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133580. 2.5, 3.5, 4.5, 5.5,
  133581. };
  133582. static long _vq_quantmap__44u2__p7_2[] = {
  133583. 11, 9, 7, 5, 3, 1, 0, 2,
  133584. 4, 6, 8, 10, 12,
  133585. };
  133586. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133587. _vq_quantthresh__44u2__p7_2,
  133588. _vq_quantmap__44u2__p7_2,
  133589. 13,
  133590. 13
  133591. };
  133592. static static_codebook _44u2__p7_2 = {
  133593. 2, 169,
  133594. _vq_lengthlist__44u2__p7_2,
  133595. 1, -531103744, 1611661312, 4, 0,
  133596. _vq_quantlist__44u2__p7_2,
  133597. NULL,
  133598. &_vq_auxt__44u2__p7_2,
  133599. NULL,
  133600. 0
  133601. };
  133602. static long _huff_lengthlist__44u2__short[] = {
  133603. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133604. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133605. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133606. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133607. };
  133608. static static_codebook _huff_book__44u2__short = {
  133609. 2, 64,
  133610. _huff_lengthlist__44u2__short,
  133611. 0, 0, 0, 0, 0,
  133612. NULL,
  133613. NULL,
  133614. NULL,
  133615. NULL,
  133616. 0
  133617. };
  133618. static long _huff_lengthlist__44u3__long[] = {
  133619. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133620. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133621. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133622. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133623. };
  133624. static static_codebook _huff_book__44u3__long = {
  133625. 2, 64,
  133626. _huff_lengthlist__44u3__long,
  133627. 0, 0, 0, 0, 0,
  133628. NULL,
  133629. NULL,
  133630. NULL,
  133631. NULL,
  133632. 0
  133633. };
  133634. static long _vq_quantlist__44u3__p1_0[] = {
  133635. 1,
  133636. 0,
  133637. 2,
  133638. };
  133639. static long _vq_lengthlist__44u3__p1_0[] = {
  133640. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133641. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133642. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133643. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133644. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133645. 13,
  133646. };
  133647. static float _vq_quantthresh__44u3__p1_0[] = {
  133648. -0.5, 0.5,
  133649. };
  133650. static long _vq_quantmap__44u3__p1_0[] = {
  133651. 1, 0, 2,
  133652. };
  133653. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133654. _vq_quantthresh__44u3__p1_0,
  133655. _vq_quantmap__44u3__p1_0,
  133656. 3,
  133657. 3
  133658. };
  133659. static static_codebook _44u3__p1_0 = {
  133660. 4, 81,
  133661. _vq_lengthlist__44u3__p1_0,
  133662. 1, -535822336, 1611661312, 2, 0,
  133663. _vq_quantlist__44u3__p1_0,
  133664. NULL,
  133665. &_vq_auxt__44u3__p1_0,
  133666. NULL,
  133667. 0
  133668. };
  133669. static long _vq_quantlist__44u3__p2_0[] = {
  133670. 1,
  133671. 0,
  133672. 2,
  133673. };
  133674. static long _vq_lengthlist__44u3__p2_0[] = {
  133675. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133676. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133677. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133678. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133679. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133680. 9,
  133681. };
  133682. static float _vq_quantthresh__44u3__p2_0[] = {
  133683. -0.5, 0.5,
  133684. };
  133685. static long _vq_quantmap__44u3__p2_0[] = {
  133686. 1, 0, 2,
  133687. };
  133688. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133689. _vq_quantthresh__44u3__p2_0,
  133690. _vq_quantmap__44u3__p2_0,
  133691. 3,
  133692. 3
  133693. };
  133694. static static_codebook _44u3__p2_0 = {
  133695. 4, 81,
  133696. _vq_lengthlist__44u3__p2_0,
  133697. 1, -535822336, 1611661312, 2, 0,
  133698. _vq_quantlist__44u3__p2_0,
  133699. NULL,
  133700. &_vq_auxt__44u3__p2_0,
  133701. NULL,
  133702. 0
  133703. };
  133704. static long _vq_quantlist__44u3__p3_0[] = {
  133705. 2,
  133706. 1,
  133707. 3,
  133708. 0,
  133709. 4,
  133710. };
  133711. static long _vq_lengthlist__44u3__p3_0[] = {
  133712. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133713. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133714. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133715. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133716. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133717. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133718. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133719. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133720. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133721. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133722. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133723. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133724. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133725. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133726. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133727. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133728. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133729. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133730. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133731. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133732. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133733. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133734. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133735. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133736. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133737. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133738. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133739. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133740. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133741. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133742. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133743. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133744. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133745. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133746. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133747. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133748. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133749. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133750. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133751. 0,
  133752. };
  133753. static float _vq_quantthresh__44u3__p3_0[] = {
  133754. -1.5, -0.5, 0.5, 1.5,
  133755. };
  133756. static long _vq_quantmap__44u3__p3_0[] = {
  133757. 3, 1, 0, 2, 4,
  133758. };
  133759. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133760. _vq_quantthresh__44u3__p3_0,
  133761. _vq_quantmap__44u3__p3_0,
  133762. 5,
  133763. 5
  133764. };
  133765. static static_codebook _44u3__p3_0 = {
  133766. 4, 625,
  133767. _vq_lengthlist__44u3__p3_0,
  133768. 1, -533725184, 1611661312, 3, 0,
  133769. _vq_quantlist__44u3__p3_0,
  133770. NULL,
  133771. &_vq_auxt__44u3__p3_0,
  133772. NULL,
  133773. 0
  133774. };
  133775. static long _vq_quantlist__44u3__p4_0[] = {
  133776. 2,
  133777. 1,
  133778. 3,
  133779. 0,
  133780. 4,
  133781. };
  133782. static long _vq_lengthlist__44u3__p4_0[] = {
  133783. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133784. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133785. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133786. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133787. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133788. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133789. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133790. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133791. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133792. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133793. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133794. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133795. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133796. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133797. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133798. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133799. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133800. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133801. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133802. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133803. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133804. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133805. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133806. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133807. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133808. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133809. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133810. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133811. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133812. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133813. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133814. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133815. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133816. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133817. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133818. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133819. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133820. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133821. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133822. 13,
  133823. };
  133824. static float _vq_quantthresh__44u3__p4_0[] = {
  133825. -1.5, -0.5, 0.5, 1.5,
  133826. };
  133827. static long _vq_quantmap__44u3__p4_0[] = {
  133828. 3, 1, 0, 2, 4,
  133829. };
  133830. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133831. _vq_quantthresh__44u3__p4_0,
  133832. _vq_quantmap__44u3__p4_0,
  133833. 5,
  133834. 5
  133835. };
  133836. static static_codebook _44u3__p4_0 = {
  133837. 4, 625,
  133838. _vq_lengthlist__44u3__p4_0,
  133839. 1, -533725184, 1611661312, 3, 0,
  133840. _vq_quantlist__44u3__p4_0,
  133841. NULL,
  133842. &_vq_auxt__44u3__p4_0,
  133843. NULL,
  133844. 0
  133845. };
  133846. static long _vq_quantlist__44u3__p5_0[] = {
  133847. 4,
  133848. 3,
  133849. 5,
  133850. 2,
  133851. 6,
  133852. 1,
  133853. 7,
  133854. 0,
  133855. 8,
  133856. };
  133857. static long _vq_lengthlist__44u3__p5_0[] = {
  133858. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133859. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133860. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133861. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133862. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133863. 12,
  133864. };
  133865. static float _vq_quantthresh__44u3__p5_0[] = {
  133866. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133867. };
  133868. static long _vq_quantmap__44u3__p5_0[] = {
  133869. 7, 5, 3, 1, 0, 2, 4, 6,
  133870. 8,
  133871. };
  133872. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133873. _vq_quantthresh__44u3__p5_0,
  133874. _vq_quantmap__44u3__p5_0,
  133875. 9,
  133876. 9
  133877. };
  133878. static static_codebook _44u3__p5_0 = {
  133879. 2, 81,
  133880. _vq_lengthlist__44u3__p5_0,
  133881. 1, -531628032, 1611661312, 4, 0,
  133882. _vq_quantlist__44u3__p5_0,
  133883. NULL,
  133884. &_vq_auxt__44u3__p5_0,
  133885. NULL,
  133886. 0
  133887. };
  133888. static long _vq_quantlist__44u3__p6_0[] = {
  133889. 6,
  133890. 5,
  133891. 7,
  133892. 4,
  133893. 8,
  133894. 3,
  133895. 9,
  133896. 2,
  133897. 10,
  133898. 1,
  133899. 11,
  133900. 0,
  133901. 12,
  133902. };
  133903. static long _vq_lengthlist__44u3__p6_0[] = {
  133904. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133905. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133906. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133907. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133908. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133909. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133910. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133911. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133912. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133913. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133914. 15,16,16,16,17,18,16,20,18,
  133915. };
  133916. static float _vq_quantthresh__44u3__p6_0[] = {
  133917. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133918. 12.5, 17.5, 22.5, 27.5,
  133919. };
  133920. static long _vq_quantmap__44u3__p6_0[] = {
  133921. 11, 9, 7, 5, 3, 1, 0, 2,
  133922. 4, 6, 8, 10, 12,
  133923. };
  133924. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133925. _vq_quantthresh__44u3__p6_0,
  133926. _vq_quantmap__44u3__p6_0,
  133927. 13,
  133928. 13
  133929. };
  133930. static static_codebook _44u3__p6_0 = {
  133931. 2, 169,
  133932. _vq_lengthlist__44u3__p6_0,
  133933. 1, -526516224, 1616117760, 4, 0,
  133934. _vq_quantlist__44u3__p6_0,
  133935. NULL,
  133936. &_vq_auxt__44u3__p6_0,
  133937. NULL,
  133938. 0
  133939. };
  133940. static long _vq_quantlist__44u3__p6_1[] = {
  133941. 2,
  133942. 1,
  133943. 3,
  133944. 0,
  133945. 4,
  133946. };
  133947. static long _vq_lengthlist__44u3__p6_1[] = {
  133948. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133949. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133950. };
  133951. static float _vq_quantthresh__44u3__p6_1[] = {
  133952. -1.5, -0.5, 0.5, 1.5,
  133953. };
  133954. static long _vq_quantmap__44u3__p6_1[] = {
  133955. 3, 1, 0, 2, 4,
  133956. };
  133957. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133958. _vq_quantthresh__44u3__p6_1,
  133959. _vq_quantmap__44u3__p6_1,
  133960. 5,
  133961. 5
  133962. };
  133963. static static_codebook _44u3__p6_1 = {
  133964. 2, 25,
  133965. _vq_lengthlist__44u3__p6_1,
  133966. 1, -533725184, 1611661312, 3, 0,
  133967. _vq_quantlist__44u3__p6_1,
  133968. NULL,
  133969. &_vq_auxt__44u3__p6_1,
  133970. NULL,
  133971. 0
  133972. };
  133973. static long _vq_quantlist__44u3__p7_0[] = {
  133974. 4,
  133975. 3,
  133976. 5,
  133977. 2,
  133978. 6,
  133979. 1,
  133980. 7,
  133981. 0,
  133982. 8,
  133983. };
  133984. static long _vq_lengthlist__44u3__p7_0[] = {
  133985. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133986. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133987. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133988. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133989. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133990. 9,
  133991. };
  133992. static float _vq_quantthresh__44u3__p7_0[] = {
  133993. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133994. };
  133995. static long _vq_quantmap__44u3__p7_0[] = {
  133996. 7, 5, 3, 1, 0, 2, 4, 6,
  133997. 8,
  133998. };
  133999. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  134000. _vq_quantthresh__44u3__p7_0,
  134001. _vq_quantmap__44u3__p7_0,
  134002. 9,
  134003. 9
  134004. };
  134005. static static_codebook _44u3__p7_0 = {
  134006. 2, 81,
  134007. _vq_lengthlist__44u3__p7_0,
  134008. 1, -515907584, 1627381760, 4, 0,
  134009. _vq_quantlist__44u3__p7_0,
  134010. NULL,
  134011. &_vq_auxt__44u3__p7_0,
  134012. NULL,
  134013. 0
  134014. };
  134015. static long _vq_quantlist__44u3__p7_1[] = {
  134016. 7,
  134017. 6,
  134018. 8,
  134019. 5,
  134020. 9,
  134021. 4,
  134022. 10,
  134023. 3,
  134024. 11,
  134025. 2,
  134026. 12,
  134027. 1,
  134028. 13,
  134029. 0,
  134030. 14,
  134031. };
  134032. static long _vq_lengthlist__44u3__p7_1[] = {
  134033. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  134034. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  134035. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  134036. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  134037. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  134038. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  134039. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  134040. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  134041. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  134042. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  134043. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  134044. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  134045. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  134046. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  134047. 17,
  134048. };
  134049. static float _vq_quantthresh__44u3__p7_1[] = {
  134050. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134051. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134052. };
  134053. static long _vq_quantmap__44u3__p7_1[] = {
  134054. 13, 11, 9, 7, 5, 3, 1, 0,
  134055. 2, 4, 6, 8, 10, 12, 14,
  134056. };
  134057. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  134058. _vq_quantthresh__44u3__p7_1,
  134059. _vq_quantmap__44u3__p7_1,
  134060. 15,
  134061. 15
  134062. };
  134063. static static_codebook _44u3__p7_1 = {
  134064. 2, 225,
  134065. _vq_lengthlist__44u3__p7_1,
  134066. 1, -522338304, 1620115456, 4, 0,
  134067. _vq_quantlist__44u3__p7_1,
  134068. NULL,
  134069. &_vq_auxt__44u3__p7_1,
  134070. NULL,
  134071. 0
  134072. };
  134073. static long _vq_quantlist__44u3__p7_2[] = {
  134074. 8,
  134075. 7,
  134076. 9,
  134077. 6,
  134078. 10,
  134079. 5,
  134080. 11,
  134081. 4,
  134082. 12,
  134083. 3,
  134084. 13,
  134085. 2,
  134086. 14,
  134087. 1,
  134088. 15,
  134089. 0,
  134090. 16,
  134091. };
  134092. static long _vq_lengthlist__44u3__p7_2[] = {
  134093. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134094. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134095. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  134096. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134097. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134098. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134099. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134100. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134101. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134102. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134103. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134104. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134105. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134106. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134107. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134108. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134109. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134110. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134111. 11,
  134112. };
  134113. static float _vq_quantthresh__44u3__p7_2[] = {
  134114. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134115. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134116. };
  134117. static long _vq_quantmap__44u3__p7_2[] = {
  134118. 15, 13, 11, 9, 7, 5, 3, 1,
  134119. 0, 2, 4, 6, 8, 10, 12, 14,
  134120. 16,
  134121. };
  134122. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134123. _vq_quantthresh__44u3__p7_2,
  134124. _vq_quantmap__44u3__p7_2,
  134125. 17,
  134126. 17
  134127. };
  134128. static static_codebook _44u3__p7_2 = {
  134129. 2, 289,
  134130. _vq_lengthlist__44u3__p7_2,
  134131. 1, -529530880, 1611661312, 5, 0,
  134132. _vq_quantlist__44u3__p7_2,
  134133. NULL,
  134134. &_vq_auxt__44u3__p7_2,
  134135. NULL,
  134136. 0
  134137. };
  134138. static long _huff_lengthlist__44u3__short[] = {
  134139. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134140. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134141. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134142. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134143. };
  134144. static static_codebook _huff_book__44u3__short = {
  134145. 2, 64,
  134146. _huff_lengthlist__44u3__short,
  134147. 0, 0, 0, 0, 0,
  134148. NULL,
  134149. NULL,
  134150. NULL,
  134151. NULL,
  134152. 0
  134153. };
  134154. static long _huff_lengthlist__44u4__long[] = {
  134155. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134156. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134157. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134158. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134159. };
  134160. static static_codebook _huff_book__44u4__long = {
  134161. 2, 64,
  134162. _huff_lengthlist__44u4__long,
  134163. 0, 0, 0, 0, 0,
  134164. NULL,
  134165. NULL,
  134166. NULL,
  134167. NULL,
  134168. 0
  134169. };
  134170. static long _vq_quantlist__44u4__p1_0[] = {
  134171. 1,
  134172. 0,
  134173. 2,
  134174. };
  134175. static long _vq_lengthlist__44u4__p1_0[] = {
  134176. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134177. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134178. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134179. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134180. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134181. 13,
  134182. };
  134183. static float _vq_quantthresh__44u4__p1_0[] = {
  134184. -0.5, 0.5,
  134185. };
  134186. static long _vq_quantmap__44u4__p1_0[] = {
  134187. 1, 0, 2,
  134188. };
  134189. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134190. _vq_quantthresh__44u4__p1_0,
  134191. _vq_quantmap__44u4__p1_0,
  134192. 3,
  134193. 3
  134194. };
  134195. static static_codebook _44u4__p1_0 = {
  134196. 4, 81,
  134197. _vq_lengthlist__44u4__p1_0,
  134198. 1, -535822336, 1611661312, 2, 0,
  134199. _vq_quantlist__44u4__p1_0,
  134200. NULL,
  134201. &_vq_auxt__44u4__p1_0,
  134202. NULL,
  134203. 0
  134204. };
  134205. static long _vq_quantlist__44u4__p2_0[] = {
  134206. 1,
  134207. 0,
  134208. 2,
  134209. };
  134210. static long _vq_lengthlist__44u4__p2_0[] = {
  134211. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134212. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134213. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134214. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134215. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134216. 9,
  134217. };
  134218. static float _vq_quantthresh__44u4__p2_0[] = {
  134219. -0.5, 0.5,
  134220. };
  134221. static long _vq_quantmap__44u4__p2_0[] = {
  134222. 1, 0, 2,
  134223. };
  134224. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134225. _vq_quantthresh__44u4__p2_0,
  134226. _vq_quantmap__44u4__p2_0,
  134227. 3,
  134228. 3
  134229. };
  134230. static static_codebook _44u4__p2_0 = {
  134231. 4, 81,
  134232. _vq_lengthlist__44u4__p2_0,
  134233. 1, -535822336, 1611661312, 2, 0,
  134234. _vq_quantlist__44u4__p2_0,
  134235. NULL,
  134236. &_vq_auxt__44u4__p2_0,
  134237. NULL,
  134238. 0
  134239. };
  134240. static long _vq_quantlist__44u4__p3_0[] = {
  134241. 2,
  134242. 1,
  134243. 3,
  134244. 0,
  134245. 4,
  134246. };
  134247. static long _vq_lengthlist__44u4__p3_0[] = {
  134248. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134249. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134250. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134251. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134252. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134253. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134254. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134255. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134256. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134257. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134258. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134259. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134260. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134261. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134262. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134263. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134264. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134265. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134266. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134267. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134268. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134269. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134270. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134271. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134272. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134273. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134274. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134275. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134276. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134277. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134278. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134279. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134280. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134281. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134282. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134283. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134284. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134285. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134286. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134287. 0,
  134288. };
  134289. static float _vq_quantthresh__44u4__p3_0[] = {
  134290. -1.5, -0.5, 0.5, 1.5,
  134291. };
  134292. static long _vq_quantmap__44u4__p3_0[] = {
  134293. 3, 1, 0, 2, 4,
  134294. };
  134295. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134296. _vq_quantthresh__44u4__p3_0,
  134297. _vq_quantmap__44u4__p3_0,
  134298. 5,
  134299. 5
  134300. };
  134301. static static_codebook _44u4__p3_0 = {
  134302. 4, 625,
  134303. _vq_lengthlist__44u4__p3_0,
  134304. 1, -533725184, 1611661312, 3, 0,
  134305. _vq_quantlist__44u4__p3_0,
  134306. NULL,
  134307. &_vq_auxt__44u4__p3_0,
  134308. NULL,
  134309. 0
  134310. };
  134311. static long _vq_quantlist__44u4__p4_0[] = {
  134312. 2,
  134313. 1,
  134314. 3,
  134315. 0,
  134316. 4,
  134317. };
  134318. static long _vq_lengthlist__44u4__p4_0[] = {
  134319. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134320. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134321. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134322. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134323. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134324. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134325. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134326. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134327. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134328. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134329. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134330. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134331. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134332. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134333. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134334. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134335. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134336. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134337. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134338. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134339. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134340. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134341. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134342. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134343. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134344. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134345. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134346. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134347. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134348. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134349. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134350. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134351. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134352. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134353. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134354. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134355. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134356. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134357. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134358. 13,
  134359. };
  134360. static float _vq_quantthresh__44u4__p4_0[] = {
  134361. -1.5, -0.5, 0.5, 1.5,
  134362. };
  134363. static long _vq_quantmap__44u4__p4_0[] = {
  134364. 3, 1, 0, 2, 4,
  134365. };
  134366. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134367. _vq_quantthresh__44u4__p4_0,
  134368. _vq_quantmap__44u4__p4_0,
  134369. 5,
  134370. 5
  134371. };
  134372. static static_codebook _44u4__p4_0 = {
  134373. 4, 625,
  134374. _vq_lengthlist__44u4__p4_0,
  134375. 1, -533725184, 1611661312, 3, 0,
  134376. _vq_quantlist__44u4__p4_0,
  134377. NULL,
  134378. &_vq_auxt__44u4__p4_0,
  134379. NULL,
  134380. 0
  134381. };
  134382. static long _vq_quantlist__44u4__p5_0[] = {
  134383. 4,
  134384. 3,
  134385. 5,
  134386. 2,
  134387. 6,
  134388. 1,
  134389. 7,
  134390. 0,
  134391. 8,
  134392. };
  134393. static long _vq_lengthlist__44u4__p5_0[] = {
  134394. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134395. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134396. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134397. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134398. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134399. 12,
  134400. };
  134401. static float _vq_quantthresh__44u4__p5_0[] = {
  134402. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134403. };
  134404. static long _vq_quantmap__44u4__p5_0[] = {
  134405. 7, 5, 3, 1, 0, 2, 4, 6,
  134406. 8,
  134407. };
  134408. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134409. _vq_quantthresh__44u4__p5_0,
  134410. _vq_quantmap__44u4__p5_0,
  134411. 9,
  134412. 9
  134413. };
  134414. static static_codebook _44u4__p5_0 = {
  134415. 2, 81,
  134416. _vq_lengthlist__44u4__p5_0,
  134417. 1, -531628032, 1611661312, 4, 0,
  134418. _vq_quantlist__44u4__p5_0,
  134419. NULL,
  134420. &_vq_auxt__44u4__p5_0,
  134421. NULL,
  134422. 0
  134423. };
  134424. static long _vq_quantlist__44u4__p6_0[] = {
  134425. 6,
  134426. 5,
  134427. 7,
  134428. 4,
  134429. 8,
  134430. 3,
  134431. 9,
  134432. 2,
  134433. 10,
  134434. 1,
  134435. 11,
  134436. 0,
  134437. 12,
  134438. };
  134439. static long _vq_lengthlist__44u4__p6_0[] = {
  134440. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134441. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134442. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134443. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134444. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134445. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134446. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134447. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134448. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134449. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134450. 16,16,16,17,17,18,17,20,21,
  134451. };
  134452. static float _vq_quantthresh__44u4__p6_0[] = {
  134453. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134454. 12.5, 17.5, 22.5, 27.5,
  134455. };
  134456. static long _vq_quantmap__44u4__p6_0[] = {
  134457. 11, 9, 7, 5, 3, 1, 0, 2,
  134458. 4, 6, 8, 10, 12,
  134459. };
  134460. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134461. _vq_quantthresh__44u4__p6_0,
  134462. _vq_quantmap__44u4__p6_0,
  134463. 13,
  134464. 13
  134465. };
  134466. static static_codebook _44u4__p6_0 = {
  134467. 2, 169,
  134468. _vq_lengthlist__44u4__p6_0,
  134469. 1, -526516224, 1616117760, 4, 0,
  134470. _vq_quantlist__44u4__p6_0,
  134471. NULL,
  134472. &_vq_auxt__44u4__p6_0,
  134473. NULL,
  134474. 0
  134475. };
  134476. static long _vq_quantlist__44u4__p6_1[] = {
  134477. 2,
  134478. 1,
  134479. 3,
  134480. 0,
  134481. 4,
  134482. };
  134483. static long _vq_lengthlist__44u4__p6_1[] = {
  134484. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134485. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134486. };
  134487. static float _vq_quantthresh__44u4__p6_1[] = {
  134488. -1.5, -0.5, 0.5, 1.5,
  134489. };
  134490. static long _vq_quantmap__44u4__p6_1[] = {
  134491. 3, 1, 0, 2, 4,
  134492. };
  134493. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134494. _vq_quantthresh__44u4__p6_1,
  134495. _vq_quantmap__44u4__p6_1,
  134496. 5,
  134497. 5
  134498. };
  134499. static static_codebook _44u4__p6_1 = {
  134500. 2, 25,
  134501. _vq_lengthlist__44u4__p6_1,
  134502. 1, -533725184, 1611661312, 3, 0,
  134503. _vq_quantlist__44u4__p6_1,
  134504. NULL,
  134505. &_vq_auxt__44u4__p6_1,
  134506. NULL,
  134507. 0
  134508. };
  134509. static long _vq_quantlist__44u4__p7_0[] = {
  134510. 6,
  134511. 5,
  134512. 7,
  134513. 4,
  134514. 8,
  134515. 3,
  134516. 9,
  134517. 2,
  134518. 10,
  134519. 1,
  134520. 11,
  134521. 0,
  134522. 12,
  134523. };
  134524. static long _vq_lengthlist__44u4__p7_0[] = {
  134525. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134526. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134527. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134528. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134529. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134530. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134531. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134532. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134533. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134534. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134535. 11,11,11,11,11,11,11,11,11,
  134536. };
  134537. static float _vq_quantthresh__44u4__p7_0[] = {
  134538. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134539. 637.5, 892.5, 1147.5, 1402.5,
  134540. };
  134541. static long _vq_quantmap__44u4__p7_0[] = {
  134542. 11, 9, 7, 5, 3, 1, 0, 2,
  134543. 4, 6, 8, 10, 12,
  134544. };
  134545. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134546. _vq_quantthresh__44u4__p7_0,
  134547. _vq_quantmap__44u4__p7_0,
  134548. 13,
  134549. 13
  134550. };
  134551. static static_codebook _44u4__p7_0 = {
  134552. 2, 169,
  134553. _vq_lengthlist__44u4__p7_0,
  134554. 1, -514332672, 1627381760, 4, 0,
  134555. _vq_quantlist__44u4__p7_0,
  134556. NULL,
  134557. &_vq_auxt__44u4__p7_0,
  134558. NULL,
  134559. 0
  134560. };
  134561. static long _vq_quantlist__44u4__p7_1[] = {
  134562. 7,
  134563. 6,
  134564. 8,
  134565. 5,
  134566. 9,
  134567. 4,
  134568. 10,
  134569. 3,
  134570. 11,
  134571. 2,
  134572. 12,
  134573. 1,
  134574. 13,
  134575. 0,
  134576. 14,
  134577. };
  134578. static long _vq_lengthlist__44u4__p7_1[] = {
  134579. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134580. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134581. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134582. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134583. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134584. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134585. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134586. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134587. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134588. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134589. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134590. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134591. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134592. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134593. 16,
  134594. };
  134595. static float _vq_quantthresh__44u4__p7_1[] = {
  134596. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134597. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134598. };
  134599. static long _vq_quantmap__44u4__p7_1[] = {
  134600. 13, 11, 9, 7, 5, 3, 1, 0,
  134601. 2, 4, 6, 8, 10, 12, 14,
  134602. };
  134603. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134604. _vq_quantthresh__44u4__p7_1,
  134605. _vq_quantmap__44u4__p7_1,
  134606. 15,
  134607. 15
  134608. };
  134609. static static_codebook _44u4__p7_1 = {
  134610. 2, 225,
  134611. _vq_lengthlist__44u4__p7_1,
  134612. 1, -522338304, 1620115456, 4, 0,
  134613. _vq_quantlist__44u4__p7_1,
  134614. NULL,
  134615. &_vq_auxt__44u4__p7_1,
  134616. NULL,
  134617. 0
  134618. };
  134619. static long _vq_quantlist__44u4__p7_2[] = {
  134620. 8,
  134621. 7,
  134622. 9,
  134623. 6,
  134624. 10,
  134625. 5,
  134626. 11,
  134627. 4,
  134628. 12,
  134629. 3,
  134630. 13,
  134631. 2,
  134632. 14,
  134633. 1,
  134634. 15,
  134635. 0,
  134636. 16,
  134637. };
  134638. static long _vq_lengthlist__44u4__p7_2[] = {
  134639. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134640. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134641. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134642. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134643. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134644. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134645. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134646. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134647. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134648. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134649. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134650. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134651. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134652. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134653. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134654. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134655. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134656. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134657. 10,
  134658. };
  134659. static float _vq_quantthresh__44u4__p7_2[] = {
  134660. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134661. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134662. };
  134663. static long _vq_quantmap__44u4__p7_2[] = {
  134664. 15, 13, 11, 9, 7, 5, 3, 1,
  134665. 0, 2, 4, 6, 8, 10, 12, 14,
  134666. 16,
  134667. };
  134668. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134669. _vq_quantthresh__44u4__p7_2,
  134670. _vq_quantmap__44u4__p7_2,
  134671. 17,
  134672. 17
  134673. };
  134674. static static_codebook _44u4__p7_2 = {
  134675. 2, 289,
  134676. _vq_lengthlist__44u4__p7_2,
  134677. 1, -529530880, 1611661312, 5, 0,
  134678. _vq_quantlist__44u4__p7_2,
  134679. NULL,
  134680. &_vq_auxt__44u4__p7_2,
  134681. NULL,
  134682. 0
  134683. };
  134684. static long _huff_lengthlist__44u4__short[] = {
  134685. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134686. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134687. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134688. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134689. };
  134690. static static_codebook _huff_book__44u4__short = {
  134691. 2, 64,
  134692. _huff_lengthlist__44u4__short,
  134693. 0, 0, 0, 0, 0,
  134694. NULL,
  134695. NULL,
  134696. NULL,
  134697. NULL,
  134698. 0
  134699. };
  134700. static long _huff_lengthlist__44u5__long[] = {
  134701. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134702. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134703. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134704. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134705. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134706. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134707. 14, 8, 7, 8,
  134708. };
  134709. static static_codebook _huff_book__44u5__long = {
  134710. 2, 100,
  134711. _huff_lengthlist__44u5__long,
  134712. 0, 0, 0, 0, 0,
  134713. NULL,
  134714. NULL,
  134715. NULL,
  134716. NULL,
  134717. 0
  134718. };
  134719. static long _vq_quantlist__44u5__p1_0[] = {
  134720. 1,
  134721. 0,
  134722. 2,
  134723. };
  134724. static long _vq_lengthlist__44u5__p1_0[] = {
  134725. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134726. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134727. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134728. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134729. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134730. 12,
  134731. };
  134732. static float _vq_quantthresh__44u5__p1_0[] = {
  134733. -0.5, 0.5,
  134734. };
  134735. static long _vq_quantmap__44u5__p1_0[] = {
  134736. 1, 0, 2,
  134737. };
  134738. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134739. _vq_quantthresh__44u5__p1_0,
  134740. _vq_quantmap__44u5__p1_0,
  134741. 3,
  134742. 3
  134743. };
  134744. static static_codebook _44u5__p1_0 = {
  134745. 4, 81,
  134746. _vq_lengthlist__44u5__p1_0,
  134747. 1, -535822336, 1611661312, 2, 0,
  134748. _vq_quantlist__44u5__p1_0,
  134749. NULL,
  134750. &_vq_auxt__44u5__p1_0,
  134751. NULL,
  134752. 0
  134753. };
  134754. static long _vq_quantlist__44u5__p2_0[] = {
  134755. 1,
  134756. 0,
  134757. 2,
  134758. };
  134759. static long _vq_lengthlist__44u5__p2_0[] = {
  134760. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134761. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134762. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134763. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134764. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134765. 9,
  134766. };
  134767. static float _vq_quantthresh__44u5__p2_0[] = {
  134768. -0.5, 0.5,
  134769. };
  134770. static long _vq_quantmap__44u5__p2_0[] = {
  134771. 1, 0, 2,
  134772. };
  134773. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134774. _vq_quantthresh__44u5__p2_0,
  134775. _vq_quantmap__44u5__p2_0,
  134776. 3,
  134777. 3
  134778. };
  134779. static static_codebook _44u5__p2_0 = {
  134780. 4, 81,
  134781. _vq_lengthlist__44u5__p2_0,
  134782. 1, -535822336, 1611661312, 2, 0,
  134783. _vq_quantlist__44u5__p2_0,
  134784. NULL,
  134785. &_vq_auxt__44u5__p2_0,
  134786. NULL,
  134787. 0
  134788. };
  134789. static long _vq_quantlist__44u5__p3_0[] = {
  134790. 2,
  134791. 1,
  134792. 3,
  134793. 0,
  134794. 4,
  134795. };
  134796. static long _vq_lengthlist__44u5__p3_0[] = {
  134797. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134798. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134799. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134800. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134801. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134802. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134803. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134804. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134805. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134806. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134807. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134808. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134809. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134810. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134811. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134812. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134813. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134814. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134815. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134816. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134817. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134818. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134819. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134820. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134821. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134822. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134823. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134824. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134825. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134826. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134827. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134828. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134829. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134830. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134831. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134832. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134833. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134834. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134835. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134836. 0,
  134837. };
  134838. static float _vq_quantthresh__44u5__p3_0[] = {
  134839. -1.5, -0.5, 0.5, 1.5,
  134840. };
  134841. static long _vq_quantmap__44u5__p3_0[] = {
  134842. 3, 1, 0, 2, 4,
  134843. };
  134844. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134845. _vq_quantthresh__44u5__p3_0,
  134846. _vq_quantmap__44u5__p3_0,
  134847. 5,
  134848. 5
  134849. };
  134850. static static_codebook _44u5__p3_0 = {
  134851. 4, 625,
  134852. _vq_lengthlist__44u5__p3_0,
  134853. 1, -533725184, 1611661312, 3, 0,
  134854. _vq_quantlist__44u5__p3_0,
  134855. NULL,
  134856. &_vq_auxt__44u5__p3_0,
  134857. NULL,
  134858. 0
  134859. };
  134860. static long _vq_quantlist__44u5__p4_0[] = {
  134861. 2,
  134862. 1,
  134863. 3,
  134864. 0,
  134865. 4,
  134866. };
  134867. static long _vq_lengthlist__44u5__p4_0[] = {
  134868. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134869. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134870. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134871. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134872. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134873. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134874. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134875. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134876. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134877. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134878. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134879. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134880. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134881. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134882. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134883. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134884. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134885. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134886. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134887. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134888. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134889. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134890. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134891. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134892. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134893. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134894. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134895. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134896. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134897. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134898. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134899. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134900. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134901. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134902. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134903. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134904. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134905. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134906. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134907. 12,
  134908. };
  134909. static float _vq_quantthresh__44u5__p4_0[] = {
  134910. -1.5, -0.5, 0.5, 1.5,
  134911. };
  134912. static long _vq_quantmap__44u5__p4_0[] = {
  134913. 3, 1, 0, 2, 4,
  134914. };
  134915. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134916. _vq_quantthresh__44u5__p4_0,
  134917. _vq_quantmap__44u5__p4_0,
  134918. 5,
  134919. 5
  134920. };
  134921. static static_codebook _44u5__p4_0 = {
  134922. 4, 625,
  134923. _vq_lengthlist__44u5__p4_0,
  134924. 1, -533725184, 1611661312, 3, 0,
  134925. _vq_quantlist__44u5__p4_0,
  134926. NULL,
  134927. &_vq_auxt__44u5__p4_0,
  134928. NULL,
  134929. 0
  134930. };
  134931. static long _vq_quantlist__44u5__p5_0[] = {
  134932. 4,
  134933. 3,
  134934. 5,
  134935. 2,
  134936. 6,
  134937. 1,
  134938. 7,
  134939. 0,
  134940. 8,
  134941. };
  134942. static long _vq_lengthlist__44u5__p5_0[] = {
  134943. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134944. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134945. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134946. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134947. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134948. 14,
  134949. };
  134950. static float _vq_quantthresh__44u5__p5_0[] = {
  134951. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134952. };
  134953. static long _vq_quantmap__44u5__p5_0[] = {
  134954. 7, 5, 3, 1, 0, 2, 4, 6,
  134955. 8,
  134956. };
  134957. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134958. _vq_quantthresh__44u5__p5_0,
  134959. _vq_quantmap__44u5__p5_0,
  134960. 9,
  134961. 9
  134962. };
  134963. static static_codebook _44u5__p5_0 = {
  134964. 2, 81,
  134965. _vq_lengthlist__44u5__p5_0,
  134966. 1, -531628032, 1611661312, 4, 0,
  134967. _vq_quantlist__44u5__p5_0,
  134968. NULL,
  134969. &_vq_auxt__44u5__p5_0,
  134970. NULL,
  134971. 0
  134972. };
  134973. static long _vq_quantlist__44u5__p6_0[] = {
  134974. 4,
  134975. 3,
  134976. 5,
  134977. 2,
  134978. 6,
  134979. 1,
  134980. 7,
  134981. 0,
  134982. 8,
  134983. };
  134984. static long _vq_lengthlist__44u5__p6_0[] = {
  134985. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134986. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134987. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134988. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134989. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134990. 11,
  134991. };
  134992. static float _vq_quantthresh__44u5__p6_0[] = {
  134993. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134994. };
  134995. static long _vq_quantmap__44u5__p6_0[] = {
  134996. 7, 5, 3, 1, 0, 2, 4, 6,
  134997. 8,
  134998. };
  134999. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  135000. _vq_quantthresh__44u5__p6_0,
  135001. _vq_quantmap__44u5__p6_0,
  135002. 9,
  135003. 9
  135004. };
  135005. static static_codebook _44u5__p6_0 = {
  135006. 2, 81,
  135007. _vq_lengthlist__44u5__p6_0,
  135008. 1, -531628032, 1611661312, 4, 0,
  135009. _vq_quantlist__44u5__p6_0,
  135010. NULL,
  135011. &_vq_auxt__44u5__p6_0,
  135012. NULL,
  135013. 0
  135014. };
  135015. static long _vq_quantlist__44u5__p7_0[] = {
  135016. 1,
  135017. 0,
  135018. 2,
  135019. };
  135020. static long _vq_lengthlist__44u5__p7_0[] = {
  135021. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  135022. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  135023. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  135024. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  135025. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  135026. 12,
  135027. };
  135028. static float _vq_quantthresh__44u5__p7_0[] = {
  135029. -5.5, 5.5,
  135030. };
  135031. static long _vq_quantmap__44u5__p7_0[] = {
  135032. 1, 0, 2,
  135033. };
  135034. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  135035. _vq_quantthresh__44u5__p7_0,
  135036. _vq_quantmap__44u5__p7_0,
  135037. 3,
  135038. 3
  135039. };
  135040. static static_codebook _44u5__p7_0 = {
  135041. 4, 81,
  135042. _vq_lengthlist__44u5__p7_0,
  135043. 1, -529137664, 1618345984, 2, 0,
  135044. _vq_quantlist__44u5__p7_0,
  135045. NULL,
  135046. &_vq_auxt__44u5__p7_0,
  135047. NULL,
  135048. 0
  135049. };
  135050. static long _vq_quantlist__44u5__p7_1[] = {
  135051. 5,
  135052. 4,
  135053. 6,
  135054. 3,
  135055. 7,
  135056. 2,
  135057. 8,
  135058. 1,
  135059. 9,
  135060. 0,
  135061. 10,
  135062. };
  135063. static long _vq_lengthlist__44u5__p7_1[] = {
  135064. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  135065. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  135066. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  135067. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  135068. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  135069. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135070. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  135071. 9, 9, 9, 9, 9,10,10,10,10,
  135072. };
  135073. static float _vq_quantthresh__44u5__p7_1[] = {
  135074. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135075. 3.5, 4.5,
  135076. };
  135077. static long _vq_quantmap__44u5__p7_1[] = {
  135078. 9, 7, 5, 3, 1, 0, 2, 4,
  135079. 6, 8, 10,
  135080. };
  135081. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  135082. _vq_quantthresh__44u5__p7_1,
  135083. _vq_quantmap__44u5__p7_1,
  135084. 11,
  135085. 11
  135086. };
  135087. static static_codebook _44u5__p7_1 = {
  135088. 2, 121,
  135089. _vq_lengthlist__44u5__p7_1,
  135090. 1, -531365888, 1611661312, 4, 0,
  135091. _vq_quantlist__44u5__p7_1,
  135092. NULL,
  135093. &_vq_auxt__44u5__p7_1,
  135094. NULL,
  135095. 0
  135096. };
  135097. static long _vq_quantlist__44u5__p8_0[] = {
  135098. 5,
  135099. 4,
  135100. 6,
  135101. 3,
  135102. 7,
  135103. 2,
  135104. 8,
  135105. 1,
  135106. 9,
  135107. 0,
  135108. 10,
  135109. };
  135110. static long _vq_lengthlist__44u5__p8_0[] = {
  135111. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135112. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135113. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135114. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135115. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135116. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135117. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135118. 12,13,13,14,14,14,14,15,15,
  135119. };
  135120. static float _vq_quantthresh__44u5__p8_0[] = {
  135121. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135122. 38.5, 49.5,
  135123. };
  135124. static long _vq_quantmap__44u5__p8_0[] = {
  135125. 9, 7, 5, 3, 1, 0, 2, 4,
  135126. 6, 8, 10,
  135127. };
  135128. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135129. _vq_quantthresh__44u5__p8_0,
  135130. _vq_quantmap__44u5__p8_0,
  135131. 11,
  135132. 11
  135133. };
  135134. static static_codebook _44u5__p8_0 = {
  135135. 2, 121,
  135136. _vq_lengthlist__44u5__p8_0,
  135137. 1, -524582912, 1618345984, 4, 0,
  135138. _vq_quantlist__44u5__p8_0,
  135139. NULL,
  135140. &_vq_auxt__44u5__p8_0,
  135141. NULL,
  135142. 0
  135143. };
  135144. static long _vq_quantlist__44u5__p8_1[] = {
  135145. 5,
  135146. 4,
  135147. 6,
  135148. 3,
  135149. 7,
  135150. 2,
  135151. 8,
  135152. 1,
  135153. 9,
  135154. 0,
  135155. 10,
  135156. };
  135157. static long _vq_lengthlist__44u5__p8_1[] = {
  135158. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135159. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135160. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135161. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135162. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135163. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135164. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135165. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135166. };
  135167. static float _vq_quantthresh__44u5__p8_1[] = {
  135168. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135169. 3.5, 4.5,
  135170. };
  135171. static long _vq_quantmap__44u5__p8_1[] = {
  135172. 9, 7, 5, 3, 1, 0, 2, 4,
  135173. 6, 8, 10,
  135174. };
  135175. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135176. _vq_quantthresh__44u5__p8_1,
  135177. _vq_quantmap__44u5__p8_1,
  135178. 11,
  135179. 11
  135180. };
  135181. static static_codebook _44u5__p8_1 = {
  135182. 2, 121,
  135183. _vq_lengthlist__44u5__p8_1,
  135184. 1, -531365888, 1611661312, 4, 0,
  135185. _vq_quantlist__44u5__p8_1,
  135186. NULL,
  135187. &_vq_auxt__44u5__p8_1,
  135188. NULL,
  135189. 0
  135190. };
  135191. static long _vq_quantlist__44u5__p9_0[] = {
  135192. 6,
  135193. 5,
  135194. 7,
  135195. 4,
  135196. 8,
  135197. 3,
  135198. 9,
  135199. 2,
  135200. 10,
  135201. 1,
  135202. 11,
  135203. 0,
  135204. 12,
  135205. };
  135206. static long _vq_lengthlist__44u5__p9_0[] = {
  135207. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135208. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135209. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135210. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135211. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135212. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135213. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135214. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135215. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135216. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135217. 12,12,12,12,12,12,12,12,12,
  135218. };
  135219. static float _vq_quantthresh__44u5__p9_0[] = {
  135220. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135221. 637.5, 892.5, 1147.5, 1402.5,
  135222. };
  135223. static long _vq_quantmap__44u5__p9_0[] = {
  135224. 11, 9, 7, 5, 3, 1, 0, 2,
  135225. 4, 6, 8, 10, 12,
  135226. };
  135227. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135228. _vq_quantthresh__44u5__p9_0,
  135229. _vq_quantmap__44u5__p9_0,
  135230. 13,
  135231. 13
  135232. };
  135233. static static_codebook _44u5__p9_0 = {
  135234. 2, 169,
  135235. _vq_lengthlist__44u5__p9_0,
  135236. 1, -514332672, 1627381760, 4, 0,
  135237. _vq_quantlist__44u5__p9_0,
  135238. NULL,
  135239. &_vq_auxt__44u5__p9_0,
  135240. NULL,
  135241. 0
  135242. };
  135243. static long _vq_quantlist__44u5__p9_1[] = {
  135244. 7,
  135245. 6,
  135246. 8,
  135247. 5,
  135248. 9,
  135249. 4,
  135250. 10,
  135251. 3,
  135252. 11,
  135253. 2,
  135254. 12,
  135255. 1,
  135256. 13,
  135257. 0,
  135258. 14,
  135259. };
  135260. static long _vq_lengthlist__44u5__p9_1[] = {
  135261. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135262. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135263. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135264. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135265. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135266. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135267. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135268. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135269. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135270. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135271. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135272. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135273. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135274. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135275. 14,
  135276. };
  135277. static float _vq_quantthresh__44u5__p9_1[] = {
  135278. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135279. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135280. };
  135281. static long _vq_quantmap__44u5__p9_1[] = {
  135282. 13, 11, 9, 7, 5, 3, 1, 0,
  135283. 2, 4, 6, 8, 10, 12, 14,
  135284. };
  135285. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135286. _vq_quantthresh__44u5__p9_1,
  135287. _vq_quantmap__44u5__p9_1,
  135288. 15,
  135289. 15
  135290. };
  135291. static static_codebook _44u5__p9_1 = {
  135292. 2, 225,
  135293. _vq_lengthlist__44u5__p9_1,
  135294. 1, -522338304, 1620115456, 4, 0,
  135295. _vq_quantlist__44u5__p9_1,
  135296. NULL,
  135297. &_vq_auxt__44u5__p9_1,
  135298. NULL,
  135299. 0
  135300. };
  135301. static long _vq_quantlist__44u5__p9_2[] = {
  135302. 8,
  135303. 7,
  135304. 9,
  135305. 6,
  135306. 10,
  135307. 5,
  135308. 11,
  135309. 4,
  135310. 12,
  135311. 3,
  135312. 13,
  135313. 2,
  135314. 14,
  135315. 1,
  135316. 15,
  135317. 0,
  135318. 16,
  135319. };
  135320. static long _vq_lengthlist__44u5__p9_2[] = {
  135321. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135322. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135323. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135324. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135325. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135326. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135327. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135328. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135329. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135330. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135331. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135332. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135333. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135334. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135335. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135336. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135337. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135338. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135339. 10,
  135340. };
  135341. static float _vq_quantthresh__44u5__p9_2[] = {
  135342. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135343. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135344. };
  135345. static long _vq_quantmap__44u5__p9_2[] = {
  135346. 15, 13, 11, 9, 7, 5, 3, 1,
  135347. 0, 2, 4, 6, 8, 10, 12, 14,
  135348. 16,
  135349. };
  135350. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135351. _vq_quantthresh__44u5__p9_2,
  135352. _vq_quantmap__44u5__p9_2,
  135353. 17,
  135354. 17
  135355. };
  135356. static static_codebook _44u5__p9_2 = {
  135357. 2, 289,
  135358. _vq_lengthlist__44u5__p9_2,
  135359. 1, -529530880, 1611661312, 5, 0,
  135360. _vq_quantlist__44u5__p9_2,
  135361. NULL,
  135362. &_vq_auxt__44u5__p9_2,
  135363. NULL,
  135364. 0
  135365. };
  135366. static long _huff_lengthlist__44u5__short[] = {
  135367. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135368. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135369. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135370. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135371. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135372. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135373. 6, 8,15,17,
  135374. };
  135375. static static_codebook _huff_book__44u5__short = {
  135376. 2, 100,
  135377. _huff_lengthlist__44u5__short,
  135378. 0, 0, 0, 0, 0,
  135379. NULL,
  135380. NULL,
  135381. NULL,
  135382. NULL,
  135383. 0
  135384. };
  135385. static long _huff_lengthlist__44u6__long[] = {
  135386. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135387. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135388. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135389. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135390. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135391. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135392. 13, 8, 7, 7,
  135393. };
  135394. static static_codebook _huff_book__44u6__long = {
  135395. 2, 100,
  135396. _huff_lengthlist__44u6__long,
  135397. 0, 0, 0, 0, 0,
  135398. NULL,
  135399. NULL,
  135400. NULL,
  135401. NULL,
  135402. 0
  135403. };
  135404. static long _vq_quantlist__44u6__p1_0[] = {
  135405. 1,
  135406. 0,
  135407. 2,
  135408. };
  135409. static long _vq_lengthlist__44u6__p1_0[] = {
  135410. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135411. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135412. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135413. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135414. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135415. 12,
  135416. };
  135417. static float _vq_quantthresh__44u6__p1_0[] = {
  135418. -0.5, 0.5,
  135419. };
  135420. static long _vq_quantmap__44u6__p1_0[] = {
  135421. 1, 0, 2,
  135422. };
  135423. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135424. _vq_quantthresh__44u6__p1_0,
  135425. _vq_quantmap__44u6__p1_0,
  135426. 3,
  135427. 3
  135428. };
  135429. static static_codebook _44u6__p1_0 = {
  135430. 4, 81,
  135431. _vq_lengthlist__44u6__p1_0,
  135432. 1, -535822336, 1611661312, 2, 0,
  135433. _vq_quantlist__44u6__p1_0,
  135434. NULL,
  135435. &_vq_auxt__44u6__p1_0,
  135436. NULL,
  135437. 0
  135438. };
  135439. static long _vq_quantlist__44u6__p2_0[] = {
  135440. 1,
  135441. 0,
  135442. 2,
  135443. };
  135444. static long _vq_lengthlist__44u6__p2_0[] = {
  135445. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135446. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135447. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135448. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135449. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135450. 9,
  135451. };
  135452. static float _vq_quantthresh__44u6__p2_0[] = {
  135453. -0.5, 0.5,
  135454. };
  135455. static long _vq_quantmap__44u6__p2_0[] = {
  135456. 1, 0, 2,
  135457. };
  135458. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135459. _vq_quantthresh__44u6__p2_0,
  135460. _vq_quantmap__44u6__p2_0,
  135461. 3,
  135462. 3
  135463. };
  135464. static static_codebook _44u6__p2_0 = {
  135465. 4, 81,
  135466. _vq_lengthlist__44u6__p2_0,
  135467. 1, -535822336, 1611661312, 2, 0,
  135468. _vq_quantlist__44u6__p2_0,
  135469. NULL,
  135470. &_vq_auxt__44u6__p2_0,
  135471. NULL,
  135472. 0
  135473. };
  135474. static long _vq_quantlist__44u6__p3_0[] = {
  135475. 2,
  135476. 1,
  135477. 3,
  135478. 0,
  135479. 4,
  135480. };
  135481. static long _vq_lengthlist__44u6__p3_0[] = {
  135482. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135483. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135484. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135485. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135486. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135487. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135488. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135489. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135490. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135491. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135492. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135493. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135494. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135495. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135496. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135497. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135498. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135499. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135500. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135501. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135502. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135503. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135504. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135505. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135506. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135507. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135508. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135509. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135510. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135511. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135512. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135513. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135514. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135515. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135516. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135517. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135518. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135519. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135520. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135521. 19,
  135522. };
  135523. static float _vq_quantthresh__44u6__p3_0[] = {
  135524. -1.5, -0.5, 0.5, 1.5,
  135525. };
  135526. static long _vq_quantmap__44u6__p3_0[] = {
  135527. 3, 1, 0, 2, 4,
  135528. };
  135529. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135530. _vq_quantthresh__44u6__p3_0,
  135531. _vq_quantmap__44u6__p3_0,
  135532. 5,
  135533. 5
  135534. };
  135535. static static_codebook _44u6__p3_0 = {
  135536. 4, 625,
  135537. _vq_lengthlist__44u6__p3_0,
  135538. 1, -533725184, 1611661312, 3, 0,
  135539. _vq_quantlist__44u6__p3_0,
  135540. NULL,
  135541. &_vq_auxt__44u6__p3_0,
  135542. NULL,
  135543. 0
  135544. };
  135545. static long _vq_quantlist__44u6__p4_0[] = {
  135546. 2,
  135547. 1,
  135548. 3,
  135549. 0,
  135550. 4,
  135551. };
  135552. static long _vq_lengthlist__44u6__p4_0[] = {
  135553. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135554. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135555. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135556. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135557. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135558. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135559. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135560. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135561. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135562. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135563. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135564. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135565. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135566. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135567. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135568. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135569. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135570. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135571. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135572. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135573. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135574. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135575. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135576. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135577. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135578. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135579. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135580. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135581. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135582. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135583. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135584. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135585. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135586. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135587. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135588. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135589. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135590. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135591. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135592. 13,
  135593. };
  135594. static float _vq_quantthresh__44u6__p4_0[] = {
  135595. -1.5, -0.5, 0.5, 1.5,
  135596. };
  135597. static long _vq_quantmap__44u6__p4_0[] = {
  135598. 3, 1, 0, 2, 4,
  135599. };
  135600. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135601. _vq_quantthresh__44u6__p4_0,
  135602. _vq_quantmap__44u6__p4_0,
  135603. 5,
  135604. 5
  135605. };
  135606. static static_codebook _44u6__p4_0 = {
  135607. 4, 625,
  135608. _vq_lengthlist__44u6__p4_0,
  135609. 1, -533725184, 1611661312, 3, 0,
  135610. _vq_quantlist__44u6__p4_0,
  135611. NULL,
  135612. &_vq_auxt__44u6__p4_0,
  135613. NULL,
  135614. 0
  135615. };
  135616. static long _vq_quantlist__44u6__p5_0[] = {
  135617. 4,
  135618. 3,
  135619. 5,
  135620. 2,
  135621. 6,
  135622. 1,
  135623. 7,
  135624. 0,
  135625. 8,
  135626. };
  135627. static long _vq_lengthlist__44u6__p5_0[] = {
  135628. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135629. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135630. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135631. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135632. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135633. 14,
  135634. };
  135635. static float _vq_quantthresh__44u6__p5_0[] = {
  135636. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135637. };
  135638. static long _vq_quantmap__44u6__p5_0[] = {
  135639. 7, 5, 3, 1, 0, 2, 4, 6,
  135640. 8,
  135641. };
  135642. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135643. _vq_quantthresh__44u6__p5_0,
  135644. _vq_quantmap__44u6__p5_0,
  135645. 9,
  135646. 9
  135647. };
  135648. static static_codebook _44u6__p5_0 = {
  135649. 2, 81,
  135650. _vq_lengthlist__44u6__p5_0,
  135651. 1, -531628032, 1611661312, 4, 0,
  135652. _vq_quantlist__44u6__p5_0,
  135653. NULL,
  135654. &_vq_auxt__44u6__p5_0,
  135655. NULL,
  135656. 0
  135657. };
  135658. static long _vq_quantlist__44u6__p6_0[] = {
  135659. 4,
  135660. 3,
  135661. 5,
  135662. 2,
  135663. 6,
  135664. 1,
  135665. 7,
  135666. 0,
  135667. 8,
  135668. };
  135669. static long _vq_lengthlist__44u6__p6_0[] = {
  135670. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135671. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135672. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135673. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135674. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135675. 12,
  135676. };
  135677. static float _vq_quantthresh__44u6__p6_0[] = {
  135678. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135679. };
  135680. static long _vq_quantmap__44u6__p6_0[] = {
  135681. 7, 5, 3, 1, 0, 2, 4, 6,
  135682. 8,
  135683. };
  135684. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135685. _vq_quantthresh__44u6__p6_0,
  135686. _vq_quantmap__44u6__p6_0,
  135687. 9,
  135688. 9
  135689. };
  135690. static static_codebook _44u6__p6_0 = {
  135691. 2, 81,
  135692. _vq_lengthlist__44u6__p6_0,
  135693. 1, -531628032, 1611661312, 4, 0,
  135694. _vq_quantlist__44u6__p6_0,
  135695. NULL,
  135696. &_vq_auxt__44u6__p6_0,
  135697. NULL,
  135698. 0
  135699. };
  135700. static long _vq_quantlist__44u6__p7_0[] = {
  135701. 1,
  135702. 0,
  135703. 2,
  135704. };
  135705. static long _vq_lengthlist__44u6__p7_0[] = {
  135706. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135707. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135708. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135709. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135710. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135711. 10,
  135712. };
  135713. static float _vq_quantthresh__44u6__p7_0[] = {
  135714. -5.5, 5.5,
  135715. };
  135716. static long _vq_quantmap__44u6__p7_0[] = {
  135717. 1, 0, 2,
  135718. };
  135719. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135720. _vq_quantthresh__44u6__p7_0,
  135721. _vq_quantmap__44u6__p7_0,
  135722. 3,
  135723. 3
  135724. };
  135725. static static_codebook _44u6__p7_0 = {
  135726. 4, 81,
  135727. _vq_lengthlist__44u6__p7_0,
  135728. 1, -529137664, 1618345984, 2, 0,
  135729. _vq_quantlist__44u6__p7_0,
  135730. NULL,
  135731. &_vq_auxt__44u6__p7_0,
  135732. NULL,
  135733. 0
  135734. };
  135735. static long _vq_quantlist__44u6__p7_1[] = {
  135736. 5,
  135737. 4,
  135738. 6,
  135739. 3,
  135740. 7,
  135741. 2,
  135742. 8,
  135743. 1,
  135744. 9,
  135745. 0,
  135746. 10,
  135747. };
  135748. static long _vq_lengthlist__44u6__p7_1[] = {
  135749. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135750. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135751. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135752. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135753. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135754. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135755. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135756. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135757. };
  135758. static float _vq_quantthresh__44u6__p7_1[] = {
  135759. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135760. 3.5, 4.5,
  135761. };
  135762. static long _vq_quantmap__44u6__p7_1[] = {
  135763. 9, 7, 5, 3, 1, 0, 2, 4,
  135764. 6, 8, 10,
  135765. };
  135766. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135767. _vq_quantthresh__44u6__p7_1,
  135768. _vq_quantmap__44u6__p7_1,
  135769. 11,
  135770. 11
  135771. };
  135772. static static_codebook _44u6__p7_1 = {
  135773. 2, 121,
  135774. _vq_lengthlist__44u6__p7_1,
  135775. 1, -531365888, 1611661312, 4, 0,
  135776. _vq_quantlist__44u6__p7_1,
  135777. NULL,
  135778. &_vq_auxt__44u6__p7_1,
  135779. NULL,
  135780. 0
  135781. };
  135782. static long _vq_quantlist__44u6__p8_0[] = {
  135783. 5,
  135784. 4,
  135785. 6,
  135786. 3,
  135787. 7,
  135788. 2,
  135789. 8,
  135790. 1,
  135791. 9,
  135792. 0,
  135793. 10,
  135794. };
  135795. static long _vq_lengthlist__44u6__p8_0[] = {
  135796. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135797. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135798. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135799. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135800. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135801. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135802. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135803. 12,13,13,14,14,14,15,15,15,
  135804. };
  135805. static float _vq_quantthresh__44u6__p8_0[] = {
  135806. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135807. 38.5, 49.5,
  135808. };
  135809. static long _vq_quantmap__44u6__p8_0[] = {
  135810. 9, 7, 5, 3, 1, 0, 2, 4,
  135811. 6, 8, 10,
  135812. };
  135813. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135814. _vq_quantthresh__44u6__p8_0,
  135815. _vq_quantmap__44u6__p8_0,
  135816. 11,
  135817. 11
  135818. };
  135819. static static_codebook _44u6__p8_0 = {
  135820. 2, 121,
  135821. _vq_lengthlist__44u6__p8_0,
  135822. 1, -524582912, 1618345984, 4, 0,
  135823. _vq_quantlist__44u6__p8_0,
  135824. NULL,
  135825. &_vq_auxt__44u6__p8_0,
  135826. NULL,
  135827. 0
  135828. };
  135829. static long _vq_quantlist__44u6__p8_1[] = {
  135830. 5,
  135831. 4,
  135832. 6,
  135833. 3,
  135834. 7,
  135835. 2,
  135836. 8,
  135837. 1,
  135838. 9,
  135839. 0,
  135840. 10,
  135841. };
  135842. static long _vq_lengthlist__44u6__p8_1[] = {
  135843. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135844. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135845. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135846. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135847. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135848. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135849. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135850. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135851. };
  135852. static float _vq_quantthresh__44u6__p8_1[] = {
  135853. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135854. 3.5, 4.5,
  135855. };
  135856. static long _vq_quantmap__44u6__p8_1[] = {
  135857. 9, 7, 5, 3, 1, 0, 2, 4,
  135858. 6, 8, 10,
  135859. };
  135860. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135861. _vq_quantthresh__44u6__p8_1,
  135862. _vq_quantmap__44u6__p8_1,
  135863. 11,
  135864. 11
  135865. };
  135866. static static_codebook _44u6__p8_1 = {
  135867. 2, 121,
  135868. _vq_lengthlist__44u6__p8_1,
  135869. 1, -531365888, 1611661312, 4, 0,
  135870. _vq_quantlist__44u6__p8_1,
  135871. NULL,
  135872. &_vq_auxt__44u6__p8_1,
  135873. NULL,
  135874. 0
  135875. };
  135876. static long _vq_quantlist__44u6__p9_0[] = {
  135877. 7,
  135878. 6,
  135879. 8,
  135880. 5,
  135881. 9,
  135882. 4,
  135883. 10,
  135884. 3,
  135885. 11,
  135886. 2,
  135887. 12,
  135888. 1,
  135889. 13,
  135890. 0,
  135891. 14,
  135892. };
  135893. static long _vq_lengthlist__44u6__p9_0[] = {
  135894. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135895. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135896. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135897. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135898. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135899. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135900. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135901. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135902. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135903. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135904. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135905. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135906. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135907. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135908. 14,
  135909. };
  135910. static float _vq_quantthresh__44u6__p9_0[] = {
  135911. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135912. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135913. };
  135914. static long _vq_quantmap__44u6__p9_0[] = {
  135915. 13, 11, 9, 7, 5, 3, 1, 0,
  135916. 2, 4, 6, 8, 10, 12, 14,
  135917. };
  135918. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135919. _vq_quantthresh__44u6__p9_0,
  135920. _vq_quantmap__44u6__p9_0,
  135921. 15,
  135922. 15
  135923. };
  135924. static static_codebook _44u6__p9_0 = {
  135925. 2, 225,
  135926. _vq_lengthlist__44u6__p9_0,
  135927. 1, -514071552, 1627381760, 4, 0,
  135928. _vq_quantlist__44u6__p9_0,
  135929. NULL,
  135930. &_vq_auxt__44u6__p9_0,
  135931. NULL,
  135932. 0
  135933. };
  135934. static long _vq_quantlist__44u6__p9_1[] = {
  135935. 7,
  135936. 6,
  135937. 8,
  135938. 5,
  135939. 9,
  135940. 4,
  135941. 10,
  135942. 3,
  135943. 11,
  135944. 2,
  135945. 12,
  135946. 1,
  135947. 13,
  135948. 0,
  135949. 14,
  135950. };
  135951. static long _vq_lengthlist__44u6__p9_1[] = {
  135952. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135953. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135954. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135955. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135956. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135957. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135958. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135959. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135960. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135961. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135962. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135963. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135964. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135965. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135966. 13,
  135967. };
  135968. static float _vq_quantthresh__44u6__p9_1[] = {
  135969. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135970. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135971. };
  135972. static long _vq_quantmap__44u6__p9_1[] = {
  135973. 13, 11, 9, 7, 5, 3, 1, 0,
  135974. 2, 4, 6, 8, 10, 12, 14,
  135975. };
  135976. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135977. _vq_quantthresh__44u6__p9_1,
  135978. _vq_quantmap__44u6__p9_1,
  135979. 15,
  135980. 15
  135981. };
  135982. static static_codebook _44u6__p9_1 = {
  135983. 2, 225,
  135984. _vq_lengthlist__44u6__p9_1,
  135985. 1, -522338304, 1620115456, 4, 0,
  135986. _vq_quantlist__44u6__p9_1,
  135987. NULL,
  135988. &_vq_auxt__44u6__p9_1,
  135989. NULL,
  135990. 0
  135991. };
  135992. static long _vq_quantlist__44u6__p9_2[] = {
  135993. 8,
  135994. 7,
  135995. 9,
  135996. 6,
  135997. 10,
  135998. 5,
  135999. 11,
  136000. 4,
  136001. 12,
  136002. 3,
  136003. 13,
  136004. 2,
  136005. 14,
  136006. 1,
  136007. 15,
  136008. 0,
  136009. 16,
  136010. };
  136011. static long _vq_lengthlist__44u6__p9_2[] = {
  136012. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  136013. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  136014. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  136015. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136016. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136017. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136018. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136019. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136020. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136021. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  136022. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  136023. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136024. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  136025. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  136026. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  136027. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  136028. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  136029. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  136030. 10,
  136031. };
  136032. static float _vq_quantthresh__44u6__p9_2[] = {
  136033. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136034. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136035. };
  136036. static long _vq_quantmap__44u6__p9_2[] = {
  136037. 15, 13, 11, 9, 7, 5, 3, 1,
  136038. 0, 2, 4, 6, 8, 10, 12, 14,
  136039. 16,
  136040. };
  136041. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  136042. _vq_quantthresh__44u6__p9_2,
  136043. _vq_quantmap__44u6__p9_2,
  136044. 17,
  136045. 17
  136046. };
  136047. static static_codebook _44u6__p9_2 = {
  136048. 2, 289,
  136049. _vq_lengthlist__44u6__p9_2,
  136050. 1, -529530880, 1611661312, 5, 0,
  136051. _vq_quantlist__44u6__p9_2,
  136052. NULL,
  136053. &_vq_auxt__44u6__p9_2,
  136054. NULL,
  136055. 0
  136056. };
  136057. static long _huff_lengthlist__44u6__short[] = {
  136058. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  136059. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  136060. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  136061. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  136062. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  136063. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  136064. 7, 6, 9,16,
  136065. };
  136066. static static_codebook _huff_book__44u6__short = {
  136067. 2, 100,
  136068. _huff_lengthlist__44u6__short,
  136069. 0, 0, 0, 0, 0,
  136070. NULL,
  136071. NULL,
  136072. NULL,
  136073. NULL,
  136074. 0
  136075. };
  136076. static long _huff_lengthlist__44u7__long[] = {
  136077. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  136078. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  136079. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  136080. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  136081. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  136082. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  136083. 12, 8, 6, 7,
  136084. };
  136085. static static_codebook _huff_book__44u7__long = {
  136086. 2, 100,
  136087. _huff_lengthlist__44u7__long,
  136088. 0, 0, 0, 0, 0,
  136089. NULL,
  136090. NULL,
  136091. NULL,
  136092. NULL,
  136093. 0
  136094. };
  136095. static long _vq_quantlist__44u7__p1_0[] = {
  136096. 1,
  136097. 0,
  136098. 2,
  136099. };
  136100. static long _vq_lengthlist__44u7__p1_0[] = {
  136101. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136102. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136103. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136104. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136105. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136106. 12,
  136107. };
  136108. static float _vq_quantthresh__44u7__p1_0[] = {
  136109. -0.5, 0.5,
  136110. };
  136111. static long _vq_quantmap__44u7__p1_0[] = {
  136112. 1, 0, 2,
  136113. };
  136114. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136115. _vq_quantthresh__44u7__p1_0,
  136116. _vq_quantmap__44u7__p1_0,
  136117. 3,
  136118. 3
  136119. };
  136120. static static_codebook _44u7__p1_0 = {
  136121. 4, 81,
  136122. _vq_lengthlist__44u7__p1_0,
  136123. 1, -535822336, 1611661312, 2, 0,
  136124. _vq_quantlist__44u7__p1_0,
  136125. NULL,
  136126. &_vq_auxt__44u7__p1_0,
  136127. NULL,
  136128. 0
  136129. };
  136130. static long _vq_quantlist__44u7__p2_0[] = {
  136131. 1,
  136132. 0,
  136133. 2,
  136134. };
  136135. static long _vq_lengthlist__44u7__p2_0[] = {
  136136. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136137. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136138. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136139. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136140. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136141. 9,
  136142. };
  136143. static float _vq_quantthresh__44u7__p2_0[] = {
  136144. -0.5, 0.5,
  136145. };
  136146. static long _vq_quantmap__44u7__p2_0[] = {
  136147. 1, 0, 2,
  136148. };
  136149. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136150. _vq_quantthresh__44u7__p2_0,
  136151. _vq_quantmap__44u7__p2_0,
  136152. 3,
  136153. 3
  136154. };
  136155. static static_codebook _44u7__p2_0 = {
  136156. 4, 81,
  136157. _vq_lengthlist__44u7__p2_0,
  136158. 1, -535822336, 1611661312, 2, 0,
  136159. _vq_quantlist__44u7__p2_0,
  136160. NULL,
  136161. &_vq_auxt__44u7__p2_0,
  136162. NULL,
  136163. 0
  136164. };
  136165. static long _vq_quantlist__44u7__p3_0[] = {
  136166. 2,
  136167. 1,
  136168. 3,
  136169. 0,
  136170. 4,
  136171. };
  136172. static long _vq_lengthlist__44u7__p3_0[] = {
  136173. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136174. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136175. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136176. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136177. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136178. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136179. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136180. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136181. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136182. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136183. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136184. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136185. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136186. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136187. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136188. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136189. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136190. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136191. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136192. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136193. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136194. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136195. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136196. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136197. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136198. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136199. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136200. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136201. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136202. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136203. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136204. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136205. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136206. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136207. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136208. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136209. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136210. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136211. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136212. 0,
  136213. };
  136214. static float _vq_quantthresh__44u7__p3_0[] = {
  136215. -1.5, -0.5, 0.5, 1.5,
  136216. };
  136217. static long _vq_quantmap__44u7__p3_0[] = {
  136218. 3, 1, 0, 2, 4,
  136219. };
  136220. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136221. _vq_quantthresh__44u7__p3_0,
  136222. _vq_quantmap__44u7__p3_0,
  136223. 5,
  136224. 5
  136225. };
  136226. static static_codebook _44u7__p3_0 = {
  136227. 4, 625,
  136228. _vq_lengthlist__44u7__p3_0,
  136229. 1, -533725184, 1611661312, 3, 0,
  136230. _vq_quantlist__44u7__p3_0,
  136231. NULL,
  136232. &_vq_auxt__44u7__p3_0,
  136233. NULL,
  136234. 0
  136235. };
  136236. static long _vq_quantlist__44u7__p4_0[] = {
  136237. 2,
  136238. 1,
  136239. 3,
  136240. 0,
  136241. 4,
  136242. };
  136243. static long _vq_lengthlist__44u7__p4_0[] = {
  136244. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136245. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136246. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136247. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136248. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136249. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136250. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136251. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136252. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136253. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136254. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136255. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136256. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136257. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136258. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136259. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136260. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136261. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136262. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136263. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136264. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136265. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136266. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136267. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136268. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136269. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136270. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136271. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136272. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136273. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136274. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136275. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136276. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136277. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136278. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136279. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136280. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136281. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136282. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136283. 14,
  136284. };
  136285. static float _vq_quantthresh__44u7__p4_0[] = {
  136286. -1.5, -0.5, 0.5, 1.5,
  136287. };
  136288. static long _vq_quantmap__44u7__p4_0[] = {
  136289. 3, 1, 0, 2, 4,
  136290. };
  136291. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136292. _vq_quantthresh__44u7__p4_0,
  136293. _vq_quantmap__44u7__p4_0,
  136294. 5,
  136295. 5
  136296. };
  136297. static static_codebook _44u7__p4_0 = {
  136298. 4, 625,
  136299. _vq_lengthlist__44u7__p4_0,
  136300. 1, -533725184, 1611661312, 3, 0,
  136301. _vq_quantlist__44u7__p4_0,
  136302. NULL,
  136303. &_vq_auxt__44u7__p4_0,
  136304. NULL,
  136305. 0
  136306. };
  136307. static long _vq_quantlist__44u7__p5_0[] = {
  136308. 4,
  136309. 3,
  136310. 5,
  136311. 2,
  136312. 6,
  136313. 1,
  136314. 7,
  136315. 0,
  136316. 8,
  136317. };
  136318. static long _vq_lengthlist__44u7__p5_0[] = {
  136319. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136320. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136321. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136322. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136323. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136324. 14,
  136325. };
  136326. static float _vq_quantthresh__44u7__p5_0[] = {
  136327. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136328. };
  136329. static long _vq_quantmap__44u7__p5_0[] = {
  136330. 7, 5, 3, 1, 0, 2, 4, 6,
  136331. 8,
  136332. };
  136333. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136334. _vq_quantthresh__44u7__p5_0,
  136335. _vq_quantmap__44u7__p5_0,
  136336. 9,
  136337. 9
  136338. };
  136339. static static_codebook _44u7__p5_0 = {
  136340. 2, 81,
  136341. _vq_lengthlist__44u7__p5_0,
  136342. 1, -531628032, 1611661312, 4, 0,
  136343. _vq_quantlist__44u7__p5_0,
  136344. NULL,
  136345. &_vq_auxt__44u7__p5_0,
  136346. NULL,
  136347. 0
  136348. };
  136349. static long _vq_quantlist__44u7__p6_0[] = {
  136350. 4,
  136351. 3,
  136352. 5,
  136353. 2,
  136354. 6,
  136355. 1,
  136356. 7,
  136357. 0,
  136358. 8,
  136359. };
  136360. static long _vq_lengthlist__44u7__p6_0[] = {
  136361. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136362. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136363. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136364. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136365. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136366. 12,
  136367. };
  136368. static float _vq_quantthresh__44u7__p6_0[] = {
  136369. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136370. };
  136371. static long _vq_quantmap__44u7__p6_0[] = {
  136372. 7, 5, 3, 1, 0, 2, 4, 6,
  136373. 8,
  136374. };
  136375. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136376. _vq_quantthresh__44u7__p6_0,
  136377. _vq_quantmap__44u7__p6_0,
  136378. 9,
  136379. 9
  136380. };
  136381. static static_codebook _44u7__p6_0 = {
  136382. 2, 81,
  136383. _vq_lengthlist__44u7__p6_0,
  136384. 1, -531628032, 1611661312, 4, 0,
  136385. _vq_quantlist__44u7__p6_0,
  136386. NULL,
  136387. &_vq_auxt__44u7__p6_0,
  136388. NULL,
  136389. 0
  136390. };
  136391. static long _vq_quantlist__44u7__p7_0[] = {
  136392. 1,
  136393. 0,
  136394. 2,
  136395. };
  136396. static long _vq_lengthlist__44u7__p7_0[] = {
  136397. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136398. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136399. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136400. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136401. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136402. 10,
  136403. };
  136404. static float _vq_quantthresh__44u7__p7_0[] = {
  136405. -5.5, 5.5,
  136406. };
  136407. static long _vq_quantmap__44u7__p7_0[] = {
  136408. 1, 0, 2,
  136409. };
  136410. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136411. _vq_quantthresh__44u7__p7_0,
  136412. _vq_quantmap__44u7__p7_0,
  136413. 3,
  136414. 3
  136415. };
  136416. static static_codebook _44u7__p7_0 = {
  136417. 4, 81,
  136418. _vq_lengthlist__44u7__p7_0,
  136419. 1, -529137664, 1618345984, 2, 0,
  136420. _vq_quantlist__44u7__p7_0,
  136421. NULL,
  136422. &_vq_auxt__44u7__p7_0,
  136423. NULL,
  136424. 0
  136425. };
  136426. static long _vq_quantlist__44u7__p7_1[] = {
  136427. 5,
  136428. 4,
  136429. 6,
  136430. 3,
  136431. 7,
  136432. 2,
  136433. 8,
  136434. 1,
  136435. 9,
  136436. 0,
  136437. 10,
  136438. };
  136439. static long _vq_lengthlist__44u7__p7_1[] = {
  136440. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136441. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136442. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136443. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136444. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136445. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136446. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136447. 8, 9, 9, 9, 9, 9,10,10,10,
  136448. };
  136449. static float _vq_quantthresh__44u7__p7_1[] = {
  136450. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136451. 3.5, 4.5,
  136452. };
  136453. static long _vq_quantmap__44u7__p7_1[] = {
  136454. 9, 7, 5, 3, 1, 0, 2, 4,
  136455. 6, 8, 10,
  136456. };
  136457. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136458. _vq_quantthresh__44u7__p7_1,
  136459. _vq_quantmap__44u7__p7_1,
  136460. 11,
  136461. 11
  136462. };
  136463. static static_codebook _44u7__p7_1 = {
  136464. 2, 121,
  136465. _vq_lengthlist__44u7__p7_1,
  136466. 1, -531365888, 1611661312, 4, 0,
  136467. _vq_quantlist__44u7__p7_1,
  136468. NULL,
  136469. &_vq_auxt__44u7__p7_1,
  136470. NULL,
  136471. 0
  136472. };
  136473. static long _vq_quantlist__44u7__p8_0[] = {
  136474. 5,
  136475. 4,
  136476. 6,
  136477. 3,
  136478. 7,
  136479. 2,
  136480. 8,
  136481. 1,
  136482. 9,
  136483. 0,
  136484. 10,
  136485. };
  136486. static long _vq_lengthlist__44u7__p8_0[] = {
  136487. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136488. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136489. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136490. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136491. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136492. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136493. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136494. 12,13,13,14,14,15,15,15,16,
  136495. };
  136496. static float _vq_quantthresh__44u7__p8_0[] = {
  136497. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136498. 38.5, 49.5,
  136499. };
  136500. static long _vq_quantmap__44u7__p8_0[] = {
  136501. 9, 7, 5, 3, 1, 0, 2, 4,
  136502. 6, 8, 10,
  136503. };
  136504. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136505. _vq_quantthresh__44u7__p8_0,
  136506. _vq_quantmap__44u7__p8_0,
  136507. 11,
  136508. 11
  136509. };
  136510. static static_codebook _44u7__p8_0 = {
  136511. 2, 121,
  136512. _vq_lengthlist__44u7__p8_0,
  136513. 1, -524582912, 1618345984, 4, 0,
  136514. _vq_quantlist__44u7__p8_0,
  136515. NULL,
  136516. &_vq_auxt__44u7__p8_0,
  136517. NULL,
  136518. 0
  136519. };
  136520. static long _vq_quantlist__44u7__p8_1[] = {
  136521. 5,
  136522. 4,
  136523. 6,
  136524. 3,
  136525. 7,
  136526. 2,
  136527. 8,
  136528. 1,
  136529. 9,
  136530. 0,
  136531. 10,
  136532. };
  136533. static long _vq_lengthlist__44u7__p8_1[] = {
  136534. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136535. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136536. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136537. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136538. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136539. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136540. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136541. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136542. };
  136543. static float _vq_quantthresh__44u7__p8_1[] = {
  136544. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136545. 3.5, 4.5,
  136546. };
  136547. static long _vq_quantmap__44u7__p8_1[] = {
  136548. 9, 7, 5, 3, 1, 0, 2, 4,
  136549. 6, 8, 10,
  136550. };
  136551. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136552. _vq_quantthresh__44u7__p8_1,
  136553. _vq_quantmap__44u7__p8_1,
  136554. 11,
  136555. 11
  136556. };
  136557. static static_codebook _44u7__p8_1 = {
  136558. 2, 121,
  136559. _vq_lengthlist__44u7__p8_1,
  136560. 1, -531365888, 1611661312, 4, 0,
  136561. _vq_quantlist__44u7__p8_1,
  136562. NULL,
  136563. &_vq_auxt__44u7__p8_1,
  136564. NULL,
  136565. 0
  136566. };
  136567. static long _vq_quantlist__44u7__p9_0[] = {
  136568. 5,
  136569. 4,
  136570. 6,
  136571. 3,
  136572. 7,
  136573. 2,
  136574. 8,
  136575. 1,
  136576. 9,
  136577. 0,
  136578. 10,
  136579. };
  136580. static long _vq_lengthlist__44u7__p9_0[] = {
  136581. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136582. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136583. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136584. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136585. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136586. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136587. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136588. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136589. };
  136590. static float _vq_quantthresh__44u7__p9_0[] = {
  136591. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136592. 2229.5, 2866.5,
  136593. };
  136594. static long _vq_quantmap__44u7__p9_0[] = {
  136595. 9, 7, 5, 3, 1, 0, 2, 4,
  136596. 6, 8, 10,
  136597. };
  136598. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136599. _vq_quantthresh__44u7__p9_0,
  136600. _vq_quantmap__44u7__p9_0,
  136601. 11,
  136602. 11
  136603. };
  136604. static static_codebook _44u7__p9_0 = {
  136605. 2, 121,
  136606. _vq_lengthlist__44u7__p9_0,
  136607. 1, -512171520, 1630791680, 4, 0,
  136608. _vq_quantlist__44u7__p9_0,
  136609. NULL,
  136610. &_vq_auxt__44u7__p9_0,
  136611. NULL,
  136612. 0
  136613. };
  136614. static long _vq_quantlist__44u7__p9_1[] = {
  136615. 6,
  136616. 5,
  136617. 7,
  136618. 4,
  136619. 8,
  136620. 3,
  136621. 9,
  136622. 2,
  136623. 10,
  136624. 1,
  136625. 11,
  136626. 0,
  136627. 12,
  136628. };
  136629. static long _vq_lengthlist__44u7__p9_1[] = {
  136630. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136631. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136632. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136633. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136634. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136635. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136636. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136637. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136638. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136639. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136640. 15,15,15,15,17,17,16,17,16,
  136641. };
  136642. static float _vq_quantthresh__44u7__p9_1[] = {
  136643. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136644. 122.5, 171.5, 220.5, 269.5,
  136645. };
  136646. static long _vq_quantmap__44u7__p9_1[] = {
  136647. 11, 9, 7, 5, 3, 1, 0, 2,
  136648. 4, 6, 8, 10, 12,
  136649. };
  136650. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136651. _vq_quantthresh__44u7__p9_1,
  136652. _vq_quantmap__44u7__p9_1,
  136653. 13,
  136654. 13
  136655. };
  136656. static static_codebook _44u7__p9_1 = {
  136657. 2, 169,
  136658. _vq_lengthlist__44u7__p9_1,
  136659. 1, -518889472, 1622704128, 4, 0,
  136660. _vq_quantlist__44u7__p9_1,
  136661. NULL,
  136662. &_vq_auxt__44u7__p9_1,
  136663. NULL,
  136664. 0
  136665. };
  136666. static long _vq_quantlist__44u7__p9_2[] = {
  136667. 24,
  136668. 23,
  136669. 25,
  136670. 22,
  136671. 26,
  136672. 21,
  136673. 27,
  136674. 20,
  136675. 28,
  136676. 19,
  136677. 29,
  136678. 18,
  136679. 30,
  136680. 17,
  136681. 31,
  136682. 16,
  136683. 32,
  136684. 15,
  136685. 33,
  136686. 14,
  136687. 34,
  136688. 13,
  136689. 35,
  136690. 12,
  136691. 36,
  136692. 11,
  136693. 37,
  136694. 10,
  136695. 38,
  136696. 9,
  136697. 39,
  136698. 8,
  136699. 40,
  136700. 7,
  136701. 41,
  136702. 6,
  136703. 42,
  136704. 5,
  136705. 43,
  136706. 4,
  136707. 44,
  136708. 3,
  136709. 45,
  136710. 2,
  136711. 46,
  136712. 1,
  136713. 47,
  136714. 0,
  136715. 48,
  136716. };
  136717. static long _vq_lengthlist__44u7__p9_2[] = {
  136718. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136719. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136720. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136721. 8,
  136722. };
  136723. static float _vq_quantthresh__44u7__p9_2[] = {
  136724. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136725. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136726. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136727. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136728. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136729. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136730. };
  136731. static long _vq_quantmap__44u7__p9_2[] = {
  136732. 47, 45, 43, 41, 39, 37, 35, 33,
  136733. 31, 29, 27, 25, 23, 21, 19, 17,
  136734. 15, 13, 11, 9, 7, 5, 3, 1,
  136735. 0, 2, 4, 6, 8, 10, 12, 14,
  136736. 16, 18, 20, 22, 24, 26, 28, 30,
  136737. 32, 34, 36, 38, 40, 42, 44, 46,
  136738. 48,
  136739. };
  136740. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136741. _vq_quantthresh__44u7__p9_2,
  136742. _vq_quantmap__44u7__p9_2,
  136743. 49,
  136744. 49
  136745. };
  136746. static static_codebook _44u7__p9_2 = {
  136747. 1, 49,
  136748. _vq_lengthlist__44u7__p9_2,
  136749. 1, -526909440, 1611661312, 6, 0,
  136750. _vq_quantlist__44u7__p9_2,
  136751. NULL,
  136752. &_vq_auxt__44u7__p9_2,
  136753. NULL,
  136754. 0
  136755. };
  136756. static long _huff_lengthlist__44u7__short[] = {
  136757. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136758. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136759. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136760. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136761. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136762. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136763. 6, 8, 5, 9,
  136764. };
  136765. static static_codebook _huff_book__44u7__short = {
  136766. 2, 100,
  136767. _huff_lengthlist__44u7__short,
  136768. 0, 0, 0, 0, 0,
  136769. NULL,
  136770. NULL,
  136771. NULL,
  136772. NULL,
  136773. 0
  136774. };
  136775. static long _huff_lengthlist__44u8__long[] = {
  136776. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136777. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136778. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136779. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136780. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136781. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136782. 10, 8, 8, 9,
  136783. };
  136784. static static_codebook _huff_book__44u8__long = {
  136785. 2, 100,
  136786. _huff_lengthlist__44u8__long,
  136787. 0, 0, 0, 0, 0,
  136788. NULL,
  136789. NULL,
  136790. NULL,
  136791. NULL,
  136792. 0
  136793. };
  136794. static long _huff_lengthlist__44u8__short[] = {
  136795. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136796. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136797. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136798. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136799. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136800. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136801. 10,10,15,17,
  136802. };
  136803. static static_codebook _huff_book__44u8__short = {
  136804. 2, 100,
  136805. _huff_lengthlist__44u8__short,
  136806. 0, 0, 0, 0, 0,
  136807. NULL,
  136808. NULL,
  136809. NULL,
  136810. NULL,
  136811. 0
  136812. };
  136813. static long _vq_quantlist__44u8_p1_0[] = {
  136814. 1,
  136815. 0,
  136816. 2,
  136817. };
  136818. static long _vq_lengthlist__44u8_p1_0[] = {
  136819. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136820. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136821. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136822. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136823. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136824. 10,
  136825. };
  136826. static float _vq_quantthresh__44u8_p1_0[] = {
  136827. -0.5, 0.5,
  136828. };
  136829. static long _vq_quantmap__44u8_p1_0[] = {
  136830. 1, 0, 2,
  136831. };
  136832. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136833. _vq_quantthresh__44u8_p1_0,
  136834. _vq_quantmap__44u8_p1_0,
  136835. 3,
  136836. 3
  136837. };
  136838. static static_codebook _44u8_p1_0 = {
  136839. 4, 81,
  136840. _vq_lengthlist__44u8_p1_0,
  136841. 1, -535822336, 1611661312, 2, 0,
  136842. _vq_quantlist__44u8_p1_0,
  136843. NULL,
  136844. &_vq_auxt__44u8_p1_0,
  136845. NULL,
  136846. 0
  136847. };
  136848. static long _vq_quantlist__44u8_p2_0[] = {
  136849. 2,
  136850. 1,
  136851. 3,
  136852. 0,
  136853. 4,
  136854. };
  136855. static long _vq_lengthlist__44u8_p2_0[] = {
  136856. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136857. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136858. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136859. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136860. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136861. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136862. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136863. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136864. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136865. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136866. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136867. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136868. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136869. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136870. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136871. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136872. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136873. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136874. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136875. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136876. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136877. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136878. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136879. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136880. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136881. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136882. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136883. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136884. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136885. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136886. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136887. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136888. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136889. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136890. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136891. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136892. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136893. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136894. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136895. 14,
  136896. };
  136897. static float _vq_quantthresh__44u8_p2_0[] = {
  136898. -1.5, -0.5, 0.5, 1.5,
  136899. };
  136900. static long _vq_quantmap__44u8_p2_0[] = {
  136901. 3, 1, 0, 2, 4,
  136902. };
  136903. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136904. _vq_quantthresh__44u8_p2_0,
  136905. _vq_quantmap__44u8_p2_0,
  136906. 5,
  136907. 5
  136908. };
  136909. static static_codebook _44u8_p2_0 = {
  136910. 4, 625,
  136911. _vq_lengthlist__44u8_p2_0,
  136912. 1, -533725184, 1611661312, 3, 0,
  136913. _vq_quantlist__44u8_p2_0,
  136914. NULL,
  136915. &_vq_auxt__44u8_p2_0,
  136916. NULL,
  136917. 0
  136918. };
  136919. static long _vq_quantlist__44u8_p3_0[] = {
  136920. 4,
  136921. 3,
  136922. 5,
  136923. 2,
  136924. 6,
  136925. 1,
  136926. 7,
  136927. 0,
  136928. 8,
  136929. };
  136930. static long _vq_lengthlist__44u8_p3_0[] = {
  136931. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136932. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136933. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136934. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136935. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136936. 12,
  136937. };
  136938. static float _vq_quantthresh__44u8_p3_0[] = {
  136939. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136940. };
  136941. static long _vq_quantmap__44u8_p3_0[] = {
  136942. 7, 5, 3, 1, 0, 2, 4, 6,
  136943. 8,
  136944. };
  136945. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136946. _vq_quantthresh__44u8_p3_0,
  136947. _vq_quantmap__44u8_p3_0,
  136948. 9,
  136949. 9
  136950. };
  136951. static static_codebook _44u8_p3_0 = {
  136952. 2, 81,
  136953. _vq_lengthlist__44u8_p3_0,
  136954. 1, -531628032, 1611661312, 4, 0,
  136955. _vq_quantlist__44u8_p3_0,
  136956. NULL,
  136957. &_vq_auxt__44u8_p3_0,
  136958. NULL,
  136959. 0
  136960. };
  136961. static long _vq_quantlist__44u8_p4_0[] = {
  136962. 8,
  136963. 7,
  136964. 9,
  136965. 6,
  136966. 10,
  136967. 5,
  136968. 11,
  136969. 4,
  136970. 12,
  136971. 3,
  136972. 13,
  136973. 2,
  136974. 14,
  136975. 1,
  136976. 15,
  136977. 0,
  136978. 16,
  136979. };
  136980. static long _vq_lengthlist__44u8_p4_0[] = {
  136981. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136982. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136983. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136984. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136985. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136986. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136987. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136988. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136989. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136990. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136991. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136992. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136993. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136994. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136995. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136996. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136997. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136998. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136999. 14,
  137000. };
  137001. static float _vq_quantthresh__44u8_p4_0[] = {
  137002. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137003. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137004. };
  137005. static long _vq_quantmap__44u8_p4_0[] = {
  137006. 15, 13, 11, 9, 7, 5, 3, 1,
  137007. 0, 2, 4, 6, 8, 10, 12, 14,
  137008. 16,
  137009. };
  137010. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  137011. _vq_quantthresh__44u8_p4_0,
  137012. _vq_quantmap__44u8_p4_0,
  137013. 17,
  137014. 17
  137015. };
  137016. static static_codebook _44u8_p4_0 = {
  137017. 2, 289,
  137018. _vq_lengthlist__44u8_p4_0,
  137019. 1, -529530880, 1611661312, 5, 0,
  137020. _vq_quantlist__44u8_p4_0,
  137021. NULL,
  137022. &_vq_auxt__44u8_p4_0,
  137023. NULL,
  137024. 0
  137025. };
  137026. static long _vq_quantlist__44u8_p5_0[] = {
  137027. 1,
  137028. 0,
  137029. 2,
  137030. };
  137031. static long _vq_lengthlist__44u8_p5_0[] = {
  137032. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137033. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137034. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  137035. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137036. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137037. 10,
  137038. };
  137039. static float _vq_quantthresh__44u8_p5_0[] = {
  137040. -5.5, 5.5,
  137041. };
  137042. static long _vq_quantmap__44u8_p5_0[] = {
  137043. 1, 0, 2,
  137044. };
  137045. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  137046. _vq_quantthresh__44u8_p5_0,
  137047. _vq_quantmap__44u8_p5_0,
  137048. 3,
  137049. 3
  137050. };
  137051. static static_codebook _44u8_p5_0 = {
  137052. 4, 81,
  137053. _vq_lengthlist__44u8_p5_0,
  137054. 1, -529137664, 1618345984, 2, 0,
  137055. _vq_quantlist__44u8_p5_0,
  137056. NULL,
  137057. &_vq_auxt__44u8_p5_0,
  137058. NULL,
  137059. 0
  137060. };
  137061. static long _vq_quantlist__44u8_p5_1[] = {
  137062. 5,
  137063. 4,
  137064. 6,
  137065. 3,
  137066. 7,
  137067. 2,
  137068. 8,
  137069. 1,
  137070. 9,
  137071. 0,
  137072. 10,
  137073. };
  137074. static long _vq_lengthlist__44u8_p5_1[] = {
  137075. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  137076. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  137077. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  137078. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137079. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  137080. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  137081. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  137082. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  137083. };
  137084. static float _vq_quantthresh__44u8_p5_1[] = {
  137085. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137086. 3.5, 4.5,
  137087. };
  137088. static long _vq_quantmap__44u8_p5_1[] = {
  137089. 9, 7, 5, 3, 1, 0, 2, 4,
  137090. 6, 8, 10,
  137091. };
  137092. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  137093. _vq_quantthresh__44u8_p5_1,
  137094. _vq_quantmap__44u8_p5_1,
  137095. 11,
  137096. 11
  137097. };
  137098. static static_codebook _44u8_p5_1 = {
  137099. 2, 121,
  137100. _vq_lengthlist__44u8_p5_1,
  137101. 1, -531365888, 1611661312, 4, 0,
  137102. _vq_quantlist__44u8_p5_1,
  137103. NULL,
  137104. &_vq_auxt__44u8_p5_1,
  137105. NULL,
  137106. 0
  137107. };
  137108. static long _vq_quantlist__44u8_p6_0[] = {
  137109. 6,
  137110. 5,
  137111. 7,
  137112. 4,
  137113. 8,
  137114. 3,
  137115. 9,
  137116. 2,
  137117. 10,
  137118. 1,
  137119. 11,
  137120. 0,
  137121. 12,
  137122. };
  137123. static long _vq_lengthlist__44u8_p6_0[] = {
  137124. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137125. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137126. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137127. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137128. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137129. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137130. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137131. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137132. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137133. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137134. 11,11,11,11,11,12,11,12,12,
  137135. };
  137136. static float _vq_quantthresh__44u8_p6_0[] = {
  137137. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137138. 12.5, 17.5, 22.5, 27.5,
  137139. };
  137140. static long _vq_quantmap__44u8_p6_0[] = {
  137141. 11, 9, 7, 5, 3, 1, 0, 2,
  137142. 4, 6, 8, 10, 12,
  137143. };
  137144. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137145. _vq_quantthresh__44u8_p6_0,
  137146. _vq_quantmap__44u8_p6_0,
  137147. 13,
  137148. 13
  137149. };
  137150. static static_codebook _44u8_p6_0 = {
  137151. 2, 169,
  137152. _vq_lengthlist__44u8_p6_0,
  137153. 1, -526516224, 1616117760, 4, 0,
  137154. _vq_quantlist__44u8_p6_0,
  137155. NULL,
  137156. &_vq_auxt__44u8_p6_0,
  137157. NULL,
  137158. 0
  137159. };
  137160. static long _vq_quantlist__44u8_p6_1[] = {
  137161. 2,
  137162. 1,
  137163. 3,
  137164. 0,
  137165. 4,
  137166. };
  137167. static long _vq_lengthlist__44u8_p6_1[] = {
  137168. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137169. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137170. };
  137171. static float _vq_quantthresh__44u8_p6_1[] = {
  137172. -1.5, -0.5, 0.5, 1.5,
  137173. };
  137174. static long _vq_quantmap__44u8_p6_1[] = {
  137175. 3, 1, 0, 2, 4,
  137176. };
  137177. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137178. _vq_quantthresh__44u8_p6_1,
  137179. _vq_quantmap__44u8_p6_1,
  137180. 5,
  137181. 5
  137182. };
  137183. static static_codebook _44u8_p6_1 = {
  137184. 2, 25,
  137185. _vq_lengthlist__44u8_p6_1,
  137186. 1, -533725184, 1611661312, 3, 0,
  137187. _vq_quantlist__44u8_p6_1,
  137188. NULL,
  137189. &_vq_auxt__44u8_p6_1,
  137190. NULL,
  137191. 0
  137192. };
  137193. static long _vq_quantlist__44u8_p7_0[] = {
  137194. 6,
  137195. 5,
  137196. 7,
  137197. 4,
  137198. 8,
  137199. 3,
  137200. 9,
  137201. 2,
  137202. 10,
  137203. 1,
  137204. 11,
  137205. 0,
  137206. 12,
  137207. };
  137208. static long _vq_lengthlist__44u8_p7_0[] = {
  137209. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137210. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137211. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137212. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137213. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137214. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137215. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137216. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137217. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137218. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137219. 13,13,14,14,14,15,15,15,16,
  137220. };
  137221. static float _vq_quantthresh__44u8_p7_0[] = {
  137222. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137223. 27.5, 38.5, 49.5, 60.5,
  137224. };
  137225. static long _vq_quantmap__44u8_p7_0[] = {
  137226. 11, 9, 7, 5, 3, 1, 0, 2,
  137227. 4, 6, 8, 10, 12,
  137228. };
  137229. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137230. _vq_quantthresh__44u8_p7_0,
  137231. _vq_quantmap__44u8_p7_0,
  137232. 13,
  137233. 13
  137234. };
  137235. static static_codebook _44u8_p7_0 = {
  137236. 2, 169,
  137237. _vq_lengthlist__44u8_p7_0,
  137238. 1, -523206656, 1618345984, 4, 0,
  137239. _vq_quantlist__44u8_p7_0,
  137240. NULL,
  137241. &_vq_auxt__44u8_p7_0,
  137242. NULL,
  137243. 0
  137244. };
  137245. static long _vq_quantlist__44u8_p7_1[] = {
  137246. 5,
  137247. 4,
  137248. 6,
  137249. 3,
  137250. 7,
  137251. 2,
  137252. 8,
  137253. 1,
  137254. 9,
  137255. 0,
  137256. 10,
  137257. };
  137258. static long _vq_lengthlist__44u8_p7_1[] = {
  137259. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137260. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137261. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137262. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137263. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137264. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137265. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137266. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137267. };
  137268. static float _vq_quantthresh__44u8_p7_1[] = {
  137269. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137270. 3.5, 4.5,
  137271. };
  137272. static long _vq_quantmap__44u8_p7_1[] = {
  137273. 9, 7, 5, 3, 1, 0, 2, 4,
  137274. 6, 8, 10,
  137275. };
  137276. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137277. _vq_quantthresh__44u8_p7_1,
  137278. _vq_quantmap__44u8_p7_1,
  137279. 11,
  137280. 11
  137281. };
  137282. static static_codebook _44u8_p7_1 = {
  137283. 2, 121,
  137284. _vq_lengthlist__44u8_p7_1,
  137285. 1, -531365888, 1611661312, 4, 0,
  137286. _vq_quantlist__44u8_p7_1,
  137287. NULL,
  137288. &_vq_auxt__44u8_p7_1,
  137289. NULL,
  137290. 0
  137291. };
  137292. static long _vq_quantlist__44u8_p8_0[] = {
  137293. 7,
  137294. 6,
  137295. 8,
  137296. 5,
  137297. 9,
  137298. 4,
  137299. 10,
  137300. 3,
  137301. 11,
  137302. 2,
  137303. 12,
  137304. 1,
  137305. 13,
  137306. 0,
  137307. 14,
  137308. };
  137309. static long _vq_lengthlist__44u8_p8_0[] = {
  137310. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137311. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137312. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137313. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137314. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137315. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137316. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137317. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137318. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137319. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137320. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137321. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137322. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137323. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137324. 17,
  137325. };
  137326. static float _vq_quantthresh__44u8_p8_0[] = {
  137327. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137328. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137329. };
  137330. static long _vq_quantmap__44u8_p8_0[] = {
  137331. 13, 11, 9, 7, 5, 3, 1, 0,
  137332. 2, 4, 6, 8, 10, 12, 14,
  137333. };
  137334. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137335. _vq_quantthresh__44u8_p8_0,
  137336. _vq_quantmap__44u8_p8_0,
  137337. 15,
  137338. 15
  137339. };
  137340. static static_codebook _44u8_p8_0 = {
  137341. 2, 225,
  137342. _vq_lengthlist__44u8_p8_0,
  137343. 1, -520986624, 1620377600, 4, 0,
  137344. _vq_quantlist__44u8_p8_0,
  137345. NULL,
  137346. &_vq_auxt__44u8_p8_0,
  137347. NULL,
  137348. 0
  137349. };
  137350. static long _vq_quantlist__44u8_p8_1[] = {
  137351. 10,
  137352. 9,
  137353. 11,
  137354. 8,
  137355. 12,
  137356. 7,
  137357. 13,
  137358. 6,
  137359. 14,
  137360. 5,
  137361. 15,
  137362. 4,
  137363. 16,
  137364. 3,
  137365. 17,
  137366. 2,
  137367. 18,
  137368. 1,
  137369. 19,
  137370. 0,
  137371. 20,
  137372. };
  137373. static long _vq_lengthlist__44u8_p8_1[] = {
  137374. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137375. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137376. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137377. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137378. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137379. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137380. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137381. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137382. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137383. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137384. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137385. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137386. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137387. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137388. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137389. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137390. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137391. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137392. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137393. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137394. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137395. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137396. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137397. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137398. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137399. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137400. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137401. 10,10,10,10,10,10,10,10,10,
  137402. };
  137403. static float _vq_quantthresh__44u8_p8_1[] = {
  137404. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137405. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137406. 6.5, 7.5, 8.5, 9.5,
  137407. };
  137408. static long _vq_quantmap__44u8_p8_1[] = {
  137409. 19, 17, 15, 13, 11, 9, 7, 5,
  137410. 3, 1, 0, 2, 4, 6, 8, 10,
  137411. 12, 14, 16, 18, 20,
  137412. };
  137413. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137414. _vq_quantthresh__44u8_p8_1,
  137415. _vq_quantmap__44u8_p8_1,
  137416. 21,
  137417. 21
  137418. };
  137419. static static_codebook _44u8_p8_1 = {
  137420. 2, 441,
  137421. _vq_lengthlist__44u8_p8_1,
  137422. 1, -529268736, 1611661312, 5, 0,
  137423. _vq_quantlist__44u8_p8_1,
  137424. NULL,
  137425. &_vq_auxt__44u8_p8_1,
  137426. NULL,
  137427. 0
  137428. };
  137429. static long _vq_quantlist__44u8_p9_0[] = {
  137430. 4,
  137431. 3,
  137432. 5,
  137433. 2,
  137434. 6,
  137435. 1,
  137436. 7,
  137437. 0,
  137438. 8,
  137439. };
  137440. static long _vq_lengthlist__44u8_p9_0[] = {
  137441. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137442. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137443. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137444. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137445. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137446. 8,
  137447. };
  137448. static float _vq_quantthresh__44u8_p9_0[] = {
  137449. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137450. };
  137451. static long _vq_quantmap__44u8_p9_0[] = {
  137452. 7, 5, 3, 1, 0, 2, 4, 6,
  137453. 8,
  137454. };
  137455. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137456. _vq_quantthresh__44u8_p9_0,
  137457. _vq_quantmap__44u8_p9_0,
  137458. 9,
  137459. 9
  137460. };
  137461. static static_codebook _44u8_p9_0 = {
  137462. 2, 81,
  137463. _vq_lengthlist__44u8_p9_0,
  137464. 1, -511895552, 1631393792, 4, 0,
  137465. _vq_quantlist__44u8_p9_0,
  137466. NULL,
  137467. &_vq_auxt__44u8_p9_0,
  137468. NULL,
  137469. 0
  137470. };
  137471. static long _vq_quantlist__44u8_p9_1[] = {
  137472. 9,
  137473. 8,
  137474. 10,
  137475. 7,
  137476. 11,
  137477. 6,
  137478. 12,
  137479. 5,
  137480. 13,
  137481. 4,
  137482. 14,
  137483. 3,
  137484. 15,
  137485. 2,
  137486. 16,
  137487. 1,
  137488. 17,
  137489. 0,
  137490. 18,
  137491. };
  137492. static long _vq_lengthlist__44u8_p9_1[] = {
  137493. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137494. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137495. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137496. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137497. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137498. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137499. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137500. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137501. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137502. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137503. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137504. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137505. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137506. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137507. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137508. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137509. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137510. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137511. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137512. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137513. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137514. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137515. 16,15,16,16,16,16,16,16,16,
  137516. };
  137517. static float _vq_quantthresh__44u8_p9_1[] = {
  137518. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137519. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137520. 367.5, 416.5,
  137521. };
  137522. static long _vq_quantmap__44u8_p9_1[] = {
  137523. 17, 15, 13, 11, 9, 7, 5, 3,
  137524. 1, 0, 2, 4, 6, 8, 10, 12,
  137525. 14, 16, 18,
  137526. };
  137527. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137528. _vq_quantthresh__44u8_p9_1,
  137529. _vq_quantmap__44u8_p9_1,
  137530. 19,
  137531. 19
  137532. };
  137533. static static_codebook _44u8_p9_1 = {
  137534. 2, 361,
  137535. _vq_lengthlist__44u8_p9_1,
  137536. 1, -518287360, 1622704128, 5, 0,
  137537. _vq_quantlist__44u8_p9_1,
  137538. NULL,
  137539. &_vq_auxt__44u8_p9_1,
  137540. NULL,
  137541. 0
  137542. };
  137543. static long _vq_quantlist__44u8_p9_2[] = {
  137544. 24,
  137545. 23,
  137546. 25,
  137547. 22,
  137548. 26,
  137549. 21,
  137550. 27,
  137551. 20,
  137552. 28,
  137553. 19,
  137554. 29,
  137555. 18,
  137556. 30,
  137557. 17,
  137558. 31,
  137559. 16,
  137560. 32,
  137561. 15,
  137562. 33,
  137563. 14,
  137564. 34,
  137565. 13,
  137566. 35,
  137567. 12,
  137568. 36,
  137569. 11,
  137570. 37,
  137571. 10,
  137572. 38,
  137573. 9,
  137574. 39,
  137575. 8,
  137576. 40,
  137577. 7,
  137578. 41,
  137579. 6,
  137580. 42,
  137581. 5,
  137582. 43,
  137583. 4,
  137584. 44,
  137585. 3,
  137586. 45,
  137587. 2,
  137588. 46,
  137589. 1,
  137590. 47,
  137591. 0,
  137592. 48,
  137593. };
  137594. static long _vq_lengthlist__44u8_p9_2[] = {
  137595. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137596. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137597. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137598. 7,
  137599. };
  137600. static float _vq_quantthresh__44u8_p9_2[] = {
  137601. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137602. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137603. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137604. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137605. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137606. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137607. };
  137608. static long _vq_quantmap__44u8_p9_2[] = {
  137609. 47, 45, 43, 41, 39, 37, 35, 33,
  137610. 31, 29, 27, 25, 23, 21, 19, 17,
  137611. 15, 13, 11, 9, 7, 5, 3, 1,
  137612. 0, 2, 4, 6, 8, 10, 12, 14,
  137613. 16, 18, 20, 22, 24, 26, 28, 30,
  137614. 32, 34, 36, 38, 40, 42, 44, 46,
  137615. 48,
  137616. };
  137617. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137618. _vq_quantthresh__44u8_p9_2,
  137619. _vq_quantmap__44u8_p9_2,
  137620. 49,
  137621. 49
  137622. };
  137623. static static_codebook _44u8_p9_2 = {
  137624. 1, 49,
  137625. _vq_lengthlist__44u8_p9_2,
  137626. 1, -526909440, 1611661312, 6, 0,
  137627. _vq_quantlist__44u8_p9_2,
  137628. NULL,
  137629. &_vq_auxt__44u8_p9_2,
  137630. NULL,
  137631. 0
  137632. };
  137633. static long _huff_lengthlist__44u9__long[] = {
  137634. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137635. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137636. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137637. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137638. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137639. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137640. 10, 8, 8, 9,
  137641. };
  137642. static static_codebook _huff_book__44u9__long = {
  137643. 2, 100,
  137644. _huff_lengthlist__44u9__long,
  137645. 0, 0, 0, 0, 0,
  137646. NULL,
  137647. NULL,
  137648. NULL,
  137649. NULL,
  137650. 0
  137651. };
  137652. static long _huff_lengthlist__44u9__short[] = {
  137653. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137654. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137655. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137656. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137657. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137658. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137659. 9, 9,12,15,
  137660. };
  137661. static static_codebook _huff_book__44u9__short = {
  137662. 2, 100,
  137663. _huff_lengthlist__44u9__short,
  137664. 0, 0, 0, 0, 0,
  137665. NULL,
  137666. NULL,
  137667. NULL,
  137668. NULL,
  137669. 0
  137670. };
  137671. static long _vq_quantlist__44u9_p1_0[] = {
  137672. 1,
  137673. 0,
  137674. 2,
  137675. };
  137676. static long _vq_lengthlist__44u9_p1_0[] = {
  137677. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137678. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137679. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137680. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137681. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137682. 10,
  137683. };
  137684. static float _vq_quantthresh__44u9_p1_0[] = {
  137685. -0.5, 0.5,
  137686. };
  137687. static long _vq_quantmap__44u9_p1_0[] = {
  137688. 1, 0, 2,
  137689. };
  137690. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137691. _vq_quantthresh__44u9_p1_0,
  137692. _vq_quantmap__44u9_p1_0,
  137693. 3,
  137694. 3
  137695. };
  137696. static static_codebook _44u9_p1_0 = {
  137697. 4, 81,
  137698. _vq_lengthlist__44u9_p1_0,
  137699. 1, -535822336, 1611661312, 2, 0,
  137700. _vq_quantlist__44u9_p1_0,
  137701. NULL,
  137702. &_vq_auxt__44u9_p1_0,
  137703. NULL,
  137704. 0
  137705. };
  137706. static long _vq_quantlist__44u9_p2_0[] = {
  137707. 2,
  137708. 1,
  137709. 3,
  137710. 0,
  137711. 4,
  137712. };
  137713. static long _vq_lengthlist__44u9_p2_0[] = {
  137714. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137715. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137716. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137717. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137718. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137719. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137720. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137721. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137722. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137723. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137724. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137725. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137726. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137727. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137728. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137729. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137730. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137731. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137732. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137733. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137734. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137735. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137736. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137737. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137738. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137739. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137740. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137741. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137742. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137743. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137744. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137745. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137746. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137747. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137748. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137749. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137750. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137751. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137752. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137753. 14,
  137754. };
  137755. static float _vq_quantthresh__44u9_p2_0[] = {
  137756. -1.5, -0.5, 0.5, 1.5,
  137757. };
  137758. static long _vq_quantmap__44u9_p2_0[] = {
  137759. 3, 1, 0, 2, 4,
  137760. };
  137761. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137762. _vq_quantthresh__44u9_p2_0,
  137763. _vq_quantmap__44u9_p2_0,
  137764. 5,
  137765. 5
  137766. };
  137767. static static_codebook _44u9_p2_0 = {
  137768. 4, 625,
  137769. _vq_lengthlist__44u9_p2_0,
  137770. 1, -533725184, 1611661312, 3, 0,
  137771. _vq_quantlist__44u9_p2_0,
  137772. NULL,
  137773. &_vq_auxt__44u9_p2_0,
  137774. NULL,
  137775. 0
  137776. };
  137777. static long _vq_quantlist__44u9_p3_0[] = {
  137778. 4,
  137779. 3,
  137780. 5,
  137781. 2,
  137782. 6,
  137783. 1,
  137784. 7,
  137785. 0,
  137786. 8,
  137787. };
  137788. static long _vq_lengthlist__44u9_p3_0[] = {
  137789. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137790. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137791. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137792. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137793. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137794. 11,
  137795. };
  137796. static float _vq_quantthresh__44u9_p3_0[] = {
  137797. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137798. };
  137799. static long _vq_quantmap__44u9_p3_0[] = {
  137800. 7, 5, 3, 1, 0, 2, 4, 6,
  137801. 8,
  137802. };
  137803. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137804. _vq_quantthresh__44u9_p3_0,
  137805. _vq_quantmap__44u9_p3_0,
  137806. 9,
  137807. 9
  137808. };
  137809. static static_codebook _44u9_p3_0 = {
  137810. 2, 81,
  137811. _vq_lengthlist__44u9_p3_0,
  137812. 1, -531628032, 1611661312, 4, 0,
  137813. _vq_quantlist__44u9_p3_0,
  137814. NULL,
  137815. &_vq_auxt__44u9_p3_0,
  137816. NULL,
  137817. 0
  137818. };
  137819. static long _vq_quantlist__44u9_p4_0[] = {
  137820. 8,
  137821. 7,
  137822. 9,
  137823. 6,
  137824. 10,
  137825. 5,
  137826. 11,
  137827. 4,
  137828. 12,
  137829. 3,
  137830. 13,
  137831. 2,
  137832. 14,
  137833. 1,
  137834. 15,
  137835. 0,
  137836. 16,
  137837. };
  137838. static long _vq_lengthlist__44u9_p4_0[] = {
  137839. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137840. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137841. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137842. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137843. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137844. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137845. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137846. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137847. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137848. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137849. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137850. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137851. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137852. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137853. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137854. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137855. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137856. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137857. 14,
  137858. };
  137859. static float _vq_quantthresh__44u9_p4_0[] = {
  137860. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137861. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137862. };
  137863. static long _vq_quantmap__44u9_p4_0[] = {
  137864. 15, 13, 11, 9, 7, 5, 3, 1,
  137865. 0, 2, 4, 6, 8, 10, 12, 14,
  137866. 16,
  137867. };
  137868. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137869. _vq_quantthresh__44u9_p4_0,
  137870. _vq_quantmap__44u9_p4_0,
  137871. 17,
  137872. 17
  137873. };
  137874. static static_codebook _44u9_p4_0 = {
  137875. 2, 289,
  137876. _vq_lengthlist__44u9_p4_0,
  137877. 1, -529530880, 1611661312, 5, 0,
  137878. _vq_quantlist__44u9_p4_0,
  137879. NULL,
  137880. &_vq_auxt__44u9_p4_0,
  137881. NULL,
  137882. 0
  137883. };
  137884. static long _vq_quantlist__44u9_p5_0[] = {
  137885. 1,
  137886. 0,
  137887. 2,
  137888. };
  137889. static long _vq_lengthlist__44u9_p5_0[] = {
  137890. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137891. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137892. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137893. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137894. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137895. 10,
  137896. };
  137897. static float _vq_quantthresh__44u9_p5_0[] = {
  137898. -5.5, 5.5,
  137899. };
  137900. static long _vq_quantmap__44u9_p5_0[] = {
  137901. 1, 0, 2,
  137902. };
  137903. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137904. _vq_quantthresh__44u9_p5_0,
  137905. _vq_quantmap__44u9_p5_0,
  137906. 3,
  137907. 3
  137908. };
  137909. static static_codebook _44u9_p5_0 = {
  137910. 4, 81,
  137911. _vq_lengthlist__44u9_p5_0,
  137912. 1, -529137664, 1618345984, 2, 0,
  137913. _vq_quantlist__44u9_p5_0,
  137914. NULL,
  137915. &_vq_auxt__44u9_p5_0,
  137916. NULL,
  137917. 0
  137918. };
  137919. static long _vq_quantlist__44u9_p5_1[] = {
  137920. 5,
  137921. 4,
  137922. 6,
  137923. 3,
  137924. 7,
  137925. 2,
  137926. 8,
  137927. 1,
  137928. 9,
  137929. 0,
  137930. 10,
  137931. };
  137932. static long _vq_lengthlist__44u9_p5_1[] = {
  137933. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137934. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137935. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137936. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137937. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137938. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137939. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137940. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137941. };
  137942. static float _vq_quantthresh__44u9_p5_1[] = {
  137943. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137944. 3.5, 4.5,
  137945. };
  137946. static long _vq_quantmap__44u9_p5_1[] = {
  137947. 9, 7, 5, 3, 1, 0, 2, 4,
  137948. 6, 8, 10,
  137949. };
  137950. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137951. _vq_quantthresh__44u9_p5_1,
  137952. _vq_quantmap__44u9_p5_1,
  137953. 11,
  137954. 11
  137955. };
  137956. static static_codebook _44u9_p5_1 = {
  137957. 2, 121,
  137958. _vq_lengthlist__44u9_p5_1,
  137959. 1, -531365888, 1611661312, 4, 0,
  137960. _vq_quantlist__44u9_p5_1,
  137961. NULL,
  137962. &_vq_auxt__44u9_p5_1,
  137963. NULL,
  137964. 0
  137965. };
  137966. static long _vq_quantlist__44u9_p6_0[] = {
  137967. 6,
  137968. 5,
  137969. 7,
  137970. 4,
  137971. 8,
  137972. 3,
  137973. 9,
  137974. 2,
  137975. 10,
  137976. 1,
  137977. 11,
  137978. 0,
  137979. 12,
  137980. };
  137981. static long _vq_lengthlist__44u9_p6_0[] = {
  137982. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137983. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137984. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137985. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137986. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137987. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137988. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137989. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137990. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137991. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137992. 10,11,11,11,11,12,11,12,12,
  137993. };
  137994. static float _vq_quantthresh__44u9_p6_0[] = {
  137995. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137996. 12.5, 17.5, 22.5, 27.5,
  137997. };
  137998. static long _vq_quantmap__44u9_p6_0[] = {
  137999. 11, 9, 7, 5, 3, 1, 0, 2,
  138000. 4, 6, 8, 10, 12,
  138001. };
  138002. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  138003. _vq_quantthresh__44u9_p6_0,
  138004. _vq_quantmap__44u9_p6_0,
  138005. 13,
  138006. 13
  138007. };
  138008. static static_codebook _44u9_p6_0 = {
  138009. 2, 169,
  138010. _vq_lengthlist__44u9_p6_0,
  138011. 1, -526516224, 1616117760, 4, 0,
  138012. _vq_quantlist__44u9_p6_0,
  138013. NULL,
  138014. &_vq_auxt__44u9_p6_0,
  138015. NULL,
  138016. 0
  138017. };
  138018. static long _vq_quantlist__44u9_p6_1[] = {
  138019. 2,
  138020. 1,
  138021. 3,
  138022. 0,
  138023. 4,
  138024. };
  138025. static long _vq_lengthlist__44u9_p6_1[] = {
  138026. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  138027. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  138028. };
  138029. static float _vq_quantthresh__44u9_p6_1[] = {
  138030. -1.5, -0.5, 0.5, 1.5,
  138031. };
  138032. static long _vq_quantmap__44u9_p6_1[] = {
  138033. 3, 1, 0, 2, 4,
  138034. };
  138035. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  138036. _vq_quantthresh__44u9_p6_1,
  138037. _vq_quantmap__44u9_p6_1,
  138038. 5,
  138039. 5
  138040. };
  138041. static static_codebook _44u9_p6_1 = {
  138042. 2, 25,
  138043. _vq_lengthlist__44u9_p6_1,
  138044. 1, -533725184, 1611661312, 3, 0,
  138045. _vq_quantlist__44u9_p6_1,
  138046. NULL,
  138047. &_vq_auxt__44u9_p6_1,
  138048. NULL,
  138049. 0
  138050. };
  138051. static long _vq_quantlist__44u9_p7_0[] = {
  138052. 6,
  138053. 5,
  138054. 7,
  138055. 4,
  138056. 8,
  138057. 3,
  138058. 9,
  138059. 2,
  138060. 10,
  138061. 1,
  138062. 11,
  138063. 0,
  138064. 12,
  138065. };
  138066. static long _vq_lengthlist__44u9_p7_0[] = {
  138067. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  138068. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  138069. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  138070. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  138071. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  138072. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  138073. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  138074. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  138075. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  138076. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  138077. 12,13,13,14,14,14,15,15,15,
  138078. };
  138079. static float _vq_quantthresh__44u9_p7_0[] = {
  138080. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  138081. 27.5, 38.5, 49.5, 60.5,
  138082. };
  138083. static long _vq_quantmap__44u9_p7_0[] = {
  138084. 11, 9, 7, 5, 3, 1, 0, 2,
  138085. 4, 6, 8, 10, 12,
  138086. };
  138087. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  138088. _vq_quantthresh__44u9_p7_0,
  138089. _vq_quantmap__44u9_p7_0,
  138090. 13,
  138091. 13
  138092. };
  138093. static static_codebook _44u9_p7_0 = {
  138094. 2, 169,
  138095. _vq_lengthlist__44u9_p7_0,
  138096. 1, -523206656, 1618345984, 4, 0,
  138097. _vq_quantlist__44u9_p7_0,
  138098. NULL,
  138099. &_vq_auxt__44u9_p7_0,
  138100. NULL,
  138101. 0
  138102. };
  138103. static long _vq_quantlist__44u9_p7_1[] = {
  138104. 5,
  138105. 4,
  138106. 6,
  138107. 3,
  138108. 7,
  138109. 2,
  138110. 8,
  138111. 1,
  138112. 9,
  138113. 0,
  138114. 10,
  138115. };
  138116. static long _vq_lengthlist__44u9_p7_1[] = {
  138117. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138118. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138119. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138120. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138121. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138122. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138123. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138124. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138125. };
  138126. static float _vq_quantthresh__44u9_p7_1[] = {
  138127. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138128. 3.5, 4.5,
  138129. };
  138130. static long _vq_quantmap__44u9_p7_1[] = {
  138131. 9, 7, 5, 3, 1, 0, 2, 4,
  138132. 6, 8, 10,
  138133. };
  138134. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138135. _vq_quantthresh__44u9_p7_1,
  138136. _vq_quantmap__44u9_p7_1,
  138137. 11,
  138138. 11
  138139. };
  138140. static static_codebook _44u9_p7_1 = {
  138141. 2, 121,
  138142. _vq_lengthlist__44u9_p7_1,
  138143. 1, -531365888, 1611661312, 4, 0,
  138144. _vq_quantlist__44u9_p7_1,
  138145. NULL,
  138146. &_vq_auxt__44u9_p7_1,
  138147. NULL,
  138148. 0
  138149. };
  138150. static long _vq_quantlist__44u9_p8_0[] = {
  138151. 7,
  138152. 6,
  138153. 8,
  138154. 5,
  138155. 9,
  138156. 4,
  138157. 10,
  138158. 3,
  138159. 11,
  138160. 2,
  138161. 12,
  138162. 1,
  138163. 13,
  138164. 0,
  138165. 14,
  138166. };
  138167. static long _vq_lengthlist__44u9_p8_0[] = {
  138168. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138169. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138170. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138171. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138172. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138173. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138174. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138175. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138176. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138177. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138178. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138179. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138180. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138181. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138182. 15,
  138183. };
  138184. static float _vq_quantthresh__44u9_p8_0[] = {
  138185. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138186. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138187. };
  138188. static long _vq_quantmap__44u9_p8_0[] = {
  138189. 13, 11, 9, 7, 5, 3, 1, 0,
  138190. 2, 4, 6, 8, 10, 12, 14,
  138191. };
  138192. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138193. _vq_quantthresh__44u9_p8_0,
  138194. _vq_quantmap__44u9_p8_0,
  138195. 15,
  138196. 15
  138197. };
  138198. static static_codebook _44u9_p8_0 = {
  138199. 2, 225,
  138200. _vq_lengthlist__44u9_p8_0,
  138201. 1, -520986624, 1620377600, 4, 0,
  138202. _vq_quantlist__44u9_p8_0,
  138203. NULL,
  138204. &_vq_auxt__44u9_p8_0,
  138205. NULL,
  138206. 0
  138207. };
  138208. static long _vq_quantlist__44u9_p8_1[] = {
  138209. 10,
  138210. 9,
  138211. 11,
  138212. 8,
  138213. 12,
  138214. 7,
  138215. 13,
  138216. 6,
  138217. 14,
  138218. 5,
  138219. 15,
  138220. 4,
  138221. 16,
  138222. 3,
  138223. 17,
  138224. 2,
  138225. 18,
  138226. 1,
  138227. 19,
  138228. 0,
  138229. 20,
  138230. };
  138231. static long _vq_lengthlist__44u9_p8_1[] = {
  138232. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138233. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138234. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138235. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138236. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138237. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138238. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138239. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138240. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138241. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138242. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138243. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138244. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138245. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138246. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138247. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138248. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138249. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138250. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138251. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138252. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138253. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138254. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138255. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138256. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138257. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138258. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138259. 10,10,10,10,10,10,10,10,10,
  138260. };
  138261. static float _vq_quantthresh__44u9_p8_1[] = {
  138262. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138263. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138264. 6.5, 7.5, 8.5, 9.5,
  138265. };
  138266. static long _vq_quantmap__44u9_p8_1[] = {
  138267. 19, 17, 15, 13, 11, 9, 7, 5,
  138268. 3, 1, 0, 2, 4, 6, 8, 10,
  138269. 12, 14, 16, 18, 20,
  138270. };
  138271. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138272. _vq_quantthresh__44u9_p8_1,
  138273. _vq_quantmap__44u9_p8_1,
  138274. 21,
  138275. 21
  138276. };
  138277. static static_codebook _44u9_p8_1 = {
  138278. 2, 441,
  138279. _vq_lengthlist__44u9_p8_1,
  138280. 1, -529268736, 1611661312, 5, 0,
  138281. _vq_quantlist__44u9_p8_1,
  138282. NULL,
  138283. &_vq_auxt__44u9_p8_1,
  138284. NULL,
  138285. 0
  138286. };
  138287. static long _vq_quantlist__44u9_p9_0[] = {
  138288. 7,
  138289. 6,
  138290. 8,
  138291. 5,
  138292. 9,
  138293. 4,
  138294. 10,
  138295. 3,
  138296. 11,
  138297. 2,
  138298. 12,
  138299. 1,
  138300. 13,
  138301. 0,
  138302. 14,
  138303. };
  138304. static long _vq_lengthlist__44u9_p9_0[] = {
  138305. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138306. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138307. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138308. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138309. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138310. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138311. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138312. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138313. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138314. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138315. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138316. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138317. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138318. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138319. 10,
  138320. };
  138321. static float _vq_quantthresh__44u9_p9_0[] = {
  138322. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138323. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138324. };
  138325. static long _vq_quantmap__44u9_p9_0[] = {
  138326. 13, 11, 9, 7, 5, 3, 1, 0,
  138327. 2, 4, 6, 8, 10, 12, 14,
  138328. };
  138329. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138330. _vq_quantthresh__44u9_p9_0,
  138331. _vq_quantmap__44u9_p9_0,
  138332. 15,
  138333. 15
  138334. };
  138335. static static_codebook _44u9_p9_0 = {
  138336. 2, 225,
  138337. _vq_lengthlist__44u9_p9_0,
  138338. 1, -510036736, 1631393792, 4, 0,
  138339. _vq_quantlist__44u9_p9_0,
  138340. NULL,
  138341. &_vq_auxt__44u9_p9_0,
  138342. NULL,
  138343. 0
  138344. };
  138345. static long _vq_quantlist__44u9_p9_1[] = {
  138346. 9,
  138347. 8,
  138348. 10,
  138349. 7,
  138350. 11,
  138351. 6,
  138352. 12,
  138353. 5,
  138354. 13,
  138355. 4,
  138356. 14,
  138357. 3,
  138358. 15,
  138359. 2,
  138360. 16,
  138361. 1,
  138362. 17,
  138363. 0,
  138364. 18,
  138365. };
  138366. static long _vq_lengthlist__44u9_p9_1[] = {
  138367. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138368. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138369. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138370. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138371. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138372. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138373. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138374. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138375. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138376. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138377. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138378. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138379. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138380. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138381. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138382. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138383. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138384. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138385. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138386. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138387. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138388. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138389. 17,17,15,17,15,17,16,16,17,
  138390. };
  138391. static float _vq_quantthresh__44u9_p9_1[] = {
  138392. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138393. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138394. 367.5, 416.5,
  138395. };
  138396. static long _vq_quantmap__44u9_p9_1[] = {
  138397. 17, 15, 13, 11, 9, 7, 5, 3,
  138398. 1, 0, 2, 4, 6, 8, 10, 12,
  138399. 14, 16, 18,
  138400. };
  138401. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138402. _vq_quantthresh__44u9_p9_1,
  138403. _vq_quantmap__44u9_p9_1,
  138404. 19,
  138405. 19
  138406. };
  138407. static static_codebook _44u9_p9_1 = {
  138408. 2, 361,
  138409. _vq_lengthlist__44u9_p9_1,
  138410. 1, -518287360, 1622704128, 5, 0,
  138411. _vq_quantlist__44u9_p9_1,
  138412. NULL,
  138413. &_vq_auxt__44u9_p9_1,
  138414. NULL,
  138415. 0
  138416. };
  138417. static long _vq_quantlist__44u9_p9_2[] = {
  138418. 24,
  138419. 23,
  138420. 25,
  138421. 22,
  138422. 26,
  138423. 21,
  138424. 27,
  138425. 20,
  138426. 28,
  138427. 19,
  138428. 29,
  138429. 18,
  138430. 30,
  138431. 17,
  138432. 31,
  138433. 16,
  138434. 32,
  138435. 15,
  138436. 33,
  138437. 14,
  138438. 34,
  138439. 13,
  138440. 35,
  138441. 12,
  138442. 36,
  138443. 11,
  138444. 37,
  138445. 10,
  138446. 38,
  138447. 9,
  138448. 39,
  138449. 8,
  138450. 40,
  138451. 7,
  138452. 41,
  138453. 6,
  138454. 42,
  138455. 5,
  138456. 43,
  138457. 4,
  138458. 44,
  138459. 3,
  138460. 45,
  138461. 2,
  138462. 46,
  138463. 1,
  138464. 47,
  138465. 0,
  138466. 48,
  138467. };
  138468. static long _vq_lengthlist__44u9_p9_2[] = {
  138469. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138470. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138471. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138472. 7,
  138473. };
  138474. static float _vq_quantthresh__44u9_p9_2[] = {
  138475. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138476. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138477. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138478. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138479. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138480. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138481. };
  138482. static long _vq_quantmap__44u9_p9_2[] = {
  138483. 47, 45, 43, 41, 39, 37, 35, 33,
  138484. 31, 29, 27, 25, 23, 21, 19, 17,
  138485. 15, 13, 11, 9, 7, 5, 3, 1,
  138486. 0, 2, 4, 6, 8, 10, 12, 14,
  138487. 16, 18, 20, 22, 24, 26, 28, 30,
  138488. 32, 34, 36, 38, 40, 42, 44, 46,
  138489. 48,
  138490. };
  138491. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138492. _vq_quantthresh__44u9_p9_2,
  138493. _vq_quantmap__44u9_p9_2,
  138494. 49,
  138495. 49
  138496. };
  138497. static static_codebook _44u9_p9_2 = {
  138498. 1, 49,
  138499. _vq_lengthlist__44u9_p9_2,
  138500. 1, -526909440, 1611661312, 6, 0,
  138501. _vq_quantlist__44u9_p9_2,
  138502. NULL,
  138503. &_vq_auxt__44u9_p9_2,
  138504. NULL,
  138505. 0
  138506. };
  138507. static long _huff_lengthlist__44un1__long[] = {
  138508. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138509. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138510. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138511. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138512. };
  138513. static static_codebook _huff_book__44un1__long = {
  138514. 2, 64,
  138515. _huff_lengthlist__44un1__long,
  138516. 0, 0, 0, 0, 0,
  138517. NULL,
  138518. NULL,
  138519. NULL,
  138520. NULL,
  138521. 0
  138522. };
  138523. static long _vq_quantlist__44un1__p1_0[] = {
  138524. 1,
  138525. 0,
  138526. 2,
  138527. };
  138528. static long _vq_lengthlist__44un1__p1_0[] = {
  138529. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138530. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138531. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138532. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138533. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138534. 12,
  138535. };
  138536. static float _vq_quantthresh__44un1__p1_0[] = {
  138537. -0.5, 0.5,
  138538. };
  138539. static long _vq_quantmap__44un1__p1_0[] = {
  138540. 1, 0, 2,
  138541. };
  138542. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138543. _vq_quantthresh__44un1__p1_0,
  138544. _vq_quantmap__44un1__p1_0,
  138545. 3,
  138546. 3
  138547. };
  138548. static static_codebook _44un1__p1_0 = {
  138549. 4, 81,
  138550. _vq_lengthlist__44un1__p1_0,
  138551. 1, -535822336, 1611661312, 2, 0,
  138552. _vq_quantlist__44un1__p1_0,
  138553. NULL,
  138554. &_vq_auxt__44un1__p1_0,
  138555. NULL,
  138556. 0
  138557. };
  138558. static long _vq_quantlist__44un1__p2_0[] = {
  138559. 1,
  138560. 0,
  138561. 2,
  138562. };
  138563. static long _vq_lengthlist__44un1__p2_0[] = {
  138564. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138565. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138566. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138567. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138568. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138569. 8,
  138570. };
  138571. static float _vq_quantthresh__44un1__p2_0[] = {
  138572. -0.5, 0.5,
  138573. };
  138574. static long _vq_quantmap__44un1__p2_0[] = {
  138575. 1, 0, 2,
  138576. };
  138577. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138578. _vq_quantthresh__44un1__p2_0,
  138579. _vq_quantmap__44un1__p2_0,
  138580. 3,
  138581. 3
  138582. };
  138583. static static_codebook _44un1__p2_0 = {
  138584. 4, 81,
  138585. _vq_lengthlist__44un1__p2_0,
  138586. 1, -535822336, 1611661312, 2, 0,
  138587. _vq_quantlist__44un1__p2_0,
  138588. NULL,
  138589. &_vq_auxt__44un1__p2_0,
  138590. NULL,
  138591. 0
  138592. };
  138593. static long _vq_quantlist__44un1__p3_0[] = {
  138594. 2,
  138595. 1,
  138596. 3,
  138597. 0,
  138598. 4,
  138599. };
  138600. static long _vq_lengthlist__44un1__p3_0[] = {
  138601. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138602. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138603. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138604. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138605. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138606. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138607. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138608. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138609. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138610. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138611. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138612. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138613. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138614. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138615. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138616. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138617. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138618. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138619. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138620. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138621. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138622. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138623. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138624. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138625. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138626. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138627. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138628. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138629. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138630. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138631. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138632. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138633. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138634. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138635. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138636. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138637. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138638. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138639. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138640. 17,
  138641. };
  138642. static float _vq_quantthresh__44un1__p3_0[] = {
  138643. -1.5, -0.5, 0.5, 1.5,
  138644. };
  138645. static long _vq_quantmap__44un1__p3_0[] = {
  138646. 3, 1, 0, 2, 4,
  138647. };
  138648. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138649. _vq_quantthresh__44un1__p3_0,
  138650. _vq_quantmap__44un1__p3_0,
  138651. 5,
  138652. 5
  138653. };
  138654. static static_codebook _44un1__p3_0 = {
  138655. 4, 625,
  138656. _vq_lengthlist__44un1__p3_0,
  138657. 1, -533725184, 1611661312, 3, 0,
  138658. _vq_quantlist__44un1__p3_0,
  138659. NULL,
  138660. &_vq_auxt__44un1__p3_0,
  138661. NULL,
  138662. 0
  138663. };
  138664. static long _vq_quantlist__44un1__p4_0[] = {
  138665. 2,
  138666. 1,
  138667. 3,
  138668. 0,
  138669. 4,
  138670. };
  138671. static long _vq_lengthlist__44un1__p4_0[] = {
  138672. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138673. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138674. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138675. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138676. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138677. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138678. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138679. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138680. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138681. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138682. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138683. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138684. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138685. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138686. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138687. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138688. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138689. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138690. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138691. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138692. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138693. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138694. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138695. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138696. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138697. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138698. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138699. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138700. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138701. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138702. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138703. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138704. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138705. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138706. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138707. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138708. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138709. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138710. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138711. 12,
  138712. };
  138713. static float _vq_quantthresh__44un1__p4_0[] = {
  138714. -1.5, -0.5, 0.5, 1.5,
  138715. };
  138716. static long _vq_quantmap__44un1__p4_0[] = {
  138717. 3, 1, 0, 2, 4,
  138718. };
  138719. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138720. _vq_quantthresh__44un1__p4_0,
  138721. _vq_quantmap__44un1__p4_0,
  138722. 5,
  138723. 5
  138724. };
  138725. static static_codebook _44un1__p4_0 = {
  138726. 4, 625,
  138727. _vq_lengthlist__44un1__p4_0,
  138728. 1, -533725184, 1611661312, 3, 0,
  138729. _vq_quantlist__44un1__p4_0,
  138730. NULL,
  138731. &_vq_auxt__44un1__p4_0,
  138732. NULL,
  138733. 0
  138734. };
  138735. static long _vq_quantlist__44un1__p5_0[] = {
  138736. 4,
  138737. 3,
  138738. 5,
  138739. 2,
  138740. 6,
  138741. 1,
  138742. 7,
  138743. 0,
  138744. 8,
  138745. };
  138746. static long _vq_lengthlist__44un1__p5_0[] = {
  138747. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138748. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138749. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138750. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138751. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138752. 12,
  138753. };
  138754. static float _vq_quantthresh__44un1__p5_0[] = {
  138755. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138756. };
  138757. static long _vq_quantmap__44un1__p5_0[] = {
  138758. 7, 5, 3, 1, 0, 2, 4, 6,
  138759. 8,
  138760. };
  138761. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138762. _vq_quantthresh__44un1__p5_0,
  138763. _vq_quantmap__44un1__p5_0,
  138764. 9,
  138765. 9
  138766. };
  138767. static static_codebook _44un1__p5_0 = {
  138768. 2, 81,
  138769. _vq_lengthlist__44un1__p5_0,
  138770. 1, -531628032, 1611661312, 4, 0,
  138771. _vq_quantlist__44un1__p5_0,
  138772. NULL,
  138773. &_vq_auxt__44un1__p5_0,
  138774. NULL,
  138775. 0
  138776. };
  138777. static long _vq_quantlist__44un1__p6_0[] = {
  138778. 6,
  138779. 5,
  138780. 7,
  138781. 4,
  138782. 8,
  138783. 3,
  138784. 9,
  138785. 2,
  138786. 10,
  138787. 1,
  138788. 11,
  138789. 0,
  138790. 12,
  138791. };
  138792. static long _vq_lengthlist__44un1__p6_0[] = {
  138793. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138794. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138795. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138796. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138797. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138798. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138799. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138800. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138801. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138802. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138803. 16, 0,15,18,18, 0,16, 0, 0,
  138804. };
  138805. static float _vq_quantthresh__44un1__p6_0[] = {
  138806. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138807. 12.5, 17.5, 22.5, 27.5,
  138808. };
  138809. static long _vq_quantmap__44un1__p6_0[] = {
  138810. 11, 9, 7, 5, 3, 1, 0, 2,
  138811. 4, 6, 8, 10, 12,
  138812. };
  138813. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138814. _vq_quantthresh__44un1__p6_0,
  138815. _vq_quantmap__44un1__p6_0,
  138816. 13,
  138817. 13
  138818. };
  138819. static static_codebook _44un1__p6_0 = {
  138820. 2, 169,
  138821. _vq_lengthlist__44un1__p6_0,
  138822. 1, -526516224, 1616117760, 4, 0,
  138823. _vq_quantlist__44un1__p6_0,
  138824. NULL,
  138825. &_vq_auxt__44un1__p6_0,
  138826. NULL,
  138827. 0
  138828. };
  138829. static long _vq_quantlist__44un1__p6_1[] = {
  138830. 2,
  138831. 1,
  138832. 3,
  138833. 0,
  138834. 4,
  138835. };
  138836. static long _vq_lengthlist__44un1__p6_1[] = {
  138837. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138838. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138839. };
  138840. static float _vq_quantthresh__44un1__p6_1[] = {
  138841. -1.5, -0.5, 0.5, 1.5,
  138842. };
  138843. static long _vq_quantmap__44un1__p6_1[] = {
  138844. 3, 1, 0, 2, 4,
  138845. };
  138846. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138847. _vq_quantthresh__44un1__p6_1,
  138848. _vq_quantmap__44un1__p6_1,
  138849. 5,
  138850. 5
  138851. };
  138852. static static_codebook _44un1__p6_1 = {
  138853. 2, 25,
  138854. _vq_lengthlist__44un1__p6_1,
  138855. 1, -533725184, 1611661312, 3, 0,
  138856. _vq_quantlist__44un1__p6_1,
  138857. NULL,
  138858. &_vq_auxt__44un1__p6_1,
  138859. NULL,
  138860. 0
  138861. };
  138862. static long _vq_quantlist__44un1__p7_0[] = {
  138863. 2,
  138864. 1,
  138865. 3,
  138866. 0,
  138867. 4,
  138868. };
  138869. static long _vq_lengthlist__44un1__p7_0[] = {
  138870. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138871. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138872. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138873. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138874. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138875. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138876. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138877. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138878. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138879. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138880. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138881. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138882. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138883. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138884. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138885. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138886. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138887. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138888. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138889. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138890. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138891. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138892. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138893. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138894. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138895. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138896. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138897. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138898. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138899. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138900. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138901. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138902. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138903. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138904. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138905. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138906. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138907. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138908. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138909. 10,
  138910. };
  138911. static float _vq_quantthresh__44un1__p7_0[] = {
  138912. -253.5, -84.5, 84.5, 253.5,
  138913. };
  138914. static long _vq_quantmap__44un1__p7_0[] = {
  138915. 3, 1, 0, 2, 4,
  138916. };
  138917. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138918. _vq_quantthresh__44un1__p7_0,
  138919. _vq_quantmap__44un1__p7_0,
  138920. 5,
  138921. 5
  138922. };
  138923. static static_codebook _44un1__p7_0 = {
  138924. 4, 625,
  138925. _vq_lengthlist__44un1__p7_0,
  138926. 1, -518709248, 1626677248, 3, 0,
  138927. _vq_quantlist__44un1__p7_0,
  138928. NULL,
  138929. &_vq_auxt__44un1__p7_0,
  138930. NULL,
  138931. 0
  138932. };
  138933. static long _vq_quantlist__44un1__p7_1[] = {
  138934. 6,
  138935. 5,
  138936. 7,
  138937. 4,
  138938. 8,
  138939. 3,
  138940. 9,
  138941. 2,
  138942. 10,
  138943. 1,
  138944. 11,
  138945. 0,
  138946. 12,
  138947. };
  138948. static long _vq_lengthlist__44un1__p7_1[] = {
  138949. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138950. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138951. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138952. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138953. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138954. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138955. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138956. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138957. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138958. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138959. 12,13,13,12,13,13,14,14,14,
  138960. };
  138961. static float _vq_quantthresh__44un1__p7_1[] = {
  138962. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138963. 32.5, 45.5, 58.5, 71.5,
  138964. };
  138965. static long _vq_quantmap__44un1__p7_1[] = {
  138966. 11, 9, 7, 5, 3, 1, 0, 2,
  138967. 4, 6, 8, 10, 12,
  138968. };
  138969. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138970. _vq_quantthresh__44un1__p7_1,
  138971. _vq_quantmap__44un1__p7_1,
  138972. 13,
  138973. 13
  138974. };
  138975. static static_codebook _44un1__p7_1 = {
  138976. 2, 169,
  138977. _vq_lengthlist__44un1__p7_1,
  138978. 1, -523010048, 1618608128, 4, 0,
  138979. _vq_quantlist__44un1__p7_1,
  138980. NULL,
  138981. &_vq_auxt__44un1__p7_1,
  138982. NULL,
  138983. 0
  138984. };
  138985. static long _vq_quantlist__44un1__p7_2[] = {
  138986. 6,
  138987. 5,
  138988. 7,
  138989. 4,
  138990. 8,
  138991. 3,
  138992. 9,
  138993. 2,
  138994. 10,
  138995. 1,
  138996. 11,
  138997. 0,
  138998. 12,
  138999. };
  139000. static long _vq_lengthlist__44un1__p7_2[] = {
  139001. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  139002. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  139003. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  139004. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  139005. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  139006. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  139007. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  139008. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  139009. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  139010. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  139011. 9, 9, 9,10,10,10,10,10,10,
  139012. };
  139013. static float _vq_quantthresh__44un1__p7_2[] = {
  139014. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  139015. 2.5, 3.5, 4.5, 5.5,
  139016. };
  139017. static long _vq_quantmap__44un1__p7_2[] = {
  139018. 11, 9, 7, 5, 3, 1, 0, 2,
  139019. 4, 6, 8, 10, 12,
  139020. };
  139021. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  139022. _vq_quantthresh__44un1__p7_2,
  139023. _vq_quantmap__44un1__p7_2,
  139024. 13,
  139025. 13
  139026. };
  139027. static static_codebook _44un1__p7_2 = {
  139028. 2, 169,
  139029. _vq_lengthlist__44un1__p7_2,
  139030. 1, -531103744, 1611661312, 4, 0,
  139031. _vq_quantlist__44un1__p7_2,
  139032. NULL,
  139033. &_vq_auxt__44un1__p7_2,
  139034. NULL,
  139035. 0
  139036. };
  139037. static long _huff_lengthlist__44un1__short[] = {
  139038. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  139039. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  139040. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  139041. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  139042. };
  139043. static static_codebook _huff_book__44un1__short = {
  139044. 2, 64,
  139045. _huff_lengthlist__44un1__short,
  139046. 0, 0, 0, 0, 0,
  139047. NULL,
  139048. NULL,
  139049. NULL,
  139050. NULL,
  139051. 0
  139052. };
  139053. /*** End of inlined file: res_books_uncoupled.h ***/
  139054. static vorbis_info_residue0 _residue_44_low_un={
  139055. 0,-1, -1, 8,-1,
  139056. {0},
  139057. {-1},
  139058. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  139059. { -1, 25, -1, 45, -1, -1, -1}
  139060. };
  139061. static vorbis_info_residue0 _residue_44_mid_un={
  139062. 0,-1, -1, 10,-1,
  139063. {0},
  139064. {-1},
  139065. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  139066. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  139067. };
  139068. static vorbis_info_residue0 _residue_44_hi_un={
  139069. 0,-1, -1, 10,-1,
  139070. {0},
  139071. {-1},
  139072. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  139073. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  139074. };
  139075. static vorbis_info_mapping0 _map_nominal_u[2]={
  139076. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  139077. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  139078. };
  139079. static static_bookblock _resbook_44u_n1={
  139080. {
  139081. {0},
  139082. {0,0,&_44un1__p1_0},
  139083. {0,0,&_44un1__p2_0},
  139084. {0,0,&_44un1__p3_0},
  139085. {0,0,&_44un1__p4_0},
  139086. {0,0,&_44un1__p5_0},
  139087. {&_44un1__p6_0,&_44un1__p6_1},
  139088. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  139089. }
  139090. };
  139091. static static_bookblock _resbook_44u_0={
  139092. {
  139093. {0},
  139094. {0,0,&_44u0__p1_0},
  139095. {0,0,&_44u0__p2_0},
  139096. {0,0,&_44u0__p3_0},
  139097. {0,0,&_44u0__p4_0},
  139098. {0,0,&_44u0__p5_0},
  139099. {&_44u0__p6_0,&_44u0__p6_1},
  139100. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139101. }
  139102. };
  139103. static static_bookblock _resbook_44u_1={
  139104. {
  139105. {0},
  139106. {0,0,&_44u1__p1_0},
  139107. {0,0,&_44u1__p2_0},
  139108. {0,0,&_44u1__p3_0},
  139109. {0,0,&_44u1__p4_0},
  139110. {0,0,&_44u1__p5_0},
  139111. {&_44u1__p6_0,&_44u1__p6_1},
  139112. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139113. }
  139114. };
  139115. static static_bookblock _resbook_44u_2={
  139116. {
  139117. {0},
  139118. {0,0,&_44u2__p1_0},
  139119. {0,0,&_44u2__p2_0},
  139120. {0,0,&_44u2__p3_0},
  139121. {0,0,&_44u2__p4_0},
  139122. {0,0,&_44u2__p5_0},
  139123. {&_44u2__p6_0,&_44u2__p6_1},
  139124. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139125. }
  139126. };
  139127. static static_bookblock _resbook_44u_3={
  139128. {
  139129. {0},
  139130. {0,0,&_44u3__p1_0},
  139131. {0,0,&_44u3__p2_0},
  139132. {0,0,&_44u3__p3_0},
  139133. {0,0,&_44u3__p4_0},
  139134. {0,0,&_44u3__p5_0},
  139135. {&_44u3__p6_0,&_44u3__p6_1},
  139136. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139137. }
  139138. };
  139139. static static_bookblock _resbook_44u_4={
  139140. {
  139141. {0},
  139142. {0,0,&_44u4__p1_0},
  139143. {0,0,&_44u4__p2_0},
  139144. {0,0,&_44u4__p3_0},
  139145. {0,0,&_44u4__p4_0},
  139146. {0,0,&_44u4__p5_0},
  139147. {&_44u4__p6_0,&_44u4__p6_1},
  139148. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139149. }
  139150. };
  139151. static static_bookblock _resbook_44u_5={
  139152. {
  139153. {0},
  139154. {0,0,&_44u5__p1_0},
  139155. {0,0,&_44u5__p2_0},
  139156. {0,0,&_44u5__p3_0},
  139157. {0,0,&_44u5__p4_0},
  139158. {0,0,&_44u5__p5_0},
  139159. {0,0,&_44u5__p6_0},
  139160. {&_44u5__p7_0,&_44u5__p7_1},
  139161. {&_44u5__p8_0,&_44u5__p8_1},
  139162. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139163. }
  139164. };
  139165. static static_bookblock _resbook_44u_6={
  139166. {
  139167. {0},
  139168. {0,0,&_44u6__p1_0},
  139169. {0,0,&_44u6__p2_0},
  139170. {0,0,&_44u6__p3_0},
  139171. {0,0,&_44u6__p4_0},
  139172. {0,0,&_44u6__p5_0},
  139173. {0,0,&_44u6__p6_0},
  139174. {&_44u6__p7_0,&_44u6__p7_1},
  139175. {&_44u6__p8_0,&_44u6__p8_1},
  139176. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139177. }
  139178. };
  139179. static static_bookblock _resbook_44u_7={
  139180. {
  139181. {0},
  139182. {0,0,&_44u7__p1_0},
  139183. {0,0,&_44u7__p2_0},
  139184. {0,0,&_44u7__p3_0},
  139185. {0,0,&_44u7__p4_0},
  139186. {0,0,&_44u7__p5_0},
  139187. {0,0,&_44u7__p6_0},
  139188. {&_44u7__p7_0,&_44u7__p7_1},
  139189. {&_44u7__p8_0,&_44u7__p8_1},
  139190. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139191. }
  139192. };
  139193. static static_bookblock _resbook_44u_8={
  139194. {
  139195. {0},
  139196. {0,0,&_44u8_p1_0},
  139197. {0,0,&_44u8_p2_0},
  139198. {0,0,&_44u8_p3_0},
  139199. {0,0,&_44u8_p4_0},
  139200. {&_44u8_p5_0,&_44u8_p5_1},
  139201. {&_44u8_p6_0,&_44u8_p6_1},
  139202. {&_44u8_p7_0,&_44u8_p7_1},
  139203. {&_44u8_p8_0,&_44u8_p8_1},
  139204. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139205. }
  139206. };
  139207. static static_bookblock _resbook_44u_9={
  139208. {
  139209. {0},
  139210. {0,0,&_44u9_p1_0},
  139211. {0,0,&_44u9_p2_0},
  139212. {0,0,&_44u9_p3_0},
  139213. {0,0,&_44u9_p4_0},
  139214. {&_44u9_p5_0,&_44u9_p5_1},
  139215. {&_44u9_p6_0,&_44u9_p6_1},
  139216. {&_44u9_p7_0,&_44u9_p7_1},
  139217. {&_44u9_p8_0,&_44u9_p8_1},
  139218. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139219. }
  139220. };
  139221. static vorbis_residue_template _res_44u_n1[]={
  139222. {1,0, &_residue_44_low_un,
  139223. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139224. &_resbook_44u_n1,&_resbook_44u_n1},
  139225. {1,0, &_residue_44_low_un,
  139226. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139227. &_resbook_44u_n1,&_resbook_44u_n1}
  139228. };
  139229. static vorbis_residue_template _res_44u_0[]={
  139230. {1,0, &_residue_44_low_un,
  139231. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139232. &_resbook_44u_0,&_resbook_44u_0},
  139233. {1,0, &_residue_44_low_un,
  139234. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139235. &_resbook_44u_0,&_resbook_44u_0}
  139236. };
  139237. static vorbis_residue_template _res_44u_1[]={
  139238. {1,0, &_residue_44_low_un,
  139239. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139240. &_resbook_44u_1,&_resbook_44u_1},
  139241. {1,0, &_residue_44_low_un,
  139242. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139243. &_resbook_44u_1,&_resbook_44u_1}
  139244. };
  139245. static vorbis_residue_template _res_44u_2[]={
  139246. {1,0, &_residue_44_low_un,
  139247. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139248. &_resbook_44u_2,&_resbook_44u_2},
  139249. {1,0, &_residue_44_low_un,
  139250. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139251. &_resbook_44u_2,&_resbook_44u_2}
  139252. };
  139253. static vorbis_residue_template _res_44u_3[]={
  139254. {1,0, &_residue_44_low_un,
  139255. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139256. &_resbook_44u_3,&_resbook_44u_3},
  139257. {1,0, &_residue_44_low_un,
  139258. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139259. &_resbook_44u_3,&_resbook_44u_3}
  139260. };
  139261. static vorbis_residue_template _res_44u_4[]={
  139262. {1,0, &_residue_44_low_un,
  139263. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139264. &_resbook_44u_4,&_resbook_44u_4},
  139265. {1,0, &_residue_44_low_un,
  139266. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139267. &_resbook_44u_4,&_resbook_44u_4}
  139268. };
  139269. static vorbis_residue_template _res_44u_5[]={
  139270. {1,0, &_residue_44_mid_un,
  139271. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139272. &_resbook_44u_5,&_resbook_44u_5},
  139273. {1,0, &_residue_44_mid_un,
  139274. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139275. &_resbook_44u_5,&_resbook_44u_5}
  139276. };
  139277. static vorbis_residue_template _res_44u_6[]={
  139278. {1,0, &_residue_44_mid_un,
  139279. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139280. &_resbook_44u_6,&_resbook_44u_6},
  139281. {1,0, &_residue_44_mid_un,
  139282. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139283. &_resbook_44u_6,&_resbook_44u_6}
  139284. };
  139285. static vorbis_residue_template _res_44u_7[]={
  139286. {1,0, &_residue_44_mid_un,
  139287. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139288. &_resbook_44u_7,&_resbook_44u_7},
  139289. {1,0, &_residue_44_mid_un,
  139290. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139291. &_resbook_44u_7,&_resbook_44u_7}
  139292. };
  139293. static vorbis_residue_template _res_44u_8[]={
  139294. {1,0, &_residue_44_hi_un,
  139295. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139296. &_resbook_44u_8,&_resbook_44u_8},
  139297. {1,0, &_residue_44_hi_un,
  139298. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139299. &_resbook_44u_8,&_resbook_44u_8}
  139300. };
  139301. static vorbis_residue_template _res_44u_9[]={
  139302. {1,0, &_residue_44_hi_un,
  139303. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139304. &_resbook_44u_9,&_resbook_44u_9},
  139305. {1,0, &_residue_44_hi_un,
  139306. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139307. &_resbook_44u_9,&_resbook_44u_9}
  139308. };
  139309. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139310. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139311. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139312. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139313. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139314. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139315. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139316. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139317. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139318. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139319. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139320. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139321. };
  139322. /*** End of inlined file: residue_44u.h ***/
  139323. static double rate_mapping_44_un[12]={
  139324. 32000.,48000.,60000.,70000.,80000.,86000.,
  139325. 96000.,110000.,120000.,140000.,160000.,240001.
  139326. };
  139327. ve_setup_data_template ve_setup_44_uncoupled={
  139328. 11,
  139329. rate_mapping_44_un,
  139330. quality_mapping_44,
  139331. -1,
  139332. 40000,
  139333. 50000,
  139334. blocksize_short_44,
  139335. blocksize_long_44,
  139336. _psy_tone_masteratt_44,
  139337. _psy_tone_0dB,
  139338. _psy_tone_suppress,
  139339. _vp_tonemask_adj_otherblock,
  139340. _vp_tonemask_adj_longblock,
  139341. _vp_tonemask_adj_otherblock,
  139342. _psy_noiseguards_44,
  139343. _psy_noisebias_impulse,
  139344. _psy_noisebias_padding,
  139345. _psy_noisebias_trans,
  139346. _psy_noisebias_long,
  139347. _psy_noise_suppress,
  139348. _psy_compand_44,
  139349. _psy_compand_short_mapping,
  139350. _psy_compand_long_mapping,
  139351. {_noise_start_short_44,_noise_start_long_44},
  139352. {_noise_part_short_44,_noise_part_long_44},
  139353. _noise_thresh_44,
  139354. _psy_ath_floater,
  139355. _psy_ath_abs,
  139356. _psy_lowpass_44,
  139357. _psy_global_44,
  139358. _global_mapping_44,
  139359. NULL,
  139360. _floor_books,
  139361. _floor,
  139362. _floor_short_mapping_44,
  139363. _floor_long_mapping_44,
  139364. _mapres_template_44_uncoupled
  139365. };
  139366. /*** End of inlined file: setup_44u.h ***/
  139367. /*** Start of inlined file: setup_32.h ***/
  139368. static double rate_mapping_32[12]={
  139369. 18000.,28000.,35000.,45000.,56000.,60000.,
  139370. 75000.,90000.,100000.,115000.,150000.,190000.,
  139371. };
  139372. static double rate_mapping_32_un[12]={
  139373. 30000.,42000.,52000.,64000.,72000.,78000.,
  139374. 86000.,92000.,110000.,120000.,140000.,190000.,
  139375. };
  139376. static double _psy_lowpass_32[12]={
  139377. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139378. };
  139379. ve_setup_data_template ve_setup_32_stereo={
  139380. 11,
  139381. rate_mapping_32,
  139382. quality_mapping_44,
  139383. 2,
  139384. 26000,
  139385. 40000,
  139386. blocksize_short_44,
  139387. blocksize_long_44,
  139388. _psy_tone_masteratt_44,
  139389. _psy_tone_0dB,
  139390. _psy_tone_suppress,
  139391. _vp_tonemask_adj_otherblock,
  139392. _vp_tonemask_adj_longblock,
  139393. _vp_tonemask_adj_otherblock,
  139394. _psy_noiseguards_44,
  139395. _psy_noisebias_impulse,
  139396. _psy_noisebias_padding,
  139397. _psy_noisebias_trans,
  139398. _psy_noisebias_long,
  139399. _psy_noise_suppress,
  139400. _psy_compand_44,
  139401. _psy_compand_short_mapping,
  139402. _psy_compand_long_mapping,
  139403. {_noise_start_short_44,_noise_start_long_44},
  139404. {_noise_part_short_44,_noise_part_long_44},
  139405. _noise_thresh_44,
  139406. _psy_ath_floater,
  139407. _psy_ath_abs,
  139408. _psy_lowpass_32,
  139409. _psy_global_44,
  139410. _global_mapping_44,
  139411. _psy_stereo_modes_44,
  139412. _floor_books,
  139413. _floor,
  139414. _floor_short_mapping_44,
  139415. _floor_long_mapping_44,
  139416. _mapres_template_44_stereo
  139417. };
  139418. ve_setup_data_template ve_setup_32_uncoupled={
  139419. 11,
  139420. rate_mapping_32_un,
  139421. quality_mapping_44,
  139422. -1,
  139423. 26000,
  139424. 40000,
  139425. blocksize_short_44,
  139426. blocksize_long_44,
  139427. _psy_tone_masteratt_44,
  139428. _psy_tone_0dB,
  139429. _psy_tone_suppress,
  139430. _vp_tonemask_adj_otherblock,
  139431. _vp_tonemask_adj_longblock,
  139432. _vp_tonemask_adj_otherblock,
  139433. _psy_noiseguards_44,
  139434. _psy_noisebias_impulse,
  139435. _psy_noisebias_padding,
  139436. _psy_noisebias_trans,
  139437. _psy_noisebias_long,
  139438. _psy_noise_suppress,
  139439. _psy_compand_44,
  139440. _psy_compand_short_mapping,
  139441. _psy_compand_long_mapping,
  139442. {_noise_start_short_44,_noise_start_long_44},
  139443. {_noise_part_short_44,_noise_part_long_44},
  139444. _noise_thresh_44,
  139445. _psy_ath_floater,
  139446. _psy_ath_abs,
  139447. _psy_lowpass_32,
  139448. _psy_global_44,
  139449. _global_mapping_44,
  139450. NULL,
  139451. _floor_books,
  139452. _floor,
  139453. _floor_short_mapping_44,
  139454. _floor_long_mapping_44,
  139455. _mapres_template_44_uncoupled
  139456. };
  139457. /*** End of inlined file: setup_32.h ***/
  139458. /*** Start of inlined file: setup_8.h ***/
  139459. /*** Start of inlined file: psych_8.h ***/
  139460. static att3 _psy_tone_masteratt_8[3]={
  139461. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139462. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139463. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139464. };
  139465. static vp_adjblock _vp_tonemask_adj_8[3]={
  139466. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139467. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139468. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139469. };
  139470. static noise3 _psy_noisebias_8[3]={
  139471. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139472. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139473. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139474. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139475. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139476. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139477. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139478. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139479. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139480. };
  139481. static adj_stereo _psy_stereo_modes_8[3]={
  139482. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139483. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139484. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139485. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139486. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139487. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139488. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139489. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139490. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139491. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139492. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139493. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139494. };
  139495. static noiseguard _psy_noiseguards_8[2]={
  139496. {10,10,-1},
  139497. {10,10,-1},
  139498. };
  139499. static compandblock _psy_compand_8[2]={
  139500. {{
  139501. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139502. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139503. 12,12,13,13,14,14,15, 15, /* 23dB */
  139504. 16,16,17,17,17,18,18, 19, /* 31dB */
  139505. 19,19,20,21,22,23,24, 25, /* 39dB */
  139506. }},
  139507. {{
  139508. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139509. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139510. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139511. 9,10,11,12,13,14,15, 16, /* 31dB */
  139512. 17,18,19,20,21,22,23, 24, /* 39dB */
  139513. }},
  139514. };
  139515. static double _psy_lowpass_8[3]={3.,4.,4.};
  139516. static int _noise_start_8[2]={
  139517. 64,64,
  139518. };
  139519. static int _noise_part_8[2]={
  139520. 8,8,
  139521. };
  139522. static int _psy_ath_floater_8[3]={
  139523. -100,-100,-105,
  139524. };
  139525. static int _psy_ath_abs_8[3]={
  139526. -130,-130,-140,
  139527. };
  139528. /*** End of inlined file: psych_8.h ***/
  139529. /*** Start of inlined file: residue_8.h ***/
  139530. static static_bookblock _resbook_8s_0={
  139531. {
  139532. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139533. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139534. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139535. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139536. }
  139537. };
  139538. static static_bookblock _resbook_8s_1={
  139539. {
  139540. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139541. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139542. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139543. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139544. }
  139545. };
  139546. static vorbis_residue_template _res_8s_0[]={
  139547. {2,0, &_residue_44_mid,
  139548. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139549. &_resbook_8s_0,&_resbook_8s_0},
  139550. };
  139551. static vorbis_residue_template _res_8s_1[]={
  139552. {2,0, &_residue_44_mid,
  139553. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139554. &_resbook_8s_1,&_resbook_8s_1},
  139555. };
  139556. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139557. { _map_nominal, _res_8s_0 }, /* 0 */
  139558. { _map_nominal, _res_8s_1 }, /* 1 */
  139559. };
  139560. static static_bookblock _resbook_8u_0={
  139561. {
  139562. {0},
  139563. {0,0,&_8u0__p1_0},
  139564. {0,0,&_8u0__p2_0},
  139565. {0,0,&_8u0__p3_0},
  139566. {0,0,&_8u0__p4_0},
  139567. {0,0,&_8u0__p5_0},
  139568. {&_8u0__p6_0,&_8u0__p6_1},
  139569. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139570. }
  139571. };
  139572. static static_bookblock _resbook_8u_1={
  139573. {
  139574. {0},
  139575. {0,0,&_8u1__p1_0},
  139576. {0,0,&_8u1__p2_0},
  139577. {0,0,&_8u1__p3_0},
  139578. {0,0,&_8u1__p4_0},
  139579. {0,0,&_8u1__p5_0},
  139580. {0,0,&_8u1__p6_0},
  139581. {&_8u1__p7_0,&_8u1__p7_1},
  139582. {&_8u1__p8_0,&_8u1__p8_1},
  139583. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139584. }
  139585. };
  139586. static vorbis_residue_template _res_8u_0[]={
  139587. {1,0, &_residue_44_low_un,
  139588. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139589. &_resbook_8u_0,&_resbook_8u_0},
  139590. };
  139591. static vorbis_residue_template _res_8u_1[]={
  139592. {1,0, &_residue_44_mid_un,
  139593. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139594. &_resbook_8u_1,&_resbook_8u_1},
  139595. };
  139596. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139597. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139598. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139599. };
  139600. /*** End of inlined file: residue_8.h ***/
  139601. static int blocksize_8[2]={
  139602. 512,512
  139603. };
  139604. static int _floor_mapping_8[2]={
  139605. 6,6,
  139606. };
  139607. static double rate_mapping_8[3]={
  139608. 6000.,9000.,32000.,
  139609. };
  139610. static double rate_mapping_8_uncoupled[3]={
  139611. 8000.,14000.,42000.,
  139612. };
  139613. static double quality_mapping_8[3]={
  139614. -.1,.0,1.
  139615. };
  139616. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139617. static double _global_mapping_8[3]={ 1., 2., 3. };
  139618. ve_setup_data_template ve_setup_8_stereo={
  139619. 2,
  139620. rate_mapping_8,
  139621. quality_mapping_8,
  139622. 2,
  139623. 8000,
  139624. 9000,
  139625. blocksize_8,
  139626. blocksize_8,
  139627. _psy_tone_masteratt_8,
  139628. _psy_tone_0dB,
  139629. _psy_tone_suppress,
  139630. _vp_tonemask_adj_8,
  139631. NULL,
  139632. _vp_tonemask_adj_8,
  139633. _psy_noiseguards_8,
  139634. _psy_noisebias_8,
  139635. _psy_noisebias_8,
  139636. NULL,
  139637. NULL,
  139638. _psy_noise_suppress,
  139639. _psy_compand_8,
  139640. _psy_compand_8_mapping,
  139641. NULL,
  139642. {_noise_start_8,_noise_start_8},
  139643. {_noise_part_8,_noise_part_8},
  139644. _noise_thresh_5only,
  139645. _psy_ath_floater_8,
  139646. _psy_ath_abs_8,
  139647. _psy_lowpass_8,
  139648. _psy_global_44,
  139649. _global_mapping_8,
  139650. _psy_stereo_modes_8,
  139651. _floor_books,
  139652. _floor,
  139653. _floor_mapping_8,
  139654. NULL,
  139655. _mapres_template_8_stereo
  139656. };
  139657. ve_setup_data_template ve_setup_8_uncoupled={
  139658. 2,
  139659. rate_mapping_8_uncoupled,
  139660. quality_mapping_8,
  139661. -1,
  139662. 8000,
  139663. 9000,
  139664. blocksize_8,
  139665. blocksize_8,
  139666. _psy_tone_masteratt_8,
  139667. _psy_tone_0dB,
  139668. _psy_tone_suppress,
  139669. _vp_tonemask_adj_8,
  139670. NULL,
  139671. _vp_tonemask_adj_8,
  139672. _psy_noiseguards_8,
  139673. _psy_noisebias_8,
  139674. _psy_noisebias_8,
  139675. NULL,
  139676. NULL,
  139677. _psy_noise_suppress,
  139678. _psy_compand_8,
  139679. _psy_compand_8_mapping,
  139680. NULL,
  139681. {_noise_start_8,_noise_start_8},
  139682. {_noise_part_8,_noise_part_8},
  139683. _noise_thresh_5only,
  139684. _psy_ath_floater_8,
  139685. _psy_ath_abs_8,
  139686. _psy_lowpass_8,
  139687. _psy_global_44,
  139688. _global_mapping_8,
  139689. _psy_stereo_modes_8,
  139690. _floor_books,
  139691. _floor,
  139692. _floor_mapping_8,
  139693. NULL,
  139694. _mapres_template_8_uncoupled
  139695. };
  139696. /*** End of inlined file: setup_8.h ***/
  139697. /*** Start of inlined file: setup_11.h ***/
  139698. /*** Start of inlined file: psych_11.h ***/
  139699. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139700. static att3 _psy_tone_masteratt_11[3]={
  139701. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139702. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139703. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139704. };
  139705. static vp_adjblock _vp_tonemask_adj_11[3]={
  139706. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139707. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139708. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139709. };
  139710. static noise3 _psy_noisebias_11[3]={
  139711. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139712. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139713. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139714. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139715. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139716. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139717. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139718. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139719. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139720. };
  139721. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139722. /*** End of inlined file: psych_11.h ***/
  139723. static int blocksize_11[2]={
  139724. 512,512
  139725. };
  139726. static int _floor_mapping_11[2]={
  139727. 6,6,
  139728. };
  139729. static double rate_mapping_11[3]={
  139730. 8000.,13000.,44000.,
  139731. };
  139732. static double rate_mapping_11_uncoupled[3]={
  139733. 12000.,20000.,50000.,
  139734. };
  139735. static double quality_mapping_11[3]={
  139736. -.1,.0,1.
  139737. };
  139738. ve_setup_data_template ve_setup_11_stereo={
  139739. 2,
  139740. rate_mapping_11,
  139741. quality_mapping_11,
  139742. 2,
  139743. 9000,
  139744. 15000,
  139745. blocksize_11,
  139746. blocksize_11,
  139747. _psy_tone_masteratt_11,
  139748. _psy_tone_0dB,
  139749. _psy_tone_suppress,
  139750. _vp_tonemask_adj_11,
  139751. NULL,
  139752. _vp_tonemask_adj_11,
  139753. _psy_noiseguards_8,
  139754. _psy_noisebias_11,
  139755. _psy_noisebias_11,
  139756. NULL,
  139757. NULL,
  139758. _psy_noise_suppress,
  139759. _psy_compand_8,
  139760. _psy_compand_8_mapping,
  139761. NULL,
  139762. {_noise_start_8,_noise_start_8},
  139763. {_noise_part_8,_noise_part_8},
  139764. _noise_thresh_11,
  139765. _psy_ath_floater_8,
  139766. _psy_ath_abs_8,
  139767. _psy_lowpass_11,
  139768. _psy_global_44,
  139769. _global_mapping_8,
  139770. _psy_stereo_modes_8,
  139771. _floor_books,
  139772. _floor,
  139773. _floor_mapping_11,
  139774. NULL,
  139775. _mapres_template_8_stereo
  139776. };
  139777. ve_setup_data_template ve_setup_11_uncoupled={
  139778. 2,
  139779. rate_mapping_11_uncoupled,
  139780. quality_mapping_11,
  139781. -1,
  139782. 9000,
  139783. 15000,
  139784. blocksize_11,
  139785. blocksize_11,
  139786. _psy_tone_masteratt_11,
  139787. _psy_tone_0dB,
  139788. _psy_tone_suppress,
  139789. _vp_tonemask_adj_11,
  139790. NULL,
  139791. _vp_tonemask_adj_11,
  139792. _psy_noiseguards_8,
  139793. _psy_noisebias_11,
  139794. _psy_noisebias_11,
  139795. NULL,
  139796. NULL,
  139797. _psy_noise_suppress,
  139798. _psy_compand_8,
  139799. _psy_compand_8_mapping,
  139800. NULL,
  139801. {_noise_start_8,_noise_start_8},
  139802. {_noise_part_8,_noise_part_8},
  139803. _noise_thresh_11,
  139804. _psy_ath_floater_8,
  139805. _psy_ath_abs_8,
  139806. _psy_lowpass_11,
  139807. _psy_global_44,
  139808. _global_mapping_8,
  139809. _psy_stereo_modes_8,
  139810. _floor_books,
  139811. _floor,
  139812. _floor_mapping_11,
  139813. NULL,
  139814. _mapres_template_8_uncoupled
  139815. };
  139816. /*** End of inlined file: setup_11.h ***/
  139817. /*** Start of inlined file: setup_16.h ***/
  139818. /*** Start of inlined file: psych_16.h ***/
  139819. static adj_stereo _psy_stereo_modes_16[4]={
  139820. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139821. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139822. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139823. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139824. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139825. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139826. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139827. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139828. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139829. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139830. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139831. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139832. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139833. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139834. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139835. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139836. };
  139837. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139838. static att3 _psy_tone_masteratt_16[4]={
  139839. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139840. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139841. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139842. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139843. };
  139844. static vp_adjblock _vp_tonemask_adj_16[4]={
  139845. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139846. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139847. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139848. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139849. };
  139850. static noise3 _psy_noisebias_16_short[4]={
  139851. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139852. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139853. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139854. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139855. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139856. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139857. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139858. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139859. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139860. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139861. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139862. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139863. };
  139864. static noise3 _psy_noisebias_16_impulse[4]={
  139865. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139866. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139867. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139868. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139869. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139870. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139871. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139872. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139873. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139874. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139875. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139876. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139877. };
  139878. static noise3 _psy_noisebias_16[4]={
  139879. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139880. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139881. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139882. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139883. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139884. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139885. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139886. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139887. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139888. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139889. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139890. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139891. };
  139892. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139893. static int _noise_start_16[3]={ 256,256,9999 };
  139894. static int _noise_part_16[4]={ 8,8,8,8 };
  139895. static int _psy_ath_floater_16[4]={
  139896. -100,-100,-100,-105,
  139897. };
  139898. static int _psy_ath_abs_16[4]={
  139899. -130,-130,-130,-140,
  139900. };
  139901. /*** End of inlined file: psych_16.h ***/
  139902. /*** Start of inlined file: residue_16.h ***/
  139903. static static_bookblock _resbook_16s_0={
  139904. {
  139905. {0},
  139906. {0,0,&_16c0_s_p1_0},
  139907. {0,0,&_16c0_s_p2_0},
  139908. {0,0,&_16c0_s_p3_0},
  139909. {0,0,&_16c0_s_p4_0},
  139910. {0,0,&_16c0_s_p5_0},
  139911. {0,0,&_16c0_s_p6_0},
  139912. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139913. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139914. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139915. }
  139916. };
  139917. static static_bookblock _resbook_16s_1={
  139918. {
  139919. {0},
  139920. {0,0,&_16c1_s_p1_0},
  139921. {0,0,&_16c1_s_p2_0},
  139922. {0,0,&_16c1_s_p3_0},
  139923. {0,0,&_16c1_s_p4_0},
  139924. {0,0,&_16c1_s_p5_0},
  139925. {0,0,&_16c1_s_p6_0},
  139926. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139927. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139928. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139929. }
  139930. };
  139931. static static_bookblock _resbook_16s_2={
  139932. {
  139933. {0},
  139934. {0,0,&_16c2_s_p1_0},
  139935. {0,0,&_16c2_s_p2_0},
  139936. {0,0,&_16c2_s_p3_0},
  139937. {0,0,&_16c2_s_p4_0},
  139938. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139939. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139940. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139941. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139942. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139943. }
  139944. };
  139945. static vorbis_residue_template _res_16s_0[]={
  139946. {2,0, &_residue_44_mid,
  139947. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139948. &_resbook_16s_0,&_resbook_16s_0},
  139949. };
  139950. static vorbis_residue_template _res_16s_1[]={
  139951. {2,0, &_residue_44_mid,
  139952. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139953. &_resbook_16s_1,&_resbook_16s_1},
  139954. {2,0, &_residue_44_mid,
  139955. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139956. &_resbook_16s_1,&_resbook_16s_1}
  139957. };
  139958. static vorbis_residue_template _res_16s_2[]={
  139959. {2,0, &_residue_44_high,
  139960. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139961. &_resbook_16s_2,&_resbook_16s_2},
  139962. {2,0, &_residue_44_high,
  139963. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139964. &_resbook_16s_2,&_resbook_16s_2}
  139965. };
  139966. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139967. { _map_nominal, _res_16s_0 }, /* 0 */
  139968. { _map_nominal, _res_16s_1 }, /* 1 */
  139969. { _map_nominal, _res_16s_2 }, /* 2 */
  139970. };
  139971. static static_bookblock _resbook_16u_0={
  139972. {
  139973. {0},
  139974. {0,0,&_16u0__p1_0},
  139975. {0,0,&_16u0__p2_0},
  139976. {0,0,&_16u0__p3_0},
  139977. {0,0,&_16u0__p4_0},
  139978. {0,0,&_16u0__p5_0},
  139979. {&_16u0__p6_0,&_16u0__p6_1},
  139980. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139981. }
  139982. };
  139983. static static_bookblock _resbook_16u_1={
  139984. {
  139985. {0},
  139986. {0,0,&_16u1__p1_0},
  139987. {0,0,&_16u1__p2_0},
  139988. {0,0,&_16u1__p3_0},
  139989. {0,0,&_16u1__p4_0},
  139990. {0,0,&_16u1__p5_0},
  139991. {0,0,&_16u1__p6_0},
  139992. {&_16u1__p7_0,&_16u1__p7_1},
  139993. {&_16u1__p8_0,&_16u1__p8_1},
  139994. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139995. }
  139996. };
  139997. static static_bookblock _resbook_16u_2={
  139998. {
  139999. {0},
  140000. {0,0,&_16u2_p1_0},
  140001. {0,0,&_16u2_p2_0},
  140002. {0,0,&_16u2_p3_0},
  140003. {0,0,&_16u2_p4_0},
  140004. {&_16u2_p5_0,&_16u2_p5_1},
  140005. {&_16u2_p6_0,&_16u2_p6_1},
  140006. {&_16u2_p7_0,&_16u2_p7_1},
  140007. {&_16u2_p8_0,&_16u2_p8_1},
  140008. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  140009. }
  140010. };
  140011. static vorbis_residue_template _res_16u_0[]={
  140012. {1,0, &_residue_44_low_un,
  140013. &_huff_book__16u0__single,&_huff_book__16u0__single,
  140014. &_resbook_16u_0,&_resbook_16u_0},
  140015. };
  140016. static vorbis_residue_template _res_16u_1[]={
  140017. {1,0, &_residue_44_mid_un,
  140018. &_huff_book__16u1__short,&_huff_book__16u1__short,
  140019. &_resbook_16u_1,&_resbook_16u_1},
  140020. {1,0, &_residue_44_mid_un,
  140021. &_huff_book__16u1__long,&_huff_book__16u1__long,
  140022. &_resbook_16u_1,&_resbook_16u_1}
  140023. };
  140024. static vorbis_residue_template _res_16u_2[]={
  140025. {1,0, &_residue_44_hi_un,
  140026. &_huff_book__16u2__short,&_huff_book__16u2__short,
  140027. &_resbook_16u_2,&_resbook_16u_2},
  140028. {1,0, &_residue_44_hi_un,
  140029. &_huff_book__16u2__long,&_huff_book__16u2__long,
  140030. &_resbook_16u_2,&_resbook_16u_2}
  140031. };
  140032. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  140033. { _map_nominal_u, _res_16u_0 }, /* 0 */
  140034. { _map_nominal_u, _res_16u_1 }, /* 1 */
  140035. { _map_nominal_u, _res_16u_2 }, /* 2 */
  140036. };
  140037. /*** End of inlined file: residue_16.h ***/
  140038. static int blocksize_16_short[3]={
  140039. 1024,512,512
  140040. };
  140041. static int blocksize_16_long[3]={
  140042. 1024,1024,1024
  140043. };
  140044. static int _floor_mapping_16_short[3]={
  140045. 9,3,3
  140046. };
  140047. static int _floor_mapping_16[3]={
  140048. 9,9,9
  140049. };
  140050. static double rate_mapping_16[4]={
  140051. 12000.,20000.,44000.,86000.
  140052. };
  140053. static double rate_mapping_16_uncoupled[4]={
  140054. 16000.,28000.,64000.,100000.
  140055. };
  140056. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  140057. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  140058. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  140059. ve_setup_data_template ve_setup_16_stereo={
  140060. 3,
  140061. rate_mapping_16,
  140062. quality_mapping_16,
  140063. 2,
  140064. 15000,
  140065. 19000,
  140066. blocksize_16_short,
  140067. blocksize_16_long,
  140068. _psy_tone_masteratt_16,
  140069. _psy_tone_0dB,
  140070. _psy_tone_suppress,
  140071. _vp_tonemask_adj_16,
  140072. _vp_tonemask_adj_16,
  140073. _vp_tonemask_adj_16,
  140074. _psy_noiseguards_8,
  140075. _psy_noisebias_16_impulse,
  140076. _psy_noisebias_16_short,
  140077. _psy_noisebias_16_short,
  140078. _psy_noisebias_16,
  140079. _psy_noise_suppress,
  140080. _psy_compand_8,
  140081. _psy_compand_16_mapping,
  140082. _psy_compand_16_mapping,
  140083. {_noise_start_16,_noise_start_16},
  140084. { _noise_part_16, _noise_part_16},
  140085. _noise_thresh_16,
  140086. _psy_ath_floater_16,
  140087. _psy_ath_abs_16,
  140088. _psy_lowpass_16,
  140089. _psy_global_44,
  140090. _global_mapping_16,
  140091. _psy_stereo_modes_16,
  140092. _floor_books,
  140093. _floor,
  140094. _floor_mapping_16_short,
  140095. _floor_mapping_16,
  140096. _mapres_template_16_stereo
  140097. };
  140098. ve_setup_data_template ve_setup_16_uncoupled={
  140099. 3,
  140100. rate_mapping_16_uncoupled,
  140101. quality_mapping_16,
  140102. -1,
  140103. 15000,
  140104. 19000,
  140105. blocksize_16_short,
  140106. blocksize_16_long,
  140107. _psy_tone_masteratt_16,
  140108. _psy_tone_0dB,
  140109. _psy_tone_suppress,
  140110. _vp_tonemask_adj_16,
  140111. _vp_tonemask_adj_16,
  140112. _vp_tonemask_adj_16,
  140113. _psy_noiseguards_8,
  140114. _psy_noisebias_16_impulse,
  140115. _psy_noisebias_16_short,
  140116. _psy_noisebias_16_short,
  140117. _psy_noisebias_16,
  140118. _psy_noise_suppress,
  140119. _psy_compand_8,
  140120. _psy_compand_16_mapping,
  140121. _psy_compand_16_mapping,
  140122. {_noise_start_16,_noise_start_16},
  140123. { _noise_part_16, _noise_part_16},
  140124. _noise_thresh_16,
  140125. _psy_ath_floater_16,
  140126. _psy_ath_abs_16,
  140127. _psy_lowpass_16,
  140128. _psy_global_44,
  140129. _global_mapping_16,
  140130. _psy_stereo_modes_16,
  140131. _floor_books,
  140132. _floor,
  140133. _floor_mapping_16_short,
  140134. _floor_mapping_16,
  140135. _mapres_template_16_uncoupled
  140136. };
  140137. /*** End of inlined file: setup_16.h ***/
  140138. /*** Start of inlined file: setup_22.h ***/
  140139. static double rate_mapping_22[4]={
  140140. 15000.,20000.,44000.,86000.
  140141. };
  140142. static double rate_mapping_22_uncoupled[4]={
  140143. 16000.,28000.,50000.,90000.
  140144. };
  140145. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140146. ve_setup_data_template ve_setup_22_stereo={
  140147. 3,
  140148. rate_mapping_22,
  140149. quality_mapping_16,
  140150. 2,
  140151. 19000,
  140152. 26000,
  140153. blocksize_16_short,
  140154. blocksize_16_long,
  140155. _psy_tone_masteratt_16,
  140156. _psy_tone_0dB,
  140157. _psy_tone_suppress,
  140158. _vp_tonemask_adj_16,
  140159. _vp_tonemask_adj_16,
  140160. _vp_tonemask_adj_16,
  140161. _psy_noiseguards_8,
  140162. _psy_noisebias_16_impulse,
  140163. _psy_noisebias_16_short,
  140164. _psy_noisebias_16_short,
  140165. _psy_noisebias_16,
  140166. _psy_noise_suppress,
  140167. _psy_compand_8,
  140168. _psy_compand_8_mapping,
  140169. _psy_compand_8_mapping,
  140170. {_noise_start_16,_noise_start_16},
  140171. { _noise_part_16, _noise_part_16},
  140172. _noise_thresh_16,
  140173. _psy_ath_floater_16,
  140174. _psy_ath_abs_16,
  140175. _psy_lowpass_22,
  140176. _psy_global_44,
  140177. _global_mapping_16,
  140178. _psy_stereo_modes_16,
  140179. _floor_books,
  140180. _floor,
  140181. _floor_mapping_16_short,
  140182. _floor_mapping_16,
  140183. _mapres_template_16_stereo
  140184. };
  140185. ve_setup_data_template ve_setup_22_uncoupled={
  140186. 3,
  140187. rate_mapping_22_uncoupled,
  140188. quality_mapping_16,
  140189. -1,
  140190. 19000,
  140191. 26000,
  140192. blocksize_16_short,
  140193. blocksize_16_long,
  140194. _psy_tone_masteratt_16,
  140195. _psy_tone_0dB,
  140196. _psy_tone_suppress,
  140197. _vp_tonemask_adj_16,
  140198. _vp_tonemask_adj_16,
  140199. _vp_tonemask_adj_16,
  140200. _psy_noiseguards_8,
  140201. _psy_noisebias_16_impulse,
  140202. _psy_noisebias_16_short,
  140203. _psy_noisebias_16_short,
  140204. _psy_noisebias_16,
  140205. _psy_noise_suppress,
  140206. _psy_compand_8,
  140207. _psy_compand_8_mapping,
  140208. _psy_compand_8_mapping,
  140209. {_noise_start_16,_noise_start_16},
  140210. { _noise_part_16, _noise_part_16},
  140211. _noise_thresh_16,
  140212. _psy_ath_floater_16,
  140213. _psy_ath_abs_16,
  140214. _psy_lowpass_22,
  140215. _psy_global_44,
  140216. _global_mapping_16,
  140217. _psy_stereo_modes_16,
  140218. _floor_books,
  140219. _floor,
  140220. _floor_mapping_16_short,
  140221. _floor_mapping_16,
  140222. _mapres_template_16_uncoupled
  140223. };
  140224. /*** End of inlined file: setup_22.h ***/
  140225. /*** Start of inlined file: setup_X.h ***/
  140226. static double rate_mapping_X[12]={
  140227. -1.,-1.,-1.,-1.,-1.,-1.,
  140228. -1.,-1.,-1.,-1.,-1.,-1.
  140229. };
  140230. ve_setup_data_template ve_setup_X_stereo={
  140231. 11,
  140232. rate_mapping_X,
  140233. quality_mapping_44,
  140234. 2,
  140235. 50000,
  140236. 200000,
  140237. blocksize_short_44,
  140238. blocksize_long_44,
  140239. _psy_tone_masteratt_44,
  140240. _psy_tone_0dB,
  140241. _psy_tone_suppress,
  140242. _vp_tonemask_adj_otherblock,
  140243. _vp_tonemask_adj_longblock,
  140244. _vp_tonemask_adj_otherblock,
  140245. _psy_noiseguards_44,
  140246. _psy_noisebias_impulse,
  140247. _psy_noisebias_padding,
  140248. _psy_noisebias_trans,
  140249. _psy_noisebias_long,
  140250. _psy_noise_suppress,
  140251. _psy_compand_44,
  140252. _psy_compand_short_mapping,
  140253. _psy_compand_long_mapping,
  140254. {_noise_start_short_44,_noise_start_long_44},
  140255. {_noise_part_short_44,_noise_part_long_44},
  140256. _noise_thresh_44,
  140257. _psy_ath_floater,
  140258. _psy_ath_abs,
  140259. _psy_lowpass_44,
  140260. _psy_global_44,
  140261. _global_mapping_44,
  140262. _psy_stereo_modes_44,
  140263. _floor_books,
  140264. _floor,
  140265. _floor_short_mapping_44,
  140266. _floor_long_mapping_44,
  140267. _mapres_template_44_stereo
  140268. };
  140269. ve_setup_data_template ve_setup_X_uncoupled={
  140270. 11,
  140271. rate_mapping_X,
  140272. quality_mapping_44,
  140273. -1,
  140274. 50000,
  140275. 200000,
  140276. blocksize_short_44,
  140277. blocksize_long_44,
  140278. _psy_tone_masteratt_44,
  140279. _psy_tone_0dB,
  140280. _psy_tone_suppress,
  140281. _vp_tonemask_adj_otherblock,
  140282. _vp_tonemask_adj_longblock,
  140283. _vp_tonemask_adj_otherblock,
  140284. _psy_noiseguards_44,
  140285. _psy_noisebias_impulse,
  140286. _psy_noisebias_padding,
  140287. _psy_noisebias_trans,
  140288. _psy_noisebias_long,
  140289. _psy_noise_suppress,
  140290. _psy_compand_44,
  140291. _psy_compand_short_mapping,
  140292. _psy_compand_long_mapping,
  140293. {_noise_start_short_44,_noise_start_long_44},
  140294. {_noise_part_short_44,_noise_part_long_44},
  140295. _noise_thresh_44,
  140296. _psy_ath_floater,
  140297. _psy_ath_abs,
  140298. _psy_lowpass_44,
  140299. _psy_global_44,
  140300. _global_mapping_44,
  140301. NULL,
  140302. _floor_books,
  140303. _floor,
  140304. _floor_short_mapping_44,
  140305. _floor_long_mapping_44,
  140306. _mapres_template_44_uncoupled
  140307. };
  140308. ve_setup_data_template ve_setup_XX_stereo={
  140309. 2,
  140310. rate_mapping_X,
  140311. quality_mapping_8,
  140312. 2,
  140313. 0,
  140314. 8000,
  140315. blocksize_8,
  140316. blocksize_8,
  140317. _psy_tone_masteratt_8,
  140318. _psy_tone_0dB,
  140319. _psy_tone_suppress,
  140320. _vp_tonemask_adj_8,
  140321. NULL,
  140322. _vp_tonemask_adj_8,
  140323. _psy_noiseguards_8,
  140324. _psy_noisebias_8,
  140325. _psy_noisebias_8,
  140326. NULL,
  140327. NULL,
  140328. _psy_noise_suppress,
  140329. _psy_compand_8,
  140330. _psy_compand_8_mapping,
  140331. NULL,
  140332. {_noise_start_8,_noise_start_8},
  140333. {_noise_part_8,_noise_part_8},
  140334. _noise_thresh_5only,
  140335. _psy_ath_floater_8,
  140336. _psy_ath_abs_8,
  140337. _psy_lowpass_8,
  140338. _psy_global_44,
  140339. _global_mapping_8,
  140340. _psy_stereo_modes_8,
  140341. _floor_books,
  140342. _floor,
  140343. _floor_mapping_8,
  140344. NULL,
  140345. _mapres_template_8_stereo
  140346. };
  140347. ve_setup_data_template ve_setup_XX_uncoupled={
  140348. 2,
  140349. rate_mapping_X,
  140350. quality_mapping_8,
  140351. -1,
  140352. 0,
  140353. 8000,
  140354. blocksize_8,
  140355. blocksize_8,
  140356. _psy_tone_masteratt_8,
  140357. _psy_tone_0dB,
  140358. _psy_tone_suppress,
  140359. _vp_tonemask_adj_8,
  140360. NULL,
  140361. _vp_tonemask_adj_8,
  140362. _psy_noiseguards_8,
  140363. _psy_noisebias_8,
  140364. _psy_noisebias_8,
  140365. NULL,
  140366. NULL,
  140367. _psy_noise_suppress,
  140368. _psy_compand_8,
  140369. _psy_compand_8_mapping,
  140370. NULL,
  140371. {_noise_start_8,_noise_start_8},
  140372. {_noise_part_8,_noise_part_8},
  140373. _noise_thresh_5only,
  140374. _psy_ath_floater_8,
  140375. _psy_ath_abs_8,
  140376. _psy_lowpass_8,
  140377. _psy_global_44,
  140378. _global_mapping_8,
  140379. _psy_stereo_modes_8,
  140380. _floor_books,
  140381. _floor,
  140382. _floor_mapping_8,
  140383. NULL,
  140384. _mapres_template_8_uncoupled
  140385. };
  140386. /*** End of inlined file: setup_X.h ***/
  140387. static ve_setup_data_template *setup_list[]={
  140388. &ve_setup_44_stereo,
  140389. &ve_setup_44_uncoupled,
  140390. &ve_setup_32_stereo,
  140391. &ve_setup_32_uncoupled,
  140392. &ve_setup_22_stereo,
  140393. &ve_setup_22_uncoupled,
  140394. &ve_setup_16_stereo,
  140395. &ve_setup_16_uncoupled,
  140396. &ve_setup_11_stereo,
  140397. &ve_setup_11_uncoupled,
  140398. &ve_setup_8_stereo,
  140399. &ve_setup_8_uncoupled,
  140400. &ve_setup_X_stereo,
  140401. &ve_setup_X_uncoupled,
  140402. &ve_setup_XX_stereo,
  140403. &ve_setup_XX_uncoupled,
  140404. 0
  140405. };
  140406. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140407. if(vi && vi->codec_setup){
  140408. vi->version=0;
  140409. vi->channels=ch;
  140410. vi->rate=rate;
  140411. return(0);
  140412. }
  140413. return(OV_EINVAL);
  140414. }
  140415. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140416. static_codebook ***books,
  140417. vorbis_info_floor1 *in,
  140418. int *x){
  140419. int i,k,is=s;
  140420. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140421. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140422. memcpy(f,in+x[is],sizeof(*f));
  140423. f->n=ci->blocksizes[block]>>1;
  140424. {
  140425. int partitions=f->partitions;
  140426. int maxclass=-1;
  140427. int maxbook=-1;
  140428. for(i=0;i<partitions;i++)
  140429. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140430. for(i=0;i<=maxclass;i++){
  140431. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140432. f->class_book[i]+=ci->books;
  140433. for(k=0;k<(1<<f->class_subs[i]);k++){
  140434. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140435. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140436. }
  140437. }
  140438. for(i=0;i<=maxbook;i++)
  140439. ci->book_param[ci->books++]=books[x[is]][i];
  140440. }
  140441. ci->floor_type[ci->floors]=1;
  140442. ci->floor_param[ci->floors]=f;
  140443. ci->floors++;
  140444. return;
  140445. }
  140446. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140447. vorbis_info_psy_global *in,
  140448. double *x){
  140449. int i,is=s;
  140450. double ds=s-is;
  140451. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140452. vorbis_info_psy_global *g=&ci->psy_g_param;
  140453. memcpy(g,in+(int)x[is],sizeof(*g));
  140454. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140455. is=(int)ds;
  140456. ds-=is;
  140457. if(ds==0 && is>0){
  140458. is--;
  140459. ds=1.;
  140460. }
  140461. for(i=0;i<4;i++){
  140462. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140463. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140464. }
  140465. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140466. return;
  140467. }
  140468. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140469. highlevel_encode_setup *hi,
  140470. adj_stereo *p){
  140471. float s=hi->stereo_point_setting;
  140472. int i,is=s;
  140473. double ds=s-is;
  140474. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140475. vorbis_info_psy_global *g=&ci->psy_g_param;
  140476. if(p){
  140477. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140478. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140479. if(hi->managed){
  140480. for(i=0;i<PACKETBLOBS;i++){
  140481. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140482. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140483. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140484. g->coupling_pkHz[i]=kHz;
  140485. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140486. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140487. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140488. }
  140489. }else{
  140490. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140491. for(i=0;i<PACKETBLOBS;i++){
  140492. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140493. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140494. g->coupling_pkHz[i]=kHz;
  140495. }
  140496. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140497. for(i=0;i<PACKETBLOBS;i++){
  140498. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140499. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140500. }
  140501. }
  140502. }else{
  140503. for(i=0;i<PACKETBLOBS;i++){
  140504. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140505. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140506. }
  140507. }
  140508. return;
  140509. }
  140510. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140511. int *nn_start,
  140512. int *nn_partition,
  140513. double *nn_thresh,
  140514. int block){
  140515. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140516. vorbis_info_psy *p=ci->psy_param[block];
  140517. highlevel_encode_setup *hi=&ci->hi;
  140518. int is=s;
  140519. if(block>=ci->psys)
  140520. ci->psys=block+1;
  140521. if(!p){
  140522. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140523. ci->psy_param[block]=p;
  140524. }
  140525. memcpy(p,&_psy_info_template,sizeof(*p));
  140526. p->blockflag=block>>1;
  140527. if(hi->noise_normalize_p){
  140528. p->normal_channel_p=1;
  140529. p->normal_point_p=1;
  140530. p->normal_start=nn_start[is];
  140531. p->normal_partition=nn_partition[is];
  140532. p->normal_thresh=nn_thresh[is];
  140533. }
  140534. return;
  140535. }
  140536. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140537. att3 *att,
  140538. int *max,
  140539. vp_adjblock *in){
  140540. int i,is=s;
  140541. double ds=s-is;
  140542. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140543. vorbis_info_psy *p=ci->psy_param[block];
  140544. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140545. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140546. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140547. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140548. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140549. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140550. for(i=0;i<P_BANDS;i++)
  140551. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140552. return;
  140553. }
  140554. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140555. compandblock *in, double *x){
  140556. int i,is=s;
  140557. double ds=s-is;
  140558. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140559. vorbis_info_psy *p=ci->psy_param[block];
  140560. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140561. is=(int)ds;
  140562. ds-=is;
  140563. if(ds==0 && is>0){
  140564. is--;
  140565. ds=1.;
  140566. }
  140567. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140568. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140569. return;
  140570. }
  140571. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140572. int *suppress){
  140573. int is=s;
  140574. double ds=s-is;
  140575. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140576. vorbis_info_psy *p=ci->psy_param[block];
  140577. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140578. return;
  140579. }
  140580. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140581. int *suppress,
  140582. noise3 *in,
  140583. noiseguard *guard,
  140584. double userbias){
  140585. int i,is=s,j;
  140586. double ds=s-is;
  140587. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140588. vorbis_info_psy *p=ci->psy_param[block];
  140589. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140590. p->noisewindowlomin=guard[block].lo;
  140591. p->noisewindowhimin=guard[block].hi;
  140592. p->noisewindowfixed=guard[block].fixed;
  140593. for(j=0;j<P_NOISECURVES;j++)
  140594. for(i=0;i<P_BANDS;i++)
  140595. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140596. for(j=0;j<P_NOISECURVES;j++){
  140597. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140598. for(i=0;i<P_BANDS;i++){
  140599. p->noiseoff[j][i]+=userbias;
  140600. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140601. }
  140602. }
  140603. return;
  140604. }
  140605. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140606. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140607. vorbis_info_psy *p=ci->psy_param[block];
  140608. p->ath_adjatt=ci->hi.ath_floating_dB;
  140609. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140610. return;
  140611. }
  140612. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140613. int i;
  140614. for(i=0;i<ci->books;i++)
  140615. if(ci->book_param[i]==book)return(i);
  140616. return(ci->books++);
  140617. }
  140618. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140619. int *shortb,int *longb){
  140620. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140621. int is=s;
  140622. int blockshort=shortb[is];
  140623. int blocklong=longb[is];
  140624. ci->blocksizes[0]=blockshort;
  140625. ci->blocksizes[1]=blocklong;
  140626. }
  140627. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140628. int number, int block,
  140629. vorbis_residue_template *res){
  140630. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140631. int i,n;
  140632. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140633. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140634. memcpy(r,res->res,sizeof(*r));
  140635. if(ci->residues<=number)ci->residues=number+1;
  140636. switch(ci->blocksizes[block]){
  140637. case 64:case 128:case 256:
  140638. r->grouping=16;
  140639. break;
  140640. default:
  140641. r->grouping=32;
  140642. break;
  140643. }
  140644. ci->residue_type[number]=res->res_type;
  140645. n=r->end=ci->blocksizes[block]>>1;
  140646. if(res->res_type==2)
  140647. n=r->end*=vi->channels;
  140648. {
  140649. int booklist=0,k;
  140650. if(ci->hi.managed){
  140651. for(i=0;i<r->partitions;i++)
  140652. for(k=0;k<3;k++)
  140653. if(res->books_base_managed->books[i][k])
  140654. r->secondstages[i]|=(1<<k);
  140655. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140656. ci->book_param[r->groupbook]=res->book_aux_managed;
  140657. for(i=0;i<r->partitions;i++){
  140658. for(k=0;k<3;k++){
  140659. if(res->books_base_managed->books[i][k]){
  140660. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140661. r->booklist[booklist++]=bookid;
  140662. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140663. }
  140664. }
  140665. }
  140666. }else{
  140667. for(i=0;i<r->partitions;i++)
  140668. for(k=0;k<3;k++)
  140669. if(res->books_base->books[i][k])
  140670. r->secondstages[i]|=(1<<k);
  140671. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140672. ci->book_param[r->groupbook]=res->book_aux;
  140673. for(i=0;i<r->partitions;i++){
  140674. for(k=0;k<3;k++){
  140675. if(res->books_base->books[i][k]){
  140676. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140677. r->booklist[booklist++]=bookid;
  140678. ci->book_param[bookid]=res->books_base->books[i][k];
  140679. }
  140680. }
  140681. }
  140682. }
  140683. }
  140684. {
  140685. double freq=ci->hi.lowpass_kHz*1000.;
  140686. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140687. double nyq=vi->rate/2.;
  140688. long blocksize=ci->blocksizes[block]>>1;
  140689. if(freq>nyq)freq=nyq;
  140690. f->n=freq/nyq*blocksize;
  140691. if(res->limit_type){
  140692. if(ci->hi.managed)
  140693. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140694. else
  140695. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140696. if(freq>nyq)freq=nyq;
  140697. }
  140698. if(ci->residue_type[block]==2)
  140699. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140700. r->grouping;
  140701. else
  140702. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140703. r->grouping;
  140704. }
  140705. }
  140706. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140707. vorbis_mapping_template *maps){
  140708. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140709. int i,j,is=s,modes=2;
  140710. vorbis_info_mapping0 *map=maps[is].map;
  140711. vorbis_info_mode *mode=_mode_template;
  140712. vorbis_residue_template *res=maps[is].res;
  140713. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140714. for(i=0;i<modes;i++){
  140715. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140716. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140717. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140718. if(i>=ci->modes)ci->modes=i+1;
  140719. ci->map_type[i]=0;
  140720. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140721. if(i>=ci->maps)ci->maps=i+1;
  140722. for(j=0;j<map[i].submaps;j++)
  140723. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140724. ,res+map[i].residuesubmap[j]);
  140725. }
  140726. }
  140727. static double setting_to_approx_bitrate(vorbis_info *vi){
  140728. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140729. highlevel_encode_setup *hi=&ci->hi;
  140730. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140731. int is=hi->base_setting;
  140732. double ds=hi->base_setting-is;
  140733. int ch=vi->channels;
  140734. double *r=setup->rate_mapping;
  140735. if(r==NULL)
  140736. return(-1);
  140737. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140738. }
  140739. static void get_setup_template(vorbis_info *vi,
  140740. long ch,long srate,
  140741. double req,int q_or_bitrate){
  140742. int i=0,j;
  140743. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140744. highlevel_encode_setup *hi=&ci->hi;
  140745. if(q_or_bitrate)req/=ch;
  140746. while(setup_list[i]){
  140747. if(setup_list[i]->coupling_restriction==-1 ||
  140748. setup_list[i]->coupling_restriction==ch){
  140749. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140750. srate<=setup_list[i]->samplerate_max_restriction){
  140751. int mappings=setup_list[i]->mappings;
  140752. double *map=(q_or_bitrate?
  140753. setup_list[i]->rate_mapping:
  140754. setup_list[i]->quality_mapping);
  140755. if(req<map[0]){++i;continue;}
  140756. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140757. for(j=0;j<mappings;j++)
  140758. if(req>=map[j] && req<map[j+1])break;
  140759. hi->setup=setup_list[i];
  140760. if(j==mappings)
  140761. hi->base_setting=j-.001;
  140762. else{
  140763. float low=map[j];
  140764. float high=map[j+1];
  140765. float del=(req-low)/(high-low);
  140766. hi->base_setting=j+del;
  140767. }
  140768. return;
  140769. }
  140770. }
  140771. i++;
  140772. }
  140773. hi->setup=NULL;
  140774. }
  140775. int vorbis_encode_setup_init(vorbis_info *vi){
  140776. int i0=0,singleblock=0;
  140777. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140778. ve_setup_data_template *setup=NULL;
  140779. highlevel_encode_setup *hi=&ci->hi;
  140780. if(ci==NULL)return(OV_EINVAL);
  140781. if(!hi->impulse_block_p)i0=1;
  140782. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140783. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140784. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140785. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140786. setup=(ve_setup_data_template *)hi->setup;
  140787. if(setup==NULL)return(OV_EINVAL);
  140788. hi->set_in_stone=1;
  140789. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140790. setup->blocksize_short,
  140791. setup->blocksize_long);
  140792. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140793. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140794. setup->floor_books,
  140795. setup->floor_params,
  140796. setup->floor_short_mapping);
  140797. if(!singleblock)
  140798. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140799. setup->floor_books,
  140800. setup->floor_params,
  140801. setup->floor_long_mapping);
  140802. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140803. setup->global_params,
  140804. setup->global_mapping);
  140805. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140806. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140807. setup->psy_noise_normal_start[0],
  140808. setup->psy_noise_normal_partition[0],
  140809. setup->psy_noise_normal_thresh,
  140810. 0);
  140811. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140812. setup->psy_noise_normal_start[0],
  140813. setup->psy_noise_normal_partition[0],
  140814. setup->psy_noise_normal_thresh,
  140815. 1);
  140816. if(!singleblock){
  140817. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140818. setup->psy_noise_normal_start[1],
  140819. setup->psy_noise_normal_partition[1],
  140820. setup->psy_noise_normal_thresh,
  140821. 2);
  140822. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140823. setup->psy_noise_normal_start[1],
  140824. setup->psy_noise_normal_partition[1],
  140825. setup->psy_noise_normal_thresh,
  140826. 3);
  140827. }
  140828. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140829. setup->psy_tone_masteratt,
  140830. setup->psy_tone_0dB,
  140831. setup->psy_tone_adj_impulse);
  140832. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140833. setup->psy_tone_masteratt,
  140834. setup->psy_tone_0dB,
  140835. setup->psy_tone_adj_other);
  140836. if(!singleblock){
  140837. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140838. setup->psy_tone_masteratt,
  140839. setup->psy_tone_0dB,
  140840. setup->psy_tone_adj_other);
  140841. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140842. setup->psy_tone_masteratt,
  140843. setup->psy_tone_0dB,
  140844. setup->psy_tone_adj_long);
  140845. }
  140846. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140847. setup->psy_noise_compand,
  140848. setup->psy_noise_compand_short_mapping);
  140849. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140850. setup->psy_noise_compand,
  140851. setup->psy_noise_compand_short_mapping);
  140852. if(!singleblock){
  140853. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140854. setup->psy_noise_compand,
  140855. setup->psy_noise_compand_long_mapping);
  140856. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140857. setup->psy_noise_compand,
  140858. setup->psy_noise_compand_long_mapping);
  140859. }
  140860. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140861. setup->psy_tone_dBsuppress);
  140862. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140863. setup->psy_tone_dBsuppress);
  140864. if(!singleblock){
  140865. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140866. setup->psy_tone_dBsuppress);
  140867. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140868. setup->psy_tone_dBsuppress);
  140869. }
  140870. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140871. setup->psy_noise_dBsuppress,
  140872. setup->psy_noise_bias_impulse,
  140873. setup->psy_noiseguards,
  140874. (i0==0?hi->impulse_noisetune:0.));
  140875. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140876. setup->psy_noise_dBsuppress,
  140877. setup->psy_noise_bias_padding,
  140878. setup->psy_noiseguards,0.);
  140879. if(!singleblock){
  140880. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140881. setup->psy_noise_dBsuppress,
  140882. setup->psy_noise_bias_trans,
  140883. setup->psy_noiseguards,0.);
  140884. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140885. setup->psy_noise_dBsuppress,
  140886. setup->psy_noise_bias_long,
  140887. setup->psy_noiseguards,0.);
  140888. }
  140889. vorbis_encode_ath_setup(vi,0);
  140890. vorbis_encode_ath_setup(vi,1);
  140891. if(!singleblock){
  140892. vorbis_encode_ath_setup(vi,2);
  140893. vorbis_encode_ath_setup(vi,3);
  140894. }
  140895. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140896. if(hi->bitrate_av>0)
  140897. vi->bitrate_nominal=hi->bitrate_av;
  140898. else{
  140899. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140900. }
  140901. vi->bitrate_lower=hi->bitrate_min;
  140902. vi->bitrate_upper=hi->bitrate_max;
  140903. if(hi->bitrate_av)
  140904. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140905. else
  140906. vi->bitrate_window=0.;
  140907. if(hi->managed){
  140908. ci->bi.avg_rate=hi->bitrate_av;
  140909. ci->bi.min_rate=hi->bitrate_min;
  140910. ci->bi.max_rate=hi->bitrate_max;
  140911. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140912. ci->bi.reservoir_bias=
  140913. hi->bitrate_reservoir_bias;
  140914. ci->bi.slew_damp=hi->bitrate_av_damp;
  140915. }
  140916. return(0);
  140917. }
  140918. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140919. long channels,
  140920. long rate){
  140921. int ret=0,i,is;
  140922. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140923. highlevel_encode_setup *hi=&ci->hi;
  140924. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140925. double ds;
  140926. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140927. if(ret)return(ret);
  140928. is=hi->base_setting;
  140929. ds=hi->base_setting-is;
  140930. hi->short_setting=hi->base_setting;
  140931. hi->long_setting=hi->base_setting;
  140932. hi->managed=0;
  140933. hi->impulse_block_p=1;
  140934. hi->noise_normalize_p=1;
  140935. hi->stereo_point_setting=hi->base_setting;
  140936. hi->lowpass_kHz=
  140937. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140938. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140939. setup->psy_ath_float[is+1]*ds;
  140940. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140941. setup->psy_ath_abs[is+1]*ds;
  140942. hi->amplitude_track_dBpersec=-6.;
  140943. hi->trigger_setting=hi->base_setting;
  140944. for(i=0;i<4;i++){
  140945. hi->block[i].tone_mask_setting=hi->base_setting;
  140946. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140947. hi->block[i].noise_bias_setting=hi->base_setting;
  140948. hi->block[i].noise_compand_setting=hi->base_setting;
  140949. }
  140950. return(ret);
  140951. }
  140952. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140953. long channels,
  140954. long rate,
  140955. float quality){
  140956. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140957. highlevel_encode_setup *hi=&ci->hi;
  140958. quality+=.0000001;
  140959. if(quality>=1.)quality=.9999;
  140960. get_setup_template(vi,channels,rate,quality,0);
  140961. if(!hi->setup)return OV_EIMPL;
  140962. return vorbis_encode_setup_setting(vi,channels,rate);
  140963. }
  140964. int vorbis_encode_init_vbr(vorbis_info *vi,
  140965. long channels,
  140966. long rate,
  140967. float base_quality /* 0. to 1. */
  140968. ){
  140969. int ret=0;
  140970. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140971. if(ret){
  140972. vorbis_info_clear(vi);
  140973. return ret;
  140974. }
  140975. ret=vorbis_encode_setup_init(vi);
  140976. if(ret)
  140977. vorbis_info_clear(vi);
  140978. return(ret);
  140979. }
  140980. int vorbis_encode_setup_managed(vorbis_info *vi,
  140981. long channels,
  140982. long rate,
  140983. long max_bitrate,
  140984. long nominal_bitrate,
  140985. long min_bitrate){
  140986. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140987. highlevel_encode_setup *hi=&ci->hi;
  140988. double tnominal=nominal_bitrate;
  140989. int ret=0;
  140990. if(nominal_bitrate<=0.){
  140991. if(max_bitrate>0.){
  140992. if(min_bitrate>0.)
  140993. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140994. else
  140995. nominal_bitrate=max_bitrate*.875;
  140996. }else{
  140997. if(min_bitrate>0.){
  140998. nominal_bitrate=min_bitrate;
  140999. }else{
  141000. return(OV_EINVAL);
  141001. }
  141002. }
  141003. }
  141004. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  141005. if(!hi->setup)return OV_EIMPL;
  141006. ret=vorbis_encode_setup_setting(vi,channels,rate);
  141007. if(ret){
  141008. vorbis_info_clear(vi);
  141009. return ret;
  141010. }
  141011. hi->managed=1;
  141012. hi->bitrate_min=min_bitrate;
  141013. hi->bitrate_max=max_bitrate;
  141014. hi->bitrate_av=tnominal;
  141015. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  141016. hi->bitrate_reservoir=nominal_bitrate*2;
  141017. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  141018. return(ret);
  141019. }
  141020. int vorbis_encode_init(vorbis_info *vi,
  141021. long channels,
  141022. long rate,
  141023. long max_bitrate,
  141024. long nominal_bitrate,
  141025. long min_bitrate){
  141026. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  141027. max_bitrate,
  141028. nominal_bitrate,
  141029. min_bitrate);
  141030. if(ret){
  141031. vorbis_info_clear(vi);
  141032. return(ret);
  141033. }
  141034. ret=vorbis_encode_setup_init(vi);
  141035. if(ret)
  141036. vorbis_info_clear(vi);
  141037. return(ret);
  141038. }
  141039. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  141040. if(vi){
  141041. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141042. highlevel_encode_setup *hi=&ci->hi;
  141043. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  141044. if(setp && hi->set_in_stone)return(OV_EINVAL);
  141045. switch(number){
  141046. case OV_ECTL_RATEMANAGE_GET:
  141047. {
  141048. struct ovectl_ratemanage_arg *ai=
  141049. (struct ovectl_ratemanage_arg *)arg;
  141050. ai->management_active=hi->managed;
  141051. ai->bitrate_hard_window=ai->bitrate_av_window=
  141052. (double)hi->bitrate_reservoir/vi->rate;
  141053. ai->bitrate_av_window_center=1.;
  141054. ai->bitrate_hard_min=hi->bitrate_min;
  141055. ai->bitrate_hard_max=hi->bitrate_max;
  141056. ai->bitrate_av_lo=hi->bitrate_av;
  141057. ai->bitrate_av_hi=hi->bitrate_av;
  141058. }
  141059. return(0);
  141060. case OV_ECTL_RATEMANAGE_SET:
  141061. {
  141062. struct ovectl_ratemanage_arg *ai=
  141063. (struct ovectl_ratemanage_arg *)arg;
  141064. if(ai==NULL){
  141065. hi->managed=0;
  141066. }else{
  141067. hi->managed=ai->management_active;
  141068. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  141069. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  141070. }
  141071. }
  141072. return 0;
  141073. case OV_ECTL_RATEMANAGE_AVG:
  141074. {
  141075. struct ovectl_ratemanage_arg *ai=
  141076. (struct ovectl_ratemanage_arg *)arg;
  141077. if(ai==NULL){
  141078. hi->bitrate_av=0;
  141079. }else{
  141080. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  141081. }
  141082. }
  141083. return(0);
  141084. case OV_ECTL_RATEMANAGE_HARD:
  141085. {
  141086. struct ovectl_ratemanage_arg *ai=
  141087. (struct ovectl_ratemanage_arg *)arg;
  141088. if(ai==NULL){
  141089. hi->bitrate_min=0;
  141090. hi->bitrate_max=0;
  141091. }else{
  141092. hi->bitrate_min=ai->bitrate_hard_min;
  141093. hi->bitrate_max=ai->bitrate_hard_max;
  141094. hi->bitrate_reservoir=ai->bitrate_hard_window*
  141095. (hi->bitrate_max+hi->bitrate_min)*.5;
  141096. }
  141097. if(hi->bitrate_reservoir<128.)
  141098. hi->bitrate_reservoir=128.;
  141099. }
  141100. return(0);
  141101. case OV_ECTL_RATEMANAGE2_GET:
  141102. {
  141103. struct ovectl_ratemanage2_arg *ai=
  141104. (struct ovectl_ratemanage2_arg *)arg;
  141105. if(ai==NULL)return OV_EINVAL;
  141106. ai->management_active=hi->managed;
  141107. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141108. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141109. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141110. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141111. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141112. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141113. }
  141114. return (0);
  141115. case OV_ECTL_RATEMANAGE2_SET:
  141116. {
  141117. struct ovectl_ratemanage2_arg *ai=
  141118. (struct ovectl_ratemanage2_arg *)arg;
  141119. if(ai==NULL){
  141120. hi->managed=0;
  141121. }else{
  141122. if(ai->bitrate_limit_min_kbps>0 &&
  141123. ai->bitrate_average_kbps>0 &&
  141124. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141125. return OV_EINVAL;
  141126. if(ai->bitrate_limit_max_kbps>0 &&
  141127. ai->bitrate_average_kbps>0 &&
  141128. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141129. return OV_EINVAL;
  141130. if(ai->bitrate_limit_min_kbps>0 &&
  141131. ai->bitrate_limit_max_kbps>0 &&
  141132. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141133. return OV_EINVAL;
  141134. if(ai->bitrate_average_damping <= 0.)
  141135. return OV_EINVAL;
  141136. if(ai->bitrate_limit_reservoir_bits < 0)
  141137. return OV_EINVAL;
  141138. if(ai->bitrate_limit_reservoir_bias < 0.)
  141139. return OV_EINVAL;
  141140. if(ai->bitrate_limit_reservoir_bias > 1.)
  141141. return OV_EINVAL;
  141142. hi->managed=ai->management_active;
  141143. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141144. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141145. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141146. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141147. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141148. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141149. }
  141150. }
  141151. return 0;
  141152. case OV_ECTL_LOWPASS_GET:
  141153. {
  141154. double *farg=(double *)arg;
  141155. *farg=hi->lowpass_kHz;
  141156. }
  141157. return(0);
  141158. case OV_ECTL_LOWPASS_SET:
  141159. {
  141160. double *farg=(double *)arg;
  141161. hi->lowpass_kHz=*farg;
  141162. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141163. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141164. }
  141165. return(0);
  141166. case OV_ECTL_IBLOCK_GET:
  141167. {
  141168. double *farg=(double *)arg;
  141169. *farg=hi->impulse_noisetune;
  141170. }
  141171. return(0);
  141172. case OV_ECTL_IBLOCK_SET:
  141173. {
  141174. double *farg=(double *)arg;
  141175. hi->impulse_noisetune=*farg;
  141176. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141177. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141178. }
  141179. return(0);
  141180. }
  141181. return(OV_EIMPL);
  141182. }
  141183. return(OV_EINVAL);
  141184. }
  141185. #endif
  141186. /*** End of inlined file: vorbisenc.c ***/
  141187. /*** Start of inlined file: vorbisfile.c ***/
  141188. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141189. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141190. // tasks..
  141191. #if JUCE_MSVC
  141192. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141193. #endif
  141194. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141195. #if JUCE_USE_OGGVORBIS
  141196. #include <stdlib.h>
  141197. #include <stdio.h>
  141198. #include <errno.h>
  141199. #include <string.h>
  141200. #include <math.h>
  141201. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141202. over 8k gets what they deserve */
  141203. static long _get_data(OggVorbis_File *vf){
  141204. errno=0;
  141205. if(vf->datasource){
  141206. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141207. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141208. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141209. if(bytes==0 && errno)return(-1);
  141210. return(bytes);
  141211. }else
  141212. return(0);
  141213. }
  141214. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141215. if(vf->datasource){
  141216. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141217. vf->offset=offset;
  141218. ogg_sync_reset(&vf->oy);
  141219. }else{
  141220. return;
  141221. }
  141222. }
  141223. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141224. ogg_int64_t boundary){
  141225. if(boundary>0)boundary+=vf->offset;
  141226. while(1){
  141227. long more;
  141228. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141229. more=ogg_sync_pageseek(&vf->oy,og);
  141230. if(more<0){
  141231. vf->offset-=more;
  141232. }else{
  141233. if(more==0){
  141234. if(!boundary)return(OV_FALSE);
  141235. {
  141236. long ret=_get_data(vf);
  141237. if(ret==0)return(OV_EOF);
  141238. if(ret<0)return(OV_EREAD);
  141239. }
  141240. }else{
  141241. ogg_int64_t ret=vf->offset;
  141242. vf->offset+=more;
  141243. return(ret);
  141244. }
  141245. }
  141246. }
  141247. }
  141248. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141249. ogg_int64_t begin=vf->offset;
  141250. ogg_int64_t end=begin;
  141251. ogg_int64_t ret;
  141252. ogg_int64_t offset=-1;
  141253. while(offset==-1){
  141254. begin-=CHUNKSIZE;
  141255. if(begin<0)
  141256. begin=0;
  141257. _seek_helper(vf,begin);
  141258. while(vf->offset<end){
  141259. ret=_get_next_page(vf,og,end-vf->offset);
  141260. if(ret==OV_EREAD)return(OV_EREAD);
  141261. if(ret<0){
  141262. break;
  141263. }else{
  141264. offset=ret;
  141265. }
  141266. }
  141267. }
  141268. _seek_helper(vf,offset);
  141269. ret=_get_next_page(vf,og,CHUNKSIZE);
  141270. if(ret<0)
  141271. return(OV_EFAULT);
  141272. return(offset);
  141273. }
  141274. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141275. ogg_int64_t begin,
  141276. ogg_int64_t searched,
  141277. ogg_int64_t end,
  141278. long currentno,
  141279. long m){
  141280. ogg_int64_t endsearched=end;
  141281. ogg_int64_t next=end;
  141282. ogg_page og;
  141283. ogg_int64_t ret;
  141284. while(searched<endsearched){
  141285. ogg_int64_t bisect;
  141286. if(endsearched-searched<CHUNKSIZE){
  141287. bisect=searched;
  141288. }else{
  141289. bisect=(searched+endsearched)/2;
  141290. }
  141291. _seek_helper(vf,bisect);
  141292. ret=_get_next_page(vf,&og,-1);
  141293. if(ret==OV_EREAD)return(OV_EREAD);
  141294. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141295. endsearched=bisect;
  141296. if(ret>=0)next=ret;
  141297. }else{
  141298. searched=ret+og.header_len+og.body_len;
  141299. }
  141300. }
  141301. _seek_helper(vf,next);
  141302. ret=_get_next_page(vf,&og,-1);
  141303. if(ret==OV_EREAD)return(OV_EREAD);
  141304. if(searched>=end || ret<0){
  141305. vf->links=m+1;
  141306. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141307. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141308. vf->offsets[m+1]=searched;
  141309. }else{
  141310. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141311. end,ogg_page_serialno(&og),m+1);
  141312. if(ret==OV_EREAD)return(OV_EREAD);
  141313. }
  141314. vf->offsets[m]=begin;
  141315. vf->serialnos[m]=currentno;
  141316. return(0);
  141317. }
  141318. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141319. long *serialno,ogg_page *og_ptr){
  141320. ogg_page og;
  141321. ogg_packet op;
  141322. int i,ret;
  141323. if(!og_ptr){
  141324. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141325. if(llret==OV_EREAD)return(OV_EREAD);
  141326. if(llret<0)return OV_ENOTVORBIS;
  141327. og_ptr=&og;
  141328. }
  141329. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141330. if(serialno)*serialno=vf->os.serialno;
  141331. vf->ready_state=STREAMSET;
  141332. vorbis_info_init(vi);
  141333. vorbis_comment_init(vc);
  141334. i=0;
  141335. while(i<3){
  141336. ogg_stream_pagein(&vf->os,og_ptr);
  141337. while(i<3){
  141338. int result=ogg_stream_packetout(&vf->os,&op);
  141339. if(result==0)break;
  141340. if(result==-1){
  141341. ret=OV_EBADHEADER;
  141342. goto bail_header;
  141343. }
  141344. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141345. goto bail_header;
  141346. }
  141347. i++;
  141348. }
  141349. if(i<3)
  141350. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141351. ret=OV_EBADHEADER;
  141352. goto bail_header;
  141353. }
  141354. }
  141355. return 0;
  141356. bail_header:
  141357. vorbis_info_clear(vi);
  141358. vorbis_comment_clear(vc);
  141359. vf->ready_state=OPENED;
  141360. return ret;
  141361. }
  141362. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141363. ogg_page og;
  141364. int i;
  141365. ogg_int64_t ret;
  141366. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141367. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141368. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141369. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141370. for(i=0;i<vf->links;i++){
  141371. if(i==0){
  141372. vf->dataoffsets[i]=dataoffset;
  141373. _seek_helper(vf,dataoffset);
  141374. }else{
  141375. _seek_helper(vf,vf->offsets[i]);
  141376. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141377. vf->dataoffsets[i]=-1;
  141378. }else{
  141379. vf->dataoffsets[i]=vf->offset;
  141380. }
  141381. }
  141382. if(vf->dataoffsets[i]!=-1){
  141383. ogg_int64_t accumulated=0;
  141384. long lastblock=-1;
  141385. int result;
  141386. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141387. while(1){
  141388. ogg_packet op;
  141389. ret=_get_next_page(vf,&og,-1);
  141390. if(ret<0)
  141391. break;
  141392. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141393. break;
  141394. ogg_stream_pagein(&vf->os,&og);
  141395. while((result=ogg_stream_packetout(&vf->os,&op))){
  141396. if(result>0){ /* ignore holes */
  141397. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141398. if(lastblock!=-1)
  141399. accumulated+=(lastblock+thisblock)>>2;
  141400. lastblock=thisblock;
  141401. }
  141402. }
  141403. if(ogg_page_granulepos(&og)!=-1){
  141404. accumulated= ogg_page_granulepos(&og)-accumulated;
  141405. break;
  141406. }
  141407. }
  141408. if(accumulated<0)accumulated=0;
  141409. vf->pcmlengths[i*2]=accumulated;
  141410. }
  141411. {
  141412. ogg_int64_t end=vf->offsets[i+1];
  141413. _seek_helper(vf,end);
  141414. while(1){
  141415. ret=_get_prev_page(vf,&og);
  141416. if(ret<0){
  141417. vorbis_info_clear(vf->vi+i);
  141418. vorbis_comment_clear(vf->vc+i);
  141419. break;
  141420. }
  141421. if(ogg_page_granulepos(&og)!=-1){
  141422. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141423. break;
  141424. }
  141425. vf->offset=ret;
  141426. }
  141427. }
  141428. }
  141429. }
  141430. static int _make_decode_ready(OggVorbis_File *vf){
  141431. if(vf->ready_state>STREAMSET)return 0;
  141432. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141433. if(vf->seekable){
  141434. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141435. return OV_EBADLINK;
  141436. }else{
  141437. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141438. return OV_EBADLINK;
  141439. }
  141440. vorbis_block_init(&vf->vd,&vf->vb);
  141441. vf->ready_state=INITSET;
  141442. vf->bittrack=0.f;
  141443. vf->samptrack=0.f;
  141444. return 0;
  141445. }
  141446. static int _open_seekable2(OggVorbis_File *vf){
  141447. long serialno=vf->current_serialno;
  141448. ogg_int64_t dataoffset=vf->offset, end;
  141449. ogg_page og;
  141450. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141451. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141452. end=_get_prev_page(vf,&og);
  141453. if(end<0)return(end);
  141454. if(ogg_page_serialno(&og)!=serialno){
  141455. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141456. }else{
  141457. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141458. }
  141459. _prefetch_all_headers(vf,dataoffset);
  141460. return(ov_raw_seek(vf,0));
  141461. }
  141462. static void _decode_clear(OggVorbis_File *vf){
  141463. vorbis_dsp_clear(&vf->vd);
  141464. vorbis_block_clear(&vf->vb);
  141465. vf->ready_state=OPENED;
  141466. }
  141467. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141468. ogg_packet *op_in,
  141469. int readp,
  141470. int spanp){
  141471. ogg_page og;
  141472. while(1){
  141473. if(vf->ready_state==INITSET){
  141474. while(1) {
  141475. ogg_packet op;
  141476. ogg_packet *op_ptr=(op_in?op_in:&op);
  141477. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141478. ogg_int64_t granulepos;
  141479. op_in=NULL;
  141480. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141481. if(result>0){
  141482. granulepos=op_ptr->granulepos;
  141483. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141484. header handling. The
  141485. header packets aren't
  141486. audio, so if/when we
  141487. submit them,
  141488. vorbis_synthesis will
  141489. reject them */
  141490. {
  141491. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141492. if(oldsamples)return(OV_EFAULT);
  141493. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141494. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141495. vf->bittrack+=op_ptr->bytes*8;
  141496. }
  141497. if(granulepos!=-1 && !op_ptr->e_o_s){
  141498. int link=(vf->seekable?vf->current_link:0);
  141499. int i,samples;
  141500. if(vf->seekable && link>0)
  141501. granulepos-=vf->pcmlengths[link*2];
  141502. if(granulepos<0)granulepos=0; /* actually, this
  141503. shouldn't be possible
  141504. here unless the stream
  141505. is very broken */
  141506. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141507. granulepos-=samples;
  141508. for(i=0;i<link;i++)
  141509. granulepos+=vf->pcmlengths[i*2+1];
  141510. vf->pcm_offset=granulepos;
  141511. }
  141512. return(1);
  141513. }
  141514. }
  141515. else
  141516. break;
  141517. }
  141518. }
  141519. if(vf->ready_state>=OPENED){
  141520. ogg_int64_t ret;
  141521. if(!readp)return(0);
  141522. if((ret=_get_next_page(vf,&og,-1))<0){
  141523. return(OV_EOF); /* eof.
  141524. leave unitialized */
  141525. }
  141526. vf->bittrack+=og.header_len*8;
  141527. if(vf->ready_state==INITSET){
  141528. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141529. if(!spanp)
  141530. return(OV_EOF);
  141531. _decode_clear(vf);
  141532. if(!vf->seekable){
  141533. vorbis_info_clear(vf->vi);
  141534. vorbis_comment_clear(vf->vc);
  141535. }
  141536. }
  141537. }
  141538. }
  141539. if(vf->ready_state!=INITSET){
  141540. int link;
  141541. if(vf->ready_state<STREAMSET){
  141542. if(vf->seekable){
  141543. vf->current_serialno=ogg_page_serialno(&og);
  141544. for(link=0;link<vf->links;link++)
  141545. if(vf->serialnos[link]==vf->current_serialno)break;
  141546. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141547. stream. error out,
  141548. leave machine
  141549. uninitialized */
  141550. vf->current_link=link;
  141551. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141552. vf->ready_state=STREAMSET;
  141553. }else{
  141554. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141555. if(ret)return(ret);
  141556. vf->current_link++;
  141557. link=0;
  141558. }
  141559. }
  141560. {
  141561. int ret=_make_decode_ready(vf);
  141562. if(ret<0)return ret;
  141563. }
  141564. }
  141565. ogg_stream_pagein(&vf->os,&og);
  141566. }
  141567. }
  141568. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141569. if(f==NULL)return(-1);
  141570. return fseek(f,off,whence);
  141571. }
  141572. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141573. long ibytes, ov_callbacks callbacks){
  141574. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141575. int ret;
  141576. memset(vf,0,sizeof(*vf));
  141577. vf->datasource=f;
  141578. vf->callbacks = callbacks;
  141579. ogg_sync_init(&vf->oy);
  141580. if(initial){
  141581. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141582. memcpy(buffer,initial,ibytes);
  141583. ogg_sync_wrote(&vf->oy,ibytes);
  141584. }
  141585. if(offsettest!=-1)vf->seekable=1;
  141586. vf->links=1;
  141587. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141588. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141589. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141590. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141591. vf->datasource=NULL;
  141592. ov_clear(vf);
  141593. }else
  141594. vf->ready_state=PARTOPEN;
  141595. return(ret);
  141596. }
  141597. static int _ov_open2(OggVorbis_File *vf){
  141598. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141599. vf->ready_state=OPENED;
  141600. if(vf->seekable){
  141601. int ret=_open_seekable2(vf);
  141602. if(ret){
  141603. vf->datasource=NULL;
  141604. ov_clear(vf);
  141605. }
  141606. return(ret);
  141607. }else
  141608. vf->ready_state=STREAMSET;
  141609. return 0;
  141610. }
  141611. int ov_clear(OggVorbis_File *vf){
  141612. if(vf){
  141613. vorbis_block_clear(&vf->vb);
  141614. vorbis_dsp_clear(&vf->vd);
  141615. ogg_stream_clear(&vf->os);
  141616. if(vf->vi && vf->links){
  141617. int i;
  141618. for(i=0;i<vf->links;i++){
  141619. vorbis_info_clear(vf->vi+i);
  141620. vorbis_comment_clear(vf->vc+i);
  141621. }
  141622. _ogg_free(vf->vi);
  141623. _ogg_free(vf->vc);
  141624. }
  141625. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141626. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141627. if(vf->serialnos)_ogg_free(vf->serialnos);
  141628. if(vf->offsets)_ogg_free(vf->offsets);
  141629. ogg_sync_clear(&vf->oy);
  141630. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141631. memset(vf,0,sizeof(*vf));
  141632. }
  141633. #ifdef DEBUG_LEAKS
  141634. _VDBG_dump();
  141635. #endif
  141636. return(0);
  141637. }
  141638. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141639. ov_callbacks callbacks){
  141640. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141641. if(ret)return ret;
  141642. return _ov_open2(vf);
  141643. }
  141644. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141645. ov_callbacks callbacks = {
  141646. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141647. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141648. (int (*)(void *)) fclose,
  141649. (long (*)(void *)) ftell
  141650. };
  141651. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141652. }
  141653. int ov_halfrate(OggVorbis_File *vf,int flag){
  141654. int i;
  141655. if(vf->vi==NULL)return OV_EINVAL;
  141656. if(!vf->seekable)return OV_EINVAL;
  141657. if(vf->ready_state>=STREAMSET)
  141658. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141659. will be able to swap this on the fly, but
  141660. for now dumping the decode machine is needed
  141661. to reinit the MDCT lookups. 1.1 libvorbis
  141662. is planned to be able to switch on the fly */
  141663. for(i=0;i<vf->links;i++){
  141664. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141665. ov_halfrate(vf,0);
  141666. return OV_EINVAL;
  141667. }
  141668. }
  141669. return 0;
  141670. }
  141671. int ov_halfrate_p(OggVorbis_File *vf){
  141672. if(vf->vi==NULL)return OV_EINVAL;
  141673. return vorbis_synthesis_halfrate_p(vf->vi);
  141674. }
  141675. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141676. ov_callbacks callbacks)
  141677. {
  141678. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141679. }
  141680. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141681. ov_callbacks callbacks = {
  141682. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141683. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141684. (int (*)(void *)) fclose,
  141685. (long (*)(void *)) ftell
  141686. };
  141687. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141688. }
  141689. int ov_test_open(OggVorbis_File *vf){
  141690. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141691. return _ov_open2(vf);
  141692. }
  141693. long ov_streams(OggVorbis_File *vf){
  141694. return vf->links;
  141695. }
  141696. long ov_seekable(OggVorbis_File *vf){
  141697. return vf->seekable;
  141698. }
  141699. long ov_bitrate(OggVorbis_File *vf,int i){
  141700. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141701. if(i>=vf->links)return(OV_EINVAL);
  141702. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141703. if(i<0){
  141704. ogg_int64_t bits=0;
  141705. int i;
  141706. float br;
  141707. for(i=0;i<vf->links;i++)
  141708. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141709. br = bits/ov_time_total(vf,-1);
  141710. return(rint(br));
  141711. }else{
  141712. if(vf->seekable){
  141713. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141714. }else{
  141715. if(vf->vi[i].bitrate_nominal>0){
  141716. return vf->vi[i].bitrate_nominal;
  141717. }else{
  141718. if(vf->vi[i].bitrate_upper>0){
  141719. if(vf->vi[i].bitrate_lower>0){
  141720. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141721. }else{
  141722. return vf->vi[i].bitrate_upper;
  141723. }
  141724. }
  141725. return(OV_FALSE);
  141726. }
  141727. }
  141728. }
  141729. }
  141730. long ov_bitrate_instant(OggVorbis_File *vf){
  141731. int link=(vf->seekable?vf->current_link:0);
  141732. long ret;
  141733. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141734. if(vf->samptrack==0)return(OV_FALSE);
  141735. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141736. vf->bittrack=0.f;
  141737. vf->samptrack=0.f;
  141738. return(ret);
  141739. }
  141740. long ov_serialnumber(OggVorbis_File *vf,int i){
  141741. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141742. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141743. if(i<0){
  141744. return(vf->current_serialno);
  141745. }else{
  141746. return(vf->serialnos[i]);
  141747. }
  141748. }
  141749. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141750. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141751. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141752. if(i<0){
  141753. ogg_int64_t acc=0;
  141754. int i;
  141755. for(i=0;i<vf->links;i++)
  141756. acc+=ov_raw_total(vf,i);
  141757. return(acc);
  141758. }else{
  141759. return(vf->offsets[i+1]-vf->offsets[i]);
  141760. }
  141761. }
  141762. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141763. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141764. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141765. if(i<0){
  141766. ogg_int64_t acc=0;
  141767. int i;
  141768. for(i=0;i<vf->links;i++)
  141769. acc+=ov_pcm_total(vf,i);
  141770. return(acc);
  141771. }else{
  141772. return(vf->pcmlengths[i*2+1]);
  141773. }
  141774. }
  141775. double ov_time_total(OggVorbis_File *vf,int i){
  141776. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141777. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141778. if(i<0){
  141779. double acc=0;
  141780. int i;
  141781. for(i=0;i<vf->links;i++)
  141782. acc+=ov_time_total(vf,i);
  141783. return(acc);
  141784. }else{
  141785. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141786. }
  141787. }
  141788. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141789. ogg_stream_state work_os;
  141790. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141791. if(!vf->seekable)
  141792. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141793. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141794. vf->pcm_offset=-1;
  141795. ogg_stream_reset_serialno(&vf->os,
  141796. vf->current_serialno); /* must set serialno */
  141797. vorbis_synthesis_restart(&vf->vd);
  141798. _seek_helper(vf,pos);
  141799. {
  141800. ogg_page og;
  141801. ogg_packet op;
  141802. int lastblock=0;
  141803. int accblock=0;
  141804. int thisblock;
  141805. int eosflag;
  141806. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141807. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141808. return from not necessarily
  141809. starting from the beginning */
  141810. while(1){
  141811. if(vf->ready_state>=STREAMSET){
  141812. int result=ogg_stream_packetout(&work_os,&op);
  141813. if(result>0){
  141814. if(vf->vi[vf->current_link].codec_setup){
  141815. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141816. if(thisblock<0){
  141817. ogg_stream_packetout(&vf->os,NULL);
  141818. thisblock=0;
  141819. }else{
  141820. if(eosflag)
  141821. ogg_stream_packetout(&vf->os,NULL);
  141822. else
  141823. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141824. }
  141825. if(op.granulepos!=-1){
  141826. int i,link=vf->current_link;
  141827. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141828. if(granulepos<0)granulepos=0;
  141829. for(i=0;i<link;i++)
  141830. granulepos+=vf->pcmlengths[i*2+1];
  141831. vf->pcm_offset=granulepos-accblock;
  141832. break;
  141833. }
  141834. lastblock=thisblock;
  141835. continue;
  141836. }else
  141837. ogg_stream_packetout(&vf->os,NULL);
  141838. }
  141839. }
  141840. if(!lastblock){
  141841. if(_get_next_page(vf,&og,-1)<0){
  141842. vf->pcm_offset=ov_pcm_total(vf,-1);
  141843. break;
  141844. }
  141845. }else{
  141846. vf->pcm_offset=-1;
  141847. break;
  141848. }
  141849. if(vf->ready_state>=STREAMSET)
  141850. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141851. _decode_clear(vf); /* clear out stream state */
  141852. ogg_stream_clear(&work_os);
  141853. }
  141854. if(vf->ready_state<STREAMSET){
  141855. int link;
  141856. vf->current_serialno=ogg_page_serialno(&og);
  141857. for(link=0;link<vf->links;link++)
  141858. if(vf->serialnos[link]==vf->current_serialno)break;
  141859. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141860. error out, leave
  141861. machine uninitialized */
  141862. vf->current_link=link;
  141863. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141864. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141865. vf->ready_state=STREAMSET;
  141866. }
  141867. ogg_stream_pagein(&vf->os,&og);
  141868. ogg_stream_pagein(&work_os,&og);
  141869. eosflag=ogg_page_eos(&og);
  141870. }
  141871. }
  141872. ogg_stream_clear(&work_os);
  141873. vf->bittrack=0.f;
  141874. vf->samptrack=0.f;
  141875. return(0);
  141876. seek_error:
  141877. vf->pcm_offset=-1;
  141878. ogg_stream_clear(&work_os);
  141879. _decode_clear(vf);
  141880. return OV_EBADLINK;
  141881. }
  141882. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141883. int link=-1;
  141884. ogg_int64_t result=0;
  141885. ogg_int64_t total=ov_pcm_total(vf,-1);
  141886. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141887. if(!vf->seekable)return(OV_ENOSEEK);
  141888. if(pos<0 || pos>total)return(OV_EINVAL);
  141889. for(link=vf->links-1;link>=0;link--){
  141890. total-=vf->pcmlengths[link*2+1];
  141891. if(pos>=total)break;
  141892. }
  141893. {
  141894. ogg_int64_t end=vf->offsets[link+1];
  141895. ogg_int64_t begin=vf->offsets[link];
  141896. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141897. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141898. ogg_int64_t target=pos-total+begintime;
  141899. ogg_int64_t best=begin;
  141900. ogg_page og;
  141901. while(begin<end){
  141902. ogg_int64_t bisect;
  141903. if(end-begin<CHUNKSIZE){
  141904. bisect=begin;
  141905. }else{
  141906. bisect=begin +
  141907. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141908. if(bisect<=begin)
  141909. bisect=begin+1;
  141910. }
  141911. _seek_helper(vf,bisect);
  141912. while(begin<end){
  141913. result=_get_next_page(vf,&og,end-vf->offset);
  141914. if(result==OV_EREAD) goto seek_error;
  141915. if(result<0){
  141916. if(bisect<=begin+1)
  141917. end=begin; /* found it */
  141918. else{
  141919. if(bisect==0) goto seek_error;
  141920. bisect-=CHUNKSIZE;
  141921. if(bisect<=begin)bisect=begin+1;
  141922. _seek_helper(vf,bisect);
  141923. }
  141924. }else{
  141925. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141926. if(granulepos==-1)continue;
  141927. if(granulepos<target){
  141928. best=result; /* raw offset of packet with granulepos */
  141929. begin=vf->offset; /* raw offset of next page */
  141930. begintime=granulepos;
  141931. if(target-begintime>44100)break;
  141932. bisect=begin; /* *not* begin + 1 */
  141933. }else{
  141934. if(bisect<=begin+1)
  141935. end=begin; /* found it */
  141936. else{
  141937. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141938. end=result;
  141939. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141940. if(bisect<=begin)bisect=begin+1;
  141941. _seek_helper(vf,bisect);
  141942. }else{
  141943. end=result;
  141944. endtime=granulepos;
  141945. break;
  141946. }
  141947. }
  141948. }
  141949. }
  141950. }
  141951. }
  141952. {
  141953. ogg_page og;
  141954. ogg_packet op;
  141955. _seek_helper(vf,best);
  141956. vf->pcm_offset=-1;
  141957. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141958. if(link!=vf->current_link){
  141959. _decode_clear(vf);
  141960. vf->current_link=link;
  141961. vf->current_serialno=ogg_page_serialno(&og);
  141962. vf->ready_state=STREAMSET;
  141963. }else{
  141964. vorbis_synthesis_restart(&vf->vd);
  141965. }
  141966. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141967. ogg_stream_pagein(&vf->os,&og);
  141968. while(1){
  141969. result=ogg_stream_packetpeek(&vf->os,&op);
  141970. if(result==0){
  141971. _seek_helper(vf,best);
  141972. while(1){
  141973. result=_get_prev_page(vf,&og);
  141974. if(result<0) goto seek_error;
  141975. if(ogg_page_granulepos(&og)>-1 ||
  141976. !ogg_page_continued(&og)){
  141977. return ov_raw_seek(vf,result);
  141978. }
  141979. vf->offset=result;
  141980. }
  141981. }
  141982. if(result<0){
  141983. result = OV_EBADPACKET;
  141984. goto seek_error;
  141985. }
  141986. if(op.granulepos!=-1){
  141987. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141988. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141989. vf->pcm_offset+=total;
  141990. break;
  141991. }else
  141992. result=ogg_stream_packetout(&vf->os,NULL);
  141993. }
  141994. }
  141995. }
  141996. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141997. result=OV_EFAULT;
  141998. goto seek_error;
  141999. }
  142000. vf->bittrack=0.f;
  142001. vf->samptrack=0.f;
  142002. return(0);
  142003. seek_error:
  142004. vf->pcm_offset=-1;
  142005. _decode_clear(vf);
  142006. return (int)result;
  142007. }
  142008. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  142009. int thisblock,lastblock=0;
  142010. int ret=ov_pcm_seek_page(vf,pos);
  142011. if(ret<0)return(ret);
  142012. if((ret=_make_decode_ready(vf)))return ret;
  142013. while(1){
  142014. ogg_packet op;
  142015. ogg_page og;
  142016. int ret=ogg_stream_packetpeek(&vf->os,&op);
  142017. if(ret>0){
  142018. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  142019. if(thisblock<0){
  142020. ogg_stream_packetout(&vf->os,NULL);
  142021. continue; /* non audio packet */
  142022. }
  142023. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  142024. if(vf->pcm_offset+((thisblock+
  142025. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  142026. ogg_stream_packetout(&vf->os,NULL);
  142027. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  142028. only tracking, no
  142029. pcm_decode */
  142030. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  142031. if(op.granulepos>-1){
  142032. int i;
  142033. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142034. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142035. for(i=0;i<vf->current_link;i++)
  142036. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  142037. }
  142038. lastblock=thisblock;
  142039. }else{
  142040. if(ret<0 && ret!=OV_HOLE)break;
  142041. if(_get_next_page(vf,&og,-1)<0)break;
  142042. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  142043. if(vf->ready_state<STREAMSET){
  142044. int link;
  142045. vf->current_serialno=ogg_page_serialno(&og);
  142046. for(link=0;link<vf->links;link++)
  142047. if(vf->serialnos[link]==vf->current_serialno)break;
  142048. if(link==vf->links)return(OV_EBADLINK);
  142049. vf->current_link=link;
  142050. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142051. vf->ready_state=STREAMSET;
  142052. ret=_make_decode_ready(vf);
  142053. if(ret)return ret;
  142054. lastblock=0;
  142055. }
  142056. ogg_stream_pagein(&vf->os,&og);
  142057. }
  142058. }
  142059. vf->bittrack=0.f;
  142060. vf->samptrack=0.f;
  142061. while(vf->pcm_offset<pos){
  142062. ogg_int64_t target=pos-vf->pcm_offset;
  142063. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  142064. if(samples>target)samples=target;
  142065. vorbis_synthesis_read(&vf->vd,samples);
  142066. vf->pcm_offset+=samples;
  142067. if(samples<target)
  142068. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  142069. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  142070. }
  142071. return 0;
  142072. }
  142073. int ov_time_seek(OggVorbis_File *vf,double seconds){
  142074. int link=-1;
  142075. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142076. double time_total=ov_time_total(vf,-1);
  142077. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142078. if(!vf->seekable)return(OV_ENOSEEK);
  142079. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142080. for(link=vf->links-1;link>=0;link--){
  142081. pcm_total-=vf->pcmlengths[link*2+1];
  142082. time_total-=ov_time_total(vf,link);
  142083. if(seconds>=time_total)break;
  142084. }
  142085. {
  142086. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142087. return(ov_pcm_seek(vf,target));
  142088. }
  142089. }
  142090. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  142091. int link=-1;
  142092. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142093. double time_total=ov_time_total(vf,-1);
  142094. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142095. if(!vf->seekable)return(OV_ENOSEEK);
  142096. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142097. for(link=vf->links-1;link>=0;link--){
  142098. pcm_total-=vf->pcmlengths[link*2+1];
  142099. time_total-=ov_time_total(vf,link);
  142100. if(seconds>=time_total)break;
  142101. }
  142102. {
  142103. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142104. return(ov_pcm_seek_page(vf,target));
  142105. }
  142106. }
  142107. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142108. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142109. return(vf->offset);
  142110. }
  142111. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142112. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142113. return(vf->pcm_offset);
  142114. }
  142115. double ov_time_tell(OggVorbis_File *vf){
  142116. int link=0;
  142117. ogg_int64_t pcm_total=0;
  142118. double time_total=0.f;
  142119. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142120. if(vf->seekable){
  142121. pcm_total=ov_pcm_total(vf,-1);
  142122. time_total=ov_time_total(vf,-1);
  142123. for(link=vf->links-1;link>=0;link--){
  142124. pcm_total-=vf->pcmlengths[link*2+1];
  142125. time_total-=ov_time_total(vf,link);
  142126. if(vf->pcm_offset>=pcm_total)break;
  142127. }
  142128. }
  142129. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142130. }
  142131. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142132. if(vf->seekable){
  142133. if(link<0)
  142134. if(vf->ready_state>=STREAMSET)
  142135. return vf->vi+vf->current_link;
  142136. else
  142137. return vf->vi;
  142138. else
  142139. if(link>=vf->links)
  142140. return NULL;
  142141. else
  142142. return vf->vi+link;
  142143. }else{
  142144. return vf->vi;
  142145. }
  142146. }
  142147. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142148. if(vf->seekable){
  142149. if(link<0)
  142150. if(vf->ready_state>=STREAMSET)
  142151. return vf->vc+vf->current_link;
  142152. else
  142153. return vf->vc;
  142154. else
  142155. if(link>=vf->links)
  142156. return NULL;
  142157. else
  142158. return vf->vc+link;
  142159. }else{
  142160. return vf->vc;
  142161. }
  142162. }
  142163. static int host_is_big_endian() {
  142164. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142165. unsigned char *bytewise = (unsigned char *)&pattern;
  142166. if (bytewise[0] == 0xfe) return 1;
  142167. return 0;
  142168. }
  142169. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142170. int bigendianp,int word,int sgned,int *bitstream){
  142171. int i,j;
  142172. int host_endian = host_is_big_endian();
  142173. float **pcm;
  142174. long samples;
  142175. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142176. while(1){
  142177. if(vf->ready_state==INITSET){
  142178. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142179. if(samples)break;
  142180. }
  142181. {
  142182. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142183. if(ret==OV_EOF)
  142184. return(0);
  142185. if(ret<=0)
  142186. return(ret);
  142187. }
  142188. }
  142189. if(samples>0){
  142190. long channels=ov_info(vf,-1)->channels;
  142191. long bytespersample=word * channels;
  142192. vorbis_fpu_control fpu;
  142193. (void) fpu; // (to avoid a warning about it being unused)
  142194. if(samples>length/bytespersample)samples=length/bytespersample;
  142195. if(samples <= 0)
  142196. return OV_EINVAL;
  142197. {
  142198. int val;
  142199. if(word==1){
  142200. int off=(sgned?0:128);
  142201. vorbis_fpu_setround(&fpu);
  142202. for(j=0;j<samples;j++)
  142203. for(i=0;i<channels;i++){
  142204. val=vorbis_ftoi(pcm[i][j]*128.f);
  142205. if(val>127)val=127;
  142206. else if(val<-128)val=-128;
  142207. *buffer++=val+off;
  142208. }
  142209. vorbis_fpu_restore(fpu);
  142210. }else{
  142211. int off=(sgned?0:32768);
  142212. if(host_endian==bigendianp){
  142213. if(sgned){
  142214. vorbis_fpu_setround(&fpu);
  142215. for(i=0;i<channels;i++) { /* It's faster in this order */
  142216. float *src=pcm[i];
  142217. short *dest=((short *)buffer)+i;
  142218. for(j=0;j<samples;j++) {
  142219. val=vorbis_ftoi(src[j]*32768.f);
  142220. if(val>32767)val=32767;
  142221. else if(val<-32768)val=-32768;
  142222. *dest=val;
  142223. dest+=channels;
  142224. }
  142225. }
  142226. vorbis_fpu_restore(fpu);
  142227. }else{
  142228. vorbis_fpu_setround(&fpu);
  142229. for(i=0;i<channels;i++) {
  142230. float *src=pcm[i];
  142231. short *dest=((short *)buffer)+i;
  142232. for(j=0;j<samples;j++) {
  142233. val=vorbis_ftoi(src[j]*32768.f);
  142234. if(val>32767)val=32767;
  142235. else if(val<-32768)val=-32768;
  142236. *dest=val+off;
  142237. dest+=channels;
  142238. }
  142239. }
  142240. vorbis_fpu_restore(fpu);
  142241. }
  142242. }else if(bigendianp){
  142243. vorbis_fpu_setround(&fpu);
  142244. for(j=0;j<samples;j++)
  142245. for(i=0;i<channels;i++){
  142246. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142247. if(val>32767)val=32767;
  142248. else if(val<-32768)val=-32768;
  142249. val+=off;
  142250. *buffer++=(val>>8);
  142251. *buffer++=(val&0xff);
  142252. }
  142253. vorbis_fpu_restore(fpu);
  142254. }else{
  142255. int val;
  142256. vorbis_fpu_setround(&fpu);
  142257. for(j=0;j<samples;j++)
  142258. for(i=0;i<channels;i++){
  142259. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142260. if(val>32767)val=32767;
  142261. else if(val<-32768)val=-32768;
  142262. val+=off;
  142263. *buffer++=(val&0xff);
  142264. *buffer++=(val>>8);
  142265. }
  142266. vorbis_fpu_restore(fpu);
  142267. }
  142268. }
  142269. }
  142270. vorbis_synthesis_read(&vf->vd,samples);
  142271. vf->pcm_offset+=samples;
  142272. if(bitstream)*bitstream=vf->current_link;
  142273. return(samples*bytespersample);
  142274. }else{
  142275. return(samples);
  142276. }
  142277. }
  142278. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142279. int *bitstream){
  142280. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142281. while(1){
  142282. if(vf->ready_state==INITSET){
  142283. float **pcm;
  142284. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142285. if(samples){
  142286. if(pcm_channels)*pcm_channels=pcm;
  142287. if(samples>length)samples=length;
  142288. vorbis_synthesis_read(&vf->vd,samples);
  142289. vf->pcm_offset+=samples;
  142290. if(bitstream)*bitstream=vf->current_link;
  142291. return samples;
  142292. }
  142293. }
  142294. {
  142295. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142296. if(ret==OV_EOF)return(0);
  142297. if(ret<=0)return(ret);
  142298. }
  142299. }
  142300. }
  142301. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142302. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142303. ogg_int64_t off);
  142304. static void _ov_splice(float **pcm,float **lappcm,
  142305. int n1, int n2,
  142306. int ch1, int ch2,
  142307. float *w1, float *w2){
  142308. int i,j;
  142309. float *w=w1;
  142310. int n=n1;
  142311. if(n1>n2){
  142312. n=n2;
  142313. w=w2;
  142314. }
  142315. for(j=0;j<ch1 && j<ch2;j++){
  142316. float *s=lappcm[j];
  142317. float *d=pcm[j];
  142318. for(i=0;i<n;i++){
  142319. float wd=w[i]*w[i];
  142320. float ws=1.-wd;
  142321. d[i]=d[i]*wd + s[i]*ws;
  142322. }
  142323. }
  142324. for(;j<ch2;j++){
  142325. float *d=pcm[j];
  142326. for(i=0;i<n;i++){
  142327. float wd=w[i]*w[i];
  142328. d[i]=d[i]*wd;
  142329. }
  142330. }
  142331. }
  142332. static int _ov_initset(OggVorbis_File *vf){
  142333. while(1){
  142334. if(vf->ready_state==INITSET)break;
  142335. {
  142336. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142337. if(ret<0 && ret!=OV_HOLE)return(ret);
  142338. }
  142339. }
  142340. return 0;
  142341. }
  142342. static int _ov_initprime(OggVorbis_File *vf){
  142343. vorbis_dsp_state *vd=&vf->vd;
  142344. while(1){
  142345. if(vf->ready_state==INITSET)
  142346. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142347. {
  142348. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142349. if(ret<0 && ret!=OV_HOLE)return(ret);
  142350. }
  142351. }
  142352. return 0;
  142353. }
  142354. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142355. float **lappcm,int lapsize){
  142356. int lapcount=0,i;
  142357. float **pcm;
  142358. while(lapcount<lapsize){
  142359. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142360. if(samples){
  142361. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142362. for(i=0;i<vi->channels;i++)
  142363. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142364. lapcount+=samples;
  142365. vorbis_synthesis_read(vd,samples);
  142366. }else{
  142367. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142368. if(ret==OV_EOF)break;
  142369. }
  142370. }
  142371. if(lapcount<lapsize){
  142372. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142373. if(samples==0){
  142374. for(i=0;i<vi->channels;i++)
  142375. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142376. lapcount=lapsize;
  142377. }else{
  142378. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142379. for(i=0;i<vi->channels;i++)
  142380. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142381. lapcount+=samples;
  142382. }
  142383. }
  142384. }
  142385. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142386. vorbis_info *vi1,*vi2;
  142387. float **lappcm;
  142388. float **pcm;
  142389. float *w1,*w2;
  142390. int n1,n2,i,ret,hs1,hs2;
  142391. if(vf1==vf2)return(0); /* degenerate case */
  142392. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142393. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142394. ret=_ov_initset(vf1);
  142395. if(ret)return(ret);
  142396. ret=_ov_initprime(vf2);
  142397. if(ret)return(ret);
  142398. vi1=ov_info(vf1,-1);
  142399. vi2=ov_info(vf2,-1);
  142400. hs1=ov_halfrate_p(vf1);
  142401. hs2=ov_halfrate_p(vf2);
  142402. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142403. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142404. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142405. w1=vorbis_window(&vf1->vd,0);
  142406. w2=vorbis_window(&vf2->vd,0);
  142407. for(i=0;i<vi1->channels;i++)
  142408. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142409. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142410. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142411. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142412. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142413. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142414. return(0);
  142415. }
  142416. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142417. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142418. vorbis_info *vi;
  142419. float **lappcm;
  142420. float **pcm;
  142421. float *w1,*w2;
  142422. int n1,n2,ch1,ch2,hs;
  142423. int i,ret;
  142424. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142425. ret=_ov_initset(vf);
  142426. if(ret)return(ret);
  142427. vi=ov_info(vf,-1);
  142428. hs=ov_halfrate_p(vf);
  142429. ch1=vi->channels;
  142430. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142431. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142432. persistent; even if the decode state
  142433. from this link gets dumped, this
  142434. window array continues to exist */
  142435. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142436. for(i=0;i<ch1;i++)
  142437. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142438. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142439. ret=localseek(vf,pos);
  142440. if(ret)return ret;
  142441. ret=_ov_initprime(vf);
  142442. if(ret)return(ret);
  142443. vi=ov_info(vf,-1);
  142444. ch2=vi->channels;
  142445. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142446. w2=vorbis_window(&vf->vd,0);
  142447. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142448. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142449. return(0);
  142450. }
  142451. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142452. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142453. }
  142454. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142455. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142456. }
  142457. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142458. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142459. }
  142460. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142461. int (*localseek)(OggVorbis_File *,double)){
  142462. vorbis_info *vi;
  142463. float **lappcm;
  142464. float **pcm;
  142465. float *w1,*w2;
  142466. int n1,n2,ch1,ch2,hs;
  142467. int i,ret;
  142468. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142469. ret=_ov_initset(vf);
  142470. if(ret)return(ret);
  142471. vi=ov_info(vf,-1);
  142472. hs=ov_halfrate_p(vf);
  142473. ch1=vi->channels;
  142474. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142475. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142476. persistent; even if the decode state
  142477. from this link gets dumped, this
  142478. window array continues to exist */
  142479. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142480. for(i=0;i<ch1;i++)
  142481. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142482. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142483. ret=localseek(vf,pos);
  142484. if(ret)return ret;
  142485. ret=_ov_initprime(vf);
  142486. if(ret)return(ret);
  142487. vi=ov_info(vf,-1);
  142488. ch2=vi->channels;
  142489. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142490. w2=vorbis_window(&vf->vd,0);
  142491. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142492. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142493. return(0);
  142494. }
  142495. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142496. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142497. }
  142498. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142499. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142500. }
  142501. #endif
  142502. /*** End of inlined file: vorbisfile.c ***/
  142503. /*** Start of inlined file: window.c ***/
  142504. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142505. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142506. // tasks..
  142507. #if JUCE_MSVC
  142508. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142509. #endif
  142510. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142511. #if JUCE_USE_OGGVORBIS
  142512. #include <stdlib.h>
  142513. #include <math.h>
  142514. static float vwin64[32] = {
  142515. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142516. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142517. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142518. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142519. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142520. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142521. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142522. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142523. };
  142524. static float vwin128[64] = {
  142525. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142526. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142527. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142528. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142529. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142530. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142531. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142532. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142533. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142534. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142535. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142536. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142537. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142538. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142539. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142540. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142541. };
  142542. static float vwin256[128] = {
  142543. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142544. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142545. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142546. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142547. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142548. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142549. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142550. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142551. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142552. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142553. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142554. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142555. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142556. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142557. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142558. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142559. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142560. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142561. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142562. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142563. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142564. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142565. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142566. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142567. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142568. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142569. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142570. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142571. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142572. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142573. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142574. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142575. };
  142576. static float vwin512[256] = {
  142577. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142578. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142579. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142580. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142581. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142582. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142583. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142584. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142585. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142586. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142587. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142588. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142589. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142590. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142591. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142592. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142593. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142594. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142595. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142596. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142597. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142598. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142599. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142600. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142601. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142602. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142603. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142604. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142605. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142606. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142607. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142608. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142609. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142610. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142611. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142612. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142613. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142614. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142615. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142616. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142617. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142618. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142619. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142620. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142621. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142622. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142623. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142624. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142625. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142626. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142627. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142628. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142629. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142630. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142631. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142632. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142633. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142634. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142635. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142636. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142637. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142638. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142639. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142640. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142641. };
  142642. static float vwin1024[512] = {
  142643. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142644. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142645. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142646. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142647. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142648. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142649. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142650. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142651. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142652. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142653. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142654. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142655. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142656. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142657. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142658. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142659. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142660. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142661. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142662. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142663. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142664. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142665. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142666. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142667. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142668. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142669. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142670. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142671. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142672. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142673. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142674. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142675. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142676. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142677. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142678. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142679. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142680. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142681. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142682. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142683. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142684. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142685. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142686. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142687. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142688. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142689. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142690. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142691. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142692. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142693. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142694. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142695. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142696. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142697. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142698. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142699. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142700. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142701. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142702. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142703. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142704. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142705. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142706. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142707. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142708. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142709. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142710. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142711. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142712. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142713. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142714. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142715. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142716. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142717. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142718. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142719. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142720. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142721. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142722. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142723. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142724. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142725. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142726. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142727. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142728. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142729. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142730. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142731. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142732. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142733. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142734. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142735. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142736. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142737. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142738. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142739. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142740. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142741. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142742. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142743. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142744. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142745. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142746. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142747. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142748. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142749. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142750. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142751. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142752. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142753. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142754. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142755. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142756. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142757. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142758. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142759. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142760. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142761. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142762. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142763. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142764. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142765. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142766. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142767. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142768. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142769. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142770. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142771. };
  142772. static float vwin2048[1024] = {
  142773. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142774. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142775. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142776. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142777. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142778. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142779. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142780. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142781. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142782. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142783. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142784. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142785. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142786. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142787. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142788. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142789. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142790. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142791. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142792. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142793. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142794. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142795. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142796. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142797. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142798. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142799. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142800. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142801. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142802. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142803. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142804. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142805. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142806. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142807. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142808. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142809. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142810. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142811. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142812. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142813. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142814. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142815. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142816. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142817. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142818. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142819. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142820. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142821. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142822. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142823. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142824. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142825. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142826. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142827. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142828. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142829. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142830. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142831. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142832. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142833. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142834. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142835. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142836. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142837. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142838. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142839. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142840. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142841. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142842. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142843. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142844. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142845. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142846. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142847. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142848. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142849. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142850. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142851. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142852. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142853. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142854. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142855. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142856. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142857. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142858. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142859. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142860. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142861. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142862. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142863. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142864. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142865. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142866. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142867. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142868. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142869. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142870. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142871. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142872. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142873. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142874. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142875. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142876. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142877. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142878. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142879. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142880. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142881. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142882. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142883. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142884. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142885. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142886. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142887. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142888. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142889. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142890. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142891. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142892. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142893. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142894. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142895. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142896. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142897. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142898. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142899. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142900. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142901. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142902. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142903. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142904. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142905. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142906. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142907. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142908. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142909. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142910. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142911. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142912. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142913. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142914. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142915. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142916. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142917. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142918. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142919. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142920. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142921. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142922. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142923. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142924. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142925. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142926. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142927. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142928. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142929. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142930. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142931. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142932. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142933. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142934. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142935. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142936. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142937. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142938. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142939. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142940. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142941. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142942. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142943. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142944. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142945. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142946. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142947. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142948. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142949. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142950. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142951. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142952. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142953. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142954. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142955. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142956. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142957. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142958. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142959. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142960. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142961. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142962. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142963. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142964. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142965. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142966. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142967. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142968. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142969. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142970. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142971. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142972. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142973. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142974. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142975. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142976. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142977. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142978. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142979. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142980. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142981. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142982. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142983. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142984. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142985. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142986. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142987. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142988. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142989. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142990. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142991. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142992. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142993. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142994. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142995. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142996. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142997. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142998. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142999. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  143000. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  143001. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  143002. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  143003. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  143004. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  143005. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  143006. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  143007. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  143008. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  143009. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  143010. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  143011. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  143012. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  143013. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  143014. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  143015. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  143016. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  143017. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  143018. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  143019. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  143020. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  143021. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  143022. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  143023. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  143024. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  143025. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  143026. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  143027. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  143028. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  143029. };
  143030. static float vwin4096[2048] = {
  143031. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  143032. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  143033. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  143034. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  143035. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  143036. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  143037. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  143038. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  143039. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  143040. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  143041. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  143042. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  143043. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  143044. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  143045. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  143046. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  143047. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  143048. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  143049. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  143050. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  143051. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  143052. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  143053. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  143054. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  143055. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  143056. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  143057. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  143058. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  143059. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  143060. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  143061. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  143062. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  143063. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  143064. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  143065. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  143066. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  143067. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  143068. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  143069. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  143070. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  143071. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  143072. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  143073. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  143074. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  143075. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  143076. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  143077. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  143078. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  143079. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  143080. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  143081. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  143082. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  143083. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  143084. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  143085. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  143086. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  143087. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  143088. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  143089. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  143090. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  143091. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  143092. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  143093. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  143094. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  143095. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  143096. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143097. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143098. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143099. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143100. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143101. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143102. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143103. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143104. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143105. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143106. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143107. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143108. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143109. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143110. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143111. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143112. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143113. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143114. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143115. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143116. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143117. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143118. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143119. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143120. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143121. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143122. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143123. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143124. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143125. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143126. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143127. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143128. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143129. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143130. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143131. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143132. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143133. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143134. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143135. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143136. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143137. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143138. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143139. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143140. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143141. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143142. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143143. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143144. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143145. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143146. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143147. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143148. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143149. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143150. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143151. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143152. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143153. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143154. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143155. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143156. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143157. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143158. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143159. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143160. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143161. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143162. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143163. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143164. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143165. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143166. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143167. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143168. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143169. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143170. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143171. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143172. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143173. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143174. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143175. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143176. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143177. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143178. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143179. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143180. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143181. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143182. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143183. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143184. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143185. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143186. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143187. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143188. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143189. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143190. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143191. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143192. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143193. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143194. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143195. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143196. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143197. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143198. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143199. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143200. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143201. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143202. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143203. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143204. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143205. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143206. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143207. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143208. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143209. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143210. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143211. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143212. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143213. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143214. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143215. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143216. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143217. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143218. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143219. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143220. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143221. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143222. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143223. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143224. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143225. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143226. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143227. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143228. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143229. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143230. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143231. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143232. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143233. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143234. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143235. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143236. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143237. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143238. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143239. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143240. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143241. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143242. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143243. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143244. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143245. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143246. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143247. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143248. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143249. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143250. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143251. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143252. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143253. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143254. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143255. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143256. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143257. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143258. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143259. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143260. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143261. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143262. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143263. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143264. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143265. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143266. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143267. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143268. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143269. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143270. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143271. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143272. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143273. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143274. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143275. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143276. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143277. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143278. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143279. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143280. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143281. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143282. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143283. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143284. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143285. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143286. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143287. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143288. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143289. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143290. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143291. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143292. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143293. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143294. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143295. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143296. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143297. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143298. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143299. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143300. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143301. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143302. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143303. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143304. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143305. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143306. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143307. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143308. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143309. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143310. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143311. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143312. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143313. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143314. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143315. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143316. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143317. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143318. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143319. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143320. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143321. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143322. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143323. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143324. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143325. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143326. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143327. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143328. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143329. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143330. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143331. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143332. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143333. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143334. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143335. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143336. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143337. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143338. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143339. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143340. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143341. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143342. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143343. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143344. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143345. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143346. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143347. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143348. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143349. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143350. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143351. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143352. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143353. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143354. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143355. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143356. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143357. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143358. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143359. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143360. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143361. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143362. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143363. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143364. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143365. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143366. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143367. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143368. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143369. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143370. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143371. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143372. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143373. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143374. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143375. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143376. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143377. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143378. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143379. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143380. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143381. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143382. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143383. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143384. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143385. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143386. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143387. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143388. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143389. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143390. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143391. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143392. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143393. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143394. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143395. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143396. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143397. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143398. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143399. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143400. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143401. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143402. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143403. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143404. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143405. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143406. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143407. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143408. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143409. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143410. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143411. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143412. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143413. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143414. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143415. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143416. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143417. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143418. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143419. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143420. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143421. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143422. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143423. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143424. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143425. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143426. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143427. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143428. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143429. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143430. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143431. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143432. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143433. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143434. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143435. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143436. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143437. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143438. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143439. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143440. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143441. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143442. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143443. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143444. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143445. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143446. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143447. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143448. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143449. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143450. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143451. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143452. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143453. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143454. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143455. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143456. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143457. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143458. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143459. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143460. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143461. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143462. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143463. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143464. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143465. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143466. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143467. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143468. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143469. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143470. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143471. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143472. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143473. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143474. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143475. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143476. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143477. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143478. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143479. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143480. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143481. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143482. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143483. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143484. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143485. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143486. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143487. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143488. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143489. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143490. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143491. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143492. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143493. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143494. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143495. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143496. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143497. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143498. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143499. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143500. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143501. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143502. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143503. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143504. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143505. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143506. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143507. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143508. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143509. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143510. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143511. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143512. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143513. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143514. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143515. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143516. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143517. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143518. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143519. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143520. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143521. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143522. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143523. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143524. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143525. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143526. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143527. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143528. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143529. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143530. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143531. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143532. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143533. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143534. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143535. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143536. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143537. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143538. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143539. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143540. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143541. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143542. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143543. };
  143544. static float vwin8192[4096] = {
  143545. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143546. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143547. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143548. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143549. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143550. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143551. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143552. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143553. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143554. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143555. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143556. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143557. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143558. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143559. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143560. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143561. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143562. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143563. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143564. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143565. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143566. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143567. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143568. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143569. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143570. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143571. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143572. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143573. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143574. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143575. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143576. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143577. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143578. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143579. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143580. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143581. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143582. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143583. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143584. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143585. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143586. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143587. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143588. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143589. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143590. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143591. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143592. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143593. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143594. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143595. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143596. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143597. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143598. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143599. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143600. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143601. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143602. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143603. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143604. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143605. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143606. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143607. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143608. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143609. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143610. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143611. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143612. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143613. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143614. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143615. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143616. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143617. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143618. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143619. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143620. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143621. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143622. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143623. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143624. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143625. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143626. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143627. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143628. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143629. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143630. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143631. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143632. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143633. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143634. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143635. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143636. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143637. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143638. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143639. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143640. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143641. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143642. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143643. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143644. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143645. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143646. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143647. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143648. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143649. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143650. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143651. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143652. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143653. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143654. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143655. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143656. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143657. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143658. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143659. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143660. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143661. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143662. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143663. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143664. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143665. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143666. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143667. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143668. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143669. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143670. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143671. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143672. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143673. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143674. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143675. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143676. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143677. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143678. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143679. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143680. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143681. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143682. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143683. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143684. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143685. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143686. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143687. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143688. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143689. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143690. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143691. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143692. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143693. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143694. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143695. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143696. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143697. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143698. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143699. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143700. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143701. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143702. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143703. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143704. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143705. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143706. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143707. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143708. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143709. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143710. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143711. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143712. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143713. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143714. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143715. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143716. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143717. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143718. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143719. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143720. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143721. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143722. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143723. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143724. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143725. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143726. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143727. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143728. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143729. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143730. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143731. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143732. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143733. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143734. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143735. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143736. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143737. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143738. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143739. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143740. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143741. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143742. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143743. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143744. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143745. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143746. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143747. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143748. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143749. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143750. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143751. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143752. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143753. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143754. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143755. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143756. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143757. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143758. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143759. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143760. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143761. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143762. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143763. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143764. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143765. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143766. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143767. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143768. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143769. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143770. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143771. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143772. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143773. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143774. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143775. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143776. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143777. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143778. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143779. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143780. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143781. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143782. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143783. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143784. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143785. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143786. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143787. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143788. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143789. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143790. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143791. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143792. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143793. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143794. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143795. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143796. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143797. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143798. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143799. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143800. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143801. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143802. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143803. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143804. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143805. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143806. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143807. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143808. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143809. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143810. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143811. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143812. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143813. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143814. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143815. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143816. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143817. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143818. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143819. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143820. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143821. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143822. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143823. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143824. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143825. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143826. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143827. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143828. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143829. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143830. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143831. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143832. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143833. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143834. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143835. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143836. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143837. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143838. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143839. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143840. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143841. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143842. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143843. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143844. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143845. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143846. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143847. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143848. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143849. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143850. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143851. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143852. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143853. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143854. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143855. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143856. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143857. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143858. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143859. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143860. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143861. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143862. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143863. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143864. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143865. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143866. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143867. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143868. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143869. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143870. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143871. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143872. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143873. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143874. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143875. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143876. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143877. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143878. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143879. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143880. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143881. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143882. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143883. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143884. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143885. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143886. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143887. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143888. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143889. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143890. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143891. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143892. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143893. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143894. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143895. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143896. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143897. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143898. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143899. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143900. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143901. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143902. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143903. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143904. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143905. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143906. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143907. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143908. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143909. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143910. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143911. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143912. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143913. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143914. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143915. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143916. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143917. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143918. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143919. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143920. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143921. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143922. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143923. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143924. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143925. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143926. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143927. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143928. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143929. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143930. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143931. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143932. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143933. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143934. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143935. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143936. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143937. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143938. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143939. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143940. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143941. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143942. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143943. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143944. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143945. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143946. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143947. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143948. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143949. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143950. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143951. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143952. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143953. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143954. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143955. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143956. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143957. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143958. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143959. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143960. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143961. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143962. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143963. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143964. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143965. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143966. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143967. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143968. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143969. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143970. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143971. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143972. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143973. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143974. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143975. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143976. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143977. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143978. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143979. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143980. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143981. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143982. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143983. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143984. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143985. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143986. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143987. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143988. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143989. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143990. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143991. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143992. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143993. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143994. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143995. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143996. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143997. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143998. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143999. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  144000. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  144001. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  144002. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  144003. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  144004. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  144005. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  144006. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  144007. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  144008. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  144009. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  144010. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  144011. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  144012. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  144013. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  144014. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  144015. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  144016. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  144017. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  144018. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  144019. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  144020. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  144021. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  144022. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  144023. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  144024. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  144025. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  144026. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  144027. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  144028. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  144029. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  144030. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  144031. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  144032. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  144033. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  144034. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  144035. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  144036. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  144037. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  144038. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  144039. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  144040. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  144041. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  144042. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  144043. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  144044. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  144045. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  144046. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  144047. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  144048. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  144049. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  144050. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  144051. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  144052. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  144053. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  144054. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  144055. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  144056. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  144057. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  144058. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  144059. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  144060. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  144061. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  144062. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  144063. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  144064. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  144065. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  144066. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  144067. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  144068. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  144069. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  144070. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  144071. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  144072. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  144073. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  144074. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  144075. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  144076. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  144077. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  144078. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  144079. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  144080. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  144081. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  144082. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  144083. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  144084. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  144085. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  144086. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  144087. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  144088. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  144089. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  144090. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  144091. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  144092. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  144093. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  144094. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  144095. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  144096. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144097. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144098. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144099. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144100. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144101. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144102. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144103. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144104. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144105. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144106. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144107. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144108. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144109. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144110. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144111. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144112. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144113. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144114. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144115. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144116. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144117. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144118. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144119. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144120. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144121. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144122. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144123. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144124. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144125. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144126. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144127. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144128. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144129. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144130. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144131. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144132. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144133. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144134. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144135. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144136. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144137. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144138. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144139. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144140. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144141. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144142. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144143. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144144. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144145. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144146. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144147. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144148. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144149. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144150. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144151. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144152. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144153. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144154. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144155. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144156. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144157. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144158. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144159. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144160. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144161. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144162. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144163. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144164. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144165. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144166. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144167. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144168. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144169. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144170. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144171. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144172. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144173. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144174. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144175. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144176. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144177. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144178. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144179. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144180. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144181. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144182. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144183. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144184. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144185. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144186. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144187. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144188. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144189. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144190. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144191. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144192. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144193. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144194. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144195. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144196. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144197. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144198. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144199. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144200. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144201. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144202. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144203. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144204. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144205. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144206. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144207. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144208. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144209. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144210. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144211. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144212. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144213. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144214. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144215. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144216. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144217. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144218. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144219. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144220. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144221. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144222. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144223. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144224. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144225. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144226. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144227. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144228. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144229. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144230. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144231. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144232. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144233. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144234. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144235. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144236. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144237. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144238. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144239. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144240. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144241. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144242. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144243. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144244. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144245. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144246. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144247. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144248. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144249. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144250. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144251. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144252. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144253. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144254. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144255. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144256. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144257. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144258. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144259. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144260. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144261. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144262. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144263. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144264. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144265. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144266. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144267. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144268. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144269. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144270. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144271. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144272. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144273. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144274. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144275. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144276. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144277. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144278. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144279. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144280. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144281. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144282. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144283. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144284. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144285. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144286. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144287. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144288. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144289. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144290. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144291. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144292. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144293. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144294. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144295. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144296. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144297. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144298. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144299. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144300. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144301. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144302. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144303. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144304. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144305. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144306. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144307. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144308. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144309. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144310. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144311. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144312. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144313. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144314. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144315. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144316. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144317. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144318. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144319. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144320. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144321. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144322. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144323. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144324. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144325. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144326. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144327. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144328. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144329. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144330. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144331. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144332. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144333. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144334. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144335. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144336. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144337. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144338. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144339. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144340. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144341. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144342. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144343. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144344. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144345. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144346. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144347. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144348. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144349. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144350. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144351. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144352. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144353. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144354. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144355. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144356. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144357. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144358. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144359. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144360. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144361. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144362. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144363. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144364. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144365. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144366. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144367. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144368. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144369. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144370. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144371. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144372. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144373. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144374. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144375. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144376. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144377. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144378. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144379. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144380. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144381. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144382. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144383. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144384. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144385. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144386. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144387. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144388. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144389. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144390. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144391. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144392. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144393. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144394. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144395. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144396. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144397. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144398. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144399. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144400. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144401. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144402. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144403. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144404. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144405. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144406. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144407. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144408. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144409. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144410. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144411. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144412. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144413. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144414. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144415. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144416. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144417. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144418. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144419. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144420. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144421. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144422. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144423. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144424. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144425. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144426. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144427. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144428. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144429. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144430. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144431. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144432. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144433. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144434. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144435. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144436. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144437. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144438. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144439. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144440. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144441. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144442. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144443. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144444. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144445. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144446. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144447. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144448. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144449. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144450. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144451. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144452. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144453. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144454. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144455. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144456. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144457. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144458. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144459. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144460. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144461. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144462. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144463. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144464. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144465. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144466. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144467. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144468. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144469. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144470. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144471. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144472. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144473. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144474. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144475. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144476. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144477. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144478. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144479. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144480. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144481. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144482. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144483. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144484. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144485. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144486. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144487. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144488. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144489. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144490. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144491. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144492. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144493. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144494. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144495. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144496. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144497. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144498. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144499. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144500. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144501. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144502. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144503. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144504. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144505. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144506. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144507. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144508. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144509. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144510. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144511. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144512. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144513. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144514. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144515. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144516. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144517. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144518. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144519. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144520. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144521. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144522. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144523. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144524. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144525. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144526. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144527. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144528. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144529. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144530. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144531. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144532. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144533. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144534. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144535. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144536. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144537. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144538. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144539. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144540. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144541. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144542. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144543. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144544. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144545. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144546. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144547. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144548. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144549. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144550. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144551. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144552. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144553. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144554. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144555. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144556. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144557. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144558. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144559. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144560. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144561. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144562. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144563. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144564. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144565. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144566. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144567. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144568. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144569. };
  144570. static float *vwin[8] = {
  144571. vwin64,
  144572. vwin128,
  144573. vwin256,
  144574. vwin512,
  144575. vwin1024,
  144576. vwin2048,
  144577. vwin4096,
  144578. vwin8192,
  144579. };
  144580. float *_vorbis_window_get(int n){
  144581. return vwin[n];
  144582. }
  144583. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144584. int lW,int W,int nW){
  144585. lW=(W?lW:0);
  144586. nW=(W?nW:0);
  144587. {
  144588. float *windowLW=vwin[winno[lW]];
  144589. float *windowNW=vwin[winno[nW]];
  144590. long n=blocksizes[W];
  144591. long ln=blocksizes[lW];
  144592. long rn=blocksizes[nW];
  144593. long leftbegin=n/4-ln/4;
  144594. long leftend=leftbegin+ln/2;
  144595. long rightbegin=n/2+n/4-rn/4;
  144596. long rightend=rightbegin+rn/2;
  144597. int i,p;
  144598. for(i=0;i<leftbegin;i++)
  144599. d[i]=0.f;
  144600. for(p=0;i<leftend;i++,p++)
  144601. d[i]*=windowLW[p];
  144602. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144603. d[i]*=windowNW[p];
  144604. for(;i<n;i++)
  144605. d[i]=0.f;
  144606. }
  144607. }
  144608. #endif
  144609. /*** End of inlined file: window.c ***/
  144610. #else
  144611. #include <vorbis/vorbisenc.h>
  144612. #include <vorbis/codec.h>
  144613. #include <vorbis/vorbisfile.h>
  144614. #endif
  144615. }
  144616. BEGIN_JUCE_NAMESPACE
  144617. using namespace OggVorbisNamespace;
  144618. static const char* const oggFormatName = "Ogg-Vorbis file";
  144619. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144620. class OggReader : public AudioFormatReader
  144621. {
  144622. OggVorbis_File ovFile;
  144623. ov_callbacks callbacks;
  144624. AudioSampleBuffer reservoir;
  144625. int reservoirStart, samplesInReservoir;
  144626. public:
  144627. OggReader (InputStream* const inp)
  144628. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144629. reservoir (2, 4096),
  144630. reservoirStart (0),
  144631. samplesInReservoir (0)
  144632. {
  144633. sampleRate = 0;
  144634. usesFloatingPointData = true;
  144635. callbacks.read_func = &oggReadCallback;
  144636. callbacks.seek_func = &oggSeekCallback;
  144637. callbacks.close_func = &oggCloseCallback;
  144638. callbacks.tell_func = &oggTellCallback;
  144639. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144640. if (err == 0)
  144641. {
  144642. vorbis_info* info = ov_info (&ovFile, -1);
  144643. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144644. numChannels = info->channels;
  144645. bitsPerSample = 16;
  144646. sampleRate = info->rate;
  144647. reservoir.setSize (numChannels,
  144648. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144649. }
  144650. }
  144651. ~OggReader()
  144652. {
  144653. ov_clear (&ovFile);
  144654. }
  144655. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144656. int64 startSampleInFile, int numSamples)
  144657. {
  144658. while (numSamples > 0)
  144659. {
  144660. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144661. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144662. {
  144663. // got a few samples overlapping, so use them before seeking..
  144664. const int numToUse = jmin (numSamples, numAvailable);
  144665. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144666. if (destSamples[i] != 0)
  144667. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144668. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144669. sizeof (float) * numToUse);
  144670. startSampleInFile += numToUse;
  144671. numSamples -= numToUse;
  144672. startOffsetInDestBuffer += numToUse;
  144673. if (numSamples == 0)
  144674. break;
  144675. }
  144676. if (startSampleInFile < reservoirStart
  144677. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144678. {
  144679. // buffer miss, so refill the reservoir
  144680. int bitStream = 0;
  144681. reservoirStart = jmax (0, (int) startSampleInFile);
  144682. samplesInReservoir = reservoir.getNumSamples();
  144683. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144684. ov_pcm_seek (&ovFile, reservoirStart);
  144685. int offset = 0;
  144686. int numToRead = samplesInReservoir;
  144687. while (numToRead > 0)
  144688. {
  144689. float** dataIn = 0;
  144690. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144691. if (samps <= 0)
  144692. break;
  144693. jassert (samps <= numToRead);
  144694. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144695. {
  144696. memcpy (reservoir.getSampleData (i, offset),
  144697. dataIn[i],
  144698. sizeof (float) * samps);
  144699. }
  144700. numToRead -= samps;
  144701. offset += samps;
  144702. }
  144703. if (numToRead > 0)
  144704. reservoir.clear (offset, numToRead);
  144705. }
  144706. }
  144707. if (numSamples > 0)
  144708. {
  144709. for (int i = numDestChannels; --i >= 0;)
  144710. if (destSamples[i] != 0)
  144711. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144712. sizeof (int) * numSamples);
  144713. }
  144714. return true;
  144715. }
  144716. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144717. {
  144718. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144719. }
  144720. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144721. {
  144722. InputStream* const in = (InputStream*) datasource;
  144723. if (whence == SEEK_CUR)
  144724. offset += in->getPosition();
  144725. else if (whence == SEEK_END)
  144726. offset += in->getTotalLength();
  144727. in->setPosition (offset);
  144728. return 0;
  144729. }
  144730. static int oggCloseCallback (void*)
  144731. {
  144732. return 0;
  144733. }
  144734. static long oggTellCallback (void* datasource)
  144735. {
  144736. return (long) ((InputStream*) datasource)->getPosition();
  144737. }
  144738. juce_UseDebuggingNewOperator
  144739. };
  144740. class OggWriter : public AudioFormatWriter
  144741. {
  144742. ogg_stream_state os;
  144743. ogg_page og;
  144744. ogg_packet op;
  144745. vorbis_info vi;
  144746. vorbis_comment vc;
  144747. vorbis_dsp_state vd;
  144748. vorbis_block vb;
  144749. public:
  144750. bool ok;
  144751. OggWriter (OutputStream* const out,
  144752. const double sampleRate,
  144753. const int numChannels,
  144754. const int bitsPerSample,
  144755. const int qualityIndex)
  144756. : AudioFormatWriter (out, TRANS (oggFormatName),
  144757. sampleRate,
  144758. numChannels,
  144759. bitsPerSample)
  144760. {
  144761. ok = false;
  144762. vorbis_info_init (&vi);
  144763. if (vorbis_encode_init_vbr (&vi,
  144764. numChannels,
  144765. (int) sampleRate,
  144766. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144767. {
  144768. vorbis_comment_init (&vc);
  144769. if (JUCEApplication::getInstance() != 0)
  144770. vorbis_comment_add_tag (&vc, "ENCODER",
  144771. (char*) (const char*) JUCEApplication::getInstance()->getApplicationName());
  144772. vorbis_analysis_init (&vd, &vi);
  144773. vorbis_block_init (&vd, &vb);
  144774. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144775. ogg_packet header;
  144776. ogg_packet header_comm;
  144777. ogg_packet header_code;
  144778. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144779. ogg_stream_packetin (&os, &header);
  144780. ogg_stream_packetin (&os, &header_comm);
  144781. ogg_stream_packetin (&os, &header_code);
  144782. for (;;)
  144783. {
  144784. if (ogg_stream_flush (&os, &og) == 0)
  144785. break;
  144786. output->write (og.header, og.header_len);
  144787. output->write (og.body, og.body_len);
  144788. }
  144789. ok = true;
  144790. }
  144791. }
  144792. ~OggWriter()
  144793. {
  144794. if (ok)
  144795. {
  144796. // write a zero-length packet to show ogg that we're finished..
  144797. write (0, 0);
  144798. ogg_stream_clear (&os);
  144799. vorbis_block_clear (&vb);
  144800. vorbis_dsp_clear (&vd);
  144801. vorbis_comment_clear (&vc);
  144802. vorbis_info_clear (&vi);
  144803. output->flush();
  144804. }
  144805. else
  144806. {
  144807. vorbis_info_clear (&vi);
  144808. output = 0; // to stop the base class deleting this, as it needs to be returned
  144809. // to the caller of createWriter()
  144810. }
  144811. }
  144812. bool write (const int** samplesToWrite, int numSamples)
  144813. {
  144814. if (! ok)
  144815. return false;
  144816. if (numSamples > 0)
  144817. {
  144818. const double gain = 1.0 / 0x80000000u;
  144819. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144820. for (int i = numChannels; --i >= 0;)
  144821. {
  144822. float* const dst = vorbisBuffer[i];
  144823. const int* const src = samplesToWrite [i];
  144824. if (src != 0 && dst != 0)
  144825. {
  144826. for (int j = 0; j < numSamples; ++j)
  144827. dst[j] = (float) (src[j] * gain);
  144828. }
  144829. }
  144830. }
  144831. vorbis_analysis_wrote (&vd, numSamples);
  144832. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144833. {
  144834. vorbis_analysis (&vb, 0);
  144835. vorbis_bitrate_addblock (&vb);
  144836. while (vorbis_bitrate_flushpacket (&vd, &op))
  144837. {
  144838. ogg_stream_packetin (&os, &op);
  144839. for (;;)
  144840. {
  144841. if (ogg_stream_pageout (&os, &og) == 0)
  144842. break;
  144843. output->write (og.header, og.header_len);
  144844. output->write (og.body, og.body_len);
  144845. if (ogg_page_eos (&og))
  144846. break;
  144847. }
  144848. }
  144849. }
  144850. return true;
  144851. }
  144852. juce_UseDebuggingNewOperator
  144853. };
  144854. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144855. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144856. {
  144857. }
  144858. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144859. {
  144860. }
  144861. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144862. {
  144863. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144864. return Array <int> (rates);
  144865. }
  144866. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144867. {
  144868. Array <int> depths;
  144869. depths.add (32);
  144870. return depths;
  144871. }
  144872. bool OggVorbisAudioFormat::canDoStereo()
  144873. {
  144874. return true;
  144875. }
  144876. bool OggVorbisAudioFormat::canDoMono()
  144877. {
  144878. return true;
  144879. }
  144880. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144881. const bool deleteStreamIfOpeningFails)
  144882. {
  144883. ScopedPointer <OggReader> r (new OggReader (in));
  144884. if (r->sampleRate != 0)
  144885. return r.release();
  144886. if (! deleteStreamIfOpeningFails)
  144887. r->input = 0;
  144888. return 0;
  144889. }
  144890. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144891. double sampleRate,
  144892. unsigned int numChannels,
  144893. int bitsPerSample,
  144894. const StringPairArray& /*metadataValues*/,
  144895. int qualityOptionIndex)
  144896. {
  144897. ScopedPointer <OggWriter> w (new OggWriter (out,
  144898. sampleRate,
  144899. numChannels,
  144900. bitsPerSample,
  144901. qualityOptionIndex));
  144902. return w->ok ? w.release() : 0;
  144903. }
  144904. bool OggVorbisAudioFormat::isCompressed()
  144905. {
  144906. return true;
  144907. }
  144908. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144909. {
  144910. StringArray s;
  144911. s.add ("Low Quality");
  144912. s.add ("Medium Quality");
  144913. s.add ("High Quality");
  144914. return s;
  144915. }
  144916. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144917. {
  144918. FileInputStream* const in = source.createInputStream();
  144919. if (in != 0)
  144920. {
  144921. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144922. if (r != 0)
  144923. {
  144924. const int64 numSamps = r->lengthInSamples;
  144925. r = 0;
  144926. const int64 fileNumSamps = source.getSize() / 4;
  144927. const double ratio = numSamps / (double) fileNumSamps;
  144928. if (ratio > 12.0)
  144929. return 0;
  144930. else if (ratio > 6.0)
  144931. return 1;
  144932. else
  144933. return 2;
  144934. }
  144935. }
  144936. return 1;
  144937. }
  144938. END_JUCE_NAMESPACE
  144939. #endif
  144940. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144941. #endif
  144942. #if JUCE_BUILD_GUI
  144943. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144944. #if JUCE_MSVC
  144945. #pragma warning (push)
  144946. #endif
  144947. namespace jpeglibNamespace
  144948. {
  144949. #if JUCE_INCLUDE_JPEGLIB_CODE
  144950. #if JUCE_MINGW
  144951. typedef unsigned char boolean;
  144952. #endif
  144953. extern "C"
  144954. {
  144955. #define JPEG_INTERNALS
  144956. #undef FAR
  144957. /*** Start of inlined file: jpeglib.h ***/
  144958. #ifndef JPEGLIB_H
  144959. #define JPEGLIB_H
  144960. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144961. /*** Start of inlined file: jconfig.h ***/
  144962. // disable all the warnings under MSVC
  144963. #ifdef _MSC_VER
  144964. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144965. #endif
  144966. #ifdef __BORLANDC__
  144967. #pragma warn -8057
  144968. #pragma warn -8019
  144969. #pragma warn -8004
  144970. #pragma warn -8008
  144971. #endif
  144972. #define HAVE_PROTOTYPES
  144973. #define HAVE_UNSIGNED_CHAR
  144974. #define HAVE_UNSIGNED_SHORT
  144975. #undef CHAR_IS_UNSIGNED
  144976. #define HAVE_STDDEF_H
  144977. #define HAVE_STDLIB_H
  144978. #undef NEED_BSD_STRINGS
  144979. #undef NEED_SYS_TYPES_H
  144980. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144981. #undef NEED_SHORT_EXTERNAL_NAMES
  144982. #undef INCOMPLETE_TYPES_BROKEN
  144983. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144984. typedef unsigned char boolean;
  144985. #endif
  144986. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144987. #ifdef JPEG_INTERNALS
  144988. #undef RIGHT_SHIFT_IS_UNSIGNED
  144989. #endif /* JPEG_INTERNALS */
  144990. #ifdef JPEG_CJPEG_DJPEG
  144991. #define BMP_SUPPORTED /* BMP image file format */
  144992. #define GIF_SUPPORTED /* GIF image file format */
  144993. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144994. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144995. #define TARGA_SUPPORTED /* Targa image file format */
  144996. #define TWO_FILE_COMMANDLINE /* optional */
  144997. #define USE_SETMODE /* Microsoft has setmode() */
  144998. #undef NEED_SIGNAL_CATCHER
  144999. #undef DONT_USE_B_MODE
  145000. #undef PROGRESS_REPORT /* optional */
  145001. #endif /* JPEG_CJPEG_DJPEG */
  145002. /*** End of inlined file: jconfig.h ***/
  145003. /* widely used configuration options */
  145004. #endif
  145005. /*** Start of inlined file: jmorecfg.h ***/
  145006. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  145007. #define MAX_COMPONENTS 10 /* maximum number of image components */
  145008. #if BITS_IN_JSAMPLE == 8
  145009. #ifdef HAVE_UNSIGNED_CHAR
  145010. typedef unsigned char JSAMPLE;
  145011. #define GETJSAMPLE(value) ((int) (value))
  145012. #else /* not HAVE_UNSIGNED_CHAR */
  145013. typedef char JSAMPLE;
  145014. #ifdef CHAR_IS_UNSIGNED
  145015. #define GETJSAMPLE(value) ((int) (value))
  145016. #else
  145017. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  145018. #endif /* CHAR_IS_UNSIGNED */
  145019. #endif /* HAVE_UNSIGNED_CHAR */
  145020. #define MAXJSAMPLE 255
  145021. #define CENTERJSAMPLE 128
  145022. #endif /* BITS_IN_JSAMPLE == 8 */
  145023. #if BITS_IN_JSAMPLE == 12
  145024. typedef short JSAMPLE;
  145025. #define GETJSAMPLE(value) ((int) (value))
  145026. #define MAXJSAMPLE 4095
  145027. #define CENTERJSAMPLE 2048
  145028. #endif /* BITS_IN_JSAMPLE == 12 */
  145029. typedef short JCOEF;
  145030. #ifdef HAVE_UNSIGNED_CHAR
  145031. typedef unsigned char JOCTET;
  145032. #define GETJOCTET(value) (value)
  145033. #else /* not HAVE_UNSIGNED_CHAR */
  145034. typedef char JOCTET;
  145035. #ifdef CHAR_IS_UNSIGNED
  145036. #define GETJOCTET(value) (value)
  145037. #else
  145038. #define GETJOCTET(value) ((value) & 0xFF)
  145039. #endif /* CHAR_IS_UNSIGNED */
  145040. #endif /* HAVE_UNSIGNED_CHAR */
  145041. #ifdef HAVE_UNSIGNED_CHAR
  145042. typedef unsigned char UINT8;
  145043. #else /* not HAVE_UNSIGNED_CHAR */
  145044. #ifdef CHAR_IS_UNSIGNED
  145045. typedef char UINT8;
  145046. #else /* not CHAR_IS_UNSIGNED */
  145047. typedef short UINT8;
  145048. #endif /* CHAR_IS_UNSIGNED */
  145049. #endif /* HAVE_UNSIGNED_CHAR */
  145050. #ifdef HAVE_UNSIGNED_SHORT
  145051. typedef unsigned short UINT16;
  145052. #else /* not HAVE_UNSIGNED_SHORT */
  145053. typedef unsigned int UINT16;
  145054. #endif /* HAVE_UNSIGNED_SHORT */
  145055. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  145056. typedef short INT16;
  145057. #endif
  145058. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  145059. typedef long INT32;
  145060. #endif
  145061. typedef unsigned int JDIMENSION;
  145062. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  145063. #define METHODDEF(type) static type
  145064. #define LOCAL(type) static type
  145065. #define GLOBAL(type) type
  145066. #define EXTERN(type) extern type
  145067. #ifdef HAVE_PROTOTYPES
  145068. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  145069. #else
  145070. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  145071. #endif
  145072. #ifdef NEED_FAR_POINTERS
  145073. #define FAR far
  145074. #else
  145075. #define FAR
  145076. #endif
  145077. #ifndef HAVE_BOOLEAN
  145078. typedef int boolean;
  145079. #endif
  145080. #ifndef FALSE /* in case these macros already exist */
  145081. #define FALSE 0 /* values of boolean */
  145082. #endif
  145083. #ifndef TRUE
  145084. #define TRUE 1
  145085. #endif
  145086. #ifdef JPEG_INTERNALS
  145087. #define JPEG_INTERNAL_OPTIONS
  145088. #endif
  145089. #ifdef JPEG_INTERNAL_OPTIONS
  145090. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  145091. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  145092. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  145093. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145094. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145095. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145096. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145097. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145098. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145099. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145100. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145101. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145102. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145103. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145104. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145105. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145106. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145107. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145108. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145109. #define RGB_GREEN 1 /* Offset of Green */
  145110. #define RGB_BLUE 2 /* Offset of Blue */
  145111. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145112. #ifndef INLINE
  145113. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145114. #define INLINE __inline__
  145115. #endif
  145116. #ifndef INLINE
  145117. #define INLINE /* default is to define it as empty */
  145118. #endif
  145119. #endif
  145120. #ifndef MULTIPLIER
  145121. #define MULTIPLIER int /* type for fastest integer multiply */
  145122. #endif
  145123. #ifndef FAST_FLOAT
  145124. #ifdef HAVE_PROTOTYPES
  145125. #define FAST_FLOAT float
  145126. #else
  145127. #define FAST_FLOAT double
  145128. #endif
  145129. #endif
  145130. #endif /* JPEG_INTERNAL_OPTIONS */
  145131. /*** End of inlined file: jmorecfg.h ***/
  145132. /* seldom changed options */
  145133. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145134. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145135. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145136. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145137. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145138. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145139. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145140. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145141. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145142. #ifndef D_MAX_BLOCKS_IN_MCU
  145143. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145144. #endif
  145145. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145146. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145147. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145148. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145149. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145150. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145151. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145152. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145153. typedef struct {
  145154. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145155. boolean sent_table; /* TRUE when table has been output */
  145156. } JQUANT_TBL;
  145157. typedef struct {
  145158. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145159. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145160. boolean sent_table; /* TRUE when table has been output */
  145161. } JHUFF_TBL;
  145162. typedef struct {
  145163. int component_id; /* identifier for this component (0..255) */
  145164. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145165. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145166. int v_samp_factor; /* vertical sampling factor (1..4) */
  145167. int quant_tbl_no; /* quantization table selector (0..3) */
  145168. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145169. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145170. JDIMENSION width_in_blocks;
  145171. JDIMENSION height_in_blocks;
  145172. int DCT_scaled_size;
  145173. JDIMENSION downsampled_width; /* actual width in samples */
  145174. JDIMENSION downsampled_height; /* actual height in samples */
  145175. boolean component_needed; /* do we need the value of this component? */
  145176. int MCU_width; /* number of blocks per MCU, horizontally */
  145177. int MCU_height; /* number of blocks per MCU, vertically */
  145178. int MCU_blocks; /* MCU_width * MCU_height */
  145179. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145180. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145181. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145182. JQUANT_TBL * quant_table;
  145183. void * dct_table;
  145184. } jpeg_component_info;
  145185. typedef struct {
  145186. int comps_in_scan; /* number of components encoded in this scan */
  145187. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145188. int Ss, Se; /* progressive JPEG spectral selection parms */
  145189. int Ah, Al; /* progressive JPEG successive approx. parms */
  145190. } jpeg_scan_info;
  145191. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145192. struct jpeg_marker_struct {
  145193. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145194. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145195. unsigned int original_length; /* # bytes of data in the file */
  145196. unsigned int data_length; /* # bytes of data saved at data[] */
  145197. JOCTET FAR * data; /* the data contained in the marker */
  145198. };
  145199. typedef enum {
  145200. JCS_UNKNOWN, /* error/unspecified */
  145201. JCS_GRAYSCALE, /* monochrome */
  145202. JCS_RGB, /* red/green/blue */
  145203. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145204. JCS_CMYK, /* C/M/Y/K */
  145205. JCS_YCCK /* Y/Cb/Cr/K */
  145206. } J_COLOR_SPACE;
  145207. typedef enum {
  145208. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145209. JDCT_IFAST, /* faster, less accurate integer method */
  145210. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145211. } J_DCT_METHOD;
  145212. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145213. #define JDCT_DEFAULT JDCT_ISLOW
  145214. #endif
  145215. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145216. #define JDCT_FASTEST JDCT_IFAST
  145217. #endif
  145218. typedef enum {
  145219. JDITHER_NONE, /* no dithering */
  145220. JDITHER_ORDERED, /* simple ordered dither */
  145221. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145222. } J_DITHER_MODE;
  145223. #define jpeg_common_fields \
  145224. struct jpeg_error_mgr * err; /* Error handler module */\
  145225. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145226. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145227. void * client_data; /* Available for use by application */\
  145228. boolean is_decompressor; /* So common code can tell which is which */\
  145229. int global_state /* For checking call sequence validity */
  145230. struct jpeg_common_struct {
  145231. jpeg_common_fields; /* Fields common to both master struct types */
  145232. };
  145233. typedef struct jpeg_common_struct * j_common_ptr;
  145234. typedef struct jpeg_compress_struct * j_compress_ptr;
  145235. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145236. struct jpeg_compress_struct {
  145237. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145238. struct jpeg_destination_mgr * dest;
  145239. JDIMENSION image_width; /* input image width */
  145240. JDIMENSION image_height; /* input image height */
  145241. int input_components; /* # of color components in input image */
  145242. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145243. double input_gamma; /* image gamma of input image */
  145244. int data_precision; /* bits of precision in image data */
  145245. int num_components; /* # of color components in JPEG image */
  145246. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145247. jpeg_component_info * comp_info;
  145248. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145249. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145250. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145251. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145252. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145253. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145254. int num_scans; /* # of entries in scan_info array */
  145255. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145256. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145257. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145258. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145259. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145260. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145261. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145262. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145263. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145264. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145265. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145266. UINT8 JFIF_minor_version;
  145267. UINT8 density_unit; /* JFIF code for pixel size units */
  145268. UINT16 X_density; /* Horizontal pixel density */
  145269. UINT16 Y_density; /* Vertical pixel density */
  145270. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145271. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145272. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145273. int max_h_samp_factor; /* largest h_samp_factor */
  145274. int max_v_samp_factor; /* largest v_samp_factor */
  145275. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145276. int comps_in_scan; /* # of JPEG components in this scan */
  145277. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145278. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145279. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145280. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145281. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145282. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145283. struct jpeg_comp_master * master;
  145284. struct jpeg_c_main_controller * main;
  145285. struct jpeg_c_prep_controller * prep;
  145286. struct jpeg_c_coef_controller * coef;
  145287. struct jpeg_marker_writer * marker;
  145288. struct jpeg_color_converter * cconvert;
  145289. struct jpeg_downsampler * downsample;
  145290. struct jpeg_forward_dct * fdct;
  145291. struct jpeg_entropy_encoder * entropy;
  145292. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145293. int script_space_size;
  145294. };
  145295. struct jpeg_decompress_struct {
  145296. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145297. struct jpeg_source_mgr * src;
  145298. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145299. JDIMENSION image_height; /* nominal image height */
  145300. int num_components; /* # of color components in JPEG image */
  145301. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145302. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145303. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145304. double output_gamma; /* image gamma wanted in output */
  145305. boolean buffered_image; /* TRUE=multiple output passes */
  145306. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145307. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145308. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145309. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145310. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145311. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145312. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145313. int desired_number_of_colors; /* max # colors to use in created colormap */
  145314. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145315. boolean enable_external_quant;/* enable future use of external colormap */
  145316. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145317. JDIMENSION output_width; /* scaled image width */
  145318. JDIMENSION output_height; /* scaled image height */
  145319. int out_color_components; /* # of color components in out_color_space */
  145320. int output_components; /* # of color components returned */
  145321. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145322. int actual_number_of_colors; /* number of entries in use */
  145323. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145324. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145325. int input_scan_number; /* Number of SOS markers seen so far */
  145326. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145327. int output_scan_number; /* Nominal scan number being displayed */
  145328. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145329. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145330. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145331. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145332. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145333. int data_precision; /* bits of precision in image data */
  145334. jpeg_component_info * comp_info;
  145335. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145336. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145337. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145338. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145339. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145340. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145341. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145342. UINT8 JFIF_major_version; /* JFIF version number */
  145343. UINT8 JFIF_minor_version;
  145344. UINT8 density_unit; /* JFIF code for pixel size units */
  145345. UINT16 X_density; /* Horizontal pixel density */
  145346. UINT16 Y_density; /* Vertical pixel density */
  145347. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145348. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145349. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145350. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145351. int max_h_samp_factor; /* largest h_samp_factor */
  145352. int max_v_samp_factor; /* largest v_samp_factor */
  145353. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145354. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145355. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145356. int comps_in_scan; /* # of JPEG components in this scan */
  145357. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145358. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145359. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145360. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145361. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145362. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145363. int unread_marker;
  145364. struct jpeg_decomp_master * master;
  145365. struct jpeg_d_main_controller * main;
  145366. struct jpeg_d_coef_controller * coef;
  145367. struct jpeg_d_post_controller * post;
  145368. struct jpeg_input_controller * inputctl;
  145369. struct jpeg_marker_reader * marker;
  145370. struct jpeg_entropy_decoder * entropy;
  145371. struct jpeg_inverse_dct * idct;
  145372. struct jpeg_upsampler * upsample;
  145373. struct jpeg_color_deconverter * cconvert;
  145374. struct jpeg_color_quantizer * cquantize;
  145375. };
  145376. struct jpeg_error_mgr {
  145377. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145378. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145379. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145380. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145381. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145382. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145383. int msg_code;
  145384. #define JMSG_STR_PARM_MAX 80
  145385. union {
  145386. int i[8];
  145387. char s[JMSG_STR_PARM_MAX];
  145388. } msg_parm;
  145389. int trace_level; /* max msg_level that will be displayed */
  145390. long num_warnings; /* number of corrupt-data warnings */
  145391. const char * const * jpeg_message_table; /* Library errors */
  145392. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145393. const char * const * addon_message_table; /* Non-library errors */
  145394. int first_addon_message; /* code for first string in addon table */
  145395. int last_addon_message; /* code for last string in addon table */
  145396. };
  145397. struct jpeg_progress_mgr {
  145398. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145399. long pass_counter; /* work units completed in this pass */
  145400. long pass_limit; /* total number of work units in this pass */
  145401. int completed_passes; /* passes completed so far */
  145402. int total_passes; /* total number of passes expected */
  145403. };
  145404. struct jpeg_destination_mgr {
  145405. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145406. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145407. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145408. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145409. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145410. };
  145411. struct jpeg_source_mgr {
  145412. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145413. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145414. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145415. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145416. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145417. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145418. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145419. };
  145420. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145421. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145422. #define JPOOL_NUMPOOLS 2
  145423. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145424. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145425. struct jpeg_memory_mgr {
  145426. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145427. size_t sizeofobject));
  145428. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145429. size_t sizeofobject));
  145430. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145431. JDIMENSION samplesperrow,
  145432. JDIMENSION numrows));
  145433. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145434. JDIMENSION blocksperrow,
  145435. JDIMENSION numrows));
  145436. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145437. int pool_id,
  145438. boolean pre_zero,
  145439. JDIMENSION samplesperrow,
  145440. JDIMENSION numrows,
  145441. JDIMENSION maxaccess));
  145442. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145443. int pool_id,
  145444. boolean pre_zero,
  145445. JDIMENSION blocksperrow,
  145446. JDIMENSION numrows,
  145447. JDIMENSION maxaccess));
  145448. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145449. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145450. jvirt_sarray_ptr ptr,
  145451. JDIMENSION start_row,
  145452. JDIMENSION num_rows,
  145453. boolean writable));
  145454. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145455. jvirt_barray_ptr ptr,
  145456. JDIMENSION start_row,
  145457. JDIMENSION num_rows,
  145458. boolean writable));
  145459. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145460. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145461. long max_memory_to_use;
  145462. long max_alloc_chunk;
  145463. };
  145464. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145465. #ifdef HAVE_PROTOTYPES
  145466. #define JPP(arglist) arglist
  145467. #else
  145468. #define JPP(arglist) ()
  145469. #endif
  145470. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145471. #define jpeg_std_error jStdError
  145472. #define jpeg_CreateCompress jCreaCompress
  145473. #define jpeg_CreateDecompress jCreaDecompress
  145474. #define jpeg_destroy_compress jDestCompress
  145475. #define jpeg_destroy_decompress jDestDecompress
  145476. #define jpeg_stdio_dest jStdDest
  145477. #define jpeg_stdio_src jStdSrc
  145478. #define jpeg_set_defaults jSetDefaults
  145479. #define jpeg_set_colorspace jSetColorspace
  145480. #define jpeg_default_colorspace jDefColorspace
  145481. #define jpeg_set_quality jSetQuality
  145482. #define jpeg_set_linear_quality jSetLQuality
  145483. #define jpeg_add_quant_table jAddQuantTable
  145484. #define jpeg_quality_scaling jQualityScaling
  145485. #define jpeg_simple_progression jSimProgress
  145486. #define jpeg_suppress_tables jSuppressTables
  145487. #define jpeg_alloc_quant_table jAlcQTable
  145488. #define jpeg_alloc_huff_table jAlcHTable
  145489. #define jpeg_start_compress jStrtCompress
  145490. #define jpeg_write_scanlines jWrtScanlines
  145491. #define jpeg_finish_compress jFinCompress
  145492. #define jpeg_write_raw_data jWrtRawData
  145493. #define jpeg_write_marker jWrtMarker
  145494. #define jpeg_write_m_header jWrtMHeader
  145495. #define jpeg_write_m_byte jWrtMByte
  145496. #define jpeg_write_tables jWrtTables
  145497. #define jpeg_read_header jReadHeader
  145498. #define jpeg_start_decompress jStrtDecompress
  145499. #define jpeg_read_scanlines jReadScanlines
  145500. #define jpeg_finish_decompress jFinDecompress
  145501. #define jpeg_read_raw_data jReadRawData
  145502. #define jpeg_has_multiple_scans jHasMultScn
  145503. #define jpeg_start_output jStrtOutput
  145504. #define jpeg_finish_output jFinOutput
  145505. #define jpeg_input_complete jInComplete
  145506. #define jpeg_new_colormap jNewCMap
  145507. #define jpeg_consume_input jConsumeInput
  145508. #define jpeg_calc_output_dimensions jCalcDimensions
  145509. #define jpeg_save_markers jSaveMarkers
  145510. #define jpeg_set_marker_processor jSetMarker
  145511. #define jpeg_read_coefficients jReadCoefs
  145512. #define jpeg_write_coefficients jWrtCoefs
  145513. #define jpeg_copy_critical_parameters jCopyCrit
  145514. #define jpeg_abort_compress jAbrtCompress
  145515. #define jpeg_abort_decompress jAbrtDecompress
  145516. #define jpeg_abort jAbort
  145517. #define jpeg_destroy jDestroy
  145518. #define jpeg_resync_to_restart jResyncRestart
  145519. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145520. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145521. JPP((struct jpeg_error_mgr * err));
  145522. #define jpeg_create_compress(cinfo) \
  145523. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145524. (size_t) sizeof(struct jpeg_compress_struct))
  145525. #define jpeg_create_decompress(cinfo) \
  145526. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145527. (size_t) sizeof(struct jpeg_decompress_struct))
  145528. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145529. int version, size_t structsize));
  145530. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145531. int version, size_t structsize));
  145532. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145533. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145534. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145535. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145536. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145537. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145538. J_COLOR_SPACE colorspace));
  145539. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145540. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145541. boolean force_baseline));
  145542. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145543. int scale_factor,
  145544. boolean force_baseline));
  145545. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145546. const unsigned int *basic_table,
  145547. int scale_factor,
  145548. boolean force_baseline));
  145549. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145550. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145551. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145552. boolean suppress));
  145553. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145554. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145555. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145556. boolean write_all_tables));
  145557. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145558. JSAMPARRAY scanlines,
  145559. JDIMENSION num_lines));
  145560. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145561. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145562. JSAMPIMAGE data,
  145563. JDIMENSION num_lines));
  145564. EXTERN(void) jpeg_write_marker
  145565. JPP((j_compress_ptr cinfo, int marker,
  145566. const JOCTET * dataptr, unsigned int datalen));
  145567. EXTERN(void) jpeg_write_m_header
  145568. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145569. EXTERN(void) jpeg_write_m_byte
  145570. JPP((j_compress_ptr cinfo, int val));
  145571. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145572. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145573. boolean require_image));
  145574. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145575. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145576. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145577. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145578. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145579. JSAMPARRAY scanlines,
  145580. JDIMENSION max_lines));
  145581. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145582. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145583. JSAMPIMAGE data,
  145584. JDIMENSION max_lines));
  145585. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145586. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145587. int scan_number));
  145588. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145589. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145590. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145591. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145592. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145593. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145594. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145595. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145596. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145597. EXTERN(void) jpeg_save_markers
  145598. JPP((j_decompress_ptr cinfo, int marker_code,
  145599. unsigned int length_limit));
  145600. EXTERN(void) jpeg_set_marker_processor
  145601. JPP((j_decompress_ptr cinfo, int marker_code,
  145602. jpeg_marker_parser_method routine));
  145603. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145604. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145605. jvirt_barray_ptr * coef_arrays));
  145606. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145607. j_compress_ptr dstinfo));
  145608. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145609. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145610. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145611. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145612. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145613. int desired));
  145614. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145615. #define JPEG_EOI 0xD9 /* EOI marker code */
  145616. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145617. #define JPEG_COM 0xFE /* COM marker code */
  145618. #ifdef INCOMPLETE_TYPES_BROKEN
  145619. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145620. struct jvirt_sarray_control { long dummy; };
  145621. struct jvirt_barray_control { long dummy; };
  145622. struct jpeg_comp_master { long dummy; };
  145623. struct jpeg_c_main_controller { long dummy; };
  145624. struct jpeg_c_prep_controller { long dummy; };
  145625. struct jpeg_c_coef_controller { long dummy; };
  145626. struct jpeg_marker_writer { long dummy; };
  145627. struct jpeg_color_converter { long dummy; };
  145628. struct jpeg_downsampler { long dummy; };
  145629. struct jpeg_forward_dct { long dummy; };
  145630. struct jpeg_entropy_encoder { long dummy; };
  145631. struct jpeg_decomp_master { long dummy; };
  145632. struct jpeg_d_main_controller { long dummy; };
  145633. struct jpeg_d_coef_controller { long dummy; };
  145634. struct jpeg_d_post_controller { long dummy; };
  145635. struct jpeg_input_controller { long dummy; };
  145636. struct jpeg_marker_reader { long dummy; };
  145637. struct jpeg_entropy_decoder { long dummy; };
  145638. struct jpeg_inverse_dct { long dummy; };
  145639. struct jpeg_upsampler { long dummy; };
  145640. struct jpeg_color_deconverter { long dummy; };
  145641. struct jpeg_color_quantizer { long dummy; };
  145642. #endif /* JPEG_INTERNALS */
  145643. #endif /* INCOMPLETE_TYPES_BROKEN */
  145644. #ifdef JPEG_INTERNALS
  145645. /*** Start of inlined file: jpegint.h ***/
  145646. typedef enum { /* Operating modes for buffer controllers */
  145647. JBUF_PASS_THRU, /* Plain stripwise operation */
  145648. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145649. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145650. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145651. } J_BUF_MODE;
  145652. #define CSTATE_START 100 /* after create_compress */
  145653. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145654. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145655. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145656. #define DSTATE_START 200 /* after create_decompress */
  145657. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145658. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145659. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145660. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145661. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145662. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145663. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145664. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145665. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145666. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145667. struct jpeg_comp_master {
  145668. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145669. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145670. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145671. boolean call_pass_startup; /* True if pass_startup must be called */
  145672. boolean is_last_pass; /* True during last pass */
  145673. };
  145674. struct jpeg_c_main_controller {
  145675. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145676. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145677. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145678. JDIMENSION in_rows_avail));
  145679. };
  145680. struct jpeg_c_prep_controller {
  145681. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145682. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145683. JSAMPARRAY input_buf,
  145684. JDIMENSION *in_row_ctr,
  145685. JDIMENSION in_rows_avail,
  145686. JSAMPIMAGE output_buf,
  145687. JDIMENSION *out_row_group_ctr,
  145688. JDIMENSION out_row_groups_avail));
  145689. };
  145690. struct jpeg_c_coef_controller {
  145691. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145692. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145693. JSAMPIMAGE input_buf));
  145694. };
  145695. struct jpeg_color_converter {
  145696. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145697. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145698. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145699. JDIMENSION output_row, int num_rows));
  145700. };
  145701. struct jpeg_downsampler {
  145702. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145703. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145704. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145705. JSAMPIMAGE output_buf,
  145706. JDIMENSION out_row_group_index));
  145707. boolean need_context_rows; /* TRUE if need rows above & below */
  145708. };
  145709. struct jpeg_forward_dct {
  145710. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145711. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145712. jpeg_component_info * compptr,
  145713. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145714. JDIMENSION start_row, JDIMENSION start_col,
  145715. JDIMENSION num_blocks));
  145716. };
  145717. struct jpeg_entropy_encoder {
  145718. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145719. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145720. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145721. };
  145722. struct jpeg_marker_writer {
  145723. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145724. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145725. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145726. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145727. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145728. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145729. unsigned int datalen));
  145730. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145731. };
  145732. struct jpeg_decomp_master {
  145733. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145734. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145735. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145736. };
  145737. struct jpeg_input_controller {
  145738. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145739. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145740. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145741. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145742. boolean has_multiple_scans; /* True if file has multiple scans */
  145743. boolean eoi_reached; /* True when EOI has been consumed */
  145744. };
  145745. struct jpeg_d_main_controller {
  145746. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145747. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145748. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145749. JDIMENSION out_rows_avail));
  145750. };
  145751. struct jpeg_d_coef_controller {
  145752. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145753. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145754. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145755. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145756. JSAMPIMAGE output_buf));
  145757. jvirt_barray_ptr *coef_arrays;
  145758. };
  145759. struct jpeg_d_post_controller {
  145760. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145761. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145762. JSAMPIMAGE input_buf,
  145763. JDIMENSION *in_row_group_ctr,
  145764. JDIMENSION in_row_groups_avail,
  145765. JSAMPARRAY output_buf,
  145766. JDIMENSION *out_row_ctr,
  145767. JDIMENSION out_rows_avail));
  145768. };
  145769. struct jpeg_marker_reader {
  145770. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145771. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145772. jpeg_marker_parser_method read_restart_marker;
  145773. boolean saw_SOI; /* found SOI? */
  145774. boolean saw_SOF; /* found SOF? */
  145775. int next_restart_num; /* next restart number expected (0-7) */
  145776. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145777. };
  145778. struct jpeg_entropy_decoder {
  145779. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145780. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145781. JBLOCKROW *MCU_data));
  145782. boolean insufficient_data; /* set TRUE after emitting warning */
  145783. };
  145784. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145785. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145786. JCOEFPTR coef_block,
  145787. JSAMPARRAY output_buf, JDIMENSION output_col));
  145788. struct jpeg_inverse_dct {
  145789. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145790. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145791. };
  145792. struct jpeg_upsampler {
  145793. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145794. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145795. JSAMPIMAGE input_buf,
  145796. JDIMENSION *in_row_group_ctr,
  145797. JDIMENSION in_row_groups_avail,
  145798. JSAMPARRAY output_buf,
  145799. JDIMENSION *out_row_ctr,
  145800. JDIMENSION out_rows_avail));
  145801. boolean need_context_rows; /* TRUE if need rows above & below */
  145802. };
  145803. struct jpeg_color_deconverter {
  145804. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145805. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145806. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145807. JSAMPARRAY output_buf, int num_rows));
  145808. };
  145809. struct jpeg_color_quantizer {
  145810. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145811. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145812. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145813. int num_rows));
  145814. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145815. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145816. };
  145817. #undef MAX
  145818. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145819. #undef MIN
  145820. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145821. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145822. #define SHIFT_TEMPS INT32 shift_temp;
  145823. #define RIGHT_SHIFT(x,shft) \
  145824. ((shift_temp = (x)) < 0 ? \
  145825. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145826. (shift_temp >> (shft)))
  145827. #else
  145828. #define SHIFT_TEMPS
  145829. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145830. #endif
  145831. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145832. #define jinit_compress_master jICompress
  145833. #define jinit_c_master_control jICMaster
  145834. #define jinit_c_main_controller jICMainC
  145835. #define jinit_c_prep_controller jICPrepC
  145836. #define jinit_c_coef_controller jICCoefC
  145837. #define jinit_color_converter jICColor
  145838. #define jinit_downsampler jIDownsampler
  145839. #define jinit_forward_dct jIFDCT
  145840. #define jinit_huff_encoder jIHEncoder
  145841. #define jinit_phuff_encoder jIPHEncoder
  145842. #define jinit_marker_writer jIMWriter
  145843. #define jinit_master_decompress jIDMaster
  145844. #define jinit_d_main_controller jIDMainC
  145845. #define jinit_d_coef_controller jIDCoefC
  145846. #define jinit_d_post_controller jIDPostC
  145847. #define jinit_input_controller jIInCtlr
  145848. #define jinit_marker_reader jIMReader
  145849. #define jinit_huff_decoder jIHDecoder
  145850. #define jinit_phuff_decoder jIPHDecoder
  145851. #define jinit_inverse_dct jIIDCT
  145852. #define jinit_upsampler jIUpsampler
  145853. #define jinit_color_deconverter jIDColor
  145854. #define jinit_1pass_quantizer jI1Quant
  145855. #define jinit_2pass_quantizer jI2Quant
  145856. #define jinit_merged_upsampler jIMUpsampler
  145857. #define jinit_memory_mgr jIMemMgr
  145858. #define jdiv_round_up jDivRound
  145859. #define jround_up jRound
  145860. #define jcopy_sample_rows jCopySamples
  145861. #define jcopy_block_row jCopyBlocks
  145862. #define jzero_far jZeroFar
  145863. #define jpeg_zigzag_order jZIGTable
  145864. #define jpeg_natural_order jZAGTable
  145865. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145866. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145867. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145868. boolean transcode_only));
  145869. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145870. boolean need_full_buffer));
  145871. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145872. boolean need_full_buffer));
  145873. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145874. boolean need_full_buffer));
  145875. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145876. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145877. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145878. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145879. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145880. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145881. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145882. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145883. boolean need_full_buffer));
  145884. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145885. boolean need_full_buffer));
  145886. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145887. boolean need_full_buffer));
  145888. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145889. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145890. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145891. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145892. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145893. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145894. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145895. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145896. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145897. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145898. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145899. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145900. EXTERN(long) jround_up JPP((long a, long b));
  145901. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145902. JSAMPARRAY output_array, int dest_row,
  145903. int num_rows, JDIMENSION num_cols));
  145904. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145905. JDIMENSION num_blocks));
  145906. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145907. #if 0 /* This table is not actually needed in v6a */
  145908. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145909. #endif
  145910. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145911. #ifdef INCOMPLETE_TYPES_BROKEN
  145912. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145913. struct jvirt_sarray_control { long dummy; };
  145914. struct jvirt_barray_control { long dummy; };
  145915. #endif
  145916. #endif /* INCOMPLETE_TYPES_BROKEN */
  145917. /*** End of inlined file: jpegint.h ***/
  145918. /* fetch private declarations */
  145919. /*** Start of inlined file: jerror.h ***/
  145920. #ifndef JMESSAGE
  145921. #ifndef JERROR_H
  145922. #define JMAKE_ENUM_LIST
  145923. #else
  145924. #define JMESSAGE(code,string)
  145925. #endif /* JERROR_H */
  145926. #endif /* JMESSAGE */
  145927. #ifdef JMAKE_ENUM_LIST
  145928. typedef enum {
  145929. #define JMESSAGE(code,string) code ,
  145930. #endif /* JMAKE_ENUM_LIST */
  145931. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145932. JMESSAGE(JERR_ARITH_NOTIMPL,
  145933. "Sorry, there are legal restrictions on arithmetic coding")
  145934. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145935. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145936. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145937. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145938. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145939. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145940. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145941. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145942. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145943. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145944. JMESSAGE(JERR_BAD_LIB_VERSION,
  145945. "Wrong JPEG library version: library is %d, caller expects %d")
  145946. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145947. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145948. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145949. JMESSAGE(JERR_BAD_PROGRESSION,
  145950. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145951. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145952. "Invalid progressive parameters at scan script entry %d")
  145953. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145954. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145955. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145956. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145957. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145958. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145959. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145960. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145961. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145962. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145963. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145964. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145965. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145966. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145967. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145968. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145969. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145970. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145971. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145972. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145973. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145974. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145975. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145976. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145977. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145978. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145979. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145980. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145981. "Cannot transcode due to multiple use of quantization table %d")
  145982. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145983. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145984. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145985. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145986. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145987. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145988. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145989. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145990. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145991. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145992. JMESSAGE(JERR_QUANT_COMPONENTS,
  145993. "Cannot quantize more than %d color components")
  145994. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145995. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145996. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145997. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145998. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145999. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  146000. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  146001. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  146002. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  146003. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  146004. JMESSAGE(JERR_TFILE_WRITE,
  146005. "Write failed on temporary file --- out of disk space?")
  146006. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  146007. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  146008. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  146009. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  146010. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  146011. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  146012. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  146013. JMESSAGE(JMSG_VERSION, JVERSION)
  146014. JMESSAGE(JTRC_16BIT_TABLES,
  146015. "Caution: quantization tables are too coarse for baseline JPEG")
  146016. JMESSAGE(JTRC_ADOBE,
  146017. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  146018. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  146019. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  146020. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  146021. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  146022. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  146023. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  146024. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  146025. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  146026. JMESSAGE(JTRC_EOI, "End Of Image")
  146027. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  146028. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  146029. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  146030. "Warning: thumbnail image size does not match data length %u")
  146031. JMESSAGE(JTRC_JFIF_EXTENSION,
  146032. "JFIF extension marker: type 0x%02x, length %u")
  146033. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  146034. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  146035. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  146036. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  146037. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  146038. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  146039. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  146040. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  146041. JMESSAGE(JTRC_RST, "RST%d")
  146042. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  146043. "Smoothing not supported with nonstandard sampling ratios")
  146044. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  146045. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  146046. JMESSAGE(JTRC_SOI, "Start of Image")
  146047. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  146048. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  146049. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  146050. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  146051. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  146052. JMESSAGE(JTRC_THUMB_JPEG,
  146053. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  146054. JMESSAGE(JTRC_THUMB_PALETTE,
  146055. "JFIF extension marker: palette thumbnail image, length %u")
  146056. JMESSAGE(JTRC_THUMB_RGB,
  146057. "JFIF extension marker: RGB thumbnail image, length %u")
  146058. JMESSAGE(JTRC_UNKNOWN_IDS,
  146059. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  146060. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  146061. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  146062. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  146063. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  146064. "Inconsistent progression sequence for component %d coefficient %d")
  146065. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  146066. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  146067. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  146068. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  146069. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  146070. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  146071. JMESSAGE(JWRN_MUST_RESYNC,
  146072. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  146073. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  146074. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  146075. #ifdef JMAKE_ENUM_LIST
  146076. JMSG_LASTMSGCODE
  146077. } J_MESSAGE_CODE;
  146078. #undef JMAKE_ENUM_LIST
  146079. #endif /* JMAKE_ENUM_LIST */
  146080. #undef JMESSAGE
  146081. #ifndef JERROR_H
  146082. #define JERROR_H
  146083. #define ERREXIT(cinfo,code) \
  146084. ((cinfo)->err->msg_code = (code), \
  146085. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146086. #define ERREXIT1(cinfo,code,p1) \
  146087. ((cinfo)->err->msg_code = (code), \
  146088. (cinfo)->err->msg_parm.i[0] = (p1), \
  146089. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146090. #define ERREXIT2(cinfo,code,p1,p2) \
  146091. ((cinfo)->err->msg_code = (code), \
  146092. (cinfo)->err->msg_parm.i[0] = (p1), \
  146093. (cinfo)->err->msg_parm.i[1] = (p2), \
  146094. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146095. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  146096. ((cinfo)->err->msg_code = (code), \
  146097. (cinfo)->err->msg_parm.i[0] = (p1), \
  146098. (cinfo)->err->msg_parm.i[1] = (p2), \
  146099. (cinfo)->err->msg_parm.i[2] = (p3), \
  146100. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146101. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146102. ((cinfo)->err->msg_code = (code), \
  146103. (cinfo)->err->msg_parm.i[0] = (p1), \
  146104. (cinfo)->err->msg_parm.i[1] = (p2), \
  146105. (cinfo)->err->msg_parm.i[2] = (p3), \
  146106. (cinfo)->err->msg_parm.i[3] = (p4), \
  146107. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146108. #define ERREXITS(cinfo,code,str) \
  146109. ((cinfo)->err->msg_code = (code), \
  146110. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146111. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146112. #define MAKESTMT(stuff) do { stuff } while (0)
  146113. #define WARNMS(cinfo,code) \
  146114. ((cinfo)->err->msg_code = (code), \
  146115. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146116. #define WARNMS1(cinfo,code,p1) \
  146117. ((cinfo)->err->msg_code = (code), \
  146118. (cinfo)->err->msg_parm.i[0] = (p1), \
  146119. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146120. #define WARNMS2(cinfo,code,p1,p2) \
  146121. ((cinfo)->err->msg_code = (code), \
  146122. (cinfo)->err->msg_parm.i[0] = (p1), \
  146123. (cinfo)->err->msg_parm.i[1] = (p2), \
  146124. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146125. #define TRACEMS(cinfo,lvl,code) \
  146126. ((cinfo)->err->msg_code = (code), \
  146127. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146128. #define TRACEMS1(cinfo,lvl,code,p1) \
  146129. ((cinfo)->err->msg_code = (code), \
  146130. (cinfo)->err->msg_parm.i[0] = (p1), \
  146131. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146132. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146133. ((cinfo)->err->msg_code = (code), \
  146134. (cinfo)->err->msg_parm.i[0] = (p1), \
  146135. (cinfo)->err->msg_parm.i[1] = (p2), \
  146136. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146137. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146138. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146139. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146140. (cinfo)->err->msg_code = (code); \
  146141. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146142. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146143. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146144. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146145. (cinfo)->err->msg_code = (code); \
  146146. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146147. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146148. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146149. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146150. _mp[4] = (p5); \
  146151. (cinfo)->err->msg_code = (code); \
  146152. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146153. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146154. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146155. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146156. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146157. (cinfo)->err->msg_code = (code); \
  146158. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146159. #define TRACEMSS(cinfo,lvl,code,str) \
  146160. ((cinfo)->err->msg_code = (code), \
  146161. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146162. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146163. #endif /* JERROR_H */
  146164. /*** End of inlined file: jerror.h ***/
  146165. /* fetch error codes too */
  146166. #endif
  146167. #endif /* JPEGLIB_H */
  146168. /*** End of inlined file: jpeglib.h ***/
  146169. /*** Start of inlined file: jcapimin.c ***/
  146170. #define JPEG_INTERNALS
  146171. /*** Start of inlined file: jinclude.h ***/
  146172. #ifndef __jinclude_h__
  146173. #define __jinclude_h__
  146174. /*** Start of inlined file: jconfig.h ***/
  146175. // disable all the warnings under MSVC
  146176. #ifdef _MSC_VER
  146177. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146178. #endif
  146179. #ifdef __BORLANDC__
  146180. #pragma warn -8057
  146181. #pragma warn -8019
  146182. #pragma warn -8004
  146183. #pragma warn -8008
  146184. #endif
  146185. #define HAVE_PROTOTYPES
  146186. #define HAVE_UNSIGNED_CHAR
  146187. #define HAVE_UNSIGNED_SHORT
  146188. #undef CHAR_IS_UNSIGNED
  146189. #define HAVE_STDDEF_H
  146190. #define HAVE_STDLIB_H
  146191. #undef NEED_BSD_STRINGS
  146192. #undef NEED_SYS_TYPES_H
  146193. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146194. #undef NEED_SHORT_EXTERNAL_NAMES
  146195. #undef INCOMPLETE_TYPES_BROKEN
  146196. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146197. typedef unsigned char boolean;
  146198. #endif
  146199. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146200. #ifdef JPEG_INTERNALS
  146201. #undef RIGHT_SHIFT_IS_UNSIGNED
  146202. #endif /* JPEG_INTERNALS */
  146203. #ifdef JPEG_CJPEG_DJPEG
  146204. #define BMP_SUPPORTED /* BMP image file format */
  146205. #define GIF_SUPPORTED /* GIF image file format */
  146206. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146207. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146208. #define TARGA_SUPPORTED /* Targa image file format */
  146209. #define TWO_FILE_COMMANDLINE /* optional */
  146210. #define USE_SETMODE /* Microsoft has setmode() */
  146211. #undef NEED_SIGNAL_CATCHER
  146212. #undef DONT_USE_B_MODE
  146213. #undef PROGRESS_REPORT /* optional */
  146214. #endif /* JPEG_CJPEG_DJPEG */
  146215. /*** End of inlined file: jconfig.h ***/
  146216. /* auto configuration options */
  146217. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146218. #ifdef HAVE_STDDEF_H
  146219. #include <stddef.h>
  146220. #endif
  146221. #ifdef HAVE_STDLIB_H
  146222. #include <stdlib.h>
  146223. #endif
  146224. #ifdef NEED_SYS_TYPES_H
  146225. #include <sys/types.h>
  146226. #endif
  146227. #include <stdio.h>
  146228. #ifdef NEED_BSD_STRINGS
  146229. #include <strings.h>
  146230. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146231. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146232. #else /* not BSD, assume ANSI/SysV string lib */
  146233. #include <string.h>
  146234. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146235. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146236. #endif
  146237. #define SIZEOF(object) ((size_t) sizeof(object))
  146238. #define JFREAD(file,buf,sizeofbuf) \
  146239. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146240. #define JFWRITE(file,buf,sizeofbuf) \
  146241. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146242. typedef enum { /* JPEG marker codes */
  146243. M_SOF0 = 0xc0,
  146244. M_SOF1 = 0xc1,
  146245. M_SOF2 = 0xc2,
  146246. M_SOF3 = 0xc3,
  146247. M_SOF5 = 0xc5,
  146248. M_SOF6 = 0xc6,
  146249. M_SOF7 = 0xc7,
  146250. M_JPG = 0xc8,
  146251. M_SOF9 = 0xc9,
  146252. M_SOF10 = 0xca,
  146253. M_SOF11 = 0xcb,
  146254. M_SOF13 = 0xcd,
  146255. M_SOF14 = 0xce,
  146256. M_SOF15 = 0xcf,
  146257. M_DHT = 0xc4,
  146258. M_DAC = 0xcc,
  146259. M_RST0 = 0xd0,
  146260. M_RST1 = 0xd1,
  146261. M_RST2 = 0xd2,
  146262. M_RST3 = 0xd3,
  146263. M_RST4 = 0xd4,
  146264. M_RST5 = 0xd5,
  146265. M_RST6 = 0xd6,
  146266. M_RST7 = 0xd7,
  146267. M_SOI = 0xd8,
  146268. M_EOI = 0xd9,
  146269. M_SOS = 0xda,
  146270. M_DQT = 0xdb,
  146271. M_DNL = 0xdc,
  146272. M_DRI = 0xdd,
  146273. M_DHP = 0xde,
  146274. M_EXP = 0xdf,
  146275. M_APP0 = 0xe0,
  146276. M_APP1 = 0xe1,
  146277. M_APP2 = 0xe2,
  146278. M_APP3 = 0xe3,
  146279. M_APP4 = 0xe4,
  146280. M_APP5 = 0xe5,
  146281. M_APP6 = 0xe6,
  146282. M_APP7 = 0xe7,
  146283. M_APP8 = 0xe8,
  146284. M_APP9 = 0xe9,
  146285. M_APP10 = 0xea,
  146286. M_APP11 = 0xeb,
  146287. M_APP12 = 0xec,
  146288. M_APP13 = 0xed,
  146289. M_APP14 = 0xee,
  146290. M_APP15 = 0xef,
  146291. M_JPG0 = 0xf0,
  146292. M_JPG13 = 0xfd,
  146293. M_COM = 0xfe,
  146294. M_TEM = 0x01,
  146295. M_ERROR = 0x100
  146296. } JPEG_MARKER;
  146297. #ifdef AVOID_TABLES
  146298. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146299. #else
  146300. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146301. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146302. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146303. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146304. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146305. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146306. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146307. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146308. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146309. #endif /* AVOID_TABLES */
  146310. #endif
  146311. /*** End of inlined file: jinclude.h ***/
  146312. GLOBAL(void)
  146313. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146314. {
  146315. int i;
  146316. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146317. if (version != JPEG_LIB_VERSION)
  146318. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146319. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146320. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146321. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146322. {
  146323. struct jpeg_error_mgr * err = cinfo->err;
  146324. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146325. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146326. cinfo->err = err;
  146327. cinfo->client_data = client_data;
  146328. }
  146329. cinfo->is_decompressor = FALSE;
  146330. jinit_memory_mgr((j_common_ptr) cinfo);
  146331. cinfo->progress = NULL;
  146332. cinfo->dest = NULL;
  146333. cinfo->comp_info = NULL;
  146334. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146335. cinfo->quant_tbl_ptrs[i] = NULL;
  146336. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146337. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146338. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146339. }
  146340. cinfo->script_space = NULL;
  146341. cinfo->input_gamma = 1.0; /* in case application forgets */
  146342. cinfo->global_state = CSTATE_START;
  146343. }
  146344. GLOBAL(void)
  146345. jpeg_destroy_compress (j_compress_ptr cinfo)
  146346. {
  146347. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146348. }
  146349. GLOBAL(void)
  146350. jpeg_abort_compress (j_compress_ptr cinfo)
  146351. {
  146352. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146353. }
  146354. GLOBAL(void)
  146355. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146356. {
  146357. int i;
  146358. JQUANT_TBL * qtbl;
  146359. JHUFF_TBL * htbl;
  146360. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146361. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146362. qtbl->sent_table = suppress;
  146363. }
  146364. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146365. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146366. htbl->sent_table = suppress;
  146367. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146368. htbl->sent_table = suppress;
  146369. }
  146370. }
  146371. GLOBAL(void)
  146372. jpeg_finish_compress (j_compress_ptr cinfo)
  146373. {
  146374. JDIMENSION iMCU_row;
  146375. if (cinfo->global_state == CSTATE_SCANNING ||
  146376. cinfo->global_state == CSTATE_RAW_OK) {
  146377. if (cinfo->next_scanline < cinfo->image_height)
  146378. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146379. (*cinfo->master->finish_pass) (cinfo);
  146380. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146381. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146382. while (! cinfo->master->is_last_pass) {
  146383. (*cinfo->master->prepare_for_pass) (cinfo);
  146384. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146385. if (cinfo->progress != NULL) {
  146386. cinfo->progress->pass_counter = (long) iMCU_row;
  146387. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146388. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146389. }
  146390. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146391. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146392. }
  146393. (*cinfo->master->finish_pass) (cinfo);
  146394. }
  146395. (*cinfo->marker->write_file_trailer) (cinfo);
  146396. (*cinfo->dest->term_destination) (cinfo);
  146397. jpeg_abort((j_common_ptr) cinfo);
  146398. }
  146399. GLOBAL(void)
  146400. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146401. const JOCTET *dataptr, unsigned int datalen)
  146402. {
  146403. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146404. if (cinfo->next_scanline != 0 ||
  146405. (cinfo->global_state != CSTATE_SCANNING &&
  146406. cinfo->global_state != CSTATE_RAW_OK &&
  146407. cinfo->global_state != CSTATE_WRCOEFS))
  146408. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146409. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146410. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146411. while (datalen--) {
  146412. (*write_marker_byte) (cinfo, *dataptr);
  146413. dataptr++;
  146414. }
  146415. }
  146416. GLOBAL(void)
  146417. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146418. {
  146419. if (cinfo->next_scanline != 0 ||
  146420. (cinfo->global_state != CSTATE_SCANNING &&
  146421. cinfo->global_state != CSTATE_RAW_OK &&
  146422. cinfo->global_state != CSTATE_WRCOEFS))
  146423. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146424. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146425. }
  146426. GLOBAL(void)
  146427. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146428. {
  146429. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146430. }
  146431. GLOBAL(void)
  146432. jpeg_write_tables (j_compress_ptr cinfo)
  146433. {
  146434. if (cinfo->global_state != CSTATE_START)
  146435. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146436. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146437. (*cinfo->dest->init_destination) (cinfo);
  146438. jinit_marker_writer(cinfo);
  146439. (*cinfo->marker->write_tables_only) (cinfo);
  146440. (*cinfo->dest->term_destination) (cinfo);
  146441. }
  146442. /*** End of inlined file: jcapimin.c ***/
  146443. /*** Start of inlined file: jcapistd.c ***/
  146444. #define JPEG_INTERNALS
  146445. GLOBAL(void)
  146446. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146447. {
  146448. if (cinfo->global_state != CSTATE_START)
  146449. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146450. if (write_all_tables)
  146451. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146452. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146453. (*cinfo->dest->init_destination) (cinfo);
  146454. jinit_compress_master(cinfo);
  146455. (*cinfo->master->prepare_for_pass) (cinfo);
  146456. cinfo->next_scanline = 0;
  146457. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146458. }
  146459. GLOBAL(JDIMENSION)
  146460. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146461. JDIMENSION num_lines)
  146462. {
  146463. JDIMENSION row_ctr, rows_left;
  146464. if (cinfo->global_state != CSTATE_SCANNING)
  146465. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146466. if (cinfo->next_scanline >= cinfo->image_height)
  146467. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146468. if (cinfo->progress != NULL) {
  146469. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146470. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146471. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146472. }
  146473. if (cinfo->master->call_pass_startup)
  146474. (*cinfo->master->pass_startup) (cinfo);
  146475. rows_left = cinfo->image_height - cinfo->next_scanline;
  146476. if (num_lines > rows_left)
  146477. num_lines = rows_left;
  146478. row_ctr = 0;
  146479. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146480. cinfo->next_scanline += row_ctr;
  146481. return row_ctr;
  146482. }
  146483. GLOBAL(JDIMENSION)
  146484. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146485. JDIMENSION num_lines)
  146486. {
  146487. JDIMENSION lines_per_iMCU_row;
  146488. if (cinfo->global_state != CSTATE_RAW_OK)
  146489. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146490. if (cinfo->next_scanline >= cinfo->image_height) {
  146491. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146492. return 0;
  146493. }
  146494. if (cinfo->progress != NULL) {
  146495. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146496. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146497. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146498. }
  146499. if (cinfo->master->call_pass_startup)
  146500. (*cinfo->master->pass_startup) (cinfo);
  146501. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146502. if (num_lines < lines_per_iMCU_row)
  146503. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146504. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146505. return 0;
  146506. }
  146507. cinfo->next_scanline += lines_per_iMCU_row;
  146508. return lines_per_iMCU_row;
  146509. }
  146510. /*** End of inlined file: jcapistd.c ***/
  146511. /*** Start of inlined file: jccoefct.c ***/
  146512. #define JPEG_INTERNALS
  146513. #ifdef ENTROPY_OPT_SUPPORTED
  146514. #define FULL_COEF_BUFFER_SUPPORTED
  146515. #else
  146516. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146517. #define FULL_COEF_BUFFER_SUPPORTED
  146518. #endif
  146519. #endif
  146520. typedef struct {
  146521. struct jpeg_c_coef_controller pub; /* public fields */
  146522. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146523. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146524. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146525. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146526. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146527. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146528. } my_coef_controller;
  146529. typedef my_coef_controller * my_coef_ptr;
  146530. METHODDEF(boolean) compress_data
  146531. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146532. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146533. METHODDEF(boolean) compress_first_pass
  146534. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146535. METHODDEF(boolean) compress_output
  146536. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146537. #endif
  146538. LOCAL(void)
  146539. start_iMCU_row (j_compress_ptr cinfo)
  146540. {
  146541. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146542. if (cinfo->comps_in_scan > 1) {
  146543. coef->MCU_rows_per_iMCU_row = 1;
  146544. } else {
  146545. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146546. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146547. else
  146548. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146549. }
  146550. coef->mcu_ctr = 0;
  146551. coef->MCU_vert_offset = 0;
  146552. }
  146553. METHODDEF(void)
  146554. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146555. {
  146556. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146557. coef->iMCU_row_num = 0;
  146558. start_iMCU_row(cinfo);
  146559. switch (pass_mode) {
  146560. case JBUF_PASS_THRU:
  146561. if (coef->whole_image[0] != NULL)
  146562. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146563. coef->pub.compress_data = compress_data;
  146564. break;
  146565. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146566. case JBUF_SAVE_AND_PASS:
  146567. if (coef->whole_image[0] == NULL)
  146568. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146569. coef->pub.compress_data = compress_first_pass;
  146570. break;
  146571. case JBUF_CRANK_DEST:
  146572. if (coef->whole_image[0] == NULL)
  146573. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146574. coef->pub.compress_data = compress_output;
  146575. break;
  146576. #endif
  146577. default:
  146578. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146579. break;
  146580. }
  146581. }
  146582. METHODDEF(boolean)
  146583. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146584. {
  146585. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146586. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146587. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146588. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146589. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146590. JDIMENSION ypos, xpos;
  146591. jpeg_component_info *compptr;
  146592. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146593. yoffset++) {
  146594. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146595. MCU_col_num++) {
  146596. blkn = 0;
  146597. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146598. compptr = cinfo->cur_comp_info[ci];
  146599. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146600. : compptr->last_col_width;
  146601. xpos = MCU_col_num * compptr->MCU_sample_width;
  146602. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146603. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146604. if (coef->iMCU_row_num < last_iMCU_row ||
  146605. yoffset+yindex < compptr->last_row_height) {
  146606. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146607. input_buf[compptr->component_index],
  146608. coef->MCU_buffer[blkn],
  146609. ypos, xpos, (JDIMENSION) blockcnt);
  146610. if (blockcnt < compptr->MCU_width) {
  146611. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146612. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146613. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146614. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146615. }
  146616. }
  146617. } else {
  146618. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146619. compptr->MCU_width * SIZEOF(JBLOCK));
  146620. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146621. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146622. }
  146623. }
  146624. blkn += compptr->MCU_width;
  146625. ypos += DCTSIZE;
  146626. }
  146627. }
  146628. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146629. coef->MCU_vert_offset = yoffset;
  146630. coef->mcu_ctr = MCU_col_num;
  146631. return FALSE;
  146632. }
  146633. }
  146634. coef->mcu_ctr = 0;
  146635. }
  146636. coef->iMCU_row_num++;
  146637. start_iMCU_row(cinfo);
  146638. return TRUE;
  146639. }
  146640. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146641. METHODDEF(boolean)
  146642. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146643. {
  146644. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146645. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146646. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146647. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146648. JCOEF lastDC;
  146649. jpeg_component_info *compptr;
  146650. JBLOCKARRAY buffer;
  146651. JBLOCKROW thisblockrow, lastblockrow;
  146652. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146653. ci++, compptr++) {
  146654. buffer = (*cinfo->mem->access_virt_barray)
  146655. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146656. coef->iMCU_row_num * compptr->v_samp_factor,
  146657. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146658. if (coef->iMCU_row_num < last_iMCU_row)
  146659. block_rows = compptr->v_samp_factor;
  146660. else {
  146661. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146662. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146663. }
  146664. blocks_across = compptr->width_in_blocks;
  146665. h_samp_factor = compptr->h_samp_factor;
  146666. ndummy = (int) (blocks_across % h_samp_factor);
  146667. if (ndummy > 0)
  146668. ndummy = h_samp_factor - ndummy;
  146669. for (block_row = 0; block_row < block_rows; block_row++) {
  146670. thisblockrow = buffer[block_row];
  146671. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146672. input_buf[ci], thisblockrow,
  146673. (JDIMENSION) (block_row * DCTSIZE),
  146674. (JDIMENSION) 0, blocks_across);
  146675. if (ndummy > 0) {
  146676. thisblockrow += blocks_across; /* => first dummy block */
  146677. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146678. lastDC = thisblockrow[-1][0];
  146679. for (bi = 0; bi < ndummy; bi++) {
  146680. thisblockrow[bi][0] = lastDC;
  146681. }
  146682. }
  146683. }
  146684. if (coef->iMCU_row_num == last_iMCU_row) {
  146685. blocks_across += ndummy; /* include lower right corner */
  146686. MCUs_across = blocks_across / h_samp_factor;
  146687. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146688. block_row++) {
  146689. thisblockrow = buffer[block_row];
  146690. lastblockrow = buffer[block_row-1];
  146691. jzero_far((void FAR *) thisblockrow,
  146692. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146693. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146694. lastDC = lastblockrow[h_samp_factor-1][0];
  146695. for (bi = 0; bi < h_samp_factor; bi++) {
  146696. thisblockrow[bi][0] = lastDC;
  146697. }
  146698. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146699. lastblockrow += h_samp_factor;
  146700. }
  146701. }
  146702. }
  146703. }
  146704. return compress_output(cinfo, input_buf);
  146705. }
  146706. METHODDEF(boolean)
  146707. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146708. {
  146709. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146710. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146711. int blkn, ci, xindex, yindex, yoffset;
  146712. JDIMENSION start_col;
  146713. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146714. JBLOCKROW buffer_ptr;
  146715. jpeg_component_info *compptr;
  146716. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146717. compptr = cinfo->cur_comp_info[ci];
  146718. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146719. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146720. coef->iMCU_row_num * compptr->v_samp_factor,
  146721. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146722. }
  146723. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146724. yoffset++) {
  146725. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146726. MCU_col_num++) {
  146727. blkn = 0; /* index of current DCT block within MCU */
  146728. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146729. compptr = cinfo->cur_comp_info[ci];
  146730. start_col = MCU_col_num * compptr->MCU_width;
  146731. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146732. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146733. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146734. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146735. }
  146736. }
  146737. }
  146738. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146739. coef->MCU_vert_offset = yoffset;
  146740. coef->mcu_ctr = MCU_col_num;
  146741. return FALSE;
  146742. }
  146743. }
  146744. coef->mcu_ctr = 0;
  146745. }
  146746. coef->iMCU_row_num++;
  146747. start_iMCU_row(cinfo);
  146748. return TRUE;
  146749. }
  146750. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146751. GLOBAL(void)
  146752. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146753. {
  146754. my_coef_ptr coef;
  146755. coef = (my_coef_ptr)
  146756. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146757. SIZEOF(my_coef_controller));
  146758. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146759. coef->pub.start_pass = start_pass_coef;
  146760. if (need_full_buffer) {
  146761. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146762. int ci;
  146763. jpeg_component_info *compptr;
  146764. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146765. ci++, compptr++) {
  146766. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146767. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146768. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146769. (long) compptr->h_samp_factor),
  146770. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146771. (long) compptr->v_samp_factor),
  146772. (JDIMENSION) compptr->v_samp_factor);
  146773. }
  146774. #else
  146775. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146776. #endif
  146777. } else {
  146778. JBLOCKROW buffer;
  146779. int i;
  146780. buffer = (JBLOCKROW)
  146781. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146782. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146783. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146784. coef->MCU_buffer[i] = buffer + i;
  146785. }
  146786. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146787. }
  146788. }
  146789. /*** End of inlined file: jccoefct.c ***/
  146790. /*** Start of inlined file: jccolor.c ***/
  146791. #define JPEG_INTERNALS
  146792. typedef struct {
  146793. struct jpeg_color_converter pub; /* public fields */
  146794. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146795. } my_color_converter;
  146796. typedef my_color_converter * my_cconvert_ptr;
  146797. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146798. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146799. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146800. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146801. #define R_Y_OFF 0 /* offset to R => Y section */
  146802. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146803. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146804. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146805. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146806. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146807. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146808. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146809. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146810. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146811. METHODDEF(void)
  146812. rgb_ycc_start (j_compress_ptr cinfo)
  146813. {
  146814. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146815. INT32 * rgb_ycc_tab;
  146816. INT32 i;
  146817. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146818. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146819. (TABLE_SIZE * SIZEOF(INT32)));
  146820. for (i = 0; i <= MAXJSAMPLE; i++) {
  146821. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146822. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146823. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146824. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146825. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146826. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146827. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146828. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146829. }
  146830. }
  146831. METHODDEF(void)
  146832. rgb_ycc_convert (j_compress_ptr cinfo,
  146833. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146834. JDIMENSION output_row, int num_rows)
  146835. {
  146836. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146837. register int r, g, b;
  146838. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146839. register JSAMPROW inptr;
  146840. register JSAMPROW outptr0, outptr1, outptr2;
  146841. register JDIMENSION col;
  146842. JDIMENSION num_cols = cinfo->image_width;
  146843. while (--num_rows >= 0) {
  146844. inptr = *input_buf++;
  146845. outptr0 = output_buf[0][output_row];
  146846. outptr1 = output_buf[1][output_row];
  146847. outptr2 = output_buf[2][output_row];
  146848. output_row++;
  146849. for (col = 0; col < num_cols; col++) {
  146850. r = GETJSAMPLE(inptr[RGB_RED]);
  146851. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146852. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146853. inptr += RGB_PIXELSIZE;
  146854. outptr0[col] = (JSAMPLE)
  146855. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146856. >> SCALEBITS);
  146857. outptr1[col] = (JSAMPLE)
  146858. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146859. >> SCALEBITS);
  146860. outptr2[col] = (JSAMPLE)
  146861. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146862. >> SCALEBITS);
  146863. }
  146864. }
  146865. }
  146866. METHODDEF(void)
  146867. rgb_gray_convert (j_compress_ptr cinfo,
  146868. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146869. JDIMENSION output_row, int num_rows)
  146870. {
  146871. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146872. register int r, g, b;
  146873. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146874. register JSAMPROW inptr;
  146875. register JSAMPROW outptr;
  146876. register JDIMENSION col;
  146877. JDIMENSION num_cols = cinfo->image_width;
  146878. while (--num_rows >= 0) {
  146879. inptr = *input_buf++;
  146880. outptr = output_buf[0][output_row];
  146881. output_row++;
  146882. for (col = 0; col < num_cols; col++) {
  146883. r = GETJSAMPLE(inptr[RGB_RED]);
  146884. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146885. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146886. inptr += RGB_PIXELSIZE;
  146887. outptr[col] = (JSAMPLE)
  146888. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146889. >> SCALEBITS);
  146890. }
  146891. }
  146892. }
  146893. METHODDEF(void)
  146894. cmyk_ycck_convert (j_compress_ptr cinfo,
  146895. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146896. JDIMENSION output_row, int num_rows)
  146897. {
  146898. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146899. register int r, g, b;
  146900. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146901. register JSAMPROW inptr;
  146902. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146903. register JDIMENSION col;
  146904. JDIMENSION num_cols = cinfo->image_width;
  146905. while (--num_rows >= 0) {
  146906. inptr = *input_buf++;
  146907. outptr0 = output_buf[0][output_row];
  146908. outptr1 = output_buf[1][output_row];
  146909. outptr2 = output_buf[2][output_row];
  146910. outptr3 = output_buf[3][output_row];
  146911. output_row++;
  146912. for (col = 0; col < num_cols; col++) {
  146913. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146914. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146915. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146916. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146917. inptr += 4;
  146918. outptr0[col] = (JSAMPLE)
  146919. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146920. >> SCALEBITS);
  146921. outptr1[col] = (JSAMPLE)
  146922. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146923. >> SCALEBITS);
  146924. outptr2[col] = (JSAMPLE)
  146925. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146926. >> SCALEBITS);
  146927. }
  146928. }
  146929. }
  146930. METHODDEF(void)
  146931. grayscale_convert (j_compress_ptr cinfo,
  146932. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146933. JDIMENSION output_row, int num_rows)
  146934. {
  146935. register JSAMPROW inptr;
  146936. register JSAMPROW outptr;
  146937. register JDIMENSION col;
  146938. JDIMENSION num_cols = cinfo->image_width;
  146939. int instride = cinfo->input_components;
  146940. while (--num_rows >= 0) {
  146941. inptr = *input_buf++;
  146942. outptr = output_buf[0][output_row];
  146943. output_row++;
  146944. for (col = 0; col < num_cols; col++) {
  146945. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146946. inptr += instride;
  146947. }
  146948. }
  146949. }
  146950. METHODDEF(void)
  146951. null_convert (j_compress_ptr cinfo,
  146952. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146953. JDIMENSION output_row, int num_rows)
  146954. {
  146955. register JSAMPROW inptr;
  146956. register JSAMPROW outptr;
  146957. register JDIMENSION col;
  146958. register int ci;
  146959. int nc = cinfo->num_components;
  146960. JDIMENSION num_cols = cinfo->image_width;
  146961. while (--num_rows >= 0) {
  146962. for (ci = 0; ci < nc; ci++) {
  146963. inptr = *input_buf;
  146964. outptr = output_buf[ci][output_row];
  146965. for (col = 0; col < num_cols; col++) {
  146966. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146967. inptr += nc;
  146968. }
  146969. }
  146970. input_buf++;
  146971. output_row++;
  146972. }
  146973. }
  146974. METHODDEF(void)
  146975. null_method (j_compress_ptr cinfo)
  146976. {
  146977. }
  146978. GLOBAL(void)
  146979. jinit_color_converter (j_compress_ptr cinfo)
  146980. {
  146981. my_cconvert_ptr cconvert;
  146982. cconvert = (my_cconvert_ptr)
  146983. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146984. SIZEOF(my_color_converter));
  146985. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146986. cconvert->pub.start_pass = null_method;
  146987. switch (cinfo->in_color_space) {
  146988. case JCS_GRAYSCALE:
  146989. if (cinfo->input_components != 1)
  146990. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146991. break;
  146992. case JCS_RGB:
  146993. #if RGB_PIXELSIZE != 3
  146994. if (cinfo->input_components != RGB_PIXELSIZE)
  146995. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146996. break;
  146997. #endif /* else share code with YCbCr */
  146998. case JCS_YCbCr:
  146999. if (cinfo->input_components != 3)
  147000. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147001. break;
  147002. case JCS_CMYK:
  147003. case JCS_YCCK:
  147004. if (cinfo->input_components != 4)
  147005. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147006. break;
  147007. default: /* JCS_UNKNOWN can be anything */
  147008. if (cinfo->input_components < 1)
  147009. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147010. break;
  147011. }
  147012. switch (cinfo->jpeg_color_space) {
  147013. case JCS_GRAYSCALE:
  147014. if (cinfo->num_components != 1)
  147015. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147016. if (cinfo->in_color_space == JCS_GRAYSCALE)
  147017. cconvert->pub.color_convert = grayscale_convert;
  147018. else if (cinfo->in_color_space == JCS_RGB) {
  147019. cconvert->pub.start_pass = rgb_ycc_start;
  147020. cconvert->pub.color_convert = rgb_gray_convert;
  147021. } else if (cinfo->in_color_space == JCS_YCbCr)
  147022. cconvert->pub.color_convert = grayscale_convert;
  147023. else
  147024. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147025. break;
  147026. case JCS_RGB:
  147027. if (cinfo->num_components != 3)
  147028. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147029. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  147030. cconvert->pub.color_convert = null_convert;
  147031. else
  147032. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147033. break;
  147034. case JCS_YCbCr:
  147035. if (cinfo->num_components != 3)
  147036. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147037. if (cinfo->in_color_space == JCS_RGB) {
  147038. cconvert->pub.start_pass = rgb_ycc_start;
  147039. cconvert->pub.color_convert = rgb_ycc_convert;
  147040. } else if (cinfo->in_color_space == JCS_YCbCr)
  147041. cconvert->pub.color_convert = null_convert;
  147042. else
  147043. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147044. break;
  147045. case JCS_CMYK:
  147046. if (cinfo->num_components != 4)
  147047. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147048. if (cinfo->in_color_space == JCS_CMYK)
  147049. cconvert->pub.color_convert = null_convert;
  147050. else
  147051. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147052. break;
  147053. case JCS_YCCK:
  147054. if (cinfo->num_components != 4)
  147055. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147056. if (cinfo->in_color_space == JCS_CMYK) {
  147057. cconvert->pub.start_pass = rgb_ycc_start;
  147058. cconvert->pub.color_convert = cmyk_ycck_convert;
  147059. } else if (cinfo->in_color_space == JCS_YCCK)
  147060. cconvert->pub.color_convert = null_convert;
  147061. else
  147062. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147063. break;
  147064. default: /* allow null conversion of JCS_UNKNOWN */
  147065. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  147066. cinfo->num_components != cinfo->input_components)
  147067. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147068. cconvert->pub.color_convert = null_convert;
  147069. break;
  147070. }
  147071. }
  147072. /*** End of inlined file: jccolor.c ***/
  147073. #undef FIX
  147074. /*** Start of inlined file: jcdctmgr.c ***/
  147075. #define JPEG_INTERNALS
  147076. /*** Start of inlined file: jdct.h ***/
  147077. #ifndef __jdct_h__
  147078. #define __jdct_h__
  147079. #if BITS_IN_JSAMPLE == 8
  147080. typedef int DCTELEM; /* 16 or 32 bits is fine */
  147081. #else
  147082. typedef INT32 DCTELEM; /* must have 32 bits */
  147083. #endif
  147084. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  147085. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  147086. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  147087. #if BITS_IN_JSAMPLE == 8
  147088. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  147089. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  147090. #else
  147091. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  147092. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  147093. #endif
  147094. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  147095. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  147096. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147097. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147098. #define jpeg_fdct_islow jFDislow
  147099. #define jpeg_fdct_ifast jFDifast
  147100. #define jpeg_fdct_float jFDfloat
  147101. #define jpeg_idct_islow jRDislow
  147102. #define jpeg_idct_ifast jRDifast
  147103. #define jpeg_idct_float jRDfloat
  147104. #define jpeg_idct_4x4 jRD4x4
  147105. #define jpeg_idct_2x2 jRD2x2
  147106. #define jpeg_idct_1x1 jRD1x1
  147107. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147108. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147109. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147110. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147111. EXTERN(void) jpeg_idct_islow
  147112. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147113. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147114. EXTERN(void) jpeg_idct_ifast
  147115. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147116. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147117. EXTERN(void) jpeg_idct_float
  147118. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147119. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147120. EXTERN(void) jpeg_idct_4x4
  147121. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147122. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147123. EXTERN(void) jpeg_idct_2x2
  147124. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147125. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147126. EXTERN(void) jpeg_idct_1x1
  147127. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147128. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147129. #define ONE ((INT32) 1)
  147130. #define CONST_SCALE (ONE << CONST_BITS)
  147131. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147132. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147133. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147134. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147135. #endif
  147136. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147137. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147138. #endif
  147139. #ifndef MULTIPLY16C16 /* default definition */
  147140. #define MULTIPLY16C16(var,const) ((var) * (const))
  147141. #endif
  147142. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147143. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147144. #endif
  147145. #ifndef MULTIPLY16V16 /* default definition */
  147146. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147147. #endif
  147148. #endif
  147149. /*** End of inlined file: jdct.h ***/
  147150. /* Private declarations for DCT subsystem */
  147151. typedef struct {
  147152. struct jpeg_forward_dct pub; /* public fields */
  147153. forward_DCT_method_ptr do_dct;
  147154. DCTELEM * divisors[NUM_QUANT_TBLS];
  147155. #ifdef DCT_FLOAT_SUPPORTED
  147156. float_DCT_method_ptr do_float_dct;
  147157. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147158. #endif
  147159. } my_fdct_controller;
  147160. typedef my_fdct_controller * my_fdct_ptr;
  147161. METHODDEF(void)
  147162. start_pass_fdctmgr (j_compress_ptr cinfo)
  147163. {
  147164. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147165. int ci, qtblno, i;
  147166. jpeg_component_info *compptr;
  147167. JQUANT_TBL * qtbl;
  147168. DCTELEM * dtbl;
  147169. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147170. ci++, compptr++) {
  147171. qtblno = compptr->quant_tbl_no;
  147172. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147173. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147174. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147175. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147176. switch (cinfo->dct_method) {
  147177. #ifdef DCT_ISLOW_SUPPORTED
  147178. case JDCT_ISLOW:
  147179. if (fdct->divisors[qtblno] == NULL) {
  147180. fdct->divisors[qtblno] = (DCTELEM *)
  147181. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147182. DCTSIZE2 * SIZEOF(DCTELEM));
  147183. }
  147184. dtbl = fdct->divisors[qtblno];
  147185. for (i = 0; i < DCTSIZE2; i++) {
  147186. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147187. }
  147188. break;
  147189. #endif
  147190. #ifdef DCT_IFAST_SUPPORTED
  147191. case JDCT_IFAST:
  147192. {
  147193. #define CONST_BITS 14
  147194. static const INT16 aanscales[DCTSIZE2] = {
  147195. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147196. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147197. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147198. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147199. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147200. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147201. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147202. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147203. };
  147204. SHIFT_TEMPS
  147205. if (fdct->divisors[qtblno] == NULL) {
  147206. fdct->divisors[qtblno] = (DCTELEM *)
  147207. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147208. DCTSIZE2 * SIZEOF(DCTELEM));
  147209. }
  147210. dtbl = fdct->divisors[qtblno];
  147211. for (i = 0; i < DCTSIZE2; i++) {
  147212. dtbl[i] = (DCTELEM)
  147213. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147214. (INT32) aanscales[i]),
  147215. CONST_BITS-3);
  147216. }
  147217. }
  147218. break;
  147219. #endif
  147220. #ifdef DCT_FLOAT_SUPPORTED
  147221. case JDCT_FLOAT:
  147222. {
  147223. FAST_FLOAT * fdtbl;
  147224. int row, col;
  147225. static const double aanscalefactor[DCTSIZE] = {
  147226. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147227. 1.0, 0.785694958, 0.541196100, 0.275899379
  147228. };
  147229. if (fdct->float_divisors[qtblno] == NULL) {
  147230. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147231. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147232. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147233. }
  147234. fdtbl = fdct->float_divisors[qtblno];
  147235. i = 0;
  147236. for (row = 0; row < DCTSIZE; row++) {
  147237. for (col = 0; col < DCTSIZE; col++) {
  147238. fdtbl[i] = (FAST_FLOAT)
  147239. (1.0 / (((double) qtbl->quantval[i] *
  147240. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147241. i++;
  147242. }
  147243. }
  147244. }
  147245. break;
  147246. #endif
  147247. default:
  147248. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147249. break;
  147250. }
  147251. }
  147252. }
  147253. METHODDEF(void)
  147254. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147255. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147256. JDIMENSION start_row, JDIMENSION start_col,
  147257. JDIMENSION num_blocks)
  147258. {
  147259. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147260. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147261. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147262. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147263. JDIMENSION bi;
  147264. sample_data += start_row; /* fold in the vertical offset once */
  147265. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147266. { register DCTELEM *workspaceptr;
  147267. register JSAMPROW elemptr;
  147268. register int elemr;
  147269. workspaceptr = workspace;
  147270. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147271. elemptr = sample_data[elemr] + start_col;
  147272. #if DCTSIZE == 8 /* unroll the inner loop */
  147273. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147274. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147275. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147276. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147277. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147278. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147279. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147280. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147281. #else
  147282. { register int elemc;
  147283. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147284. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147285. }
  147286. }
  147287. #endif
  147288. }
  147289. }
  147290. (*do_dct) (workspace);
  147291. { register DCTELEM temp, qval;
  147292. register int i;
  147293. register JCOEFPTR output_ptr = coef_blocks[bi];
  147294. for (i = 0; i < DCTSIZE2; i++) {
  147295. qval = divisors[i];
  147296. temp = workspace[i];
  147297. #ifdef FAST_DIVIDE
  147298. #define DIVIDE_BY(a,b) a /= b
  147299. #else
  147300. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147301. #endif
  147302. if (temp < 0) {
  147303. temp = -temp;
  147304. temp += qval>>1; /* for rounding */
  147305. DIVIDE_BY(temp, qval);
  147306. temp = -temp;
  147307. } else {
  147308. temp += qval>>1; /* for rounding */
  147309. DIVIDE_BY(temp, qval);
  147310. }
  147311. output_ptr[i] = (JCOEF) temp;
  147312. }
  147313. }
  147314. }
  147315. }
  147316. #ifdef DCT_FLOAT_SUPPORTED
  147317. METHODDEF(void)
  147318. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147319. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147320. JDIMENSION start_row, JDIMENSION start_col,
  147321. JDIMENSION num_blocks)
  147322. {
  147323. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147324. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147325. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147326. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147327. JDIMENSION bi;
  147328. sample_data += start_row; /* fold in the vertical offset once */
  147329. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147330. { register FAST_FLOAT *workspaceptr;
  147331. register JSAMPROW elemptr;
  147332. register int elemr;
  147333. workspaceptr = workspace;
  147334. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147335. elemptr = sample_data[elemr] + start_col;
  147336. #if DCTSIZE == 8 /* unroll the inner loop */
  147337. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147338. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147339. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147340. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147341. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147342. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147343. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147344. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147345. #else
  147346. { register int elemc;
  147347. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147348. *workspaceptr++ = (FAST_FLOAT)
  147349. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147350. }
  147351. }
  147352. #endif
  147353. }
  147354. }
  147355. (*do_dct) (workspace);
  147356. { register FAST_FLOAT temp;
  147357. register int i;
  147358. register JCOEFPTR output_ptr = coef_blocks[bi];
  147359. for (i = 0; i < DCTSIZE2; i++) {
  147360. temp = workspace[i] * divisors[i];
  147361. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147362. }
  147363. }
  147364. }
  147365. }
  147366. #endif /* DCT_FLOAT_SUPPORTED */
  147367. GLOBAL(void)
  147368. jinit_forward_dct (j_compress_ptr cinfo)
  147369. {
  147370. my_fdct_ptr fdct;
  147371. int i;
  147372. fdct = (my_fdct_ptr)
  147373. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147374. SIZEOF(my_fdct_controller));
  147375. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147376. fdct->pub.start_pass = start_pass_fdctmgr;
  147377. switch (cinfo->dct_method) {
  147378. #ifdef DCT_ISLOW_SUPPORTED
  147379. case JDCT_ISLOW:
  147380. fdct->pub.forward_DCT = forward_DCT;
  147381. fdct->do_dct = jpeg_fdct_islow;
  147382. break;
  147383. #endif
  147384. #ifdef DCT_IFAST_SUPPORTED
  147385. case JDCT_IFAST:
  147386. fdct->pub.forward_DCT = forward_DCT;
  147387. fdct->do_dct = jpeg_fdct_ifast;
  147388. break;
  147389. #endif
  147390. #ifdef DCT_FLOAT_SUPPORTED
  147391. case JDCT_FLOAT:
  147392. fdct->pub.forward_DCT = forward_DCT_float;
  147393. fdct->do_float_dct = jpeg_fdct_float;
  147394. break;
  147395. #endif
  147396. default:
  147397. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147398. break;
  147399. }
  147400. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147401. fdct->divisors[i] = NULL;
  147402. #ifdef DCT_FLOAT_SUPPORTED
  147403. fdct->float_divisors[i] = NULL;
  147404. #endif
  147405. }
  147406. }
  147407. /*** End of inlined file: jcdctmgr.c ***/
  147408. #undef CONST_BITS
  147409. /*** Start of inlined file: jchuff.c ***/
  147410. #define JPEG_INTERNALS
  147411. /*** Start of inlined file: jchuff.h ***/
  147412. #ifndef _jchuff_h_
  147413. #define _jchuff_h_
  147414. #if BITS_IN_JSAMPLE == 8
  147415. #define MAX_COEF_BITS 10
  147416. #else
  147417. #define MAX_COEF_BITS 14
  147418. #endif
  147419. typedef struct {
  147420. unsigned int ehufco[256]; /* code for each symbol */
  147421. char ehufsi[256]; /* length of code for each symbol */
  147422. } c_derived_tbl;
  147423. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147424. #define jpeg_make_c_derived_tbl jMkCDerived
  147425. #define jpeg_gen_optimal_table jGenOptTbl
  147426. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147427. EXTERN(void) jpeg_make_c_derived_tbl
  147428. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147429. c_derived_tbl ** pdtbl));
  147430. EXTERN(void) jpeg_gen_optimal_table
  147431. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147432. #endif
  147433. /*** End of inlined file: jchuff.h ***/
  147434. /* Declarations shared with jcphuff.c */
  147435. typedef struct {
  147436. INT32 put_buffer; /* current bit-accumulation buffer */
  147437. int put_bits; /* # of bits now in it */
  147438. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147439. } savable_state;
  147440. #ifndef NO_STRUCT_ASSIGN
  147441. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147442. #else
  147443. #if MAX_COMPS_IN_SCAN == 4
  147444. #define ASSIGN_STATE(dest,src) \
  147445. ((dest).put_buffer = (src).put_buffer, \
  147446. (dest).put_bits = (src).put_bits, \
  147447. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147448. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147449. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147450. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147451. #endif
  147452. #endif
  147453. typedef struct {
  147454. struct jpeg_entropy_encoder pub; /* public fields */
  147455. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147456. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147457. int next_restart_num; /* next restart number to write (0-7) */
  147458. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147459. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147460. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147461. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147462. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147463. #endif
  147464. } huff_entropy_encoder;
  147465. typedef huff_entropy_encoder * huff_entropy_ptr;
  147466. typedef struct {
  147467. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147468. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147469. savable_state cur; /* Current bit buffer & DC state */
  147470. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147471. } working_state;
  147472. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147473. JBLOCKROW *MCU_data));
  147474. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147475. #ifdef ENTROPY_OPT_SUPPORTED
  147476. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147477. JBLOCKROW *MCU_data));
  147478. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147479. #endif
  147480. METHODDEF(void)
  147481. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147482. {
  147483. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147484. int ci, dctbl, actbl;
  147485. jpeg_component_info * compptr;
  147486. if (gather_statistics) {
  147487. #ifdef ENTROPY_OPT_SUPPORTED
  147488. entropy->pub.encode_mcu = encode_mcu_gather;
  147489. entropy->pub.finish_pass = finish_pass_gather;
  147490. #else
  147491. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147492. #endif
  147493. } else {
  147494. entropy->pub.encode_mcu = encode_mcu_huff;
  147495. entropy->pub.finish_pass = finish_pass_huff;
  147496. }
  147497. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147498. compptr = cinfo->cur_comp_info[ci];
  147499. dctbl = compptr->dc_tbl_no;
  147500. actbl = compptr->ac_tbl_no;
  147501. if (gather_statistics) {
  147502. #ifdef ENTROPY_OPT_SUPPORTED
  147503. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147504. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147505. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147506. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147507. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147508. entropy->dc_count_ptrs[dctbl] = (long *)
  147509. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147510. 257 * SIZEOF(long));
  147511. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147512. if (entropy->ac_count_ptrs[actbl] == NULL)
  147513. entropy->ac_count_ptrs[actbl] = (long *)
  147514. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147515. 257 * SIZEOF(long));
  147516. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147517. #endif
  147518. } else {
  147519. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147520. & entropy->dc_derived_tbls[dctbl]);
  147521. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147522. & entropy->ac_derived_tbls[actbl]);
  147523. }
  147524. entropy->saved.last_dc_val[ci] = 0;
  147525. }
  147526. entropy->saved.put_buffer = 0;
  147527. entropy->saved.put_bits = 0;
  147528. entropy->restarts_to_go = cinfo->restart_interval;
  147529. entropy->next_restart_num = 0;
  147530. }
  147531. GLOBAL(void)
  147532. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147533. c_derived_tbl ** pdtbl)
  147534. {
  147535. JHUFF_TBL *htbl;
  147536. c_derived_tbl *dtbl;
  147537. int p, i, l, lastp, si, maxsymbol;
  147538. char huffsize[257];
  147539. unsigned int huffcode[257];
  147540. unsigned int code;
  147541. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147542. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147543. htbl =
  147544. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147545. if (htbl == NULL)
  147546. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147547. if (*pdtbl == NULL)
  147548. *pdtbl = (c_derived_tbl *)
  147549. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147550. SIZEOF(c_derived_tbl));
  147551. dtbl = *pdtbl;
  147552. p = 0;
  147553. for (l = 1; l <= 16; l++) {
  147554. i = (int) htbl->bits[l];
  147555. if (i < 0 || p + i > 256) /* protect against table overrun */
  147556. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147557. while (i--)
  147558. huffsize[p++] = (char) l;
  147559. }
  147560. huffsize[p] = 0;
  147561. lastp = p;
  147562. code = 0;
  147563. si = huffsize[0];
  147564. p = 0;
  147565. while (huffsize[p]) {
  147566. while (((int) huffsize[p]) == si) {
  147567. huffcode[p++] = code;
  147568. code++;
  147569. }
  147570. if (((INT32) code) >= (((INT32) 1) << si))
  147571. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147572. code <<= 1;
  147573. si++;
  147574. }
  147575. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147576. maxsymbol = isDC ? 15 : 255;
  147577. for (p = 0; p < lastp; p++) {
  147578. i = htbl->huffval[p];
  147579. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147580. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147581. dtbl->ehufco[i] = huffcode[p];
  147582. dtbl->ehufsi[i] = huffsize[p];
  147583. }
  147584. }
  147585. #define emit_byte(state,val,action) \
  147586. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147587. if (--(state)->free_in_buffer == 0) \
  147588. if (! dump_buffer(state)) \
  147589. { action; } }
  147590. LOCAL(boolean)
  147591. dump_buffer (working_state * state)
  147592. {
  147593. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147594. if (! (*dest->empty_output_buffer) (state->cinfo))
  147595. return FALSE;
  147596. state->next_output_byte = dest->next_output_byte;
  147597. state->free_in_buffer = dest->free_in_buffer;
  147598. return TRUE;
  147599. }
  147600. INLINE
  147601. LOCAL(boolean)
  147602. emit_bits (working_state * state, unsigned int code, int size)
  147603. {
  147604. register INT32 put_buffer = (INT32) code;
  147605. register int put_bits = state->cur.put_bits;
  147606. if (size == 0)
  147607. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147608. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147609. put_bits += size; /* new number of bits in buffer */
  147610. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147611. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147612. while (put_bits >= 8) {
  147613. int c = (int) ((put_buffer >> 16) & 0xFF);
  147614. emit_byte(state, c, return FALSE);
  147615. if (c == 0xFF) { /* need to stuff a zero byte? */
  147616. emit_byte(state, 0, return FALSE);
  147617. }
  147618. put_buffer <<= 8;
  147619. put_bits -= 8;
  147620. }
  147621. state->cur.put_buffer = put_buffer; /* update state variables */
  147622. state->cur.put_bits = put_bits;
  147623. return TRUE;
  147624. }
  147625. LOCAL(boolean)
  147626. flush_bits (working_state * state)
  147627. {
  147628. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147629. return FALSE;
  147630. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147631. state->cur.put_bits = 0;
  147632. return TRUE;
  147633. }
  147634. LOCAL(boolean)
  147635. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147636. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147637. {
  147638. register int temp, temp2;
  147639. register int nbits;
  147640. register int k, r, i;
  147641. temp = temp2 = block[0] - last_dc_val;
  147642. if (temp < 0) {
  147643. temp = -temp; /* temp is abs value of input */
  147644. temp2--;
  147645. }
  147646. nbits = 0;
  147647. while (temp) {
  147648. nbits++;
  147649. temp >>= 1;
  147650. }
  147651. if (nbits > MAX_COEF_BITS+1)
  147652. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147653. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147654. return FALSE;
  147655. if (nbits) /* emit_bits rejects calls with size 0 */
  147656. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147657. return FALSE;
  147658. r = 0; /* r = run length of zeros */
  147659. for (k = 1; k < DCTSIZE2; k++) {
  147660. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147661. r++;
  147662. } else {
  147663. while (r > 15) {
  147664. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147665. return FALSE;
  147666. r -= 16;
  147667. }
  147668. temp2 = temp;
  147669. if (temp < 0) {
  147670. temp = -temp; /* temp is abs value of input */
  147671. temp2--;
  147672. }
  147673. nbits = 1; /* there must be at least one 1 bit */
  147674. while ((temp >>= 1))
  147675. nbits++;
  147676. if (nbits > MAX_COEF_BITS)
  147677. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147678. i = (r << 4) + nbits;
  147679. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147680. return FALSE;
  147681. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147682. return FALSE;
  147683. r = 0;
  147684. }
  147685. }
  147686. if (r > 0)
  147687. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147688. return FALSE;
  147689. return TRUE;
  147690. }
  147691. LOCAL(boolean)
  147692. emit_restart (working_state * state, int restart_num)
  147693. {
  147694. int ci;
  147695. if (! flush_bits(state))
  147696. return FALSE;
  147697. emit_byte(state, 0xFF, return FALSE);
  147698. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147699. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147700. state->cur.last_dc_val[ci] = 0;
  147701. return TRUE;
  147702. }
  147703. METHODDEF(boolean)
  147704. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147705. {
  147706. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147707. working_state state;
  147708. int blkn, ci;
  147709. jpeg_component_info * compptr;
  147710. state.next_output_byte = cinfo->dest->next_output_byte;
  147711. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147712. ASSIGN_STATE(state.cur, entropy->saved);
  147713. state.cinfo = cinfo;
  147714. if (cinfo->restart_interval) {
  147715. if (entropy->restarts_to_go == 0)
  147716. if (! emit_restart(&state, entropy->next_restart_num))
  147717. return FALSE;
  147718. }
  147719. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147720. ci = cinfo->MCU_membership[blkn];
  147721. compptr = cinfo->cur_comp_info[ci];
  147722. if (! encode_one_block(&state,
  147723. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147724. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147725. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147726. return FALSE;
  147727. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147728. }
  147729. cinfo->dest->next_output_byte = state.next_output_byte;
  147730. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147731. ASSIGN_STATE(entropy->saved, state.cur);
  147732. if (cinfo->restart_interval) {
  147733. if (entropy->restarts_to_go == 0) {
  147734. entropy->restarts_to_go = cinfo->restart_interval;
  147735. entropy->next_restart_num++;
  147736. entropy->next_restart_num &= 7;
  147737. }
  147738. entropy->restarts_to_go--;
  147739. }
  147740. return TRUE;
  147741. }
  147742. METHODDEF(void)
  147743. finish_pass_huff (j_compress_ptr cinfo)
  147744. {
  147745. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147746. working_state state;
  147747. state.next_output_byte = cinfo->dest->next_output_byte;
  147748. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147749. ASSIGN_STATE(state.cur, entropy->saved);
  147750. state.cinfo = cinfo;
  147751. if (! flush_bits(&state))
  147752. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147753. cinfo->dest->next_output_byte = state.next_output_byte;
  147754. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147755. ASSIGN_STATE(entropy->saved, state.cur);
  147756. }
  147757. #ifdef ENTROPY_OPT_SUPPORTED
  147758. LOCAL(void)
  147759. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147760. long dc_counts[], long ac_counts[])
  147761. {
  147762. register int temp;
  147763. register int nbits;
  147764. register int k, r;
  147765. temp = block[0] - last_dc_val;
  147766. if (temp < 0)
  147767. temp = -temp;
  147768. nbits = 0;
  147769. while (temp) {
  147770. nbits++;
  147771. temp >>= 1;
  147772. }
  147773. if (nbits > MAX_COEF_BITS+1)
  147774. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147775. dc_counts[nbits]++;
  147776. r = 0; /* r = run length of zeros */
  147777. for (k = 1; k < DCTSIZE2; k++) {
  147778. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147779. r++;
  147780. } else {
  147781. while (r > 15) {
  147782. ac_counts[0xF0]++;
  147783. r -= 16;
  147784. }
  147785. if (temp < 0)
  147786. temp = -temp;
  147787. nbits = 1; /* there must be at least one 1 bit */
  147788. while ((temp >>= 1))
  147789. nbits++;
  147790. if (nbits > MAX_COEF_BITS)
  147791. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147792. ac_counts[(r << 4) + nbits]++;
  147793. r = 0;
  147794. }
  147795. }
  147796. if (r > 0)
  147797. ac_counts[0]++;
  147798. }
  147799. METHODDEF(boolean)
  147800. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147801. {
  147802. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147803. int blkn, ci;
  147804. jpeg_component_info * compptr;
  147805. if (cinfo->restart_interval) {
  147806. if (entropy->restarts_to_go == 0) {
  147807. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147808. entropy->saved.last_dc_val[ci] = 0;
  147809. entropy->restarts_to_go = cinfo->restart_interval;
  147810. }
  147811. entropy->restarts_to_go--;
  147812. }
  147813. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147814. ci = cinfo->MCU_membership[blkn];
  147815. compptr = cinfo->cur_comp_info[ci];
  147816. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147817. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147818. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147819. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147820. }
  147821. return TRUE;
  147822. }
  147823. GLOBAL(void)
  147824. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147825. {
  147826. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147827. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147828. int codesize[257]; /* codesize[k] = code length of symbol k */
  147829. int others[257]; /* next symbol in current branch of tree */
  147830. int c1, c2;
  147831. int p, i, j;
  147832. long v;
  147833. MEMZERO(bits, SIZEOF(bits));
  147834. MEMZERO(codesize, SIZEOF(codesize));
  147835. for (i = 0; i < 257; i++)
  147836. others[i] = -1; /* init links to empty */
  147837. freq[256] = 1; /* make sure 256 has a nonzero count */
  147838. for (;;) {
  147839. c1 = -1;
  147840. v = 1000000000L;
  147841. for (i = 0; i <= 256; i++) {
  147842. if (freq[i] && freq[i] <= v) {
  147843. v = freq[i];
  147844. c1 = i;
  147845. }
  147846. }
  147847. c2 = -1;
  147848. v = 1000000000L;
  147849. for (i = 0; i <= 256; i++) {
  147850. if (freq[i] && freq[i] <= v && i != c1) {
  147851. v = freq[i];
  147852. c2 = i;
  147853. }
  147854. }
  147855. if (c2 < 0)
  147856. break;
  147857. freq[c1] += freq[c2];
  147858. freq[c2] = 0;
  147859. codesize[c1]++;
  147860. while (others[c1] >= 0) {
  147861. c1 = others[c1];
  147862. codesize[c1]++;
  147863. }
  147864. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147865. codesize[c2]++;
  147866. while (others[c2] >= 0) {
  147867. c2 = others[c2];
  147868. codesize[c2]++;
  147869. }
  147870. }
  147871. for (i = 0; i <= 256; i++) {
  147872. if (codesize[i]) {
  147873. if (codesize[i] > MAX_CLEN)
  147874. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147875. bits[codesize[i]]++;
  147876. }
  147877. }
  147878. for (i = MAX_CLEN; i > 16; i--) {
  147879. while (bits[i] > 0) {
  147880. j = i - 2; /* find length of new prefix to be used */
  147881. while (bits[j] == 0)
  147882. j--;
  147883. bits[i] -= 2; /* remove two symbols */
  147884. bits[i-1]++; /* one goes in this length */
  147885. bits[j+1] += 2; /* two new symbols in this length */
  147886. bits[j]--; /* symbol of this length is now a prefix */
  147887. }
  147888. }
  147889. while (bits[i] == 0) /* find largest codelength still in use */
  147890. i--;
  147891. bits[i]--;
  147892. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147893. p = 0;
  147894. for (i = 1; i <= MAX_CLEN; i++) {
  147895. for (j = 0; j <= 255; j++) {
  147896. if (codesize[j] == i) {
  147897. htbl->huffval[p] = (UINT8) j;
  147898. p++;
  147899. }
  147900. }
  147901. }
  147902. htbl->sent_table = FALSE;
  147903. }
  147904. METHODDEF(void)
  147905. finish_pass_gather (j_compress_ptr cinfo)
  147906. {
  147907. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147908. int ci, dctbl, actbl;
  147909. jpeg_component_info * compptr;
  147910. JHUFF_TBL **htblptr;
  147911. boolean did_dc[NUM_HUFF_TBLS];
  147912. boolean did_ac[NUM_HUFF_TBLS];
  147913. MEMZERO(did_dc, SIZEOF(did_dc));
  147914. MEMZERO(did_ac, SIZEOF(did_ac));
  147915. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147916. compptr = cinfo->cur_comp_info[ci];
  147917. dctbl = compptr->dc_tbl_no;
  147918. actbl = compptr->ac_tbl_no;
  147919. if (! did_dc[dctbl]) {
  147920. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147921. if (*htblptr == NULL)
  147922. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147923. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147924. did_dc[dctbl] = TRUE;
  147925. }
  147926. if (! did_ac[actbl]) {
  147927. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147928. if (*htblptr == NULL)
  147929. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147930. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147931. did_ac[actbl] = TRUE;
  147932. }
  147933. }
  147934. }
  147935. #endif /* ENTROPY_OPT_SUPPORTED */
  147936. GLOBAL(void)
  147937. jinit_huff_encoder (j_compress_ptr cinfo)
  147938. {
  147939. huff_entropy_ptr entropy;
  147940. int i;
  147941. entropy = (huff_entropy_ptr)
  147942. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147943. SIZEOF(huff_entropy_encoder));
  147944. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147945. entropy->pub.start_pass = start_pass_huff;
  147946. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147947. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147948. #ifdef ENTROPY_OPT_SUPPORTED
  147949. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147950. #endif
  147951. }
  147952. }
  147953. /*** End of inlined file: jchuff.c ***/
  147954. #undef emit_byte
  147955. /*** Start of inlined file: jcinit.c ***/
  147956. #define JPEG_INTERNALS
  147957. GLOBAL(void)
  147958. jinit_compress_master (j_compress_ptr cinfo)
  147959. {
  147960. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147961. if (! cinfo->raw_data_in) {
  147962. jinit_color_converter(cinfo);
  147963. jinit_downsampler(cinfo);
  147964. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147965. }
  147966. jinit_forward_dct(cinfo);
  147967. if (cinfo->arith_code) {
  147968. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147969. } else {
  147970. if (cinfo->progressive_mode) {
  147971. #ifdef C_PROGRESSIVE_SUPPORTED
  147972. jinit_phuff_encoder(cinfo);
  147973. #else
  147974. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147975. #endif
  147976. } else
  147977. jinit_huff_encoder(cinfo);
  147978. }
  147979. jinit_c_coef_controller(cinfo,
  147980. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147981. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147982. jinit_marker_writer(cinfo);
  147983. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147984. (*cinfo->marker->write_file_header) (cinfo);
  147985. }
  147986. /*** End of inlined file: jcinit.c ***/
  147987. /*** Start of inlined file: jcmainct.c ***/
  147988. #define JPEG_INTERNALS
  147989. #undef FULL_MAIN_BUFFER_SUPPORTED
  147990. typedef struct {
  147991. struct jpeg_c_main_controller pub; /* public fields */
  147992. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147993. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147994. boolean suspended; /* remember if we suspended output */
  147995. J_BUF_MODE pass_mode; /* current operating mode */
  147996. JSAMPARRAY buffer[MAX_COMPONENTS];
  147997. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147998. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147999. #endif
  148000. } my_main_controller;
  148001. typedef my_main_controller * my_main_ptr;
  148002. METHODDEF(void) process_data_simple_main
  148003. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148004. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148005. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148006. METHODDEF(void) process_data_buffer_main
  148007. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148008. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148009. #endif
  148010. METHODDEF(void)
  148011. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  148012. {
  148013. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148014. if (cinfo->raw_data_in)
  148015. return;
  148016. main_->cur_iMCU_row = 0; /* initialize counters */
  148017. main_->rowgroup_ctr = 0;
  148018. main_->suspended = FALSE;
  148019. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  148020. switch (pass_mode) {
  148021. case JBUF_PASS_THRU:
  148022. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148023. if (main_->whole_image[0] != NULL)
  148024. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148025. #endif
  148026. main_->pub.process_data = process_data_simple_main;
  148027. break;
  148028. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148029. case JBUF_SAVE_SOURCE:
  148030. case JBUF_CRANK_DEST:
  148031. case JBUF_SAVE_AND_PASS:
  148032. if (main_->whole_image[0] == NULL)
  148033. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148034. main_->pub.process_data = process_data_buffer_main;
  148035. break;
  148036. #endif
  148037. default:
  148038. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148039. break;
  148040. }
  148041. }
  148042. METHODDEF(void)
  148043. process_data_simple_main (j_compress_ptr cinfo,
  148044. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148045. JDIMENSION in_rows_avail)
  148046. {
  148047. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148048. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148049. if (main_->rowgroup_ctr < DCTSIZE)
  148050. (*cinfo->prep->pre_process_data) (cinfo,
  148051. input_buf, in_row_ctr, in_rows_avail,
  148052. main_->buffer, &main_->rowgroup_ctr,
  148053. (JDIMENSION) DCTSIZE);
  148054. if (main_->rowgroup_ctr != DCTSIZE)
  148055. return;
  148056. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  148057. if (! main_->suspended) {
  148058. (*in_row_ctr)--;
  148059. main_->suspended = TRUE;
  148060. }
  148061. return;
  148062. }
  148063. if (main_->suspended) {
  148064. (*in_row_ctr)++;
  148065. main_->suspended = FALSE;
  148066. }
  148067. main_->rowgroup_ctr = 0;
  148068. main_->cur_iMCU_row++;
  148069. }
  148070. }
  148071. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148072. METHODDEF(void)
  148073. process_data_buffer_main (j_compress_ptr cinfo,
  148074. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148075. JDIMENSION in_rows_avail)
  148076. {
  148077. my_main_ptr main = (my_main_ptr) cinfo->main;
  148078. int ci;
  148079. jpeg_component_info *compptr;
  148080. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  148081. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148082. if (main->rowgroup_ctr == 0) {
  148083. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148084. ci++, compptr++) {
  148085. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  148086. ((j_common_ptr) cinfo, main->whole_image[ci],
  148087. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  148088. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  148089. }
  148090. if (! writing) {
  148091. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  148092. main->rowgroup_ctr = DCTSIZE;
  148093. }
  148094. }
  148095. if (writing) {
  148096. (*cinfo->prep->pre_process_data) (cinfo,
  148097. input_buf, in_row_ctr, in_rows_avail,
  148098. main->buffer, &main->rowgroup_ctr,
  148099. (JDIMENSION) DCTSIZE);
  148100. if (main->rowgroup_ctr < DCTSIZE)
  148101. return;
  148102. }
  148103. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148104. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148105. if (! main->suspended) {
  148106. (*in_row_ctr)--;
  148107. main->suspended = TRUE;
  148108. }
  148109. return;
  148110. }
  148111. if (main->suspended) {
  148112. (*in_row_ctr)++;
  148113. main->suspended = FALSE;
  148114. }
  148115. }
  148116. main->rowgroup_ctr = 0;
  148117. main->cur_iMCU_row++;
  148118. }
  148119. }
  148120. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148121. GLOBAL(void)
  148122. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148123. {
  148124. my_main_ptr main_;
  148125. int ci;
  148126. jpeg_component_info *compptr;
  148127. main_ = (my_main_ptr)
  148128. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148129. SIZEOF(my_main_controller));
  148130. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148131. main_->pub.start_pass = start_pass_main;
  148132. if (cinfo->raw_data_in)
  148133. return;
  148134. if (need_full_buffer) {
  148135. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148136. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148137. ci++, compptr++) {
  148138. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148139. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148140. compptr->width_in_blocks * DCTSIZE,
  148141. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148142. (long) compptr->v_samp_factor) * DCTSIZE,
  148143. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148144. }
  148145. #else
  148146. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148147. #endif
  148148. } else {
  148149. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148150. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148151. #endif
  148152. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148153. ci++, compptr++) {
  148154. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148155. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148156. compptr->width_in_blocks * DCTSIZE,
  148157. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148158. }
  148159. }
  148160. }
  148161. /*** End of inlined file: jcmainct.c ***/
  148162. /*** Start of inlined file: jcmarker.c ***/
  148163. #define JPEG_INTERNALS
  148164. typedef struct {
  148165. struct jpeg_marker_writer pub; /* public fields */
  148166. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148167. } my_marker_writer;
  148168. typedef my_marker_writer * my_marker_ptr;
  148169. LOCAL(void)
  148170. emit_byte (j_compress_ptr cinfo, int val)
  148171. {
  148172. struct jpeg_destination_mgr * dest = cinfo->dest;
  148173. *(dest->next_output_byte)++ = (JOCTET) val;
  148174. if (--dest->free_in_buffer == 0) {
  148175. if (! (*dest->empty_output_buffer) (cinfo))
  148176. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148177. }
  148178. }
  148179. LOCAL(void)
  148180. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148181. {
  148182. emit_byte(cinfo, 0xFF);
  148183. emit_byte(cinfo, (int) mark);
  148184. }
  148185. LOCAL(void)
  148186. emit_2bytes (j_compress_ptr cinfo, int value)
  148187. {
  148188. emit_byte(cinfo, (value >> 8) & 0xFF);
  148189. emit_byte(cinfo, value & 0xFF);
  148190. }
  148191. LOCAL(int)
  148192. emit_dqt (j_compress_ptr cinfo, int index)
  148193. {
  148194. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148195. int prec;
  148196. int i;
  148197. if (qtbl == NULL)
  148198. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148199. prec = 0;
  148200. for (i = 0; i < DCTSIZE2; i++) {
  148201. if (qtbl->quantval[i] > 255)
  148202. prec = 1;
  148203. }
  148204. if (! qtbl->sent_table) {
  148205. emit_marker(cinfo, M_DQT);
  148206. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148207. emit_byte(cinfo, index + (prec<<4));
  148208. for (i = 0; i < DCTSIZE2; i++) {
  148209. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148210. if (prec)
  148211. emit_byte(cinfo, (int) (qval >> 8));
  148212. emit_byte(cinfo, (int) (qval & 0xFF));
  148213. }
  148214. qtbl->sent_table = TRUE;
  148215. }
  148216. return prec;
  148217. }
  148218. LOCAL(void)
  148219. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148220. {
  148221. JHUFF_TBL * htbl;
  148222. int length, i;
  148223. if (is_ac) {
  148224. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148225. index += 0x10; /* output index has AC bit set */
  148226. } else {
  148227. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148228. }
  148229. if (htbl == NULL)
  148230. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148231. if (! htbl->sent_table) {
  148232. emit_marker(cinfo, M_DHT);
  148233. length = 0;
  148234. for (i = 1; i <= 16; i++)
  148235. length += htbl->bits[i];
  148236. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148237. emit_byte(cinfo, index);
  148238. for (i = 1; i <= 16; i++)
  148239. emit_byte(cinfo, htbl->bits[i]);
  148240. for (i = 0; i < length; i++)
  148241. emit_byte(cinfo, htbl->huffval[i]);
  148242. htbl->sent_table = TRUE;
  148243. }
  148244. }
  148245. LOCAL(void)
  148246. emit_dac (j_compress_ptr cinfo)
  148247. {
  148248. #ifdef C_ARITH_CODING_SUPPORTED
  148249. char dc_in_use[NUM_ARITH_TBLS];
  148250. char ac_in_use[NUM_ARITH_TBLS];
  148251. int length, i;
  148252. jpeg_component_info *compptr;
  148253. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148254. dc_in_use[i] = ac_in_use[i] = 0;
  148255. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148256. compptr = cinfo->cur_comp_info[i];
  148257. dc_in_use[compptr->dc_tbl_no] = 1;
  148258. ac_in_use[compptr->ac_tbl_no] = 1;
  148259. }
  148260. length = 0;
  148261. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148262. length += dc_in_use[i] + ac_in_use[i];
  148263. emit_marker(cinfo, M_DAC);
  148264. emit_2bytes(cinfo, length*2 + 2);
  148265. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148266. if (dc_in_use[i]) {
  148267. emit_byte(cinfo, i);
  148268. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148269. }
  148270. if (ac_in_use[i]) {
  148271. emit_byte(cinfo, i + 0x10);
  148272. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148273. }
  148274. }
  148275. #endif /* C_ARITH_CODING_SUPPORTED */
  148276. }
  148277. LOCAL(void)
  148278. emit_dri (j_compress_ptr cinfo)
  148279. {
  148280. emit_marker(cinfo, M_DRI);
  148281. emit_2bytes(cinfo, 4); /* fixed length */
  148282. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148283. }
  148284. LOCAL(void)
  148285. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148286. {
  148287. int ci;
  148288. jpeg_component_info *compptr;
  148289. emit_marker(cinfo, code);
  148290. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148291. if ((long) cinfo->image_height > 65535L ||
  148292. (long) cinfo->image_width > 65535L)
  148293. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148294. emit_byte(cinfo, cinfo->data_precision);
  148295. emit_2bytes(cinfo, (int) cinfo->image_height);
  148296. emit_2bytes(cinfo, (int) cinfo->image_width);
  148297. emit_byte(cinfo, cinfo->num_components);
  148298. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148299. ci++, compptr++) {
  148300. emit_byte(cinfo, compptr->component_id);
  148301. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148302. emit_byte(cinfo, compptr->quant_tbl_no);
  148303. }
  148304. }
  148305. LOCAL(void)
  148306. emit_sos (j_compress_ptr cinfo)
  148307. {
  148308. int i, td, ta;
  148309. jpeg_component_info *compptr;
  148310. emit_marker(cinfo, M_SOS);
  148311. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148312. emit_byte(cinfo, cinfo->comps_in_scan);
  148313. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148314. compptr = cinfo->cur_comp_info[i];
  148315. emit_byte(cinfo, compptr->component_id);
  148316. td = compptr->dc_tbl_no;
  148317. ta = compptr->ac_tbl_no;
  148318. if (cinfo->progressive_mode) {
  148319. if (cinfo->Ss == 0) {
  148320. ta = 0; /* DC scan */
  148321. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148322. td = 0; /* no DC table either */
  148323. } else {
  148324. td = 0; /* AC scan */
  148325. }
  148326. }
  148327. emit_byte(cinfo, (td << 4) + ta);
  148328. }
  148329. emit_byte(cinfo, cinfo->Ss);
  148330. emit_byte(cinfo, cinfo->Se);
  148331. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148332. }
  148333. LOCAL(void)
  148334. emit_jfif_app0 (j_compress_ptr cinfo)
  148335. {
  148336. emit_marker(cinfo, M_APP0);
  148337. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148338. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148339. emit_byte(cinfo, 0x46);
  148340. emit_byte(cinfo, 0x49);
  148341. emit_byte(cinfo, 0x46);
  148342. emit_byte(cinfo, 0);
  148343. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148344. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148345. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148346. emit_2bytes(cinfo, (int) cinfo->X_density);
  148347. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148348. emit_byte(cinfo, 0); /* No thumbnail image */
  148349. emit_byte(cinfo, 0);
  148350. }
  148351. LOCAL(void)
  148352. emit_adobe_app14 (j_compress_ptr cinfo)
  148353. {
  148354. emit_marker(cinfo, M_APP14);
  148355. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148356. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148357. emit_byte(cinfo, 0x64);
  148358. emit_byte(cinfo, 0x6F);
  148359. emit_byte(cinfo, 0x62);
  148360. emit_byte(cinfo, 0x65);
  148361. emit_2bytes(cinfo, 100); /* Version */
  148362. emit_2bytes(cinfo, 0); /* Flags0 */
  148363. emit_2bytes(cinfo, 0); /* Flags1 */
  148364. switch (cinfo->jpeg_color_space) {
  148365. case JCS_YCbCr:
  148366. emit_byte(cinfo, 1); /* Color transform = 1 */
  148367. break;
  148368. case JCS_YCCK:
  148369. emit_byte(cinfo, 2); /* Color transform = 2 */
  148370. break;
  148371. default:
  148372. emit_byte(cinfo, 0); /* Color transform = 0 */
  148373. break;
  148374. }
  148375. }
  148376. METHODDEF(void)
  148377. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148378. {
  148379. if (datalen > (unsigned int) 65533) /* safety check */
  148380. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148381. emit_marker(cinfo, (JPEG_MARKER) marker);
  148382. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148383. }
  148384. METHODDEF(void)
  148385. write_marker_byte (j_compress_ptr cinfo, int val)
  148386. {
  148387. emit_byte(cinfo, val);
  148388. }
  148389. METHODDEF(void)
  148390. write_file_header (j_compress_ptr cinfo)
  148391. {
  148392. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148393. emit_marker(cinfo, M_SOI); /* first the SOI */
  148394. marker->last_restart_interval = 0;
  148395. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148396. emit_jfif_app0(cinfo);
  148397. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148398. emit_adobe_app14(cinfo);
  148399. }
  148400. METHODDEF(void)
  148401. write_frame_header (j_compress_ptr cinfo)
  148402. {
  148403. int ci, prec;
  148404. boolean is_baseline;
  148405. jpeg_component_info *compptr;
  148406. prec = 0;
  148407. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148408. ci++, compptr++) {
  148409. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148410. }
  148411. if (cinfo->arith_code || cinfo->progressive_mode ||
  148412. cinfo->data_precision != 8) {
  148413. is_baseline = FALSE;
  148414. } else {
  148415. is_baseline = TRUE;
  148416. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148417. ci++, compptr++) {
  148418. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148419. is_baseline = FALSE;
  148420. }
  148421. if (prec && is_baseline) {
  148422. is_baseline = FALSE;
  148423. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148424. }
  148425. }
  148426. if (cinfo->arith_code) {
  148427. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148428. } else {
  148429. if (cinfo->progressive_mode)
  148430. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148431. else if (is_baseline)
  148432. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148433. else
  148434. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148435. }
  148436. }
  148437. METHODDEF(void)
  148438. write_scan_header (j_compress_ptr cinfo)
  148439. {
  148440. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148441. int i;
  148442. jpeg_component_info *compptr;
  148443. if (cinfo->arith_code) {
  148444. emit_dac(cinfo);
  148445. } else {
  148446. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148447. compptr = cinfo->cur_comp_info[i];
  148448. if (cinfo->progressive_mode) {
  148449. if (cinfo->Ss == 0) {
  148450. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148451. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148452. } else {
  148453. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148454. }
  148455. } else {
  148456. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148457. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148458. }
  148459. }
  148460. }
  148461. if (cinfo->restart_interval != marker->last_restart_interval) {
  148462. emit_dri(cinfo);
  148463. marker->last_restart_interval = cinfo->restart_interval;
  148464. }
  148465. emit_sos(cinfo);
  148466. }
  148467. METHODDEF(void)
  148468. write_file_trailer (j_compress_ptr cinfo)
  148469. {
  148470. emit_marker(cinfo, M_EOI);
  148471. }
  148472. METHODDEF(void)
  148473. write_tables_only (j_compress_ptr cinfo)
  148474. {
  148475. int i;
  148476. emit_marker(cinfo, M_SOI);
  148477. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148478. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148479. (void) emit_dqt(cinfo, i);
  148480. }
  148481. if (! cinfo->arith_code) {
  148482. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148483. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148484. emit_dht(cinfo, i, FALSE);
  148485. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148486. emit_dht(cinfo, i, TRUE);
  148487. }
  148488. }
  148489. emit_marker(cinfo, M_EOI);
  148490. }
  148491. GLOBAL(void)
  148492. jinit_marker_writer (j_compress_ptr cinfo)
  148493. {
  148494. my_marker_ptr marker;
  148495. marker = (my_marker_ptr)
  148496. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148497. SIZEOF(my_marker_writer));
  148498. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148499. marker->pub.write_file_header = write_file_header;
  148500. marker->pub.write_frame_header = write_frame_header;
  148501. marker->pub.write_scan_header = write_scan_header;
  148502. marker->pub.write_file_trailer = write_file_trailer;
  148503. marker->pub.write_tables_only = write_tables_only;
  148504. marker->pub.write_marker_header = write_marker_header;
  148505. marker->pub.write_marker_byte = write_marker_byte;
  148506. marker->last_restart_interval = 0;
  148507. }
  148508. /*** End of inlined file: jcmarker.c ***/
  148509. /*** Start of inlined file: jcmaster.c ***/
  148510. #define JPEG_INTERNALS
  148511. typedef enum {
  148512. main_pass, /* input data, also do first output step */
  148513. huff_opt_pass, /* Huffman code optimization pass */
  148514. output_pass /* data output pass */
  148515. } c_pass_type;
  148516. typedef struct {
  148517. struct jpeg_comp_master pub; /* public fields */
  148518. c_pass_type pass_type; /* the type of the current pass */
  148519. int pass_number; /* # of passes completed */
  148520. int total_passes; /* total # of passes needed */
  148521. int scan_number; /* current index in scan_info[] */
  148522. } my_comp_master;
  148523. typedef my_comp_master * my_master_ptr;
  148524. LOCAL(void)
  148525. initial_setup (j_compress_ptr cinfo)
  148526. {
  148527. int ci;
  148528. jpeg_component_info *compptr;
  148529. long samplesperrow;
  148530. JDIMENSION jd_samplesperrow;
  148531. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148532. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148533. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148534. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148535. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148536. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148537. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148538. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148539. if ((long) jd_samplesperrow != samplesperrow)
  148540. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148541. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148542. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148543. if (cinfo->num_components > MAX_COMPONENTS)
  148544. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148545. MAX_COMPONENTS);
  148546. cinfo->max_h_samp_factor = 1;
  148547. cinfo->max_v_samp_factor = 1;
  148548. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148549. ci++, compptr++) {
  148550. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148551. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148552. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148553. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148554. compptr->h_samp_factor);
  148555. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148556. compptr->v_samp_factor);
  148557. }
  148558. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148559. ci++, compptr++) {
  148560. compptr->component_index = ci;
  148561. compptr->DCT_scaled_size = DCTSIZE;
  148562. compptr->width_in_blocks = (JDIMENSION)
  148563. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148564. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148565. compptr->height_in_blocks = (JDIMENSION)
  148566. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148567. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148568. compptr->downsampled_width = (JDIMENSION)
  148569. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148570. (long) cinfo->max_h_samp_factor);
  148571. compptr->downsampled_height = (JDIMENSION)
  148572. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148573. (long) cinfo->max_v_samp_factor);
  148574. compptr->component_needed = TRUE;
  148575. }
  148576. cinfo->total_iMCU_rows = (JDIMENSION)
  148577. jdiv_round_up((long) cinfo->image_height,
  148578. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148579. }
  148580. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148581. LOCAL(void)
  148582. validate_script (j_compress_ptr cinfo)
  148583. {
  148584. const jpeg_scan_info * scanptr;
  148585. int scanno, ncomps, ci, coefi, thisi;
  148586. int Ss, Se, Ah, Al;
  148587. boolean component_sent[MAX_COMPONENTS];
  148588. #ifdef C_PROGRESSIVE_SUPPORTED
  148589. int * last_bitpos_ptr;
  148590. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148591. #endif
  148592. if (cinfo->num_scans <= 0)
  148593. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148594. scanptr = cinfo->scan_info;
  148595. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148596. #ifdef C_PROGRESSIVE_SUPPORTED
  148597. cinfo->progressive_mode = TRUE;
  148598. last_bitpos_ptr = & last_bitpos[0][0];
  148599. for (ci = 0; ci < cinfo->num_components; ci++)
  148600. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148601. *last_bitpos_ptr++ = -1;
  148602. #else
  148603. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148604. #endif
  148605. } else {
  148606. cinfo->progressive_mode = FALSE;
  148607. for (ci = 0; ci < cinfo->num_components; ci++)
  148608. component_sent[ci] = FALSE;
  148609. }
  148610. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148611. ncomps = scanptr->comps_in_scan;
  148612. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148613. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148614. for (ci = 0; ci < ncomps; ci++) {
  148615. thisi = scanptr->component_index[ci];
  148616. if (thisi < 0 || thisi >= cinfo->num_components)
  148617. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148618. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148619. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148620. }
  148621. Ss = scanptr->Ss;
  148622. Se = scanptr->Se;
  148623. Ah = scanptr->Ah;
  148624. Al = scanptr->Al;
  148625. if (cinfo->progressive_mode) {
  148626. #ifdef C_PROGRESSIVE_SUPPORTED
  148627. #if BITS_IN_JSAMPLE == 8
  148628. #define MAX_AH_AL 10
  148629. #else
  148630. #define MAX_AH_AL 13
  148631. #endif
  148632. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148633. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148634. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148635. if (Ss == 0) {
  148636. if (Se != 0) /* DC and AC together not OK */
  148637. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148638. } else {
  148639. if (ncomps != 1) /* AC scans must be for only one component */
  148640. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148641. }
  148642. for (ci = 0; ci < ncomps; ci++) {
  148643. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148644. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148645. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148646. for (coefi = Ss; coefi <= Se; coefi++) {
  148647. if (last_bitpos_ptr[coefi] < 0) {
  148648. if (Ah != 0)
  148649. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148650. } else {
  148651. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148652. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148653. }
  148654. last_bitpos_ptr[coefi] = Al;
  148655. }
  148656. }
  148657. #endif
  148658. } else {
  148659. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148660. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148661. for (ci = 0; ci < ncomps; ci++) {
  148662. thisi = scanptr->component_index[ci];
  148663. if (component_sent[thisi])
  148664. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148665. component_sent[thisi] = TRUE;
  148666. }
  148667. }
  148668. }
  148669. if (cinfo->progressive_mode) {
  148670. #ifdef C_PROGRESSIVE_SUPPORTED
  148671. for (ci = 0; ci < cinfo->num_components; ci++) {
  148672. if (last_bitpos[ci][0] < 0)
  148673. ERREXIT(cinfo, JERR_MISSING_DATA);
  148674. }
  148675. #endif
  148676. } else {
  148677. for (ci = 0; ci < cinfo->num_components; ci++) {
  148678. if (! component_sent[ci])
  148679. ERREXIT(cinfo, JERR_MISSING_DATA);
  148680. }
  148681. }
  148682. }
  148683. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148684. LOCAL(void)
  148685. select_scan_parameters (j_compress_ptr cinfo)
  148686. {
  148687. int ci;
  148688. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148689. if (cinfo->scan_info != NULL) {
  148690. my_master_ptr master = (my_master_ptr) cinfo->master;
  148691. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148692. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148693. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148694. cinfo->cur_comp_info[ci] =
  148695. &cinfo->comp_info[scanptr->component_index[ci]];
  148696. }
  148697. cinfo->Ss = scanptr->Ss;
  148698. cinfo->Se = scanptr->Se;
  148699. cinfo->Ah = scanptr->Ah;
  148700. cinfo->Al = scanptr->Al;
  148701. }
  148702. else
  148703. #endif
  148704. {
  148705. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148706. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148707. MAX_COMPS_IN_SCAN);
  148708. cinfo->comps_in_scan = cinfo->num_components;
  148709. for (ci = 0; ci < cinfo->num_components; ci++) {
  148710. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148711. }
  148712. cinfo->Ss = 0;
  148713. cinfo->Se = DCTSIZE2-1;
  148714. cinfo->Ah = 0;
  148715. cinfo->Al = 0;
  148716. }
  148717. }
  148718. LOCAL(void)
  148719. per_scan_setup (j_compress_ptr cinfo)
  148720. {
  148721. int ci, mcublks, tmp;
  148722. jpeg_component_info *compptr;
  148723. if (cinfo->comps_in_scan == 1) {
  148724. compptr = cinfo->cur_comp_info[0];
  148725. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148726. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148727. compptr->MCU_width = 1;
  148728. compptr->MCU_height = 1;
  148729. compptr->MCU_blocks = 1;
  148730. compptr->MCU_sample_width = DCTSIZE;
  148731. compptr->last_col_width = 1;
  148732. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148733. if (tmp == 0) tmp = compptr->v_samp_factor;
  148734. compptr->last_row_height = tmp;
  148735. cinfo->blocks_in_MCU = 1;
  148736. cinfo->MCU_membership[0] = 0;
  148737. } else {
  148738. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148739. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148740. MAX_COMPS_IN_SCAN);
  148741. cinfo->MCUs_per_row = (JDIMENSION)
  148742. jdiv_round_up((long) cinfo->image_width,
  148743. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148744. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148745. jdiv_round_up((long) cinfo->image_height,
  148746. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148747. cinfo->blocks_in_MCU = 0;
  148748. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148749. compptr = cinfo->cur_comp_info[ci];
  148750. compptr->MCU_width = compptr->h_samp_factor;
  148751. compptr->MCU_height = compptr->v_samp_factor;
  148752. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148753. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148754. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148755. if (tmp == 0) tmp = compptr->MCU_width;
  148756. compptr->last_col_width = tmp;
  148757. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148758. if (tmp == 0) tmp = compptr->MCU_height;
  148759. compptr->last_row_height = tmp;
  148760. mcublks = compptr->MCU_blocks;
  148761. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148762. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148763. while (mcublks-- > 0) {
  148764. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148765. }
  148766. }
  148767. }
  148768. if (cinfo->restart_in_rows > 0) {
  148769. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148770. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148771. }
  148772. }
  148773. METHODDEF(void)
  148774. prepare_for_pass (j_compress_ptr cinfo)
  148775. {
  148776. my_master_ptr master = (my_master_ptr) cinfo->master;
  148777. switch (master->pass_type) {
  148778. case main_pass:
  148779. select_scan_parameters(cinfo);
  148780. per_scan_setup(cinfo);
  148781. if (! cinfo->raw_data_in) {
  148782. (*cinfo->cconvert->start_pass) (cinfo);
  148783. (*cinfo->downsample->start_pass) (cinfo);
  148784. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148785. }
  148786. (*cinfo->fdct->start_pass) (cinfo);
  148787. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148788. (*cinfo->coef->start_pass) (cinfo,
  148789. (master->total_passes > 1 ?
  148790. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148791. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148792. if (cinfo->optimize_coding) {
  148793. master->pub.call_pass_startup = FALSE;
  148794. } else {
  148795. master->pub.call_pass_startup = TRUE;
  148796. }
  148797. break;
  148798. #ifdef ENTROPY_OPT_SUPPORTED
  148799. case huff_opt_pass:
  148800. select_scan_parameters(cinfo);
  148801. per_scan_setup(cinfo);
  148802. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148803. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148804. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148805. master->pub.call_pass_startup = FALSE;
  148806. break;
  148807. }
  148808. master->pass_type = output_pass;
  148809. master->pass_number++;
  148810. #endif
  148811. case output_pass:
  148812. if (! cinfo->optimize_coding) {
  148813. select_scan_parameters(cinfo);
  148814. per_scan_setup(cinfo);
  148815. }
  148816. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148817. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148818. if (master->scan_number == 0)
  148819. (*cinfo->marker->write_frame_header) (cinfo);
  148820. (*cinfo->marker->write_scan_header) (cinfo);
  148821. master->pub.call_pass_startup = FALSE;
  148822. break;
  148823. default:
  148824. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148825. }
  148826. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148827. if (cinfo->progress != NULL) {
  148828. cinfo->progress->completed_passes = master->pass_number;
  148829. cinfo->progress->total_passes = master->total_passes;
  148830. }
  148831. }
  148832. METHODDEF(void)
  148833. pass_startup (j_compress_ptr cinfo)
  148834. {
  148835. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148836. (*cinfo->marker->write_frame_header) (cinfo);
  148837. (*cinfo->marker->write_scan_header) (cinfo);
  148838. }
  148839. METHODDEF(void)
  148840. finish_pass_master (j_compress_ptr cinfo)
  148841. {
  148842. my_master_ptr master = (my_master_ptr) cinfo->master;
  148843. (*cinfo->entropy->finish_pass) (cinfo);
  148844. switch (master->pass_type) {
  148845. case main_pass:
  148846. master->pass_type = output_pass;
  148847. if (! cinfo->optimize_coding)
  148848. master->scan_number++;
  148849. break;
  148850. case huff_opt_pass:
  148851. master->pass_type = output_pass;
  148852. break;
  148853. case output_pass:
  148854. if (cinfo->optimize_coding)
  148855. master->pass_type = huff_opt_pass;
  148856. master->scan_number++;
  148857. break;
  148858. }
  148859. master->pass_number++;
  148860. }
  148861. GLOBAL(void)
  148862. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148863. {
  148864. my_master_ptr master;
  148865. master = (my_master_ptr)
  148866. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148867. SIZEOF(my_comp_master));
  148868. cinfo->master = (struct jpeg_comp_master *) master;
  148869. master->pub.prepare_for_pass = prepare_for_pass;
  148870. master->pub.pass_startup = pass_startup;
  148871. master->pub.finish_pass = finish_pass_master;
  148872. master->pub.is_last_pass = FALSE;
  148873. initial_setup(cinfo);
  148874. if (cinfo->scan_info != NULL) {
  148875. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148876. validate_script(cinfo);
  148877. #else
  148878. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148879. #endif
  148880. } else {
  148881. cinfo->progressive_mode = FALSE;
  148882. cinfo->num_scans = 1;
  148883. }
  148884. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148885. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148886. if (transcode_only) {
  148887. if (cinfo->optimize_coding)
  148888. master->pass_type = huff_opt_pass;
  148889. else
  148890. master->pass_type = output_pass;
  148891. } else {
  148892. master->pass_type = main_pass;
  148893. }
  148894. master->scan_number = 0;
  148895. master->pass_number = 0;
  148896. if (cinfo->optimize_coding)
  148897. master->total_passes = cinfo->num_scans * 2;
  148898. else
  148899. master->total_passes = cinfo->num_scans;
  148900. }
  148901. /*** End of inlined file: jcmaster.c ***/
  148902. /*** Start of inlined file: jcomapi.c ***/
  148903. #define JPEG_INTERNALS
  148904. GLOBAL(void)
  148905. jpeg_abort (j_common_ptr cinfo)
  148906. {
  148907. int pool;
  148908. if (cinfo->mem == NULL)
  148909. return;
  148910. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148911. (*cinfo->mem->free_pool) (cinfo, pool);
  148912. }
  148913. if (cinfo->is_decompressor) {
  148914. cinfo->global_state = DSTATE_START;
  148915. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148916. } else {
  148917. cinfo->global_state = CSTATE_START;
  148918. }
  148919. }
  148920. GLOBAL(void)
  148921. jpeg_destroy (j_common_ptr cinfo)
  148922. {
  148923. if (cinfo->mem != NULL)
  148924. (*cinfo->mem->self_destruct) (cinfo);
  148925. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148926. cinfo->global_state = 0; /* mark it destroyed */
  148927. }
  148928. GLOBAL(JQUANT_TBL *)
  148929. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148930. {
  148931. JQUANT_TBL *tbl;
  148932. tbl = (JQUANT_TBL *)
  148933. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148934. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148935. return tbl;
  148936. }
  148937. GLOBAL(JHUFF_TBL *)
  148938. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148939. {
  148940. JHUFF_TBL *tbl;
  148941. tbl = (JHUFF_TBL *)
  148942. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148943. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148944. return tbl;
  148945. }
  148946. /*** End of inlined file: jcomapi.c ***/
  148947. /*** Start of inlined file: jcparam.c ***/
  148948. #define JPEG_INTERNALS
  148949. GLOBAL(void)
  148950. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148951. const unsigned int *basic_table,
  148952. int scale_factor, boolean force_baseline)
  148953. {
  148954. JQUANT_TBL ** qtblptr;
  148955. int i;
  148956. long temp;
  148957. if (cinfo->global_state != CSTATE_START)
  148958. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148959. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148960. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148961. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148962. if (*qtblptr == NULL)
  148963. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148964. for (i = 0; i < DCTSIZE2; i++) {
  148965. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148966. if (temp <= 0L) temp = 1L;
  148967. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148968. if (force_baseline && temp > 255L)
  148969. temp = 255L; /* limit to baseline range if requested */
  148970. (*qtblptr)->quantval[i] = (UINT16) temp;
  148971. }
  148972. (*qtblptr)->sent_table = FALSE;
  148973. }
  148974. GLOBAL(void)
  148975. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148976. boolean force_baseline)
  148977. {
  148978. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148979. 16, 11, 10, 16, 24, 40, 51, 61,
  148980. 12, 12, 14, 19, 26, 58, 60, 55,
  148981. 14, 13, 16, 24, 40, 57, 69, 56,
  148982. 14, 17, 22, 29, 51, 87, 80, 62,
  148983. 18, 22, 37, 56, 68, 109, 103, 77,
  148984. 24, 35, 55, 64, 81, 104, 113, 92,
  148985. 49, 64, 78, 87, 103, 121, 120, 101,
  148986. 72, 92, 95, 98, 112, 100, 103, 99
  148987. };
  148988. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148989. 17, 18, 24, 47, 99, 99, 99, 99,
  148990. 18, 21, 26, 66, 99, 99, 99, 99,
  148991. 24, 26, 56, 99, 99, 99, 99, 99,
  148992. 47, 66, 99, 99, 99, 99, 99, 99,
  148993. 99, 99, 99, 99, 99, 99, 99, 99,
  148994. 99, 99, 99, 99, 99, 99, 99, 99,
  148995. 99, 99, 99, 99, 99, 99, 99, 99,
  148996. 99, 99, 99, 99, 99, 99, 99, 99
  148997. };
  148998. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148999. scale_factor, force_baseline);
  149000. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  149001. scale_factor, force_baseline);
  149002. }
  149003. GLOBAL(int)
  149004. jpeg_quality_scaling (int quality)
  149005. {
  149006. if (quality <= 0) quality = 1;
  149007. if (quality > 100) quality = 100;
  149008. if (quality < 50)
  149009. quality = 5000 / quality;
  149010. else
  149011. quality = 200 - quality*2;
  149012. return quality;
  149013. }
  149014. GLOBAL(void)
  149015. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  149016. {
  149017. quality = jpeg_quality_scaling(quality);
  149018. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  149019. }
  149020. LOCAL(void)
  149021. add_huff_table (j_compress_ptr cinfo,
  149022. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  149023. {
  149024. int nsymbols, len;
  149025. if (*htblptr == NULL)
  149026. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149027. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  149028. nsymbols = 0;
  149029. for (len = 1; len <= 16; len++)
  149030. nsymbols += bits[len];
  149031. if (nsymbols < 1 || nsymbols > 256)
  149032. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  149033. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  149034. (*htblptr)->sent_table = FALSE;
  149035. }
  149036. LOCAL(void)
  149037. std_huff_tables (j_compress_ptr cinfo)
  149038. {
  149039. static const UINT8 bits_dc_luminance[17] =
  149040. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  149041. static const UINT8 val_dc_luminance[] =
  149042. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149043. static const UINT8 bits_dc_chrominance[17] =
  149044. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  149045. static const UINT8 val_dc_chrominance[] =
  149046. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149047. static const UINT8 bits_ac_luminance[17] =
  149048. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  149049. static const UINT8 val_ac_luminance[] =
  149050. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  149051. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  149052. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  149053. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  149054. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  149055. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  149056. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  149057. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  149058. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  149059. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  149060. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  149061. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  149062. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  149063. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  149064. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  149065. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  149066. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  149067. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  149068. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  149069. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149070. 0xf9, 0xfa };
  149071. static const UINT8 bits_ac_chrominance[17] =
  149072. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  149073. static const UINT8 val_ac_chrominance[] =
  149074. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  149075. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  149076. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  149077. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  149078. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  149079. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  149080. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  149081. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  149082. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  149083. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  149084. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  149085. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  149086. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  149087. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  149088. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  149089. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  149090. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  149091. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  149092. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  149093. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149094. 0xf9, 0xfa };
  149095. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  149096. bits_dc_luminance, val_dc_luminance);
  149097. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149098. bits_ac_luminance, val_ac_luminance);
  149099. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149100. bits_dc_chrominance, val_dc_chrominance);
  149101. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149102. bits_ac_chrominance, val_ac_chrominance);
  149103. }
  149104. GLOBAL(void)
  149105. jpeg_set_defaults (j_compress_ptr cinfo)
  149106. {
  149107. int i;
  149108. if (cinfo->global_state != CSTATE_START)
  149109. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149110. if (cinfo->comp_info == NULL)
  149111. cinfo->comp_info = (jpeg_component_info *)
  149112. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149113. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149114. cinfo->data_precision = BITS_IN_JSAMPLE;
  149115. jpeg_set_quality(cinfo, 75, TRUE);
  149116. std_huff_tables(cinfo);
  149117. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149118. cinfo->arith_dc_L[i] = 0;
  149119. cinfo->arith_dc_U[i] = 1;
  149120. cinfo->arith_ac_K[i] = 5;
  149121. }
  149122. cinfo->scan_info = NULL;
  149123. cinfo->num_scans = 0;
  149124. cinfo->raw_data_in = FALSE;
  149125. cinfo->arith_code = FALSE;
  149126. cinfo->optimize_coding = FALSE;
  149127. if (cinfo->data_precision > 8)
  149128. cinfo->optimize_coding = TRUE;
  149129. cinfo->CCIR601_sampling = FALSE;
  149130. cinfo->smoothing_factor = 0;
  149131. cinfo->dct_method = JDCT_DEFAULT;
  149132. cinfo->restart_interval = 0;
  149133. cinfo->restart_in_rows = 0;
  149134. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149135. cinfo->JFIF_minor_version = 1;
  149136. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149137. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149138. cinfo->Y_density = 1;
  149139. jpeg_default_colorspace(cinfo);
  149140. }
  149141. GLOBAL(void)
  149142. jpeg_default_colorspace (j_compress_ptr cinfo)
  149143. {
  149144. switch (cinfo->in_color_space) {
  149145. case JCS_GRAYSCALE:
  149146. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149147. break;
  149148. case JCS_RGB:
  149149. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149150. break;
  149151. case JCS_YCbCr:
  149152. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149153. break;
  149154. case JCS_CMYK:
  149155. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149156. break;
  149157. case JCS_YCCK:
  149158. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149159. break;
  149160. case JCS_UNKNOWN:
  149161. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149162. break;
  149163. default:
  149164. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149165. }
  149166. }
  149167. GLOBAL(void)
  149168. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149169. {
  149170. jpeg_component_info * compptr;
  149171. int ci;
  149172. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149173. (compptr = &cinfo->comp_info[index], \
  149174. compptr->component_id = (id), \
  149175. compptr->h_samp_factor = (hsamp), \
  149176. compptr->v_samp_factor = (vsamp), \
  149177. compptr->quant_tbl_no = (quant), \
  149178. compptr->dc_tbl_no = (dctbl), \
  149179. compptr->ac_tbl_no = (actbl) )
  149180. if (cinfo->global_state != CSTATE_START)
  149181. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149182. cinfo->jpeg_color_space = colorspace;
  149183. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149184. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149185. switch (colorspace) {
  149186. case JCS_GRAYSCALE:
  149187. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149188. cinfo->num_components = 1;
  149189. SET_COMP(0, 1, 1,1, 0, 0,0);
  149190. break;
  149191. case JCS_RGB:
  149192. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149193. cinfo->num_components = 3;
  149194. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149195. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149196. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149197. break;
  149198. case JCS_YCbCr:
  149199. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149200. cinfo->num_components = 3;
  149201. SET_COMP(0, 1, 2,2, 0, 0,0);
  149202. SET_COMP(1, 2, 1,1, 1, 1,1);
  149203. SET_COMP(2, 3, 1,1, 1, 1,1);
  149204. break;
  149205. case JCS_CMYK:
  149206. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149207. cinfo->num_components = 4;
  149208. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149209. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149210. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149211. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149212. break;
  149213. case JCS_YCCK:
  149214. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149215. cinfo->num_components = 4;
  149216. SET_COMP(0, 1, 2,2, 0, 0,0);
  149217. SET_COMP(1, 2, 1,1, 1, 1,1);
  149218. SET_COMP(2, 3, 1,1, 1, 1,1);
  149219. SET_COMP(3, 4, 2,2, 0, 0,0);
  149220. break;
  149221. case JCS_UNKNOWN:
  149222. cinfo->num_components = cinfo->input_components;
  149223. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149224. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149225. MAX_COMPONENTS);
  149226. for (ci = 0; ci < cinfo->num_components; ci++) {
  149227. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149228. }
  149229. break;
  149230. default:
  149231. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149232. }
  149233. }
  149234. #ifdef C_PROGRESSIVE_SUPPORTED
  149235. LOCAL(jpeg_scan_info *)
  149236. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149237. int Ss, int Se, int Ah, int Al)
  149238. {
  149239. scanptr->comps_in_scan = 1;
  149240. scanptr->component_index[0] = ci;
  149241. scanptr->Ss = Ss;
  149242. scanptr->Se = Se;
  149243. scanptr->Ah = Ah;
  149244. scanptr->Al = Al;
  149245. scanptr++;
  149246. return scanptr;
  149247. }
  149248. LOCAL(jpeg_scan_info *)
  149249. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149250. int Ss, int Se, int Ah, int Al)
  149251. {
  149252. int ci;
  149253. for (ci = 0; ci < ncomps; ci++) {
  149254. scanptr->comps_in_scan = 1;
  149255. scanptr->component_index[0] = ci;
  149256. scanptr->Ss = Ss;
  149257. scanptr->Se = Se;
  149258. scanptr->Ah = Ah;
  149259. scanptr->Al = Al;
  149260. scanptr++;
  149261. }
  149262. return scanptr;
  149263. }
  149264. LOCAL(jpeg_scan_info *)
  149265. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149266. {
  149267. int ci;
  149268. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149269. scanptr->comps_in_scan = ncomps;
  149270. for (ci = 0; ci < ncomps; ci++)
  149271. scanptr->component_index[ci] = ci;
  149272. scanptr->Ss = scanptr->Se = 0;
  149273. scanptr->Ah = Ah;
  149274. scanptr->Al = Al;
  149275. scanptr++;
  149276. } else {
  149277. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149278. }
  149279. return scanptr;
  149280. }
  149281. GLOBAL(void)
  149282. jpeg_simple_progression (j_compress_ptr cinfo)
  149283. {
  149284. int ncomps = cinfo->num_components;
  149285. int nscans;
  149286. jpeg_scan_info * scanptr;
  149287. if (cinfo->global_state != CSTATE_START)
  149288. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149289. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149290. nscans = 10;
  149291. } else {
  149292. if (ncomps > MAX_COMPS_IN_SCAN)
  149293. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149294. else
  149295. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149296. }
  149297. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149298. cinfo->script_space_size = MAX(nscans, 10);
  149299. cinfo->script_space = (jpeg_scan_info *)
  149300. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149301. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149302. }
  149303. scanptr = cinfo->script_space;
  149304. cinfo->scan_info = scanptr;
  149305. cinfo->num_scans = nscans;
  149306. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149307. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149308. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149309. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149310. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149311. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149312. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149313. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149314. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149315. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149316. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149317. } else {
  149318. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149319. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149320. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149321. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149322. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149323. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149324. }
  149325. }
  149326. #endif /* C_PROGRESSIVE_SUPPORTED */
  149327. /*** End of inlined file: jcparam.c ***/
  149328. /*** Start of inlined file: jcphuff.c ***/
  149329. #define JPEG_INTERNALS
  149330. #ifdef C_PROGRESSIVE_SUPPORTED
  149331. typedef struct {
  149332. struct jpeg_entropy_encoder pub; /* public fields */
  149333. boolean gather_statistics;
  149334. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149335. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149336. INT32 put_buffer; /* current bit-accumulation buffer */
  149337. int put_bits; /* # of bits now in it */
  149338. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149339. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149340. int ac_tbl_no; /* the table number of the single component */
  149341. unsigned int EOBRUN; /* run length of EOBs */
  149342. unsigned int BE; /* # of buffered correction bits before MCU */
  149343. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149344. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149345. int next_restart_num; /* next restart number to write (0-7) */
  149346. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149347. long * count_ptrs[NUM_HUFF_TBLS];
  149348. } phuff_entropy_encoder;
  149349. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149350. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149351. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149352. #define ISHIFT_TEMPS int ishift_temp;
  149353. #define IRIGHT_SHIFT(x,shft) \
  149354. ((ishift_temp = (x)) < 0 ? \
  149355. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149356. (ishift_temp >> (shft)))
  149357. #else
  149358. #define ISHIFT_TEMPS
  149359. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149360. #endif
  149361. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149362. JBLOCKROW *MCU_data));
  149363. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149364. JBLOCKROW *MCU_data));
  149365. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149366. JBLOCKROW *MCU_data));
  149367. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149368. JBLOCKROW *MCU_data));
  149369. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149370. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149371. METHODDEF(void)
  149372. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149373. {
  149374. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149375. boolean is_DC_band;
  149376. int ci, tbl;
  149377. jpeg_component_info * compptr;
  149378. entropy->cinfo = cinfo;
  149379. entropy->gather_statistics = gather_statistics;
  149380. is_DC_band = (cinfo->Ss == 0);
  149381. if (cinfo->Ah == 0) {
  149382. if (is_DC_band)
  149383. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149384. else
  149385. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149386. } else {
  149387. if (is_DC_band)
  149388. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149389. else {
  149390. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149391. if (entropy->bit_buffer == NULL)
  149392. entropy->bit_buffer = (char *)
  149393. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149394. MAX_CORR_BITS * SIZEOF(char));
  149395. }
  149396. }
  149397. if (gather_statistics)
  149398. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149399. else
  149400. entropy->pub.finish_pass = finish_pass_phuff;
  149401. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149402. compptr = cinfo->cur_comp_info[ci];
  149403. entropy->last_dc_val[ci] = 0;
  149404. if (is_DC_band) {
  149405. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149406. continue;
  149407. tbl = compptr->dc_tbl_no;
  149408. } else {
  149409. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149410. }
  149411. if (gather_statistics) {
  149412. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149413. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149414. if (entropy->count_ptrs[tbl] == NULL)
  149415. entropy->count_ptrs[tbl] = (long *)
  149416. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149417. 257 * SIZEOF(long));
  149418. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149419. } else {
  149420. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149421. & entropy->derived_tbls[tbl]);
  149422. }
  149423. }
  149424. entropy->EOBRUN = 0;
  149425. entropy->BE = 0;
  149426. entropy->put_buffer = 0;
  149427. entropy->put_bits = 0;
  149428. entropy->restarts_to_go = cinfo->restart_interval;
  149429. entropy->next_restart_num = 0;
  149430. }
  149431. #define emit_byte(entropy,val) \
  149432. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149433. if (--(entropy)->free_in_buffer == 0) \
  149434. dump_buffer_p(entropy); }
  149435. LOCAL(void)
  149436. dump_buffer_p (phuff_entropy_ptr entropy)
  149437. {
  149438. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149439. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149440. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149441. entropy->next_output_byte = dest->next_output_byte;
  149442. entropy->free_in_buffer = dest->free_in_buffer;
  149443. }
  149444. INLINE
  149445. LOCAL(void)
  149446. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149447. {
  149448. register INT32 put_buffer = (INT32) code;
  149449. register int put_bits = entropy->put_bits;
  149450. if (size == 0)
  149451. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149452. if (entropy->gather_statistics)
  149453. return; /* do nothing if we're only getting stats */
  149454. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149455. put_bits += size; /* new number of bits in buffer */
  149456. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149457. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149458. while (put_bits >= 8) {
  149459. int c = (int) ((put_buffer >> 16) & 0xFF);
  149460. emit_byte(entropy, c);
  149461. if (c == 0xFF) { /* need to stuff a zero byte? */
  149462. emit_byte(entropy, 0);
  149463. }
  149464. put_buffer <<= 8;
  149465. put_bits -= 8;
  149466. }
  149467. entropy->put_buffer = put_buffer; /* update variables */
  149468. entropy->put_bits = put_bits;
  149469. }
  149470. LOCAL(void)
  149471. flush_bits_p (phuff_entropy_ptr entropy)
  149472. {
  149473. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149474. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149475. entropy->put_bits = 0;
  149476. }
  149477. INLINE
  149478. LOCAL(void)
  149479. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149480. {
  149481. if (entropy->gather_statistics)
  149482. entropy->count_ptrs[tbl_no][symbol]++;
  149483. else {
  149484. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149485. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149486. }
  149487. }
  149488. LOCAL(void)
  149489. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149490. unsigned int nbits)
  149491. {
  149492. if (entropy->gather_statistics)
  149493. return; /* no real work */
  149494. while (nbits > 0) {
  149495. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149496. bufstart++;
  149497. nbits--;
  149498. }
  149499. }
  149500. LOCAL(void)
  149501. emit_eobrun (phuff_entropy_ptr entropy)
  149502. {
  149503. register int temp, nbits;
  149504. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149505. temp = entropy->EOBRUN;
  149506. nbits = 0;
  149507. while ((temp >>= 1))
  149508. nbits++;
  149509. if (nbits > 14)
  149510. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149511. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149512. if (nbits)
  149513. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149514. entropy->EOBRUN = 0;
  149515. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149516. entropy->BE = 0;
  149517. }
  149518. }
  149519. LOCAL(void)
  149520. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149521. {
  149522. int ci;
  149523. emit_eobrun(entropy);
  149524. if (! entropy->gather_statistics) {
  149525. flush_bits_p(entropy);
  149526. emit_byte(entropy, 0xFF);
  149527. emit_byte(entropy, JPEG_RST0 + restart_num);
  149528. }
  149529. if (entropy->cinfo->Ss == 0) {
  149530. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149531. entropy->last_dc_val[ci] = 0;
  149532. } else {
  149533. entropy->EOBRUN = 0;
  149534. entropy->BE = 0;
  149535. }
  149536. }
  149537. METHODDEF(boolean)
  149538. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149539. {
  149540. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149541. register int temp, temp2;
  149542. register int nbits;
  149543. int blkn, ci;
  149544. int Al = cinfo->Al;
  149545. JBLOCKROW block;
  149546. jpeg_component_info * compptr;
  149547. ISHIFT_TEMPS
  149548. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149549. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149550. if (cinfo->restart_interval)
  149551. if (entropy->restarts_to_go == 0)
  149552. emit_restart_p(entropy, entropy->next_restart_num);
  149553. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149554. block = MCU_data[blkn];
  149555. ci = cinfo->MCU_membership[blkn];
  149556. compptr = cinfo->cur_comp_info[ci];
  149557. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149558. temp = temp2 - entropy->last_dc_val[ci];
  149559. entropy->last_dc_val[ci] = temp2;
  149560. temp2 = temp;
  149561. if (temp < 0) {
  149562. temp = -temp; /* temp is abs value of input */
  149563. temp2--;
  149564. }
  149565. nbits = 0;
  149566. while (temp) {
  149567. nbits++;
  149568. temp >>= 1;
  149569. }
  149570. if (nbits > MAX_COEF_BITS+1)
  149571. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149572. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149573. if (nbits) /* emit_bits rejects calls with size 0 */
  149574. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149575. }
  149576. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149577. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149578. if (cinfo->restart_interval) {
  149579. if (entropy->restarts_to_go == 0) {
  149580. entropy->restarts_to_go = cinfo->restart_interval;
  149581. entropy->next_restart_num++;
  149582. entropy->next_restart_num &= 7;
  149583. }
  149584. entropy->restarts_to_go--;
  149585. }
  149586. return TRUE;
  149587. }
  149588. METHODDEF(boolean)
  149589. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149590. {
  149591. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149592. register int temp, temp2;
  149593. register int nbits;
  149594. register int r, k;
  149595. int Se = cinfo->Se;
  149596. int Al = cinfo->Al;
  149597. JBLOCKROW block;
  149598. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149599. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149600. if (cinfo->restart_interval)
  149601. if (entropy->restarts_to_go == 0)
  149602. emit_restart_p(entropy, entropy->next_restart_num);
  149603. block = MCU_data[0];
  149604. r = 0; /* r = run length of zeros */
  149605. for (k = cinfo->Ss; k <= Se; k++) {
  149606. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149607. r++;
  149608. continue;
  149609. }
  149610. if (temp < 0) {
  149611. temp = -temp; /* temp is abs value of input */
  149612. temp >>= Al; /* apply the point transform */
  149613. temp2 = ~temp;
  149614. } else {
  149615. temp >>= Al; /* apply the point transform */
  149616. temp2 = temp;
  149617. }
  149618. if (temp == 0) {
  149619. r++;
  149620. continue;
  149621. }
  149622. if (entropy->EOBRUN > 0)
  149623. emit_eobrun(entropy);
  149624. while (r > 15) {
  149625. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149626. r -= 16;
  149627. }
  149628. nbits = 1; /* there must be at least one 1 bit */
  149629. while ((temp >>= 1))
  149630. nbits++;
  149631. if (nbits > MAX_COEF_BITS)
  149632. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149633. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149634. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149635. r = 0; /* reset zero run length */
  149636. }
  149637. if (r > 0) { /* If there are trailing zeroes, */
  149638. entropy->EOBRUN++; /* count an EOB */
  149639. if (entropy->EOBRUN == 0x7FFF)
  149640. emit_eobrun(entropy); /* force it out to avoid overflow */
  149641. }
  149642. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149643. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149644. if (cinfo->restart_interval) {
  149645. if (entropy->restarts_to_go == 0) {
  149646. entropy->restarts_to_go = cinfo->restart_interval;
  149647. entropy->next_restart_num++;
  149648. entropy->next_restart_num &= 7;
  149649. }
  149650. entropy->restarts_to_go--;
  149651. }
  149652. return TRUE;
  149653. }
  149654. METHODDEF(boolean)
  149655. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149656. {
  149657. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149658. register int temp;
  149659. int blkn;
  149660. int Al = cinfo->Al;
  149661. JBLOCKROW block;
  149662. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149663. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149664. if (cinfo->restart_interval)
  149665. if (entropy->restarts_to_go == 0)
  149666. emit_restart_p(entropy, entropy->next_restart_num);
  149667. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149668. block = MCU_data[blkn];
  149669. temp = (*block)[0];
  149670. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149671. }
  149672. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149673. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149674. if (cinfo->restart_interval) {
  149675. if (entropy->restarts_to_go == 0) {
  149676. entropy->restarts_to_go = cinfo->restart_interval;
  149677. entropy->next_restart_num++;
  149678. entropy->next_restart_num &= 7;
  149679. }
  149680. entropy->restarts_to_go--;
  149681. }
  149682. return TRUE;
  149683. }
  149684. METHODDEF(boolean)
  149685. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149686. {
  149687. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149688. register int temp;
  149689. register int r, k;
  149690. int EOB;
  149691. char *BR_buffer;
  149692. unsigned int BR;
  149693. int Se = cinfo->Se;
  149694. int Al = cinfo->Al;
  149695. JBLOCKROW block;
  149696. int absvalues[DCTSIZE2];
  149697. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149698. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149699. if (cinfo->restart_interval)
  149700. if (entropy->restarts_to_go == 0)
  149701. emit_restart_p(entropy, entropy->next_restart_num);
  149702. block = MCU_data[0];
  149703. EOB = 0;
  149704. for (k = cinfo->Ss; k <= Se; k++) {
  149705. temp = (*block)[jpeg_natural_order[k]];
  149706. if (temp < 0)
  149707. temp = -temp; /* temp is abs value of input */
  149708. temp >>= Al; /* apply the point transform */
  149709. absvalues[k] = temp; /* save abs value for main pass */
  149710. if (temp == 1)
  149711. EOB = k; /* EOB = index of last newly-nonzero coef */
  149712. }
  149713. r = 0; /* r = run length of zeros */
  149714. BR = 0; /* BR = count of buffered bits added now */
  149715. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149716. for (k = cinfo->Ss; k <= Se; k++) {
  149717. if ((temp = absvalues[k]) == 0) {
  149718. r++;
  149719. continue;
  149720. }
  149721. while (r > 15 && k <= EOB) {
  149722. emit_eobrun(entropy);
  149723. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149724. r -= 16;
  149725. emit_buffered_bits(entropy, BR_buffer, BR);
  149726. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149727. BR = 0;
  149728. }
  149729. if (temp > 1) {
  149730. BR_buffer[BR++] = (char) (temp & 1);
  149731. continue;
  149732. }
  149733. emit_eobrun(entropy);
  149734. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149735. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149736. emit_bits_p(entropy, (unsigned int) temp, 1);
  149737. emit_buffered_bits(entropy, BR_buffer, BR);
  149738. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149739. BR = 0;
  149740. r = 0; /* reset zero run length */
  149741. }
  149742. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149743. entropy->EOBRUN++; /* count an EOB */
  149744. entropy->BE += BR; /* concat my correction bits to older ones */
  149745. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149746. emit_eobrun(entropy);
  149747. }
  149748. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149749. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149750. if (cinfo->restart_interval) {
  149751. if (entropy->restarts_to_go == 0) {
  149752. entropy->restarts_to_go = cinfo->restart_interval;
  149753. entropy->next_restart_num++;
  149754. entropy->next_restart_num &= 7;
  149755. }
  149756. entropy->restarts_to_go--;
  149757. }
  149758. return TRUE;
  149759. }
  149760. METHODDEF(void)
  149761. finish_pass_phuff (j_compress_ptr cinfo)
  149762. {
  149763. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149764. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149765. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149766. emit_eobrun(entropy);
  149767. flush_bits_p(entropy);
  149768. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149769. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149770. }
  149771. METHODDEF(void)
  149772. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149773. {
  149774. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149775. boolean is_DC_band;
  149776. int ci, tbl;
  149777. jpeg_component_info * compptr;
  149778. JHUFF_TBL **htblptr;
  149779. boolean did[NUM_HUFF_TBLS];
  149780. emit_eobrun(entropy);
  149781. is_DC_band = (cinfo->Ss == 0);
  149782. MEMZERO(did, SIZEOF(did));
  149783. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149784. compptr = cinfo->cur_comp_info[ci];
  149785. if (is_DC_band) {
  149786. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149787. continue;
  149788. tbl = compptr->dc_tbl_no;
  149789. } else {
  149790. tbl = compptr->ac_tbl_no;
  149791. }
  149792. if (! did[tbl]) {
  149793. if (is_DC_band)
  149794. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149795. else
  149796. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149797. if (*htblptr == NULL)
  149798. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149799. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149800. did[tbl] = TRUE;
  149801. }
  149802. }
  149803. }
  149804. GLOBAL(void)
  149805. jinit_phuff_encoder (j_compress_ptr cinfo)
  149806. {
  149807. phuff_entropy_ptr entropy;
  149808. int i;
  149809. entropy = (phuff_entropy_ptr)
  149810. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149811. SIZEOF(phuff_entropy_encoder));
  149812. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149813. entropy->pub.start_pass = start_pass_phuff;
  149814. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149815. entropy->derived_tbls[i] = NULL;
  149816. entropy->count_ptrs[i] = NULL;
  149817. }
  149818. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149819. }
  149820. #endif /* C_PROGRESSIVE_SUPPORTED */
  149821. /*** End of inlined file: jcphuff.c ***/
  149822. /*** Start of inlined file: jcprepct.c ***/
  149823. #define JPEG_INTERNALS
  149824. #ifdef INPUT_SMOOTHING_SUPPORTED
  149825. #define CONTEXT_ROWS_SUPPORTED
  149826. #endif
  149827. typedef struct {
  149828. struct jpeg_c_prep_controller pub; /* public fields */
  149829. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149830. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149831. int next_buf_row; /* index of next row to store in color_buf */
  149832. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149833. int this_row_group; /* starting row index of group to process */
  149834. int next_buf_stop; /* downsample when we reach this index */
  149835. #endif
  149836. } my_prep_controller;
  149837. typedef my_prep_controller * my_prep_ptr;
  149838. METHODDEF(void)
  149839. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149840. {
  149841. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149842. if (pass_mode != JBUF_PASS_THRU)
  149843. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149844. prep->rows_to_go = cinfo->image_height;
  149845. prep->next_buf_row = 0;
  149846. #ifdef CONTEXT_ROWS_SUPPORTED
  149847. prep->this_row_group = 0;
  149848. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149849. #endif
  149850. }
  149851. LOCAL(void)
  149852. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149853. int input_rows, int output_rows)
  149854. {
  149855. register int row;
  149856. for (row = input_rows; row < output_rows; row++) {
  149857. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149858. 1, num_cols);
  149859. }
  149860. }
  149861. METHODDEF(void)
  149862. pre_process_data (j_compress_ptr cinfo,
  149863. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149864. JDIMENSION in_rows_avail,
  149865. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149866. JDIMENSION out_row_groups_avail)
  149867. {
  149868. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149869. int numrows, ci;
  149870. JDIMENSION inrows;
  149871. jpeg_component_info * compptr;
  149872. while (*in_row_ctr < in_rows_avail &&
  149873. *out_row_group_ctr < out_row_groups_avail) {
  149874. inrows = in_rows_avail - *in_row_ctr;
  149875. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149876. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149877. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149878. prep->color_buf,
  149879. (JDIMENSION) prep->next_buf_row,
  149880. numrows);
  149881. *in_row_ctr += numrows;
  149882. prep->next_buf_row += numrows;
  149883. prep->rows_to_go -= numrows;
  149884. if (prep->rows_to_go == 0 &&
  149885. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149886. for (ci = 0; ci < cinfo->num_components; ci++) {
  149887. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149888. prep->next_buf_row, cinfo->max_v_samp_factor);
  149889. }
  149890. prep->next_buf_row = cinfo->max_v_samp_factor;
  149891. }
  149892. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149893. (*cinfo->downsample->downsample) (cinfo,
  149894. prep->color_buf, (JDIMENSION) 0,
  149895. output_buf, *out_row_group_ctr);
  149896. prep->next_buf_row = 0;
  149897. (*out_row_group_ctr)++;
  149898. }
  149899. if (prep->rows_to_go == 0 &&
  149900. *out_row_group_ctr < out_row_groups_avail) {
  149901. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149902. ci++, compptr++) {
  149903. expand_bottom_edge(output_buf[ci],
  149904. compptr->width_in_blocks * DCTSIZE,
  149905. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149906. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149907. }
  149908. *out_row_group_ctr = out_row_groups_avail;
  149909. break; /* can exit outer loop without test */
  149910. }
  149911. }
  149912. }
  149913. #ifdef CONTEXT_ROWS_SUPPORTED
  149914. METHODDEF(void)
  149915. pre_process_context (j_compress_ptr cinfo,
  149916. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149917. JDIMENSION in_rows_avail,
  149918. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149919. JDIMENSION out_row_groups_avail)
  149920. {
  149921. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149922. int numrows, ci;
  149923. int buf_height = cinfo->max_v_samp_factor * 3;
  149924. JDIMENSION inrows;
  149925. while (*out_row_group_ctr < out_row_groups_avail) {
  149926. if (*in_row_ctr < in_rows_avail) {
  149927. inrows = in_rows_avail - *in_row_ctr;
  149928. numrows = prep->next_buf_stop - prep->next_buf_row;
  149929. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149930. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149931. prep->color_buf,
  149932. (JDIMENSION) prep->next_buf_row,
  149933. numrows);
  149934. if (prep->rows_to_go == cinfo->image_height) {
  149935. for (ci = 0; ci < cinfo->num_components; ci++) {
  149936. int row;
  149937. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149938. jcopy_sample_rows(prep->color_buf[ci], 0,
  149939. prep->color_buf[ci], -row,
  149940. 1, cinfo->image_width);
  149941. }
  149942. }
  149943. }
  149944. *in_row_ctr += numrows;
  149945. prep->next_buf_row += numrows;
  149946. prep->rows_to_go -= numrows;
  149947. } else {
  149948. if (prep->rows_to_go != 0)
  149949. break;
  149950. if (prep->next_buf_row < prep->next_buf_stop) {
  149951. for (ci = 0; ci < cinfo->num_components; ci++) {
  149952. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149953. prep->next_buf_row, prep->next_buf_stop);
  149954. }
  149955. prep->next_buf_row = prep->next_buf_stop;
  149956. }
  149957. }
  149958. if (prep->next_buf_row == prep->next_buf_stop) {
  149959. (*cinfo->downsample->downsample) (cinfo,
  149960. prep->color_buf,
  149961. (JDIMENSION) prep->this_row_group,
  149962. output_buf, *out_row_group_ctr);
  149963. (*out_row_group_ctr)++;
  149964. prep->this_row_group += cinfo->max_v_samp_factor;
  149965. if (prep->this_row_group >= buf_height)
  149966. prep->this_row_group = 0;
  149967. if (prep->next_buf_row >= buf_height)
  149968. prep->next_buf_row = 0;
  149969. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149970. }
  149971. }
  149972. }
  149973. LOCAL(void)
  149974. create_context_buffer (j_compress_ptr cinfo)
  149975. {
  149976. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149977. int rgroup_height = cinfo->max_v_samp_factor;
  149978. int ci, i;
  149979. jpeg_component_info * compptr;
  149980. JSAMPARRAY true_buffer, fake_buffer;
  149981. fake_buffer = (JSAMPARRAY)
  149982. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149983. (cinfo->num_components * 5 * rgroup_height) *
  149984. SIZEOF(JSAMPROW));
  149985. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149986. ci++, compptr++) {
  149987. true_buffer = (*cinfo->mem->alloc_sarray)
  149988. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149989. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149990. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149991. (JDIMENSION) (3 * rgroup_height));
  149992. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149993. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149994. for (i = 0; i < rgroup_height; i++) {
  149995. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149996. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149997. }
  149998. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149999. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  150000. }
  150001. }
  150002. #endif /* CONTEXT_ROWS_SUPPORTED */
  150003. GLOBAL(void)
  150004. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  150005. {
  150006. my_prep_ptr prep;
  150007. int ci;
  150008. jpeg_component_info * compptr;
  150009. if (need_full_buffer) /* safety check */
  150010. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150011. prep = (my_prep_ptr)
  150012. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150013. SIZEOF(my_prep_controller));
  150014. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  150015. prep->pub.start_pass = start_pass_prep;
  150016. if (cinfo->downsample->need_context_rows) {
  150017. #ifdef CONTEXT_ROWS_SUPPORTED
  150018. prep->pub.pre_process_data = pre_process_context;
  150019. create_context_buffer(cinfo);
  150020. #else
  150021. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150022. #endif
  150023. } else {
  150024. prep->pub.pre_process_data = pre_process_data;
  150025. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150026. ci++, compptr++) {
  150027. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  150028. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150029. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150030. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150031. (JDIMENSION) cinfo->max_v_samp_factor);
  150032. }
  150033. }
  150034. }
  150035. /*** End of inlined file: jcprepct.c ***/
  150036. /*** Start of inlined file: jcsample.c ***/
  150037. #define JPEG_INTERNALS
  150038. typedef JMETHOD(void, downsample1_ptr,
  150039. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150040. JSAMPARRAY input_data, JSAMPARRAY output_data));
  150041. typedef struct {
  150042. struct jpeg_downsampler pub; /* public fields */
  150043. downsample1_ptr methods[MAX_COMPONENTS];
  150044. } my_downsampler;
  150045. typedef my_downsampler * my_downsample_ptr;
  150046. METHODDEF(void)
  150047. start_pass_downsample (j_compress_ptr cinfo)
  150048. {
  150049. }
  150050. LOCAL(void)
  150051. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  150052. JDIMENSION input_cols, JDIMENSION output_cols)
  150053. {
  150054. register JSAMPROW ptr;
  150055. register JSAMPLE pixval;
  150056. register int count;
  150057. int row;
  150058. int numcols = (int) (output_cols - input_cols);
  150059. if (numcols > 0) {
  150060. for (row = 0; row < num_rows; row++) {
  150061. ptr = image_data[row] + input_cols;
  150062. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  150063. for (count = numcols; count > 0; count--)
  150064. *ptr++ = pixval;
  150065. }
  150066. }
  150067. }
  150068. METHODDEF(void)
  150069. sep_downsample (j_compress_ptr cinfo,
  150070. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  150071. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  150072. {
  150073. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  150074. int ci;
  150075. jpeg_component_info * compptr;
  150076. JSAMPARRAY in_ptr, out_ptr;
  150077. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150078. ci++, compptr++) {
  150079. in_ptr = input_buf[ci] + in_row_index;
  150080. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  150081. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  150082. }
  150083. }
  150084. METHODDEF(void)
  150085. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150086. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150087. {
  150088. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150089. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  150090. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150091. JSAMPROW inptr, outptr;
  150092. INT32 outvalue;
  150093. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  150094. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  150095. numpix = h_expand * v_expand;
  150096. numpix2 = numpix/2;
  150097. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150098. cinfo->image_width, output_cols * h_expand);
  150099. inrow = 0;
  150100. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150101. outptr = output_data[outrow];
  150102. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150103. outcol++, outcol_h += h_expand) {
  150104. outvalue = 0;
  150105. for (v = 0; v < v_expand; v++) {
  150106. inptr = input_data[inrow+v] + outcol_h;
  150107. for (h = 0; h < h_expand; h++) {
  150108. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150109. }
  150110. }
  150111. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150112. }
  150113. inrow += v_expand;
  150114. }
  150115. }
  150116. METHODDEF(void)
  150117. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150118. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150119. {
  150120. jcopy_sample_rows(input_data, 0, output_data, 0,
  150121. cinfo->max_v_samp_factor, cinfo->image_width);
  150122. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150123. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150124. }
  150125. METHODDEF(void)
  150126. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150127. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150128. {
  150129. int outrow;
  150130. JDIMENSION outcol;
  150131. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150132. register JSAMPROW inptr, outptr;
  150133. register int bias;
  150134. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150135. cinfo->image_width, output_cols * 2);
  150136. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150137. outptr = output_data[outrow];
  150138. inptr = input_data[outrow];
  150139. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150140. for (outcol = 0; outcol < output_cols; outcol++) {
  150141. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150142. + bias) >> 1);
  150143. bias ^= 1; /* 0=>1, 1=>0 */
  150144. inptr += 2;
  150145. }
  150146. }
  150147. }
  150148. METHODDEF(void)
  150149. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150150. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150151. {
  150152. int inrow, outrow;
  150153. JDIMENSION outcol;
  150154. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150155. register JSAMPROW inptr0, inptr1, outptr;
  150156. register int bias;
  150157. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150158. cinfo->image_width, output_cols * 2);
  150159. inrow = 0;
  150160. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150161. outptr = output_data[outrow];
  150162. inptr0 = input_data[inrow];
  150163. inptr1 = input_data[inrow+1];
  150164. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150165. for (outcol = 0; outcol < output_cols; outcol++) {
  150166. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150167. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150168. + bias) >> 2);
  150169. bias ^= 3; /* 1=>2, 2=>1 */
  150170. inptr0 += 2; inptr1 += 2;
  150171. }
  150172. inrow += 2;
  150173. }
  150174. }
  150175. #ifdef INPUT_SMOOTHING_SUPPORTED
  150176. METHODDEF(void)
  150177. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150178. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150179. {
  150180. int inrow, outrow;
  150181. JDIMENSION colctr;
  150182. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150183. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150184. INT32 membersum, neighsum, memberscale, neighscale;
  150185. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150186. cinfo->image_width, output_cols * 2);
  150187. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150188. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150189. inrow = 0;
  150190. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150191. outptr = output_data[outrow];
  150192. inptr0 = input_data[inrow];
  150193. inptr1 = input_data[inrow+1];
  150194. above_ptr = input_data[inrow-1];
  150195. below_ptr = input_data[inrow+2];
  150196. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150197. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150198. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150199. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150200. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150201. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150202. neighsum += neighsum;
  150203. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150204. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150205. membersum = membersum * memberscale + neighsum * neighscale;
  150206. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150207. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150208. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150209. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150210. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150211. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150212. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150213. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150214. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150215. neighsum += neighsum;
  150216. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150217. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150218. membersum = membersum * memberscale + neighsum * neighscale;
  150219. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150220. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150221. }
  150222. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150223. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150224. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150225. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150226. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150227. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150228. neighsum += neighsum;
  150229. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150230. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150231. membersum = membersum * memberscale + neighsum * neighscale;
  150232. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150233. inrow += 2;
  150234. }
  150235. }
  150236. METHODDEF(void)
  150237. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150238. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150239. {
  150240. int outrow;
  150241. JDIMENSION colctr;
  150242. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150243. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150244. INT32 membersum, neighsum, memberscale, neighscale;
  150245. int colsum, lastcolsum, nextcolsum;
  150246. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150247. cinfo->image_width, output_cols);
  150248. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150249. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150250. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150251. outptr = output_data[outrow];
  150252. inptr = input_data[outrow];
  150253. above_ptr = input_data[outrow-1];
  150254. below_ptr = input_data[outrow+1];
  150255. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150256. GETJSAMPLE(*inptr);
  150257. membersum = GETJSAMPLE(*inptr++);
  150258. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150259. GETJSAMPLE(*inptr);
  150260. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150261. membersum = membersum * memberscale + neighsum * neighscale;
  150262. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150263. lastcolsum = colsum; colsum = nextcolsum;
  150264. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150265. membersum = GETJSAMPLE(*inptr++);
  150266. above_ptr++; below_ptr++;
  150267. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150268. GETJSAMPLE(*inptr);
  150269. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150270. membersum = membersum * memberscale + neighsum * neighscale;
  150271. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150272. lastcolsum = colsum; colsum = nextcolsum;
  150273. }
  150274. membersum = GETJSAMPLE(*inptr);
  150275. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150276. membersum = membersum * memberscale + neighsum * neighscale;
  150277. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150278. }
  150279. }
  150280. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150281. GLOBAL(void)
  150282. jinit_downsampler (j_compress_ptr cinfo)
  150283. {
  150284. my_downsample_ptr downsample;
  150285. int ci;
  150286. jpeg_component_info * compptr;
  150287. boolean smoothok = TRUE;
  150288. downsample = (my_downsample_ptr)
  150289. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150290. SIZEOF(my_downsampler));
  150291. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150292. downsample->pub.start_pass = start_pass_downsample;
  150293. downsample->pub.downsample = sep_downsample;
  150294. downsample->pub.need_context_rows = FALSE;
  150295. if (cinfo->CCIR601_sampling)
  150296. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150297. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150298. ci++, compptr++) {
  150299. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150300. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150301. #ifdef INPUT_SMOOTHING_SUPPORTED
  150302. if (cinfo->smoothing_factor) {
  150303. downsample->methods[ci] = fullsize_smooth_downsample;
  150304. downsample->pub.need_context_rows = TRUE;
  150305. } else
  150306. #endif
  150307. downsample->methods[ci] = fullsize_downsample;
  150308. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150309. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150310. smoothok = FALSE;
  150311. downsample->methods[ci] = h2v1_downsample;
  150312. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150313. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150314. #ifdef INPUT_SMOOTHING_SUPPORTED
  150315. if (cinfo->smoothing_factor) {
  150316. downsample->methods[ci] = h2v2_smooth_downsample;
  150317. downsample->pub.need_context_rows = TRUE;
  150318. } else
  150319. #endif
  150320. downsample->methods[ci] = h2v2_downsample;
  150321. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150322. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150323. smoothok = FALSE;
  150324. downsample->methods[ci] = int_downsample;
  150325. } else
  150326. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150327. }
  150328. #ifdef INPUT_SMOOTHING_SUPPORTED
  150329. if (cinfo->smoothing_factor && !smoothok)
  150330. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150331. #endif
  150332. }
  150333. /*** End of inlined file: jcsample.c ***/
  150334. /*** Start of inlined file: jctrans.c ***/
  150335. #define JPEG_INTERNALS
  150336. LOCAL(void) transencode_master_selection
  150337. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150338. LOCAL(void) transencode_coef_controller
  150339. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150340. GLOBAL(void)
  150341. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150342. {
  150343. if (cinfo->global_state != CSTATE_START)
  150344. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150345. jpeg_suppress_tables(cinfo, FALSE);
  150346. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150347. (*cinfo->dest->init_destination) (cinfo);
  150348. transencode_master_selection(cinfo, coef_arrays);
  150349. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150350. cinfo->global_state = CSTATE_WRCOEFS;
  150351. }
  150352. GLOBAL(void)
  150353. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150354. j_compress_ptr dstinfo)
  150355. {
  150356. JQUANT_TBL ** qtblptr;
  150357. jpeg_component_info *incomp, *outcomp;
  150358. JQUANT_TBL *c_quant, *slot_quant;
  150359. int tblno, ci, coefi;
  150360. if (dstinfo->global_state != CSTATE_START)
  150361. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150362. dstinfo->image_width = srcinfo->image_width;
  150363. dstinfo->image_height = srcinfo->image_height;
  150364. dstinfo->input_components = srcinfo->num_components;
  150365. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150366. jpeg_set_defaults(dstinfo);
  150367. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150368. dstinfo->data_precision = srcinfo->data_precision;
  150369. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150370. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150371. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150372. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150373. if (*qtblptr == NULL)
  150374. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150375. MEMCOPY((*qtblptr)->quantval,
  150376. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150377. SIZEOF((*qtblptr)->quantval));
  150378. (*qtblptr)->sent_table = FALSE;
  150379. }
  150380. }
  150381. dstinfo->num_components = srcinfo->num_components;
  150382. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150383. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150384. MAX_COMPONENTS);
  150385. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150386. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150387. outcomp->component_id = incomp->component_id;
  150388. outcomp->h_samp_factor = incomp->h_samp_factor;
  150389. outcomp->v_samp_factor = incomp->v_samp_factor;
  150390. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150391. tblno = outcomp->quant_tbl_no;
  150392. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150393. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150394. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150395. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150396. c_quant = incomp->quant_table;
  150397. if (c_quant != NULL) {
  150398. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150399. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150400. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150401. }
  150402. }
  150403. }
  150404. if (srcinfo->saw_JFIF_marker) {
  150405. if (srcinfo->JFIF_major_version == 1) {
  150406. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150407. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150408. }
  150409. dstinfo->density_unit = srcinfo->density_unit;
  150410. dstinfo->X_density = srcinfo->X_density;
  150411. dstinfo->Y_density = srcinfo->Y_density;
  150412. }
  150413. }
  150414. LOCAL(void)
  150415. transencode_master_selection (j_compress_ptr cinfo,
  150416. jvirt_barray_ptr * coef_arrays)
  150417. {
  150418. cinfo->input_components = 1;
  150419. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150420. if (cinfo->arith_code) {
  150421. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150422. } else {
  150423. if (cinfo->progressive_mode) {
  150424. #ifdef C_PROGRESSIVE_SUPPORTED
  150425. jinit_phuff_encoder(cinfo);
  150426. #else
  150427. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150428. #endif
  150429. } else
  150430. jinit_huff_encoder(cinfo);
  150431. }
  150432. transencode_coef_controller(cinfo, coef_arrays);
  150433. jinit_marker_writer(cinfo);
  150434. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150435. (*cinfo->marker->write_file_header) (cinfo);
  150436. }
  150437. typedef struct {
  150438. struct jpeg_c_coef_controller pub; /* public fields */
  150439. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150440. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150441. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150442. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150443. jvirt_barray_ptr * whole_image;
  150444. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150445. } my_coef_controller2;
  150446. typedef my_coef_controller2 * my_coef_ptr2;
  150447. LOCAL(void)
  150448. start_iMCU_row2 (j_compress_ptr cinfo)
  150449. {
  150450. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150451. if (cinfo->comps_in_scan > 1) {
  150452. coef->MCU_rows_per_iMCU_row = 1;
  150453. } else {
  150454. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150455. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150456. else
  150457. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150458. }
  150459. coef->mcu_ctr = 0;
  150460. coef->MCU_vert_offset = 0;
  150461. }
  150462. METHODDEF(void)
  150463. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150464. {
  150465. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150466. if (pass_mode != JBUF_CRANK_DEST)
  150467. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150468. coef->iMCU_row_num = 0;
  150469. start_iMCU_row2(cinfo);
  150470. }
  150471. METHODDEF(boolean)
  150472. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150473. {
  150474. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150475. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150476. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150477. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150478. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150479. JDIMENSION start_col;
  150480. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150481. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150482. JBLOCKROW buffer_ptr;
  150483. jpeg_component_info *compptr;
  150484. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150485. compptr = cinfo->cur_comp_info[ci];
  150486. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150487. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150488. coef->iMCU_row_num * compptr->v_samp_factor,
  150489. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150490. }
  150491. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150492. yoffset++) {
  150493. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150494. MCU_col_num++) {
  150495. blkn = 0; /* index of current DCT block within MCU */
  150496. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150497. compptr = cinfo->cur_comp_info[ci];
  150498. start_col = MCU_col_num * compptr->MCU_width;
  150499. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150500. : compptr->last_col_width;
  150501. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150502. if (coef->iMCU_row_num < last_iMCU_row ||
  150503. yindex+yoffset < compptr->last_row_height) {
  150504. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150505. for (xindex = 0; xindex < blockcnt; xindex++)
  150506. MCU_buffer[blkn++] = buffer_ptr++;
  150507. } else {
  150508. xindex = 0;
  150509. }
  150510. for (; xindex < compptr->MCU_width; xindex++) {
  150511. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150512. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150513. blkn++;
  150514. }
  150515. }
  150516. }
  150517. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150518. coef->MCU_vert_offset = yoffset;
  150519. coef->mcu_ctr = MCU_col_num;
  150520. return FALSE;
  150521. }
  150522. }
  150523. coef->mcu_ctr = 0;
  150524. }
  150525. coef->iMCU_row_num++;
  150526. start_iMCU_row2(cinfo);
  150527. return TRUE;
  150528. }
  150529. LOCAL(void)
  150530. transencode_coef_controller (j_compress_ptr cinfo,
  150531. jvirt_barray_ptr * coef_arrays)
  150532. {
  150533. my_coef_ptr2 coef;
  150534. JBLOCKROW buffer;
  150535. int i;
  150536. coef = (my_coef_ptr2)
  150537. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150538. SIZEOF(my_coef_controller2));
  150539. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150540. coef->pub.start_pass = start_pass_coef2;
  150541. coef->pub.compress_data = compress_output2;
  150542. coef->whole_image = coef_arrays;
  150543. buffer = (JBLOCKROW)
  150544. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150545. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150546. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150547. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150548. coef->dummy_buffer[i] = buffer + i;
  150549. }
  150550. }
  150551. /*** End of inlined file: jctrans.c ***/
  150552. /*** Start of inlined file: jdapistd.c ***/
  150553. #define JPEG_INTERNALS
  150554. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150555. GLOBAL(boolean)
  150556. jpeg_start_decompress (j_decompress_ptr cinfo)
  150557. {
  150558. if (cinfo->global_state == DSTATE_READY) {
  150559. jinit_master_decompress(cinfo);
  150560. if (cinfo->buffered_image) {
  150561. cinfo->global_state = DSTATE_BUFIMAGE;
  150562. return TRUE;
  150563. }
  150564. cinfo->global_state = DSTATE_PRELOAD;
  150565. }
  150566. if (cinfo->global_state == DSTATE_PRELOAD) {
  150567. if (cinfo->inputctl->has_multiple_scans) {
  150568. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150569. for (;;) {
  150570. int retcode;
  150571. if (cinfo->progress != NULL)
  150572. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150573. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150574. if (retcode == JPEG_SUSPENDED)
  150575. return FALSE;
  150576. if (retcode == JPEG_REACHED_EOI)
  150577. break;
  150578. if (cinfo->progress != NULL &&
  150579. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150580. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150581. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150582. }
  150583. }
  150584. }
  150585. #else
  150586. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150587. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150588. }
  150589. cinfo->output_scan_number = cinfo->input_scan_number;
  150590. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150591. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150592. return output_pass_setup(cinfo);
  150593. }
  150594. LOCAL(boolean)
  150595. output_pass_setup (j_decompress_ptr cinfo)
  150596. {
  150597. if (cinfo->global_state != DSTATE_PRESCAN) {
  150598. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150599. cinfo->output_scanline = 0;
  150600. cinfo->global_state = DSTATE_PRESCAN;
  150601. }
  150602. while (cinfo->master->is_dummy_pass) {
  150603. #ifdef QUANT_2PASS_SUPPORTED
  150604. while (cinfo->output_scanline < cinfo->output_height) {
  150605. JDIMENSION last_scanline;
  150606. if (cinfo->progress != NULL) {
  150607. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150608. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150609. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150610. }
  150611. last_scanline = cinfo->output_scanline;
  150612. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150613. &cinfo->output_scanline, (JDIMENSION) 0);
  150614. if (cinfo->output_scanline == last_scanline)
  150615. return FALSE; /* No progress made, must suspend */
  150616. }
  150617. (*cinfo->master->finish_output_pass) (cinfo);
  150618. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150619. cinfo->output_scanline = 0;
  150620. #else
  150621. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150622. #endif /* QUANT_2PASS_SUPPORTED */
  150623. }
  150624. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150625. return TRUE;
  150626. }
  150627. GLOBAL(JDIMENSION)
  150628. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150629. JDIMENSION max_lines)
  150630. {
  150631. JDIMENSION row_ctr;
  150632. if (cinfo->global_state != DSTATE_SCANNING)
  150633. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150634. if (cinfo->output_scanline >= cinfo->output_height) {
  150635. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150636. return 0;
  150637. }
  150638. if (cinfo->progress != NULL) {
  150639. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150640. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150641. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150642. }
  150643. row_ctr = 0;
  150644. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150645. cinfo->output_scanline += row_ctr;
  150646. return row_ctr;
  150647. }
  150648. GLOBAL(JDIMENSION)
  150649. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150650. JDIMENSION max_lines)
  150651. {
  150652. JDIMENSION lines_per_iMCU_row;
  150653. if (cinfo->global_state != DSTATE_RAW_OK)
  150654. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150655. if (cinfo->output_scanline >= cinfo->output_height) {
  150656. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150657. return 0;
  150658. }
  150659. if (cinfo->progress != NULL) {
  150660. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150661. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150662. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150663. }
  150664. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150665. if (max_lines < lines_per_iMCU_row)
  150666. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150667. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150668. return 0; /* suspension forced, can do nothing more */
  150669. cinfo->output_scanline += lines_per_iMCU_row;
  150670. return lines_per_iMCU_row;
  150671. }
  150672. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150673. GLOBAL(boolean)
  150674. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150675. {
  150676. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150677. cinfo->global_state != DSTATE_PRESCAN)
  150678. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150679. if (scan_number <= 0)
  150680. scan_number = 1;
  150681. if (cinfo->inputctl->eoi_reached &&
  150682. scan_number > cinfo->input_scan_number)
  150683. scan_number = cinfo->input_scan_number;
  150684. cinfo->output_scan_number = scan_number;
  150685. return output_pass_setup(cinfo);
  150686. }
  150687. GLOBAL(boolean)
  150688. jpeg_finish_output (j_decompress_ptr cinfo)
  150689. {
  150690. if ((cinfo->global_state == DSTATE_SCANNING ||
  150691. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150692. (*cinfo->master->finish_output_pass) (cinfo);
  150693. cinfo->global_state = DSTATE_BUFPOST;
  150694. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150695. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150696. }
  150697. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150698. ! cinfo->inputctl->eoi_reached) {
  150699. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150700. return FALSE; /* Suspend, come back later */
  150701. }
  150702. cinfo->global_state = DSTATE_BUFIMAGE;
  150703. return TRUE;
  150704. }
  150705. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150706. /*** End of inlined file: jdapistd.c ***/
  150707. /*** Start of inlined file: jdapimin.c ***/
  150708. #define JPEG_INTERNALS
  150709. GLOBAL(void)
  150710. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150711. {
  150712. int i;
  150713. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150714. if (version != JPEG_LIB_VERSION)
  150715. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150716. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150717. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150718. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150719. {
  150720. struct jpeg_error_mgr * err = cinfo->err;
  150721. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150722. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150723. cinfo->err = err;
  150724. cinfo->client_data = client_data;
  150725. }
  150726. cinfo->is_decompressor = TRUE;
  150727. jinit_memory_mgr((j_common_ptr) cinfo);
  150728. cinfo->progress = NULL;
  150729. cinfo->src = NULL;
  150730. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150731. cinfo->quant_tbl_ptrs[i] = NULL;
  150732. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150733. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150734. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150735. }
  150736. cinfo->marker_list = NULL;
  150737. jinit_marker_reader(cinfo);
  150738. jinit_input_controller(cinfo);
  150739. cinfo->global_state = DSTATE_START;
  150740. }
  150741. GLOBAL(void)
  150742. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150743. {
  150744. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150745. }
  150746. GLOBAL(void)
  150747. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150748. {
  150749. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150750. }
  150751. LOCAL(void)
  150752. default_decompress_parms (j_decompress_ptr cinfo)
  150753. {
  150754. switch (cinfo->num_components) {
  150755. case 1:
  150756. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150757. cinfo->out_color_space = JCS_GRAYSCALE;
  150758. break;
  150759. case 3:
  150760. if (cinfo->saw_JFIF_marker) {
  150761. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150762. } else if (cinfo->saw_Adobe_marker) {
  150763. switch (cinfo->Adobe_transform) {
  150764. case 0:
  150765. cinfo->jpeg_color_space = JCS_RGB;
  150766. break;
  150767. case 1:
  150768. cinfo->jpeg_color_space = JCS_YCbCr;
  150769. break;
  150770. default:
  150771. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150772. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150773. break;
  150774. }
  150775. } else {
  150776. int cid0 = cinfo->comp_info[0].component_id;
  150777. int cid1 = cinfo->comp_info[1].component_id;
  150778. int cid2 = cinfo->comp_info[2].component_id;
  150779. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150780. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150781. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150782. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150783. else {
  150784. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150785. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150786. }
  150787. }
  150788. cinfo->out_color_space = JCS_RGB;
  150789. break;
  150790. case 4:
  150791. if (cinfo->saw_Adobe_marker) {
  150792. switch (cinfo->Adobe_transform) {
  150793. case 0:
  150794. cinfo->jpeg_color_space = JCS_CMYK;
  150795. break;
  150796. case 2:
  150797. cinfo->jpeg_color_space = JCS_YCCK;
  150798. break;
  150799. default:
  150800. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150801. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150802. break;
  150803. }
  150804. } else {
  150805. cinfo->jpeg_color_space = JCS_CMYK;
  150806. }
  150807. cinfo->out_color_space = JCS_CMYK;
  150808. break;
  150809. default:
  150810. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150811. cinfo->out_color_space = JCS_UNKNOWN;
  150812. break;
  150813. }
  150814. cinfo->scale_num = 1; /* 1:1 scaling */
  150815. cinfo->scale_denom = 1;
  150816. cinfo->output_gamma = 1.0;
  150817. cinfo->buffered_image = FALSE;
  150818. cinfo->raw_data_out = FALSE;
  150819. cinfo->dct_method = JDCT_DEFAULT;
  150820. cinfo->do_fancy_upsampling = TRUE;
  150821. cinfo->do_block_smoothing = TRUE;
  150822. cinfo->quantize_colors = FALSE;
  150823. cinfo->dither_mode = JDITHER_FS;
  150824. #ifdef QUANT_2PASS_SUPPORTED
  150825. cinfo->two_pass_quantize = TRUE;
  150826. #else
  150827. cinfo->two_pass_quantize = FALSE;
  150828. #endif
  150829. cinfo->desired_number_of_colors = 256;
  150830. cinfo->colormap = NULL;
  150831. cinfo->enable_1pass_quant = FALSE;
  150832. cinfo->enable_external_quant = FALSE;
  150833. cinfo->enable_2pass_quant = FALSE;
  150834. }
  150835. GLOBAL(int)
  150836. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150837. {
  150838. int retcode;
  150839. if (cinfo->global_state != DSTATE_START &&
  150840. cinfo->global_state != DSTATE_INHEADER)
  150841. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150842. retcode = jpeg_consume_input(cinfo);
  150843. switch (retcode) {
  150844. case JPEG_REACHED_SOS:
  150845. retcode = JPEG_HEADER_OK;
  150846. break;
  150847. case JPEG_REACHED_EOI:
  150848. if (require_image) /* Complain if application wanted an image */
  150849. ERREXIT(cinfo, JERR_NO_IMAGE);
  150850. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150851. retcode = JPEG_HEADER_TABLES_ONLY;
  150852. break;
  150853. case JPEG_SUSPENDED:
  150854. break;
  150855. }
  150856. return retcode;
  150857. }
  150858. GLOBAL(int)
  150859. jpeg_consume_input (j_decompress_ptr cinfo)
  150860. {
  150861. int retcode = JPEG_SUSPENDED;
  150862. switch (cinfo->global_state) {
  150863. case DSTATE_START:
  150864. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150865. (*cinfo->src->init_source) (cinfo);
  150866. cinfo->global_state = DSTATE_INHEADER;
  150867. case DSTATE_INHEADER:
  150868. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150869. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150870. default_decompress_parms(cinfo);
  150871. cinfo->global_state = DSTATE_READY;
  150872. }
  150873. break;
  150874. case DSTATE_READY:
  150875. retcode = JPEG_REACHED_SOS;
  150876. break;
  150877. case DSTATE_PRELOAD:
  150878. case DSTATE_PRESCAN:
  150879. case DSTATE_SCANNING:
  150880. case DSTATE_RAW_OK:
  150881. case DSTATE_BUFIMAGE:
  150882. case DSTATE_BUFPOST:
  150883. case DSTATE_STOPPING:
  150884. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150885. break;
  150886. default:
  150887. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150888. }
  150889. return retcode;
  150890. }
  150891. GLOBAL(boolean)
  150892. jpeg_input_complete (j_decompress_ptr cinfo)
  150893. {
  150894. if (cinfo->global_state < DSTATE_START ||
  150895. cinfo->global_state > DSTATE_STOPPING)
  150896. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150897. return cinfo->inputctl->eoi_reached;
  150898. }
  150899. GLOBAL(boolean)
  150900. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150901. {
  150902. if (cinfo->global_state < DSTATE_READY ||
  150903. cinfo->global_state > DSTATE_STOPPING)
  150904. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150905. return cinfo->inputctl->has_multiple_scans;
  150906. }
  150907. GLOBAL(boolean)
  150908. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150909. {
  150910. if ((cinfo->global_state == DSTATE_SCANNING ||
  150911. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150912. if (cinfo->output_scanline < cinfo->output_height)
  150913. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150914. (*cinfo->master->finish_output_pass) (cinfo);
  150915. cinfo->global_state = DSTATE_STOPPING;
  150916. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150917. cinfo->global_state = DSTATE_STOPPING;
  150918. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150919. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150920. }
  150921. while (! cinfo->inputctl->eoi_reached) {
  150922. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150923. return FALSE; /* Suspend, come back later */
  150924. }
  150925. (*cinfo->src->term_source) (cinfo);
  150926. jpeg_abort((j_common_ptr) cinfo);
  150927. return TRUE;
  150928. }
  150929. /*** End of inlined file: jdapimin.c ***/
  150930. /*** Start of inlined file: jdatasrc.c ***/
  150931. /*** Start of inlined file: jerror.h ***/
  150932. #ifndef JMESSAGE
  150933. #ifndef JERROR_H
  150934. #define JMAKE_ENUM_LIST
  150935. #else
  150936. #define JMESSAGE(code,string)
  150937. #endif /* JERROR_H */
  150938. #endif /* JMESSAGE */
  150939. #ifdef JMAKE_ENUM_LIST
  150940. typedef enum {
  150941. #define JMESSAGE(code,string) code ,
  150942. #endif /* JMAKE_ENUM_LIST */
  150943. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150944. JMESSAGE(JERR_ARITH_NOTIMPL,
  150945. "Sorry, there are legal restrictions on arithmetic coding")
  150946. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150947. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150948. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150949. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150950. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150951. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150952. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150953. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150954. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150955. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150956. JMESSAGE(JERR_BAD_LIB_VERSION,
  150957. "Wrong JPEG library version: library is %d, caller expects %d")
  150958. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150959. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150960. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150961. JMESSAGE(JERR_BAD_PROGRESSION,
  150962. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150963. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150964. "Invalid progressive parameters at scan script entry %d")
  150965. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150966. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150967. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150968. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150969. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150970. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150971. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150972. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150973. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150974. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150975. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150976. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150977. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150978. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150979. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150980. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150981. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150982. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150983. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150984. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150985. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150986. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150987. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150988. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150989. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150990. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150991. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150992. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150993. "Cannot transcode due to multiple use of quantization table %d")
  150994. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150995. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150996. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150997. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150998. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150999. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  151000. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  151001. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  151002. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  151003. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  151004. JMESSAGE(JERR_QUANT_COMPONENTS,
  151005. "Cannot quantize more than %d color components")
  151006. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  151007. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  151008. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  151009. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  151010. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  151011. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  151012. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  151013. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  151014. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  151015. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  151016. JMESSAGE(JERR_TFILE_WRITE,
  151017. "Write failed on temporary file --- out of disk space?")
  151018. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  151019. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  151020. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  151021. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  151022. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  151023. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  151024. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  151025. JMESSAGE(JMSG_VERSION, JVERSION)
  151026. JMESSAGE(JTRC_16BIT_TABLES,
  151027. "Caution: quantization tables are too coarse for baseline JPEG")
  151028. JMESSAGE(JTRC_ADOBE,
  151029. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  151030. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  151031. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  151032. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  151033. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  151034. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  151035. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  151036. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  151037. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  151038. JMESSAGE(JTRC_EOI, "End Of Image")
  151039. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  151040. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  151041. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  151042. "Warning: thumbnail image size does not match data length %u")
  151043. JMESSAGE(JTRC_JFIF_EXTENSION,
  151044. "JFIF extension marker: type 0x%02x, length %u")
  151045. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  151046. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  151047. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  151048. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  151049. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  151050. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  151051. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  151052. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  151053. JMESSAGE(JTRC_RST, "RST%d")
  151054. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  151055. "Smoothing not supported with nonstandard sampling ratios")
  151056. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  151057. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  151058. JMESSAGE(JTRC_SOI, "Start of Image")
  151059. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  151060. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  151061. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  151062. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  151063. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  151064. JMESSAGE(JTRC_THUMB_JPEG,
  151065. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  151066. JMESSAGE(JTRC_THUMB_PALETTE,
  151067. "JFIF extension marker: palette thumbnail image, length %u")
  151068. JMESSAGE(JTRC_THUMB_RGB,
  151069. "JFIF extension marker: RGB thumbnail image, length %u")
  151070. JMESSAGE(JTRC_UNKNOWN_IDS,
  151071. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  151072. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  151073. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  151074. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  151075. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  151076. "Inconsistent progression sequence for component %d coefficient %d")
  151077. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  151078. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  151079. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  151080. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  151081. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  151082. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  151083. JMESSAGE(JWRN_MUST_RESYNC,
  151084. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  151085. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  151086. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  151087. #ifdef JMAKE_ENUM_LIST
  151088. JMSG_LASTMSGCODE
  151089. } J_MESSAGE_CODE;
  151090. #undef JMAKE_ENUM_LIST
  151091. #endif /* JMAKE_ENUM_LIST */
  151092. #undef JMESSAGE
  151093. #ifndef JERROR_H
  151094. #define JERROR_H
  151095. #define ERREXIT(cinfo,code) \
  151096. ((cinfo)->err->msg_code = (code), \
  151097. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151098. #define ERREXIT1(cinfo,code,p1) \
  151099. ((cinfo)->err->msg_code = (code), \
  151100. (cinfo)->err->msg_parm.i[0] = (p1), \
  151101. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151102. #define ERREXIT2(cinfo,code,p1,p2) \
  151103. ((cinfo)->err->msg_code = (code), \
  151104. (cinfo)->err->msg_parm.i[0] = (p1), \
  151105. (cinfo)->err->msg_parm.i[1] = (p2), \
  151106. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151107. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151108. ((cinfo)->err->msg_code = (code), \
  151109. (cinfo)->err->msg_parm.i[0] = (p1), \
  151110. (cinfo)->err->msg_parm.i[1] = (p2), \
  151111. (cinfo)->err->msg_parm.i[2] = (p3), \
  151112. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151113. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151114. ((cinfo)->err->msg_code = (code), \
  151115. (cinfo)->err->msg_parm.i[0] = (p1), \
  151116. (cinfo)->err->msg_parm.i[1] = (p2), \
  151117. (cinfo)->err->msg_parm.i[2] = (p3), \
  151118. (cinfo)->err->msg_parm.i[3] = (p4), \
  151119. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151120. #define ERREXITS(cinfo,code,str) \
  151121. ((cinfo)->err->msg_code = (code), \
  151122. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151123. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151124. #define MAKESTMT(stuff) do { stuff } while (0)
  151125. #define WARNMS(cinfo,code) \
  151126. ((cinfo)->err->msg_code = (code), \
  151127. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151128. #define WARNMS1(cinfo,code,p1) \
  151129. ((cinfo)->err->msg_code = (code), \
  151130. (cinfo)->err->msg_parm.i[0] = (p1), \
  151131. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151132. #define WARNMS2(cinfo,code,p1,p2) \
  151133. ((cinfo)->err->msg_code = (code), \
  151134. (cinfo)->err->msg_parm.i[0] = (p1), \
  151135. (cinfo)->err->msg_parm.i[1] = (p2), \
  151136. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151137. #define TRACEMS(cinfo,lvl,code) \
  151138. ((cinfo)->err->msg_code = (code), \
  151139. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151140. #define TRACEMS1(cinfo,lvl,code,p1) \
  151141. ((cinfo)->err->msg_code = (code), \
  151142. (cinfo)->err->msg_parm.i[0] = (p1), \
  151143. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151144. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151145. ((cinfo)->err->msg_code = (code), \
  151146. (cinfo)->err->msg_parm.i[0] = (p1), \
  151147. (cinfo)->err->msg_parm.i[1] = (p2), \
  151148. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151149. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151150. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151151. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151152. (cinfo)->err->msg_code = (code); \
  151153. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151154. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151155. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151156. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151157. (cinfo)->err->msg_code = (code); \
  151158. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151159. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151160. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151161. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151162. _mp[4] = (p5); \
  151163. (cinfo)->err->msg_code = (code); \
  151164. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151165. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151166. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151167. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151168. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151169. (cinfo)->err->msg_code = (code); \
  151170. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151171. #define TRACEMSS(cinfo,lvl,code,str) \
  151172. ((cinfo)->err->msg_code = (code), \
  151173. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151174. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151175. #endif /* JERROR_H */
  151176. /*** End of inlined file: jerror.h ***/
  151177. typedef struct {
  151178. struct jpeg_source_mgr pub; /* public fields */
  151179. FILE * infile; /* source stream */
  151180. JOCTET * buffer; /* start of buffer */
  151181. boolean start_of_file; /* have we gotten any data yet? */
  151182. } my_source_mgr;
  151183. typedef my_source_mgr * my_src_ptr;
  151184. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151185. METHODDEF(void)
  151186. init_source (j_decompress_ptr cinfo)
  151187. {
  151188. my_src_ptr src = (my_src_ptr) cinfo->src;
  151189. src->start_of_file = TRUE;
  151190. }
  151191. METHODDEF(boolean)
  151192. fill_input_buffer (j_decompress_ptr cinfo)
  151193. {
  151194. my_src_ptr src = (my_src_ptr) cinfo->src;
  151195. size_t nbytes;
  151196. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151197. if (nbytes <= 0) {
  151198. if (src->start_of_file) /* Treat empty input file as fatal error */
  151199. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151200. WARNMS(cinfo, JWRN_JPEG_EOF);
  151201. src->buffer[0] = (JOCTET) 0xFF;
  151202. src->buffer[1] = (JOCTET) JPEG_EOI;
  151203. nbytes = 2;
  151204. }
  151205. src->pub.next_input_byte = src->buffer;
  151206. src->pub.bytes_in_buffer = nbytes;
  151207. src->start_of_file = FALSE;
  151208. return TRUE;
  151209. }
  151210. METHODDEF(void)
  151211. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151212. {
  151213. my_src_ptr src = (my_src_ptr) cinfo->src;
  151214. if (num_bytes > 0) {
  151215. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151216. num_bytes -= (long) src->pub.bytes_in_buffer;
  151217. (void) fill_input_buffer(cinfo);
  151218. }
  151219. src->pub.next_input_byte += (size_t) num_bytes;
  151220. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151221. }
  151222. }
  151223. METHODDEF(void)
  151224. term_source (j_decompress_ptr cinfo)
  151225. {
  151226. }
  151227. GLOBAL(void)
  151228. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151229. {
  151230. my_src_ptr src;
  151231. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151232. cinfo->src = (struct jpeg_source_mgr *)
  151233. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151234. SIZEOF(my_source_mgr));
  151235. src = (my_src_ptr) cinfo->src;
  151236. src->buffer = (JOCTET *)
  151237. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151238. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151239. }
  151240. src = (my_src_ptr) cinfo->src;
  151241. src->pub.init_source = init_source;
  151242. src->pub.fill_input_buffer = fill_input_buffer;
  151243. src->pub.skip_input_data = skip_input_data;
  151244. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151245. src->pub.term_source = term_source;
  151246. src->infile = infile;
  151247. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151248. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151249. }
  151250. /*** End of inlined file: jdatasrc.c ***/
  151251. /*** Start of inlined file: jdcoefct.c ***/
  151252. #define JPEG_INTERNALS
  151253. #ifndef D_PROGRESSIVE_SUPPORTED
  151254. #undef BLOCK_SMOOTHING_SUPPORTED
  151255. #endif
  151256. typedef struct {
  151257. struct jpeg_d_coef_controller pub; /* public fields */
  151258. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151259. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151260. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151261. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151262. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151263. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151264. #endif
  151265. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151266. int * coef_bits_latch;
  151267. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151268. #endif
  151269. } my_coef_controller3;
  151270. typedef my_coef_controller3 * my_coef_ptr3;
  151271. METHODDEF(int) decompress_onepass
  151272. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151273. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151274. METHODDEF(int) decompress_data
  151275. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151276. #endif
  151277. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151278. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151279. METHODDEF(int) decompress_smooth_data
  151280. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151281. #endif
  151282. LOCAL(void)
  151283. start_iMCU_row3 (j_decompress_ptr cinfo)
  151284. {
  151285. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151286. if (cinfo->comps_in_scan > 1) {
  151287. coef->MCU_rows_per_iMCU_row = 1;
  151288. } else {
  151289. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151290. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151291. else
  151292. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151293. }
  151294. coef->MCU_ctr = 0;
  151295. coef->MCU_vert_offset = 0;
  151296. }
  151297. METHODDEF(void)
  151298. start_input_pass (j_decompress_ptr cinfo)
  151299. {
  151300. cinfo->input_iMCU_row = 0;
  151301. start_iMCU_row3(cinfo);
  151302. }
  151303. METHODDEF(void)
  151304. start_output_pass (j_decompress_ptr cinfo)
  151305. {
  151306. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151307. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151308. if (coef->pub.coef_arrays != NULL) {
  151309. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151310. coef->pub.decompress_data = decompress_smooth_data;
  151311. else
  151312. coef->pub.decompress_data = decompress_data;
  151313. }
  151314. #endif
  151315. cinfo->output_iMCU_row = 0;
  151316. }
  151317. METHODDEF(int)
  151318. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151319. {
  151320. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151321. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151322. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151323. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151324. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151325. JSAMPARRAY output_ptr;
  151326. JDIMENSION start_col, output_col;
  151327. jpeg_component_info *compptr;
  151328. inverse_DCT_method_ptr inverse_DCT;
  151329. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151330. yoffset++) {
  151331. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151332. MCU_col_num++) {
  151333. jzero_far((void FAR *) coef->MCU_buffer[0],
  151334. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151335. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151336. coef->MCU_vert_offset = yoffset;
  151337. coef->MCU_ctr = MCU_col_num;
  151338. return JPEG_SUSPENDED;
  151339. }
  151340. blkn = 0; /* index of current DCT block within MCU */
  151341. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151342. compptr = cinfo->cur_comp_info[ci];
  151343. if (! compptr->component_needed) {
  151344. blkn += compptr->MCU_blocks;
  151345. continue;
  151346. }
  151347. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151348. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151349. : compptr->last_col_width;
  151350. output_ptr = output_buf[compptr->component_index] +
  151351. yoffset * compptr->DCT_scaled_size;
  151352. start_col = MCU_col_num * compptr->MCU_sample_width;
  151353. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151354. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151355. yoffset+yindex < compptr->last_row_height) {
  151356. output_col = start_col;
  151357. for (xindex = 0; xindex < useful_width; xindex++) {
  151358. (*inverse_DCT) (cinfo, compptr,
  151359. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151360. output_ptr, output_col);
  151361. output_col += compptr->DCT_scaled_size;
  151362. }
  151363. }
  151364. blkn += compptr->MCU_width;
  151365. output_ptr += compptr->DCT_scaled_size;
  151366. }
  151367. }
  151368. }
  151369. coef->MCU_ctr = 0;
  151370. }
  151371. cinfo->output_iMCU_row++;
  151372. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151373. start_iMCU_row3(cinfo);
  151374. return JPEG_ROW_COMPLETED;
  151375. }
  151376. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151377. return JPEG_SCAN_COMPLETED;
  151378. }
  151379. METHODDEF(int)
  151380. dummy_consume_data (j_decompress_ptr cinfo)
  151381. {
  151382. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151383. }
  151384. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151385. METHODDEF(int)
  151386. consume_data (j_decompress_ptr cinfo)
  151387. {
  151388. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151389. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151390. int blkn, ci, xindex, yindex, yoffset;
  151391. JDIMENSION start_col;
  151392. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151393. JBLOCKROW buffer_ptr;
  151394. jpeg_component_info *compptr;
  151395. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151396. compptr = cinfo->cur_comp_info[ci];
  151397. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151398. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151399. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151400. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151401. }
  151402. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151403. yoffset++) {
  151404. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151405. MCU_col_num++) {
  151406. blkn = 0; /* index of current DCT block within MCU */
  151407. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151408. compptr = cinfo->cur_comp_info[ci];
  151409. start_col = MCU_col_num * compptr->MCU_width;
  151410. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151411. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151412. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151413. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151414. }
  151415. }
  151416. }
  151417. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151418. coef->MCU_vert_offset = yoffset;
  151419. coef->MCU_ctr = MCU_col_num;
  151420. return JPEG_SUSPENDED;
  151421. }
  151422. }
  151423. coef->MCU_ctr = 0;
  151424. }
  151425. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151426. start_iMCU_row3(cinfo);
  151427. return JPEG_ROW_COMPLETED;
  151428. }
  151429. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151430. return JPEG_SCAN_COMPLETED;
  151431. }
  151432. METHODDEF(int)
  151433. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151434. {
  151435. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151436. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151437. JDIMENSION block_num;
  151438. int ci, block_row, block_rows;
  151439. JBLOCKARRAY buffer;
  151440. JBLOCKROW buffer_ptr;
  151441. JSAMPARRAY output_ptr;
  151442. JDIMENSION output_col;
  151443. jpeg_component_info *compptr;
  151444. inverse_DCT_method_ptr inverse_DCT;
  151445. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151446. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151447. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151448. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151449. return JPEG_SUSPENDED;
  151450. }
  151451. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151452. ci++, compptr++) {
  151453. if (! compptr->component_needed)
  151454. continue;
  151455. buffer = (*cinfo->mem->access_virt_barray)
  151456. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151457. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151458. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151459. if (cinfo->output_iMCU_row < last_iMCU_row)
  151460. block_rows = compptr->v_samp_factor;
  151461. else {
  151462. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151463. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151464. }
  151465. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151466. output_ptr = output_buf[ci];
  151467. for (block_row = 0; block_row < block_rows; block_row++) {
  151468. buffer_ptr = buffer[block_row];
  151469. output_col = 0;
  151470. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151471. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151472. output_ptr, output_col);
  151473. buffer_ptr++;
  151474. output_col += compptr->DCT_scaled_size;
  151475. }
  151476. output_ptr += compptr->DCT_scaled_size;
  151477. }
  151478. }
  151479. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151480. return JPEG_ROW_COMPLETED;
  151481. return JPEG_SCAN_COMPLETED;
  151482. }
  151483. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151484. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151485. #define Q01_POS 1
  151486. #define Q10_POS 8
  151487. #define Q20_POS 16
  151488. #define Q11_POS 9
  151489. #define Q02_POS 2
  151490. LOCAL(boolean)
  151491. smoothing_ok (j_decompress_ptr cinfo)
  151492. {
  151493. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151494. boolean smoothing_useful = FALSE;
  151495. int ci, coefi;
  151496. jpeg_component_info *compptr;
  151497. JQUANT_TBL * qtable;
  151498. int * coef_bits;
  151499. int * coef_bits_latch;
  151500. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151501. return FALSE;
  151502. if (coef->coef_bits_latch == NULL)
  151503. coef->coef_bits_latch = (int *)
  151504. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151505. cinfo->num_components *
  151506. (SAVED_COEFS * SIZEOF(int)));
  151507. coef_bits_latch = coef->coef_bits_latch;
  151508. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151509. ci++, compptr++) {
  151510. if ((qtable = compptr->quant_table) == NULL)
  151511. return FALSE;
  151512. if (qtable->quantval[0] == 0 ||
  151513. qtable->quantval[Q01_POS] == 0 ||
  151514. qtable->quantval[Q10_POS] == 0 ||
  151515. qtable->quantval[Q20_POS] == 0 ||
  151516. qtable->quantval[Q11_POS] == 0 ||
  151517. qtable->quantval[Q02_POS] == 0)
  151518. return FALSE;
  151519. coef_bits = cinfo->coef_bits[ci];
  151520. if (coef_bits[0] < 0)
  151521. return FALSE;
  151522. for (coefi = 1; coefi <= 5; coefi++) {
  151523. coef_bits_latch[coefi] = coef_bits[coefi];
  151524. if (coef_bits[coefi] != 0)
  151525. smoothing_useful = TRUE;
  151526. }
  151527. coef_bits_latch += SAVED_COEFS;
  151528. }
  151529. return smoothing_useful;
  151530. }
  151531. METHODDEF(int)
  151532. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151533. {
  151534. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151535. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151536. JDIMENSION block_num, last_block_column;
  151537. int ci, block_row, block_rows, access_rows;
  151538. JBLOCKARRAY buffer;
  151539. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151540. JSAMPARRAY output_ptr;
  151541. JDIMENSION output_col;
  151542. jpeg_component_info *compptr;
  151543. inverse_DCT_method_ptr inverse_DCT;
  151544. boolean first_row, last_row;
  151545. JBLOCK workspace;
  151546. int *coef_bits;
  151547. JQUANT_TBL *quanttbl;
  151548. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151549. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151550. int Al, pred;
  151551. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151552. ! cinfo->inputctl->eoi_reached) {
  151553. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151554. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151555. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151556. break;
  151557. }
  151558. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151559. return JPEG_SUSPENDED;
  151560. }
  151561. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151562. ci++, compptr++) {
  151563. if (! compptr->component_needed)
  151564. continue;
  151565. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151566. block_rows = compptr->v_samp_factor;
  151567. access_rows = block_rows * 2; /* this and next iMCU row */
  151568. last_row = FALSE;
  151569. } else {
  151570. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151571. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151572. access_rows = block_rows; /* this iMCU row only */
  151573. last_row = TRUE;
  151574. }
  151575. if (cinfo->output_iMCU_row > 0) {
  151576. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151577. buffer = (*cinfo->mem->access_virt_barray)
  151578. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151579. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151580. (JDIMENSION) access_rows, FALSE);
  151581. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151582. first_row = FALSE;
  151583. } else {
  151584. buffer = (*cinfo->mem->access_virt_barray)
  151585. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151586. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151587. first_row = TRUE;
  151588. }
  151589. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151590. quanttbl = compptr->quant_table;
  151591. Q00 = quanttbl->quantval[0];
  151592. Q01 = quanttbl->quantval[Q01_POS];
  151593. Q10 = quanttbl->quantval[Q10_POS];
  151594. Q20 = quanttbl->quantval[Q20_POS];
  151595. Q11 = quanttbl->quantval[Q11_POS];
  151596. Q02 = quanttbl->quantval[Q02_POS];
  151597. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151598. output_ptr = output_buf[ci];
  151599. for (block_row = 0; block_row < block_rows; block_row++) {
  151600. buffer_ptr = buffer[block_row];
  151601. if (first_row && block_row == 0)
  151602. prev_block_row = buffer_ptr;
  151603. else
  151604. prev_block_row = buffer[block_row-1];
  151605. if (last_row && block_row == block_rows-1)
  151606. next_block_row = buffer_ptr;
  151607. else
  151608. next_block_row = buffer[block_row+1];
  151609. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151610. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151611. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151612. output_col = 0;
  151613. last_block_column = compptr->width_in_blocks - 1;
  151614. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151615. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151616. if (block_num < last_block_column) {
  151617. DC3 = (int) prev_block_row[1][0];
  151618. DC6 = (int) buffer_ptr[1][0];
  151619. DC9 = (int) next_block_row[1][0];
  151620. }
  151621. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151622. num = 36 * Q00 * (DC4 - DC6);
  151623. if (num >= 0) {
  151624. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151625. if (Al > 0 && pred >= (1<<Al))
  151626. pred = (1<<Al)-1;
  151627. } else {
  151628. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151629. if (Al > 0 && pred >= (1<<Al))
  151630. pred = (1<<Al)-1;
  151631. pred = -pred;
  151632. }
  151633. workspace[1] = (JCOEF) pred;
  151634. }
  151635. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151636. num = 36 * Q00 * (DC2 - DC8);
  151637. if (num >= 0) {
  151638. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151639. if (Al > 0 && pred >= (1<<Al))
  151640. pred = (1<<Al)-1;
  151641. } else {
  151642. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151643. if (Al > 0 && pred >= (1<<Al))
  151644. pred = (1<<Al)-1;
  151645. pred = -pred;
  151646. }
  151647. workspace[8] = (JCOEF) pred;
  151648. }
  151649. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151650. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151651. if (num >= 0) {
  151652. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151653. if (Al > 0 && pred >= (1<<Al))
  151654. pred = (1<<Al)-1;
  151655. } else {
  151656. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151657. if (Al > 0 && pred >= (1<<Al))
  151658. pred = (1<<Al)-1;
  151659. pred = -pred;
  151660. }
  151661. workspace[16] = (JCOEF) pred;
  151662. }
  151663. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151664. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151665. if (num >= 0) {
  151666. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151667. if (Al > 0 && pred >= (1<<Al))
  151668. pred = (1<<Al)-1;
  151669. } else {
  151670. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151671. if (Al > 0 && pred >= (1<<Al))
  151672. pred = (1<<Al)-1;
  151673. pred = -pred;
  151674. }
  151675. workspace[9] = (JCOEF) pred;
  151676. }
  151677. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151678. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151679. if (num >= 0) {
  151680. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151681. if (Al > 0 && pred >= (1<<Al))
  151682. pred = (1<<Al)-1;
  151683. } else {
  151684. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151685. if (Al > 0 && pred >= (1<<Al))
  151686. pred = (1<<Al)-1;
  151687. pred = -pred;
  151688. }
  151689. workspace[2] = (JCOEF) pred;
  151690. }
  151691. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151692. output_ptr, output_col);
  151693. DC1 = DC2; DC2 = DC3;
  151694. DC4 = DC5; DC5 = DC6;
  151695. DC7 = DC8; DC8 = DC9;
  151696. buffer_ptr++, prev_block_row++, next_block_row++;
  151697. output_col += compptr->DCT_scaled_size;
  151698. }
  151699. output_ptr += compptr->DCT_scaled_size;
  151700. }
  151701. }
  151702. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151703. return JPEG_ROW_COMPLETED;
  151704. return JPEG_SCAN_COMPLETED;
  151705. }
  151706. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151707. GLOBAL(void)
  151708. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151709. {
  151710. my_coef_ptr3 coef;
  151711. coef = (my_coef_ptr3)
  151712. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151713. SIZEOF(my_coef_controller3));
  151714. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151715. coef->pub.start_input_pass = start_input_pass;
  151716. coef->pub.start_output_pass = start_output_pass;
  151717. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151718. coef->coef_bits_latch = NULL;
  151719. #endif
  151720. if (need_full_buffer) {
  151721. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151722. int ci, access_rows;
  151723. jpeg_component_info *compptr;
  151724. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151725. ci++, compptr++) {
  151726. access_rows = compptr->v_samp_factor;
  151727. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151728. if (cinfo->progressive_mode)
  151729. access_rows *= 3;
  151730. #endif
  151731. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151732. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151733. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151734. (long) compptr->h_samp_factor),
  151735. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151736. (long) compptr->v_samp_factor),
  151737. (JDIMENSION) access_rows);
  151738. }
  151739. coef->pub.consume_data = consume_data;
  151740. coef->pub.decompress_data = decompress_data;
  151741. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151742. #else
  151743. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151744. #endif
  151745. } else {
  151746. JBLOCKROW buffer;
  151747. int i;
  151748. buffer = (JBLOCKROW)
  151749. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151750. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151751. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151752. coef->MCU_buffer[i] = buffer + i;
  151753. }
  151754. coef->pub.consume_data = dummy_consume_data;
  151755. coef->pub.decompress_data = decompress_onepass;
  151756. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151757. }
  151758. }
  151759. /*** End of inlined file: jdcoefct.c ***/
  151760. #undef FIX
  151761. /*** Start of inlined file: jdcolor.c ***/
  151762. #define JPEG_INTERNALS
  151763. typedef struct {
  151764. struct jpeg_color_deconverter pub; /* public fields */
  151765. int * Cr_r_tab; /* => table for Cr to R conversion */
  151766. int * Cb_b_tab; /* => table for Cb to B conversion */
  151767. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151768. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151769. } my_color_deconverter2;
  151770. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151771. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151772. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151773. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151774. LOCAL(void)
  151775. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151776. {
  151777. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151778. int i;
  151779. INT32 x;
  151780. SHIFT_TEMPS
  151781. cconvert->Cr_r_tab = (int *)
  151782. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151783. (MAXJSAMPLE+1) * SIZEOF(int));
  151784. cconvert->Cb_b_tab = (int *)
  151785. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151786. (MAXJSAMPLE+1) * SIZEOF(int));
  151787. cconvert->Cr_g_tab = (INT32 *)
  151788. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151789. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151790. cconvert->Cb_g_tab = (INT32 *)
  151791. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151792. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151793. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151794. cconvert->Cr_r_tab[i] = (int)
  151795. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151796. cconvert->Cb_b_tab[i] = (int)
  151797. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151798. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151799. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151800. }
  151801. }
  151802. METHODDEF(void)
  151803. ycc_rgb_convert (j_decompress_ptr cinfo,
  151804. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151805. JSAMPARRAY output_buf, int num_rows)
  151806. {
  151807. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151808. register int y, cb, cr;
  151809. register JSAMPROW outptr;
  151810. register JSAMPROW inptr0, inptr1, inptr2;
  151811. register JDIMENSION col;
  151812. JDIMENSION num_cols = cinfo->output_width;
  151813. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151814. register int * Crrtab = cconvert->Cr_r_tab;
  151815. register int * Cbbtab = cconvert->Cb_b_tab;
  151816. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151817. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151818. SHIFT_TEMPS
  151819. while (--num_rows >= 0) {
  151820. inptr0 = input_buf[0][input_row];
  151821. inptr1 = input_buf[1][input_row];
  151822. inptr2 = input_buf[2][input_row];
  151823. input_row++;
  151824. outptr = *output_buf++;
  151825. for (col = 0; col < num_cols; col++) {
  151826. y = GETJSAMPLE(inptr0[col]);
  151827. cb = GETJSAMPLE(inptr1[col]);
  151828. cr = GETJSAMPLE(inptr2[col]);
  151829. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151830. outptr[RGB_GREEN] = range_limit[y +
  151831. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151832. SCALEBITS))];
  151833. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151834. outptr += RGB_PIXELSIZE;
  151835. }
  151836. }
  151837. }
  151838. METHODDEF(void)
  151839. null_convert2 (j_decompress_ptr cinfo,
  151840. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151841. JSAMPARRAY output_buf, int num_rows)
  151842. {
  151843. register JSAMPROW inptr, outptr;
  151844. register JDIMENSION count;
  151845. register int num_components = cinfo->num_components;
  151846. JDIMENSION num_cols = cinfo->output_width;
  151847. int ci;
  151848. while (--num_rows >= 0) {
  151849. for (ci = 0; ci < num_components; ci++) {
  151850. inptr = input_buf[ci][input_row];
  151851. outptr = output_buf[0] + ci;
  151852. for (count = num_cols; count > 0; count--) {
  151853. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151854. outptr += num_components;
  151855. }
  151856. }
  151857. input_row++;
  151858. output_buf++;
  151859. }
  151860. }
  151861. METHODDEF(void)
  151862. grayscale_convert2 (j_decompress_ptr cinfo,
  151863. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151864. JSAMPARRAY output_buf, int num_rows)
  151865. {
  151866. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151867. num_rows, cinfo->output_width);
  151868. }
  151869. METHODDEF(void)
  151870. gray_rgb_convert (j_decompress_ptr cinfo,
  151871. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151872. JSAMPARRAY output_buf, int num_rows)
  151873. {
  151874. register JSAMPROW inptr, outptr;
  151875. register JDIMENSION col;
  151876. JDIMENSION num_cols = cinfo->output_width;
  151877. while (--num_rows >= 0) {
  151878. inptr = input_buf[0][input_row++];
  151879. outptr = *output_buf++;
  151880. for (col = 0; col < num_cols; col++) {
  151881. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151882. outptr += RGB_PIXELSIZE;
  151883. }
  151884. }
  151885. }
  151886. METHODDEF(void)
  151887. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151888. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151889. JSAMPARRAY output_buf, int num_rows)
  151890. {
  151891. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151892. register int y, cb, cr;
  151893. register JSAMPROW outptr;
  151894. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151895. register JDIMENSION col;
  151896. JDIMENSION num_cols = cinfo->output_width;
  151897. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151898. register int * Crrtab = cconvert->Cr_r_tab;
  151899. register int * Cbbtab = cconvert->Cb_b_tab;
  151900. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151901. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151902. SHIFT_TEMPS
  151903. while (--num_rows >= 0) {
  151904. inptr0 = input_buf[0][input_row];
  151905. inptr1 = input_buf[1][input_row];
  151906. inptr2 = input_buf[2][input_row];
  151907. inptr3 = input_buf[3][input_row];
  151908. input_row++;
  151909. outptr = *output_buf++;
  151910. for (col = 0; col < num_cols; col++) {
  151911. y = GETJSAMPLE(inptr0[col]);
  151912. cb = GETJSAMPLE(inptr1[col]);
  151913. cr = GETJSAMPLE(inptr2[col]);
  151914. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151915. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151916. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151917. SCALEBITS)))];
  151918. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151919. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151920. outptr += 4;
  151921. }
  151922. }
  151923. }
  151924. METHODDEF(void)
  151925. start_pass_dcolor (j_decompress_ptr cinfo)
  151926. {
  151927. }
  151928. GLOBAL(void)
  151929. jinit_color_deconverter (j_decompress_ptr cinfo)
  151930. {
  151931. my_cconvert_ptr2 cconvert;
  151932. int ci;
  151933. cconvert = (my_cconvert_ptr2)
  151934. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151935. SIZEOF(my_color_deconverter2));
  151936. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151937. cconvert->pub.start_pass = start_pass_dcolor;
  151938. switch (cinfo->jpeg_color_space) {
  151939. case JCS_GRAYSCALE:
  151940. if (cinfo->num_components != 1)
  151941. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151942. break;
  151943. case JCS_RGB:
  151944. case JCS_YCbCr:
  151945. if (cinfo->num_components != 3)
  151946. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151947. break;
  151948. case JCS_CMYK:
  151949. case JCS_YCCK:
  151950. if (cinfo->num_components != 4)
  151951. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151952. break;
  151953. default: /* JCS_UNKNOWN can be anything */
  151954. if (cinfo->num_components < 1)
  151955. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151956. break;
  151957. }
  151958. switch (cinfo->out_color_space) {
  151959. case JCS_GRAYSCALE:
  151960. cinfo->out_color_components = 1;
  151961. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151962. cinfo->jpeg_color_space == JCS_YCbCr) {
  151963. cconvert->pub.color_convert = grayscale_convert2;
  151964. for (ci = 1; ci < cinfo->num_components; ci++)
  151965. cinfo->comp_info[ci].component_needed = FALSE;
  151966. } else
  151967. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151968. break;
  151969. case JCS_RGB:
  151970. cinfo->out_color_components = RGB_PIXELSIZE;
  151971. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151972. cconvert->pub.color_convert = ycc_rgb_convert;
  151973. build_ycc_rgb_table(cinfo);
  151974. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151975. cconvert->pub.color_convert = gray_rgb_convert;
  151976. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151977. cconvert->pub.color_convert = null_convert2;
  151978. } else
  151979. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151980. break;
  151981. case JCS_CMYK:
  151982. cinfo->out_color_components = 4;
  151983. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151984. cconvert->pub.color_convert = ycck_cmyk_convert;
  151985. build_ycc_rgb_table(cinfo);
  151986. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151987. cconvert->pub.color_convert = null_convert2;
  151988. } else
  151989. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151990. break;
  151991. default:
  151992. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151993. cinfo->out_color_components = cinfo->num_components;
  151994. cconvert->pub.color_convert = null_convert2;
  151995. } else /* unsupported non-null conversion */
  151996. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151997. break;
  151998. }
  151999. if (cinfo->quantize_colors)
  152000. cinfo->output_components = 1; /* single colormapped output component */
  152001. else
  152002. cinfo->output_components = cinfo->out_color_components;
  152003. }
  152004. /*** End of inlined file: jdcolor.c ***/
  152005. #undef FIX
  152006. /*** Start of inlined file: jddctmgr.c ***/
  152007. #define JPEG_INTERNALS
  152008. typedef struct {
  152009. struct jpeg_inverse_dct pub; /* public fields */
  152010. int cur_method[MAX_COMPONENTS];
  152011. } my_idct_controller;
  152012. typedef my_idct_controller * my_idct_ptr;
  152013. typedef union {
  152014. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  152015. #ifdef DCT_IFAST_SUPPORTED
  152016. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  152017. #endif
  152018. #ifdef DCT_FLOAT_SUPPORTED
  152019. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  152020. #endif
  152021. } multiplier_table;
  152022. #ifdef DCT_ISLOW_SUPPORTED
  152023. #define PROVIDE_ISLOW_TABLES
  152024. #else
  152025. #ifdef IDCT_SCALING_SUPPORTED
  152026. #define PROVIDE_ISLOW_TABLES
  152027. #endif
  152028. #endif
  152029. METHODDEF(void)
  152030. start_pass (j_decompress_ptr cinfo)
  152031. {
  152032. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  152033. int ci, i;
  152034. jpeg_component_info *compptr;
  152035. int method = 0;
  152036. inverse_DCT_method_ptr method_ptr = NULL;
  152037. JQUANT_TBL * qtbl;
  152038. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152039. ci++, compptr++) {
  152040. switch (compptr->DCT_scaled_size) {
  152041. #ifdef IDCT_SCALING_SUPPORTED
  152042. case 1:
  152043. method_ptr = jpeg_idct_1x1;
  152044. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152045. break;
  152046. case 2:
  152047. method_ptr = jpeg_idct_2x2;
  152048. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152049. break;
  152050. case 4:
  152051. method_ptr = jpeg_idct_4x4;
  152052. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152053. break;
  152054. #endif
  152055. case DCTSIZE:
  152056. switch (cinfo->dct_method) {
  152057. #ifdef DCT_ISLOW_SUPPORTED
  152058. case JDCT_ISLOW:
  152059. method_ptr = jpeg_idct_islow;
  152060. method = JDCT_ISLOW;
  152061. break;
  152062. #endif
  152063. #ifdef DCT_IFAST_SUPPORTED
  152064. case JDCT_IFAST:
  152065. method_ptr = jpeg_idct_ifast;
  152066. method = JDCT_IFAST;
  152067. break;
  152068. #endif
  152069. #ifdef DCT_FLOAT_SUPPORTED
  152070. case JDCT_FLOAT:
  152071. method_ptr = jpeg_idct_float;
  152072. method = JDCT_FLOAT;
  152073. break;
  152074. #endif
  152075. default:
  152076. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152077. break;
  152078. }
  152079. break;
  152080. default:
  152081. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  152082. break;
  152083. }
  152084. idct->pub.inverse_DCT[ci] = method_ptr;
  152085. if (! compptr->component_needed || idct->cur_method[ci] == method)
  152086. continue;
  152087. qtbl = compptr->quant_table;
  152088. if (qtbl == NULL) /* happens if no data yet for component */
  152089. continue;
  152090. idct->cur_method[ci] = method;
  152091. switch (method) {
  152092. #ifdef PROVIDE_ISLOW_TABLES
  152093. case JDCT_ISLOW:
  152094. {
  152095. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  152096. for (i = 0; i < DCTSIZE2; i++) {
  152097. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152098. }
  152099. }
  152100. break;
  152101. #endif
  152102. #ifdef DCT_IFAST_SUPPORTED
  152103. case JDCT_IFAST:
  152104. {
  152105. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152106. #define CONST_BITS 14
  152107. static const INT16 aanscales[DCTSIZE2] = {
  152108. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152109. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152110. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152111. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152112. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152113. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152114. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152115. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152116. };
  152117. SHIFT_TEMPS
  152118. for (i = 0; i < DCTSIZE2; i++) {
  152119. ifmtbl[i] = (IFAST_MULT_TYPE)
  152120. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152121. (INT32) aanscales[i]),
  152122. CONST_BITS-IFAST_SCALE_BITS);
  152123. }
  152124. }
  152125. break;
  152126. #endif
  152127. #ifdef DCT_FLOAT_SUPPORTED
  152128. case JDCT_FLOAT:
  152129. {
  152130. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152131. int row, col;
  152132. static const double aanscalefactor[DCTSIZE] = {
  152133. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152134. 1.0, 0.785694958, 0.541196100, 0.275899379
  152135. };
  152136. i = 0;
  152137. for (row = 0; row < DCTSIZE; row++) {
  152138. for (col = 0; col < DCTSIZE; col++) {
  152139. fmtbl[i] = (FLOAT_MULT_TYPE)
  152140. ((double) qtbl->quantval[i] *
  152141. aanscalefactor[row] * aanscalefactor[col]);
  152142. i++;
  152143. }
  152144. }
  152145. }
  152146. break;
  152147. #endif
  152148. default:
  152149. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152150. break;
  152151. }
  152152. }
  152153. }
  152154. GLOBAL(void)
  152155. jinit_inverse_dct (j_decompress_ptr cinfo)
  152156. {
  152157. my_idct_ptr idct;
  152158. int ci;
  152159. jpeg_component_info *compptr;
  152160. idct = (my_idct_ptr)
  152161. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152162. SIZEOF(my_idct_controller));
  152163. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152164. idct->pub.start_pass = start_pass;
  152165. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152166. ci++, compptr++) {
  152167. compptr->dct_table =
  152168. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152169. SIZEOF(multiplier_table));
  152170. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152171. idct->cur_method[ci] = -1;
  152172. }
  152173. }
  152174. /*** End of inlined file: jddctmgr.c ***/
  152175. #undef CONST_BITS
  152176. #undef ASSIGN_STATE
  152177. /*** Start of inlined file: jdhuff.c ***/
  152178. #define JPEG_INTERNALS
  152179. /*** Start of inlined file: jdhuff.h ***/
  152180. #ifndef __jdhuff_h__
  152181. #define __jdhuff_h__
  152182. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152183. #define jpeg_make_d_derived_tbl jMkDDerived
  152184. #define jpeg_fill_bit_buffer jFilBitBuf
  152185. #define jpeg_huff_decode jHufDecode
  152186. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152187. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152188. typedef struct {
  152189. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152190. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152191. JHUFF_TBL *pub;
  152192. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152193. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152194. } d_derived_tbl;
  152195. EXTERN(void) jpeg_make_d_derived_tbl
  152196. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152197. d_derived_tbl ** pdtbl));
  152198. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152199. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152200. typedef struct { /* Bitreading state saved across MCUs */
  152201. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152202. int bits_left; /* # of unused bits in it */
  152203. } bitread_perm_state;
  152204. typedef struct { /* Bitreading working state within an MCU */
  152205. const JOCTET * next_input_byte; /* => next byte to read from source */
  152206. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152207. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152208. int bits_left; /* # of unused bits in it */
  152209. j_decompress_ptr cinfo; /* back link to decompress master record */
  152210. } bitread_working_state;
  152211. #define BITREAD_STATE_VARS \
  152212. register bit_buf_type get_buffer; \
  152213. register int bits_left; \
  152214. bitread_working_state br_state
  152215. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152216. br_state.cinfo = cinfop; \
  152217. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152218. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152219. get_buffer = permstate.get_buffer; \
  152220. bits_left = permstate.bits_left;
  152221. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152222. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152223. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152224. permstate.get_buffer = get_buffer; \
  152225. permstate.bits_left = bits_left
  152226. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152227. { if (bits_left < (nbits)) { \
  152228. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152229. { action; } \
  152230. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152231. #define GET_BITS(nbits) \
  152232. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152233. #define PEEK_BITS(nbits) \
  152234. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152235. #define DROP_BITS(nbits) \
  152236. (bits_left -= (nbits))
  152237. EXTERN(boolean) jpeg_fill_bit_buffer
  152238. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152239. register int bits_left, int nbits));
  152240. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152241. { register int nb, look; \
  152242. if (bits_left < HUFF_LOOKAHEAD) { \
  152243. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152244. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152245. if (bits_left < HUFF_LOOKAHEAD) { \
  152246. nb = 1; goto slowlabel; \
  152247. } \
  152248. } \
  152249. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152250. if ((nb = htbl->look_nbits[look]) != 0) { \
  152251. DROP_BITS(nb); \
  152252. result = htbl->look_sym[look]; \
  152253. } else { \
  152254. nb = HUFF_LOOKAHEAD+1; \
  152255. slowlabel: \
  152256. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152257. { failaction; } \
  152258. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152259. } \
  152260. }
  152261. EXTERN(int) jpeg_huff_decode
  152262. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152263. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152264. #endif
  152265. /*** End of inlined file: jdhuff.h ***/
  152266. /* Declarations shared with jdphuff.c */
  152267. typedef struct {
  152268. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152269. } savable_state2;
  152270. #ifndef NO_STRUCT_ASSIGN
  152271. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152272. #else
  152273. #if MAX_COMPS_IN_SCAN == 4
  152274. #define ASSIGN_STATE(dest,src) \
  152275. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152276. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152277. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152278. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152279. #endif
  152280. #endif
  152281. typedef struct {
  152282. struct jpeg_entropy_decoder pub; /* public fields */
  152283. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152284. savable_state2 saved; /* Other state at start of MCU */
  152285. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152286. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152287. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152288. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152289. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152290. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152291. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152292. } huff_entropy_decoder2;
  152293. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152294. METHODDEF(void)
  152295. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152296. {
  152297. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152298. int ci, blkn, dctbl, actbl;
  152299. jpeg_component_info * compptr;
  152300. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152301. cinfo->Ah != 0 || cinfo->Al != 0)
  152302. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152303. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152304. compptr = cinfo->cur_comp_info[ci];
  152305. dctbl = compptr->dc_tbl_no;
  152306. actbl = compptr->ac_tbl_no;
  152307. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152308. & entropy->dc_derived_tbls[dctbl]);
  152309. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152310. & entropy->ac_derived_tbls[actbl]);
  152311. entropy->saved.last_dc_val[ci] = 0;
  152312. }
  152313. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152314. ci = cinfo->MCU_membership[blkn];
  152315. compptr = cinfo->cur_comp_info[ci];
  152316. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152317. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152318. if (compptr->component_needed) {
  152319. entropy->dc_needed[blkn] = TRUE;
  152320. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152321. } else {
  152322. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152323. }
  152324. }
  152325. entropy->bitstate.bits_left = 0;
  152326. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152327. entropy->pub.insufficient_data = FALSE;
  152328. entropy->restarts_to_go = cinfo->restart_interval;
  152329. }
  152330. GLOBAL(void)
  152331. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152332. d_derived_tbl ** pdtbl)
  152333. {
  152334. JHUFF_TBL *htbl;
  152335. d_derived_tbl *dtbl;
  152336. int p, i, l, si, numsymbols;
  152337. int lookbits, ctr;
  152338. char huffsize[257];
  152339. unsigned int huffcode[257];
  152340. unsigned int code;
  152341. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152342. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152343. htbl =
  152344. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152345. if (htbl == NULL)
  152346. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152347. if (*pdtbl == NULL)
  152348. *pdtbl = (d_derived_tbl *)
  152349. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152350. SIZEOF(d_derived_tbl));
  152351. dtbl = *pdtbl;
  152352. dtbl->pub = htbl; /* fill in back link */
  152353. p = 0;
  152354. for (l = 1; l <= 16; l++) {
  152355. i = (int) htbl->bits[l];
  152356. if (i < 0 || p + i > 256) /* protect against table overrun */
  152357. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152358. while (i--)
  152359. huffsize[p++] = (char) l;
  152360. }
  152361. huffsize[p] = 0;
  152362. numsymbols = p;
  152363. code = 0;
  152364. si = huffsize[0];
  152365. p = 0;
  152366. while (huffsize[p]) {
  152367. while (((int) huffsize[p]) == si) {
  152368. huffcode[p++] = code;
  152369. code++;
  152370. }
  152371. if (((INT32) code) >= (((INT32) 1) << si))
  152372. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152373. code <<= 1;
  152374. si++;
  152375. }
  152376. p = 0;
  152377. for (l = 1; l <= 16; l++) {
  152378. if (htbl->bits[l]) {
  152379. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152380. p += htbl->bits[l];
  152381. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152382. } else {
  152383. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152384. }
  152385. }
  152386. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152387. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152388. p = 0;
  152389. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152390. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152391. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152392. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152393. dtbl->look_nbits[lookbits] = l;
  152394. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152395. lookbits++;
  152396. }
  152397. }
  152398. }
  152399. if (isDC) {
  152400. for (i = 0; i < numsymbols; i++) {
  152401. int sym = htbl->huffval[i];
  152402. if (sym < 0 || sym > 15)
  152403. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152404. }
  152405. }
  152406. }
  152407. #ifdef SLOW_SHIFT_32
  152408. #define MIN_GET_BITS 15 /* minimum allowable value */
  152409. #else
  152410. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152411. #endif
  152412. GLOBAL(boolean)
  152413. jpeg_fill_bit_buffer (bitread_working_state * state,
  152414. register bit_buf_type get_buffer, register int bits_left,
  152415. int nbits)
  152416. {
  152417. register const JOCTET * next_input_byte = state->next_input_byte;
  152418. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152419. j_decompress_ptr cinfo = state->cinfo;
  152420. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152421. while (bits_left < MIN_GET_BITS) {
  152422. register int c;
  152423. if (bytes_in_buffer == 0) {
  152424. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152425. return FALSE;
  152426. next_input_byte = cinfo->src->next_input_byte;
  152427. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152428. }
  152429. bytes_in_buffer--;
  152430. c = GETJOCTET(*next_input_byte++);
  152431. if (c == 0xFF) {
  152432. do {
  152433. if (bytes_in_buffer == 0) {
  152434. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152435. return FALSE;
  152436. next_input_byte = cinfo->src->next_input_byte;
  152437. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152438. }
  152439. bytes_in_buffer--;
  152440. c = GETJOCTET(*next_input_byte++);
  152441. } while (c == 0xFF);
  152442. if (c == 0) {
  152443. c = 0xFF;
  152444. } else {
  152445. cinfo->unread_marker = c;
  152446. goto no_more_bytes;
  152447. }
  152448. }
  152449. get_buffer = (get_buffer << 8) | c;
  152450. bits_left += 8;
  152451. } /* end while */
  152452. } else {
  152453. no_more_bytes:
  152454. if (nbits > bits_left) {
  152455. if (! cinfo->entropy->insufficient_data) {
  152456. WARNMS(cinfo, JWRN_HIT_MARKER);
  152457. cinfo->entropy->insufficient_data = TRUE;
  152458. }
  152459. get_buffer <<= MIN_GET_BITS - bits_left;
  152460. bits_left = MIN_GET_BITS;
  152461. }
  152462. }
  152463. state->next_input_byte = next_input_byte;
  152464. state->bytes_in_buffer = bytes_in_buffer;
  152465. state->get_buffer = get_buffer;
  152466. state->bits_left = bits_left;
  152467. return TRUE;
  152468. }
  152469. GLOBAL(int)
  152470. jpeg_huff_decode (bitread_working_state * state,
  152471. register bit_buf_type get_buffer, register int bits_left,
  152472. d_derived_tbl * htbl, int min_bits)
  152473. {
  152474. register int l = min_bits;
  152475. register INT32 code;
  152476. CHECK_BIT_BUFFER(*state, l, return -1);
  152477. code = GET_BITS(l);
  152478. while (code > htbl->maxcode[l]) {
  152479. code <<= 1;
  152480. CHECK_BIT_BUFFER(*state, 1, return -1);
  152481. code |= GET_BITS(1);
  152482. l++;
  152483. }
  152484. state->get_buffer = get_buffer;
  152485. state->bits_left = bits_left;
  152486. if (l > 16) {
  152487. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152488. return 0; /* fake a zero as the safest result */
  152489. }
  152490. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152491. }
  152492. LOCAL(boolean)
  152493. process_restart (j_decompress_ptr cinfo)
  152494. {
  152495. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152496. int ci;
  152497. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152498. entropy->bitstate.bits_left = 0;
  152499. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152500. return FALSE;
  152501. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152502. entropy->saved.last_dc_val[ci] = 0;
  152503. entropy->restarts_to_go = cinfo->restart_interval;
  152504. if (cinfo->unread_marker == 0)
  152505. entropy->pub.insufficient_data = FALSE;
  152506. return TRUE;
  152507. }
  152508. METHODDEF(boolean)
  152509. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152510. {
  152511. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152512. int blkn;
  152513. BITREAD_STATE_VARS;
  152514. savable_state2 state;
  152515. if (cinfo->restart_interval) {
  152516. if (entropy->restarts_to_go == 0)
  152517. if (! process_restart(cinfo))
  152518. return FALSE;
  152519. }
  152520. if (! entropy->pub.insufficient_data) {
  152521. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152522. ASSIGN_STATE(state, entropy->saved);
  152523. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152524. JBLOCKROW block = MCU_data[blkn];
  152525. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152526. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152527. register int s, k, r;
  152528. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152529. if (s) {
  152530. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152531. r = GET_BITS(s);
  152532. s = HUFF_EXTEND(r, s);
  152533. }
  152534. if (entropy->dc_needed[blkn]) {
  152535. int ci = cinfo->MCU_membership[blkn];
  152536. s += state.last_dc_val[ci];
  152537. state.last_dc_val[ci] = s;
  152538. (*block)[0] = (JCOEF) s;
  152539. }
  152540. if (entropy->ac_needed[blkn]) {
  152541. for (k = 1; k < DCTSIZE2; k++) {
  152542. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152543. r = s >> 4;
  152544. s &= 15;
  152545. if (s) {
  152546. k += r;
  152547. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152548. r = GET_BITS(s);
  152549. s = HUFF_EXTEND(r, s);
  152550. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152551. } else {
  152552. if (r != 15)
  152553. break;
  152554. k += 15;
  152555. }
  152556. }
  152557. } else {
  152558. for (k = 1; k < DCTSIZE2; k++) {
  152559. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152560. r = s >> 4;
  152561. s &= 15;
  152562. if (s) {
  152563. k += r;
  152564. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152565. DROP_BITS(s);
  152566. } else {
  152567. if (r != 15)
  152568. break;
  152569. k += 15;
  152570. }
  152571. }
  152572. }
  152573. }
  152574. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152575. ASSIGN_STATE(entropy->saved, state);
  152576. }
  152577. entropy->restarts_to_go--;
  152578. return TRUE;
  152579. }
  152580. GLOBAL(void)
  152581. jinit_huff_decoder (j_decompress_ptr cinfo)
  152582. {
  152583. huff_entropy_ptr2 entropy;
  152584. int i;
  152585. entropy = (huff_entropy_ptr2)
  152586. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152587. SIZEOF(huff_entropy_decoder2));
  152588. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152589. entropy->pub.start_pass = start_pass_huff_decoder;
  152590. entropy->pub.decode_mcu = decode_mcu;
  152591. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152592. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152593. }
  152594. }
  152595. /*** End of inlined file: jdhuff.c ***/
  152596. /*** Start of inlined file: jdinput.c ***/
  152597. #define JPEG_INTERNALS
  152598. typedef struct {
  152599. struct jpeg_input_controller pub; /* public fields */
  152600. boolean inheaders; /* TRUE until first SOS is reached */
  152601. } my_input_controller;
  152602. typedef my_input_controller * my_inputctl_ptr;
  152603. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152604. LOCAL(void)
  152605. initial_setup2 (j_decompress_ptr cinfo)
  152606. {
  152607. int ci;
  152608. jpeg_component_info *compptr;
  152609. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152610. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152611. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152612. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152613. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152614. if (cinfo->num_components > MAX_COMPONENTS)
  152615. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152616. MAX_COMPONENTS);
  152617. cinfo->max_h_samp_factor = 1;
  152618. cinfo->max_v_samp_factor = 1;
  152619. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152620. ci++, compptr++) {
  152621. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152622. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152623. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152624. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152625. compptr->h_samp_factor);
  152626. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152627. compptr->v_samp_factor);
  152628. }
  152629. cinfo->min_DCT_scaled_size = DCTSIZE;
  152630. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152631. ci++, compptr++) {
  152632. compptr->DCT_scaled_size = DCTSIZE;
  152633. compptr->width_in_blocks = (JDIMENSION)
  152634. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152635. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152636. compptr->height_in_blocks = (JDIMENSION)
  152637. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152638. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152639. compptr->downsampled_width = (JDIMENSION)
  152640. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152641. (long) cinfo->max_h_samp_factor);
  152642. compptr->downsampled_height = (JDIMENSION)
  152643. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152644. (long) cinfo->max_v_samp_factor);
  152645. compptr->component_needed = TRUE;
  152646. compptr->quant_table = NULL;
  152647. }
  152648. cinfo->total_iMCU_rows = (JDIMENSION)
  152649. jdiv_round_up((long) cinfo->image_height,
  152650. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152651. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152652. cinfo->inputctl->has_multiple_scans = TRUE;
  152653. else
  152654. cinfo->inputctl->has_multiple_scans = FALSE;
  152655. }
  152656. LOCAL(void)
  152657. per_scan_setup2 (j_decompress_ptr cinfo)
  152658. {
  152659. int ci, mcublks, tmp;
  152660. jpeg_component_info *compptr;
  152661. if (cinfo->comps_in_scan == 1) {
  152662. compptr = cinfo->cur_comp_info[0];
  152663. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152664. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152665. compptr->MCU_width = 1;
  152666. compptr->MCU_height = 1;
  152667. compptr->MCU_blocks = 1;
  152668. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152669. compptr->last_col_width = 1;
  152670. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152671. if (tmp == 0) tmp = compptr->v_samp_factor;
  152672. compptr->last_row_height = tmp;
  152673. cinfo->blocks_in_MCU = 1;
  152674. cinfo->MCU_membership[0] = 0;
  152675. } else {
  152676. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152677. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152678. MAX_COMPS_IN_SCAN);
  152679. cinfo->MCUs_per_row = (JDIMENSION)
  152680. jdiv_round_up((long) cinfo->image_width,
  152681. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152682. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152683. jdiv_round_up((long) cinfo->image_height,
  152684. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152685. cinfo->blocks_in_MCU = 0;
  152686. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152687. compptr = cinfo->cur_comp_info[ci];
  152688. compptr->MCU_width = compptr->h_samp_factor;
  152689. compptr->MCU_height = compptr->v_samp_factor;
  152690. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152691. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152692. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152693. if (tmp == 0) tmp = compptr->MCU_width;
  152694. compptr->last_col_width = tmp;
  152695. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152696. if (tmp == 0) tmp = compptr->MCU_height;
  152697. compptr->last_row_height = tmp;
  152698. mcublks = compptr->MCU_blocks;
  152699. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152700. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152701. while (mcublks-- > 0) {
  152702. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152703. }
  152704. }
  152705. }
  152706. }
  152707. LOCAL(void)
  152708. latch_quant_tables (j_decompress_ptr cinfo)
  152709. {
  152710. int ci, qtblno;
  152711. jpeg_component_info *compptr;
  152712. JQUANT_TBL * qtbl;
  152713. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152714. compptr = cinfo->cur_comp_info[ci];
  152715. if (compptr->quant_table != NULL)
  152716. continue;
  152717. qtblno = compptr->quant_tbl_no;
  152718. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152719. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152720. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152721. qtbl = (JQUANT_TBL *)
  152722. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152723. SIZEOF(JQUANT_TBL));
  152724. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152725. compptr->quant_table = qtbl;
  152726. }
  152727. }
  152728. METHODDEF(void)
  152729. start_input_pass2 (j_decompress_ptr cinfo)
  152730. {
  152731. per_scan_setup2(cinfo);
  152732. latch_quant_tables(cinfo);
  152733. (*cinfo->entropy->start_pass) (cinfo);
  152734. (*cinfo->coef->start_input_pass) (cinfo);
  152735. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152736. }
  152737. METHODDEF(void)
  152738. finish_input_pass (j_decompress_ptr cinfo)
  152739. {
  152740. cinfo->inputctl->consume_input = consume_markers;
  152741. }
  152742. METHODDEF(int)
  152743. consume_markers (j_decompress_ptr cinfo)
  152744. {
  152745. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152746. int val;
  152747. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152748. return JPEG_REACHED_EOI;
  152749. val = (*cinfo->marker->read_markers) (cinfo);
  152750. switch (val) {
  152751. case JPEG_REACHED_SOS: /* Found SOS */
  152752. if (inputctl->inheaders) { /* 1st SOS */
  152753. initial_setup2(cinfo);
  152754. inputctl->inheaders = FALSE;
  152755. } else { /* 2nd or later SOS marker */
  152756. if (! inputctl->pub.has_multiple_scans)
  152757. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152758. start_input_pass2(cinfo);
  152759. }
  152760. break;
  152761. case JPEG_REACHED_EOI: /* Found EOI */
  152762. inputctl->pub.eoi_reached = TRUE;
  152763. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152764. if (cinfo->marker->saw_SOF)
  152765. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152766. } else {
  152767. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152768. cinfo->output_scan_number = cinfo->input_scan_number;
  152769. }
  152770. break;
  152771. case JPEG_SUSPENDED:
  152772. break;
  152773. }
  152774. return val;
  152775. }
  152776. METHODDEF(void)
  152777. reset_input_controller (j_decompress_ptr cinfo)
  152778. {
  152779. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152780. inputctl->pub.consume_input = consume_markers;
  152781. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152782. inputctl->pub.eoi_reached = FALSE;
  152783. inputctl->inheaders = TRUE;
  152784. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152785. (*cinfo->marker->reset_marker_reader) (cinfo);
  152786. cinfo->coef_bits = NULL;
  152787. }
  152788. GLOBAL(void)
  152789. jinit_input_controller (j_decompress_ptr cinfo)
  152790. {
  152791. my_inputctl_ptr inputctl;
  152792. inputctl = (my_inputctl_ptr)
  152793. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152794. SIZEOF(my_input_controller));
  152795. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152796. inputctl->pub.consume_input = consume_markers;
  152797. inputctl->pub.reset_input_controller = reset_input_controller;
  152798. inputctl->pub.start_input_pass = start_input_pass2;
  152799. inputctl->pub.finish_input_pass = finish_input_pass;
  152800. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152801. inputctl->pub.eoi_reached = FALSE;
  152802. inputctl->inheaders = TRUE;
  152803. }
  152804. /*** End of inlined file: jdinput.c ***/
  152805. /*** Start of inlined file: jdmainct.c ***/
  152806. #define JPEG_INTERNALS
  152807. typedef struct {
  152808. struct jpeg_d_main_controller pub; /* public fields */
  152809. JSAMPARRAY buffer[MAX_COMPONENTS];
  152810. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152811. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152812. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152813. int whichptr; /* indicates which pointer set is now in use */
  152814. int context_state; /* process_data state machine status */
  152815. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152816. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152817. } my_main_controller4;
  152818. typedef my_main_controller4 * my_main_ptr4;
  152819. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152820. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152821. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152822. METHODDEF(void) process_data_simple_main2
  152823. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152824. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152825. METHODDEF(void) process_data_context_main
  152826. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152827. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152828. #ifdef QUANT_2PASS_SUPPORTED
  152829. METHODDEF(void) process_data_crank_post
  152830. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152831. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152832. #endif
  152833. LOCAL(void)
  152834. alloc_funny_pointers (j_decompress_ptr cinfo)
  152835. {
  152836. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152837. int ci, rgroup;
  152838. int M = cinfo->min_DCT_scaled_size;
  152839. jpeg_component_info *compptr;
  152840. JSAMPARRAY xbuf;
  152841. main_->xbuffer[0] = (JSAMPIMAGE)
  152842. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152843. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152844. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152845. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152846. ci++, compptr++) {
  152847. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152848. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152849. xbuf = (JSAMPARRAY)
  152850. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152851. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152852. xbuf += rgroup; /* want one row group at negative offsets */
  152853. main_->xbuffer[0][ci] = xbuf;
  152854. xbuf += rgroup * (M + 4);
  152855. main_->xbuffer[1][ci] = xbuf;
  152856. }
  152857. }
  152858. LOCAL(void)
  152859. make_funny_pointers (j_decompress_ptr cinfo)
  152860. {
  152861. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152862. int ci, i, rgroup;
  152863. int M = cinfo->min_DCT_scaled_size;
  152864. jpeg_component_info *compptr;
  152865. JSAMPARRAY buf, xbuf0, xbuf1;
  152866. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152867. ci++, compptr++) {
  152868. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152869. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152870. xbuf0 = main_->xbuffer[0][ci];
  152871. xbuf1 = main_->xbuffer[1][ci];
  152872. buf = main_->buffer[ci];
  152873. for (i = 0; i < rgroup * (M + 2); i++) {
  152874. xbuf0[i] = xbuf1[i] = buf[i];
  152875. }
  152876. for (i = 0; i < rgroup * 2; i++) {
  152877. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152878. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152879. }
  152880. for (i = 0; i < rgroup; i++) {
  152881. xbuf0[i - rgroup] = xbuf0[0];
  152882. }
  152883. }
  152884. }
  152885. LOCAL(void)
  152886. set_wraparound_pointers (j_decompress_ptr cinfo)
  152887. {
  152888. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152889. int ci, i, rgroup;
  152890. int M = cinfo->min_DCT_scaled_size;
  152891. jpeg_component_info *compptr;
  152892. JSAMPARRAY xbuf0, xbuf1;
  152893. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152894. ci++, compptr++) {
  152895. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152896. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152897. xbuf0 = main_->xbuffer[0][ci];
  152898. xbuf1 = main_->xbuffer[1][ci];
  152899. for (i = 0; i < rgroup; i++) {
  152900. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152901. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152902. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152903. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152904. }
  152905. }
  152906. }
  152907. LOCAL(void)
  152908. set_bottom_pointers (j_decompress_ptr cinfo)
  152909. {
  152910. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152911. int ci, i, rgroup, iMCUheight, rows_left;
  152912. jpeg_component_info *compptr;
  152913. JSAMPARRAY xbuf;
  152914. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152915. ci++, compptr++) {
  152916. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152917. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152918. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152919. if (rows_left == 0) rows_left = iMCUheight;
  152920. if (ci == 0) {
  152921. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152922. }
  152923. xbuf = main_->xbuffer[main_->whichptr][ci];
  152924. for (i = 0; i < rgroup * 2; i++) {
  152925. xbuf[rows_left + i] = xbuf[rows_left-1];
  152926. }
  152927. }
  152928. }
  152929. METHODDEF(void)
  152930. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152931. {
  152932. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152933. switch (pass_mode) {
  152934. case JBUF_PASS_THRU:
  152935. if (cinfo->upsample->need_context_rows) {
  152936. main_->pub.process_data = process_data_context_main;
  152937. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152938. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152939. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152940. main_->iMCU_row_ctr = 0;
  152941. } else {
  152942. main_->pub.process_data = process_data_simple_main2;
  152943. }
  152944. main_->buffer_full = FALSE; /* Mark buffer empty */
  152945. main_->rowgroup_ctr = 0;
  152946. break;
  152947. #ifdef QUANT_2PASS_SUPPORTED
  152948. case JBUF_CRANK_DEST:
  152949. main_->pub.process_data = process_data_crank_post;
  152950. break;
  152951. #endif
  152952. default:
  152953. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152954. break;
  152955. }
  152956. }
  152957. METHODDEF(void)
  152958. process_data_simple_main2 (j_decompress_ptr cinfo,
  152959. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152960. JDIMENSION out_rows_avail)
  152961. {
  152962. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152963. JDIMENSION rowgroups_avail;
  152964. if (! main_->buffer_full) {
  152965. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152966. return; /* suspension forced, can do nothing more */
  152967. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152968. }
  152969. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152970. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152971. &main_->rowgroup_ctr, rowgroups_avail,
  152972. output_buf, out_row_ctr, out_rows_avail);
  152973. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152974. main_->buffer_full = FALSE;
  152975. main_->rowgroup_ctr = 0;
  152976. }
  152977. }
  152978. METHODDEF(void)
  152979. process_data_context_main (j_decompress_ptr cinfo,
  152980. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152981. JDIMENSION out_rows_avail)
  152982. {
  152983. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152984. if (! main_->buffer_full) {
  152985. if (! (*cinfo->coef->decompress_data) (cinfo,
  152986. main_->xbuffer[main_->whichptr]))
  152987. return; /* suspension forced, can do nothing more */
  152988. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152989. main_->iMCU_row_ctr++; /* count rows received */
  152990. }
  152991. switch (main_->context_state) {
  152992. case CTX_POSTPONED_ROW:
  152993. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152994. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152995. output_buf, out_row_ctr, out_rows_avail);
  152996. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152997. return; /* Need to suspend */
  152998. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152999. if (*out_row_ctr >= out_rows_avail)
  153000. return; /* Postprocessor exactly filled output buf */
  153001. case CTX_PREPARE_FOR_IMCU:
  153002. main_->rowgroup_ctr = 0;
  153003. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  153004. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  153005. set_bottom_pointers(cinfo);
  153006. main_->context_state = CTX_PROCESS_IMCU;
  153007. case CTX_PROCESS_IMCU:
  153008. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153009. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153010. output_buf, out_row_ctr, out_rows_avail);
  153011. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153012. return; /* Need to suspend */
  153013. if (main_->iMCU_row_ctr == 1)
  153014. set_wraparound_pointers(cinfo);
  153015. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  153016. main_->buffer_full = FALSE;
  153017. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  153018. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  153019. main_->context_state = CTX_POSTPONED_ROW;
  153020. }
  153021. }
  153022. #ifdef QUANT_2PASS_SUPPORTED
  153023. METHODDEF(void)
  153024. process_data_crank_post (j_decompress_ptr cinfo,
  153025. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153026. JDIMENSION out_rows_avail)
  153027. {
  153028. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  153029. (JDIMENSION *) NULL, (JDIMENSION) 0,
  153030. output_buf, out_row_ctr, out_rows_avail);
  153031. }
  153032. #endif /* QUANT_2PASS_SUPPORTED */
  153033. GLOBAL(void)
  153034. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  153035. {
  153036. my_main_ptr4 main_;
  153037. int ci, rgroup, ngroups;
  153038. jpeg_component_info *compptr;
  153039. main_ = (my_main_ptr4)
  153040. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153041. SIZEOF(my_main_controller4));
  153042. cinfo->main = (struct jpeg_d_main_controller *) main_;
  153043. main_->pub.start_pass = start_pass_main2;
  153044. if (need_full_buffer) /* shouldn't happen */
  153045. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  153046. if (cinfo->upsample->need_context_rows) {
  153047. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  153048. ERREXIT(cinfo, JERR_NOTIMPL);
  153049. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  153050. ngroups = cinfo->min_DCT_scaled_size + 2;
  153051. } else {
  153052. ngroups = cinfo->min_DCT_scaled_size;
  153053. }
  153054. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153055. ci++, compptr++) {
  153056. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153057. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153058. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  153059. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153060. compptr->width_in_blocks * compptr->DCT_scaled_size,
  153061. (JDIMENSION) (rgroup * ngroups));
  153062. }
  153063. }
  153064. /*** End of inlined file: jdmainct.c ***/
  153065. /*** Start of inlined file: jdmarker.c ***/
  153066. #define JPEG_INTERNALS
  153067. typedef struct {
  153068. struct jpeg_marker_reader pub; /* public fields */
  153069. jpeg_marker_parser_method process_COM;
  153070. jpeg_marker_parser_method process_APPn[16];
  153071. unsigned int length_limit_COM;
  153072. unsigned int length_limit_APPn[16];
  153073. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  153074. unsigned int bytes_read; /* data bytes read so far in marker */
  153075. } my_marker_reader;
  153076. typedef my_marker_reader * my_marker_ptr2;
  153077. #define INPUT_VARS(cinfo) \
  153078. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  153079. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  153080. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  153081. #define INPUT_SYNC(cinfo) \
  153082. ( datasrc->next_input_byte = next_input_byte, \
  153083. datasrc->bytes_in_buffer = bytes_in_buffer )
  153084. #define INPUT_RELOAD(cinfo) \
  153085. ( next_input_byte = datasrc->next_input_byte, \
  153086. bytes_in_buffer = datasrc->bytes_in_buffer )
  153087. #define MAKE_BYTE_AVAIL(cinfo,action) \
  153088. if (bytes_in_buffer == 0) { \
  153089. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  153090. { action; } \
  153091. INPUT_RELOAD(cinfo); \
  153092. }
  153093. #define INPUT_BYTE(cinfo,V,action) \
  153094. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153095. bytes_in_buffer--; \
  153096. V = GETJOCTET(*next_input_byte++); )
  153097. #define INPUT_2BYTES(cinfo,V,action) \
  153098. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153099. bytes_in_buffer--; \
  153100. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153101. MAKE_BYTE_AVAIL(cinfo,action); \
  153102. bytes_in_buffer--; \
  153103. V += GETJOCTET(*next_input_byte++); )
  153104. LOCAL(boolean)
  153105. get_soi (j_decompress_ptr cinfo)
  153106. {
  153107. int i;
  153108. TRACEMS(cinfo, 1, JTRC_SOI);
  153109. if (cinfo->marker->saw_SOI)
  153110. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153111. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153112. cinfo->arith_dc_L[i] = 0;
  153113. cinfo->arith_dc_U[i] = 1;
  153114. cinfo->arith_ac_K[i] = 5;
  153115. }
  153116. cinfo->restart_interval = 0;
  153117. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153118. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153119. cinfo->saw_JFIF_marker = FALSE;
  153120. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153121. cinfo->JFIF_minor_version = 1;
  153122. cinfo->density_unit = 0;
  153123. cinfo->X_density = 1;
  153124. cinfo->Y_density = 1;
  153125. cinfo->saw_Adobe_marker = FALSE;
  153126. cinfo->Adobe_transform = 0;
  153127. cinfo->marker->saw_SOI = TRUE;
  153128. return TRUE;
  153129. }
  153130. LOCAL(boolean)
  153131. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153132. {
  153133. INT32 length;
  153134. int c, ci;
  153135. jpeg_component_info * compptr;
  153136. INPUT_VARS(cinfo);
  153137. cinfo->progressive_mode = is_prog;
  153138. cinfo->arith_code = is_arith;
  153139. INPUT_2BYTES(cinfo, length, return FALSE);
  153140. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153141. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153142. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153143. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153144. length -= 8;
  153145. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153146. (int) cinfo->image_width, (int) cinfo->image_height,
  153147. cinfo->num_components);
  153148. if (cinfo->marker->saw_SOF)
  153149. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153150. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153151. || cinfo->num_components <= 0)
  153152. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153153. if (length != (cinfo->num_components * 3))
  153154. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153155. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153156. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153157. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153158. cinfo->num_components * SIZEOF(jpeg_component_info));
  153159. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153160. ci++, compptr++) {
  153161. compptr->component_index = ci;
  153162. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153163. INPUT_BYTE(cinfo, c, return FALSE);
  153164. compptr->h_samp_factor = (c >> 4) & 15;
  153165. compptr->v_samp_factor = (c ) & 15;
  153166. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153167. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153168. compptr->component_id, compptr->h_samp_factor,
  153169. compptr->v_samp_factor, compptr->quant_tbl_no);
  153170. }
  153171. cinfo->marker->saw_SOF = TRUE;
  153172. INPUT_SYNC(cinfo);
  153173. return TRUE;
  153174. }
  153175. LOCAL(boolean)
  153176. get_sos (j_decompress_ptr cinfo)
  153177. {
  153178. INT32 length;
  153179. int i, ci, n, c, cc;
  153180. jpeg_component_info * compptr;
  153181. INPUT_VARS(cinfo);
  153182. if (! cinfo->marker->saw_SOF)
  153183. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153184. INPUT_2BYTES(cinfo, length, return FALSE);
  153185. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153186. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153187. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153188. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153189. cinfo->comps_in_scan = n;
  153190. for (i = 0; i < n; i++) {
  153191. INPUT_BYTE(cinfo, cc, return FALSE);
  153192. INPUT_BYTE(cinfo, c, return FALSE);
  153193. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153194. ci++, compptr++) {
  153195. if (cc == compptr->component_id)
  153196. goto id_found;
  153197. }
  153198. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153199. id_found:
  153200. cinfo->cur_comp_info[i] = compptr;
  153201. compptr->dc_tbl_no = (c >> 4) & 15;
  153202. compptr->ac_tbl_no = (c ) & 15;
  153203. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153204. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153205. }
  153206. INPUT_BYTE(cinfo, c, return FALSE);
  153207. cinfo->Ss = c;
  153208. INPUT_BYTE(cinfo, c, return FALSE);
  153209. cinfo->Se = c;
  153210. INPUT_BYTE(cinfo, c, return FALSE);
  153211. cinfo->Ah = (c >> 4) & 15;
  153212. cinfo->Al = (c ) & 15;
  153213. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153214. cinfo->Ah, cinfo->Al);
  153215. cinfo->marker->next_restart_num = 0;
  153216. cinfo->input_scan_number++;
  153217. INPUT_SYNC(cinfo);
  153218. return TRUE;
  153219. }
  153220. #ifdef D_ARITH_CODING_SUPPORTED
  153221. LOCAL(boolean)
  153222. get_dac (j_decompress_ptr cinfo)
  153223. {
  153224. INT32 length;
  153225. int index, val;
  153226. INPUT_VARS(cinfo);
  153227. INPUT_2BYTES(cinfo, length, return FALSE);
  153228. length -= 2;
  153229. while (length > 0) {
  153230. INPUT_BYTE(cinfo, index, return FALSE);
  153231. INPUT_BYTE(cinfo, val, return FALSE);
  153232. length -= 2;
  153233. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153234. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153235. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153236. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153237. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153238. } else { /* define DC table */
  153239. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153240. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153241. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153242. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153243. }
  153244. }
  153245. if (length != 0)
  153246. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153247. INPUT_SYNC(cinfo);
  153248. return TRUE;
  153249. }
  153250. #else /* ! D_ARITH_CODING_SUPPORTED */
  153251. #define get_dac(cinfo) skip_variable(cinfo)
  153252. #endif /* D_ARITH_CODING_SUPPORTED */
  153253. LOCAL(boolean)
  153254. get_dht (j_decompress_ptr cinfo)
  153255. {
  153256. INT32 length;
  153257. UINT8 bits[17];
  153258. UINT8 huffval[256];
  153259. int i, index, count;
  153260. JHUFF_TBL **htblptr;
  153261. INPUT_VARS(cinfo);
  153262. INPUT_2BYTES(cinfo, length, return FALSE);
  153263. length -= 2;
  153264. while (length > 16) {
  153265. INPUT_BYTE(cinfo, index, return FALSE);
  153266. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153267. bits[0] = 0;
  153268. count = 0;
  153269. for (i = 1; i <= 16; i++) {
  153270. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153271. count += bits[i];
  153272. }
  153273. length -= 1 + 16;
  153274. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153275. bits[1], bits[2], bits[3], bits[4],
  153276. bits[5], bits[6], bits[7], bits[8]);
  153277. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153278. bits[9], bits[10], bits[11], bits[12],
  153279. bits[13], bits[14], bits[15], bits[16]);
  153280. if (count > 256 || ((INT32) count) > length)
  153281. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153282. for (i = 0; i < count; i++)
  153283. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153284. length -= count;
  153285. if (index & 0x10) { /* AC table definition */
  153286. index -= 0x10;
  153287. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153288. } else { /* DC table definition */
  153289. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153290. }
  153291. if (index < 0 || index >= NUM_HUFF_TBLS)
  153292. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153293. if (*htblptr == NULL)
  153294. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153295. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153296. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153297. }
  153298. if (length != 0)
  153299. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153300. INPUT_SYNC(cinfo);
  153301. return TRUE;
  153302. }
  153303. LOCAL(boolean)
  153304. get_dqt (j_decompress_ptr cinfo)
  153305. {
  153306. INT32 length;
  153307. int n, i, prec;
  153308. unsigned int tmp;
  153309. JQUANT_TBL *quant_ptr;
  153310. INPUT_VARS(cinfo);
  153311. INPUT_2BYTES(cinfo, length, return FALSE);
  153312. length -= 2;
  153313. while (length > 0) {
  153314. INPUT_BYTE(cinfo, n, return FALSE);
  153315. prec = n >> 4;
  153316. n &= 0x0F;
  153317. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153318. if (n >= NUM_QUANT_TBLS)
  153319. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153320. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153321. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153322. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153323. for (i = 0; i < DCTSIZE2; i++) {
  153324. if (prec)
  153325. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153326. else
  153327. INPUT_BYTE(cinfo, tmp, return FALSE);
  153328. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153329. }
  153330. if (cinfo->err->trace_level >= 2) {
  153331. for (i = 0; i < DCTSIZE2; i += 8) {
  153332. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153333. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153334. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153335. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153336. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153337. }
  153338. }
  153339. length -= DCTSIZE2+1;
  153340. if (prec) length -= DCTSIZE2;
  153341. }
  153342. if (length != 0)
  153343. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153344. INPUT_SYNC(cinfo);
  153345. return TRUE;
  153346. }
  153347. LOCAL(boolean)
  153348. get_dri (j_decompress_ptr cinfo)
  153349. {
  153350. INT32 length;
  153351. unsigned int tmp;
  153352. INPUT_VARS(cinfo);
  153353. INPUT_2BYTES(cinfo, length, return FALSE);
  153354. if (length != 4)
  153355. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153356. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153357. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153358. cinfo->restart_interval = tmp;
  153359. INPUT_SYNC(cinfo);
  153360. return TRUE;
  153361. }
  153362. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153363. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153364. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153365. LOCAL(void)
  153366. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153367. unsigned int datalen, INT32 remaining)
  153368. {
  153369. INT32 totallen = (INT32) datalen + remaining;
  153370. if (datalen >= APP0_DATA_LEN &&
  153371. GETJOCTET(data[0]) == 0x4A &&
  153372. GETJOCTET(data[1]) == 0x46 &&
  153373. GETJOCTET(data[2]) == 0x49 &&
  153374. GETJOCTET(data[3]) == 0x46 &&
  153375. GETJOCTET(data[4]) == 0) {
  153376. cinfo->saw_JFIF_marker = TRUE;
  153377. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153378. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153379. cinfo->density_unit = GETJOCTET(data[7]);
  153380. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153381. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153382. if (cinfo->JFIF_major_version != 1)
  153383. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153384. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153385. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153386. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153387. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153388. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153389. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153390. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153391. totallen -= APP0_DATA_LEN;
  153392. if (totallen !=
  153393. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153394. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153395. } else if (datalen >= 6 &&
  153396. GETJOCTET(data[0]) == 0x4A &&
  153397. GETJOCTET(data[1]) == 0x46 &&
  153398. GETJOCTET(data[2]) == 0x58 &&
  153399. GETJOCTET(data[3]) == 0x58 &&
  153400. GETJOCTET(data[4]) == 0) {
  153401. switch (GETJOCTET(data[5])) {
  153402. case 0x10:
  153403. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153404. break;
  153405. case 0x11:
  153406. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153407. break;
  153408. case 0x13:
  153409. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153410. break;
  153411. default:
  153412. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153413. GETJOCTET(data[5]), (int) totallen);
  153414. break;
  153415. }
  153416. } else {
  153417. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153418. }
  153419. }
  153420. LOCAL(void)
  153421. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153422. unsigned int datalen, INT32 remaining)
  153423. {
  153424. unsigned int version, flags0, flags1, transform;
  153425. if (datalen >= APP14_DATA_LEN &&
  153426. GETJOCTET(data[0]) == 0x41 &&
  153427. GETJOCTET(data[1]) == 0x64 &&
  153428. GETJOCTET(data[2]) == 0x6F &&
  153429. GETJOCTET(data[3]) == 0x62 &&
  153430. GETJOCTET(data[4]) == 0x65) {
  153431. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153432. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153433. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153434. transform = GETJOCTET(data[11]);
  153435. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153436. cinfo->saw_Adobe_marker = TRUE;
  153437. cinfo->Adobe_transform = (UINT8) transform;
  153438. } else {
  153439. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153440. }
  153441. }
  153442. METHODDEF(boolean)
  153443. get_interesting_appn (j_decompress_ptr cinfo)
  153444. {
  153445. INT32 length;
  153446. JOCTET b[APPN_DATA_LEN];
  153447. unsigned int i, numtoread;
  153448. INPUT_VARS(cinfo);
  153449. INPUT_2BYTES(cinfo, length, return FALSE);
  153450. length -= 2;
  153451. if (length >= APPN_DATA_LEN)
  153452. numtoread = APPN_DATA_LEN;
  153453. else if (length > 0)
  153454. numtoread = (unsigned int) length;
  153455. else
  153456. numtoread = 0;
  153457. for (i = 0; i < numtoread; i++)
  153458. INPUT_BYTE(cinfo, b[i], return FALSE);
  153459. length -= numtoread;
  153460. switch (cinfo->unread_marker) {
  153461. case M_APP0:
  153462. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153463. break;
  153464. case M_APP14:
  153465. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153466. break;
  153467. default:
  153468. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153469. break;
  153470. }
  153471. INPUT_SYNC(cinfo);
  153472. if (length > 0)
  153473. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153474. return TRUE;
  153475. }
  153476. #ifdef SAVE_MARKERS_SUPPORTED
  153477. METHODDEF(boolean)
  153478. save_marker (j_decompress_ptr cinfo)
  153479. {
  153480. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153481. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153482. unsigned int bytes_read, data_length;
  153483. JOCTET FAR * data;
  153484. INT32 length = 0;
  153485. INPUT_VARS(cinfo);
  153486. if (cur_marker == NULL) {
  153487. INPUT_2BYTES(cinfo, length, return FALSE);
  153488. length -= 2;
  153489. if (length >= 0) { /* watch out for bogus length word */
  153490. unsigned int limit;
  153491. if (cinfo->unread_marker == (int) M_COM)
  153492. limit = marker->length_limit_COM;
  153493. else
  153494. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153495. if ((unsigned int) length < limit)
  153496. limit = (unsigned int) length;
  153497. cur_marker = (jpeg_saved_marker_ptr)
  153498. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153499. SIZEOF(struct jpeg_marker_struct) + limit);
  153500. cur_marker->next = NULL;
  153501. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153502. cur_marker->original_length = (unsigned int) length;
  153503. cur_marker->data_length = limit;
  153504. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153505. marker->cur_marker = cur_marker;
  153506. marker->bytes_read = 0;
  153507. bytes_read = 0;
  153508. data_length = limit;
  153509. } else {
  153510. bytes_read = data_length = 0;
  153511. data = NULL;
  153512. }
  153513. } else {
  153514. bytes_read = marker->bytes_read;
  153515. data_length = cur_marker->data_length;
  153516. data = cur_marker->data + bytes_read;
  153517. }
  153518. while (bytes_read < data_length) {
  153519. INPUT_SYNC(cinfo); /* move the restart point to here */
  153520. marker->bytes_read = bytes_read;
  153521. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153522. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153523. *data++ = *next_input_byte++;
  153524. bytes_in_buffer--;
  153525. bytes_read++;
  153526. }
  153527. }
  153528. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153529. if (cinfo->marker_list == NULL) {
  153530. cinfo->marker_list = cur_marker;
  153531. } else {
  153532. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153533. while (prev->next != NULL)
  153534. prev = prev->next;
  153535. prev->next = cur_marker;
  153536. }
  153537. data = cur_marker->data;
  153538. length = cur_marker->original_length - data_length;
  153539. }
  153540. marker->cur_marker = NULL;
  153541. switch (cinfo->unread_marker) {
  153542. case M_APP0:
  153543. examine_app0(cinfo, data, data_length, length);
  153544. break;
  153545. case M_APP14:
  153546. examine_app14(cinfo, data, data_length, length);
  153547. break;
  153548. default:
  153549. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153550. (int) (data_length + length));
  153551. break;
  153552. }
  153553. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153554. if (length > 0)
  153555. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153556. return TRUE;
  153557. }
  153558. #endif /* SAVE_MARKERS_SUPPORTED */
  153559. METHODDEF(boolean)
  153560. skip_variable (j_decompress_ptr cinfo)
  153561. {
  153562. INT32 length;
  153563. INPUT_VARS(cinfo);
  153564. INPUT_2BYTES(cinfo, length, return FALSE);
  153565. length -= 2;
  153566. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153567. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153568. if (length > 0)
  153569. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153570. return TRUE;
  153571. }
  153572. LOCAL(boolean)
  153573. next_marker (j_decompress_ptr cinfo)
  153574. {
  153575. int c;
  153576. INPUT_VARS(cinfo);
  153577. for (;;) {
  153578. INPUT_BYTE(cinfo, c, return FALSE);
  153579. while (c != 0xFF) {
  153580. cinfo->marker->discarded_bytes++;
  153581. INPUT_SYNC(cinfo);
  153582. INPUT_BYTE(cinfo, c, return FALSE);
  153583. }
  153584. do {
  153585. INPUT_BYTE(cinfo, c, return FALSE);
  153586. } while (c == 0xFF);
  153587. if (c != 0)
  153588. break; /* found a valid marker, exit loop */
  153589. cinfo->marker->discarded_bytes += 2;
  153590. INPUT_SYNC(cinfo);
  153591. }
  153592. if (cinfo->marker->discarded_bytes != 0) {
  153593. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153594. cinfo->marker->discarded_bytes = 0;
  153595. }
  153596. cinfo->unread_marker = c;
  153597. INPUT_SYNC(cinfo);
  153598. return TRUE;
  153599. }
  153600. LOCAL(boolean)
  153601. first_marker (j_decompress_ptr cinfo)
  153602. {
  153603. int c, c2;
  153604. INPUT_VARS(cinfo);
  153605. INPUT_BYTE(cinfo, c, return FALSE);
  153606. INPUT_BYTE(cinfo, c2, return FALSE);
  153607. if (c != 0xFF || c2 != (int) M_SOI)
  153608. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153609. cinfo->unread_marker = c2;
  153610. INPUT_SYNC(cinfo);
  153611. return TRUE;
  153612. }
  153613. METHODDEF(int)
  153614. read_markers (j_decompress_ptr cinfo)
  153615. {
  153616. for (;;) {
  153617. if (cinfo->unread_marker == 0) {
  153618. if (! cinfo->marker->saw_SOI) {
  153619. if (! first_marker(cinfo))
  153620. return JPEG_SUSPENDED;
  153621. } else {
  153622. if (! next_marker(cinfo))
  153623. return JPEG_SUSPENDED;
  153624. }
  153625. }
  153626. switch (cinfo->unread_marker) {
  153627. case M_SOI:
  153628. if (! get_soi(cinfo))
  153629. return JPEG_SUSPENDED;
  153630. break;
  153631. case M_SOF0: /* Baseline */
  153632. case M_SOF1: /* Extended sequential, Huffman */
  153633. if (! get_sof(cinfo, FALSE, FALSE))
  153634. return JPEG_SUSPENDED;
  153635. break;
  153636. case M_SOF2: /* Progressive, Huffman */
  153637. if (! get_sof(cinfo, TRUE, FALSE))
  153638. return JPEG_SUSPENDED;
  153639. break;
  153640. case M_SOF9: /* Extended sequential, arithmetic */
  153641. if (! get_sof(cinfo, FALSE, TRUE))
  153642. return JPEG_SUSPENDED;
  153643. break;
  153644. case M_SOF10: /* Progressive, arithmetic */
  153645. if (! get_sof(cinfo, TRUE, TRUE))
  153646. return JPEG_SUSPENDED;
  153647. break;
  153648. case M_SOF3: /* Lossless, Huffman */
  153649. case M_SOF5: /* Differential sequential, Huffman */
  153650. case M_SOF6: /* Differential progressive, Huffman */
  153651. case M_SOF7: /* Differential lossless, Huffman */
  153652. case M_JPG: /* Reserved for JPEG extensions */
  153653. case M_SOF11: /* Lossless, arithmetic */
  153654. case M_SOF13: /* Differential sequential, arithmetic */
  153655. case M_SOF14: /* Differential progressive, arithmetic */
  153656. case M_SOF15: /* Differential lossless, arithmetic */
  153657. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153658. break;
  153659. case M_SOS:
  153660. if (! get_sos(cinfo))
  153661. return JPEG_SUSPENDED;
  153662. cinfo->unread_marker = 0; /* processed the marker */
  153663. return JPEG_REACHED_SOS;
  153664. case M_EOI:
  153665. TRACEMS(cinfo, 1, JTRC_EOI);
  153666. cinfo->unread_marker = 0; /* processed the marker */
  153667. return JPEG_REACHED_EOI;
  153668. case M_DAC:
  153669. if (! get_dac(cinfo))
  153670. return JPEG_SUSPENDED;
  153671. break;
  153672. case M_DHT:
  153673. if (! get_dht(cinfo))
  153674. return JPEG_SUSPENDED;
  153675. break;
  153676. case M_DQT:
  153677. if (! get_dqt(cinfo))
  153678. return JPEG_SUSPENDED;
  153679. break;
  153680. case M_DRI:
  153681. if (! get_dri(cinfo))
  153682. return JPEG_SUSPENDED;
  153683. break;
  153684. case M_APP0:
  153685. case M_APP1:
  153686. case M_APP2:
  153687. case M_APP3:
  153688. case M_APP4:
  153689. case M_APP5:
  153690. case M_APP6:
  153691. case M_APP7:
  153692. case M_APP8:
  153693. case M_APP9:
  153694. case M_APP10:
  153695. case M_APP11:
  153696. case M_APP12:
  153697. case M_APP13:
  153698. case M_APP14:
  153699. case M_APP15:
  153700. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153701. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153702. return JPEG_SUSPENDED;
  153703. break;
  153704. case M_COM:
  153705. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153706. return JPEG_SUSPENDED;
  153707. break;
  153708. case M_RST0: /* these are all parameterless */
  153709. case M_RST1:
  153710. case M_RST2:
  153711. case M_RST3:
  153712. case M_RST4:
  153713. case M_RST5:
  153714. case M_RST6:
  153715. case M_RST7:
  153716. case M_TEM:
  153717. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153718. break;
  153719. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153720. if (! skip_variable(cinfo))
  153721. return JPEG_SUSPENDED;
  153722. break;
  153723. default: /* must be DHP, EXP, JPGn, or RESn */
  153724. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153725. break;
  153726. }
  153727. cinfo->unread_marker = 0;
  153728. } /* end loop */
  153729. }
  153730. METHODDEF(boolean)
  153731. read_restart_marker (j_decompress_ptr cinfo)
  153732. {
  153733. if (cinfo->unread_marker == 0) {
  153734. if (! next_marker(cinfo))
  153735. return FALSE;
  153736. }
  153737. if (cinfo->unread_marker ==
  153738. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153739. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153740. cinfo->unread_marker = 0;
  153741. } else {
  153742. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153743. cinfo->marker->next_restart_num))
  153744. return FALSE;
  153745. }
  153746. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153747. return TRUE;
  153748. }
  153749. GLOBAL(boolean)
  153750. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153751. {
  153752. int marker = cinfo->unread_marker;
  153753. int action = 1;
  153754. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153755. for (;;) {
  153756. if (marker < (int) M_SOF0)
  153757. action = 2; /* invalid marker */
  153758. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153759. action = 3; /* valid non-restart marker */
  153760. else {
  153761. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153762. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153763. action = 3; /* one of the next two expected restarts */
  153764. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153765. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153766. action = 2; /* a prior restart, so advance */
  153767. else
  153768. action = 1; /* desired restart or too far away */
  153769. }
  153770. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153771. switch (action) {
  153772. case 1:
  153773. cinfo->unread_marker = 0;
  153774. return TRUE;
  153775. case 2:
  153776. if (! next_marker(cinfo))
  153777. return FALSE;
  153778. marker = cinfo->unread_marker;
  153779. break;
  153780. case 3:
  153781. return TRUE;
  153782. }
  153783. } /* end loop */
  153784. }
  153785. METHODDEF(void)
  153786. reset_marker_reader (j_decompress_ptr cinfo)
  153787. {
  153788. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153789. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153790. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153791. cinfo->unread_marker = 0; /* no pending marker */
  153792. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153793. marker->pub.saw_SOF = FALSE;
  153794. marker->pub.discarded_bytes = 0;
  153795. marker->cur_marker = NULL;
  153796. }
  153797. GLOBAL(void)
  153798. jinit_marker_reader (j_decompress_ptr cinfo)
  153799. {
  153800. my_marker_ptr2 marker;
  153801. int i;
  153802. marker = (my_marker_ptr2)
  153803. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153804. SIZEOF(my_marker_reader));
  153805. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153806. marker->pub.reset_marker_reader = reset_marker_reader;
  153807. marker->pub.read_markers = read_markers;
  153808. marker->pub.read_restart_marker = read_restart_marker;
  153809. marker->process_COM = skip_variable;
  153810. marker->length_limit_COM = 0;
  153811. for (i = 0; i < 16; i++) {
  153812. marker->process_APPn[i] = skip_variable;
  153813. marker->length_limit_APPn[i] = 0;
  153814. }
  153815. marker->process_APPn[0] = get_interesting_appn;
  153816. marker->process_APPn[14] = get_interesting_appn;
  153817. reset_marker_reader(cinfo);
  153818. }
  153819. #ifdef SAVE_MARKERS_SUPPORTED
  153820. GLOBAL(void)
  153821. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153822. unsigned int length_limit)
  153823. {
  153824. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153825. long maxlength;
  153826. jpeg_marker_parser_method processor;
  153827. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153828. if (((long) length_limit) > maxlength)
  153829. length_limit = (unsigned int) maxlength;
  153830. if (length_limit) {
  153831. processor = save_marker;
  153832. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153833. length_limit = APP0_DATA_LEN;
  153834. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153835. length_limit = APP14_DATA_LEN;
  153836. } else {
  153837. processor = skip_variable;
  153838. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153839. processor = get_interesting_appn;
  153840. }
  153841. if (marker_code == (int) M_COM) {
  153842. marker->process_COM = processor;
  153843. marker->length_limit_COM = length_limit;
  153844. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153845. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153846. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153847. } else
  153848. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153849. }
  153850. #endif /* SAVE_MARKERS_SUPPORTED */
  153851. GLOBAL(void)
  153852. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153853. jpeg_marker_parser_method routine)
  153854. {
  153855. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153856. if (marker_code == (int) M_COM)
  153857. marker->process_COM = routine;
  153858. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153859. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153860. else
  153861. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153862. }
  153863. /*** End of inlined file: jdmarker.c ***/
  153864. /*** Start of inlined file: jdmaster.c ***/
  153865. #define JPEG_INTERNALS
  153866. typedef struct {
  153867. struct jpeg_decomp_master pub; /* public fields */
  153868. int pass_number; /* # of passes completed */
  153869. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153870. struct jpeg_color_quantizer * quantizer_1pass;
  153871. struct jpeg_color_quantizer * quantizer_2pass;
  153872. } my_decomp_master;
  153873. typedef my_decomp_master * my_master_ptr6;
  153874. LOCAL(boolean)
  153875. use_merged_upsample (j_decompress_ptr cinfo)
  153876. {
  153877. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153878. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153879. return FALSE;
  153880. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153881. cinfo->out_color_space != JCS_RGB ||
  153882. cinfo->out_color_components != RGB_PIXELSIZE)
  153883. return FALSE;
  153884. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153885. cinfo->comp_info[1].h_samp_factor != 1 ||
  153886. cinfo->comp_info[2].h_samp_factor != 1 ||
  153887. cinfo->comp_info[0].v_samp_factor > 2 ||
  153888. cinfo->comp_info[1].v_samp_factor != 1 ||
  153889. cinfo->comp_info[2].v_samp_factor != 1)
  153890. return FALSE;
  153891. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153892. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153893. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153894. return FALSE;
  153895. return TRUE; /* by golly, it'll work... */
  153896. #else
  153897. return FALSE;
  153898. #endif
  153899. }
  153900. GLOBAL(void)
  153901. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153902. {
  153903. #ifdef IDCT_SCALING_SUPPORTED
  153904. int ci;
  153905. jpeg_component_info *compptr;
  153906. #endif
  153907. if (cinfo->global_state != DSTATE_READY)
  153908. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153909. #ifdef IDCT_SCALING_SUPPORTED
  153910. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153911. cinfo->output_width = (JDIMENSION)
  153912. jdiv_round_up((long) cinfo->image_width, 8L);
  153913. cinfo->output_height = (JDIMENSION)
  153914. jdiv_round_up((long) cinfo->image_height, 8L);
  153915. cinfo->min_DCT_scaled_size = 1;
  153916. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153917. cinfo->output_width = (JDIMENSION)
  153918. jdiv_round_up((long) cinfo->image_width, 4L);
  153919. cinfo->output_height = (JDIMENSION)
  153920. jdiv_round_up((long) cinfo->image_height, 4L);
  153921. cinfo->min_DCT_scaled_size = 2;
  153922. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153923. cinfo->output_width = (JDIMENSION)
  153924. jdiv_round_up((long) cinfo->image_width, 2L);
  153925. cinfo->output_height = (JDIMENSION)
  153926. jdiv_round_up((long) cinfo->image_height, 2L);
  153927. cinfo->min_DCT_scaled_size = 4;
  153928. } else {
  153929. cinfo->output_width = cinfo->image_width;
  153930. cinfo->output_height = cinfo->image_height;
  153931. cinfo->min_DCT_scaled_size = DCTSIZE;
  153932. }
  153933. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153934. ci++, compptr++) {
  153935. int ssize = cinfo->min_DCT_scaled_size;
  153936. while (ssize < DCTSIZE &&
  153937. (compptr->h_samp_factor * ssize * 2 <=
  153938. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153939. (compptr->v_samp_factor * ssize * 2 <=
  153940. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153941. ssize = ssize * 2;
  153942. }
  153943. compptr->DCT_scaled_size = ssize;
  153944. }
  153945. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153946. ci++, compptr++) {
  153947. compptr->downsampled_width = (JDIMENSION)
  153948. jdiv_round_up((long) cinfo->image_width *
  153949. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153950. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153951. compptr->downsampled_height = (JDIMENSION)
  153952. jdiv_round_up((long) cinfo->image_height *
  153953. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153954. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153955. }
  153956. #else /* !IDCT_SCALING_SUPPORTED */
  153957. cinfo->output_width = cinfo->image_width;
  153958. cinfo->output_height = cinfo->image_height;
  153959. #endif /* IDCT_SCALING_SUPPORTED */
  153960. switch (cinfo->out_color_space) {
  153961. case JCS_GRAYSCALE:
  153962. cinfo->out_color_components = 1;
  153963. break;
  153964. case JCS_RGB:
  153965. #if RGB_PIXELSIZE != 3
  153966. cinfo->out_color_components = RGB_PIXELSIZE;
  153967. break;
  153968. #endif /* else share code with YCbCr */
  153969. case JCS_YCbCr:
  153970. cinfo->out_color_components = 3;
  153971. break;
  153972. case JCS_CMYK:
  153973. case JCS_YCCK:
  153974. cinfo->out_color_components = 4;
  153975. break;
  153976. default: /* else must be same colorspace as in file */
  153977. cinfo->out_color_components = cinfo->num_components;
  153978. break;
  153979. }
  153980. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153981. cinfo->out_color_components);
  153982. if (use_merged_upsample(cinfo))
  153983. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153984. else
  153985. cinfo->rec_outbuf_height = 1;
  153986. }
  153987. LOCAL(void)
  153988. prepare_range_limit_table (j_decompress_ptr cinfo)
  153989. {
  153990. JSAMPLE * table;
  153991. int i;
  153992. table = (JSAMPLE *)
  153993. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153994. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153995. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153996. cinfo->sample_range_limit = table;
  153997. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153998. for (i = 0; i <= MAXJSAMPLE; i++)
  153999. table[i] = (JSAMPLE) i;
  154000. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  154001. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  154002. table[i] = MAXJSAMPLE;
  154003. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  154004. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154005. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  154006. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  154007. }
  154008. LOCAL(void)
  154009. master_selection (j_decompress_ptr cinfo)
  154010. {
  154011. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154012. boolean use_c_buffer;
  154013. long samplesperrow;
  154014. JDIMENSION jd_samplesperrow;
  154015. jpeg_calc_output_dimensions(cinfo);
  154016. prepare_range_limit_table(cinfo);
  154017. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  154018. jd_samplesperrow = (JDIMENSION) samplesperrow;
  154019. if ((long) jd_samplesperrow != samplesperrow)
  154020. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  154021. master->pass_number = 0;
  154022. master->using_merged_upsample = use_merged_upsample(cinfo);
  154023. master->quantizer_1pass = NULL;
  154024. master->quantizer_2pass = NULL;
  154025. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  154026. cinfo->enable_1pass_quant = FALSE;
  154027. cinfo->enable_external_quant = FALSE;
  154028. cinfo->enable_2pass_quant = FALSE;
  154029. }
  154030. if (cinfo->quantize_colors) {
  154031. if (cinfo->raw_data_out)
  154032. ERREXIT(cinfo, JERR_NOTIMPL);
  154033. if (cinfo->out_color_components != 3) {
  154034. cinfo->enable_1pass_quant = TRUE;
  154035. cinfo->enable_external_quant = FALSE;
  154036. cinfo->enable_2pass_quant = FALSE;
  154037. cinfo->colormap = NULL;
  154038. } else if (cinfo->colormap != NULL) {
  154039. cinfo->enable_external_quant = TRUE;
  154040. } else if (cinfo->two_pass_quantize) {
  154041. cinfo->enable_2pass_quant = TRUE;
  154042. } else {
  154043. cinfo->enable_1pass_quant = TRUE;
  154044. }
  154045. if (cinfo->enable_1pass_quant) {
  154046. #ifdef QUANT_1PASS_SUPPORTED
  154047. jinit_1pass_quantizer(cinfo);
  154048. master->quantizer_1pass = cinfo->cquantize;
  154049. #else
  154050. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154051. #endif
  154052. }
  154053. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  154054. #ifdef QUANT_2PASS_SUPPORTED
  154055. jinit_2pass_quantizer(cinfo);
  154056. master->quantizer_2pass = cinfo->cquantize;
  154057. #else
  154058. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154059. #endif
  154060. }
  154061. }
  154062. if (! cinfo->raw_data_out) {
  154063. if (master->using_merged_upsample) {
  154064. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154065. jinit_merged_upsampler(cinfo); /* does color conversion too */
  154066. #else
  154067. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154068. #endif
  154069. } else {
  154070. jinit_color_deconverter(cinfo);
  154071. jinit_upsampler(cinfo);
  154072. }
  154073. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  154074. }
  154075. jinit_inverse_dct(cinfo);
  154076. if (cinfo->arith_code) {
  154077. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154078. } else {
  154079. if (cinfo->progressive_mode) {
  154080. #ifdef D_PROGRESSIVE_SUPPORTED
  154081. jinit_phuff_decoder(cinfo);
  154082. #else
  154083. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154084. #endif
  154085. } else
  154086. jinit_huff_decoder(cinfo);
  154087. }
  154088. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  154089. jinit_d_coef_controller(cinfo, use_c_buffer);
  154090. if (! cinfo->raw_data_out)
  154091. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  154092. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154093. (*cinfo->inputctl->start_input_pass) (cinfo);
  154094. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154095. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  154096. cinfo->inputctl->has_multiple_scans) {
  154097. int nscans;
  154098. if (cinfo->progressive_mode) {
  154099. nscans = 2 + 3 * cinfo->num_components;
  154100. } else {
  154101. nscans = cinfo->num_components;
  154102. }
  154103. cinfo->progress->pass_counter = 0L;
  154104. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154105. cinfo->progress->completed_passes = 0;
  154106. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154107. master->pass_number++;
  154108. }
  154109. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154110. }
  154111. METHODDEF(void)
  154112. prepare_for_output_pass (j_decompress_ptr cinfo)
  154113. {
  154114. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154115. if (master->pub.is_dummy_pass) {
  154116. #ifdef QUANT_2PASS_SUPPORTED
  154117. master->pub.is_dummy_pass = FALSE;
  154118. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154119. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154120. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154121. #else
  154122. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154123. #endif /* QUANT_2PASS_SUPPORTED */
  154124. } else {
  154125. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154126. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154127. cinfo->cquantize = master->quantizer_2pass;
  154128. master->pub.is_dummy_pass = TRUE;
  154129. } else if (cinfo->enable_1pass_quant) {
  154130. cinfo->cquantize = master->quantizer_1pass;
  154131. } else {
  154132. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154133. }
  154134. }
  154135. (*cinfo->idct->start_pass) (cinfo);
  154136. (*cinfo->coef->start_output_pass) (cinfo);
  154137. if (! cinfo->raw_data_out) {
  154138. if (! master->using_merged_upsample)
  154139. (*cinfo->cconvert->start_pass) (cinfo);
  154140. (*cinfo->upsample->start_pass) (cinfo);
  154141. if (cinfo->quantize_colors)
  154142. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154143. (*cinfo->post->start_pass) (cinfo,
  154144. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154145. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154146. }
  154147. }
  154148. if (cinfo->progress != NULL) {
  154149. cinfo->progress->completed_passes = master->pass_number;
  154150. cinfo->progress->total_passes = master->pass_number +
  154151. (master->pub.is_dummy_pass ? 2 : 1);
  154152. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154153. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154154. }
  154155. }
  154156. }
  154157. METHODDEF(void)
  154158. finish_output_pass (j_decompress_ptr cinfo)
  154159. {
  154160. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154161. if (cinfo->quantize_colors)
  154162. (*cinfo->cquantize->finish_pass) (cinfo);
  154163. master->pass_number++;
  154164. }
  154165. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154166. GLOBAL(void)
  154167. jpeg_new_colormap (j_decompress_ptr cinfo)
  154168. {
  154169. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154170. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154171. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154172. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154173. cinfo->colormap != NULL) {
  154174. cinfo->cquantize = master->quantizer_2pass;
  154175. (*cinfo->cquantize->new_color_map) (cinfo);
  154176. master->pub.is_dummy_pass = FALSE; /* just in case */
  154177. } else
  154178. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154179. }
  154180. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154181. GLOBAL(void)
  154182. jinit_master_decompress (j_decompress_ptr cinfo)
  154183. {
  154184. my_master_ptr6 master;
  154185. master = (my_master_ptr6)
  154186. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154187. SIZEOF(my_decomp_master));
  154188. cinfo->master = (struct jpeg_decomp_master *) master;
  154189. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154190. master->pub.finish_output_pass = finish_output_pass;
  154191. master->pub.is_dummy_pass = FALSE;
  154192. master_selection(cinfo);
  154193. }
  154194. /*** End of inlined file: jdmaster.c ***/
  154195. #undef FIX
  154196. /*** Start of inlined file: jdmerge.c ***/
  154197. #define JPEG_INTERNALS
  154198. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154199. typedef struct {
  154200. struct jpeg_upsampler pub; /* public fields */
  154201. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154202. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154203. JSAMPARRAY output_buf));
  154204. int * Cr_r_tab; /* => table for Cr to R conversion */
  154205. int * Cb_b_tab; /* => table for Cb to B conversion */
  154206. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154207. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154208. JSAMPROW spare_row;
  154209. boolean spare_full; /* T if spare buffer is occupied */
  154210. JDIMENSION out_row_width; /* samples per output row */
  154211. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154212. } my_upsampler;
  154213. typedef my_upsampler * my_upsample_ptr;
  154214. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154215. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154216. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154217. LOCAL(void)
  154218. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154219. {
  154220. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154221. int i;
  154222. INT32 x;
  154223. SHIFT_TEMPS
  154224. upsample->Cr_r_tab = (int *)
  154225. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154226. (MAXJSAMPLE+1) * SIZEOF(int));
  154227. upsample->Cb_b_tab = (int *)
  154228. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154229. (MAXJSAMPLE+1) * SIZEOF(int));
  154230. upsample->Cr_g_tab = (INT32 *)
  154231. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154232. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154233. upsample->Cb_g_tab = (INT32 *)
  154234. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154235. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154236. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154237. upsample->Cr_r_tab[i] = (int)
  154238. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154239. upsample->Cb_b_tab[i] = (int)
  154240. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154241. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154242. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154243. }
  154244. }
  154245. METHODDEF(void)
  154246. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154247. {
  154248. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154249. upsample->spare_full = FALSE;
  154250. upsample->rows_to_go = cinfo->output_height;
  154251. }
  154252. METHODDEF(void)
  154253. merged_2v_upsample (j_decompress_ptr cinfo,
  154254. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154255. JDIMENSION in_row_groups_avail,
  154256. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154257. JDIMENSION out_rows_avail)
  154258. {
  154259. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154260. JSAMPROW work_ptrs[2];
  154261. JDIMENSION num_rows; /* number of rows returned to caller */
  154262. if (upsample->spare_full) {
  154263. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154264. 1, upsample->out_row_width);
  154265. num_rows = 1;
  154266. upsample->spare_full = FALSE;
  154267. } else {
  154268. num_rows = 2;
  154269. if (num_rows > upsample->rows_to_go)
  154270. num_rows = upsample->rows_to_go;
  154271. out_rows_avail -= *out_row_ctr;
  154272. if (num_rows > out_rows_avail)
  154273. num_rows = out_rows_avail;
  154274. work_ptrs[0] = output_buf[*out_row_ctr];
  154275. if (num_rows > 1) {
  154276. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154277. } else {
  154278. work_ptrs[1] = upsample->spare_row;
  154279. upsample->spare_full = TRUE;
  154280. }
  154281. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154282. }
  154283. *out_row_ctr += num_rows;
  154284. upsample->rows_to_go -= num_rows;
  154285. if (! upsample->spare_full)
  154286. (*in_row_group_ctr)++;
  154287. }
  154288. METHODDEF(void)
  154289. merged_1v_upsample (j_decompress_ptr cinfo,
  154290. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154291. JDIMENSION in_row_groups_avail,
  154292. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154293. JDIMENSION out_rows_avail)
  154294. {
  154295. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154296. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154297. output_buf + *out_row_ctr);
  154298. (*out_row_ctr)++;
  154299. (*in_row_group_ctr)++;
  154300. }
  154301. METHODDEF(void)
  154302. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154303. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154304. JSAMPARRAY output_buf)
  154305. {
  154306. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154307. register int y, cred, cgreen, cblue;
  154308. int cb, cr;
  154309. register JSAMPROW outptr;
  154310. JSAMPROW inptr0, inptr1, inptr2;
  154311. JDIMENSION col;
  154312. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154313. int * Crrtab = upsample->Cr_r_tab;
  154314. int * Cbbtab = upsample->Cb_b_tab;
  154315. INT32 * Crgtab = upsample->Cr_g_tab;
  154316. INT32 * Cbgtab = upsample->Cb_g_tab;
  154317. SHIFT_TEMPS
  154318. inptr0 = input_buf[0][in_row_group_ctr];
  154319. inptr1 = input_buf[1][in_row_group_ctr];
  154320. inptr2 = input_buf[2][in_row_group_ctr];
  154321. outptr = output_buf[0];
  154322. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154323. cb = GETJSAMPLE(*inptr1++);
  154324. cr = GETJSAMPLE(*inptr2++);
  154325. cred = Crrtab[cr];
  154326. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154327. cblue = Cbbtab[cb];
  154328. y = GETJSAMPLE(*inptr0++);
  154329. outptr[RGB_RED] = range_limit[y + cred];
  154330. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154331. outptr[RGB_BLUE] = range_limit[y + cblue];
  154332. outptr += RGB_PIXELSIZE;
  154333. y = GETJSAMPLE(*inptr0++);
  154334. outptr[RGB_RED] = range_limit[y + cred];
  154335. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154336. outptr[RGB_BLUE] = range_limit[y + cblue];
  154337. outptr += RGB_PIXELSIZE;
  154338. }
  154339. if (cinfo->output_width & 1) {
  154340. cb = GETJSAMPLE(*inptr1);
  154341. cr = GETJSAMPLE(*inptr2);
  154342. cred = Crrtab[cr];
  154343. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154344. cblue = Cbbtab[cb];
  154345. y = GETJSAMPLE(*inptr0);
  154346. outptr[RGB_RED] = range_limit[y + cred];
  154347. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154348. outptr[RGB_BLUE] = range_limit[y + cblue];
  154349. }
  154350. }
  154351. METHODDEF(void)
  154352. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154353. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154354. JSAMPARRAY output_buf)
  154355. {
  154356. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154357. register int y, cred, cgreen, cblue;
  154358. int cb, cr;
  154359. register JSAMPROW outptr0, outptr1;
  154360. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154361. JDIMENSION col;
  154362. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154363. int * Crrtab = upsample->Cr_r_tab;
  154364. int * Cbbtab = upsample->Cb_b_tab;
  154365. INT32 * Crgtab = upsample->Cr_g_tab;
  154366. INT32 * Cbgtab = upsample->Cb_g_tab;
  154367. SHIFT_TEMPS
  154368. inptr00 = input_buf[0][in_row_group_ctr*2];
  154369. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154370. inptr1 = input_buf[1][in_row_group_ctr];
  154371. inptr2 = input_buf[2][in_row_group_ctr];
  154372. outptr0 = output_buf[0];
  154373. outptr1 = output_buf[1];
  154374. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154375. cb = GETJSAMPLE(*inptr1++);
  154376. cr = GETJSAMPLE(*inptr2++);
  154377. cred = Crrtab[cr];
  154378. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154379. cblue = Cbbtab[cb];
  154380. y = GETJSAMPLE(*inptr00++);
  154381. outptr0[RGB_RED] = range_limit[y + cred];
  154382. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154383. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154384. outptr0 += RGB_PIXELSIZE;
  154385. y = GETJSAMPLE(*inptr00++);
  154386. outptr0[RGB_RED] = range_limit[y + cred];
  154387. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154388. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154389. outptr0 += RGB_PIXELSIZE;
  154390. y = GETJSAMPLE(*inptr01++);
  154391. outptr1[RGB_RED] = range_limit[y + cred];
  154392. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154393. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154394. outptr1 += RGB_PIXELSIZE;
  154395. y = GETJSAMPLE(*inptr01++);
  154396. outptr1[RGB_RED] = range_limit[y + cred];
  154397. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154398. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154399. outptr1 += RGB_PIXELSIZE;
  154400. }
  154401. if (cinfo->output_width & 1) {
  154402. cb = GETJSAMPLE(*inptr1);
  154403. cr = GETJSAMPLE(*inptr2);
  154404. cred = Crrtab[cr];
  154405. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154406. cblue = Cbbtab[cb];
  154407. y = GETJSAMPLE(*inptr00);
  154408. outptr0[RGB_RED] = range_limit[y + cred];
  154409. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154410. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154411. y = GETJSAMPLE(*inptr01);
  154412. outptr1[RGB_RED] = range_limit[y + cred];
  154413. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154414. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154415. }
  154416. }
  154417. GLOBAL(void)
  154418. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154419. {
  154420. my_upsample_ptr upsample;
  154421. upsample = (my_upsample_ptr)
  154422. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154423. SIZEOF(my_upsampler));
  154424. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154425. upsample->pub.start_pass = start_pass_merged_upsample;
  154426. upsample->pub.need_context_rows = FALSE;
  154427. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154428. if (cinfo->max_v_samp_factor == 2) {
  154429. upsample->pub.upsample = merged_2v_upsample;
  154430. upsample->upmethod = h2v2_merged_upsample;
  154431. upsample->spare_row = (JSAMPROW)
  154432. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154433. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154434. } else {
  154435. upsample->pub.upsample = merged_1v_upsample;
  154436. upsample->upmethod = h2v1_merged_upsample;
  154437. upsample->spare_row = NULL;
  154438. }
  154439. build_ycc_rgb_table2(cinfo);
  154440. }
  154441. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154442. /*** End of inlined file: jdmerge.c ***/
  154443. #undef ASSIGN_STATE
  154444. /*** Start of inlined file: jdphuff.c ***/
  154445. #define JPEG_INTERNALS
  154446. #ifdef D_PROGRESSIVE_SUPPORTED
  154447. typedef struct {
  154448. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154449. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154450. } savable_state3;
  154451. #ifndef NO_STRUCT_ASSIGN
  154452. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154453. #else
  154454. #if MAX_COMPS_IN_SCAN == 4
  154455. #define ASSIGN_STATE(dest,src) \
  154456. ((dest).EOBRUN = (src).EOBRUN, \
  154457. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154458. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154459. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154460. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154461. #endif
  154462. #endif
  154463. typedef struct {
  154464. struct jpeg_entropy_decoder pub; /* public fields */
  154465. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154466. savable_state3 saved; /* Other state at start of MCU */
  154467. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154468. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154469. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154470. } phuff_entropy_decoder;
  154471. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154472. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154473. JBLOCKROW *MCU_data));
  154474. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154475. JBLOCKROW *MCU_data));
  154476. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154477. JBLOCKROW *MCU_data));
  154478. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154479. JBLOCKROW *MCU_data));
  154480. METHODDEF(void)
  154481. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154482. {
  154483. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154484. boolean is_DC_band, bad;
  154485. int ci, coefi, tbl;
  154486. int *coef_bit_ptr;
  154487. jpeg_component_info * compptr;
  154488. is_DC_band = (cinfo->Ss == 0);
  154489. bad = FALSE;
  154490. if (is_DC_band) {
  154491. if (cinfo->Se != 0)
  154492. bad = TRUE;
  154493. } else {
  154494. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154495. bad = TRUE;
  154496. if (cinfo->comps_in_scan != 1)
  154497. bad = TRUE;
  154498. }
  154499. if (cinfo->Ah != 0) {
  154500. if (cinfo->Al != cinfo->Ah-1)
  154501. bad = TRUE;
  154502. }
  154503. if (cinfo->Al > 13) /* need not check for < 0 */
  154504. bad = TRUE;
  154505. if (bad)
  154506. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154507. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154508. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154509. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154510. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154511. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154512. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154513. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154514. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154515. if (cinfo->Ah != expected)
  154516. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154517. coef_bit_ptr[coefi] = cinfo->Al;
  154518. }
  154519. }
  154520. if (cinfo->Ah == 0) {
  154521. if (is_DC_band)
  154522. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154523. else
  154524. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154525. } else {
  154526. if (is_DC_band)
  154527. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154528. else
  154529. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154530. }
  154531. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154532. compptr = cinfo->cur_comp_info[ci];
  154533. if (is_DC_band) {
  154534. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154535. tbl = compptr->dc_tbl_no;
  154536. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154537. & entropy->derived_tbls[tbl]);
  154538. }
  154539. } else {
  154540. tbl = compptr->ac_tbl_no;
  154541. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154542. & entropy->derived_tbls[tbl]);
  154543. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154544. }
  154545. entropy->saved.last_dc_val[ci] = 0;
  154546. }
  154547. entropy->bitstate.bits_left = 0;
  154548. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154549. entropy->pub.insufficient_data = FALSE;
  154550. entropy->saved.EOBRUN = 0;
  154551. entropy->restarts_to_go = cinfo->restart_interval;
  154552. }
  154553. LOCAL(boolean)
  154554. process_restartp (j_decompress_ptr cinfo)
  154555. {
  154556. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154557. int ci;
  154558. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154559. entropy->bitstate.bits_left = 0;
  154560. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154561. return FALSE;
  154562. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154563. entropy->saved.last_dc_val[ci] = 0;
  154564. entropy->saved.EOBRUN = 0;
  154565. entropy->restarts_to_go = cinfo->restart_interval;
  154566. if (cinfo->unread_marker == 0)
  154567. entropy->pub.insufficient_data = FALSE;
  154568. return TRUE;
  154569. }
  154570. METHODDEF(boolean)
  154571. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154572. {
  154573. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154574. int Al = cinfo->Al;
  154575. register int s, r;
  154576. int blkn, ci;
  154577. JBLOCKROW block;
  154578. BITREAD_STATE_VARS;
  154579. savable_state3 state;
  154580. d_derived_tbl * tbl;
  154581. jpeg_component_info * compptr;
  154582. if (cinfo->restart_interval) {
  154583. if (entropy->restarts_to_go == 0)
  154584. if (! process_restartp(cinfo))
  154585. return FALSE;
  154586. }
  154587. if (! entropy->pub.insufficient_data) {
  154588. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154589. ASSIGN_STATE(state, entropy->saved);
  154590. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154591. block = MCU_data[blkn];
  154592. ci = cinfo->MCU_membership[blkn];
  154593. compptr = cinfo->cur_comp_info[ci];
  154594. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154595. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154596. if (s) {
  154597. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154598. r = GET_BITS(s);
  154599. s = HUFF_EXTEND(r, s);
  154600. }
  154601. s += state.last_dc_val[ci];
  154602. state.last_dc_val[ci] = s;
  154603. (*block)[0] = (JCOEF) (s << Al);
  154604. }
  154605. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154606. ASSIGN_STATE(entropy->saved, state);
  154607. }
  154608. entropy->restarts_to_go--;
  154609. return TRUE;
  154610. }
  154611. METHODDEF(boolean)
  154612. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154613. {
  154614. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154615. int Se = cinfo->Se;
  154616. int Al = cinfo->Al;
  154617. register int s, k, r;
  154618. unsigned int EOBRUN;
  154619. JBLOCKROW block;
  154620. BITREAD_STATE_VARS;
  154621. d_derived_tbl * tbl;
  154622. if (cinfo->restart_interval) {
  154623. if (entropy->restarts_to_go == 0)
  154624. if (! process_restartp(cinfo))
  154625. return FALSE;
  154626. }
  154627. if (! entropy->pub.insufficient_data) {
  154628. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154629. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154630. EOBRUN--; /* ...process it now (we do nothing) */
  154631. else {
  154632. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154633. block = MCU_data[0];
  154634. tbl = entropy->ac_derived_tbl;
  154635. for (k = cinfo->Ss; k <= Se; k++) {
  154636. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154637. r = s >> 4;
  154638. s &= 15;
  154639. if (s) {
  154640. k += r;
  154641. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154642. r = GET_BITS(s);
  154643. s = HUFF_EXTEND(r, s);
  154644. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154645. } else {
  154646. if (r == 15) { /* ZRL */
  154647. k += 15; /* skip 15 zeroes in band */
  154648. } else { /* EOBr, run length is 2^r + appended bits */
  154649. EOBRUN = 1 << r;
  154650. if (r) { /* EOBr, r > 0 */
  154651. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154652. r = GET_BITS(r);
  154653. EOBRUN += r;
  154654. }
  154655. EOBRUN--; /* this band is processed at this moment */
  154656. break; /* force end-of-band */
  154657. }
  154658. }
  154659. }
  154660. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154661. }
  154662. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154663. }
  154664. entropy->restarts_to_go--;
  154665. return TRUE;
  154666. }
  154667. METHODDEF(boolean)
  154668. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154669. {
  154670. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154671. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154672. int blkn;
  154673. JBLOCKROW block;
  154674. BITREAD_STATE_VARS;
  154675. if (cinfo->restart_interval) {
  154676. if (entropy->restarts_to_go == 0)
  154677. if (! process_restartp(cinfo))
  154678. return FALSE;
  154679. }
  154680. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154681. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154682. block = MCU_data[blkn];
  154683. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154684. if (GET_BITS(1))
  154685. (*block)[0] |= p1;
  154686. }
  154687. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154688. entropy->restarts_to_go--;
  154689. return TRUE;
  154690. }
  154691. METHODDEF(boolean)
  154692. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154693. {
  154694. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154695. int Se = cinfo->Se;
  154696. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154697. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154698. register int s, k, r;
  154699. unsigned int EOBRUN;
  154700. JBLOCKROW block;
  154701. JCOEFPTR thiscoef;
  154702. BITREAD_STATE_VARS;
  154703. d_derived_tbl * tbl;
  154704. int num_newnz;
  154705. int newnz_pos[DCTSIZE2];
  154706. if (cinfo->restart_interval) {
  154707. if (entropy->restarts_to_go == 0)
  154708. if (! process_restartp(cinfo))
  154709. return FALSE;
  154710. }
  154711. if (! entropy->pub.insufficient_data) {
  154712. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154713. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154714. block = MCU_data[0];
  154715. tbl = entropy->ac_derived_tbl;
  154716. num_newnz = 0;
  154717. k = cinfo->Ss;
  154718. if (EOBRUN == 0) {
  154719. for (; k <= Se; k++) {
  154720. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154721. r = s >> 4;
  154722. s &= 15;
  154723. if (s) {
  154724. if (s != 1) /* size of new coef should always be 1 */
  154725. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154726. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154727. if (GET_BITS(1))
  154728. s = p1; /* newly nonzero coef is positive */
  154729. else
  154730. s = m1; /* newly nonzero coef is negative */
  154731. } else {
  154732. if (r != 15) {
  154733. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154734. if (r) {
  154735. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154736. r = GET_BITS(r);
  154737. EOBRUN += r;
  154738. }
  154739. break; /* rest of block is handled by EOB logic */
  154740. }
  154741. }
  154742. do {
  154743. thiscoef = *block + jpeg_natural_order[k];
  154744. if (*thiscoef != 0) {
  154745. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154746. if (GET_BITS(1)) {
  154747. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154748. if (*thiscoef >= 0)
  154749. *thiscoef += p1;
  154750. else
  154751. *thiscoef += m1;
  154752. }
  154753. }
  154754. } else {
  154755. if (--r < 0)
  154756. break; /* reached target zero coefficient */
  154757. }
  154758. k++;
  154759. } while (k <= Se);
  154760. if (s) {
  154761. int pos = jpeg_natural_order[k];
  154762. (*block)[pos] = (JCOEF) s;
  154763. newnz_pos[num_newnz++] = pos;
  154764. }
  154765. }
  154766. }
  154767. if (EOBRUN > 0) {
  154768. for (; k <= Se; k++) {
  154769. thiscoef = *block + jpeg_natural_order[k];
  154770. if (*thiscoef != 0) {
  154771. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154772. if (GET_BITS(1)) {
  154773. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154774. if (*thiscoef >= 0)
  154775. *thiscoef += p1;
  154776. else
  154777. *thiscoef += m1;
  154778. }
  154779. }
  154780. }
  154781. }
  154782. EOBRUN--;
  154783. }
  154784. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154785. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154786. }
  154787. entropy->restarts_to_go--;
  154788. return TRUE;
  154789. undoit:
  154790. while (num_newnz > 0)
  154791. (*block)[newnz_pos[--num_newnz]] = 0;
  154792. return FALSE;
  154793. }
  154794. GLOBAL(void)
  154795. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154796. {
  154797. phuff_entropy_ptr2 entropy;
  154798. int *coef_bit_ptr;
  154799. int ci, i;
  154800. entropy = (phuff_entropy_ptr2)
  154801. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154802. SIZEOF(phuff_entropy_decoder));
  154803. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154804. entropy->pub.start_pass = start_pass_phuff_decoder;
  154805. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154806. entropy->derived_tbls[i] = NULL;
  154807. }
  154808. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154809. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154810. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154811. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154812. for (ci = 0; ci < cinfo->num_components; ci++)
  154813. for (i = 0; i < DCTSIZE2; i++)
  154814. *coef_bit_ptr++ = -1;
  154815. }
  154816. #endif /* D_PROGRESSIVE_SUPPORTED */
  154817. /*** End of inlined file: jdphuff.c ***/
  154818. /*** Start of inlined file: jdpostct.c ***/
  154819. #define JPEG_INTERNALS
  154820. typedef struct {
  154821. struct jpeg_d_post_controller pub; /* public fields */
  154822. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154823. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154824. JDIMENSION strip_height; /* buffer size in rows */
  154825. JDIMENSION starting_row; /* row # of first row in current strip */
  154826. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154827. } my_post_controller;
  154828. typedef my_post_controller * my_post_ptr;
  154829. METHODDEF(void) post_process_1pass
  154830. JPP((j_decompress_ptr cinfo,
  154831. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154832. JDIMENSION in_row_groups_avail,
  154833. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154834. JDIMENSION out_rows_avail));
  154835. #ifdef QUANT_2PASS_SUPPORTED
  154836. METHODDEF(void) post_process_prepass
  154837. JPP((j_decompress_ptr cinfo,
  154838. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154839. JDIMENSION in_row_groups_avail,
  154840. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154841. JDIMENSION out_rows_avail));
  154842. METHODDEF(void) post_process_2pass
  154843. JPP((j_decompress_ptr cinfo,
  154844. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154845. JDIMENSION in_row_groups_avail,
  154846. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154847. JDIMENSION out_rows_avail));
  154848. #endif
  154849. METHODDEF(void)
  154850. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154851. {
  154852. my_post_ptr post = (my_post_ptr) cinfo->post;
  154853. switch (pass_mode) {
  154854. case JBUF_PASS_THRU:
  154855. if (cinfo->quantize_colors) {
  154856. post->pub.post_process_data = post_process_1pass;
  154857. if (post->buffer == NULL) {
  154858. post->buffer = (*cinfo->mem->access_virt_sarray)
  154859. ((j_common_ptr) cinfo, post->whole_image,
  154860. (JDIMENSION) 0, post->strip_height, TRUE);
  154861. }
  154862. } else {
  154863. post->pub.post_process_data = cinfo->upsample->upsample;
  154864. }
  154865. break;
  154866. #ifdef QUANT_2PASS_SUPPORTED
  154867. case JBUF_SAVE_AND_PASS:
  154868. if (post->whole_image == NULL)
  154869. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154870. post->pub.post_process_data = post_process_prepass;
  154871. break;
  154872. case JBUF_CRANK_DEST:
  154873. if (post->whole_image == NULL)
  154874. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154875. post->pub.post_process_data = post_process_2pass;
  154876. break;
  154877. #endif /* QUANT_2PASS_SUPPORTED */
  154878. default:
  154879. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154880. break;
  154881. }
  154882. post->starting_row = post->next_row = 0;
  154883. }
  154884. METHODDEF(void)
  154885. post_process_1pass (j_decompress_ptr cinfo,
  154886. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154887. JDIMENSION in_row_groups_avail,
  154888. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154889. JDIMENSION out_rows_avail)
  154890. {
  154891. my_post_ptr post = (my_post_ptr) cinfo->post;
  154892. JDIMENSION num_rows, max_rows;
  154893. max_rows = out_rows_avail - *out_row_ctr;
  154894. if (max_rows > post->strip_height)
  154895. max_rows = post->strip_height;
  154896. num_rows = 0;
  154897. (*cinfo->upsample->upsample) (cinfo,
  154898. input_buf, in_row_group_ctr, in_row_groups_avail,
  154899. post->buffer, &num_rows, max_rows);
  154900. (*cinfo->cquantize->color_quantize) (cinfo,
  154901. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154902. *out_row_ctr += num_rows;
  154903. }
  154904. #ifdef QUANT_2PASS_SUPPORTED
  154905. METHODDEF(void)
  154906. post_process_prepass (j_decompress_ptr cinfo,
  154907. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154908. JDIMENSION in_row_groups_avail,
  154909. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154910. JDIMENSION out_rows_avail)
  154911. {
  154912. my_post_ptr post = (my_post_ptr) cinfo->post;
  154913. JDIMENSION old_next_row, num_rows;
  154914. if (post->next_row == 0) {
  154915. post->buffer = (*cinfo->mem->access_virt_sarray)
  154916. ((j_common_ptr) cinfo, post->whole_image,
  154917. post->starting_row, post->strip_height, TRUE);
  154918. }
  154919. old_next_row = post->next_row;
  154920. (*cinfo->upsample->upsample) (cinfo,
  154921. input_buf, in_row_group_ctr, in_row_groups_avail,
  154922. post->buffer, &post->next_row, post->strip_height);
  154923. if (post->next_row > old_next_row) {
  154924. num_rows = post->next_row - old_next_row;
  154925. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154926. (JSAMPARRAY) NULL, (int) num_rows);
  154927. *out_row_ctr += num_rows;
  154928. }
  154929. if (post->next_row >= post->strip_height) {
  154930. post->starting_row += post->strip_height;
  154931. post->next_row = 0;
  154932. }
  154933. }
  154934. METHODDEF(void)
  154935. post_process_2pass (j_decompress_ptr cinfo,
  154936. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154937. JDIMENSION in_row_groups_avail,
  154938. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154939. JDIMENSION out_rows_avail)
  154940. {
  154941. my_post_ptr post = (my_post_ptr) cinfo->post;
  154942. JDIMENSION num_rows, max_rows;
  154943. if (post->next_row == 0) {
  154944. post->buffer = (*cinfo->mem->access_virt_sarray)
  154945. ((j_common_ptr) cinfo, post->whole_image,
  154946. post->starting_row, post->strip_height, FALSE);
  154947. }
  154948. num_rows = post->strip_height - post->next_row; /* available in strip */
  154949. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154950. if (num_rows > max_rows)
  154951. num_rows = max_rows;
  154952. max_rows = cinfo->output_height - post->starting_row;
  154953. if (num_rows > max_rows)
  154954. num_rows = max_rows;
  154955. (*cinfo->cquantize->color_quantize) (cinfo,
  154956. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154957. (int) num_rows);
  154958. *out_row_ctr += num_rows;
  154959. post->next_row += num_rows;
  154960. if (post->next_row >= post->strip_height) {
  154961. post->starting_row += post->strip_height;
  154962. post->next_row = 0;
  154963. }
  154964. }
  154965. #endif /* QUANT_2PASS_SUPPORTED */
  154966. GLOBAL(void)
  154967. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154968. {
  154969. my_post_ptr post;
  154970. post = (my_post_ptr)
  154971. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154972. SIZEOF(my_post_controller));
  154973. cinfo->post = (struct jpeg_d_post_controller *) post;
  154974. post->pub.start_pass = start_pass_dpost;
  154975. post->whole_image = NULL; /* flag for no virtual arrays */
  154976. post->buffer = NULL; /* flag for no strip buffer */
  154977. if (cinfo->quantize_colors) {
  154978. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154979. if (need_full_buffer) {
  154980. #ifdef QUANT_2PASS_SUPPORTED
  154981. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154982. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154983. cinfo->output_width * cinfo->out_color_components,
  154984. (JDIMENSION) jround_up((long) cinfo->output_height,
  154985. (long) post->strip_height),
  154986. post->strip_height);
  154987. #else
  154988. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154989. #endif /* QUANT_2PASS_SUPPORTED */
  154990. } else {
  154991. post->buffer = (*cinfo->mem->alloc_sarray)
  154992. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154993. cinfo->output_width * cinfo->out_color_components,
  154994. post->strip_height);
  154995. }
  154996. }
  154997. }
  154998. /*** End of inlined file: jdpostct.c ***/
  154999. #undef FIX
  155000. /*** Start of inlined file: jdsample.c ***/
  155001. #define JPEG_INTERNALS
  155002. typedef JMETHOD(void, upsample1_ptr,
  155003. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155004. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  155005. typedef struct {
  155006. struct jpeg_upsampler pub; /* public fields */
  155007. JSAMPARRAY color_buf[MAX_COMPONENTS];
  155008. upsample1_ptr methods[MAX_COMPONENTS];
  155009. int next_row_out; /* counts rows emitted from color_buf */
  155010. JDIMENSION rows_to_go; /* counts rows remaining in image */
  155011. int rowgroup_height[MAX_COMPONENTS];
  155012. UINT8 h_expand[MAX_COMPONENTS];
  155013. UINT8 v_expand[MAX_COMPONENTS];
  155014. } my_upsampler2;
  155015. typedef my_upsampler2 * my_upsample_ptr2;
  155016. METHODDEF(void)
  155017. start_pass_upsample (j_decompress_ptr cinfo)
  155018. {
  155019. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155020. upsample->next_row_out = cinfo->max_v_samp_factor;
  155021. upsample->rows_to_go = cinfo->output_height;
  155022. }
  155023. METHODDEF(void)
  155024. sep_upsample (j_decompress_ptr cinfo,
  155025. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155026. JDIMENSION in_row_groups_avail,
  155027. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155028. JDIMENSION out_rows_avail)
  155029. {
  155030. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155031. int ci;
  155032. jpeg_component_info * compptr;
  155033. JDIMENSION num_rows;
  155034. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  155035. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155036. ci++, compptr++) {
  155037. (*upsample->methods[ci]) (cinfo, compptr,
  155038. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  155039. upsample->color_buf + ci);
  155040. }
  155041. upsample->next_row_out = 0;
  155042. }
  155043. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  155044. if (num_rows > upsample->rows_to_go)
  155045. num_rows = upsample->rows_to_go;
  155046. out_rows_avail -= *out_row_ctr;
  155047. if (num_rows > out_rows_avail)
  155048. num_rows = out_rows_avail;
  155049. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  155050. (JDIMENSION) upsample->next_row_out,
  155051. output_buf + *out_row_ctr,
  155052. (int) num_rows);
  155053. *out_row_ctr += num_rows;
  155054. upsample->rows_to_go -= num_rows;
  155055. upsample->next_row_out += num_rows;
  155056. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  155057. (*in_row_group_ctr)++;
  155058. }
  155059. METHODDEF(void)
  155060. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155061. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155062. {
  155063. *output_data_ptr = input_data;
  155064. }
  155065. METHODDEF(void)
  155066. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155067. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155068. {
  155069. *output_data_ptr = NULL; /* safety check */
  155070. }
  155071. METHODDEF(void)
  155072. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155073. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155074. {
  155075. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155076. JSAMPARRAY output_data = *output_data_ptr;
  155077. register JSAMPROW inptr, outptr;
  155078. register JSAMPLE invalue;
  155079. register int h;
  155080. JSAMPROW outend;
  155081. int h_expand, v_expand;
  155082. int inrow, outrow;
  155083. h_expand = upsample->h_expand[compptr->component_index];
  155084. v_expand = upsample->v_expand[compptr->component_index];
  155085. inrow = outrow = 0;
  155086. while (outrow < cinfo->max_v_samp_factor) {
  155087. inptr = input_data[inrow];
  155088. outptr = output_data[outrow];
  155089. outend = outptr + cinfo->output_width;
  155090. while (outptr < outend) {
  155091. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155092. for (h = h_expand; h > 0; h--) {
  155093. *outptr++ = invalue;
  155094. }
  155095. }
  155096. if (v_expand > 1) {
  155097. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155098. v_expand-1, cinfo->output_width);
  155099. }
  155100. inrow++;
  155101. outrow += v_expand;
  155102. }
  155103. }
  155104. METHODDEF(void)
  155105. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155106. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155107. {
  155108. JSAMPARRAY output_data = *output_data_ptr;
  155109. register JSAMPROW inptr, outptr;
  155110. register JSAMPLE invalue;
  155111. JSAMPROW outend;
  155112. int inrow;
  155113. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155114. inptr = input_data[inrow];
  155115. outptr = output_data[inrow];
  155116. outend = outptr + cinfo->output_width;
  155117. while (outptr < outend) {
  155118. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155119. *outptr++ = invalue;
  155120. *outptr++ = invalue;
  155121. }
  155122. }
  155123. }
  155124. METHODDEF(void)
  155125. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155126. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155127. {
  155128. JSAMPARRAY output_data = *output_data_ptr;
  155129. register JSAMPROW inptr, outptr;
  155130. register JSAMPLE invalue;
  155131. JSAMPROW outend;
  155132. int inrow, outrow;
  155133. inrow = outrow = 0;
  155134. while (outrow < cinfo->max_v_samp_factor) {
  155135. inptr = input_data[inrow];
  155136. outptr = output_data[outrow];
  155137. outend = outptr + cinfo->output_width;
  155138. while (outptr < outend) {
  155139. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155140. *outptr++ = invalue;
  155141. *outptr++ = invalue;
  155142. }
  155143. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155144. 1, cinfo->output_width);
  155145. inrow++;
  155146. outrow += 2;
  155147. }
  155148. }
  155149. METHODDEF(void)
  155150. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155151. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155152. {
  155153. JSAMPARRAY output_data = *output_data_ptr;
  155154. register JSAMPROW inptr, outptr;
  155155. register int invalue;
  155156. register JDIMENSION colctr;
  155157. int inrow;
  155158. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155159. inptr = input_data[inrow];
  155160. outptr = output_data[inrow];
  155161. invalue = GETJSAMPLE(*inptr++);
  155162. *outptr++ = (JSAMPLE) invalue;
  155163. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155164. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155165. invalue = GETJSAMPLE(*inptr++) * 3;
  155166. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155167. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155168. }
  155169. invalue = GETJSAMPLE(*inptr);
  155170. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155171. *outptr++ = (JSAMPLE) invalue;
  155172. }
  155173. }
  155174. METHODDEF(void)
  155175. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155176. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155177. {
  155178. JSAMPARRAY output_data = *output_data_ptr;
  155179. register JSAMPROW inptr0, inptr1, outptr;
  155180. #if BITS_IN_JSAMPLE == 8
  155181. register int thiscolsum, lastcolsum, nextcolsum;
  155182. #else
  155183. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155184. #endif
  155185. register JDIMENSION colctr;
  155186. int inrow, outrow, v;
  155187. inrow = outrow = 0;
  155188. while (outrow < cinfo->max_v_samp_factor) {
  155189. for (v = 0; v < 2; v++) {
  155190. inptr0 = input_data[inrow];
  155191. if (v == 0) /* next nearest is row above */
  155192. inptr1 = input_data[inrow-1];
  155193. else /* next nearest is row below */
  155194. inptr1 = input_data[inrow+1];
  155195. outptr = output_data[outrow++];
  155196. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155197. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155198. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155199. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155200. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155201. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155202. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155203. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155204. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155205. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155206. }
  155207. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155208. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155209. }
  155210. inrow++;
  155211. }
  155212. }
  155213. GLOBAL(void)
  155214. jinit_upsampler (j_decompress_ptr cinfo)
  155215. {
  155216. my_upsample_ptr2 upsample;
  155217. int ci;
  155218. jpeg_component_info * compptr;
  155219. boolean need_buffer, do_fancy;
  155220. int h_in_group, v_in_group, h_out_group, v_out_group;
  155221. upsample = (my_upsample_ptr2)
  155222. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155223. SIZEOF(my_upsampler2));
  155224. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155225. upsample->pub.start_pass = start_pass_upsample;
  155226. upsample->pub.upsample = sep_upsample;
  155227. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155228. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155229. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155230. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155231. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155232. ci++, compptr++) {
  155233. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155234. cinfo->min_DCT_scaled_size;
  155235. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155236. cinfo->min_DCT_scaled_size;
  155237. h_out_group = cinfo->max_h_samp_factor;
  155238. v_out_group = cinfo->max_v_samp_factor;
  155239. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155240. need_buffer = TRUE;
  155241. if (! compptr->component_needed) {
  155242. upsample->methods[ci] = noop_upsample;
  155243. need_buffer = FALSE;
  155244. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155245. upsample->methods[ci] = fullsize_upsample;
  155246. need_buffer = FALSE;
  155247. } else if (h_in_group * 2 == h_out_group &&
  155248. v_in_group == v_out_group) {
  155249. if (do_fancy && compptr->downsampled_width > 2)
  155250. upsample->methods[ci] = h2v1_fancy_upsample;
  155251. else
  155252. upsample->methods[ci] = h2v1_upsample;
  155253. } else if (h_in_group * 2 == h_out_group &&
  155254. v_in_group * 2 == v_out_group) {
  155255. if (do_fancy && compptr->downsampled_width > 2) {
  155256. upsample->methods[ci] = h2v2_fancy_upsample;
  155257. upsample->pub.need_context_rows = TRUE;
  155258. } else
  155259. upsample->methods[ci] = h2v2_upsample;
  155260. } else if ((h_out_group % h_in_group) == 0 &&
  155261. (v_out_group % v_in_group) == 0) {
  155262. upsample->methods[ci] = int_upsample;
  155263. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155264. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155265. } else
  155266. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155267. if (need_buffer) {
  155268. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155269. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155270. (JDIMENSION) jround_up((long) cinfo->output_width,
  155271. (long) cinfo->max_h_samp_factor),
  155272. (JDIMENSION) cinfo->max_v_samp_factor);
  155273. }
  155274. }
  155275. }
  155276. /*** End of inlined file: jdsample.c ***/
  155277. /*** Start of inlined file: jdtrans.c ***/
  155278. #define JPEG_INTERNALS
  155279. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155280. GLOBAL(jvirt_barray_ptr *)
  155281. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155282. {
  155283. if (cinfo->global_state == DSTATE_READY) {
  155284. transdecode_master_selection(cinfo);
  155285. cinfo->global_state = DSTATE_RDCOEFS;
  155286. }
  155287. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155288. for (;;) {
  155289. int retcode;
  155290. if (cinfo->progress != NULL)
  155291. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155292. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155293. if (retcode == JPEG_SUSPENDED)
  155294. return NULL;
  155295. if (retcode == JPEG_REACHED_EOI)
  155296. break;
  155297. if (cinfo->progress != NULL &&
  155298. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155299. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155300. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155301. }
  155302. }
  155303. }
  155304. cinfo->global_state = DSTATE_STOPPING;
  155305. }
  155306. if ((cinfo->global_state == DSTATE_STOPPING ||
  155307. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155308. return cinfo->coef->coef_arrays;
  155309. }
  155310. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155311. return NULL; /* keep compiler happy */
  155312. }
  155313. LOCAL(void)
  155314. transdecode_master_selection (j_decompress_ptr cinfo)
  155315. {
  155316. cinfo->buffered_image = TRUE;
  155317. if (cinfo->arith_code) {
  155318. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155319. } else {
  155320. if (cinfo->progressive_mode) {
  155321. #ifdef D_PROGRESSIVE_SUPPORTED
  155322. jinit_phuff_decoder(cinfo);
  155323. #else
  155324. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155325. #endif
  155326. } else
  155327. jinit_huff_decoder(cinfo);
  155328. }
  155329. jinit_d_coef_controller(cinfo, TRUE);
  155330. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155331. (*cinfo->inputctl->start_input_pass) (cinfo);
  155332. if (cinfo->progress != NULL) {
  155333. int nscans;
  155334. if (cinfo->progressive_mode) {
  155335. nscans = 2 + 3 * cinfo->num_components;
  155336. } else if (cinfo->inputctl->has_multiple_scans) {
  155337. nscans = cinfo->num_components;
  155338. } else {
  155339. nscans = 1;
  155340. }
  155341. cinfo->progress->pass_counter = 0L;
  155342. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155343. cinfo->progress->completed_passes = 0;
  155344. cinfo->progress->total_passes = 1;
  155345. }
  155346. }
  155347. /*** End of inlined file: jdtrans.c ***/
  155348. /*** Start of inlined file: jfdctflt.c ***/
  155349. #define JPEG_INTERNALS
  155350. #ifdef DCT_FLOAT_SUPPORTED
  155351. #if DCTSIZE != 8
  155352. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155353. #endif
  155354. GLOBAL(void)
  155355. jpeg_fdct_float (FAST_FLOAT * data)
  155356. {
  155357. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155358. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155359. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155360. FAST_FLOAT *dataptr;
  155361. int ctr;
  155362. dataptr = data;
  155363. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155364. tmp0 = dataptr[0] + dataptr[7];
  155365. tmp7 = dataptr[0] - dataptr[7];
  155366. tmp1 = dataptr[1] + dataptr[6];
  155367. tmp6 = dataptr[1] - dataptr[6];
  155368. tmp2 = dataptr[2] + dataptr[5];
  155369. tmp5 = dataptr[2] - dataptr[5];
  155370. tmp3 = dataptr[3] + dataptr[4];
  155371. tmp4 = dataptr[3] - dataptr[4];
  155372. tmp10 = tmp0 + tmp3; /* phase 2 */
  155373. tmp13 = tmp0 - tmp3;
  155374. tmp11 = tmp1 + tmp2;
  155375. tmp12 = tmp1 - tmp2;
  155376. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155377. dataptr[4] = tmp10 - tmp11;
  155378. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155379. dataptr[2] = tmp13 + z1; /* phase 5 */
  155380. dataptr[6] = tmp13 - z1;
  155381. tmp10 = tmp4 + tmp5; /* phase 2 */
  155382. tmp11 = tmp5 + tmp6;
  155383. tmp12 = tmp6 + tmp7;
  155384. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155385. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155386. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155387. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155388. z11 = tmp7 + z3; /* phase 5 */
  155389. z13 = tmp7 - z3;
  155390. dataptr[5] = z13 + z2; /* phase 6 */
  155391. dataptr[3] = z13 - z2;
  155392. dataptr[1] = z11 + z4;
  155393. dataptr[7] = z11 - z4;
  155394. dataptr += DCTSIZE; /* advance pointer to next row */
  155395. }
  155396. dataptr = data;
  155397. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155398. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155399. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155400. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155401. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155402. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155403. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155404. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155405. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155406. tmp10 = tmp0 + tmp3; /* phase 2 */
  155407. tmp13 = tmp0 - tmp3;
  155408. tmp11 = tmp1 + tmp2;
  155409. tmp12 = tmp1 - tmp2;
  155410. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155411. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155412. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155413. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155414. dataptr[DCTSIZE*6] = tmp13 - z1;
  155415. tmp10 = tmp4 + tmp5; /* phase 2 */
  155416. tmp11 = tmp5 + tmp6;
  155417. tmp12 = tmp6 + tmp7;
  155418. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155419. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155420. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155421. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155422. z11 = tmp7 + z3; /* phase 5 */
  155423. z13 = tmp7 - z3;
  155424. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155425. dataptr[DCTSIZE*3] = z13 - z2;
  155426. dataptr[DCTSIZE*1] = z11 + z4;
  155427. dataptr[DCTSIZE*7] = z11 - z4;
  155428. dataptr++; /* advance pointer to next column */
  155429. }
  155430. }
  155431. #endif /* DCT_FLOAT_SUPPORTED */
  155432. /*** End of inlined file: jfdctflt.c ***/
  155433. /*** Start of inlined file: jfdctint.c ***/
  155434. #define JPEG_INTERNALS
  155435. #ifdef DCT_ISLOW_SUPPORTED
  155436. #if DCTSIZE != 8
  155437. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155438. #endif
  155439. #if BITS_IN_JSAMPLE == 8
  155440. #define CONST_BITS 13
  155441. #define PASS1_BITS 2
  155442. #else
  155443. #define CONST_BITS 13
  155444. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155445. #endif
  155446. #if CONST_BITS == 13
  155447. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155448. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155449. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155450. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155451. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155452. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155453. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155454. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155455. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155456. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155457. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155458. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155459. #else
  155460. #define FIX_0_298631336 FIX(0.298631336)
  155461. #define FIX_0_390180644 FIX(0.390180644)
  155462. #define FIX_0_541196100 FIX(0.541196100)
  155463. #define FIX_0_765366865 FIX(0.765366865)
  155464. #define FIX_0_899976223 FIX(0.899976223)
  155465. #define FIX_1_175875602 FIX(1.175875602)
  155466. #define FIX_1_501321110 FIX(1.501321110)
  155467. #define FIX_1_847759065 FIX(1.847759065)
  155468. #define FIX_1_961570560 FIX(1.961570560)
  155469. #define FIX_2_053119869 FIX(2.053119869)
  155470. #define FIX_2_562915447 FIX(2.562915447)
  155471. #define FIX_3_072711026 FIX(3.072711026)
  155472. #endif
  155473. #if BITS_IN_JSAMPLE == 8
  155474. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155475. #else
  155476. #define MULTIPLY(var,const) ((var) * (const))
  155477. #endif
  155478. GLOBAL(void)
  155479. jpeg_fdct_islow (DCTELEM * data)
  155480. {
  155481. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155482. INT32 tmp10, tmp11, tmp12, tmp13;
  155483. INT32 z1, z2, z3, z4, z5;
  155484. DCTELEM *dataptr;
  155485. int ctr;
  155486. SHIFT_TEMPS
  155487. dataptr = data;
  155488. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155489. tmp0 = dataptr[0] + dataptr[7];
  155490. tmp7 = dataptr[0] - dataptr[7];
  155491. tmp1 = dataptr[1] + dataptr[6];
  155492. tmp6 = dataptr[1] - dataptr[6];
  155493. tmp2 = dataptr[2] + dataptr[5];
  155494. tmp5 = dataptr[2] - dataptr[5];
  155495. tmp3 = dataptr[3] + dataptr[4];
  155496. tmp4 = dataptr[3] - dataptr[4];
  155497. tmp10 = tmp0 + tmp3;
  155498. tmp13 = tmp0 - tmp3;
  155499. tmp11 = tmp1 + tmp2;
  155500. tmp12 = tmp1 - tmp2;
  155501. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155502. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155503. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155504. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155505. CONST_BITS-PASS1_BITS);
  155506. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155507. CONST_BITS-PASS1_BITS);
  155508. z1 = tmp4 + tmp7;
  155509. z2 = tmp5 + tmp6;
  155510. z3 = tmp4 + tmp6;
  155511. z4 = tmp5 + tmp7;
  155512. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155513. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155514. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155515. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155516. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155517. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155518. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155519. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155520. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155521. z3 += z5;
  155522. z4 += z5;
  155523. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155524. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155525. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155526. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155527. dataptr += DCTSIZE; /* advance pointer to next row */
  155528. }
  155529. dataptr = data;
  155530. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155531. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155532. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155533. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155534. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155535. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155536. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155537. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155538. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155539. tmp10 = tmp0 + tmp3;
  155540. tmp13 = tmp0 - tmp3;
  155541. tmp11 = tmp1 + tmp2;
  155542. tmp12 = tmp1 - tmp2;
  155543. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155544. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155545. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155546. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155547. CONST_BITS+PASS1_BITS);
  155548. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155549. CONST_BITS+PASS1_BITS);
  155550. z1 = tmp4 + tmp7;
  155551. z2 = tmp5 + tmp6;
  155552. z3 = tmp4 + tmp6;
  155553. z4 = tmp5 + tmp7;
  155554. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155555. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155556. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155557. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155558. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155559. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155560. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155561. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155562. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155563. z3 += z5;
  155564. z4 += z5;
  155565. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155566. CONST_BITS+PASS1_BITS);
  155567. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155568. CONST_BITS+PASS1_BITS);
  155569. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155570. CONST_BITS+PASS1_BITS);
  155571. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155572. CONST_BITS+PASS1_BITS);
  155573. dataptr++; /* advance pointer to next column */
  155574. }
  155575. }
  155576. #endif /* DCT_ISLOW_SUPPORTED */
  155577. /*** End of inlined file: jfdctint.c ***/
  155578. #undef CONST_BITS
  155579. #undef MULTIPLY
  155580. #undef FIX_0_541196100
  155581. /*** Start of inlined file: jfdctfst.c ***/
  155582. #define JPEG_INTERNALS
  155583. #ifdef DCT_IFAST_SUPPORTED
  155584. #if DCTSIZE != 8
  155585. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155586. #endif
  155587. #define CONST_BITS 8
  155588. #if CONST_BITS == 8
  155589. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155590. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155591. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155592. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155593. #else
  155594. #define FIX_0_382683433 FIX(0.382683433)
  155595. #define FIX_0_541196100 FIX(0.541196100)
  155596. #define FIX_0_707106781 FIX(0.707106781)
  155597. #define FIX_1_306562965 FIX(1.306562965)
  155598. #endif
  155599. #ifndef USE_ACCURATE_ROUNDING
  155600. #undef DESCALE
  155601. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155602. #endif
  155603. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155604. GLOBAL(void)
  155605. jpeg_fdct_ifast (DCTELEM * data)
  155606. {
  155607. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155608. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155609. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155610. DCTELEM *dataptr;
  155611. int ctr;
  155612. SHIFT_TEMPS
  155613. dataptr = data;
  155614. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155615. tmp0 = dataptr[0] + dataptr[7];
  155616. tmp7 = dataptr[0] - dataptr[7];
  155617. tmp1 = dataptr[1] + dataptr[6];
  155618. tmp6 = dataptr[1] - dataptr[6];
  155619. tmp2 = dataptr[2] + dataptr[5];
  155620. tmp5 = dataptr[2] - dataptr[5];
  155621. tmp3 = dataptr[3] + dataptr[4];
  155622. tmp4 = dataptr[3] - dataptr[4];
  155623. tmp10 = tmp0 + tmp3; /* phase 2 */
  155624. tmp13 = tmp0 - tmp3;
  155625. tmp11 = tmp1 + tmp2;
  155626. tmp12 = tmp1 - tmp2;
  155627. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155628. dataptr[4] = tmp10 - tmp11;
  155629. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155630. dataptr[2] = tmp13 + z1; /* phase 5 */
  155631. dataptr[6] = tmp13 - z1;
  155632. tmp10 = tmp4 + tmp5; /* phase 2 */
  155633. tmp11 = tmp5 + tmp6;
  155634. tmp12 = tmp6 + tmp7;
  155635. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155636. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155637. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155638. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155639. z11 = tmp7 + z3; /* phase 5 */
  155640. z13 = tmp7 - z3;
  155641. dataptr[5] = z13 + z2; /* phase 6 */
  155642. dataptr[3] = z13 - z2;
  155643. dataptr[1] = z11 + z4;
  155644. dataptr[7] = z11 - z4;
  155645. dataptr += DCTSIZE; /* advance pointer to next row */
  155646. }
  155647. dataptr = data;
  155648. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155649. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155650. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155651. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155652. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155653. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155654. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155655. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155656. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155657. tmp10 = tmp0 + tmp3; /* phase 2 */
  155658. tmp13 = tmp0 - tmp3;
  155659. tmp11 = tmp1 + tmp2;
  155660. tmp12 = tmp1 - tmp2;
  155661. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155662. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155663. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155664. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155665. dataptr[DCTSIZE*6] = tmp13 - z1;
  155666. tmp10 = tmp4 + tmp5; /* phase 2 */
  155667. tmp11 = tmp5 + tmp6;
  155668. tmp12 = tmp6 + tmp7;
  155669. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155670. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155671. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155672. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155673. z11 = tmp7 + z3; /* phase 5 */
  155674. z13 = tmp7 - z3;
  155675. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155676. dataptr[DCTSIZE*3] = z13 - z2;
  155677. dataptr[DCTSIZE*1] = z11 + z4;
  155678. dataptr[DCTSIZE*7] = z11 - z4;
  155679. dataptr++; /* advance pointer to next column */
  155680. }
  155681. }
  155682. #endif /* DCT_IFAST_SUPPORTED */
  155683. /*** End of inlined file: jfdctfst.c ***/
  155684. #undef FIX_0_541196100
  155685. /*** Start of inlined file: jidctflt.c ***/
  155686. #define JPEG_INTERNALS
  155687. #ifdef DCT_FLOAT_SUPPORTED
  155688. #if DCTSIZE != 8
  155689. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155690. #endif
  155691. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155692. GLOBAL(void)
  155693. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155694. JCOEFPTR coef_block,
  155695. JSAMPARRAY output_buf, JDIMENSION output_col)
  155696. {
  155697. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155698. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155699. FAST_FLOAT z5, z10, z11, z12, z13;
  155700. JCOEFPTR inptr;
  155701. FLOAT_MULT_TYPE * quantptr;
  155702. FAST_FLOAT * wsptr;
  155703. JSAMPROW outptr;
  155704. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155705. int ctr;
  155706. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155707. SHIFT_TEMPS
  155708. inptr = coef_block;
  155709. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155710. wsptr = workspace;
  155711. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155712. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155713. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155714. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155715. inptr[DCTSIZE*7] == 0) {
  155716. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155717. wsptr[DCTSIZE*0] = dcval;
  155718. wsptr[DCTSIZE*1] = dcval;
  155719. wsptr[DCTSIZE*2] = dcval;
  155720. wsptr[DCTSIZE*3] = dcval;
  155721. wsptr[DCTSIZE*4] = dcval;
  155722. wsptr[DCTSIZE*5] = dcval;
  155723. wsptr[DCTSIZE*6] = dcval;
  155724. wsptr[DCTSIZE*7] = dcval;
  155725. inptr++; /* advance pointers to next column */
  155726. quantptr++;
  155727. wsptr++;
  155728. continue;
  155729. }
  155730. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155731. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155732. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155733. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155734. tmp10 = tmp0 + tmp2; /* phase 3 */
  155735. tmp11 = tmp0 - tmp2;
  155736. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155737. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155738. tmp0 = tmp10 + tmp13; /* phase 2 */
  155739. tmp3 = tmp10 - tmp13;
  155740. tmp1 = tmp11 + tmp12;
  155741. tmp2 = tmp11 - tmp12;
  155742. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155743. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155744. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155745. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155746. z13 = tmp6 + tmp5; /* phase 6 */
  155747. z10 = tmp6 - tmp5;
  155748. z11 = tmp4 + tmp7;
  155749. z12 = tmp4 - tmp7;
  155750. tmp7 = z11 + z13; /* phase 5 */
  155751. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155752. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155753. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155754. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155755. tmp6 = tmp12 - tmp7; /* phase 2 */
  155756. tmp5 = tmp11 - tmp6;
  155757. tmp4 = tmp10 + tmp5;
  155758. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155759. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155760. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155761. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155762. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155763. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155764. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155765. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155766. inptr++; /* advance pointers to next column */
  155767. quantptr++;
  155768. wsptr++;
  155769. }
  155770. wsptr = workspace;
  155771. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155772. outptr = output_buf[ctr] + output_col;
  155773. tmp10 = wsptr[0] + wsptr[4];
  155774. tmp11 = wsptr[0] - wsptr[4];
  155775. tmp13 = wsptr[2] + wsptr[6];
  155776. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155777. tmp0 = tmp10 + tmp13;
  155778. tmp3 = tmp10 - tmp13;
  155779. tmp1 = tmp11 + tmp12;
  155780. tmp2 = tmp11 - tmp12;
  155781. z13 = wsptr[5] + wsptr[3];
  155782. z10 = wsptr[5] - wsptr[3];
  155783. z11 = wsptr[1] + wsptr[7];
  155784. z12 = wsptr[1] - wsptr[7];
  155785. tmp7 = z11 + z13;
  155786. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155787. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155788. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155789. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155790. tmp6 = tmp12 - tmp7;
  155791. tmp5 = tmp11 - tmp6;
  155792. tmp4 = tmp10 + tmp5;
  155793. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155794. & RANGE_MASK];
  155795. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155796. & RANGE_MASK];
  155797. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155798. & RANGE_MASK];
  155799. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155800. & RANGE_MASK];
  155801. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155802. & RANGE_MASK];
  155803. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155804. & RANGE_MASK];
  155805. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155806. & RANGE_MASK];
  155807. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155808. & RANGE_MASK];
  155809. wsptr += DCTSIZE; /* advance pointer to next row */
  155810. }
  155811. }
  155812. #endif /* DCT_FLOAT_SUPPORTED */
  155813. /*** End of inlined file: jidctflt.c ***/
  155814. #undef CONST_BITS
  155815. #undef FIX_1_847759065
  155816. #undef MULTIPLY
  155817. #undef DEQUANTIZE
  155818. #undef DESCALE
  155819. /*** Start of inlined file: jidctfst.c ***/
  155820. #define JPEG_INTERNALS
  155821. #ifdef DCT_IFAST_SUPPORTED
  155822. #if DCTSIZE != 8
  155823. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155824. #endif
  155825. #if BITS_IN_JSAMPLE == 8
  155826. #define CONST_BITS 8
  155827. #define PASS1_BITS 2
  155828. #else
  155829. #define CONST_BITS 8
  155830. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155831. #endif
  155832. #if CONST_BITS == 8
  155833. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155834. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155835. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155836. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155837. #else
  155838. #define FIX_1_082392200 FIX(1.082392200)
  155839. #define FIX_1_414213562 FIX(1.414213562)
  155840. #define FIX_1_847759065 FIX(1.847759065)
  155841. #define FIX_2_613125930 FIX(2.613125930)
  155842. #endif
  155843. #ifndef USE_ACCURATE_ROUNDING
  155844. #undef DESCALE
  155845. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155846. #endif
  155847. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155848. #if BITS_IN_JSAMPLE == 8
  155849. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155850. #else
  155851. #define DEQUANTIZE(coef,quantval) \
  155852. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155853. #endif
  155854. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155855. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155856. #if BITS_IN_JSAMPLE == 8
  155857. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155858. #else
  155859. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155860. #endif
  155861. #define IRIGHT_SHIFT(x,shft) \
  155862. ((ishift_temp = (x)) < 0 ? \
  155863. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155864. (ishift_temp >> (shft)))
  155865. #else
  155866. #define ISHIFT_TEMPS
  155867. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155868. #endif
  155869. #ifdef USE_ACCURATE_ROUNDING
  155870. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155871. #else
  155872. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155873. #endif
  155874. GLOBAL(void)
  155875. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155876. JCOEFPTR coef_block,
  155877. JSAMPARRAY output_buf, JDIMENSION output_col)
  155878. {
  155879. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155880. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155881. DCTELEM z5, z10, z11, z12, z13;
  155882. JCOEFPTR inptr;
  155883. IFAST_MULT_TYPE * quantptr;
  155884. int * wsptr;
  155885. JSAMPROW outptr;
  155886. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155887. int ctr;
  155888. int workspace[DCTSIZE2]; /* buffers data between passes */
  155889. SHIFT_TEMPS /* for DESCALE */
  155890. ISHIFT_TEMPS /* for IDESCALE */
  155891. inptr = coef_block;
  155892. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155893. wsptr = workspace;
  155894. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155895. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155896. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155897. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155898. inptr[DCTSIZE*7] == 0) {
  155899. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155900. wsptr[DCTSIZE*0] = dcval;
  155901. wsptr[DCTSIZE*1] = dcval;
  155902. wsptr[DCTSIZE*2] = dcval;
  155903. wsptr[DCTSIZE*3] = dcval;
  155904. wsptr[DCTSIZE*4] = dcval;
  155905. wsptr[DCTSIZE*5] = dcval;
  155906. wsptr[DCTSIZE*6] = dcval;
  155907. wsptr[DCTSIZE*7] = dcval;
  155908. inptr++; /* advance pointers to next column */
  155909. quantptr++;
  155910. wsptr++;
  155911. continue;
  155912. }
  155913. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155914. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155915. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155916. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155917. tmp10 = tmp0 + tmp2; /* phase 3 */
  155918. tmp11 = tmp0 - tmp2;
  155919. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155920. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155921. tmp0 = tmp10 + tmp13; /* phase 2 */
  155922. tmp3 = tmp10 - tmp13;
  155923. tmp1 = tmp11 + tmp12;
  155924. tmp2 = tmp11 - tmp12;
  155925. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155926. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155927. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155928. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155929. z13 = tmp6 + tmp5; /* phase 6 */
  155930. z10 = tmp6 - tmp5;
  155931. z11 = tmp4 + tmp7;
  155932. z12 = tmp4 - tmp7;
  155933. tmp7 = z11 + z13; /* phase 5 */
  155934. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155935. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155936. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155937. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155938. tmp6 = tmp12 - tmp7; /* phase 2 */
  155939. tmp5 = tmp11 - tmp6;
  155940. tmp4 = tmp10 + tmp5;
  155941. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155942. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155943. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155944. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155945. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155946. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155947. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155948. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155949. inptr++; /* advance pointers to next column */
  155950. quantptr++;
  155951. wsptr++;
  155952. }
  155953. wsptr = workspace;
  155954. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155955. outptr = output_buf[ctr] + output_col;
  155956. #ifndef NO_ZERO_ROW_TEST
  155957. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155958. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155959. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155960. & RANGE_MASK];
  155961. outptr[0] = dcval;
  155962. outptr[1] = dcval;
  155963. outptr[2] = dcval;
  155964. outptr[3] = dcval;
  155965. outptr[4] = dcval;
  155966. outptr[5] = dcval;
  155967. outptr[6] = dcval;
  155968. outptr[7] = dcval;
  155969. wsptr += DCTSIZE; /* advance pointer to next row */
  155970. continue;
  155971. }
  155972. #endif
  155973. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155974. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155975. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155976. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155977. - tmp13;
  155978. tmp0 = tmp10 + tmp13;
  155979. tmp3 = tmp10 - tmp13;
  155980. tmp1 = tmp11 + tmp12;
  155981. tmp2 = tmp11 - tmp12;
  155982. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155983. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155984. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155985. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155986. tmp7 = z11 + z13; /* phase 5 */
  155987. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155988. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155989. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155990. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155991. tmp6 = tmp12 - tmp7; /* phase 2 */
  155992. tmp5 = tmp11 - tmp6;
  155993. tmp4 = tmp10 + tmp5;
  155994. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155995. & RANGE_MASK];
  155996. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155997. & RANGE_MASK];
  155998. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155999. & RANGE_MASK];
  156000. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  156001. & RANGE_MASK];
  156002. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  156003. & RANGE_MASK];
  156004. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  156005. & RANGE_MASK];
  156006. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  156007. & RANGE_MASK];
  156008. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  156009. & RANGE_MASK];
  156010. wsptr += DCTSIZE; /* advance pointer to next row */
  156011. }
  156012. }
  156013. #endif /* DCT_IFAST_SUPPORTED */
  156014. /*** End of inlined file: jidctfst.c ***/
  156015. #undef CONST_BITS
  156016. #undef FIX_1_847759065
  156017. #undef MULTIPLY
  156018. #undef DEQUANTIZE
  156019. /*** Start of inlined file: jidctint.c ***/
  156020. #define JPEG_INTERNALS
  156021. #ifdef DCT_ISLOW_SUPPORTED
  156022. #if DCTSIZE != 8
  156023. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156024. #endif
  156025. #if BITS_IN_JSAMPLE == 8
  156026. #define CONST_BITS 13
  156027. #define PASS1_BITS 2
  156028. #else
  156029. #define CONST_BITS 13
  156030. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156031. #endif
  156032. #if CONST_BITS == 13
  156033. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  156034. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  156035. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  156036. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156037. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156038. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  156039. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  156040. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156041. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  156042. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  156043. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156044. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  156045. #else
  156046. #define FIX_0_298631336 FIX(0.298631336)
  156047. #define FIX_0_390180644 FIX(0.390180644)
  156048. #define FIX_0_541196100 FIX(0.541196100)
  156049. #define FIX_0_765366865 FIX(0.765366865)
  156050. #define FIX_0_899976223 FIX(0.899976223)
  156051. #define FIX_1_175875602 FIX(1.175875602)
  156052. #define FIX_1_501321110 FIX(1.501321110)
  156053. #define FIX_1_847759065 FIX(1.847759065)
  156054. #define FIX_1_961570560 FIX(1.961570560)
  156055. #define FIX_2_053119869 FIX(2.053119869)
  156056. #define FIX_2_562915447 FIX(2.562915447)
  156057. #define FIX_3_072711026 FIX(3.072711026)
  156058. #endif
  156059. #if BITS_IN_JSAMPLE == 8
  156060. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156061. #else
  156062. #define MULTIPLY(var,const) ((var) * (const))
  156063. #endif
  156064. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156065. GLOBAL(void)
  156066. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156067. JCOEFPTR coef_block,
  156068. JSAMPARRAY output_buf, JDIMENSION output_col)
  156069. {
  156070. INT32 tmp0, tmp1, tmp2, tmp3;
  156071. INT32 tmp10, tmp11, tmp12, tmp13;
  156072. INT32 z1, z2, z3, z4, z5;
  156073. JCOEFPTR inptr;
  156074. ISLOW_MULT_TYPE * quantptr;
  156075. int * wsptr;
  156076. JSAMPROW outptr;
  156077. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156078. int ctr;
  156079. int workspace[DCTSIZE2]; /* buffers data between passes */
  156080. SHIFT_TEMPS
  156081. inptr = coef_block;
  156082. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156083. wsptr = workspace;
  156084. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156085. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156086. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156087. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156088. inptr[DCTSIZE*7] == 0) {
  156089. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156090. wsptr[DCTSIZE*0] = dcval;
  156091. wsptr[DCTSIZE*1] = dcval;
  156092. wsptr[DCTSIZE*2] = dcval;
  156093. wsptr[DCTSIZE*3] = dcval;
  156094. wsptr[DCTSIZE*4] = dcval;
  156095. wsptr[DCTSIZE*5] = dcval;
  156096. wsptr[DCTSIZE*6] = dcval;
  156097. wsptr[DCTSIZE*7] = dcval;
  156098. inptr++; /* advance pointers to next column */
  156099. quantptr++;
  156100. wsptr++;
  156101. continue;
  156102. }
  156103. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156104. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156105. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156106. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156107. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156108. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156109. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156110. tmp0 = (z2 + z3) << CONST_BITS;
  156111. tmp1 = (z2 - z3) << CONST_BITS;
  156112. tmp10 = tmp0 + tmp3;
  156113. tmp13 = tmp0 - tmp3;
  156114. tmp11 = tmp1 + tmp2;
  156115. tmp12 = tmp1 - tmp2;
  156116. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156117. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156118. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156119. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156120. z1 = tmp0 + tmp3;
  156121. z2 = tmp1 + tmp2;
  156122. z3 = tmp0 + tmp2;
  156123. z4 = tmp1 + tmp3;
  156124. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156125. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156126. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156127. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156128. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156129. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156130. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156131. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156132. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156133. z3 += z5;
  156134. z4 += z5;
  156135. tmp0 += z1 + z3;
  156136. tmp1 += z2 + z4;
  156137. tmp2 += z2 + z3;
  156138. tmp3 += z1 + z4;
  156139. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156140. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156141. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156142. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156143. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156144. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156145. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156146. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156147. inptr++; /* advance pointers to next column */
  156148. quantptr++;
  156149. wsptr++;
  156150. }
  156151. wsptr = workspace;
  156152. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156153. outptr = output_buf[ctr] + output_col;
  156154. #ifndef NO_ZERO_ROW_TEST
  156155. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156156. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156157. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156158. & RANGE_MASK];
  156159. outptr[0] = dcval;
  156160. outptr[1] = dcval;
  156161. outptr[2] = dcval;
  156162. outptr[3] = dcval;
  156163. outptr[4] = dcval;
  156164. outptr[5] = dcval;
  156165. outptr[6] = dcval;
  156166. outptr[7] = dcval;
  156167. wsptr += DCTSIZE; /* advance pointer to next row */
  156168. continue;
  156169. }
  156170. #endif
  156171. z2 = (INT32) wsptr[2];
  156172. z3 = (INT32) wsptr[6];
  156173. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156174. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156175. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156176. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156177. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156178. tmp10 = tmp0 + tmp3;
  156179. tmp13 = tmp0 - tmp3;
  156180. tmp11 = tmp1 + tmp2;
  156181. tmp12 = tmp1 - tmp2;
  156182. tmp0 = (INT32) wsptr[7];
  156183. tmp1 = (INT32) wsptr[5];
  156184. tmp2 = (INT32) wsptr[3];
  156185. tmp3 = (INT32) wsptr[1];
  156186. z1 = tmp0 + tmp3;
  156187. z2 = tmp1 + tmp2;
  156188. z3 = tmp0 + tmp2;
  156189. z4 = tmp1 + tmp3;
  156190. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156191. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156192. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156193. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156194. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156195. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156196. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156197. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156198. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156199. z3 += z5;
  156200. z4 += z5;
  156201. tmp0 += z1 + z3;
  156202. tmp1 += z2 + z4;
  156203. tmp2 += z2 + z3;
  156204. tmp3 += z1 + z4;
  156205. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156206. CONST_BITS+PASS1_BITS+3)
  156207. & RANGE_MASK];
  156208. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156209. CONST_BITS+PASS1_BITS+3)
  156210. & RANGE_MASK];
  156211. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156212. CONST_BITS+PASS1_BITS+3)
  156213. & RANGE_MASK];
  156214. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156215. CONST_BITS+PASS1_BITS+3)
  156216. & RANGE_MASK];
  156217. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156218. CONST_BITS+PASS1_BITS+3)
  156219. & RANGE_MASK];
  156220. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156221. CONST_BITS+PASS1_BITS+3)
  156222. & RANGE_MASK];
  156223. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156224. CONST_BITS+PASS1_BITS+3)
  156225. & RANGE_MASK];
  156226. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156227. CONST_BITS+PASS1_BITS+3)
  156228. & RANGE_MASK];
  156229. wsptr += DCTSIZE; /* advance pointer to next row */
  156230. }
  156231. }
  156232. #endif /* DCT_ISLOW_SUPPORTED */
  156233. /*** End of inlined file: jidctint.c ***/
  156234. /*** Start of inlined file: jidctred.c ***/
  156235. #define JPEG_INTERNALS
  156236. #ifdef IDCT_SCALING_SUPPORTED
  156237. #if DCTSIZE != 8
  156238. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156239. #endif
  156240. #if BITS_IN_JSAMPLE == 8
  156241. #define CONST_BITS 13
  156242. #define PASS1_BITS 2
  156243. #else
  156244. #define CONST_BITS 13
  156245. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156246. #endif
  156247. #if CONST_BITS == 13
  156248. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156249. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156250. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156251. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156252. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156253. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156254. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156255. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156256. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156257. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156258. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156259. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156260. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156261. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156262. #else
  156263. #define FIX_0_211164243 FIX(0.211164243)
  156264. #define FIX_0_509795579 FIX(0.509795579)
  156265. #define FIX_0_601344887 FIX(0.601344887)
  156266. #define FIX_0_720959822 FIX(0.720959822)
  156267. #define FIX_0_765366865 FIX(0.765366865)
  156268. #define FIX_0_850430095 FIX(0.850430095)
  156269. #define FIX_0_899976223 FIX(0.899976223)
  156270. #define FIX_1_061594337 FIX(1.061594337)
  156271. #define FIX_1_272758580 FIX(1.272758580)
  156272. #define FIX_1_451774981 FIX(1.451774981)
  156273. #define FIX_1_847759065 FIX(1.847759065)
  156274. #define FIX_2_172734803 FIX(2.172734803)
  156275. #define FIX_2_562915447 FIX(2.562915447)
  156276. #define FIX_3_624509785 FIX(3.624509785)
  156277. #endif
  156278. #if BITS_IN_JSAMPLE == 8
  156279. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156280. #else
  156281. #define MULTIPLY(var,const) ((var) * (const))
  156282. #endif
  156283. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156284. GLOBAL(void)
  156285. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156286. JCOEFPTR coef_block,
  156287. JSAMPARRAY output_buf, JDIMENSION output_col)
  156288. {
  156289. INT32 tmp0, tmp2, tmp10, tmp12;
  156290. INT32 z1, z2, z3, z4;
  156291. JCOEFPTR inptr;
  156292. ISLOW_MULT_TYPE * quantptr;
  156293. int * wsptr;
  156294. JSAMPROW outptr;
  156295. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156296. int ctr;
  156297. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156298. SHIFT_TEMPS
  156299. inptr = coef_block;
  156300. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156301. wsptr = workspace;
  156302. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156303. if (ctr == DCTSIZE-4)
  156304. continue;
  156305. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156306. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156307. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156308. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156309. wsptr[DCTSIZE*0] = dcval;
  156310. wsptr[DCTSIZE*1] = dcval;
  156311. wsptr[DCTSIZE*2] = dcval;
  156312. wsptr[DCTSIZE*3] = dcval;
  156313. continue;
  156314. }
  156315. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156316. tmp0 <<= (CONST_BITS+1);
  156317. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156318. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156319. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156320. tmp10 = tmp0 + tmp2;
  156321. tmp12 = tmp0 - tmp2;
  156322. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156323. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156324. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156325. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156326. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156327. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156328. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156329. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156330. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156331. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156332. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156333. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156334. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156335. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156336. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156337. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156338. }
  156339. wsptr = workspace;
  156340. for (ctr = 0; ctr < 4; ctr++) {
  156341. outptr = output_buf[ctr] + output_col;
  156342. #ifndef NO_ZERO_ROW_TEST
  156343. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156344. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156345. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156346. & RANGE_MASK];
  156347. outptr[0] = dcval;
  156348. outptr[1] = dcval;
  156349. outptr[2] = dcval;
  156350. outptr[3] = dcval;
  156351. wsptr += DCTSIZE; /* advance pointer to next row */
  156352. continue;
  156353. }
  156354. #endif
  156355. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156356. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156357. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156358. tmp10 = tmp0 + tmp2;
  156359. tmp12 = tmp0 - tmp2;
  156360. z1 = (INT32) wsptr[7];
  156361. z2 = (INT32) wsptr[5];
  156362. z3 = (INT32) wsptr[3];
  156363. z4 = (INT32) wsptr[1];
  156364. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156365. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156366. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156367. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156368. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156369. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156370. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156371. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156372. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156373. CONST_BITS+PASS1_BITS+3+1)
  156374. & RANGE_MASK];
  156375. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156376. CONST_BITS+PASS1_BITS+3+1)
  156377. & RANGE_MASK];
  156378. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156379. CONST_BITS+PASS1_BITS+3+1)
  156380. & RANGE_MASK];
  156381. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156382. CONST_BITS+PASS1_BITS+3+1)
  156383. & RANGE_MASK];
  156384. wsptr += DCTSIZE; /* advance pointer to next row */
  156385. }
  156386. }
  156387. GLOBAL(void)
  156388. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156389. JCOEFPTR coef_block,
  156390. JSAMPARRAY output_buf, JDIMENSION output_col)
  156391. {
  156392. INT32 tmp0, tmp10, z1;
  156393. JCOEFPTR inptr;
  156394. ISLOW_MULT_TYPE * quantptr;
  156395. int * wsptr;
  156396. JSAMPROW outptr;
  156397. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156398. int ctr;
  156399. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156400. SHIFT_TEMPS
  156401. inptr = coef_block;
  156402. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156403. wsptr = workspace;
  156404. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156405. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156406. continue;
  156407. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156408. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156409. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156410. wsptr[DCTSIZE*0] = dcval;
  156411. wsptr[DCTSIZE*1] = dcval;
  156412. continue;
  156413. }
  156414. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156415. tmp10 = z1 << (CONST_BITS+2);
  156416. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156417. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156418. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156419. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156420. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156421. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156422. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156423. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156424. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156425. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156426. }
  156427. wsptr = workspace;
  156428. for (ctr = 0; ctr < 2; ctr++) {
  156429. outptr = output_buf[ctr] + output_col;
  156430. #ifndef NO_ZERO_ROW_TEST
  156431. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156432. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156433. & RANGE_MASK];
  156434. outptr[0] = dcval;
  156435. outptr[1] = dcval;
  156436. wsptr += DCTSIZE; /* advance pointer to next row */
  156437. continue;
  156438. }
  156439. #endif
  156440. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156441. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156442. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156443. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156444. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156445. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156446. CONST_BITS+PASS1_BITS+3+2)
  156447. & RANGE_MASK];
  156448. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156449. CONST_BITS+PASS1_BITS+3+2)
  156450. & RANGE_MASK];
  156451. wsptr += DCTSIZE; /* advance pointer to next row */
  156452. }
  156453. }
  156454. GLOBAL(void)
  156455. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156456. JCOEFPTR coef_block,
  156457. JSAMPARRAY output_buf, JDIMENSION output_col)
  156458. {
  156459. int dcval;
  156460. ISLOW_MULT_TYPE * quantptr;
  156461. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156462. SHIFT_TEMPS
  156463. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156464. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156465. dcval = (int) DESCALE((INT32) dcval, 3);
  156466. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156467. }
  156468. #endif /* IDCT_SCALING_SUPPORTED */
  156469. /*** End of inlined file: jidctred.c ***/
  156470. /*** Start of inlined file: jmemmgr.c ***/
  156471. #define JPEG_INTERNALS
  156472. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156473. /*** Start of inlined file: jmemsys.h ***/
  156474. #ifndef __jmemsys_h__
  156475. #define __jmemsys_h__
  156476. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156477. #define jpeg_get_small jGetSmall
  156478. #define jpeg_free_small jFreeSmall
  156479. #define jpeg_get_large jGetLarge
  156480. #define jpeg_free_large jFreeLarge
  156481. #define jpeg_mem_available jMemAvail
  156482. #define jpeg_open_backing_store jOpenBackStore
  156483. #define jpeg_mem_init jMemInit
  156484. #define jpeg_mem_term jMemTerm
  156485. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156486. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156487. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156488. size_t sizeofobject));
  156489. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156490. size_t sizeofobject));
  156491. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156492. size_t sizeofobject));
  156493. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156494. #define MAX_ALLOC_CHUNK 1000000000L
  156495. #endif
  156496. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156497. long min_bytes_needed,
  156498. long max_bytes_needed,
  156499. long already_allocated));
  156500. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156501. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156502. typedef unsigned short XMSH; /* type of extended-memory handles */
  156503. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156504. typedef union {
  156505. short file_handle; /* DOS file handle if it's a temp file */
  156506. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156507. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156508. } handle_union;
  156509. #endif /* USE_MSDOS_MEMMGR */
  156510. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156511. #include <Files.h>
  156512. #endif /* USE_MAC_MEMMGR */
  156513. //typedef struct backing_store_struct * backing_store_ptr;
  156514. typedef struct backing_store_struct {
  156515. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156516. struct backing_store_struct *info,
  156517. void FAR * buffer_address,
  156518. long file_offset, long byte_count));
  156519. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156520. struct backing_store_struct *info,
  156521. void FAR * buffer_address,
  156522. long file_offset, long byte_count));
  156523. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156524. struct backing_store_struct *info));
  156525. #ifdef USE_MSDOS_MEMMGR
  156526. handle_union handle; /* reference to backing-store storage object */
  156527. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156528. #else
  156529. #ifdef USE_MAC_MEMMGR
  156530. short temp_file; /* file reference number to temp file */
  156531. FSSpec tempSpec; /* the FSSpec for the temp file */
  156532. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156533. #else
  156534. FILE * temp_file; /* stdio reference to temp file */
  156535. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156536. #endif
  156537. #endif
  156538. } backing_store_info;
  156539. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156540. struct backing_store_struct *info,
  156541. long total_bytes_needed));
  156542. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156543. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156544. #endif
  156545. /*** End of inlined file: jmemsys.h ***/
  156546. /* import the system-dependent declarations */
  156547. #ifndef NO_GETENV
  156548. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156549. extern char * getenv JPP((const char * name));
  156550. #endif
  156551. #endif
  156552. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156553. #define ALIGN_TYPE double
  156554. #endif
  156555. typedef union small_pool_struct * small_pool_ptr;
  156556. typedef union small_pool_struct {
  156557. struct {
  156558. small_pool_ptr next; /* next in list of pools */
  156559. size_t bytes_used; /* how many bytes already used within pool */
  156560. size_t bytes_left; /* bytes still available in this pool */
  156561. } hdr;
  156562. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156563. } small_pool_hdr;
  156564. typedef union large_pool_struct FAR * large_pool_ptr;
  156565. typedef union large_pool_struct {
  156566. struct {
  156567. large_pool_ptr next; /* next in list of pools */
  156568. size_t bytes_used; /* how many bytes already used within pool */
  156569. size_t bytes_left; /* bytes still available in this pool */
  156570. } hdr;
  156571. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156572. } large_pool_hdr;
  156573. typedef struct {
  156574. struct jpeg_memory_mgr pub; /* public fields */
  156575. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156576. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156577. jvirt_sarray_ptr virt_sarray_list;
  156578. jvirt_barray_ptr virt_barray_list;
  156579. long total_space_allocated;
  156580. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156581. } my_memory_mgr;
  156582. typedef my_memory_mgr * my_mem_ptr;
  156583. struct jvirt_sarray_control {
  156584. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156585. JDIMENSION rows_in_array; /* total virtual array height */
  156586. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156587. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156588. JDIMENSION rows_in_mem; /* height of memory buffer */
  156589. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156590. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156591. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156592. boolean pre_zero; /* pre-zero mode requested? */
  156593. boolean dirty; /* do current buffer contents need written? */
  156594. boolean b_s_open; /* is backing-store data valid? */
  156595. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156596. backing_store_info b_s_info; /* System-dependent control info */
  156597. };
  156598. struct jvirt_barray_control {
  156599. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156600. JDIMENSION rows_in_array; /* total virtual array height */
  156601. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156602. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156603. JDIMENSION rows_in_mem; /* height of memory buffer */
  156604. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156605. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156606. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156607. boolean pre_zero; /* pre-zero mode requested? */
  156608. boolean dirty; /* do current buffer contents need written? */
  156609. boolean b_s_open; /* is backing-store data valid? */
  156610. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156611. backing_store_info b_s_info; /* System-dependent control info */
  156612. };
  156613. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156614. LOCAL(void)
  156615. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156616. {
  156617. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156618. small_pool_ptr shdr_ptr;
  156619. large_pool_ptr lhdr_ptr;
  156620. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156621. pool_id, mem->total_space_allocated);
  156622. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156623. lhdr_ptr = lhdr_ptr->hdr.next) {
  156624. fprintf(stderr, " Large chunk used %ld\n",
  156625. (long) lhdr_ptr->hdr.bytes_used);
  156626. }
  156627. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156628. shdr_ptr = shdr_ptr->hdr.next) {
  156629. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156630. (long) shdr_ptr->hdr.bytes_used,
  156631. (long) shdr_ptr->hdr.bytes_left);
  156632. }
  156633. }
  156634. #endif /* MEM_STATS */
  156635. LOCAL(void)
  156636. out_of_memory (j_common_ptr cinfo, int which)
  156637. {
  156638. #ifdef MEM_STATS
  156639. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156640. #endif
  156641. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156642. }
  156643. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156644. {
  156645. 1600, /* first PERMANENT pool */
  156646. 16000 /* first IMAGE pool */
  156647. };
  156648. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156649. {
  156650. 0, /* additional PERMANENT pools */
  156651. 5000 /* additional IMAGE pools */
  156652. };
  156653. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156654. METHODDEF(void *)
  156655. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156656. {
  156657. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156658. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156659. char * data_ptr;
  156660. size_t odd_bytes, min_request, slop;
  156661. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156662. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156663. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156664. if (odd_bytes > 0)
  156665. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156666. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156667. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156668. prev_hdr_ptr = NULL;
  156669. hdr_ptr = mem->small_list[pool_id];
  156670. while (hdr_ptr != NULL) {
  156671. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156672. break; /* found pool with enough space */
  156673. prev_hdr_ptr = hdr_ptr;
  156674. hdr_ptr = hdr_ptr->hdr.next;
  156675. }
  156676. if (hdr_ptr == NULL) {
  156677. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156678. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156679. slop = first_pool_slop[pool_id];
  156680. else
  156681. slop = extra_pool_slop[pool_id];
  156682. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156683. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156684. for (;;) {
  156685. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156686. if (hdr_ptr != NULL)
  156687. break;
  156688. slop /= 2;
  156689. if (slop < MIN_SLOP) /* give up when it gets real small */
  156690. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156691. }
  156692. mem->total_space_allocated += min_request + slop;
  156693. hdr_ptr->hdr.next = NULL;
  156694. hdr_ptr->hdr.bytes_used = 0;
  156695. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156696. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156697. mem->small_list[pool_id] = hdr_ptr;
  156698. else
  156699. prev_hdr_ptr->hdr.next = hdr_ptr;
  156700. }
  156701. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156702. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156703. hdr_ptr->hdr.bytes_used += sizeofobject;
  156704. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156705. return (void *) data_ptr;
  156706. }
  156707. METHODDEF(void FAR *)
  156708. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156709. {
  156710. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156711. large_pool_ptr hdr_ptr;
  156712. size_t odd_bytes;
  156713. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156714. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156715. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156716. if (odd_bytes > 0)
  156717. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156718. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156719. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156720. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156721. SIZEOF(large_pool_hdr));
  156722. if (hdr_ptr == NULL)
  156723. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156724. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156725. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156726. hdr_ptr->hdr.bytes_used = sizeofobject;
  156727. hdr_ptr->hdr.bytes_left = 0;
  156728. mem->large_list[pool_id] = hdr_ptr;
  156729. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156730. }
  156731. METHODDEF(JSAMPARRAY)
  156732. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156733. JDIMENSION samplesperrow, JDIMENSION numrows)
  156734. {
  156735. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156736. JSAMPARRAY result;
  156737. JSAMPROW workspace;
  156738. JDIMENSION rowsperchunk, currow, i;
  156739. long ltemp;
  156740. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156741. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156742. if (ltemp <= 0)
  156743. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156744. if (ltemp < (long) numrows)
  156745. rowsperchunk = (JDIMENSION) ltemp;
  156746. else
  156747. rowsperchunk = numrows;
  156748. mem->last_rowsperchunk = rowsperchunk;
  156749. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156750. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156751. currow = 0;
  156752. while (currow < numrows) {
  156753. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156754. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156755. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156756. * SIZEOF(JSAMPLE)));
  156757. for (i = rowsperchunk; i > 0; i--) {
  156758. result[currow++] = workspace;
  156759. workspace += samplesperrow;
  156760. }
  156761. }
  156762. return result;
  156763. }
  156764. METHODDEF(JBLOCKARRAY)
  156765. alloc_barray (j_common_ptr cinfo, int pool_id,
  156766. JDIMENSION blocksperrow, JDIMENSION numrows)
  156767. {
  156768. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156769. JBLOCKARRAY result;
  156770. JBLOCKROW workspace;
  156771. JDIMENSION rowsperchunk, currow, i;
  156772. long ltemp;
  156773. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156774. ((long) blocksperrow * SIZEOF(JBLOCK));
  156775. if (ltemp <= 0)
  156776. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156777. if (ltemp < (long) numrows)
  156778. rowsperchunk = (JDIMENSION) ltemp;
  156779. else
  156780. rowsperchunk = numrows;
  156781. mem->last_rowsperchunk = rowsperchunk;
  156782. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156783. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156784. currow = 0;
  156785. while (currow < numrows) {
  156786. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156787. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156788. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156789. * SIZEOF(JBLOCK)));
  156790. for (i = rowsperchunk; i > 0; i--) {
  156791. result[currow++] = workspace;
  156792. workspace += blocksperrow;
  156793. }
  156794. }
  156795. return result;
  156796. }
  156797. METHODDEF(jvirt_sarray_ptr)
  156798. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156799. JDIMENSION samplesperrow, JDIMENSION numrows,
  156800. JDIMENSION maxaccess)
  156801. {
  156802. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156803. jvirt_sarray_ptr result;
  156804. if (pool_id != JPOOL_IMAGE)
  156805. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156806. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156807. SIZEOF(struct jvirt_sarray_control));
  156808. result->mem_buffer = NULL; /* marks array not yet realized */
  156809. result->rows_in_array = numrows;
  156810. result->samplesperrow = samplesperrow;
  156811. result->maxaccess = maxaccess;
  156812. result->pre_zero = pre_zero;
  156813. result->b_s_open = FALSE; /* no associated backing-store object */
  156814. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156815. mem->virt_sarray_list = result;
  156816. return result;
  156817. }
  156818. METHODDEF(jvirt_barray_ptr)
  156819. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156820. JDIMENSION blocksperrow, JDIMENSION numrows,
  156821. JDIMENSION maxaccess)
  156822. {
  156823. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156824. jvirt_barray_ptr result;
  156825. if (pool_id != JPOOL_IMAGE)
  156826. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156827. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156828. SIZEOF(struct jvirt_barray_control));
  156829. result->mem_buffer = NULL; /* marks array not yet realized */
  156830. result->rows_in_array = numrows;
  156831. result->blocksperrow = blocksperrow;
  156832. result->maxaccess = maxaccess;
  156833. result->pre_zero = pre_zero;
  156834. result->b_s_open = FALSE; /* no associated backing-store object */
  156835. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156836. mem->virt_barray_list = result;
  156837. return result;
  156838. }
  156839. METHODDEF(void)
  156840. realize_virt_arrays (j_common_ptr cinfo)
  156841. {
  156842. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156843. long space_per_minheight, maximum_space, avail_mem;
  156844. long minheights, max_minheights;
  156845. jvirt_sarray_ptr sptr;
  156846. jvirt_barray_ptr bptr;
  156847. space_per_minheight = 0;
  156848. maximum_space = 0;
  156849. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156850. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156851. space_per_minheight += (long) sptr->maxaccess *
  156852. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156853. maximum_space += (long) sptr->rows_in_array *
  156854. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156855. }
  156856. }
  156857. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156858. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156859. space_per_minheight += (long) bptr->maxaccess *
  156860. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156861. maximum_space += (long) bptr->rows_in_array *
  156862. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156863. }
  156864. }
  156865. if (space_per_minheight <= 0)
  156866. return; /* no unrealized arrays, no work */
  156867. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156868. mem->total_space_allocated);
  156869. if (avail_mem >= maximum_space)
  156870. max_minheights = 1000000000L;
  156871. else {
  156872. max_minheights = avail_mem / space_per_minheight;
  156873. if (max_minheights <= 0)
  156874. max_minheights = 1;
  156875. }
  156876. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156877. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156878. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156879. if (minheights <= max_minheights) {
  156880. sptr->rows_in_mem = sptr->rows_in_array;
  156881. } else {
  156882. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156883. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156884. (long) sptr->rows_in_array *
  156885. (long) sptr->samplesperrow *
  156886. (long) SIZEOF(JSAMPLE));
  156887. sptr->b_s_open = TRUE;
  156888. }
  156889. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156890. sptr->samplesperrow, sptr->rows_in_mem);
  156891. sptr->rowsperchunk = mem->last_rowsperchunk;
  156892. sptr->cur_start_row = 0;
  156893. sptr->first_undef_row = 0;
  156894. sptr->dirty = FALSE;
  156895. }
  156896. }
  156897. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156898. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156899. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156900. if (minheights <= max_minheights) {
  156901. bptr->rows_in_mem = bptr->rows_in_array;
  156902. } else {
  156903. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156904. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156905. (long) bptr->rows_in_array *
  156906. (long) bptr->blocksperrow *
  156907. (long) SIZEOF(JBLOCK));
  156908. bptr->b_s_open = TRUE;
  156909. }
  156910. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156911. bptr->blocksperrow, bptr->rows_in_mem);
  156912. bptr->rowsperchunk = mem->last_rowsperchunk;
  156913. bptr->cur_start_row = 0;
  156914. bptr->first_undef_row = 0;
  156915. bptr->dirty = FALSE;
  156916. }
  156917. }
  156918. }
  156919. LOCAL(void)
  156920. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156921. {
  156922. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156923. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156924. file_offset = ptr->cur_start_row * bytesperrow;
  156925. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156926. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156927. thisrow = (long) ptr->cur_start_row + i;
  156928. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156929. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156930. if (rows <= 0) /* this chunk might be past end of file! */
  156931. break;
  156932. byte_count = rows * bytesperrow;
  156933. if (writing)
  156934. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156935. (void FAR *) ptr->mem_buffer[i],
  156936. file_offset, byte_count);
  156937. else
  156938. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156939. (void FAR *) ptr->mem_buffer[i],
  156940. file_offset, byte_count);
  156941. file_offset += byte_count;
  156942. }
  156943. }
  156944. LOCAL(void)
  156945. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156946. {
  156947. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156948. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156949. file_offset = ptr->cur_start_row * bytesperrow;
  156950. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156951. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156952. thisrow = (long) ptr->cur_start_row + i;
  156953. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156954. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156955. if (rows <= 0) /* this chunk might be past end of file! */
  156956. break;
  156957. byte_count = rows * bytesperrow;
  156958. if (writing)
  156959. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156960. (void FAR *) ptr->mem_buffer[i],
  156961. file_offset, byte_count);
  156962. else
  156963. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156964. (void FAR *) ptr->mem_buffer[i],
  156965. file_offset, byte_count);
  156966. file_offset += byte_count;
  156967. }
  156968. }
  156969. METHODDEF(JSAMPARRAY)
  156970. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156971. JDIMENSION start_row, JDIMENSION num_rows,
  156972. boolean writable)
  156973. {
  156974. JDIMENSION end_row = start_row + num_rows;
  156975. JDIMENSION undef_row;
  156976. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156977. ptr->mem_buffer == NULL)
  156978. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156979. if (start_row < ptr->cur_start_row ||
  156980. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156981. if (! ptr->b_s_open)
  156982. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156983. if (ptr->dirty) {
  156984. do_sarray_io(cinfo, ptr, TRUE);
  156985. ptr->dirty = FALSE;
  156986. }
  156987. if (start_row > ptr->cur_start_row) {
  156988. ptr->cur_start_row = start_row;
  156989. } else {
  156990. long ltemp;
  156991. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156992. if (ltemp < 0)
  156993. ltemp = 0; /* don't fall off front end of file */
  156994. ptr->cur_start_row = (JDIMENSION) ltemp;
  156995. }
  156996. do_sarray_io(cinfo, ptr, FALSE);
  156997. }
  156998. if (ptr->first_undef_row < end_row) {
  156999. if (ptr->first_undef_row < start_row) {
  157000. if (writable) /* writer skipped over a section of array */
  157001. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157002. undef_row = start_row; /* but reader is allowed to read ahead */
  157003. } else {
  157004. undef_row = ptr->first_undef_row;
  157005. }
  157006. if (writable)
  157007. ptr->first_undef_row = end_row;
  157008. if (ptr->pre_zero) {
  157009. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  157010. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157011. end_row -= ptr->cur_start_row;
  157012. while (undef_row < end_row) {
  157013. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157014. undef_row++;
  157015. }
  157016. } else {
  157017. if (! writable) /* reader looking at undefined data */
  157018. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157019. }
  157020. }
  157021. if (writable)
  157022. ptr->dirty = TRUE;
  157023. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157024. }
  157025. METHODDEF(JBLOCKARRAY)
  157026. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  157027. JDIMENSION start_row, JDIMENSION num_rows,
  157028. boolean writable)
  157029. {
  157030. JDIMENSION end_row = start_row + num_rows;
  157031. JDIMENSION undef_row;
  157032. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157033. ptr->mem_buffer == NULL)
  157034. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157035. if (start_row < ptr->cur_start_row ||
  157036. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157037. if (! ptr->b_s_open)
  157038. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157039. if (ptr->dirty) {
  157040. do_barray_io(cinfo, ptr, TRUE);
  157041. ptr->dirty = FALSE;
  157042. }
  157043. if (start_row > ptr->cur_start_row) {
  157044. ptr->cur_start_row = start_row;
  157045. } else {
  157046. long ltemp;
  157047. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157048. if (ltemp < 0)
  157049. ltemp = 0; /* don't fall off front end of file */
  157050. ptr->cur_start_row = (JDIMENSION) ltemp;
  157051. }
  157052. do_barray_io(cinfo, ptr, FALSE);
  157053. }
  157054. if (ptr->first_undef_row < end_row) {
  157055. if (ptr->first_undef_row < start_row) {
  157056. if (writable) /* writer skipped over a section of array */
  157057. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157058. undef_row = start_row; /* but reader is allowed to read ahead */
  157059. } else {
  157060. undef_row = ptr->first_undef_row;
  157061. }
  157062. if (writable)
  157063. ptr->first_undef_row = end_row;
  157064. if (ptr->pre_zero) {
  157065. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  157066. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157067. end_row -= ptr->cur_start_row;
  157068. while (undef_row < end_row) {
  157069. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157070. undef_row++;
  157071. }
  157072. } else {
  157073. if (! writable) /* reader looking at undefined data */
  157074. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157075. }
  157076. }
  157077. if (writable)
  157078. ptr->dirty = TRUE;
  157079. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157080. }
  157081. METHODDEF(void)
  157082. free_pool (j_common_ptr cinfo, int pool_id)
  157083. {
  157084. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157085. small_pool_ptr shdr_ptr;
  157086. large_pool_ptr lhdr_ptr;
  157087. size_t space_freed;
  157088. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157089. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157090. #ifdef MEM_STATS
  157091. if (cinfo->err->trace_level > 1)
  157092. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  157093. #endif
  157094. if (pool_id == JPOOL_IMAGE) {
  157095. jvirt_sarray_ptr sptr;
  157096. jvirt_barray_ptr bptr;
  157097. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157098. if (sptr->b_s_open) { /* there may be no backing store */
  157099. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157100. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157101. }
  157102. }
  157103. mem->virt_sarray_list = NULL;
  157104. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157105. if (bptr->b_s_open) { /* there may be no backing store */
  157106. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157107. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157108. }
  157109. }
  157110. mem->virt_barray_list = NULL;
  157111. }
  157112. lhdr_ptr = mem->large_list[pool_id];
  157113. mem->large_list[pool_id] = NULL;
  157114. while (lhdr_ptr != NULL) {
  157115. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157116. space_freed = lhdr_ptr->hdr.bytes_used +
  157117. lhdr_ptr->hdr.bytes_left +
  157118. SIZEOF(large_pool_hdr);
  157119. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157120. mem->total_space_allocated -= space_freed;
  157121. lhdr_ptr = next_lhdr_ptr;
  157122. }
  157123. shdr_ptr = mem->small_list[pool_id];
  157124. mem->small_list[pool_id] = NULL;
  157125. while (shdr_ptr != NULL) {
  157126. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157127. space_freed = shdr_ptr->hdr.bytes_used +
  157128. shdr_ptr->hdr.bytes_left +
  157129. SIZEOF(small_pool_hdr);
  157130. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157131. mem->total_space_allocated -= space_freed;
  157132. shdr_ptr = next_shdr_ptr;
  157133. }
  157134. }
  157135. METHODDEF(void)
  157136. self_destruct (j_common_ptr cinfo)
  157137. {
  157138. int pool;
  157139. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157140. free_pool(cinfo, pool);
  157141. }
  157142. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157143. cinfo->mem = NULL; /* ensures I will be called only once */
  157144. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157145. }
  157146. GLOBAL(void)
  157147. jinit_memory_mgr (j_common_ptr cinfo)
  157148. {
  157149. my_mem_ptr mem;
  157150. long max_to_use;
  157151. int pool;
  157152. size_t test_mac;
  157153. cinfo->mem = NULL; /* for safety if init fails */
  157154. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157155. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157156. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157157. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157158. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157159. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157160. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157161. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157162. if (mem == NULL) {
  157163. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157164. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157165. }
  157166. mem->pub.alloc_small = alloc_small;
  157167. mem->pub.alloc_large = alloc_large;
  157168. mem->pub.alloc_sarray = alloc_sarray;
  157169. mem->pub.alloc_barray = alloc_barray;
  157170. mem->pub.request_virt_sarray = request_virt_sarray;
  157171. mem->pub.request_virt_barray = request_virt_barray;
  157172. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157173. mem->pub.access_virt_sarray = access_virt_sarray;
  157174. mem->pub.access_virt_barray = access_virt_barray;
  157175. mem->pub.free_pool = free_pool;
  157176. mem->pub.self_destruct = self_destruct;
  157177. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157178. mem->pub.max_memory_to_use = max_to_use;
  157179. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157180. mem->small_list[pool] = NULL;
  157181. mem->large_list[pool] = NULL;
  157182. }
  157183. mem->virt_sarray_list = NULL;
  157184. mem->virt_barray_list = NULL;
  157185. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157186. cinfo->mem = & mem->pub;
  157187. #ifndef NO_GETENV
  157188. { char * memenv;
  157189. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157190. char ch = 'x';
  157191. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157192. if (ch == 'm' || ch == 'M')
  157193. max_to_use *= 1000L;
  157194. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157195. }
  157196. }
  157197. }
  157198. #endif
  157199. }
  157200. /*** End of inlined file: jmemmgr.c ***/
  157201. /*** Start of inlined file: jmemnobs.c ***/
  157202. #define JPEG_INTERNALS
  157203. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157204. extern void * malloc JPP((size_t size));
  157205. extern void free JPP((void *ptr));
  157206. #endif
  157207. GLOBAL(void *)
  157208. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157209. {
  157210. return (void *) malloc(sizeofobject);
  157211. }
  157212. GLOBAL(void)
  157213. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157214. {
  157215. free(object);
  157216. }
  157217. GLOBAL(void FAR *)
  157218. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157219. {
  157220. return (void FAR *) malloc(sizeofobject);
  157221. }
  157222. GLOBAL(void)
  157223. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157224. {
  157225. free(object);
  157226. }
  157227. GLOBAL(long)
  157228. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157229. long max_bytes_needed, long already_allocated)
  157230. {
  157231. return max_bytes_needed;
  157232. }
  157233. GLOBAL(void)
  157234. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157235. long total_bytes_needed)
  157236. {
  157237. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157238. }
  157239. GLOBAL(long)
  157240. jpeg_mem_init (j_common_ptr cinfo)
  157241. {
  157242. return 0; /* just set max_memory_to_use to 0 */
  157243. }
  157244. GLOBAL(void)
  157245. jpeg_mem_term (j_common_ptr cinfo)
  157246. {
  157247. }
  157248. /*** End of inlined file: jmemnobs.c ***/
  157249. /*** Start of inlined file: jquant1.c ***/
  157250. #define JPEG_INTERNALS
  157251. #ifdef QUANT_1PASS_SUPPORTED
  157252. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157253. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157254. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157255. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157256. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157257. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157258. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157259. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157260. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157261. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157262. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157263. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157264. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157265. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157266. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157267. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157268. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157269. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157270. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157271. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157272. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157273. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157274. };
  157275. #if BITS_IN_JSAMPLE == 8
  157276. typedef INT16 FSERROR; /* 16 bits should be enough */
  157277. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157278. #else
  157279. typedef INT32 FSERROR; /* may need more than 16 bits */
  157280. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157281. #endif
  157282. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157283. #define MAX_Q_COMPS 4 /* max components I can handle */
  157284. typedef struct {
  157285. struct jpeg_color_quantizer pub; /* public fields */
  157286. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157287. int sv_actual; /* number of entries in use */
  157288. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157289. boolean is_padded; /* is the colorindex padded for odither? */
  157290. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157291. int row_index; /* cur row's vertical index in dither matrix */
  157292. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157293. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157294. boolean on_odd_row; /* flag to remember which row we are on */
  157295. } my_cquantizer;
  157296. typedef my_cquantizer * my_cquantize_ptr;
  157297. LOCAL(int)
  157298. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157299. {
  157300. int nc = cinfo->out_color_components; /* number of color components */
  157301. int max_colors = cinfo->desired_number_of_colors;
  157302. int total_colors, iroot, i, j;
  157303. boolean changed;
  157304. long temp;
  157305. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157306. iroot = 1;
  157307. do {
  157308. iroot++;
  157309. temp = iroot; /* set temp = iroot ** nc */
  157310. for (i = 1; i < nc; i++)
  157311. temp *= iroot;
  157312. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157313. iroot--; /* now iroot = floor(root) */
  157314. if (iroot < 2)
  157315. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157316. total_colors = 1;
  157317. for (i = 0; i < nc; i++) {
  157318. Ncolors[i] = iroot;
  157319. total_colors *= iroot;
  157320. }
  157321. do {
  157322. changed = FALSE;
  157323. for (i = 0; i < nc; i++) {
  157324. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157325. temp = total_colors / Ncolors[j];
  157326. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157327. if (temp > (long) max_colors)
  157328. break; /* won't fit, done with this pass */
  157329. Ncolors[j]++; /* OK, apply the increment */
  157330. total_colors = (int) temp;
  157331. changed = TRUE;
  157332. }
  157333. } while (changed);
  157334. return total_colors;
  157335. }
  157336. LOCAL(int)
  157337. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157338. {
  157339. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157340. }
  157341. LOCAL(int)
  157342. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157343. {
  157344. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157345. }
  157346. LOCAL(void)
  157347. create_colormap (j_decompress_ptr cinfo)
  157348. {
  157349. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157350. JSAMPARRAY colormap; /* Created colormap */
  157351. int total_colors; /* Number of distinct output colors */
  157352. int i,j,k, nci, blksize, blkdist, ptr, val;
  157353. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157354. if (cinfo->out_color_components == 3)
  157355. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157356. total_colors, cquantize->Ncolors[0],
  157357. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157358. else
  157359. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157360. colormap = (*cinfo->mem->alloc_sarray)
  157361. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157362. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157363. blkdist = total_colors;
  157364. for (i = 0; i < cinfo->out_color_components; i++) {
  157365. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157366. blksize = blkdist / nci;
  157367. for (j = 0; j < nci; j++) {
  157368. val = output_value(cinfo, i, j, nci-1);
  157369. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157370. for (k = 0; k < blksize; k++)
  157371. colormap[i][ptr+k] = (JSAMPLE) val;
  157372. }
  157373. }
  157374. blkdist = blksize; /* blksize of this color is blkdist of next */
  157375. }
  157376. cquantize->sv_colormap = colormap;
  157377. cquantize->sv_actual = total_colors;
  157378. }
  157379. LOCAL(void)
  157380. create_colorindex (j_decompress_ptr cinfo)
  157381. {
  157382. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157383. JSAMPROW indexptr;
  157384. int i,j,k, nci, blksize, val, pad;
  157385. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157386. pad = MAXJSAMPLE*2;
  157387. cquantize->is_padded = TRUE;
  157388. } else {
  157389. pad = 0;
  157390. cquantize->is_padded = FALSE;
  157391. }
  157392. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157393. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157394. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157395. (JDIMENSION) cinfo->out_color_components);
  157396. blksize = cquantize->sv_actual;
  157397. for (i = 0; i < cinfo->out_color_components; i++) {
  157398. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157399. blksize = blksize / nci;
  157400. if (pad)
  157401. cquantize->colorindex[i] += MAXJSAMPLE;
  157402. indexptr = cquantize->colorindex[i];
  157403. val = 0;
  157404. k = largest_input_value(cinfo, i, 0, nci-1);
  157405. for (j = 0; j <= MAXJSAMPLE; j++) {
  157406. while (j > k) /* advance val if past boundary */
  157407. k = largest_input_value(cinfo, i, ++val, nci-1);
  157408. indexptr[j] = (JSAMPLE) (val * blksize);
  157409. }
  157410. if (pad)
  157411. for (j = 1; j <= MAXJSAMPLE; j++) {
  157412. indexptr[-j] = indexptr[0];
  157413. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157414. }
  157415. }
  157416. }
  157417. LOCAL(ODITHER_MATRIX_PTR)
  157418. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157419. {
  157420. ODITHER_MATRIX_PTR odither;
  157421. int j,k;
  157422. INT32 num,den;
  157423. odither = (ODITHER_MATRIX_PTR)
  157424. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157425. SIZEOF(ODITHER_MATRIX));
  157426. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157427. for (j = 0; j < ODITHER_SIZE; j++) {
  157428. for (k = 0; k < ODITHER_SIZE; k++) {
  157429. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157430. * MAXJSAMPLE;
  157431. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157432. }
  157433. }
  157434. return odither;
  157435. }
  157436. LOCAL(void)
  157437. create_odither_tables (j_decompress_ptr cinfo)
  157438. {
  157439. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157440. ODITHER_MATRIX_PTR odither;
  157441. int i, j, nci;
  157442. for (i = 0; i < cinfo->out_color_components; i++) {
  157443. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157444. odither = NULL; /* search for matching prior component */
  157445. for (j = 0; j < i; j++) {
  157446. if (nci == cquantize->Ncolors[j]) {
  157447. odither = cquantize->odither[j];
  157448. break;
  157449. }
  157450. }
  157451. if (odither == NULL) /* need a new table? */
  157452. odither = make_odither_array(cinfo, nci);
  157453. cquantize->odither[i] = odither;
  157454. }
  157455. }
  157456. METHODDEF(void)
  157457. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157458. JSAMPARRAY output_buf, int num_rows)
  157459. {
  157460. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157461. JSAMPARRAY colorindex = cquantize->colorindex;
  157462. register int pixcode, ci;
  157463. register JSAMPROW ptrin, ptrout;
  157464. int row;
  157465. JDIMENSION col;
  157466. JDIMENSION width = cinfo->output_width;
  157467. register int nc = cinfo->out_color_components;
  157468. for (row = 0; row < num_rows; row++) {
  157469. ptrin = input_buf[row];
  157470. ptrout = output_buf[row];
  157471. for (col = width; col > 0; col--) {
  157472. pixcode = 0;
  157473. for (ci = 0; ci < nc; ci++) {
  157474. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157475. }
  157476. *ptrout++ = (JSAMPLE) pixcode;
  157477. }
  157478. }
  157479. }
  157480. METHODDEF(void)
  157481. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157482. JSAMPARRAY output_buf, int num_rows)
  157483. {
  157484. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157485. register int pixcode;
  157486. register JSAMPROW ptrin, ptrout;
  157487. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157488. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157489. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157490. int row;
  157491. JDIMENSION col;
  157492. JDIMENSION width = cinfo->output_width;
  157493. for (row = 0; row < num_rows; row++) {
  157494. ptrin = input_buf[row];
  157495. ptrout = output_buf[row];
  157496. for (col = width; col > 0; col--) {
  157497. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157498. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157499. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157500. *ptrout++ = (JSAMPLE) pixcode;
  157501. }
  157502. }
  157503. }
  157504. METHODDEF(void)
  157505. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157506. JSAMPARRAY output_buf, int num_rows)
  157507. {
  157508. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157509. register JSAMPROW input_ptr;
  157510. register JSAMPROW output_ptr;
  157511. JSAMPROW colorindex_ci;
  157512. int * dither; /* points to active row of dither matrix */
  157513. int row_index, col_index; /* current indexes into dither matrix */
  157514. int nc = cinfo->out_color_components;
  157515. int ci;
  157516. int row;
  157517. JDIMENSION col;
  157518. JDIMENSION width = cinfo->output_width;
  157519. for (row = 0; row < num_rows; row++) {
  157520. jzero_far((void FAR *) output_buf[row],
  157521. (size_t) (width * SIZEOF(JSAMPLE)));
  157522. row_index = cquantize->row_index;
  157523. for (ci = 0; ci < nc; ci++) {
  157524. input_ptr = input_buf[row] + ci;
  157525. output_ptr = output_buf[row];
  157526. colorindex_ci = cquantize->colorindex[ci];
  157527. dither = cquantize->odither[ci][row_index];
  157528. col_index = 0;
  157529. for (col = width; col > 0; col--) {
  157530. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157531. input_ptr += nc;
  157532. output_ptr++;
  157533. col_index = (col_index + 1) & ODITHER_MASK;
  157534. }
  157535. }
  157536. row_index = (row_index + 1) & ODITHER_MASK;
  157537. cquantize->row_index = row_index;
  157538. }
  157539. }
  157540. METHODDEF(void)
  157541. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157542. JSAMPARRAY output_buf, int num_rows)
  157543. {
  157544. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157545. register int pixcode;
  157546. register JSAMPROW input_ptr;
  157547. register JSAMPROW output_ptr;
  157548. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157549. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157550. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157551. int * dither0; /* points to active row of dither matrix */
  157552. int * dither1;
  157553. int * dither2;
  157554. int row_index, col_index; /* current indexes into dither matrix */
  157555. int row;
  157556. JDIMENSION col;
  157557. JDIMENSION width = cinfo->output_width;
  157558. for (row = 0; row < num_rows; row++) {
  157559. row_index = cquantize->row_index;
  157560. input_ptr = input_buf[row];
  157561. output_ptr = output_buf[row];
  157562. dither0 = cquantize->odither[0][row_index];
  157563. dither1 = cquantize->odither[1][row_index];
  157564. dither2 = cquantize->odither[2][row_index];
  157565. col_index = 0;
  157566. for (col = width; col > 0; col--) {
  157567. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157568. dither0[col_index]]);
  157569. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157570. dither1[col_index]]);
  157571. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157572. dither2[col_index]]);
  157573. *output_ptr++ = (JSAMPLE) pixcode;
  157574. col_index = (col_index + 1) & ODITHER_MASK;
  157575. }
  157576. row_index = (row_index + 1) & ODITHER_MASK;
  157577. cquantize->row_index = row_index;
  157578. }
  157579. }
  157580. METHODDEF(void)
  157581. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157582. JSAMPARRAY output_buf, int num_rows)
  157583. {
  157584. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157585. register LOCFSERROR cur; /* current error or pixel value */
  157586. LOCFSERROR belowerr; /* error for pixel below cur */
  157587. LOCFSERROR bpreverr; /* error for below/prev col */
  157588. LOCFSERROR bnexterr; /* error for below/next col */
  157589. LOCFSERROR delta;
  157590. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157591. register JSAMPROW input_ptr;
  157592. register JSAMPROW output_ptr;
  157593. JSAMPROW colorindex_ci;
  157594. JSAMPROW colormap_ci;
  157595. int pixcode;
  157596. int nc = cinfo->out_color_components;
  157597. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157598. int dirnc; /* dir * nc */
  157599. int ci;
  157600. int row;
  157601. JDIMENSION col;
  157602. JDIMENSION width = cinfo->output_width;
  157603. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157604. SHIFT_TEMPS
  157605. for (row = 0; row < num_rows; row++) {
  157606. jzero_far((void FAR *) output_buf[row],
  157607. (size_t) (width * SIZEOF(JSAMPLE)));
  157608. for (ci = 0; ci < nc; ci++) {
  157609. input_ptr = input_buf[row] + ci;
  157610. output_ptr = output_buf[row];
  157611. if (cquantize->on_odd_row) {
  157612. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157613. output_ptr += width-1;
  157614. dir = -1;
  157615. dirnc = -nc;
  157616. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157617. } else {
  157618. dir = 1;
  157619. dirnc = nc;
  157620. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157621. }
  157622. colorindex_ci = cquantize->colorindex[ci];
  157623. colormap_ci = cquantize->sv_colormap[ci];
  157624. cur = 0;
  157625. belowerr = bpreverr = 0;
  157626. for (col = width; col > 0; col--) {
  157627. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157628. cur += GETJSAMPLE(*input_ptr);
  157629. cur = GETJSAMPLE(range_limit[cur]);
  157630. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157631. *output_ptr += (JSAMPLE) pixcode;
  157632. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157633. bnexterr = cur;
  157634. delta = cur * 2;
  157635. cur += delta; /* form error * 3 */
  157636. errorptr[0] = (FSERROR) (bpreverr + cur);
  157637. cur += delta; /* form error * 5 */
  157638. bpreverr = belowerr + cur;
  157639. belowerr = bnexterr;
  157640. cur += delta; /* form error * 7 */
  157641. input_ptr += dirnc; /* advance input ptr to next column */
  157642. output_ptr += dir; /* advance output ptr to next column */
  157643. errorptr += dir; /* advance errorptr to current column */
  157644. }
  157645. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157646. }
  157647. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157648. }
  157649. }
  157650. LOCAL(void)
  157651. alloc_fs_workspace (j_decompress_ptr cinfo)
  157652. {
  157653. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157654. size_t arraysize;
  157655. int i;
  157656. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157657. for (i = 0; i < cinfo->out_color_components; i++) {
  157658. cquantize->fserrors[i] = (FSERRPTR)
  157659. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157660. }
  157661. }
  157662. METHODDEF(void)
  157663. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157664. {
  157665. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157666. size_t arraysize;
  157667. int i;
  157668. cinfo->colormap = cquantize->sv_colormap;
  157669. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157670. switch (cinfo->dither_mode) {
  157671. case JDITHER_NONE:
  157672. if (cinfo->out_color_components == 3)
  157673. cquantize->pub.color_quantize = color_quantize3;
  157674. else
  157675. cquantize->pub.color_quantize = color_quantize;
  157676. break;
  157677. case JDITHER_ORDERED:
  157678. if (cinfo->out_color_components == 3)
  157679. cquantize->pub.color_quantize = quantize3_ord_dither;
  157680. else
  157681. cquantize->pub.color_quantize = quantize_ord_dither;
  157682. cquantize->row_index = 0; /* initialize state for ordered dither */
  157683. if (! cquantize->is_padded)
  157684. create_colorindex(cinfo);
  157685. if (cquantize->odither[0] == NULL)
  157686. create_odither_tables(cinfo);
  157687. break;
  157688. case JDITHER_FS:
  157689. cquantize->pub.color_quantize = quantize_fs_dither;
  157690. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157691. if (cquantize->fserrors[0] == NULL)
  157692. alloc_fs_workspace(cinfo);
  157693. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157694. for (i = 0; i < cinfo->out_color_components; i++)
  157695. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157696. break;
  157697. default:
  157698. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157699. break;
  157700. }
  157701. }
  157702. METHODDEF(void)
  157703. finish_pass_1_quant (j_decompress_ptr cinfo)
  157704. {
  157705. }
  157706. METHODDEF(void)
  157707. new_color_map_1_quant (j_decompress_ptr cinfo)
  157708. {
  157709. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157710. }
  157711. GLOBAL(void)
  157712. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157713. {
  157714. my_cquantize_ptr cquantize;
  157715. cquantize = (my_cquantize_ptr)
  157716. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157717. SIZEOF(my_cquantizer));
  157718. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157719. cquantize->pub.start_pass = start_pass_1_quant;
  157720. cquantize->pub.finish_pass = finish_pass_1_quant;
  157721. cquantize->pub.new_color_map = new_color_map_1_quant;
  157722. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157723. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157724. if (cinfo->out_color_components > MAX_Q_COMPS)
  157725. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157726. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157727. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157728. create_colormap(cinfo);
  157729. create_colorindex(cinfo);
  157730. if (cinfo->dither_mode == JDITHER_FS)
  157731. alloc_fs_workspace(cinfo);
  157732. }
  157733. #endif /* QUANT_1PASS_SUPPORTED */
  157734. /*** End of inlined file: jquant1.c ***/
  157735. /*** Start of inlined file: jquant2.c ***/
  157736. #define JPEG_INTERNALS
  157737. #ifdef QUANT_2PASS_SUPPORTED
  157738. #define R_SCALE 2 /* scale R distances by this much */
  157739. #define G_SCALE 3 /* scale G distances by this much */
  157740. #define B_SCALE 1 /* and B by this much */
  157741. #if RGB_RED == 0
  157742. #define C0_SCALE R_SCALE
  157743. #endif
  157744. #if RGB_BLUE == 0
  157745. #define C0_SCALE B_SCALE
  157746. #endif
  157747. #if RGB_GREEN == 1
  157748. #define C1_SCALE G_SCALE
  157749. #endif
  157750. #if RGB_RED == 2
  157751. #define C2_SCALE R_SCALE
  157752. #endif
  157753. #if RGB_BLUE == 2
  157754. #define C2_SCALE B_SCALE
  157755. #endif
  157756. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157757. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157758. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157759. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157760. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157761. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157762. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157763. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157764. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157765. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157766. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157767. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157768. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157769. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157770. typedef hist2d * hist3d; /* type for top-level pointer */
  157771. #if BITS_IN_JSAMPLE == 8
  157772. typedef INT16 FSERROR; /* 16 bits should be enough */
  157773. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157774. #else
  157775. typedef INT32 FSERROR; /* may need more than 16 bits */
  157776. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157777. #endif
  157778. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157779. typedef struct {
  157780. struct jpeg_color_quantizer pub; /* public fields */
  157781. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157782. int desired; /* desired # of colors = size of colormap */
  157783. hist3d histogram; /* pointer to the histogram */
  157784. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157785. FSERRPTR fserrors; /* accumulated errors */
  157786. boolean on_odd_row; /* flag to remember which row we are on */
  157787. int * error_limiter; /* table for clamping the applied error */
  157788. } my_cquantizer2;
  157789. typedef my_cquantizer2 * my_cquantize_ptr2;
  157790. METHODDEF(void)
  157791. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157792. JSAMPARRAY output_buf, int num_rows)
  157793. {
  157794. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157795. register JSAMPROW ptr;
  157796. register histptr histp;
  157797. register hist3d histogram = cquantize->histogram;
  157798. int row;
  157799. JDIMENSION col;
  157800. JDIMENSION width = cinfo->output_width;
  157801. for (row = 0; row < num_rows; row++) {
  157802. ptr = input_buf[row];
  157803. for (col = width; col > 0; col--) {
  157804. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157805. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157806. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157807. if (++(*histp) <= 0)
  157808. (*histp)--;
  157809. ptr += 3;
  157810. }
  157811. }
  157812. }
  157813. typedef struct {
  157814. int c0min, c0max;
  157815. int c1min, c1max;
  157816. int c2min, c2max;
  157817. INT32 volume;
  157818. long colorcount;
  157819. } box;
  157820. typedef box * boxptr;
  157821. LOCAL(boxptr)
  157822. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157823. {
  157824. register boxptr boxp;
  157825. register int i;
  157826. register long maxc = 0;
  157827. boxptr which = NULL;
  157828. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157829. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157830. which = boxp;
  157831. maxc = boxp->colorcount;
  157832. }
  157833. }
  157834. return which;
  157835. }
  157836. LOCAL(boxptr)
  157837. find_biggest_volume (boxptr boxlist, int numboxes)
  157838. {
  157839. register boxptr boxp;
  157840. register int i;
  157841. register INT32 maxv = 0;
  157842. boxptr which = NULL;
  157843. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157844. if (boxp->volume > maxv) {
  157845. which = boxp;
  157846. maxv = boxp->volume;
  157847. }
  157848. }
  157849. return which;
  157850. }
  157851. LOCAL(void)
  157852. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157853. {
  157854. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157855. hist3d histogram = cquantize->histogram;
  157856. histptr histp;
  157857. int c0,c1,c2;
  157858. int c0min,c0max,c1min,c1max,c2min,c2max;
  157859. INT32 dist0,dist1,dist2;
  157860. long ccount;
  157861. c0min = boxp->c0min; c0max = boxp->c0max;
  157862. c1min = boxp->c1min; c1max = boxp->c1max;
  157863. c2min = boxp->c2min; c2max = boxp->c2max;
  157864. if (c0max > c0min)
  157865. for (c0 = c0min; c0 <= c0max; c0++)
  157866. for (c1 = c1min; c1 <= c1max; c1++) {
  157867. histp = & histogram[c0][c1][c2min];
  157868. for (c2 = c2min; c2 <= c2max; c2++)
  157869. if (*histp++ != 0) {
  157870. boxp->c0min = c0min = c0;
  157871. goto have_c0min;
  157872. }
  157873. }
  157874. have_c0min:
  157875. if (c0max > c0min)
  157876. for (c0 = c0max; c0 >= c0min; c0--)
  157877. for (c1 = c1min; c1 <= c1max; c1++) {
  157878. histp = & histogram[c0][c1][c2min];
  157879. for (c2 = c2min; c2 <= c2max; c2++)
  157880. if (*histp++ != 0) {
  157881. boxp->c0max = c0max = c0;
  157882. goto have_c0max;
  157883. }
  157884. }
  157885. have_c0max:
  157886. if (c1max > c1min)
  157887. for (c1 = c1min; c1 <= c1max; c1++)
  157888. for (c0 = c0min; c0 <= c0max; c0++) {
  157889. histp = & histogram[c0][c1][c2min];
  157890. for (c2 = c2min; c2 <= c2max; c2++)
  157891. if (*histp++ != 0) {
  157892. boxp->c1min = c1min = c1;
  157893. goto have_c1min;
  157894. }
  157895. }
  157896. have_c1min:
  157897. if (c1max > c1min)
  157898. for (c1 = c1max; c1 >= c1min; c1--)
  157899. for (c0 = c0min; c0 <= c0max; c0++) {
  157900. histp = & histogram[c0][c1][c2min];
  157901. for (c2 = c2min; c2 <= c2max; c2++)
  157902. if (*histp++ != 0) {
  157903. boxp->c1max = c1max = c1;
  157904. goto have_c1max;
  157905. }
  157906. }
  157907. have_c1max:
  157908. if (c2max > c2min)
  157909. for (c2 = c2min; c2 <= c2max; c2++)
  157910. for (c0 = c0min; c0 <= c0max; c0++) {
  157911. histp = & histogram[c0][c1min][c2];
  157912. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157913. if (*histp != 0) {
  157914. boxp->c2min = c2min = c2;
  157915. goto have_c2min;
  157916. }
  157917. }
  157918. have_c2min:
  157919. if (c2max > c2min)
  157920. for (c2 = c2max; c2 >= c2min; c2--)
  157921. for (c0 = c0min; c0 <= c0max; c0++) {
  157922. histp = & histogram[c0][c1min][c2];
  157923. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157924. if (*histp != 0) {
  157925. boxp->c2max = c2max = c2;
  157926. goto have_c2max;
  157927. }
  157928. }
  157929. have_c2max:
  157930. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157931. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157932. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157933. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157934. ccount = 0;
  157935. for (c0 = c0min; c0 <= c0max; c0++)
  157936. for (c1 = c1min; c1 <= c1max; c1++) {
  157937. histp = & histogram[c0][c1][c2min];
  157938. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157939. if (*histp != 0) {
  157940. ccount++;
  157941. }
  157942. }
  157943. boxp->colorcount = ccount;
  157944. }
  157945. LOCAL(int)
  157946. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157947. int desired_colors)
  157948. {
  157949. int n,lb;
  157950. int c0,c1,c2,cmax;
  157951. register boxptr b1,b2;
  157952. while (numboxes < desired_colors) {
  157953. if (numboxes*2 <= desired_colors) {
  157954. b1 = find_biggest_color_pop(boxlist, numboxes);
  157955. } else {
  157956. b1 = find_biggest_volume(boxlist, numboxes);
  157957. }
  157958. if (b1 == NULL) /* no splittable boxes left! */
  157959. break;
  157960. b2 = &boxlist[numboxes]; /* where new box will go */
  157961. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157962. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157963. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157964. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157965. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157966. #if RGB_RED == 0
  157967. cmax = c1; n = 1;
  157968. if (c0 > cmax) { cmax = c0; n = 0; }
  157969. if (c2 > cmax) { n = 2; }
  157970. #else
  157971. cmax = c1; n = 1;
  157972. if (c2 > cmax) { cmax = c2; n = 2; }
  157973. if (c0 > cmax) { n = 0; }
  157974. #endif
  157975. switch (n) {
  157976. case 0:
  157977. lb = (b1->c0max + b1->c0min) / 2;
  157978. b1->c0max = lb;
  157979. b2->c0min = lb+1;
  157980. break;
  157981. case 1:
  157982. lb = (b1->c1max + b1->c1min) / 2;
  157983. b1->c1max = lb;
  157984. b2->c1min = lb+1;
  157985. break;
  157986. case 2:
  157987. lb = (b1->c2max + b1->c2min) / 2;
  157988. b1->c2max = lb;
  157989. b2->c2min = lb+1;
  157990. break;
  157991. }
  157992. update_box(cinfo, b1);
  157993. update_box(cinfo, b2);
  157994. numboxes++;
  157995. }
  157996. return numboxes;
  157997. }
  157998. LOCAL(void)
  157999. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  158000. {
  158001. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158002. hist3d histogram = cquantize->histogram;
  158003. histptr histp;
  158004. int c0,c1,c2;
  158005. int c0min,c0max,c1min,c1max,c2min,c2max;
  158006. long count;
  158007. long total = 0;
  158008. long c0total = 0;
  158009. long c1total = 0;
  158010. long c2total = 0;
  158011. c0min = boxp->c0min; c0max = boxp->c0max;
  158012. c1min = boxp->c1min; c1max = boxp->c1max;
  158013. c2min = boxp->c2min; c2max = boxp->c2max;
  158014. for (c0 = c0min; c0 <= c0max; c0++)
  158015. for (c1 = c1min; c1 <= c1max; c1++) {
  158016. histp = & histogram[c0][c1][c2min];
  158017. for (c2 = c2min; c2 <= c2max; c2++) {
  158018. if ((count = *histp++) != 0) {
  158019. total += count;
  158020. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  158021. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  158022. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  158023. }
  158024. }
  158025. }
  158026. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  158027. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  158028. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  158029. }
  158030. LOCAL(void)
  158031. select_colors (j_decompress_ptr cinfo, int desired_colors)
  158032. {
  158033. boxptr boxlist;
  158034. int numboxes;
  158035. int i;
  158036. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  158037. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  158038. numboxes = 1;
  158039. boxlist[0].c0min = 0;
  158040. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  158041. boxlist[0].c1min = 0;
  158042. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  158043. boxlist[0].c2min = 0;
  158044. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  158045. update_box(cinfo, & boxlist[0]);
  158046. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  158047. for (i = 0; i < numboxes; i++)
  158048. compute_color(cinfo, & boxlist[i], i);
  158049. cinfo->actual_number_of_colors = numboxes;
  158050. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  158051. }
  158052. #define BOX_C0_LOG (HIST_C0_BITS-3)
  158053. #define BOX_C1_LOG (HIST_C1_BITS-3)
  158054. #define BOX_C2_LOG (HIST_C2_BITS-3)
  158055. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  158056. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  158057. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  158058. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  158059. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  158060. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  158061. LOCAL(int)
  158062. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158063. JSAMPLE colorlist[])
  158064. {
  158065. int numcolors = cinfo->actual_number_of_colors;
  158066. int maxc0, maxc1, maxc2;
  158067. int centerc0, centerc1, centerc2;
  158068. int i, x, ncolors;
  158069. INT32 minmaxdist, min_dist, max_dist, tdist;
  158070. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  158071. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  158072. centerc0 = (minc0 + maxc0) >> 1;
  158073. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  158074. centerc1 = (minc1 + maxc1) >> 1;
  158075. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  158076. centerc2 = (minc2 + maxc2) >> 1;
  158077. minmaxdist = 0x7FFFFFFFL;
  158078. for (i = 0; i < numcolors; i++) {
  158079. x = GETJSAMPLE(cinfo->colormap[0][i]);
  158080. if (x < minc0) {
  158081. tdist = (x - minc0) * C0_SCALE;
  158082. min_dist = tdist*tdist;
  158083. tdist = (x - maxc0) * C0_SCALE;
  158084. max_dist = tdist*tdist;
  158085. } else if (x > maxc0) {
  158086. tdist = (x - maxc0) * C0_SCALE;
  158087. min_dist = tdist*tdist;
  158088. tdist = (x - minc0) * C0_SCALE;
  158089. max_dist = tdist*tdist;
  158090. } else {
  158091. min_dist = 0;
  158092. if (x <= centerc0) {
  158093. tdist = (x - maxc0) * C0_SCALE;
  158094. max_dist = tdist*tdist;
  158095. } else {
  158096. tdist = (x - minc0) * C0_SCALE;
  158097. max_dist = tdist*tdist;
  158098. }
  158099. }
  158100. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158101. if (x < minc1) {
  158102. tdist = (x - minc1) * C1_SCALE;
  158103. min_dist += tdist*tdist;
  158104. tdist = (x - maxc1) * C1_SCALE;
  158105. max_dist += tdist*tdist;
  158106. } else if (x > maxc1) {
  158107. tdist = (x - maxc1) * C1_SCALE;
  158108. min_dist += tdist*tdist;
  158109. tdist = (x - minc1) * C1_SCALE;
  158110. max_dist += tdist*tdist;
  158111. } else {
  158112. if (x <= centerc1) {
  158113. tdist = (x - maxc1) * C1_SCALE;
  158114. max_dist += tdist*tdist;
  158115. } else {
  158116. tdist = (x - minc1) * C1_SCALE;
  158117. max_dist += tdist*tdist;
  158118. }
  158119. }
  158120. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158121. if (x < minc2) {
  158122. tdist = (x - minc2) * C2_SCALE;
  158123. min_dist += tdist*tdist;
  158124. tdist = (x - maxc2) * C2_SCALE;
  158125. max_dist += tdist*tdist;
  158126. } else if (x > maxc2) {
  158127. tdist = (x - maxc2) * C2_SCALE;
  158128. min_dist += tdist*tdist;
  158129. tdist = (x - minc2) * C2_SCALE;
  158130. max_dist += tdist*tdist;
  158131. } else {
  158132. if (x <= centerc2) {
  158133. tdist = (x - maxc2) * C2_SCALE;
  158134. max_dist += tdist*tdist;
  158135. } else {
  158136. tdist = (x - minc2) * C2_SCALE;
  158137. max_dist += tdist*tdist;
  158138. }
  158139. }
  158140. mindist[i] = min_dist; /* save away the results */
  158141. if (max_dist < minmaxdist)
  158142. minmaxdist = max_dist;
  158143. }
  158144. ncolors = 0;
  158145. for (i = 0; i < numcolors; i++) {
  158146. if (mindist[i] <= minmaxdist)
  158147. colorlist[ncolors++] = (JSAMPLE) i;
  158148. }
  158149. return ncolors;
  158150. }
  158151. LOCAL(void)
  158152. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158153. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158154. {
  158155. int ic0, ic1, ic2;
  158156. int i, icolor;
  158157. register INT32 * bptr; /* pointer into bestdist[] array */
  158158. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158159. INT32 dist0, dist1; /* initial distance values */
  158160. register INT32 dist2; /* current distance in inner loop */
  158161. INT32 xx0, xx1; /* distance increments */
  158162. register INT32 xx2;
  158163. INT32 inc0, inc1, inc2; /* initial values for increments */
  158164. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158165. bptr = bestdist;
  158166. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158167. *bptr++ = 0x7FFFFFFFL;
  158168. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158169. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158170. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158171. for (i = 0; i < numcolors; i++) {
  158172. icolor = GETJSAMPLE(colorlist[i]);
  158173. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158174. dist0 = inc0*inc0;
  158175. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158176. dist0 += inc1*inc1;
  158177. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158178. dist0 += inc2*inc2;
  158179. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158180. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158181. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158182. bptr = bestdist;
  158183. cptr = bestcolor;
  158184. xx0 = inc0;
  158185. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158186. dist1 = dist0;
  158187. xx1 = inc1;
  158188. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158189. dist2 = dist1;
  158190. xx2 = inc2;
  158191. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158192. if (dist2 < *bptr) {
  158193. *bptr = dist2;
  158194. *cptr = (JSAMPLE) icolor;
  158195. }
  158196. dist2 += xx2;
  158197. xx2 += 2 * STEP_C2 * STEP_C2;
  158198. bptr++;
  158199. cptr++;
  158200. }
  158201. dist1 += xx1;
  158202. xx1 += 2 * STEP_C1 * STEP_C1;
  158203. }
  158204. dist0 += xx0;
  158205. xx0 += 2 * STEP_C0 * STEP_C0;
  158206. }
  158207. }
  158208. }
  158209. LOCAL(void)
  158210. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158211. {
  158212. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158213. hist3d histogram = cquantize->histogram;
  158214. int minc0, minc1, minc2; /* lower left corner of update box */
  158215. int ic0, ic1, ic2;
  158216. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158217. register histptr cachep; /* pointer into main cache array */
  158218. JSAMPLE colorlist[MAXNUMCOLORS];
  158219. int numcolors; /* number of candidate colors */
  158220. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158221. c0 >>= BOX_C0_LOG;
  158222. c1 >>= BOX_C1_LOG;
  158223. c2 >>= BOX_C2_LOG;
  158224. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158225. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158226. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158227. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158228. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158229. bestcolor);
  158230. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158231. c1 <<= BOX_C1_LOG;
  158232. c2 <<= BOX_C2_LOG;
  158233. cptr = bestcolor;
  158234. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158235. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158236. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158237. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158238. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158239. }
  158240. }
  158241. }
  158242. }
  158243. METHODDEF(void)
  158244. pass2_no_dither (j_decompress_ptr cinfo,
  158245. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158246. {
  158247. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158248. hist3d histogram = cquantize->histogram;
  158249. register JSAMPROW inptr, outptr;
  158250. register histptr cachep;
  158251. register int c0, c1, c2;
  158252. int row;
  158253. JDIMENSION col;
  158254. JDIMENSION width = cinfo->output_width;
  158255. for (row = 0; row < num_rows; row++) {
  158256. inptr = input_buf[row];
  158257. outptr = output_buf[row];
  158258. for (col = width; col > 0; col--) {
  158259. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158260. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158261. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158262. cachep = & histogram[c0][c1][c2];
  158263. if (*cachep == 0)
  158264. fill_inverse_cmap(cinfo, c0,c1,c2);
  158265. *outptr++ = (JSAMPLE) (*cachep - 1);
  158266. }
  158267. }
  158268. }
  158269. METHODDEF(void)
  158270. pass2_fs_dither (j_decompress_ptr cinfo,
  158271. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158272. {
  158273. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158274. hist3d histogram = cquantize->histogram;
  158275. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158276. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158277. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158278. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158279. JSAMPROW inptr; /* => current input pixel */
  158280. JSAMPROW outptr; /* => current output pixel */
  158281. histptr cachep;
  158282. int dir; /* +1 or -1 depending on direction */
  158283. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158284. int row;
  158285. JDIMENSION col;
  158286. JDIMENSION width = cinfo->output_width;
  158287. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158288. int *error_limit = cquantize->error_limiter;
  158289. JSAMPROW colormap0 = cinfo->colormap[0];
  158290. JSAMPROW colormap1 = cinfo->colormap[1];
  158291. JSAMPROW colormap2 = cinfo->colormap[2];
  158292. SHIFT_TEMPS
  158293. for (row = 0; row < num_rows; row++) {
  158294. inptr = input_buf[row];
  158295. outptr = output_buf[row];
  158296. if (cquantize->on_odd_row) {
  158297. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158298. outptr += width-1;
  158299. dir = -1;
  158300. dir3 = -3;
  158301. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158302. cquantize->on_odd_row = FALSE; /* flip for next time */
  158303. } else {
  158304. dir = 1;
  158305. dir3 = 3;
  158306. errorptr = cquantize->fserrors; /* => entry before first real column */
  158307. cquantize->on_odd_row = TRUE; /* flip for next time */
  158308. }
  158309. cur0 = cur1 = cur2 = 0;
  158310. belowerr0 = belowerr1 = belowerr2 = 0;
  158311. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158312. for (col = width; col > 0; col--) {
  158313. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158314. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158315. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158316. cur0 = error_limit[cur0];
  158317. cur1 = error_limit[cur1];
  158318. cur2 = error_limit[cur2];
  158319. cur0 += GETJSAMPLE(inptr[0]);
  158320. cur1 += GETJSAMPLE(inptr[1]);
  158321. cur2 += GETJSAMPLE(inptr[2]);
  158322. cur0 = GETJSAMPLE(range_limit[cur0]);
  158323. cur1 = GETJSAMPLE(range_limit[cur1]);
  158324. cur2 = GETJSAMPLE(range_limit[cur2]);
  158325. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158326. if (*cachep == 0)
  158327. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158328. { register int pixcode = *cachep - 1;
  158329. *outptr = (JSAMPLE) pixcode;
  158330. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158331. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158332. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158333. }
  158334. { register LOCFSERROR bnexterr, delta;
  158335. bnexterr = cur0; /* Process component 0 */
  158336. delta = cur0 * 2;
  158337. cur0 += delta; /* form error * 3 */
  158338. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158339. cur0 += delta; /* form error * 5 */
  158340. bpreverr0 = belowerr0 + cur0;
  158341. belowerr0 = bnexterr;
  158342. cur0 += delta; /* form error * 7 */
  158343. bnexterr = cur1; /* Process component 1 */
  158344. delta = cur1 * 2;
  158345. cur1 += delta; /* form error * 3 */
  158346. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158347. cur1 += delta; /* form error * 5 */
  158348. bpreverr1 = belowerr1 + cur1;
  158349. belowerr1 = bnexterr;
  158350. cur1 += delta; /* form error * 7 */
  158351. bnexterr = cur2; /* Process component 2 */
  158352. delta = cur2 * 2;
  158353. cur2 += delta; /* form error * 3 */
  158354. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158355. cur2 += delta; /* form error * 5 */
  158356. bpreverr2 = belowerr2 + cur2;
  158357. belowerr2 = bnexterr;
  158358. cur2 += delta; /* form error * 7 */
  158359. }
  158360. inptr += dir3; /* Advance pixel pointers to next column */
  158361. outptr += dir;
  158362. errorptr += dir3; /* advance errorptr to current column */
  158363. }
  158364. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158365. errorptr[1] = (FSERROR) bpreverr1;
  158366. errorptr[2] = (FSERROR) bpreverr2;
  158367. }
  158368. }
  158369. LOCAL(void)
  158370. init_error_limit (j_decompress_ptr cinfo)
  158371. {
  158372. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158373. int * table;
  158374. int in, out;
  158375. table = (int *) (*cinfo->mem->alloc_small)
  158376. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158377. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158378. cquantize->error_limiter = table;
  158379. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158380. out = 0;
  158381. for (in = 0; in < STEPSIZE; in++, out++) {
  158382. table[in] = out; table[-in] = -out;
  158383. }
  158384. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158385. table[in] = out; table[-in] = -out;
  158386. }
  158387. for (; in <= MAXJSAMPLE; in++) {
  158388. table[in] = out; table[-in] = -out;
  158389. }
  158390. #undef STEPSIZE
  158391. }
  158392. METHODDEF(void)
  158393. finish_pass1 (j_decompress_ptr cinfo)
  158394. {
  158395. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158396. cinfo->colormap = cquantize->sv_colormap;
  158397. select_colors(cinfo, cquantize->desired);
  158398. cquantize->needs_zeroed = TRUE;
  158399. }
  158400. METHODDEF(void)
  158401. finish_pass2 (j_decompress_ptr cinfo)
  158402. {
  158403. }
  158404. METHODDEF(void)
  158405. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158406. {
  158407. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158408. hist3d histogram = cquantize->histogram;
  158409. int i;
  158410. if (cinfo->dither_mode != JDITHER_NONE)
  158411. cinfo->dither_mode = JDITHER_FS;
  158412. if (is_pre_scan) {
  158413. cquantize->pub.color_quantize = prescan_quantize;
  158414. cquantize->pub.finish_pass = finish_pass1;
  158415. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158416. } else {
  158417. if (cinfo->dither_mode == JDITHER_FS)
  158418. cquantize->pub.color_quantize = pass2_fs_dither;
  158419. else
  158420. cquantize->pub.color_quantize = pass2_no_dither;
  158421. cquantize->pub.finish_pass = finish_pass2;
  158422. i = cinfo->actual_number_of_colors;
  158423. if (i < 1)
  158424. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158425. if (i > MAXNUMCOLORS)
  158426. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158427. if (cinfo->dither_mode == JDITHER_FS) {
  158428. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158429. (3 * SIZEOF(FSERROR)));
  158430. if (cquantize->fserrors == NULL)
  158431. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158432. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158433. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158434. if (cquantize->error_limiter == NULL)
  158435. init_error_limit(cinfo);
  158436. cquantize->on_odd_row = FALSE;
  158437. }
  158438. }
  158439. if (cquantize->needs_zeroed) {
  158440. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158441. jzero_far((void FAR *) histogram[i],
  158442. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158443. }
  158444. cquantize->needs_zeroed = FALSE;
  158445. }
  158446. }
  158447. METHODDEF(void)
  158448. new_color_map_2_quant (j_decompress_ptr cinfo)
  158449. {
  158450. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158451. cquantize->needs_zeroed = TRUE;
  158452. }
  158453. GLOBAL(void)
  158454. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158455. {
  158456. my_cquantize_ptr2 cquantize;
  158457. int i;
  158458. cquantize = (my_cquantize_ptr2)
  158459. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158460. SIZEOF(my_cquantizer2));
  158461. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158462. cquantize->pub.start_pass = start_pass_2_quant;
  158463. cquantize->pub.new_color_map = new_color_map_2_quant;
  158464. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158465. cquantize->error_limiter = NULL;
  158466. if (cinfo->out_color_components != 3)
  158467. ERREXIT(cinfo, JERR_NOTIMPL);
  158468. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158469. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158470. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158471. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158472. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158473. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158474. }
  158475. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158476. if (cinfo->enable_2pass_quant) {
  158477. int desired = cinfo->desired_number_of_colors;
  158478. if (desired < 8)
  158479. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158480. if (desired > MAXNUMCOLORS)
  158481. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158482. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158483. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158484. cquantize->desired = desired;
  158485. } else
  158486. cquantize->sv_colormap = NULL;
  158487. if (cinfo->dither_mode != JDITHER_NONE)
  158488. cinfo->dither_mode = JDITHER_FS;
  158489. if (cinfo->dither_mode == JDITHER_FS) {
  158490. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158491. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158492. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158493. init_error_limit(cinfo);
  158494. }
  158495. }
  158496. #endif /* QUANT_2PASS_SUPPORTED */
  158497. /*** End of inlined file: jquant2.c ***/
  158498. /*** Start of inlined file: jutils.c ***/
  158499. #define JPEG_INTERNALS
  158500. #if 0 /* This table is not actually needed in v6a */
  158501. const int jpeg_zigzag_order[DCTSIZE2] = {
  158502. 0, 1, 5, 6, 14, 15, 27, 28,
  158503. 2, 4, 7, 13, 16, 26, 29, 42,
  158504. 3, 8, 12, 17, 25, 30, 41, 43,
  158505. 9, 11, 18, 24, 31, 40, 44, 53,
  158506. 10, 19, 23, 32, 39, 45, 52, 54,
  158507. 20, 22, 33, 38, 46, 51, 55, 60,
  158508. 21, 34, 37, 47, 50, 56, 59, 61,
  158509. 35, 36, 48, 49, 57, 58, 62, 63
  158510. };
  158511. #endif
  158512. const int jpeg_natural_order[DCTSIZE2+16] = {
  158513. 0, 1, 8, 16, 9, 2, 3, 10,
  158514. 17, 24, 32, 25, 18, 11, 4, 5,
  158515. 12, 19, 26, 33, 40, 48, 41, 34,
  158516. 27, 20, 13, 6, 7, 14, 21, 28,
  158517. 35, 42, 49, 56, 57, 50, 43, 36,
  158518. 29, 22, 15, 23, 30, 37, 44, 51,
  158519. 58, 59, 52, 45, 38, 31, 39, 46,
  158520. 53, 60, 61, 54, 47, 55, 62, 63,
  158521. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158522. 63, 63, 63, 63, 63, 63, 63, 63
  158523. };
  158524. GLOBAL(long)
  158525. jdiv_round_up (long a, long b)
  158526. {
  158527. return (a + b - 1L) / b;
  158528. }
  158529. GLOBAL(long)
  158530. jround_up (long a, long b)
  158531. {
  158532. a += b - 1L;
  158533. return a - (a % b);
  158534. }
  158535. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158536. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158537. #define FMEMZERO(target,size) MEMZERO(target,size)
  158538. #else /* 80x86 case, define if we can */
  158539. #ifdef USE_FMEM
  158540. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158541. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158542. #endif
  158543. #endif
  158544. GLOBAL(void)
  158545. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158546. JSAMPARRAY output_array, int dest_row,
  158547. int num_rows, JDIMENSION num_cols)
  158548. {
  158549. register JSAMPROW inptr, outptr;
  158550. #ifdef FMEMCOPY
  158551. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158552. #else
  158553. register JDIMENSION count;
  158554. #endif
  158555. register int row;
  158556. input_array += source_row;
  158557. output_array += dest_row;
  158558. for (row = num_rows; row > 0; row--) {
  158559. inptr = *input_array++;
  158560. outptr = *output_array++;
  158561. #ifdef FMEMCOPY
  158562. FMEMCOPY(outptr, inptr, count);
  158563. #else
  158564. for (count = num_cols; count > 0; count--)
  158565. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158566. #endif
  158567. }
  158568. }
  158569. GLOBAL(void)
  158570. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158571. JDIMENSION num_blocks)
  158572. {
  158573. #ifdef FMEMCOPY
  158574. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158575. #else
  158576. register JCOEFPTR inptr, outptr;
  158577. register long count;
  158578. inptr = (JCOEFPTR) input_row;
  158579. outptr = (JCOEFPTR) output_row;
  158580. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158581. *outptr++ = *inptr++;
  158582. }
  158583. #endif
  158584. }
  158585. GLOBAL(void)
  158586. jzero_far (void FAR * target, size_t bytestozero)
  158587. {
  158588. #ifdef FMEMZERO
  158589. FMEMZERO(target, bytestozero);
  158590. #else
  158591. register char FAR * ptr = (char FAR *) target;
  158592. register size_t count;
  158593. for (count = bytestozero; count > 0; count--) {
  158594. *ptr++ = 0;
  158595. }
  158596. #endif
  158597. }
  158598. /*** End of inlined file: jutils.c ***/
  158599. /*** Start of inlined file: transupp.c ***/
  158600. #define JPEG_INTERNALS
  158601. /*** Start of inlined file: transupp.h ***/
  158602. #ifndef TRANSFORMS_SUPPORTED
  158603. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158604. #endif
  158605. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158606. #define jtransform_request_workspace jTrRequest
  158607. #define jtransform_adjust_parameters jTrAdjust
  158608. #define jtransform_execute_transformation jTrExec
  158609. #define jcopy_markers_setup jCMrkSetup
  158610. #define jcopy_markers_execute jCMrkExec
  158611. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158612. typedef enum {
  158613. JXFORM_NONE, /* no transformation */
  158614. JXFORM_FLIP_H, /* horizontal flip */
  158615. JXFORM_FLIP_V, /* vertical flip */
  158616. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158617. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158618. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158619. JXFORM_ROT_180, /* 180-degree rotation */
  158620. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158621. } JXFORM_CODE;
  158622. typedef struct {
  158623. JXFORM_CODE transform; /* image transform operator */
  158624. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158625. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158626. int num_components; /* # of components in workspace */
  158627. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158628. } jpeg_transform_info;
  158629. #if TRANSFORMS_SUPPORTED
  158630. EXTERN(void) jtransform_request_workspace
  158631. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158632. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158633. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158634. jvirt_barray_ptr *src_coef_arrays,
  158635. jpeg_transform_info *info));
  158636. EXTERN(void) jtransform_execute_transformation
  158637. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158638. jvirt_barray_ptr *src_coef_arrays,
  158639. jpeg_transform_info *info));
  158640. #endif /* TRANSFORMS_SUPPORTED */
  158641. typedef enum {
  158642. JCOPYOPT_NONE, /* copy no optional markers */
  158643. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158644. JCOPYOPT_ALL /* copy all optional markers */
  158645. } JCOPY_OPTION;
  158646. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158647. EXTERN(void) jcopy_markers_setup
  158648. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158649. EXTERN(void) jcopy_markers_execute
  158650. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158651. JCOPY_OPTION option));
  158652. /*** End of inlined file: transupp.h ***/
  158653. /* My own external interface */
  158654. #if TRANSFORMS_SUPPORTED
  158655. LOCAL(void)
  158656. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158657. jvirt_barray_ptr *src_coef_arrays)
  158658. {
  158659. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158660. int ci, k, offset_y;
  158661. JBLOCKARRAY buffer;
  158662. JCOEFPTR ptr1, ptr2;
  158663. JCOEF temp1, temp2;
  158664. jpeg_component_info *compptr;
  158665. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158666. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158667. compptr = dstinfo->comp_info + ci;
  158668. comp_width = MCU_cols * compptr->h_samp_factor;
  158669. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158670. blk_y += compptr->v_samp_factor) {
  158671. buffer = (*srcinfo->mem->access_virt_barray)
  158672. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158673. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158674. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158675. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158676. ptr1 = buffer[offset_y][blk_x];
  158677. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158678. for (k = 0; k < DCTSIZE2; k += 2) {
  158679. temp1 = *ptr1; /* swap even column */
  158680. temp2 = *ptr2;
  158681. *ptr1++ = temp2;
  158682. *ptr2++ = temp1;
  158683. temp1 = *ptr1; /* swap odd column with sign change */
  158684. temp2 = *ptr2;
  158685. *ptr1++ = -temp2;
  158686. *ptr2++ = -temp1;
  158687. }
  158688. }
  158689. }
  158690. }
  158691. }
  158692. }
  158693. LOCAL(void)
  158694. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158695. jvirt_barray_ptr *src_coef_arrays,
  158696. jvirt_barray_ptr *dst_coef_arrays)
  158697. {
  158698. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158699. int ci, i, j, offset_y;
  158700. JBLOCKARRAY src_buffer, dst_buffer;
  158701. JBLOCKROW src_row_ptr, dst_row_ptr;
  158702. JCOEFPTR src_ptr, dst_ptr;
  158703. jpeg_component_info *compptr;
  158704. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158705. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158706. compptr = dstinfo->comp_info + ci;
  158707. comp_height = MCU_rows * compptr->v_samp_factor;
  158708. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158709. dst_blk_y += compptr->v_samp_factor) {
  158710. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158711. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158712. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158713. if (dst_blk_y < comp_height) {
  158714. src_buffer = (*srcinfo->mem->access_virt_barray)
  158715. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158716. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158717. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158718. } else {
  158719. src_buffer = (*srcinfo->mem->access_virt_barray)
  158720. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158721. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158722. }
  158723. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158724. if (dst_blk_y < comp_height) {
  158725. dst_row_ptr = dst_buffer[offset_y];
  158726. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158727. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158728. dst_blk_x++) {
  158729. dst_ptr = dst_row_ptr[dst_blk_x];
  158730. src_ptr = src_row_ptr[dst_blk_x];
  158731. for (i = 0; i < DCTSIZE; i += 2) {
  158732. for (j = 0; j < DCTSIZE; j++)
  158733. *dst_ptr++ = *src_ptr++;
  158734. for (j = 0; j < DCTSIZE; j++)
  158735. *dst_ptr++ = - *src_ptr++;
  158736. }
  158737. }
  158738. } else {
  158739. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158740. compptr->width_in_blocks);
  158741. }
  158742. }
  158743. }
  158744. }
  158745. }
  158746. LOCAL(void)
  158747. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158748. jvirt_barray_ptr *src_coef_arrays,
  158749. jvirt_barray_ptr *dst_coef_arrays)
  158750. {
  158751. JDIMENSION dst_blk_x, dst_blk_y;
  158752. int ci, i, j, offset_x, offset_y;
  158753. JBLOCKARRAY src_buffer, dst_buffer;
  158754. JCOEFPTR src_ptr, dst_ptr;
  158755. jpeg_component_info *compptr;
  158756. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158757. compptr = dstinfo->comp_info + ci;
  158758. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158759. dst_blk_y += compptr->v_samp_factor) {
  158760. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158761. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158762. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158763. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158764. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158765. dst_blk_x += compptr->h_samp_factor) {
  158766. src_buffer = (*srcinfo->mem->access_virt_barray)
  158767. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158768. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158769. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158770. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158771. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158772. for (i = 0; i < DCTSIZE; i++)
  158773. for (j = 0; j < DCTSIZE; j++)
  158774. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158775. }
  158776. }
  158777. }
  158778. }
  158779. }
  158780. }
  158781. LOCAL(void)
  158782. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158783. jvirt_barray_ptr *src_coef_arrays,
  158784. jvirt_barray_ptr *dst_coef_arrays)
  158785. {
  158786. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158787. int ci, i, j, offset_x, offset_y;
  158788. JBLOCKARRAY src_buffer, dst_buffer;
  158789. JCOEFPTR src_ptr, dst_ptr;
  158790. jpeg_component_info *compptr;
  158791. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158792. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158793. compptr = dstinfo->comp_info + ci;
  158794. comp_width = MCU_cols * compptr->h_samp_factor;
  158795. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158796. dst_blk_y += compptr->v_samp_factor) {
  158797. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158798. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158799. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158800. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158801. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158802. dst_blk_x += compptr->h_samp_factor) {
  158803. src_buffer = (*srcinfo->mem->access_virt_barray)
  158804. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158805. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158806. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158807. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158808. if (dst_blk_x < comp_width) {
  158809. dst_ptr = dst_buffer[offset_y]
  158810. [comp_width - dst_blk_x - offset_x - 1];
  158811. for (i = 0; i < DCTSIZE; i++) {
  158812. for (j = 0; j < DCTSIZE; j++)
  158813. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158814. i++;
  158815. for (j = 0; j < DCTSIZE; j++)
  158816. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158817. }
  158818. } else {
  158819. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158820. for (i = 0; i < DCTSIZE; i++)
  158821. for (j = 0; j < DCTSIZE; j++)
  158822. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158823. }
  158824. }
  158825. }
  158826. }
  158827. }
  158828. }
  158829. }
  158830. LOCAL(void)
  158831. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158832. jvirt_barray_ptr *src_coef_arrays,
  158833. jvirt_barray_ptr *dst_coef_arrays)
  158834. {
  158835. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158836. int ci, i, j, offset_x, offset_y;
  158837. JBLOCKARRAY src_buffer, dst_buffer;
  158838. JCOEFPTR src_ptr, dst_ptr;
  158839. jpeg_component_info *compptr;
  158840. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158841. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158842. compptr = dstinfo->comp_info + ci;
  158843. comp_height = MCU_rows * compptr->v_samp_factor;
  158844. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158845. dst_blk_y += compptr->v_samp_factor) {
  158846. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158847. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158848. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158849. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158850. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158851. dst_blk_x += compptr->h_samp_factor) {
  158852. src_buffer = (*srcinfo->mem->access_virt_barray)
  158853. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158854. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158855. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158856. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158857. if (dst_blk_y < comp_height) {
  158858. src_ptr = src_buffer[offset_x]
  158859. [comp_height - dst_blk_y - offset_y - 1];
  158860. for (i = 0; i < DCTSIZE; i++) {
  158861. for (j = 0; j < DCTSIZE; j++) {
  158862. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158863. j++;
  158864. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158865. }
  158866. }
  158867. } else {
  158868. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158869. for (i = 0; i < DCTSIZE; i++)
  158870. for (j = 0; j < DCTSIZE; j++)
  158871. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158872. }
  158873. }
  158874. }
  158875. }
  158876. }
  158877. }
  158878. }
  158879. LOCAL(void)
  158880. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158881. jvirt_barray_ptr *src_coef_arrays,
  158882. jvirt_barray_ptr *dst_coef_arrays)
  158883. {
  158884. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158885. int ci, i, j, offset_y;
  158886. JBLOCKARRAY src_buffer, dst_buffer;
  158887. JBLOCKROW src_row_ptr, dst_row_ptr;
  158888. JCOEFPTR src_ptr, dst_ptr;
  158889. jpeg_component_info *compptr;
  158890. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158891. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158892. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158893. compptr = dstinfo->comp_info + ci;
  158894. comp_width = MCU_cols * compptr->h_samp_factor;
  158895. comp_height = MCU_rows * compptr->v_samp_factor;
  158896. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158897. dst_blk_y += compptr->v_samp_factor) {
  158898. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158899. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158900. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158901. if (dst_blk_y < comp_height) {
  158902. src_buffer = (*srcinfo->mem->access_virt_barray)
  158903. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158904. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158905. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158906. } else {
  158907. src_buffer = (*srcinfo->mem->access_virt_barray)
  158908. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158909. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158910. }
  158911. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158912. if (dst_blk_y < comp_height) {
  158913. dst_row_ptr = dst_buffer[offset_y];
  158914. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158915. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158916. dst_ptr = dst_row_ptr[dst_blk_x];
  158917. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158918. for (i = 0; i < DCTSIZE; i += 2) {
  158919. for (j = 0; j < DCTSIZE; j += 2) {
  158920. *dst_ptr++ = *src_ptr++;
  158921. *dst_ptr++ = - *src_ptr++;
  158922. }
  158923. for (j = 0; j < DCTSIZE; j += 2) {
  158924. *dst_ptr++ = - *src_ptr++;
  158925. *dst_ptr++ = *src_ptr++;
  158926. }
  158927. }
  158928. }
  158929. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158930. dst_ptr = dst_row_ptr[dst_blk_x];
  158931. src_ptr = src_row_ptr[dst_blk_x];
  158932. for (i = 0; i < DCTSIZE; i += 2) {
  158933. for (j = 0; j < DCTSIZE; j++)
  158934. *dst_ptr++ = *src_ptr++;
  158935. for (j = 0; j < DCTSIZE; j++)
  158936. *dst_ptr++ = - *src_ptr++;
  158937. }
  158938. }
  158939. } else {
  158940. dst_row_ptr = dst_buffer[offset_y];
  158941. src_row_ptr = src_buffer[offset_y];
  158942. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158943. dst_ptr = dst_row_ptr[dst_blk_x];
  158944. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158945. for (i = 0; i < DCTSIZE2; i += 2) {
  158946. *dst_ptr++ = *src_ptr++;
  158947. *dst_ptr++ = - *src_ptr++;
  158948. }
  158949. }
  158950. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158951. dst_ptr = dst_row_ptr[dst_blk_x];
  158952. src_ptr = src_row_ptr[dst_blk_x];
  158953. for (i = 0; i < DCTSIZE2; i++)
  158954. *dst_ptr++ = *src_ptr++;
  158955. }
  158956. }
  158957. }
  158958. }
  158959. }
  158960. }
  158961. LOCAL(void)
  158962. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158963. jvirt_barray_ptr *src_coef_arrays,
  158964. jvirt_barray_ptr *dst_coef_arrays)
  158965. {
  158966. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158967. int ci, i, j, offset_x, offset_y;
  158968. JBLOCKARRAY src_buffer, dst_buffer;
  158969. JCOEFPTR src_ptr, dst_ptr;
  158970. jpeg_component_info *compptr;
  158971. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158972. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158973. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158974. compptr = dstinfo->comp_info + ci;
  158975. comp_width = MCU_cols * compptr->h_samp_factor;
  158976. comp_height = MCU_rows * compptr->v_samp_factor;
  158977. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158978. dst_blk_y += compptr->v_samp_factor) {
  158979. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158980. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158981. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158982. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158983. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158984. dst_blk_x += compptr->h_samp_factor) {
  158985. src_buffer = (*srcinfo->mem->access_virt_barray)
  158986. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158987. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158988. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158989. if (dst_blk_y < comp_height) {
  158990. src_ptr = src_buffer[offset_x]
  158991. [comp_height - dst_blk_y - offset_y - 1];
  158992. if (dst_blk_x < comp_width) {
  158993. dst_ptr = dst_buffer[offset_y]
  158994. [comp_width - dst_blk_x - offset_x - 1];
  158995. for (i = 0; i < DCTSIZE; i++) {
  158996. for (j = 0; j < DCTSIZE; j++) {
  158997. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158998. j++;
  158999. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159000. }
  159001. i++;
  159002. for (j = 0; j < DCTSIZE; j++) {
  159003. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159004. j++;
  159005. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159006. }
  159007. }
  159008. } else {
  159009. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159010. for (i = 0; i < DCTSIZE; i++) {
  159011. for (j = 0; j < DCTSIZE; j++) {
  159012. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159013. j++;
  159014. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159015. }
  159016. }
  159017. }
  159018. } else {
  159019. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159020. if (dst_blk_x < comp_width) {
  159021. dst_ptr = dst_buffer[offset_y]
  159022. [comp_width - dst_blk_x - offset_x - 1];
  159023. for (i = 0; i < DCTSIZE; i++) {
  159024. for (j = 0; j < DCTSIZE; j++)
  159025. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159026. i++;
  159027. for (j = 0; j < DCTSIZE; j++)
  159028. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159029. }
  159030. } else {
  159031. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159032. for (i = 0; i < DCTSIZE; i++)
  159033. for (j = 0; j < DCTSIZE; j++)
  159034. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159035. }
  159036. }
  159037. }
  159038. }
  159039. }
  159040. }
  159041. }
  159042. }
  159043. GLOBAL(void)
  159044. jtransform_request_workspace (j_decompress_ptr srcinfo,
  159045. jpeg_transform_info *info)
  159046. {
  159047. jvirt_barray_ptr *coef_arrays = NULL;
  159048. jpeg_component_info *compptr;
  159049. int ci;
  159050. if (info->force_grayscale &&
  159051. srcinfo->jpeg_color_space == JCS_YCbCr &&
  159052. srcinfo->num_components == 3) {
  159053. info->num_components = 1;
  159054. } else {
  159055. info->num_components = srcinfo->num_components;
  159056. }
  159057. switch (info->transform) {
  159058. case JXFORM_NONE:
  159059. case JXFORM_FLIP_H:
  159060. break;
  159061. case JXFORM_FLIP_V:
  159062. case JXFORM_ROT_180:
  159063. coef_arrays = (jvirt_barray_ptr *)
  159064. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159065. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159066. for (ci = 0; ci < info->num_components; ci++) {
  159067. compptr = srcinfo->comp_info + ci;
  159068. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159069. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159070. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159071. (long) compptr->h_samp_factor),
  159072. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159073. (long) compptr->v_samp_factor),
  159074. (JDIMENSION) compptr->v_samp_factor);
  159075. }
  159076. break;
  159077. case JXFORM_TRANSPOSE:
  159078. case JXFORM_TRANSVERSE:
  159079. case JXFORM_ROT_90:
  159080. case JXFORM_ROT_270:
  159081. coef_arrays = (jvirt_barray_ptr *)
  159082. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159083. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159084. for (ci = 0; ci < info->num_components; ci++) {
  159085. compptr = srcinfo->comp_info + ci;
  159086. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159087. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159088. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159089. (long) compptr->v_samp_factor),
  159090. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159091. (long) compptr->h_samp_factor),
  159092. (JDIMENSION) compptr->h_samp_factor);
  159093. }
  159094. break;
  159095. }
  159096. info->workspace_coef_arrays = coef_arrays;
  159097. }
  159098. LOCAL(void)
  159099. transpose_critical_parameters (j_compress_ptr dstinfo)
  159100. {
  159101. int tblno, i, j, ci, itemp;
  159102. jpeg_component_info *compptr;
  159103. JQUANT_TBL *qtblptr;
  159104. JDIMENSION dtemp;
  159105. UINT16 qtemp;
  159106. dtemp = dstinfo->image_width;
  159107. dstinfo->image_width = dstinfo->image_height;
  159108. dstinfo->image_height = dtemp;
  159109. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159110. compptr = dstinfo->comp_info + ci;
  159111. itemp = compptr->h_samp_factor;
  159112. compptr->h_samp_factor = compptr->v_samp_factor;
  159113. compptr->v_samp_factor = itemp;
  159114. }
  159115. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159116. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159117. if (qtblptr != NULL) {
  159118. for (i = 0; i < DCTSIZE; i++) {
  159119. for (j = 0; j < i; j++) {
  159120. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159121. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159122. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159123. }
  159124. }
  159125. }
  159126. }
  159127. }
  159128. LOCAL(void)
  159129. trim_right_edge (j_compress_ptr dstinfo)
  159130. {
  159131. int ci, max_h_samp_factor;
  159132. JDIMENSION MCU_cols;
  159133. max_h_samp_factor = 1;
  159134. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159135. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159136. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159137. }
  159138. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159139. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159140. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159141. }
  159142. LOCAL(void)
  159143. trim_bottom_edge (j_compress_ptr dstinfo)
  159144. {
  159145. int ci, max_v_samp_factor;
  159146. JDIMENSION MCU_rows;
  159147. max_v_samp_factor = 1;
  159148. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159149. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159150. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159151. }
  159152. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159153. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159154. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159155. }
  159156. GLOBAL(jvirt_barray_ptr *)
  159157. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159158. j_compress_ptr dstinfo,
  159159. jvirt_barray_ptr *src_coef_arrays,
  159160. jpeg_transform_info *info)
  159161. {
  159162. if (info->force_grayscale) {
  159163. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159164. dstinfo->num_components == 3) ||
  159165. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159166. dstinfo->num_components == 1)) {
  159167. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159168. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159169. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159170. } else {
  159171. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159172. }
  159173. }
  159174. switch (info->transform) {
  159175. case JXFORM_NONE:
  159176. break;
  159177. case JXFORM_FLIP_H:
  159178. if (info->trim)
  159179. trim_right_edge(dstinfo);
  159180. break;
  159181. case JXFORM_FLIP_V:
  159182. if (info->trim)
  159183. trim_bottom_edge(dstinfo);
  159184. break;
  159185. case JXFORM_TRANSPOSE:
  159186. transpose_critical_parameters(dstinfo);
  159187. break;
  159188. case JXFORM_TRANSVERSE:
  159189. transpose_critical_parameters(dstinfo);
  159190. if (info->trim) {
  159191. trim_right_edge(dstinfo);
  159192. trim_bottom_edge(dstinfo);
  159193. }
  159194. break;
  159195. case JXFORM_ROT_90:
  159196. transpose_critical_parameters(dstinfo);
  159197. if (info->trim)
  159198. trim_right_edge(dstinfo);
  159199. break;
  159200. case JXFORM_ROT_180:
  159201. if (info->trim) {
  159202. trim_right_edge(dstinfo);
  159203. trim_bottom_edge(dstinfo);
  159204. }
  159205. break;
  159206. case JXFORM_ROT_270:
  159207. transpose_critical_parameters(dstinfo);
  159208. if (info->trim)
  159209. trim_bottom_edge(dstinfo);
  159210. break;
  159211. }
  159212. if (info->workspace_coef_arrays != NULL)
  159213. return info->workspace_coef_arrays;
  159214. return src_coef_arrays;
  159215. }
  159216. GLOBAL(void)
  159217. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159218. j_compress_ptr dstinfo,
  159219. jvirt_barray_ptr *src_coef_arrays,
  159220. jpeg_transform_info *info)
  159221. {
  159222. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159223. switch (info->transform) {
  159224. case JXFORM_NONE:
  159225. break;
  159226. case JXFORM_FLIP_H:
  159227. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159228. break;
  159229. case JXFORM_FLIP_V:
  159230. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159231. break;
  159232. case JXFORM_TRANSPOSE:
  159233. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159234. break;
  159235. case JXFORM_TRANSVERSE:
  159236. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159237. break;
  159238. case JXFORM_ROT_90:
  159239. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159240. break;
  159241. case JXFORM_ROT_180:
  159242. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159243. break;
  159244. case JXFORM_ROT_270:
  159245. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159246. break;
  159247. }
  159248. }
  159249. #endif /* TRANSFORMS_SUPPORTED */
  159250. GLOBAL(void)
  159251. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159252. {
  159253. #ifdef SAVE_MARKERS_SUPPORTED
  159254. int m;
  159255. if (option != JCOPYOPT_NONE) {
  159256. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159257. }
  159258. if (option == JCOPYOPT_ALL) {
  159259. for (m = 0; m < 16; m++)
  159260. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159261. }
  159262. #endif /* SAVE_MARKERS_SUPPORTED */
  159263. }
  159264. GLOBAL(void)
  159265. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159266. JCOPY_OPTION option)
  159267. {
  159268. jpeg_saved_marker_ptr marker;
  159269. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159270. if (dstinfo->write_JFIF_header &&
  159271. marker->marker == JPEG_APP0 &&
  159272. marker->data_length >= 5 &&
  159273. GETJOCTET(marker->data[0]) == 0x4A &&
  159274. GETJOCTET(marker->data[1]) == 0x46 &&
  159275. GETJOCTET(marker->data[2]) == 0x49 &&
  159276. GETJOCTET(marker->data[3]) == 0x46 &&
  159277. GETJOCTET(marker->data[4]) == 0)
  159278. continue; /* reject duplicate JFIF */
  159279. if (dstinfo->write_Adobe_marker &&
  159280. marker->marker == JPEG_APP0+14 &&
  159281. marker->data_length >= 5 &&
  159282. GETJOCTET(marker->data[0]) == 0x41 &&
  159283. GETJOCTET(marker->data[1]) == 0x64 &&
  159284. GETJOCTET(marker->data[2]) == 0x6F &&
  159285. GETJOCTET(marker->data[3]) == 0x62 &&
  159286. GETJOCTET(marker->data[4]) == 0x65)
  159287. continue; /* reject duplicate Adobe */
  159288. #ifdef NEED_FAR_POINTERS
  159289. {
  159290. unsigned int i;
  159291. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159292. for (i = 0; i < marker->data_length; i++)
  159293. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159294. }
  159295. #else
  159296. jpeg_write_marker(dstinfo, marker->marker,
  159297. marker->data, marker->data_length);
  159298. #endif
  159299. }
  159300. }
  159301. /*** End of inlined file: transupp.c ***/
  159302. }
  159303. #else
  159304. #define JPEG_INTERNALS
  159305. #undef FAR
  159306. #include <jpeglib.h>
  159307. #endif
  159308. }
  159309. #if JUCE_MSVC
  159310. #pragma warning (pop)
  159311. #endif
  159312. BEGIN_JUCE_NAMESPACE
  159313. using namespace jpeglibNamespace;
  159314. #if ! JUCE_MSVC
  159315. using jpeglibNamespace::boolean;
  159316. #endif
  159317. struct JPEGDecodingFailure {};
  159318. static void fatalErrorHandler (j_common_ptr)
  159319. {
  159320. throw JPEGDecodingFailure();
  159321. }
  159322. static void silentErrorCallback1 (j_common_ptr) {}
  159323. static void silentErrorCallback2 (j_common_ptr, int) {}
  159324. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159325. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159326. {
  159327. zerostruct (err);
  159328. err.error_exit = fatalErrorHandler;
  159329. err.emit_message = silentErrorCallback2;
  159330. err.output_message = silentErrorCallback1;
  159331. err.format_message = silentErrorCallback3;
  159332. err.reset_error_mgr = silentErrorCallback1;
  159333. }
  159334. static void dummyCallback1 (j_decompress_ptr)
  159335. {
  159336. }
  159337. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159338. {
  159339. decompStruct->src->next_input_byte += num;
  159340. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159341. decompStruct->src->bytes_in_buffer -= num;
  159342. }
  159343. static boolean jpegFill (j_decompress_ptr)
  159344. {
  159345. return 0;
  159346. }
  159347. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159348. {
  159349. MemoryBlock mb;
  159350. in.readIntoMemoryBlock (mb);
  159351. Image* image = 0;
  159352. if (mb.getSize() > 16)
  159353. {
  159354. struct jpeg_decompress_struct jpegDecompStruct;
  159355. struct jpeg_error_mgr jerr;
  159356. setupSilentErrorHandler (jerr);
  159357. jpegDecompStruct.err = &jerr;
  159358. jpeg_create_decompress (&jpegDecompStruct);
  159359. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159360. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159361. jpegDecompStruct.src->init_source = dummyCallback1;
  159362. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159363. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159364. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159365. jpegDecompStruct.src->term_source = dummyCallback1;
  159366. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159367. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159368. try
  159369. {
  159370. jpeg_read_header (&jpegDecompStruct, TRUE);
  159371. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159372. const int width = jpegDecompStruct.output_width;
  159373. const int height = jpegDecompStruct.output_height;
  159374. jpegDecompStruct.out_color_space = JCS_RGB;
  159375. JSAMPARRAY buffer
  159376. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159377. JPOOL_IMAGE,
  159378. width * 3, 1);
  159379. if (jpeg_start_decompress (&jpegDecompStruct))
  159380. {
  159381. image = Image::createNativeImage (Image::RGB, width, height, false);
  159382. const bool hasAlphaChan = image->hasAlphaChannel();
  159383. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159384. for (int y = 0; y < height; ++y)
  159385. {
  159386. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159387. const uint8* src = *buffer;
  159388. uint8* dest = destData.getLinePointer (y);
  159389. if (hasAlphaChan)
  159390. {
  159391. for (int i = width; --i >= 0;)
  159392. {
  159393. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159394. ((PixelARGB*) dest)->premultiply();
  159395. dest += destData.pixelStride;
  159396. src += 3;
  159397. }
  159398. }
  159399. else
  159400. {
  159401. for (int i = width; --i >= 0;)
  159402. {
  159403. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159404. dest += destData.pixelStride;
  159405. src += 3;
  159406. }
  159407. }
  159408. }
  159409. jpeg_finish_decompress (&jpegDecompStruct);
  159410. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159411. }
  159412. jpeg_destroy_decompress (&jpegDecompStruct);
  159413. }
  159414. catch (...)
  159415. {}
  159416. }
  159417. return image;
  159418. }
  159419. static const int jpegBufferSize = 512;
  159420. struct JuceJpegDest : public jpeg_destination_mgr
  159421. {
  159422. OutputStream* output;
  159423. char* buffer;
  159424. };
  159425. static void jpegWriteInit (j_compress_ptr)
  159426. {
  159427. }
  159428. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159429. {
  159430. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159431. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159432. dest->output->write (dest->buffer, (int) numToWrite);
  159433. }
  159434. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159435. {
  159436. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159437. const int numToWrite = jpegBufferSize;
  159438. dest->next_output_byte = (JOCTET*) dest->buffer;
  159439. dest->free_in_buffer = jpegBufferSize;
  159440. return dest->output->write (dest->buffer, numToWrite);
  159441. }
  159442. bool juce_writeJPEGImageToStream (const Image& image,
  159443. OutputStream& out,
  159444. float quality)
  159445. {
  159446. if (image.hasAlphaChannel())
  159447. {
  159448. // this method could fill the background in white and still save the image..
  159449. jassertfalse
  159450. return true;
  159451. }
  159452. struct jpeg_compress_struct jpegCompStruct;
  159453. struct jpeg_error_mgr jerr;
  159454. setupSilentErrorHandler (jerr);
  159455. jpegCompStruct.err = &jerr;
  159456. jpeg_create_compress (&jpegCompStruct);
  159457. JuceJpegDest dest;
  159458. jpegCompStruct.dest = &dest;
  159459. dest.output = &out;
  159460. HeapBlock <char> tempBuffer (jpegBufferSize);
  159461. dest.buffer = (char*) tempBuffer;
  159462. dest.next_output_byte = (JOCTET*) dest.buffer;
  159463. dest.free_in_buffer = jpegBufferSize;
  159464. dest.init_destination = jpegWriteInit;
  159465. dest.empty_output_buffer = jpegWriteFlush;
  159466. dest.term_destination = jpegWriteTerminate;
  159467. jpegCompStruct.image_width = image.getWidth();
  159468. jpegCompStruct.image_height = image.getHeight();
  159469. jpegCompStruct.input_components = 3;
  159470. jpegCompStruct.in_color_space = JCS_RGB;
  159471. jpegCompStruct.write_JFIF_header = 1;
  159472. jpegCompStruct.X_density = 72;
  159473. jpegCompStruct.Y_density = 72;
  159474. jpeg_set_defaults (&jpegCompStruct);
  159475. jpegCompStruct.dct_method = JDCT_FLOAT;
  159476. jpegCompStruct.optimize_coding = 1;
  159477. // jpegCompStruct.smoothing_factor = 10;
  159478. if (quality < 0.0f)
  159479. quality = 0.85f;
  159480. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159481. jpeg_start_compress (&jpegCompStruct, TRUE);
  159482. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159483. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159484. JPOOL_IMAGE,
  159485. strideBytes, 1);
  159486. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159487. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159488. {
  159489. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159490. uint8* dst = *buffer;
  159491. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159492. {
  159493. *dst++ = ((const PixelRGB*) src)->getRed();
  159494. *dst++ = ((const PixelRGB*) src)->getGreen();
  159495. *dst++ = ((const PixelRGB*) src)->getBlue();
  159496. src += srcData.pixelStride;
  159497. }
  159498. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159499. }
  159500. jpeg_finish_compress (&jpegCompStruct);
  159501. jpeg_destroy_compress (&jpegCompStruct);
  159502. out.flush();
  159503. return true;
  159504. }
  159505. END_JUCE_NAMESPACE
  159506. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159507. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159508. #ifdef _MSC_VER
  159509. #pragma warning (push)
  159510. #pragma warning (disable: 4390 4611)
  159511. #endif
  159512. namespace zlibNamespace
  159513. {
  159514. #if JUCE_INCLUDE_ZLIB_CODE
  159515. #undef OS_CODE
  159516. #undef fdopen
  159517. #undef OS_CODE
  159518. #else
  159519. #include <zlib.h>
  159520. #endif
  159521. }
  159522. namespace pnglibNamespace
  159523. {
  159524. using namespace zlibNamespace;
  159525. #if JUCE_INCLUDE_PNGLIB_CODE
  159526. #if _MSC_VER != 1310
  159527. using ::calloc; // (causes conflict in VS.NET 2003)
  159528. using ::malloc;
  159529. using ::free;
  159530. #endif
  159531. extern "C"
  159532. {
  159533. using ::abs;
  159534. #define PNG_INTERNAL
  159535. #define NO_DUMMY_DECL
  159536. #define PNG_SETJMP_NOT_SUPPORTED
  159537. /*** Start of inlined file: png.h ***/
  159538. #ifndef PNG_H
  159539. #define PNG_H
  159540. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159541. #define PNG_HEADER_VERSION_STRING \
  159542. " libpng version 1.2.21 - October 4, 2007\n"
  159543. #define PNG_LIBPNG_VER_SONUM 0
  159544. #define PNG_LIBPNG_VER_DLLNUM 13
  159545. #define PNG_LIBPNG_VER_MAJOR 1
  159546. #define PNG_LIBPNG_VER_MINOR 2
  159547. #define PNG_LIBPNG_VER_RELEASE 21
  159548. #define PNG_LIBPNG_VER_BUILD 0
  159549. #define PNG_LIBPNG_BUILD_ALPHA 1
  159550. #define PNG_LIBPNG_BUILD_BETA 2
  159551. #define PNG_LIBPNG_BUILD_RC 3
  159552. #define PNG_LIBPNG_BUILD_STABLE 4
  159553. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159554. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159555. PNG_LIBPNG_BUILD_STABLE only */
  159556. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159557. PNG_LIBPNG_BUILD_SPECIAL */
  159558. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159559. PNG_LIBPNG_BUILD_PRIVATE */
  159560. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159561. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159562. #ifndef PNG_VERSION_INFO_ONLY
  159563. #endif
  159564. /*** Start of inlined file: pngconf.h ***/
  159565. #ifndef PNGCONF_H
  159566. #define PNGCONF_H
  159567. #define PNG_1_2_X
  159568. // These are some Juce config settings that should remove any unnecessary code bloat..
  159569. #define PNG_NO_STDIO 1
  159570. #define PNG_DEBUG 0
  159571. #define PNG_NO_WARNINGS 1
  159572. #define PNG_NO_ERROR_TEXT 1
  159573. #define PNG_NO_ERROR_NUMBERS 1
  159574. #define PNG_NO_USER_MEM 1
  159575. #define PNG_NO_READ_iCCP 1
  159576. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159577. #define PNG_NO_READ_USER_CHUNKS 1
  159578. #define PNG_NO_READ_iTXt 1
  159579. #define PNG_NO_READ_sCAL 1
  159580. #define PNG_NO_READ_sPLT 1
  159581. #define png_error(a, b) png_err(a)
  159582. #define png_warning(a, b)
  159583. #define png_chunk_error(a, b) png_err(a)
  159584. #define png_chunk_warning(a, b)
  159585. #ifdef PNG_USER_CONFIG
  159586. # ifndef PNG_USER_PRIVATEBUILD
  159587. # define PNG_USER_PRIVATEBUILD
  159588. # endif
  159589. #include "pngusr.h"
  159590. #endif
  159591. #ifdef PNG_CONFIGURE_LIBPNG
  159592. #ifdef HAVE_CONFIG_H
  159593. #include "config.h"
  159594. #endif
  159595. #endif
  159596. #ifdef __STDC__
  159597. #ifdef SPECIALBUILD
  159598. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159599. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159600. #endif
  159601. #ifdef PRIVATEBUILD
  159602. # pragma message("PRIVATEBUILD is deprecated.\
  159603. Use PNG_USER_PRIVATEBUILD instead.")
  159604. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159605. #endif
  159606. #endif /* __STDC__ */
  159607. #ifndef PNG_VERSION_INFO_ONLY
  159608. # define PNG_WARN_UNINITIALIZED_ROW 1
  159609. #ifndef PNG_ZBUF_SIZE
  159610. # define PNG_ZBUF_SIZE 8192
  159611. #endif
  159612. #ifndef PNG_NO_READ_SUPPORTED
  159613. # define PNG_READ_SUPPORTED
  159614. #endif
  159615. #ifndef PNG_NO_WRITE_SUPPORTED
  159616. # define PNG_WRITE_SUPPORTED
  159617. #endif
  159618. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159619. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159620. # define PNG_MNG_FEATURES_SUPPORTED
  159621. # endif
  159622. #endif
  159623. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159624. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159625. # define PNG_FLOATING_POINT_SUPPORTED
  159626. # endif
  159627. #endif
  159628. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159629. # define PNG_MAX_MALLOC_64K
  159630. #endif
  159631. #if defined(__CYGWIN__)
  159632. # if defined(ALL_STATIC)
  159633. # if defined(PNG_BUILD_DLL)
  159634. # undef PNG_BUILD_DLL
  159635. # endif
  159636. # if defined(PNG_USE_DLL)
  159637. # undef PNG_USE_DLL
  159638. # endif
  159639. # if defined(PNG_DLL)
  159640. # undef PNG_DLL
  159641. # endif
  159642. # if !defined(PNG_STATIC)
  159643. # define PNG_STATIC
  159644. # endif
  159645. # else
  159646. # if defined (PNG_BUILD_DLL)
  159647. # if defined(PNG_STATIC)
  159648. # undef PNG_STATIC
  159649. # endif
  159650. # if defined(PNG_USE_DLL)
  159651. # undef PNG_USE_DLL
  159652. # endif
  159653. # if !defined(PNG_DLL)
  159654. # define PNG_DLL
  159655. # endif
  159656. # else
  159657. # if defined(PNG_STATIC)
  159658. # if defined(PNG_USE_DLL)
  159659. # undef PNG_USE_DLL
  159660. # endif
  159661. # if defined(PNG_DLL)
  159662. # undef PNG_DLL
  159663. # endif
  159664. # else
  159665. # if !defined(PNG_USE_DLL)
  159666. # define PNG_USE_DLL
  159667. # endif
  159668. # if !defined(PNG_DLL)
  159669. # define PNG_DLL
  159670. # endif
  159671. # endif
  159672. # endif
  159673. # endif
  159674. #endif
  159675. #if defined(_WIN32_WCE)
  159676. # include <windows.h>
  159677. # define PNG_NO_CONSOLE_IO
  159678. # ifdef PNG_DEBUG
  159679. # undef PNG_DEBUG
  159680. # endif
  159681. #endif
  159682. #ifdef PNG_BUILD_DLL
  159683. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159684. # ifndef PNG_NO_CONSOLE_IO
  159685. # define PNG_NO_CONSOLE_IO
  159686. # endif
  159687. # endif
  159688. #endif
  159689. # ifdef PNG_NO_STDIO
  159690. # ifndef PNG_NO_CONSOLE_IO
  159691. # define PNG_NO_CONSOLE_IO
  159692. # endif
  159693. # ifdef PNG_DEBUG
  159694. # if (PNG_DEBUG > 0)
  159695. # include <stdio.h>
  159696. # endif
  159697. # endif
  159698. # else
  159699. # if !defined(_WIN32_WCE)
  159700. # include <stdio.h>
  159701. # endif
  159702. # endif
  159703. #ifndef PNGARG
  159704. #ifdef OF /* zlib prototype munger */
  159705. # define PNGARG(arglist) OF(arglist)
  159706. #else
  159707. #ifdef _NO_PROTO
  159708. # define PNGARG(arglist) ()
  159709. # ifndef PNG_TYPECAST_NULL
  159710. # define PNG_TYPECAST_NULL
  159711. # endif
  159712. #else
  159713. # define PNGARG(arglist) arglist
  159714. #endif /* _NO_PROTO */
  159715. #endif /* OF */
  159716. #endif /* PNGARG */
  159717. #ifndef MACOS
  159718. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159719. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159720. # define MACOS
  159721. # endif
  159722. #endif
  159723. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159724. # include <sys/types.h>
  159725. #endif
  159726. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159727. # define PNG_SETJMP_SUPPORTED
  159728. #endif
  159729. #ifdef PNG_SETJMP_SUPPORTED
  159730. # ifdef __linux__
  159731. # ifdef _BSD_SOURCE
  159732. # define PNG_SAVE_BSD_SOURCE
  159733. # undef _BSD_SOURCE
  159734. # endif
  159735. # ifdef _SETJMP_H
  159736. __png.h__ already includes setjmp.h;
  159737. __dont__ include it again.;
  159738. # endif
  159739. # endif /* __linux__ */
  159740. # include <setjmp.h>
  159741. # ifdef __linux__
  159742. # ifdef PNG_SAVE_BSD_SOURCE
  159743. # define _BSD_SOURCE
  159744. # undef PNG_SAVE_BSD_SOURCE
  159745. # endif
  159746. # endif /* __linux__ */
  159747. #endif /* PNG_SETJMP_SUPPORTED */
  159748. #ifdef BSD
  159749. #if ! JUCE_MAC
  159750. # include <strings.h>
  159751. #endif
  159752. #else
  159753. # include <string.h>
  159754. #endif
  159755. #ifdef PNG_INTERNAL
  159756. #include <stdlib.h>
  159757. #define PNG_EXTERN
  159758. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159759. # if defined(MACOS)
  159760. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159761. # include <fp.h>
  159762. # endif
  159763. # else
  159764. # include <math.h>
  159765. # endif
  159766. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159767. # include <m68881.h>
  159768. # endif
  159769. #endif
  159770. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159771. # define PNG_ALWAYS_EXTERN
  159772. #endif
  159773. #if defined(__TURBOC__) && defined(__MSDOS__)
  159774. # include <mem.h>
  159775. # include <alloc.h>
  159776. #endif
  159777. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159778. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159779. # include <malloc.h>
  159780. #endif
  159781. #ifndef PNG_DITHER_RED_BITS
  159782. # define PNG_DITHER_RED_BITS 5
  159783. #endif
  159784. #ifndef PNG_DITHER_GREEN_BITS
  159785. # define PNG_DITHER_GREEN_BITS 5
  159786. #endif
  159787. #ifndef PNG_DITHER_BLUE_BITS
  159788. # define PNG_DITHER_BLUE_BITS 5
  159789. #endif
  159790. #ifndef PNG_MAX_GAMMA_8
  159791. # define PNG_MAX_GAMMA_8 11
  159792. #endif
  159793. #ifndef PNG_GAMMA_THRESHOLD
  159794. # define PNG_GAMMA_THRESHOLD 0.05
  159795. #endif
  159796. #endif /* PNG_INTERNAL */
  159797. #ifndef PNG_NO_CONST
  159798. # define PNG_CONST const
  159799. #else
  159800. # define PNG_CONST
  159801. #endif
  159802. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159803. # ifndef PNG_NO_iTXt_SUPPORTED
  159804. # define PNG_NO_iTXt_SUPPORTED
  159805. # endif
  159806. # ifndef PNG_NO_READ_iTXt
  159807. # define PNG_NO_READ_iTXt
  159808. # endif
  159809. # ifndef PNG_NO_WRITE_iTXt
  159810. # define PNG_NO_WRITE_iTXt
  159811. # endif
  159812. #endif
  159813. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159814. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159815. # define PNG_READ_iTXt
  159816. # endif
  159817. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159818. # define PNG_WRITE_iTXt
  159819. # endif
  159820. #endif
  159821. #ifdef PNG_LEGACY_SUPPORTED
  159822. # define PNG_NO_FREE_ME
  159823. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159824. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159825. # define PNG_NO_READ_USER_CHUNKS
  159826. # define PNG_NO_READ_iCCP
  159827. # define PNG_NO_WRITE_iCCP
  159828. # define PNG_NO_READ_iTXt
  159829. # define PNG_NO_WRITE_iTXt
  159830. # define PNG_NO_READ_sCAL
  159831. # define PNG_NO_WRITE_sCAL
  159832. # define PNG_NO_READ_sPLT
  159833. # define PNG_NO_WRITE_sPLT
  159834. # define PNG_NO_INFO_IMAGE
  159835. # define PNG_NO_READ_RGB_TO_GRAY
  159836. # define PNG_NO_READ_USER_TRANSFORM
  159837. # define PNG_NO_WRITE_USER_TRANSFORM
  159838. # define PNG_NO_USER_MEM
  159839. # define PNG_NO_READ_EMPTY_PLTE
  159840. # define PNG_NO_MNG_FEATURES
  159841. # define PNG_NO_FIXED_POINT_SUPPORTED
  159842. #endif
  159843. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159844. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159845. # define PNG_FIXED_POINT_SUPPORTED
  159846. #endif
  159847. #ifndef PNG_NO_FREE_ME
  159848. # define PNG_FREE_ME_SUPPORTED
  159849. #endif
  159850. #if defined(PNG_READ_SUPPORTED)
  159851. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159852. !defined(PNG_NO_READ_TRANSFORMS)
  159853. # define PNG_READ_TRANSFORMS_SUPPORTED
  159854. #endif
  159855. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159856. # ifndef PNG_NO_READ_EXPAND
  159857. # define PNG_READ_EXPAND_SUPPORTED
  159858. # endif
  159859. # ifndef PNG_NO_READ_SHIFT
  159860. # define PNG_READ_SHIFT_SUPPORTED
  159861. # endif
  159862. # ifndef PNG_NO_READ_PACK
  159863. # define PNG_READ_PACK_SUPPORTED
  159864. # endif
  159865. # ifndef PNG_NO_READ_BGR
  159866. # define PNG_READ_BGR_SUPPORTED
  159867. # endif
  159868. # ifndef PNG_NO_READ_SWAP
  159869. # define PNG_READ_SWAP_SUPPORTED
  159870. # endif
  159871. # ifndef PNG_NO_READ_PACKSWAP
  159872. # define PNG_READ_PACKSWAP_SUPPORTED
  159873. # endif
  159874. # ifndef PNG_NO_READ_INVERT
  159875. # define PNG_READ_INVERT_SUPPORTED
  159876. # endif
  159877. # ifndef PNG_NO_READ_DITHER
  159878. # define PNG_READ_DITHER_SUPPORTED
  159879. # endif
  159880. # ifndef PNG_NO_READ_BACKGROUND
  159881. # define PNG_READ_BACKGROUND_SUPPORTED
  159882. # endif
  159883. # ifndef PNG_NO_READ_16_TO_8
  159884. # define PNG_READ_16_TO_8_SUPPORTED
  159885. # endif
  159886. # ifndef PNG_NO_READ_FILLER
  159887. # define PNG_READ_FILLER_SUPPORTED
  159888. # endif
  159889. # ifndef PNG_NO_READ_GAMMA
  159890. # define PNG_READ_GAMMA_SUPPORTED
  159891. # endif
  159892. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159893. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159894. # endif
  159895. # ifndef PNG_NO_READ_SWAP_ALPHA
  159896. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159897. # endif
  159898. # ifndef PNG_NO_READ_INVERT_ALPHA
  159899. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159900. # endif
  159901. # ifndef PNG_NO_READ_STRIP_ALPHA
  159902. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159903. # endif
  159904. # ifndef PNG_NO_READ_USER_TRANSFORM
  159905. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159906. # endif
  159907. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159908. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159909. # endif
  159910. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159911. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159912. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159913. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159914. #endif /* about interlacing capability! You'll */
  159915. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159916. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159917. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159918. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159919. # endif
  159920. #endif
  159921. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159922. #ifndef PNG_NO_READ_EMPTY_PLTE
  159923. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159924. #endif
  159925. #endif
  159926. #endif /* PNG_READ_SUPPORTED */
  159927. #if defined(PNG_WRITE_SUPPORTED)
  159928. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159929. !defined(PNG_NO_WRITE_TRANSFORMS)
  159930. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159931. #endif
  159932. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159933. # ifndef PNG_NO_WRITE_SHIFT
  159934. # define PNG_WRITE_SHIFT_SUPPORTED
  159935. # endif
  159936. # ifndef PNG_NO_WRITE_PACK
  159937. # define PNG_WRITE_PACK_SUPPORTED
  159938. # endif
  159939. # ifndef PNG_NO_WRITE_BGR
  159940. # define PNG_WRITE_BGR_SUPPORTED
  159941. # endif
  159942. # ifndef PNG_NO_WRITE_SWAP
  159943. # define PNG_WRITE_SWAP_SUPPORTED
  159944. # endif
  159945. # ifndef PNG_NO_WRITE_PACKSWAP
  159946. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159947. # endif
  159948. # ifndef PNG_NO_WRITE_INVERT
  159949. # define PNG_WRITE_INVERT_SUPPORTED
  159950. # endif
  159951. # ifndef PNG_NO_WRITE_FILLER
  159952. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159953. # endif
  159954. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159955. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159956. # endif
  159957. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159958. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159959. # endif
  159960. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159961. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159962. # endif
  159963. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159964. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159965. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159966. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159967. encoders, but can cause trouble
  159968. if left undefined */
  159969. #endif
  159970. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159971. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159972. defined(PNG_FLOATING_POINT_SUPPORTED)
  159973. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159974. #endif
  159975. #ifndef PNG_NO_WRITE_FLUSH
  159976. # define PNG_WRITE_FLUSH_SUPPORTED
  159977. #endif
  159978. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159979. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159980. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159981. #endif
  159982. #endif
  159983. #endif /* PNG_WRITE_SUPPORTED */
  159984. #ifndef PNG_1_0_X
  159985. # ifndef PNG_NO_ERROR_NUMBERS
  159986. # define PNG_ERROR_NUMBERS_SUPPORTED
  159987. # endif
  159988. #endif /* PNG_1_0_X */
  159989. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159990. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159991. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159992. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159993. # endif
  159994. #endif
  159995. #ifndef PNG_NO_STDIO
  159996. # define PNG_TIME_RFC1123_SUPPORTED
  159997. #endif
  159998. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159999. # define PNG_EASY_ACCESS_SUPPORTED
  160000. #endif
  160001. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  160002. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  160003. # define PNG_OPTIMIZED_CODE_SUPPORTED
  160004. # endif
  160005. #endif
  160006. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  160007. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  160008. # define PNG_ASSEMBLER_CODE_SUPPORTED
  160009. # endif
  160010. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  160011. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160012. # define PNG_NO_MMX_CODE
  160013. # endif
  160014. # endif
  160015. # if defined(__APPLE__)
  160016. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160017. # define PNG_NO_MMX_CODE
  160018. # endif
  160019. # endif
  160020. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  160021. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160022. # define PNG_NO_MMX_CODE
  160023. # endif
  160024. # endif
  160025. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160026. # define PNG_MMX_CODE_SUPPORTED
  160027. # endif
  160028. #endif
  160029. #if !defined(PNG_1_0_X)
  160030. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  160031. # define PNG_USER_MEM_SUPPORTED
  160032. #endif
  160033. #endif /* PNG_1_0_X */
  160034. #if !defined(PNG_1_0_X)
  160035. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  160036. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  160037. # define PNG_SET_USER_LIMITS_SUPPORTED
  160038. #endif
  160039. #endif
  160040. #endif /* PNG_1_0_X */
  160041. #ifndef PNG_USER_WIDTH_MAX
  160042. # define PNG_USER_WIDTH_MAX 1000000L
  160043. #endif
  160044. #ifndef PNG_USER_HEIGHT_MAX
  160045. # define PNG_USER_HEIGHT_MAX 1000000L
  160046. #endif
  160047. #if defined(PNG_READ_SUPPORTED) && \
  160048. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160049. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  160050. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160051. #endif
  160052. #if defined(PNG_WRITE_SUPPORTED) && \
  160053. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160054. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  160055. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160056. #endif
  160057. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160058. #ifdef PNG_NO_READ_TEXT
  160059. # define PNG_NO_READ_iTXt
  160060. # define PNG_NO_READ_tEXt
  160061. # define PNG_NO_READ_zTXt
  160062. #endif
  160063. #ifndef PNG_NO_READ_bKGD
  160064. # define PNG_READ_bKGD_SUPPORTED
  160065. # define PNG_bKGD_SUPPORTED
  160066. #endif
  160067. #ifndef PNG_NO_READ_cHRM
  160068. # define PNG_READ_cHRM_SUPPORTED
  160069. # define PNG_cHRM_SUPPORTED
  160070. #endif
  160071. #ifndef PNG_NO_READ_gAMA
  160072. # define PNG_READ_gAMA_SUPPORTED
  160073. # define PNG_gAMA_SUPPORTED
  160074. #endif
  160075. #ifndef PNG_NO_READ_hIST
  160076. # define PNG_READ_hIST_SUPPORTED
  160077. # define PNG_hIST_SUPPORTED
  160078. #endif
  160079. #ifndef PNG_NO_READ_iCCP
  160080. # define PNG_READ_iCCP_SUPPORTED
  160081. # define PNG_iCCP_SUPPORTED
  160082. #endif
  160083. #ifndef PNG_NO_READ_iTXt
  160084. # ifndef PNG_READ_iTXt_SUPPORTED
  160085. # define PNG_READ_iTXt_SUPPORTED
  160086. # endif
  160087. # ifndef PNG_iTXt_SUPPORTED
  160088. # define PNG_iTXt_SUPPORTED
  160089. # endif
  160090. #endif
  160091. #ifndef PNG_NO_READ_oFFs
  160092. # define PNG_READ_oFFs_SUPPORTED
  160093. # define PNG_oFFs_SUPPORTED
  160094. #endif
  160095. #ifndef PNG_NO_READ_pCAL
  160096. # define PNG_READ_pCAL_SUPPORTED
  160097. # define PNG_pCAL_SUPPORTED
  160098. #endif
  160099. #ifndef PNG_NO_READ_sCAL
  160100. # define PNG_READ_sCAL_SUPPORTED
  160101. # define PNG_sCAL_SUPPORTED
  160102. #endif
  160103. #ifndef PNG_NO_READ_pHYs
  160104. # define PNG_READ_pHYs_SUPPORTED
  160105. # define PNG_pHYs_SUPPORTED
  160106. #endif
  160107. #ifndef PNG_NO_READ_sBIT
  160108. # define PNG_READ_sBIT_SUPPORTED
  160109. # define PNG_sBIT_SUPPORTED
  160110. #endif
  160111. #ifndef PNG_NO_READ_sPLT
  160112. # define PNG_READ_sPLT_SUPPORTED
  160113. # define PNG_sPLT_SUPPORTED
  160114. #endif
  160115. #ifndef PNG_NO_READ_sRGB
  160116. # define PNG_READ_sRGB_SUPPORTED
  160117. # define PNG_sRGB_SUPPORTED
  160118. #endif
  160119. #ifndef PNG_NO_READ_tEXt
  160120. # define PNG_READ_tEXt_SUPPORTED
  160121. # define PNG_tEXt_SUPPORTED
  160122. #endif
  160123. #ifndef PNG_NO_READ_tIME
  160124. # define PNG_READ_tIME_SUPPORTED
  160125. # define PNG_tIME_SUPPORTED
  160126. #endif
  160127. #ifndef PNG_NO_READ_tRNS
  160128. # define PNG_READ_tRNS_SUPPORTED
  160129. # define PNG_tRNS_SUPPORTED
  160130. #endif
  160131. #ifndef PNG_NO_READ_zTXt
  160132. # define PNG_READ_zTXt_SUPPORTED
  160133. # define PNG_zTXt_SUPPORTED
  160134. #endif
  160135. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160136. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160137. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160138. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160139. # endif
  160140. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160141. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160142. # endif
  160143. #endif
  160144. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160145. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160146. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160147. # define PNG_USER_CHUNKS_SUPPORTED
  160148. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160149. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160150. # endif
  160151. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160152. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160153. # endif
  160154. #endif
  160155. #ifndef PNG_NO_READ_OPT_PLTE
  160156. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160157. #endif /* optional PLTE chunk in RGB and RGBA images */
  160158. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160159. defined(PNG_READ_zTXt_SUPPORTED)
  160160. # define PNG_READ_TEXT_SUPPORTED
  160161. # define PNG_TEXT_SUPPORTED
  160162. #endif
  160163. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160164. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160165. #ifdef PNG_NO_WRITE_TEXT
  160166. # define PNG_NO_WRITE_iTXt
  160167. # define PNG_NO_WRITE_tEXt
  160168. # define PNG_NO_WRITE_zTXt
  160169. #endif
  160170. #ifndef PNG_NO_WRITE_bKGD
  160171. # define PNG_WRITE_bKGD_SUPPORTED
  160172. # ifndef PNG_bKGD_SUPPORTED
  160173. # define PNG_bKGD_SUPPORTED
  160174. # endif
  160175. #endif
  160176. #ifndef PNG_NO_WRITE_cHRM
  160177. # define PNG_WRITE_cHRM_SUPPORTED
  160178. # ifndef PNG_cHRM_SUPPORTED
  160179. # define PNG_cHRM_SUPPORTED
  160180. # endif
  160181. #endif
  160182. #ifndef PNG_NO_WRITE_gAMA
  160183. # define PNG_WRITE_gAMA_SUPPORTED
  160184. # ifndef PNG_gAMA_SUPPORTED
  160185. # define PNG_gAMA_SUPPORTED
  160186. # endif
  160187. #endif
  160188. #ifndef PNG_NO_WRITE_hIST
  160189. # define PNG_WRITE_hIST_SUPPORTED
  160190. # ifndef PNG_hIST_SUPPORTED
  160191. # define PNG_hIST_SUPPORTED
  160192. # endif
  160193. #endif
  160194. #ifndef PNG_NO_WRITE_iCCP
  160195. # define PNG_WRITE_iCCP_SUPPORTED
  160196. # ifndef PNG_iCCP_SUPPORTED
  160197. # define PNG_iCCP_SUPPORTED
  160198. # endif
  160199. #endif
  160200. #ifndef PNG_NO_WRITE_iTXt
  160201. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160202. # define PNG_WRITE_iTXt_SUPPORTED
  160203. # endif
  160204. # ifndef PNG_iTXt_SUPPORTED
  160205. # define PNG_iTXt_SUPPORTED
  160206. # endif
  160207. #endif
  160208. #ifndef PNG_NO_WRITE_oFFs
  160209. # define PNG_WRITE_oFFs_SUPPORTED
  160210. # ifndef PNG_oFFs_SUPPORTED
  160211. # define PNG_oFFs_SUPPORTED
  160212. # endif
  160213. #endif
  160214. #ifndef PNG_NO_WRITE_pCAL
  160215. # define PNG_WRITE_pCAL_SUPPORTED
  160216. # ifndef PNG_pCAL_SUPPORTED
  160217. # define PNG_pCAL_SUPPORTED
  160218. # endif
  160219. #endif
  160220. #ifndef PNG_NO_WRITE_sCAL
  160221. # define PNG_WRITE_sCAL_SUPPORTED
  160222. # ifndef PNG_sCAL_SUPPORTED
  160223. # define PNG_sCAL_SUPPORTED
  160224. # endif
  160225. #endif
  160226. #ifndef PNG_NO_WRITE_pHYs
  160227. # define PNG_WRITE_pHYs_SUPPORTED
  160228. # ifndef PNG_pHYs_SUPPORTED
  160229. # define PNG_pHYs_SUPPORTED
  160230. # endif
  160231. #endif
  160232. #ifndef PNG_NO_WRITE_sBIT
  160233. # define PNG_WRITE_sBIT_SUPPORTED
  160234. # ifndef PNG_sBIT_SUPPORTED
  160235. # define PNG_sBIT_SUPPORTED
  160236. # endif
  160237. #endif
  160238. #ifndef PNG_NO_WRITE_sPLT
  160239. # define PNG_WRITE_sPLT_SUPPORTED
  160240. # ifndef PNG_sPLT_SUPPORTED
  160241. # define PNG_sPLT_SUPPORTED
  160242. # endif
  160243. #endif
  160244. #ifndef PNG_NO_WRITE_sRGB
  160245. # define PNG_WRITE_sRGB_SUPPORTED
  160246. # ifndef PNG_sRGB_SUPPORTED
  160247. # define PNG_sRGB_SUPPORTED
  160248. # endif
  160249. #endif
  160250. #ifndef PNG_NO_WRITE_tEXt
  160251. # define PNG_WRITE_tEXt_SUPPORTED
  160252. # ifndef PNG_tEXt_SUPPORTED
  160253. # define PNG_tEXt_SUPPORTED
  160254. # endif
  160255. #endif
  160256. #ifndef PNG_NO_WRITE_tIME
  160257. # define PNG_WRITE_tIME_SUPPORTED
  160258. # ifndef PNG_tIME_SUPPORTED
  160259. # define PNG_tIME_SUPPORTED
  160260. # endif
  160261. #endif
  160262. #ifndef PNG_NO_WRITE_tRNS
  160263. # define PNG_WRITE_tRNS_SUPPORTED
  160264. # ifndef PNG_tRNS_SUPPORTED
  160265. # define PNG_tRNS_SUPPORTED
  160266. # endif
  160267. #endif
  160268. #ifndef PNG_NO_WRITE_zTXt
  160269. # define PNG_WRITE_zTXt_SUPPORTED
  160270. # ifndef PNG_zTXt_SUPPORTED
  160271. # define PNG_zTXt_SUPPORTED
  160272. # endif
  160273. #endif
  160274. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160275. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160276. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160277. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160278. # endif
  160279. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160280. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160281. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160282. # endif
  160283. # endif
  160284. #endif
  160285. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160286. defined(PNG_WRITE_zTXt_SUPPORTED)
  160287. # define PNG_WRITE_TEXT_SUPPORTED
  160288. # ifndef PNG_TEXT_SUPPORTED
  160289. # define PNG_TEXT_SUPPORTED
  160290. # endif
  160291. #endif
  160292. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160293. #ifndef PNG_NO_INFO_IMAGE
  160294. # define PNG_INFO_IMAGE_SUPPORTED
  160295. #endif
  160296. #if defined(PNG_tIME_SUPPORTED)
  160297. # if !defined(_WIN32_WCE)
  160298. # include <time.h>
  160299. # endif
  160300. #endif
  160301. typedef unsigned long png_uint_32;
  160302. typedef long png_int_32;
  160303. typedef unsigned short png_uint_16;
  160304. typedef short png_int_16;
  160305. typedef unsigned char png_byte;
  160306. #ifdef PNG_SIZE_T
  160307. typedef PNG_SIZE_T png_size_t;
  160308. # define png_sizeof(x) png_convert_size(sizeof (x))
  160309. #else
  160310. typedef size_t png_size_t;
  160311. # define png_sizeof(x) sizeof (x)
  160312. #endif
  160313. #ifdef __BORLANDC__
  160314. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160315. # define LDATA 1
  160316. # else
  160317. # define LDATA 0
  160318. # endif
  160319. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160320. # define PNG_MAX_MALLOC_64K
  160321. # if (LDATA != 1)
  160322. # ifndef FAR
  160323. # define FAR __far
  160324. # endif
  160325. # define USE_FAR_KEYWORD
  160326. # endif /* LDATA != 1 */
  160327. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160328. #endif /* __BORLANDC__ */
  160329. #if defined(FAR)
  160330. # if defined(M_I86MM)
  160331. # define USE_FAR_KEYWORD
  160332. # define FARDATA FAR
  160333. # include <dos.h>
  160334. # endif
  160335. #endif
  160336. #ifndef FAR
  160337. # define FAR
  160338. #endif
  160339. #ifndef FARDATA
  160340. # define FARDATA
  160341. #endif
  160342. typedef png_int_32 png_fixed_point;
  160343. typedef void FAR * png_voidp;
  160344. typedef png_byte FAR * png_bytep;
  160345. typedef png_uint_32 FAR * png_uint_32p;
  160346. typedef png_int_32 FAR * png_int_32p;
  160347. typedef png_uint_16 FAR * png_uint_16p;
  160348. typedef png_int_16 FAR * png_int_16p;
  160349. typedef PNG_CONST char FAR * png_const_charp;
  160350. typedef char FAR * png_charp;
  160351. typedef png_fixed_point FAR * png_fixed_point_p;
  160352. #ifndef PNG_NO_STDIO
  160353. #if defined(_WIN32_WCE)
  160354. typedef HANDLE png_FILE_p;
  160355. #else
  160356. typedef FILE * png_FILE_p;
  160357. #endif
  160358. #endif
  160359. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160360. typedef double FAR * png_doublep;
  160361. #endif
  160362. typedef png_byte FAR * FAR * png_bytepp;
  160363. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160364. typedef png_int_32 FAR * FAR * png_int_32pp;
  160365. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160366. typedef png_int_16 FAR * FAR * png_int_16pp;
  160367. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160368. typedef char FAR * FAR * png_charpp;
  160369. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160370. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160371. typedef double FAR * FAR * png_doublepp;
  160372. #endif
  160373. typedef char FAR * FAR * FAR * png_charppp;
  160374. #if 0
  160375. typedef charf * png_zcharp;
  160376. typedef charf * FAR * png_zcharpp;
  160377. typedef z_stream FAR * png_zstreamp;
  160378. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160379. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160380. # define PNG_DLL
  160381. #endif
  160382. #if defined(__CYGWIN__)
  160383. # if !defined(PNG_STATIC)
  160384. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160385. # undef PNG_USE_GLOBAL_ARRAYS
  160386. # endif
  160387. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160388. # define PNG_USE_LOCAL_ARRAYS
  160389. # endif
  160390. # else
  160391. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160392. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160393. # undef PNG_USE_GLOBAL_ARRAYS
  160394. # endif
  160395. # endif
  160396. # endif
  160397. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160398. # define PNG_USE_LOCAL_ARRAYS
  160399. # endif
  160400. #endif
  160401. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160402. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160403. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160404. # define PNG_USE_LOCAL_ARRAYS
  160405. # else
  160406. # define PNG_USE_GLOBAL_ARRAYS
  160407. # endif
  160408. #endif
  160409. #if defined(__CYGWIN__)
  160410. # undef PNGAPI
  160411. # define PNGAPI __cdecl
  160412. # undef PNG_IMPEXP
  160413. # define PNG_IMPEXP
  160414. #endif
  160415. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160416. # ifndef PNG_NO_MODULEDEF
  160417. # define PNG_NO_MODULEDEF
  160418. # endif
  160419. #endif
  160420. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160421. # define PNG_IMPEXP
  160422. #endif
  160423. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160424. (( defined(_Windows) || defined(_WINDOWS) || \
  160425. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160426. # ifndef PNGAPI
  160427. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160428. # define PNGAPI __cdecl
  160429. # else
  160430. # define PNGAPI _cdecl
  160431. # endif
  160432. # endif
  160433. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160434. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160435. # define PNG_IMPEXP
  160436. # endif
  160437. # if !defined(PNG_IMPEXP)
  160438. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160439. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160440. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160441. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160442. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160443. # else
  160444. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160445. # if defined(PNG_BUILD_DLL)
  160446. # define PNG_IMPEXP __export
  160447. # else
  160448. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160449. VC++ */
  160450. # endif /* Exists in Borland C++ for
  160451. C++ classes (== huge) */
  160452. # endif
  160453. # endif
  160454. # if !defined(PNG_IMPEXP)
  160455. # if defined(PNG_BUILD_DLL)
  160456. # define PNG_IMPEXP __declspec(dllexport)
  160457. # else
  160458. # define PNG_IMPEXP __declspec(dllimport)
  160459. # endif
  160460. # endif
  160461. # endif /* PNG_IMPEXP */
  160462. #else /* !(DLL || non-cygwin WINDOWS) */
  160463. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160464. # ifndef PNGAPI
  160465. # define PNGAPI _System
  160466. # endif
  160467. # else
  160468. # if 0 /* ... other platforms, with other meanings */
  160469. # endif
  160470. # endif
  160471. #endif
  160472. #ifndef PNGAPI
  160473. # define PNGAPI
  160474. #endif
  160475. #ifndef PNG_IMPEXP
  160476. # define PNG_IMPEXP
  160477. #endif
  160478. #ifdef PNG_BUILDSYMS
  160479. # ifndef PNG_EXPORT
  160480. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160481. # endif
  160482. # ifdef PNG_USE_GLOBAL_ARRAYS
  160483. # ifndef PNG_EXPORT_VAR
  160484. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160485. # endif
  160486. # endif
  160487. #endif
  160488. #ifndef PNG_EXPORT
  160489. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160490. #endif
  160491. #ifdef PNG_USE_GLOBAL_ARRAYS
  160492. # ifndef PNG_EXPORT_VAR
  160493. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160494. # endif
  160495. #endif
  160496. #ifndef PNG_ABORT
  160497. # define PNG_ABORT() abort()
  160498. #endif
  160499. #ifdef PNG_SETJMP_SUPPORTED
  160500. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160501. #else
  160502. # define png_jmpbuf(png_ptr) \
  160503. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160504. #endif
  160505. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160506. # define CHECK 1
  160507. # define NOCHECK 0
  160508. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160509. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160510. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160511. # define png_strcpy _fstrcpy
  160512. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160513. # define png_strlen _fstrlen
  160514. # define png_memcmp _fmemcmp /* SJT: added */
  160515. # define png_memcpy _fmemcpy
  160516. # define png_memset _fmemset
  160517. #else /* use the usual functions */
  160518. # define CVT_PTR(ptr) (ptr)
  160519. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160520. # ifndef PNG_NO_SNPRINTF
  160521. # ifdef _MSC_VER
  160522. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160523. # define png_snprintf2 _snprintf
  160524. # define png_snprintf6 _snprintf
  160525. # else
  160526. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160527. # define png_snprintf2 snprintf
  160528. # define png_snprintf6 snprintf
  160529. # endif
  160530. # else
  160531. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160532. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160533. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160534. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160535. # endif
  160536. # define png_strcpy strcpy
  160537. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160538. # define png_strlen strlen
  160539. # define png_memcmp memcmp /* SJT: added */
  160540. # define png_memcpy memcpy
  160541. # define png_memset memset
  160542. #endif
  160543. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160544. # undef PNG_ZBUF_SIZE
  160545. # define PNG_ZBUF_SIZE 65536L
  160546. #endif
  160547. #endif /* PNG_VERSION_INFO_ONLY */
  160548. #endif /* PNGCONF_H */
  160549. /*** End of inlined file: pngconf.h ***/
  160550. #ifdef _MSC_VER
  160551. #pragma warning (disable: 4996 4100)
  160552. #endif
  160553. #if defined(PNG_USER_PRIVATEBUILD)
  160554. # define PNG_LIBPNG_BUILD_TYPE \
  160555. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160556. #else
  160557. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160558. # define PNG_LIBPNG_BUILD_TYPE \
  160559. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160560. # else
  160561. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160562. # endif
  160563. #endif
  160564. #ifndef PNG_VERSION_INFO_ONLY
  160565. #ifdef __cplusplus
  160566. extern "C" {
  160567. #endif /* __cplusplus */
  160568. #ifndef PNG_NO_TYPECAST_NULL
  160569. #define int_p_NULL (int *)NULL
  160570. #define png_bytep_NULL (png_bytep)NULL
  160571. #define png_bytepp_NULL (png_bytepp)NULL
  160572. #define png_doublep_NULL (png_doublep)NULL
  160573. #define png_error_ptr_NULL (png_error_ptr)NULL
  160574. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160575. #define png_free_ptr_NULL (png_free_ptr)NULL
  160576. #define png_infopp_NULL (png_infopp)NULL
  160577. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160578. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160579. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160580. #define png_structp_NULL (png_structp)NULL
  160581. #define png_uint_16p_NULL (png_uint_16p)NULL
  160582. #define png_voidp_NULL (png_voidp)NULL
  160583. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160584. #else
  160585. #define int_p_NULL NULL
  160586. #define png_bytep_NULL NULL
  160587. #define png_bytepp_NULL NULL
  160588. #define png_doublep_NULL NULL
  160589. #define png_error_ptr_NULL NULL
  160590. #define png_flush_ptr_NULL NULL
  160591. #define png_free_ptr_NULL NULL
  160592. #define png_infopp_NULL NULL
  160593. #define png_malloc_ptr_NULL NULL
  160594. #define png_read_status_ptr_NULL NULL
  160595. #define png_rw_ptr_NULL NULL
  160596. #define png_structp_NULL NULL
  160597. #define png_uint_16p_NULL NULL
  160598. #define png_voidp_NULL NULL
  160599. #define png_write_status_ptr_NULL NULL
  160600. #endif
  160601. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160602. #ifdef PNG_USE_GLOBAL_ARRAYS
  160603. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160604. #else
  160605. #define png_libpng_ver png_get_header_ver(NULL)
  160606. #endif
  160607. #ifdef PNG_USE_GLOBAL_ARRAYS
  160608. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160609. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160610. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160611. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160612. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160613. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160614. #endif
  160615. #endif /* PNG_NO_EXTERN */
  160616. typedef struct png_color_struct
  160617. {
  160618. png_byte red;
  160619. png_byte green;
  160620. png_byte blue;
  160621. } png_color;
  160622. typedef png_color FAR * png_colorp;
  160623. typedef png_color FAR * FAR * png_colorpp;
  160624. typedef struct png_color_16_struct
  160625. {
  160626. png_byte index; /* used for palette files */
  160627. png_uint_16 red; /* for use in red green blue files */
  160628. png_uint_16 green;
  160629. png_uint_16 blue;
  160630. png_uint_16 gray; /* for use in grayscale files */
  160631. } png_color_16;
  160632. typedef png_color_16 FAR * png_color_16p;
  160633. typedef png_color_16 FAR * FAR * png_color_16pp;
  160634. typedef struct png_color_8_struct
  160635. {
  160636. png_byte red; /* for use in red green blue files */
  160637. png_byte green;
  160638. png_byte blue;
  160639. png_byte gray; /* for use in grayscale files */
  160640. png_byte alpha; /* for alpha channel files */
  160641. } png_color_8;
  160642. typedef png_color_8 FAR * png_color_8p;
  160643. typedef png_color_8 FAR * FAR * png_color_8pp;
  160644. typedef struct png_sPLT_entry_struct
  160645. {
  160646. png_uint_16 red;
  160647. png_uint_16 green;
  160648. png_uint_16 blue;
  160649. png_uint_16 alpha;
  160650. png_uint_16 frequency;
  160651. } png_sPLT_entry;
  160652. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160653. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160654. typedef struct png_sPLT_struct
  160655. {
  160656. png_charp name; /* palette name */
  160657. png_byte depth; /* depth of palette samples */
  160658. png_sPLT_entryp entries; /* palette entries */
  160659. png_int_32 nentries; /* number of palette entries */
  160660. } png_sPLT_t;
  160661. typedef png_sPLT_t FAR * png_sPLT_tp;
  160662. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160663. #ifdef PNG_TEXT_SUPPORTED
  160664. typedef struct png_text_struct
  160665. {
  160666. int compression; /* compression value:
  160667. -1: tEXt, none
  160668. 0: zTXt, deflate
  160669. 1: iTXt, none
  160670. 2: iTXt, deflate */
  160671. png_charp key; /* keyword, 1-79 character description of "text" */
  160672. png_charp text; /* comment, may be an empty string (ie "")
  160673. or a NULL pointer */
  160674. png_size_t text_length; /* length of the text string */
  160675. #ifdef PNG_iTXt_SUPPORTED
  160676. png_size_t itxt_length; /* length of the itxt string */
  160677. png_charp lang; /* language code, 0-79 characters
  160678. or a NULL pointer */
  160679. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160680. chars or a NULL pointer */
  160681. #endif
  160682. } png_text;
  160683. typedef png_text FAR * png_textp;
  160684. typedef png_text FAR * FAR * png_textpp;
  160685. #endif
  160686. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160687. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160688. #define PNG_TEXT_COMPRESSION_NONE -1
  160689. #define PNG_TEXT_COMPRESSION_zTXt 0
  160690. #define PNG_ITXT_COMPRESSION_NONE 1
  160691. #define PNG_ITXT_COMPRESSION_zTXt 2
  160692. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160693. typedef struct png_time_struct
  160694. {
  160695. png_uint_16 year; /* full year, as in, 1995 */
  160696. png_byte month; /* month of year, 1 - 12 */
  160697. png_byte day; /* day of month, 1 - 31 */
  160698. png_byte hour; /* hour of day, 0 - 23 */
  160699. png_byte minute; /* minute of hour, 0 - 59 */
  160700. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160701. } png_time;
  160702. typedef png_time FAR * png_timep;
  160703. typedef png_time FAR * FAR * png_timepp;
  160704. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160705. typedef struct png_unknown_chunk_t
  160706. {
  160707. png_byte name[5];
  160708. png_byte *data;
  160709. png_size_t size;
  160710. png_byte location; /* mode of operation at read time */
  160711. }
  160712. png_unknown_chunk;
  160713. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160714. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160715. #endif
  160716. typedef struct png_info_struct
  160717. {
  160718. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160719. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160720. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160721. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160722. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160723. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160724. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160725. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160726. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160727. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160728. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160729. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160730. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160731. png_byte pixel_depth; /* number of bits per pixel */
  160732. png_byte spare_byte; /* to align the data, and for future use */
  160733. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160734. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160735. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160736. #endif
  160737. #if defined(PNG_sRGB_SUPPORTED)
  160738. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160739. #endif
  160740. #if defined(PNG_TEXT_SUPPORTED)
  160741. int num_text; /* number of comments read/to write */
  160742. int max_text; /* current size of text array */
  160743. png_textp text; /* array of comments read/to write */
  160744. #endif /* PNG_TEXT_SUPPORTED */
  160745. #if defined(PNG_tIME_SUPPORTED)
  160746. png_time mod_time;
  160747. #endif
  160748. #if defined(PNG_sBIT_SUPPORTED)
  160749. png_color_8 sig_bit; /* significant bits in color channels */
  160750. #endif
  160751. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160752. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160753. png_bytep trans; /* transparent values for paletted image */
  160754. png_color_16 trans_values; /* transparent color for non-palette image */
  160755. #endif
  160756. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160757. png_color_16 background;
  160758. #endif
  160759. #if defined(PNG_oFFs_SUPPORTED)
  160760. png_int_32 x_offset; /* x offset on page */
  160761. png_int_32 y_offset; /* y offset on page */
  160762. png_byte offset_unit_type; /* offset units type */
  160763. #endif
  160764. #if defined(PNG_pHYs_SUPPORTED)
  160765. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160766. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160767. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160768. #endif
  160769. #if defined(PNG_hIST_SUPPORTED)
  160770. png_uint_16p hist;
  160771. #endif
  160772. #ifdef PNG_cHRM_SUPPORTED
  160773. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160774. float x_white;
  160775. float y_white;
  160776. float x_red;
  160777. float y_red;
  160778. float x_green;
  160779. float y_green;
  160780. float x_blue;
  160781. float y_blue;
  160782. #endif
  160783. #endif
  160784. #if defined(PNG_pCAL_SUPPORTED)
  160785. png_charp pcal_purpose; /* pCAL chunk description string */
  160786. png_int_32 pcal_X0; /* minimum value */
  160787. png_int_32 pcal_X1; /* maximum value */
  160788. png_charp pcal_units; /* Latin-1 string giving physical units */
  160789. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160790. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160791. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160792. #endif
  160793. #ifdef PNG_FREE_ME_SUPPORTED
  160794. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160795. #endif
  160796. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160797. png_unknown_chunkp unknown_chunks;
  160798. png_size_t unknown_chunks_num;
  160799. #endif
  160800. #if defined(PNG_iCCP_SUPPORTED)
  160801. png_charp iccp_name; /* profile name */
  160802. png_charp iccp_profile; /* International Color Consortium profile data */
  160803. png_uint_32 iccp_proflen; /* ICC profile data length */
  160804. png_byte iccp_compression; /* Always zero */
  160805. #endif
  160806. #if defined(PNG_sPLT_SUPPORTED)
  160807. png_sPLT_tp splt_palettes;
  160808. png_uint_32 splt_palettes_num;
  160809. #endif
  160810. #if defined(PNG_sCAL_SUPPORTED)
  160811. png_byte scal_unit; /* unit of physical scale */
  160812. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160813. double scal_pixel_width; /* width of one pixel */
  160814. double scal_pixel_height; /* height of one pixel */
  160815. #endif
  160816. #ifdef PNG_FIXED_POINT_SUPPORTED
  160817. png_charp scal_s_width; /* string containing height */
  160818. png_charp scal_s_height; /* string containing width */
  160819. #endif
  160820. #endif
  160821. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160822. png_bytepp row_pointers; /* the image bits */
  160823. #endif
  160824. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160825. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160826. #endif
  160827. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160828. png_fixed_point int_x_white;
  160829. png_fixed_point int_y_white;
  160830. png_fixed_point int_x_red;
  160831. png_fixed_point int_y_red;
  160832. png_fixed_point int_x_green;
  160833. png_fixed_point int_y_green;
  160834. png_fixed_point int_x_blue;
  160835. png_fixed_point int_y_blue;
  160836. #endif
  160837. } png_info;
  160838. typedef png_info FAR * png_infop;
  160839. typedef png_info FAR * FAR * png_infopp;
  160840. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160841. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160842. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160843. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160844. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160845. #endif
  160846. #define PNG_COLOR_MASK_PALETTE 1
  160847. #define PNG_COLOR_MASK_COLOR 2
  160848. #define PNG_COLOR_MASK_ALPHA 4
  160849. #define PNG_COLOR_TYPE_GRAY 0
  160850. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160851. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160852. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160853. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160854. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160855. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160856. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160857. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160858. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160859. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160860. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160861. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160862. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160863. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160864. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160865. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160866. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160867. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160868. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160869. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160870. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160871. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160872. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160873. #define PNG_SCALE_METER 1 /* meters per pixel */
  160874. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160875. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160876. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160877. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160878. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160879. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160880. #define PNG_sRGB_INTENT_RELATIVE 1
  160881. #define PNG_sRGB_INTENT_SATURATION 2
  160882. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160883. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160884. #define PNG_KEYWORD_MAX_LENGTH 79
  160885. #define PNG_MAX_PALETTE_LENGTH 256
  160886. #define PNG_INFO_gAMA 0x0001
  160887. #define PNG_INFO_sBIT 0x0002
  160888. #define PNG_INFO_cHRM 0x0004
  160889. #define PNG_INFO_PLTE 0x0008
  160890. #define PNG_INFO_tRNS 0x0010
  160891. #define PNG_INFO_bKGD 0x0020
  160892. #define PNG_INFO_hIST 0x0040
  160893. #define PNG_INFO_pHYs 0x0080
  160894. #define PNG_INFO_oFFs 0x0100
  160895. #define PNG_INFO_tIME 0x0200
  160896. #define PNG_INFO_pCAL 0x0400
  160897. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160898. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160899. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160900. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160901. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160902. typedef struct png_row_info_struct
  160903. {
  160904. png_uint_32 width; /* width of row */
  160905. png_uint_32 rowbytes; /* number of bytes in row */
  160906. png_byte color_type; /* color type of row */
  160907. png_byte bit_depth; /* bit depth of row */
  160908. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160909. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160910. } png_row_info;
  160911. typedef png_row_info FAR * png_row_infop;
  160912. typedef png_row_info FAR * FAR * png_row_infopp;
  160913. typedef struct png_struct_def png_struct;
  160914. typedef png_struct FAR * png_structp;
  160915. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160916. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160917. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160918. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160919. int));
  160920. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160921. int));
  160922. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160923. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160924. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160925. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160926. png_uint_32, int));
  160927. #endif
  160928. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160929. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160930. defined(PNG_LEGACY_SUPPORTED)
  160931. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160932. png_row_infop, png_bytep));
  160933. #endif
  160934. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160935. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160936. #endif
  160937. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160938. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160939. #endif
  160940. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160941. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160942. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160943. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160944. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160945. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160946. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160947. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160948. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160949. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160950. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160951. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160952. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160953. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160954. #define PNG_FLAG_MNG_FILTER_64 0x04
  160955. #define PNG_ALL_MNG_FEATURES 0x05
  160956. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160957. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160958. struct png_struct_def
  160959. {
  160960. #ifdef PNG_SETJMP_SUPPORTED
  160961. jmp_buf jmpbuf; /* used in png_error */
  160962. #endif
  160963. png_error_ptr error_fn; /* function for printing errors and aborting */
  160964. png_error_ptr warning_fn; /* function for printing warnings */
  160965. png_voidp error_ptr; /* user supplied struct for error functions */
  160966. png_rw_ptr write_data_fn; /* function for writing output data */
  160967. png_rw_ptr read_data_fn; /* function for reading input data */
  160968. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160969. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160970. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160971. #endif
  160972. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160973. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160974. #endif
  160975. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160976. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160977. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160978. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160979. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160980. png_byte user_transform_channels; /* channels in user transformed pixels */
  160981. #endif
  160982. #endif
  160983. png_uint_32 mode; /* tells us where we are in the PNG file */
  160984. png_uint_32 flags; /* flags indicating various things to libpng */
  160985. png_uint_32 transformations; /* which transformations to perform */
  160986. z_stream zstream; /* pointer to decompression structure (below) */
  160987. png_bytep zbuf; /* buffer for zlib */
  160988. png_size_t zbuf_size; /* size of zbuf */
  160989. int zlib_level; /* holds zlib compression level */
  160990. int zlib_method; /* holds zlib compression method */
  160991. int zlib_window_bits; /* holds zlib compression window bits */
  160992. int zlib_mem_level; /* holds zlib compression memory level */
  160993. int zlib_strategy; /* holds zlib compression strategy */
  160994. png_uint_32 width; /* width of image in pixels */
  160995. png_uint_32 height; /* height of image in pixels */
  160996. png_uint_32 num_rows; /* number of rows in current pass */
  160997. png_uint_32 usr_width; /* width of row at start of write */
  160998. png_uint_32 rowbytes; /* size of row in bytes */
  160999. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  161000. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  161001. png_uint_32 row_number; /* current row in interlace pass */
  161002. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  161003. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  161004. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  161005. png_bytep up_row; /* buffer to save "up" row when filtering */
  161006. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  161007. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  161008. png_row_info row_info; /* used for transformation routines */
  161009. png_uint_32 idat_size; /* current IDAT size for read */
  161010. png_uint_32 crc; /* current chunk CRC value */
  161011. png_colorp palette; /* palette from the input file */
  161012. png_uint_16 num_palette; /* number of color entries in palette */
  161013. png_uint_16 num_trans; /* number of transparency values */
  161014. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  161015. png_byte compression; /* file compression type (always 0) */
  161016. png_byte filter; /* file filter type (always 0) */
  161017. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  161018. png_byte pass; /* current interlace pass (0 - 6) */
  161019. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  161020. png_byte color_type; /* color type of file */
  161021. png_byte bit_depth; /* bit depth of file */
  161022. png_byte usr_bit_depth; /* bit depth of users row */
  161023. png_byte pixel_depth; /* number of bits per pixel */
  161024. png_byte channels; /* number of channels in file */
  161025. png_byte usr_channels; /* channels at start of write */
  161026. png_byte sig_bytes; /* magic bytes read/written from start of file */
  161027. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161028. #ifdef PNG_LEGACY_SUPPORTED
  161029. png_byte filler; /* filler byte for pixel expansion */
  161030. #else
  161031. png_uint_16 filler; /* filler bytes for pixel expansion */
  161032. #endif
  161033. #endif
  161034. #if defined(PNG_bKGD_SUPPORTED)
  161035. png_byte background_gamma_type;
  161036. # ifdef PNG_FLOATING_POINT_SUPPORTED
  161037. float background_gamma;
  161038. # endif
  161039. png_color_16 background; /* background color in screen gamma space */
  161040. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161041. png_color_16 background_1; /* background normalized to gamma 1.0 */
  161042. #endif
  161043. #endif /* PNG_bKGD_SUPPORTED */
  161044. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161045. png_flush_ptr output_flush_fn;/* Function for flushing output */
  161046. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  161047. png_uint_32 flush_rows; /* number of rows written since last flush */
  161048. #endif
  161049. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161050. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  161051. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161052. float gamma; /* file gamma value */
  161053. float screen_gamma; /* screen gamma value (display_exponent) */
  161054. #endif
  161055. #endif
  161056. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161057. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  161058. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  161059. png_bytep gamma_to_1; /* converts from file to 1.0 */
  161060. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  161061. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  161062. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  161063. #endif
  161064. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  161065. png_color_8 sig_bit; /* significant bits in each available channel */
  161066. #endif
  161067. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161068. png_color_8 shift; /* shift for significant bit tranformation */
  161069. #endif
  161070. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  161071. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161072. png_bytep trans; /* transparency values for paletted files */
  161073. png_color_16 trans_values; /* transparency values for non-paletted files */
  161074. #endif
  161075. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  161076. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  161077. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161078. png_progressive_info_ptr info_fn; /* called after header data fully read */
  161079. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  161080. png_progressive_end_ptr end_fn; /* called after image is complete */
  161081. png_bytep save_buffer_ptr; /* current location in save_buffer */
  161082. png_bytep save_buffer; /* buffer for previously read data */
  161083. png_bytep current_buffer_ptr; /* current location in current_buffer */
  161084. png_bytep current_buffer; /* buffer for recently used data */
  161085. png_uint_32 push_length; /* size of current input chunk */
  161086. png_uint_32 skip_length; /* bytes to skip in input data */
  161087. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  161088. png_size_t save_buffer_max; /* total size of save_buffer */
  161089. png_size_t buffer_size; /* total amount of available input data */
  161090. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  161091. int process_mode; /* what push library is currently doing */
  161092. int cur_palette; /* current push library palette index */
  161093. # if defined(PNG_TEXT_SUPPORTED)
  161094. png_size_t current_text_size; /* current size of text input data */
  161095. png_size_t current_text_left; /* how much text left to read in input */
  161096. png_charp current_text; /* current text chunk buffer */
  161097. png_charp current_text_ptr; /* current location in current_text */
  161098. # endif /* PNG_TEXT_SUPPORTED */
  161099. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161100. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161101. png_bytepp offset_table_ptr;
  161102. png_bytep offset_table;
  161103. png_uint_16 offset_table_number;
  161104. png_uint_16 offset_table_count;
  161105. png_uint_16 offset_table_count_free;
  161106. #endif
  161107. #if defined(PNG_READ_DITHER_SUPPORTED)
  161108. png_bytep palette_lookup; /* lookup table for dithering */
  161109. png_bytep dither_index; /* index translation for palette files */
  161110. #endif
  161111. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161112. png_uint_16p hist; /* histogram */
  161113. #endif
  161114. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161115. png_byte heuristic_method; /* heuristic for row filter selection */
  161116. png_byte num_prev_filters; /* number of weights for previous rows */
  161117. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161118. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161119. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161120. png_uint_16p filter_costs; /* relative filter calculation cost */
  161121. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161122. #endif
  161123. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161124. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161125. #endif
  161126. #ifdef PNG_FREE_ME_SUPPORTED
  161127. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161128. #endif
  161129. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161130. png_voidp user_chunk_ptr;
  161131. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161132. #endif
  161133. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161134. int num_chunk_list;
  161135. png_bytep chunk_list;
  161136. #endif
  161137. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161138. png_byte rgb_to_gray_status;
  161139. png_uint_16 rgb_to_gray_red_coeff;
  161140. png_uint_16 rgb_to_gray_green_coeff;
  161141. png_uint_16 rgb_to_gray_blue_coeff;
  161142. #endif
  161143. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161144. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161145. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161146. #ifdef PNG_1_0_X
  161147. png_byte mng_features_permitted;
  161148. #else
  161149. png_uint_32 mng_features_permitted;
  161150. #endif /* PNG_1_0_X */
  161151. #endif
  161152. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161153. png_fixed_point int_gamma;
  161154. #endif
  161155. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161156. png_byte filter_type;
  161157. #endif
  161158. #if defined(PNG_1_0_X)
  161159. png_uint_32 row_buf_size;
  161160. #endif
  161161. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161162. # if !defined(PNG_1_0_X)
  161163. # if defined(PNG_MMX_CODE_SUPPORTED)
  161164. png_byte mmx_bitdepth_threshold;
  161165. png_uint_32 mmx_rowbytes_threshold;
  161166. # endif
  161167. png_uint_32 asm_flags;
  161168. # endif
  161169. #endif
  161170. #ifdef PNG_USER_MEM_SUPPORTED
  161171. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161172. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161173. png_free_ptr free_fn; /* function for freeing memory */
  161174. #endif
  161175. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161176. #if defined(PNG_READ_DITHER_SUPPORTED)
  161177. png_bytep dither_sort; /* working sort array */
  161178. png_bytep index_to_palette; /* where the original index currently is */
  161179. png_bytep palette_to_index; /* which original index points to this */
  161180. #endif
  161181. png_byte compression_type;
  161182. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161183. png_uint_32 user_width_max;
  161184. png_uint_32 user_height_max;
  161185. #endif
  161186. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161187. png_unknown_chunk unknown_chunk;
  161188. #endif
  161189. };
  161190. typedef png_structp version_1_2_21;
  161191. typedef png_struct FAR * FAR * png_structpp;
  161192. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161193. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161194. int num_bytes));
  161195. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161196. png_size_t num_to_check));
  161197. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161198. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161199. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161200. png_error_ptr error_fn, png_error_ptr warn_fn));
  161201. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161202. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161203. png_error_ptr error_fn, png_error_ptr warn_fn));
  161204. #ifdef PNG_WRITE_SUPPORTED
  161205. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161206. PNGARG((png_structp png_ptr));
  161207. #endif
  161208. #ifdef PNG_WRITE_SUPPORTED
  161209. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161210. PNGARG((png_structp png_ptr, png_uint_32 size));
  161211. #endif
  161212. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161213. #ifdef PNG_USER_MEM_SUPPORTED
  161214. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161215. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161216. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161217. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161218. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161219. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161220. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161221. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161222. #endif
  161223. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161224. png_bytep chunk_name, png_bytep data, png_size_t length));
  161225. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161226. png_bytep chunk_name, png_uint_32 length));
  161227. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161228. png_bytep data, png_size_t length));
  161229. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161230. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161231. PNGARG((png_structp png_ptr));
  161232. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161233. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161234. #undef png_info_init
  161235. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161236. png_sizeof(png_info));
  161237. #endif
  161238. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161239. png_size_t png_info_struct_size));
  161240. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161241. png_infop info_ptr));
  161242. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161243. png_infop info_ptr));
  161244. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161245. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161246. png_infop info_ptr));
  161247. #endif
  161248. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161249. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161250. PNGARG((png_structp png_ptr, png_timep ptime));
  161251. #endif
  161252. #if !defined(_WIN32_WCE)
  161253. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161254. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161255. struct tm FAR * ttime));
  161256. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161257. time_t ttime));
  161258. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161259. #endif /* _WIN32_WCE */
  161260. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161261. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161262. #if !defined(PNG_1_0_X)
  161263. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161264. png_ptr));
  161265. #endif
  161266. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161267. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161268. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161269. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161270. #endif
  161271. #endif
  161272. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161273. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161274. #endif
  161275. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161276. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161277. #endif
  161278. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161279. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161280. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161281. int error_action, double red, double green ));
  161282. #endif
  161283. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161284. int error_action, png_fixed_point red, png_fixed_point green ));
  161285. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161286. png_ptr));
  161287. #endif
  161288. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161289. png_colorp palette));
  161290. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161291. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161292. #endif
  161293. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161294. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161295. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161296. #endif
  161297. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161298. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161299. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161300. #endif
  161301. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161302. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161303. png_uint_32 filler, int flags));
  161304. #define PNG_FILLER_BEFORE 0
  161305. #define PNG_FILLER_AFTER 1
  161306. #if !defined(PNG_1_0_X)
  161307. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161308. png_uint_32 filler, int flags));
  161309. #endif
  161310. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161311. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161312. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161313. #endif
  161314. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161315. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161316. #endif
  161317. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161318. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161319. #endif
  161320. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161321. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161322. png_color_8p true_bits));
  161323. #endif
  161324. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161325. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161326. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161327. #endif
  161328. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161329. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161330. #endif
  161331. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161332. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161333. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161334. png_color_16p background_color, int background_gamma_code,
  161335. int need_expand, double background_gamma));
  161336. #endif
  161337. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161338. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161339. #define PNG_BACKGROUND_GAMMA_FILE 2
  161340. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161341. #endif
  161342. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161343. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161344. #endif
  161345. #if defined(PNG_READ_DITHER_SUPPORTED)
  161346. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161347. png_colorp palette, int num_palette, int maximum_colors,
  161348. png_uint_16p histogram, int full_dither));
  161349. #endif
  161350. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161351. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161352. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161353. double screen_gamma, double default_file_gamma));
  161354. #endif
  161355. #endif
  161356. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161357. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161358. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161359. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161360. int empty_plte_permitted));
  161361. #endif
  161362. #endif
  161363. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161364. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161365. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161366. #endif
  161367. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161368. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161369. png_infop info_ptr));
  161370. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161371. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161372. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161373. #endif
  161374. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161375. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161376. png_bytep row,
  161377. png_bytep display_row));
  161378. #endif
  161379. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161380. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161381. png_bytepp image));
  161382. #endif
  161383. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161384. png_bytep row));
  161385. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161386. png_bytepp row, png_uint_32 num_rows));
  161387. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161388. png_bytepp image));
  161389. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161390. png_infop info_ptr));
  161391. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161392. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161393. png_infop info_ptr));
  161394. #endif
  161395. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161396. png_infopp info_ptr_ptr));
  161397. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161398. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161399. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161400. png_infop end_info_ptr));
  161401. extern PNG_EXPORT(void,png_destroy_write_struct)
  161402. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161403. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161404. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161405. int crit_action, int ancil_action));
  161406. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161407. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161408. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161409. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161410. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161411. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161412. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161413. int filters));
  161414. #define PNG_NO_FILTERS 0x00
  161415. #define PNG_FILTER_NONE 0x08
  161416. #define PNG_FILTER_SUB 0x10
  161417. #define PNG_FILTER_UP 0x20
  161418. #define PNG_FILTER_AVG 0x40
  161419. #define PNG_FILTER_PAETH 0x80
  161420. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161421. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161422. #define PNG_FILTER_VALUE_NONE 0
  161423. #define PNG_FILTER_VALUE_SUB 1
  161424. #define PNG_FILTER_VALUE_UP 2
  161425. #define PNG_FILTER_VALUE_AVG 3
  161426. #define PNG_FILTER_VALUE_PAETH 4
  161427. #define PNG_FILTER_VALUE_LAST 5
  161428. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161429. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161430. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161431. int heuristic_method, int num_weights, png_doublep filter_weights,
  161432. png_doublep filter_costs));
  161433. #endif
  161434. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161435. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161436. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161437. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161438. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161439. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161440. int level));
  161441. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161442. PNGARG((png_structp png_ptr, int mem_level));
  161443. extern PNG_EXPORT(void,png_set_compression_strategy)
  161444. PNGARG((png_structp png_ptr, int strategy));
  161445. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161446. PNGARG((png_structp png_ptr, int window_bits));
  161447. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161448. int method));
  161449. #if !defined(PNG_NO_STDIO)
  161450. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161451. #endif
  161452. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161453. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161454. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161455. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161456. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161457. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161458. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161459. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161460. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161461. png_read_status_ptr read_row_fn));
  161462. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161463. png_write_status_ptr write_row_fn));
  161464. #ifdef PNG_USER_MEM_SUPPORTED
  161465. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161466. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161467. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161468. #endif
  161469. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161470. defined(PNG_LEGACY_SUPPORTED)
  161471. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161472. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161473. #endif
  161474. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161475. defined(PNG_LEGACY_SUPPORTED)
  161476. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161477. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161478. #endif
  161479. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161480. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161481. defined(PNG_LEGACY_SUPPORTED)
  161482. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161483. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161484. int user_transform_channels));
  161485. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161486. PNGARG((png_structp png_ptr));
  161487. #endif
  161488. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161489. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161490. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161491. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161492. png_ptr));
  161493. #endif
  161494. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161495. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161496. png_voidp progressive_ptr,
  161497. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161498. png_progressive_end_ptr end_fn));
  161499. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161500. PNGARG((png_structp png_ptr));
  161501. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161502. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161503. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161504. png_bytep old_row, png_bytep new_row));
  161505. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161506. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161507. png_uint_32 size));
  161508. #if defined(PNG_1_0_X)
  161509. # define png_malloc_warn png_malloc
  161510. #else
  161511. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161512. png_uint_32 size));
  161513. #endif
  161514. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161515. #if defined(PNG_1_0_X)
  161516. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161517. uInt size));
  161518. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161519. #endif
  161520. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161521. png_infop info_ptr, png_uint_32 free_me, int num));
  161522. #ifdef PNG_FREE_ME_SUPPORTED
  161523. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161524. png_infop info_ptr, int freer, png_uint_32 mask));
  161525. #endif
  161526. #define PNG_DESTROY_WILL_FREE_DATA 1
  161527. #define PNG_SET_WILL_FREE_DATA 1
  161528. #define PNG_USER_WILL_FREE_DATA 2
  161529. #define PNG_FREE_HIST 0x0008
  161530. #define PNG_FREE_ICCP 0x0010
  161531. #define PNG_FREE_SPLT 0x0020
  161532. #define PNG_FREE_ROWS 0x0040
  161533. #define PNG_FREE_PCAL 0x0080
  161534. #define PNG_FREE_SCAL 0x0100
  161535. #define PNG_FREE_UNKN 0x0200
  161536. #define PNG_FREE_LIST 0x0400
  161537. #define PNG_FREE_PLTE 0x1000
  161538. #define PNG_FREE_TRNS 0x2000
  161539. #define PNG_FREE_TEXT 0x4000
  161540. #define PNG_FREE_ALL 0x7fff
  161541. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161542. #ifdef PNG_USER_MEM_SUPPORTED
  161543. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161544. png_uint_32 size));
  161545. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161546. png_voidp ptr));
  161547. #endif
  161548. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161549. png_voidp s1, png_voidp s2, png_uint_32 size));
  161550. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161551. png_voidp s1, int value, png_uint_32 size));
  161552. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161553. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161554. int check));
  161555. #endif /* USE_FAR_KEYWORD */
  161556. #ifndef PNG_NO_ERROR_TEXT
  161557. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161558. png_const_charp error_message));
  161559. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161560. png_const_charp error_message));
  161561. #else
  161562. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161563. #endif
  161564. #ifndef PNG_NO_WARNINGS
  161565. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161566. png_const_charp warning_message));
  161567. #ifdef PNG_READ_SUPPORTED
  161568. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161569. png_const_charp warning_message));
  161570. #endif /* PNG_READ_SUPPORTED */
  161571. #endif /* PNG_NO_WARNINGS */
  161572. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161573. png_infop info_ptr, png_uint_32 flag));
  161574. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161575. png_infop info_ptr));
  161576. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161577. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161578. png_infop info_ptr));
  161579. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161580. png_infop info_ptr, png_bytepp row_pointers));
  161581. #endif
  161582. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161583. png_infop info_ptr));
  161584. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161585. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161586. png_ptr, png_infop info_ptr));
  161587. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161588. png_ptr, png_infop info_ptr));
  161589. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161590. png_ptr, png_infop info_ptr));
  161591. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161592. png_ptr, png_infop info_ptr));
  161593. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161594. png_ptr, png_infop info_ptr));
  161595. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161596. png_ptr, png_infop info_ptr));
  161597. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161598. png_ptr, png_infop info_ptr));
  161599. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161600. png_ptr, png_infop info_ptr));
  161601. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161602. png_ptr, png_infop info_ptr));
  161603. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161604. png_ptr, png_infop info_ptr));
  161605. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161606. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161607. png_ptr, png_infop info_ptr));
  161608. #endif
  161609. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161610. png_ptr, png_infop info_ptr));
  161611. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161612. png_ptr, png_infop info_ptr));
  161613. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161614. png_ptr, png_infop info_ptr));
  161615. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161616. png_ptr, png_infop info_ptr));
  161617. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161618. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161619. png_infop info_ptr));
  161620. #if defined(PNG_bKGD_SUPPORTED)
  161621. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161622. png_infop info_ptr, png_color_16p *background));
  161623. #endif
  161624. #if defined(PNG_bKGD_SUPPORTED)
  161625. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161626. png_infop info_ptr, png_color_16p background));
  161627. #endif
  161628. #if defined(PNG_cHRM_SUPPORTED)
  161629. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161630. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161631. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161632. double *red_y, double *green_x, double *green_y, double *blue_x,
  161633. double *blue_y));
  161634. #endif
  161635. #ifdef PNG_FIXED_POINT_SUPPORTED
  161636. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161637. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161638. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161639. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161640. *int_blue_x, png_fixed_point *int_blue_y));
  161641. #endif
  161642. #endif
  161643. #if defined(PNG_cHRM_SUPPORTED)
  161644. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161645. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161646. png_infop info_ptr, double white_x, double white_y, double red_x,
  161647. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161648. #endif
  161649. #ifdef PNG_FIXED_POINT_SUPPORTED
  161650. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161651. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161652. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161653. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161654. png_fixed_point int_blue_y));
  161655. #endif
  161656. #endif
  161657. #if defined(PNG_gAMA_SUPPORTED)
  161658. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161659. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161660. png_infop info_ptr, double *file_gamma));
  161661. #endif
  161662. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161663. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161664. #endif
  161665. #if defined(PNG_gAMA_SUPPORTED)
  161666. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161667. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161668. png_infop info_ptr, double file_gamma));
  161669. #endif
  161670. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161671. png_infop info_ptr, png_fixed_point int_file_gamma));
  161672. #endif
  161673. #if defined(PNG_hIST_SUPPORTED)
  161674. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161675. png_infop info_ptr, png_uint_16p *hist));
  161676. #endif
  161677. #if defined(PNG_hIST_SUPPORTED)
  161678. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161679. png_infop info_ptr, png_uint_16p hist));
  161680. #endif
  161681. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161682. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161683. int *bit_depth, int *color_type, int *interlace_method,
  161684. int *compression_method, int *filter_method));
  161685. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161686. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161687. int color_type, int interlace_method, int compression_method,
  161688. int filter_method));
  161689. #if defined(PNG_oFFs_SUPPORTED)
  161690. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161691. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161692. int *unit_type));
  161693. #endif
  161694. #if defined(PNG_oFFs_SUPPORTED)
  161695. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161696. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161697. int unit_type));
  161698. #endif
  161699. #if defined(PNG_pCAL_SUPPORTED)
  161700. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161701. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161702. int *type, int *nparams, png_charp *units, png_charpp *params));
  161703. #endif
  161704. #if defined(PNG_pCAL_SUPPORTED)
  161705. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161706. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161707. int type, int nparams, png_charp units, png_charpp params));
  161708. #endif
  161709. #if defined(PNG_pHYs_SUPPORTED)
  161710. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161711. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161712. #endif
  161713. #if defined(PNG_pHYs_SUPPORTED)
  161714. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161715. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161716. #endif
  161717. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161718. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161719. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161720. png_infop info_ptr, png_colorp palette, int num_palette));
  161721. #if defined(PNG_sBIT_SUPPORTED)
  161722. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161723. png_infop info_ptr, png_color_8p *sig_bit));
  161724. #endif
  161725. #if defined(PNG_sBIT_SUPPORTED)
  161726. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161727. png_infop info_ptr, png_color_8p sig_bit));
  161728. #endif
  161729. #if defined(PNG_sRGB_SUPPORTED)
  161730. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161731. png_infop info_ptr, int *intent));
  161732. #endif
  161733. #if defined(PNG_sRGB_SUPPORTED)
  161734. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161735. png_infop info_ptr, int intent));
  161736. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161737. png_infop info_ptr, int intent));
  161738. #endif
  161739. #if defined(PNG_iCCP_SUPPORTED)
  161740. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161741. png_infop info_ptr, png_charpp name, int *compression_type,
  161742. png_charpp profile, png_uint_32 *proflen));
  161743. #endif
  161744. #if defined(PNG_iCCP_SUPPORTED)
  161745. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161746. png_infop info_ptr, png_charp name, int compression_type,
  161747. png_charp profile, png_uint_32 proflen));
  161748. #endif
  161749. #if defined(PNG_sPLT_SUPPORTED)
  161750. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161751. png_infop info_ptr, png_sPLT_tpp entries));
  161752. #endif
  161753. #if defined(PNG_sPLT_SUPPORTED)
  161754. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161755. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161756. #endif
  161757. #if defined(PNG_TEXT_SUPPORTED)
  161758. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161759. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161760. #endif
  161761. #if defined(PNG_TEXT_SUPPORTED)
  161762. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161763. png_infop info_ptr, png_textp text_ptr, int num_text));
  161764. #endif
  161765. #if defined(PNG_tIME_SUPPORTED)
  161766. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161767. png_infop info_ptr, png_timep *mod_time));
  161768. #endif
  161769. #if defined(PNG_tIME_SUPPORTED)
  161770. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161771. png_infop info_ptr, png_timep mod_time));
  161772. #endif
  161773. #if defined(PNG_tRNS_SUPPORTED)
  161774. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161775. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161776. png_color_16p *trans_values));
  161777. #endif
  161778. #if defined(PNG_tRNS_SUPPORTED)
  161779. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161780. png_infop info_ptr, png_bytep trans, int num_trans,
  161781. png_color_16p trans_values));
  161782. #endif
  161783. #if defined(PNG_tRNS_SUPPORTED)
  161784. #endif
  161785. #if defined(PNG_sCAL_SUPPORTED)
  161786. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161787. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161788. png_infop info_ptr, int *unit, double *width, double *height));
  161789. #else
  161790. #ifdef PNG_FIXED_POINT_SUPPORTED
  161791. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161792. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161793. #endif
  161794. #endif
  161795. #endif /* PNG_sCAL_SUPPORTED */
  161796. #if defined(PNG_sCAL_SUPPORTED)
  161797. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161798. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161799. png_infop info_ptr, int unit, double width, double height));
  161800. #else
  161801. #ifdef PNG_FIXED_POINT_SUPPORTED
  161802. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161803. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161804. #endif
  161805. #endif
  161806. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161807. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161808. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161809. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161810. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161811. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161812. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161813. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161814. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161815. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161816. #endif
  161817. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161818. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161819. chunk_name));
  161820. #endif
  161821. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161822. png_infop info_ptr, int mask));
  161823. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161824. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161825. png_infop info_ptr,
  161826. int transforms,
  161827. png_voidp params));
  161828. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161829. png_infop info_ptr,
  161830. int transforms,
  161831. png_voidp params));
  161832. #endif
  161833. #ifdef PNG_DEBUG
  161834. #if (PNG_DEBUG > 0)
  161835. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161836. #include <crtdbg.h>
  161837. #if (PNG_DEBUG > 1)
  161838. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161839. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161840. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161841. #endif
  161842. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161843. #ifndef PNG_DEBUG_FILE
  161844. #define PNG_DEBUG_FILE stderr
  161845. #endif /* PNG_DEBUG_FILE */
  161846. #if (PNG_DEBUG > 1)
  161847. #define png_debug(l,m) \
  161848. { \
  161849. int num_tabs=l; \
  161850. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161851. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161852. }
  161853. #define png_debug1(l,m,p1) \
  161854. { \
  161855. int num_tabs=l; \
  161856. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161857. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161858. }
  161859. #define png_debug2(l,m,p1,p2) \
  161860. { \
  161861. int num_tabs=l; \
  161862. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161863. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161864. }
  161865. #endif /* (PNG_DEBUG > 1) */
  161866. #endif /* _MSC_VER */
  161867. #endif /* (PNG_DEBUG > 0) */
  161868. #endif /* PNG_DEBUG */
  161869. #ifndef png_debug
  161870. #define png_debug(l, m)
  161871. #endif
  161872. #ifndef png_debug1
  161873. #define png_debug1(l, m, p1)
  161874. #endif
  161875. #ifndef png_debug2
  161876. #define png_debug2(l, m, p1, p2)
  161877. #endif
  161878. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161879. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161880. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161881. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161882. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161883. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161884. png_ptr, png_uint_32 mng_features_permitted));
  161885. #endif
  161886. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161887. #define PNG_HANDLE_CHUNK_NEVER 1
  161888. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161889. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161890. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161891. #if defined(PNG_MMX_CODE_SUPPORTED)
  161892. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161893. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161894. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161895. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161896. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161897. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161898. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161899. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161900. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161901. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161902. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161903. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161904. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161905. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161906. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161907. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161908. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161909. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161910. | PNG_MMX_READ_FLAGS \
  161911. | PNG_MMX_WRITE_FLAGS )
  161912. #define PNG_SELECT_READ 1
  161913. #define PNG_SELECT_WRITE 2
  161914. #endif /* PNG_MMX_CODE_SUPPORTED */
  161915. #if !defined(PNG_1_0_X)
  161916. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161917. PNGARG((int flag_select, int *compilerID));
  161918. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161919. PNGARG((int flag_select));
  161920. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161921. PNGARG((png_structp png_ptr));
  161922. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161923. PNGARG((png_structp png_ptr));
  161924. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161925. PNGARG((png_structp png_ptr));
  161926. extern PNG_EXPORT(void,png_set_asm_flags)
  161927. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161928. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161929. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161930. png_uint_32 mmx_rowbytes_threshold));
  161931. #endif /* PNG_1_0_X */
  161932. #if !defined(PNG_1_0_X)
  161933. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161934. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161935. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161936. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161937. png_ptr, png_uint_32 strip_mode));
  161938. #endif
  161939. #endif /* PNG_1_0_X */
  161940. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161941. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161942. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161943. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161944. png_ptr));
  161945. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161946. png_ptr));
  161947. #endif
  161948. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161949. # define png_composite(composite, fg, alpha, bg) \
  161950. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161951. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161952. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161953. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161954. # define png_composite_16(composite, fg, alpha, bg) \
  161955. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161956. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161957. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161958. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161959. #else /* standard method using integer division */
  161960. # define png_composite(composite, fg, alpha, bg) \
  161961. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161962. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161963. (png_uint_16)127) / 255)
  161964. # define png_composite_16(composite, fg, alpha, bg) \
  161965. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161966. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161967. (png_uint_32)32767) / (png_uint_32)65535L)
  161968. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161969. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161970. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161971. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161972. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161973. #else
  161974. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161975. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161976. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161977. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161978. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161979. PNGARG((png_structp png_ptr, png_bytep buf));
  161980. extern PNG_EXPORT(void,png_save_uint_32)
  161981. PNGARG((png_bytep buf, png_uint_32 i));
  161982. extern PNG_EXPORT(void,png_save_int_32)
  161983. PNGARG((png_bytep buf, png_int_32 i));
  161984. extern PNG_EXPORT(void,png_save_uint_16)
  161985. PNGARG((png_bytep buf, unsigned int i));
  161986. #define PNG_HAVE_IHDR 0x01
  161987. #define PNG_HAVE_PLTE 0x02
  161988. #define PNG_HAVE_IDAT 0x04
  161989. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161990. #define PNG_HAVE_IEND 0x10
  161991. #if defined(PNG_INTERNAL)
  161992. #define PNG_HAVE_gAMA 0x20
  161993. #define PNG_HAVE_cHRM 0x40
  161994. #define PNG_HAVE_sRGB 0x80
  161995. #define PNG_HAVE_CHUNK_HEADER 0x100
  161996. #define PNG_WROTE_tIME 0x200
  161997. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161998. #define PNG_BACKGROUND_IS_GRAY 0x800
  161999. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  162000. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  162001. #define PNG_BGR 0x0001
  162002. #define PNG_INTERLACE 0x0002
  162003. #define PNG_PACK 0x0004
  162004. #define PNG_SHIFT 0x0008
  162005. #define PNG_SWAP_BYTES 0x0010
  162006. #define PNG_INVERT_MONO 0x0020
  162007. #define PNG_DITHER 0x0040
  162008. #define PNG_BACKGROUND 0x0080
  162009. #define PNG_BACKGROUND_EXPAND 0x0100
  162010. #define PNG_16_TO_8 0x0400
  162011. #define PNG_RGBA 0x0800
  162012. #define PNG_EXPAND 0x1000
  162013. #define PNG_GAMMA 0x2000
  162014. #define PNG_GRAY_TO_RGB 0x4000
  162015. #define PNG_FILLER 0x8000L
  162016. #define PNG_PACKSWAP 0x10000L
  162017. #define PNG_SWAP_ALPHA 0x20000L
  162018. #define PNG_STRIP_ALPHA 0x40000L
  162019. #define PNG_INVERT_ALPHA 0x80000L
  162020. #define PNG_USER_TRANSFORM 0x100000L
  162021. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  162022. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  162023. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  162024. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  162025. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  162026. #define PNG_STRUCT_PNG 0x0001
  162027. #define PNG_STRUCT_INFO 0x0002
  162028. #define PNG_WEIGHT_SHIFT 8
  162029. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  162030. #define PNG_COST_SHIFT 3
  162031. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  162032. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  162033. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  162034. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  162035. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  162036. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  162037. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  162038. #define PNG_FLAG_ROW_INIT 0x0040
  162039. #define PNG_FLAG_FILLER_AFTER 0x0080
  162040. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  162041. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  162042. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  162043. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  162044. #define PNG_FLAG_FREE_PLTE 0x1000
  162045. #define PNG_FLAG_FREE_TRNS 0x2000
  162046. #define PNG_FLAG_FREE_HIST 0x4000
  162047. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  162048. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  162049. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  162050. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  162051. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  162052. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  162053. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  162054. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  162055. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  162056. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  162057. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  162058. PNG_FLAG_CRC_CRITICAL_IGNORE)
  162059. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  162060. PNG_FLAG_CRC_CRITICAL_MASK)
  162061. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  162062. abs((int)((c1).green) - (int)((c2).green)) + \
  162063. abs((int)((c1).blue) - (int)((c2).blue)))
  162064. #define PNG_ROWBYTES(pixel_bits, width) \
  162065. ((pixel_bits) >= 8 ? \
  162066. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  162067. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  162068. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  162069. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  162070. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  162071. #ifdef PNG_USE_GLOBAL_ARRAYS
  162072. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  162073. #else
  162074. #endif
  162075. #endif /* PNG_NO_EXTERN */
  162076. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  162077. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  162078. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  162079. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  162080. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  162081. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  162082. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  162083. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  162084. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  162085. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  162086. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  162087. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  162088. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  162089. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  162090. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  162091. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  162092. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  162093. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  162094. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  162095. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  162096. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162097. #ifdef PNG_USE_GLOBAL_ARRAYS
  162098. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162099. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162100. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162101. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162102. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162103. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162104. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162105. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162106. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162107. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162108. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162109. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162110. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162111. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162112. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162113. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162114. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162115. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162116. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162117. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162118. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162119. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162120. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162121. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162122. #undef png_read_init
  162123. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162124. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162125. #endif
  162126. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162127. png_const_charp user_png_ver, png_size_t png_struct_size));
  162128. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162129. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162130. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162131. png_info_size));
  162132. #endif
  162133. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162134. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162135. #undef png_write_init
  162136. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162137. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162138. #endif
  162139. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162140. png_const_charp user_png_ver, png_size_t png_struct_size));
  162141. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162142. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162143. png_info_size));
  162144. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162145. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162146. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162147. malloc_fn, png_voidp mem_ptr));
  162148. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162149. png_free_ptr free_fn, png_voidp mem_ptr));
  162150. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162151. png_infop info_ptr));
  162152. #ifndef PNG_1_0_X
  162153. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162154. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162155. #ifdef PNG_SIZE_T
  162156. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162157. #endif
  162158. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162159. png_bytep data, png_size_t length));
  162160. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162161. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162162. png_bytep buffer, png_size_t length));
  162163. #endif
  162164. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162165. png_bytep data, png_size_t length));
  162166. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162167. #if !defined(PNG_NO_STDIO)
  162168. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162169. #endif
  162170. #endif
  162171. #else /* PNG_1_0_X */
  162172. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162173. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162174. png_bytep buffer, png_size_t length));
  162175. #endif
  162176. #endif /* PNG_1_0_X */
  162177. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162178. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162179. png_size_t length));
  162180. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162181. png_size_t length));
  162182. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162183. png_size_t length));
  162184. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162185. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162186. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162187. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162188. png_size_t prefix_length, png_size_t *data_length));
  162189. #endif
  162190. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162191. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162192. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162193. png_size_t length));
  162194. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162195. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162196. #endif
  162197. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162198. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162199. png_uint_32 height,
  162200. int bit_depth, int color_type, int compression_method, int filter_method,
  162201. int interlace_method));
  162202. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162203. png_uint_32 num_pal));
  162204. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162205. png_size_t length));
  162206. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162207. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162208. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162209. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162210. #endif
  162211. #ifdef PNG_FIXED_POINT_SUPPORTED
  162212. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162213. file_gamma));
  162214. #endif
  162215. #endif
  162216. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162217. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162218. int color_type));
  162219. #endif
  162220. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162221. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162222. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162223. double white_x, double white_y,
  162224. double red_x, double red_y, double green_x, double green_y,
  162225. double blue_x, double blue_y));
  162226. #endif
  162227. #ifdef PNG_FIXED_POINT_SUPPORTED
  162228. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162229. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162230. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162231. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162232. png_fixed_point int_blue_y));
  162233. #endif
  162234. #endif
  162235. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162236. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162237. int intent));
  162238. #endif
  162239. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162240. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162241. png_charp name, int compression_type,
  162242. png_charp profile, int proflen));
  162243. #endif
  162244. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162245. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162246. png_sPLT_tp palette));
  162247. #endif
  162248. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162249. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162250. png_color_16p values, int number, int color_type));
  162251. #endif
  162252. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162253. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162254. png_color_16p values, int color_type));
  162255. #endif
  162256. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162257. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162258. int num_hist));
  162259. #endif
  162260. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162261. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162262. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162263. png_charp key, png_charpp new_key));
  162264. #endif
  162265. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162266. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162267. png_charp text, png_size_t text_len));
  162268. #endif
  162269. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162270. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162271. png_charp text, png_size_t text_len, int compression));
  162272. #endif
  162273. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162274. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162275. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162276. png_charp text));
  162277. #endif
  162278. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162279. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162280. png_infop info_ptr, png_textp text_ptr, int num_text));
  162281. #endif
  162282. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162283. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162284. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162285. #endif
  162286. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162287. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162288. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162289. png_charp units, png_charpp params));
  162290. #endif
  162291. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162292. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162293. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162294. int unit_type));
  162295. #endif
  162296. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162297. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162298. png_timep mod_time));
  162299. #endif
  162300. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162301. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162302. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162303. int unit, double width, double height));
  162304. #else
  162305. #ifdef PNG_FIXED_POINT_SUPPORTED
  162306. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162307. int unit, png_charp width, png_charp height));
  162308. #endif
  162309. #endif
  162310. #endif
  162311. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162312. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162313. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162314. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162315. #endif
  162316. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162317. int mask));
  162318. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162319. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162320. #endif
  162321. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162322. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162323. png_bytep row, int pass));
  162324. #endif
  162325. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162326. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162327. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162328. png_row_infop row_info));
  162329. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162330. png_bytep filtered_row));
  162331. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162332. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162333. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162334. png_infop info_ptr));
  162335. #if defined(PNG_READ_FILLER_SUPPORTED)
  162336. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162337. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162338. #endif
  162339. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162340. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162341. png_bytep row));
  162342. #endif
  162343. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162344. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162345. png_bytep row));
  162346. #endif
  162347. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162348. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162349. png_bytep row));
  162350. #endif
  162351. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162352. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162353. png_bytep row));
  162354. #endif
  162355. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162356. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162357. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162358. png_bytep row, png_uint_32 flags));
  162359. #endif
  162360. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162361. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162362. #endif
  162363. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162364. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162365. #endif
  162366. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162367. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162368. row_info, png_bytep row));
  162369. #endif
  162370. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162371. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162372. png_bytep row));
  162373. #endif
  162374. #if defined(PNG_READ_PACK_SUPPORTED)
  162375. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162376. #endif
  162377. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162378. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162379. png_color_8p sig_bits));
  162380. #endif
  162381. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162382. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162383. #endif
  162384. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162385. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162386. #endif
  162387. #if defined(PNG_READ_DITHER_SUPPORTED)
  162388. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162389. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162390. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162391. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162392. png_colorp palette, int num_palette));
  162393. # endif
  162394. #endif
  162395. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162396. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162397. #endif
  162398. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162399. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162400. png_bytep row, png_uint_32 bit_depth));
  162401. #endif
  162402. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162403. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162404. png_color_8p bit_depth));
  162405. #endif
  162406. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162407. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162408. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162409. png_color_16p trans_values, png_color_16p background,
  162410. png_color_16p background_1,
  162411. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162412. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162413. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162414. #else
  162415. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162416. png_color_16p trans_values, png_color_16p background));
  162417. #endif
  162418. #endif
  162419. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162420. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162421. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162422. int gamma_shift));
  162423. #endif
  162424. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162425. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162426. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162427. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162428. png_bytep row, png_color_16p trans_value));
  162429. #endif
  162430. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162431. png_uint_32 length));
  162432. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162433. png_uint_32 length));
  162434. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162435. png_uint_32 length));
  162436. #if defined(PNG_READ_bKGD_SUPPORTED)
  162437. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162438. png_uint_32 length));
  162439. #endif
  162440. #if defined(PNG_READ_cHRM_SUPPORTED)
  162441. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162442. png_uint_32 length));
  162443. #endif
  162444. #if defined(PNG_READ_gAMA_SUPPORTED)
  162445. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162446. png_uint_32 length));
  162447. #endif
  162448. #if defined(PNG_READ_hIST_SUPPORTED)
  162449. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162450. png_uint_32 length));
  162451. #endif
  162452. #if defined(PNG_READ_iCCP_SUPPORTED)
  162453. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162454. png_uint_32 length));
  162455. #endif /* PNG_READ_iCCP_SUPPORTED */
  162456. #if defined(PNG_READ_iTXt_SUPPORTED)
  162457. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162458. png_uint_32 length));
  162459. #endif
  162460. #if defined(PNG_READ_oFFs_SUPPORTED)
  162461. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162462. png_uint_32 length));
  162463. #endif
  162464. #if defined(PNG_READ_pCAL_SUPPORTED)
  162465. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162466. png_uint_32 length));
  162467. #endif
  162468. #if defined(PNG_READ_pHYs_SUPPORTED)
  162469. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162470. png_uint_32 length));
  162471. #endif
  162472. #if defined(PNG_READ_sBIT_SUPPORTED)
  162473. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162474. png_uint_32 length));
  162475. #endif
  162476. #if defined(PNG_READ_sCAL_SUPPORTED)
  162477. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162478. png_uint_32 length));
  162479. #endif
  162480. #if defined(PNG_READ_sPLT_SUPPORTED)
  162481. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162482. png_uint_32 length));
  162483. #endif /* PNG_READ_sPLT_SUPPORTED */
  162484. #if defined(PNG_READ_sRGB_SUPPORTED)
  162485. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162486. png_uint_32 length));
  162487. #endif
  162488. #if defined(PNG_READ_tEXt_SUPPORTED)
  162489. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162490. png_uint_32 length));
  162491. #endif
  162492. #if defined(PNG_READ_tIME_SUPPORTED)
  162493. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162494. png_uint_32 length));
  162495. #endif
  162496. #if defined(PNG_READ_tRNS_SUPPORTED)
  162497. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162498. png_uint_32 length));
  162499. #endif
  162500. #if defined(PNG_READ_zTXt_SUPPORTED)
  162501. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162502. png_uint_32 length));
  162503. #endif
  162504. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162505. png_infop info_ptr, png_uint_32 length));
  162506. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162507. png_bytep chunk_name));
  162508. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162509. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162510. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162511. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162512. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162513. png_infop info_ptr));
  162514. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162515. png_infop info_ptr));
  162516. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162517. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162518. png_uint_32 length));
  162519. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162520. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162521. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162522. png_bytep buffer, png_size_t buffer_length));
  162523. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162524. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162525. png_bytep buffer, png_size_t buffer_length));
  162526. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162527. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162528. png_infop info_ptr, png_uint_32 length));
  162529. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162530. png_infop info_ptr));
  162531. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162532. png_infop info_ptr));
  162533. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162534. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162535. png_infop info_ptr));
  162536. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162537. png_infop info_ptr));
  162538. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162539. #if defined(PNG_READ_tEXt_SUPPORTED)
  162540. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162541. png_infop info_ptr, png_uint_32 length));
  162542. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162543. png_infop info_ptr));
  162544. #endif
  162545. #if defined(PNG_READ_zTXt_SUPPORTED)
  162546. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162547. png_infop info_ptr, png_uint_32 length));
  162548. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162549. png_infop info_ptr));
  162550. #endif
  162551. #if defined(PNG_READ_iTXt_SUPPORTED)
  162552. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162553. png_infop info_ptr, png_uint_32 length));
  162554. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162555. png_infop info_ptr));
  162556. #endif
  162557. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162558. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162559. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162560. png_bytep row));
  162561. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162562. png_bytep row));
  162563. #endif
  162564. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162565. #if defined(PNG_MMX_CODE_SUPPORTED)
  162566. /* PRIVATE */
  162567. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162568. #endif
  162569. #endif
  162570. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162571. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162572. png_infop info_ptr));
  162573. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162574. png_infop info_ptr));
  162575. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162576. png_infop info_ptr));
  162577. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162578. png_infop info_ptr));
  162579. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162580. png_infop info_ptr));
  162581. #if defined(PNG_pHYs_SUPPORTED)
  162582. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162583. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162584. #endif /* PNG_pHYs_SUPPORTED */
  162585. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162586. #endif /* PNG_INTERNAL */
  162587. #ifdef __cplusplus
  162588. }
  162589. #endif
  162590. #endif /* PNG_VERSION_INFO_ONLY */
  162591. #endif /* PNG_H */
  162592. /*** End of inlined file: png.h ***/
  162593. #define PNG_NO_EXTERN
  162594. /*** Start of inlined file: png.c ***/
  162595. #define PNG_INTERNAL
  162596. #define PNG_NO_EXTERN
  162597. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162598. #ifdef PNG_USE_GLOBAL_ARRAYS
  162599. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162600. #ifdef PNG_READ_SUPPORTED
  162601. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162602. #endif /* PNG_READ_SUPPORTED */
  162603. PNG_IHDR;
  162604. PNG_IDAT;
  162605. PNG_IEND;
  162606. PNG_PLTE;
  162607. PNG_bKGD;
  162608. PNG_cHRM;
  162609. PNG_gAMA;
  162610. PNG_hIST;
  162611. PNG_iCCP;
  162612. PNG_iTXt;
  162613. PNG_oFFs;
  162614. PNG_pCAL;
  162615. PNG_sCAL;
  162616. PNG_pHYs;
  162617. PNG_sBIT;
  162618. PNG_sPLT;
  162619. PNG_sRGB;
  162620. PNG_tEXt;
  162621. PNG_tIME;
  162622. PNG_tRNS;
  162623. PNG_zTXt;
  162624. #ifdef PNG_READ_SUPPORTED
  162625. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162626. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162627. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162628. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162629. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162630. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162631. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162632. #endif /* PNG_READ_SUPPORTED */
  162633. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162634. #ifdef PNG_READ_SUPPORTED
  162635. void PNGAPI
  162636. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162637. {
  162638. if(png_ptr == NULL) return;
  162639. png_debug(1, "in png_set_sig_bytes\n");
  162640. if (num_bytes > 8)
  162641. png_error(png_ptr, "Too many bytes for PNG signature.");
  162642. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162643. }
  162644. int PNGAPI
  162645. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162646. {
  162647. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162648. if (num_to_check > 8)
  162649. num_to_check = 8;
  162650. else if (num_to_check < 1)
  162651. return (-1);
  162652. if (start > 7)
  162653. return (-1);
  162654. if (start + num_to_check > 8)
  162655. num_to_check = 8 - start;
  162656. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162657. }
  162658. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162659. int PNGAPI
  162660. png_check_sig(png_bytep sig, int num)
  162661. {
  162662. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162663. }
  162664. #endif
  162665. #endif /* PNG_READ_SUPPORTED */
  162666. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162667. #ifdef PNG_1_0_X
  162668. voidpf PNGAPI
  162669. #else
  162670. voidpf /* private */
  162671. #endif
  162672. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162673. {
  162674. png_voidp ptr;
  162675. png_structp p=(png_structp)png_ptr;
  162676. png_uint_32 save_flags=p->flags;
  162677. png_uint_32 num_bytes;
  162678. if(png_ptr == NULL) return (NULL);
  162679. if (items > PNG_UINT_32_MAX/size)
  162680. {
  162681. png_warning (p, "Potential overflow in png_zalloc()");
  162682. return (NULL);
  162683. }
  162684. num_bytes = (png_uint_32)items * size;
  162685. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162686. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162687. p->flags=save_flags;
  162688. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162689. if (ptr == NULL)
  162690. return ((voidpf)ptr);
  162691. if (num_bytes > (png_uint_32)0x8000L)
  162692. {
  162693. png_memset(ptr, 0, (png_size_t)0x8000L);
  162694. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162695. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162696. }
  162697. else
  162698. {
  162699. png_memset(ptr, 0, (png_size_t)num_bytes);
  162700. }
  162701. #endif
  162702. return ((voidpf)ptr);
  162703. }
  162704. #ifdef PNG_1_0_X
  162705. void PNGAPI
  162706. #else
  162707. void /* private */
  162708. #endif
  162709. png_zfree(voidpf png_ptr, voidpf ptr)
  162710. {
  162711. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162712. }
  162713. void /* PRIVATE */
  162714. png_reset_crc(png_structp png_ptr)
  162715. {
  162716. png_ptr->crc = crc32(0, Z_NULL, 0);
  162717. }
  162718. void /* PRIVATE */
  162719. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162720. {
  162721. int need_crc = 1;
  162722. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162723. {
  162724. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162725. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162726. need_crc = 0;
  162727. }
  162728. else /* critical */
  162729. {
  162730. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162731. need_crc = 0;
  162732. }
  162733. if (need_crc)
  162734. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162735. }
  162736. png_infop PNGAPI
  162737. png_create_info_struct(png_structp png_ptr)
  162738. {
  162739. png_infop info_ptr;
  162740. png_debug(1, "in png_create_info_struct\n");
  162741. if(png_ptr == NULL) return (NULL);
  162742. #ifdef PNG_USER_MEM_SUPPORTED
  162743. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162744. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162745. #else
  162746. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162747. #endif
  162748. if (info_ptr != NULL)
  162749. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162750. return (info_ptr);
  162751. }
  162752. void PNGAPI
  162753. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162754. {
  162755. png_infop info_ptr = NULL;
  162756. if(png_ptr == NULL) return;
  162757. png_debug(1, "in png_destroy_info_struct\n");
  162758. if (info_ptr_ptr != NULL)
  162759. info_ptr = *info_ptr_ptr;
  162760. if (info_ptr != NULL)
  162761. {
  162762. png_info_destroy(png_ptr, info_ptr);
  162763. #ifdef PNG_USER_MEM_SUPPORTED
  162764. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162765. png_ptr->mem_ptr);
  162766. #else
  162767. png_destroy_struct((png_voidp)info_ptr);
  162768. #endif
  162769. *info_ptr_ptr = NULL;
  162770. }
  162771. }
  162772. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162773. #undef png_info_init
  162774. void PNGAPI
  162775. png_info_init(png_infop info_ptr)
  162776. {
  162777. png_info_init_3(&info_ptr, 0);
  162778. }
  162779. #endif
  162780. void PNGAPI
  162781. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162782. {
  162783. png_infop info_ptr = *ptr_ptr;
  162784. if(info_ptr == NULL) return;
  162785. png_debug(1, "in png_info_init_3\n");
  162786. if(png_sizeof(png_info) > png_info_struct_size)
  162787. {
  162788. png_destroy_struct(info_ptr);
  162789. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162790. *ptr_ptr = info_ptr;
  162791. }
  162792. png_memset(info_ptr, 0, png_sizeof (png_info));
  162793. }
  162794. #ifdef PNG_FREE_ME_SUPPORTED
  162795. void PNGAPI
  162796. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162797. int freer, png_uint_32 mask)
  162798. {
  162799. png_debug(1, "in png_data_freer\n");
  162800. if (png_ptr == NULL || info_ptr == NULL)
  162801. return;
  162802. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162803. info_ptr->free_me |= mask;
  162804. else if(freer == PNG_USER_WILL_FREE_DATA)
  162805. info_ptr->free_me &= ~mask;
  162806. else
  162807. png_warning(png_ptr,
  162808. "Unknown freer parameter in png_data_freer.");
  162809. }
  162810. #endif
  162811. void PNGAPI
  162812. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162813. int num)
  162814. {
  162815. png_debug(1, "in png_free_data\n");
  162816. if (png_ptr == NULL || info_ptr == NULL)
  162817. return;
  162818. #if defined(PNG_TEXT_SUPPORTED)
  162819. #ifdef PNG_FREE_ME_SUPPORTED
  162820. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162821. #else
  162822. if (mask & PNG_FREE_TEXT)
  162823. #endif
  162824. {
  162825. if (num != -1)
  162826. {
  162827. if (info_ptr->text && info_ptr->text[num].key)
  162828. {
  162829. png_free(png_ptr, info_ptr->text[num].key);
  162830. info_ptr->text[num].key = NULL;
  162831. }
  162832. }
  162833. else
  162834. {
  162835. int i;
  162836. for (i = 0; i < info_ptr->num_text; i++)
  162837. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162838. png_free(png_ptr, info_ptr->text);
  162839. info_ptr->text = NULL;
  162840. info_ptr->num_text=0;
  162841. }
  162842. }
  162843. #endif
  162844. #if defined(PNG_tRNS_SUPPORTED)
  162845. #ifdef PNG_FREE_ME_SUPPORTED
  162846. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162847. #else
  162848. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162849. #endif
  162850. {
  162851. png_free(png_ptr, info_ptr->trans);
  162852. info_ptr->valid &= ~PNG_INFO_tRNS;
  162853. #ifndef PNG_FREE_ME_SUPPORTED
  162854. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162855. #endif
  162856. info_ptr->trans = NULL;
  162857. }
  162858. #endif
  162859. #if defined(PNG_sCAL_SUPPORTED)
  162860. #ifdef PNG_FREE_ME_SUPPORTED
  162861. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162862. #else
  162863. if (mask & PNG_FREE_SCAL)
  162864. #endif
  162865. {
  162866. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162867. png_free(png_ptr, info_ptr->scal_s_width);
  162868. png_free(png_ptr, info_ptr->scal_s_height);
  162869. info_ptr->scal_s_width = NULL;
  162870. info_ptr->scal_s_height = NULL;
  162871. #endif
  162872. info_ptr->valid &= ~PNG_INFO_sCAL;
  162873. }
  162874. #endif
  162875. #if defined(PNG_pCAL_SUPPORTED)
  162876. #ifdef PNG_FREE_ME_SUPPORTED
  162877. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162878. #else
  162879. if (mask & PNG_FREE_PCAL)
  162880. #endif
  162881. {
  162882. png_free(png_ptr, info_ptr->pcal_purpose);
  162883. png_free(png_ptr, info_ptr->pcal_units);
  162884. info_ptr->pcal_purpose = NULL;
  162885. info_ptr->pcal_units = NULL;
  162886. if (info_ptr->pcal_params != NULL)
  162887. {
  162888. int i;
  162889. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162890. {
  162891. png_free(png_ptr, info_ptr->pcal_params[i]);
  162892. info_ptr->pcal_params[i]=NULL;
  162893. }
  162894. png_free(png_ptr, info_ptr->pcal_params);
  162895. info_ptr->pcal_params = NULL;
  162896. }
  162897. info_ptr->valid &= ~PNG_INFO_pCAL;
  162898. }
  162899. #endif
  162900. #if defined(PNG_iCCP_SUPPORTED)
  162901. #ifdef PNG_FREE_ME_SUPPORTED
  162902. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162903. #else
  162904. if (mask & PNG_FREE_ICCP)
  162905. #endif
  162906. {
  162907. png_free(png_ptr, info_ptr->iccp_name);
  162908. png_free(png_ptr, info_ptr->iccp_profile);
  162909. info_ptr->iccp_name = NULL;
  162910. info_ptr->iccp_profile = NULL;
  162911. info_ptr->valid &= ~PNG_INFO_iCCP;
  162912. }
  162913. #endif
  162914. #if defined(PNG_sPLT_SUPPORTED)
  162915. #ifdef PNG_FREE_ME_SUPPORTED
  162916. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162917. #else
  162918. if (mask & PNG_FREE_SPLT)
  162919. #endif
  162920. {
  162921. if (num != -1)
  162922. {
  162923. if(info_ptr->splt_palettes)
  162924. {
  162925. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162926. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162927. info_ptr->splt_palettes[num].name = NULL;
  162928. info_ptr->splt_palettes[num].entries = NULL;
  162929. }
  162930. }
  162931. else
  162932. {
  162933. if(info_ptr->splt_palettes_num)
  162934. {
  162935. int i;
  162936. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162937. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162938. png_free(png_ptr, info_ptr->splt_palettes);
  162939. info_ptr->splt_palettes = NULL;
  162940. info_ptr->splt_palettes_num = 0;
  162941. }
  162942. info_ptr->valid &= ~PNG_INFO_sPLT;
  162943. }
  162944. }
  162945. #endif
  162946. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162947. if(png_ptr->unknown_chunk.data)
  162948. {
  162949. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162950. png_ptr->unknown_chunk.data = NULL;
  162951. }
  162952. #ifdef PNG_FREE_ME_SUPPORTED
  162953. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162954. #else
  162955. if (mask & PNG_FREE_UNKN)
  162956. #endif
  162957. {
  162958. if (num != -1)
  162959. {
  162960. if(info_ptr->unknown_chunks)
  162961. {
  162962. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162963. info_ptr->unknown_chunks[num].data = NULL;
  162964. }
  162965. }
  162966. else
  162967. {
  162968. int i;
  162969. if(info_ptr->unknown_chunks_num)
  162970. {
  162971. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162972. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162973. png_free(png_ptr, info_ptr->unknown_chunks);
  162974. info_ptr->unknown_chunks = NULL;
  162975. info_ptr->unknown_chunks_num = 0;
  162976. }
  162977. }
  162978. }
  162979. #endif
  162980. #if defined(PNG_hIST_SUPPORTED)
  162981. #ifdef PNG_FREE_ME_SUPPORTED
  162982. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162983. #else
  162984. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162985. #endif
  162986. {
  162987. png_free(png_ptr, info_ptr->hist);
  162988. info_ptr->hist = NULL;
  162989. info_ptr->valid &= ~PNG_INFO_hIST;
  162990. #ifndef PNG_FREE_ME_SUPPORTED
  162991. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162992. #endif
  162993. }
  162994. #endif
  162995. #ifdef PNG_FREE_ME_SUPPORTED
  162996. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162997. #else
  162998. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162999. #endif
  163000. {
  163001. png_zfree(png_ptr, info_ptr->palette);
  163002. info_ptr->palette = NULL;
  163003. info_ptr->valid &= ~PNG_INFO_PLTE;
  163004. #ifndef PNG_FREE_ME_SUPPORTED
  163005. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  163006. #endif
  163007. info_ptr->num_palette = 0;
  163008. }
  163009. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163010. #ifdef PNG_FREE_ME_SUPPORTED
  163011. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  163012. #else
  163013. if (mask & PNG_FREE_ROWS)
  163014. #endif
  163015. {
  163016. if(info_ptr->row_pointers)
  163017. {
  163018. int row;
  163019. for (row = 0; row < (int)info_ptr->height; row++)
  163020. {
  163021. png_free(png_ptr, info_ptr->row_pointers[row]);
  163022. info_ptr->row_pointers[row]=NULL;
  163023. }
  163024. png_free(png_ptr, info_ptr->row_pointers);
  163025. info_ptr->row_pointers=NULL;
  163026. }
  163027. info_ptr->valid &= ~PNG_INFO_IDAT;
  163028. }
  163029. #endif
  163030. #ifdef PNG_FREE_ME_SUPPORTED
  163031. if(num == -1)
  163032. info_ptr->free_me &= ~mask;
  163033. else
  163034. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  163035. #endif
  163036. }
  163037. void /* PRIVATE */
  163038. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  163039. {
  163040. png_debug(1, "in png_info_destroy\n");
  163041. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  163042. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163043. if (png_ptr->num_chunk_list)
  163044. {
  163045. png_free(png_ptr, png_ptr->chunk_list);
  163046. png_ptr->chunk_list=NULL;
  163047. png_ptr->num_chunk_list=0;
  163048. }
  163049. #endif
  163050. png_info_init_3(&info_ptr, png_sizeof(png_info));
  163051. }
  163052. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163053. png_voidp PNGAPI
  163054. png_get_io_ptr(png_structp png_ptr)
  163055. {
  163056. if(png_ptr == NULL) return (NULL);
  163057. return (png_ptr->io_ptr);
  163058. }
  163059. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163060. #if !defined(PNG_NO_STDIO)
  163061. void PNGAPI
  163062. png_init_io(png_structp png_ptr, png_FILE_p fp)
  163063. {
  163064. png_debug(1, "in png_init_io\n");
  163065. if(png_ptr == NULL) return;
  163066. png_ptr->io_ptr = (png_voidp)fp;
  163067. }
  163068. #endif
  163069. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  163070. png_charp PNGAPI
  163071. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  163072. {
  163073. static PNG_CONST char short_months[12][4] =
  163074. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  163075. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  163076. if(png_ptr == NULL) return (NULL);
  163077. if (png_ptr->time_buffer == NULL)
  163078. {
  163079. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  163080. png_sizeof(char)));
  163081. }
  163082. #if defined(_WIN32_WCE)
  163083. {
  163084. wchar_t time_buf[29];
  163085. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  163086. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163087. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163088. ptime->second % 61);
  163089. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  163090. NULL, NULL);
  163091. }
  163092. #else
  163093. #ifdef USE_FAR_KEYWORD
  163094. {
  163095. char near_time_buf[29];
  163096. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163097. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163098. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163099. ptime->second % 61);
  163100. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163101. 29*png_sizeof(char));
  163102. }
  163103. #else
  163104. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163105. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163106. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163107. ptime->second % 61);
  163108. #endif
  163109. #endif /* _WIN32_WCE */
  163110. return ((png_charp)png_ptr->time_buffer);
  163111. }
  163112. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163113. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163114. png_charp PNGAPI
  163115. png_get_copyright(png_structp png_ptr)
  163116. {
  163117. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163118. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163119. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163120. Copyright (c) 1996-1997 Andreas Dilger\n\
  163121. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163122. }
  163123. png_charp PNGAPI
  163124. png_get_libpng_ver(png_structp png_ptr)
  163125. {
  163126. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163127. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163128. }
  163129. png_charp PNGAPI
  163130. png_get_header_ver(png_structp png_ptr)
  163131. {
  163132. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163133. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163134. }
  163135. png_charp PNGAPI
  163136. png_get_header_version(png_structp png_ptr)
  163137. {
  163138. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163139. return ((png_charp) PNG_HEADER_VERSION_STRING
  163140. #ifndef PNG_READ_SUPPORTED
  163141. " (NO READ SUPPORT)"
  163142. #endif
  163143. "\n");
  163144. }
  163145. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163146. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163147. int PNGAPI
  163148. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163149. {
  163150. int i;
  163151. png_bytep p;
  163152. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163153. return 0;
  163154. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163155. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163156. if (!png_memcmp(chunk_name, p, 4))
  163157. return ((int)*(p+4));
  163158. return 0;
  163159. }
  163160. #endif
  163161. int PNGAPI
  163162. png_reset_zstream(png_structp png_ptr)
  163163. {
  163164. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163165. return (inflateReset(&png_ptr->zstream));
  163166. }
  163167. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163168. png_uint_32 PNGAPI
  163169. png_access_version_number(void)
  163170. {
  163171. return((png_uint_32) PNG_LIBPNG_VER);
  163172. }
  163173. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163174. #if !defined(PNG_1_0_X)
  163175. int PNGAPI
  163176. png_mmx_support(void)
  163177. {
  163178. return -1;
  163179. }
  163180. #endif /* PNG_1_0_X */
  163181. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163182. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163183. #ifdef PNG_SIZE_T
  163184. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163185. png_size_t PNGAPI
  163186. png_convert_size(size_t size)
  163187. {
  163188. if (size > (png_size_t)-1)
  163189. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163190. return ((png_size_t)size);
  163191. }
  163192. #endif /* PNG_SIZE_T */
  163193. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163194. /*** End of inlined file: png.c ***/
  163195. /*** Start of inlined file: pngerror.c ***/
  163196. #define PNG_INTERNAL
  163197. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163198. static void /* PRIVATE */
  163199. png_default_error PNGARG((png_structp png_ptr,
  163200. png_const_charp error_message));
  163201. #ifndef PNG_NO_WARNINGS
  163202. static void /* PRIVATE */
  163203. png_default_warning PNGARG((png_structp png_ptr,
  163204. png_const_charp warning_message));
  163205. #endif /* PNG_NO_WARNINGS */
  163206. #ifndef PNG_NO_ERROR_TEXT
  163207. void PNGAPI
  163208. png_error(png_structp png_ptr, png_const_charp error_message)
  163209. {
  163210. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163211. char msg[16];
  163212. if (png_ptr != NULL)
  163213. {
  163214. if (png_ptr->flags&
  163215. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163216. {
  163217. if (*error_message == '#')
  163218. {
  163219. int offset;
  163220. for (offset=1; offset<15; offset++)
  163221. if (*(error_message+offset) == ' ')
  163222. break;
  163223. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163224. {
  163225. int i;
  163226. for (i=0; i<offset-1; i++)
  163227. msg[i]=error_message[i+1];
  163228. msg[i]='\0';
  163229. error_message=msg;
  163230. }
  163231. else
  163232. error_message+=offset;
  163233. }
  163234. else
  163235. {
  163236. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163237. {
  163238. msg[0]='0';
  163239. msg[1]='\0';
  163240. error_message=msg;
  163241. }
  163242. }
  163243. }
  163244. }
  163245. #endif
  163246. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163247. (*(png_ptr->error_fn))(png_ptr, error_message);
  163248. png_default_error(png_ptr, error_message);
  163249. }
  163250. #else
  163251. void PNGAPI
  163252. png_err(png_structp png_ptr)
  163253. {
  163254. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163255. (*(png_ptr->error_fn))(png_ptr, '\0');
  163256. png_default_error(png_ptr, '\0');
  163257. }
  163258. #endif /* PNG_NO_ERROR_TEXT */
  163259. #ifndef PNG_NO_WARNINGS
  163260. void PNGAPI
  163261. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163262. {
  163263. int offset = 0;
  163264. if (png_ptr != NULL)
  163265. {
  163266. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163267. if (png_ptr->flags&
  163268. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163269. #endif
  163270. {
  163271. if (*warning_message == '#')
  163272. {
  163273. for (offset=1; offset<15; offset++)
  163274. if (*(warning_message+offset) == ' ')
  163275. break;
  163276. }
  163277. }
  163278. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163279. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163280. }
  163281. else
  163282. png_default_warning(png_ptr, warning_message+offset);
  163283. }
  163284. #endif /* PNG_NO_WARNINGS */
  163285. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163286. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163287. static void /* PRIVATE */
  163288. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163289. error_message)
  163290. {
  163291. int iout = 0, iin = 0;
  163292. while (iin < 4)
  163293. {
  163294. int c = png_ptr->chunk_name[iin++];
  163295. if (isnonalpha(c))
  163296. {
  163297. buffer[iout++] = '[';
  163298. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163299. buffer[iout++] = png_digit[c & 0x0f];
  163300. buffer[iout++] = ']';
  163301. }
  163302. else
  163303. {
  163304. buffer[iout++] = (png_byte)c;
  163305. }
  163306. }
  163307. if (error_message == NULL)
  163308. buffer[iout] = 0;
  163309. else
  163310. {
  163311. buffer[iout++] = ':';
  163312. buffer[iout++] = ' ';
  163313. png_strncpy(buffer+iout, error_message, 63);
  163314. buffer[iout+63] = 0;
  163315. }
  163316. }
  163317. #ifdef PNG_READ_SUPPORTED
  163318. void PNGAPI
  163319. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163320. {
  163321. char msg[18+64];
  163322. if (png_ptr == NULL)
  163323. png_error(png_ptr, error_message);
  163324. else
  163325. {
  163326. png_format_buffer(png_ptr, msg, error_message);
  163327. png_error(png_ptr, msg);
  163328. }
  163329. }
  163330. #endif /* PNG_READ_SUPPORTED */
  163331. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163332. #ifndef PNG_NO_WARNINGS
  163333. void PNGAPI
  163334. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163335. {
  163336. char msg[18+64];
  163337. if (png_ptr == NULL)
  163338. png_warning(png_ptr, warning_message);
  163339. else
  163340. {
  163341. png_format_buffer(png_ptr, msg, warning_message);
  163342. png_warning(png_ptr, msg);
  163343. }
  163344. }
  163345. #endif /* PNG_NO_WARNINGS */
  163346. static void /* PRIVATE */
  163347. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163348. {
  163349. #ifndef PNG_NO_CONSOLE_IO
  163350. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163351. if (*error_message == '#')
  163352. {
  163353. int offset;
  163354. char error_number[16];
  163355. for (offset=0; offset<15; offset++)
  163356. {
  163357. error_number[offset] = *(error_message+offset+1);
  163358. if (*(error_message+offset) == ' ')
  163359. break;
  163360. }
  163361. if((offset > 1) && (offset < 15))
  163362. {
  163363. error_number[offset-1]='\0';
  163364. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163365. error_message+offset);
  163366. }
  163367. else
  163368. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163369. }
  163370. else
  163371. #endif
  163372. fprintf(stderr, "libpng error: %s\n", error_message);
  163373. #endif
  163374. #ifdef PNG_SETJMP_SUPPORTED
  163375. if (png_ptr)
  163376. {
  163377. # ifdef USE_FAR_KEYWORD
  163378. {
  163379. jmp_buf jmpbuf;
  163380. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163381. longjmp(jmpbuf, 1);
  163382. }
  163383. # else
  163384. longjmp(png_ptr->jmpbuf, 1);
  163385. # endif
  163386. }
  163387. #else
  163388. PNG_ABORT();
  163389. #endif
  163390. #ifdef PNG_NO_CONSOLE_IO
  163391. error_message = error_message; /* make compiler happy */
  163392. #endif
  163393. }
  163394. #ifndef PNG_NO_WARNINGS
  163395. static void /* PRIVATE */
  163396. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163397. {
  163398. #ifndef PNG_NO_CONSOLE_IO
  163399. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163400. if (*warning_message == '#')
  163401. {
  163402. int offset;
  163403. char warning_number[16];
  163404. for (offset=0; offset<15; offset++)
  163405. {
  163406. warning_number[offset]=*(warning_message+offset+1);
  163407. if (*(warning_message+offset) == ' ')
  163408. break;
  163409. }
  163410. if((offset > 1) && (offset < 15))
  163411. {
  163412. warning_number[offset-1]='\0';
  163413. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163414. warning_message+offset);
  163415. }
  163416. else
  163417. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163418. }
  163419. else
  163420. # endif
  163421. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163422. #else
  163423. warning_message = warning_message; /* make compiler happy */
  163424. #endif
  163425. png_ptr = png_ptr; /* make compiler happy */
  163426. }
  163427. #endif /* PNG_NO_WARNINGS */
  163428. void PNGAPI
  163429. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163430. png_error_ptr error_fn, png_error_ptr warning_fn)
  163431. {
  163432. if (png_ptr == NULL)
  163433. return;
  163434. png_ptr->error_ptr = error_ptr;
  163435. png_ptr->error_fn = error_fn;
  163436. png_ptr->warning_fn = warning_fn;
  163437. }
  163438. png_voidp PNGAPI
  163439. png_get_error_ptr(png_structp png_ptr)
  163440. {
  163441. if (png_ptr == NULL)
  163442. return NULL;
  163443. return ((png_voidp)png_ptr->error_ptr);
  163444. }
  163445. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163446. void PNGAPI
  163447. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163448. {
  163449. if(png_ptr != NULL)
  163450. {
  163451. png_ptr->flags &=
  163452. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163453. }
  163454. }
  163455. #endif
  163456. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163457. /*** End of inlined file: pngerror.c ***/
  163458. /*** Start of inlined file: pngget.c ***/
  163459. #define PNG_INTERNAL
  163460. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163461. png_uint_32 PNGAPI
  163462. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163463. {
  163464. if (png_ptr != NULL && info_ptr != NULL)
  163465. return(info_ptr->valid & flag);
  163466. else
  163467. return(0);
  163468. }
  163469. png_uint_32 PNGAPI
  163470. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163471. {
  163472. if (png_ptr != NULL && info_ptr != NULL)
  163473. return(info_ptr->rowbytes);
  163474. else
  163475. return(0);
  163476. }
  163477. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163478. png_bytepp PNGAPI
  163479. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163480. {
  163481. if (png_ptr != NULL && info_ptr != NULL)
  163482. return(info_ptr->row_pointers);
  163483. else
  163484. return(0);
  163485. }
  163486. #endif
  163487. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163488. png_uint_32 PNGAPI
  163489. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163490. {
  163491. if (png_ptr != NULL && info_ptr != NULL)
  163492. {
  163493. return info_ptr->width;
  163494. }
  163495. return (0);
  163496. }
  163497. png_uint_32 PNGAPI
  163498. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163499. {
  163500. if (png_ptr != NULL && info_ptr != NULL)
  163501. {
  163502. return info_ptr->height;
  163503. }
  163504. return (0);
  163505. }
  163506. png_byte PNGAPI
  163507. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163508. {
  163509. if (png_ptr != NULL && info_ptr != NULL)
  163510. {
  163511. return info_ptr->bit_depth;
  163512. }
  163513. return (0);
  163514. }
  163515. png_byte PNGAPI
  163516. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163517. {
  163518. if (png_ptr != NULL && info_ptr != NULL)
  163519. {
  163520. return info_ptr->color_type;
  163521. }
  163522. return (0);
  163523. }
  163524. png_byte PNGAPI
  163525. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163526. {
  163527. if (png_ptr != NULL && info_ptr != NULL)
  163528. {
  163529. return info_ptr->filter_type;
  163530. }
  163531. return (0);
  163532. }
  163533. png_byte PNGAPI
  163534. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163535. {
  163536. if (png_ptr != NULL && info_ptr != NULL)
  163537. {
  163538. return info_ptr->interlace_type;
  163539. }
  163540. return (0);
  163541. }
  163542. png_byte PNGAPI
  163543. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163544. {
  163545. if (png_ptr != NULL && info_ptr != NULL)
  163546. {
  163547. return info_ptr->compression_type;
  163548. }
  163549. return (0);
  163550. }
  163551. png_uint_32 PNGAPI
  163552. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163553. {
  163554. if (png_ptr != NULL && info_ptr != NULL)
  163555. #if defined(PNG_pHYs_SUPPORTED)
  163556. if (info_ptr->valid & PNG_INFO_pHYs)
  163557. {
  163558. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163559. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163560. return (0);
  163561. else return (info_ptr->x_pixels_per_unit);
  163562. }
  163563. #else
  163564. return (0);
  163565. #endif
  163566. return (0);
  163567. }
  163568. png_uint_32 PNGAPI
  163569. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163570. {
  163571. if (png_ptr != NULL && info_ptr != NULL)
  163572. #if defined(PNG_pHYs_SUPPORTED)
  163573. if (info_ptr->valid & PNG_INFO_pHYs)
  163574. {
  163575. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163576. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163577. return (0);
  163578. else return (info_ptr->y_pixels_per_unit);
  163579. }
  163580. #else
  163581. return (0);
  163582. #endif
  163583. return (0);
  163584. }
  163585. png_uint_32 PNGAPI
  163586. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163587. {
  163588. if (png_ptr != NULL && info_ptr != NULL)
  163589. #if defined(PNG_pHYs_SUPPORTED)
  163590. if (info_ptr->valid & PNG_INFO_pHYs)
  163591. {
  163592. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163593. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163594. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163595. return (0);
  163596. else return (info_ptr->x_pixels_per_unit);
  163597. }
  163598. #else
  163599. return (0);
  163600. #endif
  163601. return (0);
  163602. }
  163603. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163604. float PNGAPI
  163605. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163606. {
  163607. if (png_ptr != NULL && info_ptr != NULL)
  163608. #if defined(PNG_pHYs_SUPPORTED)
  163609. if (info_ptr->valid & PNG_INFO_pHYs)
  163610. {
  163611. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163612. if (info_ptr->x_pixels_per_unit == 0)
  163613. return ((float)0.0);
  163614. else
  163615. return ((float)((float)info_ptr->y_pixels_per_unit
  163616. /(float)info_ptr->x_pixels_per_unit));
  163617. }
  163618. #else
  163619. return (0.0);
  163620. #endif
  163621. return ((float)0.0);
  163622. }
  163623. #endif
  163624. png_int_32 PNGAPI
  163625. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163626. {
  163627. if (png_ptr != NULL && info_ptr != NULL)
  163628. #if defined(PNG_oFFs_SUPPORTED)
  163629. if (info_ptr->valid & PNG_INFO_oFFs)
  163630. {
  163631. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163632. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163633. return (0);
  163634. else return (info_ptr->x_offset);
  163635. }
  163636. #else
  163637. return (0);
  163638. #endif
  163639. return (0);
  163640. }
  163641. png_int_32 PNGAPI
  163642. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163643. {
  163644. if (png_ptr != NULL && info_ptr != NULL)
  163645. #if defined(PNG_oFFs_SUPPORTED)
  163646. if (info_ptr->valid & PNG_INFO_oFFs)
  163647. {
  163648. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163649. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163650. return (0);
  163651. else return (info_ptr->y_offset);
  163652. }
  163653. #else
  163654. return (0);
  163655. #endif
  163656. return (0);
  163657. }
  163658. png_int_32 PNGAPI
  163659. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163660. {
  163661. if (png_ptr != NULL && info_ptr != NULL)
  163662. #if defined(PNG_oFFs_SUPPORTED)
  163663. if (info_ptr->valid & PNG_INFO_oFFs)
  163664. {
  163665. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163666. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163667. return (0);
  163668. else return (info_ptr->x_offset);
  163669. }
  163670. #else
  163671. return (0);
  163672. #endif
  163673. return (0);
  163674. }
  163675. png_int_32 PNGAPI
  163676. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163677. {
  163678. if (png_ptr != NULL && info_ptr != NULL)
  163679. #if defined(PNG_oFFs_SUPPORTED)
  163680. if (info_ptr->valid & PNG_INFO_oFFs)
  163681. {
  163682. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163683. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163684. return (0);
  163685. else return (info_ptr->y_offset);
  163686. }
  163687. #else
  163688. return (0);
  163689. #endif
  163690. return (0);
  163691. }
  163692. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163693. png_uint_32 PNGAPI
  163694. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163695. {
  163696. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163697. *.0254 +.5));
  163698. }
  163699. png_uint_32 PNGAPI
  163700. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163701. {
  163702. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163703. *.0254 +.5));
  163704. }
  163705. png_uint_32 PNGAPI
  163706. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163707. {
  163708. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163709. *.0254 +.5));
  163710. }
  163711. float PNGAPI
  163712. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163713. {
  163714. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163715. *.00003937);
  163716. }
  163717. float PNGAPI
  163718. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163719. {
  163720. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163721. *.00003937);
  163722. }
  163723. #if defined(PNG_pHYs_SUPPORTED)
  163724. png_uint_32 PNGAPI
  163725. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163726. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163727. {
  163728. png_uint_32 retval = 0;
  163729. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163730. {
  163731. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163732. if (res_x != NULL)
  163733. {
  163734. *res_x = info_ptr->x_pixels_per_unit;
  163735. retval |= PNG_INFO_pHYs;
  163736. }
  163737. if (res_y != NULL)
  163738. {
  163739. *res_y = info_ptr->y_pixels_per_unit;
  163740. retval |= PNG_INFO_pHYs;
  163741. }
  163742. if (unit_type != NULL)
  163743. {
  163744. *unit_type = (int)info_ptr->phys_unit_type;
  163745. retval |= PNG_INFO_pHYs;
  163746. if(*unit_type == 1)
  163747. {
  163748. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163749. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163750. }
  163751. }
  163752. }
  163753. return (retval);
  163754. }
  163755. #endif /* PNG_pHYs_SUPPORTED */
  163756. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163757. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163758. png_byte PNGAPI
  163759. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163760. {
  163761. if (png_ptr != NULL && info_ptr != NULL)
  163762. return(info_ptr->channels);
  163763. else
  163764. return (0);
  163765. }
  163766. png_bytep PNGAPI
  163767. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163768. {
  163769. if (png_ptr != NULL && info_ptr != NULL)
  163770. return(info_ptr->signature);
  163771. else
  163772. return (NULL);
  163773. }
  163774. #if defined(PNG_bKGD_SUPPORTED)
  163775. png_uint_32 PNGAPI
  163776. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163777. png_color_16p *background)
  163778. {
  163779. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163780. && background != NULL)
  163781. {
  163782. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163783. *background = &(info_ptr->background);
  163784. return (PNG_INFO_bKGD);
  163785. }
  163786. return (0);
  163787. }
  163788. #endif
  163789. #if defined(PNG_cHRM_SUPPORTED)
  163790. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163791. png_uint_32 PNGAPI
  163792. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163793. double *white_x, double *white_y, double *red_x, double *red_y,
  163794. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163795. {
  163796. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163797. {
  163798. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163799. if (white_x != NULL)
  163800. *white_x = (double)info_ptr->x_white;
  163801. if (white_y != NULL)
  163802. *white_y = (double)info_ptr->y_white;
  163803. if (red_x != NULL)
  163804. *red_x = (double)info_ptr->x_red;
  163805. if (red_y != NULL)
  163806. *red_y = (double)info_ptr->y_red;
  163807. if (green_x != NULL)
  163808. *green_x = (double)info_ptr->x_green;
  163809. if (green_y != NULL)
  163810. *green_y = (double)info_ptr->y_green;
  163811. if (blue_x != NULL)
  163812. *blue_x = (double)info_ptr->x_blue;
  163813. if (blue_y != NULL)
  163814. *blue_y = (double)info_ptr->y_blue;
  163815. return (PNG_INFO_cHRM);
  163816. }
  163817. return (0);
  163818. }
  163819. #endif
  163820. #ifdef PNG_FIXED_POINT_SUPPORTED
  163821. png_uint_32 PNGAPI
  163822. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163823. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163824. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163825. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163826. {
  163827. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163828. {
  163829. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163830. if (white_x != NULL)
  163831. *white_x = info_ptr->int_x_white;
  163832. if (white_y != NULL)
  163833. *white_y = info_ptr->int_y_white;
  163834. if (red_x != NULL)
  163835. *red_x = info_ptr->int_x_red;
  163836. if (red_y != NULL)
  163837. *red_y = info_ptr->int_y_red;
  163838. if (green_x != NULL)
  163839. *green_x = info_ptr->int_x_green;
  163840. if (green_y != NULL)
  163841. *green_y = info_ptr->int_y_green;
  163842. if (blue_x != NULL)
  163843. *blue_x = info_ptr->int_x_blue;
  163844. if (blue_y != NULL)
  163845. *blue_y = info_ptr->int_y_blue;
  163846. return (PNG_INFO_cHRM);
  163847. }
  163848. return (0);
  163849. }
  163850. #endif
  163851. #endif
  163852. #if defined(PNG_gAMA_SUPPORTED)
  163853. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163854. png_uint_32 PNGAPI
  163855. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163856. {
  163857. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163858. && file_gamma != NULL)
  163859. {
  163860. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163861. *file_gamma = (double)info_ptr->gamma;
  163862. return (PNG_INFO_gAMA);
  163863. }
  163864. return (0);
  163865. }
  163866. #endif
  163867. #ifdef PNG_FIXED_POINT_SUPPORTED
  163868. png_uint_32 PNGAPI
  163869. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163870. png_fixed_point *int_file_gamma)
  163871. {
  163872. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163873. && int_file_gamma != NULL)
  163874. {
  163875. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163876. *int_file_gamma = info_ptr->int_gamma;
  163877. return (PNG_INFO_gAMA);
  163878. }
  163879. return (0);
  163880. }
  163881. #endif
  163882. #endif
  163883. #if defined(PNG_sRGB_SUPPORTED)
  163884. png_uint_32 PNGAPI
  163885. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163886. {
  163887. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163888. && file_srgb_intent != NULL)
  163889. {
  163890. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163891. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163892. return (PNG_INFO_sRGB);
  163893. }
  163894. return (0);
  163895. }
  163896. #endif
  163897. #if defined(PNG_iCCP_SUPPORTED)
  163898. png_uint_32 PNGAPI
  163899. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163900. png_charpp name, int *compression_type,
  163901. png_charpp profile, png_uint_32 *proflen)
  163902. {
  163903. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163904. && name != NULL && profile != NULL && proflen != NULL)
  163905. {
  163906. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163907. *name = info_ptr->iccp_name;
  163908. *profile = info_ptr->iccp_profile;
  163909. *proflen = (int)info_ptr->iccp_proflen;
  163910. *compression_type = (int)info_ptr->iccp_compression;
  163911. return (PNG_INFO_iCCP);
  163912. }
  163913. return (0);
  163914. }
  163915. #endif
  163916. #if defined(PNG_sPLT_SUPPORTED)
  163917. png_uint_32 PNGAPI
  163918. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163919. png_sPLT_tpp spalettes)
  163920. {
  163921. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163922. {
  163923. *spalettes = info_ptr->splt_palettes;
  163924. return ((png_uint_32)info_ptr->splt_palettes_num);
  163925. }
  163926. return (0);
  163927. }
  163928. #endif
  163929. #if defined(PNG_hIST_SUPPORTED)
  163930. png_uint_32 PNGAPI
  163931. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163932. {
  163933. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163934. && hist != NULL)
  163935. {
  163936. png_debug1(1, "in %s retrieval function\n", "hIST");
  163937. *hist = info_ptr->hist;
  163938. return (PNG_INFO_hIST);
  163939. }
  163940. return (0);
  163941. }
  163942. #endif
  163943. png_uint_32 PNGAPI
  163944. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163945. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163946. int *color_type, int *interlace_type, int *compression_type,
  163947. int *filter_type)
  163948. {
  163949. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163950. bit_depth != NULL && color_type != NULL)
  163951. {
  163952. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163953. *width = info_ptr->width;
  163954. *height = info_ptr->height;
  163955. *bit_depth = info_ptr->bit_depth;
  163956. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163957. png_error(png_ptr, "Invalid bit depth");
  163958. *color_type = info_ptr->color_type;
  163959. if (info_ptr->color_type > 6)
  163960. png_error(png_ptr, "Invalid color type");
  163961. if (compression_type != NULL)
  163962. *compression_type = info_ptr->compression_type;
  163963. if (filter_type != NULL)
  163964. *filter_type = info_ptr->filter_type;
  163965. if (interlace_type != NULL)
  163966. *interlace_type = info_ptr->interlace_type;
  163967. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163968. png_error(png_ptr, "Invalid image width");
  163969. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163970. png_error(png_ptr, "Invalid image height");
  163971. if (info_ptr->width > (PNG_UINT_32_MAX
  163972. >> 3) /* 8-byte RGBA pixels */
  163973. - 64 /* bigrowbuf hack */
  163974. - 1 /* filter byte */
  163975. - 7*8 /* rounding of width to multiple of 8 pixels */
  163976. - 8) /* extra max_pixel_depth pad */
  163977. {
  163978. png_warning(png_ptr,
  163979. "Width too large for libpng to process image data.");
  163980. }
  163981. return (1);
  163982. }
  163983. return (0);
  163984. }
  163985. #if defined(PNG_oFFs_SUPPORTED)
  163986. png_uint_32 PNGAPI
  163987. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163988. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163989. {
  163990. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163991. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163992. {
  163993. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163994. *offset_x = info_ptr->x_offset;
  163995. *offset_y = info_ptr->y_offset;
  163996. *unit_type = (int)info_ptr->offset_unit_type;
  163997. return (PNG_INFO_oFFs);
  163998. }
  163999. return (0);
  164000. }
  164001. #endif
  164002. #if defined(PNG_pCAL_SUPPORTED)
  164003. png_uint_32 PNGAPI
  164004. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  164005. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  164006. png_charp *units, png_charpp *params)
  164007. {
  164008. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  164009. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  164010. nparams != NULL && units != NULL && params != NULL)
  164011. {
  164012. png_debug1(1, "in %s retrieval function\n", "pCAL");
  164013. *purpose = info_ptr->pcal_purpose;
  164014. *X0 = info_ptr->pcal_X0;
  164015. *X1 = info_ptr->pcal_X1;
  164016. *type = (int)info_ptr->pcal_type;
  164017. *nparams = (int)info_ptr->pcal_nparams;
  164018. *units = info_ptr->pcal_units;
  164019. *params = info_ptr->pcal_params;
  164020. return (PNG_INFO_pCAL);
  164021. }
  164022. return (0);
  164023. }
  164024. #endif
  164025. #if defined(PNG_sCAL_SUPPORTED)
  164026. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164027. png_uint_32 PNGAPI
  164028. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  164029. int *unit, double *width, double *height)
  164030. {
  164031. if (png_ptr != NULL && info_ptr != NULL &&
  164032. (info_ptr->valid & PNG_INFO_sCAL))
  164033. {
  164034. *unit = info_ptr->scal_unit;
  164035. *width = info_ptr->scal_pixel_width;
  164036. *height = info_ptr->scal_pixel_height;
  164037. return (PNG_INFO_sCAL);
  164038. }
  164039. return(0);
  164040. }
  164041. #else
  164042. #ifdef PNG_FIXED_POINT_SUPPORTED
  164043. png_uint_32 PNGAPI
  164044. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  164045. int *unit, png_charpp width, png_charpp height)
  164046. {
  164047. if (png_ptr != NULL && info_ptr != NULL &&
  164048. (info_ptr->valid & PNG_INFO_sCAL))
  164049. {
  164050. *unit = info_ptr->scal_unit;
  164051. *width = info_ptr->scal_s_width;
  164052. *height = info_ptr->scal_s_height;
  164053. return (PNG_INFO_sCAL);
  164054. }
  164055. return(0);
  164056. }
  164057. #endif
  164058. #endif
  164059. #endif
  164060. #if defined(PNG_pHYs_SUPPORTED)
  164061. png_uint_32 PNGAPI
  164062. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  164063. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164064. {
  164065. png_uint_32 retval = 0;
  164066. if (png_ptr != NULL && info_ptr != NULL &&
  164067. (info_ptr->valid & PNG_INFO_pHYs))
  164068. {
  164069. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164070. if (res_x != NULL)
  164071. {
  164072. *res_x = info_ptr->x_pixels_per_unit;
  164073. retval |= PNG_INFO_pHYs;
  164074. }
  164075. if (res_y != NULL)
  164076. {
  164077. *res_y = info_ptr->y_pixels_per_unit;
  164078. retval |= PNG_INFO_pHYs;
  164079. }
  164080. if (unit_type != NULL)
  164081. {
  164082. *unit_type = (int)info_ptr->phys_unit_type;
  164083. retval |= PNG_INFO_pHYs;
  164084. }
  164085. }
  164086. return (retval);
  164087. }
  164088. #endif
  164089. png_uint_32 PNGAPI
  164090. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  164091. int *num_palette)
  164092. {
  164093. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  164094. && palette != NULL)
  164095. {
  164096. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164097. *palette = info_ptr->palette;
  164098. *num_palette = info_ptr->num_palette;
  164099. png_debug1(3, "num_palette = %d\n", *num_palette);
  164100. return (PNG_INFO_PLTE);
  164101. }
  164102. return (0);
  164103. }
  164104. #if defined(PNG_sBIT_SUPPORTED)
  164105. png_uint_32 PNGAPI
  164106. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164107. {
  164108. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164109. && sig_bit != NULL)
  164110. {
  164111. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164112. *sig_bit = &(info_ptr->sig_bit);
  164113. return (PNG_INFO_sBIT);
  164114. }
  164115. return (0);
  164116. }
  164117. #endif
  164118. #if defined(PNG_TEXT_SUPPORTED)
  164119. png_uint_32 PNGAPI
  164120. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164121. int *num_text)
  164122. {
  164123. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164124. {
  164125. png_debug1(1, "in %s retrieval function\n",
  164126. (png_ptr->chunk_name[0] == '\0' ? "text"
  164127. : (png_const_charp)png_ptr->chunk_name));
  164128. if (text_ptr != NULL)
  164129. *text_ptr = info_ptr->text;
  164130. if (num_text != NULL)
  164131. *num_text = info_ptr->num_text;
  164132. return ((png_uint_32)info_ptr->num_text);
  164133. }
  164134. if (num_text != NULL)
  164135. *num_text = 0;
  164136. return(0);
  164137. }
  164138. #endif
  164139. #if defined(PNG_tIME_SUPPORTED)
  164140. png_uint_32 PNGAPI
  164141. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164142. {
  164143. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164144. && mod_time != NULL)
  164145. {
  164146. png_debug1(1, "in %s retrieval function\n", "tIME");
  164147. *mod_time = &(info_ptr->mod_time);
  164148. return (PNG_INFO_tIME);
  164149. }
  164150. return (0);
  164151. }
  164152. #endif
  164153. #if defined(PNG_tRNS_SUPPORTED)
  164154. png_uint_32 PNGAPI
  164155. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164156. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164157. {
  164158. png_uint_32 retval = 0;
  164159. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164160. {
  164161. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164162. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164163. {
  164164. if (trans != NULL)
  164165. {
  164166. *trans = info_ptr->trans;
  164167. retval |= PNG_INFO_tRNS;
  164168. }
  164169. if (trans_values != NULL)
  164170. *trans_values = &(info_ptr->trans_values);
  164171. }
  164172. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164173. {
  164174. if (trans_values != NULL)
  164175. {
  164176. *trans_values = &(info_ptr->trans_values);
  164177. retval |= PNG_INFO_tRNS;
  164178. }
  164179. if(trans != NULL)
  164180. *trans = NULL;
  164181. }
  164182. if(num_trans != NULL)
  164183. {
  164184. *num_trans = info_ptr->num_trans;
  164185. retval |= PNG_INFO_tRNS;
  164186. }
  164187. }
  164188. return (retval);
  164189. }
  164190. #endif
  164191. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164192. png_uint_32 PNGAPI
  164193. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164194. png_unknown_chunkpp unknowns)
  164195. {
  164196. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164197. {
  164198. *unknowns = info_ptr->unknown_chunks;
  164199. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164200. }
  164201. return (0);
  164202. }
  164203. #endif
  164204. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164205. png_byte PNGAPI
  164206. png_get_rgb_to_gray_status (png_structp png_ptr)
  164207. {
  164208. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164209. }
  164210. #endif
  164211. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164212. png_voidp PNGAPI
  164213. png_get_user_chunk_ptr(png_structp png_ptr)
  164214. {
  164215. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164216. }
  164217. #endif
  164218. #ifdef PNG_WRITE_SUPPORTED
  164219. png_uint_32 PNGAPI
  164220. png_get_compression_buffer_size(png_structp png_ptr)
  164221. {
  164222. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164223. }
  164224. #endif
  164225. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164226. #ifndef PNG_1_0_X
  164227. png_uint_32 PNGAPI
  164228. png_get_asm_flags (png_structp png_ptr)
  164229. {
  164230. return (png_ptr? 0L: 0L);
  164231. }
  164232. png_uint_32 PNGAPI
  164233. png_get_asm_flagmask (int flag_select)
  164234. {
  164235. flag_select=flag_select;
  164236. return 0L;
  164237. }
  164238. png_uint_32 PNGAPI
  164239. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164240. {
  164241. flag_select=flag_select;
  164242. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164243. return 0L;
  164244. }
  164245. png_byte PNGAPI
  164246. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164247. {
  164248. return (png_ptr? 0: 0);
  164249. }
  164250. png_uint_32 PNGAPI
  164251. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164252. {
  164253. return (png_ptr? 0L: 0L);
  164254. }
  164255. #endif /* ?PNG_1_0_X */
  164256. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164257. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164258. png_uint_32 PNGAPI
  164259. png_get_user_width_max (png_structp png_ptr)
  164260. {
  164261. return (png_ptr? png_ptr->user_width_max : 0);
  164262. }
  164263. png_uint_32 PNGAPI
  164264. png_get_user_height_max (png_structp png_ptr)
  164265. {
  164266. return (png_ptr? png_ptr->user_height_max : 0);
  164267. }
  164268. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164269. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164270. /*** End of inlined file: pngget.c ***/
  164271. /*** Start of inlined file: pngmem.c ***/
  164272. #define PNG_INTERNAL
  164273. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164274. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164275. png_voidp /* PRIVATE */
  164276. png_create_struct(int type)
  164277. {
  164278. #ifdef PNG_USER_MEM_SUPPORTED
  164279. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164280. }
  164281. png_voidp /* PRIVATE */
  164282. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164283. {
  164284. #endif /* PNG_USER_MEM_SUPPORTED */
  164285. png_size_t size;
  164286. png_voidp struct_ptr;
  164287. if (type == PNG_STRUCT_INFO)
  164288. size = png_sizeof(png_info);
  164289. else if (type == PNG_STRUCT_PNG)
  164290. size = png_sizeof(png_struct);
  164291. else
  164292. return (png_get_copyright(NULL));
  164293. #ifdef PNG_USER_MEM_SUPPORTED
  164294. if(malloc_fn != NULL)
  164295. {
  164296. png_struct dummy_struct;
  164297. png_structp png_ptr = &dummy_struct;
  164298. png_ptr->mem_ptr=mem_ptr;
  164299. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164300. }
  164301. else
  164302. #endif /* PNG_USER_MEM_SUPPORTED */
  164303. struct_ptr = (png_voidp)farmalloc(size);
  164304. if (struct_ptr != NULL)
  164305. png_memset(struct_ptr, 0, size);
  164306. return (struct_ptr);
  164307. }
  164308. void /* PRIVATE */
  164309. png_destroy_struct(png_voidp struct_ptr)
  164310. {
  164311. #ifdef PNG_USER_MEM_SUPPORTED
  164312. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164313. }
  164314. void /* PRIVATE */
  164315. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164316. png_voidp mem_ptr)
  164317. {
  164318. #endif
  164319. if (struct_ptr != NULL)
  164320. {
  164321. #ifdef PNG_USER_MEM_SUPPORTED
  164322. if(free_fn != NULL)
  164323. {
  164324. png_struct dummy_struct;
  164325. png_structp png_ptr = &dummy_struct;
  164326. png_ptr->mem_ptr=mem_ptr;
  164327. (*(free_fn))(png_ptr, struct_ptr);
  164328. return;
  164329. }
  164330. #endif /* PNG_USER_MEM_SUPPORTED */
  164331. farfree (struct_ptr);
  164332. }
  164333. }
  164334. png_voidp PNGAPI
  164335. png_malloc(png_structp png_ptr, png_uint_32 size)
  164336. {
  164337. png_voidp ret;
  164338. if (png_ptr == NULL || size == 0)
  164339. return (NULL);
  164340. #ifdef PNG_USER_MEM_SUPPORTED
  164341. if(png_ptr->malloc_fn != NULL)
  164342. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164343. else
  164344. ret = (png_malloc_default(png_ptr, size));
  164345. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164346. png_error(png_ptr, "Out of memory!");
  164347. return (ret);
  164348. }
  164349. png_voidp PNGAPI
  164350. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164351. {
  164352. png_voidp ret;
  164353. #endif /* PNG_USER_MEM_SUPPORTED */
  164354. if (png_ptr == NULL || size == 0)
  164355. return (NULL);
  164356. #ifdef PNG_MAX_MALLOC_64K
  164357. if (size > (png_uint_32)65536L)
  164358. {
  164359. png_warning(png_ptr, "Cannot Allocate > 64K");
  164360. ret = NULL;
  164361. }
  164362. else
  164363. #endif
  164364. if (size != (size_t)size)
  164365. ret = NULL;
  164366. else if (size == (png_uint_32)65536L)
  164367. {
  164368. if (png_ptr->offset_table == NULL)
  164369. {
  164370. ret = farmalloc(size);
  164371. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164372. {
  164373. int num_blocks;
  164374. png_uint_32 total_size;
  164375. png_bytep table;
  164376. int i;
  164377. png_byte huge * hptr;
  164378. if (ret != NULL)
  164379. {
  164380. farfree(ret);
  164381. ret = NULL;
  164382. }
  164383. if(png_ptr->zlib_window_bits > 14)
  164384. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164385. else
  164386. num_blocks = 1;
  164387. if (png_ptr->zlib_mem_level >= 7)
  164388. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164389. else
  164390. num_blocks++;
  164391. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164392. table = farmalloc(total_size);
  164393. if (table == NULL)
  164394. {
  164395. #ifndef PNG_USER_MEM_SUPPORTED
  164396. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164397. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164398. else
  164399. png_warning(png_ptr, "Out Of Memory.");
  164400. #endif
  164401. return (NULL);
  164402. }
  164403. if ((png_size_t)table & 0xfff0)
  164404. {
  164405. #ifndef PNG_USER_MEM_SUPPORTED
  164406. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164407. png_error(png_ptr,
  164408. "Farmalloc didn't return normalized pointer");
  164409. else
  164410. png_warning(png_ptr,
  164411. "Farmalloc didn't return normalized pointer");
  164412. #endif
  164413. return (NULL);
  164414. }
  164415. png_ptr->offset_table = table;
  164416. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164417. png_sizeof (png_bytep));
  164418. if (png_ptr->offset_table_ptr == NULL)
  164419. {
  164420. #ifndef PNG_USER_MEM_SUPPORTED
  164421. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164422. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164423. else
  164424. png_warning(png_ptr, "Out Of memory.");
  164425. #endif
  164426. return (NULL);
  164427. }
  164428. hptr = (png_byte huge *)table;
  164429. if ((png_size_t)hptr & 0xf)
  164430. {
  164431. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164432. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164433. }
  164434. for (i = 0; i < num_blocks; i++)
  164435. {
  164436. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164437. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164438. }
  164439. png_ptr->offset_table_number = num_blocks;
  164440. png_ptr->offset_table_count = 0;
  164441. png_ptr->offset_table_count_free = 0;
  164442. }
  164443. }
  164444. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164445. {
  164446. #ifndef PNG_USER_MEM_SUPPORTED
  164447. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164448. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164449. else
  164450. png_warning(png_ptr, "Out of Memory.");
  164451. #endif
  164452. return (NULL);
  164453. }
  164454. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164455. }
  164456. else
  164457. ret = farmalloc(size);
  164458. #ifndef PNG_USER_MEM_SUPPORTED
  164459. if (ret == NULL)
  164460. {
  164461. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164462. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164463. else
  164464. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164465. }
  164466. #endif
  164467. return (ret);
  164468. }
  164469. void PNGAPI
  164470. png_free(png_structp png_ptr, png_voidp ptr)
  164471. {
  164472. if (png_ptr == NULL || ptr == NULL)
  164473. return;
  164474. #ifdef PNG_USER_MEM_SUPPORTED
  164475. if (png_ptr->free_fn != NULL)
  164476. {
  164477. (*(png_ptr->free_fn))(png_ptr, ptr);
  164478. return;
  164479. }
  164480. else png_free_default(png_ptr, ptr);
  164481. }
  164482. void PNGAPI
  164483. png_free_default(png_structp png_ptr, png_voidp ptr)
  164484. {
  164485. #endif /* PNG_USER_MEM_SUPPORTED */
  164486. if(png_ptr == NULL) return;
  164487. if (png_ptr->offset_table != NULL)
  164488. {
  164489. int i;
  164490. for (i = 0; i < png_ptr->offset_table_count; i++)
  164491. {
  164492. if (ptr == png_ptr->offset_table_ptr[i])
  164493. {
  164494. ptr = NULL;
  164495. png_ptr->offset_table_count_free++;
  164496. break;
  164497. }
  164498. }
  164499. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164500. {
  164501. farfree(png_ptr->offset_table);
  164502. farfree(png_ptr->offset_table_ptr);
  164503. png_ptr->offset_table = NULL;
  164504. png_ptr->offset_table_ptr = NULL;
  164505. }
  164506. }
  164507. if (ptr != NULL)
  164508. {
  164509. farfree(ptr);
  164510. }
  164511. }
  164512. #else /* Not the Borland DOS special memory handler */
  164513. png_voidp /* PRIVATE */
  164514. png_create_struct(int type)
  164515. {
  164516. #ifdef PNG_USER_MEM_SUPPORTED
  164517. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164518. }
  164519. png_voidp /* PRIVATE */
  164520. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164521. {
  164522. #endif /* PNG_USER_MEM_SUPPORTED */
  164523. png_size_t size;
  164524. png_voidp struct_ptr;
  164525. if (type == PNG_STRUCT_INFO)
  164526. size = png_sizeof(png_info);
  164527. else if (type == PNG_STRUCT_PNG)
  164528. size = png_sizeof(png_struct);
  164529. else
  164530. return (NULL);
  164531. #ifdef PNG_USER_MEM_SUPPORTED
  164532. if(malloc_fn != NULL)
  164533. {
  164534. png_struct dummy_struct;
  164535. png_structp png_ptr = &dummy_struct;
  164536. png_ptr->mem_ptr=mem_ptr;
  164537. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164538. if (struct_ptr != NULL)
  164539. png_memset(struct_ptr, 0, size);
  164540. return (struct_ptr);
  164541. }
  164542. #endif /* PNG_USER_MEM_SUPPORTED */
  164543. #if defined(__TURBOC__) && !defined(__FLAT__)
  164544. struct_ptr = (png_voidp)farmalloc(size);
  164545. #else
  164546. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164547. struct_ptr = (png_voidp)halloc(size,1);
  164548. # else
  164549. struct_ptr = (png_voidp)malloc(size);
  164550. # endif
  164551. #endif
  164552. if (struct_ptr != NULL)
  164553. png_memset(struct_ptr, 0, size);
  164554. return (struct_ptr);
  164555. }
  164556. void /* PRIVATE */
  164557. png_destroy_struct(png_voidp struct_ptr)
  164558. {
  164559. #ifdef PNG_USER_MEM_SUPPORTED
  164560. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164561. }
  164562. void /* PRIVATE */
  164563. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164564. png_voidp mem_ptr)
  164565. {
  164566. #endif /* PNG_USER_MEM_SUPPORTED */
  164567. if (struct_ptr != NULL)
  164568. {
  164569. #ifdef PNG_USER_MEM_SUPPORTED
  164570. if(free_fn != NULL)
  164571. {
  164572. png_struct dummy_struct;
  164573. png_structp png_ptr = &dummy_struct;
  164574. png_ptr->mem_ptr=mem_ptr;
  164575. (*(free_fn))(png_ptr, struct_ptr);
  164576. return;
  164577. }
  164578. #endif /* PNG_USER_MEM_SUPPORTED */
  164579. #if defined(__TURBOC__) && !defined(__FLAT__)
  164580. farfree(struct_ptr);
  164581. #else
  164582. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164583. hfree(struct_ptr);
  164584. # else
  164585. free(struct_ptr);
  164586. # endif
  164587. #endif
  164588. }
  164589. }
  164590. png_voidp PNGAPI
  164591. png_malloc(png_structp png_ptr, png_uint_32 size)
  164592. {
  164593. png_voidp ret;
  164594. #ifdef PNG_USER_MEM_SUPPORTED
  164595. if (png_ptr == NULL || size == 0)
  164596. return (NULL);
  164597. if(png_ptr->malloc_fn != NULL)
  164598. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164599. else
  164600. ret = (png_malloc_default(png_ptr, size));
  164601. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164602. png_error(png_ptr, "Out of Memory!");
  164603. return (ret);
  164604. }
  164605. png_voidp PNGAPI
  164606. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164607. {
  164608. png_voidp ret;
  164609. #endif /* PNG_USER_MEM_SUPPORTED */
  164610. if (png_ptr == NULL || size == 0)
  164611. return (NULL);
  164612. #ifdef PNG_MAX_MALLOC_64K
  164613. if (size > (png_uint_32)65536L)
  164614. {
  164615. #ifndef PNG_USER_MEM_SUPPORTED
  164616. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164617. png_error(png_ptr, "Cannot Allocate > 64K");
  164618. else
  164619. #endif
  164620. return NULL;
  164621. }
  164622. #endif
  164623. #if defined(__TURBOC__) && !defined(__FLAT__)
  164624. if (size != (unsigned long)size)
  164625. ret = NULL;
  164626. else
  164627. ret = farmalloc(size);
  164628. #else
  164629. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164630. if (size != (unsigned long)size)
  164631. ret = NULL;
  164632. else
  164633. ret = halloc(size, 1);
  164634. # else
  164635. if (size != (size_t)size)
  164636. ret = NULL;
  164637. else
  164638. ret = malloc((size_t)size);
  164639. # endif
  164640. #endif
  164641. #ifndef PNG_USER_MEM_SUPPORTED
  164642. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164643. png_error(png_ptr, "Out of Memory");
  164644. #endif
  164645. return (ret);
  164646. }
  164647. void PNGAPI
  164648. png_free(png_structp png_ptr, png_voidp ptr)
  164649. {
  164650. if (png_ptr == NULL || ptr == NULL)
  164651. return;
  164652. #ifdef PNG_USER_MEM_SUPPORTED
  164653. if (png_ptr->free_fn != NULL)
  164654. {
  164655. (*(png_ptr->free_fn))(png_ptr, ptr);
  164656. return;
  164657. }
  164658. else png_free_default(png_ptr, ptr);
  164659. }
  164660. void PNGAPI
  164661. png_free_default(png_structp png_ptr, png_voidp ptr)
  164662. {
  164663. if (png_ptr == NULL || ptr == NULL)
  164664. return;
  164665. #endif /* PNG_USER_MEM_SUPPORTED */
  164666. #if defined(__TURBOC__) && !defined(__FLAT__)
  164667. farfree(ptr);
  164668. #else
  164669. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164670. hfree(ptr);
  164671. # else
  164672. free(ptr);
  164673. # endif
  164674. #endif
  164675. }
  164676. #endif /* Not Borland DOS special memory handler */
  164677. #if defined(PNG_1_0_X)
  164678. # define png_malloc_warn png_malloc
  164679. #else
  164680. png_voidp PNGAPI
  164681. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164682. {
  164683. png_voidp ptr;
  164684. png_uint_32 save_flags;
  164685. if(png_ptr == NULL) return (NULL);
  164686. save_flags=png_ptr->flags;
  164687. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164688. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164689. png_ptr->flags=save_flags;
  164690. return(ptr);
  164691. }
  164692. #endif
  164693. png_voidp PNGAPI
  164694. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164695. png_uint_32 length)
  164696. {
  164697. png_size_t size;
  164698. size = (png_size_t)length;
  164699. if ((png_uint_32)size != length)
  164700. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164701. return(png_memcpy (s1, s2, size));
  164702. }
  164703. png_voidp PNGAPI
  164704. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164705. png_uint_32 length)
  164706. {
  164707. png_size_t size;
  164708. size = (png_size_t)length;
  164709. if ((png_uint_32)size != length)
  164710. png_error(png_ptr,"Overflow in png_memset_check.");
  164711. return (png_memset (s1, value, size));
  164712. }
  164713. #ifdef PNG_USER_MEM_SUPPORTED
  164714. void PNGAPI
  164715. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164716. malloc_fn, png_free_ptr free_fn)
  164717. {
  164718. if(png_ptr != NULL) {
  164719. png_ptr->mem_ptr = mem_ptr;
  164720. png_ptr->malloc_fn = malloc_fn;
  164721. png_ptr->free_fn = free_fn;
  164722. }
  164723. }
  164724. png_voidp PNGAPI
  164725. png_get_mem_ptr(png_structp png_ptr)
  164726. {
  164727. if(png_ptr == NULL) return (NULL);
  164728. return ((png_voidp)png_ptr->mem_ptr);
  164729. }
  164730. #endif /* PNG_USER_MEM_SUPPORTED */
  164731. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164732. /*** End of inlined file: pngmem.c ***/
  164733. /*** Start of inlined file: pngread.c ***/
  164734. #define PNG_INTERNAL
  164735. #if defined(PNG_READ_SUPPORTED)
  164736. png_structp PNGAPI
  164737. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164738. png_error_ptr error_fn, png_error_ptr warn_fn)
  164739. {
  164740. #ifdef PNG_USER_MEM_SUPPORTED
  164741. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164742. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164743. }
  164744. png_structp PNGAPI
  164745. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164746. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164747. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164748. {
  164749. #endif /* PNG_USER_MEM_SUPPORTED */
  164750. png_structp png_ptr;
  164751. #ifdef PNG_SETJMP_SUPPORTED
  164752. #ifdef USE_FAR_KEYWORD
  164753. jmp_buf jmpbuf;
  164754. #endif
  164755. #endif
  164756. int i;
  164757. png_debug(1, "in png_create_read_struct\n");
  164758. #ifdef PNG_USER_MEM_SUPPORTED
  164759. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164760. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164761. #else
  164762. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164763. #endif
  164764. if (png_ptr == NULL)
  164765. return (NULL);
  164766. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164767. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164768. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164769. #endif
  164770. #ifdef PNG_SETJMP_SUPPORTED
  164771. #ifdef USE_FAR_KEYWORD
  164772. if (setjmp(jmpbuf))
  164773. #else
  164774. if (setjmp(png_ptr->jmpbuf))
  164775. #endif
  164776. {
  164777. png_free(png_ptr, png_ptr->zbuf);
  164778. png_ptr->zbuf=NULL;
  164779. #ifdef PNG_USER_MEM_SUPPORTED
  164780. png_destroy_struct_2((png_voidp)png_ptr,
  164781. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164782. #else
  164783. png_destroy_struct((png_voidp)png_ptr);
  164784. #endif
  164785. return (NULL);
  164786. }
  164787. #ifdef USE_FAR_KEYWORD
  164788. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164789. #endif
  164790. #endif
  164791. #ifdef PNG_USER_MEM_SUPPORTED
  164792. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164793. #endif
  164794. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164795. i=0;
  164796. do
  164797. {
  164798. if(user_png_ver[i] != png_libpng_ver[i])
  164799. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164800. } while (png_libpng_ver[i++]);
  164801. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164802. {
  164803. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164804. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164805. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164806. {
  164807. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164808. char msg[80];
  164809. if (user_png_ver)
  164810. {
  164811. png_snprintf(msg, 80,
  164812. "Application was compiled with png.h from libpng-%.20s",
  164813. user_png_ver);
  164814. png_warning(png_ptr, msg);
  164815. }
  164816. png_snprintf(msg, 80,
  164817. "Application is running with png.c from libpng-%.20s",
  164818. png_libpng_ver);
  164819. png_warning(png_ptr, msg);
  164820. #endif
  164821. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164822. png_ptr->flags=0;
  164823. #endif
  164824. png_error(png_ptr,
  164825. "Incompatible libpng version in application and library");
  164826. }
  164827. }
  164828. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164829. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164830. (png_uint_32)png_ptr->zbuf_size);
  164831. png_ptr->zstream.zalloc = png_zalloc;
  164832. png_ptr->zstream.zfree = png_zfree;
  164833. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164834. switch (inflateInit(&png_ptr->zstream))
  164835. {
  164836. case Z_OK: /* Do nothing */ break;
  164837. case Z_MEM_ERROR:
  164838. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164839. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164840. default: png_error(png_ptr, "Unknown zlib error");
  164841. }
  164842. png_ptr->zstream.next_out = png_ptr->zbuf;
  164843. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164844. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164845. #ifdef PNG_SETJMP_SUPPORTED
  164846. #ifdef USE_FAR_KEYWORD
  164847. if (setjmp(jmpbuf))
  164848. PNG_ABORT();
  164849. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164850. #else
  164851. if (setjmp(png_ptr->jmpbuf))
  164852. PNG_ABORT();
  164853. #endif
  164854. #endif
  164855. return (png_ptr);
  164856. }
  164857. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164858. #undef png_read_init
  164859. void PNGAPI
  164860. png_read_init(png_structp png_ptr)
  164861. {
  164862. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164863. }
  164864. void PNGAPI
  164865. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164866. png_size_t png_struct_size, png_size_t png_info_size)
  164867. {
  164868. if(png_ptr == NULL) return;
  164869. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164870. if(png_sizeof(png_struct) > png_struct_size ||
  164871. png_sizeof(png_info) > png_info_size)
  164872. {
  164873. char msg[80];
  164874. png_ptr->warning_fn=NULL;
  164875. if (user_png_ver)
  164876. {
  164877. png_snprintf(msg, 80,
  164878. "Application was compiled with png.h from libpng-%.20s",
  164879. user_png_ver);
  164880. png_warning(png_ptr, msg);
  164881. }
  164882. png_snprintf(msg, 80,
  164883. "Application is running with png.c from libpng-%.20s",
  164884. png_libpng_ver);
  164885. png_warning(png_ptr, msg);
  164886. }
  164887. #endif
  164888. if(png_sizeof(png_struct) > png_struct_size)
  164889. {
  164890. png_ptr->error_fn=NULL;
  164891. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164892. png_ptr->flags=0;
  164893. #endif
  164894. png_error(png_ptr,
  164895. "The png struct allocated by the application for reading is too small.");
  164896. }
  164897. if(png_sizeof(png_info) > png_info_size)
  164898. {
  164899. png_ptr->error_fn=NULL;
  164900. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164901. png_ptr->flags=0;
  164902. #endif
  164903. png_error(png_ptr,
  164904. "The info struct allocated by application for reading is too small.");
  164905. }
  164906. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164907. }
  164908. #endif /* PNG_1_0_X || PNG_1_2_X */
  164909. void PNGAPI
  164910. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164911. png_size_t png_struct_size)
  164912. {
  164913. #ifdef PNG_SETJMP_SUPPORTED
  164914. jmp_buf tmp_jmp; /* to save current jump buffer */
  164915. #endif
  164916. int i=0;
  164917. png_structp png_ptr=*ptr_ptr;
  164918. if(png_ptr == NULL) return;
  164919. do
  164920. {
  164921. if(user_png_ver[i] != png_libpng_ver[i])
  164922. {
  164923. #ifdef PNG_LEGACY_SUPPORTED
  164924. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164925. #else
  164926. png_ptr->warning_fn=NULL;
  164927. png_warning(png_ptr,
  164928. "Application uses deprecated png_read_init() and should be recompiled.");
  164929. break;
  164930. #endif
  164931. }
  164932. } while (png_libpng_ver[i++]);
  164933. png_debug(1, "in png_read_init_3\n");
  164934. #ifdef PNG_SETJMP_SUPPORTED
  164935. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164936. #endif
  164937. if(png_sizeof(png_struct) > png_struct_size)
  164938. {
  164939. png_destroy_struct(png_ptr);
  164940. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164941. png_ptr = *ptr_ptr;
  164942. }
  164943. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164944. #ifdef PNG_SETJMP_SUPPORTED
  164945. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164946. #endif
  164947. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164948. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164949. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164950. #endif
  164951. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164952. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164953. (png_uint_32)png_ptr->zbuf_size);
  164954. png_ptr->zstream.zalloc = png_zalloc;
  164955. png_ptr->zstream.zfree = png_zfree;
  164956. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164957. switch (inflateInit(&png_ptr->zstream))
  164958. {
  164959. case Z_OK: /* Do nothing */ break;
  164960. case Z_MEM_ERROR:
  164961. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164962. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164963. default: png_error(png_ptr, "Unknown zlib error");
  164964. }
  164965. png_ptr->zstream.next_out = png_ptr->zbuf;
  164966. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164967. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164968. }
  164969. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164970. void PNGAPI
  164971. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164972. {
  164973. if(png_ptr == NULL) return;
  164974. png_debug(1, "in png_read_info\n");
  164975. if (png_ptr->sig_bytes < 8)
  164976. {
  164977. png_size_t num_checked = png_ptr->sig_bytes,
  164978. num_to_check = 8 - num_checked;
  164979. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164980. png_ptr->sig_bytes = 8;
  164981. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164982. {
  164983. if (num_checked < 4 &&
  164984. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164985. png_error(png_ptr, "Not a PNG file");
  164986. else
  164987. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164988. }
  164989. if (num_checked < 3)
  164990. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164991. }
  164992. for(;;)
  164993. {
  164994. #ifdef PNG_USE_LOCAL_ARRAYS
  164995. PNG_CONST PNG_IHDR;
  164996. PNG_CONST PNG_IDAT;
  164997. PNG_CONST PNG_IEND;
  164998. PNG_CONST PNG_PLTE;
  164999. #if defined(PNG_READ_bKGD_SUPPORTED)
  165000. PNG_CONST PNG_bKGD;
  165001. #endif
  165002. #if defined(PNG_READ_cHRM_SUPPORTED)
  165003. PNG_CONST PNG_cHRM;
  165004. #endif
  165005. #if defined(PNG_READ_gAMA_SUPPORTED)
  165006. PNG_CONST PNG_gAMA;
  165007. #endif
  165008. #if defined(PNG_READ_hIST_SUPPORTED)
  165009. PNG_CONST PNG_hIST;
  165010. #endif
  165011. #if defined(PNG_READ_iCCP_SUPPORTED)
  165012. PNG_CONST PNG_iCCP;
  165013. #endif
  165014. #if defined(PNG_READ_iTXt_SUPPORTED)
  165015. PNG_CONST PNG_iTXt;
  165016. #endif
  165017. #if defined(PNG_READ_oFFs_SUPPORTED)
  165018. PNG_CONST PNG_oFFs;
  165019. #endif
  165020. #if defined(PNG_READ_pCAL_SUPPORTED)
  165021. PNG_CONST PNG_pCAL;
  165022. #endif
  165023. #if defined(PNG_READ_pHYs_SUPPORTED)
  165024. PNG_CONST PNG_pHYs;
  165025. #endif
  165026. #if defined(PNG_READ_sBIT_SUPPORTED)
  165027. PNG_CONST PNG_sBIT;
  165028. #endif
  165029. #if defined(PNG_READ_sCAL_SUPPORTED)
  165030. PNG_CONST PNG_sCAL;
  165031. #endif
  165032. #if defined(PNG_READ_sPLT_SUPPORTED)
  165033. PNG_CONST PNG_sPLT;
  165034. #endif
  165035. #if defined(PNG_READ_sRGB_SUPPORTED)
  165036. PNG_CONST PNG_sRGB;
  165037. #endif
  165038. #if defined(PNG_READ_tEXt_SUPPORTED)
  165039. PNG_CONST PNG_tEXt;
  165040. #endif
  165041. #if defined(PNG_READ_tIME_SUPPORTED)
  165042. PNG_CONST PNG_tIME;
  165043. #endif
  165044. #if defined(PNG_READ_tRNS_SUPPORTED)
  165045. PNG_CONST PNG_tRNS;
  165046. #endif
  165047. #if defined(PNG_READ_zTXt_SUPPORTED)
  165048. PNG_CONST PNG_zTXt;
  165049. #endif
  165050. #endif /* PNG_USE_LOCAL_ARRAYS */
  165051. png_byte chunk_length[4];
  165052. png_uint_32 length;
  165053. png_read_data(png_ptr, chunk_length, 4);
  165054. length = png_get_uint_31(png_ptr,chunk_length);
  165055. png_reset_crc(png_ptr);
  165056. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165057. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  165058. length);
  165059. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165060. if(png_ptr->mode & PNG_AFTER_IDAT)
  165061. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165062. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165063. png_handle_IHDR(png_ptr, info_ptr, length);
  165064. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165065. png_handle_IEND(png_ptr, info_ptr, length);
  165066. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165067. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165068. {
  165069. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165070. png_ptr->mode |= PNG_HAVE_IDAT;
  165071. png_handle_unknown(png_ptr, info_ptr, length);
  165072. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165073. png_ptr->mode |= PNG_HAVE_PLTE;
  165074. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165075. {
  165076. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165077. png_error(png_ptr, "Missing IHDR before IDAT");
  165078. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165079. !(png_ptr->mode & PNG_HAVE_PLTE))
  165080. png_error(png_ptr, "Missing PLTE before IDAT");
  165081. break;
  165082. }
  165083. }
  165084. #endif
  165085. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165086. png_handle_PLTE(png_ptr, info_ptr, length);
  165087. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165088. {
  165089. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165090. png_error(png_ptr, "Missing IHDR before IDAT");
  165091. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165092. !(png_ptr->mode & PNG_HAVE_PLTE))
  165093. png_error(png_ptr, "Missing PLTE before IDAT");
  165094. png_ptr->idat_size = length;
  165095. png_ptr->mode |= PNG_HAVE_IDAT;
  165096. break;
  165097. }
  165098. #if defined(PNG_READ_bKGD_SUPPORTED)
  165099. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165100. png_handle_bKGD(png_ptr, info_ptr, length);
  165101. #endif
  165102. #if defined(PNG_READ_cHRM_SUPPORTED)
  165103. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165104. png_handle_cHRM(png_ptr, info_ptr, length);
  165105. #endif
  165106. #if defined(PNG_READ_gAMA_SUPPORTED)
  165107. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165108. png_handle_gAMA(png_ptr, info_ptr, length);
  165109. #endif
  165110. #if defined(PNG_READ_hIST_SUPPORTED)
  165111. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165112. png_handle_hIST(png_ptr, info_ptr, length);
  165113. #endif
  165114. #if defined(PNG_READ_oFFs_SUPPORTED)
  165115. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165116. png_handle_oFFs(png_ptr, info_ptr, length);
  165117. #endif
  165118. #if defined(PNG_READ_pCAL_SUPPORTED)
  165119. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165120. png_handle_pCAL(png_ptr, info_ptr, length);
  165121. #endif
  165122. #if defined(PNG_READ_sCAL_SUPPORTED)
  165123. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165124. png_handle_sCAL(png_ptr, info_ptr, length);
  165125. #endif
  165126. #if defined(PNG_READ_pHYs_SUPPORTED)
  165127. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165128. png_handle_pHYs(png_ptr, info_ptr, length);
  165129. #endif
  165130. #if defined(PNG_READ_sBIT_SUPPORTED)
  165131. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165132. png_handle_sBIT(png_ptr, info_ptr, length);
  165133. #endif
  165134. #if defined(PNG_READ_sRGB_SUPPORTED)
  165135. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165136. png_handle_sRGB(png_ptr, info_ptr, length);
  165137. #endif
  165138. #if defined(PNG_READ_iCCP_SUPPORTED)
  165139. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165140. png_handle_iCCP(png_ptr, info_ptr, length);
  165141. #endif
  165142. #if defined(PNG_READ_sPLT_SUPPORTED)
  165143. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165144. png_handle_sPLT(png_ptr, info_ptr, length);
  165145. #endif
  165146. #if defined(PNG_READ_tEXt_SUPPORTED)
  165147. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165148. png_handle_tEXt(png_ptr, info_ptr, length);
  165149. #endif
  165150. #if defined(PNG_READ_tIME_SUPPORTED)
  165151. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165152. png_handle_tIME(png_ptr, info_ptr, length);
  165153. #endif
  165154. #if defined(PNG_READ_tRNS_SUPPORTED)
  165155. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165156. png_handle_tRNS(png_ptr, info_ptr, length);
  165157. #endif
  165158. #if defined(PNG_READ_zTXt_SUPPORTED)
  165159. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165160. png_handle_zTXt(png_ptr, info_ptr, length);
  165161. #endif
  165162. #if defined(PNG_READ_iTXt_SUPPORTED)
  165163. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165164. png_handle_iTXt(png_ptr, info_ptr, length);
  165165. #endif
  165166. else
  165167. png_handle_unknown(png_ptr, info_ptr, length);
  165168. }
  165169. }
  165170. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165171. void PNGAPI
  165172. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165173. {
  165174. png_debug(1, "in png_read_update_info\n");
  165175. if(png_ptr == NULL) return;
  165176. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165177. png_read_start_row(png_ptr);
  165178. else
  165179. png_warning(png_ptr,
  165180. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165181. png_read_transform_info(png_ptr, info_ptr);
  165182. }
  165183. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165184. void PNGAPI
  165185. png_start_read_image(png_structp png_ptr)
  165186. {
  165187. png_debug(1, "in png_start_read_image\n");
  165188. if(png_ptr == NULL) return;
  165189. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165190. png_read_start_row(png_ptr);
  165191. }
  165192. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165193. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165194. void PNGAPI
  165195. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165196. {
  165197. #ifdef PNG_USE_LOCAL_ARRAYS
  165198. PNG_CONST PNG_IDAT;
  165199. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165200. 0xff};
  165201. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165202. #endif
  165203. int ret;
  165204. if(png_ptr == NULL) return;
  165205. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165206. png_ptr->row_number, png_ptr->pass);
  165207. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165208. png_read_start_row(png_ptr);
  165209. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165210. {
  165211. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165212. if (png_ptr->transformations & PNG_INVERT_MONO)
  165213. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165214. #endif
  165215. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165216. if (png_ptr->transformations & PNG_FILLER)
  165217. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165218. #endif
  165219. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165220. if (png_ptr->transformations & PNG_PACKSWAP)
  165221. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165222. #endif
  165223. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165224. if (png_ptr->transformations & PNG_PACK)
  165225. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165226. #endif
  165227. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165228. if (png_ptr->transformations & PNG_SHIFT)
  165229. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165230. #endif
  165231. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165232. if (png_ptr->transformations & PNG_BGR)
  165233. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165234. #endif
  165235. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165236. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165237. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165238. #endif
  165239. }
  165240. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165241. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165242. {
  165243. switch (png_ptr->pass)
  165244. {
  165245. case 0:
  165246. if (png_ptr->row_number & 0x07)
  165247. {
  165248. if (dsp_row != NULL)
  165249. png_combine_row(png_ptr, dsp_row,
  165250. png_pass_dsp_mask[png_ptr->pass]);
  165251. png_read_finish_row(png_ptr);
  165252. return;
  165253. }
  165254. break;
  165255. case 1:
  165256. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165257. {
  165258. if (dsp_row != NULL)
  165259. png_combine_row(png_ptr, dsp_row,
  165260. png_pass_dsp_mask[png_ptr->pass]);
  165261. png_read_finish_row(png_ptr);
  165262. return;
  165263. }
  165264. break;
  165265. case 2:
  165266. if ((png_ptr->row_number & 0x07) != 4)
  165267. {
  165268. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165269. png_combine_row(png_ptr, dsp_row,
  165270. png_pass_dsp_mask[png_ptr->pass]);
  165271. png_read_finish_row(png_ptr);
  165272. return;
  165273. }
  165274. break;
  165275. case 3:
  165276. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165277. {
  165278. if (dsp_row != NULL)
  165279. png_combine_row(png_ptr, dsp_row,
  165280. png_pass_dsp_mask[png_ptr->pass]);
  165281. png_read_finish_row(png_ptr);
  165282. return;
  165283. }
  165284. break;
  165285. case 4:
  165286. if ((png_ptr->row_number & 3) != 2)
  165287. {
  165288. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165289. png_combine_row(png_ptr, dsp_row,
  165290. png_pass_dsp_mask[png_ptr->pass]);
  165291. png_read_finish_row(png_ptr);
  165292. return;
  165293. }
  165294. break;
  165295. case 5:
  165296. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165297. {
  165298. if (dsp_row != NULL)
  165299. png_combine_row(png_ptr, dsp_row,
  165300. png_pass_dsp_mask[png_ptr->pass]);
  165301. png_read_finish_row(png_ptr);
  165302. return;
  165303. }
  165304. break;
  165305. case 6:
  165306. if (!(png_ptr->row_number & 1))
  165307. {
  165308. png_read_finish_row(png_ptr);
  165309. return;
  165310. }
  165311. break;
  165312. }
  165313. }
  165314. #endif
  165315. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165316. png_error(png_ptr, "Invalid attempt to read row data");
  165317. png_ptr->zstream.next_out = png_ptr->row_buf;
  165318. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165319. do
  165320. {
  165321. if (!(png_ptr->zstream.avail_in))
  165322. {
  165323. while (!png_ptr->idat_size)
  165324. {
  165325. png_byte chunk_length[4];
  165326. png_crc_finish(png_ptr, 0);
  165327. png_read_data(png_ptr, chunk_length, 4);
  165328. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165329. png_reset_crc(png_ptr);
  165330. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165331. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165332. png_error(png_ptr, "Not enough image data");
  165333. }
  165334. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165335. png_ptr->zstream.next_in = png_ptr->zbuf;
  165336. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165337. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165338. png_crc_read(png_ptr, png_ptr->zbuf,
  165339. (png_size_t)png_ptr->zstream.avail_in);
  165340. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165341. }
  165342. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165343. if (ret == Z_STREAM_END)
  165344. {
  165345. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165346. png_ptr->idat_size)
  165347. png_error(png_ptr, "Extra compressed data");
  165348. png_ptr->mode |= PNG_AFTER_IDAT;
  165349. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165350. break;
  165351. }
  165352. if (ret != Z_OK)
  165353. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165354. "Decompression error");
  165355. } while (png_ptr->zstream.avail_out);
  165356. png_ptr->row_info.color_type = png_ptr->color_type;
  165357. png_ptr->row_info.width = png_ptr->iwidth;
  165358. png_ptr->row_info.channels = png_ptr->channels;
  165359. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165360. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165361. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165362. png_ptr->row_info.width);
  165363. if(png_ptr->row_buf[0])
  165364. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165365. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165366. (int)(png_ptr->row_buf[0]));
  165367. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165368. png_ptr->rowbytes + 1);
  165369. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165370. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165371. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165372. {
  165373. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165374. }
  165375. #endif
  165376. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165377. png_do_read_transformations(png_ptr);
  165378. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165379. if (png_ptr->interlaced &&
  165380. (png_ptr->transformations & PNG_INTERLACE))
  165381. {
  165382. if (png_ptr->pass < 6)
  165383. png_do_read_interlace(png_ptr);
  165384. if (dsp_row != NULL)
  165385. png_combine_row(png_ptr, dsp_row,
  165386. png_pass_dsp_mask[png_ptr->pass]);
  165387. if (row != NULL)
  165388. png_combine_row(png_ptr, row,
  165389. png_pass_mask[png_ptr->pass]);
  165390. }
  165391. else
  165392. #endif
  165393. {
  165394. if (row != NULL)
  165395. png_combine_row(png_ptr, row, 0xff);
  165396. if (dsp_row != NULL)
  165397. png_combine_row(png_ptr, dsp_row, 0xff);
  165398. }
  165399. png_read_finish_row(png_ptr);
  165400. if (png_ptr->read_row_fn != NULL)
  165401. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165402. }
  165403. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165404. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165405. void PNGAPI
  165406. png_read_rows(png_structp png_ptr, png_bytepp row,
  165407. png_bytepp display_row, png_uint_32 num_rows)
  165408. {
  165409. png_uint_32 i;
  165410. png_bytepp rp;
  165411. png_bytepp dp;
  165412. png_debug(1, "in png_read_rows\n");
  165413. if(png_ptr == NULL) return;
  165414. rp = row;
  165415. dp = display_row;
  165416. if (rp != NULL && dp != NULL)
  165417. for (i = 0; i < num_rows; i++)
  165418. {
  165419. png_bytep rptr = *rp++;
  165420. png_bytep dptr = *dp++;
  165421. png_read_row(png_ptr, rptr, dptr);
  165422. }
  165423. else if(rp != NULL)
  165424. for (i = 0; i < num_rows; i++)
  165425. {
  165426. png_bytep rptr = *rp;
  165427. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165428. rp++;
  165429. }
  165430. else if(dp != NULL)
  165431. for (i = 0; i < num_rows; i++)
  165432. {
  165433. png_bytep dptr = *dp;
  165434. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165435. dp++;
  165436. }
  165437. }
  165438. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165439. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165440. void PNGAPI
  165441. png_read_image(png_structp png_ptr, png_bytepp image)
  165442. {
  165443. png_uint_32 i,image_height;
  165444. int pass, j;
  165445. png_bytepp rp;
  165446. png_debug(1, "in png_read_image\n");
  165447. if(png_ptr == NULL) return;
  165448. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165449. pass = png_set_interlace_handling(png_ptr);
  165450. #else
  165451. if (png_ptr->interlaced)
  165452. png_error(png_ptr,
  165453. "Cannot read interlaced image -- interlace handler disabled.");
  165454. pass = 1;
  165455. #endif
  165456. image_height=png_ptr->height;
  165457. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165458. for (j = 0; j < pass; j++)
  165459. {
  165460. rp = image;
  165461. for (i = 0; i < image_height; i++)
  165462. {
  165463. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165464. rp++;
  165465. }
  165466. }
  165467. }
  165468. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165469. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165470. void PNGAPI
  165471. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165472. {
  165473. png_byte chunk_length[4];
  165474. png_uint_32 length;
  165475. png_debug(1, "in png_read_end\n");
  165476. if(png_ptr == NULL) return;
  165477. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165478. do
  165479. {
  165480. #ifdef PNG_USE_LOCAL_ARRAYS
  165481. PNG_CONST PNG_IHDR;
  165482. PNG_CONST PNG_IDAT;
  165483. PNG_CONST PNG_IEND;
  165484. PNG_CONST PNG_PLTE;
  165485. #if defined(PNG_READ_bKGD_SUPPORTED)
  165486. PNG_CONST PNG_bKGD;
  165487. #endif
  165488. #if defined(PNG_READ_cHRM_SUPPORTED)
  165489. PNG_CONST PNG_cHRM;
  165490. #endif
  165491. #if defined(PNG_READ_gAMA_SUPPORTED)
  165492. PNG_CONST PNG_gAMA;
  165493. #endif
  165494. #if defined(PNG_READ_hIST_SUPPORTED)
  165495. PNG_CONST PNG_hIST;
  165496. #endif
  165497. #if defined(PNG_READ_iCCP_SUPPORTED)
  165498. PNG_CONST PNG_iCCP;
  165499. #endif
  165500. #if defined(PNG_READ_iTXt_SUPPORTED)
  165501. PNG_CONST PNG_iTXt;
  165502. #endif
  165503. #if defined(PNG_READ_oFFs_SUPPORTED)
  165504. PNG_CONST PNG_oFFs;
  165505. #endif
  165506. #if defined(PNG_READ_pCAL_SUPPORTED)
  165507. PNG_CONST PNG_pCAL;
  165508. #endif
  165509. #if defined(PNG_READ_pHYs_SUPPORTED)
  165510. PNG_CONST PNG_pHYs;
  165511. #endif
  165512. #if defined(PNG_READ_sBIT_SUPPORTED)
  165513. PNG_CONST PNG_sBIT;
  165514. #endif
  165515. #if defined(PNG_READ_sCAL_SUPPORTED)
  165516. PNG_CONST PNG_sCAL;
  165517. #endif
  165518. #if defined(PNG_READ_sPLT_SUPPORTED)
  165519. PNG_CONST PNG_sPLT;
  165520. #endif
  165521. #if defined(PNG_READ_sRGB_SUPPORTED)
  165522. PNG_CONST PNG_sRGB;
  165523. #endif
  165524. #if defined(PNG_READ_tEXt_SUPPORTED)
  165525. PNG_CONST PNG_tEXt;
  165526. #endif
  165527. #if defined(PNG_READ_tIME_SUPPORTED)
  165528. PNG_CONST PNG_tIME;
  165529. #endif
  165530. #if defined(PNG_READ_tRNS_SUPPORTED)
  165531. PNG_CONST PNG_tRNS;
  165532. #endif
  165533. #if defined(PNG_READ_zTXt_SUPPORTED)
  165534. PNG_CONST PNG_zTXt;
  165535. #endif
  165536. #endif /* PNG_USE_LOCAL_ARRAYS */
  165537. png_read_data(png_ptr, chunk_length, 4);
  165538. length = png_get_uint_31(png_ptr,chunk_length);
  165539. png_reset_crc(png_ptr);
  165540. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165541. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165542. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165543. png_handle_IHDR(png_ptr, info_ptr, length);
  165544. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165545. png_handle_IEND(png_ptr, info_ptr, length);
  165546. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165547. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165548. {
  165549. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165550. {
  165551. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165552. png_error(png_ptr, "Too many IDAT's found");
  165553. }
  165554. png_handle_unknown(png_ptr, info_ptr, length);
  165555. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165556. png_ptr->mode |= PNG_HAVE_PLTE;
  165557. }
  165558. #endif
  165559. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165560. {
  165561. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165562. png_error(png_ptr, "Too many IDAT's found");
  165563. png_crc_finish(png_ptr, length);
  165564. }
  165565. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165566. png_handle_PLTE(png_ptr, info_ptr, length);
  165567. #if defined(PNG_READ_bKGD_SUPPORTED)
  165568. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165569. png_handle_bKGD(png_ptr, info_ptr, length);
  165570. #endif
  165571. #if defined(PNG_READ_cHRM_SUPPORTED)
  165572. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165573. png_handle_cHRM(png_ptr, info_ptr, length);
  165574. #endif
  165575. #if defined(PNG_READ_gAMA_SUPPORTED)
  165576. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165577. png_handle_gAMA(png_ptr, info_ptr, length);
  165578. #endif
  165579. #if defined(PNG_READ_hIST_SUPPORTED)
  165580. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165581. png_handle_hIST(png_ptr, info_ptr, length);
  165582. #endif
  165583. #if defined(PNG_READ_oFFs_SUPPORTED)
  165584. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165585. png_handle_oFFs(png_ptr, info_ptr, length);
  165586. #endif
  165587. #if defined(PNG_READ_pCAL_SUPPORTED)
  165588. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165589. png_handle_pCAL(png_ptr, info_ptr, length);
  165590. #endif
  165591. #if defined(PNG_READ_sCAL_SUPPORTED)
  165592. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165593. png_handle_sCAL(png_ptr, info_ptr, length);
  165594. #endif
  165595. #if defined(PNG_READ_pHYs_SUPPORTED)
  165596. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165597. png_handle_pHYs(png_ptr, info_ptr, length);
  165598. #endif
  165599. #if defined(PNG_READ_sBIT_SUPPORTED)
  165600. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165601. png_handle_sBIT(png_ptr, info_ptr, length);
  165602. #endif
  165603. #if defined(PNG_READ_sRGB_SUPPORTED)
  165604. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165605. png_handle_sRGB(png_ptr, info_ptr, length);
  165606. #endif
  165607. #if defined(PNG_READ_iCCP_SUPPORTED)
  165608. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165609. png_handle_iCCP(png_ptr, info_ptr, length);
  165610. #endif
  165611. #if defined(PNG_READ_sPLT_SUPPORTED)
  165612. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165613. png_handle_sPLT(png_ptr, info_ptr, length);
  165614. #endif
  165615. #if defined(PNG_READ_tEXt_SUPPORTED)
  165616. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165617. png_handle_tEXt(png_ptr, info_ptr, length);
  165618. #endif
  165619. #if defined(PNG_READ_tIME_SUPPORTED)
  165620. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165621. png_handle_tIME(png_ptr, info_ptr, length);
  165622. #endif
  165623. #if defined(PNG_READ_tRNS_SUPPORTED)
  165624. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165625. png_handle_tRNS(png_ptr, info_ptr, length);
  165626. #endif
  165627. #if defined(PNG_READ_zTXt_SUPPORTED)
  165628. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165629. png_handle_zTXt(png_ptr, info_ptr, length);
  165630. #endif
  165631. #if defined(PNG_READ_iTXt_SUPPORTED)
  165632. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165633. png_handle_iTXt(png_ptr, info_ptr, length);
  165634. #endif
  165635. else
  165636. png_handle_unknown(png_ptr, info_ptr, length);
  165637. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165638. }
  165639. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165640. void PNGAPI
  165641. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165642. png_infopp end_info_ptr_ptr)
  165643. {
  165644. png_structp png_ptr = NULL;
  165645. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165646. #ifdef PNG_USER_MEM_SUPPORTED
  165647. png_free_ptr free_fn;
  165648. png_voidp mem_ptr;
  165649. #endif
  165650. png_debug(1, "in png_destroy_read_struct\n");
  165651. if (png_ptr_ptr != NULL)
  165652. png_ptr = *png_ptr_ptr;
  165653. if (info_ptr_ptr != NULL)
  165654. info_ptr = *info_ptr_ptr;
  165655. if (end_info_ptr_ptr != NULL)
  165656. end_info_ptr = *end_info_ptr_ptr;
  165657. #ifdef PNG_USER_MEM_SUPPORTED
  165658. free_fn = png_ptr->free_fn;
  165659. mem_ptr = png_ptr->mem_ptr;
  165660. #endif
  165661. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165662. if (info_ptr != NULL)
  165663. {
  165664. #if defined(PNG_TEXT_SUPPORTED)
  165665. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165666. #endif
  165667. #ifdef PNG_USER_MEM_SUPPORTED
  165668. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165669. (png_voidp)mem_ptr);
  165670. #else
  165671. png_destroy_struct((png_voidp)info_ptr);
  165672. #endif
  165673. *info_ptr_ptr = NULL;
  165674. }
  165675. if (end_info_ptr != NULL)
  165676. {
  165677. #if defined(PNG_READ_TEXT_SUPPORTED)
  165678. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165679. #endif
  165680. #ifdef PNG_USER_MEM_SUPPORTED
  165681. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165682. (png_voidp)mem_ptr);
  165683. #else
  165684. png_destroy_struct((png_voidp)end_info_ptr);
  165685. #endif
  165686. *end_info_ptr_ptr = NULL;
  165687. }
  165688. if (png_ptr != NULL)
  165689. {
  165690. #ifdef PNG_USER_MEM_SUPPORTED
  165691. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165692. (png_voidp)mem_ptr);
  165693. #else
  165694. png_destroy_struct((png_voidp)png_ptr);
  165695. #endif
  165696. *png_ptr_ptr = NULL;
  165697. }
  165698. }
  165699. void /* PRIVATE */
  165700. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165701. {
  165702. #ifdef PNG_SETJMP_SUPPORTED
  165703. jmp_buf tmp_jmp;
  165704. #endif
  165705. png_error_ptr error_fn;
  165706. png_error_ptr warning_fn;
  165707. png_voidp error_ptr;
  165708. #ifdef PNG_USER_MEM_SUPPORTED
  165709. png_free_ptr free_fn;
  165710. #endif
  165711. png_debug(1, "in png_read_destroy\n");
  165712. if (info_ptr != NULL)
  165713. png_info_destroy(png_ptr, info_ptr);
  165714. if (end_info_ptr != NULL)
  165715. png_info_destroy(png_ptr, end_info_ptr);
  165716. png_free(png_ptr, png_ptr->zbuf);
  165717. png_free(png_ptr, png_ptr->big_row_buf);
  165718. png_free(png_ptr, png_ptr->prev_row);
  165719. #if defined(PNG_READ_DITHER_SUPPORTED)
  165720. png_free(png_ptr, png_ptr->palette_lookup);
  165721. png_free(png_ptr, png_ptr->dither_index);
  165722. #endif
  165723. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165724. png_free(png_ptr, png_ptr->gamma_table);
  165725. #endif
  165726. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165727. png_free(png_ptr, png_ptr->gamma_from_1);
  165728. png_free(png_ptr, png_ptr->gamma_to_1);
  165729. #endif
  165730. #ifdef PNG_FREE_ME_SUPPORTED
  165731. if (png_ptr->free_me & PNG_FREE_PLTE)
  165732. png_zfree(png_ptr, png_ptr->palette);
  165733. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165734. #else
  165735. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165736. png_zfree(png_ptr, png_ptr->palette);
  165737. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165738. #endif
  165739. #if defined(PNG_tRNS_SUPPORTED) || \
  165740. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165741. #ifdef PNG_FREE_ME_SUPPORTED
  165742. if (png_ptr->free_me & PNG_FREE_TRNS)
  165743. png_free(png_ptr, png_ptr->trans);
  165744. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165745. #else
  165746. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165747. png_free(png_ptr, png_ptr->trans);
  165748. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165749. #endif
  165750. #endif
  165751. #if defined(PNG_READ_hIST_SUPPORTED)
  165752. #ifdef PNG_FREE_ME_SUPPORTED
  165753. if (png_ptr->free_me & PNG_FREE_HIST)
  165754. png_free(png_ptr, png_ptr->hist);
  165755. png_ptr->free_me &= ~PNG_FREE_HIST;
  165756. #else
  165757. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165758. png_free(png_ptr, png_ptr->hist);
  165759. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165760. #endif
  165761. #endif
  165762. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165763. if (png_ptr->gamma_16_table != NULL)
  165764. {
  165765. int i;
  165766. int istop = (1 << (8 - png_ptr->gamma_shift));
  165767. for (i = 0; i < istop; i++)
  165768. {
  165769. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165770. }
  165771. png_free(png_ptr, png_ptr->gamma_16_table);
  165772. }
  165773. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165774. if (png_ptr->gamma_16_from_1 != NULL)
  165775. {
  165776. int i;
  165777. int istop = (1 << (8 - png_ptr->gamma_shift));
  165778. for (i = 0; i < istop; i++)
  165779. {
  165780. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165781. }
  165782. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165783. }
  165784. if (png_ptr->gamma_16_to_1 != NULL)
  165785. {
  165786. int i;
  165787. int istop = (1 << (8 - png_ptr->gamma_shift));
  165788. for (i = 0; i < istop; i++)
  165789. {
  165790. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165791. }
  165792. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165793. }
  165794. #endif
  165795. #endif
  165796. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165797. png_free(png_ptr, png_ptr->time_buffer);
  165798. #endif
  165799. inflateEnd(&png_ptr->zstream);
  165800. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165801. png_free(png_ptr, png_ptr->save_buffer);
  165802. #endif
  165803. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165804. #ifdef PNG_TEXT_SUPPORTED
  165805. png_free(png_ptr, png_ptr->current_text);
  165806. #endif /* PNG_TEXT_SUPPORTED */
  165807. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165808. #ifdef PNG_SETJMP_SUPPORTED
  165809. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165810. #endif
  165811. error_fn = png_ptr->error_fn;
  165812. warning_fn = png_ptr->warning_fn;
  165813. error_ptr = png_ptr->error_ptr;
  165814. #ifdef PNG_USER_MEM_SUPPORTED
  165815. free_fn = png_ptr->free_fn;
  165816. #endif
  165817. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165818. png_ptr->error_fn = error_fn;
  165819. png_ptr->warning_fn = warning_fn;
  165820. png_ptr->error_ptr = error_ptr;
  165821. #ifdef PNG_USER_MEM_SUPPORTED
  165822. png_ptr->free_fn = free_fn;
  165823. #endif
  165824. #ifdef PNG_SETJMP_SUPPORTED
  165825. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165826. #endif
  165827. }
  165828. void PNGAPI
  165829. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165830. {
  165831. if(png_ptr == NULL) return;
  165832. png_ptr->read_row_fn = read_row_fn;
  165833. }
  165834. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165835. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165836. void PNGAPI
  165837. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165838. int transforms,
  165839. voidp params)
  165840. {
  165841. int row;
  165842. if(png_ptr == NULL) return;
  165843. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165844. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165845. png_set_invert_alpha(png_ptr);
  165846. #endif
  165847. png_read_info(png_ptr, info_ptr);
  165848. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165849. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165850. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165851. if (transforms & PNG_TRANSFORM_STRIP_16)
  165852. png_set_strip_16(png_ptr);
  165853. #endif
  165854. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165855. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165856. png_set_strip_alpha(png_ptr);
  165857. #endif
  165858. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165859. if (transforms & PNG_TRANSFORM_PACKING)
  165860. png_set_packing(png_ptr);
  165861. #endif
  165862. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165863. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165864. png_set_packswap(png_ptr);
  165865. #endif
  165866. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165867. if (transforms & PNG_TRANSFORM_EXPAND)
  165868. if ((png_ptr->bit_depth < 8) ||
  165869. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165870. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165871. png_set_expand(png_ptr);
  165872. #endif
  165873. #if defined(PNG_READ_INVERT_SUPPORTED)
  165874. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165875. png_set_invert_mono(png_ptr);
  165876. #endif
  165877. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165878. if ((transforms & PNG_TRANSFORM_SHIFT)
  165879. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165880. {
  165881. png_color_8p sig_bit;
  165882. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165883. png_set_shift(png_ptr, sig_bit);
  165884. }
  165885. #endif
  165886. #if defined(PNG_READ_BGR_SUPPORTED)
  165887. if (transforms & PNG_TRANSFORM_BGR)
  165888. png_set_bgr(png_ptr);
  165889. #endif
  165890. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165891. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165892. png_set_swap_alpha(png_ptr);
  165893. #endif
  165894. #if defined(PNG_READ_SWAP_SUPPORTED)
  165895. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165896. png_set_swap(png_ptr);
  165897. #endif
  165898. png_read_update_info(png_ptr, info_ptr);
  165899. #ifdef PNG_FREE_ME_SUPPORTED
  165900. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165901. #endif
  165902. if(info_ptr->row_pointers == NULL)
  165903. {
  165904. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165905. info_ptr->height * png_sizeof(png_bytep));
  165906. #ifdef PNG_FREE_ME_SUPPORTED
  165907. info_ptr->free_me |= PNG_FREE_ROWS;
  165908. #endif
  165909. for (row = 0; row < (int)info_ptr->height; row++)
  165910. {
  165911. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165912. png_get_rowbytes(png_ptr, info_ptr));
  165913. }
  165914. }
  165915. png_read_image(png_ptr, info_ptr->row_pointers);
  165916. info_ptr->valid |= PNG_INFO_IDAT;
  165917. png_read_end(png_ptr, info_ptr);
  165918. transforms = transforms; /* quiet compiler warnings */
  165919. params = params;
  165920. }
  165921. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165922. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165923. #endif /* PNG_READ_SUPPORTED */
  165924. /*** End of inlined file: pngread.c ***/
  165925. /*** Start of inlined file: pngpread.c ***/
  165926. #define PNG_INTERNAL
  165927. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165928. #define PNG_READ_SIG_MODE 0
  165929. #define PNG_READ_CHUNK_MODE 1
  165930. #define PNG_READ_IDAT_MODE 2
  165931. #define PNG_SKIP_MODE 3
  165932. #define PNG_READ_tEXt_MODE 4
  165933. #define PNG_READ_zTXt_MODE 5
  165934. #define PNG_READ_DONE_MODE 6
  165935. #define PNG_READ_iTXt_MODE 7
  165936. #define PNG_ERROR_MODE 8
  165937. void PNGAPI
  165938. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165939. png_bytep buffer, png_size_t buffer_size)
  165940. {
  165941. if(png_ptr == NULL) return;
  165942. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165943. while (png_ptr->buffer_size)
  165944. {
  165945. png_process_some_data(png_ptr, info_ptr);
  165946. }
  165947. }
  165948. void /* PRIVATE */
  165949. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165950. {
  165951. if(png_ptr == NULL) return;
  165952. switch (png_ptr->process_mode)
  165953. {
  165954. case PNG_READ_SIG_MODE:
  165955. {
  165956. png_push_read_sig(png_ptr, info_ptr);
  165957. break;
  165958. }
  165959. case PNG_READ_CHUNK_MODE:
  165960. {
  165961. png_push_read_chunk(png_ptr, info_ptr);
  165962. break;
  165963. }
  165964. case PNG_READ_IDAT_MODE:
  165965. {
  165966. png_push_read_IDAT(png_ptr);
  165967. break;
  165968. }
  165969. #if defined(PNG_READ_tEXt_SUPPORTED)
  165970. case PNG_READ_tEXt_MODE:
  165971. {
  165972. png_push_read_tEXt(png_ptr, info_ptr);
  165973. break;
  165974. }
  165975. #endif
  165976. #if defined(PNG_READ_zTXt_SUPPORTED)
  165977. case PNG_READ_zTXt_MODE:
  165978. {
  165979. png_push_read_zTXt(png_ptr, info_ptr);
  165980. break;
  165981. }
  165982. #endif
  165983. #if defined(PNG_READ_iTXt_SUPPORTED)
  165984. case PNG_READ_iTXt_MODE:
  165985. {
  165986. png_push_read_iTXt(png_ptr, info_ptr);
  165987. break;
  165988. }
  165989. #endif
  165990. case PNG_SKIP_MODE:
  165991. {
  165992. png_push_crc_finish(png_ptr);
  165993. break;
  165994. }
  165995. default:
  165996. {
  165997. png_ptr->buffer_size = 0;
  165998. break;
  165999. }
  166000. }
  166001. }
  166002. void /* PRIVATE */
  166003. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  166004. {
  166005. png_size_t num_checked = png_ptr->sig_bytes,
  166006. num_to_check = 8 - num_checked;
  166007. if (png_ptr->buffer_size < num_to_check)
  166008. {
  166009. num_to_check = png_ptr->buffer_size;
  166010. }
  166011. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  166012. num_to_check);
  166013. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  166014. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  166015. {
  166016. if (num_checked < 4 &&
  166017. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  166018. png_error(png_ptr, "Not a PNG file");
  166019. else
  166020. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  166021. }
  166022. else
  166023. {
  166024. if (png_ptr->sig_bytes >= 8)
  166025. {
  166026. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166027. }
  166028. }
  166029. }
  166030. void /* PRIVATE */
  166031. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  166032. {
  166033. #ifdef PNG_USE_LOCAL_ARRAYS
  166034. PNG_CONST PNG_IHDR;
  166035. PNG_CONST PNG_IDAT;
  166036. PNG_CONST PNG_IEND;
  166037. PNG_CONST PNG_PLTE;
  166038. #if defined(PNG_READ_bKGD_SUPPORTED)
  166039. PNG_CONST PNG_bKGD;
  166040. #endif
  166041. #if defined(PNG_READ_cHRM_SUPPORTED)
  166042. PNG_CONST PNG_cHRM;
  166043. #endif
  166044. #if defined(PNG_READ_gAMA_SUPPORTED)
  166045. PNG_CONST PNG_gAMA;
  166046. #endif
  166047. #if defined(PNG_READ_hIST_SUPPORTED)
  166048. PNG_CONST PNG_hIST;
  166049. #endif
  166050. #if defined(PNG_READ_iCCP_SUPPORTED)
  166051. PNG_CONST PNG_iCCP;
  166052. #endif
  166053. #if defined(PNG_READ_iTXt_SUPPORTED)
  166054. PNG_CONST PNG_iTXt;
  166055. #endif
  166056. #if defined(PNG_READ_oFFs_SUPPORTED)
  166057. PNG_CONST PNG_oFFs;
  166058. #endif
  166059. #if defined(PNG_READ_pCAL_SUPPORTED)
  166060. PNG_CONST PNG_pCAL;
  166061. #endif
  166062. #if defined(PNG_READ_pHYs_SUPPORTED)
  166063. PNG_CONST PNG_pHYs;
  166064. #endif
  166065. #if defined(PNG_READ_sBIT_SUPPORTED)
  166066. PNG_CONST PNG_sBIT;
  166067. #endif
  166068. #if defined(PNG_READ_sCAL_SUPPORTED)
  166069. PNG_CONST PNG_sCAL;
  166070. #endif
  166071. #if defined(PNG_READ_sRGB_SUPPORTED)
  166072. PNG_CONST PNG_sRGB;
  166073. #endif
  166074. #if defined(PNG_READ_sPLT_SUPPORTED)
  166075. PNG_CONST PNG_sPLT;
  166076. #endif
  166077. #if defined(PNG_READ_tEXt_SUPPORTED)
  166078. PNG_CONST PNG_tEXt;
  166079. #endif
  166080. #if defined(PNG_READ_tIME_SUPPORTED)
  166081. PNG_CONST PNG_tIME;
  166082. #endif
  166083. #if defined(PNG_READ_tRNS_SUPPORTED)
  166084. PNG_CONST PNG_tRNS;
  166085. #endif
  166086. #if defined(PNG_READ_zTXt_SUPPORTED)
  166087. PNG_CONST PNG_zTXt;
  166088. #endif
  166089. #endif /* PNG_USE_LOCAL_ARRAYS */
  166090. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166091. {
  166092. png_byte chunk_length[4];
  166093. if (png_ptr->buffer_size < 8)
  166094. {
  166095. png_push_save_buffer(png_ptr);
  166096. return;
  166097. }
  166098. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166099. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166100. png_reset_crc(png_ptr);
  166101. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166102. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166103. }
  166104. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166105. if(png_ptr->mode & PNG_AFTER_IDAT)
  166106. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166107. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  166108. {
  166109. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166110. {
  166111. png_push_save_buffer(png_ptr);
  166112. return;
  166113. }
  166114. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166115. }
  166116. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  166117. {
  166118. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166119. {
  166120. png_push_save_buffer(png_ptr);
  166121. return;
  166122. }
  166123. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166124. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166125. png_push_have_end(png_ptr, info_ptr);
  166126. }
  166127. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166128. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166129. {
  166130. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166131. {
  166132. png_push_save_buffer(png_ptr);
  166133. return;
  166134. }
  166135. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166136. png_ptr->mode |= PNG_HAVE_IDAT;
  166137. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166138. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166139. png_ptr->mode |= PNG_HAVE_PLTE;
  166140. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166141. {
  166142. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166143. png_error(png_ptr, "Missing IHDR before IDAT");
  166144. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166145. !(png_ptr->mode & PNG_HAVE_PLTE))
  166146. png_error(png_ptr, "Missing PLTE before IDAT");
  166147. }
  166148. }
  166149. #endif
  166150. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166151. {
  166152. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166153. {
  166154. png_push_save_buffer(png_ptr);
  166155. return;
  166156. }
  166157. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166158. }
  166159. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166160. {
  166161. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166162. png_error(png_ptr, "Missing IHDR before IDAT");
  166163. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166164. !(png_ptr->mode & PNG_HAVE_PLTE))
  166165. png_error(png_ptr, "Missing PLTE before IDAT");
  166166. if (png_ptr->mode & PNG_HAVE_IDAT)
  166167. {
  166168. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166169. if (png_ptr->push_length == 0)
  166170. return;
  166171. if (png_ptr->mode & PNG_AFTER_IDAT)
  166172. png_error(png_ptr, "Too many IDAT's found");
  166173. }
  166174. png_ptr->idat_size = png_ptr->push_length;
  166175. png_ptr->mode |= PNG_HAVE_IDAT;
  166176. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166177. png_push_have_info(png_ptr, info_ptr);
  166178. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166179. png_ptr->zstream.next_out = png_ptr->row_buf;
  166180. return;
  166181. }
  166182. #if defined(PNG_READ_gAMA_SUPPORTED)
  166183. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166184. {
  166185. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166186. {
  166187. png_push_save_buffer(png_ptr);
  166188. return;
  166189. }
  166190. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166191. }
  166192. #endif
  166193. #if defined(PNG_READ_sBIT_SUPPORTED)
  166194. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166195. {
  166196. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166197. {
  166198. png_push_save_buffer(png_ptr);
  166199. return;
  166200. }
  166201. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166202. }
  166203. #endif
  166204. #if defined(PNG_READ_cHRM_SUPPORTED)
  166205. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166206. {
  166207. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166208. {
  166209. png_push_save_buffer(png_ptr);
  166210. return;
  166211. }
  166212. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166213. }
  166214. #endif
  166215. #if defined(PNG_READ_sRGB_SUPPORTED)
  166216. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166217. {
  166218. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166219. {
  166220. png_push_save_buffer(png_ptr);
  166221. return;
  166222. }
  166223. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166224. }
  166225. #endif
  166226. #if defined(PNG_READ_iCCP_SUPPORTED)
  166227. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166228. {
  166229. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166230. {
  166231. png_push_save_buffer(png_ptr);
  166232. return;
  166233. }
  166234. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166235. }
  166236. #endif
  166237. #if defined(PNG_READ_sPLT_SUPPORTED)
  166238. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166239. {
  166240. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166241. {
  166242. png_push_save_buffer(png_ptr);
  166243. return;
  166244. }
  166245. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166246. }
  166247. #endif
  166248. #if defined(PNG_READ_tRNS_SUPPORTED)
  166249. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166250. {
  166251. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166252. {
  166253. png_push_save_buffer(png_ptr);
  166254. return;
  166255. }
  166256. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166257. }
  166258. #endif
  166259. #if defined(PNG_READ_bKGD_SUPPORTED)
  166260. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166261. {
  166262. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166263. {
  166264. png_push_save_buffer(png_ptr);
  166265. return;
  166266. }
  166267. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166268. }
  166269. #endif
  166270. #if defined(PNG_READ_hIST_SUPPORTED)
  166271. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166272. {
  166273. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166274. {
  166275. png_push_save_buffer(png_ptr);
  166276. return;
  166277. }
  166278. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166279. }
  166280. #endif
  166281. #if defined(PNG_READ_pHYs_SUPPORTED)
  166282. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  166283. {
  166284. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166285. {
  166286. png_push_save_buffer(png_ptr);
  166287. return;
  166288. }
  166289. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166290. }
  166291. #endif
  166292. #if defined(PNG_READ_oFFs_SUPPORTED)
  166293. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166294. {
  166295. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166296. {
  166297. png_push_save_buffer(png_ptr);
  166298. return;
  166299. }
  166300. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166301. }
  166302. #endif
  166303. #if defined(PNG_READ_pCAL_SUPPORTED)
  166304. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166305. {
  166306. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166307. {
  166308. png_push_save_buffer(png_ptr);
  166309. return;
  166310. }
  166311. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166312. }
  166313. #endif
  166314. #if defined(PNG_READ_sCAL_SUPPORTED)
  166315. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166316. {
  166317. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166318. {
  166319. png_push_save_buffer(png_ptr);
  166320. return;
  166321. }
  166322. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166323. }
  166324. #endif
  166325. #if defined(PNG_READ_tIME_SUPPORTED)
  166326. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166327. {
  166328. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166329. {
  166330. png_push_save_buffer(png_ptr);
  166331. return;
  166332. }
  166333. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166334. }
  166335. #endif
  166336. #if defined(PNG_READ_tEXt_SUPPORTED)
  166337. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166338. {
  166339. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166340. {
  166341. png_push_save_buffer(png_ptr);
  166342. return;
  166343. }
  166344. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166345. }
  166346. #endif
  166347. #if defined(PNG_READ_zTXt_SUPPORTED)
  166348. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166349. {
  166350. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166351. {
  166352. png_push_save_buffer(png_ptr);
  166353. return;
  166354. }
  166355. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166356. }
  166357. #endif
  166358. #if defined(PNG_READ_iTXt_SUPPORTED)
  166359. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166360. {
  166361. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166362. {
  166363. png_push_save_buffer(png_ptr);
  166364. return;
  166365. }
  166366. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166367. }
  166368. #endif
  166369. else
  166370. {
  166371. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166372. {
  166373. png_push_save_buffer(png_ptr);
  166374. return;
  166375. }
  166376. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166377. }
  166378. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166379. }
  166380. void /* PRIVATE */
  166381. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166382. {
  166383. png_ptr->process_mode = PNG_SKIP_MODE;
  166384. png_ptr->skip_length = skip;
  166385. }
  166386. void /* PRIVATE */
  166387. png_push_crc_finish(png_structp png_ptr)
  166388. {
  166389. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166390. {
  166391. png_size_t save_size;
  166392. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166393. save_size = (png_size_t)png_ptr->skip_length;
  166394. else
  166395. save_size = png_ptr->save_buffer_size;
  166396. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166397. png_ptr->skip_length -= save_size;
  166398. png_ptr->buffer_size -= save_size;
  166399. png_ptr->save_buffer_size -= save_size;
  166400. png_ptr->save_buffer_ptr += save_size;
  166401. }
  166402. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166403. {
  166404. png_size_t save_size;
  166405. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166406. save_size = (png_size_t)png_ptr->skip_length;
  166407. else
  166408. save_size = png_ptr->current_buffer_size;
  166409. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166410. png_ptr->skip_length -= save_size;
  166411. png_ptr->buffer_size -= save_size;
  166412. png_ptr->current_buffer_size -= save_size;
  166413. png_ptr->current_buffer_ptr += save_size;
  166414. }
  166415. if (!png_ptr->skip_length)
  166416. {
  166417. if (png_ptr->buffer_size < 4)
  166418. {
  166419. png_push_save_buffer(png_ptr);
  166420. return;
  166421. }
  166422. png_crc_finish(png_ptr, 0);
  166423. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166424. }
  166425. }
  166426. void PNGAPI
  166427. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166428. {
  166429. png_bytep ptr;
  166430. if(png_ptr == NULL) return;
  166431. ptr = buffer;
  166432. if (png_ptr->save_buffer_size)
  166433. {
  166434. png_size_t save_size;
  166435. if (length < png_ptr->save_buffer_size)
  166436. save_size = length;
  166437. else
  166438. save_size = png_ptr->save_buffer_size;
  166439. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166440. length -= save_size;
  166441. ptr += save_size;
  166442. png_ptr->buffer_size -= save_size;
  166443. png_ptr->save_buffer_size -= save_size;
  166444. png_ptr->save_buffer_ptr += save_size;
  166445. }
  166446. if (length && png_ptr->current_buffer_size)
  166447. {
  166448. png_size_t save_size;
  166449. if (length < png_ptr->current_buffer_size)
  166450. save_size = length;
  166451. else
  166452. save_size = png_ptr->current_buffer_size;
  166453. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166454. png_ptr->buffer_size -= save_size;
  166455. png_ptr->current_buffer_size -= save_size;
  166456. png_ptr->current_buffer_ptr += save_size;
  166457. }
  166458. }
  166459. void /* PRIVATE */
  166460. png_push_save_buffer(png_structp png_ptr)
  166461. {
  166462. if (png_ptr->save_buffer_size)
  166463. {
  166464. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166465. {
  166466. png_size_t i,istop;
  166467. png_bytep sp;
  166468. png_bytep dp;
  166469. istop = png_ptr->save_buffer_size;
  166470. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166471. i < istop; i++, sp++, dp++)
  166472. {
  166473. *dp = *sp;
  166474. }
  166475. }
  166476. }
  166477. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166478. png_ptr->save_buffer_max)
  166479. {
  166480. png_size_t new_max;
  166481. png_bytep old_buffer;
  166482. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166483. (png_ptr->current_buffer_size + 256))
  166484. {
  166485. png_error(png_ptr, "Potential overflow of save_buffer");
  166486. }
  166487. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166488. old_buffer = png_ptr->save_buffer;
  166489. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166490. (png_uint_32)new_max);
  166491. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166492. png_free(png_ptr, old_buffer);
  166493. png_ptr->save_buffer_max = new_max;
  166494. }
  166495. if (png_ptr->current_buffer_size)
  166496. {
  166497. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166498. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166499. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166500. png_ptr->current_buffer_size = 0;
  166501. }
  166502. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166503. png_ptr->buffer_size = 0;
  166504. }
  166505. void /* PRIVATE */
  166506. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166507. png_size_t buffer_length)
  166508. {
  166509. png_ptr->current_buffer = buffer;
  166510. png_ptr->current_buffer_size = buffer_length;
  166511. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166512. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166513. }
  166514. void /* PRIVATE */
  166515. png_push_read_IDAT(png_structp png_ptr)
  166516. {
  166517. #ifdef PNG_USE_LOCAL_ARRAYS
  166518. PNG_CONST PNG_IDAT;
  166519. #endif
  166520. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166521. {
  166522. png_byte chunk_length[4];
  166523. if (png_ptr->buffer_size < 8)
  166524. {
  166525. png_push_save_buffer(png_ptr);
  166526. return;
  166527. }
  166528. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166529. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166530. png_reset_crc(png_ptr);
  166531. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166532. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166533. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166534. {
  166535. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166536. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166537. png_error(png_ptr, "Not enough compressed data");
  166538. return;
  166539. }
  166540. png_ptr->idat_size = png_ptr->push_length;
  166541. }
  166542. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166543. {
  166544. png_size_t save_size;
  166545. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166546. {
  166547. save_size = (png_size_t)png_ptr->idat_size;
  166548. if((png_uint_32)save_size != png_ptr->idat_size)
  166549. png_error(png_ptr, "save_size overflowed in pngpread");
  166550. }
  166551. else
  166552. save_size = png_ptr->save_buffer_size;
  166553. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166554. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166555. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166556. png_ptr->idat_size -= save_size;
  166557. png_ptr->buffer_size -= save_size;
  166558. png_ptr->save_buffer_size -= save_size;
  166559. png_ptr->save_buffer_ptr += save_size;
  166560. }
  166561. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166562. {
  166563. png_size_t save_size;
  166564. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166565. {
  166566. save_size = (png_size_t)png_ptr->idat_size;
  166567. if((png_uint_32)save_size != png_ptr->idat_size)
  166568. png_error(png_ptr, "save_size overflowed in pngpread");
  166569. }
  166570. else
  166571. save_size = png_ptr->current_buffer_size;
  166572. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166573. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166574. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166575. png_ptr->idat_size -= save_size;
  166576. png_ptr->buffer_size -= save_size;
  166577. png_ptr->current_buffer_size -= save_size;
  166578. png_ptr->current_buffer_ptr += save_size;
  166579. }
  166580. if (!png_ptr->idat_size)
  166581. {
  166582. if (png_ptr->buffer_size < 4)
  166583. {
  166584. png_push_save_buffer(png_ptr);
  166585. return;
  166586. }
  166587. png_crc_finish(png_ptr, 0);
  166588. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166589. png_ptr->mode |= PNG_AFTER_IDAT;
  166590. }
  166591. }
  166592. void /* PRIVATE */
  166593. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166594. png_size_t buffer_length)
  166595. {
  166596. int ret;
  166597. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166598. png_error(png_ptr, "Extra compression data");
  166599. png_ptr->zstream.next_in = buffer;
  166600. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166601. for(;;)
  166602. {
  166603. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166604. if (ret != Z_OK)
  166605. {
  166606. if (ret == Z_STREAM_END)
  166607. {
  166608. if (png_ptr->zstream.avail_in)
  166609. png_error(png_ptr, "Extra compressed data");
  166610. if (!(png_ptr->zstream.avail_out))
  166611. {
  166612. png_push_process_row(png_ptr);
  166613. }
  166614. png_ptr->mode |= PNG_AFTER_IDAT;
  166615. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166616. break;
  166617. }
  166618. else if (ret == Z_BUF_ERROR)
  166619. break;
  166620. else
  166621. png_error(png_ptr, "Decompression Error");
  166622. }
  166623. if (!(png_ptr->zstream.avail_out))
  166624. {
  166625. if ((
  166626. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166627. png_ptr->interlaced && png_ptr->pass > 6) ||
  166628. (!png_ptr->interlaced &&
  166629. #endif
  166630. png_ptr->row_number == png_ptr->num_rows))
  166631. {
  166632. if (png_ptr->zstream.avail_in)
  166633. {
  166634. png_warning(png_ptr, "Too much data in IDAT chunks");
  166635. }
  166636. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166637. break;
  166638. }
  166639. png_push_process_row(png_ptr);
  166640. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166641. png_ptr->zstream.next_out = png_ptr->row_buf;
  166642. }
  166643. else
  166644. break;
  166645. }
  166646. }
  166647. void /* PRIVATE */
  166648. png_push_process_row(png_structp png_ptr)
  166649. {
  166650. png_ptr->row_info.color_type = png_ptr->color_type;
  166651. png_ptr->row_info.width = png_ptr->iwidth;
  166652. png_ptr->row_info.channels = png_ptr->channels;
  166653. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166654. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166655. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166656. png_ptr->row_info.width);
  166657. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166658. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166659. (int)(png_ptr->row_buf[0]));
  166660. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166661. png_ptr->rowbytes + 1);
  166662. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166663. png_do_read_transformations(png_ptr);
  166664. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166665. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166666. {
  166667. if (png_ptr->pass < 6)
  166668. png_do_read_interlace(png_ptr);
  166669. switch (png_ptr->pass)
  166670. {
  166671. case 0:
  166672. {
  166673. int i;
  166674. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166675. {
  166676. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166677. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166678. }
  166679. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166680. {
  166681. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166682. {
  166683. png_push_have_row(png_ptr, png_bytep_NULL);
  166684. png_read_push_finish_row(png_ptr);
  166685. }
  166686. }
  166687. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166688. {
  166689. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166690. {
  166691. png_push_have_row(png_ptr, png_bytep_NULL);
  166692. png_read_push_finish_row(png_ptr);
  166693. }
  166694. }
  166695. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166696. {
  166697. png_push_have_row(png_ptr, png_bytep_NULL);
  166698. png_read_push_finish_row(png_ptr);
  166699. }
  166700. break;
  166701. }
  166702. case 1:
  166703. {
  166704. int i;
  166705. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166706. {
  166707. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166708. png_read_push_finish_row(png_ptr);
  166709. }
  166710. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166711. {
  166712. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166713. {
  166714. png_push_have_row(png_ptr, png_bytep_NULL);
  166715. png_read_push_finish_row(png_ptr);
  166716. }
  166717. }
  166718. break;
  166719. }
  166720. case 2:
  166721. {
  166722. int i;
  166723. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166724. {
  166725. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166726. png_read_push_finish_row(png_ptr);
  166727. }
  166728. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166729. {
  166730. png_push_have_row(png_ptr, png_bytep_NULL);
  166731. png_read_push_finish_row(png_ptr);
  166732. }
  166733. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166734. {
  166735. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166736. {
  166737. png_push_have_row(png_ptr, png_bytep_NULL);
  166738. png_read_push_finish_row(png_ptr);
  166739. }
  166740. }
  166741. break;
  166742. }
  166743. case 3:
  166744. {
  166745. int i;
  166746. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166747. {
  166748. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166749. png_read_push_finish_row(png_ptr);
  166750. }
  166751. if (png_ptr->pass == 4) /* skip top two generated rows */
  166752. {
  166753. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166754. {
  166755. png_push_have_row(png_ptr, png_bytep_NULL);
  166756. png_read_push_finish_row(png_ptr);
  166757. }
  166758. }
  166759. break;
  166760. }
  166761. case 4:
  166762. {
  166763. int i;
  166764. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166765. {
  166766. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166767. png_read_push_finish_row(png_ptr);
  166768. }
  166769. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166770. {
  166771. png_push_have_row(png_ptr, png_bytep_NULL);
  166772. png_read_push_finish_row(png_ptr);
  166773. }
  166774. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166775. {
  166776. png_push_have_row(png_ptr, png_bytep_NULL);
  166777. png_read_push_finish_row(png_ptr);
  166778. }
  166779. break;
  166780. }
  166781. case 5:
  166782. {
  166783. int i;
  166784. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166785. {
  166786. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166787. png_read_push_finish_row(png_ptr);
  166788. }
  166789. if (png_ptr->pass == 6) /* skip top generated row */
  166790. {
  166791. png_push_have_row(png_ptr, png_bytep_NULL);
  166792. png_read_push_finish_row(png_ptr);
  166793. }
  166794. break;
  166795. }
  166796. case 6:
  166797. {
  166798. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166799. png_read_push_finish_row(png_ptr);
  166800. if (png_ptr->pass != 6)
  166801. break;
  166802. png_push_have_row(png_ptr, png_bytep_NULL);
  166803. png_read_push_finish_row(png_ptr);
  166804. }
  166805. }
  166806. }
  166807. else
  166808. #endif
  166809. {
  166810. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166811. png_read_push_finish_row(png_ptr);
  166812. }
  166813. }
  166814. void /* PRIVATE */
  166815. png_read_push_finish_row(png_structp png_ptr)
  166816. {
  166817. #ifdef PNG_USE_LOCAL_ARRAYS
  166818. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166819. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166820. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166821. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166822. #endif
  166823. png_ptr->row_number++;
  166824. if (png_ptr->row_number < png_ptr->num_rows)
  166825. return;
  166826. if (png_ptr->interlaced)
  166827. {
  166828. png_ptr->row_number = 0;
  166829. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166830. png_ptr->rowbytes + 1);
  166831. do
  166832. {
  166833. png_ptr->pass++;
  166834. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166835. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166836. (png_ptr->pass == 5 && png_ptr->width < 2))
  166837. png_ptr->pass++;
  166838. if (png_ptr->pass > 7)
  166839. png_ptr->pass--;
  166840. if (png_ptr->pass >= 7)
  166841. break;
  166842. png_ptr->iwidth = (png_ptr->width +
  166843. png_pass_inc[png_ptr->pass] - 1 -
  166844. png_pass_start[png_ptr->pass]) /
  166845. png_pass_inc[png_ptr->pass];
  166846. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166847. png_ptr->iwidth) + 1;
  166848. if (png_ptr->transformations & PNG_INTERLACE)
  166849. break;
  166850. png_ptr->num_rows = (png_ptr->height +
  166851. png_pass_yinc[png_ptr->pass] - 1 -
  166852. png_pass_ystart[png_ptr->pass]) /
  166853. png_pass_yinc[png_ptr->pass];
  166854. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166855. }
  166856. }
  166857. #if defined(PNG_READ_tEXt_SUPPORTED)
  166858. void /* PRIVATE */
  166859. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166860. length)
  166861. {
  166862. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166863. {
  166864. png_error(png_ptr, "Out of place tEXt");
  166865. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166866. }
  166867. #ifdef PNG_MAX_MALLOC_64K
  166868. png_ptr->skip_length = 0; /* This may not be necessary */
  166869. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166870. {
  166871. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166872. png_ptr->skip_length = length - (png_uint_32)65535L;
  166873. length = (png_uint_32)65535L;
  166874. }
  166875. #endif
  166876. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166877. (png_uint_32)(length+1));
  166878. png_ptr->current_text[length] = '\0';
  166879. png_ptr->current_text_ptr = png_ptr->current_text;
  166880. png_ptr->current_text_size = (png_size_t)length;
  166881. png_ptr->current_text_left = (png_size_t)length;
  166882. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166883. }
  166884. void /* PRIVATE */
  166885. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166886. {
  166887. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166888. {
  166889. png_size_t text_size;
  166890. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166891. text_size = png_ptr->buffer_size;
  166892. else
  166893. text_size = png_ptr->current_text_left;
  166894. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166895. png_ptr->current_text_left -= text_size;
  166896. png_ptr->current_text_ptr += text_size;
  166897. }
  166898. if (!(png_ptr->current_text_left))
  166899. {
  166900. png_textp text_ptr;
  166901. png_charp text;
  166902. png_charp key;
  166903. int ret;
  166904. if (png_ptr->buffer_size < 4)
  166905. {
  166906. png_push_save_buffer(png_ptr);
  166907. return;
  166908. }
  166909. png_push_crc_finish(png_ptr);
  166910. #if defined(PNG_MAX_MALLOC_64K)
  166911. if (png_ptr->skip_length)
  166912. return;
  166913. #endif
  166914. key = png_ptr->current_text;
  166915. for (text = key; *text; text++)
  166916. ;
  166917. if (text < key + png_ptr->current_text_size)
  166918. text++;
  166919. text_ptr = (png_textp)png_malloc(png_ptr,
  166920. (png_uint_32)png_sizeof(png_text));
  166921. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166922. text_ptr->key = key;
  166923. #ifdef PNG_iTXt_SUPPORTED
  166924. text_ptr->lang = NULL;
  166925. text_ptr->lang_key = NULL;
  166926. #endif
  166927. text_ptr->text = text;
  166928. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166929. png_free(png_ptr, key);
  166930. png_free(png_ptr, text_ptr);
  166931. png_ptr->current_text = NULL;
  166932. if (ret)
  166933. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166934. }
  166935. }
  166936. #endif
  166937. #if defined(PNG_READ_zTXt_SUPPORTED)
  166938. void /* PRIVATE */
  166939. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166940. length)
  166941. {
  166942. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166943. {
  166944. png_error(png_ptr, "Out of place zTXt");
  166945. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166946. }
  166947. #ifdef PNG_MAX_MALLOC_64K
  166948. if (length > (png_uint_32)65535L)
  166949. {
  166950. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166951. png_push_crc_skip(png_ptr, length);
  166952. return;
  166953. }
  166954. #endif
  166955. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166956. (png_uint_32)(length+1));
  166957. png_ptr->current_text[length] = '\0';
  166958. png_ptr->current_text_ptr = png_ptr->current_text;
  166959. png_ptr->current_text_size = (png_size_t)length;
  166960. png_ptr->current_text_left = (png_size_t)length;
  166961. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166962. }
  166963. void /* PRIVATE */
  166964. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166965. {
  166966. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166967. {
  166968. png_size_t text_size;
  166969. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166970. text_size = png_ptr->buffer_size;
  166971. else
  166972. text_size = png_ptr->current_text_left;
  166973. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166974. png_ptr->current_text_left -= text_size;
  166975. png_ptr->current_text_ptr += text_size;
  166976. }
  166977. if (!(png_ptr->current_text_left))
  166978. {
  166979. png_textp text_ptr;
  166980. png_charp text;
  166981. png_charp key;
  166982. int ret;
  166983. png_size_t text_size, key_size;
  166984. if (png_ptr->buffer_size < 4)
  166985. {
  166986. png_push_save_buffer(png_ptr);
  166987. return;
  166988. }
  166989. png_push_crc_finish(png_ptr);
  166990. key = png_ptr->current_text;
  166991. for (text = key; *text; text++)
  166992. ;
  166993. if (text >= key + png_ptr->current_text_size)
  166994. {
  166995. png_ptr->current_text = NULL;
  166996. png_free(png_ptr, key);
  166997. return;
  166998. }
  166999. text++;
  167000. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  167001. {
  167002. png_ptr->current_text = NULL;
  167003. png_free(png_ptr, key);
  167004. return;
  167005. }
  167006. text++;
  167007. png_ptr->zstream.next_in = (png_bytep )text;
  167008. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  167009. (text - key));
  167010. png_ptr->zstream.next_out = png_ptr->zbuf;
  167011. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167012. key_size = text - key;
  167013. text_size = 0;
  167014. text = NULL;
  167015. ret = Z_STREAM_END;
  167016. while (png_ptr->zstream.avail_in)
  167017. {
  167018. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  167019. if (ret != Z_OK && ret != Z_STREAM_END)
  167020. {
  167021. inflateReset(&png_ptr->zstream);
  167022. png_ptr->zstream.avail_in = 0;
  167023. png_ptr->current_text = NULL;
  167024. png_free(png_ptr, key);
  167025. png_free(png_ptr, text);
  167026. return;
  167027. }
  167028. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  167029. {
  167030. if (text == NULL)
  167031. {
  167032. text = (png_charp)png_malloc(png_ptr,
  167033. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167034. + key_size + 1));
  167035. png_memcpy(text + key_size, png_ptr->zbuf,
  167036. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167037. png_memcpy(text, key, key_size);
  167038. text_size = key_size + png_ptr->zbuf_size -
  167039. png_ptr->zstream.avail_out;
  167040. *(text + text_size) = '\0';
  167041. }
  167042. else
  167043. {
  167044. png_charp tmp;
  167045. tmp = text;
  167046. text = (png_charp)png_malloc(png_ptr, text_size +
  167047. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167048. + 1));
  167049. png_memcpy(text, tmp, text_size);
  167050. png_free(png_ptr, tmp);
  167051. png_memcpy(text + text_size, png_ptr->zbuf,
  167052. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167053. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  167054. *(text + text_size) = '\0';
  167055. }
  167056. if (ret != Z_STREAM_END)
  167057. {
  167058. png_ptr->zstream.next_out = png_ptr->zbuf;
  167059. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167060. }
  167061. }
  167062. else
  167063. {
  167064. break;
  167065. }
  167066. if (ret == Z_STREAM_END)
  167067. break;
  167068. }
  167069. inflateReset(&png_ptr->zstream);
  167070. png_ptr->zstream.avail_in = 0;
  167071. if (ret != Z_STREAM_END)
  167072. {
  167073. png_ptr->current_text = NULL;
  167074. png_free(png_ptr, key);
  167075. png_free(png_ptr, text);
  167076. return;
  167077. }
  167078. png_ptr->current_text = NULL;
  167079. png_free(png_ptr, key);
  167080. key = text;
  167081. text += key_size;
  167082. text_ptr = (png_textp)png_malloc(png_ptr,
  167083. (png_uint_32)png_sizeof(png_text));
  167084. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  167085. text_ptr->key = key;
  167086. #ifdef PNG_iTXt_SUPPORTED
  167087. text_ptr->lang = NULL;
  167088. text_ptr->lang_key = NULL;
  167089. #endif
  167090. text_ptr->text = text;
  167091. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167092. png_free(png_ptr, key);
  167093. png_free(png_ptr, text_ptr);
  167094. if (ret)
  167095. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167096. }
  167097. }
  167098. #endif
  167099. #if defined(PNG_READ_iTXt_SUPPORTED)
  167100. void /* PRIVATE */
  167101. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167102. length)
  167103. {
  167104. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167105. {
  167106. png_error(png_ptr, "Out of place iTXt");
  167107. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167108. }
  167109. #ifdef PNG_MAX_MALLOC_64K
  167110. png_ptr->skip_length = 0; /* This may not be necessary */
  167111. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167112. {
  167113. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167114. png_ptr->skip_length = length - (png_uint_32)65535L;
  167115. length = (png_uint_32)65535L;
  167116. }
  167117. #endif
  167118. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167119. (png_uint_32)(length+1));
  167120. png_ptr->current_text[length] = '\0';
  167121. png_ptr->current_text_ptr = png_ptr->current_text;
  167122. png_ptr->current_text_size = (png_size_t)length;
  167123. png_ptr->current_text_left = (png_size_t)length;
  167124. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167125. }
  167126. void /* PRIVATE */
  167127. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167128. {
  167129. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167130. {
  167131. png_size_t text_size;
  167132. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167133. text_size = png_ptr->buffer_size;
  167134. else
  167135. text_size = png_ptr->current_text_left;
  167136. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167137. png_ptr->current_text_left -= text_size;
  167138. png_ptr->current_text_ptr += text_size;
  167139. }
  167140. if (!(png_ptr->current_text_left))
  167141. {
  167142. png_textp text_ptr;
  167143. png_charp key;
  167144. int comp_flag;
  167145. png_charp lang;
  167146. png_charp lang_key;
  167147. png_charp text;
  167148. int ret;
  167149. if (png_ptr->buffer_size < 4)
  167150. {
  167151. png_push_save_buffer(png_ptr);
  167152. return;
  167153. }
  167154. png_push_crc_finish(png_ptr);
  167155. #if defined(PNG_MAX_MALLOC_64K)
  167156. if (png_ptr->skip_length)
  167157. return;
  167158. #endif
  167159. key = png_ptr->current_text;
  167160. for (lang = key; *lang; lang++)
  167161. ;
  167162. if (lang < key + png_ptr->current_text_size - 3)
  167163. lang++;
  167164. comp_flag = *lang++;
  167165. lang++; /* skip comp_type, always zero */
  167166. for (lang_key = lang; *lang_key; lang_key++)
  167167. ;
  167168. lang_key++; /* skip NUL separator */
  167169. text=lang_key;
  167170. if (lang_key < key + png_ptr->current_text_size - 1)
  167171. {
  167172. for (; *text; text++)
  167173. ;
  167174. }
  167175. if (text < key + png_ptr->current_text_size)
  167176. text++;
  167177. text_ptr = (png_textp)png_malloc(png_ptr,
  167178. (png_uint_32)png_sizeof(png_text));
  167179. text_ptr->compression = comp_flag + 2;
  167180. text_ptr->key = key;
  167181. text_ptr->lang = lang;
  167182. text_ptr->lang_key = lang_key;
  167183. text_ptr->text = text;
  167184. text_ptr->text_length = 0;
  167185. text_ptr->itxt_length = png_strlen(text);
  167186. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167187. png_ptr->current_text = NULL;
  167188. png_free(png_ptr, text_ptr);
  167189. if (ret)
  167190. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167191. }
  167192. }
  167193. #endif
  167194. void /* PRIVATE */
  167195. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167196. length)
  167197. {
  167198. png_uint_32 skip=0;
  167199. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167200. if (!(png_ptr->chunk_name[0] & 0x20))
  167201. {
  167202. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167203. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167204. PNG_HANDLE_CHUNK_ALWAYS
  167205. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167206. && png_ptr->read_user_chunk_fn == NULL
  167207. #endif
  167208. )
  167209. #endif
  167210. png_chunk_error(png_ptr, "unknown critical chunk");
  167211. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167212. }
  167213. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167214. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167215. {
  167216. #ifdef PNG_MAX_MALLOC_64K
  167217. if (length > (png_uint_32)65535L)
  167218. {
  167219. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167220. skip = length - (png_uint_32)65535L;
  167221. length = (png_uint_32)65535L;
  167222. }
  167223. #endif
  167224. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167225. (png_charp)png_ptr->chunk_name, 5);
  167226. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167227. png_ptr->unknown_chunk.size = (png_size_t)length;
  167228. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167229. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167230. if(png_ptr->read_user_chunk_fn != NULL)
  167231. {
  167232. int ret;
  167233. ret = (*(png_ptr->read_user_chunk_fn))
  167234. (png_ptr, &png_ptr->unknown_chunk);
  167235. if (ret < 0)
  167236. png_chunk_error(png_ptr, "error in user chunk");
  167237. if (ret == 0)
  167238. {
  167239. if (!(png_ptr->chunk_name[0] & 0x20))
  167240. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167241. PNG_HANDLE_CHUNK_ALWAYS)
  167242. png_chunk_error(png_ptr, "unknown critical chunk");
  167243. png_set_unknown_chunks(png_ptr, info_ptr,
  167244. &png_ptr->unknown_chunk, 1);
  167245. }
  167246. }
  167247. #else
  167248. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167249. #endif
  167250. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167251. png_ptr->unknown_chunk.data = NULL;
  167252. }
  167253. else
  167254. #endif
  167255. skip=length;
  167256. png_push_crc_skip(png_ptr, skip);
  167257. }
  167258. void /* PRIVATE */
  167259. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167260. {
  167261. if (png_ptr->info_fn != NULL)
  167262. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167263. }
  167264. void /* PRIVATE */
  167265. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167266. {
  167267. if (png_ptr->end_fn != NULL)
  167268. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167269. }
  167270. void /* PRIVATE */
  167271. png_push_have_row(png_structp png_ptr, png_bytep row)
  167272. {
  167273. if (png_ptr->row_fn != NULL)
  167274. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167275. (int)png_ptr->pass);
  167276. }
  167277. void PNGAPI
  167278. png_progressive_combine_row (png_structp png_ptr,
  167279. png_bytep old_row, png_bytep new_row)
  167280. {
  167281. #ifdef PNG_USE_LOCAL_ARRAYS
  167282. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167283. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167284. #endif
  167285. if(png_ptr == NULL) return;
  167286. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167287. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167288. }
  167289. void PNGAPI
  167290. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167291. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167292. png_progressive_end_ptr end_fn)
  167293. {
  167294. if(png_ptr == NULL) return;
  167295. png_ptr->info_fn = info_fn;
  167296. png_ptr->row_fn = row_fn;
  167297. png_ptr->end_fn = end_fn;
  167298. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167299. }
  167300. png_voidp PNGAPI
  167301. png_get_progressive_ptr(png_structp png_ptr)
  167302. {
  167303. if(png_ptr == NULL) return (NULL);
  167304. return png_ptr->io_ptr;
  167305. }
  167306. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167307. /*** End of inlined file: pngpread.c ***/
  167308. /*** Start of inlined file: pngrio.c ***/
  167309. #define PNG_INTERNAL
  167310. #if defined(PNG_READ_SUPPORTED)
  167311. void /* PRIVATE */
  167312. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167313. {
  167314. png_debug1(4,"reading %d bytes\n", (int)length);
  167315. if (png_ptr->read_data_fn != NULL)
  167316. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167317. else
  167318. png_error(png_ptr, "Call to NULL read function");
  167319. }
  167320. #if !defined(PNG_NO_STDIO)
  167321. #ifndef USE_FAR_KEYWORD
  167322. void PNGAPI
  167323. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167324. {
  167325. png_size_t check;
  167326. if(png_ptr == NULL) return;
  167327. #if defined(_WIN32_WCE)
  167328. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167329. check = 0;
  167330. #else
  167331. check = (png_size_t)fread(data, (png_size_t)1, length,
  167332. (png_FILE_p)png_ptr->io_ptr);
  167333. #endif
  167334. if (check != length)
  167335. png_error(png_ptr, "Read Error");
  167336. }
  167337. #else
  167338. #define NEAR_BUF_SIZE 1024
  167339. #define MIN(a,b) (a <= b ? a : b)
  167340. static void PNGAPI
  167341. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167342. {
  167343. int check;
  167344. png_byte *n_data;
  167345. png_FILE_p io_ptr;
  167346. if(png_ptr == NULL) return;
  167347. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167348. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167349. if ((png_bytep)n_data == data)
  167350. {
  167351. #if defined(_WIN32_WCE)
  167352. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167353. check = 0;
  167354. #else
  167355. check = fread(n_data, 1, length, io_ptr);
  167356. #endif
  167357. }
  167358. else
  167359. {
  167360. png_byte buf[NEAR_BUF_SIZE];
  167361. png_size_t read, remaining, err;
  167362. check = 0;
  167363. remaining = length;
  167364. do
  167365. {
  167366. read = MIN(NEAR_BUF_SIZE, remaining);
  167367. #if defined(_WIN32_WCE)
  167368. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167369. err = 0;
  167370. #else
  167371. err = fread(buf, (png_size_t)1, read, io_ptr);
  167372. #endif
  167373. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167374. if(err != read)
  167375. break;
  167376. else
  167377. check += err;
  167378. data += read;
  167379. remaining -= read;
  167380. }
  167381. while (remaining != 0);
  167382. }
  167383. if ((png_uint_32)check != (png_uint_32)length)
  167384. png_error(png_ptr, "read Error");
  167385. }
  167386. #endif
  167387. #endif
  167388. void PNGAPI
  167389. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167390. png_rw_ptr read_data_fn)
  167391. {
  167392. if(png_ptr == NULL) return;
  167393. png_ptr->io_ptr = io_ptr;
  167394. #if !defined(PNG_NO_STDIO)
  167395. if (read_data_fn != NULL)
  167396. png_ptr->read_data_fn = read_data_fn;
  167397. else
  167398. png_ptr->read_data_fn = png_default_read_data;
  167399. #else
  167400. png_ptr->read_data_fn = read_data_fn;
  167401. #endif
  167402. if (png_ptr->write_data_fn != NULL)
  167403. {
  167404. png_ptr->write_data_fn = NULL;
  167405. png_warning(png_ptr,
  167406. "It's an error to set both read_data_fn and write_data_fn in the ");
  167407. png_warning(png_ptr,
  167408. "same structure. Resetting write_data_fn to NULL.");
  167409. }
  167410. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167411. png_ptr->output_flush_fn = NULL;
  167412. #endif
  167413. }
  167414. #endif /* PNG_READ_SUPPORTED */
  167415. /*** End of inlined file: pngrio.c ***/
  167416. /*** Start of inlined file: pngrtran.c ***/
  167417. #define PNG_INTERNAL
  167418. #if defined(PNG_READ_SUPPORTED)
  167419. void PNGAPI
  167420. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167421. {
  167422. png_debug(1, "in png_set_crc_action\n");
  167423. if(png_ptr == NULL) return;
  167424. switch (crit_action)
  167425. {
  167426. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167427. break;
  167428. case PNG_CRC_WARN_USE: /* warn/use data */
  167429. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167430. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167431. break;
  167432. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167433. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167434. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167435. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167436. break;
  167437. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167438. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167439. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167440. case PNG_CRC_DEFAULT:
  167441. default:
  167442. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167443. break;
  167444. }
  167445. switch (ancil_action)
  167446. {
  167447. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167448. break;
  167449. case PNG_CRC_WARN_USE: /* warn/use data */
  167450. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167451. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167452. break;
  167453. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167454. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167455. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167456. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167457. break;
  167458. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167459. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167460. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167461. break;
  167462. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167463. case PNG_CRC_DEFAULT:
  167464. default:
  167465. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167466. break;
  167467. }
  167468. }
  167469. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167470. defined(PNG_FLOATING_POINT_SUPPORTED)
  167471. void PNGAPI
  167472. png_set_background(png_structp png_ptr,
  167473. png_color_16p background_color, int background_gamma_code,
  167474. int need_expand, double background_gamma)
  167475. {
  167476. png_debug(1, "in png_set_background\n");
  167477. if(png_ptr == NULL) return;
  167478. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167479. {
  167480. png_warning(png_ptr, "Application must supply a known background gamma");
  167481. return;
  167482. }
  167483. png_ptr->transformations |= PNG_BACKGROUND;
  167484. png_memcpy(&(png_ptr->background), background_color,
  167485. png_sizeof(png_color_16));
  167486. png_ptr->background_gamma = (float)background_gamma;
  167487. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167488. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167489. }
  167490. #endif
  167491. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167492. void PNGAPI
  167493. png_set_strip_16(png_structp png_ptr)
  167494. {
  167495. png_debug(1, "in png_set_strip_16\n");
  167496. if(png_ptr == NULL) return;
  167497. png_ptr->transformations |= PNG_16_TO_8;
  167498. }
  167499. #endif
  167500. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167501. void PNGAPI
  167502. png_set_strip_alpha(png_structp png_ptr)
  167503. {
  167504. png_debug(1, "in png_set_strip_alpha\n");
  167505. if(png_ptr == NULL) return;
  167506. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167507. }
  167508. #endif
  167509. #if defined(PNG_READ_DITHER_SUPPORTED)
  167510. typedef struct png_dsort_struct
  167511. {
  167512. struct png_dsort_struct FAR * next;
  167513. png_byte left;
  167514. png_byte right;
  167515. } png_dsort;
  167516. typedef png_dsort FAR * png_dsortp;
  167517. typedef png_dsort FAR * FAR * png_dsortpp;
  167518. void PNGAPI
  167519. png_set_dither(png_structp png_ptr, png_colorp palette,
  167520. int num_palette, int maximum_colors, png_uint_16p histogram,
  167521. int full_dither)
  167522. {
  167523. png_debug(1, "in png_set_dither\n");
  167524. if(png_ptr == NULL) return;
  167525. png_ptr->transformations |= PNG_DITHER;
  167526. if (!full_dither)
  167527. {
  167528. int i;
  167529. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167530. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167531. for (i = 0; i < num_palette; i++)
  167532. png_ptr->dither_index[i] = (png_byte)i;
  167533. }
  167534. if (num_palette > maximum_colors)
  167535. {
  167536. if (histogram != NULL)
  167537. {
  167538. int i;
  167539. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167540. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167541. for (i = 0; i < num_palette; i++)
  167542. png_ptr->dither_sort[i] = (png_byte)i;
  167543. for (i = num_palette - 1; i >= maximum_colors; i--)
  167544. {
  167545. int done; /* to stop early if the list is pre-sorted */
  167546. int j;
  167547. done = 1;
  167548. for (j = 0; j < i; j++)
  167549. {
  167550. if (histogram[png_ptr->dither_sort[j]]
  167551. < histogram[png_ptr->dither_sort[j + 1]])
  167552. {
  167553. png_byte t;
  167554. t = png_ptr->dither_sort[j];
  167555. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167556. png_ptr->dither_sort[j + 1] = t;
  167557. done = 0;
  167558. }
  167559. }
  167560. if (done)
  167561. break;
  167562. }
  167563. if (full_dither)
  167564. {
  167565. int j = num_palette;
  167566. for (i = 0; i < maximum_colors; i++)
  167567. {
  167568. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167569. {
  167570. do
  167571. j--;
  167572. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167573. palette[i] = palette[j];
  167574. }
  167575. }
  167576. }
  167577. else
  167578. {
  167579. int j = num_palette;
  167580. for (i = 0; i < maximum_colors; i++)
  167581. {
  167582. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167583. {
  167584. png_color tmp_color;
  167585. do
  167586. j--;
  167587. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167588. tmp_color = palette[j];
  167589. palette[j] = palette[i];
  167590. palette[i] = tmp_color;
  167591. png_ptr->dither_index[j] = (png_byte)i;
  167592. png_ptr->dither_index[i] = (png_byte)j;
  167593. }
  167594. }
  167595. for (i = 0; i < num_palette; i++)
  167596. {
  167597. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167598. {
  167599. int min_d, k, min_k, d_index;
  167600. d_index = png_ptr->dither_index[i];
  167601. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167602. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167603. {
  167604. int d;
  167605. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167606. if (d < min_d)
  167607. {
  167608. min_d = d;
  167609. min_k = k;
  167610. }
  167611. }
  167612. png_ptr->dither_index[i] = (png_byte)min_k;
  167613. }
  167614. }
  167615. }
  167616. png_free(png_ptr, png_ptr->dither_sort);
  167617. png_ptr->dither_sort=NULL;
  167618. }
  167619. else
  167620. {
  167621. int i;
  167622. int max_d;
  167623. int num_new_palette;
  167624. png_dsortp t;
  167625. png_dsortpp hash;
  167626. t=NULL;
  167627. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167628. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167629. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167630. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167631. for (i = 0; i < num_palette; i++)
  167632. {
  167633. png_ptr->index_to_palette[i] = (png_byte)i;
  167634. png_ptr->palette_to_index[i] = (png_byte)i;
  167635. }
  167636. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167637. png_sizeof (png_dsortp)));
  167638. for (i = 0; i < 769; i++)
  167639. hash[i] = NULL;
  167640. num_new_palette = num_palette;
  167641. max_d = 96;
  167642. while (num_new_palette > maximum_colors)
  167643. {
  167644. for (i = 0; i < num_new_palette - 1; i++)
  167645. {
  167646. int j;
  167647. for (j = i + 1; j < num_new_palette; j++)
  167648. {
  167649. int d;
  167650. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167651. if (d <= max_d)
  167652. {
  167653. t = (png_dsortp)png_malloc_warn(png_ptr,
  167654. (png_uint_32)(png_sizeof(png_dsort)));
  167655. if (t == NULL)
  167656. break;
  167657. t->next = hash[d];
  167658. t->left = (png_byte)i;
  167659. t->right = (png_byte)j;
  167660. hash[d] = t;
  167661. }
  167662. }
  167663. if (t == NULL)
  167664. break;
  167665. }
  167666. if (t != NULL)
  167667. for (i = 0; i <= max_d; i++)
  167668. {
  167669. if (hash[i] != NULL)
  167670. {
  167671. png_dsortp p;
  167672. for (p = hash[i]; p; p = p->next)
  167673. {
  167674. if ((int)png_ptr->index_to_palette[p->left]
  167675. < num_new_palette &&
  167676. (int)png_ptr->index_to_palette[p->right]
  167677. < num_new_palette)
  167678. {
  167679. int j, next_j;
  167680. if (num_new_palette & 0x01)
  167681. {
  167682. j = p->left;
  167683. next_j = p->right;
  167684. }
  167685. else
  167686. {
  167687. j = p->right;
  167688. next_j = p->left;
  167689. }
  167690. num_new_palette--;
  167691. palette[png_ptr->index_to_palette[j]]
  167692. = palette[num_new_palette];
  167693. if (!full_dither)
  167694. {
  167695. int k;
  167696. for (k = 0; k < num_palette; k++)
  167697. {
  167698. if (png_ptr->dither_index[k] ==
  167699. png_ptr->index_to_palette[j])
  167700. png_ptr->dither_index[k] =
  167701. png_ptr->index_to_palette[next_j];
  167702. if ((int)png_ptr->dither_index[k] ==
  167703. num_new_palette)
  167704. png_ptr->dither_index[k] =
  167705. png_ptr->index_to_palette[j];
  167706. }
  167707. }
  167708. png_ptr->index_to_palette[png_ptr->palette_to_index
  167709. [num_new_palette]] = png_ptr->index_to_palette[j];
  167710. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167711. = png_ptr->palette_to_index[num_new_palette];
  167712. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167713. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167714. }
  167715. if (num_new_palette <= maximum_colors)
  167716. break;
  167717. }
  167718. if (num_new_palette <= maximum_colors)
  167719. break;
  167720. }
  167721. }
  167722. for (i = 0; i < 769; i++)
  167723. {
  167724. if (hash[i] != NULL)
  167725. {
  167726. png_dsortp p = hash[i];
  167727. while (p)
  167728. {
  167729. t = p->next;
  167730. png_free(png_ptr, p);
  167731. p = t;
  167732. }
  167733. }
  167734. hash[i] = 0;
  167735. }
  167736. max_d += 96;
  167737. }
  167738. png_free(png_ptr, hash);
  167739. png_free(png_ptr, png_ptr->palette_to_index);
  167740. png_free(png_ptr, png_ptr->index_to_palette);
  167741. png_ptr->palette_to_index=NULL;
  167742. png_ptr->index_to_palette=NULL;
  167743. }
  167744. num_palette = maximum_colors;
  167745. }
  167746. if (png_ptr->palette == NULL)
  167747. {
  167748. png_ptr->palette = palette;
  167749. }
  167750. png_ptr->num_palette = (png_uint_16)num_palette;
  167751. if (full_dither)
  167752. {
  167753. int i;
  167754. png_bytep distance;
  167755. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167756. PNG_DITHER_BLUE_BITS;
  167757. int num_red = (1 << PNG_DITHER_RED_BITS);
  167758. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167759. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167760. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167761. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167762. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167763. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167764. png_sizeof (png_byte));
  167765. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167766. png_sizeof(png_byte)));
  167767. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167768. for (i = 0; i < num_palette; i++)
  167769. {
  167770. int ir, ig, ib;
  167771. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167772. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167773. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167774. for (ir = 0; ir < num_red; ir++)
  167775. {
  167776. int dr = ((ir > r) ? ir - r : r - ir);
  167777. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167778. for (ig = 0; ig < num_green; ig++)
  167779. {
  167780. int dg = ((ig > g) ? ig - g : g - ig);
  167781. int dt = dr + dg;
  167782. int dm = ((dr > dg) ? dr : dg);
  167783. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167784. for (ib = 0; ib < num_blue; ib++)
  167785. {
  167786. int d_index = index_g | ib;
  167787. int db = ((ib > b) ? ib - b : b - ib);
  167788. int dmax = ((dm > db) ? dm : db);
  167789. int d = dmax + dt + db;
  167790. if (d < (int)distance[d_index])
  167791. {
  167792. distance[d_index] = (png_byte)d;
  167793. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167794. }
  167795. }
  167796. }
  167797. }
  167798. }
  167799. png_free(png_ptr, distance);
  167800. }
  167801. }
  167802. #endif
  167803. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167804. void PNGAPI
  167805. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167806. {
  167807. png_debug(1, "in png_set_gamma\n");
  167808. if(png_ptr == NULL) return;
  167809. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167810. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167811. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167812. png_ptr->transformations |= PNG_GAMMA;
  167813. png_ptr->gamma = (float)file_gamma;
  167814. png_ptr->screen_gamma = (float)scrn_gamma;
  167815. }
  167816. #endif
  167817. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167818. void PNGAPI
  167819. png_set_expand(png_structp png_ptr)
  167820. {
  167821. png_debug(1, "in png_set_expand\n");
  167822. if(png_ptr == NULL) return;
  167823. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167824. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167825. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167826. #endif
  167827. }
  167828. void PNGAPI
  167829. png_set_palette_to_rgb(png_structp png_ptr)
  167830. {
  167831. png_debug(1, "in png_set_palette_to_rgb\n");
  167832. if(png_ptr == NULL) return;
  167833. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167834. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167835. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167836. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167837. #endif
  167838. }
  167839. #if !defined(PNG_1_0_X)
  167840. void PNGAPI
  167841. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167842. {
  167843. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167844. if(png_ptr == NULL) return;
  167845. png_ptr->transformations |= PNG_EXPAND;
  167846. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167847. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167848. #endif
  167849. }
  167850. #endif
  167851. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167852. void PNGAPI
  167853. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167854. {
  167855. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167856. if(png_ptr == NULL) return;
  167857. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167858. }
  167859. #endif
  167860. void PNGAPI
  167861. png_set_tRNS_to_alpha(png_structp png_ptr)
  167862. {
  167863. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167864. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167865. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167866. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167867. #endif
  167868. }
  167869. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167870. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167871. void PNGAPI
  167872. png_set_gray_to_rgb(png_structp png_ptr)
  167873. {
  167874. png_debug(1, "in png_set_gray_to_rgb\n");
  167875. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167876. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167877. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167878. #endif
  167879. }
  167880. #endif
  167881. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167882. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167883. void PNGAPI
  167884. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167885. double green)
  167886. {
  167887. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167888. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167889. if(png_ptr == NULL) return;
  167890. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167891. }
  167892. #endif
  167893. void PNGAPI
  167894. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167895. png_fixed_point red, png_fixed_point green)
  167896. {
  167897. png_debug(1, "in png_set_rgb_to_gray\n");
  167898. if(png_ptr == NULL) return;
  167899. switch(error_action)
  167900. {
  167901. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167902. break;
  167903. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167904. break;
  167905. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167906. }
  167907. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167908. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167909. png_ptr->transformations |= PNG_EXPAND;
  167910. #else
  167911. {
  167912. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167913. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167914. }
  167915. #endif
  167916. {
  167917. png_uint_16 red_int, green_int;
  167918. if(red < 0 || green < 0)
  167919. {
  167920. red_int = 6968; /* .212671 * 32768 + .5 */
  167921. green_int = 23434; /* .715160 * 32768 + .5 */
  167922. }
  167923. else if(red + green < 100000L)
  167924. {
  167925. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167926. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167927. }
  167928. else
  167929. {
  167930. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167931. red_int = 6968;
  167932. green_int = 23434;
  167933. }
  167934. png_ptr->rgb_to_gray_red_coeff = red_int;
  167935. png_ptr->rgb_to_gray_green_coeff = green_int;
  167936. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167937. }
  167938. }
  167939. #endif
  167940. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167941. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167942. defined(PNG_LEGACY_SUPPORTED)
  167943. void PNGAPI
  167944. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167945. read_user_transform_fn)
  167946. {
  167947. png_debug(1, "in png_set_read_user_transform_fn\n");
  167948. if(png_ptr == NULL) return;
  167949. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167950. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167951. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167952. #endif
  167953. #ifdef PNG_LEGACY_SUPPORTED
  167954. if(read_user_transform_fn)
  167955. png_warning(png_ptr,
  167956. "This version of libpng does not support user transforms");
  167957. #endif
  167958. }
  167959. #endif
  167960. void /* PRIVATE */
  167961. png_init_read_transformations(png_structp png_ptr)
  167962. {
  167963. png_debug(1, "in png_init_read_transformations\n");
  167964. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167965. if(png_ptr != NULL)
  167966. #endif
  167967. {
  167968. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167969. || defined(PNG_READ_GAMMA_SUPPORTED)
  167970. int color_type = png_ptr->color_type;
  167971. #endif
  167972. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167973. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167974. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167975. !(color_type & PNG_COLOR_MASK_COLOR))
  167976. {
  167977. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167978. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167979. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167980. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167981. png_ptr->background.red == png_ptr->background.green &&
  167982. png_ptr->background.red == png_ptr->background.blue)
  167983. {
  167984. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167985. png_ptr->background.gray = png_ptr->background.red;
  167986. }
  167987. #endif
  167988. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167989. (png_ptr->transformations & PNG_EXPAND))
  167990. {
  167991. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167992. {
  167993. switch (png_ptr->bit_depth)
  167994. {
  167995. case 1:
  167996. png_ptr->background.gray *= (png_uint_16)0xff;
  167997. png_ptr->background.red = png_ptr->background.green
  167998. = png_ptr->background.blue = png_ptr->background.gray;
  167999. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168000. {
  168001. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  168002. png_ptr->trans_values.red = png_ptr->trans_values.green
  168003. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168004. }
  168005. break;
  168006. case 2:
  168007. png_ptr->background.gray *= (png_uint_16)0x55;
  168008. png_ptr->background.red = png_ptr->background.green
  168009. = png_ptr->background.blue = png_ptr->background.gray;
  168010. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168011. {
  168012. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  168013. png_ptr->trans_values.red = png_ptr->trans_values.green
  168014. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168015. }
  168016. break;
  168017. case 4:
  168018. png_ptr->background.gray *= (png_uint_16)0x11;
  168019. png_ptr->background.red = png_ptr->background.green
  168020. = png_ptr->background.blue = png_ptr->background.gray;
  168021. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168022. {
  168023. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  168024. png_ptr->trans_values.red = png_ptr->trans_values.green
  168025. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168026. }
  168027. break;
  168028. case 8:
  168029. case 16:
  168030. png_ptr->background.red = png_ptr->background.green
  168031. = png_ptr->background.blue = png_ptr->background.gray;
  168032. break;
  168033. }
  168034. }
  168035. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  168036. {
  168037. png_ptr->background.red =
  168038. png_ptr->palette[png_ptr->background.index].red;
  168039. png_ptr->background.green =
  168040. png_ptr->palette[png_ptr->background.index].green;
  168041. png_ptr->background.blue =
  168042. png_ptr->palette[png_ptr->background.index].blue;
  168043. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168044. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168045. {
  168046. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168047. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168048. #endif
  168049. {
  168050. int i,istop;
  168051. istop=(int)png_ptr->num_trans;
  168052. for (i=0; i<istop; i++)
  168053. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  168054. }
  168055. }
  168056. #endif
  168057. }
  168058. }
  168059. #endif
  168060. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  168061. png_ptr->background_1 = png_ptr->background;
  168062. #endif
  168063. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168064. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  168065. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  168066. < PNG_GAMMA_THRESHOLD))
  168067. {
  168068. int i,k;
  168069. k=0;
  168070. for (i=0; i<png_ptr->num_trans; i++)
  168071. {
  168072. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  168073. k=1; /* partial transparency is present */
  168074. }
  168075. if (k == 0)
  168076. png_ptr->transformations &= (~PNG_GAMMA);
  168077. }
  168078. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  168079. png_ptr->gamma != 0.0)
  168080. {
  168081. png_build_gamma_table(png_ptr);
  168082. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168083. if (png_ptr->transformations & PNG_BACKGROUND)
  168084. {
  168085. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168086. {
  168087. png_color back, back_1;
  168088. png_colorp palette = png_ptr->palette;
  168089. int num_palette = png_ptr->num_palette;
  168090. int i;
  168091. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168092. {
  168093. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168094. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168095. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168096. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168097. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168098. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168099. }
  168100. else
  168101. {
  168102. double g, gs;
  168103. switch (png_ptr->background_gamma_type)
  168104. {
  168105. case PNG_BACKGROUND_GAMMA_SCREEN:
  168106. g = (png_ptr->screen_gamma);
  168107. gs = 1.0;
  168108. break;
  168109. case PNG_BACKGROUND_GAMMA_FILE:
  168110. g = 1.0 / (png_ptr->gamma);
  168111. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168112. break;
  168113. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168114. g = 1.0 / (png_ptr->background_gamma);
  168115. gs = 1.0 / (png_ptr->background_gamma *
  168116. png_ptr->screen_gamma);
  168117. break;
  168118. default:
  168119. g = 1.0; /* back_1 */
  168120. gs = 1.0; /* back */
  168121. }
  168122. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168123. {
  168124. back.red = (png_byte)png_ptr->background.red;
  168125. back.green = (png_byte)png_ptr->background.green;
  168126. back.blue = (png_byte)png_ptr->background.blue;
  168127. }
  168128. else
  168129. {
  168130. back.red = (png_byte)(pow(
  168131. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168132. back.green = (png_byte)(pow(
  168133. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168134. back.blue = (png_byte)(pow(
  168135. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168136. }
  168137. back_1.red = (png_byte)(pow(
  168138. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168139. back_1.green = (png_byte)(pow(
  168140. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168141. back_1.blue = (png_byte)(pow(
  168142. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168143. }
  168144. for (i = 0; i < num_palette; i++)
  168145. {
  168146. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168147. {
  168148. if (png_ptr->trans[i] == 0)
  168149. {
  168150. palette[i] = back;
  168151. }
  168152. else /* if (png_ptr->trans[i] != 0xff) */
  168153. {
  168154. png_byte v, w;
  168155. v = png_ptr->gamma_to_1[palette[i].red];
  168156. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168157. palette[i].red = png_ptr->gamma_from_1[w];
  168158. v = png_ptr->gamma_to_1[palette[i].green];
  168159. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168160. palette[i].green = png_ptr->gamma_from_1[w];
  168161. v = png_ptr->gamma_to_1[palette[i].blue];
  168162. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168163. palette[i].blue = png_ptr->gamma_from_1[w];
  168164. }
  168165. }
  168166. else
  168167. {
  168168. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168169. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168170. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168171. }
  168172. }
  168173. }
  168174. else
  168175. {
  168176. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168177. double g = 1.0;
  168178. double gs = 1.0;
  168179. switch (png_ptr->background_gamma_type)
  168180. {
  168181. case PNG_BACKGROUND_GAMMA_SCREEN:
  168182. g = (png_ptr->screen_gamma);
  168183. gs = 1.0;
  168184. break;
  168185. case PNG_BACKGROUND_GAMMA_FILE:
  168186. g = 1.0 / (png_ptr->gamma);
  168187. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168188. break;
  168189. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168190. g = 1.0 / (png_ptr->background_gamma);
  168191. gs = 1.0 / (png_ptr->background_gamma *
  168192. png_ptr->screen_gamma);
  168193. break;
  168194. }
  168195. png_ptr->background_1.gray = (png_uint_16)(pow(
  168196. (double)png_ptr->background.gray / m, g) * m + .5);
  168197. png_ptr->background.gray = (png_uint_16)(pow(
  168198. (double)png_ptr->background.gray / m, gs) * m + .5);
  168199. if ((png_ptr->background.red != png_ptr->background.green) ||
  168200. (png_ptr->background.red != png_ptr->background.blue) ||
  168201. (png_ptr->background.red != png_ptr->background.gray))
  168202. {
  168203. png_ptr->background_1.red = (png_uint_16)(pow(
  168204. (double)png_ptr->background.red / m, g) * m + .5);
  168205. png_ptr->background_1.green = (png_uint_16)(pow(
  168206. (double)png_ptr->background.green / m, g) * m + .5);
  168207. png_ptr->background_1.blue = (png_uint_16)(pow(
  168208. (double)png_ptr->background.blue / m, g) * m + .5);
  168209. png_ptr->background.red = (png_uint_16)(pow(
  168210. (double)png_ptr->background.red / m, gs) * m + .5);
  168211. png_ptr->background.green = (png_uint_16)(pow(
  168212. (double)png_ptr->background.green / m, gs) * m + .5);
  168213. png_ptr->background.blue = (png_uint_16)(pow(
  168214. (double)png_ptr->background.blue / m, gs) * m + .5);
  168215. }
  168216. else
  168217. {
  168218. png_ptr->background_1.red = png_ptr->background_1.green
  168219. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168220. png_ptr->background.red = png_ptr->background.green
  168221. = png_ptr->background.blue = png_ptr->background.gray;
  168222. }
  168223. }
  168224. }
  168225. else
  168226. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168227. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168228. {
  168229. png_colorp palette = png_ptr->palette;
  168230. int num_palette = png_ptr->num_palette;
  168231. int i;
  168232. for (i = 0; i < num_palette; i++)
  168233. {
  168234. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168235. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168236. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168237. }
  168238. }
  168239. }
  168240. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168241. else
  168242. #endif
  168243. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168244. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168245. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168246. (color_type == PNG_COLOR_TYPE_PALETTE))
  168247. {
  168248. int i;
  168249. int istop = (int)png_ptr->num_trans;
  168250. png_color back;
  168251. png_colorp palette = png_ptr->palette;
  168252. back.red = (png_byte)png_ptr->background.red;
  168253. back.green = (png_byte)png_ptr->background.green;
  168254. back.blue = (png_byte)png_ptr->background.blue;
  168255. for (i = 0; i < istop; i++)
  168256. {
  168257. if (png_ptr->trans[i] == 0)
  168258. {
  168259. palette[i] = back;
  168260. }
  168261. else if (png_ptr->trans[i] != 0xff)
  168262. {
  168263. png_composite(palette[i].red, palette[i].red,
  168264. png_ptr->trans[i], back.red);
  168265. png_composite(palette[i].green, palette[i].green,
  168266. png_ptr->trans[i], back.green);
  168267. png_composite(palette[i].blue, palette[i].blue,
  168268. png_ptr->trans[i], back.blue);
  168269. }
  168270. }
  168271. }
  168272. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168273. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168274. if ((png_ptr->transformations & PNG_SHIFT) &&
  168275. (color_type == PNG_COLOR_TYPE_PALETTE))
  168276. {
  168277. png_uint_16 i;
  168278. png_uint_16 istop = png_ptr->num_palette;
  168279. int sr = 8 - png_ptr->sig_bit.red;
  168280. int sg = 8 - png_ptr->sig_bit.green;
  168281. int sb = 8 - png_ptr->sig_bit.blue;
  168282. if (sr < 0 || sr > 8)
  168283. sr = 0;
  168284. if (sg < 0 || sg > 8)
  168285. sg = 0;
  168286. if (sb < 0 || sb > 8)
  168287. sb = 0;
  168288. for (i = 0; i < istop; i++)
  168289. {
  168290. png_ptr->palette[i].red >>= sr;
  168291. png_ptr->palette[i].green >>= sg;
  168292. png_ptr->palette[i].blue >>= sb;
  168293. }
  168294. }
  168295. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168296. }
  168297. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168298. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168299. if(png_ptr)
  168300. return;
  168301. #endif
  168302. }
  168303. void /* PRIVATE */
  168304. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168305. {
  168306. png_debug(1, "in png_read_transform_info\n");
  168307. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168308. if (png_ptr->transformations & PNG_EXPAND)
  168309. {
  168310. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168311. {
  168312. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168313. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168314. else
  168315. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168316. info_ptr->bit_depth = 8;
  168317. info_ptr->num_trans = 0;
  168318. }
  168319. else
  168320. {
  168321. if (png_ptr->num_trans)
  168322. {
  168323. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168324. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168325. else
  168326. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168327. }
  168328. if (info_ptr->bit_depth < 8)
  168329. info_ptr->bit_depth = 8;
  168330. info_ptr->num_trans = 0;
  168331. }
  168332. }
  168333. #endif
  168334. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168335. if (png_ptr->transformations & PNG_BACKGROUND)
  168336. {
  168337. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168338. info_ptr->num_trans = 0;
  168339. info_ptr->background = png_ptr->background;
  168340. }
  168341. #endif
  168342. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168343. if (png_ptr->transformations & PNG_GAMMA)
  168344. {
  168345. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168346. info_ptr->gamma = png_ptr->gamma;
  168347. #endif
  168348. #ifdef PNG_FIXED_POINT_SUPPORTED
  168349. info_ptr->int_gamma = png_ptr->int_gamma;
  168350. #endif
  168351. }
  168352. #endif
  168353. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168354. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168355. info_ptr->bit_depth = 8;
  168356. #endif
  168357. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168358. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168359. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168360. #endif
  168361. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168362. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168363. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168364. #endif
  168365. #if defined(PNG_READ_DITHER_SUPPORTED)
  168366. if (png_ptr->transformations & PNG_DITHER)
  168367. {
  168368. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168369. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168370. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168371. {
  168372. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168373. }
  168374. }
  168375. #endif
  168376. #if defined(PNG_READ_PACK_SUPPORTED)
  168377. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168378. info_ptr->bit_depth = 8;
  168379. #endif
  168380. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168381. info_ptr->channels = 1;
  168382. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168383. info_ptr->channels = 3;
  168384. else
  168385. info_ptr->channels = 1;
  168386. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168387. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168388. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168389. #endif
  168390. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168391. info_ptr->channels++;
  168392. #if defined(PNG_READ_FILLER_SUPPORTED)
  168393. if ((png_ptr->transformations & PNG_FILLER) &&
  168394. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168395. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168396. {
  168397. info_ptr->channels++;
  168398. #if !defined(PNG_1_0_X)
  168399. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168400. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168401. #endif
  168402. }
  168403. #endif
  168404. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168405. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168406. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168407. {
  168408. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168409. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168410. if(info_ptr->channels < png_ptr->user_transform_channels)
  168411. info_ptr->channels = png_ptr->user_transform_channels;
  168412. }
  168413. #endif
  168414. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168415. info_ptr->bit_depth);
  168416. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168417. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168418. if(png_ptr)
  168419. return;
  168420. #endif
  168421. }
  168422. void /* PRIVATE */
  168423. png_do_read_transformations(png_structp png_ptr)
  168424. {
  168425. png_debug(1, "in png_do_read_transformations\n");
  168426. if (png_ptr->row_buf == NULL)
  168427. {
  168428. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168429. char msg[50];
  168430. png_snprintf2(msg, 50,
  168431. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168432. png_ptr->pass);
  168433. png_error(png_ptr, msg);
  168434. #else
  168435. png_error(png_ptr, "NULL row buffer");
  168436. #endif
  168437. }
  168438. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168439. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168440. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168441. png_error(png_ptr, "Uninitialized row");
  168442. #else
  168443. png_warning(png_ptr, "Uninitialized row");
  168444. #endif
  168445. #endif
  168446. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168447. if (png_ptr->transformations & PNG_EXPAND)
  168448. {
  168449. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168450. {
  168451. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168452. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168453. }
  168454. else
  168455. {
  168456. if (png_ptr->num_trans &&
  168457. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168458. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168459. &(png_ptr->trans_values));
  168460. else
  168461. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168462. NULL);
  168463. }
  168464. }
  168465. #endif
  168466. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168467. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168468. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168469. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168470. #endif
  168471. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168472. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168473. {
  168474. int rgb_error =
  168475. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168476. if(rgb_error)
  168477. {
  168478. png_ptr->rgb_to_gray_status=1;
  168479. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168480. PNG_RGB_TO_GRAY_WARN)
  168481. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168482. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168483. PNG_RGB_TO_GRAY_ERR)
  168484. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168485. }
  168486. }
  168487. #endif
  168488. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168489. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168490. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168491. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168492. #endif
  168493. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168494. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168495. ((png_ptr->num_trans != 0 ) ||
  168496. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168497. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168498. &(png_ptr->trans_values), &(png_ptr->background)
  168499. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168500. , &(png_ptr->background_1),
  168501. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168502. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168503. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168504. png_ptr->gamma_shift
  168505. #endif
  168506. );
  168507. #endif
  168508. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168509. if ((png_ptr->transformations & PNG_GAMMA) &&
  168510. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168511. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168512. ((png_ptr->num_trans != 0) ||
  168513. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168514. #endif
  168515. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168516. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168517. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168518. png_ptr->gamma_shift);
  168519. #endif
  168520. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168521. if (png_ptr->transformations & PNG_16_TO_8)
  168522. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168523. #endif
  168524. #if defined(PNG_READ_DITHER_SUPPORTED)
  168525. if (png_ptr->transformations & PNG_DITHER)
  168526. {
  168527. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168528. png_ptr->palette_lookup, png_ptr->dither_index);
  168529. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168530. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168531. }
  168532. #endif
  168533. #if defined(PNG_READ_INVERT_SUPPORTED)
  168534. if (png_ptr->transformations & PNG_INVERT_MONO)
  168535. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168536. #endif
  168537. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168538. if (png_ptr->transformations & PNG_SHIFT)
  168539. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168540. &(png_ptr->shift));
  168541. #endif
  168542. #if defined(PNG_READ_PACK_SUPPORTED)
  168543. if (png_ptr->transformations & PNG_PACK)
  168544. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168545. #endif
  168546. #if defined(PNG_READ_BGR_SUPPORTED)
  168547. if (png_ptr->transformations & PNG_BGR)
  168548. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168549. #endif
  168550. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168551. if (png_ptr->transformations & PNG_PACKSWAP)
  168552. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168553. #endif
  168554. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168555. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168556. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168557. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168558. #endif
  168559. #if defined(PNG_READ_FILLER_SUPPORTED)
  168560. if (png_ptr->transformations & PNG_FILLER)
  168561. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168562. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168563. #endif
  168564. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168565. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168566. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168567. #endif
  168568. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168569. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168570. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168571. #endif
  168572. #if defined(PNG_READ_SWAP_SUPPORTED)
  168573. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168574. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168575. #endif
  168576. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168577. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168578. {
  168579. if(png_ptr->read_user_transform_fn != NULL)
  168580. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168581. (png_ptr, /* png_ptr */
  168582. &(png_ptr->row_info), /* row_info: */
  168583. png_ptr->row_buf + 1); /* start of pixel data for row */
  168584. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168585. if(png_ptr->user_transform_depth)
  168586. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168587. if(png_ptr->user_transform_channels)
  168588. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168589. #endif
  168590. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168591. png_ptr->row_info.channels);
  168592. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168593. png_ptr->row_info.width);
  168594. }
  168595. #endif
  168596. }
  168597. #if defined(PNG_READ_PACK_SUPPORTED)
  168598. void /* PRIVATE */
  168599. png_do_unpack(png_row_infop row_info, png_bytep row)
  168600. {
  168601. png_debug(1, "in png_do_unpack\n");
  168602. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168603. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168604. #else
  168605. if (row_info->bit_depth < 8)
  168606. #endif
  168607. {
  168608. png_uint_32 i;
  168609. png_uint_32 row_width=row_info->width;
  168610. switch (row_info->bit_depth)
  168611. {
  168612. case 1:
  168613. {
  168614. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168615. png_bytep dp = row + (png_size_t)row_width - 1;
  168616. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168617. for (i = 0; i < row_width; i++)
  168618. {
  168619. *dp = (png_byte)((*sp >> shift) & 0x01);
  168620. if (shift == 7)
  168621. {
  168622. shift = 0;
  168623. sp--;
  168624. }
  168625. else
  168626. shift++;
  168627. dp--;
  168628. }
  168629. break;
  168630. }
  168631. case 2:
  168632. {
  168633. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168634. png_bytep dp = row + (png_size_t)row_width - 1;
  168635. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168636. for (i = 0; i < row_width; i++)
  168637. {
  168638. *dp = (png_byte)((*sp >> shift) & 0x03);
  168639. if (shift == 6)
  168640. {
  168641. shift = 0;
  168642. sp--;
  168643. }
  168644. else
  168645. shift += 2;
  168646. dp--;
  168647. }
  168648. break;
  168649. }
  168650. case 4:
  168651. {
  168652. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168653. png_bytep dp = row + (png_size_t)row_width - 1;
  168654. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168655. for (i = 0; i < row_width; i++)
  168656. {
  168657. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168658. if (shift == 4)
  168659. {
  168660. shift = 0;
  168661. sp--;
  168662. }
  168663. else
  168664. shift = 4;
  168665. dp--;
  168666. }
  168667. break;
  168668. }
  168669. }
  168670. row_info->bit_depth = 8;
  168671. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168672. row_info->rowbytes = row_width * row_info->channels;
  168673. }
  168674. }
  168675. #endif
  168676. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168677. void /* PRIVATE */
  168678. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168679. {
  168680. png_debug(1, "in png_do_unshift\n");
  168681. if (
  168682. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168683. row != NULL && row_info != NULL && sig_bits != NULL &&
  168684. #endif
  168685. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168686. {
  168687. int shift[4];
  168688. int channels = 0;
  168689. int c;
  168690. png_uint_16 value = 0;
  168691. png_uint_32 row_width = row_info->width;
  168692. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168693. {
  168694. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168695. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168696. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168697. }
  168698. else
  168699. {
  168700. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168701. }
  168702. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168703. {
  168704. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168705. }
  168706. for (c = 0; c < channels; c++)
  168707. {
  168708. if (shift[c] <= 0)
  168709. shift[c] = 0;
  168710. else
  168711. value = 1;
  168712. }
  168713. if (!value)
  168714. return;
  168715. switch (row_info->bit_depth)
  168716. {
  168717. case 2:
  168718. {
  168719. png_bytep bp;
  168720. png_uint_32 i;
  168721. png_uint_32 istop = row_info->rowbytes;
  168722. for (bp = row, i = 0; i < istop; i++)
  168723. {
  168724. *bp >>= 1;
  168725. *bp++ &= 0x55;
  168726. }
  168727. break;
  168728. }
  168729. case 4:
  168730. {
  168731. png_bytep bp = row;
  168732. png_uint_32 i;
  168733. png_uint_32 istop = row_info->rowbytes;
  168734. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168735. (png_byte)((int)0xf >> shift[0]));
  168736. for (i = 0; i < istop; i++)
  168737. {
  168738. *bp >>= shift[0];
  168739. *bp++ &= mask;
  168740. }
  168741. break;
  168742. }
  168743. case 8:
  168744. {
  168745. png_bytep bp = row;
  168746. png_uint_32 i;
  168747. png_uint_32 istop = row_width * channels;
  168748. for (i = 0; i < istop; i++)
  168749. {
  168750. *bp++ >>= shift[i%channels];
  168751. }
  168752. break;
  168753. }
  168754. case 16:
  168755. {
  168756. png_bytep bp = row;
  168757. png_uint_32 i;
  168758. png_uint_32 istop = channels * row_width;
  168759. for (i = 0; i < istop; i++)
  168760. {
  168761. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168762. value >>= shift[i%channels];
  168763. *bp++ = (png_byte)(value >> 8);
  168764. *bp++ = (png_byte)(value & 0xff);
  168765. }
  168766. break;
  168767. }
  168768. }
  168769. }
  168770. }
  168771. #endif
  168772. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168773. void /* PRIVATE */
  168774. png_do_chop(png_row_infop row_info, png_bytep row)
  168775. {
  168776. png_debug(1, "in png_do_chop\n");
  168777. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168778. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168779. #else
  168780. if (row_info->bit_depth == 16)
  168781. #endif
  168782. {
  168783. png_bytep sp = row;
  168784. png_bytep dp = row;
  168785. png_uint_32 i;
  168786. png_uint_32 istop = row_info->width * row_info->channels;
  168787. for (i = 0; i<istop; i++, sp += 2, dp++)
  168788. {
  168789. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168790. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168791. #else
  168792. *dp = *sp;
  168793. #endif
  168794. }
  168795. row_info->bit_depth = 8;
  168796. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168797. row_info->rowbytes = row_info->width * row_info->channels;
  168798. }
  168799. }
  168800. #endif
  168801. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168802. void /* PRIVATE */
  168803. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168804. {
  168805. png_debug(1, "in png_do_read_swap_alpha\n");
  168806. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168807. if (row != NULL && row_info != NULL)
  168808. #endif
  168809. {
  168810. png_uint_32 row_width = row_info->width;
  168811. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168812. {
  168813. if (row_info->bit_depth == 8)
  168814. {
  168815. png_bytep sp = row + row_info->rowbytes;
  168816. png_bytep dp = sp;
  168817. png_byte save;
  168818. png_uint_32 i;
  168819. for (i = 0; i < row_width; i++)
  168820. {
  168821. save = *(--sp);
  168822. *(--dp) = *(--sp);
  168823. *(--dp) = *(--sp);
  168824. *(--dp) = *(--sp);
  168825. *(--dp) = save;
  168826. }
  168827. }
  168828. else
  168829. {
  168830. png_bytep sp = row + row_info->rowbytes;
  168831. png_bytep dp = sp;
  168832. png_byte save[2];
  168833. png_uint_32 i;
  168834. for (i = 0; i < row_width; i++)
  168835. {
  168836. save[0] = *(--sp);
  168837. save[1] = *(--sp);
  168838. *(--dp) = *(--sp);
  168839. *(--dp) = *(--sp);
  168840. *(--dp) = *(--sp);
  168841. *(--dp) = *(--sp);
  168842. *(--dp) = *(--sp);
  168843. *(--dp) = *(--sp);
  168844. *(--dp) = save[0];
  168845. *(--dp) = save[1];
  168846. }
  168847. }
  168848. }
  168849. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168850. {
  168851. if (row_info->bit_depth == 8)
  168852. {
  168853. png_bytep sp = row + row_info->rowbytes;
  168854. png_bytep dp = sp;
  168855. png_byte save;
  168856. png_uint_32 i;
  168857. for (i = 0; i < row_width; i++)
  168858. {
  168859. save = *(--sp);
  168860. *(--dp) = *(--sp);
  168861. *(--dp) = save;
  168862. }
  168863. }
  168864. else
  168865. {
  168866. png_bytep sp = row + row_info->rowbytes;
  168867. png_bytep dp = sp;
  168868. png_byte save[2];
  168869. png_uint_32 i;
  168870. for (i = 0; i < row_width; i++)
  168871. {
  168872. save[0] = *(--sp);
  168873. save[1] = *(--sp);
  168874. *(--dp) = *(--sp);
  168875. *(--dp) = *(--sp);
  168876. *(--dp) = save[0];
  168877. *(--dp) = save[1];
  168878. }
  168879. }
  168880. }
  168881. }
  168882. }
  168883. #endif
  168884. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168885. void /* PRIVATE */
  168886. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168887. {
  168888. png_debug(1, "in png_do_read_invert_alpha\n");
  168889. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168890. if (row != NULL && row_info != NULL)
  168891. #endif
  168892. {
  168893. png_uint_32 row_width = row_info->width;
  168894. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168895. {
  168896. if (row_info->bit_depth == 8)
  168897. {
  168898. png_bytep sp = row + row_info->rowbytes;
  168899. png_bytep dp = sp;
  168900. png_uint_32 i;
  168901. for (i = 0; i < row_width; i++)
  168902. {
  168903. *(--dp) = (png_byte)(255 - *(--sp));
  168904. sp-=3;
  168905. dp=sp;
  168906. }
  168907. }
  168908. else
  168909. {
  168910. png_bytep sp = row + row_info->rowbytes;
  168911. png_bytep dp = sp;
  168912. png_uint_32 i;
  168913. for (i = 0; i < row_width; i++)
  168914. {
  168915. *(--dp) = (png_byte)(255 - *(--sp));
  168916. *(--dp) = (png_byte)(255 - *(--sp));
  168917. sp-=6;
  168918. dp=sp;
  168919. }
  168920. }
  168921. }
  168922. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168923. {
  168924. if (row_info->bit_depth == 8)
  168925. {
  168926. png_bytep sp = row + row_info->rowbytes;
  168927. png_bytep dp = sp;
  168928. png_uint_32 i;
  168929. for (i = 0; i < row_width; i++)
  168930. {
  168931. *(--dp) = (png_byte)(255 - *(--sp));
  168932. *(--dp) = *(--sp);
  168933. }
  168934. }
  168935. else
  168936. {
  168937. png_bytep sp = row + row_info->rowbytes;
  168938. png_bytep dp = sp;
  168939. png_uint_32 i;
  168940. for (i = 0; i < row_width; i++)
  168941. {
  168942. *(--dp) = (png_byte)(255 - *(--sp));
  168943. *(--dp) = (png_byte)(255 - *(--sp));
  168944. sp-=2;
  168945. dp=sp;
  168946. }
  168947. }
  168948. }
  168949. }
  168950. }
  168951. #endif
  168952. #if defined(PNG_READ_FILLER_SUPPORTED)
  168953. void /* PRIVATE */
  168954. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168955. png_uint_32 filler, png_uint_32 flags)
  168956. {
  168957. png_uint_32 i;
  168958. png_uint_32 row_width = row_info->width;
  168959. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168960. png_byte lo_filler = (png_byte)(filler & 0xff);
  168961. png_debug(1, "in png_do_read_filler\n");
  168962. if (
  168963. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168964. row != NULL && row_info != NULL &&
  168965. #endif
  168966. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168967. {
  168968. if(row_info->bit_depth == 8)
  168969. {
  168970. if (flags & PNG_FLAG_FILLER_AFTER)
  168971. {
  168972. png_bytep sp = row + (png_size_t)row_width;
  168973. png_bytep dp = sp + (png_size_t)row_width;
  168974. for (i = 1; i < row_width; i++)
  168975. {
  168976. *(--dp) = lo_filler;
  168977. *(--dp) = *(--sp);
  168978. }
  168979. *(--dp) = lo_filler;
  168980. row_info->channels = 2;
  168981. row_info->pixel_depth = 16;
  168982. row_info->rowbytes = row_width * 2;
  168983. }
  168984. else
  168985. {
  168986. png_bytep sp = row + (png_size_t)row_width;
  168987. png_bytep dp = sp + (png_size_t)row_width;
  168988. for (i = 0; i < row_width; i++)
  168989. {
  168990. *(--dp) = *(--sp);
  168991. *(--dp) = lo_filler;
  168992. }
  168993. row_info->channels = 2;
  168994. row_info->pixel_depth = 16;
  168995. row_info->rowbytes = row_width * 2;
  168996. }
  168997. }
  168998. else if(row_info->bit_depth == 16)
  168999. {
  169000. if (flags & PNG_FLAG_FILLER_AFTER)
  169001. {
  169002. png_bytep sp = row + (png_size_t)row_width * 2;
  169003. png_bytep dp = sp + (png_size_t)row_width * 2;
  169004. for (i = 1; i < row_width; i++)
  169005. {
  169006. *(--dp) = hi_filler;
  169007. *(--dp) = lo_filler;
  169008. *(--dp) = *(--sp);
  169009. *(--dp) = *(--sp);
  169010. }
  169011. *(--dp) = hi_filler;
  169012. *(--dp) = lo_filler;
  169013. row_info->channels = 2;
  169014. row_info->pixel_depth = 32;
  169015. row_info->rowbytes = row_width * 4;
  169016. }
  169017. else
  169018. {
  169019. png_bytep sp = row + (png_size_t)row_width * 2;
  169020. png_bytep dp = sp + (png_size_t)row_width * 2;
  169021. for (i = 0; i < row_width; i++)
  169022. {
  169023. *(--dp) = *(--sp);
  169024. *(--dp) = *(--sp);
  169025. *(--dp) = hi_filler;
  169026. *(--dp) = lo_filler;
  169027. }
  169028. row_info->channels = 2;
  169029. row_info->pixel_depth = 32;
  169030. row_info->rowbytes = row_width * 4;
  169031. }
  169032. }
  169033. } /* COLOR_TYPE == GRAY */
  169034. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169035. {
  169036. if(row_info->bit_depth == 8)
  169037. {
  169038. if (flags & PNG_FLAG_FILLER_AFTER)
  169039. {
  169040. png_bytep sp = row + (png_size_t)row_width * 3;
  169041. png_bytep dp = sp + (png_size_t)row_width;
  169042. for (i = 1; i < row_width; i++)
  169043. {
  169044. *(--dp) = lo_filler;
  169045. *(--dp) = *(--sp);
  169046. *(--dp) = *(--sp);
  169047. *(--dp) = *(--sp);
  169048. }
  169049. *(--dp) = lo_filler;
  169050. row_info->channels = 4;
  169051. row_info->pixel_depth = 32;
  169052. row_info->rowbytes = row_width * 4;
  169053. }
  169054. else
  169055. {
  169056. png_bytep sp = row + (png_size_t)row_width * 3;
  169057. png_bytep dp = sp + (png_size_t)row_width;
  169058. for (i = 0; i < row_width; i++)
  169059. {
  169060. *(--dp) = *(--sp);
  169061. *(--dp) = *(--sp);
  169062. *(--dp) = *(--sp);
  169063. *(--dp) = lo_filler;
  169064. }
  169065. row_info->channels = 4;
  169066. row_info->pixel_depth = 32;
  169067. row_info->rowbytes = row_width * 4;
  169068. }
  169069. }
  169070. else if(row_info->bit_depth == 16)
  169071. {
  169072. if (flags & PNG_FLAG_FILLER_AFTER)
  169073. {
  169074. png_bytep sp = row + (png_size_t)row_width * 6;
  169075. png_bytep dp = sp + (png_size_t)row_width * 2;
  169076. for (i = 1; i < row_width; i++)
  169077. {
  169078. *(--dp) = hi_filler;
  169079. *(--dp) = lo_filler;
  169080. *(--dp) = *(--sp);
  169081. *(--dp) = *(--sp);
  169082. *(--dp) = *(--sp);
  169083. *(--dp) = *(--sp);
  169084. *(--dp) = *(--sp);
  169085. *(--dp) = *(--sp);
  169086. }
  169087. *(--dp) = hi_filler;
  169088. *(--dp) = lo_filler;
  169089. row_info->channels = 4;
  169090. row_info->pixel_depth = 64;
  169091. row_info->rowbytes = row_width * 8;
  169092. }
  169093. else
  169094. {
  169095. png_bytep sp = row + (png_size_t)row_width * 6;
  169096. png_bytep dp = sp + (png_size_t)row_width * 2;
  169097. for (i = 0; i < row_width; i++)
  169098. {
  169099. *(--dp) = *(--sp);
  169100. *(--dp) = *(--sp);
  169101. *(--dp) = *(--sp);
  169102. *(--dp) = *(--sp);
  169103. *(--dp) = *(--sp);
  169104. *(--dp) = *(--sp);
  169105. *(--dp) = hi_filler;
  169106. *(--dp) = lo_filler;
  169107. }
  169108. row_info->channels = 4;
  169109. row_info->pixel_depth = 64;
  169110. row_info->rowbytes = row_width * 8;
  169111. }
  169112. }
  169113. } /* COLOR_TYPE == RGB */
  169114. }
  169115. #endif
  169116. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169117. void /* PRIVATE */
  169118. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169119. {
  169120. png_uint_32 i;
  169121. png_uint_32 row_width = row_info->width;
  169122. png_debug(1, "in png_do_gray_to_rgb\n");
  169123. if (row_info->bit_depth >= 8 &&
  169124. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169125. row != NULL && row_info != NULL &&
  169126. #endif
  169127. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169128. {
  169129. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169130. {
  169131. if (row_info->bit_depth == 8)
  169132. {
  169133. png_bytep sp = row + (png_size_t)row_width - 1;
  169134. png_bytep dp = sp + (png_size_t)row_width * 2;
  169135. for (i = 0; i < row_width; i++)
  169136. {
  169137. *(dp--) = *sp;
  169138. *(dp--) = *sp;
  169139. *(dp--) = *(sp--);
  169140. }
  169141. }
  169142. else
  169143. {
  169144. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169145. png_bytep dp = sp + (png_size_t)row_width * 4;
  169146. for (i = 0; i < row_width; i++)
  169147. {
  169148. *(dp--) = *sp;
  169149. *(dp--) = *(sp - 1);
  169150. *(dp--) = *sp;
  169151. *(dp--) = *(sp - 1);
  169152. *(dp--) = *(sp--);
  169153. *(dp--) = *(sp--);
  169154. }
  169155. }
  169156. }
  169157. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169158. {
  169159. if (row_info->bit_depth == 8)
  169160. {
  169161. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169162. png_bytep dp = sp + (png_size_t)row_width * 2;
  169163. for (i = 0; i < row_width; i++)
  169164. {
  169165. *(dp--) = *(sp--);
  169166. *(dp--) = *sp;
  169167. *(dp--) = *sp;
  169168. *(dp--) = *(sp--);
  169169. }
  169170. }
  169171. else
  169172. {
  169173. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169174. png_bytep dp = sp + (png_size_t)row_width * 4;
  169175. for (i = 0; i < row_width; i++)
  169176. {
  169177. *(dp--) = *(sp--);
  169178. *(dp--) = *(sp--);
  169179. *(dp--) = *sp;
  169180. *(dp--) = *(sp - 1);
  169181. *(dp--) = *sp;
  169182. *(dp--) = *(sp - 1);
  169183. *(dp--) = *(sp--);
  169184. *(dp--) = *(sp--);
  169185. }
  169186. }
  169187. }
  169188. row_info->channels += (png_byte)2;
  169189. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169190. row_info->pixel_depth = (png_byte)(row_info->channels *
  169191. row_info->bit_depth);
  169192. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169193. }
  169194. }
  169195. #endif
  169196. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169197. int /* PRIVATE */
  169198. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169199. {
  169200. png_uint_32 i;
  169201. png_uint_32 row_width = row_info->width;
  169202. int rgb_error = 0;
  169203. png_debug(1, "in png_do_rgb_to_gray\n");
  169204. if (
  169205. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169206. row != NULL && row_info != NULL &&
  169207. #endif
  169208. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169209. {
  169210. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169211. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169212. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169213. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169214. {
  169215. if (row_info->bit_depth == 8)
  169216. {
  169217. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169218. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169219. {
  169220. png_bytep sp = row;
  169221. png_bytep dp = row;
  169222. for (i = 0; i < row_width; i++)
  169223. {
  169224. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169225. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169226. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169227. if(red != green || red != blue)
  169228. {
  169229. rgb_error |= 1;
  169230. *(dp++) = png_ptr->gamma_from_1[
  169231. (rc*red+gc*green+bc*blue)>>15];
  169232. }
  169233. else
  169234. *(dp++) = *(sp-1);
  169235. }
  169236. }
  169237. else
  169238. #endif
  169239. {
  169240. png_bytep sp = row;
  169241. png_bytep dp = row;
  169242. for (i = 0; i < row_width; i++)
  169243. {
  169244. png_byte red = *(sp++);
  169245. png_byte green = *(sp++);
  169246. png_byte blue = *(sp++);
  169247. if(red != green || red != blue)
  169248. {
  169249. rgb_error |= 1;
  169250. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169251. }
  169252. else
  169253. *(dp++) = *(sp-1);
  169254. }
  169255. }
  169256. }
  169257. else /* RGB bit_depth == 16 */
  169258. {
  169259. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169260. if (png_ptr->gamma_16_to_1 != NULL &&
  169261. png_ptr->gamma_16_from_1 != NULL)
  169262. {
  169263. png_bytep sp = row;
  169264. png_bytep dp = row;
  169265. for (i = 0; i < row_width; i++)
  169266. {
  169267. png_uint_16 red, green, blue, w;
  169268. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169269. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169270. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169271. if(red == green && red == blue)
  169272. w = red;
  169273. else
  169274. {
  169275. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169276. png_ptr->gamma_shift][red>>8];
  169277. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169278. png_ptr->gamma_shift][green>>8];
  169279. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169280. png_ptr->gamma_shift][blue>>8];
  169281. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169282. + bc*blue_1)>>15);
  169283. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169284. png_ptr->gamma_shift][gray16 >> 8];
  169285. rgb_error |= 1;
  169286. }
  169287. *(dp++) = (png_byte)((w>>8) & 0xff);
  169288. *(dp++) = (png_byte)(w & 0xff);
  169289. }
  169290. }
  169291. else
  169292. #endif
  169293. {
  169294. png_bytep sp = row;
  169295. png_bytep dp = row;
  169296. for (i = 0; i < row_width; i++)
  169297. {
  169298. png_uint_16 red, green, blue, gray16;
  169299. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169300. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169301. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169302. if(red != green || red != blue)
  169303. rgb_error |= 1;
  169304. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169305. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169306. *(dp++) = (png_byte)(gray16 & 0xff);
  169307. }
  169308. }
  169309. }
  169310. }
  169311. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169312. {
  169313. if (row_info->bit_depth == 8)
  169314. {
  169315. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169316. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169317. {
  169318. png_bytep sp = row;
  169319. png_bytep dp = row;
  169320. for (i = 0; i < row_width; i++)
  169321. {
  169322. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169323. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169324. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169325. if(red != green || red != blue)
  169326. rgb_error |= 1;
  169327. *(dp++) = png_ptr->gamma_from_1
  169328. [(rc*red + gc*green + bc*blue)>>15];
  169329. *(dp++) = *(sp++); /* alpha */
  169330. }
  169331. }
  169332. else
  169333. #endif
  169334. {
  169335. png_bytep sp = row;
  169336. png_bytep dp = row;
  169337. for (i = 0; i < row_width; i++)
  169338. {
  169339. png_byte red = *(sp++);
  169340. png_byte green = *(sp++);
  169341. png_byte blue = *(sp++);
  169342. if(red != green || red != blue)
  169343. rgb_error |= 1;
  169344. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169345. *(dp++) = *(sp++); /* alpha */
  169346. }
  169347. }
  169348. }
  169349. else /* RGBA bit_depth == 16 */
  169350. {
  169351. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169352. if (png_ptr->gamma_16_to_1 != NULL &&
  169353. png_ptr->gamma_16_from_1 != NULL)
  169354. {
  169355. png_bytep sp = row;
  169356. png_bytep dp = row;
  169357. for (i = 0; i < row_width; i++)
  169358. {
  169359. png_uint_16 red, green, blue, w;
  169360. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169361. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169362. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169363. if(red == green && red == blue)
  169364. w = red;
  169365. else
  169366. {
  169367. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169368. png_ptr->gamma_shift][red>>8];
  169369. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169370. png_ptr->gamma_shift][green>>8];
  169371. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169372. png_ptr->gamma_shift][blue>>8];
  169373. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169374. + gc * green_1 + bc * blue_1)>>15);
  169375. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169376. png_ptr->gamma_shift][gray16 >> 8];
  169377. rgb_error |= 1;
  169378. }
  169379. *(dp++) = (png_byte)((w>>8) & 0xff);
  169380. *(dp++) = (png_byte)(w & 0xff);
  169381. *(dp++) = *(sp++); /* alpha */
  169382. *(dp++) = *(sp++);
  169383. }
  169384. }
  169385. else
  169386. #endif
  169387. {
  169388. png_bytep sp = row;
  169389. png_bytep dp = row;
  169390. for (i = 0; i < row_width; i++)
  169391. {
  169392. png_uint_16 red, green, blue, gray16;
  169393. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169394. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169395. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169396. if(red != green || red != blue)
  169397. rgb_error |= 1;
  169398. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169399. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169400. *(dp++) = (png_byte)(gray16 & 0xff);
  169401. *(dp++) = *(sp++); /* alpha */
  169402. *(dp++) = *(sp++);
  169403. }
  169404. }
  169405. }
  169406. }
  169407. row_info->channels -= (png_byte)2;
  169408. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169409. row_info->pixel_depth = (png_byte)(row_info->channels *
  169410. row_info->bit_depth);
  169411. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169412. }
  169413. return rgb_error;
  169414. }
  169415. #endif
  169416. void PNGAPI
  169417. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169418. {
  169419. int num_palette;
  169420. int color_inc;
  169421. int i;
  169422. int v;
  169423. png_debug(1, "in png_do_build_grayscale_palette\n");
  169424. if (palette == NULL)
  169425. return;
  169426. switch (bit_depth)
  169427. {
  169428. case 1:
  169429. num_palette = 2;
  169430. color_inc = 0xff;
  169431. break;
  169432. case 2:
  169433. num_palette = 4;
  169434. color_inc = 0x55;
  169435. break;
  169436. case 4:
  169437. num_palette = 16;
  169438. color_inc = 0x11;
  169439. break;
  169440. case 8:
  169441. num_palette = 256;
  169442. color_inc = 1;
  169443. break;
  169444. default:
  169445. num_palette = 0;
  169446. color_inc = 0;
  169447. break;
  169448. }
  169449. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169450. {
  169451. palette[i].red = (png_byte)v;
  169452. palette[i].green = (png_byte)v;
  169453. palette[i].blue = (png_byte)v;
  169454. }
  169455. }
  169456. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169457. void /* PRIVATE */
  169458. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169459. int num_palette)
  169460. {
  169461. png_debug(1, "in png_correct_palette\n");
  169462. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169463. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169464. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169465. {
  169466. png_color back, back_1;
  169467. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169468. {
  169469. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169470. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169471. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169472. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169473. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169474. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169475. }
  169476. else
  169477. {
  169478. double g;
  169479. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169480. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169481. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169482. {
  169483. back.red = png_ptr->background.red;
  169484. back.green = png_ptr->background.green;
  169485. back.blue = png_ptr->background.blue;
  169486. }
  169487. else
  169488. {
  169489. back.red =
  169490. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169491. 255.0 + 0.5);
  169492. back.green =
  169493. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169494. 255.0 + 0.5);
  169495. back.blue =
  169496. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169497. 255.0 + 0.5);
  169498. }
  169499. g = 1.0 / png_ptr->background_gamma;
  169500. back_1.red =
  169501. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169502. 255.0 + 0.5);
  169503. back_1.green =
  169504. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169505. 255.0 + 0.5);
  169506. back_1.blue =
  169507. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169508. 255.0 + 0.5);
  169509. }
  169510. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169511. {
  169512. png_uint_32 i;
  169513. for (i = 0; i < (png_uint_32)num_palette; i++)
  169514. {
  169515. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169516. {
  169517. palette[i] = back;
  169518. }
  169519. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169520. {
  169521. png_byte v, w;
  169522. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169523. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169524. palette[i].red = png_ptr->gamma_from_1[w];
  169525. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169526. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169527. palette[i].green = png_ptr->gamma_from_1[w];
  169528. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169529. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169530. palette[i].blue = png_ptr->gamma_from_1[w];
  169531. }
  169532. else
  169533. {
  169534. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169535. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169536. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169537. }
  169538. }
  169539. }
  169540. else
  169541. {
  169542. int i;
  169543. for (i = 0; i < num_palette; i++)
  169544. {
  169545. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169546. {
  169547. palette[i] = back;
  169548. }
  169549. else
  169550. {
  169551. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169552. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169553. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169554. }
  169555. }
  169556. }
  169557. }
  169558. else
  169559. #endif
  169560. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169561. if (png_ptr->transformations & PNG_GAMMA)
  169562. {
  169563. int i;
  169564. for (i = 0; i < num_palette; i++)
  169565. {
  169566. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169567. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169568. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169569. }
  169570. }
  169571. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169572. else
  169573. #endif
  169574. #endif
  169575. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169576. if (png_ptr->transformations & PNG_BACKGROUND)
  169577. {
  169578. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169579. {
  169580. png_color back;
  169581. back.red = (png_byte)png_ptr->background.red;
  169582. back.green = (png_byte)png_ptr->background.green;
  169583. back.blue = (png_byte)png_ptr->background.blue;
  169584. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169585. {
  169586. if (png_ptr->trans[i] == 0)
  169587. {
  169588. palette[i].red = back.red;
  169589. palette[i].green = back.green;
  169590. palette[i].blue = back.blue;
  169591. }
  169592. else if (png_ptr->trans[i] != 0xff)
  169593. {
  169594. png_composite(palette[i].red, png_ptr->palette[i].red,
  169595. png_ptr->trans[i], back.red);
  169596. png_composite(palette[i].green, png_ptr->palette[i].green,
  169597. png_ptr->trans[i], back.green);
  169598. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169599. png_ptr->trans[i], back.blue);
  169600. }
  169601. }
  169602. }
  169603. else /* assume grayscale palette (what else could it be?) */
  169604. {
  169605. int i;
  169606. for (i = 0; i < num_palette; i++)
  169607. {
  169608. if (i == (png_byte)png_ptr->trans_values.gray)
  169609. {
  169610. palette[i].red = (png_byte)png_ptr->background.red;
  169611. palette[i].green = (png_byte)png_ptr->background.green;
  169612. palette[i].blue = (png_byte)png_ptr->background.blue;
  169613. }
  169614. }
  169615. }
  169616. }
  169617. #endif
  169618. }
  169619. #endif
  169620. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169621. void /* PRIVATE */
  169622. png_do_background(png_row_infop row_info, png_bytep row,
  169623. png_color_16p trans_values, png_color_16p background
  169624. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169625. , png_color_16p background_1,
  169626. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169627. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169628. png_uint_16pp gamma_16_to_1, int gamma_shift
  169629. #endif
  169630. )
  169631. {
  169632. png_bytep sp, dp;
  169633. png_uint_32 i;
  169634. png_uint_32 row_width=row_info->width;
  169635. int shift;
  169636. png_debug(1, "in png_do_background\n");
  169637. if (background != NULL &&
  169638. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169639. row != NULL && row_info != NULL &&
  169640. #endif
  169641. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169642. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169643. {
  169644. switch (row_info->color_type)
  169645. {
  169646. case PNG_COLOR_TYPE_GRAY:
  169647. {
  169648. switch (row_info->bit_depth)
  169649. {
  169650. case 1:
  169651. {
  169652. sp = row;
  169653. shift = 7;
  169654. for (i = 0; i < row_width; i++)
  169655. {
  169656. if ((png_uint_16)((*sp >> shift) & 0x01)
  169657. == trans_values->gray)
  169658. {
  169659. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169660. *sp |= (png_byte)(background->gray << shift);
  169661. }
  169662. if (!shift)
  169663. {
  169664. shift = 7;
  169665. sp++;
  169666. }
  169667. else
  169668. shift--;
  169669. }
  169670. break;
  169671. }
  169672. case 2:
  169673. {
  169674. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169675. if (gamma_table != NULL)
  169676. {
  169677. sp = row;
  169678. shift = 6;
  169679. for (i = 0; i < row_width; i++)
  169680. {
  169681. if ((png_uint_16)((*sp >> shift) & 0x03)
  169682. == trans_values->gray)
  169683. {
  169684. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169685. *sp |= (png_byte)(background->gray << shift);
  169686. }
  169687. else
  169688. {
  169689. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169690. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169691. (p << 4) | (p << 6)] >> 6) & 0x03);
  169692. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169693. *sp |= (png_byte)(g << shift);
  169694. }
  169695. if (!shift)
  169696. {
  169697. shift = 6;
  169698. sp++;
  169699. }
  169700. else
  169701. shift -= 2;
  169702. }
  169703. }
  169704. else
  169705. #endif
  169706. {
  169707. sp = row;
  169708. shift = 6;
  169709. for (i = 0; i < row_width; i++)
  169710. {
  169711. if ((png_uint_16)((*sp >> shift) & 0x03)
  169712. == trans_values->gray)
  169713. {
  169714. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169715. *sp |= (png_byte)(background->gray << shift);
  169716. }
  169717. if (!shift)
  169718. {
  169719. shift = 6;
  169720. sp++;
  169721. }
  169722. else
  169723. shift -= 2;
  169724. }
  169725. }
  169726. break;
  169727. }
  169728. case 4:
  169729. {
  169730. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169731. if (gamma_table != NULL)
  169732. {
  169733. sp = row;
  169734. shift = 4;
  169735. for (i = 0; i < row_width; i++)
  169736. {
  169737. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169738. == trans_values->gray)
  169739. {
  169740. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169741. *sp |= (png_byte)(background->gray << shift);
  169742. }
  169743. else
  169744. {
  169745. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169746. png_byte g = (png_byte)((gamma_table[p |
  169747. (p << 4)] >> 4) & 0x0f);
  169748. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169749. *sp |= (png_byte)(g << shift);
  169750. }
  169751. if (!shift)
  169752. {
  169753. shift = 4;
  169754. sp++;
  169755. }
  169756. else
  169757. shift -= 4;
  169758. }
  169759. }
  169760. else
  169761. #endif
  169762. {
  169763. sp = row;
  169764. shift = 4;
  169765. for (i = 0; i < row_width; i++)
  169766. {
  169767. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169768. == trans_values->gray)
  169769. {
  169770. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169771. *sp |= (png_byte)(background->gray << shift);
  169772. }
  169773. if (!shift)
  169774. {
  169775. shift = 4;
  169776. sp++;
  169777. }
  169778. else
  169779. shift -= 4;
  169780. }
  169781. }
  169782. break;
  169783. }
  169784. case 8:
  169785. {
  169786. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169787. if (gamma_table != NULL)
  169788. {
  169789. sp = row;
  169790. for (i = 0; i < row_width; i++, sp++)
  169791. {
  169792. if (*sp == trans_values->gray)
  169793. {
  169794. *sp = (png_byte)background->gray;
  169795. }
  169796. else
  169797. {
  169798. *sp = gamma_table[*sp];
  169799. }
  169800. }
  169801. }
  169802. else
  169803. #endif
  169804. {
  169805. sp = row;
  169806. for (i = 0; i < row_width; i++, sp++)
  169807. {
  169808. if (*sp == trans_values->gray)
  169809. {
  169810. *sp = (png_byte)background->gray;
  169811. }
  169812. }
  169813. }
  169814. break;
  169815. }
  169816. case 16:
  169817. {
  169818. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169819. if (gamma_16 != NULL)
  169820. {
  169821. sp = row;
  169822. for (i = 0; i < row_width; i++, sp += 2)
  169823. {
  169824. png_uint_16 v;
  169825. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169826. if (v == trans_values->gray)
  169827. {
  169828. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169829. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169830. }
  169831. else
  169832. {
  169833. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169834. *sp = (png_byte)((v >> 8) & 0xff);
  169835. *(sp + 1) = (png_byte)(v & 0xff);
  169836. }
  169837. }
  169838. }
  169839. else
  169840. #endif
  169841. {
  169842. sp = row;
  169843. for (i = 0; i < row_width; i++, sp += 2)
  169844. {
  169845. png_uint_16 v;
  169846. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169847. if (v == trans_values->gray)
  169848. {
  169849. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169850. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169851. }
  169852. }
  169853. }
  169854. break;
  169855. }
  169856. }
  169857. break;
  169858. }
  169859. case PNG_COLOR_TYPE_RGB:
  169860. {
  169861. if (row_info->bit_depth == 8)
  169862. {
  169863. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169864. if (gamma_table != NULL)
  169865. {
  169866. sp = row;
  169867. for (i = 0; i < row_width; i++, sp += 3)
  169868. {
  169869. if (*sp == trans_values->red &&
  169870. *(sp + 1) == trans_values->green &&
  169871. *(sp + 2) == trans_values->blue)
  169872. {
  169873. *sp = (png_byte)background->red;
  169874. *(sp + 1) = (png_byte)background->green;
  169875. *(sp + 2) = (png_byte)background->blue;
  169876. }
  169877. else
  169878. {
  169879. *sp = gamma_table[*sp];
  169880. *(sp + 1) = gamma_table[*(sp + 1)];
  169881. *(sp + 2) = gamma_table[*(sp + 2)];
  169882. }
  169883. }
  169884. }
  169885. else
  169886. #endif
  169887. {
  169888. sp = row;
  169889. for (i = 0; i < row_width; i++, sp += 3)
  169890. {
  169891. if (*sp == trans_values->red &&
  169892. *(sp + 1) == trans_values->green &&
  169893. *(sp + 2) == trans_values->blue)
  169894. {
  169895. *sp = (png_byte)background->red;
  169896. *(sp + 1) = (png_byte)background->green;
  169897. *(sp + 2) = (png_byte)background->blue;
  169898. }
  169899. }
  169900. }
  169901. }
  169902. else /* if (row_info->bit_depth == 16) */
  169903. {
  169904. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169905. if (gamma_16 != NULL)
  169906. {
  169907. sp = row;
  169908. for (i = 0; i < row_width; i++, sp += 6)
  169909. {
  169910. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169911. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169912. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169913. if (r == trans_values->red && g == trans_values->green &&
  169914. b == trans_values->blue)
  169915. {
  169916. *sp = (png_byte)((background->red >> 8) & 0xff);
  169917. *(sp + 1) = (png_byte)(background->red & 0xff);
  169918. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169919. *(sp + 3) = (png_byte)(background->green & 0xff);
  169920. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169921. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169922. }
  169923. else
  169924. {
  169925. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169926. *sp = (png_byte)((v >> 8) & 0xff);
  169927. *(sp + 1) = (png_byte)(v & 0xff);
  169928. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169929. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169930. *(sp + 3) = (png_byte)(v & 0xff);
  169931. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169932. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169933. *(sp + 5) = (png_byte)(v & 0xff);
  169934. }
  169935. }
  169936. }
  169937. else
  169938. #endif
  169939. {
  169940. sp = row;
  169941. for (i = 0; i < row_width; i++, sp += 6)
  169942. {
  169943. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169944. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169945. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169946. if (r == trans_values->red && g == trans_values->green &&
  169947. b == trans_values->blue)
  169948. {
  169949. *sp = (png_byte)((background->red >> 8) & 0xff);
  169950. *(sp + 1) = (png_byte)(background->red & 0xff);
  169951. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169952. *(sp + 3) = (png_byte)(background->green & 0xff);
  169953. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169954. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169955. }
  169956. }
  169957. }
  169958. }
  169959. break;
  169960. }
  169961. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169962. {
  169963. if (row_info->bit_depth == 8)
  169964. {
  169965. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169966. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169967. gamma_table != NULL)
  169968. {
  169969. sp = row;
  169970. dp = row;
  169971. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169972. {
  169973. png_uint_16 a = *(sp + 1);
  169974. if (a == 0xff)
  169975. {
  169976. *dp = gamma_table[*sp];
  169977. }
  169978. else if (a == 0)
  169979. {
  169980. *dp = (png_byte)background->gray;
  169981. }
  169982. else
  169983. {
  169984. png_byte v, w;
  169985. v = gamma_to_1[*sp];
  169986. png_composite(w, v, a, background_1->gray);
  169987. *dp = gamma_from_1[w];
  169988. }
  169989. }
  169990. }
  169991. else
  169992. #endif
  169993. {
  169994. sp = row;
  169995. dp = row;
  169996. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169997. {
  169998. png_byte a = *(sp + 1);
  169999. if (a == 0xff)
  170000. {
  170001. *dp = *sp;
  170002. }
  170003. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170004. else if (a == 0)
  170005. {
  170006. *dp = (png_byte)background->gray;
  170007. }
  170008. else
  170009. {
  170010. png_composite(*dp, *sp, a, background_1->gray);
  170011. }
  170012. #else
  170013. *dp = (png_byte)background->gray;
  170014. #endif
  170015. }
  170016. }
  170017. }
  170018. else /* if (png_ptr->bit_depth == 16) */
  170019. {
  170020. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170021. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170022. gamma_16_to_1 != NULL)
  170023. {
  170024. sp = row;
  170025. dp = row;
  170026. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170027. {
  170028. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170029. if (a == (png_uint_16)0xffff)
  170030. {
  170031. png_uint_16 v;
  170032. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170033. *dp = (png_byte)((v >> 8) & 0xff);
  170034. *(dp + 1) = (png_byte)(v & 0xff);
  170035. }
  170036. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170037. else if (a == 0)
  170038. #else
  170039. else
  170040. #endif
  170041. {
  170042. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170043. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170044. }
  170045. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170046. else
  170047. {
  170048. png_uint_16 g, v, w;
  170049. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170050. png_composite_16(v, g, a, background_1->gray);
  170051. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  170052. *dp = (png_byte)((w >> 8) & 0xff);
  170053. *(dp + 1) = (png_byte)(w & 0xff);
  170054. }
  170055. #endif
  170056. }
  170057. }
  170058. else
  170059. #endif
  170060. {
  170061. sp = row;
  170062. dp = row;
  170063. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170064. {
  170065. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170066. if (a == (png_uint_16)0xffff)
  170067. {
  170068. png_memcpy(dp, sp, 2);
  170069. }
  170070. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170071. else if (a == 0)
  170072. #else
  170073. else
  170074. #endif
  170075. {
  170076. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170077. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170078. }
  170079. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170080. else
  170081. {
  170082. png_uint_16 g, v;
  170083. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170084. png_composite_16(v, g, a, background_1->gray);
  170085. *dp = (png_byte)((v >> 8) & 0xff);
  170086. *(dp + 1) = (png_byte)(v & 0xff);
  170087. }
  170088. #endif
  170089. }
  170090. }
  170091. }
  170092. break;
  170093. }
  170094. case PNG_COLOR_TYPE_RGB_ALPHA:
  170095. {
  170096. if (row_info->bit_depth == 8)
  170097. {
  170098. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170099. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170100. gamma_table != NULL)
  170101. {
  170102. sp = row;
  170103. dp = row;
  170104. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170105. {
  170106. png_byte a = *(sp + 3);
  170107. if (a == 0xff)
  170108. {
  170109. *dp = gamma_table[*sp];
  170110. *(dp + 1) = gamma_table[*(sp + 1)];
  170111. *(dp + 2) = gamma_table[*(sp + 2)];
  170112. }
  170113. else if (a == 0)
  170114. {
  170115. *dp = (png_byte)background->red;
  170116. *(dp + 1) = (png_byte)background->green;
  170117. *(dp + 2) = (png_byte)background->blue;
  170118. }
  170119. else
  170120. {
  170121. png_byte v, w;
  170122. v = gamma_to_1[*sp];
  170123. png_composite(w, v, a, background_1->red);
  170124. *dp = gamma_from_1[w];
  170125. v = gamma_to_1[*(sp + 1)];
  170126. png_composite(w, v, a, background_1->green);
  170127. *(dp + 1) = gamma_from_1[w];
  170128. v = gamma_to_1[*(sp + 2)];
  170129. png_composite(w, v, a, background_1->blue);
  170130. *(dp + 2) = gamma_from_1[w];
  170131. }
  170132. }
  170133. }
  170134. else
  170135. #endif
  170136. {
  170137. sp = row;
  170138. dp = row;
  170139. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170140. {
  170141. png_byte a = *(sp + 3);
  170142. if (a == 0xff)
  170143. {
  170144. *dp = *sp;
  170145. *(dp + 1) = *(sp + 1);
  170146. *(dp + 2) = *(sp + 2);
  170147. }
  170148. else if (a == 0)
  170149. {
  170150. *dp = (png_byte)background->red;
  170151. *(dp + 1) = (png_byte)background->green;
  170152. *(dp + 2) = (png_byte)background->blue;
  170153. }
  170154. else
  170155. {
  170156. png_composite(*dp, *sp, a, background->red);
  170157. png_composite(*(dp + 1), *(sp + 1), a,
  170158. background->green);
  170159. png_composite(*(dp + 2), *(sp + 2), a,
  170160. background->blue);
  170161. }
  170162. }
  170163. }
  170164. }
  170165. else /* if (row_info->bit_depth == 16) */
  170166. {
  170167. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170168. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170169. gamma_16_to_1 != NULL)
  170170. {
  170171. sp = row;
  170172. dp = row;
  170173. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170174. {
  170175. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170176. << 8) + (png_uint_16)(*(sp + 7)));
  170177. if (a == (png_uint_16)0xffff)
  170178. {
  170179. png_uint_16 v;
  170180. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170181. *dp = (png_byte)((v >> 8) & 0xff);
  170182. *(dp + 1) = (png_byte)(v & 0xff);
  170183. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170184. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170185. *(dp + 3) = (png_byte)(v & 0xff);
  170186. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170187. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170188. *(dp + 5) = (png_byte)(v & 0xff);
  170189. }
  170190. else if (a == 0)
  170191. {
  170192. *dp = (png_byte)((background->red >> 8) & 0xff);
  170193. *(dp + 1) = (png_byte)(background->red & 0xff);
  170194. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170195. *(dp + 3) = (png_byte)(background->green & 0xff);
  170196. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170197. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170198. }
  170199. else
  170200. {
  170201. png_uint_16 v, w, x;
  170202. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170203. png_composite_16(w, v, a, background_1->red);
  170204. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170205. *dp = (png_byte)((x >> 8) & 0xff);
  170206. *(dp + 1) = (png_byte)(x & 0xff);
  170207. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170208. png_composite_16(w, v, a, background_1->green);
  170209. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170210. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170211. *(dp + 3) = (png_byte)(x & 0xff);
  170212. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170213. png_composite_16(w, v, a, background_1->blue);
  170214. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170215. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170216. *(dp + 5) = (png_byte)(x & 0xff);
  170217. }
  170218. }
  170219. }
  170220. else
  170221. #endif
  170222. {
  170223. sp = row;
  170224. dp = row;
  170225. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170226. {
  170227. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170228. << 8) + (png_uint_16)(*(sp + 7)));
  170229. if (a == (png_uint_16)0xffff)
  170230. {
  170231. png_memcpy(dp, sp, 6);
  170232. }
  170233. else if (a == 0)
  170234. {
  170235. *dp = (png_byte)((background->red >> 8) & 0xff);
  170236. *(dp + 1) = (png_byte)(background->red & 0xff);
  170237. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170238. *(dp + 3) = (png_byte)(background->green & 0xff);
  170239. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170240. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170241. }
  170242. else
  170243. {
  170244. png_uint_16 v;
  170245. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170246. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170247. + *(sp + 3));
  170248. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170249. + *(sp + 5));
  170250. png_composite_16(v, r, a, background->red);
  170251. *dp = (png_byte)((v >> 8) & 0xff);
  170252. *(dp + 1) = (png_byte)(v & 0xff);
  170253. png_composite_16(v, g, a, background->green);
  170254. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170255. *(dp + 3) = (png_byte)(v & 0xff);
  170256. png_composite_16(v, b, a, background->blue);
  170257. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170258. *(dp + 5) = (png_byte)(v & 0xff);
  170259. }
  170260. }
  170261. }
  170262. }
  170263. break;
  170264. }
  170265. }
  170266. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170267. {
  170268. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170269. row_info->channels--;
  170270. row_info->pixel_depth = (png_byte)(row_info->channels *
  170271. row_info->bit_depth);
  170272. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170273. }
  170274. }
  170275. }
  170276. #endif
  170277. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170278. void /* PRIVATE */
  170279. png_do_gamma(png_row_infop row_info, png_bytep row,
  170280. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170281. int gamma_shift)
  170282. {
  170283. png_bytep sp;
  170284. png_uint_32 i;
  170285. png_uint_32 row_width=row_info->width;
  170286. png_debug(1, "in png_do_gamma\n");
  170287. if (
  170288. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170289. row != NULL && row_info != NULL &&
  170290. #endif
  170291. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170292. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170293. {
  170294. switch (row_info->color_type)
  170295. {
  170296. case PNG_COLOR_TYPE_RGB:
  170297. {
  170298. if (row_info->bit_depth == 8)
  170299. {
  170300. sp = row;
  170301. for (i = 0; i < row_width; i++)
  170302. {
  170303. *sp = gamma_table[*sp];
  170304. sp++;
  170305. *sp = gamma_table[*sp];
  170306. sp++;
  170307. *sp = gamma_table[*sp];
  170308. sp++;
  170309. }
  170310. }
  170311. else /* if (row_info->bit_depth == 16) */
  170312. {
  170313. sp = row;
  170314. for (i = 0; i < row_width; i++)
  170315. {
  170316. png_uint_16 v;
  170317. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170318. *sp = (png_byte)((v >> 8) & 0xff);
  170319. *(sp + 1) = (png_byte)(v & 0xff);
  170320. sp += 2;
  170321. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170322. *sp = (png_byte)((v >> 8) & 0xff);
  170323. *(sp + 1) = (png_byte)(v & 0xff);
  170324. sp += 2;
  170325. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170326. *sp = (png_byte)((v >> 8) & 0xff);
  170327. *(sp + 1) = (png_byte)(v & 0xff);
  170328. sp += 2;
  170329. }
  170330. }
  170331. break;
  170332. }
  170333. case PNG_COLOR_TYPE_RGB_ALPHA:
  170334. {
  170335. if (row_info->bit_depth == 8)
  170336. {
  170337. sp = row;
  170338. for (i = 0; i < row_width; i++)
  170339. {
  170340. *sp = gamma_table[*sp];
  170341. sp++;
  170342. *sp = gamma_table[*sp];
  170343. sp++;
  170344. *sp = gamma_table[*sp];
  170345. sp++;
  170346. sp++;
  170347. }
  170348. }
  170349. else /* if (row_info->bit_depth == 16) */
  170350. {
  170351. sp = row;
  170352. for (i = 0; i < row_width; i++)
  170353. {
  170354. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170355. *sp = (png_byte)((v >> 8) & 0xff);
  170356. *(sp + 1) = (png_byte)(v & 0xff);
  170357. sp += 2;
  170358. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170359. *sp = (png_byte)((v >> 8) & 0xff);
  170360. *(sp + 1) = (png_byte)(v & 0xff);
  170361. sp += 2;
  170362. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170363. *sp = (png_byte)((v >> 8) & 0xff);
  170364. *(sp + 1) = (png_byte)(v & 0xff);
  170365. sp += 4;
  170366. }
  170367. }
  170368. break;
  170369. }
  170370. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170371. {
  170372. if (row_info->bit_depth == 8)
  170373. {
  170374. sp = row;
  170375. for (i = 0; i < row_width; i++)
  170376. {
  170377. *sp = gamma_table[*sp];
  170378. sp += 2;
  170379. }
  170380. }
  170381. else /* if (row_info->bit_depth == 16) */
  170382. {
  170383. sp = row;
  170384. for (i = 0; i < row_width; i++)
  170385. {
  170386. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170387. *sp = (png_byte)((v >> 8) & 0xff);
  170388. *(sp + 1) = (png_byte)(v & 0xff);
  170389. sp += 4;
  170390. }
  170391. }
  170392. break;
  170393. }
  170394. case PNG_COLOR_TYPE_GRAY:
  170395. {
  170396. if (row_info->bit_depth == 2)
  170397. {
  170398. sp = row;
  170399. for (i = 0; i < row_width; i += 4)
  170400. {
  170401. int a = *sp & 0xc0;
  170402. int b = *sp & 0x30;
  170403. int c = *sp & 0x0c;
  170404. int d = *sp & 0x03;
  170405. *sp = (png_byte)(
  170406. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170407. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170408. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170409. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170410. sp++;
  170411. }
  170412. }
  170413. if (row_info->bit_depth == 4)
  170414. {
  170415. sp = row;
  170416. for (i = 0; i < row_width; i += 2)
  170417. {
  170418. int msb = *sp & 0xf0;
  170419. int lsb = *sp & 0x0f;
  170420. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170421. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170422. sp++;
  170423. }
  170424. }
  170425. else if (row_info->bit_depth == 8)
  170426. {
  170427. sp = row;
  170428. for (i = 0; i < row_width; i++)
  170429. {
  170430. *sp = gamma_table[*sp];
  170431. sp++;
  170432. }
  170433. }
  170434. else if (row_info->bit_depth == 16)
  170435. {
  170436. sp = row;
  170437. for (i = 0; i < row_width; i++)
  170438. {
  170439. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170440. *sp = (png_byte)((v >> 8) & 0xff);
  170441. *(sp + 1) = (png_byte)(v & 0xff);
  170442. sp += 2;
  170443. }
  170444. }
  170445. break;
  170446. }
  170447. }
  170448. }
  170449. }
  170450. #endif
  170451. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170452. void /* PRIVATE */
  170453. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170454. png_colorp palette, png_bytep trans, int num_trans)
  170455. {
  170456. int shift, value;
  170457. png_bytep sp, dp;
  170458. png_uint_32 i;
  170459. png_uint_32 row_width=row_info->width;
  170460. png_debug(1, "in png_do_expand_palette\n");
  170461. if (
  170462. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170463. row != NULL && row_info != NULL &&
  170464. #endif
  170465. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170466. {
  170467. if (row_info->bit_depth < 8)
  170468. {
  170469. switch (row_info->bit_depth)
  170470. {
  170471. case 1:
  170472. {
  170473. sp = row + (png_size_t)((row_width - 1) >> 3);
  170474. dp = row + (png_size_t)row_width - 1;
  170475. shift = 7 - (int)((row_width + 7) & 0x07);
  170476. for (i = 0; i < row_width; i++)
  170477. {
  170478. if ((*sp >> shift) & 0x01)
  170479. *dp = 1;
  170480. else
  170481. *dp = 0;
  170482. if (shift == 7)
  170483. {
  170484. shift = 0;
  170485. sp--;
  170486. }
  170487. else
  170488. shift++;
  170489. dp--;
  170490. }
  170491. break;
  170492. }
  170493. case 2:
  170494. {
  170495. sp = row + (png_size_t)((row_width - 1) >> 2);
  170496. dp = row + (png_size_t)row_width - 1;
  170497. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170498. for (i = 0; i < row_width; i++)
  170499. {
  170500. value = (*sp >> shift) & 0x03;
  170501. *dp = (png_byte)value;
  170502. if (shift == 6)
  170503. {
  170504. shift = 0;
  170505. sp--;
  170506. }
  170507. else
  170508. shift += 2;
  170509. dp--;
  170510. }
  170511. break;
  170512. }
  170513. case 4:
  170514. {
  170515. sp = row + (png_size_t)((row_width - 1) >> 1);
  170516. dp = row + (png_size_t)row_width - 1;
  170517. shift = (int)((row_width & 0x01) << 2);
  170518. for (i = 0; i < row_width; i++)
  170519. {
  170520. value = (*sp >> shift) & 0x0f;
  170521. *dp = (png_byte)value;
  170522. if (shift == 4)
  170523. {
  170524. shift = 0;
  170525. sp--;
  170526. }
  170527. else
  170528. shift += 4;
  170529. dp--;
  170530. }
  170531. break;
  170532. }
  170533. }
  170534. row_info->bit_depth = 8;
  170535. row_info->pixel_depth = 8;
  170536. row_info->rowbytes = row_width;
  170537. }
  170538. switch (row_info->bit_depth)
  170539. {
  170540. case 8:
  170541. {
  170542. if (trans != NULL)
  170543. {
  170544. sp = row + (png_size_t)row_width - 1;
  170545. dp = row + (png_size_t)(row_width << 2) - 1;
  170546. for (i = 0; i < row_width; i++)
  170547. {
  170548. if ((int)(*sp) >= num_trans)
  170549. *dp-- = 0xff;
  170550. else
  170551. *dp-- = trans[*sp];
  170552. *dp-- = palette[*sp].blue;
  170553. *dp-- = palette[*sp].green;
  170554. *dp-- = palette[*sp].red;
  170555. sp--;
  170556. }
  170557. row_info->bit_depth = 8;
  170558. row_info->pixel_depth = 32;
  170559. row_info->rowbytes = row_width * 4;
  170560. row_info->color_type = 6;
  170561. row_info->channels = 4;
  170562. }
  170563. else
  170564. {
  170565. sp = row + (png_size_t)row_width - 1;
  170566. dp = row + (png_size_t)(row_width * 3) - 1;
  170567. for (i = 0; i < row_width; i++)
  170568. {
  170569. *dp-- = palette[*sp].blue;
  170570. *dp-- = palette[*sp].green;
  170571. *dp-- = palette[*sp].red;
  170572. sp--;
  170573. }
  170574. row_info->bit_depth = 8;
  170575. row_info->pixel_depth = 24;
  170576. row_info->rowbytes = row_width * 3;
  170577. row_info->color_type = 2;
  170578. row_info->channels = 3;
  170579. }
  170580. break;
  170581. }
  170582. }
  170583. }
  170584. }
  170585. void /* PRIVATE */
  170586. png_do_expand(png_row_infop row_info, png_bytep row,
  170587. png_color_16p trans_value)
  170588. {
  170589. int shift, value;
  170590. png_bytep sp, dp;
  170591. png_uint_32 i;
  170592. png_uint_32 row_width=row_info->width;
  170593. png_debug(1, "in png_do_expand\n");
  170594. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170595. if (row != NULL && row_info != NULL)
  170596. #endif
  170597. {
  170598. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170599. {
  170600. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170601. if (row_info->bit_depth < 8)
  170602. {
  170603. switch (row_info->bit_depth)
  170604. {
  170605. case 1:
  170606. {
  170607. gray = (png_uint_16)((gray&0x01)*0xff);
  170608. sp = row + (png_size_t)((row_width - 1) >> 3);
  170609. dp = row + (png_size_t)row_width - 1;
  170610. shift = 7 - (int)((row_width + 7) & 0x07);
  170611. for (i = 0; i < row_width; i++)
  170612. {
  170613. if ((*sp >> shift) & 0x01)
  170614. *dp = 0xff;
  170615. else
  170616. *dp = 0;
  170617. if (shift == 7)
  170618. {
  170619. shift = 0;
  170620. sp--;
  170621. }
  170622. else
  170623. shift++;
  170624. dp--;
  170625. }
  170626. break;
  170627. }
  170628. case 2:
  170629. {
  170630. gray = (png_uint_16)((gray&0x03)*0x55);
  170631. sp = row + (png_size_t)((row_width - 1) >> 2);
  170632. dp = row + (png_size_t)row_width - 1;
  170633. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170634. for (i = 0; i < row_width; i++)
  170635. {
  170636. value = (*sp >> shift) & 0x03;
  170637. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170638. (value << 6));
  170639. if (shift == 6)
  170640. {
  170641. shift = 0;
  170642. sp--;
  170643. }
  170644. else
  170645. shift += 2;
  170646. dp--;
  170647. }
  170648. break;
  170649. }
  170650. case 4:
  170651. {
  170652. gray = (png_uint_16)((gray&0x0f)*0x11);
  170653. sp = row + (png_size_t)((row_width - 1) >> 1);
  170654. dp = row + (png_size_t)row_width - 1;
  170655. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170656. for (i = 0; i < row_width; i++)
  170657. {
  170658. value = (*sp >> shift) & 0x0f;
  170659. *dp = (png_byte)(value | (value << 4));
  170660. if (shift == 4)
  170661. {
  170662. shift = 0;
  170663. sp--;
  170664. }
  170665. else
  170666. shift = 4;
  170667. dp--;
  170668. }
  170669. break;
  170670. }
  170671. }
  170672. row_info->bit_depth = 8;
  170673. row_info->pixel_depth = 8;
  170674. row_info->rowbytes = row_width;
  170675. }
  170676. if (trans_value != NULL)
  170677. {
  170678. if (row_info->bit_depth == 8)
  170679. {
  170680. gray = gray & 0xff;
  170681. sp = row + (png_size_t)row_width - 1;
  170682. dp = row + (png_size_t)(row_width << 1) - 1;
  170683. for (i = 0; i < row_width; i++)
  170684. {
  170685. if (*sp == gray)
  170686. *dp-- = 0;
  170687. else
  170688. *dp-- = 0xff;
  170689. *dp-- = *sp--;
  170690. }
  170691. }
  170692. else if (row_info->bit_depth == 16)
  170693. {
  170694. png_byte gray_high = (gray >> 8) & 0xff;
  170695. png_byte gray_low = gray & 0xff;
  170696. sp = row + row_info->rowbytes - 1;
  170697. dp = row + (row_info->rowbytes << 1) - 1;
  170698. for (i = 0; i < row_width; i++)
  170699. {
  170700. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170701. {
  170702. *dp-- = 0;
  170703. *dp-- = 0;
  170704. }
  170705. else
  170706. {
  170707. *dp-- = 0xff;
  170708. *dp-- = 0xff;
  170709. }
  170710. *dp-- = *sp--;
  170711. *dp-- = *sp--;
  170712. }
  170713. }
  170714. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170715. row_info->channels = 2;
  170716. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170717. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170718. row_width);
  170719. }
  170720. }
  170721. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170722. {
  170723. if (row_info->bit_depth == 8)
  170724. {
  170725. png_byte red = trans_value->red & 0xff;
  170726. png_byte green = trans_value->green & 0xff;
  170727. png_byte blue = trans_value->blue & 0xff;
  170728. sp = row + (png_size_t)row_info->rowbytes - 1;
  170729. dp = row + (png_size_t)(row_width << 2) - 1;
  170730. for (i = 0; i < row_width; i++)
  170731. {
  170732. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170733. *dp-- = 0;
  170734. else
  170735. *dp-- = 0xff;
  170736. *dp-- = *sp--;
  170737. *dp-- = *sp--;
  170738. *dp-- = *sp--;
  170739. }
  170740. }
  170741. else if (row_info->bit_depth == 16)
  170742. {
  170743. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170744. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170745. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170746. png_byte red_low = trans_value->red & 0xff;
  170747. png_byte green_low = trans_value->green & 0xff;
  170748. png_byte blue_low = trans_value->blue & 0xff;
  170749. sp = row + row_info->rowbytes - 1;
  170750. dp = row + (png_size_t)(row_width << 3) - 1;
  170751. for (i = 0; i < row_width; i++)
  170752. {
  170753. if (*(sp - 5) == red_high &&
  170754. *(sp - 4) == red_low &&
  170755. *(sp - 3) == green_high &&
  170756. *(sp - 2) == green_low &&
  170757. *(sp - 1) == blue_high &&
  170758. *(sp ) == blue_low)
  170759. {
  170760. *dp-- = 0;
  170761. *dp-- = 0;
  170762. }
  170763. else
  170764. {
  170765. *dp-- = 0xff;
  170766. *dp-- = 0xff;
  170767. }
  170768. *dp-- = *sp--;
  170769. *dp-- = *sp--;
  170770. *dp-- = *sp--;
  170771. *dp-- = *sp--;
  170772. *dp-- = *sp--;
  170773. *dp-- = *sp--;
  170774. }
  170775. }
  170776. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170777. row_info->channels = 4;
  170778. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170779. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170780. }
  170781. }
  170782. }
  170783. #endif
  170784. #if defined(PNG_READ_DITHER_SUPPORTED)
  170785. void /* PRIVATE */
  170786. png_do_dither(png_row_infop row_info, png_bytep row,
  170787. png_bytep palette_lookup, png_bytep dither_lookup)
  170788. {
  170789. png_bytep sp, dp;
  170790. png_uint_32 i;
  170791. png_uint_32 row_width=row_info->width;
  170792. png_debug(1, "in png_do_dither\n");
  170793. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170794. if (row != NULL && row_info != NULL)
  170795. #endif
  170796. {
  170797. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170798. palette_lookup && row_info->bit_depth == 8)
  170799. {
  170800. int r, g, b, p;
  170801. sp = row;
  170802. dp = row;
  170803. for (i = 0; i < row_width; i++)
  170804. {
  170805. r = *sp++;
  170806. g = *sp++;
  170807. b = *sp++;
  170808. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170809. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170810. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170811. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170812. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170813. (PNG_DITHER_BLUE_BITS)) |
  170814. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170815. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170816. *dp++ = palette_lookup[p];
  170817. }
  170818. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170819. row_info->channels = 1;
  170820. row_info->pixel_depth = row_info->bit_depth;
  170821. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170822. }
  170823. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170824. palette_lookup != NULL && row_info->bit_depth == 8)
  170825. {
  170826. int r, g, b, p;
  170827. sp = row;
  170828. dp = row;
  170829. for (i = 0; i < row_width; i++)
  170830. {
  170831. r = *sp++;
  170832. g = *sp++;
  170833. b = *sp++;
  170834. sp++;
  170835. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170836. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170837. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170838. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170839. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170840. (PNG_DITHER_BLUE_BITS)) |
  170841. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170842. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170843. *dp++ = palette_lookup[p];
  170844. }
  170845. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170846. row_info->channels = 1;
  170847. row_info->pixel_depth = row_info->bit_depth;
  170848. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170849. }
  170850. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170851. dither_lookup && row_info->bit_depth == 8)
  170852. {
  170853. sp = row;
  170854. for (i = 0; i < row_width; i++, sp++)
  170855. {
  170856. *sp = dither_lookup[*sp];
  170857. }
  170858. }
  170859. }
  170860. }
  170861. #endif
  170862. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170863. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170864. static PNG_CONST int png_gamma_shift[] =
  170865. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170866. void /* PRIVATE */
  170867. png_build_gamma_table(png_structp png_ptr)
  170868. {
  170869. png_debug(1, "in png_build_gamma_table\n");
  170870. if (png_ptr->bit_depth <= 8)
  170871. {
  170872. int i;
  170873. double g;
  170874. if (png_ptr->screen_gamma > .000001)
  170875. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170876. else
  170877. g = 1.0;
  170878. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170879. (png_uint_32)256);
  170880. for (i = 0; i < 256; i++)
  170881. {
  170882. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170883. g) * 255.0 + .5);
  170884. }
  170885. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170886. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170887. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170888. {
  170889. g = 1.0 / (png_ptr->gamma);
  170890. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170891. (png_uint_32)256);
  170892. for (i = 0; i < 256; i++)
  170893. {
  170894. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170895. g) * 255.0 + .5);
  170896. }
  170897. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170898. (png_uint_32)256);
  170899. if(png_ptr->screen_gamma > 0.000001)
  170900. g = 1.0 / png_ptr->screen_gamma;
  170901. else
  170902. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170903. for (i = 0; i < 256; i++)
  170904. {
  170905. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170906. g) * 255.0 + .5);
  170907. }
  170908. }
  170909. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170910. }
  170911. else
  170912. {
  170913. double g;
  170914. int i, j, shift, num;
  170915. int sig_bit;
  170916. png_uint_32 ig;
  170917. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170918. {
  170919. sig_bit = (int)png_ptr->sig_bit.red;
  170920. if ((int)png_ptr->sig_bit.green > sig_bit)
  170921. sig_bit = png_ptr->sig_bit.green;
  170922. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170923. sig_bit = png_ptr->sig_bit.blue;
  170924. }
  170925. else
  170926. {
  170927. sig_bit = (int)png_ptr->sig_bit.gray;
  170928. }
  170929. if (sig_bit > 0)
  170930. shift = 16 - sig_bit;
  170931. else
  170932. shift = 0;
  170933. if (png_ptr->transformations & PNG_16_TO_8)
  170934. {
  170935. if (shift < (16 - PNG_MAX_GAMMA_8))
  170936. shift = (16 - PNG_MAX_GAMMA_8);
  170937. }
  170938. if (shift > 8)
  170939. shift = 8;
  170940. if (shift < 0)
  170941. shift = 0;
  170942. png_ptr->gamma_shift = (png_byte)shift;
  170943. num = (1 << (8 - shift));
  170944. if (png_ptr->screen_gamma > .000001)
  170945. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170946. else
  170947. g = 1.0;
  170948. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170949. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170950. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170951. {
  170952. double fin, fout;
  170953. png_uint_32 last, max;
  170954. for (i = 0; i < num; i++)
  170955. {
  170956. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170957. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170958. }
  170959. g = 1.0 / g;
  170960. last = 0;
  170961. for (i = 0; i < 256; i++)
  170962. {
  170963. fout = ((double)i + 0.5) / 256.0;
  170964. fin = pow(fout, g);
  170965. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170966. while (last <= max)
  170967. {
  170968. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170969. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170970. (png_uint_16)i | ((png_uint_16)i << 8));
  170971. last++;
  170972. }
  170973. }
  170974. while (last < ((png_uint_32)num << 8))
  170975. {
  170976. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170977. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170978. last++;
  170979. }
  170980. }
  170981. else
  170982. {
  170983. for (i = 0; i < num; i++)
  170984. {
  170985. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170986. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170987. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170988. for (j = 0; j < 256; j++)
  170989. {
  170990. png_ptr->gamma_16_table[i][j] =
  170991. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170992. 65535.0, g) * 65535.0 + .5);
  170993. }
  170994. }
  170995. }
  170996. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170997. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170998. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170999. {
  171000. g = 1.0 / (png_ptr->gamma);
  171001. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  171002. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  171003. for (i = 0; i < num; i++)
  171004. {
  171005. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171006. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171007. ig = (((png_uint_32)i *
  171008. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171009. for (j = 0; j < 256; j++)
  171010. {
  171011. png_ptr->gamma_16_to_1[i][j] =
  171012. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171013. 65535.0, g) * 65535.0 + .5);
  171014. }
  171015. }
  171016. if(png_ptr->screen_gamma > 0.000001)
  171017. g = 1.0 / png_ptr->screen_gamma;
  171018. else
  171019. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  171020. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  171021. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  171022. for (i = 0; i < num; i++)
  171023. {
  171024. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171025. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171026. ig = (((png_uint_32)i *
  171027. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171028. for (j = 0; j < 256; j++)
  171029. {
  171030. png_ptr->gamma_16_from_1[i][j] =
  171031. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171032. 65535.0, g) * 65535.0 + .5);
  171033. }
  171034. }
  171035. }
  171036. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  171037. }
  171038. }
  171039. #endif
  171040. #endif
  171041. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171042. void /* PRIVATE */
  171043. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  171044. {
  171045. png_debug(1, "in png_do_read_intrapixel\n");
  171046. if (
  171047. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  171048. row != NULL && row_info != NULL &&
  171049. #endif
  171050. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  171051. {
  171052. int bytes_per_pixel;
  171053. png_uint_32 row_width = row_info->width;
  171054. if (row_info->bit_depth == 8)
  171055. {
  171056. png_bytep rp;
  171057. png_uint_32 i;
  171058. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171059. bytes_per_pixel = 3;
  171060. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171061. bytes_per_pixel = 4;
  171062. else
  171063. return;
  171064. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171065. {
  171066. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  171067. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  171068. }
  171069. }
  171070. else if (row_info->bit_depth == 16)
  171071. {
  171072. png_bytep rp;
  171073. png_uint_32 i;
  171074. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171075. bytes_per_pixel = 6;
  171076. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171077. bytes_per_pixel = 8;
  171078. else
  171079. return;
  171080. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171081. {
  171082. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  171083. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  171084. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  171085. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  171086. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  171087. *(rp ) = (png_byte)((red >> 8) & 0xff);
  171088. *(rp+1) = (png_byte)(red & 0xff);
  171089. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  171090. *(rp+5) = (png_byte)(blue & 0xff);
  171091. }
  171092. }
  171093. }
  171094. }
  171095. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  171096. #endif /* PNG_READ_SUPPORTED */
  171097. /*** End of inlined file: pngrtran.c ***/
  171098. /*** Start of inlined file: pngrutil.c ***/
  171099. #define PNG_INTERNAL
  171100. #if defined(PNG_READ_SUPPORTED)
  171101. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171102. # define WIN32_WCE_OLD
  171103. #endif
  171104. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171105. # if defined(WIN32_WCE_OLD)
  171106. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171107. {
  171108. double result = 0;
  171109. int len;
  171110. wchar_t *str, *end;
  171111. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171112. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171113. if ( NULL != str )
  171114. {
  171115. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171116. result = wcstod(str, &end);
  171117. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171118. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171119. png_free(png_ptr, str);
  171120. }
  171121. return result;
  171122. }
  171123. # else
  171124. # define png_strtod(p,a,b) strtod(a,b)
  171125. # endif
  171126. #endif
  171127. png_uint_32 PNGAPI
  171128. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171129. {
  171130. png_uint_32 i = png_get_uint_32(buf);
  171131. if (i > PNG_UINT_31_MAX)
  171132. png_error(png_ptr, "PNG unsigned integer out of range.");
  171133. return (i);
  171134. }
  171135. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171136. png_uint_32 PNGAPI
  171137. png_get_uint_32(png_bytep buf)
  171138. {
  171139. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171140. ((png_uint_32)(*(buf + 1)) << 16) +
  171141. ((png_uint_32)(*(buf + 2)) << 8) +
  171142. (png_uint_32)(*(buf + 3));
  171143. return (i);
  171144. }
  171145. png_int_32 PNGAPI
  171146. png_get_int_32(png_bytep buf)
  171147. {
  171148. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171149. ((png_int_32)(*(buf + 1)) << 16) +
  171150. ((png_int_32)(*(buf + 2)) << 8) +
  171151. (png_int_32)(*(buf + 3));
  171152. return (i);
  171153. }
  171154. png_uint_16 PNGAPI
  171155. png_get_uint_16(png_bytep buf)
  171156. {
  171157. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171158. (png_uint_16)(*(buf + 1)));
  171159. return (i);
  171160. }
  171161. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171162. void /* PRIVATE */
  171163. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171164. {
  171165. if(png_ptr == NULL) return;
  171166. png_read_data(png_ptr, buf, length);
  171167. png_calculate_crc(png_ptr, buf, length);
  171168. }
  171169. int /* PRIVATE */
  171170. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171171. {
  171172. png_size_t i;
  171173. png_size_t istop = png_ptr->zbuf_size;
  171174. for (i = (png_size_t)skip; i > istop; i -= istop)
  171175. {
  171176. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171177. }
  171178. if (i)
  171179. {
  171180. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171181. }
  171182. if (png_crc_error(png_ptr))
  171183. {
  171184. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171185. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171186. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171187. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171188. {
  171189. png_chunk_warning(png_ptr, "CRC error");
  171190. }
  171191. else
  171192. {
  171193. png_chunk_error(png_ptr, "CRC error");
  171194. }
  171195. return (1);
  171196. }
  171197. return (0);
  171198. }
  171199. int /* PRIVATE */
  171200. png_crc_error(png_structp png_ptr)
  171201. {
  171202. png_byte crc_bytes[4];
  171203. png_uint_32 crc;
  171204. int need_crc = 1;
  171205. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171206. {
  171207. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171208. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171209. need_crc = 0;
  171210. }
  171211. else /* critical */
  171212. {
  171213. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171214. need_crc = 0;
  171215. }
  171216. png_read_data(png_ptr, crc_bytes, 4);
  171217. if (need_crc)
  171218. {
  171219. crc = png_get_uint_32(crc_bytes);
  171220. return ((int)(crc != png_ptr->crc));
  171221. }
  171222. else
  171223. return (0);
  171224. }
  171225. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171226. defined(PNG_READ_iCCP_SUPPORTED)
  171227. png_charp /* PRIVATE */
  171228. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171229. png_charp chunkdata, png_size_t chunklength,
  171230. png_size_t prefix_size, png_size_t *newlength)
  171231. {
  171232. static PNG_CONST char msg[] = "Error decoding compressed text";
  171233. png_charp text;
  171234. png_size_t text_size;
  171235. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171236. {
  171237. int ret = Z_OK;
  171238. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171239. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171240. png_ptr->zstream.next_out = png_ptr->zbuf;
  171241. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171242. text_size = 0;
  171243. text = NULL;
  171244. while (png_ptr->zstream.avail_in)
  171245. {
  171246. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171247. if (ret != Z_OK && ret != Z_STREAM_END)
  171248. {
  171249. if (png_ptr->zstream.msg != NULL)
  171250. png_warning(png_ptr, png_ptr->zstream.msg);
  171251. else
  171252. png_warning(png_ptr, msg);
  171253. inflateReset(&png_ptr->zstream);
  171254. png_ptr->zstream.avail_in = 0;
  171255. if (text == NULL)
  171256. {
  171257. text_size = prefix_size + png_sizeof(msg) + 1;
  171258. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171259. if (text == NULL)
  171260. {
  171261. png_free(png_ptr,chunkdata);
  171262. png_error(png_ptr,"Not enough memory to decompress chunk");
  171263. }
  171264. png_memcpy(text, chunkdata, prefix_size);
  171265. }
  171266. text[text_size - 1] = 0x00;
  171267. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171268. text_size = png_sizeof(msg) > text_size ? text_size :
  171269. png_sizeof(msg);
  171270. png_memcpy(text + prefix_size, msg, text_size + 1);
  171271. break;
  171272. }
  171273. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171274. {
  171275. if (text == NULL)
  171276. {
  171277. text_size = prefix_size +
  171278. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171279. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171280. if (text == NULL)
  171281. {
  171282. png_free(png_ptr,chunkdata);
  171283. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171284. }
  171285. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171286. text_size - prefix_size);
  171287. png_memcpy(text, chunkdata, prefix_size);
  171288. *(text + text_size) = 0x00;
  171289. }
  171290. else
  171291. {
  171292. png_charp tmp;
  171293. tmp = text;
  171294. text = (png_charp)png_malloc_warn(png_ptr,
  171295. (png_uint_32)(text_size +
  171296. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171297. if (text == NULL)
  171298. {
  171299. png_free(png_ptr, tmp);
  171300. png_free(png_ptr, chunkdata);
  171301. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171302. }
  171303. png_memcpy(text, tmp, text_size);
  171304. png_free(png_ptr, tmp);
  171305. png_memcpy(text + text_size, png_ptr->zbuf,
  171306. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171307. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171308. *(text + text_size) = 0x00;
  171309. }
  171310. if (ret == Z_STREAM_END)
  171311. break;
  171312. else
  171313. {
  171314. png_ptr->zstream.next_out = png_ptr->zbuf;
  171315. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171316. }
  171317. }
  171318. }
  171319. if (ret != Z_STREAM_END)
  171320. {
  171321. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171322. char umsg[52];
  171323. if (ret == Z_BUF_ERROR)
  171324. png_snprintf(umsg, 52,
  171325. "Buffer error in compressed datastream in %s chunk",
  171326. png_ptr->chunk_name);
  171327. else if (ret == Z_DATA_ERROR)
  171328. png_snprintf(umsg, 52,
  171329. "Data error in compressed datastream in %s chunk",
  171330. png_ptr->chunk_name);
  171331. else
  171332. png_snprintf(umsg, 52,
  171333. "Incomplete compressed datastream in %s chunk",
  171334. png_ptr->chunk_name);
  171335. png_warning(png_ptr, umsg);
  171336. #else
  171337. png_warning(png_ptr,
  171338. "Incomplete compressed datastream in chunk other than IDAT");
  171339. #endif
  171340. text_size=prefix_size;
  171341. if (text == NULL)
  171342. {
  171343. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171344. if (text == NULL)
  171345. {
  171346. png_free(png_ptr, chunkdata);
  171347. png_error(png_ptr,"Not enough memory for text.");
  171348. }
  171349. png_memcpy(text, chunkdata, prefix_size);
  171350. }
  171351. *(text + text_size) = 0x00;
  171352. }
  171353. inflateReset(&png_ptr->zstream);
  171354. png_ptr->zstream.avail_in = 0;
  171355. png_free(png_ptr, chunkdata);
  171356. chunkdata = text;
  171357. *newlength=text_size;
  171358. }
  171359. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171360. {
  171361. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171362. char umsg[50];
  171363. png_snprintf(umsg, 50,
  171364. "Unknown zTXt compression type %d", comp_type);
  171365. png_warning(png_ptr, umsg);
  171366. #else
  171367. png_warning(png_ptr, "Unknown zTXt compression type");
  171368. #endif
  171369. *(chunkdata + prefix_size) = 0x00;
  171370. *newlength=prefix_size;
  171371. }
  171372. return chunkdata;
  171373. }
  171374. #endif
  171375. void /* PRIVATE */
  171376. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171377. {
  171378. png_byte buf[13];
  171379. png_uint_32 width, height;
  171380. int bit_depth, color_type, compression_type, filter_type;
  171381. int interlace_type;
  171382. png_debug(1, "in png_handle_IHDR\n");
  171383. if (png_ptr->mode & PNG_HAVE_IHDR)
  171384. png_error(png_ptr, "Out of place IHDR");
  171385. if (length != 13)
  171386. png_error(png_ptr, "Invalid IHDR chunk");
  171387. png_ptr->mode |= PNG_HAVE_IHDR;
  171388. png_crc_read(png_ptr, buf, 13);
  171389. png_crc_finish(png_ptr, 0);
  171390. width = png_get_uint_31(png_ptr, buf);
  171391. height = png_get_uint_31(png_ptr, buf + 4);
  171392. bit_depth = buf[8];
  171393. color_type = buf[9];
  171394. compression_type = buf[10];
  171395. filter_type = buf[11];
  171396. interlace_type = buf[12];
  171397. png_ptr->width = width;
  171398. png_ptr->height = height;
  171399. png_ptr->bit_depth = (png_byte)bit_depth;
  171400. png_ptr->interlaced = (png_byte)interlace_type;
  171401. png_ptr->color_type = (png_byte)color_type;
  171402. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171403. png_ptr->filter_type = (png_byte)filter_type;
  171404. #endif
  171405. png_ptr->compression_type = (png_byte)compression_type;
  171406. switch (png_ptr->color_type)
  171407. {
  171408. case PNG_COLOR_TYPE_GRAY:
  171409. case PNG_COLOR_TYPE_PALETTE:
  171410. png_ptr->channels = 1;
  171411. break;
  171412. case PNG_COLOR_TYPE_RGB:
  171413. png_ptr->channels = 3;
  171414. break;
  171415. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171416. png_ptr->channels = 2;
  171417. break;
  171418. case PNG_COLOR_TYPE_RGB_ALPHA:
  171419. png_ptr->channels = 4;
  171420. break;
  171421. }
  171422. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171423. png_ptr->channels);
  171424. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171425. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171426. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171427. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171428. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171429. color_type, interlace_type, compression_type, filter_type);
  171430. }
  171431. void /* PRIVATE */
  171432. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171433. {
  171434. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171435. int num, i;
  171436. #ifndef PNG_NO_POINTER_INDEXING
  171437. png_colorp pal_ptr;
  171438. #endif
  171439. png_debug(1, "in png_handle_PLTE\n");
  171440. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171441. png_error(png_ptr, "Missing IHDR before PLTE");
  171442. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171443. {
  171444. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171445. png_crc_finish(png_ptr, length);
  171446. return;
  171447. }
  171448. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171449. png_error(png_ptr, "Duplicate PLTE chunk");
  171450. png_ptr->mode |= PNG_HAVE_PLTE;
  171451. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171452. {
  171453. png_warning(png_ptr,
  171454. "Ignoring PLTE chunk in grayscale PNG");
  171455. png_crc_finish(png_ptr, length);
  171456. return;
  171457. }
  171458. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171459. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171460. {
  171461. png_crc_finish(png_ptr, length);
  171462. return;
  171463. }
  171464. #endif
  171465. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171466. {
  171467. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171468. {
  171469. png_warning(png_ptr, "Invalid palette chunk");
  171470. png_crc_finish(png_ptr, length);
  171471. return;
  171472. }
  171473. else
  171474. {
  171475. png_error(png_ptr, "Invalid palette chunk");
  171476. }
  171477. }
  171478. num = (int)length / 3;
  171479. #ifndef PNG_NO_POINTER_INDEXING
  171480. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171481. {
  171482. png_byte buf[3];
  171483. png_crc_read(png_ptr, buf, 3);
  171484. pal_ptr->red = buf[0];
  171485. pal_ptr->green = buf[1];
  171486. pal_ptr->blue = buf[2];
  171487. }
  171488. #else
  171489. for (i = 0; i < num; i++)
  171490. {
  171491. png_byte buf[3];
  171492. png_crc_read(png_ptr, buf, 3);
  171493. palette[i].red = buf[0];
  171494. palette[i].green = buf[1];
  171495. palette[i].blue = buf[2];
  171496. }
  171497. #endif
  171498. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171499. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171500. #endif
  171501. {
  171502. png_crc_finish(png_ptr, 0);
  171503. }
  171504. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171505. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171506. {
  171507. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171508. {
  171509. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171510. {
  171511. png_chunk_error(png_ptr, "CRC error");
  171512. }
  171513. else
  171514. {
  171515. png_chunk_warning(png_ptr, "CRC error");
  171516. return;
  171517. }
  171518. }
  171519. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171520. {
  171521. png_chunk_warning(png_ptr, "CRC error");
  171522. }
  171523. }
  171524. #endif
  171525. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171526. #if defined(PNG_READ_tRNS_SUPPORTED)
  171527. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171528. {
  171529. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171530. {
  171531. if (png_ptr->num_trans > (png_uint_16)num)
  171532. {
  171533. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171534. png_ptr->num_trans = (png_uint_16)num;
  171535. }
  171536. if (info_ptr->num_trans > (png_uint_16)num)
  171537. {
  171538. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171539. info_ptr->num_trans = (png_uint_16)num;
  171540. }
  171541. }
  171542. }
  171543. #endif
  171544. }
  171545. void /* PRIVATE */
  171546. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171547. {
  171548. png_debug(1, "in png_handle_IEND\n");
  171549. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171550. {
  171551. png_error(png_ptr, "No image in file");
  171552. }
  171553. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171554. if (length != 0)
  171555. {
  171556. png_warning(png_ptr, "Incorrect IEND chunk length");
  171557. }
  171558. png_crc_finish(png_ptr, length);
  171559. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171560. }
  171561. #if defined(PNG_READ_gAMA_SUPPORTED)
  171562. void /* PRIVATE */
  171563. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171564. {
  171565. png_fixed_point igamma;
  171566. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171567. float file_gamma;
  171568. #endif
  171569. png_byte buf[4];
  171570. png_debug(1, "in png_handle_gAMA\n");
  171571. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171572. png_error(png_ptr, "Missing IHDR before gAMA");
  171573. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171574. {
  171575. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171576. png_crc_finish(png_ptr, length);
  171577. return;
  171578. }
  171579. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171580. png_warning(png_ptr, "Out of place gAMA chunk");
  171581. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171582. #if defined(PNG_READ_sRGB_SUPPORTED)
  171583. && !(info_ptr->valid & PNG_INFO_sRGB)
  171584. #endif
  171585. )
  171586. {
  171587. png_warning(png_ptr, "Duplicate gAMA chunk");
  171588. png_crc_finish(png_ptr, length);
  171589. return;
  171590. }
  171591. if (length != 4)
  171592. {
  171593. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171594. png_crc_finish(png_ptr, length);
  171595. return;
  171596. }
  171597. png_crc_read(png_ptr, buf, 4);
  171598. if (png_crc_finish(png_ptr, 0))
  171599. return;
  171600. igamma = (png_fixed_point)png_get_uint_32(buf);
  171601. if (igamma == 0)
  171602. {
  171603. png_warning(png_ptr,
  171604. "Ignoring gAMA chunk with gamma=0");
  171605. return;
  171606. }
  171607. #if defined(PNG_READ_sRGB_SUPPORTED)
  171608. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171609. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171610. {
  171611. png_warning(png_ptr,
  171612. "Ignoring incorrect gAMA value when sRGB is also present");
  171613. #ifndef PNG_NO_CONSOLE_IO
  171614. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171615. #endif
  171616. return;
  171617. }
  171618. #endif /* PNG_READ_sRGB_SUPPORTED */
  171619. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171620. file_gamma = (float)igamma / (float)100000.0;
  171621. # ifdef PNG_READ_GAMMA_SUPPORTED
  171622. png_ptr->gamma = file_gamma;
  171623. # endif
  171624. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171625. #endif
  171626. #ifdef PNG_FIXED_POINT_SUPPORTED
  171627. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171628. #endif
  171629. }
  171630. #endif
  171631. #if defined(PNG_READ_sBIT_SUPPORTED)
  171632. void /* PRIVATE */
  171633. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171634. {
  171635. png_size_t truelen;
  171636. png_byte buf[4];
  171637. png_debug(1, "in png_handle_sBIT\n");
  171638. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171639. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171640. png_error(png_ptr, "Missing IHDR before sBIT");
  171641. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171642. {
  171643. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171644. png_crc_finish(png_ptr, length);
  171645. return;
  171646. }
  171647. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171648. {
  171649. png_warning(png_ptr, "Out of place sBIT chunk");
  171650. }
  171651. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171652. {
  171653. png_warning(png_ptr, "Duplicate sBIT chunk");
  171654. png_crc_finish(png_ptr, length);
  171655. return;
  171656. }
  171657. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171658. truelen = 3;
  171659. else
  171660. truelen = (png_size_t)png_ptr->channels;
  171661. if (length != truelen || length > 4)
  171662. {
  171663. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171664. png_crc_finish(png_ptr, length);
  171665. return;
  171666. }
  171667. png_crc_read(png_ptr, buf, truelen);
  171668. if (png_crc_finish(png_ptr, 0))
  171669. return;
  171670. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171671. {
  171672. png_ptr->sig_bit.red = buf[0];
  171673. png_ptr->sig_bit.green = buf[1];
  171674. png_ptr->sig_bit.blue = buf[2];
  171675. png_ptr->sig_bit.alpha = buf[3];
  171676. }
  171677. else
  171678. {
  171679. png_ptr->sig_bit.gray = buf[0];
  171680. png_ptr->sig_bit.red = buf[0];
  171681. png_ptr->sig_bit.green = buf[0];
  171682. png_ptr->sig_bit.blue = buf[0];
  171683. png_ptr->sig_bit.alpha = buf[1];
  171684. }
  171685. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171686. }
  171687. #endif
  171688. #if defined(PNG_READ_cHRM_SUPPORTED)
  171689. void /* PRIVATE */
  171690. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171691. {
  171692. png_byte buf[4];
  171693. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171694. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171695. #endif
  171696. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171697. int_y_green, int_x_blue, int_y_blue;
  171698. png_uint_32 uint_x, uint_y;
  171699. png_debug(1, "in png_handle_cHRM\n");
  171700. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171701. png_error(png_ptr, "Missing IHDR before cHRM");
  171702. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171703. {
  171704. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171705. png_crc_finish(png_ptr, length);
  171706. return;
  171707. }
  171708. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171709. png_warning(png_ptr, "Missing PLTE before cHRM");
  171710. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171711. #if defined(PNG_READ_sRGB_SUPPORTED)
  171712. && !(info_ptr->valid & PNG_INFO_sRGB)
  171713. #endif
  171714. )
  171715. {
  171716. png_warning(png_ptr, "Duplicate cHRM chunk");
  171717. png_crc_finish(png_ptr, length);
  171718. return;
  171719. }
  171720. if (length != 32)
  171721. {
  171722. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171723. png_crc_finish(png_ptr, length);
  171724. return;
  171725. }
  171726. png_crc_read(png_ptr, buf, 4);
  171727. uint_x = png_get_uint_32(buf);
  171728. png_crc_read(png_ptr, buf, 4);
  171729. uint_y = png_get_uint_32(buf);
  171730. if (uint_x > 80000L || uint_y > 80000L ||
  171731. uint_x + uint_y > 100000L)
  171732. {
  171733. png_warning(png_ptr, "Invalid cHRM white point");
  171734. png_crc_finish(png_ptr, 24);
  171735. return;
  171736. }
  171737. int_x_white = (png_fixed_point)uint_x;
  171738. int_y_white = (png_fixed_point)uint_y;
  171739. png_crc_read(png_ptr, buf, 4);
  171740. uint_x = png_get_uint_32(buf);
  171741. png_crc_read(png_ptr, buf, 4);
  171742. uint_y = png_get_uint_32(buf);
  171743. if (uint_x + uint_y > 100000L)
  171744. {
  171745. png_warning(png_ptr, "Invalid cHRM red point");
  171746. png_crc_finish(png_ptr, 16);
  171747. return;
  171748. }
  171749. int_x_red = (png_fixed_point)uint_x;
  171750. int_y_red = (png_fixed_point)uint_y;
  171751. png_crc_read(png_ptr, buf, 4);
  171752. uint_x = png_get_uint_32(buf);
  171753. png_crc_read(png_ptr, buf, 4);
  171754. uint_y = png_get_uint_32(buf);
  171755. if (uint_x + uint_y > 100000L)
  171756. {
  171757. png_warning(png_ptr, "Invalid cHRM green point");
  171758. png_crc_finish(png_ptr, 8);
  171759. return;
  171760. }
  171761. int_x_green = (png_fixed_point)uint_x;
  171762. int_y_green = (png_fixed_point)uint_y;
  171763. png_crc_read(png_ptr, buf, 4);
  171764. uint_x = png_get_uint_32(buf);
  171765. png_crc_read(png_ptr, buf, 4);
  171766. uint_y = png_get_uint_32(buf);
  171767. if (uint_x + uint_y > 100000L)
  171768. {
  171769. png_warning(png_ptr, "Invalid cHRM blue point");
  171770. png_crc_finish(png_ptr, 0);
  171771. return;
  171772. }
  171773. int_x_blue = (png_fixed_point)uint_x;
  171774. int_y_blue = (png_fixed_point)uint_y;
  171775. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171776. white_x = (float)int_x_white / (float)100000.0;
  171777. white_y = (float)int_y_white / (float)100000.0;
  171778. red_x = (float)int_x_red / (float)100000.0;
  171779. red_y = (float)int_y_red / (float)100000.0;
  171780. green_x = (float)int_x_green / (float)100000.0;
  171781. green_y = (float)int_y_green / (float)100000.0;
  171782. blue_x = (float)int_x_blue / (float)100000.0;
  171783. blue_y = (float)int_y_blue / (float)100000.0;
  171784. #endif
  171785. #if defined(PNG_READ_sRGB_SUPPORTED)
  171786. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171787. {
  171788. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171789. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171790. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171791. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171792. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171793. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171794. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171795. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171796. {
  171797. png_warning(png_ptr,
  171798. "Ignoring incorrect cHRM value when sRGB is also present");
  171799. #ifndef PNG_NO_CONSOLE_IO
  171800. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171801. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171802. white_x, white_y, red_x, red_y);
  171803. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171804. green_x, green_y, blue_x, blue_y);
  171805. #else
  171806. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171807. int_x_white, int_y_white, int_x_red, int_y_red);
  171808. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171809. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171810. #endif
  171811. #endif /* PNG_NO_CONSOLE_IO */
  171812. }
  171813. png_crc_finish(png_ptr, 0);
  171814. return;
  171815. }
  171816. #endif /* PNG_READ_sRGB_SUPPORTED */
  171817. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171818. png_set_cHRM(png_ptr, info_ptr,
  171819. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171820. #endif
  171821. #ifdef PNG_FIXED_POINT_SUPPORTED
  171822. png_set_cHRM_fixed(png_ptr, info_ptr,
  171823. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171824. int_y_green, int_x_blue, int_y_blue);
  171825. #endif
  171826. if (png_crc_finish(png_ptr, 0))
  171827. return;
  171828. }
  171829. #endif
  171830. #if defined(PNG_READ_sRGB_SUPPORTED)
  171831. void /* PRIVATE */
  171832. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171833. {
  171834. int intent;
  171835. png_byte buf[1];
  171836. png_debug(1, "in png_handle_sRGB\n");
  171837. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171838. png_error(png_ptr, "Missing IHDR before sRGB");
  171839. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171840. {
  171841. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171842. png_crc_finish(png_ptr, length);
  171843. return;
  171844. }
  171845. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171846. png_warning(png_ptr, "Out of place sRGB chunk");
  171847. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171848. {
  171849. png_warning(png_ptr, "Duplicate sRGB chunk");
  171850. png_crc_finish(png_ptr, length);
  171851. return;
  171852. }
  171853. if (length != 1)
  171854. {
  171855. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171856. png_crc_finish(png_ptr, length);
  171857. return;
  171858. }
  171859. png_crc_read(png_ptr, buf, 1);
  171860. if (png_crc_finish(png_ptr, 0))
  171861. return;
  171862. intent = buf[0];
  171863. if (intent >= PNG_sRGB_INTENT_LAST)
  171864. {
  171865. png_warning(png_ptr, "Unknown sRGB intent");
  171866. return;
  171867. }
  171868. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171869. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171870. {
  171871. png_fixed_point igamma;
  171872. #ifdef PNG_FIXED_POINT_SUPPORTED
  171873. igamma=info_ptr->int_gamma;
  171874. #else
  171875. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171876. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171877. # endif
  171878. #endif
  171879. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171880. {
  171881. png_warning(png_ptr,
  171882. "Ignoring incorrect gAMA value when sRGB is also present");
  171883. #ifndef PNG_NO_CONSOLE_IO
  171884. # ifdef PNG_FIXED_POINT_SUPPORTED
  171885. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171886. # else
  171887. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171888. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171889. # endif
  171890. # endif
  171891. #endif
  171892. }
  171893. }
  171894. #endif /* PNG_READ_gAMA_SUPPORTED */
  171895. #ifdef PNG_READ_cHRM_SUPPORTED
  171896. #ifdef PNG_FIXED_POINT_SUPPORTED
  171897. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171898. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171899. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171900. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171901. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171902. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171903. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171904. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171905. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171906. {
  171907. png_warning(png_ptr,
  171908. "Ignoring incorrect cHRM value when sRGB is also present");
  171909. }
  171910. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171911. #endif /* PNG_READ_cHRM_SUPPORTED */
  171912. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171913. }
  171914. #endif /* PNG_READ_sRGB_SUPPORTED */
  171915. #if defined(PNG_READ_iCCP_SUPPORTED)
  171916. void /* PRIVATE */
  171917. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171918. {
  171919. png_charp chunkdata;
  171920. png_byte compression_type;
  171921. png_bytep pC;
  171922. png_charp profile;
  171923. png_uint_32 skip = 0;
  171924. png_uint_32 profile_size, profile_length;
  171925. png_size_t slength, prefix_length, data_length;
  171926. png_debug(1, "in png_handle_iCCP\n");
  171927. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171928. png_error(png_ptr, "Missing IHDR before iCCP");
  171929. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171930. {
  171931. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171932. png_crc_finish(png_ptr, length);
  171933. return;
  171934. }
  171935. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171936. png_warning(png_ptr, "Out of place iCCP chunk");
  171937. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171938. {
  171939. png_warning(png_ptr, "Duplicate iCCP chunk");
  171940. png_crc_finish(png_ptr, length);
  171941. return;
  171942. }
  171943. #ifdef PNG_MAX_MALLOC_64K
  171944. if (length > (png_uint_32)65535L)
  171945. {
  171946. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171947. skip = length - (png_uint_32)65535L;
  171948. length = (png_uint_32)65535L;
  171949. }
  171950. #endif
  171951. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171952. slength = (png_size_t)length;
  171953. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171954. if (png_crc_finish(png_ptr, skip))
  171955. {
  171956. png_free(png_ptr, chunkdata);
  171957. return;
  171958. }
  171959. chunkdata[slength] = 0x00;
  171960. for (profile = chunkdata; *profile; profile++)
  171961. ;
  171962. ++profile;
  171963. if ( profile >= chunkdata + slength - 1)
  171964. {
  171965. png_free(png_ptr, chunkdata);
  171966. png_warning(png_ptr, "Malformed iCCP chunk");
  171967. return;
  171968. }
  171969. compression_type = *profile++;
  171970. if (compression_type)
  171971. {
  171972. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171973. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171974. wrote nonzero) */
  171975. }
  171976. prefix_length = profile - chunkdata;
  171977. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171978. slength, prefix_length, &data_length);
  171979. profile_length = data_length - prefix_length;
  171980. if ( prefix_length > data_length || profile_length < 4)
  171981. {
  171982. png_free(png_ptr, chunkdata);
  171983. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171984. return;
  171985. }
  171986. pC = (png_bytep)(chunkdata+prefix_length);
  171987. profile_size = ((*(pC ))<<24) |
  171988. ((*(pC+1))<<16) |
  171989. ((*(pC+2))<< 8) |
  171990. ((*(pC+3)) );
  171991. if(profile_size < profile_length)
  171992. profile_length = profile_size;
  171993. if(profile_size > profile_length)
  171994. {
  171995. png_free(png_ptr, chunkdata);
  171996. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171997. return;
  171998. }
  171999. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  172000. chunkdata + prefix_length, profile_length);
  172001. png_free(png_ptr, chunkdata);
  172002. }
  172003. #endif /* PNG_READ_iCCP_SUPPORTED */
  172004. #if defined(PNG_READ_sPLT_SUPPORTED)
  172005. void /* PRIVATE */
  172006. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172007. {
  172008. png_bytep chunkdata;
  172009. png_bytep entry_start;
  172010. png_sPLT_t new_palette;
  172011. #ifdef PNG_NO_POINTER_INDEXING
  172012. png_sPLT_entryp pp;
  172013. #endif
  172014. int data_length, entry_size, i;
  172015. png_uint_32 skip = 0;
  172016. png_size_t slength;
  172017. png_debug(1, "in png_handle_sPLT\n");
  172018. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172019. png_error(png_ptr, "Missing IHDR before sPLT");
  172020. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172021. {
  172022. png_warning(png_ptr, "Invalid sPLT after IDAT");
  172023. png_crc_finish(png_ptr, length);
  172024. return;
  172025. }
  172026. #ifdef PNG_MAX_MALLOC_64K
  172027. if (length > (png_uint_32)65535L)
  172028. {
  172029. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  172030. skip = length - (png_uint_32)65535L;
  172031. length = (png_uint_32)65535L;
  172032. }
  172033. #endif
  172034. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  172035. slength = (png_size_t)length;
  172036. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172037. if (png_crc_finish(png_ptr, skip))
  172038. {
  172039. png_free(png_ptr, chunkdata);
  172040. return;
  172041. }
  172042. chunkdata[slength] = 0x00;
  172043. for (entry_start = chunkdata; *entry_start; entry_start++)
  172044. ;
  172045. ++entry_start;
  172046. if (entry_start > chunkdata + slength - 2)
  172047. {
  172048. png_free(png_ptr, chunkdata);
  172049. png_warning(png_ptr, "malformed sPLT chunk");
  172050. return;
  172051. }
  172052. new_palette.depth = *entry_start++;
  172053. entry_size = (new_palette.depth == 8 ? 6 : 10);
  172054. data_length = (slength - (entry_start - chunkdata));
  172055. if (data_length % entry_size)
  172056. {
  172057. png_free(png_ptr, chunkdata);
  172058. png_warning(png_ptr, "sPLT chunk has bad length");
  172059. return;
  172060. }
  172061. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  172062. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  172063. png_sizeof(png_sPLT_entry)))
  172064. {
  172065. png_warning(png_ptr, "sPLT chunk too long");
  172066. return;
  172067. }
  172068. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  172069. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  172070. if (new_palette.entries == NULL)
  172071. {
  172072. png_warning(png_ptr, "sPLT chunk requires too much memory");
  172073. return;
  172074. }
  172075. #ifndef PNG_NO_POINTER_INDEXING
  172076. for (i = 0; i < new_palette.nentries; i++)
  172077. {
  172078. png_sPLT_entryp pp = new_palette.entries + i;
  172079. if (new_palette.depth == 8)
  172080. {
  172081. pp->red = *entry_start++;
  172082. pp->green = *entry_start++;
  172083. pp->blue = *entry_start++;
  172084. pp->alpha = *entry_start++;
  172085. }
  172086. else
  172087. {
  172088. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  172089. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  172090. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  172091. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  172092. }
  172093. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172094. }
  172095. #else
  172096. pp = new_palette.entries;
  172097. for (i = 0; i < new_palette.nentries; i++)
  172098. {
  172099. if (new_palette.depth == 8)
  172100. {
  172101. pp[i].red = *entry_start++;
  172102. pp[i].green = *entry_start++;
  172103. pp[i].blue = *entry_start++;
  172104. pp[i].alpha = *entry_start++;
  172105. }
  172106. else
  172107. {
  172108. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172109. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172110. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172111. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172112. }
  172113. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172114. }
  172115. #endif
  172116. new_palette.name = (png_charp)chunkdata;
  172117. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172118. png_free(png_ptr, chunkdata);
  172119. png_free(png_ptr, new_palette.entries);
  172120. }
  172121. #endif /* PNG_READ_sPLT_SUPPORTED */
  172122. #if defined(PNG_READ_tRNS_SUPPORTED)
  172123. void /* PRIVATE */
  172124. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172125. {
  172126. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172127. int bit_mask;
  172128. png_debug(1, "in png_handle_tRNS\n");
  172129. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172130. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172131. png_error(png_ptr, "Missing IHDR before tRNS");
  172132. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172133. {
  172134. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172135. png_crc_finish(png_ptr, length);
  172136. return;
  172137. }
  172138. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172139. {
  172140. png_warning(png_ptr, "Duplicate tRNS chunk");
  172141. png_crc_finish(png_ptr, length);
  172142. return;
  172143. }
  172144. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172145. {
  172146. png_byte buf[2];
  172147. if (length != 2)
  172148. {
  172149. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172150. png_crc_finish(png_ptr, length);
  172151. return;
  172152. }
  172153. png_crc_read(png_ptr, buf, 2);
  172154. png_ptr->num_trans = 1;
  172155. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172156. }
  172157. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172158. {
  172159. png_byte buf[6];
  172160. if (length != 6)
  172161. {
  172162. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172163. png_crc_finish(png_ptr, length);
  172164. return;
  172165. }
  172166. png_crc_read(png_ptr, buf, (png_size_t)length);
  172167. png_ptr->num_trans = 1;
  172168. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172169. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172170. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172171. }
  172172. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172173. {
  172174. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172175. {
  172176. png_warning(png_ptr, "Missing PLTE before tRNS");
  172177. }
  172178. if (length > (png_uint_32)png_ptr->num_palette ||
  172179. length > PNG_MAX_PALETTE_LENGTH)
  172180. {
  172181. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172182. png_crc_finish(png_ptr, length);
  172183. return;
  172184. }
  172185. if (length == 0)
  172186. {
  172187. png_warning(png_ptr, "Zero length tRNS chunk");
  172188. png_crc_finish(png_ptr, length);
  172189. return;
  172190. }
  172191. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172192. png_ptr->num_trans = (png_uint_16)length;
  172193. }
  172194. else
  172195. {
  172196. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172197. png_crc_finish(png_ptr, length);
  172198. return;
  172199. }
  172200. if (png_crc_finish(png_ptr, 0))
  172201. {
  172202. png_ptr->num_trans = 0;
  172203. return;
  172204. }
  172205. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172206. &(png_ptr->trans_values));
  172207. }
  172208. #endif
  172209. #if defined(PNG_READ_bKGD_SUPPORTED)
  172210. void /* PRIVATE */
  172211. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172212. {
  172213. png_size_t truelen;
  172214. png_byte buf[6];
  172215. png_debug(1, "in png_handle_bKGD\n");
  172216. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172217. png_error(png_ptr, "Missing IHDR before bKGD");
  172218. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172219. {
  172220. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172221. png_crc_finish(png_ptr, length);
  172222. return;
  172223. }
  172224. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172225. !(png_ptr->mode & PNG_HAVE_PLTE))
  172226. {
  172227. png_warning(png_ptr, "Missing PLTE before bKGD");
  172228. png_crc_finish(png_ptr, length);
  172229. return;
  172230. }
  172231. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172232. {
  172233. png_warning(png_ptr, "Duplicate bKGD chunk");
  172234. png_crc_finish(png_ptr, length);
  172235. return;
  172236. }
  172237. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172238. truelen = 1;
  172239. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172240. truelen = 6;
  172241. else
  172242. truelen = 2;
  172243. if (length != truelen)
  172244. {
  172245. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172246. png_crc_finish(png_ptr, length);
  172247. return;
  172248. }
  172249. png_crc_read(png_ptr, buf, truelen);
  172250. if (png_crc_finish(png_ptr, 0))
  172251. return;
  172252. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172253. {
  172254. png_ptr->background.index = buf[0];
  172255. if(info_ptr->num_palette)
  172256. {
  172257. if(buf[0] > info_ptr->num_palette)
  172258. {
  172259. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172260. return;
  172261. }
  172262. png_ptr->background.red =
  172263. (png_uint_16)png_ptr->palette[buf[0]].red;
  172264. png_ptr->background.green =
  172265. (png_uint_16)png_ptr->palette[buf[0]].green;
  172266. png_ptr->background.blue =
  172267. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172268. }
  172269. }
  172270. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172271. {
  172272. png_ptr->background.red =
  172273. png_ptr->background.green =
  172274. png_ptr->background.blue =
  172275. png_ptr->background.gray = png_get_uint_16(buf);
  172276. }
  172277. else
  172278. {
  172279. png_ptr->background.red = png_get_uint_16(buf);
  172280. png_ptr->background.green = png_get_uint_16(buf + 2);
  172281. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172282. }
  172283. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172284. }
  172285. #endif
  172286. #if defined(PNG_READ_hIST_SUPPORTED)
  172287. void /* PRIVATE */
  172288. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172289. {
  172290. unsigned int num, i;
  172291. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172292. png_debug(1, "in png_handle_hIST\n");
  172293. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172294. png_error(png_ptr, "Missing IHDR before hIST");
  172295. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172296. {
  172297. png_warning(png_ptr, "Invalid hIST after IDAT");
  172298. png_crc_finish(png_ptr, length);
  172299. return;
  172300. }
  172301. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172302. {
  172303. png_warning(png_ptr, "Missing PLTE before hIST");
  172304. png_crc_finish(png_ptr, length);
  172305. return;
  172306. }
  172307. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172308. {
  172309. png_warning(png_ptr, "Duplicate hIST chunk");
  172310. png_crc_finish(png_ptr, length);
  172311. return;
  172312. }
  172313. num = length / 2 ;
  172314. if (num != (unsigned int) png_ptr->num_palette || num >
  172315. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172316. {
  172317. png_warning(png_ptr, "Incorrect hIST chunk length");
  172318. png_crc_finish(png_ptr, length);
  172319. return;
  172320. }
  172321. for (i = 0; i < num; i++)
  172322. {
  172323. png_byte buf[2];
  172324. png_crc_read(png_ptr, buf, 2);
  172325. readbuf[i] = png_get_uint_16(buf);
  172326. }
  172327. if (png_crc_finish(png_ptr, 0))
  172328. return;
  172329. png_set_hIST(png_ptr, info_ptr, readbuf);
  172330. }
  172331. #endif
  172332. #if defined(PNG_READ_pHYs_SUPPORTED)
  172333. void /* PRIVATE */
  172334. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172335. {
  172336. png_byte buf[9];
  172337. png_uint_32 res_x, res_y;
  172338. int unit_type;
  172339. png_debug(1, "in png_handle_pHYs\n");
  172340. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172341. png_error(png_ptr, "Missing IHDR before pHYs");
  172342. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172343. {
  172344. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172345. png_crc_finish(png_ptr, length);
  172346. return;
  172347. }
  172348. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172349. {
  172350. png_warning(png_ptr, "Duplicate pHYs chunk");
  172351. png_crc_finish(png_ptr, length);
  172352. return;
  172353. }
  172354. if (length != 9)
  172355. {
  172356. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172357. png_crc_finish(png_ptr, length);
  172358. return;
  172359. }
  172360. png_crc_read(png_ptr, buf, 9);
  172361. if (png_crc_finish(png_ptr, 0))
  172362. return;
  172363. res_x = png_get_uint_32(buf);
  172364. res_y = png_get_uint_32(buf + 4);
  172365. unit_type = buf[8];
  172366. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172367. }
  172368. #endif
  172369. #if defined(PNG_READ_oFFs_SUPPORTED)
  172370. void /* PRIVATE */
  172371. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172372. {
  172373. png_byte buf[9];
  172374. png_int_32 offset_x, offset_y;
  172375. int unit_type;
  172376. png_debug(1, "in png_handle_oFFs\n");
  172377. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172378. png_error(png_ptr, "Missing IHDR before oFFs");
  172379. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172380. {
  172381. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172382. png_crc_finish(png_ptr, length);
  172383. return;
  172384. }
  172385. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172386. {
  172387. png_warning(png_ptr, "Duplicate oFFs chunk");
  172388. png_crc_finish(png_ptr, length);
  172389. return;
  172390. }
  172391. if (length != 9)
  172392. {
  172393. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172394. png_crc_finish(png_ptr, length);
  172395. return;
  172396. }
  172397. png_crc_read(png_ptr, buf, 9);
  172398. if (png_crc_finish(png_ptr, 0))
  172399. return;
  172400. offset_x = png_get_int_32(buf);
  172401. offset_y = png_get_int_32(buf + 4);
  172402. unit_type = buf[8];
  172403. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172404. }
  172405. #endif
  172406. #if defined(PNG_READ_pCAL_SUPPORTED)
  172407. void /* PRIVATE */
  172408. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172409. {
  172410. png_charp purpose;
  172411. png_int_32 X0, X1;
  172412. png_byte type, nparams;
  172413. png_charp buf, units, endptr;
  172414. png_charpp params;
  172415. png_size_t slength;
  172416. int i;
  172417. png_debug(1, "in png_handle_pCAL\n");
  172418. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172419. png_error(png_ptr, "Missing IHDR before pCAL");
  172420. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172421. {
  172422. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172423. png_crc_finish(png_ptr, length);
  172424. return;
  172425. }
  172426. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172427. {
  172428. png_warning(png_ptr, "Duplicate pCAL chunk");
  172429. png_crc_finish(png_ptr, length);
  172430. return;
  172431. }
  172432. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172433. length + 1);
  172434. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172435. if (purpose == NULL)
  172436. {
  172437. png_warning(png_ptr, "No memory for pCAL purpose.");
  172438. return;
  172439. }
  172440. slength = (png_size_t)length;
  172441. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172442. if (png_crc_finish(png_ptr, 0))
  172443. {
  172444. png_free(png_ptr, purpose);
  172445. return;
  172446. }
  172447. purpose[slength] = 0x00; /* null terminate the last string */
  172448. png_debug(3, "Finding end of pCAL purpose string\n");
  172449. for (buf = purpose; *buf; buf++)
  172450. ;
  172451. endptr = purpose + slength;
  172452. if (endptr <= buf + 12)
  172453. {
  172454. png_warning(png_ptr, "Invalid pCAL data");
  172455. png_free(png_ptr, purpose);
  172456. return;
  172457. }
  172458. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172459. X0 = png_get_int_32((png_bytep)buf+1);
  172460. X1 = png_get_int_32((png_bytep)buf+5);
  172461. type = buf[9];
  172462. nparams = buf[10];
  172463. units = buf + 11;
  172464. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172465. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172466. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172467. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172468. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172469. {
  172470. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172471. png_free(png_ptr, purpose);
  172472. return;
  172473. }
  172474. else if (type >= PNG_EQUATION_LAST)
  172475. {
  172476. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172477. }
  172478. for (buf = units; *buf; buf++)
  172479. ;
  172480. png_debug(3, "Allocating pCAL parameters array\n");
  172481. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172482. *png_sizeof(png_charp))) ;
  172483. if (params == NULL)
  172484. {
  172485. png_free(png_ptr, purpose);
  172486. png_warning(png_ptr, "No memory for pCAL params.");
  172487. return;
  172488. }
  172489. for (i = 0; i < (int)nparams; i++)
  172490. {
  172491. buf++; /* Skip the null string terminator from previous parameter. */
  172492. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172493. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172494. ;
  172495. if (buf > endptr)
  172496. {
  172497. png_warning(png_ptr, "Invalid pCAL data");
  172498. png_free(png_ptr, purpose);
  172499. png_free(png_ptr, params);
  172500. return;
  172501. }
  172502. }
  172503. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172504. units, params);
  172505. png_free(png_ptr, purpose);
  172506. png_free(png_ptr, params);
  172507. }
  172508. #endif
  172509. #if defined(PNG_READ_sCAL_SUPPORTED)
  172510. void /* PRIVATE */
  172511. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172512. {
  172513. png_charp buffer, ep;
  172514. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172515. double width, height;
  172516. png_charp vp;
  172517. #else
  172518. #ifdef PNG_FIXED_POINT_SUPPORTED
  172519. png_charp swidth, sheight;
  172520. #endif
  172521. #endif
  172522. png_size_t slength;
  172523. png_debug(1, "in png_handle_sCAL\n");
  172524. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172525. png_error(png_ptr, "Missing IHDR before sCAL");
  172526. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172527. {
  172528. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172529. png_crc_finish(png_ptr, length);
  172530. return;
  172531. }
  172532. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172533. {
  172534. png_warning(png_ptr, "Duplicate sCAL chunk");
  172535. png_crc_finish(png_ptr, length);
  172536. return;
  172537. }
  172538. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172539. length + 1);
  172540. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172541. if (buffer == NULL)
  172542. {
  172543. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172544. return;
  172545. }
  172546. slength = (png_size_t)length;
  172547. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172548. if (png_crc_finish(png_ptr, 0))
  172549. {
  172550. png_free(png_ptr, buffer);
  172551. return;
  172552. }
  172553. buffer[slength] = 0x00; /* null terminate the last string */
  172554. ep = buffer + 1; /* skip unit byte */
  172555. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172556. width = png_strtod(png_ptr, ep, &vp);
  172557. if (*vp)
  172558. {
  172559. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172560. return;
  172561. }
  172562. #else
  172563. #ifdef PNG_FIXED_POINT_SUPPORTED
  172564. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172565. if (swidth == NULL)
  172566. {
  172567. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172568. return;
  172569. }
  172570. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172571. #endif
  172572. #endif
  172573. for (ep = buffer; *ep; ep++)
  172574. ;
  172575. ep++;
  172576. if (buffer + slength < ep)
  172577. {
  172578. png_warning(png_ptr, "Truncated sCAL chunk");
  172579. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172580. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172581. png_free(png_ptr, swidth);
  172582. #endif
  172583. png_free(png_ptr, buffer);
  172584. return;
  172585. }
  172586. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172587. height = png_strtod(png_ptr, ep, &vp);
  172588. if (*vp)
  172589. {
  172590. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172591. return;
  172592. }
  172593. #else
  172594. #ifdef PNG_FIXED_POINT_SUPPORTED
  172595. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172596. if (swidth == NULL)
  172597. {
  172598. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172599. return;
  172600. }
  172601. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172602. #endif
  172603. #endif
  172604. if (buffer + slength < ep
  172605. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172606. || width <= 0. || height <= 0.
  172607. #endif
  172608. )
  172609. {
  172610. png_warning(png_ptr, "Invalid sCAL data");
  172611. png_free(png_ptr, buffer);
  172612. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172613. png_free(png_ptr, swidth);
  172614. png_free(png_ptr, sheight);
  172615. #endif
  172616. return;
  172617. }
  172618. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172619. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172620. #else
  172621. #ifdef PNG_FIXED_POINT_SUPPORTED
  172622. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172623. #endif
  172624. #endif
  172625. png_free(png_ptr, buffer);
  172626. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172627. png_free(png_ptr, swidth);
  172628. png_free(png_ptr, sheight);
  172629. #endif
  172630. }
  172631. #endif
  172632. #if defined(PNG_READ_tIME_SUPPORTED)
  172633. void /* PRIVATE */
  172634. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172635. {
  172636. png_byte buf[7];
  172637. png_time mod_time;
  172638. png_debug(1, "in png_handle_tIME\n");
  172639. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172640. png_error(png_ptr, "Out of place tIME chunk");
  172641. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172642. {
  172643. png_warning(png_ptr, "Duplicate tIME chunk");
  172644. png_crc_finish(png_ptr, length);
  172645. return;
  172646. }
  172647. if (png_ptr->mode & PNG_HAVE_IDAT)
  172648. png_ptr->mode |= PNG_AFTER_IDAT;
  172649. if (length != 7)
  172650. {
  172651. png_warning(png_ptr, "Incorrect tIME chunk length");
  172652. png_crc_finish(png_ptr, length);
  172653. return;
  172654. }
  172655. png_crc_read(png_ptr, buf, 7);
  172656. if (png_crc_finish(png_ptr, 0))
  172657. return;
  172658. mod_time.second = buf[6];
  172659. mod_time.minute = buf[5];
  172660. mod_time.hour = buf[4];
  172661. mod_time.day = buf[3];
  172662. mod_time.month = buf[2];
  172663. mod_time.year = png_get_uint_16(buf);
  172664. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172665. }
  172666. #endif
  172667. #if defined(PNG_READ_tEXt_SUPPORTED)
  172668. void /* PRIVATE */
  172669. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172670. {
  172671. png_textp text_ptr;
  172672. png_charp key;
  172673. png_charp text;
  172674. png_uint_32 skip = 0;
  172675. png_size_t slength;
  172676. int ret;
  172677. png_debug(1, "in png_handle_tEXt\n");
  172678. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172679. png_error(png_ptr, "Missing IHDR before tEXt");
  172680. if (png_ptr->mode & PNG_HAVE_IDAT)
  172681. png_ptr->mode |= PNG_AFTER_IDAT;
  172682. #ifdef PNG_MAX_MALLOC_64K
  172683. if (length > (png_uint_32)65535L)
  172684. {
  172685. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172686. skip = length - (png_uint_32)65535L;
  172687. length = (png_uint_32)65535L;
  172688. }
  172689. #endif
  172690. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172691. if (key == NULL)
  172692. {
  172693. png_warning(png_ptr, "No memory to process text chunk.");
  172694. return;
  172695. }
  172696. slength = (png_size_t)length;
  172697. png_crc_read(png_ptr, (png_bytep)key, slength);
  172698. if (png_crc_finish(png_ptr, skip))
  172699. {
  172700. png_free(png_ptr, key);
  172701. return;
  172702. }
  172703. key[slength] = 0x00;
  172704. for (text = key; *text; text++)
  172705. ;
  172706. if (text != key + slength)
  172707. text++;
  172708. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172709. (png_uint_32)png_sizeof(png_text));
  172710. if (text_ptr == NULL)
  172711. {
  172712. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172713. png_free(png_ptr, key);
  172714. return;
  172715. }
  172716. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172717. text_ptr->key = key;
  172718. #ifdef PNG_iTXt_SUPPORTED
  172719. text_ptr->lang = NULL;
  172720. text_ptr->lang_key = NULL;
  172721. text_ptr->itxt_length = 0;
  172722. #endif
  172723. text_ptr->text = text;
  172724. text_ptr->text_length = png_strlen(text);
  172725. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172726. png_free(png_ptr, key);
  172727. png_free(png_ptr, text_ptr);
  172728. if (ret)
  172729. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172730. }
  172731. #endif
  172732. #if defined(PNG_READ_zTXt_SUPPORTED)
  172733. void /* PRIVATE */
  172734. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172735. {
  172736. png_textp text_ptr;
  172737. png_charp chunkdata;
  172738. png_charp text;
  172739. int comp_type;
  172740. int ret;
  172741. png_size_t slength, prefix_len, data_len;
  172742. png_debug(1, "in png_handle_zTXt\n");
  172743. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172744. png_error(png_ptr, "Missing IHDR before zTXt");
  172745. if (png_ptr->mode & PNG_HAVE_IDAT)
  172746. png_ptr->mode |= PNG_AFTER_IDAT;
  172747. #ifdef PNG_MAX_MALLOC_64K
  172748. if (length > (png_uint_32)65535L)
  172749. {
  172750. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172751. png_crc_finish(png_ptr, length);
  172752. return;
  172753. }
  172754. #endif
  172755. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172756. if (chunkdata == NULL)
  172757. {
  172758. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172759. return;
  172760. }
  172761. slength = (png_size_t)length;
  172762. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172763. if (png_crc_finish(png_ptr, 0))
  172764. {
  172765. png_free(png_ptr, chunkdata);
  172766. return;
  172767. }
  172768. chunkdata[slength] = 0x00;
  172769. for (text = chunkdata; *text; text++)
  172770. ;
  172771. if (text >= chunkdata + slength - 2)
  172772. {
  172773. png_warning(png_ptr, "Truncated zTXt chunk");
  172774. png_free(png_ptr, chunkdata);
  172775. return;
  172776. }
  172777. else
  172778. {
  172779. comp_type = *(++text);
  172780. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172781. {
  172782. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172783. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172784. }
  172785. text++; /* skip the compression_method byte */
  172786. }
  172787. prefix_len = text - chunkdata;
  172788. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172789. (png_size_t)length, prefix_len, &data_len);
  172790. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172791. (png_uint_32)png_sizeof(png_text));
  172792. if (text_ptr == NULL)
  172793. {
  172794. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172795. png_free(png_ptr, chunkdata);
  172796. return;
  172797. }
  172798. text_ptr->compression = comp_type;
  172799. text_ptr->key = chunkdata;
  172800. #ifdef PNG_iTXt_SUPPORTED
  172801. text_ptr->lang = NULL;
  172802. text_ptr->lang_key = NULL;
  172803. text_ptr->itxt_length = 0;
  172804. #endif
  172805. text_ptr->text = chunkdata + prefix_len;
  172806. text_ptr->text_length = data_len;
  172807. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172808. png_free(png_ptr, text_ptr);
  172809. png_free(png_ptr, chunkdata);
  172810. if (ret)
  172811. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172812. }
  172813. #endif
  172814. #if defined(PNG_READ_iTXt_SUPPORTED)
  172815. void /* PRIVATE */
  172816. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172817. {
  172818. png_textp text_ptr;
  172819. png_charp chunkdata;
  172820. png_charp key, lang, text, lang_key;
  172821. int comp_flag;
  172822. int comp_type = 0;
  172823. int ret;
  172824. png_size_t slength, prefix_len, data_len;
  172825. png_debug(1, "in png_handle_iTXt\n");
  172826. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172827. png_error(png_ptr, "Missing IHDR before iTXt");
  172828. if (png_ptr->mode & PNG_HAVE_IDAT)
  172829. png_ptr->mode |= PNG_AFTER_IDAT;
  172830. #ifdef PNG_MAX_MALLOC_64K
  172831. if (length > (png_uint_32)65535L)
  172832. {
  172833. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172834. png_crc_finish(png_ptr, length);
  172835. return;
  172836. }
  172837. #endif
  172838. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172839. if (chunkdata == NULL)
  172840. {
  172841. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172842. return;
  172843. }
  172844. slength = (png_size_t)length;
  172845. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172846. if (png_crc_finish(png_ptr, 0))
  172847. {
  172848. png_free(png_ptr, chunkdata);
  172849. return;
  172850. }
  172851. chunkdata[slength] = 0x00;
  172852. for (lang = chunkdata; *lang; lang++)
  172853. ;
  172854. lang++; /* skip NUL separator */
  172855. if (lang >= chunkdata + slength - 3)
  172856. {
  172857. png_warning(png_ptr, "Truncated iTXt chunk");
  172858. png_free(png_ptr, chunkdata);
  172859. return;
  172860. }
  172861. else
  172862. {
  172863. comp_flag = *lang++;
  172864. comp_type = *lang++;
  172865. }
  172866. for (lang_key = lang; *lang_key; lang_key++)
  172867. ;
  172868. lang_key++; /* skip NUL separator */
  172869. if (lang_key >= chunkdata + slength)
  172870. {
  172871. png_warning(png_ptr, "Truncated iTXt chunk");
  172872. png_free(png_ptr, chunkdata);
  172873. return;
  172874. }
  172875. for (text = lang_key; *text; text++)
  172876. ;
  172877. text++; /* skip NUL separator */
  172878. if (text >= chunkdata + slength)
  172879. {
  172880. png_warning(png_ptr, "Malformed iTXt chunk");
  172881. png_free(png_ptr, chunkdata);
  172882. return;
  172883. }
  172884. prefix_len = text - chunkdata;
  172885. key=chunkdata;
  172886. if (comp_flag)
  172887. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172888. (size_t)length, prefix_len, &data_len);
  172889. else
  172890. data_len=png_strlen(chunkdata + prefix_len);
  172891. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172892. (png_uint_32)png_sizeof(png_text));
  172893. if (text_ptr == NULL)
  172894. {
  172895. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172896. png_free(png_ptr, chunkdata);
  172897. return;
  172898. }
  172899. text_ptr->compression = (int)comp_flag + 1;
  172900. text_ptr->lang_key = chunkdata+(lang_key-key);
  172901. text_ptr->lang = chunkdata+(lang-key);
  172902. text_ptr->itxt_length = data_len;
  172903. text_ptr->text_length = 0;
  172904. text_ptr->key = chunkdata;
  172905. text_ptr->text = chunkdata + prefix_len;
  172906. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172907. png_free(png_ptr, text_ptr);
  172908. png_free(png_ptr, chunkdata);
  172909. if (ret)
  172910. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172911. }
  172912. #endif
  172913. void /* PRIVATE */
  172914. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172915. {
  172916. png_uint_32 skip = 0;
  172917. png_debug(1, "in png_handle_unknown\n");
  172918. if (png_ptr->mode & PNG_HAVE_IDAT)
  172919. {
  172920. #ifdef PNG_USE_LOCAL_ARRAYS
  172921. PNG_CONST PNG_IDAT;
  172922. #endif
  172923. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172924. png_ptr->mode |= PNG_AFTER_IDAT;
  172925. }
  172926. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172927. if (!(png_ptr->chunk_name[0] & 0x20))
  172928. {
  172929. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172930. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172931. PNG_HANDLE_CHUNK_ALWAYS
  172932. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172933. && png_ptr->read_user_chunk_fn == NULL
  172934. #endif
  172935. )
  172936. #endif
  172937. png_chunk_error(png_ptr, "unknown critical chunk");
  172938. }
  172939. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172940. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172941. (png_ptr->read_user_chunk_fn != NULL))
  172942. {
  172943. #ifdef PNG_MAX_MALLOC_64K
  172944. if (length > (png_uint_32)65535L)
  172945. {
  172946. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172947. skip = length - (png_uint_32)65535L;
  172948. length = (png_uint_32)65535L;
  172949. }
  172950. #endif
  172951. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172952. (png_charp)png_ptr->chunk_name, 5);
  172953. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172954. png_ptr->unknown_chunk.size = (png_size_t)length;
  172955. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172956. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172957. if(png_ptr->read_user_chunk_fn != NULL)
  172958. {
  172959. int ret;
  172960. ret = (*(png_ptr->read_user_chunk_fn))
  172961. (png_ptr, &png_ptr->unknown_chunk);
  172962. if (ret < 0)
  172963. png_chunk_error(png_ptr, "error in user chunk");
  172964. if (ret == 0)
  172965. {
  172966. if (!(png_ptr->chunk_name[0] & 0x20))
  172967. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172968. PNG_HANDLE_CHUNK_ALWAYS)
  172969. png_chunk_error(png_ptr, "unknown critical chunk");
  172970. png_set_unknown_chunks(png_ptr, info_ptr,
  172971. &png_ptr->unknown_chunk, 1);
  172972. }
  172973. }
  172974. #else
  172975. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172976. #endif
  172977. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172978. png_ptr->unknown_chunk.data = NULL;
  172979. }
  172980. else
  172981. #endif
  172982. skip = length;
  172983. png_crc_finish(png_ptr, skip);
  172984. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172985. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172986. #endif
  172987. }
  172988. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172989. void /* PRIVATE */
  172990. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172991. {
  172992. png_debug(1, "in png_check_chunk_name\n");
  172993. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172994. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172995. {
  172996. png_chunk_error(png_ptr, "invalid chunk type");
  172997. }
  172998. }
  172999. void /* PRIVATE */
  173000. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  173001. {
  173002. png_debug(1,"in png_combine_row\n");
  173003. if (mask == 0xff)
  173004. {
  173005. png_memcpy(row, png_ptr->row_buf + 1,
  173006. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  173007. }
  173008. else
  173009. {
  173010. switch (png_ptr->row_info.pixel_depth)
  173011. {
  173012. case 1:
  173013. {
  173014. png_bytep sp = png_ptr->row_buf + 1;
  173015. png_bytep dp = row;
  173016. int s_inc, s_start, s_end;
  173017. int m = 0x80;
  173018. int shift;
  173019. png_uint_32 i;
  173020. png_uint_32 row_width = png_ptr->width;
  173021. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173022. if (png_ptr->transformations & PNG_PACKSWAP)
  173023. {
  173024. s_start = 0;
  173025. s_end = 7;
  173026. s_inc = 1;
  173027. }
  173028. else
  173029. #endif
  173030. {
  173031. s_start = 7;
  173032. s_end = 0;
  173033. s_inc = -1;
  173034. }
  173035. shift = s_start;
  173036. for (i = 0; i < row_width; i++)
  173037. {
  173038. if (m & mask)
  173039. {
  173040. int value;
  173041. value = (*sp >> shift) & 0x01;
  173042. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  173043. *dp |= (png_byte)(value << shift);
  173044. }
  173045. if (shift == s_end)
  173046. {
  173047. shift = s_start;
  173048. sp++;
  173049. dp++;
  173050. }
  173051. else
  173052. shift += s_inc;
  173053. if (m == 1)
  173054. m = 0x80;
  173055. else
  173056. m >>= 1;
  173057. }
  173058. break;
  173059. }
  173060. case 2:
  173061. {
  173062. png_bytep sp = png_ptr->row_buf + 1;
  173063. png_bytep dp = row;
  173064. int s_start, s_end, s_inc;
  173065. int m = 0x80;
  173066. int shift;
  173067. png_uint_32 i;
  173068. png_uint_32 row_width = png_ptr->width;
  173069. int value;
  173070. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173071. if (png_ptr->transformations & PNG_PACKSWAP)
  173072. {
  173073. s_start = 0;
  173074. s_end = 6;
  173075. s_inc = 2;
  173076. }
  173077. else
  173078. #endif
  173079. {
  173080. s_start = 6;
  173081. s_end = 0;
  173082. s_inc = -2;
  173083. }
  173084. shift = s_start;
  173085. for (i = 0; i < row_width; i++)
  173086. {
  173087. if (m & mask)
  173088. {
  173089. value = (*sp >> shift) & 0x03;
  173090. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  173091. *dp |= (png_byte)(value << shift);
  173092. }
  173093. if (shift == s_end)
  173094. {
  173095. shift = s_start;
  173096. sp++;
  173097. dp++;
  173098. }
  173099. else
  173100. shift += s_inc;
  173101. if (m == 1)
  173102. m = 0x80;
  173103. else
  173104. m >>= 1;
  173105. }
  173106. break;
  173107. }
  173108. case 4:
  173109. {
  173110. png_bytep sp = png_ptr->row_buf + 1;
  173111. png_bytep dp = row;
  173112. int s_start, s_end, s_inc;
  173113. int m = 0x80;
  173114. int shift;
  173115. png_uint_32 i;
  173116. png_uint_32 row_width = png_ptr->width;
  173117. int value;
  173118. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173119. if (png_ptr->transformations & PNG_PACKSWAP)
  173120. {
  173121. s_start = 0;
  173122. s_end = 4;
  173123. s_inc = 4;
  173124. }
  173125. else
  173126. #endif
  173127. {
  173128. s_start = 4;
  173129. s_end = 0;
  173130. s_inc = -4;
  173131. }
  173132. shift = s_start;
  173133. for (i = 0; i < row_width; i++)
  173134. {
  173135. if (m & mask)
  173136. {
  173137. value = (*sp >> shift) & 0xf;
  173138. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173139. *dp |= (png_byte)(value << shift);
  173140. }
  173141. if (shift == s_end)
  173142. {
  173143. shift = s_start;
  173144. sp++;
  173145. dp++;
  173146. }
  173147. else
  173148. shift += s_inc;
  173149. if (m == 1)
  173150. m = 0x80;
  173151. else
  173152. m >>= 1;
  173153. }
  173154. break;
  173155. }
  173156. default:
  173157. {
  173158. png_bytep sp = png_ptr->row_buf + 1;
  173159. png_bytep dp = row;
  173160. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173161. png_uint_32 i;
  173162. png_uint_32 row_width = png_ptr->width;
  173163. png_byte m = 0x80;
  173164. for (i = 0; i < row_width; i++)
  173165. {
  173166. if (m & mask)
  173167. {
  173168. png_memcpy(dp, sp, pixel_bytes);
  173169. }
  173170. sp += pixel_bytes;
  173171. dp += pixel_bytes;
  173172. if (m == 1)
  173173. m = 0x80;
  173174. else
  173175. m >>= 1;
  173176. }
  173177. break;
  173178. }
  173179. }
  173180. }
  173181. }
  173182. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173183. void /* PRIVATE */
  173184. png_do_read_interlace(png_structp png_ptr)
  173185. {
  173186. png_row_infop row_info = &(png_ptr->row_info);
  173187. png_bytep row = png_ptr->row_buf + 1;
  173188. int pass = png_ptr->pass;
  173189. png_uint_32 transformations = png_ptr->transformations;
  173190. #ifdef PNG_USE_LOCAL_ARRAYS
  173191. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173192. #endif
  173193. png_debug(1,"in png_do_read_interlace\n");
  173194. if (row != NULL && row_info != NULL)
  173195. {
  173196. png_uint_32 final_width;
  173197. final_width = row_info->width * png_pass_inc[pass];
  173198. switch (row_info->pixel_depth)
  173199. {
  173200. case 1:
  173201. {
  173202. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173203. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173204. int sshift, dshift;
  173205. int s_start, s_end, s_inc;
  173206. int jstop = png_pass_inc[pass];
  173207. png_byte v;
  173208. png_uint_32 i;
  173209. int j;
  173210. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173211. if (transformations & PNG_PACKSWAP)
  173212. {
  173213. sshift = (int)((row_info->width + 7) & 0x07);
  173214. dshift = (int)((final_width + 7) & 0x07);
  173215. s_start = 7;
  173216. s_end = 0;
  173217. s_inc = -1;
  173218. }
  173219. else
  173220. #endif
  173221. {
  173222. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173223. dshift = 7 - (int)((final_width + 7) & 0x07);
  173224. s_start = 0;
  173225. s_end = 7;
  173226. s_inc = 1;
  173227. }
  173228. for (i = 0; i < row_info->width; i++)
  173229. {
  173230. v = (png_byte)((*sp >> sshift) & 0x01);
  173231. for (j = 0; j < jstop; j++)
  173232. {
  173233. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173234. *dp |= (png_byte)(v << dshift);
  173235. if (dshift == s_end)
  173236. {
  173237. dshift = s_start;
  173238. dp--;
  173239. }
  173240. else
  173241. dshift += s_inc;
  173242. }
  173243. if (sshift == s_end)
  173244. {
  173245. sshift = s_start;
  173246. sp--;
  173247. }
  173248. else
  173249. sshift += s_inc;
  173250. }
  173251. break;
  173252. }
  173253. case 2:
  173254. {
  173255. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173256. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173257. int sshift, dshift;
  173258. int s_start, s_end, s_inc;
  173259. int jstop = png_pass_inc[pass];
  173260. png_uint_32 i;
  173261. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173262. if (transformations & PNG_PACKSWAP)
  173263. {
  173264. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173265. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173266. s_start = 6;
  173267. s_end = 0;
  173268. s_inc = -2;
  173269. }
  173270. else
  173271. #endif
  173272. {
  173273. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173274. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173275. s_start = 0;
  173276. s_end = 6;
  173277. s_inc = 2;
  173278. }
  173279. for (i = 0; i < row_info->width; i++)
  173280. {
  173281. png_byte v;
  173282. int j;
  173283. v = (png_byte)((*sp >> sshift) & 0x03);
  173284. for (j = 0; j < jstop; j++)
  173285. {
  173286. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173287. *dp |= (png_byte)(v << dshift);
  173288. if (dshift == s_end)
  173289. {
  173290. dshift = s_start;
  173291. dp--;
  173292. }
  173293. else
  173294. dshift += s_inc;
  173295. }
  173296. if (sshift == s_end)
  173297. {
  173298. sshift = s_start;
  173299. sp--;
  173300. }
  173301. else
  173302. sshift += s_inc;
  173303. }
  173304. break;
  173305. }
  173306. case 4:
  173307. {
  173308. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173309. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173310. int sshift, dshift;
  173311. int s_start, s_end, s_inc;
  173312. png_uint_32 i;
  173313. int jstop = png_pass_inc[pass];
  173314. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173315. if (transformations & PNG_PACKSWAP)
  173316. {
  173317. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173318. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173319. s_start = 4;
  173320. s_end = 0;
  173321. s_inc = -4;
  173322. }
  173323. else
  173324. #endif
  173325. {
  173326. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173327. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173328. s_start = 0;
  173329. s_end = 4;
  173330. s_inc = 4;
  173331. }
  173332. for (i = 0; i < row_info->width; i++)
  173333. {
  173334. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173335. int j;
  173336. for (j = 0; j < jstop; j++)
  173337. {
  173338. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173339. *dp |= (png_byte)(v << dshift);
  173340. if (dshift == s_end)
  173341. {
  173342. dshift = s_start;
  173343. dp--;
  173344. }
  173345. else
  173346. dshift += s_inc;
  173347. }
  173348. if (sshift == s_end)
  173349. {
  173350. sshift = s_start;
  173351. sp--;
  173352. }
  173353. else
  173354. sshift += s_inc;
  173355. }
  173356. break;
  173357. }
  173358. default:
  173359. {
  173360. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173361. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173362. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173363. int jstop = png_pass_inc[pass];
  173364. png_uint_32 i;
  173365. for (i = 0; i < row_info->width; i++)
  173366. {
  173367. png_byte v[8];
  173368. int j;
  173369. png_memcpy(v, sp, pixel_bytes);
  173370. for (j = 0; j < jstop; j++)
  173371. {
  173372. png_memcpy(dp, v, pixel_bytes);
  173373. dp -= pixel_bytes;
  173374. }
  173375. sp -= pixel_bytes;
  173376. }
  173377. break;
  173378. }
  173379. }
  173380. row_info->width = final_width;
  173381. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173382. }
  173383. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173384. transformations = transformations; /* silence compiler warning */
  173385. #endif
  173386. }
  173387. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173388. void /* PRIVATE */
  173389. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173390. png_bytep prev_row, int filter)
  173391. {
  173392. png_debug(1, "in png_read_filter_row\n");
  173393. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173394. switch (filter)
  173395. {
  173396. case PNG_FILTER_VALUE_NONE:
  173397. break;
  173398. case PNG_FILTER_VALUE_SUB:
  173399. {
  173400. png_uint_32 i;
  173401. png_uint_32 istop = row_info->rowbytes;
  173402. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173403. png_bytep rp = row + bpp;
  173404. png_bytep lp = row;
  173405. for (i = bpp; i < istop; i++)
  173406. {
  173407. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173408. rp++;
  173409. }
  173410. break;
  173411. }
  173412. case PNG_FILTER_VALUE_UP:
  173413. {
  173414. png_uint_32 i;
  173415. png_uint_32 istop = row_info->rowbytes;
  173416. png_bytep rp = row;
  173417. png_bytep pp = prev_row;
  173418. for (i = 0; i < istop; i++)
  173419. {
  173420. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173421. rp++;
  173422. }
  173423. break;
  173424. }
  173425. case PNG_FILTER_VALUE_AVG:
  173426. {
  173427. png_uint_32 i;
  173428. png_bytep rp = row;
  173429. png_bytep pp = prev_row;
  173430. png_bytep lp = row;
  173431. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173432. png_uint_32 istop = row_info->rowbytes - bpp;
  173433. for (i = 0; i < bpp; i++)
  173434. {
  173435. *rp = (png_byte)(((int)(*rp) +
  173436. ((int)(*pp++) / 2 )) & 0xff);
  173437. rp++;
  173438. }
  173439. for (i = 0; i < istop; i++)
  173440. {
  173441. *rp = (png_byte)(((int)(*rp) +
  173442. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173443. rp++;
  173444. }
  173445. break;
  173446. }
  173447. case PNG_FILTER_VALUE_PAETH:
  173448. {
  173449. png_uint_32 i;
  173450. png_bytep rp = row;
  173451. png_bytep pp = prev_row;
  173452. png_bytep lp = row;
  173453. png_bytep cp = prev_row;
  173454. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173455. png_uint_32 istop=row_info->rowbytes - bpp;
  173456. for (i = 0; i < bpp; i++)
  173457. {
  173458. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173459. rp++;
  173460. }
  173461. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173462. {
  173463. int a, b, c, pa, pb, pc, p;
  173464. a = *lp++;
  173465. b = *pp++;
  173466. c = *cp++;
  173467. p = b - c;
  173468. pc = a - c;
  173469. #ifdef PNG_USE_ABS
  173470. pa = abs(p);
  173471. pb = abs(pc);
  173472. pc = abs(p + pc);
  173473. #else
  173474. pa = p < 0 ? -p : p;
  173475. pb = pc < 0 ? -pc : pc;
  173476. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173477. #endif
  173478. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173479. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173480. rp++;
  173481. }
  173482. break;
  173483. }
  173484. default:
  173485. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173486. *row=0;
  173487. break;
  173488. }
  173489. }
  173490. void /* PRIVATE */
  173491. png_read_finish_row(png_structp png_ptr)
  173492. {
  173493. #ifdef PNG_USE_LOCAL_ARRAYS
  173494. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173495. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173496. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173497. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173498. #endif
  173499. png_debug(1, "in png_read_finish_row\n");
  173500. png_ptr->row_number++;
  173501. if (png_ptr->row_number < png_ptr->num_rows)
  173502. return;
  173503. if (png_ptr->interlaced)
  173504. {
  173505. png_ptr->row_number = 0;
  173506. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173507. png_ptr->rowbytes + 1);
  173508. do
  173509. {
  173510. png_ptr->pass++;
  173511. if (png_ptr->pass >= 7)
  173512. break;
  173513. png_ptr->iwidth = (png_ptr->width +
  173514. png_pass_inc[png_ptr->pass] - 1 -
  173515. png_pass_start[png_ptr->pass]) /
  173516. png_pass_inc[png_ptr->pass];
  173517. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173518. png_ptr->iwidth) + 1;
  173519. if (!(png_ptr->transformations & PNG_INTERLACE))
  173520. {
  173521. png_ptr->num_rows = (png_ptr->height +
  173522. png_pass_yinc[png_ptr->pass] - 1 -
  173523. png_pass_ystart[png_ptr->pass]) /
  173524. png_pass_yinc[png_ptr->pass];
  173525. if (!(png_ptr->num_rows))
  173526. continue;
  173527. }
  173528. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173529. break;
  173530. } while (png_ptr->iwidth == 0);
  173531. if (png_ptr->pass < 7)
  173532. return;
  173533. }
  173534. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173535. {
  173536. #ifdef PNG_USE_LOCAL_ARRAYS
  173537. PNG_CONST PNG_IDAT;
  173538. #endif
  173539. char extra;
  173540. int ret;
  173541. png_ptr->zstream.next_out = (Bytef *)&extra;
  173542. png_ptr->zstream.avail_out = (uInt)1;
  173543. for(;;)
  173544. {
  173545. if (!(png_ptr->zstream.avail_in))
  173546. {
  173547. while (!png_ptr->idat_size)
  173548. {
  173549. png_byte chunk_length[4];
  173550. png_crc_finish(png_ptr, 0);
  173551. png_read_data(png_ptr, chunk_length, 4);
  173552. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173553. png_reset_crc(png_ptr);
  173554. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173555. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173556. png_error(png_ptr, "Not enough image data");
  173557. }
  173558. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173559. png_ptr->zstream.next_in = png_ptr->zbuf;
  173560. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173561. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173562. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173563. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173564. }
  173565. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173566. if (ret == Z_STREAM_END)
  173567. {
  173568. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173569. png_ptr->idat_size)
  173570. png_warning(png_ptr, "Extra compressed data");
  173571. png_ptr->mode |= PNG_AFTER_IDAT;
  173572. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173573. break;
  173574. }
  173575. if (ret != Z_OK)
  173576. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173577. "Decompression Error");
  173578. if (!(png_ptr->zstream.avail_out))
  173579. {
  173580. png_warning(png_ptr, "Extra compressed data.");
  173581. png_ptr->mode |= PNG_AFTER_IDAT;
  173582. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173583. break;
  173584. }
  173585. }
  173586. png_ptr->zstream.avail_out = 0;
  173587. }
  173588. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173589. png_warning(png_ptr, "Extra compression data");
  173590. inflateReset(&png_ptr->zstream);
  173591. png_ptr->mode |= PNG_AFTER_IDAT;
  173592. }
  173593. void /* PRIVATE */
  173594. png_read_start_row(png_structp png_ptr)
  173595. {
  173596. #ifdef PNG_USE_LOCAL_ARRAYS
  173597. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173598. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173599. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173600. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173601. #endif
  173602. int max_pixel_depth;
  173603. png_uint_32 row_bytes;
  173604. png_debug(1, "in png_read_start_row\n");
  173605. png_ptr->zstream.avail_in = 0;
  173606. png_init_read_transformations(png_ptr);
  173607. if (png_ptr->interlaced)
  173608. {
  173609. if (!(png_ptr->transformations & PNG_INTERLACE))
  173610. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173611. png_pass_ystart[0]) / png_pass_yinc[0];
  173612. else
  173613. png_ptr->num_rows = png_ptr->height;
  173614. png_ptr->iwidth = (png_ptr->width +
  173615. png_pass_inc[png_ptr->pass] - 1 -
  173616. png_pass_start[png_ptr->pass]) /
  173617. png_pass_inc[png_ptr->pass];
  173618. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173619. png_ptr->irowbytes = (png_size_t)row_bytes;
  173620. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173621. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173622. }
  173623. else
  173624. {
  173625. png_ptr->num_rows = png_ptr->height;
  173626. png_ptr->iwidth = png_ptr->width;
  173627. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173628. }
  173629. max_pixel_depth = png_ptr->pixel_depth;
  173630. #if defined(PNG_READ_PACK_SUPPORTED)
  173631. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173632. max_pixel_depth = 8;
  173633. #endif
  173634. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173635. if (png_ptr->transformations & PNG_EXPAND)
  173636. {
  173637. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173638. {
  173639. if (png_ptr->num_trans)
  173640. max_pixel_depth = 32;
  173641. else
  173642. max_pixel_depth = 24;
  173643. }
  173644. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173645. {
  173646. if (max_pixel_depth < 8)
  173647. max_pixel_depth = 8;
  173648. if (png_ptr->num_trans)
  173649. max_pixel_depth *= 2;
  173650. }
  173651. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173652. {
  173653. if (png_ptr->num_trans)
  173654. {
  173655. max_pixel_depth *= 4;
  173656. max_pixel_depth /= 3;
  173657. }
  173658. }
  173659. }
  173660. #endif
  173661. #if defined(PNG_READ_FILLER_SUPPORTED)
  173662. if (png_ptr->transformations & (PNG_FILLER))
  173663. {
  173664. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173665. max_pixel_depth = 32;
  173666. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173667. {
  173668. if (max_pixel_depth <= 8)
  173669. max_pixel_depth = 16;
  173670. else
  173671. max_pixel_depth = 32;
  173672. }
  173673. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173674. {
  173675. if (max_pixel_depth <= 32)
  173676. max_pixel_depth = 32;
  173677. else
  173678. max_pixel_depth = 64;
  173679. }
  173680. }
  173681. #endif
  173682. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173683. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173684. {
  173685. if (
  173686. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173687. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173688. #endif
  173689. #if defined(PNG_READ_FILLER_SUPPORTED)
  173690. (png_ptr->transformations & (PNG_FILLER)) ||
  173691. #endif
  173692. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173693. {
  173694. if (max_pixel_depth <= 16)
  173695. max_pixel_depth = 32;
  173696. else
  173697. max_pixel_depth = 64;
  173698. }
  173699. else
  173700. {
  173701. if (max_pixel_depth <= 8)
  173702. {
  173703. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173704. max_pixel_depth = 32;
  173705. else
  173706. max_pixel_depth = 24;
  173707. }
  173708. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173709. max_pixel_depth = 64;
  173710. else
  173711. max_pixel_depth = 48;
  173712. }
  173713. }
  173714. #endif
  173715. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173716. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173717. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173718. {
  173719. int user_pixel_depth=png_ptr->user_transform_depth*
  173720. png_ptr->user_transform_channels;
  173721. if(user_pixel_depth > max_pixel_depth)
  173722. max_pixel_depth=user_pixel_depth;
  173723. }
  173724. #endif
  173725. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173726. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173727. 1 + ((max_pixel_depth + 7) >> 3);
  173728. #ifdef PNG_MAX_MALLOC_64K
  173729. if (row_bytes > (png_uint_32)65536L)
  173730. png_error(png_ptr, "This image requires a row greater than 64KB");
  173731. #endif
  173732. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173733. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173734. #ifdef PNG_MAX_MALLOC_64K
  173735. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173736. png_error(png_ptr, "This image requires a row greater than 64KB");
  173737. #endif
  173738. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173739. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173740. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173741. png_ptr->rowbytes + 1));
  173742. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173743. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173744. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173745. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173746. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173747. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173748. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173749. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173750. }
  173751. #endif /* PNG_READ_SUPPORTED */
  173752. /*** End of inlined file: pngrutil.c ***/
  173753. /*** Start of inlined file: pngset.c ***/
  173754. #define PNG_INTERNAL
  173755. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173756. #if defined(PNG_bKGD_SUPPORTED)
  173757. void PNGAPI
  173758. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173759. {
  173760. png_debug1(1, "in %s storage function\n", "bKGD");
  173761. if (png_ptr == NULL || info_ptr == NULL)
  173762. return;
  173763. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173764. info_ptr->valid |= PNG_INFO_bKGD;
  173765. }
  173766. #endif
  173767. #if defined(PNG_cHRM_SUPPORTED)
  173768. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173769. void PNGAPI
  173770. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173771. double white_x, double white_y, double red_x, double red_y,
  173772. double green_x, double green_y, double blue_x, double blue_y)
  173773. {
  173774. png_debug1(1, "in %s storage function\n", "cHRM");
  173775. if (png_ptr == NULL || info_ptr == NULL)
  173776. return;
  173777. if (white_x < 0.0 || white_y < 0.0 ||
  173778. red_x < 0.0 || red_y < 0.0 ||
  173779. green_x < 0.0 || green_y < 0.0 ||
  173780. blue_x < 0.0 || blue_y < 0.0)
  173781. {
  173782. png_warning(png_ptr,
  173783. "Ignoring attempt to set negative chromaticity value");
  173784. return;
  173785. }
  173786. if (white_x > 21474.83 || white_y > 21474.83 ||
  173787. red_x > 21474.83 || red_y > 21474.83 ||
  173788. green_x > 21474.83 || green_y > 21474.83 ||
  173789. blue_x > 21474.83 || blue_y > 21474.83)
  173790. {
  173791. png_warning(png_ptr,
  173792. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173793. return;
  173794. }
  173795. info_ptr->x_white = (float)white_x;
  173796. info_ptr->y_white = (float)white_y;
  173797. info_ptr->x_red = (float)red_x;
  173798. info_ptr->y_red = (float)red_y;
  173799. info_ptr->x_green = (float)green_x;
  173800. info_ptr->y_green = (float)green_y;
  173801. info_ptr->x_blue = (float)blue_x;
  173802. info_ptr->y_blue = (float)blue_y;
  173803. #ifdef PNG_FIXED_POINT_SUPPORTED
  173804. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173805. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173806. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173807. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173808. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173809. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173810. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173811. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173812. #endif
  173813. info_ptr->valid |= PNG_INFO_cHRM;
  173814. }
  173815. #endif
  173816. #ifdef PNG_FIXED_POINT_SUPPORTED
  173817. void PNGAPI
  173818. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173819. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173820. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173821. png_fixed_point blue_x, png_fixed_point blue_y)
  173822. {
  173823. png_debug1(1, "in %s storage function\n", "cHRM");
  173824. if (png_ptr == NULL || info_ptr == NULL)
  173825. return;
  173826. if (white_x < 0 || white_y < 0 ||
  173827. red_x < 0 || red_y < 0 ||
  173828. green_x < 0 || green_y < 0 ||
  173829. blue_x < 0 || blue_y < 0)
  173830. {
  173831. png_warning(png_ptr,
  173832. "Ignoring attempt to set negative chromaticity value");
  173833. return;
  173834. }
  173835. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173836. if (white_x > (double) PNG_UINT_31_MAX ||
  173837. white_y > (double) PNG_UINT_31_MAX ||
  173838. red_x > (double) PNG_UINT_31_MAX ||
  173839. red_y > (double) PNG_UINT_31_MAX ||
  173840. green_x > (double) PNG_UINT_31_MAX ||
  173841. green_y > (double) PNG_UINT_31_MAX ||
  173842. blue_x > (double) PNG_UINT_31_MAX ||
  173843. blue_y > (double) PNG_UINT_31_MAX)
  173844. #else
  173845. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173846. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173847. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173848. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173849. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173850. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173851. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173852. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173853. #endif
  173854. {
  173855. png_warning(png_ptr,
  173856. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173857. return;
  173858. }
  173859. info_ptr->int_x_white = white_x;
  173860. info_ptr->int_y_white = white_y;
  173861. info_ptr->int_x_red = red_x;
  173862. info_ptr->int_y_red = red_y;
  173863. info_ptr->int_x_green = green_x;
  173864. info_ptr->int_y_green = green_y;
  173865. info_ptr->int_x_blue = blue_x;
  173866. info_ptr->int_y_blue = blue_y;
  173867. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173868. info_ptr->x_white = (float)(white_x/100000.);
  173869. info_ptr->y_white = (float)(white_y/100000.);
  173870. info_ptr->x_red = (float)( red_x/100000.);
  173871. info_ptr->y_red = (float)( red_y/100000.);
  173872. info_ptr->x_green = (float)(green_x/100000.);
  173873. info_ptr->y_green = (float)(green_y/100000.);
  173874. info_ptr->x_blue = (float)( blue_x/100000.);
  173875. info_ptr->y_blue = (float)( blue_y/100000.);
  173876. #endif
  173877. info_ptr->valid |= PNG_INFO_cHRM;
  173878. }
  173879. #endif
  173880. #endif
  173881. #if defined(PNG_gAMA_SUPPORTED)
  173882. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173883. void PNGAPI
  173884. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173885. {
  173886. double gamma;
  173887. png_debug1(1, "in %s storage function\n", "gAMA");
  173888. if (png_ptr == NULL || info_ptr == NULL)
  173889. return;
  173890. if (file_gamma > 21474.83)
  173891. {
  173892. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173893. gamma=21474.83;
  173894. }
  173895. else
  173896. gamma=file_gamma;
  173897. info_ptr->gamma = (float)gamma;
  173898. #ifdef PNG_FIXED_POINT_SUPPORTED
  173899. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173900. #endif
  173901. info_ptr->valid |= PNG_INFO_gAMA;
  173902. if(gamma == 0.0)
  173903. png_warning(png_ptr, "Setting gamma=0");
  173904. }
  173905. #endif
  173906. void PNGAPI
  173907. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173908. int_gamma)
  173909. {
  173910. png_fixed_point gamma;
  173911. png_debug1(1, "in %s storage function\n", "gAMA");
  173912. if (png_ptr == NULL || info_ptr == NULL)
  173913. return;
  173914. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173915. {
  173916. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173917. gamma=PNG_UINT_31_MAX;
  173918. }
  173919. else
  173920. {
  173921. if (int_gamma < 0)
  173922. {
  173923. png_warning(png_ptr, "Setting negative gamma to zero");
  173924. gamma=0;
  173925. }
  173926. else
  173927. gamma=int_gamma;
  173928. }
  173929. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173930. info_ptr->gamma = (float)(gamma/100000.);
  173931. #endif
  173932. #ifdef PNG_FIXED_POINT_SUPPORTED
  173933. info_ptr->int_gamma = gamma;
  173934. #endif
  173935. info_ptr->valid |= PNG_INFO_gAMA;
  173936. if(gamma == 0)
  173937. png_warning(png_ptr, "Setting gamma=0");
  173938. }
  173939. #endif
  173940. #if defined(PNG_hIST_SUPPORTED)
  173941. void PNGAPI
  173942. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173943. {
  173944. int i;
  173945. png_debug1(1, "in %s storage function\n", "hIST");
  173946. if (png_ptr == NULL || info_ptr == NULL)
  173947. return;
  173948. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173949. > PNG_MAX_PALETTE_LENGTH)
  173950. {
  173951. png_warning(png_ptr,
  173952. "Invalid palette size, hIST allocation skipped.");
  173953. return;
  173954. }
  173955. #ifdef PNG_FREE_ME_SUPPORTED
  173956. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173957. #endif
  173958. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173959. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173960. if (png_ptr->hist == NULL)
  173961. {
  173962. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173963. return;
  173964. }
  173965. for (i = 0; i < info_ptr->num_palette; i++)
  173966. png_ptr->hist[i] = hist[i];
  173967. info_ptr->hist = png_ptr->hist;
  173968. info_ptr->valid |= PNG_INFO_hIST;
  173969. #ifdef PNG_FREE_ME_SUPPORTED
  173970. info_ptr->free_me |= PNG_FREE_HIST;
  173971. #else
  173972. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173973. #endif
  173974. }
  173975. #endif
  173976. void PNGAPI
  173977. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173978. png_uint_32 width, png_uint_32 height, int bit_depth,
  173979. int color_type, int interlace_type, int compression_type,
  173980. int filter_type)
  173981. {
  173982. png_debug1(1, "in %s storage function\n", "IHDR");
  173983. if (png_ptr == NULL || info_ptr == NULL)
  173984. return;
  173985. if (width == 0 || height == 0)
  173986. png_error(png_ptr, "Image width or height is zero in IHDR");
  173987. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173988. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173989. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173990. #else
  173991. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173992. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173993. #endif
  173994. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173995. png_error(png_ptr, "Invalid image size in IHDR");
  173996. if ( width > (PNG_UINT_32_MAX
  173997. >> 3) /* 8-byte RGBA pixels */
  173998. - 64 /* bigrowbuf hack */
  173999. - 1 /* filter byte */
  174000. - 7*8 /* rounding of width to multiple of 8 pixels */
  174001. - 8) /* extra max_pixel_depth pad */
  174002. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  174003. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  174004. bit_depth != 8 && bit_depth != 16)
  174005. png_error(png_ptr, "Invalid bit depth in IHDR");
  174006. if (color_type < 0 || color_type == 1 ||
  174007. color_type == 5 || color_type > 6)
  174008. png_error(png_ptr, "Invalid color type in IHDR");
  174009. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  174010. ((color_type == PNG_COLOR_TYPE_RGB ||
  174011. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  174012. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  174013. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  174014. if (interlace_type >= PNG_INTERLACE_LAST)
  174015. png_error(png_ptr, "Unknown interlace method in IHDR");
  174016. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  174017. png_error(png_ptr, "Unknown compression method in IHDR");
  174018. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174019. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  174020. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174021. if(filter_type != PNG_FILTER_TYPE_BASE)
  174022. {
  174023. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  174024. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  174025. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  174026. (color_type == PNG_COLOR_TYPE_RGB ||
  174027. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  174028. png_error(png_ptr, "Unknown filter method in IHDR");
  174029. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  174030. png_warning(png_ptr, "Invalid filter method in IHDR");
  174031. }
  174032. #else
  174033. if(filter_type != PNG_FILTER_TYPE_BASE)
  174034. png_error(png_ptr, "Unknown filter method in IHDR");
  174035. #endif
  174036. info_ptr->width = width;
  174037. info_ptr->height = height;
  174038. info_ptr->bit_depth = (png_byte)bit_depth;
  174039. info_ptr->color_type =(png_byte) color_type;
  174040. info_ptr->compression_type = (png_byte)compression_type;
  174041. info_ptr->filter_type = (png_byte)filter_type;
  174042. info_ptr->interlace_type = (png_byte)interlace_type;
  174043. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174044. info_ptr->channels = 1;
  174045. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  174046. info_ptr->channels = 3;
  174047. else
  174048. info_ptr->channels = 1;
  174049. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  174050. info_ptr->channels++;
  174051. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  174052. if (width > (PNG_UINT_32_MAX
  174053. >> 3) /* 8-byte RGBA pixels */
  174054. - 64 /* bigrowbuf hack */
  174055. - 1 /* filter byte */
  174056. - 7*8 /* rounding of width to multiple of 8 pixels */
  174057. - 8) /* extra max_pixel_depth pad */
  174058. info_ptr->rowbytes = (png_size_t)0;
  174059. else
  174060. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  174061. }
  174062. #if defined(PNG_oFFs_SUPPORTED)
  174063. void PNGAPI
  174064. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  174065. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  174066. {
  174067. png_debug1(1, "in %s storage function\n", "oFFs");
  174068. if (png_ptr == NULL || info_ptr == NULL)
  174069. return;
  174070. info_ptr->x_offset = offset_x;
  174071. info_ptr->y_offset = offset_y;
  174072. info_ptr->offset_unit_type = (png_byte)unit_type;
  174073. info_ptr->valid |= PNG_INFO_oFFs;
  174074. }
  174075. #endif
  174076. #if defined(PNG_pCAL_SUPPORTED)
  174077. void PNGAPI
  174078. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  174079. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  174080. png_charp units, png_charpp params)
  174081. {
  174082. png_uint_32 length;
  174083. int i;
  174084. png_debug1(1, "in %s storage function\n", "pCAL");
  174085. if (png_ptr == NULL || info_ptr == NULL)
  174086. return;
  174087. length = png_strlen(purpose) + 1;
  174088. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  174089. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  174090. if (info_ptr->pcal_purpose == NULL)
  174091. {
  174092. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  174093. return;
  174094. }
  174095. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  174096. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174097. info_ptr->pcal_X0 = X0;
  174098. info_ptr->pcal_X1 = X1;
  174099. info_ptr->pcal_type = (png_byte)type;
  174100. info_ptr->pcal_nparams = (png_byte)nparams;
  174101. length = png_strlen(units) + 1;
  174102. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174103. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174104. if (info_ptr->pcal_units == NULL)
  174105. {
  174106. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174107. return;
  174108. }
  174109. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174110. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174111. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174112. if (info_ptr->pcal_params == NULL)
  174113. {
  174114. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174115. return;
  174116. }
  174117. info_ptr->pcal_params[nparams] = NULL;
  174118. for (i = 0; i < nparams; i++)
  174119. {
  174120. length = png_strlen(params[i]) + 1;
  174121. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174122. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174123. if (info_ptr->pcal_params[i] == NULL)
  174124. {
  174125. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174126. return;
  174127. }
  174128. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174129. }
  174130. info_ptr->valid |= PNG_INFO_pCAL;
  174131. #ifdef PNG_FREE_ME_SUPPORTED
  174132. info_ptr->free_me |= PNG_FREE_PCAL;
  174133. #endif
  174134. }
  174135. #endif
  174136. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174137. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174138. void PNGAPI
  174139. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174140. int unit, double width, double height)
  174141. {
  174142. png_debug1(1, "in %s storage function\n", "sCAL");
  174143. if (png_ptr == NULL || info_ptr == NULL)
  174144. return;
  174145. info_ptr->scal_unit = (png_byte)unit;
  174146. info_ptr->scal_pixel_width = width;
  174147. info_ptr->scal_pixel_height = height;
  174148. info_ptr->valid |= PNG_INFO_sCAL;
  174149. }
  174150. #else
  174151. #ifdef PNG_FIXED_POINT_SUPPORTED
  174152. void PNGAPI
  174153. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174154. int unit, png_charp swidth, png_charp sheight)
  174155. {
  174156. png_uint_32 length;
  174157. png_debug1(1, "in %s storage function\n", "sCAL");
  174158. if (png_ptr == NULL || info_ptr == NULL)
  174159. return;
  174160. info_ptr->scal_unit = (png_byte)unit;
  174161. length = png_strlen(swidth) + 1;
  174162. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174163. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174164. if (info_ptr->scal_s_width == NULL)
  174165. {
  174166. png_warning(png_ptr,
  174167. "Memory allocation failed while processing sCAL.");
  174168. }
  174169. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174170. length = png_strlen(sheight) + 1;
  174171. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174172. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174173. if (info_ptr->scal_s_height == NULL)
  174174. {
  174175. png_free (png_ptr, info_ptr->scal_s_width);
  174176. png_warning(png_ptr,
  174177. "Memory allocation failed while processing sCAL.");
  174178. }
  174179. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174180. info_ptr->valid |= PNG_INFO_sCAL;
  174181. #ifdef PNG_FREE_ME_SUPPORTED
  174182. info_ptr->free_me |= PNG_FREE_SCAL;
  174183. #endif
  174184. }
  174185. #endif
  174186. #endif
  174187. #endif
  174188. #if defined(PNG_pHYs_SUPPORTED)
  174189. void PNGAPI
  174190. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174191. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174192. {
  174193. png_debug1(1, "in %s storage function\n", "pHYs");
  174194. if (png_ptr == NULL || info_ptr == NULL)
  174195. return;
  174196. info_ptr->x_pixels_per_unit = res_x;
  174197. info_ptr->y_pixels_per_unit = res_y;
  174198. info_ptr->phys_unit_type = (png_byte)unit_type;
  174199. info_ptr->valid |= PNG_INFO_pHYs;
  174200. }
  174201. #endif
  174202. void PNGAPI
  174203. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174204. png_colorp palette, int num_palette)
  174205. {
  174206. png_debug1(1, "in %s storage function\n", "PLTE");
  174207. if (png_ptr == NULL || info_ptr == NULL)
  174208. return;
  174209. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174210. {
  174211. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174212. png_error(png_ptr, "Invalid palette length");
  174213. else
  174214. {
  174215. png_warning(png_ptr, "Invalid palette length");
  174216. return;
  174217. }
  174218. }
  174219. #ifdef PNG_FREE_ME_SUPPORTED
  174220. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174221. #endif
  174222. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174223. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174224. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174225. png_sizeof(png_color));
  174226. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174227. info_ptr->palette = png_ptr->palette;
  174228. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174229. #ifdef PNG_FREE_ME_SUPPORTED
  174230. info_ptr->free_me |= PNG_FREE_PLTE;
  174231. #else
  174232. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174233. #endif
  174234. info_ptr->valid |= PNG_INFO_PLTE;
  174235. }
  174236. #if defined(PNG_sBIT_SUPPORTED)
  174237. void PNGAPI
  174238. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174239. png_color_8p sig_bit)
  174240. {
  174241. png_debug1(1, "in %s storage function\n", "sBIT");
  174242. if (png_ptr == NULL || info_ptr == NULL)
  174243. return;
  174244. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174245. info_ptr->valid |= PNG_INFO_sBIT;
  174246. }
  174247. #endif
  174248. #if defined(PNG_sRGB_SUPPORTED)
  174249. void PNGAPI
  174250. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174251. {
  174252. png_debug1(1, "in %s storage function\n", "sRGB");
  174253. if (png_ptr == NULL || info_ptr == NULL)
  174254. return;
  174255. info_ptr->srgb_intent = (png_byte)intent;
  174256. info_ptr->valid |= PNG_INFO_sRGB;
  174257. }
  174258. void PNGAPI
  174259. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174260. int intent)
  174261. {
  174262. #if defined(PNG_gAMA_SUPPORTED)
  174263. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174264. float file_gamma;
  174265. #endif
  174266. #ifdef PNG_FIXED_POINT_SUPPORTED
  174267. png_fixed_point int_file_gamma;
  174268. #endif
  174269. #endif
  174270. #if defined(PNG_cHRM_SUPPORTED)
  174271. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174272. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174273. #endif
  174274. #ifdef PNG_FIXED_POINT_SUPPORTED
  174275. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174276. int_green_y, int_blue_x, int_blue_y;
  174277. #endif
  174278. #endif
  174279. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174280. if (png_ptr == NULL || info_ptr == NULL)
  174281. return;
  174282. png_set_sRGB(png_ptr, info_ptr, intent);
  174283. #if defined(PNG_gAMA_SUPPORTED)
  174284. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174285. file_gamma = (float).45455;
  174286. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174287. #endif
  174288. #ifdef PNG_FIXED_POINT_SUPPORTED
  174289. int_file_gamma = 45455L;
  174290. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174291. #endif
  174292. #endif
  174293. #if defined(PNG_cHRM_SUPPORTED)
  174294. #ifdef PNG_FIXED_POINT_SUPPORTED
  174295. int_white_x = 31270L;
  174296. int_white_y = 32900L;
  174297. int_red_x = 64000L;
  174298. int_red_y = 33000L;
  174299. int_green_x = 30000L;
  174300. int_green_y = 60000L;
  174301. int_blue_x = 15000L;
  174302. int_blue_y = 6000L;
  174303. png_set_cHRM_fixed(png_ptr, info_ptr,
  174304. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174305. int_blue_x, int_blue_y);
  174306. #endif
  174307. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174308. white_x = (float).3127;
  174309. white_y = (float).3290;
  174310. red_x = (float).64;
  174311. red_y = (float).33;
  174312. green_x = (float).30;
  174313. green_y = (float).60;
  174314. blue_x = (float).15;
  174315. blue_y = (float).06;
  174316. png_set_cHRM(png_ptr, info_ptr,
  174317. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174318. #endif
  174319. #endif
  174320. }
  174321. #endif
  174322. #if defined(PNG_iCCP_SUPPORTED)
  174323. void PNGAPI
  174324. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174325. png_charp name, int compression_type,
  174326. png_charp profile, png_uint_32 proflen)
  174327. {
  174328. png_charp new_iccp_name;
  174329. png_charp new_iccp_profile;
  174330. png_debug1(1, "in %s storage function\n", "iCCP");
  174331. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174332. return;
  174333. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174334. if (new_iccp_name == NULL)
  174335. {
  174336. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174337. return;
  174338. }
  174339. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174340. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174341. if (new_iccp_profile == NULL)
  174342. {
  174343. png_free (png_ptr, new_iccp_name);
  174344. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174345. return;
  174346. }
  174347. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174348. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174349. info_ptr->iccp_proflen = proflen;
  174350. info_ptr->iccp_name = new_iccp_name;
  174351. info_ptr->iccp_profile = new_iccp_profile;
  174352. info_ptr->iccp_compression = (png_byte)compression_type;
  174353. #ifdef PNG_FREE_ME_SUPPORTED
  174354. info_ptr->free_me |= PNG_FREE_ICCP;
  174355. #endif
  174356. info_ptr->valid |= PNG_INFO_iCCP;
  174357. }
  174358. #endif
  174359. #if defined(PNG_TEXT_SUPPORTED)
  174360. void PNGAPI
  174361. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174362. int num_text)
  174363. {
  174364. int ret;
  174365. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174366. if (ret)
  174367. png_error(png_ptr, "Insufficient memory to store text");
  174368. }
  174369. int /* PRIVATE */
  174370. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174371. int num_text)
  174372. {
  174373. int i;
  174374. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174375. "text" : (png_const_charp)png_ptr->chunk_name));
  174376. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174377. return(0);
  174378. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174379. {
  174380. if (info_ptr->text != NULL)
  174381. {
  174382. png_textp old_text;
  174383. int old_max;
  174384. old_max = info_ptr->max_text;
  174385. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174386. old_text = info_ptr->text;
  174387. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174388. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174389. if (info_ptr->text == NULL)
  174390. {
  174391. png_free(png_ptr, old_text);
  174392. return(1);
  174393. }
  174394. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174395. png_sizeof(png_text)));
  174396. png_free(png_ptr, old_text);
  174397. }
  174398. else
  174399. {
  174400. info_ptr->max_text = num_text + 8;
  174401. info_ptr->num_text = 0;
  174402. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174403. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174404. if (info_ptr->text == NULL)
  174405. return(1);
  174406. #ifdef PNG_FREE_ME_SUPPORTED
  174407. info_ptr->free_me |= PNG_FREE_TEXT;
  174408. #endif
  174409. }
  174410. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174411. info_ptr->max_text);
  174412. }
  174413. for (i = 0; i < num_text; i++)
  174414. {
  174415. png_size_t text_length,key_len;
  174416. png_size_t lang_len,lang_key_len;
  174417. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174418. if (text_ptr[i].key == NULL)
  174419. continue;
  174420. key_len = png_strlen(text_ptr[i].key);
  174421. if(text_ptr[i].compression <= 0)
  174422. {
  174423. lang_len = 0;
  174424. lang_key_len = 0;
  174425. }
  174426. else
  174427. #ifdef PNG_iTXt_SUPPORTED
  174428. {
  174429. if (text_ptr[i].lang != NULL)
  174430. lang_len = png_strlen(text_ptr[i].lang);
  174431. else
  174432. lang_len = 0;
  174433. if (text_ptr[i].lang_key != NULL)
  174434. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174435. else
  174436. lang_key_len = 0;
  174437. }
  174438. #else
  174439. {
  174440. png_warning(png_ptr, "iTXt chunk not supported.");
  174441. continue;
  174442. }
  174443. #endif
  174444. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174445. {
  174446. text_length = 0;
  174447. #ifdef PNG_iTXt_SUPPORTED
  174448. if(text_ptr[i].compression > 0)
  174449. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174450. else
  174451. #endif
  174452. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174453. }
  174454. else
  174455. {
  174456. text_length = png_strlen(text_ptr[i].text);
  174457. textp->compression = text_ptr[i].compression;
  174458. }
  174459. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174460. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174461. if (textp->key == NULL)
  174462. return(1);
  174463. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174464. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174465. (int)textp->key);
  174466. png_memcpy(textp->key, text_ptr[i].key,
  174467. (png_size_t)(key_len));
  174468. *(textp->key+key_len) = '\0';
  174469. #ifdef PNG_iTXt_SUPPORTED
  174470. if (text_ptr[i].compression > 0)
  174471. {
  174472. textp->lang=textp->key + key_len + 1;
  174473. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174474. *(textp->lang+lang_len) = '\0';
  174475. textp->lang_key=textp->lang + lang_len + 1;
  174476. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174477. *(textp->lang_key+lang_key_len) = '\0';
  174478. textp->text=textp->lang_key + lang_key_len + 1;
  174479. }
  174480. else
  174481. #endif
  174482. {
  174483. #ifdef PNG_iTXt_SUPPORTED
  174484. textp->lang=NULL;
  174485. textp->lang_key=NULL;
  174486. #endif
  174487. textp->text=textp->key + key_len + 1;
  174488. }
  174489. if(text_length)
  174490. png_memcpy(textp->text, text_ptr[i].text,
  174491. (png_size_t)(text_length));
  174492. *(textp->text+text_length) = '\0';
  174493. #ifdef PNG_iTXt_SUPPORTED
  174494. if(textp->compression > 0)
  174495. {
  174496. textp->text_length = 0;
  174497. textp->itxt_length = text_length;
  174498. }
  174499. else
  174500. #endif
  174501. {
  174502. textp->text_length = text_length;
  174503. #ifdef PNG_iTXt_SUPPORTED
  174504. textp->itxt_length = 0;
  174505. #endif
  174506. }
  174507. info_ptr->num_text++;
  174508. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174509. }
  174510. return(0);
  174511. }
  174512. #endif
  174513. #if defined(PNG_tIME_SUPPORTED)
  174514. void PNGAPI
  174515. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174516. {
  174517. png_debug1(1, "in %s storage function\n", "tIME");
  174518. if (png_ptr == NULL || info_ptr == NULL ||
  174519. (png_ptr->mode & PNG_WROTE_tIME))
  174520. return;
  174521. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174522. info_ptr->valid |= PNG_INFO_tIME;
  174523. }
  174524. #endif
  174525. #if defined(PNG_tRNS_SUPPORTED)
  174526. void PNGAPI
  174527. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174528. png_bytep trans, int num_trans, png_color_16p trans_values)
  174529. {
  174530. png_debug1(1, "in %s storage function\n", "tRNS");
  174531. if (png_ptr == NULL || info_ptr == NULL)
  174532. return;
  174533. if (trans != NULL)
  174534. {
  174535. #ifdef PNG_FREE_ME_SUPPORTED
  174536. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174537. #endif
  174538. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174539. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174540. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174541. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174542. #ifdef PNG_FREE_ME_SUPPORTED
  174543. info_ptr->free_me |= PNG_FREE_TRNS;
  174544. #else
  174545. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174546. #endif
  174547. }
  174548. if (trans_values != NULL)
  174549. {
  174550. png_memcpy(&(info_ptr->trans_values), trans_values,
  174551. png_sizeof(png_color_16));
  174552. if (num_trans == 0)
  174553. num_trans = 1;
  174554. }
  174555. info_ptr->num_trans = (png_uint_16)num_trans;
  174556. info_ptr->valid |= PNG_INFO_tRNS;
  174557. }
  174558. #endif
  174559. #if defined(PNG_sPLT_SUPPORTED)
  174560. void PNGAPI
  174561. png_set_sPLT(png_structp png_ptr,
  174562. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174563. {
  174564. png_sPLT_tp np;
  174565. int i;
  174566. if (png_ptr == NULL || info_ptr == NULL)
  174567. return;
  174568. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174569. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174570. if (np == NULL)
  174571. {
  174572. png_warning(png_ptr, "No memory for sPLT palettes.");
  174573. return;
  174574. }
  174575. png_memcpy(np, info_ptr->splt_palettes,
  174576. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174577. png_free(png_ptr, info_ptr->splt_palettes);
  174578. info_ptr->splt_palettes=NULL;
  174579. for (i = 0; i < nentries; i++)
  174580. {
  174581. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174582. png_sPLT_tp from = entries + i;
  174583. to->name = (png_charp)png_malloc_warn(png_ptr,
  174584. png_strlen(from->name) + 1);
  174585. if (to->name == NULL)
  174586. {
  174587. png_warning(png_ptr,
  174588. "Out of memory while processing sPLT chunk");
  174589. }
  174590. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174591. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174592. from->nentries * png_sizeof(png_sPLT_entry));
  174593. png_memcpy(to->entries, from->entries,
  174594. from->nentries * png_sizeof(png_sPLT_entry));
  174595. if (to->entries == NULL)
  174596. {
  174597. png_warning(png_ptr,
  174598. "Out of memory while processing sPLT chunk");
  174599. png_free(png_ptr,to->name);
  174600. to->name = NULL;
  174601. }
  174602. to->nentries = from->nentries;
  174603. to->depth = from->depth;
  174604. }
  174605. info_ptr->splt_palettes = np;
  174606. info_ptr->splt_palettes_num += nentries;
  174607. info_ptr->valid |= PNG_INFO_sPLT;
  174608. #ifdef PNG_FREE_ME_SUPPORTED
  174609. info_ptr->free_me |= PNG_FREE_SPLT;
  174610. #endif
  174611. }
  174612. #endif /* PNG_sPLT_SUPPORTED */
  174613. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174614. void PNGAPI
  174615. png_set_unknown_chunks(png_structp png_ptr,
  174616. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174617. {
  174618. png_unknown_chunkp np;
  174619. int i;
  174620. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174621. return;
  174622. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174623. (info_ptr->unknown_chunks_num + num_unknowns) *
  174624. png_sizeof(png_unknown_chunk));
  174625. if (np == NULL)
  174626. {
  174627. png_warning(png_ptr,
  174628. "Out of memory while processing unknown chunk.");
  174629. return;
  174630. }
  174631. png_memcpy(np, info_ptr->unknown_chunks,
  174632. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174633. png_free(png_ptr, info_ptr->unknown_chunks);
  174634. info_ptr->unknown_chunks=NULL;
  174635. for (i = 0; i < num_unknowns; i++)
  174636. {
  174637. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174638. png_unknown_chunkp from = unknowns + i;
  174639. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174640. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174641. if (to->data == NULL)
  174642. {
  174643. png_warning(png_ptr,
  174644. "Out of memory while processing unknown chunk.");
  174645. }
  174646. else
  174647. {
  174648. png_memcpy(to->data, from->data, from->size);
  174649. to->size = from->size;
  174650. to->location = (png_byte)(png_ptr->mode & 0xff);
  174651. }
  174652. }
  174653. info_ptr->unknown_chunks = np;
  174654. info_ptr->unknown_chunks_num += num_unknowns;
  174655. #ifdef PNG_FREE_ME_SUPPORTED
  174656. info_ptr->free_me |= PNG_FREE_UNKN;
  174657. #endif
  174658. }
  174659. void PNGAPI
  174660. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174661. int chunk, int location)
  174662. {
  174663. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174664. (int)info_ptr->unknown_chunks_num)
  174665. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174666. }
  174667. #endif
  174668. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174669. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174670. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174671. void PNGAPI
  174672. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174673. {
  174674. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174675. if (png_ptr == NULL)
  174676. return;
  174677. png_ptr->mng_features_permitted = (png_byte)
  174678. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174679. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174680. }
  174681. #endif
  174682. #endif
  174683. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174684. png_uint_32 PNGAPI
  174685. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174686. {
  174687. png_debug(1, "in png_permit_mng_features\n");
  174688. if (png_ptr == NULL)
  174689. return (png_uint_32)0;
  174690. png_ptr->mng_features_permitted =
  174691. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174692. return (png_uint_32)png_ptr->mng_features_permitted;
  174693. }
  174694. #endif
  174695. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174696. void PNGAPI
  174697. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174698. chunk_list, int num_chunks)
  174699. {
  174700. png_bytep new_list, p;
  174701. int i, old_num_chunks;
  174702. if (png_ptr == NULL)
  174703. return;
  174704. if (num_chunks == 0)
  174705. {
  174706. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174707. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174708. else
  174709. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174710. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174711. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174712. else
  174713. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174714. return;
  174715. }
  174716. if (chunk_list == NULL)
  174717. return;
  174718. old_num_chunks=png_ptr->num_chunk_list;
  174719. new_list=(png_bytep)png_malloc(png_ptr,
  174720. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174721. if(png_ptr->chunk_list != NULL)
  174722. {
  174723. png_memcpy(new_list, png_ptr->chunk_list,
  174724. (png_size_t)(5*old_num_chunks));
  174725. png_free(png_ptr, png_ptr->chunk_list);
  174726. png_ptr->chunk_list=NULL;
  174727. }
  174728. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174729. (png_size_t)(5*num_chunks));
  174730. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174731. *p=(png_byte)keep;
  174732. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174733. png_ptr->chunk_list=new_list;
  174734. #ifdef PNG_FREE_ME_SUPPORTED
  174735. png_ptr->free_me |= PNG_FREE_LIST;
  174736. #endif
  174737. }
  174738. #endif
  174739. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174740. void PNGAPI
  174741. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174742. png_user_chunk_ptr read_user_chunk_fn)
  174743. {
  174744. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174745. if (png_ptr == NULL)
  174746. return;
  174747. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174748. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174749. }
  174750. #endif
  174751. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174752. void PNGAPI
  174753. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174754. {
  174755. png_debug1(1, "in %s storage function\n", "rows");
  174756. if (png_ptr == NULL || info_ptr == NULL)
  174757. return;
  174758. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174759. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174760. info_ptr->row_pointers = row_pointers;
  174761. if(row_pointers)
  174762. info_ptr->valid |= PNG_INFO_IDAT;
  174763. }
  174764. #endif
  174765. #ifdef PNG_WRITE_SUPPORTED
  174766. void PNGAPI
  174767. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174768. {
  174769. if (png_ptr == NULL)
  174770. return;
  174771. if(png_ptr->zbuf)
  174772. png_free(png_ptr, png_ptr->zbuf);
  174773. png_ptr->zbuf_size = (png_size_t)size;
  174774. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174775. png_ptr->zstream.next_out = png_ptr->zbuf;
  174776. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174777. }
  174778. #endif
  174779. void PNGAPI
  174780. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174781. {
  174782. if (png_ptr && info_ptr)
  174783. info_ptr->valid &= ~(mask);
  174784. }
  174785. #ifndef PNG_1_0_X
  174786. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174787. void PNGAPI
  174788. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174789. {
  174790. if (png_ptr != NULL)
  174791. png_ptr->asm_flags = 0;
  174792. }
  174793. void PNGAPI
  174794. png_set_mmx_thresholds (png_structp png_ptr,
  174795. png_byte mmx_bitdepth_threshold,
  174796. png_uint_32 mmx_rowbytes_threshold)
  174797. {
  174798. if (png_ptr == NULL)
  174799. return;
  174800. }
  174801. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174802. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174803. void PNGAPI
  174804. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174805. png_uint_32 user_height_max)
  174806. {
  174807. if(png_ptr == NULL) return;
  174808. png_ptr->user_width_max = user_width_max;
  174809. png_ptr->user_height_max = user_height_max;
  174810. }
  174811. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174812. #endif /* ?PNG_1_0_X */
  174813. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174814. /*** End of inlined file: pngset.c ***/
  174815. /*** Start of inlined file: pngtrans.c ***/
  174816. #define PNG_INTERNAL
  174817. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174818. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174819. void PNGAPI
  174820. png_set_bgr(png_structp png_ptr)
  174821. {
  174822. png_debug(1, "in png_set_bgr\n");
  174823. if(png_ptr == NULL) return;
  174824. png_ptr->transformations |= PNG_BGR;
  174825. }
  174826. #endif
  174827. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174828. void PNGAPI
  174829. png_set_swap(png_structp png_ptr)
  174830. {
  174831. png_debug(1, "in png_set_swap\n");
  174832. if(png_ptr == NULL) return;
  174833. if (png_ptr->bit_depth == 16)
  174834. png_ptr->transformations |= PNG_SWAP_BYTES;
  174835. }
  174836. #endif
  174837. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174838. void PNGAPI
  174839. png_set_packing(png_structp png_ptr)
  174840. {
  174841. png_debug(1, "in png_set_packing\n");
  174842. if(png_ptr == NULL) return;
  174843. if (png_ptr->bit_depth < 8)
  174844. {
  174845. png_ptr->transformations |= PNG_PACK;
  174846. png_ptr->usr_bit_depth = 8;
  174847. }
  174848. }
  174849. #endif
  174850. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174851. void PNGAPI
  174852. png_set_packswap(png_structp png_ptr)
  174853. {
  174854. png_debug(1, "in png_set_packswap\n");
  174855. if(png_ptr == NULL) return;
  174856. if (png_ptr->bit_depth < 8)
  174857. png_ptr->transformations |= PNG_PACKSWAP;
  174858. }
  174859. #endif
  174860. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174861. void PNGAPI
  174862. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174863. {
  174864. png_debug(1, "in png_set_shift\n");
  174865. if(png_ptr == NULL) return;
  174866. png_ptr->transformations |= PNG_SHIFT;
  174867. png_ptr->shift = *true_bits;
  174868. }
  174869. #endif
  174870. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174871. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174872. int PNGAPI
  174873. png_set_interlace_handling(png_structp png_ptr)
  174874. {
  174875. png_debug(1, "in png_set_interlace handling\n");
  174876. if (png_ptr && png_ptr->interlaced)
  174877. {
  174878. png_ptr->transformations |= PNG_INTERLACE;
  174879. return (7);
  174880. }
  174881. return (1);
  174882. }
  174883. #endif
  174884. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174885. void PNGAPI
  174886. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174887. {
  174888. png_debug(1, "in png_set_filler\n");
  174889. if(png_ptr == NULL) return;
  174890. png_ptr->transformations |= PNG_FILLER;
  174891. png_ptr->filler = (png_byte)filler;
  174892. if (filler_loc == PNG_FILLER_AFTER)
  174893. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174894. else
  174895. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174896. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174897. {
  174898. png_ptr->usr_channels = 4;
  174899. }
  174900. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174901. {
  174902. png_ptr->usr_channels = 2;
  174903. }
  174904. }
  174905. #if !defined(PNG_1_0_X)
  174906. void PNGAPI
  174907. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174908. {
  174909. png_debug(1, "in png_set_add_alpha\n");
  174910. if(png_ptr == NULL) return;
  174911. png_set_filler(png_ptr, filler, filler_loc);
  174912. png_ptr->transformations |= PNG_ADD_ALPHA;
  174913. }
  174914. #endif
  174915. #endif
  174916. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174917. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174918. void PNGAPI
  174919. png_set_swap_alpha(png_structp png_ptr)
  174920. {
  174921. png_debug(1, "in png_set_swap_alpha\n");
  174922. if(png_ptr == NULL) return;
  174923. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174924. }
  174925. #endif
  174926. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174927. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174928. void PNGAPI
  174929. png_set_invert_alpha(png_structp png_ptr)
  174930. {
  174931. png_debug(1, "in png_set_invert_alpha\n");
  174932. if(png_ptr == NULL) return;
  174933. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174934. }
  174935. #endif
  174936. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174937. void PNGAPI
  174938. png_set_invert_mono(png_structp png_ptr)
  174939. {
  174940. png_debug(1, "in png_set_invert_mono\n");
  174941. if(png_ptr == NULL) return;
  174942. png_ptr->transformations |= PNG_INVERT_MONO;
  174943. }
  174944. void /* PRIVATE */
  174945. png_do_invert(png_row_infop row_info, png_bytep row)
  174946. {
  174947. png_debug(1, "in png_do_invert\n");
  174948. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174949. if (row == NULL || row_info == NULL)
  174950. return;
  174951. #endif
  174952. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174953. {
  174954. png_bytep rp = row;
  174955. png_uint_32 i;
  174956. png_uint_32 istop = row_info->rowbytes;
  174957. for (i = 0; i < istop; i++)
  174958. {
  174959. *rp = (png_byte)(~(*rp));
  174960. rp++;
  174961. }
  174962. }
  174963. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174964. row_info->bit_depth == 8)
  174965. {
  174966. png_bytep rp = row;
  174967. png_uint_32 i;
  174968. png_uint_32 istop = row_info->rowbytes;
  174969. for (i = 0; i < istop; i+=2)
  174970. {
  174971. *rp = (png_byte)(~(*rp));
  174972. rp+=2;
  174973. }
  174974. }
  174975. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174976. row_info->bit_depth == 16)
  174977. {
  174978. png_bytep rp = row;
  174979. png_uint_32 i;
  174980. png_uint_32 istop = row_info->rowbytes;
  174981. for (i = 0; i < istop; i+=4)
  174982. {
  174983. *rp = (png_byte)(~(*rp));
  174984. *(rp+1) = (png_byte)(~(*(rp+1)));
  174985. rp+=4;
  174986. }
  174987. }
  174988. }
  174989. #endif
  174990. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174991. void /* PRIVATE */
  174992. png_do_swap(png_row_infop row_info, png_bytep row)
  174993. {
  174994. png_debug(1, "in png_do_swap\n");
  174995. if (
  174996. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174997. row != NULL && row_info != NULL &&
  174998. #endif
  174999. row_info->bit_depth == 16)
  175000. {
  175001. png_bytep rp = row;
  175002. png_uint_32 i;
  175003. png_uint_32 istop= row_info->width * row_info->channels;
  175004. for (i = 0; i < istop; i++, rp += 2)
  175005. {
  175006. png_byte t = *rp;
  175007. *rp = *(rp + 1);
  175008. *(rp + 1) = t;
  175009. }
  175010. }
  175011. }
  175012. #endif
  175013. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  175014. static PNG_CONST png_byte onebppswaptable[256] = {
  175015. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  175016. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  175017. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  175018. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  175019. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  175020. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  175021. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  175022. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  175023. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  175024. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  175025. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  175026. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  175027. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  175028. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  175029. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  175030. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  175031. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  175032. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  175033. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  175034. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  175035. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  175036. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  175037. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  175038. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  175039. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  175040. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  175041. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  175042. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  175043. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  175044. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  175045. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  175046. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  175047. };
  175048. static PNG_CONST png_byte twobppswaptable[256] = {
  175049. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  175050. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  175051. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  175052. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  175053. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  175054. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  175055. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  175056. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  175057. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  175058. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  175059. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  175060. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  175061. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  175062. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  175063. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  175064. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  175065. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  175066. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  175067. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  175068. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  175069. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  175070. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  175071. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  175072. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  175073. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  175074. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  175075. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  175076. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  175077. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  175078. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  175079. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  175080. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  175081. };
  175082. static PNG_CONST png_byte fourbppswaptable[256] = {
  175083. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  175084. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  175085. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  175086. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  175087. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  175088. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  175089. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  175090. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  175091. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  175092. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  175093. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  175094. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  175095. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  175096. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175097. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175098. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175099. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175100. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175101. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175102. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175103. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175104. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175105. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175106. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175107. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175108. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175109. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175110. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175111. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175112. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175113. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175114. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175115. };
  175116. void /* PRIVATE */
  175117. png_do_packswap(png_row_infop row_info, png_bytep row)
  175118. {
  175119. png_debug(1, "in png_do_packswap\n");
  175120. if (
  175121. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175122. row != NULL && row_info != NULL &&
  175123. #endif
  175124. row_info->bit_depth < 8)
  175125. {
  175126. png_bytep rp, end, table;
  175127. end = row + row_info->rowbytes;
  175128. if (row_info->bit_depth == 1)
  175129. table = (png_bytep)onebppswaptable;
  175130. else if (row_info->bit_depth == 2)
  175131. table = (png_bytep)twobppswaptable;
  175132. else if (row_info->bit_depth == 4)
  175133. table = (png_bytep)fourbppswaptable;
  175134. else
  175135. return;
  175136. for (rp = row; rp < end; rp++)
  175137. *rp = table[*rp];
  175138. }
  175139. }
  175140. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175141. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175142. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175143. void /* PRIVATE */
  175144. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175145. {
  175146. png_debug(1, "in png_do_strip_filler\n");
  175147. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175148. if (row != NULL && row_info != NULL)
  175149. #endif
  175150. {
  175151. png_bytep sp=row;
  175152. png_bytep dp=row;
  175153. png_uint_32 row_width=row_info->width;
  175154. png_uint_32 i;
  175155. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175156. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175157. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175158. row_info->channels == 4)
  175159. {
  175160. if (row_info->bit_depth == 8)
  175161. {
  175162. if (flags & PNG_FLAG_FILLER_AFTER)
  175163. {
  175164. dp+=3; sp+=4;
  175165. for (i = 1; i < row_width; i++)
  175166. {
  175167. *dp++ = *sp++;
  175168. *dp++ = *sp++;
  175169. *dp++ = *sp++;
  175170. sp++;
  175171. }
  175172. }
  175173. else
  175174. {
  175175. for (i = 0; i < row_width; i++)
  175176. {
  175177. sp++;
  175178. *dp++ = *sp++;
  175179. *dp++ = *sp++;
  175180. *dp++ = *sp++;
  175181. }
  175182. }
  175183. row_info->pixel_depth = 24;
  175184. row_info->rowbytes = row_width * 3;
  175185. }
  175186. else /* if (row_info->bit_depth == 16) */
  175187. {
  175188. if (flags & PNG_FLAG_FILLER_AFTER)
  175189. {
  175190. sp += 8; dp += 6;
  175191. for (i = 1; i < row_width; i++)
  175192. {
  175193. *dp++ = *sp++;
  175194. *dp++ = *sp++;
  175195. *dp++ = *sp++;
  175196. *dp++ = *sp++;
  175197. *dp++ = *sp++;
  175198. *dp++ = *sp++;
  175199. sp += 2;
  175200. }
  175201. }
  175202. else
  175203. {
  175204. for (i = 0; i < row_width; i++)
  175205. {
  175206. sp+=2;
  175207. *dp++ = *sp++;
  175208. *dp++ = *sp++;
  175209. *dp++ = *sp++;
  175210. *dp++ = *sp++;
  175211. *dp++ = *sp++;
  175212. *dp++ = *sp++;
  175213. }
  175214. }
  175215. row_info->pixel_depth = 48;
  175216. row_info->rowbytes = row_width * 6;
  175217. }
  175218. row_info->channels = 3;
  175219. }
  175220. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175221. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175222. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175223. row_info->channels == 2)
  175224. {
  175225. if (row_info->bit_depth == 8)
  175226. {
  175227. if (flags & PNG_FLAG_FILLER_AFTER)
  175228. {
  175229. for (i = 0; i < row_width; i++)
  175230. {
  175231. *dp++ = *sp++;
  175232. sp++;
  175233. }
  175234. }
  175235. else
  175236. {
  175237. for (i = 0; i < row_width; i++)
  175238. {
  175239. sp++;
  175240. *dp++ = *sp++;
  175241. }
  175242. }
  175243. row_info->pixel_depth = 8;
  175244. row_info->rowbytes = row_width;
  175245. }
  175246. else /* if (row_info->bit_depth == 16) */
  175247. {
  175248. if (flags & PNG_FLAG_FILLER_AFTER)
  175249. {
  175250. sp += 4; dp += 2;
  175251. for (i = 1; i < row_width; i++)
  175252. {
  175253. *dp++ = *sp++;
  175254. *dp++ = *sp++;
  175255. sp += 2;
  175256. }
  175257. }
  175258. else
  175259. {
  175260. for (i = 0; i < row_width; i++)
  175261. {
  175262. sp += 2;
  175263. *dp++ = *sp++;
  175264. *dp++ = *sp++;
  175265. }
  175266. }
  175267. row_info->pixel_depth = 16;
  175268. row_info->rowbytes = row_width * 2;
  175269. }
  175270. row_info->channels = 1;
  175271. }
  175272. if (flags & PNG_FLAG_STRIP_ALPHA)
  175273. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175274. }
  175275. }
  175276. #endif
  175277. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175278. void /* PRIVATE */
  175279. png_do_bgr(png_row_infop row_info, png_bytep row)
  175280. {
  175281. png_debug(1, "in png_do_bgr\n");
  175282. if (
  175283. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175284. row != NULL && row_info != NULL &&
  175285. #endif
  175286. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175287. {
  175288. png_uint_32 row_width = row_info->width;
  175289. if (row_info->bit_depth == 8)
  175290. {
  175291. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175292. {
  175293. png_bytep rp;
  175294. png_uint_32 i;
  175295. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175296. {
  175297. png_byte save = *rp;
  175298. *rp = *(rp + 2);
  175299. *(rp + 2) = save;
  175300. }
  175301. }
  175302. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175303. {
  175304. png_bytep rp;
  175305. png_uint_32 i;
  175306. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175307. {
  175308. png_byte save = *rp;
  175309. *rp = *(rp + 2);
  175310. *(rp + 2) = save;
  175311. }
  175312. }
  175313. }
  175314. else if (row_info->bit_depth == 16)
  175315. {
  175316. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175317. {
  175318. png_bytep rp;
  175319. png_uint_32 i;
  175320. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175321. {
  175322. png_byte save = *rp;
  175323. *rp = *(rp + 4);
  175324. *(rp + 4) = save;
  175325. save = *(rp + 1);
  175326. *(rp + 1) = *(rp + 5);
  175327. *(rp + 5) = save;
  175328. }
  175329. }
  175330. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175331. {
  175332. png_bytep rp;
  175333. png_uint_32 i;
  175334. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175335. {
  175336. png_byte save = *rp;
  175337. *rp = *(rp + 4);
  175338. *(rp + 4) = save;
  175339. save = *(rp + 1);
  175340. *(rp + 1) = *(rp + 5);
  175341. *(rp + 5) = save;
  175342. }
  175343. }
  175344. }
  175345. }
  175346. }
  175347. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175348. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175349. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175350. defined(PNG_LEGACY_SUPPORTED)
  175351. void PNGAPI
  175352. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175353. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175354. {
  175355. png_debug(1, "in png_set_user_transform_info\n");
  175356. if(png_ptr == NULL) return;
  175357. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175358. png_ptr->user_transform_ptr = user_transform_ptr;
  175359. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175360. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175361. #else
  175362. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175363. png_warning(png_ptr,
  175364. "This version of libpng does not support user transform info");
  175365. #endif
  175366. }
  175367. #endif
  175368. png_voidp PNGAPI
  175369. png_get_user_transform_ptr(png_structp png_ptr)
  175370. {
  175371. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175372. if (png_ptr == NULL) return (NULL);
  175373. return ((png_voidp)png_ptr->user_transform_ptr);
  175374. #else
  175375. return (NULL);
  175376. #endif
  175377. }
  175378. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175379. /*** End of inlined file: pngtrans.c ***/
  175380. /*** Start of inlined file: pngwio.c ***/
  175381. #define PNG_INTERNAL
  175382. #ifdef PNG_WRITE_SUPPORTED
  175383. void /* PRIVATE */
  175384. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175385. {
  175386. if (png_ptr->write_data_fn != NULL )
  175387. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175388. else
  175389. png_error(png_ptr, "Call to NULL write function");
  175390. }
  175391. #if !defined(PNG_NO_STDIO)
  175392. #ifndef USE_FAR_KEYWORD
  175393. void PNGAPI
  175394. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175395. {
  175396. png_uint_32 check;
  175397. if(png_ptr == NULL) return;
  175398. #if defined(_WIN32_WCE)
  175399. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175400. check = 0;
  175401. #else
  175402. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175403. #endif
  175404. if (check != length)
  175405. png_error(png_ptr, "Write Error");
  175406. }
  175407. #else
  175408. #define NEAR_BUF_SIZE 1024
  175409. #define MIN(a,b) (a <= b ? a : b)
  175410. void PNGAPI
  175411. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175412. {
  175413. png_uint_32 check;
  175414. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175415. png_FILE_p io_ptr;
  175416. if(png_ptr == NULL) return;
  175417. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175418. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175419. if ((png_bytep)near_data == data)
  175420. {
  175421. #if defined(_WIN32_WCE)
  175422. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175423. check = 0;
  175424. #else
  175425. check = fwrite(near_data, 1, length, io_ptr);
  175426. #endif
  175427. }
  175428. else
  175429. {
  175430. png_byte buf[NEAR_BUF_SIZE];
  175431. png_size_t written, remaining, err;
  175432. check = 0;
  175433. remaining = length;
  175434. do
  175435. {
  175436. written = MIN(NEAR_BUF_SIZE, remaining);
  175437. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175438. #if defined(_WIN32_WCE)
  175439. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175440. err = 0;
  175441. #else
  175442. err = fwrite(buf, 1, written, io_ptr);
  175443. #endif
  175444. if (err != written)
  175445. break;
  175446. else
  175447. check += err;
  175448. data += written;
  175449. remaining -= written;
  175450. }
  175451. while (remaining != 0);
  175452. }
  175453. if (check != length)
  175454. png_error(png_ptr, "Write Error");
  175455. }
  175456. #endif
  175457. #endif
  175458. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175459. void /* PRIVATE */
  175460. png_flush(png_structp png_ptr)
  175461. {
  175462. if (png_ptr->output_flush_fn != NULL)
  175463. (*(png_ptr->output_flush_fn))(png_ptr);
  175464. }
  175465. #if !defined(PNG_NO_STDIO)
  175466. void PNGAPI
  175467. png_default_flush(png_structp png_ptr)
  175468. {
  175469. #if !defined(_WIN32_WCE)
  175470. png_FILE_p io_ptr;
  175471. #endif
  175472. if(png_ptr == NULL) return;
  175473. #if !defined(_WIN32_WCE)
  175474. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175475. if (io_ptr != NULL)
  175476. fflush(io_ptr);
  175477. #endif
  175478. }
  175479. #endif
  175480. #endif
  175481. void PNGAPI
  175482. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175483. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175484. {
  175485. if(png_ptr == NULL) return;
  175486. png_ptr->io_ptr = io_ptr;
  175487. #if !defined(PNG_NO_STDIO)
  175488. if (write_data_fn != NULL)
  175489. png_ptr->write_data_fn = write_data_fn;
  175490. else
  175491. png_ptr->write_data_fn = png_default_write_data;
  175492. #else
  175493. png_ptr->write_data_fn = write_data_fn;
  175494. #endif
  175495. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175496. #if !defined(PNG_NO_STDIO)
  175497. if (output_flush_fn != NULL)
  175498. png_ptr->output_flush_fn = output_flush_fn;
  175499. else
  175500. png_ptr->output_flush_fn = png_default_flush;
  175501. #else
  175502. png_ptr->output_flush_fn = output_flush_fn;
  175503. #endif
  175504. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175505. if (png_ptr->read_data_fn != NULL)
  175506. {
  175507. png_ptr->read_data_fn = NULL;
  175508. png_warning(png_ptr,
  175509. "Attempted to set both read_data_fn and write_data_fn in");
  175510. png_warning(png_ptr,
  175511. "the same structure. Resetting read_data_fn to NULL.");
  175512. }
  175513. }
  175514. #if defined(USE_FAR_KEYWORD)
  175515. #if defined(_MSC_VER)
  175516. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175517. {
  175518. void *near_ptr;
  175519. void FAR *far_ptr;
  175520. FP_OFF(near_ptr) = FP_OFF(ptr);
  175521. far_ptr = (void FAR *)near_ptr;
  175522. if(check != 0)
  175523. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175524. png_error(png_ptr,"segment lost in conversion");
  175525. return(near_ptr);
  175526. }
  175527. # else
  175528. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175529. {
  175530. void *near_ptr;
  175531. void FAR *far_ptr;
  175532. near_ptr = (void FAR *)ptr;
  175533. far_ptr = (void FAR *)near_ptr;
  175534. if(check != 0)
  175535. if(far_ptr != ptr)
  175536. png_error(png_ptr,"segment lost in conversion");
  175537. return(near_ptr);
  175538. }
  175539. # endif
  175540. # endif
  175541. #endif /* PNG_WRITE_SUPPORTED */
  175542. /*** End of inlined file: pngwio.c ***/
  175543. /*** Start of inlined file: pngwrite.c ***/
  175544. #define PNG_INTERNAL
  175545. #ifdef PNG_WRITE_SUPPORTED
  175546. void PNGAPI
  175547. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175548. {
  175549. png_debug(1, "in png_write_info_before_PLTE\n");
  175550. if (png_ptr == NULL || info_ptr == NULL)
  175551. return;
  175552. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175553. {
  175554. png_write_sig(png_ptr); /* write PNG signature */
  175555. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175556. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175557. {
  175558. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175559. png_ptr->mng_features_permitted=0;
  175560. }
  175561. #endif
  175562. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175563. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175564. info_ptr->filter_type,
  175565. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175566. info_ptr->interlace_type);
  175567. #else
  175568. 0);
  175569. #endif
  175570. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175571. if (info_ptr->valid & PNG_INFO_gAMA)
  175572. {
  175573. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175574. png_write_gAMA(png_ptr, info_ptr->gamma);
  175575. #else
  175576. #ifdef PNG_FIXED_POINT_SUPPORTED
  175577. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175578. # endif
  175579. #endif
  175580. }
  175581. #endif
  175582. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175583. if (info_ptr->valid & PNG_INFO_sRGB)
  175584. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175585. #endif
  175586. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175587. if (info_ptr->valid & PNG_INFO_iCCP)
  175588. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175589. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175590. #endif
  175591. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175592. if (info_ptr->valid & PNG_INFO_sBIT)
  175593. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175594. #endif
  175595. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175596. if (info_ptr->valid & PNG_INFO_cHRM)
  175597. {
  175598. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175599. png_write_cHRM(png_ptr,
  175600. info_ptr->x_white, info_ptr->y_white,
  175601. info_ptr->x_red, info_ptr->y_red,
  175602. info_ptr->x_green, info_ptr->y_green,
  175603. info_ptr->x_blue, info_ptr->y_blue);
  175604. #else
  175605. # ifdef PNG_FIXED_POINT_SUPPORTED
  175606. png_write_cHRM_fixed(png_ptr,
  175607. info_ptr->int_x_white, info_ptr->int_y_white,
  175608. info_ptr->int_x_red, info_ptr->int_y_red,
  175609. info_ptr->int_x_green, info_ptr->int_y_green,
  175610. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175611. # endif
  175612. #endif
  175613. }
  175614. #endif
  175615. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175616. if (info_ptr->unknown_chunks_num)
  175617. {
  175618. png_unknown_chunk *up;
  175619. png_debug(5, "writing extra chunks\n");
  175620. for (up = info_ptr->unknown_chunks;
  175621. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175622. up++)
  175623. {
  175624. int keep=png_handle_as_unknown(png_ptr, up->name);
  175625. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175626. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175627. !(up->location & PNG_HAVE_IDAT) &&
  175628. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175629. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175630. {
  175631. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175632. }
  175633. }
  175634. }
  175635. #endif
  175636. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175637. }
  175638. }
  175639. void PNGAPI
  175640. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175641. {
  175642. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175643. int i;
  175644. #endif
  175645. png_debug(1, "in png_write_info\n");
  175646. if (png_ptr == NULL || info_ptr == NULL)
  175647. return;
  175648. png_write_info_before_PLTE(png_ptr, info_ptr);
  175649. if (info_ptr->valid & PNG_INFO_PLTE)
  175650. png_write_PLTE(png_ptr, info_ptr->palette,
  175651. (png_uint_32)info_ptr->num_palette);
  175652. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175653. png_error(png_ptr, "Valid palette required for paletted images");
  175654. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175655. if (info_ptr->valid & PNG_INFO_tRNS)
  175656. {
  175657. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175658. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175659. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175660. {
  175661. int j;
  175662. for (j=0; j<(int)info_ptr->num_trans; j++)
  175663. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175664. }
  175665. #endif
  175666. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175667. info_ptr->num_trans, info_ptr->color_type);
  175668. }
  175669. #endif
  175670. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175671. if (info_ptr->valid & PNG_INFO_bKGD)
  175672. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175673. #endif
  175674. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175675. if (info_ptr->valid & PNG_INFO_hIST)
  175676. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175677. #endif
  175678. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175679. if (info_ptr->valid & PNG_INFO_oFFs)
  175680. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175681. info_ptr->offset_unit_type);
  175682. #endif
  175683. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175684. if (info_ptr->valid & PNG_INFO_pCAL)
  175685. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175686. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175687. info_ptr->pcal_units, info_ptr->pcal_params);
  175688. #endif
  175689. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175690. if (info_ptr->valid & PNG_INFO_sCAL)
  175691. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175692. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175693. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175694. #else
  175695. #ifdef PNG_FIXED_POINT_SUPPORTED
  175696. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175697. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175698. #else
  175699. png_warning(png_ptr,
  175700. "png_write_sCAL not supported; sCAL chunk not written.");
  175701. #endif
  175702. #endif
  175703. #endif
  175704. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175705. if (info_ptr->valid & PNG_INFO_pHYs)
  175706. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175707. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175708. #endif
  175709. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175710. if (info_ptr->valid & PNG_INFO_tIME)
  175711. {
  175712. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175713. png_ptr->mode |= PNG_WROTE_tIME;
  175714. }
  175715. #endif
  175716. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175717. if (info_ptr->valid & PNG_INFO_sPLT)
  175718. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175719. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175720. #endif
  175721. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175722. for (i = 0; i < info_ptr->num_text; i++)
  175723. {
  175724. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175725. info_ptr->text[i].compression);
  175726. if (info_ptr->text[i].compression > 0)
  175727. {
  175728. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175729. png_write_iTXt(png_ptr,
  175730. info_ptr->text[i].compression,
  175731. info_ptr->text[i].key,
  175732. info_ptr->text[i].lang,
  175733. info_ptr->text[i].lang_key,
  175734. info_ptr->text[i].text);
  175735. #else
  175736. png_warning(png_ptr, "Unable to write international text");
  175737. #endif
  175738. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175739. }
  175740. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175741. {
  175742. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175743. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175744. info_ptr->text[i].text, 0,
  175745. info_ptr->text[i].compression);
  175746. #else
  175747. png_warning(png_ptr, "Unable to write compressed text");
  175748. #endif
  175749. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175750. }
  175751. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175752. {
  175753. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175754. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175755. info_ptr->text[i].text,
  175756. 0);
  175757. #else
  175758. png_warning(png_ptr, "Unable to write uncompressed text");
  175759. #endif
  175760. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175761. }
  175762. }
  175763. #endif
  175764. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175765. if (info_ptr->unknown_chunks_num)
  175766. {
  175767. png_unknown_chunk *up;
  175768. png_debug(5, "writing extra chunks\n");
  175769. for (up = info_ptr->unknown_chunks;
  175770. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175771. up++)
  175772. {
  175773. int keep=png_handle_as_unknown(png_ptr, up->name);
  175774. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175775. up->location && (up->location & PNG_HAVE_PLTE) &&
  175776. !(up->location & PNG_HAVE_IDAT) &&
  175777. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175778. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175779. {
  175780. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175781. }
  175782. }
  175783. }
  175784. #endif
  175785. }
  175786. void PNGAPI
  175787. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175788. {
  175789. png_debug(1, "in png_write_end\n");
  175790. if (png_ptr == NULL)
  175791. return;
  175792. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175793. png_error(png_ptr, "No IDATs written into file");
  175794. if (info_ptr != NULL)
  175795. {
  175796. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175797. int i; /* local index variable */
  175798. #endif
  175799. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175800. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175801. !(png_ptr->mode & PNG_WROTE_tIME))
  175802. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175803. #endif
  175804. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175805. for (i = 0; i < info_ptr->num_text; i++)
  175806. {
  175807. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175808. info_ptr->text[i].compression);
  175809. if (info_ptr->text[i].compression > 0)
  175810. {
  175811. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175812. png_write_iTXt(png_ptr,
  175813. info_ptr->text[i].compression,
  175814. info_ptr->text[i].key,
  175815. info_ptr->text[i].lang,
  175816. info_ptr->text[i].lang_key,
  175817. info_ptr->text[i].text);
  175818. #else
  175819. png_warning(png_ptr, "Unable to write international text");
  175820. #endif
  175821. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175822. }
  175823. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175824. {
  175825. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175826. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175827. info_ptr->text[i].text, 0,
  175828. info_ptr->text[i].compression);
  175829. #else
  175830. png_warning(png_ptr, "Unable to write compressed text");
  175831. #endif
  175832. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175833. }
  175834. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175835. {
  175836. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175837. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175838. info_ptr->text[i].text, 0);
  175839. #else
  175840. png_warning(png_ptr, "Unable to write uncompressed text");
  175841. #endif
  175842. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175843. }
  175844. }
  175845. #endif
  175846. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175847. if (info_ptr->unknown_chunks_num)
  175848. {
  175849. png_unknown_chunk *up;
  175850. png_debug(5, "writing extra chunks\n");
  175851. for (up = info_ptr->unknown_chunks;
  175852. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175853. up++)
  175854. {
  175855. int keep=png_handle_as_unknown(png_ptr, up->name);
  175856. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175857. up->location && (up->location & PNG_AFTER_IDAT) &&
  175858. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175859. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175860. {
  175861. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175862. }
  175863. }
  175864. }
  175865. #endif
  175866. }
  175867. png_ptr->mode |= PNG_AFTER_IDAT;
  175868. png_write_IEND(png_ptr);
  175869. }
  175870. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175871. #if !defined(_WIN32_WCE)
  175872. void PNGAPI
  175873. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175874. {
  175875. png_debug(1, "in png_convert_from_struct_tm\n");
  175876. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175877. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175878. ptime->day = (png_byte)ttime->tm_mday;
  175879. ptime->hour = (png_byte)ttime->tm_hour;
  175880. ptime->minute = (png_byte)ttime->tm_min;
  175881. ptime->second = (png_byte)ttime->tm_sec;
  175882. }
  175883. void PNGAPI
  175884. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175885. {
  175886. struct tm *tbuf;
  175887. png_debug(1, "in png_convert_from_time_t\n");
  175888. tbuf = gmtime(&ttime);
  175889. png_convert_from_struct_tm(ptime, tbuf);
  175890. }
  175891. #endif
  175892. #endif
  175893. png_structp PNGAPI
  175894. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175895. png_error_ptr error_fn, png_error_ptr warn_fn)
  175896. {
  175897. #ifdef PNG_USER_MEM_SUPPORTED
  175898. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175899. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175900. }
  175901. png_structp PNGAPI
  175902. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175903. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175904. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175905. {
  175906. #endif /* PNG_USER_MEM_SUPPORTED */
  175907. png_structp png_ptr;
  175908. #ifdef PNG_SETJMP_SUPPORTED
  175909. #ifdef USE_FAR_KEYWORD
  175910. jmp_buf jmpbuf;
  175911. #endif
  175912. #endif
  175913. int i;
  175914. png_debug(1, "in png_create_write_struct\n");
  175915. #ifdef PNG_USER_MEM_SUPPORTED
  175916. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175917. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175918. #else
  175919. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175920. #endif /* PNG_USER_MEM_SUPPORTED */
  175921. if (png_ptr == NULL)
  175922. return (NULL);
  175923. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175924. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175925. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175926. #endif
  175927. #ifdef PNG_SETJMP_SUPPORTED
  175928. #ifdef USE_FAR_KEYWORD
  175929. if (setjmp(jmpbuf))
  175930. #else
  175931. if (setjmp(png_ptr->jmpbuf))
  175932. #endif
  175933. {
  175934. png_free(png_ptr, png_ptr->zbuf);
  175935. png_ptr->zbuf=NULL;
  175936. png_destroy_struct(png_ptr);
  175937. return (NULL);
  175938. }
  175939. #ifdef USE_FAR_KEYWORD
  175940. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175941. #endif
  175942. #endif
  175943. #ifdef PNG_USER_MEM_SUPPORTED
  175944. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175945. #endif /* PNG_USER_MEM_SUPPORTED */
  175946. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175947. i=0;
  175948. do
  175949. {
  175950. if(user_png_ver[i] != png_libpng_ver[i])
  175951. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175952. } while (png_libpng_ver[i++]);
  175953. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175954. {
  175955. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175956. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175957. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175958. {
  175959. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175960. char msg[80];
  175961. if (user_png_ver)
  175962. {
  175963. png_snprintf(msg, 80,
  175964. "Application was compiled with png.h from libpng-%.20s",
  175965. user_png_ver);
  175966. png_warning(png_ptr, msg);
  175967. }
  175968. png_snprintf(msg, 80,
  175969. "Application is running with png.c from libpng-%.20s",
  175970. png_libpng_ver);
  175971. png_warning(png_ptr, msg);
  175972. #endif
  175973. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175974. png_ptr->flags=0;
  175975. #endif
  175976. png_error(png_ptr,
  175977. "Incompatible libpng version in application and library");
  175978. }
  175979. }
  175980. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175981. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175982. (png_uint_32)png_ptr->zbuf_size);
  175983. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175984. png_flush_ptr_NULL);
  175985. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175986. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175987. 1, png_doublep_NULL, png_doublep_NULL);
  175988. #endif
  175989. #ifdef PNG_SETJMP_SUPPORTED
  175990. #ifdef USE_FAR_KEYWORD
  175991. if (setjmp(jmpbuf))
  175992. PNG_ABORT();
  175993. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175994. #else
  175995. if (setjmp(png_ptr->jmpbuf))
  175996. PNG_ABORT();
  175997. #endif
  175998. #endif
  175999. return (png_ptr);
  176000. }
  176001. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  176002. #undef png_write_init
  176003. void PNGAPI
  176004. png_write_init(png_structp png_ptr)
  176005. {
  176006. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  176007. }
  176008. void PNGAPI
  176009. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  176010. png_size_t png_struct_size, png_size_t png_info_size)
  176011. {
  176012. if(png_ptr == NULL) return;
  176013. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176014. if(png_sizeof(png_struct) > png_struct_size ||
  176015. png_sizeof(png_info) > png_info_size)
  176016. {
  176017. char msg[80];
  176018. png_ptr->warning_fn=NULL;
  176019. if (user_png_ver)
  176020. {
  176021. png_snprintf(msg, 80,
  176022. "Application was compiled with png.h from libpng-%.20s",
  176023. user_png_ver);
  176024. png_warning(png_ptr, msg);
  176025. }
  176026. png_snprintf(msg, 80,
  176027. "Application is running with png.c from libpng-%.20s",
  176028. png_libpng_ver);
  176029. png_warning(png_ptr, msg);
  176030. }
  176031. #endif
  176032. if(png_sizeof(png_struct) > png_struct_size)
  176033. {
  176034. png_ptr->error_fn=NULL;
  176035. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176036. png_ptr->flags=0;
  176037. #endif
  176038. png_error(png_ptr,
  176039. "The png struct allocated by the application for writing is too small.");
  176040. }
  176041. if(png_sizeof(png_info) > png_info_size)
  176042. {
  176043. png_ptr->error_fn=NULL;
  176044. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176045. png_ptr->flags=0;
  176046. #endif
  176047. png_error(png_ptr,
  176048. "The info struct allocated by the application for writing is too small.");
  176049. }
  176050. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  176051. }
  176052. #endif /* PNG_1_0_X || PNG_1_2_X */
  176053. void PNGAPI
  176054. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  176055. png_size_t png_struct_size)
  176056. {
  176057. png_structp png_ptr=*ptr_ptr;
  176058. #ifdef PNG_SETJMP_SUPPORTED
  176059. jmp_buf tmp_jmp; /* to save current jump buffer */
  176060. #endif
  176061. int i = 0;
  176062. if (png_ptr == NULL)
  176063. return;
  176064. do
  176065. {
  176066. if (user_png_ver[i] != png_libpng_ver[i])
  176067. {
  176068. #ifdef PNG_LEGACY_SUPPORTED
  176069. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176070. #else
  176071. png_ptr->warning_fn=NULL;
  176072. png_warning(png_ptr,
  176073. "Application uses deprecated png_write_init() and should be recompiled.");
  176074. break;
  176075. #endif
  176076. }
  176077. } while (png_libpng_ver[i++]);
  176078. png_debug(1, "in png_write_init_3\n");
  176079. #ifdef PNG_SETJMP_SUPPORTED
  176080. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176081. #endif
  176082. if (png_sizeof(png_struct) > png_struct_size)
  176083. {
  176084. png_destroy_struct(png_ptr);
  176085. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176086. *ptr_ptr = png_ptr;
  176087. }
  176088. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176089. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176090. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176091. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176092. #endif
  176093. #ifdef PNG_SETJMP_SUPPORTED
  176094. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176095. #endif
  176096. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176097. png_flush_ptr_NULL);
  176098. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176099. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176100. (png_uint_32)png_ptr->zbuf_size);
  176101. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176102. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176103. 1, png_doublep_NULL, png_doublep_NULL);
  176104. #endif
  176105. }
  176106. void PNGAPI
  176107. png_write_rows(png_structp png_ptr, png_bytepp row,
  176108. png_uint_32 num_rows)
  176109. {
  176110. png_uint_32 i; /* row counter */
  176111. png_bytepp rp; /* row pointer */
  176112. png_debug(1, "in png_write_rows\n");
  176113. if (png_ptr == NULL)
  176114. return;
  176115. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176116. {
  176117. png_write_row(png_ptr, *rp);
  176118. }
  176119. }
  176120. void PNGAPI
  176121. png_write_image(png_structp png_ptr, png_bytepp image)
  176122. {
  176123. png_uint_32 i; /* row index */
  176124. int pass, num_pass; /* pass variables */
  176125. png_bytepp rp; /* points to current row */
  176126. if (png_ptr == NULL)
  176127. return;
  176128. png_debug(1, "in png_write_image\n");
  176129. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176130. num_pass = png_set_interlace_handling(png_ptr);
  176131. #else
  176132. num_pass = 1;
  176133. #endif
  176134. for (pass = 0; pass < num_pass; pass++)
  176135. {
  176136. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176137. {
  176138. png_write_row(png_ptr, *rp);
  176139. }
  176140. }
  176141. }
  176142. void PNGAPI
  176143. png_write_row(png_structp png_ptr, png_bytep row)
  176144. {
  176145. if (png_ptr == NULL)
  176146. return;
  176147. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176148. png_ptr->row_number, png_ptr->pass);
  176149. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176150. {
  176151. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176152. png_error(png_ptr,
  176153. "png_write_info was never called before png_write_row.");
  176154. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176155. if (png_ptr->transformations & PNG_INVERT_MONO)
  176156. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176157. #endif
  176158. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176159. if (png_ptr->transformations & PNG_FILLER)
  176160. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176161. #endif
  176162. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176163. if (png_ptr->transformations & PNG_PACKSWAP)
  176164. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176165. #endif
  176166. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176167. if (png_ptr->transformations & PNG_PACK)
  176168. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176169. #endif
  176170. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176171. if (png_ptr->transformations & PNG_SHIFT)
  176172. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176173. #endif
  176174. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176175. if (png_ptr->transformations & PNG_BGR)
  176176. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176177. #endif
  176178. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176179. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176180. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176181. #endif
  176182. png_write_start_row(png_ptr);
  176183. }
  176184. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176185. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176186. {
  176187. switch (png_ptr->pass)
  176188. {
  176189. case 0:
  176190. if (png_ptr->row_number & 0x07)
  176191. {
  176192. png_write_finish_row(png_ptr);
  176193. return;
  176194. }
  176195. break;
  176196. case 1:
  176197. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176198. {
  176199. png_write_finish_row(png_ptr);
  176200. return;
  176201. }
  176202. break;
  176203. case 2:
  176204. if ((png_ptr->row_number & 0x07) != 4)
  176205. {
  176206. png_write_finish_row(png_ptr);
  176207. return;
  176208. }
  176209. break;
  176210. case 3:
  176211. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176212. {
  176213. png_write_finish_row(png_ptr);
  176214. return;
  176215. }
  176216. break;
  176217. case 4:
  176218. if ((png_ptr->row_number & 0x03) != 2)
  176219. {
  176220. png_write_finish_row(png_ptr);
  176221. return;
  176222. }
  176223. break;
  176224. case 5:
  176225. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176226. {
  176227. png_write_finish_row(png_ptr);
  176228. return;
  176229. }
  176230. break;
  176231. case 6:
  176232. if (!(png_ptr->row_number & 0x01))
  176233. {
  176234. png_write_finish_row(png_ptr);
  176235. return;
  176236. }
  176237. break;
  176238. }
  176239. }
  176240. #endif
  176241. png_ptr->row_info.color_type = png_ptr->color_type;
  176242. png_ptr->row_info.width = png_ptr->usr_width;
  176243. png_ptr->row_info.channels = png_ptr->usr_channels;
  176244. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176245. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176246. png_ptr->row_info.channels);
  176247. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176248. png_ptr->row_info.width);
  176249. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176250. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176251. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176252. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176253. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176254. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176255. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176256. png_ptr->row_info.rowbytes);
  176257. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176258. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176259. (png_ptr->transformations & PNG_INTERLACE))
  176260. {
  176261. png_do_write_interlace(&(png_ptr->row_info),
  176262. png_ptr->row_buf + 1, png_ptr->pass);
  176263. if (!(png_ptr->row_info.width))
  176264. {
  176265. png_write_finish_row(png_ptr);
  176266. return;
  176267. }
  176268. }
  176269. #endif
  176270. if (png_ptr->transformations)
  176271. png_do_write_transformations(png_ptr);
  176272. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176273. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176274. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176275. {
  176276. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176277. }
  176278. #endif
  176279. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176280. if (png_ptr->write_row_fn != NULL)
  176281. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176282. }
  176283. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176284. void PNGAPI
  176285. png_set_flush(png_structp png_ptr, int nrows)
  176286. {
  176287. png_debug(1, "in png_set_flush\n");
  176288. if (png_ptr == NULL)
  176289. return;
  176290. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176291. }
  176292. void PNGAPI
  176293. png_write_flush(png_structp png_ptr)
  176294. {
  176295. int wrote_IDAT;
  176296. png_debug(1, "in png_write_flush\n");
  176297. if (png_ptr == NULL)
  176298. return;
  176299. if (png_ptr->row_number >= png_ptr->num_rows)
  176300. return;
  176301. do
  176302. {
  176303. int ret;
  176304. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176305. wrote_IDAT = 0;
  176306. if (ret != Z_OK)
  176307. {
  176308. if (png_ptr->zstream.msg != NULL)
  176309. png_error(png_ptr, png_ptr->zstream.msg);
  176310. else
  176311. png_error(png_ptr, "zlib error");
  176312. }
  176313. if (!(png_ptr->zstream.avail_out))
  176314. {
  176315. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176316. png_ptr->zbuf_size);
  176317. png_ptr->zstream.next_out = png_ptr->zbuf;
  176318. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176319. wrote_IDAT = 1;
  176320. }
  176321. } while(wrote_IDAT == 1);
  176322. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176323. {
  176324. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176325. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176326. png_ptr->zstream.next_out = png_ptr->zbuf;
  176327. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176328. }
  176329. png_ptr->flush_rows = 0;
  176330. png_flush(png_ptr);
  176331. }
  176332. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176333. void PNGAPI
  176334. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176335. {
  176336. png_structp png_ptr = NULL;
  176337. png_infop info_ptr = NULL;
  176338. #ifdef PNG_USER_MEM_SUPPORTED
  176339. png_free_ptr free_fn = NULL;
  176340. png_voidp mem_ptr = NULL;
  176341. #endif
  176342. png_debug(1, "in png_destroy_write_struct\n");
  176343. if (png_ptr_ptr != NULL)
  176344. {
  176345. png_ptr = *png_ptr_ptr;
  176346. #ifdef PNG_USER_MEM_SUPPORTED
  176347. free_fn = png_ptr->free_fn;
  176348. mem_ptr = png_ptr->mem_ptr;
  176349. #endif
  176350. }
  176351. if (info_ptr_ptr != NULL)
  176352. info_ptr = *info_ptr_ptr;
  176353. if (info_ptr != NULL)
  176354. {
  176355. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176356. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176357. if (png_ptr->num_chunk_list)
  176358. {
  176359. png_free(png_ptr, png_ptr->chunk_list);
  176360. png_ptr->chunk_list=NULL;
  176361. png_ptr->num_chunk_list=0;
  176362. }
  176363. #endif
  176364. #ifdef PNG_USER_MEM_SUPPORTED
  176365. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176366. (png_voidp)mem_ptr);
  176367. #else
  176368. png_destroy_struct((png_voidp)info_ptr);
  176369. #endif
  176370. *info_ptr_ptr = NULL;
  176371. }
  176372. if (png_ptr != NULL)
  176373. {
  176374. png_write_destroy(png_ptr);
  176375. #ifdef PNG_USER_MEM_SUPPORTED
  176376. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176377. (png_voidp)mem_ptr);
  176378. #else
  176379. png_destroy_struct((png_voidp)png_ptr);
  176380. #endif
  176381. *png_ptr_ptr = NULL;
  176382. }
  176383. }
  176384. void /* PRIVATE */
  176385. png_write_destroy(png_structp png_ptr)
  176386. {
  176387. #ifdef PNG_SETJMP_SUPPORTED
  176388. jmp_buf tmp_jmp; /* save jump buffer */
  176389. #endif
  176390. png_error_ptr error_fn;
  176391. png_error_ptr warning_fn;
  176392. png_voidp error_ptr;
  176393. #ifdef PNG_USER_MEM_SUPPORTED
  176394. png_free_ptr free_fn;
  176395. #endif
  176396. png_debug(1, "in png_write_destroy\n");
  176397. deflateEnd(&png_ptr->zstream);
  176398. png_free(png_ptr, png_ptr->zbuf);
  176399. png_free(png_ptr, png_ptr->row_buf);
  176400. png_free(png_ptr, png_ptr->prev_row);
  176401. png_free(png_ptr, png_ptr->sub_row);
  176402. png_free(png_ptr, png_ptr->up_row);
  176403. png_free(png_ptr, png_ptr->avg_row);
  176404. png_free(png_ptr, png_ptr->paeth_row);
  176405. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176406. png_free(png_ptr, png_ptr->time_buffer);
  176407. #endif
  176408. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176409. png_free(png_ptr, png_ptr->prev_filters);
  176410. png_free(png_ptr, png_ptr->filter_weights);
  176411. png_free(png_ptr, png_ptr->inv_filter_weights);
  176412. png_free(png_ptr, png_ptr->filter_costs);
  176413. png_free(png_ptr, png_ptr->inv_filter_costs);
  176414. #endif
  176415. #ifdef PNG_SETJMP_SUPPORTED
  176416. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176417. #endif
  176418. error_fn = png_ptr->error_fn;
  176419. warning_fn = png_ptr->warning_fn;
  176420. error_ptr = png_ptr->error_ptr;
  176421. #ifdef PNG_USER_MEM_SUPPORTED
  176422. free_fn = png_ptr->free_fn;
  176423. #endif
  176424. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176425. png_ptr->error_fn = error_fn;
  176426. png_ptr->warning_fn = warning_fn;
  176427. png_ptr->error_ptr = error_ptr;
  176428. #ifdef PNG_USER_MEM_SUPPORTED
  176429. png_ptr->free_fn = free_fn;
  176430. #endif
  176431. #ifdef PNG_SETJMP_SUPPORTED
  176432. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176433. #endif
  176434. }
  176435. void PNGAPI
  176436. png_set_filter(png_structp png_ptr, int method, int filters)
  176437. {
  176438. png_debug(1, "in png_set_filter\n");
  176439. if (png_ptr == NULL)
  176440. return;
  176441. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176442. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176443. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176444. method = PNG_FILTER_TYPE_BASE;
  176445. #endif
  176446. if (method == PNG_FILTER_TYPE_BASE)
  176447. {
  176448. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176449. {
  176450. #ifndef PNG_NO_WRITE_FILTER
  176451. case 5:
  176452. case 6:
  176453. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176454. #endif /* PNG_NO_WRITE_FILTER */
  176455. case PNG_FILTER_VALUE_NONE:
  176456. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176457. #ifndef PNG_NO_WRITE_FILTER
  176458. case PNG_FILTER_VALUE_SUB:
  176459. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176460. case PNG_FILTER_VALUE_UP:
  176461. png_ptr->do_filter=PNG_FILTER_UP; break;
  176462. case PNG_FILTER_VALUE_AVG:
  176463. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176464. case PNG_FILTER_VALUE_PAETH:
  176465. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176466. default: png_ptr->do_filter = (png_byte)filters; break;
  176467. #else
  176468. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176469. #endif /* PNG_NO_WRITE_FILTER */
  176470. }
  176471. if (png_ptr->row_buf != NULL)
  176472. {
  176473. #ifndef PNG_NO_WRITE_FILTER
  176474. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176475. {
  176476. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176477. (png_ptr->rowbytes + 1));
  176478. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176479. }
  176480. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176481. {
  176482. if (png_ptr->prev_row == NULL)
  176483. {
  176484. png_warning(png_ptr, "Can't add Up filter after starting");
  176485. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176486. }
  176487. else
  176488. {
  176489. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176490. (png_ptr->rowbytes + 1));
  176491. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176492. }
  176493. }
  176494. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176495. {
  176496. if (png_ptr->prev_row == NULL)
  176497. {
  176498. png_warning(png_ptr, "Can't add Average filter after starting");
  176499. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176500. }
  176501. else
  176502. {
  176503. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176504. (png_ptr->rowbytes + 1));
  176505. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176506. }
  176507. }
  176508. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176509. png_ptr->paeth_row == NULL)
  176510. {
  176511. if (png_ptr->prev_row == NULL)
  176512. {
  176513. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176514. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176515. }
  176516. else
  176517. {
  176518. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176519. (png_ptr->rowbytes + 1));
  176520. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176521. }
  176522. }
  176523. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176524. #endif /* PNG_NO_WRITE_FILTER */
  176525. png_ptr->do_filter = PNG_FILTER_NONE;
  176526. }
  176527. }
  176528. else
  176529. png_error(png_ptr, "Unknown custom filter method");
  176530. }
  176531. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176532. void PNGAPI
  176533. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176534. int num_weights, png_doublep filter_weights,
  176535. png_doublep filter_costs)
  176536. {
  176537. int i;
  176538. png_debug(1, "in png_set_filter_heuristics\n");
  176539. if (png_ptr == NULL)
  176540. return;
  176541. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176542. {
  176543. png_warning(png_ptr, "Unknown filter heuristic method");
  176544. return;
  176545. }
  176546. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176547. {
  176548. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176549. }
  176550. if (num_weights < 0 || filter_weights == NULL ||
  176551. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176552. {
  176553. num_weights = 0;
  176554. }
  176555. png_ptr->num_prev_filters = (png_byte)num_weights;
  176556. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176557. if (num_weights > 0)
  176558. {
  176559. if (png_ptr->prev_filters == NULL)
  176560. {
  176561. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176562. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176563. for (i = 0; i < num_weights; i++)
  176564. {
  176565. png_ptr->prev_filters[i] = 255;
  176566. }
  176567. }
  176568. if (png_ptr->filter_weights == NULL)
  176569. {
  176570. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176571. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176572. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176573. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176574. for (i = 0; i < num_weights; i++)
  176575. {
  176576. png_ptr->inv_filter_weights[i] =
  176577. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176578. }
  176579. }
  176580. for (i = 0; i < num_weights; i++)
  176581. {
  176582. if (filter_weights[i] < 0.0)
  176583. {
  176584. png_ptr->inv_filter_weights[i] =
  176585. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176586. }
  176587. else
  176588. {
  176589. png_ptr->inv_filter_weights[i] =
  176590. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176591. png_ptr->filter_weights[i] =
  176592. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176593. }
  176594. }
  176595. }
  176596. if (png_ptr->filter_costs == NULL)
  176597. {
  176598. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176599. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176600. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176601. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176602. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176603. {
  176604. png_ptr->inv_filter_costs[i] =
  176605. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176606. }
  176607. }
  176608. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176609. {
  176610. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176611. {
  176612. png_ptr->inv_filter_costs[i] =
  176613. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176614. }
  176615. else if (filter_costs[i] >= 1.0)
  176616. {
  176617. png_ptr->inv_filter_costs[i] =
  176618. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176619. png_ptr->filter_costs[i] =
  176620. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176621. }
  176622. }
  176623. }
  176624. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176625. void PNGAPI
  176626. png_set_compression_level(png_structp png_ptr, int level)
  176627. {
  176628. png_debug(1, "in png_set_compression_level\n");
  176629. if (png_ptr == NULL)
  176630. return;
  176631. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176632. png_ptr->zlib_level = level;
  176633. }
  176634. void PNGAPI
  176635. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176636. {
  176637. png_debug(1, "in png_set_compression_mem_level\n");
  176638. if (png_ptr == NULL)
  176639. return;
  176640. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176641. png_ptr->zlib_mem_level = mem_level;
  176642. }
  176643. void PNGAPI
  176644. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176645. {
  176646. png_debug(1, "in png_set_compression_strategy\n");
  176647. if (png_ptr == NULL)
  176648. return;
  176649. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176650. png_ptr->zlib_strategy = strategy;
  176651. }
  176652. void PNGAPI
  176653. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176654. {
  176655. if (png_ptr == NULL)
  176656. return;
  176657. if (window_bits > 15)
  176658. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176659. else if (window_bits < 8)
  176660. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176661. #ifndef WBITS_8_OK
  176662. if (window_bits == 8)
  176663. {
  176664. png_warning(png_ptr, "Compression window is being reset to 512");
  176665. window_bits=9;
  176666. }
  176667. #endif
  176668. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176669. png_ptr->zlib_window_bits = window_bits;
  176670. }
  176671. void PNGAPI
  176672. png_set_compression_method(png_structp png_ptr, int method)
  176673. {
  176674. png_debug(1, "in png_set_compression_method\n");
  176675. if (png_ptr == NULL)
  176676. return;
  176677. if (method != 8)
  176678. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176679. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176680. png_ptr->zlib_method = method;
  176681. }
  176682. void PNGAPI
  176683. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176684. {
  176685. if (png_ptr == NULL)
  176686. return;
  176687. png_ptr->write_row_fn = write_row_fn;
  176688. }
  176689. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176690. void PNGAPI
  176691. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176692. write_user_transform_fn)
  176693. {
  176694. png_debug(1, "in png_set_write_user_transform_fn\n");
  176695. if (png_ptr == NULL)
  176696. return;
  176697. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176698. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176699. }
  176700. #endif
  176701. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176702. void PNGAPI
  176703. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176704. int transforms, voidp params)
  176705. {
  176706. if (png_ptr == NULL || info_ptr == NULL)
  176707. return;
  176708. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176709. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176710. png_set_invert_alpha(png_ptr);
  176711. #endif
  176712. png_write_info(png_ptr, info_ptr);
  176713. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176714. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176715. png_set_invert_mono(png_ptr);
  176716. #endif
  176717. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176718. if ((transforms & PNG_TRANSFORM_SHIFT)
  176719. && (info_ptr->valid & PNG_INFO_sBIT))
  176720. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176721. #endif
  176722. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176723. if (transforms & PNG_TRANSFORM_PACKING)
  176724. png_set_packing(png_ptr);
  176725. #endif
  176726. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176727. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176728. png_set_swap_alpha(png_ptr);
  176729. #endif
  176730. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176731. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176732. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176733. #endif
  176734. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176735. if (transforms & PNG_TRANSFORM_BGR)
  176736. png_set_bgr(png_ptr);
  176737. #endif
  176738. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176739. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176740. png_set_swap(png_ptr);
  176741. #endif
  176742. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176743. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176744. png_set_packswap(png_ptr);
  176745. #endif
  176746. if (info_ptr->valid & PNG_INFO_IDAT)
  176747. png_write_image(png_ptr, info_ptr->row_pointers);
  176748. png_write_end(png_ptr, info_ptr);
  176749. transforms = transforms; /* quiet compiler warnings */
  176750. params = params;
  176751. }
  176752. #endif
  176753. #endif /* PNG_WRITE_SUPPORTED */
  176754. /*** End of inlined file: pngwrite.c ***/
  176755. /*** Start of inlined file: pngwtran.c ***/
  176756. #define PNG_INTERNAL
  176757. #ifdef PNG_WRITE_SUPPORTED
  176758. void /* PRIVATE */
  176759. png_do_write_transformations(png_structp png_ptr)
  176760. {
  176761. png_debug(1, "in png_do_write_transformations\n");
  176762. if (png_ptr == NULL)
  176763. return;
  176764. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176765. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176766. if(png_ptr->write_user_transform_fn != NULL)
  176767. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176768. (png_ptr, /* png_ptr */
  176769. &(png_ptr->row_info), /* row_info: */
  176770. png_ptr->row_buf + 1); /* start of pixel data for row */
  176771. #endif
  176772. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176773. if (png_ptr->transformations & PNG_FILLER)
  176774. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176775. png_ptr->flags);
  176776. #endif
  176777. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176778. if (png_ptr->transformations & PNG_PACKSWAP)
  176779. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176780. #endif
  176781. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176782. if (png_ptr->transformations & PNG_PACK)
  176783. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176784. (png_uint_32)png_ptr->bit_depth);
  176785. #endif
  176786. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176787. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176788. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176789. #endif
  176790. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176791. if (png_ptr->transformations & PNG_SHIFT)
  176792. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176793. &(png_ptr->shift));
  176794. #endif
  176795. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176796. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176797. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176798. #endif
  176799. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176800. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176801. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176802. #endif
  176803. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176804. if (png_ptr->transformations & PNG_BGR)
  176805. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176806. #endif
  176807. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176808. if (png_ptr->transformations & PNG_INVERT_MONO)
  176809. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176810. #endif
  176811. }
  176812. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176813. void /* PRIVATE */
  176814. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176815. {
  176816. png_debug(1, "in png_do_pack\n");
  176817. if (row_info->bit_depth == 8 &&
  176818. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176819. row != NULL && row_info != NULL &&
  176820. #endif
  176821. row_info->channels == 1)
  176822. {
  176823. switch ((int)bit_depth)
  176824. {
  176825. case 1:
  176826. {
  176827. png_bytep sp, dp;
  176828. int mask, v;
  176829. png_uint_32 i;
  176830. png_uint_32 row_width = row_info->width;
  176831. sp = row;
  176832. dp = row;
  176833. mask = 0x80;
  176834. v = 0;
  176835. for (i = 0; i < row_width; i++)
  176836. {
  176837. if (*sp != 0)
  176838. v |= mask;
  176839. sp++;
  176840. if (mask > 1)
  176841. mask >>= 1;
  176842. else
  176843. {
  176844. mask = 0x80;
  176845. *dp = (png_byte)v;
  176846. dp++;
  176847. v = 0;
  176848. }
  176849. }
  176850. if (mask != 0x80)
  176851. *dp = (png_byte)v;
  176852. break;
  176853. }
  176854. case 2:
  176855. {
  176856. png_bytep sp, dp;
  176857. int shift, v;
  176858. png_uint_32 i;
  176859. png_uint_32 row_width = row_info->width;
  176860. sp = row;
  176861. dp = row;
  176862. shift = 6;
  176863. v = 0;
  176864. for (i = 0; i < row_width; i++)
  176865. {
  176866. png_byte value;
  176867. value = (png_byte)(*sp & 0x03);
  176868. v |= (value << shift);
  176869. if (shift == 0)
  176870. {
  176871. shift = 6;
  176872. *dp = (png_byte)v;
  176873. dp++;
  176874. v = 0;
  176875. }
  176876. else
  176877. shift -= 2;
  176878. sp++;
  176879. }
  176880. if (shift != 6)
  176881. *dp = (png_byte)v;
  176882. break;
  176883. }
  176884. case 4:
  176885. {
  176886. png_bytep sp, dp;
  176887. int shift, v;
  176888. png_uint_32 i;
  176889. png_uint_32 row_width = row_info->width;
  176890. sp = row;
  176891. dp = row;
  176892. shift = 4;
  176893. v = 0;
  176894. for (i = 0; i < row_width; i++)
  176895. {
  176896. png_byte value;
  176897. value = (png_byte)(*sp & 0x0f);
  176898. v |= (value << shift);
  176899. if (shift == 0)
  176900. {
  176901. shift = 4;
  176902. *dp = (png_byte)v;
  176903. dp++;
  176904. v = 0;
  176905. }
  176906. else
  176907. shift -= 4;
  176908. sp++;
  176909. }
  176910. if (shift != 4)
  176911. *dp = (png_byte)v;
  176912. break;
  176913. }
  176914. }
  176915. row_info->bit_depth = (png_byte)bit_depth;
  176916. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176917. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176918. row_info->width);
  176919. }
  176920. }
  176921. #endif
  176922. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176923. void /* PRIVATE */
  176924. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176925. {
  176926. png_debug(1, "in png_do_shift\n");
  176927. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176928. if (row != NULL && row_info != NULL &&
  176929. #else
  176930. if (
  176931. #endif
  176932. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176933. {
  176934. int shift_start[4], shift_dec[4];
  176935. int channels = 0;
  176936. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176937. {
  176938. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176939. shift_dec[channels] = bit_depth->red;
  176940. channels++;
  176941. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176942. shift_dec[channels] = bit_depth->green;
  176943. channels++;
  176944. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176945. shift_dec[channels] = bit_depth->blue;
  176946. channels++;
  176947. }
  176948. else
  176949. {
  176950. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176951. shift_dec[channels] = bit_depth->gray;
  176952. channels++;
  176953. }
  176954. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176955. {
  176956. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176957. shift_dec[channels] = bit_depth->alpha;
  176958. channels++;
  176959. }
  176960. if (row_info->bit_depth < 8)
  176961. {
  176962. png_bytep bp = row;
  176963. png_uint_32 i;
  176964. png_byte mask;
  176965. png_uint_32 row_bytes = row_info->rowbytes;
  176966. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176967. mask = 0x55;
  176968. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176969. mask = 0x11;
  176970. else
  176971. mask = 0xff;
  176972. for (i = 0; i < row_bytes; i++, bp++)
  176973. {
  176974. png_uint_16 v;
  176975. int j;
  176976. v = *bp;
  176977. *bp = 0;
  176978. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176979. {
  176980. if (j > 0)
  176981. *bp |= (png_byte)((v << j) & 0xff);
  176982. else
  176983. *bp |= (png_byte)((v >> (-j)) & mask);
  176984. }
  176985. }
  176986. }
  176987. else if (row_info->bit_depth == 8)
  176988. {
  176989. png_bytep bp = row;
  176990. png_uint_32 i;
  176991. png_uint_32 istop = channels * row_info->width;
  176992. for (i = 0; i < istop; i++, bp++)
  176993. {
  176994. png_uint_16 v;
  176995. int j;
  176996. int c = (int)(i%channels);
  176997. v = *bp;
  176998. *bp = 0;
  176999. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177000. {
  177001. if (j > 0)
  177002. *bp |= (png_byte)((v << j) & 0xff);
  177003. else
  177004. *bp |= (png_byte)((v >> (-j)) & 0xff);
  177005. }
  177006. }
  177007. }
  177008. else
  177009. {
  177010. png_bytep bp;
  177011. png_uint_32 i;
  177012. png_uint_32 istop = channels * row_info->width;
  177013. for (bp = row, i = 0; i < istop; i++)
  177014. {
  177015. int c = (int)(i%channels);
  177016. png_uint_16 value, v;
  177017. int j;
  177018. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  177019. value = 0;
  177020. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177021. {
  177022. if (j > 0)
  177023. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  177024. else
  177025. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  177026. }
  177027. *bp++ = (png_byte)(value >> 8);
  177028. *bp++ = (png_byte)(value & 0xff);
  177029. }
  177030. }
  177031. }
  177032. }
  177033. #endif
  177034. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177035. void /* PRIVATE */
  177036. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  177037. {
  177038. png_debug(1, "in png_do_write_swap_alpha\n");
  177039. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177040. if (row != NULL && row_info != NULL)
  177041. #endif
  177042. {
  177043. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177044. {
  177045. if (row_info->bit_depth == 8)
  177046. {
  177047. png_bytep sp, dp;
  177048. png_uint_32 i;
  177049. png_uint_32 row_width = row_info->width;
  177050. for (i = 0, sp = dp = row; i < row_width; i++)
  177051. {
  177052. png_byte save = *(sp++);
  177053. *(dp++) = *(sp++);
  177054. *(dp++) = *(sp++);
  177055. *(dp++) = *(sp++);
  177056. *(dp++) = save;
  177057. }
  177058. }
  177059. else
  177060. {
  177061. png_bytep sp, dp;
  177062. png_uint_32 i;
  177063. png_uint_32 row_width = row_info->width;
  177064. for (i = 0, sp = dp = row; i < row_width; i++)
  177065. {
  177066. png_byte save[2];
  177067. save[0] = *(sp++);
  177068. save[1] = *(sp++);
  177069. *(dp++) = *(sp++);
  177070. *(dp++) = *(sp++);
  177071. *(dp++) = *(sp++);
  177072. *(dp++) = *(sp++);
  177073. *(dp++) = *(sp++);
  177074. *(dp++) = *(sp++);
  177075. *(dp++) = save[0];
  177076. *(dp++) = save[1];
  177077. }
  177078. }
  177079. }
  177080. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177081. {
  177082. if (row_info->bit_depth == 8)
  177083. {
  177084. png_bytep sp, dp;
  177085. png_uint_32 i;
  177086. png_uint_32 row_width = row_info->width;
  177087. for (i = 0, sp = dp = row; i < row_width; i++)
  177088. {
  177089. png_byte save = *(sp++);
  177090. *(dp++) = *(sp++);
  177091. *(dp++) = save;
  177092. }
  177093. }
  177094. else
  177095. {
  177096. png_bytep sp, dp;
  177097. png_uint_32 i;
  177098. png_uint_32 row_width = row_info->width;
  177099. for (i = 0, sp = dp = row; i < row_width; i++)
  177100. {
  177101. png_byte save[2];
  177102. save[0] = *(sp++);
  177103. save[1] = *(sp++);
  177104. *(dp++) = *(sp++);
  177105. *(dp++) = *(sp++);
  177106. *(dp++) = save[0];
  177107. *(dp++) = save[1];
  177108. }
  177109. }
  177110. }
  177111. }
  177112. }
  177113. #endif
  177114. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177115. void /* PRIVATE */
  177116. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177117. {
  177118. png_debug(1, "in png_do_write_invert_alpha\n");
  177119. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177120. if (row != NULL && row_info != NULL)
  177121. #endif
  177122. {
  177123. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177124. {
  177125. if (row_info->bit_depth == 8)
  177126. {
  177127. png_bytep sp, dp;
  177128. png_uint_32 i;
  177129. png_uint_32 row_width = row_info->width;
  177130. for (i = 0, sp = dp = row; i < row_width; i++)
  177131. {
  177132. sp+=3; dp = sp;
  177133. *(dp++) = (png_byte)(255 - *(sp++));
  177134. }
  177135. }
  177136. else
  177137. {
  177138. png_bytep sp, dp;
  177139. png_uint_32 i;
  177140. png_uint_32 row_width = row_info->width;
  177141. for (i = 0, sp = dp = row; i < row_width; i++)
  177142. {
  177143. sp+=6; dp = sp;
  177144. *(dp++) = (png_byte)(255 - *(sp++));
  177145. *(dp++) = (png_byte)(255 - *(sp++));
  177146. }
  177147. }
  177148. }
  177149. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177150. {
  177151. if (row_info->bit_depth == 8)
  177152. {
  177153. png_bytep sp, dp;
  177154. png_uint_32 i;
  177155. png_uint_32 row_width = row_info->width;
  177156. for (i = 0, sp = dp = row; i < row_width; i++)
  177157. {
  177158. *(dp++) = *(sp++);
  177159. *(dp++) = (png_byte)(255 - *(sp++));
  177160. }
  177161. }
  177162. else
  177163. {
  177164. png_bytep sp, dp;
  177165. png_uint_32 i;
  177166. png_uint_32 row_width = row_info->width;
  177167. for (i = 0, sp = dp = row; i < row_width; i++)
  177168. {
  177169. sp+=2; dp = sp;
  177170. *(dp++) = (png_byte)(255 - *(sp++));
  177171. *(dp++) = (png_byte)(255 - *(sp++));
  177172. }
  177173. }
  177174. }
  177175. }
  177176. }
  177177. #endif
  177178. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177179. void /* PRIVATE */
  177180. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177181. {
  177182. png_debug(1, "in png_do_write_intrapixel\n");
  177183. if (
  177184. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177185. row != NULL && row_info != NULL &&
  177186. #endif
  177187. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177188. {
  177189. int bytes_per_pixel;
  177190. png_uint_32 row_width = row_info->width;
  177191. if (row_info->bit_depth == 8)
  177192. {
  177193. png_bytep rp;
  177194. png_uint_32 i;
  177195. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177196. bytes_per_pixel = 3;
  177197. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177198. bytes_per_pixel = 4;
  177199. else
  177200. return;
  177201. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177202. {
  177203. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177204. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177205. }
  177206. }
  177207. else if (row_info->bit_depth == 16)
  177208. {
  177209. png_bytep rp;
  177210. png_uint_32 i;
  177211. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177212. bytes_per_pixel = 6;
  177213. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177214. bytes_per_pixel = 8;
  177215. else
  177216. return;
  177217. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177218. {
  177219. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177220. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177221. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177222. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177223. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177224. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177225. *(rp+1) = (png_byte)(red & 0xff);
  177226. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177227. *(rp+5) = (png_byte)(blue & 0xff);
  177228. }
  177229. }
  177230. }
  177231. }
  177232. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177233. #endif /* PNG_WRITE_SUPPORTED */
  177234. /*** End of inlined file: pngwtran.c ***/
  177235. /*** Start of inlined file: pngwutil.c ***/
  177236. #define PNG_INTERNAL
  177237. #ifdef PNG_WRITE_SUPPORTED
  177238. void PNGAPI
  177239. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177240. {
  177241. buf[0] = (png_byte)((i >> 24) & 0xff);
  177242. buf[1] = (png_byte)((i >> 16) & 0xff);
  177243. buf[2] = (png_byte)((i >> 8) & 0xff);
  177244. buf[3] = (png_byte)(i & 0xff);
  177245. }
  177246. void PNGAPI
  177247. png_save_int_32(png_bytep buf, png_int_32 i)
  177248. {
  177249. buf[0] = (png_byte)((i >> 24) & 0xff);
  177250. buf[1] = (png_byte)((i >> 16) & 0xff);
  177251. buf[2] = (png_byte)((i >> 8) & 0xff);
  177252. buf[3] = (png_byte)(i & 0xff);
  177253. }
  177254. void PNGAPI
  177255. png_save_uint_16(png_bytep buf, unsigned int i)
  177256. {
  177257. buf[0] = (png_byte)((i >> 8) & 0xff);
  177258. buf[1] = (png_byte)(i & 0xff);
  177259. }
  177260. void PNGAPI
  177261. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177262. png_bytep data, png_size_t length)
  177263. {
  177264. if(png_ptr == NULL) return;
  177265. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177266. png_write_chunk_data(png_ptr, data, length);
  177267. png_write_chunk_end(png_ptr);
  177268. }
  177269. void PNGAPI
  177270. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177271. png_uint_32 length)
  177272. {
  177273. png_byte buf[4];
  177274. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177275. if(png_ptr == NULL) return;
  177276. png_save_uint_32(buf, length);
  177277. png_write_data(png_ptr, buf, (png_size_t)4);
  177278. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177279. png_reset_crc(png_ptr);
  177280. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177281. }
  177282. void PNGAPI
  177283. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177284. {
  177285. if(png_ptr == NULL) return;
  177286. if (data != NULL && length > 0)
  177287. {
  177288. png_calculate_crc(png_ptr, data, length);
  177289. png_write_data(png_ptr, data, length);
  177290. }
  177291. }
  177292. void PNGAPI
  177293. png_write_chunk_end(png_structp png_ptr)
  177294. {
  177295. png_byte buf[4];
  177296. if(png_ptr == NULL) return;
  177297. png_save_uint_32(buf, png_ptr->crc);
  177298. png_write_data(png_ptr, buf, (png_size_t)4);
  177299. }
  177300. void /* PRIVATE */
  177301. png_write_sig(png_structp png_ptr)
  177302. {
  177303. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177304. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177305. (png_size_t)8 - png_ptr->sig_bytes);
  177306. if(png_ptr->sig_bytes < 3)
  177307. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177308. }
  177309. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177310. typedef struct
  177311. {
  177312. char *input; /* the uncompressed input data */
  177313. int input_len; /* its length */
  177314. int num_output_ptr; /* number of output pointers used */
  177315. int max_output_ptr; /* size of output_ptr */
  177316. png_charpp output_ptr; /* array of pointers to output */
  177317. } compression_state;
  177318. static int /* PRIVATE */
  177319. png_text_compress(png_structp png_ptr,
  177320. png_charp text, png_size_t text_len, int compression,
  177321. compression_state *comp)
  177322. {
  177323. int ret;
  177324. comp->num_output_ptr = 0;
  177325. comp->max_output_ptr = 0;
  177326. comp->output_ptr = NULL;
  177327. comp->input = NULL;
  177328. comp->input_len = 0;
  177329. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177330. {
  177331. comp->input = text;
  177332. comp->input_len = text_len;
  177333. return((int)text_len);
  177334. }
  177335. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177336. {
  177337. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177338. char msg[50];
  177339. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177340. png_warning(png_ptr, msg);
  177341. #else
  177342. png_warning(png_ptr, "Unknown compression type");
  177343. #endif
  177344. }
  177345. png_ptr->zstream.avail_in = (uInt)text_len;
  177346. png_ptr->zstream.next_in = (Bytef *)text;
  177347. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177348. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177349. do
  177350. {
  177351. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177352. if (ret != Z_OK)
  177353. {
  177354. if (png_ptr->zstream.msg != NULL)
  177355. png_error(png_ptr, png_ptr->zstream.msg);
  177356. else
  177357. png_error(png_ptr, "zlib error");
  177358. }
  177359. if (!(png_ptr->zstream.avail_out))
  177360. {
  177361. if (comp->num_output_ptr >= comp->max_output_ptr)
  177362. {
  177363. int old_max;
  177364. old_max = comp->max_output_ptr;
  177365. comp->max_output_ptr = comp->num_output_ptr + 4;
  177366. if (comp->output_ptr != NULL)
  177367. {
  177368. png_charpp old_ptr;
  177369. old_ptr = comp->output_ptr;
  177370. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177371. (png_uint_32)(comp->max_output_ptr *
  177372. png_sizeof (png_charpp)));
  177373. png_memcpy(comp->output_ptr, old_ptr, old_max
  177374. * png_sizeof (png_charp));
  177375. png_free(png_ptr, old_ptr);
  177376. }
  177377. else
  177378. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177379. (png_uint_32)(comp->max_output_ptr *
  177380. png_sizeof (png_charp)));
  177381. }
  177382. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177383. (png_uint_32)png_ptr->zbuf_size);
  177384. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177385. png_ptr->zbuf_size);
  177386. comp->num_output_ptr++;
  177387. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177388. png_ptr->zstream.next_out = png_ptr->zbuf;
  177389. }
  177390. } while (png_ptr->zstream.avail_in);
  177391. do
  177392. {
  177393. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177394. if (ret == Z_OK)
  177395. {
  177396. if (!(png_ptr->zstream.avail_out))
  177397. {
  177398. if (comp->num_output_ptr >= comp->max_output_ptr)
  177399. {
  177400. int old_max;
  177401. old_max = comp->max_output_ptr;
  177402. comp->max_output_ptr = comp->num_output_ptr + 4;
  177403. if (comp->output_ptr != NULL)
  177404. {
  177405. png_charpp old_ptr;
  177406. old_ptr = comp->output_ptr;
  177407. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177408. (png_uint_32)(comp->max_output_ptr *
  177409. png_sizeof (png_charpp)));
  177410. png_memcpy(comp->output_ptr, old_ptr,
  177411. old_max * png_sizeof (png_charp));
  177412. png_free(png_ptr, old_ptr);
  177413. }
  177414. else
  177415. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177416. (png_uint_32)(comp->max_output_ptr *
  177417. png_sizeof (png_charp)));
  177418. }
  177419. comp->output_ptr[comp->num_output_ptr] =
  177420. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177421. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177422. png_ptr->zbuf_size);
  177423. comp->num_output_ptr++;
  177424. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177425. png_ptr->zstream.next_out = png_ptr->zbuf;
  177426. }
  177427. }
  177428. else if (ret != Z_STREAM_END)
  177429. {
  177430. if (png_ptr->zstream.msg != NULL)
  177431. png_error(png_ptr, png_ptr->zstream.msg);
  177432. else
  177433. png_error(png_ptr, "zlib error");
  177434. }
  177435. } while (ret != Z_STREAM_END);
  177436. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177437. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177438. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177439. return((int)text_len);
  177440. }
  177441. static void /* PRIVATE */
  177442. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177443. {
  177444. int i;
  177445. if (comp->input)
  177446. {
  177447. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177448. (png_size_t)comp->input_len);
  177449. return;
  177450. }
  177451. for (i = 0; i < comp->num_output_ptr; i++)
  177452. {
  177453. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177454. png_ptr->zbuf_size);
  177455. png_free(png_ptr, comp->output_ptr[i]);
  177456. comp->output_ptr[i]=NULL;
  177457. }
  177458. if (comp->max_output_ptr != 0)
  177459. png_free(png_ptr, comp->output_ptr);
  177460. comp->output_ptr=NULL;
  177461. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177462. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177463. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177464. deflateReset(&png_ptr->zstream);
  177465. png_ptr->zstream.data_type = Z_BINARY;
  177466. }
  177467. #endif
  177468. void /* PRIVATE */
  177469. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177470. int bit_depth, int color_type, int compression_type, int filter_type,
  177471. int interlace_type)
  177472. {
  177473. #ifdef PNG_USE_LOCAL_ARRAYS
  177474. PNG_IHDR;
  177475. #endif
  177476. png_byte buf[13]; /* buffer to store the IHDR info */
  177477. png_debug(1, "in png_write_IHDR\n");
  177478. switch (color_type)
  177479. {
  177480. case PNG_COLOR_TYPE_GRAY:
  177481. switch (bit_depth)
  177482. {
  177483. case 1:
  177484. case 2:
  177485. case 4:
  177486. case 8:
  177487. case 16: png_ptr->channels = 1; break;
  177488. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177489. }
  177490. break;
  177491. case PNG_COLOR_TYPE_RGB:
  177492. if (bit_depth != 8 && bit_depth != 16)
  177493. png_error(png_ptr, "Invalid bit depth for RGB image");
  177494. png_ptr->channels = 3;
  177495. break;
  177496. case PNG_COLOR_TYPE_PALETTE:
  177497. switch (bit_depth)
  177498. {
  177499. case 1:
  177500. case 2:
  177501. case 4:
  177502. case 8: png_ptr->channels = 1; break;
  177503. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177504. }
  177505. break;
  177506. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177507. if (bit_depth != 8 && bit_depth != 16)
  177508. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177509. png_ptr->channels = 2;
  177510. break;
  177511. case PNG_COLOR_TYPE_RGB_ALPHA:
  177512. if (bit_depth != 8 && bit_depth != 16)
  177513. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177514. png_ptr->channels = 4;
  177515. break;
  177516. default:
  177517. png_error(png_ptr, "Invalid image color type specified");
  177518. }
  177519. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177520. {
  177521. png_warning(png_ptr, "Invalid compression type specified");
  177522. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177523. }
  177524. if (
  177525. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177526. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177527. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177528. (color_type == PNG_COLOR_TYPE_RGB ||
  177529. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177530. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177531. #endif
  177532. filter_type != PNG_FILTER_TYPE_BASE)
  177533. {
  177534. png_warning(png_ptr, "Invalid filter type specified");
  177535. filter_type = PNG_FILTER_TYPE_BASE;
  177536. }
  177537. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177538. if (interlace_type != PNG_INTERLACE_NONE &&
  177539. interlace_type != PNG_INTERLACE_ADAM7)
  177540. {
  177541. png_warning(png_ptr, "Invalid interlace type specified");
  177542. interlace_type = PNG_INTERLACE_ADAM7;
  177543. }
  177544. #else
  177545. interlace_type=PNG_INTERLACE_NONE;
  177546. #endif
  177547. png_ptr->bit_depth = (png_byte)bit_depth;
  177548. png_ptr->color_type = (png_byte)color_type;
  177549. png_ptr->interlaced = (png_byte)interlace_type;
  177550. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177551. png_ptr->filter_type = (png_byte)filter_type;
  177552. #endif
  177553. png_ptr->compression_type = (png_byte)compression_type;
  177554. png_ptr->width = width;
  177555. png_ptr->height = height;
  177556. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177557. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177558. png_ptr->usr_width = png_ptr->width;
  177559. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177560. png_ptr->usr_channels = png_ptr->channels;
  177561. png_save_uint_32(buf, width);
  177562. png_save_uint_32(buf + 4, height);
  177563. buf[8] = (png_byte)bit_depth;
  177564. buf[9] = (png_byte)color_type;
  177565. buf[10] = (png_byte)compression_type;
  177566. buf[11] = (png_byte)filter_type;
  177567. buf[12] = (png_byte)interlace_type;
  177568. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177569. png_ptr->zstream.zalloc = png_zalloc;
  177570. png_ptr->zstream.zfree = png_zfree;
  177571. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177572. if (!(png_ptr->do_filter))
  177573. {
  177574. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177575. png_ptr->bit_depth < 8)
  177576. png_ptr->do_filter = PNG_FILTER_NONE;
  177577. else
  177578. png_ptr->do_filter = PNG_ALL_FILTERS;
  177579. }
  177580. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177581. {
  177582. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177583. png_ptr->zlib_strategy = Z_FILTERED;
  177584. else
  177585. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177586. }
  177587. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177588. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177589. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177590. png_ptr->zlib_mem_level = 8;
  177591. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177592. png_ptr->zlib_window_bits = 15;
  177593. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177594. png_ptr->zlib_method = 8;
  177595. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177596. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177597. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177598. png_error(png_ptr, "zlib failed to initialize compressor");
  177599. png_ptr->zstream.next_out = png_ptr->zbuf;
  177600. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177601. png_ptr->zstream.data_type = Z_BINARY;
  177602. png_ptr->mode = PNG_HAVE_IHDR;
  177603. }
  177604. void /* PRIVATE */
  177605. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177606. {
  177607. #ifdef PNG_USE_LOCAL_ARRAYS
  177608. PNG_PLTE;
  177609. #endif
  177610. png_uint_32 i;
  177611. png_colorp pal_ptr;
  177612. png_byte buf[3];
  177613. png_debug(1, "in png_write_PLTE\n");
  177614. if ((
  177615. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177616. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177617. #endif
  177618. num_pal == 0) || num_pal > 256)
  177619. {
  177620. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177621. {
  177622. png_error(png_ptr, "Invalid number of colors in palette");
  177623. }
  177624. else
  177625. {
  177626. png_warning(png_ptr, "Invalid number of colors in palette");
  177627. return;
  177628. }
  177629. }
  177630. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177631. {
  177632. png_warning(png_ptr,
  177633. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177634. return;
  177635. }
  177636. png_ptr->num_palette = (png_uint_16)num_pal;
  177637. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177638. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177639. #ifndef PNG_NO_POINTER_INDEXING
  177640. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177641. {
  177642. buf[0] = pal_ptr->red;
  177643. buf[1] = pal_ptr->green;
  177644. buf[2] = pal_ptr->blue;
  177645. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177646. }
  177647. #else
  177648. pal_ptr=palette;
  177649. for (i = 0; i < num_pal; i++)
  177650. {
  177651. buf[0] = pal_ptr[i].red;
  177652. buf[1] = pal_ptr[i].green;
  177653. buf[2] = pal_ptr[i].blue;
  177654. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177655. }
  177656. #endif
  177657. png_write_chunk_end(png_ptr);
  177658. png_ptr->mode |= PNG_HAVE_PLTE;
  177659. }
  177660. void /* PRIVATE */
  177661. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177662. {
  177663. #ifdef PNG_USE_LOCAL_ARRAYS
  177664. PNG_IDAT;
  177665. #endif
  177666. png_debug(1, "in png_write_IDAT\n");
  177667. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177668. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177669. {
  177670. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177671. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177672. {
  177673. if (length >= 2 &&
  177674. png_ptr->height < 16384 && png_ptr->width < 16384)
  177675. {
  177676. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177677. ((png_ptr->width *
  177678. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177679. unsigned int z_cinfo = z_cmf >> 4;
  177680. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177681. while (uncompressed_idat_size <= half_z_window_size &&
  177682. half_z_window_size >= 256)
  177683. {
  177684. z_cinfo--;
  177685. half_z_window_size >>= 1;
  177686. }
  177687. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177688. if (data[0] != (png_byte)z_cmf)
  177689. {
  177690. data[0] = (png_byte)z_cmf;
  177691. data[1] &= 0xe0;
  177692. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177693. }
  177694. }
  177695. }
  177696. else
  177697. png_error(png_ptr,
  177698. "Invalid zlib compression method or flags in IDAT");
  177699. }
  177700. png_write_chunk(png_ptr, png_IDAT, data, length);
  177701. png_ptr->mode |= PNG_HAVE_IDAT;
  177702. }
  177703. void /* PRIVATE */
  177704. png_write_IEND(png_structp png_ptr)
  177705. {
  177706. #ifdef PNG_USE_LOCAL_ARRAYS
  177707. PNG_IEND;
  177708. #endif
  177709. png_debug(1, "in png_write_IEND\n");
  177710. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177711. (png_size_t)0);
  177712. png_ptr->mode |= PNG_HAVE_IEND;
  177713. }
  177714. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177715. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177716. void /* PRIVATE */
  177717. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177718. {
  177719. #ifdef PNG_USE_LOCAL_ARRAYS
  177720. PNG_gAMA;
  177721. #endif
  177722. png_uint_32 igamma;
  177723. png_byte buf[4];
  177724. png_debug(1, "in png_write_gAMA\n");
  177725. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177726. png_save_uint_32(buf, igamma);
  177727. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177728. }
  177729. #endif
  177730. #ifdef PNG_FIXED_POINT_SUPPORTED
  177731. void /* PRIVATE */
  177732. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177733. {
  177734. #ifdef PNG_USE_LOCAL_ARRAYS
  177735. PNG_gAMA;
  177736. #endif
  177737. png_byte buf[4];
  177738. png_debug(1, "in png_write_gAMA\n");
  177739. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177740. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177741. }
  177742. #endif
  177743. #endif
  177744. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177745. void /* PRIVATE */
  177746. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177747. {
  177748. #ifdef PNG_USE_LOCAL_ARRAYS
  177749. PNG_sRGB;
  177750. #endif
  177751. png_byte buf[1];
  177752. png_debug(1, "in png_write_sRGB\n");
  177753. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177754. png_warning(png_ptr,
  177755. "Invalid sRGB rendering intent specified");
  177756. buf[0]=(png_byte)srgb_intent;
  177757. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177758. }
  177759. #endif
  177760. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177761. void /* PRIVATE */
  177762. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177763. png_charp profile, int profile_len)
  177764. {
  177765. #ifdef PNG_USE_LOCAL_ARRAYS
  177766. PNG_iCCP;
  177767. #endif
  177768. png_size_t name_len;
  177769. png_charp new_name;
  177770. compression_state comp;
  177771. int embedded_profile_len = 0;
  177772. png_debug(1, "in png_write_iCCP\n");
  177773. comp.num_output_ptr = 0;
  177774. comp.max_output_ptr = 0;
  177775. comp.output_ptr = NULL;
  177776. comp.input = NULL;
  177777. comp.input_len = 0;
  177778. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177779. &new_name)) == 0)
  177780. {
  177781. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177782. return;
  177783. }
  177784. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177785. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177786. if (profile == NULL)
  177787. profile_len = 0;
  177788. if (profile_len > 3)
  177789. embedded_profile_len =
  177790. ((*( (png_bytep)profile ))<<24) |
  177791. ((*( (png_bytep)profile+1))<<16) |
  177792. ((*( (png_bytep)profile+2))<< 8) |
  177793. ((*( (png_bytep)profile+3)) );
  177794. if (profile_len < embedded_profile_len)
  177795. {
  177796. png_warning(png_ptr,
  177797. "Embedded profile length too large in iCCP chunk");
  177798. return;
  177799. }
  177800. if (profile_len > embedded_profile_len)
  177801. {
  177802. png_warning(png_ptr,
  177803. "Truncating profile to actual length in iCCP chunk");
  177804. profile_len = embedded_profile_len;
  177805. }
  177806. if (profile_len)
  177807. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177808. PNG_COMPRESSION_TYPE_BASE, &comp);
  177809. png_write_chunk_start(png_ptr, png_iCCP,
  177810. (png_uint_32)name_len+profile_len+2);
  177811. new_name[name_len+1]=0x00;
  177812. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177813. if (profile_len)
  177814. png_write_compressed_data_out(png_ptr, &comp);
  177815. png_write_chunk_end(png_ptr);
  177816. png_free(png_ptr, new_name);
  177817. }
  177818. #endif
  177819. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177820. void /* PRIVATE */
  177821. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177822. {
  177823. #ifdef PNG_USE_LOCAL_ARRAYS
  177824. PNG_sPLT;
  177825. #endif
  177826. png_size_t name_len;
  177827. png_charp new_name;
  177828. png_byte entrybuf[10];
  177829. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177830. int palette_size = entry_size * spalette->nentries;
  177831. png_sPLT_entryp ep;
  177832. #ifdef PNG_NO_POINTER_INDEXING
  177833. int i;
  177834. #endif
  177835. png_debug(1, "in png_write_sPLT\n");
  177836. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177837. spalette->name, &new_name))==0)
  177838. {
  177839. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177840. return;
  177841. }
  177842. png_write_chunk_start(png_ptr, png_sPLT,
  177843. (png_uint_32)(name_len + 2 + palette_size));
  177844. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177845. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177846. #ifndef PNG_NO_POINTER_INDEXING
  177847. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177848. {
  177849. if (spalette->depth == 8)
  177850. {
  177851. entrybuf[0] = (png_byte)ep->red;
  177852. entrybuf[1] = (png_byte)ep->green;
  177853. entrybuf[2] = (png_byte)ep->blue;
  177854. entrybuf[3] = (png_byte)ep->alpha;
  177855. png_save_uint_16(entrybuf + 4, ep->frequency);
  177856. }
  177857. else
  177858. {
  177859. png_save_uint_16(entrybuf + 0, ep->red);
  177860. png_save_uint_16(entrybuf + 2, ep->green);
  177861. png_save_uint_16(entrybuf + 4, ep->blue);
  177862. png_save_uint_16(entrybuf + 6, ep->alpha);
  177863. png_save_uint_16(entrybuf + 8, ep->frequency);
  177864. }
  177865. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177866. }
  177867. #else
  177868. ep=spalette->entries;
  177869. for (i=0; i>spalette->nentries; i++)
  177870. {
  177871. if (spalette->depth == 8)
  177872. {
  177873. entrybuf[0] = (png_byte)ep[i].red;
  177874. entrybuf[1] = (png_byte)ep[i].green;
  177875. entrybuf[2] = (png_byte)ep[i].blue;
  177876. entrybuf[3] = (png_byte)ep[i].alpha;
  177877. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177878. }
  177879. else
  177880. {
  177881. png_save_uint_16(entrybuf + 0, ep[i].red);
  177882. png_save_uint_16(entrybuf + 2, ep[i].green);
  177883. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177884. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177885. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177886. }
  177887. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177888. }
  177889. #endif
  177890. png_write_chunk_end(png_ptr);
  177891. png_free(png_ptr, new_name);
  177892. }
  177893. #endif
  177894. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177895. void /* PRIVATE */
  177896. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177897. {
  177898. #ifdef PNG_USE_LOCAL_ARRAYS
  177899. PNG_sBIT;
  177900. #endif
  177901. png_byte buf[4];
  177902. png_size_t size;
  177903. png_debug(1, "in png_write_sBIT\n");
  177904. if (color_type & PNG_COLOR_MASK_COLOR)
  177905. {
  177906. png_byte maxbits;
  177907. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177908. png_ptr->usr_bit_depth);
  177909. if (sbit->red == 0 || sbit->red > maxbits ||
  177910. sbit->green == 0 || sbit->green > maxbits ||
  177911. sbit->blue == 0 || sbit->blue > maxbits)
  177912. {
  177913. png_warning(png_ptr, "Invalid sBIT depth specified");
  177914. return;
  177915. }
  177916. buf[0] = sbit->red;
  177917. buf[1] = sbit->green;
  177918. buf[2] = sbit->blue;
  177919. size = 3;
  177920. }
  177921. else
  177922. {
  177923. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177924. {
  177925. png_warning(png_ptr, "Invalid sBIT depth specified");
  177926. return;
  177927. }
  177928. buf[0] = sbit->gray;
  177929. size = 1;
  177930. }
  177931. if (color_type & PNG_COLOR_MASK_ALPHA)
  177932. {
  177933. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177934. {
  177935. png_warning(png_ptr, "Invalid sBIT depth specified");
  177936. return;
  177937. }
  177938. buf[size++] = sbit->alpha;
  177939. }
  177940. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177941. }
  177942. #endif
  177943. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177944. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177945. void /* PRIVATE */
  177946. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177947. double red_x, double red_y, double green_x, double green_y,
  177948. double blue_x, double blue_y)
  177949. {
  177950. #ifdef PNG_USE_LOCAL_ARRAYS
  177951. PNG_cHRM;
  177952. #endif
  177953. png_byte buf[32];
  177954. png_uint_32 itemp;
  177955. png_debug(1, "in png_write_cHRM\n");
  177956. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177957. white_x + white_y > 1.0)
  177958. {
  177959. png_warning(png_ptr, "Invalid cHRM white point specified");
  177960. #if !defined(PNG_NO_CONSOLE_IO)
  177961. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177962. #endif
  177963. return;
  177964. }
  177965. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177966. png_save_uint_32(buf, itemp);
  177967. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177968. png_save_uint_32(buf + 4, itemp);
  177969. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177970. {
  177971. png_warning(png_ptr, "Invalid cHRM red point specified");
  177972. return;
  177973. }
  177974. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177975. png_save_uint_32(buf + 8, itemp);
  177976. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177977. png_save_uint_32(buf + 12, itemp);
  177978. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177979. {
  177980. png_warning(png_ptr, "Invalid cHRM green point specified");
  177981. return;
  177982. }
  177983. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177984. png_save_uint_32(buf + 16, itemp);
  177985. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177986. png_save_uint_32(buf + 20, itemp);
  177987. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177988. {
  177989. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177990. return;
  177991. }
  177992. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177993. png_save_uint_32(buf + 24, itemp);
  177994. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177995. png_save_uint_32(buf + 28, itemp);
  177996. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177997. }
  177998. #endif
  177999. #ifdef PNG_FIXED_POINT_SUPPORTED
  178000. void /* PRIVATE */
  178001. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  178002. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  178003. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  178004. png_fixed_point blue_y)
  178005. {
  178006. #ifdef PNG_USE_LOCAL_ARRAYS
  178007. PNG_cHRM;
  178008. #endif
  178009. png_byte buf[32];
  178010. png_debug(1, "in png_write_cHRM\n");
  178011. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  178012. {
  178013. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  178014. #if !defined(PNG_NO_CONSOLE_IO)
  178015. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  178016. #endif
  178017. return;
  178018. }
  178019. png_save_uint_32(buf, (png_uint_32)white_x);
  178020. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  178021. if (red_x + red_y > 100000L)
  178022. {
  178023. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  178024. return;
  178025. }
  178026. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  178027. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  178028. if (green_x + green_y > 100000L)
  178029. {
  178030. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  178031. return;
  178032. }
  178033. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  178034. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  178035. if (blue_x + blue_y > 100000L)
  178036. {
  178037. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  178038. return;
  178039. }
  178040. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  178041. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  178042. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178043. }
  178044. #endif
  178045. #endif
  178046. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  178047. void /* PRIVATE */
  178048. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  178049. int num_trans, int color_type)
  178050. {
  178051. #ifdef PNG_USE_LOCAL_ARRAYS
  178052. PNG_tRNS;
  178053. #endif
  178054. png_byte buf[6];
  178055. png_debug(1, "in png_write_tRNS\n");
  178056. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178057. {
  178058. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  178059. {
  178060. png_warning(png_ptr,"Invalid number of transparent colors specified");
  178061. return;
  178062. }
  178063. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  178064. }
  178065. else if (color_type == PNG_COLOR_TYPE_GRAY)
  178066. {
  178067. if(tran->gray >= (1 << png_ptr->bit_depth))
  178068. {
  178069. png_warning(png_ptr,
  178070. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  178071. return;
  178072. }
  178073. png_save_uint_16(buf, tran->gray);
  178074. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  178075. }
  178076. else if (color_type == PNG_COLOR_TYPE_RGB)
  178077. {
  178078. png_save_uint_16(buf, tran->red);
  178079. png_save_uint_16(buf + 2, tran->green);
  178080. png_save_uint_16(buf + 4, tran->blue);
  178081. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178082. {
  178083. png_warning(png_ptr,
  178084. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  178085. return;
  178086. }
  178087. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  178088. }
  178089. else
  178090. {
  178091. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  178092. }
  178093. }
  178094. #endif
  178095. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  178096. void /* PRIVATE */
  178097. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178098. {
  178099. #ifdef PNG_USE_LOCAL_ARRAYS
  178100. PNG_bKGD;
  178101. #endif
  178102. png_byte buf[6];
  178103. png_debug(1, "in png_write_bKGD\n");
  178104. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178105. {
  178106. if (
  178107. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178108. (png_ptr->num_palette ||
  178109. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178110. #endif
  178111. back->index > png_ptr->num_palette)
  178112. {
  178113. png_warning(png_ptr, "Invalid background palette index");
  178114. return;
  178115. }
  178116. buf[0] = back->index;
  178117. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178118. }
  178119. else if (color_type & PNG_COLOR_MASK_COLOR)
  178120. {
  178121. png_save_uint_16(buf, back->red);
  178122. png_save_uint_16(buf + 2, back->green);
  178123. png_save_uint_16(buf + 4, back->blue);
  178124. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178125. {
  178126. png_warning(png_ptr,
  178127. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178128. return;
  178129. }
  178130. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178131. }
  178132. else
  178133. {
  178134. if(back->gray >= (1 << png_ptr->bit_depth))
  178135. {
  178136. png_warning(png_ptr,
  178137. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178138. return;
  178139. }
  178140. png_save_uint_16(buf, back->gray);
  178141. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178142. }
  178143. }
  178144. #endif
  178145. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178146. void /* PRIVATE */
  178147. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178148. {
  178149. #ifdef PNG_USE_LOCAL_ARRAYS
  178150. PNG_hIST;
  178151. #endif
  178152. int i;
  178153. png_byte buf[3];
  178154. png_debug(1, "in png_write_hIST\n");
  178155. if (num_hist > (int)png_ptr->num_palette)
  178156. {
  178157. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178158. png_ptr->num_palette);
  178159. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178160. return;
  178161. }
  178162. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178163. for (i = 0; i < num_hist; i++)
  178164. {
  178165. png_save_uint_16(buf, hist[i]);
  178166. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178167. }
  178168. png_write_chunk_end(png_ptr);
  178169. }
  178170. #endif
  178171. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178172. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178173. png_size_t /* PRIVATE */
  178174. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178175. {
  178176. png_size_t key_len;
  178177. png_charp kp, dp;
  178178. int kflag;
  178179. int kwarn=0;
  178180. png_debug(1, "in png_check_keyword\n");
  178181. *new_key = NULL;
  178182. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178183. {
  178184. png_warning(png_ptr, "zero length keyword");
  178185. return ((png_size_t)0);
  178186. }
  178187. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178188. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178189. if (*new_key == NULL)
  178190. {
  178191. png_warning(png_ptr, "Out of memory while procesing keyword");
  178192. return ((png_size_t)0);
  178193. }
  178194. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178195. {
  178196. if ((png_byte)*kp < 0x20 ||
  178197. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178198. {
  178199. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178200. char msg[40];
  178201. png_snprintf(msg, 40,
  178202. "invalid keyword character 0x%02X", (png_byte)*kp);
  178203. png_warning(png_ptr, msg);
  178204. #else
  178205. png_warning(png_ptr, "invalid character in keyword");
  178206. #endif
  178207. *dp = ' ';
  178208. }
  178209. else
  178210. {
  178211. *dp = *kp;
  178212. }
  178213. }
  178214. *dp = '\0';
  178215. kp = *new_key + key_len - 1;
  178216. if (*kp == ' ')
  178217. {
  178218. png_warning(png_ptr, "trailing spaces removed from keyword");
  178219. while (*kp == ' ')
  178220. {
  178221. *(kp--) = '\0';
  178222. key_len--;
  178223. }
  178224. }
  178225. kp = *new_key;
  178226. if (*kp == ' ')
  178227. {
  178228. png_warning(png_ptr, "leading spaces removed from keyword");
  178229. while (*kp == ' ')
  178230. {
  178231. kp++;
  178232. key_len--;
  178233. }
  178234. }
  178235. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178236. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178237. {
  178238. if (*kp == ' ' && kflag == 0)
  178239. {
  178240. *(dp++) = *kp;
  178241. kflag = 1;
  178242. }
  178243. else if (*kp == ' ')
  178244. {
  178245. key_len--;
  178246. kwarn=1;
  178247. }
  178248. else
  178249. {
  178250. *(dp++) = *kp;
  178251. kflag = 0;
  178252. }
  178253. }
  178254. *dp = '\0';
  178255. if(kwarn)
  178256. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178257. if (key_len == 0)
  178258. {
  178259. png_free(png_ptr, *new_key);
  178260. *new_key=NULL;
  178261. png_warning(png_ptr, "Zero length keyword");
  178262. }
  178263. if (key_len > 79)
  178264. {
  178265. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178266. new_key[79] = '\0';
  178267. key_len = 79;
  178268. }
  178269. return (key_len);
  178270. }
  178271. #endif
  178272. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178273. void /* PRIVATE */
  178274. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178275. png_size_t text_len)
  178276. {
  178277. #ifdef PNG_USE_LOCAL_ARRAYS
  178278. PNG_tEXt;
  178279. #endif
  178280. png_size_t key_len;
  178281. png_charp new_key;
  178282. png_debug(1, "in png_write_tEXt\n");
  178283. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178284. {
  178285. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178286. return;
  178287. }
  178288. if (text == NULL || *text == '\0')
  178289. text_len = 0;
  178290. else
  178291. text_len = png_strlen(text);
  178292. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178293. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178294. if (text_len)
  178295. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178296. png_write_chunk_end(png_ptr);
  178297. png_free(png_ptr, new_key);
  178298. }
  178299. #endif
  178300. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178301. void /* PRIVATE */
  178302. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178303. png_size_t text_len, int compression)
  178304. {
  178305. #ifdef PNG_USE_LOCAL_ARRAYS
  178306. PNG_zTXt;
  178307. #endif
  178308. png_size_t key_len;
  178309. char buf[1];
  178310. png_charp new_key;
  178311. compression_state comp;
  178312. png_debug(1, "in png_write_zTXt\n");
  178313. comp.num_output_ptr = 0;
  178314. comp.max_output_ptr = 0;
  178315. comp.output_ptr = NULL;
  178316. comp.input = NULL;
  178317. comp.input_len = 0;
  178318. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178319. {
  178320. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178321. return;
  178322. }
  178323. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178324. {
  178325. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178326. png_free(png_ptr, new_key);
  178327. return;
  178328. }
  178329. text_len = png_strlen(text);
  178330. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178331. &comp);
  178332. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178333. (key_len+text_len+2));
  178334. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178335. png_free(png_ptr, new_key);
  178336. buf[0] = (png_byte)compression;
  178337. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178338. png_write_compressed_data_out(png_ptr, &comp);
  178339. png_write_chunk_end(png_ptr);
  178340. }
  178341. #endif
  178342. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178343. void /* PRIVATE */
  178344. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178345. png_charp lang, png_charp lang_key, png_charp text)
  178346. {
  178347. #ifdef PNG_USE_LOCAL_ARRAYS
  178348. PNG_iTXt;
  178349. #endif
  178350. png_size_t lang_len, key_len, lang_key_len, text_len;
  178351. png_charp new_lang, new_key;
  178352. png_byte cbuf[2];
  178353. compression_state comp;
  178354. png_debug(1, "in png_write_iTXt\n");
  178355. comp.num_output_ptr = 0;
  178356. comp.max_output_ptr = 0;
  178357. comp.output_ptr = NULL;
  178358. comp.input = NULL;
  178359. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178360. {
  178361. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178362. return;
  178363. }
  178364. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178365. {
  178366. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178367. new_lang = NULL;
  178368. lang_len = 0;
  178369. }
  178370. if (lang_key == NULL)
  178371. lang_key_len = 0;
  178372. else
  178373. lang_key_len = png_strlen(lang_key);
  178374. if (text == NULL)
  178375. text_len = 0;
  178376. else
  178377. text_len = png_strlen(text);
  178378. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178379. &comp);
  178380. png_write_chunk_start(png_ptr, png_iTXt,
  178381. (png_uint_32)(
  178382. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178383. + key_len
  178384. + lang_len
  178385. + lang_key_len
  178386. + text_len));
  178387. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178388. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178389. compression == PNG_TEXT_COMPRESSION_NONE)
  178390. cbuf[0] = 0;
  178391. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178392. cbuf[0] = 1;
  178393. cbuf[1] = 0;
  178394. png_write_chunk_data(png_ptr, cbuf, 2);
  178395. cbuf[0] = 0;
  178396. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178397. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178398. png_write_compressed_data_out(png_ptr, &comp);
  178399. png_write_chunk_end(png_ptr);
  178400. png_free(png_ptr, new_key);
  178401. if (new_lang)
  178402. png_free(png_ptr, new_lang);
  178403. }
  178404. #endif
  178405. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178406. void /* PRIVATE */
  178407. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178408. int unit_type)
  178409. {
  178410. #ifdef PNG_USE_LOCAL_ARRAYS
  178411. PNG_oFFs;
  178412. #endif
  178413. png_byte buf[9];
  178414. png_debug(1, "in png_write_oFFs\n");
  178415. if (unit_type >= PNG_OFFSET_LAST)
  178416. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178417. png_save_int_32(buf, x_offset);
  178418. png_save_int_32(buf + 4, y_offset);
  178419. buf[8] = (png_byte)unit_type;
  178420. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178421. }
  178422. #endif
  178423. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178424. void /* PRIVATE */
  178425. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178426. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178427. {
  178428. #ifdef PNG_USE_LOCAL_ARRAYS
  178429. PNG_pCAL;
  178430. #endif
  178431. png_size_t purpose_len, units_len, total_len;
  178432. png_uint_32p params_len;
  178433. png_byte buf[10];
  178434. png_charp new_purpose;
  178435. int i;
  178436. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178437. if (type >= PNG_EQUATION_LAST)
  178438. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178439. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178440. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178441. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178442. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178443. total_len = purpose_len + units_len + 10;
  178444. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178445. *png_sizeof(png_uint_32)));
  178446. for (i = 0; i < nparams; i++)
  178447. {
  178448. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178449. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178450. total_len += (png_size_t)params_len[i];
  178451. }
  178452. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178453. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178454. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178455. png_save_int_32(buf, X0);
  178456. png_save_int_32(buf + 4, X1);
  178457. buf[8] = (png_byte)type;
  178458. buf[9] = (png_byte)nparams;
  178459. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178460. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178461. png_free(png_ptr, new_purpose);
  178462. for (i = 0; i < nparams; i++)
  178463. {
  178464. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178465. (png_size_t)params_len[i]);
  178466. }
  178467. png_free(png_ptr, params_len);
  178468. png_write_chunk_end(png_ptr);
  178469. }
  178470. #endif
  178471. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178472. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178473. void /* PRIVATE */
  178474. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178475. {
  178476. #ifdef PNG_USE_LOCAL_ARRAYS
  178477. PNG_sCAL;
  178478. #endif
  178479. char buf[64];
  178480. png_size_t total_len;
  178481. png_debug(1, "in png_write_sCAL\n");
  178482. buf[0] = (char)unit;
  178483. #if defined(_WIN32_WCE)
  178484. {
  178485. wchar_t wc_buf[32];
  178486. size_t wc_len;
  178487. swprintf(wc_buf, TEXT("%12.12e"), width);
  178488. wc_len = wcslen(wc_buf);
  178489. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178490. total_len = wc_len + 2;
  178491. swprintf(wc_buf, TEXT("%12.12e"), height);
  178492. wc_len = wcslen(wc_buf);
  178493. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178494. NULL, NULL);
  178495. total_len += wc_len;
  178496. }
  178497. #else
  178498. png_snprintf(buf + 1, 63, "%12.12e", width);
  178499. total_len = 1 + png_strlen(buf + 1) + 1;
  178500. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178501. total_len += png_strlen(buf + total_len);
  178502. #endif
  178503. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178504. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178505. }
  178506. #else
  178507. #ifdef PNG_FIXED_POINT_SUPPORTED
  178508. void /* PRIVATE */
  178509. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178510. png_charp height)
  178511. {
  178512. #ifdef PNG_USE_LOCAL_ARRAYS
  178513. PNG_sCAL;
  178514. #endif
  178515. png_byte buf[64];
  178516. png_size_t wlen, hlen, total_len;
  178517. png_debug(1, "in png_write_sCAL_s\n");
  178518. wlen = png_strlen(width);
  178519. hlen = png_strlen(height);
  178520. total_len = wlen + hlen + 2;
  178521. if (total_len > 64)
  178522. {
  178523. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178524. return;
  178525. }
  178526. buf[0] = (png_byte)unit;
  178527. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178528. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178529. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178530. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178531. }
  178532. #endif
  178533. #endif
  178534. #endif
  178535. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178536. void /* PRIVATE */
  178537. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178538. png_uint_32 y_pixels_per_unit,
  178539. int unit_type)
  178540. {
  178541. #ifdef PNG_USE_LOCAL_ARRAYS
  178542. PNG_pHYs;
  178543. #endif
  178544. png_byte buf[9];
  178545. png_debug(1, "in png_write_pHYs\n");
  178546. if (unit_type >= PNG_RESOLUTION_LAST)
  178547. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178548. png_save_uint_32(buf, x_pixels_per_unit);
  178549. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178550. buf[8] = (png_byte)unit_type;
  178551. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178552. }
  178553. #endif
  178554. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178555. void /* PRIVATE */
  178556. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178557. {
  178558. #ifdef PNG_USE_LOCAL_ARRAYS
  178559. PNG_tIME;
  178560. #endif
  178561. png_byte buf[7];
  178562. png_debug(1, "in png_write_tIME\n");
  178563. if (mod_time->month > 12 || mod_time->month < 1 ||
  178564. mod_time->day > 31 || mod_time->day < 1 ||
  178565. mod_time->hour > 23 || mod_time->second > 60)
  178566. {
  178567. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178568. return;
  178569. }
  178570. png_save_uint_16(buf, mod_time->year);
  178571. buf[2] = mod_time->month;
  178572. buf[3] = mod_time->day;
  178573. buf[4] = mod_time->hour;
  178574. buf[5] = mod_time->minute;
  178575. buf[6] = mod_time->second;
  178576. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178577. }
  178578. #endif
  178579. void /* PRIVATE */
  178580. png_write_start_row(png_structp png_ptr)
  178581. {
  178582. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178583. #ifdef PNG_USE_LOCAL_ARRAYS
  178584. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178585. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178586. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178587. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178588. #endif
  178589. #endif
  178590. png_size_t buf_size;
  178591. png_debug(1, "in png_write_start_row\n");
  178592. buf_size = (png_size_t)(PNG_ROWBYTES(
  178593. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178594. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178595. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178596. #ifndef PNG_NO_WRITE_FILTERING
  178597. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178598. {
  178599. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178600. (png_ptr->rowbytes + 1));
  178601. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178602. }
  178603. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178604. {
  178605. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178606. png_memset(png_ptr->prev_row, 0, buf_size);
  178607. if (png_ptr->do_filter & PNG_FILTER_UP)
  178608. {
  178609. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178610. (png_ptr->rowbytes + 1));
  178611. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178612. }
  178613. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178614. {
  178615. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178616. (png_ptr->rowbytes + 1));
  178617. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178618. }
  178619. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178620. {
  178621. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178622. (png_ptr->rowbytes + 1));
  178623. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178624. }
  178625. #endif /* PNG_NO_WRITE_FILTERING */
  178626. }
  178627. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178628. if (png_ptr->interlaced)
  178629. {
  178630. if (!(png_ptr->transformations & PNG_INTERLACE))
  178631. {
  178632. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178633. png_pass_ystart[0]) / png_pass_yinc[0];
  178634. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178635. png_pass_start[0]) / png_pass_inc[0];
  178636. }
  178637. else
  178638. {
  178639. png_ptr->num_rows = png_ptr->height;
  178640. png_ptr->usr_width = png_ptr->width;
  178641. }
  178642. }
  178643. else
  178644. #endif
  178645. {
  178646. png_ptr->num_rows = png_ptr->height;
  178647. png_ptr->usr_width = png_ptr->width;
  178648. }
  178649. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178650. png_ptr->zstream.next_out = png_ptr->zbuf;
  178651. }
  178652. void /* PRIVATE */
  178653. png_write_finish_row(png_structp png_ptr)
  178654. {
  178655. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178656. #ifdef PNG_USE_LOCAL_ARRAYS
  178657. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178658. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178659. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178660. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178661. #endif
  178662. #endif
  178663. int ret;
  178664. png_debug(1, "in png_write_finish_row\n");
  178665. png_ptr->row_number++;
  178666. if (png_ptr->row_number < png_ptr->num_rows)
  178667. return;
  178668. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178669. if (png_ptr->interlaced)
  178670. {
  178671. png_ptr->row_number = 0;
  178672. if (png_ptr->transformations & PNG_INTERLACE)
  178673. {
  178674. png_ptr->pass++;
  178675. }
  178676. else
  178677. {
  178678. do
  178679. {
  178680. png_ptr->pass++;
  178681. if (png_ptr->pass >= 7)
  178682. break;
  178683. png_ptr->usr_width = (png_ptr->width +
  178684. png_pass_inc[png_ptr->pass] - 1 -
  178685. png_pass_start[png_ptr->pass]) /
  178686. png_pass_inc[png_ptr->pass];
  178687. png_ptr->num_rows = (png_ptr->height +
  178688. png_pass_yinc[png_ptr->pass] - 1 -
  178689. png_pass_ystart[png_ptr->pass]) /
  178690. png_pass_yinc[png_ptr->pass];
  178691. if (png_ptr->transformations & PNG_INTERLACE)
  178692. break;
  178693. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178694. }
  178695. if (png_ptr->pass < 7)
  178696. {
  178697. if (png_ptr->prev_row != NULL)
  178698. png_memset(png_ptr->prev_row, 0,
  178699. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178700. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178701. return;
  178702. }
  178703. }
  178704. #endif
  178705. do
  178706. {
  178707. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178708. if (ret == Z_OK)
  178709. {
  178710. if (!(png_ptr->zstream.avail_out))
  178711. {
  178712. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178713. png_ptr->zstream.next_out = png_ptr->zbuf;
  178714. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178715. }
  178716. }
  178717. else if (ret != Z_STREAM_END)
  178718. {
  178719. if (png_ptr->zstream.msg != NULL)
  178720. png_error(png_ptr, png_ptr->zstream.msg);
  178721. else
  178722. png_error(png_ptr, "zlib error");
  178723. }
  178724. } while (ret != Z_STREAM_END);
  178725. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178726. {
  178727. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178728. png_ptr->zstream.avail_out);
  178729. }
  178730. deflateReset(&png_ptr->zstream);
  178731. png_ptr->zstream.data_type = Z_BINARY;
  178732. }
  178733. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178734. void /* PRIVATE */
  178735. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178736. {
  178737. #ifdef PNG_USE_LOCAL_ARRAYS
  178738. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178739. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178740. #endif
  178741. png_debug(1, "in png_do_write_interlace\n");
  178742. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178743. if (row != NULL && row_info != NULL && pass < 6)
  178744. #else
  178745. if (pass < 6)
  178746. #endif
  178747. {
  178748. switch (row_info->pixel_depth)
  178749. {
  178750. case 1:
  178751. {
  178752. png_bytep sp;
  178753. png_bytep dp;
  178754. int shift;
  178755. int d;
  178756. int value;
  178757. png_uint_32 i;
  178758. png_uint_32 row_width = row_info->width;
  178759. dp = row;
  178760. d = 0;
  178761. shift = 7;
  178762. for (i = png_pass_start[pass]; i < row_width;
  178763. i += png_pass_inc[pass])
  178764. {
  178765. sp = row + (png_size_t)(i >> 3);
  178766. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178767. d |= (value << shift);
  178768. if (shift == 0)
  178769. {
  178770. shift = 7;
  178771. *dp++ = (png_byte)d;
  178772. d = 0;
  178773. }
  178774. else
  178775. shift--;
  178776. }
  178777. if (shift != 7)
  178778. *dp = (png_byte)d;
  178779. break;
  178780. }
  178781. case 2:
  178782. {
  178783. png_bytep sp;
  178784. png_bytep dp;
  178785. int shift;
  178786. int d;
  178787. int value;
  178788. png_uint_32 i;
  178789. png_uint_32 row_width = row_info->width;
  178790. dp = row;
  178791. shift = 6;
  178792. d = 0;
  178793. for (i = png_pass_start[pass]; i < row_width;
  178794. i += png_pass_inc[pass])
  178795. {
  178796. sp = row + (png_size_t)(i >> 2);
  178797. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178798. d |= (value << shift);
  178799. if (shift == 0)
  178800. {
  178801. shift = 6;
  178802. *dp++ = (png_byte)d;
  178803. d = 0;
  178804. }
  178805. else
  178806. shift -= 2;
  178807. }
  178808. if (shift != 6)
  178809. *dp = (png_byte)d;
  178810. break;
  178811. }
  178812. case 4:
  178813. {
  178814. png_bytep sp;
  178815. png_bytep dp;
  178816. int shift;
  178817. int d;
  178818. int value;
  178819. png_uint_32 i;
  178820. png_uint_32 row_width = row_info->width;
  178821. dp = row;
  178822. shift = 4;
  178823. d = 0;
  178824. for (i = png_pass_start[pass]; i < row_width;
  178825. i += png_pass_inc[pass])
  178826. {
  178827. sp = row + (png_size_t)(i >> 1);
  178828. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178829. d |= (value << shift);
  178830. if (shift == 0)
  178831. {
  178832. shift = 4;
  178833. *dp++ = (png_byte)d;
  178834. d = 0;
  178835. }
  178836. else
  178837. shift -= 4;
  178838. }
  178839. if (shift != 4)
  178840. *dp = (png_byte)d;
  178841. break;
  178842. }
  178843. default:
  178844. {
  178845. png_bytep sp;
  178846. png_bytep dp;
  178847. png_uint_32 i;
  178848. png_uint_32 row_width = row_info->width;
  178849. png_size_t pixel_bytes;
  178850. dp = row;
  178851. pixel_bytes = (row_info->pixel_depth >> 3);
  178852. for (i = png_pass_start[pass]; i < row_width;
  178853. i += png_pass_inc[pass])
  178854. {
  178855. sp = row + (png_size_t)i * pixel_bytes;
  178856. if (dp != sp)
  178857. png_memcpy(dp, sp, pixel_bytes);
  178858. dp += pixel_bytes;
  178859. }
  178860. break;
  178861. }
  178862. }
  178863. row_info->width = (row_info->width +
  178864. png_pass_inc[pass] - 1 -
  178865. png_pass_start[pass]) /
  178866. png_pass_inc[pass];
  178867. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178868. row_info->width);
  178869. }
  178870. }
  178871. #endif
  178872. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178873. #define PNG_HISHIFT 10
  178874. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178875. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178876. void /* PRIVATE */
  178877. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178878. {
  178879. png_bytep best_row;
  178880. #ifndef PNG_NO_WRITE_FILTER
  178881. png_bytep prev_row, row_buf;
  178882. png_uint_32 mins, bpp;
  178883. png_byte filter_to_do = png_ptr->do_filter;
  178884. png_uint_32 row_bytes = row_info->rowbytes;
  178885. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178886. int num_p_filters = (int)png_ptr->num_prev_filters;
  178887. #endif
  178888. png_debug(1, "in png_write_find_filter\n");
  178889. bpp = (row_info->pixel_depth + 7) >> 3;
  178890. prev_row = png_ptr->prev_row;
  178891. #endif
  178892. best_row = png_ptr->row_buf;
  178893. #ifndef PNG_NO_WRITE_FILTER
  178894. row_buf = best_row;
  178895. mins = PNG_MAXSUM;
  178896. if ((filter_to_do & PNG_FILTER_NONE) &&
  178897. filter_to_do != PNG_FILTER_NONE)
  178898. {
  178899. png_bytep rp;
  178900. png_uint_32 sum = 0;
  178901. png_uint_32 i;
  178902. int v;
  178903. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178904. {
  178905. v = *rp;
  178906. sum += (v < 128) ? v : 256 - v;
  178907. }
  178908. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178909. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178910. {
  178911. png_uint_32 sumhi, sumlo;
  178912. int j;
  178913. sumlo = sum & PNG_LOMASK;
  178914. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178915. for (j = 0; j < num_p_filters; j++)
  178916. {
  178917. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178918. {
  178919. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178920. PNG_WEIGHT_SHIFT;
  178921. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178922. PNG_WEIGHT_SHIFT;
  178923. }
  178924. }
  178925. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178926. PNG_COST_SHIFT;
  178927. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178928. PNG_COST_SHIFT;
  178929. if (sumhi > PNG_HIMASK)
  178930. sum = PNG_MAXSUM;
  178931. else
  178932. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178933. }
  178934. #endif
  178935. mins = sum;
  178936. }
  178937. if (filter_to_do == PNG_FILTER_SUB)
  178938. {
  178939. png_bytep rp, lp, dp;
  178940. png_uint_32 i;
  178941. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178942. i++, rp++, dp++)
  178943. {
  178944. *dp = *rp;
  178945. }
  178946. for (lp = row_buf + 1; i < row_bytes;
  178947. i++, rp++, lp++, dp++)
  178948. {
  178949. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178950. }
  178951. best_row = png_ptr->sub_row;
  178952. }
  178953. else if (filter_to_do & PNG_FILTER_SUB)
  178954. {
  178955. png_bytep rp, dp, lp;
  178956. png_uint_32 sum = 0, lmins = mins;
  178957. png_uint_32 i;
  178958. int v;
  178959. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178960. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178961. {
  178962. int j;
  178963. png_uint_32 lmhi, lmlo;
  178964. lmlo = lmins & PNG_LOMASK;
  178965. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178966. for (j = 0; j < num_p_filters; j++)
  178967. {
  178968. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178969. {
  178970. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178971. PNG_WEIGHT_SHIFT;
  178972. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178973. PNG_WEIGHT_SHIFT;
  178974. }
  178975. }
  178976. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178977. PNG_COST_SHIFT;
  178978. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178979. PNG_COST_SHIFT;
  178980. if (lmhi > PNG_HIMASK)
  178981. lmins = PNG_MAXSUM;
  178982. else
  178983. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178984. }
  178985. #endif
  178986. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178987. i++, rp++, dp++)
  178988. {
  178989. v = *dp = *rp;
  178990. sum += (v < 128) ? v : 256 - v;
  178991. }
  178992. for (lp = row_buf + 1; i < row_bytes;
  178993. i++, rp++, lp++, dp++)
  178994. {
  178995. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178996. sum += (v < 128) ? v : 256 - v;
  178997. if (sum > lmins) /* We are already worse, don't continue. */
  178998. break;
  178999. }
  179000. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179001. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179002. {
  179003. int j;
  179004. png_uint_32 sumhi, sumlo;
  179005. sumlo = sum & PNG_LOMASK;
  179006. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179007. for (j = 0; j < num_p_filters; j++)
  179008. {
  179009. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179010. {
  179011. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  179012. PNG_WEIGHT_SHIFT;
  179013. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  179014. PNG_WEIGHT_SHIFT;
  179015. }
  179016. }
  179017. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179018. PNG_COST_SHIFT;
  179019. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179020. PNG_COST_SHIFT;
  179021. if (sumhi > PNG_HIMASK)
  179022. sum = PNG_MAXSUM;
  179023. else
  179024. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179025. }
  179026. #endif
  179027. if (sum < mins)
  179028. {
  179029. mins = sum;
  179030. best_row = png_ptr->sub_row;
  179031. }
  179032. }
  179033. if (filter_to_do == PNG_FILTER_UP)
  179034. {
  179035. png_bytep rp, dp, pp;
  179036. png_uint_32 i;
  179037. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179038. pp = prev_row + 1; i < row_bytes;
  179039. i++, rp++, pp++, dp++)
  179040. {
  179041. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  179042. }
  179043. best_row = png_ptr->up_row;
  179044. }
  179045. else if (filter_to_do & PNG_FILTER_UP)
  179046. {
  179047. png_bytep rp, dp, pp;
  179048. png_uint_32 sum = 0, lmins = mins;
  179049. png_uint_32 i;
  179050. int v;
  179051. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179052. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179053. {
  179054. int j;
  179055. png_uint_32 lmhi, lmlo;
  179056. lmlo = lmins & PNG_LOMASK;
  179057. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179058. for (j = 0; j < num_p_filters; j++)
  179059. {
  179060. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179061. {
  179062. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179063. PNG_WEIGHT_SHIFT;
  179064. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179065. PNG_WEIGHT_SHIFT;
  179066. }
  179067. }
  179068. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179069. PNG_COST_SHIFT;
  179070. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179071. PNG_COST_SHIFT;
  179072. if (lmhi > PNG_HIMASK)
  179073. lmins = PNG_MAXSUM;
  179074. else
  179075. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179076. }
  179077. #endif
  179078. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179079. pp = prev_row + 1; i < row_bytes; i++)
  179080. {
  179081. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179082. sum += (v < 128) ? v : 256 - v;
  179083. if (sum > lmins) /* We are already worse, don't continue. */
  179084. break;
  179085. }
  179086. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179087. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179088. {
  179089. int j;
  179090. png_uint_32 sumhi, sumlo;
  179091. sumlo = sum & PNG_LOMASK;
  179092. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179093. for (j = 0; j < num_p_filters; j++)
  179094. {
  179095. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179096. {
  179097. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179098. PNG_WEIGHT_SHIFT;
  179099. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179100. PNG_WEIGHT_SHIFT;
  179101. }
  179102. }
  179103. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179104. PNG_COST_SHIFT;
  179105. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179106. PNG_COST_SHIFT;
  179107. if (sumhi > PNG_HIMASK)
  179108. sum = PNG_MAXSUM;
  179109. else
  179110. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179111. }
  179112. #endif
  179113. if (sum < mins)
  179114. {
  179115. mins = sum;
  179116. best_row = png_ptr->up_row;
  179117. }
  179118. }
  179119. if (filter_to_do == PNG_FILTER_AVG)
  179120. {
  179121. png_bytep rp, dp, pp, lp;
  179122. png_uint_32 i;
  179123. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179124. pp = prev_row + 1; i < bpp; i++)
  179125. {
  179126. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179127. }
  179128. for (lp = row_buf + 1; i < row_bytes; i++)
  179129. {
  179130. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179131. & 0xff);
  179132. }
  179133. best_row = png_ptr->avg_row;
  179134. }
  179135. else if (filter_to_do & PNG_FILTER_AVG)
  179136. {
  179137. png_bytep rp, dp, pp, lp;
  179138. png_uint_32 sum = 0, lmins = mins;
  179139. png_uint_32 i;
  179140. int v;
  179141. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179142. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179143. {
  179144. int j;
  179145. png_uint_32 lmhi, lmlo;
  179146. lmlo = lmins & PNG_LOMASK;
  179147. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179148. for (j = 0; j < num_p_filters; j++)
  179149. {
  179150. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179151. {
  179152. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179153. PNG_WEIGHT_SHIFT;
  179154. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179155. PNG_WEIGHT_SHIFT;
  179156. }
  179157. }
  179158. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179159. PNG_COST_SHIFT;
  179160. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179161. PNG_COST_SHIFT;
  179162. if (lmhi > PNG_HIMASK)
  179163. lmins = PNG_MAXSUM;
  179164. else
  179165. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179166. }
  179167. #endif
  179168. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179169. pp = prev_row + 1; i < bpp; i++)
  179170. {
  179171. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179172. sum += (v < 128) ? v : 256 - v;
  179173. }
  179174. for (lp = row_buf + 1; i < row_bytes; i++)
  179175. {
  179176. v = *dp++ =
  179177. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179178. sum += (v < 128) ? v : 256 - v;
  179179. if (sum > lmins) /* We are already worse, don't continue. */
  179180. break;
  179181. }
  179182. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179183. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179184. {
  179185. int j;
  179186. png_uint_32 sumhi, sumlo;
  179187. sumlo = sum & PNG_LOMASK;
  179188. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179189. for (j = 0; j < num_p_filters; j++)
  179190. {
  179191. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179192. {
  179193. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179194. PNG_WEIGHT_SHIFT;
  179195. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179196. PNG_WEIGHT_SHIFT;
  179197. }
  179198. }
  179199. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179200. PNG_COST_SHIFT;
  179201. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179202. PNG_COST_SHIFT;
  179203. if (sumhi > PNG_HIMASK)
  179204. sum = PNG_MAXSUM;
  179205. else
  179206. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179207. }
  179208. #endif
  179209. if (sum < mins)
  179210. {
  179211. mins = sum;
  179212. best_row = png_ptr->avg_row;
  179213. }
  179214. }
  179215. if (filter_to_do == PNG_FILTER_PAETH)
  179216. {
  179217. png_bytep rp, dp, pp, cp, lp;
  179218. png_uint_32 i;
  179219. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179220. pp = prev_row + 1; i < bpp; i++)
  179221. {
  179222. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179223. }
  179224. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179225. {
  179226. int a, b, c, pa, pb, pc, p;
  179227. b = *pp++;
  179228. c = *cp++;
  179229. a = *lp++;
  179230. p = b - c;
  179231. pc = a - c;
  179232. #ifdef PNG_USE_ABS
  179233. pa = abs(p);
  179234. pb = abs(pc);
  179235. pc = abs(p + pc);
  179236. #else
  179237. pa = p < 0 ? -p : p;
  179238. pb = pc < 0 ? -pc : pc;
  179239. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179240. #endif
  179241. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179242. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179243. }
  179244. best_row = png_ptr->paeth_row;
  179245. }
  179246. else if (filter_to_do & PNG_FILTER_PAETH)
  179247. {
  179248. png_bytep rp, dp, pp, cp, lp;
  179249. png_uint_32 sum = 0, lmins = mins;
  179250. png_uint_32 i;
  179251. int v;
  179252. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179253. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179254. {
  179255. int j;
  179256. png_uint_32 lmhi, lmlo;
  179257. lmlo = lmins & PNG_LOMASK;
  179258. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179259. for (j = 0; j < num_p_filters; j++)
  179260. {
  179261. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179262. {
  179263. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179264. PNG_WEIGHT_SHIFT;
  179265. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179266. PNG_WEIGHT_SHIFT;
  179267. }
  179268. }
  179269. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179270. PNG_COST_SHIFT;
  179271. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179272. PNG_COST_SHIFT;
  179273. if (lmhi > PNG_HIMASK)
  179274. lmins = PNG_MAXSUM;
  179275. else
  179276. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179277. }
  179278. #endif
  179279. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179280. pp = prev_row + 1; i < bpp; i++)
  179281. {
  179282. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179283. sum += (v < 128) ? v : 256 - v;
  179284. }
  179285. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179286. {
  179287. int a, b, c, pa, pb, pc, p;
  179288. b = *pp++;
  179289. c = *cp++;
  179290. a = *lp++;
  179291. #ifndef PNG_SLOW_PAETH
  179292. p = b - c;
  179293. pc = a - c;
  179294. #ifdef PNG_USE_ABS
  179295. pa = abs(p);
  179296. pb = abs(pc);
  179297. pc = abs(p + pc);
  179298. #else
  179299. pa = p < 0 ? -p : p;
  179300. pb = pc < 0 ? -pc : pc;
  179301. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179302. #endif
  179303. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179304. #else /* PNG_SLOW_PAETH */
  179305. p = a + b - c;
  179306. pa = abs(p - a);
  179307. pb = abs(p - b);
  179308. pc = abs(p - c);
  179309. if (pa <= pb && pa <= pc)
  179310. p = a;
  179311. else if (pb <= pc)
  179312. p = b;
  179313. else
  179314. p = c;
  179315. #endif /* PNG_SLOW_PAETH */
  179316. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179317. sum += (v < 128) ? v : 256 - v;
  179318. if (sum > lmins) /* We are already worse, don't continue. */
  179319. break;
  179320. }
  179321. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179322. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179323. {
  179324. int j;
  179325. png_uint_32 sumhi, sumlo;
  179326. sumlo = sum & PNG_LOMASK;
  179327. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179328. for (j = 0; j < num_p_filters; j++)
  179329. {
  179330. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179331. {
  179332. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179333. PNG_WEIGHT_SHIFT;
  179334. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179335. PNG_WEIGHT_SHIFT;
  179336. }
  179337. }
  179338. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179339. PNG_COST_SHIFT;
  179340. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179341. PNG_COST_SHIFT;
  179342. if (sumhi > PNG_HIMASK)
  179343. sum = PNG_MAXSUM;
  179344. else
  179345. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179346. }
  179347. #endif
  179348. if (sum < mins)
  179349. {
  179350. best_row = png_ptr->paeth_row;
  179351. }
  179352. }
  179353. #endif /* PNG_NO_WRITE_FILTER */
  179354. png_write_filtered_row(png_ptr, best_row);
  179355. #ifndef PNG_NO_WRITE_FILTER
  179356. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179357. if (png_ptr->num_prev_filters > 0)
  179358. {
  179359. int j;
  179360. for (j = 1; j < num_p_filters; j++)
  179361. {
  179362. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179363. }
  179364. png_ptr->prev_filters[j] = best_row[0];
  179365. }
  179366. #endif
  179367. #endif /* PNG_NO_WRITE_FILTER */
  179368. }
  179369. void /* PRIVATE */
  179370. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179371. {
  179372. png_debug(1, "in png_write_filtered_row\n");
  179373. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179374. png_ptr->zstream.next_in = filtered_row;
  179375. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179376. do
  179377. {
  179378. int ret; /* return of zlib */
  179379. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179380. if (ret != Z_OK)
  179381. {
  179382. if (png_ptr->zstream.msg != NULL)
  179383. png_error(png_ptr, png_ptr->zstream.msg);
  179384. else
  179385. png_error(png_ptr, "zlib error");
  179386. }
  179387. if (!(png_ptr->zstream.avail_out))
  179388. {
  179389. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179390. png_ptr->zstream.next_out = png_ptr->zbuf;
  179391. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179392. }
  179393. } while (png_ptr->zstream.avail_in);
  179394. if (png_ptr->prev_row != NULL)
  179395. {
  179396. png_bytep tptr;
  179397. tptr = png_ptr->prev_row;
  179398. png_ptr->prev_row = png_ptr->row_buf;
  179399. png_ptr->row_buf = tptr;
  179400. }
  179401. png_write_finish_row(png_ptr);
  179402. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179403. png_ptr->flush_rows++;
  179404. if (png_ptr->flush_dist > 0 &&
  179405. png_ptr->flush_rows >= png_ptr->flush_dist)
  179406. {
  179407. png_write_flush(png_ptr);
  179408. }
  179409. #endif
  179410. }
  179411. #endif /* PNG_WRITE_SUPPORTED */
  179412. /*** End of inlined file: pngwutil.c ***/
  179413. }
  179414. #else
  179415. #define PNG_INTERNAL
  179416. #define PNG_SETJMP_NOT_SUPPORTED
  179417. #include <png.h>
  179418. #include <pngconf.h>
  179419. #endif
  179420. }
  179421. #ifdef _MSC_VER
  179422. #pragma warning (pop)
  179423. #endif
  179424. BEGIN_JUCE_NAMESPACE
  179425. using namespace pnglibNamespace;
  179426. using ::calloc;
  179427. using ::malloc;
  179428. using ::free;
  179429. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179430. {
  179431. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179432. in->read (data, (int) length);
  179433. }
  179434. struct PNGErrorStruct {};
  179435. static void pngErrorCallback (png_structp, png_const_charp)
  179436. {
  179437. throw PNGErrorStruct();
  179438. }
  179439. Image* juce_loadPNGImageFromStream (InputStream& in)
  179440. {
  179441. Image* image = 0;
  179442. png_structp pngReadStruct;
  179443. png_infop pngInfoStruct;
  179444. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179445. if (pngReadStruct != 0)
  179446. {
  179447. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179448. if (pngInfoStruct == 0)
  179449. {
  179450. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179451. return 0;
  179452. }
  179453. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179454. // read the header..
  179455. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179456. png_uint_32 width, height;
  179457. int bitDepth, colorType, interlaceType;
  179458. png_read_info (pngReadStruct, pngInfoStruct);
  179459. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179460. &width, &height,
  179461. &bitDepth, &colorType,
  179462. &interlaceType, 0, 0);
  179463. if (bitDepth == 16)
  179464. png_set_strip_16 (pngReadStruct);
  179465. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179466. png_set_expand (pngReadStruct);
  179467. if (bitDepth < 8)
  179468. png_set_expand (pngReadStruct);
  179469. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179470. png_set_expand (pngReadStruct);
  179471. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179472. png_set_gray_to_rgb (pngReadStruct);
  179473. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179474. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179475. || pngInfoStruct->num_trans > 0;
  179476. // Load the image into a temp buffer in the pnglib format..
  179477. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179478. {
  179479. HeapBlock <png_bytep> rows (height);
  179480. for (int y = (int) height; --y >= 0;)
  179481. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179482. png_read_image (pngReadStruct, rows);
  179483. png_read_end (pngReadStruct, pngInfoStruct);
  179484. }
  179485. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179486. // now convert the data to a juce image format..
  179487. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179488. (int) width, (int) height, hasAlphaChan);
  179489. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179490. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179491. uint8* srcRow = tempBuffer;
  179492. uint8* destRow = destData.data;
  179493. for (int y = 0; y < (int) height; ++y)
  179494. {
  179495. const uint8* src = srcRow;
  179496. srcRow += (width << 2);
  179497. uint8* dest = destRow;
  179498. destRow += destData.lineStride;
  179499. if (hasAlphaChan)
  179500. {
  179501. for (int i = (int) width; --i >= 0;)
  179502. {
  179503. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179504. ((PixelARGB*) dest)->premultiply();
  179505. dest += destData.pixelStride;
  179506. src += 4;
  179507. }
  179508. }
  179509. else
  179510. {
  179511. for (int i = (int) width; --i >= 0;)
  179512. {
  179513. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179514. dest += destData.pixelStride;
  179515. src += 4;
  179516. }
  179517. }
  179518. }
  179519. }
  179520. return image;
  179521. }
  179522. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179523. {
  179524. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179525. const bool ok = out->write (data, (int) length);
  179526. (void) ok;
  179527. jassert (ok);
  179528. }
  179529. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179530. {
  179531. const int width = image.getWidth();
  179532. const int height = image.getHeight();
  179533. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179534. if (pngWriteStruct == 0)
  179535. return false;
  179536. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179537. if (pngInfoStruct == 0)
  179538. {
  179539. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179540. return false;
  179541. }
  179542. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179543. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179544. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179545. : PNG_COLOR_TYPE_RGB,
  179546. PNG_INTERLACE_NONE,
  179547. PNG_COMPRESSION_TYPE_BASE,
  179548. PNG_FILTER_TYPE_BASE);
  179549. HeapBlock <png_byte> rowData (width * 4);
  179550. png_color_8 sig_bit;
  179551. sig_bit.red = 8;
  179552. sig_bit.green = 8;
  179553. sig_bit.blue = 8;
  179554. sig_bit.alpha = 8;
  179555. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179556. png_write_info (pngWriteStruct, pngInfoStruct);
  179557. png_set_shift (pngWriteStruct, &sig_bit);
  179558. png_set_packing (pngWriteStruct);
  179559. const Image::BitmapData srcData (image, 0, 0, width, height);
  179560. for (int y = 0; y < height; ++y)
  179561. {
  179562. uint8* dst = (uint8*) rowData;
  179563. const uint8* src = srcData.getLinePointer (y);
  179564. if (image.hasAlphaChannel())
  179565. {
  179566. for (int i = width; --i >= 0;)
  179567. {
  179568. PixelARGB p (*(const PixelARGB*) src);
  179569. p.unpremultiply();
  179570. *dst++ = p.getRed();
  179571. *dst++ = p.getGreen();
  179572. *dst++ = p.getBlue();
  179573. *dst++ = p.getAlpha();
  179574. src += srcData.pixelStride;
  179575. }
  179576. }
  179577. else
  179578. {
  179579. for (int i = width; --i >= 0;)
  179580. {
  179581. *dst++ = ((const PixelRGB*) src)->getRed();
  179582. *dst++ = ((const PixelRGB*) src)->getGreen();
  179583. *dst++ = ((const PixelRGB*) src)->getBlue();
  179584. src += srcData.pixelStride;
  179585. }
  179586. }
  179587. png_write_rows (pngWriteStruct, &rowData, 1);
  179588. }
  179589. png_write_end (pngWriteStruct, pngInfoStruct);
  179590. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179591. out.flush();
  179592. return true;
  179593. }
  179594. END_JUCE_NAMESPACE
  179595. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179596. #endif
  179597. //==============================================================================
  179598. #if JUCE_BUILD_NATIVE
  179599. #if JUCE_WINDOWS
  179600. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179601. BEGIN_JUCE_NAMESPACE
  179602. #define JUCE_INCLUDED_FILE 1
  179603. // Now include the actual code files..
  179604. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179605. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179606. // compiled on its own).
  179607. #if JUCE_INCLUDED_FILE
  179608. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179609. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179610. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179611. #ifndef DOXYGEN
  179612. // use with DynamicLibraryLoader to simplify importing functions
  179613. //
  179614. // functionName: function to import
  179615. // localFunctionName: name you want to use to actually call it (must be different)
  179616. // returnType: the return type
  179617. // object: the DynamicLibraryLoader to use
  179618. // params: list of params (bracketed)
  179619. //
  179620. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179621. typedef returnType (WINAPI *type##localFunctionName) params; \
  179622. type##localFunctionName localFunctionName \
  179623. = (type##localFunctionName)object.findProcAddress (#functionName);
  179624. // loads and unloads a DLL automatically
  179625. class JUCE_API DynamicLibraryLoader
  179626. {
  179627. public:
  179628. DynamicLibraryLoader (const String& name);
  179629. ~DynamicLibraryLoader();
  179630. void* findProcAddress (const String& functionName);
  179631. private:
  179632. void* libHandle;
  179633. };
  179634. #endif
  179635. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179636. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179637. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179638. {
  179639. libHandle = LoadLibrary (name);
  179640. }
  179641. DynamicLibraryLoader::~DynamicLibraryLoader()
  179642. {
  179643. FreeLibrary ((HMODULE) libHandle);
  179644. }
  179645. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179646. {
  179647. return (void*) GetProcAddress ((HMODULE) libHandle, functionName);
  179648. }
  179649. #endif
  179650. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179651. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179652. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179653. // compiled on its own).
  179654. #if JUCE_INCLUDED_FILE
  179655. extern void juce_initialiseThreadEvents();
  179656. void Logger::outputDebugString (const String& text) throw()
  179657. {
  179658. OutputDebugString (text + T("\n"));
  179659. }
  179660. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179661. {
  179662. String text;
  179663. va_list args;
  179664. va_start (args, format);
  179665. text.vprintf(format, args);
  179666. outputDebugString (text);
  179667. }
  179668. static int64 hiResTicksPerSecond;
  179669. static double hiResTicksScaleFactor;
  179670. #if JUCE_USE_INTRINSICS
  179671. // CPU info functions using intrinsics...
  179672. #pragma intrinsic (__cpuid)
  179673. #pragma intrinsic (__rdtsc)
  179674. const String SystemStats::getCpuVendor() throw()
  179675. {
  179676. int info [4];
  179677. __cpuid (info, 0);
  179678. char v [12];
  179679. memcpy (v, info + 1, 4);
  179680. memcpy (v + 4, info + 3, 4);
  179681. memcpy (v + 8, info + 2, 4);
  179682. return String (v, 12);
  179683. }
  179684. #else
  179685. // CPU info functions using old fashioned inline asm...
  179686. static void juce_getCpuVendor (char* const v)
  179687. {
  179688. int vendor[4];
  179689. zeromem (vendor, 16);
  179690. #ifdef JUCE_64BIT
  179691. #else
  179692. #ifndef __MINGW32__
  179693. __try
  179694. #endif
  179695. {
  179696. #if JUCE_GCC
  179697. unsigned int dummy = 0;
  179698. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179699. #else
  179700. __asm
  179701. {
  179702. mov eax, 0
  179703. cpuid
  179704. mov [vendor], ebx
  179705. mov [vendor + 4], edx
  179706. mov [vendor + 8], ecx
  179707. }
  179708. #endif
  179709. }
  179710. #ifndef __MINGW32__
  179711. __except (EXCEPTION_EXECUTE_HANDLER)
  179712. {
  179713. *v = 0;
  179714. }
  179715. #endif
  179716. #endif
  179717. memcpy (v, vendor, 16);
  179718. }
  179719. const String SystemStats::getCpuVendor() throw()
  179720. {
  179721. char v [16];
  179722. juce_getCpuVendor (v);
  179723. return String (v, 16);
  179724. }
  179725. #endif
  179726. struct CPUFlags
  179727. {
  179728. bool hasMMX : 1;
  179729. bool hasSSE : 1;
  179730. bool hasSSE2 : 1;
  179731. bool has3DNow : 1;
  179732. };
  179733. static CPUFlags cpuFlags;
  179734. bool SystemStats::hasMMX() throw()
  179735. {
  179736. return cpuFlags.hasMMX;
  179737. }
  179738. bool SystemStats::hasSSE() throw()
  179739. {
  179740. return cpuFlags.hasSSE;
  179741. }
  179742. bool SystemStats::hasSSE2() throw()
  179743. {
  179744. return cpuFlags.hasSSE2;
  179745. }
  179746. bool SystemStats::has3DNow() throw()
  179747. {
  179748. return cpuFlags.has3DNow;
  179749. }
  179750. void SystemStats::initialiseStats() throw()
  179751. {
  179752. juce_initialiseThreadEvents();
  179753. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179754. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179755. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179756. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179757. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179758. #else
  179759. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179760. #endif
  179761. LARGE_INTEGER f;
  179762. QueryPerformanceFrequency (&f);
  179763. hiResTicksPerSecond = f.QuadPart;
  179764. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179765. String s (SystemStats::getJUCEVersion());
  179766. #ifdef JUCE_DEBUG
  179767. const MMRESULT res = timeBeginPeriod (1);
  179768. jassert (res == TIMERR_NOERROR);
  179769. #else
  179770. timeBeginPeriod (1);
  179771. #endif
  179772. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179773. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179774. #endif
  179775. }
  179776. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179777. {
  179778. OSVERSIONINFO info;
  179779. info.dwOSVersionInfoSize = sizeof (info);
  179780. GetVersionEx (&info);
  179781. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179782. {
  179783. switch (info.dwMajorVersion)
  179784. {
  179785. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179786. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179787. default: jassertfalse; break; // !! not a supported OS!
  179788. }
  179789. }
  179790. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179791. {
  179792. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179793. return Win98;
  179794. }
  179795. return UnknownOS;
  179796. }
  179797. const String SystemStats::getOperatingSystemName() throw()
  179798. {
  179799. const char* name = "Unknown OS";
  179800. switch (getOperatingSystemType())
  179801. {
  179802. case Windows7: name = "Windows 7"; break;
  179803. case WinVista: name = "Windows Vista"; break;
  179804. case WinXP: name = "Windows XP"; break;
  179805. case Win2000: name = "Windows 2000"; break;
  179806. case Win98: name = "Windows 98"; break;
  179807. default: jassertfalse; break; // !! new type of OS?
  179808. }
  179809. return name;
  179810. }
  179811. bool SystemStats::isOperatingSystem64Bit() throw()
  179812. {
  179813. #ifdef _WIN64
  179814. return true;
  179815. #else
  179816. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179817. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179818. BOOL isWow64 = FALSE;
  179819. return (fnIsWow64Process != 0)
  179820. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179821. && (isWow64 != FALSE);
  179822. #endif
  179823. }
  179824. int SystemStats::getMemorySizeInMegabytes() throw()
  179825. {
  179826. MEMORYSTATUSEX mem;
  179827. mem.dwLength = sizeof (mem);
  179828. GlobalMemoryStatusEx (&mem);
  179829. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179830. }
  179831. int SystemStats::getNumCpus() throw()
  179832. {
  179833. SYSTEM_INFO systemInfo;
  179834. GetSystemInfo (&systemInfo);
  179835. return systemInfo.dwNumberOfProcessors;
  179836. }
  179837. uint32 juce_millisecondsSinceStartup() throw()
  179838. {
  179839. return (uint32) GetTickCount();
  179840. }
  179841. int64 Time::getHighResolutionTicks() throw()
  179842. {
  179843. LARGE_INTEGER ticks;
  179844. QueryPerformanceCounter (&ticks);
  179845. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179846. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179847. // fix for a very obscure PCI hardware bug that can make the counter
  179848. // sometimes jump forwards by a few seconds..
  179849. static int64 hiResTicksOffset = 0;
  179850. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179851. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179852. hiResTicksOffset = newOffset;
  179853. return ticks.QuadPart + hiResTicksOffset;
  179854. }
  179855. double Time::getMillisecondCounterHiRes() throw()
  179856. {
  179857. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179858. }
  179859. int64 Time::getHighResolutionTicksPerSecond() throw()
  179860. {
  179861. return hiResTicksPerSecond;
  179862. }
  179863. int64 SystemStats::getClockCycleCounter() throw()
  179864. {
  179865. #if JUCE_USE_INTRINSICS
  179866. // MS intrinsics version...
  179867. return __rdtsc();
  179868. #elif JUCE_GCC
  179869. // GNU inline asm version...
  179870. unsigned int hi = 0, lo = 0;
  179871. __asm__ __volatile__ (
  179872. "xor %%eax, %%eax \n\
  179873. xor %%edx, %%edx \n\
  179874. rdtsc \n\
  179875. movl %%eax, %[lo] \n\
  179876. movl %%edx, %[hi]"
  179877. :
  179878. : [hi] "m" (hi),
  179879. [lo] "m" (lo)
  179880. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179881. return (int64) ((((uint64) hi) << 32) | lo);
  179882. #else
  179883. // MSVC inline asm version...
  179884. unsigned int hi = 0, lo = 0;
  179885. __asm
  179886. {
  179887. xor eax, eax
  179888. xor edx, edx
  179889. rdtsc
  179890. mov lo, eax
  179891. mov hi, edx
  179892. }
  179893. return (int64) ((((uint64) hi) << 32) | lo);
  179894. #endif
  179895. }
  179896. int SystemStats::getCpuSpeedInMegaherz() throw()
  179897. {
  179898. const int64 cycles = SystemStats::getClockCycleCounter();
  179899. const uint32 millis = Time::getMillisecondCounter();
  179900. int lastResult = 0;
  179901. for (;;)
  179902. {
  179903. int n = 1000000;
  179904. while (--n > 0) {}
  179905. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179906. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179907. if (millisElapsed > 80)
  179908. {
  179909. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179910. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179911. return newResult;
  179912. lastResult = newResult;
  179913. }
  179914. }
  179915. }
  179916. bool Time::setSystemTimeToThisTime() const throw()
  179917. {
  179918. SYSTEMTIME st;
  179919. st.wDayOfWeek = 0;
  179920. st.wYear = (WORD) getYear();
  179921. st.wMonth = (WORD) (getMonth() + 1);
  179922. st.wDay = (WORD) getDayOfMonth();
  179923. st.wHour = (WORD) getHours();
  179924. st.wMinute = (WORD) getMinutes();
  179925. st.wSecond = (WORD) getSeconds();
  179926. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179927. // do this twice because of daylight saving conversion problems - the
  179928. // first one sets it up, the second one kicks it in.
  179929. return SetLocalTime (&st) != 0
  179930. && SetLocalTime (&st) != 0;
  179931. }
  179932. int SystemStats::getPageSize() throw()
  179933. {
  179934. SYSTEM_INFO systemInfo;
  179935. GetSystemInfo (&systemInfo);
  179936. return systemInfo.dwPageSize;
  179937. }
  179938. const String SystemStats::getLogonName()
  179939. {
  179940. TCHAR text [256];
  179941. DWORD len = numElementsInArray (text) - 2;
  179942. zerostruct (text);
  179943. GetUserName (text, &len);
  179944. return String (text, len);
  179945. }
  179946. const String SystemStats::getFullUserName()
  179947. {
  179948. return getLogonName();
  179949. }
  179950. #endif
  179951. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179952. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179953. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179954. // compiled on its own).
  179955. #if JUCE_INCLUDED_FILE
  179956. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179957. extern HWND juce_messageWindowHandle;
  179958. #endif
  179959. #if ! JUCE_USE_INTRINSICS
  179960. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179961. // older ones we have to actually call the ops as win32 functions..
  179962. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179963. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179964. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179965. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179966. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179967. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179968. #endif
  179969. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179970. CriticalSection::CriticalSection() throw()
  179971. {
  179972. // (just to check the MS haven't changed this structure and broken things...)
  179973. #if _MSC_VER >= 1400
  179974. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179975. #else
  179976. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179977. #endif
  179978. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179979. }
  179980. CriticalSection::~CriticalSection() throw()
  179981. {
  179982. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179983. }
  179984. void CriticalSection::enter() const throw()
  179985. {
  179986. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179987. }
  179988. bool CriticalSection::tryEnter() const throw()
  179989. {
  179990. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179991. }
  179992. void CriticalSection::exit() const throw()
  179993. {
  179994. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179995. }
  179996. WaitableEvent::WaitableEvent() throw()
  179997. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179998. {
  179999. }
  180000. WaitableEvent::~WaitableEvent() throw()
  180001. {
  180002. CloseHandle (internal);
  180003. }
  180004. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  180005. {
  180006. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  180007. }
  180008. void WaitableEvent::signal() const throw()
  180009. {
  180010. SetEvent (internal);
  180011. }
  180012. void WaitableEvent::reset() const throw()
  180013. {
  180014. ResetEvent (internal);
  180015. }
  180016. void JUCE_API juce_threadEntryPoint (void*);
  180017. static unsigned int __stdcall threadEntryProc (void* userData)
  180018. {
  180019. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180020. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  180021. GetCurrentThreadId(), TRUE);
  180022. #endif
  180023. juce_threadEntryPoint (userData);
  180024. _endthreadex (0);
  180025. return 0;
  180026. }
  180027. void juce_CloseThreadHandle (void* handle)
  180028. {
  180029. CloseHandle ((HANDLE) handle);
  180030. }
  180031. void* juce_createThread (void* userData)
  180032. {
  180033. unsigned int threadId;
  180034. return (void*) _beginthreadex (0, 0,
  180035. &threadEntryProc,
  180036. userData,
  180037. 0, &threadId);
  180038. }
  180039. void juce_killThread (void* handle)
  180040. {
  180041. if (handle != 0)
  180042. {
  180043. #ifdef JUCE_DEBUG
  180044. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  180045. #endif
  180046. TerminateThread (handle, 0);
  180047. }
  180048. }
  180049. void juce_setCurrentThreadName (const String& name)
  180050. {
  180051. #if defined (JUCE_DEBUG) && JUCE_MSVC
  180052. struct
  180053. {
  180054. DWORD dwType;
  180055. LPCSTR szName;
  180056. DWORD dwThreadID;
  180057. DWORD dwFlags;
  180058. } info;
  180059. info.dwType = 0x1000;
  180060. info.szName = name;
  180061. info.dwThreadID = GetCurrentThreadId();
  180062. info.dwFlags = 0;
  180063. #define MS_VC_EXCEPTION 0x406d1388
  180064. __try
  180065. {
  180066. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  180067. }
  180068. __except (EXCEPTION_CONTINUE_EXECUTION)
  180069. {}
  180070. #else
  180071. (void) name;
  180072. #endif
  180073. }
  180074. Thread::ThreadID Thread::getCurrentThreadId()
  180075. {
  180076. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  180077. }
  180078. // priority 1 to 10 where 5=normal, 1=low
  180079. bool juce_setThreadPriority (void* threadHandle, int priority)
  180080. {
  180081. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  180082. if (priority < 1)
  180083. pri = THREAD_PRIORITY_IDLE;
  180084. else if (priority < 2)
  180085. pri = THREAD_PRIORITY_LOWEST;
  180086. else if (priority < 5)
  180087. pri = THREAD_PRIORITY_BELOW_NORMAL;
  180088. else if (priority < 7)
  180089. pri = THREAD_PRIORITY_NORMAL;
  180090. else if (priority < 9)
  180091. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  180092. else if (priority < 10)
  180093. pri = THREAD_PRIORITY_HIGHEST;
  180094. if (threadHandle == 0)
  180095. threadHandle = GetCurrentThread();
  180096. return SetThreadPriority (threadHandle, pri) != FALSE;
  180097. }
  180098. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180099. {
  180100. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180101. }
  180102. static HANDLE sleepEvent = 0;
  180103. void juce_initialiseThreadEvents()
  180104. {
  180105. if (sleepEvent == 0)
  180106. #ifdef JUCE_DEBUG
  180107. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180108. #else
  180109. sleepEvent = CreateEvent (0, 0, 0, 0);
  180110. #endif
  180111. }
  180112. void Thread::yield()
  180113. {
  180114. Sleep (0);
  180115. }
  180116. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180117. {
  180118. if (millisecs >= 10)
  180119. {
  180120. Sleep (millisecs);
  180121. }
  180122. else
  180123. {
  180124. jassert (sleepEvent != 0);
  180125. // unlike Sleep() this is guaranteed to return to the current thread after
  180126. // the time expires, so we'll use this for short waits, which are more likely
  180127. // to need to be accurate
  180128. WaitForSingleObject (sleepEvent, millisecs);
  180129. }
  180130. }
  180131. static int lastProcessPriority = -1;
  180132. // called by WindowDriver because Windows does wierd things to process priority
  180133. // when you swap apps, and this forces an update when the app is brought to the front.
  180134. void juce_repeatLastProcessPriority()
  180135. {
  180136. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180137. {
  180138. DWORD p;
  180139. switch (lastProcessPriority)
  180140. {
  180141. case Process::LowPriority:
  180142. p = IDLE_PRIORITY_CLASS;
  180143. break;
  180144. case Process::NormalPriority:
  180145. p = NORMAL_PRIORITY_CLASS;
  180146. break;
  180147. case Process::HighPriority:
  180148. p = HIGH_PRIORITY_CLASS;
  180149. break;
  180150. case Process::RealtimePriority:
  180151. p = REALTIME_PRIORITY_CLASS;
  180152. break;
  180153. default:
  180154. jassertfalse // bad priority value
  180155. return;
  180156. }
  180157. SetPriorityClass (GetCurrentProcess(), p);
  180158. }
  180159. }
  180160. void Process::setPriority (ProcessPriority prior)
  180161. {
  180162. if (lastProcessPriority != (int) prior)
  180163. {
  180164. lastProcessPriority = (int) prior;
  180165. juce_repeatLastProcessPriority();
  180166. }
  180167. }
  180168. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180169. {
  180170. return IsDebuggerPresent() != FALSE;
  180171. }
  180172. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180173. {
  180174. return juce_isRunningUnderDebugger();
  180175. }
  180176. void Process::raisePrivilege()
  180177. {
  180178. jassertfalse // xxx not implemented
  180179. }
  180180. void Process::lowerPrivilege()
  180181. {
  180182. jassertfalse // xxx not implemented
  180183. }
  180184. void Process::terminate()
  180185. {
  180186. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180187. _CrtDumpMemoryLeaks();
  180188. #endif
  180189. // bullet in the head in case there's a problem shutting down..
  180190. ExitProcess (0);
  180191. }
  180192. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180193. {
  180194. void* result = 0;
  180195. JUCE_TRY
  180196. {
  180197. result = (void*) LoadLibrary (name);
  180198. }
  180199. JUCE_CATCH_ALL
  180200. return result;
  180201. }
  180202. void PlatformUtilities::freeDynamicLibrary (void* h)
  180203. {
  180204. JUCE_TRY
  180205. {
  180206. if (h != 0)
  180207. FreeLibrary ((HMODULE) h);
  180208. }
  180209. JUCE_CATCH_ALL
  180210. }
  180211. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180212. {
  180213. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name)
  180214. : 0;
  180215. }
  180216. InterProcessLock::InterProcessLock (const String& name_)
  180217. : internal (0),
  180218. name (name_),
  180219. reentrancyLevel (0)
  180220. {
  180221. }
  180222. InterProcessLock::~InterProcessLock()
  180223. {
  180224. exit();
  180225. }
  180226. bool InterProcessLock::enter (const int timeOutMillisecs)
  180227. {
  180228. if (reentrancyLevel++ == 0)
  180229. {
  180230. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180231. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180232. {
  180233. if (timeOutMillisecs == 0
  180234. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180235. == WAIT_TIMEOUT)
  180236. {
  180237. ReleaseMutex (internal);
  180238. CloseHandle (internal);
  180239. internal = 0;
  180240. }
  180241. }
  180242. }
  180243. return (internal != 0);
  180244. }
  180245. void InterProcessLock::exit()
  180246. {
  180247. if (--reentrancyLevel == 0 && internal != 0)
  180248. {
  180249. ReleaseMutex (internal);
  180250. CloseHandle (internal);
  180251. internal = 0;
  180252. }
  180253. }
  180254. #endif
  180255. /*** End of inlined file: juce_win32_Threads.cpp ***/
  180256. /*** Start of inlined file: juce_win32_Files.cpp ***/
  180257. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180258. // compiled on its own).
  180259. #if JUCE_INCLUDED_FILE
  180260. #ifndef CSIDL_MYMUSIC
  180261. #define CSIDL_MYMUSIC 0x000d
  180262. #endif
  180263. #ifndef CSIDL_MYVIDEO
  180264. #define CSIDL_MYVIDEO 0x000e
  180265. #endif
  180266. const tchar File::separator = T('\\');
  180267. const tchar* File::separatorString = T("\\");
  180268. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180269. {
  180270. if (fileName.isEmpty())
  180271. return false;
  180272. const DWORD attr = GetFileAttributes (fileName);
  180273. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180274. : (attr != 0xffffffff);
  180275. }
  180276. bool juce_isDirectory (const String& fileName)
  180277. {
  180278. const DWORD attr = GetFileAttributes (fileName);
  180279. return (attr != 0xffffffff)
  180280. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180281. }
  180282. bool juce_canWriteToFile (const String& fileName)
  180283. {
  180284. const DWORD attr = GetFileAttributes (fileName);
  180285. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180286. }
  180287. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180288. {
  180289. DWORD attr = GetFileAttributes (fileName);
  180290. if (attr == 0xffffffff)
  180291. return false;
  180292. if (isReadOnly != juce_canWriteToFile (fileName))
  180293. return true;
  180294. if (isReadOnly)
  180295. attr |= FILE_ATTRIBUTE_READONLY;
  180296. else
  180297. attr &= ~FILE_ATTRIBUTE_READONLY;
  180298. return SetFileAttributes (fileName, attr) != FALSE;
  180299. }
  180300. bool File::isHidden() const
  180301. {
  180302. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180303. }
  180304. bool juce_deleteFile (const String& fileName)
  180305. {
  180306. if (juce_isDirectory (fileName))
  180307. return RemoveDirectory (fileName) != 0;
  180308. return DeleteFile (fileName) != 0;
  180309. }
  180310. bool File::moveToTrash() const
  180311. {
  180312. if (! exists())
  180313. return true;
  180314. SHFILEOPSTRUCT fos;
  180315. zerostruct (fos);
  180316. // The string we pass in must be double null terminated..
  180317. String doubleNullTermPath (getFullPathName() + " ");
  180318. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180319. p [getFullPathName().length()] = 0;
  180320. fos.wFunc = FO_DELETE;
  180321. fos.hwnd = (HWND) 0;
  180322. fos.pFrom = p;
  180323. fos.pTo = NULL;
  180324. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180325. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180326. return SHFileOperation (&fos) == 0;
  180327. }
  180328. bool juce_moveFile (const String& source, const String& dest)
  180329. {
  180330. return MoveFile (source, dest) != 0;
  180331. }
  180332. bool juce_copyFile (const String& source, const String& dest)
  180333. {
  180334. return CopyFile (source, dest, false) != 0;
  180335. }
  180336. void juce_createDirectory (const String& fileName)
  180337. {
  180338. if (! juce_fileExists (fileName, true))
  180339. {
  180340. CreateDirectory (fileName, 0);
  180341. }
  180342. }
  180343. // return 0 if not possible
  180344. void* juce_fileOpen (const String& fileName, bool forWriting)
  180345. {
  180346. HANDLE h;
  180347. if (forWriting)
  180348. {
  180349. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180350. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180351. if (h != INVALID_HANDLE_VALUE)
  180352. SetFilePointer (h, 0, 0, FILE_END);
  180353. else
  180354. h = 0;
  180355. }
  180356. else
  180357. {
  180358. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180359. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180360. if (h == INVALID_HANDLE_VALUE)
  180361. h = 0;
  180362. }
  180363. return (void*) h;
  180364. }
  180365. void juce_fileClose (void* handle)
  180366. {
  180367. CloseHandle (handle);
  180368. }
  180369. int juce_fileRead (void* handle, void* buffer, int size)
  180370. {
  180371. DWORD num = 0;
  180372. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180373. return num;
  180374. }
  180375. int juce_fileWrite (void* handle, const void* buffer, int size)
  180376. {
  180377. DWORD num;
  180378. WriteFile ((HANDLE) handle,
  180379. buffer, size,
  180380. &num, 0);
  180381. return num;
  180382. }
  180383. int64 juce_fileSetPosition (void* handle, int64 pos)
  180384. {
  180385. LARGE_INTEGER li;
  180386. li.QuadPart = pos;
  180387. li.LowPart = SetFilePointer ((HANDLE) handle,
  180388. li.LowPart,
  180389. &li.HighPart,
  180390. FILE_BEGIN); // (returns -1 if it fails)
  180391. return li.QuadPart;
  180392. }
  180393. int64 juce_fileGetPosition (void* handle)
  180394. {
  180395. LARGE_INTEGER li;
  180396. li.QuadPart = 0;
  180397. li.LowPart = SetFilePointer ((HANDLE) handle,
  180398. 0, &li.HighPart,
  180399. FILE_CURRENT); // (returns -1 if it fails)
  180400. return jmax ((int64) 0, li.QuadPart);
  180401. }
  180402. void juce_fileFlush (void* handle)
  180403. {
  180404. FlushFileBuffers ((HANDLE) handle);
  180405. }
  180406. int64 juce_getFileSize (const String& fileName)
  180407. {
  180408. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180409. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180410. {
  180411. return (((int64) attributes.nFileSizeHigh) << 32)
  180412. | attributes.nFileSizeLow;
  180413. }
  180414. return 0;
  180415. }
  180416. static int64 fileTimeToTime (const FILETIME* const ft)
  180417. {
  180418. // tell me if this fails!
  180419. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180420. #if JUCE_GCC
  180421. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180422. #else
  180423. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180424. #endif
  180425. }
  180426. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180427. {
  180428. #if JUCE_GCC
  180429. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180430. #else
  180431. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180432. #endif
  180433. }
  180434. void juce_getFileTimes (const String& fileName,
  180435. int64& modificationTime,
  180436. int64& accessTime,
  180437. int64& creationTime)
  180438. {
  180439. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180440. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180441. {
  180442. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180443. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180444. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180445. }
  180446. else
  180447. {
  180448. creationTime = accessTime = modificationTime = 0;
  180449. }
  180450. }
  180451. bool juce_setFileTimes (const String& fileName,
  180452. int64 modificationTime,
  180453. int64 accessTime,
  180454. int64 creationTime)
  180455. {
  180456. FILETIME m, a, c;
  180457. if (modificationTime > 0)
  180458. timeToFileTime (modificationTime, &m);
  180459. if (accessTime > 0)
  180460. timeToFileTime (accessTime, &a);
  180461. if (creationTime > 0)
  180462. timeToFileTime (creationTime, &c);
  180463. void* const h = juce_fileOpen (fileName, true);
  180464. bool ok = false;
  180465. if (h != 0)
  180466. {
  180467. ok = SetFileTime ((HANDLE) h,
  180468. (creationTime > 0) ? &c : 0,
  180469. (accessTime > 0) ? &a : 0,
  180470. (modificationTime > 0) ? &m : 0) != 0;
  180471. juce_fileClose (h);
  180472. }
  180473. return ok;
  180474. }
  180475. // return '\0' separated list of strings
  180476. const StringArray juce_getFileSystemRoots()
  180477. {
  180478. TCHAR buffer [2048];
  180479. buffer[0] = 0;
  180480. buffer[1] = 0;
  180481. GetLogicalDriveStrings (2048, buffer);
  180482. TCHAR* n = buffer;
  180483. StringArray roots;
  180484. while (*n != 0)
  180485. {
  180486. roots.add (String (n));
  180487. while (*n++ != 0)
  180488. {
  180489. }
  180490. }
  180491. roots.sort (true);
  180492. return roots;
  180493. }
  180494. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180495. int& volumeSerialNumber)
  180496. {
  180497. TCHAR n [4];
  180498. n[0] = *(const TCHAR*) filenameOnVolume;
  180499. n[1] = L':';
  180500. n[2] = L'\\';
  180501. n[3] = 0;
  180502. TCHAR dest [64];
  180503. DWORD serialNum;
  180504. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180505. {
  180506. dest[0] = 0;
  180507. serialNum = 0;
  180508. }
  180509. volumeSerialNumber = serialNum;
  180510. return String (dest);
  180511. }
  180512. static int64 getDiskSpaceInfo (String fn, const bool total)
  180513. {
  180514. if (fn[1] == T(':'))
  180515. fn = fn.substring (0, 2) + T("\\");
  180516. ULARGE_INTEGER spc, tot, totFree;
  180517. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180518. return (int64) (total ? tot.QuadPart
  180519. : spc.QuadPart);
  180520. return 0;
  180521. }
  180522. int64 File::getBytesFreeOnVolume() const
  180523. {
  180524. return getDiskSpaceInfo (getFullPathName(), false);
  180525. }
  180526. int64 File::getVolumeTotalSize() const
  180527. {
  180528. return getDiskSpaceInfo (getFullPathName(), true);
  180529. }
  180530. static unsigned int getWindowsDriveType (const String& fileName)
  180531. {
  180532. TCHAR n[4];
  180533. n[0] = *(const TCHAR*) fileName;
  180534. n[1] = L':';
  180535. n[2] = L'\\';
  180536. n[3] = 0;
  180537. return GetDriveType (n);
  180538. }
  180539. bool File::isOnCDRomDrive() const
  180540. {
  180541. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180542. }
  180543. bool File::isOnHardDisk() const
  180544. {
  180545. if (fullPath.isEmpty())
  180546. return false;
  180547. const unsigned int n = getWindowsDriveType (getFullPathName());
  180548. if (fullPath.toLowerCase()[0] <= 'b'
  180549. && fullPath[1] == T(':'))
  180550. {
  180551. return n != DRIVE_REMOVABLE;
  180552. }
  180553. else
  180554. {
  180555. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180556. }
  180557. }
  180558. bool File::isOnRemovableDrive() const
  180559. {
  180560. if (fullPath.isEmpty())
  180561. return false;
  180562. const unsigned int n = getWindowsDriveType (getFullPathName());
  180563. return n == DRIVE_CDROM
  180564. || n == DRIVE_REMOTE
  180565. || n == DRIVE_REMOVABLE
  180566. || n == DRIVE_RAMDISK;
  180567. }
  180568. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180569. static const File juce_getSpecialFolderPath (int type)
  180570. {
  180571. WCHAR path [MAX_PATH_CHARS];
  180572. if (SHGetSpecialFolderPath (0, path, type, 0))
  180573. return File (String (path));
  180574. return File::nonexistent;
  180575. }
  180576. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180577. {
  180578. int csidlType = 0;
  180579. switch (type)
  180580. {
  180581. case userHomeDirectory:
  180582. csidlType = CSIDL_PROFILE;
  180583. break;
  180584. case userDocumentsDirectory:
  180585. csidlType = CSIDL_PERSONAL;
  180586. break;
  180587. case userDesktopDirectory:
  180588. csidlType = CSIDL_DESKTOP;
  180589. break;
  180590. case userApplicationDataDirectory:
  180591. csidlType = CSIDL_APPDATA;
  180592. break;
  180593. case commonApplicationDataDirectory:
  180594. csidlType = CSIDL_COMMON_APPDATA;
  180595. break;
  180596. case globalApplicationsDirectory:
  180597. csidlType = CSIDL_PROGRAM_FILES;
  180598. break;
  180599. case userMusicDirectory:
  180600. csidlType = CSIDL_MYMUSIC;
  180601. break;
  180602. case userMoviesDirectory:
  180603. csidlType = CSIDL_MYVIDEO;
  180604. break;
  180605. case tempDirectory:
  180606. {
  180607. WCHAR dest [2048];
  180608. dest[0] = 0;
  180609. GetTempPath (2048, dest);
  180610. return File (String (dest));
  180611. }
  180612. case invokedExecutableFile:
  180613. case currentExecutableFile:
  180614. case currentApplicationFile:
  180615. {
  180616. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180617. WCHAR dest [MAX_PATH_CHARS];
  180618. dest[0] = 0;
  180619. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180620. return File (String (dest));
  180621. }
  180622. break;
  180623. default:
  180624. jassertfalse // unknown type?
  180625. return File::nonexistent;
  180626. }
  180627. return juce_getSpecialFolderPath (csidlType);
  180628. }
  180629. const File File::getCurrentWorkingDirectory()
  180630. {
  180631. WCHAR dest [MAX_PATH_CHARS];
  180632. dest[0] = 0;
  180633. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180634. return File (String (dest));
  180635. }
  180636. bool File::setAsCurrentWorkingDirectory() const
  180637. {
  180638. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180639. }
  180640. const String File::getVersion() const
  180641. {
  180642. String result;
  180643. DWORD handle = 0;
  180644. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180645. HeapBlock <char> buffer;
  180646. buffer.calloc (bufferSize);
  180647. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180648. {
  180649. VS_FIXEDFILEINFO* vffi;
  180650. UINT len = 0;
  180651. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180652. {
  180653. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180654. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180655. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180656. << (int) LOWORD (vffi->dwFileVersionLS);
  180657. }
  180658. }
  180659. return result;
  180660. }
  180661. const File File::getLinkedTarget() const
  180662. {
  180663. File result (*this);
  180664. String p (getFullPathName());
  180665. if (! exists())
  180666. p += T(".lnk");
  180667. else if (getFileExtension() != T(".lnk"))
  180668. return result;
  180669. ComSmartPtr <IShellLink> shellLink;
  180670. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180671. {
  180672. ComSmartPtr <IPersistFile> persistFile;
  180673. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180674. {
  180675. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180676. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180677. {
  180678. WIN32_FIND_DATA winFindData;
  180679. WCHAR resolvedPath [MAX_PATH];
  180680. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180681. result = File (resolvedPath);
  180682. }
  180683. }
  180684. }
  180685. return result;
  180686. }
  180687. template <class FindDataType>
  180688. static void getFindFileInfo (FindDataType& findData,
  180689. String& filename, bool* const isDir, bool* const isHidden,
  180690. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180691. bool* const isReadOnly)
  180692. {
  180693. filename = findData.cFileName;
  180694. if (isDir != 0)
  180695. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180696. if (isHidden != 0)
  180697. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180698. if (fileSize != 0)
  180699. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180700. if (modTime != 0)
  180701. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180702. if (creationTime != 0)
  180703. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180704. if (isReadOnly != 0)
  180705. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180706. }
  180707. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180708. bool* isDir, bool* isHidden, int64* fileSize,
  180709. Time* modTime, Time* creationTime, bool* isReadOnly)
  180710. {
  180711. String wc (directory);
  180712. if (! wc.endsWithChar (File::separator))
  180713. wc += File::separator;
  180714. wc += wildCard;
  180715. WIN32_FIND_DATA findData;
  180716. HANDLE h = FindFirstFile (wc, &findData);
  180717. if (h != INVALID_HANDLE_VALUE)
  180718. {
  180719. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180720. modTime, creationTime, isReadOnly);
  180721. return h;
  180722. }
  180723. firstResult = String::empty;
  180724. return 0;
  180725. }
  180726. bool juce_findFileNext (void* handle, String& resultFile,
  180727. bool* isDir, bool* isHidden, int64* fileSize,
  180728. Time* modTime, Time* creationTime, bool* isReadOnly)
  180729. {
  180730. WIN32_FIND_DATA findData;
  180731. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180732. {
  180733. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180734. modTime, creationTime, isReadOnly);
  180735. return true;
  180736. }
  180737. resultFile = String::empty;
  180738. return false;
  180739. }
  180740. void juce_findFileClose (void* handle)
  180741. {
  180742. FindClose (handle);
  180743. }
  180744. bool juce_launchFile (const String& fileName,
  180745. const String& parameters)
  180746. {
  180747. HINSTANCE hInstance = 0;
  180748. JUCE_TRY
  180749. {
  180750. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180751. }
  180752. JUCE_CATCH_ALL
  180753. return hInstance > (HINSTANCE) 32;
  180754. }
  180755. void File::revealToUser() const
  180756. {
  180757. if (isDirectory())
  180758. startAsProcess();
  180759. else if (getParentDirectory().exists())
  180760. getParentDirectory().startAsProcess();
  180761. }
  180762. struct NamedPipeInternal
  180763. {
  180764. HANDLE pipeH;
  180765. HANDLE cancelEvent;
  180766. bool connected, createdPipe;
  180767. NamedPipeInternal()
  180768. : pipeH (0),
  180769. cancelEvent (0),
  180770. connected (false),
  180771. createdPipe (false)
  180772. {
  180773. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180774. }
  180775. ~NamedPipeInternal()
  180776. {
  180777. disconnect();
  180778. if (pipeH != 0)
  180779. CloseHandle (pipeH);
  180780. CloseHandle (cancelEvent);
  180781. }
  180782. bool connect (const int timeOutMs)
  180783. {
  180784. if (! createdPipe)
  180785. return true;
  180786. if (! connected)
  180787. {
  180788. OVERLAPPED over;
  180789. zerostruct (over);
  180790. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180791. if (ConnectNamedPipe (pipeH, &over))
  180792. {
  180793. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180794. }
  180795. else
  180796. {
  180797. const int err = GetLastError();
  180798. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180799. {
  180800. HANDLE handles[] = { over.hEvent, cancelEvent };
  180801. if (WaitForMultipleObjects (2, handles, FALSE,
  180802. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180803. connected = true;
  180804. }
  180805. else if (err == ERROR_PIPE_CONNECTED)
  180806. {
  180807. connected = true;
  180808. }
  180809. }
  180810. CloseHandle (over.hEvent);
  180811. }
  180812. return connected;
  180813. }
  180814. void disconnect()
  180815. {
  180816. if (connected)
  180817. {
  180818. DisconnectNamedPipe (pipeH);
  180819. connected = false;
  180820. }
  180821. }
  180822. };
  180823. void NamedPipe::close()
  180824. {
  180825. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180826. delete intern;
  180827. internal = 0;
  180828. }
  180829. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180830. {
  180831. close();
  180832. NamedPipeInternal* const intern = new NamedPipeInternal();
  180833. String file ("\\\\.\\pipe\\");
  180834. file += pipeName;
  180835. intern->createdPipe = createPipe;
  180836. if (createPipe)
  180837. {
  180838. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180839. PIPE_UNLIMITED_INSTANCES,
  180840. 4096, 4096, 0, NULL);
  180841. }
  180842. else
  180843. {
  180844. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180845. FILE_FLAG_OVERLAPPED, 0);
  180846. }
  180847. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180848. {
  180849. internal = intern;
  180850. return true;
  180851. }
  180852. delete intern;
  180853. return false;
  180854. }
  180855. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180856. {
  180857. int bytesRead = -1;
  180858. bool waitAgain = true;
  180859. while (waitAgain && internal != 0)
  180860. {
  180861. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180862. waitAgain = false;
  180863. if (! intern->connect (timeOutMilliseconds))
  180864. break;
  180865. if (maxBytesToRead <= 0)
  180866. return 0;
  180867. OVERLAPPED over;
  180868. zerostruct (over);
  180869. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180870. unsigned long numRead;
  180871. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180872. {
  180873. bytesRead = (int) numRead;
  180874. }
  180875. else if (GetLastError() == ERROR_IO_PENDING)
  180876. {
  180877. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180878. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180879. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180880. : INFINITE);
  180881. if (waitResult != WAIT_OBJECT_0)
  180882. {
  180883. // if the operation timed out, let's cancel it...
  180884. CancelIo (intern->pipeH);
  180885. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180886. }
  180887. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180888. {
  180889. bytesRead = (int) numRead;
  180890. }
  180891. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180892. {
  180893. intern->disconnect();
  180894. waitAgain = true;
  180895. }
  180896. }
  180897. else
  180898. {
  180899. waitAgain = internal != 0;
  180900. Sleep (5);
  180901. }
  180902. CloseHandle (over.hEvent);
  180903. }
  180904. return bytesRead;
  180905. }
  180906. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180907. {
  180908. int bytesWritten = -1;
  180909. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180910. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180911. {
  180912. if (numBytesToWrite <= 0)
  180913. return 0;
  180914. OVERLAPPED over;
  180915. zerostruct (over);
  180916. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180917. unsigned long numWritten;
  180918. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180919. {
  180920. bytesWritten = (int) numWritten;
  180921. }
  180922. else if (GetLastError() == ERROR_IO_PENDING)
  180923. {
  180924. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180925. DWORD waitResult;
  180926. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180927. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180928. : INFINITE);
  180929. if (waitResult != WAIT_OBJECT_0)
  180930. {
  180931. CancelIo (intern->pipeH);
  180932. WaitForSingleObject (over.hEvent, INFINITE);
  180933. }
  180934. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180935. {
  180936. bytesWritten = (int) numWritten;
  180937. }
  180938. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180939. {
  180940. intern->disconnect();
  180941. }
  180942. }
  180943. CloseHandle (over.hEvent);
  180944. }
  180945. return bytesWritten;
  180946. }
  180947. void NamedPipe::cancelPendingReads()
  180948. {
  180949. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180950. if (intern != 0)
  180951. SetEvent (intern->cancelEvent);
  180952. }
  180953. #endif
  180954. /*** End of inlined file: juce_win32_Files.cpp ***/
  180955. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180956. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180957. // compiled on its own).
  180958. #if JUCE_INCLUDED_FILE
  180959. #ifndef INTERNET_FLAG_NEED_FILE
  180960. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180961. #endif
  180962. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180963. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180964. #endif
  180965. bool juce_isOnLine()
  180966. {
  180967. DWORD connectionType;
  180968. return InternetGetConnectedState (&connectionType, 0) != 0
  180969. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180970. }
  180971. struct ConnectionAndRequestStruct
  180972. {
  180973. HINTERNET connection, request;
  180974. };
  180975. static HINTERNET sessionHandle = 0;
  180976. #ifndef WORKAROUND_TIMEOUT_BUG
  180977. //#define WORKAROUND_TIMEOUT_BUG 1
  180978. #endif
  180979. #if WORKAROUND_TIMEOUT_BUG
  180980. // Required because of a Microsoft bug in setting a timeout
  180981. class InternetConnectThread : public Thread
  180982. {
  180983. public:
  180984. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180985. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180986. {
  180987. startThread();
  180988. }
  180989. ~InternetConnectThread()
  180990. {
  180991. stopThread (60000);
  180992. }
  180993. void run()
  180994. {
  180995. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180996. uc.nPort, _T(""), _T(""),
  180997. isFtp ? INTERNET_SERVICE_FTP
  180998. : INTERNET_SERVICE_HTTP,
  180999. 0, 0);
  181000. notify();
  181001. }
  181002. juce_UseDebuggingNewOperator
  181003. private:
  181004. URL_COMPONENTS& uc;
  181005. HINTERNET& connection;
  181006. const bool isFtp;
  181007. InternetConnectThread (const InternetConnectThread&);
  181008. InternetConnectThread& operator= (const InternetConnectThread&);
  181009. };
  181010. #endif
  181011. void* juce_openInternetFile (const String& url,
  181012. const String& headers,
  181013. const MemoryBlock& postData,
  181014. const bool isPost,
  181015. URL::OpenStreamProgressCallback* callback,
  181016. void* callbackContext,
  181017. int timeOutMs)
  181018. {
  181019. if (sessionHandle == 0)
  181020. sessionHandle = InternetOpen (_T("juce"),
  181021. INTERNET_OPEN_TYPE_PRECONFIG,
  181022. 0, 0, 0);
  181023. if (sessionHandle != 0)
  181024. {
  181025. // break up the url..
  181026. TCHAR file[1024], server[1024];
  181027. URL_COMPONENTS uc;
  181028. zerostruct (uc);
  181029. uc.dwStructSize = sizeof (uc);
  181030. uc.dwUrlPathLength = sizeof (file);
  181031. uc.dwHostNameLength = sizeof (server);
  181032. uc.lpszUrlPath = file;
  181033. uc.lpszHostName = server;
  181034. if (InternetCrackUrl (url, 0, 0, &uc))
  181035. {
  181036. int disable = 1;
  181037. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  181038. if (timeOutMs == 0)
  181039. timeOutMs = 30000;
  181040. else if (timeOutMs < 0)
  181041. timeOutMs = -1;
  181042. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  181043. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  181044. #if WORKAROUND_TIMEOUT_BUG
  181045. HINTERNET connection = 0;
  181046. {
  181047. InternetConnectThread connectThread (uc, connection, isFtp);
  181048. connectThread.wait (timeOutMs);
  181049. if (connection == 0)
  181050. {
  181051. InternetCloseHandle (sessionHandle);
  181052. sessionHandle = 0;
  181053. }
  181054. }
  181055. #else
  181056. HINTERNET connection = InternetConnect (sessionHandle,
  181057. uc.lpszHostName,
  181058. uc.nPort,
  181059. _T(""), _T(""),
  181060. isFtp ? INTERNET_SERVICE_FTP
  181061. : INTERNET_SERVICE_HTTP,
  181062. 0, 0);
  181063. #endif
  181064. if (connection != 0)
  181065. {
  181066. if (isFtp)
  181067. {
  181068. HINTERNET request = FtpOpenFile (connection,
  181069. uc.lpszUrlPath,
  181070. GENERIC_READ,
  181071. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  181072. 0);
  181073. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  181074. result->connection = connection;
  181075. result->request = request;
  181076. return result;
  181077. }
  181078. else
  181079. {
  181080. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  181081. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  181082. if (url.startsWithIgnoreCase (T("https:")))
  181083. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  181084. // IE7 seems to automatically work out when it's https)
  181085. HINTERNET request = HttpOpenRequest (connection,
  181086. isPost ? _T("POST")
  181087. : _T("GET"),
  181088. uc.lpszUrlPath,
  181089. 0, 0, mimeTypes, flags, 0);
  181090. if (request != 0)
  181091. {
  181092. INTERNET_BUFFERS buffers;
  181093. zerostruct (buffers);
  181094. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  181095. buffers.lpcszHeader = (LPCTSTR) headers;
  181096. buffers.dwHeadersLength = headers.length();
  181097. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181098. ConnectionAndRequestStruct* result = 0;
  181099. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181100. {
  181101. int bytesSent = 0;
  181102. for (;;)
  181103. {
  181104. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181105. DWORD bytesDone = 0;
  181106. if (bytesToDo > 0
  181107. && ! InternetWriteFile (request,
  181108. ((const char*) postData.getData()) + bytesSent,
  181109. bytesToDo, &bytesDone))
  181110. {
  181111. break;
  181112. }
  181113. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181114. {
  181115. result = new ConnectionAndRequestStruct();
  181116. result->connection = connection;
  181117. result->request = request;
  181118. HttpEndRequest (request, 0, 0, 0);
  181119. return result;
  181120. }
  181121. bytesSent += bytesDone;
  181122. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181123. break;
  181124. }
  181125. }
  181126. InternetCloseHandle (request);
  181127. }
  181128. InternetCloseHandle (connection);
  181129. }
  181130. }
  181131. }
  181132. }
  181133. return 0;
  181134. }
  181135. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181136. {
  181137. DWORD bytesRead = 0;
  181138. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181139. if (crs != 0)
  181140. InternetReadFile (crs->request,
  181141. buffer, bytesToRead,
  181142. &bytesRead);
  181143. return bytesRead;
  181144. }
  181145. int juce_seekInInternetFile (void* handle, int newPosition)
  181146. {
  181147. if (handle != 0)
  181148. {
  181149. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181150. return InternetSetFilePointer (crs->request,
  181151. newPosition, 0,
  181152. FILE_BEGIN, 0);
  181153. }
  181154. else
  181155. {
  181156. return -1;
  181157. }
  181158. }
  181159. int64 juce_getInternetFileContentLength (void* handle)
  181160. {
  181161. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181162. if (crs != 0)
  181163. {
  181164. DWORD index = 0;
  181165. DWORD result = 0;
  181166. DWORD size = sizeof (result);
  181167. if (HttpQueryInfo (crs->request,
  181168. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181169. &result,
  181170. &size,
  181171. &index))
  181172. {
  181173. return (int64) result;
  181174. }
  181175. }
  181176. return -1;
  181177. }
  181178. void juce_closeInternetFile (void* handle)
  181179. {
  181180. if (handle != 0)
  181181. {
  181182. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181183. InternetCloseHandle (crs->request);
  181184. InternetCloseHandle (crs->connection);
  181185. delete crs;
  181186. }
  181187. }
  181188. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181189. {
  181190. int numFound = 0;
  181191. DynamicLibraryLoader dll ("iphlpapi.dll");
  181192. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181193. if (getAdaptersInfo != 0)
  181194. {
  181195. ULONG len = sizeof (IP_ADAPTER_INFO);
  181196. MemoryBlock mb;
  181197. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181198. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181199. {
  181200. mb.setSize (len);
  181201. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181202. }
  181203. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181204. {
  181205. PIP_ADAPTER_INFO adapter = adapterInfo;
  181206. while (adapter != 0)
  181207. {
  181208. int64 mac = 0;
  181209. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181210. mac = (mac << 8) | adapter->Address[i];
  181211. if (littleEndian)
  181212. mac = (int64) ByteOrder::swap ((uint64) mac);
  181213. if (numFound < maxNum && mac != 0)
  181214. addresses [numFound++] = mac;
  181215. adapter = adapter->Next;
  181216. }
  181217. }
  181218. }
  181219. return numFound;
  181220. }
  181221. struct ASTAT
  181222. {
  181223. ADAPTER_STATUS adapt;
  181224. NAME_BUFFER NameBuff [30];
  181225. };
  181226. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181227. {
  181228. int numFound = 0;
  181229. DynamicLibraryLoader dll ("netapi32.dll");
  181230. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181231. if (NetbiosCall != 0)
  181232. {
  181233. NCB ncb;
  181234. zerostruct (ncb);
  181235. ASTAT astat;
  181236. zerostruct (astat);
  181237. LANA_ENUM enums;
  181238. zerostruct (enums);
  181239. ncb.ncb_command = NCBENUM;
  181240. ncb.ncb_buffer = (unsigned char*) &enums;
  181241. ncb.ncb_length = sizeof (LANA_ENUM);
  181242. NetbiosCall (&ncb);
  181243. for (int i = 0; i < enums.length; ++i)
  181244. {
  181245. zerostruct (ncb);
  181246. ncb.ncb_command = NCBRESET;
  181247. ncb.ncb_lana_num = enums.lana[i];
  181248. if (NetbiosCall (&ncb) == 0)
  181249. {
  181250. zerostruct (ncb);
  181251. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181252. ncb.ncb_command = NCBASTAT;
  181253. ncb.ncb_lana_num = enums.lana[i];
  181254. ncb.ncb_buffer = (unsigned char*) &astat;
  181255. ncb.ncb_length = sizeof (ASTAT);
  181256. if (NetbiosCall (&ncb) == 0)
  181257. {
  181258. if (astat.adapt.adapter_type == 0xfe)
  181259. {
  181260. uint64 mac = 0;
  181261. for (int i = 6; --i >= 0;)
  181262. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181263. if (numFound < maxNum && mac != 0)
  181264. addresses [numFound++] = mac;
  181265. }
  181266. }
  181267. }
  181268. }
  181269. }
  181270. return numFound;
  181271. }
  181272. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181273. {
  181274. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181275. if (numFound == 0)
  181276. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181277. return numFound;
  181278. }
  181279. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181280. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181281. const String& emailSubject,
  181282. const String& bodyText,
  181283. const StringArray& filesToAttach)
  181284. {
  181285. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181286. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181287. bool ok = false;
  181288. if (mapiSendMail != 0)
  181289. {
  181290. MapiMessage message;
  181291. zerostruct (message);
  181292. message.lpszSubject = (LPSTR) (LPCSTR) emailSubject;
  181293. message.lpszNoteText = (LPSTR) (LPCSTR) bodyText;
  181294. MapiRecipDesc recip;
  181295. zerostruct (recip);
  181296. recip.ulRecipClass = MAPI_TO;
  181297. String targetEmailAddress_ (targetEmailAddress);
  181298. if (targetEmailAddress_.isEmpty())
  181299. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181300. recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_;
  181301. message.nRecipCount = 1;
  181302. message.lpRecips = &recip;
  181303. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181304. mb.fillWith (0);
  181305. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181306. message.nFileCount = filesToAttach.size();
  181307. message.lpFiles = files;
  181308. for (int i = 0; i < filesToAttach.size(); ++i)
  181309. {
  181310. files[i].nPosition = (ULONG) -1;
  181311. files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i];
  181312. }
  181313. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181314. }
  181315. FreeLibrary (h);
  181316. return ok;
  181317. }
  181318. #endif
  181319. /*** End of inlined file: juce_win32_Network.cpp ***/
  181320. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  181321. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181322. // compiled on its own).
  181323. #if JUCE_INCLUDED_FILE
  181324. static HKEY findKeyForPath (String name,
  181325. const bool createForWriting,
  181326. String& valueName)
  181327. {
  181328. HKEY rootKey = 0;
  181329. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181330. rootKey = HKEY_CURRENT_USER;
  181331. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181332. rootKey = HKEY_LOCAL_MACHINE;
  181333. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181334. rootKey = HKEY_CLASSES_ROOT;
  181335. if (rootKey != 0)
  181336. {
  181337. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181338. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181339. valueName = name.substring (lastSlash + 1);
  181340. name = name.substring (0, lastSlash);
  181341. HKEY key;
  181342. DWORD result;
  181343. if (createForWriting)
  181344. {
  181345. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  181346. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181347. return key;
  181348. }
  181349. else
  181350. {
  181351. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181352. return key;
  181353. }
  181354. }
  181355. return 0;
  181356. }
  181357. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181358. const String& defaultValue)
  181359. {
  181360. String valueName, result (defaultValue);
  181361. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181362. if (k != 0)
  181363. {
  181364. WCHAR buffer [2048];
  181365. unsigned long bufferSize = sizeof (buffer);
  181366. DWORD type = REG_SZ;
  181367. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181368. {
  181369. if (type == REG_SZ)
  181370. result = buffer;
  181371. else if (type == REG_DWORD)
  181372. result = String ((int) *(DWORD*) buffer);
  181373. }
  181374. RegCloseKey (k);
  181375. }
  181376. return result;
  181377. }
  181378. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181379. const String& value)
  181380. {
  181381. String valueName;
  181382. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181383. if (k != 0)
  181384. {
  181385. RegSetValueEx (k, valueName, 0, REG_SZ,
  181386. (const BYTE*) (const WCHAR*) value,
  181387. sizeof (WCHAR) * (value.length() + 1));
  181388. RegCloseKey (k);
  181389. }
  181390. }
  181391. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181392. {
  181393. bool exists = false;
  181394. String valueName;
  181395. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181396. if (k != 0)
  181397. {
  181398. unsigned char buffer [2048];
  181399. unsigned long bufferSize = sizeof (buffer);
  181400. DWORD type = 0;
  181401. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181402. exists = true;
  181403. RegCloseKey (k);
  181404. }
  181405. return exists;
  181406. }
  181407. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181408. {
  181409. String valueName;
  181410. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181411. if (k != 0)
  181412. {
  181413. RegDeleteValue (k, valueName);
  181414. RegCloseKey (k);
  181415. }
  181416. }
  181417. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181418. {
  181419. String valueName;
  181420. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181421. if (k != 0)
  181422. {
  181423. RegDeleteKey (k, valueName);
  181424. RegCloseKey (k);
  181425. }
  181426. }
  181427. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181428. const String& symbolicDescription,
  181429. const String& fullDescription,
  181430. const File& targetExecutable,
  181431. int iconResourceNumber)
  181432. {
  181433. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181434. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181435. if (iconResourceNumber != 0)
  181436. setRegistryValue (key + "\\DefaultIcon\\",
  181437. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181438. setRegistryValue (key + "\\", fullDescription);
  181439. setRegistryValue (key + "\\shell\\open\\command\\",
  181440. targetExecutable.getFullPathName() + " %1");
  181441. }
  181442. bool juce_IsRunningInWine()
  181443. {
  181444. HKEY key;
  181445. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181446. {
  181447. RegCloseKey (key);
  181448. return true;
  181449. }
  181450. return false;
  181451. }
  181452. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181453. {
  181454. String s (::GetCommandLineW());
  181455. StringArray tokens;
  181456. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181457. return tokens.joinIntoString (T(" "), 1);
  181458. }
  181459. static void* currentModuleHandle = 0;
  181460. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181461. {
  181462. if (currentModuleHandle == 0)
  181463. currentModuleHandle = GetModuleHandle (0);
  181464. return currentModuleHandle;
  181465. }
  181466. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181467. {
  181468. currentModuleHandle = newHandle;
  181469. }
  181470. void PlatformUtilities::fpuReset()
  181471. {
  181472. #if JUCE_MSVC
  181473. _clearfp();
  181474. #endif
  181475. }
  181476. void PlatformUtilities::beep()
  181477. {
  181478. MessageBeep (MB_OK);
  181479. }
  181480. #endif
  181481. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181482. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181483. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181484. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181485. // compiled on its own).
  181486. #if JUCE_INCLUDED_FILE
  181487. static const unsigned int specialId = WM_APP + 0x4400;
  181488. static const unsigned int broadcastId = WM_APP + 0x4403;
  181489. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181490. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181491. HWND juce_messageWindowHandle = 0;
  181492. extern long improbableWindowNumber; // defined in windowing.cpp
  181493. #ifndef WM_APPCOMMAND
  181494. #define WM_APPCOMMAND 0x0319
  181495. #endif
  181496. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181497. const UINT message,
  181498. const WPARAM wParam,
  181499. const LPARAM lParam) throw()
  181500. {
  181501. JUCE_TRY
  181502. {
  181503. if (h == juce_messageWindowHandle)
  181504. {
  181505. if (message == specialCallbackId)
  181506. {
  181507. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181508. return (LRESULT) (*func) ((void*) lParam);
  181509. }
  181510. else if (message == specialId)
  181511. {
  181512. // these are trapped early in the dispatch call, but must also be checked
  181513. // here in case there are windows modal dialog boxes doing their own
  181514. // dispatch loop and not calling our version
  181515. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181516. return 0;
  181517. }
  181518. else if (message == broadcastId)
  181519. {
  181520. const ScopedPointer <String> messageString ((String*) lParam);
  181521. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181522. return 0;
  181523. }
  181524. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181525. {
  181526. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181527. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181528. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181529. return 0;
  181530. }
  181531. }
  181532. }
  181533. JUCE_CATCH_EXCEPTION
  181534. return DefWindowProc (h, message, wParam, lParam);
  181535. }
  181536. static bool isEventBlockedByModalComps (MSG& m)
  181537. {
  181538. if (Component::getNumCurrentlyModalComponents() == 0
  181539. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181540. return false;
  181541. switch (m.message)
  181542. {
  181543. case WM_MOUSEMOVE:
  181544. case WM_NCMOUSEMOVE:
  181545. case 0x020A: /* WM_MOUSEWHEEL */
  181546. case 0x020E: /* WM_MOUSEHWHEEL */
  181547. case WM_KEYUP:
  181548. case WM_SYSKEYUP:
  181549. case WM_CHAR:
  181550. case WM_APPCOMMAND:
  181551. case WM_LBUTTONUP:
  181552. case WM_MBUTTONUP:
  181553. case WM_RBUTTONUP:
  181554. case WM_MOUSEACTIVATE:
  181555. case WM_NCMOUSEHOVER:
  181556. case WM_MOUSEHOVER:
  181557. return true;
  181558. case WM_NCLBUTTONDOWN:
  181559. case WM_NCLBUTTONDBLCLK:
  181560. case WM_NCRBUTTONDOWN:
  181561. case WM_NCRBUTTONDBLCLK:
  181562. case WM_NCMBUTTONDOWN:
  181563. case WM_NCMBUTTONDBLCLK:
  181564. case WM_LBUTTONDOWN:
  181565. case WM_LBUTTONDBLCLK:
  181566. case WM_MBUTTONDOWN:
  181567. case WM_MBUTTONDBLCLK:
  181568. case WM_RBUTTONDOWN:
  181569. case WM_RBUTTONDBLCLK:
  181570. case WM_KEYDOWN:
  181571. case WM_SYSKEYDOWN:
  181572. {
  181573. Component* const modal = Component::getCurrentlyModalComponent (0);
  181574. if (modal != 0)
  181575. modal->inputAttemptWhenModal();
  181576. return true;
  181577. }
  181578. default:
  181579. break;
  181580. }
  181581. return false;
  181582. }
  181583. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181584. {
  181585. MSG m;
  181586. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181587. return false;
  181588. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181589. {
  181590. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181591. {
  181592. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181593. }
  181594. else if (m.message == WM_QUIT)
  181595. {
  181596. if (JUCEApplication::getInstance())
  181597. JUCEApplication::getInstance()->systemRequestedQuit();
  181598. }
  181599. else if (! isEventBlockedByModalComps (m))
  181600. {
  181601. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181602. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181603. {
  181604. // if it's someone else's window being clicked on, and the focus is
  181605. // currently on a juce window, pass the kb focus over..
  181606. HWND currentFocus = GetFocus();
  181607. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181608. SetFocus (m.hwnd);
  181609. }
  181610. TranslateMessage (&m);
  181611. DispatchMessage (&m);
  181612. }
  181613. }
  181614. return true;
  181615. }
  181616. bool juce_postMessageToSystemQueue (void* message)
  181617. {
  181618. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181619. }
  181620. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181621. void* userData)
  181622. {
  181623. if (MessageManager::getInstance()->isThisTheMessageThread())
  181624. {
  181625. return (*callback) (userData);
  181626. }
  181627. else
  181628. {
  181629. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181630. // deadlock because the message manager is blocked from running, and can't
  181631. // call your function..
  181632. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181633. return (void*) SendMessage (juce_messageWindowHandle,
  181634. specialCallbackId,
  181635. (WPARAM) callback,
  181636. (LPARAM) userData);
  181637. }
  181638. }
  181639. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181640. {
  181641. if (hwnd != juce_messageWindowHandle)
  181642. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181643. return TRUE;
  181644. }
  181645. void MessageManager::broadcastMessage (const String& value) throw()
  181646. {
  181647. VoidArray windows;
  181648. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181649. const String localCopy (value);
  181650. COPYDATASTRUCT data;
  181651. data.dwData = broadcastId;
  181652. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181653. data.lpData = (void*) (const juce_wchar*) localCopy;
  181654. for (int i = windows.size(); --i >= 0;)
  181655. {
  181656. HWND hwnd = (HWND) windows.getUnchecked(i);
  181657. TCHAR windowName [64]; // no need to read longer strings than this
  181658. GetWindowText (hwnd, windowName, 64);
  181659. windowName [63] = 0;
  181660. if (String (windowName) == String (messageWindowName))
  181661. {
  181662. DWORD_PTR result;
  181663. SendMessageTimeout (hwnd, WM_COPYDATA,
  181664. (WPARAM) juce_messageWindowHandle,
  181665. (LPARAM) &data,
  181666. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181667. 8000,
  181668. &result);
  181669. }
  181670. }
  181671. }
  181672. static const String getMessageWindowClassName()
  181673. {
  181674. // this name has to be different for each app/dll instance because otherwise
  181675. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181676. // window class).
  181677. static int number = 0;
  181678. if (number == 0)
  181679. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181680. return T("JUCEcs_") + String (number);
  181681. }
  181682. void MessageManager::doPlatformSpecificInitialisation()
  181683. {
  181684. OleInitialize (0);
  181685. const String className (getMessageWindowClassName());
  181686. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181687. WNDCLASSEX wc;
  181688. zerostruct (wc);
  181689. wc.cbSize = sizeof (wc);
  181690. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181691. wc.cbWndExtra = 4;
  181692. wc.hInstance = hmod;
  181693. wc.lpszClassName = className;
  181694. RegisterClassEx (&wc);
  181695. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181696. messageWindowName,
  181697. 0, 0, 0, 0, 0, 0, 0,
  181698. hmod, 0);
  181699. }
  181700. void MessageManager::doPlatformSpecificShutdown()
  181701. {
  181702. DestroyWindow (juce_messageWindowHandle);
  181703. UnregisterClass (getMessageWindowClassName(), 0);
  181704. OleUninitialize();
  181705. }
  181706. #endif
  181707. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181708. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181709. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181710. // compiled on its own).
  181711. #if JUCE_INCLUDED_FILE
  181712. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181713. // these are in the windows SDK, but need to be repeated here for GCC..
  181714. #ifndef GET_APPCOMMAND_LPARAM
  181715. #define FAPPCOMMAND_MASK 0xF000
  181716. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181717. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181718. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181719. #define APPCOMMAND_MEDIA_STOP 13
  181720. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181721. #define WM_APPCOMMAND 0x0319
  181722. #endif
  181723. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181724. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181725. extern bool juce_IsRunningInWine();
  181726. #ifndef ULW_ALPHA
  181727. #define ULW_ALPHA 0x00000002
  181728. #endif
  181729. #ifndef AC_SRC_ALPHA
  181730. #define AC_SRC_ALPHA 0x01
  181731. #endif
  181732. #define DEBUG_REPAINT_TIMES 0
  181733. static HPALETTE palette = 0;
  181734. static bool createPaletteIfNeeded = true;
  181735. static bool shouldDeactivateTitleBar = true;
  181736. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181737. #define WM_TRAYNOTIFY WM_USER + 100
  181738. using ::abs;
  181739. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181740. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181741. bool Desktop::canUseSemiTransparentWindows() throw()
  181742. {
  181743. if (updateLayeredWindow == 0)
  181744. {
  181745. if (! juce_IsRunningInWine())
  181746. {
  181747. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181748. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181749. }
  181750. }
  181751. return updateLayeredWindow != 0;
  181752. }
  181753. #undef DefWindowProc
  181754. #define DefWindowProc DefWindowProcW
  181755. const int extendedKeyModifier = 0x10000;
  181756. const int KeyPress::spaceKey = VK_SPACE;
  181757. const int KeyPress::returnKey = VK_RETURN;
  181758. const int KeyPress::escapeKey = VK_ESCAPE;
  181759. const int KeyPress::backspaceKey = VK_BACK;
  181760. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181761. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181762. const int KeyPress::tabKey = VK_TAB;
  181763. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181764. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181765. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181766. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181767. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181768. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181769. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181770. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181771. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181772. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181773. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181774. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181775. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181776. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181777. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181778. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181779. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181780. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181781. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181782. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181783. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181784. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181785. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181786. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181787. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181788. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181789. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181790. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181791. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181792. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181793. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181794. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181795. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181796. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181797. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181798. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181799. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181800. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181801. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181802. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181803. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181804. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181805. const int KeyPress::playKey = 0x30000;
  181806. const int KeyPress::stopKey = 0x30001;
  181807. const int KeyPress::fastForwardKey = 0x30002;
  181808. const int KeyPress::rewindKey = 0x30003;
  181809. class WindowsBitmapImage : public Image
  181810. {
  181811. public:
  181812. HBITMAP hBitmap;
  181813. BITMAPV4HEADER bitmapInfo;
  181814. HDC hdc;
  181815. unsigned char* bitmapData;
  181816. WindowsBitmapImage (const PixelFormat format_,
  181817. const int w, const int h, const bool clearImage)
  181818. : Image (format_, w, h)
  181819. {
  181820. jassert (format_ == RGB || format_ == ARGB);
  181821. pixelStride = (format_ == RGB) ? 3 : 4;
  181822. zerostruct (bitmapInfo);
  181823. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181824. bitmapInfo.bV4Width = w;
  181825. bitmapInfo.bV4Height = h;
  181826. bitmapInfo.bV4Planes = 1;
  181827. bitmapInfo.bV4CSType = 1;
  181828. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181829. if (format_ == ARGB)
  181830. {
  181831. bitmapInfo.bV4AlphaMask = 0xff000000;
  181832. bitmapInfo.bV4RedMask = 0xff0000;
  181833. bitmapInfo.bV4GreenMask = 0xff00;
  181834. bitmapInfo.bV4BlueMask = 0xff;
  181835. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181836. }
  181837. else
  181838. {
  181839. bitmapInfo.bV4V4Compression = BI_RGB;
  181840. }
  181841. lineStride = -((w * pixelStride + 3) & ~3);
  181842. HDC dc = GetDC (0);
  181843. hdc = CreateCompatibleDC (dc);
  181844. ReleaseDC (0, dc);
  181845. SetMapMode (hdc, MM_TEXT);
  181846. hBitmap = CreateDIBSection (hdc,
  181847. (BITMAPINFO*) &(bitmapInfo),
  181848. DIB_RGB_COLORS,
  181849. (void**) &bitmapData,
  181850. 0, 0);
  181851. SelectObject (hdc, hBitmap);
  181852. if (format_ == ARGB && clearImage)
  181853. zeromem (bitmapData, abs (h * lineStride));
  181854. imageData = bitmapData - (lineStride * (h - 1));
  181855. }
  181856. ~WindowsBitmapImage()
  181857. {
  181858. DeleteDC (hdc);
  181859. DeleteObject (hBitmap);
  181860. }
  181861. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181862. const int x, const int y,
  181863. const RectangleList& maskedRegion) throw()
  181864. {
  181865. static HDRAWDIB hdd = 0;
  181866. static bool needToCreateDrawDib = true;
  181867. if (needToCreateDrawDib)
  181868. {
  181869. needToCreateDrawDib = false;
  181870. HDC dc = GetDC (0);
  181871. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181872. ReleaseDC (0, dc);
  181873. // only open if we're not palettised
  181874. if (n > 8)
  181875. hdd = DrawDibOpen();
  181876. }
  181877. if (createPaletteIfNeeded)
  181878. {
  181879. HDC dc = GetDC (0);
  181880. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181881. ReleaseDC (0, dc);
  181882. if (n <= 8)
  181883. palette = CreateHalftonePalette (dc);
  181884. createPaletteIfNeeded = false;
  181885. }
  181886. if (palette != 0)
  181887. {
  181888. SelectPalette (dc, palette, FALSE);
  181889. RealizePalette (dc);
  181890. SetStretchBltMode (dc, HALFTONE);
  181891. }
  181892. SetMapMode (dc, MM_TEXT);
  181893. if (transparent)
  181894. {
  181895. POINT p, pos;
  181896. SIZE size;
  181897. RECT windowBounds;
  181898. GetWindowRect (hwnd, &windowBounds);
  181899. p.x = -x;
  181900. p.y = -y;
  181901. pos.x = windowBounds.left;
  181902. pos.y = windowBounds.top;
  181903. size.cx = windowBounds.right - windowBounds.left;
  181904. size.cy = windowBounds.bottom - windowBounds.top;
  181905. BLENDFUNCTION bf;
  181906. bf.AlphaFormat = AC_SRC_ALPHA;
  181907. bf.BlendFlags = 0;
  181908. bf.BlendOp = AC_SRC_OVER;
  181909. bf.SourceConstantAlpha = 0xff;
  181910. if (! maskedRegion.isEmpty())
  181911. {
  181912. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181913. {
  181914. const Rectangle<int>& r = *i.getRectangle();
  181915. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181916. }
  181917. }
  181918. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181919. }
  181920. else
  181921. {
  181922. int savedDC = 0;
  181923. if (! maskedRegion.isEmpty())
  181924. {
  181925. savedDC = SaveDC (dc);
  181926. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181927. {
  181928. const Rectangle<int>& r = *i.getRectangle();
  181929. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181930. }
  181931. }
  181932. const int w = getWidth();
  181933. const int h = getHeight();
  181934. if (hdd == 0)
  181935. {
  181936. StretchDIBits (dc,
  181937. x, y, w, h,
  181938. 0, 0, w, h,
  181939. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181940. DIB_RGB_COLORS, SRCCOPY);
  181941. }
  181942. else
  181943. {
  181944. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181945. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181946. 0, 0, w, h, 0);
  181947. }
  181948. if (! maskedRegion.isEmpty())
  181949. RestoreDC (dc, savedDC);
  181950. }
  181951. }
  181952. juce_UseDebuggingNewOperator
  181953. private:
  181954. WindowsBitmapImage (const WindowsBitmapImage&);
  181955. const WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181956. };
  181957. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181958. static int currentModifiers = 0;
  181959. static int modifiersAtLastCallback = 0;
  181960. static void updateKeyModifiers() throw()
  181961. {
  181962. currentModifiers &= ~(ModifierKeys::shiftModifier
  181963. | ModifierKeys::ctrlModifier
  181964. | ModifierKeys::altModifier);
  181965. if ((GetKeyState (VK_SHIFT) & 0x8000) != 0)
  181966. currentModifiers |= ModifierKeys::shiftModifier;
  181967. if ((GetKeyState (VK_CONTROL) & 0x8000) != 0)
  181968. currentModifiers |= ModifierKeys::ctrlModifier;
  181969. if ((GetKeyState (VK_MENU) & 0x8000) != 0)
  181970. currentModifiers |= ModifierKeys::altModifier;
  181971. if ((GetKeyState (VK_RMENU) & 0x8000) != 0)
  181972. currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181973. }
  181974. void ModifierKeys::updateCurrentModifiers() throw()
  181975. {
  181976. currentModifierFlags = currentModifiers;
  181977. }
  181978. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181979. {
  181980. SHORT k = (SHORT) keyCode;
  181981. if ((keyCode & extendedKeyModifier) == 0
  181982. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181983. k += (SHORT) T('A') - (SHORT) T('a');
  181984. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181985. (SHORT) '+', VK_OEM_PLUS,
  181986. (SHORT) '-', VK_OEM_MINUS,
  181987. (SHORT) '.', VK_OEM_PERIOD,
  181988. (SHORT) ';', VK_OEM_1,
  181989. (SHORT) ':', VK_OEM_1,
  181990. (SHORT) '/', VK_OEM_2,
  181991. (SHORT) '?', VK_OEM_2,
  181992. (SHORT) '[', VK_OEM_4,
  181993. (SHORT) ']', VK_OEM_6 };
  181994. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181995. if (k == translatedValues [i])
  181996. k = translatedValues [i + 1];
  181997. return (GetKeyState (k) & 0x8000) != 0;
  181998. }
  181999. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182000. {
  182001. updateKeyModifiers();
  182002. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182003. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0)
  182004. currentModifiers |= ModifierKeys::leftButtonModifier;
  182005. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0)
  182006. currentModifiers |= ModifierKeys::rightButtonModifier;
  182007. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0)
  182008. currentModifiers |= ModifierKeys::middleButtonModifier;
  182009. return ModifierKeys (currentModifiers);
  182010. }
  182011. static int64 getMouseEventTime() throw()
  182012. {
  182013. static int64 eventTimeOffset = 0;
  182014. static DWORD lastMessageTime = 0;
  182015. const DWORD thisMessageTime = GetMessageTime();
  182016. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  182017. {
  182018. lastMessageTime = thisMessageTime;
  182019. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  182020. }
  182021. return eventTimeOffset + thisMessageTime;
  182022. }
  182023. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  182024. {
  182025. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  182026. return callback (userData);
  182027. else
  182028. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  182029. }
  182030. class Win32ComponentPeer : public ComponentPeer
  182031. {
  182032. public:
  182033. Win32ComponentPeer (Component* const component,
  182034. const int windowStyleFlags)
  182035. : ComponentPeer (component, windowStyleFlags),
  182036. dontRepaint (false),
  182037. fullScreen (false),
  182038. isDragging (false),
  182039. isMouseOver (false),
  182040. hasCreatedCaret (false),
  182041. currentWindowIcon (0),
  182042. taskBarIcon (0),
  182043. dropTarget (0)
  182044. {
  182045. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  182046. setTitle (component->getName());
  182047. if ((windowStyleFlags & windowHasDropShadow) != 0
  182048. && Desktop::canUseSemiTransparentWindows())
  182049. {
  182050. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  182051. if (shadower != 0)
  182052. shadower->setOwner (component);
  182053. }
  182054. else
  182055. {
  182056. shadower = 0;
  182057. }
  182058. }
  182059. ~Win32ComponentPeer()
  182060. {
  182061. setTaskBarIcon (0);
  182062. deleteAndZero (shadower);
  182063. // do this before the next bit to avoid messages arriving for this window
  182064. // before it's destroyed
  182065. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  182066. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  182067. if (currentWindowIcon != 0)
  182068. DestroyIcon (currentWindowIcon);
  182069. if (dropTarget != 0)
  182070. {
  182071. dropTarget->Release();
  182072. dropTarget = 0;
  182073. }
  182074. }
  182075. void* getNativeHandle() const
  182076. {
  182077. return (void*) hwnd;
  182078. }
  182079. void setVisible (bool shouldBeVisible)
  182080. {
  182081. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  182082. if (shouldBeVisible)
  182083. InvalidateRect (hwnd, 0, 0);
  182084. else
  182085. lastPaintTime = 0;
  182086. }
  182087. void setTitle (const String& title)
  182088. {
  182089. SetWindowText (hwnd, title);
  182090. }
  182091. void setPosition (int x, int y)
  182092. {
  182093. offsetWithinParent (x, y);
  182094. SetWindowPos (hwnd, 0,
  182095. x - windowBorder.getLeft(),
  182096. y - windowBorder.getTop(),
  182097. 0, 0,
  182098. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182099. }
  182100. void repaintNowIfTransparent()
  182101. {
  182102. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182103. handlePaintMessage();
  182104. }
  182105. void updateBorderSize()
  182106. {
  182107. WINDOWINFO info;
  182108. info.cbSize = sizeof (info);
  182109. if (GetWindowInfo (hwnd, &info))
  182110. {
  182111. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182112. info.rcClient.left - info.rcWindow.left,
  182113. info.rcWindow.bottom - info.rcClient.bottom,
  182114. info.rcWindow.right - info.rcClient.right);
  182115. }
  182116. }
  182117. void setSize (int w, int h)
  182118. {
  182119. SetWindowPos (hwnd, 0, 0, 0,
  182120. w + windowBorder.getLeftAndRight(),
  182121. h + windowBorder.getTopAndBottom(),
  182122. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182123. updateBorderSize();
  182124. repaintNowIfTransparent();
  182125. }
  182126. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182127. {
  182128. fullScreen = isNowFullScreen;
  182129. offsetWithinParent (x, y);
  182130. SetWindowPos (hwnd, 0,
  182131. x - windowBorder.getLeft(),
  182132. y - windowBorder.getTop(),
  182133. w + windowBorder.getLeftAndRight(),
  182134. h + windowBorder.getTopAndBottom(),
  182135. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182136. updateBorderSize();
  182137. repaintNowIfTransparent();
  182138. }
  182139. void getBounds (int& x, int& y, int& w, int& h) const
  182140. {
  182141. RECT r;
  182142. GetWindowRect (hwnd, &r);
  182143. x = r.left;
  182144. y = r.top;
  182145. w = r.right - x;
  182146. h = r.bottom - y;
  182147. HWND parentH = GetParent (hwnd);
  182148. if (parentH != 0)
  182149. {
  182150. GetWindowRect (parentH, &r);
  182151. x -= r.left;
  182152. y -= r.top;
  182153. }
  182154. x += windowBorder.getLeft();
  182155. y += windowBorder.getTop();
  182156. w -= windowBorder.getLeftAndRight();
  182157. h -= windowBorder.getTopAndBottom();
  182158. }
  182159. int getScreenX() const
  182160. {
  182161. RECT r;
  182162. GetWindowRect (hwnd, &r);
  182163. return r.left + windowBorder.getLeft();
  182164. }
  182165. int getScreenY() const
  182166. {
  182167. RECT r;
  182168. GetWindowRect (hwnd, &r);
  182169. return r.top + windowBorder.getTop();
  182170. }
  182171. void relativePositionToGlobal (int& x, int& y)
  182172. {
  182173. RECT r;
  182174. GetWindowRect (hwnd, &r);
  182175. x += r.left + windowBorder.getLeft();
  182176. y += r.top + windowBorder.getTop();
  182177. }
  182178. void globalPositionToRelative (int& x, int& y)
  182179. {
  182180. RECT r;
  182181. GetWindowRect (hwnd, &r);
  182182. x -= r.left + windowBorder.getLeft();
  182183. y -= r.top + windowBorder.getTop();
  182184. }
  182185. void setMinimised (bool shouldBeMinimised)
  182186. {
  182187. if (shouldBeMinimised != isMinimised())
  182188. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182189. }
  182190. bool isMinimised() const
  182191. {
  182192. WINDOWPLACEMENT wp;
  182193. wp.length = sizeof (WINDOWPLACEMENT);
  182194. GetWindowPlacement (hwnd, &wp);
  182195. return wp.showCmd == SW_SHOWMINIMIZED;
  182196. }
  182197. void setFullScreen (bool shouldBeFullScreen)
  182198. {
  182199. setMinimised (false);
  182200. if (fullScreen != shouldBeFullScreen)
  182201. {
  182202. fullScreen = shouldBeFullScreen;
  182203. const ComponentDeletionWatcher deletionChecker (component);
  182204. if (! fullScreen)
  182205. {
  182206. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  182207. if (hasTitleBar())
  182208. ShowWindow (hwnd, SW_SHOWNORMAL);
  182209. if (! boundsCopy.isEmpty())
  182210. {
  182211. setBounds (boundsCopy.getX(),
  182212. boundsCopy.getY(),
  182213. boundsCopy.getWidth(),
  182214. boundsCopy.getHeight(),
  182215. false);
  182216. }
  182217. }
  182218. else
  182219. {
  182220. if (hasTitleBar())
  182221. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182222. else
  182223. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182224. }
  182225. if (! deletionChecker.hasBeenDeleted())
  182226. handleMovedOrResized();
  182227. }
  182228. }
  182229. bool isFullScreen() const
  182230. {
  182231. if (! hasTitleBar())
  182232. return fullScreen;
  182233. WINDOWPLACEMENT wp;
  182234. wp.length = sizeof (wp);
  182235. GetWindowPlacement (hwnd, &wp);
  182236. return wp.showCmd == SW_SHOWMAXIMIZED;
  182237. }
  182238. bool contains (int x, int y, bool trueIfInAChildWindow) const
  182239. {
  182240. RECT r;
  182241. GetWindowRect (hwnd, &r);
  182242. POINT p;
  182243. p.x = x + r.left + windowBorder.getLeft();
  182244. p.y = y + r.top + windowBorder.getTop();
  182245. HWND w = WindowFromPoint (p);
  182246. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182247. }
  182248. const BorderSize getFrameSize() const
  182249. {
  182250. return windowBorder;
  182251. }
  182252. bool setAlwaysOnTop (bool alwaysOnTop)
  182253. {
  182254. const bool oldDeactivate = shouldDeactivateTitleBar;
  182255. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182256. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182257. 0, 0, 0, 0,
  182258. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182259. shouldDeactivateTitleBar = oldDeactivate;
  182260. if (shadower != 0)
  182261. shadower->componentBroughtToFront (*component);
  182262. return true;
  182263. }
  182264. void toFront (bool makeActive)
  182265. {
  182266. setMinimised (false);
  182267. const bool oldDeactivate = shouldDeactivateTitleBar;
  182268. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182269. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182270. : &toFrontCallback2,
  182271. (void*) hwnd);
  182272. shouldDeactivateTitleBar = oldDeactivate;
  182273. if (! makeActive)
  182274. {
  182275. // in this case a broughttofront call won't have occured, so do it now..
  182276. handleBroughtToFront();
  182277. }
  182278. }
  182279. void toBehind (ComponentPeer* other)
  182280. {
  182281. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182282. jassert (otherPeer != 0); // wrong type of window?
  182283. if (otherPeer != 0)
  182284. {
  182285. setMinimised (false);
  182286. // must be careful not to try to put a topmost window behind a normal one, or win32
  182287. // promotes the normal one to be topmost!
  182288. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182289. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182290. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182291. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182292. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182293. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182294. }
  182295. }
  182296. bool isFocused() const
  182297. {
  182298. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182299. }
  182300. void grabFocus()
  182301. {
  182302. const bool oldDeactivate = shouldDeactivateTitleBar;
  182303. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182304. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182305. shouldDeactivateTitleBar = oldDeactivate;
  182306. }
  182307. void textInputRequired (int /*x*/, int /*y*/)
  182308. {
  182309. if (! hasCreatedCaret)
  182310. {
  182311. hasCreatedCaret = true;
  182312. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182313. }
  182314. ShowCaret (hwnd);
  182315. SetCaretPos (0, 0);
  182316. }
  182317. void repaint (int x, int y, int w, int h)
  182318. {
  182319. const RECT r = { x, y, x + w, y + h };
  182320. InvalidateRect (hwnd, &r, FALSE);
  182321. }
  182322. void performAnyPendingRepaintsNow()
  182323. {
  182324. MSG m;
  182325. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182326. DispatchMessage (&m);
  182327. }
  182328. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182329. {
  182330. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182331. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182332. return 0;
  182333. }
  182334. void setTaskBarIcon (const Image* const image)
  182335. {
  182336. if (image != 0)
  182337. {
  182338. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182339. if (taskBarIcon == 0)
  182340. {
  182341. taskBarIcon = new NOTIFYICONDATA();
  182342. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182343. taskBarIcon->hWnd = (HWND) hwnd;
  182344. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182345. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182346. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182347. taskBarIcon->hIcon = hicon;
  182348. taskBarIcon->szTip[0] = 0;
  182349. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182350. }
  182351. else
  182352. {
  182353. HICON oldIcon = taskBarIcon->hIcon;
  182354. taskBarIcon->hIcon = hicon;
  182355. taskBarIcon->uFlags = NIF_ICON;
  182356. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182357. DestroyIcon (oldIcon);
  182358. }
  182359. DestroyIcon (hicon);
  182360. }
  182361. else if (taskBarIcon != 0)
  182362. {
  182363. taskBarIcon->uFlags = 0;
  182364. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182365. DestroyIcon (taskBarIcon->hIcon);
  182366. deleteAndZero (taskBarIcon);
  182367. }
  182368. }
  182369. void setTaskBarIconToolTip (const String& toolTip) const
  182370. {
  182371. if (taskBarIcon != 0)
  182372. {
  182373. taskBarIcon->uFlags = NIF_TIP;
  182374. toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182375. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182376. }
  182377. }
  182378. bool isInside (HWND h) const
  182379. {
  182380. return GetAncestor (hwnd, GA_ROOT) == h;
  182381. }
  182382. juce_UseDebuggingNewOperator
  182383. bool dontRepaint;
  182384. private:
  182385. HWND hwnd;
  182386. DropShadower* shadower;
  182387. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182388. BorderSize windowBorder;
  182389. HICON currentWindowIcon;
  182390. NOTIFYICONDATA* taskBarIcon;
  182391. IDropTarget* dropTarget;
  182392. class TemporaryImage : public Timer
  182393. {
  182394. public:
  182395. TemporaryImage()
  182396. : image (0)
  182397. {
  182398. }
  182399. ~TemporaryImage()
  182400. {
  182401. delete image;
  182402. }
  182403. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182404. {
  182405. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182406. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182407. {
  182408. delete image;
  182409. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182410. }
  182411. startTimer (3000);
  182412. return image;
  182413. }
  182414. void timerCallback()
  182415. {
  182416. stopTimer();
  182417. deleteAndZero (image);
  182418. }
  182419. private:
  182420. WindowsBitmapImage* image;
  182421. TemporaryImage (const TemporaryImage&);
  182422. const TemporaryImage& operator= (const TemporaryImage&);
  182423. };
  182424. TemporaryImage offscreenImageGenerator;
  182425. class WindowClassHolder : public DeletedAtShutdown
  182426. {
  182427. public:
  182428. WindowClassHolder()
  182429. : windowClassName ("JUCE_")
  182430. {
  182431. // this name has to be different for each app/dll instance because otherwise
  182432. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182433. // window class).
  182434. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182435. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182436. TCHAR moduleFile [1024];
  182437. moduleFile[0] = 0;
  182438. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182439. WORD iconNum = 0;
  182440. WNDCLASSEX wcex;
  182441. wcex.cbSize = sizeof (wcex);
  182442. wcex.style = CS_OWNDC;
  182443. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182444. wcex.lpszClassName = windowClassName;
  182445. wcex.cbClsExtra = 0;
  182446. wcex.cbWndExtra = 32;
  182447. wcex.hInstance = moduleHandle;
  182448. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182449. iconNum = 1;
  182450. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182451. wcex.hCursor = 0;
  182452. wcex.hbrBackground = 0;
  182453. wcex.lpszMenuName = 0;
  182454. RegisterClassEx (&wcex);
  182455. }
  182456. ~WindowClassHolder()
  182457. {
  182458. if (ComponentPeer::getNumPeers() == 0)
  182459. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182460. clearSingletonInstance();
  182461. }
  182462. String windowClassName;
  182463. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182464. };
  182465. static void* createWindowCallback (void* userData)
  182466. {
  182467. ((Win32ComponentPeer*) userData)->createWindow();
  182468. return 0;
  182469. }
  182470. void createWindow()
  182471. {
  182472. DWORD exstyle = WS_EX_ACCEPTFILES;
  182473. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182474. if (hasTitleBar())
  182475. {
  182476. type |= WS_OVERLAPPED;
  182477. exstyle |= WS_EX_APPWINDOW;
  182478. if ((styleFlags & windowHasCloseButton) != 0)
  182479. {
  182480. type |= WS_SYSMENU;
  182481. }
  182482. else
  182483. {
  182484. // annoyingly, windows won't let you have a min/max button without a close button
  182485. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182486. }
  182487. if ((styleFlags & windowIsResizable) != 0)
  182488. type |= WS_THICKFRAME;
  182489. }
  182490. else
  182491. {
  182492. type |= WS_POPUP | WS_SYSMENU;
  182493. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182494. exstyle |= WS_EX_TOOLWINDOW;
  182495. else
  182496. exstyle |= WS_EX_APPWINDOW;
  182497. }
  182498. if ((styleFlags & windowHasMinimiseButton) != 0)
  182499. type |= WS_MINIMIZEBOX;
  182500. if ((styleFlags & windowHasMaximiseButton) != 0)
  182501. type |= WS_MAXIMIZEBOX;
  182502. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182503. exstyle |= WS_EX_TRANSPARENT;
  182504. if ((styleFlags & windowIsSemiTransparent) != 0
  182505. && Desktop::canUseSemiTransparentWindows())
  182506. exstyle |= WS_EX_LAYERED;
  182507. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182508. if (hwnd != 0)
  182509. {
  182510. SetWindowLongPtr (hwnd, 0, 0);
  182511. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182512. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182513. if (dropTarget == 0)
  182514. dropTarget = new JuceDropTarget (this);
  182515. RegisterDragDrop (hwnd, dropTarget);
  182516. updateBorderSize();
  182517. // Calling this function here is (for some reason) necessary to make Windows
  182518. // correctly enable the menu items that we specify in the wm_initmenu message.
  182519. GetSystemMenu (hwnd, false);
  182520. }
  182521. else
  182522. {
  182523. jassertfalse
  182524. }
  182525. }
  182526. static void* destroyWindowCallback (void* handle)
  182527. {
  182528. RevokeDragDrop ((HWND) handle);
  182529. DestroyWindow ((HWND) handle);
  182530. return 0;
  182531. }
  182532. static void* toFrontCallback1 (void* h)
  182533. {
  182534. SetForegroundWindow ((HWND) h);
  182535. return 0;
  182536. }
  182537. static void* toFrontCallback2 (void* h)
  182538. {
  182539. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182540. return 0;
  182541. }
  182542. static void* setFocusCallback (void* h)
  182543. {
  182544. SetFocus ((HWND) h);
  182545. return 0;
  182546. }
  182547. static void* getFocusCallback (void*)
  182548. {
  182549. return (void*) GetFocus();
  182550. }
  182551. void offsetWithinParent (int& x, int& y) const
  182552. {
  182553. if (isTransparent())
  182554. {
  182555. HWND parentHwnd = GetParent (hwnd);
  182556. if (parentHwnd != 0)
  182557. {
  182558. RECT parentRect;
  182559. GetWindowRect (parentHwnd, &parentRect);
  182560. x += parentRect.left;
  182561. y += parentRect.top;
  182562. }
  182563. }
  182564. }
  182565. bool isTransparent() const
  182566. {
  182567. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182568. }
  182569. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182570. void setIcon (const Image& newIcon)
  182571. {
  182572. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182573. if (hicon != 0)
  182574. {
  182575. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182576. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182577. if (currentWindowIcon != 0)
  182578. DestroyIcon (currentWindowIcon);
  182579. currentWindowIcon = hicon;
  182580. }
  182581. }
  182582. void handlePaintMessage()
  182583. {
  182584. #if DEBUG_REPAINT_TIMES
  182585. const double paintStart = Time::getMillisecondCounterHiRes();
  182586. #endif
  182587. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182588. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182589. PAINTSTRUCT paintStruct;
  182590. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182591. // message and become re-entrant, but that's OK
  182592. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182593. // corrupt the image it's using to paint into, so do a check here.
  182594. static bool reentrant = false;
  182595. if (reentrant)
  182596. {
  182597. DeleteObject (rgn);
  182598. EndPaint (hwnd, &paintStruct);
  182599. return;
  182600. }
  182601. reentrant = true;
  182602. // this is the rectangle to update..
  182603. int x = paintStruct.rcPaint.left;
  182604. int y = paintStruct.rcPaint.top;
  182605. int w = paintStruct.rcPaint.right - x;
  182606. int h = paintStruct.rcPaint.bottom - y;
  182607. const bool transparent = isTransparent();
  182608. if (transparent)
  182609. {
  182610. // it's not possible to have a transparent window with a title bar at the moment!
  182611. jassert (! hasTitleBar());
  182612. RECT r;
  182613. GetWindowRect (hwnd, &r);
  182614. x = y = 0;
  182615. w = r.right - r.left;
  182616. h = r.bottom - r.top;
  182617. }
  182618. if (w > 0 && h > 0)
  182619. {
  182620. clearMaskedRegion();
  182621. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182622. RectangleList contextClip;
  182623. bool needToPaintAll = true;
  182624. if (regionType == COMPLEXREGION && ! transparent)
  182625. {
  182626. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182627. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182628. DeleteObject (clipRgn);
  182629. char rgnData [8192];
  182630. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182631. if (res > 0 && res <= sizeof (rgnData))
  182632. {
  182633. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182634. if (hdr->iType == RDH_RECTANGLES
  182635. && hdr->rcBound.right - hdr->rcBound.left >= w
  182636. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182637. {
  182638. needToPaintAll = false;
  182639. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182640. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182641. while (--num >= 0)
  182642. {
  182643. // (need to move this one pixel to the left because of a win32 bug)
  182644. const int cx = jmax (x, (int) rects->left - 1);
  182645. const int cy = rects->top;
  182646. const int cw = rects->right - cx;
  182647. const int ch = rects->bottom - rects->top;
  182648. if (cx + cw - x <= w && cy + ch - y <= h)
  182649. {
  182650. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182651. }
  182652. else
  182653. {
  182654. needToPaintAll = true;
  182655. break;
  182656. }
  182657. ++rects;
  182658. }
  182659. }
  182660. }
  182661. }
  182662. if (needToPaintAll)
  182663. {
  182664. contextClip.clear();
  182665. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182666. }
  182667. if (transparent)
  182668. {
  182669. RectangleList::Iterator i (contextClip);
  182670. while (i.next())
  182671. {
  182672. const Rectangle<int>& r = *i.getRectangle();
  182673. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182674. }
  182675. }
  182676. // if the component's not opaque, this won't draw properly unless the platform can support this
  182677. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182678. updateCurrentModifiers();
  182679. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182680. context.clipToRectangleList (contextClip);
  182681. context.setOrigin (-x, -y);
  182682. handlePaint (context);
  182683. if (! dontRepaint)
  182684. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182685. }
  182686. DeleteObject (rgn);
  182687. EndPaint (hwnd, &paintStruct);
  182688. reentrant = false;
  182689. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182690. _fpreset(); // because some graphics cards can unmask FP exceptions
  182691. #endif
  182692. lastPaintTime = Time::getMillisecondCounter();
  182693. #if DEBUG_REPAINT_TIMES
  182694. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182695. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182696. #endif
  182697. }
  182698. void doMouseMove (const int x, const int y)
  182699. {
  182700. static uint32 lastMouseTime = 0;
  182701. // this can be set to throttle the mouse-messages to less than a
  182702. // certain number per second, as things can get unresponsive
  182703. // if each drag or move callback has to do a lot of work.
  182704. const int maxMouseMovesPerSecond = 60;
  182705. const int64 mouseEventTime = getMouseEventTime();
  182706. if (! isMouseOver)
  182707. {
  182708. isMouseOver = true;
  182709. TRACKMOUSEEVENT tme;
  182710. tme.cbSize = sizeof (tme);
  182711. tme.dwFlags = TME_LEAVE;
  182712. tme.hwndTrack = hwnd;
  182713. tme.dwHoverTime = 0;
  182714. if (! TrackMouseEvent (&tme))
  182715. {
  182716. jassertfalse;
  182717. }
  182718. updateKeyModifiers();
  182719. handleMouseEnter (x, y, mouseEventTime);
  182720. }
  182721. else if (! isDragging)
  182722. {
  182723. if (((unsigned int) x) < (unsigned int) component->getWidth()
  182724. && ((unsigned int) y) < (unsigned int) component->getHeight())
  182725. {
  182726. RECT r;
  182727. GetWindowRect (hwnd, &r);
  182728. POINT p;
  182729. p.x = x + r.left + windowBorder.getLeft();
  182730. p.y = y + r.top + windowBorder.getTop();
  182731. if (WindowFromPoint (p) == hwnd)
  182732. {
  182733. const uint32 now = Time::getMillisecondCounter();
  182734. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182735. {
  182736. lastMouseTime = now;
  182737. handleMouseMove (x, y, mouseEventTime);
  182738. }
  182739. }
  182740. }
  182741. }
  182742. else
  182743. {
  182744. const uint32 now = Time::getMillisecondCounter();
  182745. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182746. {
  182747. lastMouseTime = now;
  182748. handleMouseDrag (x, y, mouseEventTime);
  182749. }
  182750. }
  182751. }
  182752. void doMouseDown (const int x, const int y, const WPARAM wParam)
  182753. {
  182754. if (GetCapture() != hwnd)
  182755. SetCapture (hwnd);
  182756. doMouseMove (x, y);
  182757. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182758. if ((wParam & MK_LBUTTON) != 0)
  182759. currentModifiers |= ModifierKeys::leftButtonModifier;
  182760. if ((wParam & MK_RBUTTON) != 0)
  182761. currentModifiers |= ModifierKeys::rightButtonModifier;
  182762. if ((wParam & MK_MBUTTON) != 0)
  182763. currentModifiers |= ModifierKeys::middleButtonModifier;
  182764. updateKeyModifiers();
  182765. isDragging = true;
  182766. handleMouseDown (x, y, getMouseEventTime());
  182767. }
  182768. void doMouseUp (const int x, const int y, const WPARAM wParam)
  182769. {
  182770. int numButtons = 0;
  182771. if ((wParam & MK_LBUTTON) != 0)
  182772. ++numButtons;
  182773. if ((wParam & MK_RBUTTON) != 0)
  182774. ++numButtons;
  182775. if ((wParam & MK_MBUTTON) != 0)
  182776. ++numButtons;
  182777. const int oldModifiers = currentModifiers;
  182778. // update the currentmodifiers only after the callback, so the callback
  182779. // knows which button was released.
  182780. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182781. if ((wParam & MK_LBUTTON) != 0)
  182782. currentModifiers |= ModifierKeys::leftButtonModifier;
  182783. if ((wParam & MK_RBUTTON) != 0)
  182784. currentModifiers |= ModifierKeys::rightButtonModifier;
  182785. if ((wParam & MK_MBUTTON) != 0)
  182786. currentModifiers |= ModifierKeys::middleButtonModifier;
  182787. updateKeyModifiers();
  182788. isDragging = false;
  182789. // release the mouse capture if the user's not still got a button down
  182790. if (numButtons == 0 && hwnd == GetCapture())
  182791. ReleaseCapture();
  182792. handleMouseUp (oldModifiers, x, y, getMouseEventTime());
  182793. }
  182794. void doCaptureChanged()
  182795. {
  182796. if (isDragging)
  182797. {
  182798. RECT wr;
  182799. GetWindowRect (hwnd, &wr);
  182800. const DWORD mp = GetMessagePos();
  182801. doMouseUp (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182802. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182803. (WPARAM) getMouseEventTime());
  182804. }
  182805. }
  182806. void doMouseExit()
  182807. {
  182808. if (isMouseOver)
  182809. {
  182810. isMouseOver = false;
  182811. RECT wr;
  182812. GetWindowRect (hwnd, &wr);
  182813. const DWORD mp = GetMessagePos();
  182814. handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182815. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182816. getMouseEventTime());
  182817. }
  182818. }
  182819. void doMouseWheel (const WPARAM wParam, const bool isVertical)
  182820. {
  182821. updateKeyModifiers();
  182822. const int amount = jlimit (-1000, 1000, (int) (0.75f * (short) HIWORD (wParam)));
  182823. handleMouseWheel (isVertical ? 0 : amount,
  182824. isVertical ? amount : 0,
  182825. getMouseEventTime());
  182826. }
  182827. void sendModifierKeyChangeIfNeeded()
  182828. {
  182829. if (modifiersAtLastCallback != currentModifiers)
  182830. {
  182831. modifiersAtLastCallback = currentModifiers;
  182832. handleModifierKeysChange();
  182833. }
  182834. }
  182835. bool doKeyUp (const WPARAM key)
  182836. {
  182837. updateKeyModifiers();
  182838. switch (key)
  182839. {
  182840. case VK_SHIFT:
  182841. case VK_CONTROL:
  182842. case VK_MENU:
  182843. case VK_CAPITAL:
  182844. case VK_LWIN:
  182845. case VK_RWIN:
  182846. case VK_APPS:
  182847. case VK_NUMLOCK:
  182848. case VK_SCROLL:
  182849. case VK_LSHIFT:
  182850. case VK_RSHIFT:
  182851. case VK_LCONTROL:
  182852. case VK_LMENU:
  182853. case VK_RCONTROL:
  182854. case VK_RMENU:
  182855. sendModifierKeyChangeIfNeeded();
  182856. }
  182857. return handleKeyUpOrDown (false)
  182858. || Component::getCurrentlyModalComponent() != 0;
  182859. }
  182860. bool doKeyDown (const WPARAM key)
  182861. {
  182862. updateKeyModifiers();
  182863. bool used = false;
  182864. switch (key)
  182865. {
  182866. case VK_SHIFT:
  182867. case VK_LSHIFT:
  182868. case VK_RSHIFT:
  182869. case VK_CONTROL:
  182870. case VK_LCONTROL:
  182871. case VK_RCONTROL:
  182872. case VK_MENU:
  182873. case VK_LMENU:
  182874. case VK_RMENU:
  182875. case VK_LWIN:
  182876. case VK_RWIN:
  182877. case VK_CAPITAL:
  182878. case VK_NUMLOCK:
  182879. case VK_SCROLL:
  182880. case VK_APPS:
  182881. sendModifierKeyChangeIfNeeded();
  182882. break;
  182883. case VK_LEFT:
  182884. case VK_RIGHT:
  182885. case VK_UP:
  182886. case VK_DOWN:
  182887. case VK_PRIOR:
  182888. case VK_NEXT:
  182889. case VK_HOME:
  182890. case VK_END:
  182891. case VK_DELETE:
  182892. case VK_INSERT:
  182893. case VK_F1:
  182894. case VK_F2:
  182895. case VK_F3:
  182896. case VK_F4:
  182897. case VK_F5:
  182898. case VK_F6:
  182899. case VK_F7:
  182900. case VK_F8:
  182901. case VK_F9:
  182902. case VK_F10:
  182903. case VK_F11:
  182904. case VK_F12:
  182905. case VK_F13:
  182906. case VK_F14:
  182907. case VK_F15:
  182908. case VK_F16:
  182909. used = handleKeyUpOrDown (true);
  182910. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182911. break;
  182912. case VK_ADD:
  182913. case VK_SUBTRACT:
  182914. case VK_MULTIPLY:
  182915. case VK_DIVIDE:
  182916. case VK_SEPARATOR:
  182917. case VK_DECIMAL:
  182918. used = handleKeyUpOrDown (true);
  182919. break;
  182920. default:
  182921. used = handleKeyUpOrDown (true);
  182922. {
  182923. MSG msg;
  182924. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182925. {
  182926. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182927. // manually generate the key-press event that matches this key-down.
  182928. const UINT keyChar = MapVirtualKey (key, 2);
  182929. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182930. }
  182931. }
  182932. break;
  182933. }
  182934. if (Component::getCurrentlyModalComponent() != 0)
  182935. used = true;
  182936. return used;
  182937. }
  182938. bool doKeyChar (int key, const LPARAM flags)
  182939. {
  182940. updateKeyModifiers();
  182941. juce_wchar textChar = (juce_wchar) key;
  182942. const int virtualScanCode = (flags >> 16) & 0xff;
  182943. if (key >= '0' && key <= '9')
  182944. {
  182945. switch (virtualScanCode) // check for a numeric keypad scan-code
  182946. {
  182947. case 0x52:
  182948. case 0x4f:
  182949. case 0x50:
  182950. case 0x51:
  182951. case 0x4b:
  182952. case 0x4c:
  182953. case 0x4d:
  182954. case 0x47:
  182955. case 0x48:
  182956. case 0x49:
  182957. key = (key - '0') + KeyPress::numberPad0;
  182958. break;
  182959. default:
  182960. break;
  182961. }
  182962. }
  182963. else
  182964. {
  182965. // convert the scan code to an unmodified character code..
  182966. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182967. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182968. keyChar = LOWORD (keyChar);
  182969. if (keyChar != 0)
  182970. key = (int) keyChar;
  182971. // avoid sending junk text characters for some control-key combinations
  182972. if (textChar < ' ' && (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) != 0)
  182973. textChar = 0;
  182974. }
  182975. return handleKeyPress (key, textChar);
  182976. }
  182977. bool doAppCommand (const LPARAM lParam)
  182978. {
  182979. int key = 0;
  182980. switch (GET_APPCOMMAND_LPARAM (lParam))
  182981. {
  182982. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182983. key = KeyPress::playKey;
  182984. break;
  182985. case APPCOMMAND_MEDIA_STOP:
  182986. key = KeyPress::stopKey;
  182987. break;
  182988. case APPCOMMAND_MEDIA_NEXTTRACK:
  182989. key = KeyPress::fastForwardKey;
  182990. break;
  182991. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182992. key = KeyPress::rewindKey;
  182993. break;
  182994. }
  182995. if (key != 0)
  182996. {
  182997. updateKeyModifiers();
  182998. if (hwnd == GetActiveWindow())
  182999. {
  183000. handleKeyPress (key, 0);
  183001. return true;
  183002. }
  183003. }
  183004. return false;
  183005. }
  183006. class JuceDropTarget : public IDropTarget
  183007. {
  183008. public:
  183009. JuceDropTarget (Win32ComponentPeer* const owner_)
  183010. : owner (owner_),
  183011. refCount (1)
  183012. {
  183013. }
  183014. virtual ~JuceDropTarget()
  183015. {
  183016. jassert (refCount == 0);
  183017. }
  183018. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183019. {
  183020. if (id == IID_IUnknown || id == IID_IDropTarget)
  183021. {
  183022. AddRef();
  183023. *result = this;
  183024. return S_OK;
  183025. }
  183026. *result = 0;
  183027. return E_NOINTERFACE;
  183028. }
  183029. ULONG __stdcall AddRef() { return ++refCount; }
  183030. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183031. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183032. {
  183033. updateFileList (pDataObject);
  183034. int x = mousePos.x, y = mousePos.y;
  183035. owner->globalPositionToRelative (x, y);
  183036. owner->handleFileDragMove (files, x, y);
  183037. *pdwEffect = DROPEFFECT_COPY;
  183038. return S_OK;
  183039. }
  183040. HRESULT __stdcall DragLeave()
  183041. {
  183042. owner->handleFileDragExit (files);
  183043. return S_OK;
  183044. }
  183045. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183046. {
  183047. int x = mousePos.x, y = mousePos.y;
  183048. owner->globalPositionToRelative (x, y);
  183049. owner->handleFileDragMove (files, x, y);
  183050. *pdwEffect = DROPEFFECT_COPY;
  183051. return S_OK;
  183052. }
  183053. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183054. {
  183055. updateFileList (pDataObject);
  183056. int x = mousePos.x, y = mousePos.y;
  183057. owner->globalPositionToRelative (x, y);
  183058. owner->handleFileDragDrop (files, x, y);
  183059. *pdwEffect = DROPEFFECT_COPY;
  183060. return S_OK;
  183061. }
  183062. private:
  183063. Win32ComponentPeer* const owner;
  183064. int refCount;
  183065. StringArray files;
  183066. void updateFileList (IDataObject* const pDataObject)
  183067. {
  183068. files.clear();
  183069. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183070. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183071. if (pDataObject->GetData (&format, &medium) == S_OK)
  183072. {
  183073. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  183074. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  183075. unsigned int i = 0;
  183076. if (pDropFiles->fWide)
  183077. {
  183078. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  183079. for (;;)
  183080. {
  183081. unsigned int len = 0;
  183082. while (i + len < totalLen && fname [i + len] != 0)
  183083. ++len;
  183084. if (len == 0)
  183085. break;
  183086. files.add (String (fname + i, len));
  183087. i += len + 1;
  183088. }
  183089. }
  183090. else
  183091. {
  183092. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  183093. for (;;)
  183094. {
  183095. unsigned int len = 0;
  183096. while (i + len < totalLen && fname [i + len] != 0)
  183097. ++len;
  183098. if (len == 0)
  183099. break;
  183100. files.add (String (fname + i, len));
  183101. i += len + 1;
  183102. }
  183103. }
  183104. GlobalUnlock (medium.hGlobal);
  183105. }
  183106. }
  183107. JuceDropTarget (const JuceDropTarget&);
  183108. const JuceDropTarget& operator= (const JuceDropTarget&);
  183109. };
  183110. void doSettingChange()
  183111. {
  183112. Desktop::getInstance().refreshMonitorSizes();
  183113. if (fullScreen && ! isMinimised())
  183114. {
  183115. const Rectangle<int> r (component->getParentMonitorArea());
  183116. SetWindowPos (hwnd, 0,
  183117. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  183118. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  183119. }
  183120. }
  183121. public:
  183122. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183123. {
  183124. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  183125. if (peer != 0)
  183126. return peer->peerWindowProc (h, message, wParam, lParam);
  183127. return DefWindowProc (h, message, wParam, lParam);
  183128. }
  183129. private:
  183130. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183131. {
  183132. if (isValidPeer (this))
  183133. {
  183134. switch (message)
  183135. {
  183136. case WM_NCHITTEST:
  183137. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  183138. return HTTRANSPARENT;
  183139. if (hasTitleBar())
  183140. break;
  183141. return HTCLIENT;
  183142. case WM_PAINT:
  183143. handlePaintMessage();
  183144. return 0;
  183145. case WM_NCPAINT:
  183146. if (wParam != 1)
  183147. handlePaintMessage();
  183148. if (hasTitleBar())
  183149. break;
  183150. return 0;
  183151. case WM_ERASEBKGND:
  183152. case WM_NCCALCSIZE:
  183153. if (hasTitleBar())
  183154. break;
  183155. return 1;
  183156. case WM_MOUSEMOVE:
  183157. doMouseMove (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  183158. return 0;
  183159. case WM_MOUSELEAVE:
  183160. doMouseExit();
  183161. return 0;
  183162. case WM_LBUTTONDOWN:
  183163. case WM_MBUTTONDOWN:
  183164. case WM_RBUTTONDOWN:
  183165. doMouseDown (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183166. return 0;
  183167. case WM_LBUTTONUP:
  183168. case WM_MBUTTONUP:
  183169. case WM_RBUTTONUP:
  183170. doMouseUp (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183171. return 0;
  183172. case WM_CAPTURECHANGED:
  183173. doCaptureChanged();
  183174. return 0;
  183175. case WM_NCMOUSEMOVE:
  183176. if (hasTitleBar())
  183177. break;
  183178. return 0;
  183179. case 0x020A: /* WM_MOUSEWHEEL */
  183180. doMouseWheel (wParam, true);
  183181. return 0;
  183182. case 0x020E: /* WM_MOUSEHWHEEL */
  183183. doMouseWheel (wParam, false);
  183184. return 0;
  183185. case WM_WINDOWPOSCHANGING:
  183186. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183187. {
  183188. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183189. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183190. {
  183191. if (constrainer != 0)
  183192. {
  183193. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  183194. component->getY() - windowBorder.getTop(),
  183195. component->getWidth() + windowBorder.getLeftAndRight(),
  183196. component->getHeight() + windowBorder.getTopAndBottom());
  183197. constrainer->checkBounds (wp->x, wp->y, wp->cx, wp->cy,
  183198. current,
  183199. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183200. wp->y != current.getY() && wp->y + wp->cy == current.getBottom(),
  183201. wp->x != current.getX() && wp->x + wp->cx == current.getRight(),
  183202. wp->y == current.getY() && wp->y + wp->cy != current.getBottom(),
  183203. wp->x == current.getX() && wp->x + wp->cx != current.getRight());
  183204. }
  183205. }
  183206. }
  183207. return 0;
  183208. case WM_WINDOWPOSCHANGED:
  183209. handleMovedOrResized();
  183210. if (dontRepaint)
  183211. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183212. return 0;
  183213. case WM_KEYDOWN:
  183214. case WM_SYSKEYDOWN:
  183215. if (doKeyDown (wParam))
  183216. return 0;
  183217. break;
  183218. case WM_KEYUP:
  183219. case WM_SYSKEYUP:
  183220. if (doKeyUp (wParam))
  183221. return 0;
  183222. break;
  183223. case WM_CHAR:
  183224. if (doKeyChar ((int) wParam, lParam))
  183225. return 0;
  183226. break;
  183227. case WM_APPCOMMAND:
  183228. if (doAppCommand (lParam))
  183229. return TRUE;
  183230. break;
  183231. case WM_SETFOCUS:
  183232. updateKeyModifiers();
  183233. handleFocusGain();
  183234. break;
  183235. case WM_KILLFOCUS:
  183236. if (hasCreatedCaret)
  183237. {
  183238. hasCreatedCaret = false;
  183239. DestroyCaret();
  183240. }
  183241. handleFocusLoss();
  183242. break;
  183243. case WM_ACTIVATEAPP:
  183244. // Windows does weird things to process priority when you swap apps,
  183245. // so this forces an update when the app is brought to the front
  183246. if (wParam != FALSE)
  183247. juce_repeatLastProcessPriority();
  183248. else
  183249. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183250. juce_CheckCurrentlyFocusedTopLevelWindow();
  183251. modifiersAtLastCallback = -1;
  183252. return 0;
  183253. case WM_ACTIVATE:
  183254. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183255. {
  183256. modifiersAtLastCallback = -1;
  183257. updateKeyModifiers();
  183258. if (isMinimised())
  183259. {
  183260. component->repaint();
  183261. handleMovedOrResized();
  183262. if (! isValidMessageListener())
  183263. return 0;
  183264. }
  183265. if (LOWORD (wParam) == WA_CLICKACTIVE
  183266. && component->isCurrentlyBlockedByAnotherModalComponent())
  183267. {
  183268. int mx, my;
  183269. component->getMouseXYRelative (mx, my);
  183270. Component* const underMouse = component->getComponentAt (mx, my);
  183271. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183272. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183273. return 0;
  183274. }
  183275. handleBroughtToFront();
  183276. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183277. Component::getCurrentlyModalComponent()->toFront (true);
  183278. return 0;
  183279. }
  183280. break;
  183281. case WM_NCACTIVATE:
  183282. // while a temporary window is being shown, prevent Windows from deactivating the
  183283. // title bars of our main windows.
  183284. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183285. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183286. break;
  183287. case WM_MOUSEACTIVATE:
  183288. if (! component->getMouseClickGrabsKeyboardFocus())
  183289. return MA_NOACTIVATE;
  183290. break;
  183291. case WM_SHOWWINDOW:
  183292. if (wParam != 0)
  183293. handleBroughtToFront();
  183294. break;
  183295. case WM_CLOSE:
  183296. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183297. handleUserClosingWindow();
  183298. return 0;
  183299. case WM_QUERYENDSESSION:
  183300. if (JUCEApplication::getInstance() != 0)
  183301. {
  183302. JUCEApplication::getInstance()->systemRequestedQuit();
  183303. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183304. }
  183305. return TRUE;
  183306. case WM_TRAYNOTIFY:
  183307. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183308. {
  183309. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183310. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183311. {
  183312. Component* const current = Component::getCurrentlyModalComponent();
  183313. if (current != 0)
  183314. current->inputAttemptWhenModal();
  183315. }
  183316. }
  183317. else
  183318. {
  183319. const int oldModifiers = currentModifiers;
  183320. MouseEvent e (0, 0, ModifierKeys::getCurrentModifiersRealtime(), component,
  183321. getMouseEventTime(), 0, 0, getMouseEventTime(), 1, false);
  183322. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183323. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier);
  183324. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183325. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::rightButtonModifier);
  183326. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183327. {
  183328. SetFocus (hwnd);
  183329. SetForegroundWindow (hwnd);
  183330. component->mouseDown (e);
  183331. }
  183332. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183333. {
  183334. e.mods = ModifierKeys (oldModifiers);
  183335. component->mouseUp (e);
  183336. }
  183337. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183338. {
  183339. e.mods = ModifierKeys (oldModifiers);
  183340. component->mouseDoubleClick (e);
  183341. }
  183342. else if (lParam == WM_MOUSEMOVE)
  183343. {
  183344. component->mouseMove (e);
  183345. }
  183346. }
  183347. break;
  183348. case WM_SYNCPAINT:
  183349. return 0;
  183350. case WM_PALETTECHANGED:
  183351. InvalidateRect (h, 0, 0);
  183352. break;
  183353. case WM_DISPLAYCHANGE:
  183354. InvalidateRect (h, 0, 0);
  183355. createPaletteIfNeeded = true;
  183356. // intentional fall-through...
  183357. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183358. doSettingChange();
  183359. break;
  183360. case WM_INITMENU:
  183361. if (! hasTitleBar())
  183362. {
  183363. if (isFullScreen())
  183364. {
  183365. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183366. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183367. }
  183368. else if (! isMinimised())
  183369. {
  183370. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183371. }
  183372. }
  183373. break;
  183374. case WM_SYSCOMMAND:
  183375. switch (wParam & 0xfff0)
  183376. {
  183377. case SC_CLOSE:
  183378. if (sendInputAttemptWhenModalMessage())
  183379. return 0;
  183380. if (hasTitleBar())
  183381. {
  183382. PostMessage (h, WM_CLOSE, 0, 0);
  183383. return 0;
  183384. }
  183385. break;
  183386. case SC_KEYMENU:
  183387. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183388. // obscure situations that can arise if a modal loop is started from an alt-key
  183389. // keypress).
  183390. if (hasTitleBar() && h == GetCapture())
  183391. ReleaseCapture();
  183392. break;
  183393. case SC_MAXIMIZE:
  183394. if (sendInputAttemptWhenModalMessage())
  183395. return 0;
  183396. setFullScreen (true);
  183397. return 0;
  183398. case SC_MINIMIZE:
  183399. if (sendInputAttemptWhenModalMessage())
  183400. return 0;
  183401. if (! hasTitleBar())
  183402. {
  183403. setMinimised (true);
  183404. return 0;
  183405. }
  183406. break;
  183407. case SC_RESTORE:
  183408. if (sendInputAttemptWhenModalMessage())
  183409. return 0;
  183410. if (hasTitleBar())
  183411. {
  183412. if (isFullScreen())
  183413. {
  183414. setFullScreen (false);
  183415. return 0;
  183416. }
  183417. }
  183418. else
  183419. {
  183420. if (isMinimised())
  183421. setMinimised (false);
  183422. else if (isFullScreen())
  183423. setFullScreen (false);
  183424. return 0;
  183425. }
  183426. break;
  183427. }
  183428. break;
  183429. case WM_NCLBUTTONDOWN:
  183430. case WM_NCRBUTTONDOWN:
  183431. case WM_NCMBUTTONDOWN:
  183432. sendInputAttemptWhenModalMessage();
  183433. break;
  183434. //case WM_IME_STARTCOMPOSITION;
  183435. // return 0;
  183436. case WM_GETDLGCODE:
  183437. return DLGC_WANTALLKEYS;
  183438. default:
  183439. break;
  183440. }
  183441. }
  183442. return DefWindowProc (h, message, wParam, lParam);
  183443. }
  183444. bool sendInputAttemptWhenModalMessage()
  183445. {
  183446. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183447. {
  183448. Component* const current = Component::getCurrentlyModalComponent();
  183449. if (current != 0)
  183450. current->inputAttemptWhenModal();
  183451. return true;
  183452. }
  183453. return false;
  183454. }
  183455. Win32ComponentPeer (const Win32ComponentPeer&);
  183456. const Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183457. };
  183458. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183459. {
  183460. return new Win32ComponentPeer (this, styleFlags);
  183461. }
  183462. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183463. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183464. {
  183465. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183466. if (wp != 0)
  183467. wp->setTaskBarIcon (&newImage);
  183468. }
  183469. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183470. {
  183471. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183472. if (wp != 0)
  183473. wp->setTaskBarIconToolTip (tooltip);
  183474. }
  183475. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183476. {
  183477. DWORD val = GetWindowLong (h, styleType);
  183478. if (bitIsSet)
  183479. val |= feature;
  183480. else
  183481. val &= ~feature;
  183482. SetWindowLongPtr (h, styleType, val);
  183483. SetWindowPos (h, 0, 0, 0, 0, 0,
  183484. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183485. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183486. }
  183487. bool Process::isForegroundProcess()
  183488. {
  183489. HWND fg = GetForegroundWindow();
  183490. if (fg == 0)
  183491. return true;
  183492. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183493. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183494. // have to see if any of our windows are children of the foreground window
  183495. fg = GetAncestor (fg, GA_ROOT);
  183496. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183497. {
  183498. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183499. if (wp != 0 && wp->isInside (fg))
  183500. return true;
  183501. }
  183502. return false;
  183503. }
  183504. bool AlertWindow::showNativeDialogBox (const String& title,
  183505. const String& bodyText,
  183506. bool isOkCancel)
  183507. {
  183508. return MessageBox (0, bodyText, title,
  183509. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183510. : MB_OK)) == IDOK;
  183511. }
  183512. void Desktop::getMousePosition (int& x, int& y) throw()
  183513. {
  183514. POINT mousePos;
  183515. GetCursorPos (&mousePos);
  183516. x = mousePos.x;
  183517. y = mousePos.y;
  183518. }
  183519. void Desktop::setMousePosition (int x, int y) throw()
  183520. {
  183521. SetCursorPos (x, y);
  183522. }
  183523. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183524. {
  183525. return new Image (format, imageWidth, imageHeight, clearImage);
  183526. }
  183527. class ScreenSaverDefeater : public Timer,
  183528. public DeletedAtShutdown
  183529. {
  183530. public:
  183531. ScreenSaverDefeater() throw()
  183532. {
  183533. startTimer (10000);
  183534. timerCallback();
  183535. }
  183536. ~ScreenSaverDefeater() {}
  183537. void timerCallback()
  183538. {
  183539. if (Process::isForegroundProcess())
  183540. {
  183541. // simulate a shift key getting pressed..
  183542. INPUT input[2];
  183543. input[0].type = INPUT_KEYBOARD;
  183544. input[0].ki.wVk = VK_SHIFT;
  183545. input[0].ki.dwFlags = 0;
  183546. input[0].ki.dwExtraInfo = 0;
  183547. input[1].type = INPUT_KEYBOARD;
  183548. input[1].ki.wVk = VK_SHIFT;
  183549. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183550. input[1].ki.dwExtraInfo = 0;
  183551. SendInput (2, input, sizeof (INPUT));
  183552. }
  183553. }
  183554. };
  183555. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183556. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183557. {
  183558. if (isEnabled)
  183559. {
  183560. deleteAndZero (screenSaverDefeater);
  183561. }
  183562. else if (screenSaverDefeater == 0)
  183563. {
  183564. screenSaverDefeater = new ScreenSaverDefeater();
  183565. }
  183566. }
  183567. bool Desktop::isScreenSaverEnabled() throw()
  183568. {
  183569. return screenSaverDefeater == 0;
  183570. }
  183571. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183572. {
  183573. if (enableOrDisable)
  183574. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183575. }
  183576. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183577. {
  183578. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183579. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183580. return TRUE;
  183581. }
  183582. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183583. {
  183584. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183585. // make sure the first in the list is the main monitor
  183586. for (int i = 1; i < monitorCoords.size(); ++i)
  183587. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183588. monitorCoords.swap (i, 0);
  183589. if (monitorCoords.size() == 0)
  183590. {
  183591. RECT r;
  183592. GetWindowRect (GetDesktopWindow(), &r);
  183593. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183594. }
  183595. if (clipToWorkArea)
  183596. {
  183597. // clip the main monitor to the active non-taskbar area
  183598. RECT r;
  183599. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183600. Rectangle<int>& screen = monitorCoords.getReference (0);
  183601. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183602. jmax (screen.getY(), (int) r.top));
  183603. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183604. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183605. }
  183606. }
  183607. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183608. {
  183609. Image* im = 0;
  183610. if (bitmap != 0)
  183611. {
  183612. BITMAP bm;
  183613. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183614. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183615. {
  183616. HDC tempDC = GetDC (0);
  183617. HDC dc = CreateCompatibleDC (tempDC);
  183618. ReleaseDC (0, tempDC);
  183619. SelectObject (dc, bitmap);
  183620. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183621. for (int y = bm.bmHeight; --y >= 0;)
  183622. {
  183623. for (int x = bm.bmWidth; --x >= 0;)
  183624. {
  183625. COLORREF col = GetPixel (dc, x, y);
  183626. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183627. (uint8) GetGValue (col),
  183628. (uint8) GetBValue (col)));
  183629. }
  183630. }
  183631. DeleteDC (dc);
  183632. }
  183633. }
  183634. return im;
  183635. }
  183636. static Image* createImageFromHICON (HICON icon) throw()
  183637. {
  183638. ICONINFO info;
  183639. if (GetIconInfo (icon, &info))
  183640. {
  183641. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183642. if (mask == 0)
  183643. return 0;
  183644. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183645. if (image == 0)
  183646. return mask;
  183647. for (int y = image->getHeight(); --y >= 0;)
  183648. {
  183649. for (int x = image->getWidth(); --x >= 0;)
  183650. {
  183651. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183652. if (brightness > 0.0f)
  183653. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183654. }
  183655. }
  183656. delete mask;
  183657. return image;
  183658. }
  183659. return 0;
  183660. }
  183661. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183662. {
  183663. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183664. ICONINFO info;
  183665. info.fIcon = isIcon;
  183666. info.xHotspot = hotspotX;
  183667. info.yHotspot = hotspotY;
  183668. info.hbmMask = mask;
  183669. HICON hi = 0;
  183670. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183671. {
  183672. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183673. Graphics g (bitmap);
  183674. g.drawImageAt (&image, 0, 0);
  183675. info.hbmColor = bitmap.hBitmap;
  183676. hi = CreateIconIndirect (&info);
  183677. }
  183678. else
  183679. {
  183680. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183681. HDC colDC = CreateCompatibleDC (GetDC (0));
  183682. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183683. SelectObject (colDC, colour);
  183684. SelectObject (alphaDC, mask);
  183685. for (int y = image.getHeight(); --y >= 0;)
  183686. {
  183687. for (int x = image.getWidth(); --x >= 0;)
  183688. {
  183689. const Colour c (image.getPixelAt (x, y));
  183690. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183691. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183692. }
  183693. }
  183694. DeleteDC (colDC);
  183695. DeleteDC (alphaDC);
  183696. info.hbmColor = colour;
  183697. hi = CreateIconIndirect (&info);
  183698. DeleteObject (colour);
  183699. }
  183700. DeleteObject (mask);
  183701. return hi;
  183702. }
  183703. Image* juce_createIconForFile (const File& file)
  183704. {
  183705. Image* image = 0;
  183706. TCHAR filename [1024];
  183707. file.getFullPathName().copyToBuffer (filename, 1023);
  183708. WORD iconNum = 0;
  183709. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183710. filename, &iconNum);
  183711. if (icon != 0)
  183712. {
  183713. image = createImageFromHICON (icon);
  183714. DestroyIcon (icon);
  183715. }
  183716. return image;
  183717. }
  183718. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183719. {
  183720. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183721. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183722. const Image* im = &image;
  183723. Image* newIm = 0;
  183724. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183725. {
  183726. im = newIm = image.createCopy (maxW, maxH);
  183727. hotspotX = (hotspotX * maxW) / image.getWidth();
  183728. hotspotY = (hotspotY * maxH) / image.getHeight();
  183729. }
  183730. void* cursorH = 0;
  183731. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183732. if (os == SystemStats::WinXP)
  183733. {
  183734. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183735. }
  183736. else
  183737. {
  183738. const int stride = (maxW + 7) >> 3;
  183739. HeapBlock <uint8> andPlane, xorPlane;
  183740. andPlane.calloc (stride * maxH);
  183741. xorPlane.calloc (stride * maxH);
  183742. int index = 0;
  183743. for (int y = 0; y < maxH; ++y)
  183744. {
  183745. for (int x = 0; x < maxW; ++x)
  183746. {
  183747. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183748. const Colour pixelColour (im->getPixelAt (x, y));
  183749. if (pixelColour.getAlpha() < 127)
  183750. andPlane [index + (x >> 3)] |= bit;
  183751. else if (pixelColour.getBrightness() >= 0.5f)
  183752. xorPlane [index + (x >> 3)] |= bit;
  183753. }
  183754. index += stride;
  183755. }
  183756. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183757. }
  183758. delete newIm;
  183759. return cursorH;
  183760. }
  183761. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183762. {
  183763. if (cursorHandle != 0 && ! isStandard)
  183764. DestroyCursor ((HCURSOR) cursorHandle);
  183765. }
  183766. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183767. {
  183768. LPCTSTR cursorName = IDC_ARROW;
  183769. switch (type)
  183770. {
  183771. case MouseCursor::NormalCursor:
  183772. cursorName = IDC_ARROW;
  183773. break;
  183774. case MouseCursor::NoCursor:
  183775. return 0;
  183776. case MouseCursor::DraggingHandCursor:
  183777. {
  183778. static void* dragHandCursor = 0;
  183779. if (dragHandCursor == 0)
  183780. {
  183781. static const unsigned char dragHandData[] =
  183782. { 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,
  183783. 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,
  183784. 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 };
  183785. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183786. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183787. }
  183788. return dragHandCursor;
  183789. }
  183790. case MouseCursor::WaitCursor:
  183791. cursorName = IDC_WAIT;
  183792. break;
  183793. case MouseCursor::IBeamCursor:
  183794. cursorName = IDC_IBEAM;
  183795. break;
  183796. case MouseCursor::PointingHandCursor:
  183797. cursorName = MAKEINTRESOURCE(32649);
  183798. break;
  183799. case MouseCursor::LeftRightResizeCursor:
  183800. case MouseCursor::LeftEdgeResizeCursor:
  183801. case MouseCursor::RightEdgeResizeCursor:
  183802. cursorName = IDC_SIZEWE;
  183803. break;
  183804. case MouseCursor::UpDownResizeCursor:
  183805. case MouseCursor::TopEdgeResizeCursor:
  183806. case MouseCursor::BottomEdgeResizeCursor:
  183807. cursorName = IDC_SIZENS;
  183808. break;
  183809. case MouseCursor::TopLeftCornerResizeCursor:
  183810. case MouseCursor::BottomRightCornerResizeCursor:
  183811. cursorName = IDC_SIZENWSE;
  183812. break;
  183813. case MouseCursor::TopRightCornerResizeCursor:
  183814. case MouseCursor::BottomLeftCornerResizeCursor:
  183815. cursorName = IDC_SIZENESW;
  183816. break;
  183817. case MouseCursor::UpDownLeftRightResizeCursor:
  183818. cursorName = IDC_SIZEALL;
  183819. break;
  183820. case MouseCursor::CrosshairCursor:
  183821. cursorName = IDC_CROSS;
  183822. break;
  183823. case MouseCursor::CopyingCursor:
  183824. // can't seem to find one of these in the win32 list..
  183825. break;
  183826. }
  183827. HCURSOR cursorH = LoadCursor (0, cursorName);
  183828. if (cursorH == 0)
  183829. cursorH = LoadCursor (0, IDC_ARROW);
  183830. return (void*) cursorH;
  183831. }
  183832. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183833. {
  183834. SetCursor ((HCURSOR) getHandle());
  183835. }
  183836. void MouseCursor::showInAllWindows() const throw()
  183837. {
  183838. showInWindow (0);
  183839. }
  183840. class JuceDropSource : public IDropSource
  183841. {
  183842. int refCount;
  183843. public:
  183844. JuceDropSource()
  183845. : refCount (1)
  183846. {
  183847. }
  183848. virtual ~JuceDropSource()
  183849. {
  183850. jassert (refCount == 0);
  183851. }
  183852. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183853. {
  183854. if (id == IID_IUnknown || id == IID_IDropSource)
  183855. {
  183856. AddRef();
  183857. *result = this;
  183858. return S_OK;
  183859. }
  183860. *result = 0;
  183861. return E_NOINTERFACE;
  183862. }
  183863. ULONG __stdcall AddRef() { return ++refCount; }
  183864. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183865. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183866. {
  183867. if (escapePressed)
  183868. return DRAGDROP_S_CANCEL;
  183869. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183870. return DRAGDROP_S_DROP;
  183871. return S_OK;
  183872. }
  183873. HRESULT __stdcall GiveFeedback (DWORD)
  183874. {
  183875. return DRAGDROP_S_USEDEFAULTCURSORS;
  183876. }
  183877. };
  183878. class JuceEnumFormatEtc : public IEnumFORMATETC
  183879. {
  183880. public:
  183881. JuceEnumFormatEtc (const FORMATETC* const format_)
  183882. : refCount (1),
  183883. format (format_),
  183884. index (0)
  183885. {
  183886. }
  183887. virtual ~JuceEnumFormatEtc()
  183888. {
  183889. jassert (refCount == 0);
  183890. }
  183891. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183892. {
  183893. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183894. {
  183895. AddRef();
  183896. *result = this;
  183897. return S_OK;
  183898. }
  183899. *result = 0;
  183900. return E_NOINTERFACE;
  183901. }
  183902. ULONG __stdcall AddRef() { return ++refCount; }
  183903. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183904. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183905. {
  183906. if (result == 0)
  183907. return E_POINTER;
  183908. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183909. newOne->index = index;
  183910. *result = newOne;
  183911. return S_OK;
  183912. }
  183913. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183914. {
  183915. if (pceltFetched != 0)
  183916. *pceltFetched = 0;
  183917. else if (celt != 1)
  183918. return S_FALSE;
  183919. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183920. {
  183921. copyFormatEtc (lpFormatEtc [0], *format);
  183922. ++index;
  183923. if (pceltFetched != 0)
  183924. *pceltFetched = 1;
  183925. return S_OK;
  183926. }
  183927. return S_FALSE;
  183928. }
  183929. HRESULT __stdcall Skip (ULONG celt)
  183930. {
  183931. if (index + (int) celt >= 1)
  183932. return S_FALSE;
  183933. index += celt;
  183934. return S_OK;
  183935. }
  183936. HRESULT __stdcall Reset()
  183937. {
  183938. index = 0;
  183939. return S_OK;
  183940. }
  183941. private:
  183942. int refCount;
  183943. const FORMATETC* const format;
  183944. int index;
  183945. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183946. {
  183947. dest = source;
  183948. if (source.ptd != 0)
  183949. {
  183950. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183951. *(dest.ptd) = *(source.ptd);
  183952. }
  183953. }
  183954. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183955. const JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183956. };
  183957. class JuceDataObject : public IDataObject
  183958. {
  183959. JuceDropSource* const dropSource;
  183960. const FORMATETC* const format;
  183961. const STGMEDIUM* const medium;
  183962. int refCount;
  183963. JuceDataObject (const JuceDataObject&);
  183964. const JuceDataObject& operator= (const JuceDataObject&);
  183965. public:
  183966. JuceDataObject (JuceDropSource* const dropSource_,
  183967. const FORMATETC* const format_,
  183968. const STGMEDIUM* const medium_)
  183969. : dropSource (dropSource_),
  183970. format (format_),
  183971. medium (medium_),
  183972. refCount (1)
  183973. {
  183974. }
  183975. virtual ~JuceDataObject()
  183976. {
  183977. jassert (refCount == 0);
  183978. }
  183979. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183980. {
  183981. if (id == IID_IUnknown || id == IID_IDataObject)
  183982. {
  183983. AddRef();
  183984. *result = this;
  183985. return S_OK;
  183986. }
  183987. *result = 0;
  183988. return E_NOINTERFACE;
  183989. }
  183990. ULONG __stdcall AddRef() { return ++refCount; }
  183991. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183992. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183993. {
  183994. if (pFormatEtc->tymed == format->tymed
  183995. && pFormatEtc->cfFormat == format->cfFormat
  183996. && pFormatEtc->dwAspect == format->dwAspect)
  183997. {
  183998. pMedium->tymed = format->tymed;
  183999. pMedium->pUnkForRelease = 0;
  184000. if (format->tymed == TYMED_HGLOBAL)
  184001. {
  184002. const SIZE_T len = GlobalSize (medium->hGlobal);
  184003. void* const src = GlobalLock (medium->hGlobal);
  184004. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  184005. memcpy (dst, src, len);
  184006. GlobalUnlock (medium->hGlobal);
  184007. pMedium->hGlobal = dst;
  184008. return S_OK;
  184009. }
  184010. }
  184011. return DV_E_FORMATETC;
  184012. }
  184013. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  184014. {
  184015. if (f == 0)
  184016. return E_INVALIDARG;
  184017. if (f->tymed == format->tymed
  184018. && f->cfFormat == format->cfFormat
  184019. && f->dwAspect == format->dwAspect)
  184020. return S_OK;
  184021. return DV_E_FORMATETC;
  184022. }
  184023. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  184024. {
  184025. pFormatEtcOut->ptd = 0;
  184026. return E_NOTIMPL;
  184027. }
  184028. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  184029. {
  184030. if (result == 0)
  184031. return E_POINTER;
  184032. if (direction == DATADIR_GET)
  184033. {
  184034. *result = new JuceEnumFormatEtc (format);
  184035. return S_OK;
  184036. }
  184037. *result = 0;
  184038. return E_NOTIMPL;
  184039. }
  184040. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  184041. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  184042. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  184043. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  184044. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  184045. };
  184046. static HDROP createHDrop (const StringArray& fileNames) throw()
  184047. {
  184048. int totalChars = 0;
  184049. for (int i = fileNames.size(); --i >= 0;)
  184050. totalChars += fileNames[i].length() + 1;
  184051. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  184052. sizeof (DROPFILES)
  184053. + sizeof (WCHAR) * (totalChars + 2));
  184054. if (hDrop != 0)
  184055. {
  184056. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  184057. pDropFiles->pFiles = sizeof (DROPFILES);
  184058. pDropFiles->fWide = true;
  184059. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  184060. for (int i = 0; i < fileNames.size(); ++i)
  184061. {
  184062. fileNames[i].copyToBuffer (fname, 2048);
  184063. fname += fileNames[i].length() + 1;
  184064. }
  184065. *fname = 0;
  184066. GlobalUnlock (hDrop);
  184067. }
  184068. return hDrop;
  184069. }
  184070. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  184071. {
  184072. JuceDropSource* const source = new JuceDropSource();
  184073. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  184074. DWORD effect;
  184075. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  184076. data->Release();
  184077. source->Release();
  184078. return res == DRAGDROP_S_DROP;
  184079. }
  184080. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  184081. {
  184082. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184083. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184084. medium.hGlobal = createHDrop (files);
  184085. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  184086. : DROPEFFECT_COPY);
  184087. }
  184088. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  184089. {
  184090. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184091. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184092. const int numChars = text.length();
  184093. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  184094. char* d = (char*) GlobalLock (medium.hGlobal);
  184095. text.copyToBuffer ((WCHAR*) d, numChars + 1);
  184096. format.cfFormat = CF_UNICODETEXT;
  184097. GlobalUnlock (medium.hGlobal);
  184098. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  184099. }
  184100. #endif
  184101. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  184102. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  184103. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184104. // compiled on its own).
  184105. #if JUCE_INCLUDED_FILE
  184106. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  184107. NEWTEXTMETRICEXW*,
  184108. int type,
  184109. LPARAM lParam)
  184110. {
  184111. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184112. {
  184113. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184114. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  184115. }
  184116. return 1;
  184117. }
  184118. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  184119. NEWTEXTMETRICEXW*,
  184120. int type,
  184121. LPARAM lParam)
  184122. {
  184123. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184124. {
  184125. LOGFONTW lf;
  184126. zerostruct (lf);
  184127. lf.lfWeight = FW_DONTCARE;
  184128. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184129. lf.lfQuality = DEFAULT_QUALITY;
  184130. lf.lfCharSet = DEFAULT_CHARSET;
  184131. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184132. lf.lfPitchAndFamily = FF_DONTCARE;
  184133. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184134. fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1);
  184135. HDC dc = CreateCompatibleDC (0);
  184136. EnumFontFamiliesEx (dc, &lf,
  184137. (FONTENUMPROCW) &wfontEnum2,
  184138. lParam, 0);
  184139. DeleteDC (dc);
  184140. }
  184141. return 1;
  184142. }
  184143. const StringArray Font::findAllTypefaceNames() throw()
  184144. {
  184145. StringArray results;
  184146. HDC dc = CreateCompatibleDC (0);
  184147. {
  184148. LOGFONTW lf;
  184149. zerostruct (lf);
  184150. lf.lfWeight = FW_DONTCARE;
  184151. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184152. lf.lfQuality = DEFAULT_QUALITY;
  184153. lf.lfCharSet = DEFAULT_CHARSET;
  184154. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184155. lf.lfPitchAndFamily = FF_DONTCARE;
  184156. lf.lfFaceName[0] = 0;
  184157. EnumFontFamiliesEx (dc, &lf,
  184158. (FONTENUMPROCW) &wfontEnum1,
  184159. (LPARAM) &results, 0);
  184160. }
  184161. DeleteDC (dc);
  184162. results.sort (true);
  184163. return results;
  184164. }
  184165. extern bool juce_IsRunningInWine();
  184166. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184167. {
  184168. if (juce_IsRunningInWine())
  184169. {
  184170. // If we're running in Wine, then use fonts that might be available on Linux..
  184171. defaultSans = "Bitstream Vera Sans";
  184172. defaultSerif = "Bitstream Vera Serif";
  184173. defaultFixed = "Bitstream Vera Sans Mono";
  184174. }
  184175. else
  184176. {
  184177. defaultSans = "Verdana";
  184178. defaultSerif = "Times";
  184179. defaultFixed = "Lucida Console";
  184180. }
  184181. }
  184182. class FontDCHolder : private DeletedAtShutdown
  184183. {
  184184. public:
  184185. FontDCHolder() throw()
  184186. : dc (0), numKPs (0), size (0),
  184187. bold (false), italic (false)
  184188. {
  184189. }
  184190. ~FontDCHolder() throw()
  184191. {
  184192. if (dc != 0)
  184193. {
  184194. DeleteDC (dc);
  184195. DeleteObject (fontH);
  184196. }
  184197. clearSingletonInstance();
  184198. }
  184199. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184200. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184201. {
  184202. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184203. {
  184204. fontName = fontName_;
  184205. bold = bold_;
  184206. italic = italic_;
  184207. size = size_;
  184208. if (dc != 0)
  184209. {
  184210. DeleteDC (dc);
  184211. DeleteObject (fontH);
  184212. kps.free();
  184213. }
  184214. fontH = 0;
  184215. dc = CreateCompatibleDC (0);
  184216. SetMapperFlags (dc, 0);
  184217. SetMapMode (dc, MM_TEXT);
  184218. LOGFONTW lfw;
  184219. zerostruct (lfw);
  184220. lfw.lfCharSet = DEFAULT_CHARSET;
  184221. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184222. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184223. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184224. lfw.lfQuality = PROOF_QUALITY;
  184225. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184226. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184227. fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1);
  184228. lfw.lfHeight = size > 0 ? size : -256;
  184229. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184230. if (standardSizedFont != 0)
  184231. {
  184232. if (SelectObject (dc, standardSizedFont) != 0)
  184233. {
  184234. fontH = standardSizedFont;
  184235. if (size == 0)
  184236. {
  184237. OUTLINETEXTMETRIC otm;
  184238. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184239. {
  184240. lfw.lfHeight = -(int) otm.otmEMSquare;
  184241. fontH = CreateFontIndirect (&lfw);
  184242. SelectObject (dc, fontH);
  184243. DeleteObject (standardSizedFont);
  184244. }
  184245. }
  184246. }
  184247. else
  184248. {
  184249. jassertfalse
  184250. }
  184251. }
  184252. else
  184253. {
  184254. jassertfalse
  184255. }
  184256. }
  184257. return dc;
  184258. }
  184259. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184260. {
  184261. if (kps == 0)
  184262. {
  184263. numKPs = GetKerningPairs (dc, 0, 0);
  184264. kps.calloc (numKPs);
  184265. GetKerningPairs (dc, numKPs, kps);
  184266. }
  184267. numKPs_ = numKPs;
  184268. return kps;
  184269. }
  184270. private:
  184271. HFONT fontH;
  184272. HDC dc;
  184273. String fontName;
  184274. HeapBlock <KERNINGPAIR> kps;
  184275. int numKPs, size;
  184276. bool bold, italic;
  184277. FontDCHolder (const FontDCHolder&);
  184278. const FontDCHolder& operator= (const FontDCHolder&);
  184279. };
  184280. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184281. class WindowsTypeface : public CustomTypeface
  184282. {
  184283. public:
  184284. WindowsTypeface (const Font& font)
  184285. {
  184286. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184287. font.isBold(), font.isItalic(), 0);
  184288. TEXTMETRIC tm;
  184289. tm.tmAscent = tm.tmHeight = 1;
  184290. tm.tmDefaultChar = 0;
  184291. GetTextMetrics (dc, &tm);
  184292. setCharacteristics (font.getTypefaceName(),
  184293. tm.tmAscent / (float) tm.tmHeight,
  184294. font.isBold(), font.isItalic(),
  184295. tm.tmDefaultChar);
  184296. }
  184297. bool loadGlyphIfPossible (const juce_wchar character)
  184298. {
  184299. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184300. GLYPHMETRICS gm;
  184301. {
  184302. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184303. WORD index = 0;
  184304. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184305. && index == 0xffff)
  184306. {
  184307. return false;
  184308. }
  184309. }
  184310. Path glyphPath;
  184311. TEXTMETRIC tm;
  184312. if (! GetTextMetrics (dc, &tm))
  184313. {
  184314. addGlyph (character, glyphPath, 0);
  184315. return true;
  184316. }
  184317. const float height = (float) tm.tmHeight;
  184318. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184319. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184320. &gm, 0, 0, &identityMatrix);
  184321. if (bufSize > 0)
  184322. {
  184323. HeapBlock <char> data (bufSize);
  184324. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184325. bufSize, data, &identityMatrix);
  184326. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184327. const float scaleX = 1.0f / height;
  184328. const float scaleY = -1.0f / height;
  184329. while ((char*) pheader < data + bufSize)
  184330. {
  184331. #define remapX(v) (scaleX * (v).x.value)
  184332. #define remapY(v) (scaleY * (v).y.value)
  184333. float x = remapX (pheader->pfxStart);
  184334. float y = remapY (pheader->pfxStart);
  184335. glyphPath.startNewSubPath (x, y);
  184336. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184337. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184338. while ((const char*) curve < curveEnd)
  184339. {
  184340. if (curve->wType == TT_PRIM_LINE)
  184341. {
  184342. for (int i = 0; i < curve->cpfx; ++i)
  184343. {
  184344. x = remapX (curve->apfx [i]);
  184345. y = remapY (curve->apfx [i]);
  184346. glyphPath.lineTo (x, y);
  184347. }
  184348. }
  184349. else if (curve->wType == TT_PRIM_QSPLINE)
  184350. {
  184351. for (int i = 0; i < curve->cpfx - 1; ++i)
  184352. {
  184353. const float x2 = remapX (curve->apfx [i]);
  184354. const float y2 = remapY (curve->apfx [i]);
  184355. float x3, y3;
  184356. if (i < curve->cpfx - 2)
  184357. {
  184358. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184359. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184360. }
  184361. else
  184362. {
  184363. x3 = remapX (curve->apfx [i + 1]);
  184364. y3 = remapY (curve->apfx [i + 1]);
  184365. }
  184366. glyphPath.quadraticTo (x2, y2, x3, y3);
  184367. x = x3;
  184368. y = y3;
  184369. }
  184370. }
  184371. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184372. }
  184373. pheader = (const TTPOLYGONHEADER*) curve;
  184374. glyphPath.closeSubPath();
  184375. }
  184376. }
  184377. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184378. int numKPs;
  184379. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184380. for (int i = 0; i < numKPs; ++i)
  184381. {
  184382. if (kps[i].wFirst == character)
  184383. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184384. kps[i].iKernAmount / height);
  184385. }
  184386. return true;
  184387. }
  184388. };
  184389. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184390. {
  184391. return new WindowsTypeface (font);
  184392. }
  184393. #endif
  184394. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  184395. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  184396. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184397. // compiled on its own).
  184398. #if JUCE_INCLUDED_FILE
  184399. static const void* defaultDirPath = 0;
  184400. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184401. static Component* currentExtraFileWin = 0;
  184402. static bool areThereAnyAlwaysOnTopWindows()
  184403. {
  184404. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184405. {
  184406. Component* c = Desktop::getInstance().getComponent (i);
  184407. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184408. return true;
  184409. }
  184410. return false;
  184411. }
  184412. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184413. {
  184414. if (msg == BFFM_INITIALIZED)
  184415. {
  184416. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184417. }
  184418. else if (msg == BFFM_VALIDATEFAILEDW)
  184419. {
  184420. returnedString = (LPCWSTR) lParam;
  184421. }
  184422. else if (msg == BFFM_VALIDATEFAILEDA)
  184423. {
  184424. returnedString = (const char*) lParam;
  184425. }
  184426. return 0;
  184427. }
  184428. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184429. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184430. {
  184431. if (currentExtraFileWin != 0)
  184432. {
  184433. if (uiMsg == WM_INITDIALOG)
  184434. {
  184435. HWND dialogH = GetParent (hdlg);
  184436. jassert (dialogH != 0);
  184437. if (dialogH == 0)
  184438. dialogH = hdlg;
  184439. RECT r, cr;
  184440. GetWindowRect (dialogH, &r);
  184441. GetClientRect (dialogH, &cr);
  184442. SetWindowPos (dialogH, 0,
  184443. r.left, r.top,
  184444. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184445. jmax (150, (int) (r.bottom - r.top)),
  184446. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184447. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184448. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184449. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184450. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184451. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184452. }
  184453. else if (uiMsg == WM_NOTIFY)
  184454. {
  184455. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184456. if (ofn->hdr.code == CDN_SELCHANGE)
  184457. {
  184458. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184459. if (comp != 0)
  184460. {
  184461. TCHAR path [MAX_PATH * 2];
  184462. path[0] = 0;
  184463. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184464. const String fn ((const WCHAR*) path);
  184465. comp->selectedFileChanged (File (fn));
  184466. }
  184467. }
  184468. }
  184469. }
  184470. return 0;
  184471. }
  184472. class FPComponentHolder : public Component
  184473. {
  184474. public:
  184475. FPComponentHolder()
  184476. {
  184477. setVisible (true);
  184478. setOpaque (true);
  184479. }
  184480. ~FPComponentHolder()
  184481. {
  184482. }
  184483. void paint (Graphics& g)
  184484. {
  184485. g.fillAll (Colours::lightgrey);
  184486. }
  184487. private:
  184488. FPComponentHolder (const FPComponentHolder&);
  184489. const FPComponentHolder& operator= (const FPComponentHolder&);
  184490. };
  184491. void FileChooser::showPlatformDialog (Array<File>& results,
  184492. const String& title,
  184493. const File& currentFileOrDirectory,
  184494. const String& filter,
  184495. bool selectsDirectory,
  184496. bool /*selectsFiles*/,
  184497. bool isSaveDialogue,
  184498. bool warnAboutOverwritingExistingFiles,
  184499. bool selectMultipleFiles,
  184500. FilePreviewComponent* extraInfoComponent)
  184501. {
  184502. const int numCharsAvailable = 32768;
  184503. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184504. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184505. int fnameIdx = 0;
  184506. JUCE_TRY
  184507. {
  184508. // use a modal window as the parent for this dialog box
  184509. // to block input from other app windows
  184510. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184511. Component w (String::empty);
  184512. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184513. mainMon.getY() + mainMon.getHeight() / 4,
  184514. 0, 0);
  184515. w.setOpaque (true);
  184516. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184517. w.addToDesktop (0);
  184518. if (extraInfoComponent == 0)
  184519. w.enterModalState();
  184520. String initialDir;
  184521. if (currentFileOrDirectory.isDirectory())
  184522. {
  184523. initialDir = currentFileOrDirectory.getFullPathName();
  184524. }
  184525. else
  184526. {
  184527. currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable);
  184528. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184529. }
  184530. if (currentExtraFileWin->isValidComponent())
  184531. {
  184532. jassertfalse
  184533. return;
  184534. }
  184535. if (selectsDirectory)
  184536. {
  184537. LPITEMIDLIST list = 0;
  184538. filenameSpace.fillWith (0);
  184539. {
  184540. BROWSEINFO bi;
  184541. zerostruct (bi);
  184542. bi.hwndOwner = (HWND) w.getWindowHandle();
  184543. bi.pszDisplayName = fname;
  184544. bi.lpszTitle = title;
  184545. bi.lpfn = browseCallbackProc;
  184546. #ifdef BIF_USENEWUI
  184547. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184548. #else
  184549. bi.ulFlags = 0x50;
  184550. #endif
  184551. defaultDirPath = (const WCHAR*) initialDir;
  184552. list = SHBrowseForFolder (&bi);
  184553. if (! SHGetPathFromIDListW (list, fname))
  184554. {
  184555. fname[0] = 0;
  184556. returnedString = String::empty;
  184557. }
  184558. }
  184559. LPMALLOC al;
  184560. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184561. al->Free (list);
  184562. defaultDirPath = 0;
  184563. if (returnedString.isNotEmpty())
  184564. {
  184565. const String stringFName (fname);
  184566. results.add (File (stringFName).getSiblingFile (returnedString));
  184567. returnedString = String::empty;
  184568. return;
  184569. }
  184570. }
  184571. else
  184572. {
  184573. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184574. if (warnAboutOverwritingExistingFiles)
  184575. flags |= OFN_OVERWRITEPROMPT;
  184576. if (selectMultipleFiles)
  184577. flags |= OFN_ALLOWMULTISELECT;
  184578. if (extraInfoComponent != 0)
  184579. {
  184580. flags |= OFN_ENABLEHOOK;
  184581. currentExtraFileWin = new FPComponentHolder();
  184582. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184583. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184584. extraInfoComponent->getHeight());
  184585. currentExtraFileWin->addToDesktop (0);
  184586. currentExtraFileWin->enterModalState();
  184587. }
  184588. {
  184589. WCHAR filters [1024];
  184590. zeromem (filters, sizeof (filters));
  184591. filter.copyToBuffer (filters, 1024);
  184592. filter.copyToBuffer (filters + filter.length() + 1,
  184593. 1022 - filter.length());
  184594. OPENFILENAMEW of;
  184595. zerostruct (of);
  184596. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184597. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184598. #else
  184599. of.lStructSize = sizeof (of);
  184600. #endif
  184601. of.hwndOwner = (HWND) w.getWindowHandle();
  184602. of.lpstrFilter = filters;
  184603. of.nFilterIndex = 1;
  184604. of.lpstrFile = fname;
  184605. of.nMaxFile = numCharsAvailable;
  184606. of.lpstrInitialDir = initialDir;
  184607. of.lpstrTitle = title;
  184608. of.Flags = flags;
  184609. if (extraInfoComponent != 0)
  184610. of.lpfnHook = &openCallback;
  184611. if (isSaveDialogue)
  184612. {
  184613. if (! GetSaveFileName (&of))
  184614. fname[0] = 0;
  184615. else
  184616. fnameIdx = of.nFileOffset;
  184617. }
  184618. else
  184619. {
  184620. if (! GetOpenFileName (&of))
  184621. fname[0] = 0;
  184622. else
  184623. fnameIdx = of.nFileOffset;
  184624. }
  184625. }
  184626. }
  184627. }
  184628. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184629. catch (...)
  184630. {
  184631. fname[0] = 0;
  184632. }
  184633. #endif
  184634. deleteAndZero (currentExtraFileWin);
  184635. const WCHAR* const files = fname;
  184636. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184637. {
  184638. const WCHAR* filename = files + fnameIdx;
  184639. while (*filename != 0)
  184640. {
  184641. const String filepath (String (files) + T("\\") + String (filename));
  184642. results.add (File (filepath));
  184643. filename += CharacterFunctions::length (filename) + 1;
  184644. }
  184645. }
  184646. else if (files[0] != 0)
  184647. {
  184648. results.add (File (files));
  184649. }
  184650. }
  184651. #endif
  184652. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184653. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184654. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184655. // compiled on its own).
  184656. #if JUCE_INCLUDED_FILE
  184657. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184658. {
  184659. if (OpenClipboard (0) != 0)
  184660. {
  184661. if (EmptyClipboard() != 0)
  184662. {
  184663. const int len = text.length();
  184664. if (len > 0)
  184665. {
  184666. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184667. (len + 1) * sizeof (wchar_t));
  184668. if (bufH != 0)
  184669. {
  184670. wchar_t* const data = (wchar_t*) GlobalLock (bufH);
  184671. text.copyToBuffer (data, len);
  184672. GlobalUnlock (bufH);
  184673. SetClipboardData (CF_UNICODETEXT, bufH);
  184674. }
  184675. }
  184676. }
  184677. CloseClipboard();
  184678. }
  184679. }
  184680. const String SystemClipboard::getTextFromClipboard() throw()
  184681. {
  184682. String result;
  184683. if (OpenClipboard (0) != 0)
  184684. {
  184685. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184686. if (bufH != 0)
  184687. {
  184688. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184689. if (data != 0)
  184690. {
  184691. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184692. GlobalUnlock (bufH);
  184693. }
  184694. }
  184695. CloseClipboard();
  184696. }
  184697. return result;
  184698. }
  184699. #endif
  184700. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184701. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184702. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184703. // compiled on its own).
  184704. #if JUCE_INCLUDED_FILE
  184705. class JuceIStorage : public IStorage
  184706. {
  184707. int refCount;
  184708. public:
  184709. JuceIStorage() : refCount (1) {}
  184710. virtual ~JuceIStorage()
  184711. {
  184712. jassert (refCount == 0);
  184713. }
  184714. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184715. {
  184716. if (id == IID_IUnknown || id == IID_IStorage)
  184717. {
  184718. AddRef();
  184719. *result = this;
  184720. return S_OK;
  184721. }
  184722. *result = 0;
  184723. return E_NOINTERFACE;
  184724. }
  184725. ULONG __stdcall AddRef() { return ++refCount; }
  184726. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184727. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184728. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184729. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184730. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184731. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184732. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184733. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184734. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184735. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184736. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184737. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184738. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184739. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184740. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184741. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184742. juce_UseDebuggingNewOperator
  184743. };
  184744. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184745. {
  184746. int refCount;
  184747. HWND window;
  184748. public:
  184749. JuceOleInPlaceFrame (HWND window_)
  184750. : refCount (1),
  184751. window (window_)
  184752. {
  184753. }
  184754. virtual ~JuceOleInPlaceFrame()
  184755. {
  184756. jassert (refCount == 0);
  184757. }
  184758. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184759. {
  184760. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184761. {
  184762. AddRef();
  184763. *result = this;
  184764. return S_OK;
  184765. }
  184766. *result = 0;
  184767. return E_NOINTERFACE;
  184768. }
  184769. ULONG __stdcall AddRef() { return ++refCount; }
  184770. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184771. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184772. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184773. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184774. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184775. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184776. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184777. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184778. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184779. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184780. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184781. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184782. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184783. juce_UseDebuggingNewOperator
  184784. };
  184785. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184786. {
  184787. int refCount;
  184788. HWND window;
  184789. JuceOleInPlaceFrame* frame;
  184790. public:
  184791. JuceIOleInPlaceSite (HWND window_)
  184792. : refCount (1),
  184793. window (window_)
  184794. {
  184795. frame = new JuceOleInPlaceFrame (window);
  184796. }
  184797. virtual ~JuceIOleInPlaceSite()
  184798. {
  184799. jassert (refCount == 0);
  184800. frame->Release();
  184801. }
  184802. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184803. {
  184804. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184805. {
  184806. AddRef();
  184807. *result = this;
  184808. return S_OK;
  184809. }
  184810. *result = 0;
  184811. return E_NOINTERFACE;
  184812. }
  184813. ULONG __stdcall AddRef() { return ++refCount; }
  184814. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184815. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184816. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184817. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184818. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184819. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184820. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184821. {
  184822. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184823. *lplpFrame = frame;
  184824. *lplpDoc = 0;
  184825. lpFrameInfo->fMDIApp = FALSE;
  184826. lpFrameInfo->hwndFrame = window;
  184827. lpFrameInfo->haccel = 0;
  184828. lpFrameInfo->cAccelEntries = 0;
  184829. return S_OK;
  184830. }
  184831. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184832. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184833. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184834. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184835. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184836. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184837. juce_UseDebuggingNewOperator
  184838. };
  184839. class JuceIOleClientSite : public IOleClientSite
  184840. {
  184841. int refCount;
  184842. JuceIOleInPlaceSite* inplaceSite;
  184843. public:
  184844. JuceIOleClientSite (HWND window)
  184845. : refCount (1)
  184846. {
  184847. inplaceSite = new JuceIOleInPlaceSite (window);
  184848. }
  184849. virtual ~JuceIOleClientSite()
  184850. {
  184851. jassert (refCount == 0);
  184852. inplaceSite->Release();
  184853. }
  184854. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184855. {
  184856. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184857. {
  184858. AddRef();
  184859. *result = this;
  184860. return S_OK;
  184861. }
  184862. else if (id == IID_IOleInPlaceSite)
  184863. {
  184864. inplaceSite->AddRef();
  184865. *result = inplaceSite;
  184866. return S_OK;
  184867. }
  184868. *result = 0;
  184869. return E_NOINTERFACE;
  184870. }
  184871. ULONG __stdcall AddRef() { return ++refCount; }
  184872. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184873. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184874. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184875. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184876. HRESULT __stdcall ShowObject() { return S_OK; }
  184877. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184878. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184879. juce_UseDebuggingNewOperator
  184880. };
  184881. class ActiveXControlData : public ComponentMovementWatcher
  184882. {
  184883. ActiveXControlComponent* const owner;
  184884. bool wasShowing;
  184885. public:
  184886. HWND controlHWND;
  184887. IStorage* storage;
  184888. IOleClientSite* clientSite;
  184889. IOleObject* control;
  184890. ActiveXControlData (HWND hwnd,
  184891. ActiveXControlComponent* const owner_)
  184892. : ComponentMovementWatcher (owner_),
  184893. owner (owner_),
  184894. wasShowing (owner_ != 0 && owner_->isShowing()),
  184895. controlHWND (0),
  184896. storage (new JuceIStorage()),
  184897. clientSite (new JuceIOleClientSite (hwnd)),
  184898. control (0)
  184899. {
  184900. }
  184901. ~ActiveXControlData()
  184902. {
  184903. if (control != 0)
  184904. {
  184905. control->Close (OLECLOSE_NOSAVE);
  184906. control->Release();
  184907. }
  184908. clientSite->Release();
  184909. storage->Release();
  184910. }
  184911. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184912. {
  184913. Component* const topComp = owner->getTopLevelComponent();
  184914. if (topComp->getPeer() != 0)
  184915. {
  184916. int x = 0, y = 0;
  184917. owner->relativePositionToOtherComponent (topComp, x, y);
  184918. owner->setControlBounds (Rectangle<int> (x, y, owner->getWidth(), owner->getHeight()));
  184919. }
  184920. }
  184921. void componentPeerChanged()
  184922. {
  184923. const bool isShowingNow = owner->isShowing();
  184924. if (wasShowing != isShowingNow)
  184925. {
  184926. wasShowing = isShowingNow;
  184927. owner->setControlVisible (isShowingNow);
  184928. }
  184929. componentMovedOrResized (true, true);
  184930. }
  184931. void componentVisibilityChanged (Component&)
  184932. {
  184933. componentPeerChanged();
  184934. }
  184935. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184936. {
  184937. return ((ActiveXControlData*) ax->control) != 0
  184938. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184939. }
  184940. };
  184941. static VoidArray activeXComps;
  184942. static HWND getHWND (const ActiveXControlComponent* const component)
  184943. {
  184944. HWND hwnd = 0;
  184945. const IID iid = IID_IOleWindow;
  184946. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184947. if (window != 0)
  184948. {
  184949. window->GetWindow (&hwnd);
  184950. window->Release();
  184951. }
  184952. return hwnd;
  184953. }
  184954. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184955. {
  184956. RECT activeXRect, peerRect;
  184957. GetWindowRect (hwnd, &activeXRect);
  184958. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184959. const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left;
  184960. const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top;
  184961. const int64 mouseEventTime = getMouseEventTime();
  184962. const int oldModifiers = currentModifiers;
  184963. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184964. switch (message)
  184965. {
  184966. case WM_MOUSEMOVE:
  184967. if (ModifierKeys (currentModifiers).isAnyMouseButtonDown())
  184968. peer->handleMouseDrag (mx, my, mouseEventTime);
  184969. else
  184970. peer->handleMouseMove (mx, my, mouseEventTime);
  184971. break;
  184972. case WM_LBUTTONDOWN:
  184973. case WM_MBUTTONDOWN:
  184974. case WM_RBUTTONDOWN:
  184975. peer->handleMouseDown (mx, my, mouseEventTime);
  184976. break;
  184977. case WM_LBUTTONUP:
  184978. case WM_MBUTTONUP:
  184979. case WM_RBUTTONUP:
  184980. peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime);
  184981. break;
  184982. default:
  184983. break;
  184984. }
  184985. }
  184986. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184987. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184988. {
  184989. for (int i = activeXComps.size(); --i >= 0;)
  184990. {
  184991. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) activeXComps.getUnchecked(i);
  184992. if (ActiveXControlData::doesWindowMatch (ax, hwnd))
  184993. {
  184994. switch (message)
  184995. {
  184996. case WM_MOUSEMOVE:
  184997. case WM_LBUTTONDOWN:
  184998. case WM_MBUTTONDOWN:
  184999. case WM_RBUTTONDOWN:
  185000. case WM_LBUTTONUP:
  185001. case WM_MBUTTONUP:
  185002. case WM_RBUTTONUP:
  185003. case WM_LBUTTONDBLCLK:
  185004. case WM_MBUTTONDBLCLK:
  185005. case WM_RBUTTONDBLCLK:
  185006. if (ax->isShowing())
  185007. {
  185008. ComponentPeer* const peer = ax->getPeer();
  185009. if (peer != 0)
  185010. {
  185011. offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  185012. if (! ax->areMouseEventsAllowed())
  185013. return 0;
  185014. }
  185015. }
  185016. break;
  185017. default:
  185018. break;
  185019. }
  185020. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  185021. }
  185022. }
  185023. return DefWindowProc (hwnd, message, wParam, lParam);
  185024. }
  185025. ActiveXControlComponent::ActiveXControlComponent()
  185026. : originalWndProc (0),
  185027. control (0),
  185028. mouseEventsAllowed (true)
  185029. {
  185030. activeXComps.add (this);
  185031. }
  185032. ActiveXControlComponent::~ActiveXControlComponent()
  185033. {
  185034. deleteControl();
  185035. activeXComps.removeValue (this);
  185036. }
  185037. void ActiveXControlComponent::paint (Graphics& g)
  185038. {
  185039. if (control == 0)
  185040. g.fillAll (Colours::lightgrey);
  185041. }
  185042. bool ActiveXControlComponent::createControl (const void* controlIID)
  185043. {
  185044. deleteControl();
  185045. ComponentPeer* const peer = getPeer();
  185046. // the component must have already been added to a real window when you call this!
  185047. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  185048. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  185049. {
  185050. int x = 0, y = 0;
  185051. relativePositionToOtherComponent (getTopLevelComponent(), x, y);
  185052. HWND hwnd = (HWND) peer->getNativeHandle();
  185053. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  185054. HRESULT hr;
  185055. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  185056. info->clientSite, info->storage,
  185057. (void**) &(info->control))) == S_OK)
  185058. {
  185059. info->control->SetHostNames (L"Juce", 0);
  185060. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  185061. {
  185062. RECT rect;
  185063. rect.left = x;
  185064. rect.top = y;
  185065. rect.right = x + getWidth();
  185066. rect.bottom = y + getHeight();
  185067. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  185068. {
  185069. control = info.release();
  185070. setControlBounds (Rectangle<int> (x, y, getWidth(), getHeight()));
  185071. ((ActiveXControlData*) control)->controlHWND = getHWND (this);
  185072. if (((ActiveXControlData*) control)->controlHWND != 0)
  185073. {
  185074. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  185075. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) activeXHookWndProc);
  185076. }
  185077. return true;
  185078. }
  185079. }
  185080. }
  185081. }
  185082. return false;
  185083. }
  185084. void ActiveXControlComponent::deleteControl()
  185085. {
  185086. ActiveXControlData* const info = (ActiveXControlData*) control;
  185087. if (info != 0)
  185088. {
  185089. delete info;
  185090. control = 0;
  185091. originalWndProc = 0;
  185092. }
  185093. }
  185094. void* ActiveXControlComponent::queryInterface (const void* iid) const
  185095. {
  185096. ActiveXControlData* const info = (ActiveXControlData*) control;
  185097. void* result = 0;
  185098. if (info != 0 && info->control != 0
  185099. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  185100. return result;
  185101. return 0;
  185102. }
  185103. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  185104. {
  185105. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185106. if (hwnd != 0)
  185107. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  185108. }
  185109. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  185110. {
  185111. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185112. if (hwnd != 0)
  185113. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  185114. }
  185115. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  185116. {
  185117. mouseEventsAllowed = eventsCanReachControl;
  185118. }
  185119. #endif
  185120. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  185121. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185122. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185123. // compiled on its own).
  185124. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  185125. using namespace QTOLibrary;
  185126. using namespace QTOControlLib;
  185127. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  185128. static bool isQTAvailable = false;
  185129. struct QTMovieCompInternal
  185130. {
  185131. QTMovieCompInternal()
  185132. : dataHandle (0)
  185133. {
  185134. }
  185135. ~QTMovieCompInternal()
  185136. {
  185137. clearHandle();
  185138. }
  185139. IQTControlPtr qtControlInternal;
  185140. IQTMoviePtr qtMovieInternal;
  185141. Handle dataHandle;
  185142. void clearHandle()
  185143. {
  185144. if (dataHandle != 0)
  185145. {
  185146. DisposeHandle (dataHandle);
  185147. dataHandle = 0;
  185148. }
  185149. }
  185150. };
  185151. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185152. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185153. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185154. : movieLoaded (false),
  185155. controllerVisible (true)
  185156. {
  185157. internal = new QTMovieCompInternal();
  185158. setMouseEventsAllowed (false);
  185159. }
  185160. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185161. {
  185162. closeMovie();
  185163. qtControl = 0;
  185164. deleteControl();
  185165. delete internal;
  185166. internal = 0;
  185167. }
  185168. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185169. {
  185170. if (! isQTAvailable)
  185171. {
  185172. isQTAvailable = (InitializeQTML (0) == noErr)
  185173. && (EnterMovies() == noErr);
  185174. }
  185175. return isQTAvailable;
  185176. }
  185177. void QuickTimeMovieComponent::createControlIfNeeded()
  185178. {
  185179. if (isShowing() && ! isControlCreated())
  185180. {
  185181. const IID qtIID = __uuidof (QTControl);
  185182. if (createControl (&qtIID))
  185183. {
  185184. const IID qtInterfaceIID = __uuidof (IQTControl);
  185185. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185186. if (qtControl != 0)
  185187. {
  185188. qtControl->Release(); // it has one ref too many at this point
  185189. qtControl->QuickTimeInitialize();
  185190. qtControl->PutSizing (qtMovieFitsControl);
  185191. if (movieFile != File::nonexistent)
  185192. loadMovie (movieFile, controllerVisible);
  185193. }
  185194. }
  185195. }
  185196. }
  185197. bool QuickTimeMovieComponent::isControlCreated() const
  185198. {
  185199. return isControlOpen();
  185200. }
  185201. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185202. const bool isControllerVisible)
  185203. {
  185204. movieFile = File::nonexistent;
  185205. movieLoaded = false;
  185206. qtMovie = 0;
  185207. controllerVisible = isControllerVisible;
  185208. createControlIfNeeded();
  185209. if (isControlCreated())
  185210. {
  185211. if (qtControl != 0)
  185212. {
  185213. qtControl->Put_MovieHandle (0);
  185214. ((QTMovieCompInternal*) internal)->clearHandle();
  185215. Movie movie;
  185216. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185217. {
  185218. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185219. qtMovie = qtControl->GetMovie();
  185220. if (qtMovie != 0)
  185221. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185222. : qtMovieControllerTypeNone);
  185223. }
  185224. if (movie == 0)
  185225. ((QTMovieCompInternal*) internal)->clearHandle();
  185226. }
  185227. movieLoaded = (qtMovie != 0);
  185228. }
  185229. else
  185230. {
  185231. // You're trying to open a movie when the control hasn't yet been created, probably because
  185232. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185233. jassertfalse
  185234. }
  185235. delete movieStream;
  185236. return movieLoaded;
  185237. }
  185238. void QuickTimeMovieComponent::closeMovie()
  185239. {
  185240. stop();
  185241. movieFile = File::nonexistent;
  185242. movieLoaded = false;
  185243. qtMovie = 0;
  185244. if (qtControl != 0)
  185245. qtControl->Put_MovieHandle (0);
  185246. ((QTMovieCompInternal*) internal)->clearHandle();
  185247. }
  185248. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185249. {
  185250. return movieFile;
  185251. }
  185252. bool QuickTimeMovieComponent::isMovieOpen() const
  185253. {
  185254. return movieLoaded;
  185255. }
  185256. double QuickTimeMovieComponent::getMovieDuration() const
  185257. {
  185258. if (qtMovie != 0)
  185259. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185260. return 0.0;
  185261. }
  185262. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185263. {
  185264. if (qtMovie != 0)
  185265. {
  185266. struct QTRECT r = qtMovie->GetNaturalRect();
  185267. width = r.right - r.left;
  185268. height = r.bottom - r.top;
  185269. }
  185270. else
  185271. {
  185272. width = height = 0;
  185273. }
  185274. }
  185275. void QuickTimeMovieComponent::play()
  185276. {
  185277. if (qtMovie != 0)
  185278. qtMovie->Play();
  185279. }
  185280. void QuickTimeMovieComponent::stop()
  185281. {
  185282. if (qtMovie != 0)
  185283. qtMovie->Stop();
  185284. }
  185285. bool QuickTimeMovieComponent::isPlaying() const
  185286. {
  185287. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185288. }
  185289. void QuickTimeMovieComponent::setPosition (const double seconds)
  185290. {
  185291. if (qtMovie != 0)
  185292. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185293. }
  185294. double QuickTimeMovieComponent::getPosition() const
  185295. {
  185296. if (qtMovie != 0)
  185297. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185298. return 0.0;
  185299. }
  185300. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185301. {
  185302. if (qtMovie != 0)
  185303. qtMovie->PutRate (newSpeed);
  185304. }
  185305. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185306. {
  185307. if (qtMovie != 0)
  185308. {
  185309. qtMovie->PutAudioVolume (newVolume);
  185310. qtMovie->PutAudioMute (newVolume <= 0);
  185311. }
  185312. }
  185313. float QuickTimeMovieComponent::getMovieVolume() const
  185314. {
  185315. if (qtMovie != 0)
  185316. return qtMovie->GetAudioVolume();
  185317. return 0.0f;
  185318. }
  185319. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185320. {
  185321. if (qtMovie != 0)
  185322. qtMovie->PutLoop (shouldLoop);
  185323. }
  185324. bool QuickTimeMovieComponent::isLooping() const
  185325. {
  185326. return qtMovie != 0 && qtMovie->GetLoop();
  185327. }
  185328. bool QuickTimeMovieComponent::isControllerVisible() const
  185329. {
  185330. return controllerVisible;
  185331. }
  185332. void QuickTimeMovieComponent::parentHierarchyChanged()
  185333. {
  185334. createControlIfNeeded();
  185335. QTCompBaseClass::parentHierarchyChanged();
  185336. }
  185337. void QuickTimeMovieComponent::visibilityChanged()
  185338. {
  185339. createControlIfNeeded();
  185340. QTCompBaseClass::visibilityChanged();
  185341. }
  185342. void QuickTimeMovieComponent::paint (Graphics& g)
  185343. {
  185344. if (! isControlCreated())
  185345. g.fillAll (Colours::black);
  185346. }
  185347. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185348. {
  185349. Handle dataRef = 0;
  185350. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185351. if (err == noErr)
  185352. {
  185353. Str255 suffix;
  185354. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185355. StringPtr name = suffix;
  185356. err = PtrAndHand (name, dataRef, name[0] + 1);
  185357. if (err == noErr)
  185358. {
  185359. long atoms[3];
  185360. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185361. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185362. atoms[2] = EndianU32_NtoB (MovieFileType);
  185363. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185364. if (err == noErr)
  185365. return dataRef;
  185366. }
  185367. DisposeHandle (dataRef);
  185368. }
  185369. return 0;
  185370. }
  185371. static CFStringRef juceStringToCFString (const String& s)
  185372. {
  185373. const int len = s.length();
  185374. const juce_wchar* const t = (const juce_wchar*) s;
  185375. HeapBlock <UniChar> temp (len + 2);
  185376. for (int i = 0; i <= len; ++i)
  185377. temp[i] = t[i];
  185378. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185379. }
  185380. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185381. {
  185382. Boolean trueBool = true;
  185383. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185384. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185385. props[prop].propValueSize = sizeof (trueBool);
  185386. props[prop].propValueAddress = &trueBool;
  185387. ++prop;
  185388. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185389. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185390. props[prop].propValueSize = sizeof (trueBool);
  185391. props[prop].propValueAddress = &trueBool;
  185392. ++prop;
  185393. Boolean isActive = true;
  185394. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185395. props[prop].propID = kQTNewMoviePropertyID_Active;
  185396. props[prop].propValueSize = sizeof (isActive);
  185397. props[prop].propValueAddress = &isActive;
  185398. ++prop;
  185399. MacSetPort (0);
  185400. jassert (prop <= 5);
  185401. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185402. return err == noErr;
  185403. }
  185404. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185405. {
  185406. if (input == 0)
  185407. return false;
  185408. dataHandle = 0;
  185409. bool ok = false;
  185410. QTNewMoviePropertyElement props[5];
  185411. zeromem (props, sizeof (props));
  185412. int prop = 0;
  185413. DataReferenceRecord dr;
  185414. props[prop].propClass = kQTPropertyClass_DataLocation;
  185415. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185416. props[prop].propValueSize = sizeof (dr);
  185417. props[prop].propValueAddress = (void*) &dr;
  185418. ++prop;
  185419. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185420. if (fin != 0)
  185421. {
  185422. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185423. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185424. &dr.dataRef, &dr.dataRefType);
  185425. ok = openMovie (props, prop, movie);
  185426. DisposeHandle (dr.dataRef);
  185427. CFRelease (filePath);
  185428. }
  185429. else
  185430. {
  185431. // sanity-check because this currently needs to load the whole stream into memory..
  185432. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185433. dataHandle = NewHandle ((Size) input->getTotalLength());
  185434. HLock (dataHandle);
  185435. // read the entire stream into memory - this is a pain, but can't get it to work
  185436. // properly using a custom callback to supply the data.
  185437. input->read (*dataHandle, (int) input->getTotalLength());
  185438. HUnlock (dataHandle);
  185439. // different types to get QT to try. (We should really be a bit smarter here by
  185440. // working out in advance which one the stream contains, rather than just trying
  185441. // each one)
  185442. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185443. "\04.avi", "\04.m4a" };
  185444. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185445. {
  185446. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185447. dr.dataRefType = HandleDataHandlerSubType;
  185448. ok = openMovie (props, prop, movie);
  185449. DisposeHandle (dr.dataRef);
  185450. }
  185451. }
  185452. return ok;
  185453. }
  185454. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185455. const bool isControllerVisible)
  185456. {
  185457. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185458. movieFile = movieFile_;
  185459. return ok;
  185460. }
  185461. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185462. const bool isControllerVisible)
  185463. {
  185464. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185465. }
  185466. void QuickTimeMovieComponent::goToStart()
  185467. {
  185468. setPosition (0.0);
  185469. }
  185470. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185471. const RectanglePlacement& placement)
  185472. {
  185473. int normalWidth, normalHeight;
  185474. getMovieNormalSize (normalWidth, normalHeight);
  185475. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185476. {
  185477. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185478. placement.applyTo (x, y, w, h,
  185479. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185480. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185481. if (w > 0 && h > 0)
  185482. {
  185483. setBounds (roundToInt (x), roundToInt (y),
  185484. roundToInt (w), roundToInt (h));
  185485. }
  185486. }
  185487. else
  185488. {
  185489. setBounds (spaceToFitWithin);
  185490. }
  185491. }
  185492. #endif
  185493. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185494. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185495. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185496. // compiled on its own).
  185497. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185498. class WebBrowserComponentInternal : public ActiveXControlComponent
  185499. {
  185500. public:
  185501. WebBrowserComponentInternal()
  185502. : browser (0),
  185503. connectionPoint (0),
  185504. adviseCookie (0)
  185505. {
  185506. }
  185507. ~WebBrowserComponentInternal()
  185508. {
  185509. if (connectionPoint != 0)
  185510. connectionPoint->Unadvise (adviseCookie);
  185511. if (browser != 0)
  185512. browser->Release();
  185513. }
  185514. void createBrowser()
  185515. {
  185516. createControl (&CLSID_WebBrowser);
  185517. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185518. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185519. if (connectionPointContainer != 0)
  185520. {
  185521. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185522. &connectionPoint);
  185523. if (connectionPoint != 0)
  185524. {
  185525. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185526. jassert (owner != 0);
  185527. EventHandler* handler = new EventHandler (owner);
  185528. connectionPoint->Advise (handler, &adviseCookie);
  185529. }
  185530. }
  185531. }
  185532. void goToURL (const String& url,
  185533. const StringArray* headers,
  185534. const MemoryBlock* postData)
  185535. {
  185536. if (browser != 0)
  185537. {
  185538. LPSAFEARRAY sa = 0;
  185539. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185540. VariantInit (&flags);
  185541. VariantInit (&frame);
  185542. VariantInit (&postDataVar);
  185543. VariantInit (&headersVar);
  185544. if (headers != 0)
  185545. {
  185546. V_VT (&headersVar) = VT_BSTR;
  185547. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185548. }
  185549. if (postData != 0 && postData->getSize() > 0)
  185550. {
  185551. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185552. if (sa != 0)
  185553. {
  185554. void* data = 0;
  185555. SafeArrayAccessData (sa, &data);
  185556. jassert (data != 0);
  185557. if (data != 0)
  185558. {
  185559. postData->copyTo (data, 0, postData->getSize());
  185560. SafeArrayUnaccessData (sa);
  185561. VARIANT postDataVar2;
  185562. VariantInit (&postDataVar2);
  185563. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185564. V_ARRAY (&postDataVar2) = sa;
  185565. postDataVar = postDataVar2;
  185566. }
  185567. }
  185568. }
  185569. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185570. &flags, &frame,
  185571. &postDataVar, &headersVar);
  185572. if (sa != 0)
  185573. SafeArrayDestroy (sa);
  185574. VariantClear (&flags);
  185575. VariantClear (&frame);
  185576. VariantClear (&postDataVar);
  185577. VariantClear (&headersVar);
  185578. }
  185579. }
  185580. IWebBrowser2* browser;
  185581. juce_UseDebuggingNewOperator
  185582. private:
  185583. IConnectionPoint* connectionPoint;
  185584. DWORD adviseCookie;
  185585. class EventHandler : public IDispatch,
  185586. public ComponentMovementWatcher
  185587. {
  185588. public:
  185589. EventHandler (WebBrowserComponent* owner_)
  185590. : ComponentMovementWatcher (owner_),
  185591. owner (owner_),
  185592. refCount (0)
  185593. {
  185594. }
  185595. ~EventHandler()
  185596. {
  185597. }
  185598. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185599. {
  185600. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185601. {
  185602. AddRef();
  185603. *result = this;
  185604. return S_OK;
  185605. }
  185606. *result = 0;
  185607. return E_NOINTERFACE;
  185608. }
  185609. ULONG __stdcall AddRef() { return ++refCount; }
  185610. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185611. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185612. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185613. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185614. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185615. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185616. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185617. UINT __RPC_FAR* /*puArgErr*/)
  185618. {
  185619. switch (dispIdMember)
  185620. {
  185621. case DISPID_BEFORENAVIGATE2:
  185622. {
  185623. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185624. String url;
  185625. if ((vurl->vt & VT_BYREF) != 0)
  185626. url = *vurl->pbstrVal;
  185627. else
  185628. url = vurl->bstrVal;
  185629. *pDispParams->rgvarg->pboolVal
  185630. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185631. : VARIANT_TRUE;
  185632. return S_OK;
  185633. }
  185634. default:
  185635. break;
  185636. }
  185637. return E_NOTIMPL;
  185638. }
  185639. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185640. void componentPeerChanged() {}
  185641. void componentVisibilityChanged (Component&)
  185642. {
  185643. owner->visibilityChanged();
  185644. }
  185645. juce_UseDebuggingNewOperator
  185646. private:
  185647. WebBrowserComponent* const owner;
  185648. int refCount;
  185649. EventHandler (const EventHandler&);
  185650. const EventHandler& operator= (const EventHandler&);
  185651. };
  185652. };
  185653. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185654. : browser (0),
  185655. blankPageShown (false),
  185656. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185657. {
  185658. setOpaque (true);
  185659. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185660. }
  185661. WebBrowserComponent::~WebBrowserComponent()
  185662. {
  185663. delete browser;
  185664. }
  185665. void WebBrowserComponent::goToURL (const String& url,
  185666. const StringArray* headers,
  185667. const MemoryBlock* postData)
  185668. {
  185669. lastURL = url;
  185670. lastHeaders.clear();
  185671. if (headers != 0)
  185672. lastHeaders = *headers;
  185673. lastPostData.setSize (0);
  185674. if (postData != 0)
  185675. lastPostData = *postData;
  185676. blankPageShown = false;
  185677. browser->goToURL (url, headers, postData);
  185678. }
  185679. void WebBrowserComponent::stop()
  185680. {
  185681. if (browser->browser != 0)
  185682. browser->browser->Stop();
  185683. }
  185684. void WebBrowserComponent::goBack()
  185685. {
  185686. lastURL = String::empty;
  185687. blankPageShown = false;
  185688. if (browser->browser != 0)
  185689. browser->browser->GoBack();
  185690. }
  185691. void WebBrowserComponent::goForward()
  185692. {
  185693. lastURL = String::empty;
  185694. if (browser->browser != 0)
  185695. browser->browser->GoForward();
  185696. }
  185697. void WebBrowserComponent::refresh()
  185698. {
  185699. if (browser->browser != 0)
  185700. browser->browser->Refresh();
  185701. }
  185702. void WebBrowserComponent::paint (Graphics& g)
  185703. {
  185704. if (browser->browser == 0)
  185705. g.fillAll (Colours::white);
  185706. }
  185707. void WebBrowserComponent::checkWindowAssociation()
  185708. {
  185709. if (isShowing())
  185710. {
  185711. if (browser->browser == 0 && getPeer() != 0)
  185712. {
  185713. browser->createBrowser();
  185714. reloadLastURL();
  185715. }
  185716. else
  185717. {
  185718. if (blankPageShown)
  185719. goBack();
  185720. }
  185721. }
  185722. else
  185723. {
  185724. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185725. {
  185726. // when the component becomes invisible, some stuff like flash
  185727. // carries on playing audio, so we need to force it onto a blank
  185728. // page to avoid this..
  185729. blankPageShown = true;
  185730. browser->goToURL ("about:blank", 0, 0);
  185731. }
  185732. }
  185733. }
  185734. void WebBrowserComponent::reloadLastURL()
  185735. {
  185736. if (lastURL.isNotEmpty())
  185737. {
  185738. goToURL (lastURL, &lastHeaders, &lastPostData);
  185739. lastURL = String::empty;
  185740. }
  185741. }
  185742. void WebBrowserComponent::parentHierarchyChanged()
  185743. {
  185744. checkWindowAssociation();
  185745. }
  185746. void WebBrowserComponent::resized()
  185747. {
  185748. browser->setSize (getWidth(), getHeight());
  185749. }
  185750. void WebBrowserComponent::visibilityChanged()
  185751. {
  185752. checkWindowAssociation();
  185753. }
  185754. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185755. {
  185756. return true;
  185757. }
  185758. #endif
  185759. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185760. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185761. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185762. // compiled on its own).
  185763. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185764. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185765. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185766. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185767. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185768. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185769. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185770. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185771. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185772. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185773. #define WGL_ACCELERATION_ARB 0x2003
  185774. #define WGL_SWAP_METHOD_ARB 0x2007
  185775. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185776. #define WGL_PIXEL_TYPE_ARB 0x2013
  185777. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185778. #define WGL_COLOR_BITS_ARB 0x2014
  185779. #define WGL_RED_BITS_ARB 0x2015
  185780. #define WGL_GREEN_BITS_ARB 0x2017
  185781. #define WGL_BLUE_BITS_ARB 0x2019
  185782. #define WGL_ALPHA_BITS_ARB 0x201B
  185783. #define WGL_DEPTH_BITS_ARB 0x2022
  185784. #define WGL_STENCIL_BITS_ARB 0x2023
  185785. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185786. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185787. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185788. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185789. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185790. #define WGL_STEREO_ARB 0x2012
  185791. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185792. #define WGL_SAMPLES_ARB 0x2042
  185793. #define WGL_TYPE_RGBA_ARB 0x202B
  185794. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185795. {
  185796. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185797. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185798. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185799. else
  185800. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185801. }
  185802. class WindowedGLContext : public OpenGLContext
  185803. {
  185804. public:
  185805. WindowedGLContext (Component* const component_,
  185806. HGLRC contextToShareWith,
  185807. const OpenGLPixelFormat& pixelFormat)
  185808. : renderContext (0),
  185809. nativeWindow (0),
  185810. dc (0),
  185811. component (component_)
  185812. {
  185813. jassert (component != 0);
  185814. createNativeWindow();
  185815. // Use a default pixel format that should be supported everywhere
  185816. PIXELFORMATDESCRIPTOR pfd;
  185817. zerostruct (pfd);
  185818. pfd.nSize = sizeof (pfd);
  185819. pfd.nVersion = 1;
  185820. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185821. pfd.iPixelType = PFD_TYPE_RGBA;
  185822. pfd.cColorBits = 24;
  185823. pfd.cDepthBits = 16;
  185824. const int format = ChoosePixelFormat (dc, &pfd);
  185825. if (format != 0)
  185826. SetPixelFormat (dc, format, &pfd);
  185827. renderContext = wglCreateContext (dc);
  185828. makeActive();
  185829. setPixelFormat (pixelFormat);
  185830. if (contextToShareWith != 0 && renderContext != 0)
  185831. wglShareLists (contextToShareWith, renderContext);
  185832. }
  185833. ~WindowedGLContext()
  185834. {
  185835. makeInactive();
  185836. wglDeleteContext (renderContext);
  185837. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185838. delete nativeWindow;
  185839. }
  185840. bool makeActive() const throw()
  185841. {
  185842. jassert (renderContext != 0);
  185843. return wglMakeCurrent (dc, renderContext) != 0;
  185844. }
  185845. bool makeInactive() const throw()
  185846. {
  185847. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185848. }
  185849. bool isActive() const throw()
  185850. {
  185851. return wglGetCurrentContext() == renderContext;
  185852. }
  185853. const OpenGLPixelFormat getPixelFormat() const
  185854. {
  185855. OpenGLPixelFormat pf;
  185856. makeActive();
  185857. StringArray availableExtensions;
  185858. getWglExtensions (dc, availableExtensions);
  185859. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185860. return pf;
  185861. }
  185862. void* getRawContext() const throw()
  185863. {
  185864. return renderContext;
  185865. }
  185866. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185867. {
  185868. makeActive();
  185869. PIXELFORMATDESCRIPTOR pfd;
  185870. zerostruct (pfd);
  185871. pfd.nSize = sizeof (pfd);
  185872. pfd.nVersion = 1;
  185873. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185874. pfd.iPixelType = PFD_TYPE_RGBA;
  185875. pfd.iLayerType = PFD_MAIN_PLANE;
  185876. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185877. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185878. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185879. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185880. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185881. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185882. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185883. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185884. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185885. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185886. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185887. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185888. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185889. int format = 0;
  185890. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185891. StringArray availableExtensions;
  185892. getWglExtensions (dc, availableExtensions);
  185893. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185894. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185895. {
  185896. int attributes[64];
  185897. int n = 0;
  185898. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185899. attributes[n++] = GL_TRUE;
  185900. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185901. attributes[n++] = GL_TRUE;
  185902. attributes[n++] = WGL_ACCELERATION_ARB;
  185903. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185904. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185905. attributes[n++] = GL_TRUE;
  185906. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185907. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185908. attributes[n++] = WGL_COLOR_BITS_ARB;
  185909. attributes[n++] = pfd.cColorBits;
  185910. attributes[n++] = WGL_RED_BITS_ARB;
  185911. attributes[n++] = pixelFormat.redBits;
  185912. attributes[n++] = WGL_GREEN_BITS_ARB;
  185913. attributes[n++] = pixelFormat.greenBits;
  185914. attributes[n++] = WGL_BLUE_BITS_ARB;
  185915. attributes[n++] = pixelFormat.blueBits;
  185916. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185917. attributes[n++] = pixelFormat.alphaBits;
  185918. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185919. attributes[n++] = pixelFormat.depthBufferBits;
  185920. if (pixelFormat.stencilBufferBits > 0)
  185921. {
  185922. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185923. attributes[n++] = pixelFormat.stencilBufferBits;
  185924. }
  185925. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185926. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185927. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185928. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185929. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185930. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185931. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185932. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185933. if (availableExtensions.contains ("WGL_ARB_multisample")
  185934. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185935. {
  185936. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185937. attributes[n++] = 1;
  185938. attributes[n++] = WGL_SAMPLES_ARB;
  185939. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185940. }
  185941. attributes[n++] = 0;
  185942. UINT formatsCount;
  185943. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185944. (void) ok;
  185945. jassert (ok);
  185946. }
  185947. else
  185948. {
  185949. format = ChoosePixelFormat (dc, &pfd);
  185950. }
  185951. if (format != 0)
  185952. {
  185953. makeInactive();
  185954. // win32 can't change the pixel format of a window, so need to delete the
  185955. // old one and create a new one..
  185956. jassert (nativeWindow != 0);
  185957. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185958. delete nativeWindow;
  185959. createNativeWindow();
  185960. if (SetPixelFormat (dc, format, &pfd))
  185961. {
  185962. wglDeleteContext (renderContext);
  185963. renderContext = wglCreateContext (dc);
  185964. jassert (renderContext != 0);
  185965. return renderContext != 0;
  185966. }
  185967. }
  185968. return false;
  185969. }
  185970. void updateWindowPosition (int x, int y, int w, int h, int)
  185971. {
  185972. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185973. x, y, w, h,
  185974. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185975. }
  185976. void repaint()
  185977. {
  185978. int x, y, w, h;
  185979. nativeWindow->getBounds (x, y, w, h);
  185980. nativeWindow->repaint (0, 0, w, h);
  185981. }
  185982. void swapBuffers()
  185983. {
  185984. SwapBuffers (dc);
  185985. }
  185986. bool setSwapInterval (const int numFramesPerSwap)
  185987. {
  185988. makeActive();
  185989. StringArray availableExtensions;
  185990. getWglExtensions (dc, availableExtensions);
  185991. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185992. return availableExtensions.contains ("WGL_EXT_swap_control")
  185993. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185994. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185995. }
  185996. int getSwapInterval() const
  185997. {
  185998. makeActive();
  185999. StringArray availableExtensions;
  186000. getWglExtensions (dc, availableExtensions);
  186001. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  186002. if (availableExtensions.contains ("WGL_EXT_swap_control")
  186003. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  186004. return wglGetSwapIntervalEXT();
  186005. return 0;
  186006. }
  186007. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  186008. {
  186009. jassert (isActive());
  186010. StringArray availableExtensions;
  186011. getWglExtensions (dc, availableExtensions);
  186012. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186013. int numTypes = 0;
  186014. if (availableExtensions.contains("WGL_ARB_pixel_format")
  186015. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186016. {
  186017. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  186018. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  186019. jassertfalse
  186020. }
  186021. else
  186022. {
  186023. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  186024. }
  186025. OpenGLPixelFormat pf;
  186026. for (int i = 0; i < numTypes; ++i)
  186027. {
  186028. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  186029. {
  186030. bool alreadyListed = false;
  186031. for (int j = results.size(); --j >= 0;)
  186032. if (pf == *results.getUnchecked(j))
  186033. alreadyListed = true;
  186034. if (! alreadyListed)
  186035. results.add (new OpenGLPixelFormat (pf));
  186036. }
  186037. }
  186038. }
  186039. void* getNativeWindowHandle() const
  186040. {
  186041. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  186042. }
  186043. juce_UseDebuggingNewOperator
  186044. HGLRC renderContext;
  186045. private:
  186046. Win32ComponentPeer* nativeWindow;
  186047. Component* const component;
  186048. HDC dc;
  186049. void createNativeWindow()
  186050. {
  186051. nativeWindow = new Win32ComponentPeer (component, 0);
  186052. nativeWindow->dontRepaint = true;
  186053. nativeWindow->setVisible (true);
  186054. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  186055. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  186056. if (peer != 0)
  186057. {
  186058. SetParent (hwnd, (HWND) peer->getNativeHandle());
  186059. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  186060. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  186061. }
  186062. dc = GetDC (hwnd);
  186063. }
  186064. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  186065. OpenGLPixelFormat& result,
  186066. const StringArray& availableExtensions) const throw()
  186067. {
  186068. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186069. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  186070. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186071. {
  186072. int attributes[32];
  186073. int numAttributes = 0;
  186074. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  186075. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  186076. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  186077. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  186078. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  186079. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  186080. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  186081. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  186082. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  186083. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  186084. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  186085. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  186086. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  186087. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  186088. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  186089. if (availableExtensions.contains ("WGL_ARB_multisample"))
  186090. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  186091. int values[32];
  186092. zeromem (values, sizeof (values));
  186093. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  186094. {
  186095. int n = 0;
  186096. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  186097. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  186098. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  186099. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  186100. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  186101. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  186102. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  186103. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  186104. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  186105. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  186106. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  186107. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  186108. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  186109. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  186110. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  186111. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  186112. return isValidFormat;
  186113. }
  186114. else
  186115. {
  186116. jassertfalse
  186117. }
  186118. }
  186119. else
  186120. {
  186121. PIXELFORMATDESCRIPTOR pfd;
  186122. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  186123. {
  186124. result.redBits = pfd.cRedBits;
  186125. result.greenBits = pfd.cGreenBits;
  186126. result.blueBits = pfd.cBlueBits;
  186127. result.alphaBits = pfd.cAlphaBits;
  186128. result.depthBufferBits = pfd.cDepthBits;
  186129. result.stencilBufferBits = pfd.cStencilBits;
  186130. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186131. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186132. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186133. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186134. result.fullSceneAntiAliasingNumSamples = 0;
  186135. return true;
  186136. }
  186137. else
  186138. {
  186139. jassertfalse
  186140. }
  186141. }
  186142. return false;
  186143. }
  186144. WindowedGLContext (const WindowedGLContext&);
  186145. const WindowedGLContext& operator= (const WindowedGLContext&);
  186146. };
  186147. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186148. const OpenGLPixelFormat& pixelFormat,
  186149. const OpenGLContext* const contextToShareWith)
  186150. {
  186151. WindowedGLContext* c = new WindowedGLContext (component,
  186152. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186153. pixelFormat);
  186154. if (c->renderContext == 0)
  186155. deleteAndZero (c);
  186156. return c;
  186157. }
  186158. void* OpenGLComponent::getNativeWindowHandle() const
  186159. {
  186160. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186161. }
  186162. void juce_glViewport (const int w, const int h)
  186163. {
  186164. glViewport (0, 0, w, h);
  186165. }
  186166. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186167. OwnedArray <OpenGLPixelFormat>& results)
  186168. {
  186169. Component tempComp;
  186170. {
  186171. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186172. wc.makeActive();
  186173. wc.findAlternativeOpenGLPixelFormats (results);
  186174. }
  186175. }
  186176. #endif
  186177. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  186178. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  186179. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186180. // compiled on its own).
  186181. #if JUCE_INCLUDED_FILE
  186182. #if JUCE_USE_CDREADER
  186183. //***************************************************************************
  186184. // %%% TARGET STATUS VALUES %%%
  186185. //***************************************************************************
  186186. #define STATUS_GOOD 0x00 // Status Good
  186187. #define STATUS_CHKCOND 0x02 // Check Condition
  186188. #define STATUS_CONDMET 0x04 // Condition Met
  186189. #define STATUS_BUSY 0x08 // Busy
  186190. #define STATUS_INTERM 0x10 // Intermediate
  186191. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186192. #define STATUS_RESCONF 0x18 // Reservation conflict
  186193. #define STATUS_COMTERM 0x22 // Command Terminated
  186194. #define STATUS_QFULL 0x28 // Queue full
  186195. //***************************************************************************
  186196. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186197. //***************************************************************************
  186198. #define MAXLUN 7 // Maximum Logical Unit Id
  186199. #define MAXTARG 7 // Maximum Target Id
  186200. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186201. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186202. //***************************************************************************
  186203. // %%% Commands for all Device Types %%%
  186204. //***************************************************************************
  186205. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186206. #define SCSI_COMPARE 0x39 // Compare (O)
  186207. #define SCSI_COPY 0x18 // Copy (O)
  186208. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186209. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186210. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186211. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186212. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186213. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186214. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186215. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186216. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186217. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186218. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186219. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186220. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186221. //***************************************************************************
  186222. // %%% Commands Unique to Direct Access Devices %%%
  186223. //***************************************************************************
  186224. #define SCSI_COMPARE 0x39 // Compare (O)
  186225. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186226. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186227. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186228. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186229. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186230. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186231. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186232. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186233. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186234. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186235. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186236. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186237. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186238. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186239. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186240. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186241. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186242. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186243. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186244. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186245. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186246. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186247. #define SCSI_VERIFY 0x2F // Verify (O)
  186248. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186249. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186250. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186251. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186252. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186253. //***************************************************************************
  186254. // %%% Commands Unique to Sequential Access Devices %%%
  186255. //***************************************************************************
  186256. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186257. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186258. #define SCSI_LOCATE 0x2B // Locate (O)
  186259. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186260. #define SCSI_READ_POS 0x34 // Read Position (O)
  186261. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186262. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186263. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186264. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186265. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186266. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186267. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186268. //***************************************************************************
  186269. // %%% Commands Unique to Printer Devices %%%
  186270. //***************************************************************************
  186271. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186272. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186273. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186274. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186275. //***************************************************************************
  186276. // %%% Commands Unique to Processor Devices %%%
  186277. //***************************************************************************
  186278. #define SCSI_RECEIVE 0x08 // Receive (O)
  186279. #define SCSI_SEND 0x0A // Send (O)
  186280. //***************************************************************************
  186281. // %%% Commands Unique to Write-Once Devices %%%
  186282. //***************************************************************************
  186283. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186284. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186285. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186286. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186287. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186288. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186289. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186290. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186291. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186292. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186293. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186294. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186295. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186296. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186297. //***************************************************************************
  186298. // %%% Commands Unique to CD-ROM Devices %%%
  186299. //***************************************************************************
  186300. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186301. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186302. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186303. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186304. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186305. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186306. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186307. #define SCSI_READHEADER 0x44 // Read Header (O)
  186308. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186309. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186310. //***************************************************************************
  186311. // %%% Commands Unique to Scanner Devices %%%
  186312. //***************************************************************************
  186313. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186314. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186315. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186316. #define SCSI_SCAN 0x1B // Scan (O)
  186317. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186318. //***************************************************************************
  186319. // %%% Commands Unique to Optical Memory Devices %%%
  186320. //***************************************************************************
  186321. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186322. //***************************************************************************
  186323. // %%% Commands Unique to Medium Changer Devices %%%
  186324. //***************************************************************************
  186325. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186326. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186327. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186328. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186329. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186330. //***************************************************************************
  186331. // %%% Commands Unique to Communication Devices %%%
  186332. //***************************************************************************
  186333. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186334. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186335. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186336. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186337. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186338. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186339. //***************************************************************************
  186340. // %%% Request Sense Data Format %%%
  186341. //***************************************************************************
  186342. typedef struct {
  186343. BYTE ErrorCode; // Error Code (70H or 71H)
  186344. BYTE SegmentNum; // Number of current segment descriptor
  186345. BYTE SenseKey; // Sense Key(See bit definitions too)
  186346. BYTE InfoByte0; // Information MSB
  186347. BYTE InfoByte1; // Information MID
  186348. BYTE InfoByte2; // Information MID
  186349. BYTE InfoByte3; // Information LSB
  186350. BYTE AddSenLen; // Additional Sense Length
  186351. BYTE ComSpecInf0; // Command Specific Information MSB
  186352. BYTE ComSpecInf1; // Command Specific Information MID
  186353. BYTE ComSpecInf2; // Command Specific Information MID
  186354. BYTE ComSpecInf3; // Command Specific Information LSB
  186355. BYTE AddSenseCode; // Additional Sense Code
  186356. BYTE AddSenQual; // Additional Sense Code Qualifier
  186357. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186358. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186359. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186360. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186361. BYTE AddSenseBytes; // Additional Sense Bytes
  186362. } SENSE_DATA_FMT;
  186363. //***************************************************************************
  186364. // %%% REQUEST SENSE ERROR CODE %%%
  186365. //***************************************************************************
  186366. #define SERROR_CURRENT 0x70 // Current Errors
  186367. #define SERROR_DEFERED 0x71 // Deferred Errors
  186368. //***************************************************************************
  186369. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186370. //***************************************************************************
  186371. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186372. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186373. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186374. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186375. //***************************************************************************
  186376. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186377. //***************************************************************************
  186378. #define KEY_NOSENSE 0x00 // No Sense
  186379. #define KEY_RECERROR 0x01 // Recovered Error
  186380. #define KEY_NOTREADY 0x02 // Not Ready
  186381. #define KEY_MEDIUMERR 0x03 // Medium Error
  186382. #define KEY_HARDERROR 0x04 // Hardware Error
  186383. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186384. #define KEY_UNITATT 0x06 // Unit Attention
  186385. #define KEY_DATAPROT 0x07 // Data Protect
  186386. #define KEY_BLANKCHK 0x08 // Blank Check
  186387. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186388. #define KEY_COPYABORT 0x0A // Copy Abort
  186389. #define KEY_EQUAL 0x0C // Equal (Search)
  186390. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186391. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186392. #define KEY_RESERVED 0x0F // Reserved
  186393. //***************************************************************************
  186394. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186395. //***************************************************************************
  186396. #define DTYPE_DASD 0x00 // Disk Device
  186397. #define DTYPE_SEQD 0x01 // Tape Device
  186398. #define DTYPE_PRNT 0x02 // Printer
  186399. #define DTYPE_PROC 0x03 // Processor
  186400. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186401. #define DTYPE_CROM 0x05 // CD-ROM device
  186402. #define DTYPE_SCAN 0x06 // Scanner device
  186403. #define DTYPE_OPTI 0x07 // Optical memory device
  186404. #define DTYPE_JUKE 0x08 // Medium Changer device
  186405. #define DTYPE_COMM 0x09 // Communications device
  186406. #define DTYPE_RESL 0x0A // Reserved (low)
  186407. #define DTYPE_RESH 0x1E // Reserved (high)
  186408. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186409. //***************************************************************************
  186410. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186411. //***************************************************************************
  186412. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186413. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186414. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186415. #define ANSI_RESLO 0x3 // Reserved (low)
  186416. #define ANSI_RESHI 0x7 // Reserved (high)
  186417. typedef struct
  186418. {
  186419. USHORT Length;
  186420. UCHAR ScsiStatus;
  186421. UCHAR PathId;
  186422. UCHAR TargetId;
  186423. UCHAR Lun;
  186424. UCHAR CdbLength;
  186425. UCHAR SenseInfoLength;
  186426. UCHAR DataIn;
  186427. ULONG DataTransferLength;
  186428. ULONG TimeOutValue;
  186429. ULONG DataBufferOffset;
  186430. ULONG SenseInfoOffset;
  186431. UCHAR Cdb[16];
  186432. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186433. typedef struct
  186434. {
  186435. USHORT Length;
  186436. UCHAR ScsiStatus;
  186437. UCHAR PathId;
  186438. UCHAR TargetId;
  186439. UCHAR Lun;
  186440. UCHAR CdbLength;
  186441. UCHAR SenseInfoLength;
  186442. UCHAR DataIn;
  186443. ULONG DataTransferLength;
  186444. ULONG TimeOutValue;
  186445. PVOID DataBuffer;
  186446. ULONG SenseInfoOffset;
  186447. UCHAR Cdb[16];
  186448. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186449. typedef struct
  186450. {
  186451. SCSI_PASS_THROUGH_DIRECT spt;
  186452. ULONG Filler;
  186453. UCHAR ucSenseBuf[32];
  186454. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186455. typedef struct
  186456. {
  186457. ULONG Length;
  186458. UCHAR PortNumber;
  186459. UCHAR PathId;
  186460. UCHAR TargetId;
  186461. UCHAR Lun;
  186462. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186463. #define METHOD_BUFFERED 0
  186464. #define METHOD_IN_DIRECT 1
  186465. #define METHOD_OUT_DIRECT 2
  186466. #define METHOD_NEITHER 3
  186467. #define FILE_ANY_ACCESS 0
  186468. #ifndef FILE_READ_ACCESS
  186469. #define FILE_READ_ACCESS (0x0001)
  186470. #endif
  186471. #ifndef FILE_WRITE_ACCESS
  186472. #define FILE_WRITE_ACCESS (0x0002)
  186473. #endif
  186474. #define IOCTL_SCSI_BASE 0x00000004
  186475. #define SCSI_IOCTL_DATA_OUT 0
  186476. #define SCSI_IOCTL_DATA_IN 1
  186477. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186478. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186479. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186480. )
  186481. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186482. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186483. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186484. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186485. #define SENSE_LEN 14
  186486. #define SRB_DIR_SCSI 0x00
  186487. #define SRB_POSTING 0x01
  186488. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186489. #define SRB_DIR_IN 0x08
  186490. #define SRB_DIR_OUT 0x10
  186491. #define SRB_EVENT_NOTIFY 0x40
  186492. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186493. #define MAX_SRB_TIMEOUT 1080001u
  186494. #define DEFAULT_SRB_TIMEOUT 1080001u
  186495. #define SC_HA_INQUIRY 0x00
  186496. #define SC_GET_DEV_TYPE 0x01
  186497. #define SC_EXEC_SCSI_CMD 0x02
  186498. #define SC_ABORT_SRB 0x03
  186499. #define SC_RESET_DEV 0x04
  186500. #define SC_SET_HA_PARMS 0x05
  186501. #define SC_GET_DISK_INFO 0x06
  186502. #define SC_RESCAN_SCSI_BUS 0x07
  186503. #define SC_GETSET_TIMEOUTS 0x08
  186504. #define SS_PENDING 0x00
  186505. #define SS_COMP 0x01
  186506. #define SS_ABORTED 0x02
  186507. #define SS_ABORT_FAIL 0x03
  186508. #define SS_ERR 0x04
  186509. #define SS_INVALID_CMD 0x80
  186510. #define SS_INVALID_HA 0x81
  186511. #define SS_NO_DEVICE 0x82
  186512. #define SS_INVALID_SRB 0xE0
  186513. #define SS_OLD_MANAGER 0xE1
  186514. #define SS_BUFFER_ALIGN 0xE1
  186515. #define SS_ILLEGAL_MODE 0xE2
  186516. #define SS_NO_ASPI 0xE3
  186517. #define SS_FAILED_INIT 0xE4
  186518. #define SS_ASPI_IS_BUSY 0xE5
  186519. #define SS_BUFFER_TO_BIG 0xE6
  186520. #define SS_BUFFER_TOO_BIG 0xE6
  186521. #define SS_MISMATCHED_COMPONENTS 0xE7
  186522. #define SS_NO_ADAPTERS 0xE8
  186523. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186524. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186525. #define SS_BAD_INSTALL 0xEB
  186526. #define HASTAT_OK 0x00
  186527. #define HASTAT_SEL_TO 0x11
  186528. #define HASTAT_DO_DU 0x12
  186529. #define HASTAT_BUS_FREE 0x13
  186530. #define HASTAT_PHASE_ERR 0x14
  186531. #define HASTAT_TIMEOUT 0x09
  186532. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186533. #define HASTAT_MESSAGE_REJECT 0x0D
  186534. #define HASTAT_BUS_RESET 0x0E
  186535. #define HASTAT_PARITY_ERROR 0x0F
  186536. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186537. #define PACKED
  186538. #pragma pack(1)
  186539. typedef struct
  186540. {
  186541. BYTE SRB_Cmd;
  186542. BYTE SRB_Status;
  186543. BYTE SRB_HaID;
  186544. BYTE SRB_Flags;
  186545. DWORD SRB_Hdr_Rsvd;
  186546. BYTE HA_Count;
  186547. BYTE HA_SCSI_ID;
  186548. BYTE HA_ManagerId[16];
  186549. BYTE HA_Identifier[16];
  186550. BYTE HA_Unique[16];
  186551. WORD HA_Rsvd1;
  186552. BYTE pad[20];
  186553. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186554. typedef struct
  186555. {
  186556. BYTE SRB_Cmd;
  186557. BYTE SRB_Status;
  186558. BYTE SRB_HaID;
  186559. BYTE SRB_Flags;
  186560. DWORD SRB_Hdr_Rsvd;
  186561. BYTE SRB_Target;
  186562. BYTE SRB_Lun;
  186563. BYTE SRB_DeviceType;
  186564. BYTE SRB_Rsvd1;
  186565. BYTE pad[68];
  186566. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186567. typedef struct
  186568. {
  186569. BYTE SRB_Cmd;
  186570. BYTE SRB_Status;
  186571. BYTE SRB_HaID;
  186572. BYTE SRB_Flags;
  186573. DWORD SRB_Hdr_Rsvd;
  186574. BYTE SRB_Target;
  186575. BYTE SRB_Lun;
  186576. WORD SRB_Rsvd1;
  186577. DWORD SRB_BufLen;
  186578. BYTE FAR *SRB_BufPointer;
  186579. BYTE SRB_SenseLen;
  186580. BYTE SRB_CDBLen;
  186581. BYTE SRB_HaStat;
  186582. BYTE SRB_TargStat;
  186583. VOID FAR *SRB_PostProc;
  186584. BYTE SRB_Rsvd2[20];
  186585. BYTE CDBByte[16];
  186586. BYTE SenseArea[SENSE_LEN+2];
  186587. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186588. typedef struct
  186589. {
  186590. BYTE SRB_Cmd;
  186591. BYTE SRB_Status;
  186592. BYTE SRB_HaId;
  186593. BYTE SRB_Flags;
  186594. DWORD SRB_Hdr_Rsvd;
  186595. } PACKED SRB, *PSRB, FAR *LPSRB;
  186596. #pragma pack()
  186597. struct CDDeviceInfo
  186598. {
  186599. char vendor[9];
  186600. char productId[17];
  186601. char rev[5];
  186602. char vendorSpec[21];
  186603. BYTE ha;
  186604. BYTE tgt;
  186605. BYTE lun;
  186606. char scsiDriveLetter; // will be 0 if not using scsi
  186607. };
  186608. class CDReadBuffer
  186609. {
  186610. public:
  186611. int startFrame;
  186612. int numFrames;
  186613. int dataStartOffset;
  186614. int dataLength;
  186615. BYTE* buffer;
  186616. int bufferSize;
  186617. int index;
  186618. bool wantsIndex;
  186619. CDReadBuffer (const int numberOfFrames)
  186620. : startFrame (0),
  186621. numFrames (0),
  186622. dataStartOffset (0),
  186623. dataLength (0),
  186624. index (0),
  186625. wantsIndex (false)
  186626. {
  186627. bufferSize = 2352 * numberOfFrames;
  186628. buffer = (BYTE*) malloc (bufferSize);
  186629. }
  186630. ~CDReadBuffer()
  186631. {
  186632. free (buffer);
  186633. }
  186634. bool isZero() const
  186635. {
  186636. BYTE* p = buffer + dataStartOffset;
  186637. for (int i = dataLength; --i >= 0;)
  186638. if (*p++ != 0)
  186639. return false;
  186640. return true;
  186641. }
  186642. };
  186643. class CDDeviceHandle;
  186644. class CDController
  186645. {
  186646. public:
  186647. CDController();
  186648. virtual ~CDController();
  186649. virtual bool read (CDReadBuffer* t) = 0;
  186650. virtual void shutDown();
  186651. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186652. int getLastIndex();
  186653. public:
  186654. bool initialised;
  186655. CDDeviceHandle* deviceInfo;
  186656. int framesToCheck, framesOverlap;
  186657. void prepare (SRB_ExecSCSICmd& s);
  186658. void perform (SRB_ExecSCSICmd& s);
  186659. void setPaused (bool paused);
  186660. };
  186661. #pragma pack(1)
  186662. struct TOCTRACK
  186663. {
  186664. BYTE rsvd;
  186665. BYTE ADR;
  186666. BYTE trackNumber;
  186667. BYTE rsvd2;
  186668. BYTE addr[4];
  186669. };
  186670. struct TOC
  186671. {
  186672. WORD tocLen;
  186673. BYTE firstTrack;
  186674. BYTE lastTrack;
  186675. TOCTRACK tracks[100];
  186676. };
  186677. #pragma pack()
  186678. enum
  186679. {
  186680. READTYPE_ANY = 0,
  186681. READTYPE_ATAPI1 = 1,
  186682. READTYPE_ATAPI2 = 2,
  186683. READTYPE_READ6 = 3,
  186684. READTYPE_READ10 = 4,
  186685. READTYPE_READ_D8 = 5,
  186686. READTYPE_READ_D4 = 6,
  186687. READTYPE_READ_D4_1 = 7,
  186688. READTYPE_READ10_2 = 8
  186689. };
  186690. class CDDeviceHandle
  186691. {
  186692. public:
  186693. CDDeviceHandle (const CDDeviceInfo* const device)
  186694. : scsiHandle (0),
  186695. readType (READTYPE_ANY),
  186696. controller (0)
  186697. {
  186698. memcpy (&info, device, sizeof (info));
  186699. }
  186700. ~CDDeviceHandle()
  186701. {
  186702. if (controller != 0)
  186703. {
  186704. controller->shutDown();
  186705. delete controller;
  186706. }
  186707. if (scsiHandle != 0)
  186708. CloseHandle (scsiHandle);
  186709. }
  186710. bool readTOC (TOC* lpToc, bool useMSF);
  186711. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186712. void openDrawer (bool shouldBeOpen);
  186713. CDDeviceInfo info;
  186714. HANDLE scsiHandle;
  186715. BYTE readType;
  186716. private:
  186717. CDController* controller;
  186718. bool testController (const int readType,
  186719. CDController* const newController,
  186720. CDReadBuffer* const bufferToUse);
  186721. };
  186722. DWORD (*fGetASPI32SupportInfo)(void);
  186723. DWORD (*fSendASPI32Command)(LPSRB);
  186724. static HINSTANCE winAspiLib = 0;
  186725. static bool usingScsi = false;
  186726. static bool initialised = false;
  186727. static bool InitialiseCDRipper()
  186728. {
  186729. if (! initialised)
  186730. {
  186731. initialised = true;
  186732. OSVERSIONINFO info;
  186733. info.dwOSVersionInfoSize = sizeof (info);
  186734. GetVersionEx (&info);
  186735. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186736. if (! usingScsi)
  186737. {
  186738. fGetASPI32SupportInfo = 0;
  186739. fSendASPI32Command = 0;
  186740. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186741. if (winAspiLib != 0)
  186742. {
  186743. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186744. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186745. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186746. return false;
  186747. }
  186748. else
  186749. {
  186750. usingScsi = true;
  186751. }
  186752. }
  186753. }
  186754. return true;
  186755. }
  186756. static void DeinitialiseCDRipper()
  186757. {
  186758. if (winAspiLib != 0)
  186759. {
  186760. fGetASPI32SupportInfo = 0;
  186761. fSendASPI32Command = 0;
  186762. FreeLibrary (winAspiLib);
  186763. winAspiLib = 0;
  186764. }
  186765. initialised = false;
  186766. }
  186767. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186768. {
  186769. TCHAR devicePath[8];
  186770. devicePath[0] = '\\';
  186771. devicePath[1] = '\\';
  186772. devicePath[2] = '.';
  186773. devicePath[3] = '\\';
  186774. devicePath[4] = driveLetter;
  186775. devicePath[5] = ':';
  186776. devicePath[6] = 0;
  186777. OSVERSIONINFO info;
  186778. info.dwOSVersionInfoSize = sizeof (info);
  186779. GetVersionEx (&info);
  186780. DWORD flags = GENERIC_READ;
  186781. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186782. flags = GENERIC_READ | GENERIC_WRITE;
  186783. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186784. if (h == INVALID_HANDLE_VALUE)
  186785. {
  186786. flags ^= GENERIC_WRITE;
  186787. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186788. }
  186789. return h;
  186790. }
  186791. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186792. const char driveLetter,
  186793. HANDLE& deviceHandle,
  186794. const bool retryOnFailure = true)
  186795. {
  186796. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186797. zerostruct (s);
  186798. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186799. s.spt.CdbLength = srb->SRB_CDBLen;
  186800. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186801. ? SCSI_IOCTL_DATA_IN
  186802. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186803. ? SCSI_IOCTL_DATA_OUT
  186804. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186805. s.spt.DataTransferLength = srb->SRB_BufLen;
  186806. s.spt.TimeOutValue = 5;
  186807. s.spt.DataBuffer = srb->SRB_BufPointer;
  186808. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186809. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186810. srb->SRB_Status = SS_ERR;
  186811. srb->SRB_TargStat = 0x0004;
  186812. DWORD bytesReturned = 0;
  186813. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186814. &s, sizeof (s),
  186815. &s, sizeof (s),
  186816. &bytesReturned, 0) != 0)
  186817. {
  186818. srb->SRB_Status = SS_COMP;
  186819. }
  186820. else if (retryOnFailure)
  186821. {
  186822. const DWORD error = GetLastError();
  186823. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186824. {
  186825. if (error != ERROR_INVALID_HANDLE)
  186826. CloseHandle (deviceHandle);
  186827. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186828. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186829. }
  186830. }
  186831. return srb->SRB_Status;
  186832. }
  186833. // Controller types..
  186834. class ControllerType1 : public CDController
  186835. {
  186836. public:
  186837. ControllerType1() {}
  186838. ~ControllerType1() {}
  186839. bool read (CDReadBuffer* rb)
  186840. {
  186841. if (rb->numFrames * 2352 > rb->bufferSize)
  186842. return false;
  186843. SRB_ExecSCSICmd s;
  186844. prepare (s);
  186845. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186846. s.SRB_BufLen = rb->bufferSize;
  186847. s.SRB_BufPointer = rb->buffer;
  186848. s.SRB_CDBLen = 12;
  186849. s.CDBByte[0] = 0xBE;
  186850. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186851. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186852. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186853. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186854. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186855. perform (s);
  186856. if (s.SRB_Status != SS_COMP)
  186857. return false;
  186858. rb->dataLength = rb->numFrames * 2352;
  186859. rb->dataStartOffset = 0;
  186860. return true;
  186861. }
  186862. };
  186863. class ControllerType2 : public CDController
  186864. {
  186865. public:
  186866. ControllerType2() {}
  186867. ~ControllerType2() {}
  186868. void shutDown()
  186869. {
  186870. if (initialised)
  186871. {
  186872. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186873. SRB_ExecSCSICmd s;
  186874. prepare (s);
  186875. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186876. s.SRB_BufLen = 0x0C;
  186877. s.SRB_BufPointer = bufPointer;
  186878. s.SRB_CDBLen = 6;
  186879. s.CDBByte[0] = 0x15;
  186880. s.CDBByte[4] = 0x0C;
  186881. perform (s);
  186882. }
  186883. }
  186884. bool init()
  186885. {
  186886. SRB_ExecSCSICmd s;
  186887. s.SRB_Status = SS_ERR;
  186888. if (deviceInfo->readType == READTYPE_READ10_2)
  186889. {
  186890. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186891. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186892. for (int i = 0; i < 2; ++i)
  186893. {
  186894. prepare (s);
  186895. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186896. s.SRB_BufLen = 0x14;
  186897. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186898. s.SRB_CDBLen = 6;
  186899. s.CDBByte[0] = 0x15;
  186900. s.CDBByte[1] = 0x10;
  186901. s.CDBByte[4] = 0x14;
  186902. perform (s);
  186903. if (s.SRB_Status != SS_COMP)
  186904. return false;
  186905. }
  186906. }
  186907. else
  186908. {
  186909. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186910. prepare (s);
  186911. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186912. s.SRB_BufLen = 0x0C;
  186913. s.SRB_BufPointer = bufPointer;
  186914. s.SRB_CDBLen = 6;
  186915. s.CDBByte[0] = 0x15;
  186916. s.CDBByte[4] = 0x0C;
  186917. perform (s);
  186918. }
  186919. return s.SRB_Status == SS_COMP;
  186920. }
  186921. bool read (CDReadBuffer* rb)
  186922. {
  186923. if (rb->numFrames * 2352 > rb->bufferSize)
  186924. return false;
  186925. if (!initialised)
  186926. {
  186927. initialised = init();
  186928. if (!initialised)
  186929. return false;
  186930. }
  186931. SRB_ExecSCSICmd s;
  186932. prepare (s);
  186933. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186934. s.SRB_BufLen = rb->bufferSize;
  186935. s.SRB_BufPointer = rb->buffer;
  186936. s.SRB_CDBLen = 10;
  186937. s.CDBByte[0] = 0x28;
  186938. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186939. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186940. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186941. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186942. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186943. perform (s);
  186944. if (s.SRB_Status != SS_COMP)
  186945. return false;
  186946. rb->dataLength = rb->numFrames * 2352;
  186947. rb->dataStartOffset = 0;
  186948. return true;
  186949. }
  186950. };
  186951. class ControllerType3 : public CDController
  186952. {
  186953. public:
  186954. ControllerType3() {}
  186955. ~ControllerType3() {}
  186956. bool read (CDReadBuffer* rb)
  186957. {
  186958. if (rb->numFrames * 2352 > rb->bufferSize)
  186959. return false;
  186960. if (!initialised)
  186961. {
  186962. setPaused (false);
  186963. initialised = true;
  186964. }
  186965. SRB_ExecSCSICmd s;
  186966. prepare (s);
  186967. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186968. s.SRB_BufLen = rb->numFrames * 2352;
  186969. s.SRB_BufPointer = rb->buffer;
  186970. s.SRB_CDBLen = 12;
  186971. s.CDBByte[0] = 0xD8;
  186972. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186973. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186974. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186975. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186976. perform (s);
  186977. if (s.SRB_Status != SS_COMP)
  186978. return false;
  186979. rb->dataLength = rb->numFrames * 2352;
  186980. rb->dataStartOffset = 0;
  186981. return true;
  186982. }
  186983. };
  186984. class ControllerType4 : public CDController
  186985. {
  186986. public:
  186987. ControllerType4() {}
  186988. ~ControllerType4() {}
  186989. bool selectD4Mode()
  186990. {
  186991. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186992. SRB_ExecSCSICmd s;
  186993. prepare (s);
  186994. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186995. s.SRB_CDBLen = 6;
  186996. s.SRB_BufLen = 12;
  186997. s.SRB_BufPointer = bufPointer;
  186998. s.CDBByte[0] = 0x15;
  186999. s.CDBByte[1] = 0x10;
  187000. s.CDBByte[4] = 0x08;
  187001. perform (s);
  187002. return s.SRB_Status == SS_COMP;
  187003. }
  187004. bool read (CDReadBuffer* rb)
  187005. {
  187006. if (rb->numFrames * 2352 > rb->bufferSize)
  187007. return false;
  187008. if (!initialised)
  187009. {
  187010. setPaused (true);
  187011. if (deviceInfo->readType == READTYPE_READ_D4_1)
  187012. selectD4Mode();
  187013. initialised = true;
  187014. }
  187015. SRB_ExecSCSICmd s;
  187016. prepare (s);
  187017. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187018. s.SRB_BufLen = rb->bufferSize;
  187019. s.SRB_BufPointer = rb->buffer;
  187020. s.SRB_CDBLen = 10;
  187021. s.CDBByte[0] = 0xD4;
  187022. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187023. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187024. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187025. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187026. perform (s);
  187027. if (s.SRB_Status != SS_COMP)
  187028. return false;
  187029. rb->dataLength = rb->numFrames * 2352;
  187030. rb->dataStartOffset = 0;
  187031. return true;
  187032. }
  187033. };
  187034. CDController::CDController() : initialised (false)
  187035. {
  187036. }
  187037. CDController::~CDController()
  187038. {
  187039. }
  187040. void CDController::prepare (SRB_ExecSCSICmd& s)
  187041. {
  187042. zerostruct (s);
  187043. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187044. s.SRB_HaID = deviceInfo->info.ha;
  187045. s.SRB_Target = deviceInfo->info.tgt;
  187046. s.SRB_Lun = deviceInfo->info.lun;
  187047. s.SRB_SenseLen = SENSE_LEN;
  187048. }
  187049. void CDController::perform (SRB_ExecSCSICmd& s)
  187050. {
  187051. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187052. s.SRB_PostProc = (void*)event;
  187053. ResetEvent (event);
  187054. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  187055. deviceInfo->info.scsiDriveLetter,
  187056. deviceInfo->scsiHandle)
  187057. : fSendASPI32Command ((LPSRB)&s);
  187058. if (status == SS_PENDING)
  187059. WaitForSingleObject (event, 4000);
  187060. CloseHandle (event);
  187061. }
  187062. void CDController::setPaused (bool paused)
  187063. {
  187064. SRB_ExecSCSICmd s;
  187065. prepare (s);
  187066. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187067. s.SRB_CDBLen = 10;
  187068. s.CDBByte[0] = 0x4B;
  187069. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  187070. perform (s);
  187071. }
  187072. void CDController::shutDown()
  187073. {
  187074. }
  187075. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  187076. {
  187077. if (overlapBuffer != 0)
  187078. {
  187079. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  187080. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  187081. if (doJitter
  187082. && overlapBuffer->startFrame > 0
  187083. && overlapBuffer->numFrames > 0
  187084. && overlapBuffer->dataLength > 0)
  187085. {
  187086. const int numFrames = rb->numFrames;
  187087. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  187088. {
  187089. rb->startFrame -= framesOverlap;
  187090. if (framesToCheck < framesOverlap
  187091. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  187092. rb->numFrames += framesOverlap;
  187093. }
  187094. else
  187095. {
  187096. overlapBuffer->dataLength = 0;
  187097. overlapBuffer->startFrame = 0;
  187098. overlapBuffer->numFrames = 0;
  187099. }
  187100. }
  187101. if (! read (rb))
  187102. return false;
  187103. if (doJitter)
  187104. {
  187105. const int checkLen = framesToCheck * 2352;
  187106. const int maxToCheck = rb->dataLength - checkLen;
  187107. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  187108. return true;
  187109. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  187110. bool found = false;
  187111. for (int i = 0; i < maxToCheck; ++i)
  187112. {
  187113. if (!memcmp (p, rb->buffer + i, checkLen))
  187114. {
  187115. i += checkLen;
  187116. rb->dataStartOffset = i;
  187117. rb->dataLength -= i;
  187118. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  187119. found = true;
  187120. break;
  187121. }
  187122. }
  187123. rb->numFrames = rb->dataLength / 2352;
  187124. rb->dataLength = 2352 * rb->numFrames;
  187125. if (!found)
  187126. return false;
  187127. }
  187128. if (canDoJitter)
  187129. {
  187130. memcpy (overlapBuffer->buffer,
  187131. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187132. 2352 * framesToCheck);
  187133. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187134. overlapBuffer->numFrames = framesToCheck;
  187135. overlapBuffer->dataLength = 2352 * framesToCheck;
  187136. overlapBuffer->dataStartOffset = 0;
  187137. }
  187138. else
  187139. {
  187140. overlapBuffer->startFrame = 0;
  187141. overlapBuffer->numFrames = 0;
  187142. overlapBuffer->dataLength = 0;
  187143. }
  187144. return true;
  187145. }
  187146. else
  187147. {
  187148. return read (rb);
  187149. }
  187150. }
  187151. int CDController::getLastIndex()
  187152. {
  187153. char qdata[100];
  187154. SRB_ExecSCSICmd s;
  187155. prepare (s);
  187156. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187157. s.SRB_BufLen = sizeof (qdata);
  187158. s.SRB_BufPointer = (BYTE*)qdata;
  187159. s.SRB_CDBLen = 12;
  187160. s.CDBByte[0] = 0x42;
  187161. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187162. s.CDBByte[2] = 64;
  187163. s.CDBByte[3] = 1; // get current position
  187164. s.CDBByte[7] = 0;
  187165. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187166. perform (s);
  187167. if (s.SRB_Status == SS_COMP)
  187168. return qdata[7];
  187169. return 0;
  187170. }
  187171. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187172. {
  187173. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187174. SRB_ExecSCSICmd s;
  187175. zerostruct (s);
  187176. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187177. s.SRB_HaID = info.ha;
  187178. s.SRB_Target = info.tgt;
  187179. s.SRB_Lun = info.lun;
  187180. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187181. s.SRB_BufLen = 0x324;
  187182. s.SRB_BufPointer = (BYTE*)lpToc;
  187183. s.SRB_SenseLen = 0x0E;
  187184. s.SRB_CDBLen = 0x0A;
  187185. s.SRB_PostProc = (void*)event;
  187186. s.CDBByte[0] = 0x43;
  187187. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187188. s.CDBByte[7] = 0x03;
  187189. s.CDBByte[8] = 0x24;
  187190. ResetEvent (event);
  187191. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187192. : fSendASPI32Command ((LPSRB)&s);
  187193. if (status == SS_PENDING)
  187194. WaitForSingleObject (event, 4000);
  187195. CloseHandle (event);
  187196. return (s.SRB_Status == SS_COMP);
  187197. }
  187198. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187199. CDReadBuffer* const overlapBuffer)
  187200. {
  187201. if (controller == 0)
  187202. {
  187203. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187204. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187205. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187206. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187207. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187208. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187209. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187210. }
  187211. buffer->index = 0;
  187212. if ((controller != 0)
  187213. && controller->readAudio (buffer, overlapBuffer))
  187214. {
  187215. if (buffer->wantsIndex)
  187216. buffer->index = controller->getLastIndex();
  187217. return true;
  187218. }
  187219. return false;
  187220. }
  187221. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187222. {
  187223. if (shouldBeOpen)
  187224. {
  187225. if (controller != 0)
  187226. {
  187227. controller->shutDown();
  187228. delete controller;
  187229. controller = 0;
  187230. }
  187231. if (scsiHandle != 0)
  187232. {
  187233. CloseHandle (scsiHandle);
  187234. scsiHandle = 0;
  187235. }
  187236. }
  187237. SRB_ExecSCSICmd s;
  187238. zerostruct (s);
  187239. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187240. s.SRB_HaID = info.ha;
  187241. s.SRB_Target = info.tgt;
  187242. s.SRB_Lun = info.lun;
  187243. s.SRB_SenseLen = SENSE_LEN;
  187244. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187245. s.SRB_BufLen = 0;
  187246. s.SRB_BufPointer = 0;
  187247. s.SRB_CDBLen = 12;
  187248. s.CDBByte[0] = 0x1b;
  187249. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187250. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187251. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187252. s.SRB_PostProc = (void*)event;
  187253. ResetEvent (event);
  187254. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187255. : fSendASPI32Command ((LPSRB)&s);
  187256. if (status == SS_PENDING)
  187257. WaitForSingleObject (event, 4000);
  187258. CloseHandle (event);
  187259. }
  187260. bool CDDeviceHandle::testController (const int type,
  187261. CDController* const newController,
  187262. CDReadBuffer* const rb)
  187263. {
  187264. controller = newController;
  187265. readType = (BYTE)type;
  187266. controller->deviceInfo = this;
  187267. controller->framesToCheck = 1;
  187268. controller->framesOverlap = 3;
  187269. bool passed = false;
  187270. memset (rb->buffer, 0xcd, rb->bufferSize);
  187271. if (controller->read (rb))
  187272. {
  187273. passed = true;
  187274. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187275. int wrong = 0;
  187276. for (int i = rb->dataLength / 4; --i >= 0;)
  187277. {
  187278. if (*p++ == (int) 0xcdcdcdcd)
  187279. {
  187280. if (++wrong == 4)
  187281. {
  187282. passed = false;
  187283. break;
  187284. }
  187285. }
  187286. else
  187287. {
  187288. wrong = 0;
  187289. }
  187290. }
  187291. }
  187292. if (! passed)
  187293. {
  187294. controller->shutDown();
  187295. delete controller;
  187296. controller = 0;
  187297. }
  187298. return passed;
  187299. }
  187300. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187301. {
  187302. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187303. const int bufSize = 128;
  187304. BYTE buffer[bufSize];
  187305. zeromem (buffer, bufSize);
  187306. SRB_ExecSCSICmd s;
  187307. zerostruct (s);
  187308. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187309. s.SRB_HaID = ha;
  187310. s.SRB_Target = tgt;
  187311. s.SRB_Lun = lun;
  187312. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187313. s.SRB_BufLen = bufSize;
  187314. s.SRB_BufPointer = buffer;
  187315. s.SRB_SenseLen = SENSE_LEN;
  187316. s.SRB_CDBLen = 6;
  187317. s.SRB_PostProc = (void*)event;
  187318. s.CDBByte[0] = SCSI_INQUIRY;
  187319. s.CDBByte[4] = 100;
  187320. ResetEvent (event);
  187321. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187322. WaitForSingleObject (event, 4000);
  187323. CloseHandle (event);
  187324. if (s.SRB_Status == SS_COMP)
  187325. {
  187326. memcpy (dev->vendor, &buffer[8], 8);
  187327. memcpy (dev->productId, &buffer[16], 16);
  187328. memcpy (dev->rev, &buffer[32], 4);
  187329. memcpy (dev->vendorSpec, &buffer[36], 20);
  187330. }
  187331. }
  187332. static int FindCDDevices (CDDeviceInfo* const list,
  187333. int maxItems)
  187334. {
  187335. int count = 0;
  187336. if (usingScsi)
  187337. {
  187338. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187339. {
  187340. TCHAR drivePath[8];
  187341. drivePath[0] = driveLetter;
  187342. drivePath[1] = ':';
  187343. drivePath[2] = '\\';
  187344. drivePath[3] = 0;
  187345. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187346. {
  187347. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187348. if (h != INVALID_HANDLE_VALUE)
  187349. {
  187350. BYTE buffer[100], passThroughStruct[1024];
  187351. zeromem (buffer, sizeof (buffer));
  187352. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187353. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187354. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187355. p->spt.CdbLength = 6;
  187356. p->spt.SenseInfoLength = 24;
  187357. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187358. p->spt.DataTransferLength = 100;
  187359. p->spt.TimeOutValue = 2;
  187360. p->spt.DataBuffer = buffer;
  187361. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187362. p->spt.Cdb[0] = 0x12;
  187363. p->spt.Cdb[4] = 100;
  187364. DWORD bytesReturned = 0;
  187365. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187366. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187367. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187368. &bytesReturned, 0) != 0)
  187369. {
  187370. zeromem (&list[count], sizeof (CDDeviceInfo));
  187371. list[count].scsiDriveLetter = driveLetter;
  187372. memcpy (list[count].vendor, &buffer[8], 8);
  187373. memcpy (list[count].productId, &buffer[16], 16);
  187374. memcpy (list[count].rev, &buffer[32], 4);
  187375. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187376. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187377. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187378. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187379. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187380. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187381. &bytesReturned, 0) != 0)
  187382. {
  187383. list[count].ha = scsiAddr->PortNumber;
  187384. list[count].tgt = scsiAddr->TargetId;
  187385. list[count].lun = scsiAddr->Lun;
  187386. ++count;
  187387. }
  187388. }
  187389. CloseHandle (h);
  187390. }
  187391. }
  187392. }
  187393. }
  187394. else
  187395. {
  187396. const DWORD d = fGetASPI32SupportInfo();
  187397. BYTE status = HIBYTE (LOWORD (d));
  187398. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187399. return 0;
  187400. const int numAdapters = LOBYTE (LOWORD (d));
  187401. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187402. {
  187403. SRB_HAInquiry s;
  187404. zerostruct (s);
  187405. s.SRB_Cmd = SC_HA_INQUIRY;
  187406. s.SRB_HaID = ha;
  187407. fSendASPI32Command ((LPSRB)&s);
  187408. if (s.SRB_Status == SS_COMP)
  187409. {
  187410. maxItems = (int)s.HA_Unique[3];
  187411. if (maxItems == 0)
  187412. maxItems = 8;
  187413. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187414. {
  187415. for (BYTE lun = 0; lun < 8; ++lun)
  187416. {
  187417. SRB_GDEVBlock sb;
  187418. zerostruct (sb);
  187419. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187420. sb.SRB_HaID = ha;
  187421. sb.SRB_Target = tgt;
  187422. sb.SRB_Lun = lun;
  187423. fSendASPI32Command ((LPSRB) &sb);
  187424. if (sb.SRB_Status == SS_COMP
  187425. && sb.SRB_DeviceType == DTYPE_CROM)
  187426. {
  187427. zeromem (&list[count], sizeof (CDDeviceInfo));
  187428. list[count].ha = ha;
  187429. list[count].tgt = tgt;
  187430. list[count].lun = lun;
  187431. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187432. ++count;
  187433. }
  187434. }
  187435. }
  187436. }
  187437. }
  187438. }
  187439. return count;
  187440. }
  187441. static int ripperUsers = 0;
  187442. static bool initialisedOk = false;
  187443. class DeinitialiseTimer : private Timer,
  187444. private DeletedAtShutdown
  187445. {
  187446. DeinitialiseTimer (const DeinitialiseTimer&);
  187447. const DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187448. public:
  187449. DeinitialiseTimer()
  187450. {
  187451. startTimer (4000);
  187452. }
  187453. ~DeinitialiseTimer()
  187454. {
  187455. if (--ripperUsers == 0)
  187456. DeinitialiseCDRipper();
  187457. }
  187458. void timerCallback()
  187459. {
  187460. delete this;
  187461. }
  187462. juce_UseDebuggingNewOperator
  187463. };
  187464. static void incUserCount()
  187465. {
  187466. if (ripperUsers++ == 0)
  187467. initialisedOk = InitialiseCDRipper();
  187468. }
  187469. static void decUserCount()
  187470. {
  187471. new DeinitialiseTimer();
  187472. }
  187473. struct CDDeviceWrapper
  187474. {
  187475. CDDeviceHandle* cdH;
  187476. CDReadBuffer* overlapBuffer;
  187477. bool jitter;
  187478. };
  187479. static int getAddressOf (const TOCTRACK* const t)
  187480. {
  187481. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187482. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187483. }
  187484. static int getMSFAddressOf (const TOCTRACK* const t)
  187485. {
  187486. return 60 * t->addr[1] + t->addr[2];
  187487. }
  187488. static const int samplesPerFrame = 44100 / 75;
  187489. static const int bytesPerFrame = samplesPerFrame * 4;
  187490. const StringArray AudioCDReader::getAvailableCDNames()
  187491. {
  187492. StringArray results;
  187493. incUserCount();
  187494. if (initialisedOk)
  187495. {
  187496. CDDeviceInfo list[8];
  187497. const int num = FindCDDevices (list, 8);
  187498. decUserCount();
  187499. for (int i = 0; i < num; ++i)
  187500. {
  187501. String s;
  187502. if (list[i].scsiDriveLetter > 0)
  187503. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187504. s << String (list[i].vendor).trim()
  187505. << T(" ") << String (list[i].productId).trim()
  187506. << T(" ") << String (list[i].rev).trim();
  187507. results.add (s);
  187508. }
  187509. }
  187510. return results;
  187511. }
  187512. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187513. {
  187514. SRB_GDEVBlock s;
  187515. zerostruct (s);
  187516. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187517. s.SRB_HaID = device->ha;
  187518. s.SRB_Target = device->tgt;
  187519. s.SRB_Lun = device->lun;
  187520. if (usingScsi)
  187521. {
  187522. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187523. if (h != INVALID_HANDLE_VALUE)
  187524. {
  187525. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187526. cdh->scsiHandle = h;
  187527. return cdh;
  187528. }
  187529. }
  187530. else
  187531. {
  187532. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187533. && s.SRB_DeviceType == DTYPE_CROM)
  187534. {
  187535. return new CDDeviceHandle (device);
  187536. }
  187537. }
  187538. return 0;
  187539. }
  187540. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187541. {
  187542. incUserCount();
  187543. if (initialisedOk)
  187544. {
  187545. CDDeviceInfo list[8];
  187546. const int num = FindCDDevices (list, 8);
  187547. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187548. {
  187549. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187550. if (handle != 0)
  187551. {
  187552. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187553. d->cdH = handle;
  187554. d->overlapBuffer = new CDReadBuffer(3);
  187555. return new AudioCDReader (d);
  187556. }
  187557. }
  187558. }
  187559. decUserCount();
  187560. return 0;
  187561. }
  187562. AudioCDReader::AudioCDReader (void* handle_)
  187563. : AudioFormatReader (0, T("CD Audio")),
  187564. handle (handle_),
  187565. indexingEnabled (false),
  187566. lastIndex (0),
  187567. firstFrameInBuffer (0),
  187568. samplesInBuffer (0)
  187569. {
  187570. jassert (handle_ != 0);
  187571. refreshTrackLengths();
  187572. sampleRate = 44100.0;
  187573. bitsPerSample = 16;
  187574. lengthInSamples = getPositionOfTrackStart (numTracks);
  187575. numChannels = 2;
  187576. usesFloatingPointData = false;
  187577. buffer.setSize (4 * bytesPerFrame, true);
  187578. }
  187579. AudioCDReader::~AudioCDReader()
  187580. {
  187581. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187582. delete device->cdH;
  187583. delete device->overlapBuffer;
  187584. delete device;
  187585. decUserCount();
  187586. }
  187587. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187588. int64 startSampleInFile, int numSamples)
  187589. {
  187590. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187591. bool ok = true;
  187592. while (numSamples > 0)
  187593. {
  187594. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187595. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187596. if (startSampleInFile >= bufferStartSample
  187597. && startSampleInFile < bufferEndSample)
  187598. {
  187599. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187600. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187601. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187602. const short* src = (const short*) buffer.getData();
  187603. src += 2 * (startSampleInFile - bufferStartSample);
  187604. for (int i = 0; i < toDo; ++i)
  187605. {
  187606. l[i] = src [i << 1] << 16;
  187607. if (r != 0)
  187608. r[i] = src [(i << 1) + 1] << 16;
  187609. }
  187610. startOffsetInDestBuffer += toDo;
  187611. startSampleInFile += toDo;
  187612. numSamples -= toDo;
  187613. }
  187614. else
  187615. {
  187616. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187617. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187618. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187619. {
  187620. device->overlapBuffer->dataLength = 0;
  187621. device->overlapBuffer->startFrame = 0;
  187622. device->overlapBuffer->numFrames = 0;
  187623. device->jitter = false;
  187624. }
  187625. firstFrameInBuffer = frameNeeded;
  187626. lastIndex = 0;
  187627. CDReadBuffer readBuffer (framesInBuffer + 4);
  187628. readBuffer.wantsIndex = indexingEnabled;
  187629. int i;
  187630. for (i = 5; --i >= 0;)
  187631. {
  187632. readBuffer.startFrame = frameNeeded;
  187633. readBuffer.numFrames = framesInBuffer;
  187634. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187635. break;
  187636. else
  187637. device->overlapBuffer->dataLength = 0;
  187638. }
  187639. if (i >= 0)
  187640. {
  187641. memcpy ((char*) buffer.getData(),
  187642. readBuffer.buffer + readBuffer.dataStartOffset,
  187643. readBuffer.dataLength);
  187644. samplesInBuffer = readBuffer.dataLength >> 2;
  187645. lastIndex = readBuffer.index;
  187646. }
  187647. else
  187648. {
  187649. int* l = destSamples[0] + startOffsetInDestBuffer;
  187650. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187651. while (--numSamples >= 0)
  187652. {
  187653. *l++ = 0;
  187654. if (r != 0)
  187655. *r++ = 0;
  187656. }
  187657. // sometimes the read fails for just the very last couple of blocks, so
  187658. // we'll ignore and errors in the last half-second of the disk..
  187659. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187660. break;
  187661. }
  187662. }
  187663. }
  187664. return ok;
  187665. }
  187666. bool AudioCDReader::isCDStillPresent() const
  187667. {
  187668. TOC toc;
  187669. zerostruct (toc);
  187670. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187671. }
  187672. int AudioCDReader::getNumTracks() const
  187673. {
  187674. return numTracks;
  187675. }
  187676. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187677. {
  187678. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187679. : 0;
  187680. }
  187681. void AudioCDReader::refreshTrackLengths()
  187682. {
  187683. zeromem (trackStarts, sizeof (trackStarts));
  187684. zeromem (audioTracks, sizeof (audioTracks));
  187685. TOC toc;
  187686. zerostruct (toc);
  187687. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187688. {
  187689. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187690. for (int i = 0; i <= numTracks; ++i)
  187691. {
  187692. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187693. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187694. }
  187695. }
  187696. else
  187697. {
  187698. numTracks = 0;
  187699. }
  187700. }
  187701. bool AudioCDReader::isTrackAudio (int trackNum) const
  187702. {
  187703. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187704. : false;
  187705. }
  187706. void AudioCDReader::enableIndexScanning (bool b)
  187707. {
  187708. indexingEnabled = b;
  187709. }
  187710. int AudioCDReader::getLastIndex() const
  187711. {
  187712. return lastIndex;
  187713. }
  187714. const int framesPerIndexRead = 4;
  187715. int AudioCDReader::getIndexAt (int samplePos)
  187716. {
  187717. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187718. const int frameNeeded = samplePos / samplesPerFrame;
  187719. device->overlapBuffer->dataLength = 0;
  187720. device->overlapBuffer->startFrame = 0;
  187721. device->overlapBuffer->numFrames = 0;
  187722. device->jitter = false;
  187723. firstFrameInBuffer = 0;
  187724. lastIndex = 0;
  187725. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187726. readBuffer.wantsIndex = true;
  187727. int i;
  187728. for (i = 5; --i >= 0;)
  187729. {
  187730. readBuffer.startFrame = frameNeeded;
  187731. readBuffer.numFrames = framesPerIndexRead;
  187732. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187733. break;
  187734. }
  187735. if (i >= 0)
  187736. return readBuffer.index;
  187737. return -1;
  187738. }
  187739. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187740. {
  187741. Array <int> indexes;
  187742. const int trackStart = getPositionOfTrackStart (trackNumber);
  187743. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187744. bool needToScan = true;
  187745. if (trackEnd - trackStart > 20 * 44100)
  187746. {
  187747. // check the end of the track for indexes before scanning the whole thing
  187748. needToScan = false;
  187749. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187750. bool seenAnIndex = false;
  187751. while (pos <= trackEnd - samplesPerFrame)
  187752. {
  187753. const int index = getIndexAt (pos);
  187754. if (index == 0)
  187755. {
  187756. // lead-out, so skip back a bit if we've not found any indexes yet..
  187757. if (seenAnIndex)
  187758. break;
  187759. pos -= 44100 * 5;
  187760. if (pos < trackStart)
  187761. break;
  187762. }
  187763. else
  187764. {
  187765. if (index > 0)
  187766. seenAnIndex = true;
  187767. if (index > 1)
  187768. {
  187769. needToScan = true;
  187770. break;
  187771. }
  187772. pos += samplesPerFrame * framesPerIndexRead;
  187773. }
  187774. }
  187775. }
  187776. if (needToScan)
  187777. {
  187778. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187779. int pos = trackStart;
  187780. int last = -1;
  187781. while (pos < trackEnd - samplesPerFrame * 10)
  187782. {
  187783. const int frameNeeded = pos / samplesPerFrame;
  187784. device->overlapBuffer->dataLength = 0;
  187785. device->overlapBuffer->startFrame = 0;
  187786. device->overlapBuffer->numFrames = 0;
  187787. device->jitter = false;
  187788. firstFrameInBuffer = 0;
  187789. CDReadBuffer readBuffer (4);
  187790. readBuffer.wantsIndex = true;
  187791. int i;
  187792. for (i = 5; --i >= 0;)
  187793. {
  187794. readBuffer.startFrame = frameNeeded;
  187795. readBuffer.numFrames = framesPerIndexRead;
  187796. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187797. break;
  187798. }
  187799. if (i < 0)
  187800. break;
  187801. if (readBuffer.index > last && readBuffer.index > 1)
  187802. {
  187803. last = readBuffer.index;
  187804. indexes.add (pos);
  187805. }
  187806. pos += samplesPerFrame * framesPerIndexRead;
  187807. }
  187808. indexes.removeValue (trackStart);
  187809. }
  187810. return indexes;
  187811. }
  187812. int AudioCDReader::getCDDBId()
  187813. {
  187814. refreshTrackLengths();
  187815. if (numTracks > 0)
  187816. {
  187817. TOC toc;
  187818. zerostruct (toc);
  187819. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187820. {
  187821. int n = 0;
  187822. for (int i = numTracks; --i >= 0;)
  187823. {
  187824. int j = getMSFAddressOf (&toc.tracks[i]);
  187825. while (j > 0)
  187826. {
  187827. n += (j % 10);
  187828. j /= 10;
  187829. }
  187830. }
  187831. if (n != 0)
  187832. {
  187833. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187834. - getMSFAddressOf (&toc.tracks[0]);
  187835. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187836. }
  187837. }
  187838. }
  187839. return 0;
  187840. }
  187841. void AudioCDReader::ejectDisk()
  187842. {
  187843. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187844. }
  187845. #endif
  187846. #if JUCE_USE_CDBURNER
  187847. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187848. {
  187849. CoInitialize (0);
  187850. IDiscMaster* dm;
  187851. IDiscRecorder* result = 0;
  187852. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187853. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187854. IID_IDiscMaster,
  187855. (void**) &dm)))
  187856. {
  187857. if (SUCCEEDED (dm->Open()))
  187858. {
  187859. IEnumDiscRecorders* drEnum = 0;
  187860. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187861. {
  187862. IDiscRecorder* dr = 0;
  187863. DWORD dummy;
  187864. int index = 0;
  187865. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187866. {
  187867. if (indexToOpen == index)
  187868. {
  187869. result = dr;
  187870. break;
  187871. }
  187872. else if (list != 0)
  187873. {
  187874. BSTR path;
  187875. if (SUCCEEDED (dr->GetPath (&path)))
  187876. list->add ((const WCHAR*) path);
  187877. }
  187878. ++index;
  187879. dr->Release();
  187880. }
  187881. drEnum->Release();
  187882. }
  187883. if (master == 0)
  187884. dm->Close();
  187885. }
  187886. if (master != 0)
  187887. *master = dm;
  187888. else
  187889. dm->Release();
  187890. }
  187891. return result;
  187892. }
  187893. const StringArray AudioCDBurner::findAvailableDevices()
  187894. {
  187895. StringArray devs;
  187896. enumCDBurners (&devs, -1, 0);
  187897. return devs;
  187898. }
  187899. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187900. {
  187901. AudioCDBurner* b = new AudioCDBurner (deviceIndex);
  187902. if (b->internal == 0)
  187903. deleteAndZero (b);
  187904. return b;
  187905. }
  187906. class CDBurnerInfo : public IDiscMasterProgressEvents
  187907. {
  187908. public:
  187909. CDBurnerInfo()
  187910. : refCount (1),
  187911. progress (0),
  187912. shouldCancel (false),
  187913. listener (0)
  187914. {
  187915. }
  187916. ~CDBurnerInfo()
  187917. {
  187918. }
  187919. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187920. {
  187921. if (result == 0)
  187922. return E_POINTER;
  187923. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187924. {
  187925. AddRef();
  187926. *result = this;
  187927. return S_OK;
  187928. }
  187929. *result = 0;
  187930. return E_NOINTERFACE;
  187931. }
  187932. ULONG __stdcall AddRef() { return ++refCount; }
  187933. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187934. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187935. {
  187936. if (listener != 0 && ! shouldCancel)
  187937. shouldCancel = listener->audioCDBurnProgress (progress);
  187938. *pbCancel = shouldCancel;
  187939. return S_OK;
  187940. }
  187941. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187942. {
  187943. progress = nCompleted / (float) nTotal;
  187944. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187945. return E_NOTIMPL;
  187946. }
  187947. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187948. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187949. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187950. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187951. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187952. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187953. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187954. IDiscMaster* discMaster;
  187955. IDiscRecorder* discRecorder;
  187956. IRedbookDiscMaster* redbook;
  187957. AudioCDBurner::BurnProgressListener* listener;
  187958. float progress;
  187959. bool shouldCancel;
  187960. private:
  187961. int refCount;
  187962. };
  187963. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187964. : internal (0)
  187965. {
  187966. IDiscMaster* discMaster;
  187967. IDiscRecorder* dr = enumCDBurners (0, deviceIndex, &discMaster);
  187968. if (dr != 0)
  187969. {
  187970. IRedbookDiscMaster* redbook;
  187971. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187972. hr = discMaster->SetActiveDiscRecorder (dr);
  187973. CDBurnerInfo* const info = new CDBurnerInfo();
  187974. internal = info;
  187975. info->discMaster = discMaster;
  187976. info->discRecorder = dr;
  187977. info->redbook = redbook;
  187978. }
  187979. }
  187980. AudioCDBurner::~AudioCDBurner()
  187981. {
  187982. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  187983. if (info != 0)
  187984. {
  187985. info->discRecorder->Close();
  187986. info->redbook->Release();
  187987. info->discRecorder->Release();
  187988. info->discMaster->Release();
  187989. info->Release();
  187990. }
  187991. }
  187992. bool AudioCDBurner::isDiskPresent() const
  187993. {
  187994. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  187995. HRESULT hr = info->discRecorder->OpenExclusive();
  187996. long type, flags;
  187997. hr = info->discRecorder->QueryMediaType (&type, &flags);
  187998. info->discRecorder->Close();
  187999. return hr == S_OK && type != 0 && (flags & MEDIA_WRITABLE) != 0;
  188000. }
  188001. int AudioCDBurner::getNumAvailableAudioBlocks() const
  188002. {
  188003. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188004. long blocksFree = 0;
  188005. info->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  188006. return blocksFree;
  188007. }
  188008. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener,
  188009. const bool ejectDiscAfterwards,
  188010. const bool performFakeBurnForTesting)
  188011. {
  188012. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188013. info->listener = listener;
  188014. info->progress = 0;
  188015. info->shouldCancel = false;
  188016. UINT_PTR cookie;
  188017. HRESULT hr = info->discMaster->ProgressAdvise (info, &cookie);
  188018. hr = info->discMaster->RecordDisc (performFakeBurnForTesting,
  188019. ejectDiscAfterwards);
  188020. String error;
  188021. if (hr != S_OK)
  188022. {
  188023. const char* e = "Couldn't open or write to the CD device";
  188024. if (hr == IMAPI_E_USERABORT)
  188025. e = "User cancelled the write operation";
  188026. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  188027. e = "No Disk present";
  188028. error = e;
  188029. }
  188030. info->discMaster->ProgressUnadvise (cookie);
  188031. info->listener = 0;
  188032. return error;
  188033. }
  188034. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamples)
  188035. {
  188036. if (source == 0)
  188037. return false;
  188038. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188039. long bytesPerBlock;
  188040. HRESULT hr = info->redbook->GetAudioBlockSize (&bytesPerBlock);
  188041. const int samplesPerBlock = bytesPerBlock / 4;
  188042. bool ok = true;
  188043. hr = info->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  188044. HeapBlock <byte> buffer (bytesPerBlock);
  188045. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  188046. int samplesDone = 0;
  188047. source->prepareToPlay (samplesPerBlock, 44100.0);
  188048. while (ok)
  188049. {
  188050. {
  188051. AudioSourceChannelInfo info;
  188052. info.buffer = &sourceBuffer;
  188053. info.numSamples = samplesPerBlock;
  188054. info.startSample = 0;
  188055. sourceBuffer.clear();
  188056. source->getNextAudioBlock (info);
  188057. }
  188058. zeromem (buffer, bytesPerBlock);
  188059. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  188060. buffer, samplesPerBlock, 4);
  188061. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  188062. buffer + 2, samplesPerBlock, 4);
  188063. hr = info->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  188064. if (hr != S_OK)
  188065. ok = false;
  188066. samplesDone += samplesPerBlock;
  188067. if (samplesDone >= numSamples)
  188068. break;
  188069. }
  188070. hr = info->redbook->CloseAudioTrack();
  188071. delete source;
  188072. return ok && hr == S_OK;
  188073. }
  188074. #endif
  188075. #endif
  188076. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  188077. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  188078. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188079. // compiled on its own).
  188080. #if JUCE_INCLUDED_FILE
  188081. static const int midiBufferSize = 1024 * 10;
  188082. static const int numInHeaders = 32;
  188083. static const int inBufferSize = 256;
  188084. static Array <void*, CriticalSection> activeMidiThreads;
  188085. using ::free;
  188086. class MidiInThread : public Thread
  188087. {
  188088. public:
  188089. MidiInThread (MidiInput* const input_,
  188090. MidiInputCallback* const callback_)
  188091. : Thread ("Juce Midi"),
  188092. hIn (0),
  188093. input (input_),
  188094. callback (callback_),
  188095. isStarted (false),
  188096. startTime (0),
  188097. pendingLength(0)
  188098. {
  188099. for (int i = numInHeaders; --i >= 0;)
  188100. {
  188101. zeromem (&hdr[i], sizeof (MIDIHDR));
  188102. hdr[i].lpData = inData[i];
  188103. hdr[i].dwBufferLength = inBufferSize;
  188104. }
  188105. };
  188106. ~MidiInThread()
  188107. {
  188108. stop();
  188109. if (hIn != 0)
  188110. {
  188111. int count = 5;
  188112. while (--count >= 0)
  188113. {
  188114. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188115. break;
  188116. Sleep (20);
  188117. }
  188118. }
  188119. }
  188120. void handle (const uint32 message, const uint32 timeStamp) throw()
  188121. {
  188122. const int byte = message & 0xff;
  188123. if (byte < 0x80)
  188124. return;
  188125. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188126. const double time = timeStampToTime (timeStamp);
  188127. lock.enter();
  188128. if (pendingLength < midiBufferSize - 12)
  188129. {
  188130. char* const p = pending + pendingLength;
  188131. *(double*) p = time;
  188132. *(uint32*) (p + 8) = numBytes;
  188133. *(uint32*) (p + 12) = message;
  188134. pendingLength += 12 + numBytes;
  188135. }
  188136. else
  188137. {
  188138. jassertfalse // midi buffer overflow! You might need to increase the size..
  188139. }
  188140. lock.exit();
  188141. notify();
  188142. }
  188143. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188144. {
  188145. const int num = hdr->dwBytesRecorded;
  188146. if (num > 0)
  188147. {
  188148. const double time = timeStampToTime (timeStamp);
  188149. lock.enter();
  188150. if (pendingLength < midiBufferSize - (8 + num))
  188151. {
  188152. char* const p = pending + pendingLength;
  188153. *(double*) p = time;
  188154. *(uint32*) (p + 8) = num;
  188155. memcpy (p + 12, hdr->lpData, num);
  188156. pendingLength += 12 + num;
  188157. }
  188158. else
  188159. {
  188160. jassertfalse // midi buffer overflow! You might need to increase the size..
  188161. }
  188162. lock.exit();
  188163. notify();
  188164. }
  188165. }
  188166. void writeBlock (const int i) throw()
  188167. {
  188168. hdr[i].dwBytesRecorded = 0;
  188169. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188170. jassert (res == MMSYSERR_NOERROR);
  188171. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188172. jassert (res == MMSYSERR_NOERROR);
  188173. }
  188174. void run()
  188175. {
  188176. MemoryBlock pendingCopy (64);
  188177. while (! threadShouldExit())
  188178. {
  188179. for (int i = 0; i < numInHeaders; ++i)
  188180. {
  188181. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188182. {
  188183. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188184. (void) res;
  188185. jassert (res == MMSYSERR_NOERROR);
  188186. writeBlock (i);
  188187. }
  188188. }
  188189. lock.enter();
  188190. int len = pendingLength;
  188191. if (len > 0)
  188192. {
  188193. pendingCopy.ensureSize (len);
  188194. pendingCopy.copyFrom (pending, 0, len);
  188195. pendingLength = 0;
  188196. }
  188197. lock.exit();
  188198. //xxx needs to figure out if blocks are broken up or not
  188199. if (len == 0)
  188200. {
  188201. wait (500);
  188202. }
  188203. else
  188204. {
  188205. const char* p = (const char*) pendingCopy.getData();
  188206. while (len > 0)
  188207. {
  188208. const double time = *(const double*) p;
  188209. const int messageLen = *(const int*) (p + 8);
  188210. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188211. callback->handleIncomingMidiMessage (input, message);
  188212. p += 12 + messageLen;
  188213. len -= 12 + messageLen;
  188214. }
  188215. }
  188216. }
  188217. }
  188218. void start() throw()
  188219. {
  188220. jassert (hIn != 0);
  188221. if (hIn != 0 && ! isStarted)
  188222. {
  188223. stop();
  188224. activeMidiThreads.addIfNotAlreadyThere (this);
  188225. int i;
  188226. for (i = 0; i < numInHeaders; ++i)
  188227. writeBlock (i);
  188228. startTime = Time::getMillisecondCounter();
  188229. MMRESULT res = midiInStart (hIn);
  188230. jassert (res == MMSYSERR_NOERROR);
  188231. if (res == MMSYSERR_NOERROR)
  188232. {
  188233. isStarted = true;
  188234. pendingLength = 0;
  188235. startThread (6);
  188236. }
  188237. }
  188238. }
  188239. void stop() throw()
  188240. {
  188241. if (isStarted)
  188242. {
  188243. stopThread (5000);
  188244. midiInReset (hIn);
  188245. midiInStop (hIn);
  188246. activeMidiThreads.removeValue (this);
  188247. lock.enter();
  188248. lock.exit();
  188249. for (int i = numInHeaders; --i >= 0;)
  188250. {
  188251. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188252. {
  188253. int c = 10;
  188254. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188255. Sleep (20);
  188256. jassert (c >= 0);
  188257. }
  188258. }
  188259. isStarted = false;
  188260. pendingLength = 0;
  188261. }
  188262. }
  188263. juce_UseDebuggingNewOperator
  188264. HMIDIIN hIn;
  188265. private:
  188266. MidiInput* input;
  188267. MidiInputCallback* callback;
  188268. bool isStarted;
  188269. uint32 startTime;
  188270. CriticalSection lock;
  188271. MIDIHDR hdr [numInHeaders];
  188272. char inData [numInHeaders] [inBufferSize];
  188273. int pendingLength;
  188274. char pending [midiBufferSize];
  188275. double timeStampToTime (uint32 timeStamp) throw()
  188276. {
  188277. timeStamp += startTime;
  188278. const uint32 now = Time::getMillisecondCounter();
  188279. if (timeStamp > now)
  188280. {
  188281. if (timeStamp > now + 2)
  188282. --startTime;
  188283. timeStamp = now;
  188284. }
  188285. return 0.001 * timeStamp;
  188286. }
  188287. MidiInThread (const MidiInThread&);
  188288. const MidiInThread& operator= (const MidiInThread&);
  188289. };
  188290. static void CALLBACK midiInCallback (HMIDIIN,
  188291. UINT uMsg,
  188292. DWORD_PTR dwInstance,
  188293. DWORD_PTR midiMessage,
  188294. DWORD_PTR timeStamp)
  188295. {
  188296. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188297. if (thread != 0 && activeMidiThreads.contains (thread))
  188298. {
  188299. if (uMsg == MIM_DATA)
  188300. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188301. else if (uMsg == MIM_LONGDATA)
  188302. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188303. }
  188304. }
  188305. const StringArray MidiInput::getDevices()
  188306. {
  188307. StringArray s;
  188308. const int num = midiInGetNumDevs();
  188309. for (int i = 0; i < num; ++i)
  188310. {
  188311. MIDIINCAPS mc;
  188312. zerostruct (mc);
  188313. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188314. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188315. }
  188316. return s;
  188317. }
  188318. int MidiInput::getDefaultDeviceIndex()
  188319. {
  188320. return 0;
  188321. }
  188322. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188323. {
  188324. if (callback == 0)
  188325. return 0;
  188326. UINT deviceId = MIDI_MAPPER;
  188327. int n = 0;
  188328. String name;
  188329. const int num = midiInGetNumDevs();
  188330. for (int i = 0; i < num; ++i)
  188331. {
  188332. MIDIINCAPS mc;
  188333. zerostruct (mc);
  188334. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188335. {
  188336. if (index == n)
  188337. {
  188338. deviceId = i;
  188339. name = String (mc.szPname, sizeof (mc.szPname));
  188340. break;
  188341. }
  188342. ++n;
  188343. }
  188344. }
  188345. ScopedPointer <MidiInput> in (new MidiInput (name));
  188346. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188347. HMIDIIN h;
  188348. HRESULT err = midiInOpen (&h, deviceId,
  188349. (DWORD_PTR) &midiInCallback,
  188350. (DWORD_PTR) (MidiInThread*) thread,
  188351. CALLBACK_FUNCTION);
  188352. if (err == MMSYSERR_NOERROR)
  188353. {
  188354. thread->hIn = h;
  188355. in->internal = (void*) thread.release();
  188356. return in.release();
  188357. }
  188358. return 0;
  188359. }
  188360. MidiInput::MidiInput (const String& name_)
  188361. : name (name_),
  188362. internal (0)
  188363. {
  188364. }
  188365. MidiInput::~MidiInput()
  188366. {
  188367. if (internal != 0)
  188368. {
  188369. MidiInThread* const thread = (MidiInThread*) internal;
  188370. delete thread;
  188371. }
  188372. }
  188373. void MidiInput::start()
  188374. {
  188375. ((MidiInThread*) internal)->start();
  188376. }
  188377. void MidiInput::stop()
  188378. {
  188379. ((MidiInThread*) internal)->stop();
  188380. }
  188381. struct MidiOutHandle
  188382. {
  188383. int refCount;
  188384. UINT deviceId;
  188385. HMIDIOUT handle;
  188386. juce_UseDebuggingNewOperator
  188387. };
  188388. static Array <MidiOutHandle*> midiOutputHandles;
  188389. const StringArray MidiOutput::getDevices()
  188390. {
  188391. StringArray s;
  188392. const int num = midiOutGetNumDevs();
  188393. for (int i = 0; i < num; ++i)
  188394. {
  188395. MIDIOUTCAPS mc;
  188396. zerostruct (mc);
  188397. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188398. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188399. }
  188400. return s;
  188401. }
  188402. int MidiOutput::getDefaultDeviceIndex()
  188403. {
  188404. const int num = midiOutGetNumDevs();
  188405. int n = 0;
  188406. for (int i = 0; i < num; ++i)
  188407. {
  188408. MIDIOUTCAPS mc;
  188409. zerostruct (mc);
  188410. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188411. {
  188412. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188413. return n;
  188414. ++n;
  188415. }
  188416. }
  188417. return 0;
  188418. }
  188419. MidiOutput* MidiOutput::openDevice (int index)
  188420. {
  188421. UINT deviceId = MIDI_MAPPER;
  188422. const int num = midiOutGetNumDevs();
  188423. int i, n = 0;
  188424. for (i = 0; i < num; ++i)
  188425. {
  188426. MIDIOUTCAPS mc;
  188427. zerostruct (mc);
  188428. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188429. {
  188430. // use the microsoft sw synth as a default - best not to allow deviceId
  188431. // to be MIDI_MAPPER, or else device sharing breaks
  188432. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188433. deviceId = i;
  188434. if (index == n)
  188435. {
  188436. deviceId = i;
  188437. break;
  188438. }
  188439. ++n;
  188440. }
  188441. }
  188442. for (i = midiOutputHandles.size(); --i >= 0;)
  188443. {
  188444. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188445. if (han != 0 && han->deviceId == deviceId)
  188446. {
  188447. han->refCount++;
  188448. MidiOutput* const out = new MidiOutput();
  188449. out->internal = (void*) han;
  188450. return out;
  188451. }
  188452. }
  188453. for (i = 4; --i >= 0;)
  188454. {
  188455. HMIDIOUT h = 0;
  188456. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188457. if (res == MMSYSERR_NOERROR)
  188458. {
  188459. MidiOutHandle* const han = new MidiOutHandle();
  188460. han->deviceId = deviceId;
  188461. han->refCount = 1;
  188462. han->handle = h;
  188463. midiOutputHandles.add (han);
  188464. MidiOutput* const out = new MidiOutput();
  188465. out->internal = (void*) han;
  188466. return out;
  188467. }
  188468. else if (res == MMSYSERR_ALLOCATED)
  188469. {
  188470. Sleep (100);
  188471. }
  188472. else
  188473. {
  188474. break;
  188475. }
  188476. }
  188477. return 0;
  188478. }
  188479. MidiOutput::~MidiOutput()
  188480. {
  188481. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188482. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188483. {
  188484. midiOutClose (h->handle);
  188485. midiOutputHandles.removeValue (h);
  188486. delete h;
  188487. }
  188488. }
  188489. void MidiOutput::reset()
  188490. {
  188491. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188492. midiOutReset (h->handle);
  188493. }
  188494. bool MidiOutput::getVolume (float& leftVol,
  188495. float& rightVol)
  188496. {
  188497. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188498. DWORD n;
  188499. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188500. {
  188501. const unsigned short* const nn = (const unsigned short*) &n;
  188502. rightVol = nn[0] / (float) 0xffff;
  188503. leftVol = nn[1] / (float) 0xffff;
  188504. return true;
  188505. }
  188506. else
  188507. {
  188508. rightVol = leftVol = 1.0f;
  188509. return false;
  188510. }
  188511. }
  188512. void MidiOutput::setVolume (float leftVol,
  188513. float rightVol)
  188514. {
  188515. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188516. DWORD n;
  188517. unsigned short* const nn = (unsigned short*) &n;
  188518. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188519. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188520. midiOutSetVolume (handle->handle, n);
  188521. }
  188522. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188523. {
  188524. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188525. if (message.getRawDataSize() > 3
  188526. || message.isSysEx())
  188527. {
  188528. MIDIHDR h;
  188529. zerostruct (h);
  188530. h.lpData = (char*) message.getRawData();
  188531. h.dwBufferLength = message.getRawDataSize();
  188532. h.dwBytesRecorded = message.getRawDataSize();
  188533. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188534. {
  188535. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188536. if (res == MMSYSERR_NOERROR)
  188537. {
  188538. while ((h.dwFlags & MHDR_DONE) == 0)
  188539. Sleep (1);
  188540. int count = 500; // 1 sec timeout
  188541. while (--count >= 0)
  188542. {
  188543. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188544. if (res == MIDIERR_STILLPLAYING)
  188545. Sleep (2);
  188546. else
  188547. break;
  188548. }
  188549. }
  188550. }
  188551. }
  188552. else
  188553. {
  188554. midiOutShortMsg (handle->handle,
  188555. *(unsigned int*) message.getRawData());
  188556. }
  188557. }
  188558. #endif
  188559. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188560. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188561. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188562. // compiled on its own).
  188563. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188564. #undef WINDOWS
  188565. // #define ASIO_DEBUGGING
  188566. #ifdef ASIO_DEBUGGING
  188567. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188568. #else
  188569. #define log(a) {}
  188570. #endif
  188571. #ifdef ASIO_DEBUGGING
  188572. static void logError (const String& context, long error)
  188573. {
  188574. String err ("unknown error");
  188575. if (error == ASE_NotPresent)
  188576. err = "Not Present";
  188577. else if (error == ASE_HWMalfunction)
  188578. err = "Hardware Malfunction";
  188579. else if (error == ASE_InvalidParameter)
  188580. err = "Invalid Parameter";
  188581. else if (error == ASE_InvalidMode)
  188582. err = "Invalid Mode";
  188583. else if (error == ASE_SPNotAdvancing)
  188584. err = "Sample position not advancing";
  188585. else if (error == ASE_NoClock)
  188586. err = "No Clock";
  188587. else if (error == ASE_NoMemory)
  188588. err = "Out of memory";
  188589. log (T("!!error: ") + context + T(" - ") + err);
  188590. }
  188591. #else
  188592. #define logError(a, b) {}
  188593. #endif
  188594. class ASIOAudioIODevice;
  188595. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188596. static const int maxASIOChannels = 160;
  188597. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188598. private Timer
  188599. {
  188600. public:
  188601. Component ourWindow;
  188602. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188603. const String& optionalDllForDirectLoading_)
  188604. : AudioIODevice (name_, T("ASIO")),
  188605. asioObject (0),
  188606. classId (classId_),
  188607. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188608. currentBitDepth (16),
  188609. currentSampleRate (0),
  188610. isOpen_ (false),
  188611. isStarted (false),
  188612. postOutput (true),
  188613. insideControlPanelModalLoop (false),
  188614. shouldUsePreferredSize (false)
  188615. {
  188616. name = name_;
  188617. ourWindow.addToDesktop (0);
  188618. windowHandle = ourWindow.getWindowHandle();
  188619. jassert (currentASIODev [slotNumber] == 0);
  188620. currentASIODev [slotNumber] = this;
  188621. openDevice();
  188622. }
  188623. ~ASIOAudioIODevice()
  188624. {
  188625. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188626. if (currentASIODev[i] == this)
  188627. currentASIODev[i] = 0;
  188628. close();
  188629. log ("ASIO - exiting");
  188630. removeCurrentDriver();
  188631. }
  188632. void updateSampleRates()
  188633. {
  188634. // find a list of sample rates..
  188635. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188636. sampleRates.clear();
  188637. if (asioObject != 0)
  188638. {
  188639. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188640. {
  188641. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188642. if (err == 0)
  188643. {
  188644. sampleRates.add ((int) possibleSampleRates[index]);
  188645. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188646. }
  188647. else if (err != ASE_NoClock)
  188648. {
  188649. logError (T("CanSampleRate"), err);
  188650. }
  188651. }
  188652. if (sampleRates.size() == 0)
  188653. {
  188654. double cr = 0;
  188655. const long err = asioObject->getSampleRate (&cr);
  188656. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188657. if (err == 0)
  188658. sampleRates.add ((int) cr);
  188659. }
  188660. }
  188661. }
  188662. const StringArray getOutputChannelNames()
  188663. {
  188664. return outputChannelNames;
  188665. }
  188666. const StringArray getInputChannelNames()
  188667. {
  188668. return inputChannelNames;
  188669. }
  188670. int getNumSampleRates()
  188671. {
  188672. return sampleRates.size();
  188673. }
  188674. double getSampleRate (int index)
  188675. {
  188676. return sampleRates [index];
  188677. }
  188678. int getNumBufferSizesAvailable()
  188679. {
  188680. return bufferSizes.size();
  188681. }
  188682. int getBufferSizeSamples (int index)
  188683. {
  188684. return bufferSizes [index];
  188685. }
  188686. int getDefaultBufferSize()
  188687. {
  188688. return preferredSize;
  188689. }
  188690. const String open (const BitArray& inputChannels,
  188691. const BitArray& outputChannels,
  188692. double sr,
  188693. int bufferSizeSamples)
  188694. {
  188695. close();
  188696. currentCallback = 0;
  188697. if (bufferSizeSamples <= 0)
  188698. shouldUsePreferredSize = true;
  188699. if (asioObject == 0 || ! isASIOOpen)
  188700. {
  188701. log ("Warning: device not open");
  188702. const String err (openDevice());
  188703. if (asioObject == 0 || ! isASIOOpen)
  188704. return err;
  188705. }
  188706. isStarted = false;
  188707. bufferIndex = -1;
  188708. long err = 0;
  188709. long newPreferredSize = 0;
  188710. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188711. minSize = 0;
  188712. maxSize = 0;
  188713. newPreferredSize = 0;
  188714. granularity = 0;
  188715. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188716. {
  188717. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188718. shouldUsePreferredSize = true;
  188719. preferredSize = newPreferredSize;
  188720. }
  188721. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188722. // dynamic changes to the buffer size...
  188723. shouldUsePreferredSize = shouldUsePreferredSize
  188724. || getName().containsIgnoreCase (T("Digidesign"));
  188725. if (shouldUsePreferredSize)
  188726. {
  188727. log ("Using preferred size for buffer..");
  188728. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188729. {
  188730. bufferSizeSamples = preferredSize;
  188731. }
  188732. else
  188733. {
  188734. bufferSizeSamples = 1024;
  188735. logError ("GetBufferSize1", err);
  188736. }
  188737. shouldUsePreferredSize = false;
  188738. }
  188739. int sampleRate = roundDoubleToInt (sr);
  188740. currentSampleRate = sampleRate;
  188741. currentBlockSizeSamples = bufferSizeSamples;
  188742. currentChansOut.clear();
  188743. currentChansIn.clear();
  188744. zeromem (inBuffers, sizeof (inBuffers));
  188745. zeromem (outBuffers, sizeof (outBuffers));
  188746. updateSampleRates();
  188747. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188748. sampleRate = sampleRates[0];
  188749. jassert (sampleRate != 0);
  188750. if (sampleRate == 0)
  188751. sampleRate = 44100;
  188752. long numSources = 32;
  188753. ASIOClockSource clocks[32];
  188754. zeromem (clocks, sizeof (clocks));
  188755. asioObject->getClockSources (clocks, &numSources);
  188756. bool isSourceSet = false;
  188757. // careful not to remove this loop because it does more than just logging!
  188758. int i;
  188759. for (i = 0; i < numSources; ++i)
  188760. {
  188761. String s ("clock: ");
  188762. s += clocks[i].name;
  188763. if (clocks[i].isCurrentSource)
  188764. {
  188765. isSourceSet = true;
  188766. s << " (cur)";
  188767. }
  188768. log (s);
  188769. }
  188770. if (numSources > 1 && ! isSourceSet)
  188771. {
  188772. log ("setting clock source");
  188773. asioObject->setClockSource (clocks[0].index);
  188774. Thread::sleep (20);
  188775. }
  188776. else
  188777. {
  188778. if (numSources == 0)
  188779. {
  188780. log ("ASIO - no clock sources!");
  188781. }
  188782. }
  188783. double cr = 0;
  188784. err = asioObject->getSampleRate (&cr);
  188785. if (err == 0)
  188786. {
  188787. currentSampleRate = cr;
  188788. }
  188789. else
  188790. {
  188791. logError ("GetSampleRate", err);
  188792. currentSampleRate = 0;
  188793. }
  188794. error = String::empty;
  188795. needToReset = false;
  188796. isReSync = false;
  188797. err = 0;
  188798. bool buffersCreated = false;
  188799. if (currentSampleRate != sampleRate)
  188800. {
  188801. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188802. err = asioObject->setSampleRate (sampleRate);
  188803. if (err == ASE_NoClock && numSources > 0)
  188804. {
  188805. log ("trying to set a clock source..");
  188806. Thread::sleep (10);
  188807. err = asioObject->setClockSource (clocks[0].index);
  188808. if (err != 0)
  188809. {
  188810. logError ("SetClock", err);
  188811. }
  188812. Thread::sleep (10);
  188813. err = asioObject->setSampleRate (sampleRate);
  188814. }
  188815. }
  188816. if (err == 0)
  188817. {
  188818. currentSampleRate = sampleRate;
  188819. if (needToReset)
  188820. {
  188821. if (isReSync)
  188822. {
  188823. log ("Resync request");
  188824. }
  188825. log ("! Resetting ASIO after sample rate change");
  188826. removeCurrentDriver();
  188827. loadDriver();
  188828. const String error (initDriver());
  188829. if (error.isNotEmpty())
  188830. {
  188831. log (T("ASIOInit: ") + error);
  188832. }
  188833. needToReset = false;
  188834. isReSync = false;
  188835. }
  188836. numActiveInputChans = 0;
  188837. numActiveOutputChans = 0;
  188838. ASIOBufferInfo* info = bufferInfos;
  188839. int i;
  188840. for (i = 0; i < totalNumInputChans; ++i)
  188841. {
  188842. if (inputChannels[i])
  188843. {
  188844. currentChansIn.setBit (i);
  188845. info->isInput = 1;
  188846. info->channelNum = i;
  188847. info->buffers[0] = info->buffers[1] = 0;
  188848. ++info;
  188849. ++numActiveInputChans;
  188850. }
  188851. }
  188852. for (i = 0; i < totalNumOutputChans; ++i)
  188853. {
  188854. if (outputChannels[i])
  188855. {
  188856. currentChansOut.setBit (i);
  188857. info->isInput = 0;
  188858. info->channelNum = i;
  188859. info->buffers[0] = info->buffers[1] = 0;
  188860. ++info;
  188861. ++numActiveOutputChans;
  188862. }
  188863. }
  188864. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188865. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188866. if (currentASIODev[0] == this)
  188867. {
  188868. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188869. callbacks.asioMessage = &asioMessagesCallback0;
  188870. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188871. }
  188872. else if (currentASIODev[1] == this)
  188873. {
  188874. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188875. callbacks.asioMessage = &asioMessagesCallback1;
  188876. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188877. }
  188878. else if (currentASIODev[2] == this)
  188879. {
  188880. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188881. callbacks.asioMessage = &asioMessagesCallback2;
  188882. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188883. }
  188884. else
  188885. {
  188886. jassertfalse
  188887. }
  188888. log ("disposing buffers");
  188889. err = asioObject->disposeBuffers();
  188890. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188891. err = asioObject->createBuffers (bufferInfos,
  188892. totalBuffers,
  188893. currentBlockSizeSamples,
  188894. &callbacks);
  188895. if (err != 0)
  188896. {
  188897. currentBlockSizeSamples = preferredSize;
  188898. logError ("create buffers 2", err);
  188899. asioObject->disposeBuffers();
  188900. err = asioObject->createBuffers (bufferInfos,
  188901. totalBuffers,
  188902. currentBlockSizeSamples,
  188903. &callbacks);
  188904. }
  188905. if (err == 0)
  188906. {
  188907. buffersCreated = true;
  188908. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188909. int n = 0;
  188910. Array <int> types;
  188911. currentBitDepth = 16;
  188912. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188913. {
  188914. if (inputChannels[i])
  188915. {
  188916. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188917. ASIOChannelInfo channelInfo;
  188918. zerostruct (channelInfo);
  188919. channelInfo.channel = i;
  188920. channelInfo.isInput = 1;
  188921. asioObject->getChannelInfo (&channelInfo);
  188922. types.addIfNotAlreadyThere (channelInfo.type);
  188923. typeToFormatParameters (channelInfo.type,
  188924. inputChannelBitDepths[n],
  188925. inputChannelBytesPerSample[n],
  188926. inputChannelIsFloat[n],
  188927. inputChannelLittleEndian[n]);
  188928. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188929. ++n;
  188930. }
  188931. }
  188932. jassert (numActiveInputChans == n);
  188933. n = 0;
  188934. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188935. {
  188936. if (outputChannels[i])
  188937. {
  188938. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188939. ASIOChannelInfo channelInfo;
  188940. zerostruct (channelInfo);
  188941. channelInfo.channel = i;
  188942. channelInfo.isInput = 0;
  188943. asioObject->getChannelInfo (&channelInfo);
  188944. types.addIfNotAlreadyThere (channelInfo.type);
  188945. typeToFormatParameters (channelInfo.type,
  188946. outputChannelBitDepths[n],
  188947. outputChannelBytesPerSample[n],
  188948. outputChannelIsFloat[n],
  188949. outputChannelLittleEndian[n]);
  188950. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188951. ++n;
  188952. }
  188953. }
  188954. jassert (numActiveOutputChans == n);
  188955. for (i = types.size(); --i >= 0;)
  188956. {
  188957. log (T("channel format: ") + String (types[i]));
  188958. }
  188959. jassert (n <= totalBuffers);
  188960. for (i = 0; i < numActiveOutputChans; ++i)
  188961. {
  188962. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188963. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188964. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188965. {
  188966. log ("!! Null buffers");
  188967. }
  188968. else
  188969. {
  188970. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188971. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188972. }
  188973. }
  188974. inputLatency = outputLatency = 0;
  188975. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188976. {
  188977. log ("ASIO - no latencies");
  188978. }
  188979. else
  188980. {
  188981. log (T("ASIO latencies: ")
  188982. + String ((int) outputLatency)
  188983. + T(", ")
  188984. + String ((int) inputLatency));
  188985. }
  188986. isOpen_ = true;
  188987. log ("starting ASIO");
  188988. calledback = false;
  188989. err = asioObject->start();
  188990. if (err != 0)
  188991. {
  188992. isOpen_ = false;
  188993. log ("ASIO - stop on failure");
  188994. Thread::sleep (10);
  188995. asioObject->stop();
  188996. error = "Can't start device";
  188997. Thread::sleep (10);
  188998. }
  188999. else
  189000. {
  189001. int count = 300;
  189002. while (--count > 0 && ! calledback)
  189003. Thread::sleep (10);
  189004. isStarted = true;
  189005. if (! calledback)
  189006. {
  189007. error = "Device didn't start correctly";
  189008. log ("ASIO didn't callback - stopping..");
  189009. asioObject->stop();
  189010. }
  189011. }
  189012. }
  189013. else
  189014. {
  189015. error = "Can't create i/o buffers";
  189016. }
  189017. }
  189018. else
  189019. {
  189020. error = "Can't set sample rate: ";
  189021. error << sampleRate;
  189022. }
  189023. if (error.isNotEmpty())
  189024. {
  189025. logError (error, err);
  189026. if (asioObject != 0 && buffersCreated)
  189027. asioObject->disposeBuffers();
  189028. Thread::sleep (20);
  189029. isStarted = false;
  189030. isOpen_ = false;
  189031. close();
  189032. }
  189033. needToReset = false;
  189034. isReSync = false;
  189035. return error;
  189036. }
  189037. void close()
  189038. {
  189039. error = String::empty;
  189040. stopTimer();
  189041. stop();
  189042. if (isASIOOpen && isOpen_)
  189043. {
  189044. const ScopedLock sl (callbackLock);
  189045. isOpen_ = false;
  189046. isStarted = false;
  189047. needToReset = false;
  189048. isReSync = false;
  189049. log ("ASIO - stopping");
  189050. if (asioObject != 0)
  189051. {
  189052. Thread::sleep (20);
  189053. asioObject->stop();
  189054. Thread::sleep (10);
  189055. asioObject->disposeBuffers();
  189056. }
  189057. Thread::sleep (10);
  189058. }
  189059. }
  189060. bool isOpen()
  189061. {
  189062. return isOpen_ || insideControlPanelModalLoop;
  189063. }
  189064. int getCurrentBufferSizeSamples()
  189065. {
  189066. return currentBlockSizeSamples;
  189067. }
  189068. double getCurrentSampleRate()
  189069. {
  189070. return currentSampleRate;
  189071. }
  189072. const BitArray getActiveOutputChannels() const
  189073. {
  189074. return currentChansOut;
  189075. }
  189076. const BitArray getActiveInputChannels() const
  189077. {
  189078. return currentChansIn;
  189079. }
  189080. int getCurrentBitDepth()
  189081. {
  189082. return currentBitDepth;
  189083. }
  189084. int getOutputLatencyInSamples()
  189085. {
  189086. return outputLatency + currentBlockSizeSamples / 4;
  189087. }
  189088. int getInputLatencyInSamples()
  189089. {
  189090. return inputLatency + currentBlockSizeSamples / 4;
  189091. }
  189092. void start (AudioIODeviceCallback* callback)
  189093. {
  189094. if (callback != 0)
  189095. {
  189096. callback->audioDeviceAboutToStart (this);
  189097. const ScopedLock sl (callbackLock);
  189098. currentCallback = callback;
  189099. }
  189100. }
  189101. void stop()
  189102. {
  189103. AudioIODeviceCallback* const lastCallback = currentCallback;
  189104. {
  189105. const ScopedLock sl (callbackLock);
  189106. currentCallback = 0;
  189107. }
  189108. if (lastCallback != 0)
  189109. lastCallback->audioDeviceStopped();
  189110. }
  189111. bool isPlaying()
  189112. {
  189113. return isASIOOpen && (currentCallback != 0);
  189114. }
  189115. const String getLastError()
  189116. {
  189117. return error;
  189118. }
  189119. bool hasControlPanel() const
  189120. {
  189121. return true;
  189122. }
  189123. bool showControlPanel()
  189124. {
  189125. log ("ASIO - showing control panel");
  189126. Component modalWindow (String::empty);
  189127. modalWindow.setOpaque (true);
  189128. modalWindow.addToDesktop (0);
  189129. modalWindow.enterModalState();
  189130. bool done = false;
  189131. JUCE_TRY
  189132. {
  189133. // are there are devices that need to be closed before showing their control panel?
  189134. // close();
  189135. insideControlPanelModalLoop = true;
  189136. const uint32 started = Time::getMillisecondCounter();
  189137. if (asioObject != 0)
  189138. {
  189139. asioObject->controlPanel();
  189140. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189141. log (T("spent: ") + String (spent));
  189142. if (spent > 300)
  189143. {
  189144. shouldUsePreferredSize = true;
  189145. done = true;
  189146. }
  189147. }
  189148. }
  189149. JUCE_CATCH_ALL
  189150. insideControlPanelModalLoop = false;
  189151. return done;
  189152. }
  189153. void resetRequest() throw()
  189154. {
  189155. needToReset = true;
  189156. }
  189157. void resyncRequest() throw()
  189158. {
  189159. needToReset = true;
  189160. isReSync = true;
  189161. }
  189162. void timerCallback()
  189163. {
  189164. if (! insideControlPanelModalLoop)
  189165. {
  189166. stopTimer();
  189167. // used to cause a reset
  189168. log ("! ASIO restart request!");
  189169. if (isOpen_)
  189170. {
  189171. AudioIODeviceCallback* const oldCallback = currentCallback;
  189172. close();
  189173. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189174. currentSampleRate, currentBlockSizeSamples);
  189175. if (oldCallback != 0)
  189176. start (oldCallback);
  189177. }
  189178. }
  189179. else
  189180. {
  189181. startTimer (100);
  189182. }
  189183. }
  189184. juce_UseDebuggingNewOperator
  189185. private:
  189186. IASIO* volatile asioObject;
  189187. ASIOCallbacks callbacks;
  189188. void* windowHandle;
  189189. CLSID classId;
  189190. const String optionalDllForDirectLoading;
  189191. String error;
  189192. long totalNumInputChans, totalNumOutputChans;
  189193. StringArray inputChannelNames, outputChannelNames;
  189194. Array<int> sampleRates, bufferSizes;
  189195. long inputLatency, outputLatency;
  189196. long minSize, maxSize, preferredSize, granularity;
  189197. int volatile currentBlockSizeSamples;
  189198. int volatile currentBitDepth;
  189199. double volatile currentSampleRate;
  189200. BitArray currentChansOut, currentChansIn;
  189201. AudioIODeviceCallback* volatile currentCallback;
  189202. CriticalSection callbackLock;
  189203. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189204. float* inBuffers [maxASIOChannels];
  189205. float* outBuffers [maxASIOChannels];
  189206. int inputChannelBitDepths [maxASIOChannels];
  189207. int outputChannelBitDepths [maxASIOChannels];
  189208. int inputChannelBytesPerSample [maxASIOChannels];
  189209. int outputChannelBytesPerSample [maxASIOChannels];
  189210. bool inputChannelIsFloat [maxASIOChannels];
  189211. bool outputChannelIsFloat [maxASIOChannels];
  189212. bool inputChannelLittleEndian [maxASIOChannels];
  189213. bool outputChannelLittleEndian [maxASIOChannels];
  189214. WaitableEvent event1;
  189215. HeapBlock <float> tempBuffer;
  189216. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189217. bool isOpen_, isStarted;
  189218. bool volatile isASIOOpen;
  189219. bool volatile calledback;
  189220. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189221. bool volatile insideControlPanelModalLoop;
  189222. bool volatile shouldUsePreferredSize;
  189223. void removeCurrentDriver()
  189224. {
  189225. if (asioObject != 0)
  189226. {
  189227. asioObject->Release();
  189228. asioObject = 0;
  189229. }
  189230. }
  189231. bool loadDriver()
  189232. {
  189233. removeCurrentDriver();
  189234. JUCE_TRY
  189235. {
  189236. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189237. classId, (void**) &asioObject) == S_OK)
  189238. {
  189239. return true;
  189240. }
  189241. // If a class isn't registered but we have a path for it, we can fallback to
  189242. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189243. if (optionalDllForDirectLoading.isNotEmpty())
  189244. {
  189245. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189246. if (h != 0)
  189247. {
  189248. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189249. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189250. if (dllGetClassObject != 0)
  189251. {
  189252. IClassFactory* classFactory = 0;
  189253. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189254. if (classFactory != 0)
  189255. {
  189256. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189257. classFactory->Release();
  189258. }
  189259. return asioObject != 0;
  189260. }
  189261. }
  189262. }
  189263. }
  189264. JUCE_CATCH_ALL
  189265. asioObject = 0;
  189266. return false;
  189267. }
  189268. const String initDriver()
  189269. {
  189270. if (asioObject != 0)
  189271. {
  189272. char buffer [256];
  189273. zeromem (buffer, sizeof (buffer));
  189274. if (! asioObject->init (windowHandle))
  189275. {
  189276. asioObject->getErrorMessage (buffer);
  189277. return String (buffer, sizeof (buffer) - 1);
  189278. }
  189279. // just in case any daft drivers expect this to be called..
  189280. asioObject->getDriverName (buffer);
  189281. return String::empty;
  189282. }
  189283. return "No Driver";
  189284. }
  189285. const String openDevice()
  189286. {
  189287. // use this in case the driver starts opening dialog boxes..
  189288. Component modalWindow (String::empty);
  189289. modalWindow.setOpaque (true);
  189290. modalWindow.addToDesktop (0);
  189291. modalWindow.enterModalState();
  189292. // open the device and get its info..
  189293. log (T("opening ASIO device: ") + getName());
  189294. needToReset = false;
  189295. isReSync = false;
  189296. outputChannelNames.clear();
  189297. inputChannelNames.clear();
  189298. bufferSizes.clear();
  189299. sampleRates.clear();
  189300. isASIOOpen = false;
  189301. isOpen_ = false;
  189302. totalNumInputChans = 0;
  189303. totalNumOutputChans = 0;
  189304. numActiveInputChans = 0;
  189305. numActiveOutputChans = 0;
  189306. currentCallback = 0;
  189307. error = String::empty;
  189308. if (getName().isEmpty())
  189309. return error;
  189310. long err = 0;
  189311. if (loadDriver())
  189312. {
  189313. if ((error = initDriver()).isEmpty())
  189314. {
  189315. numActiveInputChans = 0;
  189316. numActiveOutputChans = 0;
  189317. totalNumInputChans = 0;
  189318. totalNumOutputChans = 0;
  189319. if (asioObject != 0
  189320. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189321. {
  189322. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189323. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189324. {
  189325. // find a list of buffer sizes..
  189326. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189327. if (granularity >= 0)
  189328. {
  189329. granularity = jmax (1, (int) granularity);
  189330. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189331. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189332. }
  189333. else if (granularity < 0)
  189334. {
  189335. for (int i = 0; i < 18; ++i)
  189336. {
  189337. const int s = (1 << i);
  189338. if (s >= minSize && s <= maxSize)
  189339. bufferSizes.add (s);
  189340. }
  189341. }
  189342. if (! bufferSizes.contains (preferredSize))
  189343. bufferSizes.insert (0, preferredSize);
  189344. double currentRate = 0;
  189345. asioObject->getSampleRate (&currentRate);
  189346. if (currentRate <= 0.0 || currentRate > 192001.0)
  189347. {
  189348. log ("setting sample rate");
  189349. err = asioObject->setSampleRate (44100.0);
  189350. if (err != 0)
  189351. {
  189352. logError ("setting sample rate", err);
  189353. }
  189354. asioObject->getSampleRate (&currentRate);
  189355. }
  189356. currentSampleRate = currentRate;
  189357. postOutput = (asioObject->outputReady() == 0);
  189358. if (postOutput)
  189359. {
  189360. log ("ASIO outputReady = ok");
  189361. }
  189362. updateSampleRates();
  189363. // ..because cubase does it at this point
  189364. inputLatency = outputLatency = 0;
  189365. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189366. {
  189367. log ("ASIO - no latencies");
  189368. }
  189369. log (String ("latencies: ")
  189370. + String ((int) inputLatency)
  189371. + T(", ") + String ((int) outputLatency));
  189372. // create some dummy buffers now.. because cubase does..
  189373. numActiveInputChans = 0;
  189374. numActiveOutputChans = 0;
  189375. ASIOBufferInfo* info = bufferInfos;
  189376. int i, numChans = 0;
  189377. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189378. {
  189379. info->isInput = 1;
  189380. info->channelNum = i;
  189381. info->buffers[0] = info->buffers[1] = 0;
  189382. ++info;
  189383. ++numChans;
  189384. }
  189385. const int outputBufferIndex = numChans;
  189386. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189387. {
  189388. info->isInput = 0;
  189389. info->channelNum = i;
  189390. info->buffers[0] = info->buffers[1] = 0;
  189391. ++info;
  189392. ++numChans;
  189393. }
  189394. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189395. if (currentASIODev[0] == this)
  189396. {
  189397. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189398. callbacks.asioMessage = &asioMessagesCallback0;
  189399. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189400. }
  189401. else if (currentASIODev[1] == this)
  189402. {
  189403. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189404. callbacks.asioMessage = &asioMessagesCallback1;
  189405. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189406. }
  189407. else if (currentASIODev[2] == this)
  189408. {
  189409. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189410. callbacks.asioMessage = &asioMessagesCallback2;
  189411. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189412. }
  189413. else
  189414. {
  189415. jassertfalse
  189416. }
  189417. log (T("creating buffers (dummy): ") + String (numChans)
  189418. + T(", ") + String ((int) preferredSize));
  189419. if (preferredSize > 0)
  189420. {
  189421. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189422. if (err != 0)
  189423. {
  189424. logError ("dummy buffers", err);
  189425. }
  189426. }
  189427. long newInps = 0, newOuts = 0;
  189428. asioObject->getChannels (&newInps, &newOuts);
  189429. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189430. {
  189431. totalNumInputChans = newInps;
  189432. totalNumOutputChans = newOuts;
  189433. log (String ((int) totalNumInputChans) + T(" in; ")
  189434. + String ((int) totalNumOutputChans) + T(" out"));
  189435. }
  189436. updateSampleRates();
  189437. ASIOChannelInfo channelInfo;
  189438. channelInfo.type = 0;
  189439. for (i = 0; i < totalNumInputChans; ++i)
  189440. {
  189441. zerostruct (channelInfo);
  189442. channelInfo.channel = i;
  189443. channelInfo.isInput = 1;
  189444. asioObject->getChannelInfo (&channelInfo);
  189445. inputChannelNames.add (String (channelInfo.name));
  189446. }
  189447. for (i = 0; i < totalNumOutputChans; ++i)
  189448. {
  189449. zerostruct (channelInfo);
  189450. channelInfo.channel = i;
  189451. channelInfo.isInput = 0;
  189452. asioObject->getChannelInfo (&channelInfo);
  189453. outputChannelNames.add (String (channelInfo.name));
  189454. typeToFormatParameters (channelInfo.type,
  189455. outputChannelBitDepths[i],
  189456. outputChannelBytesPerSample[i],
  189457. outputChannelIsFloat[i],
  189458. outputChannelLittleEndian[i]);
  189459. if (i < 2)
  189460. {
  189461. // clear the channels that are used with the dummy stuff
  189462. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189463. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189464. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189465. }
  189466. }
  189467. outputChannelNames.trim();
  189468. inputChannelNames.trim();
  189469. outputChannelNames.appendNumbersToDuplicates (false, true);
  189470. inputChannelNames.appendNumbersToDuplicates (false, true);
  189471. // start and stop because cubase does it..
  189472. asioObject->getLatencies (&inputLatency, &outputLatency);
  189473. if ((err = asioObject->start()) != 0)
  189474. {
  189475. // ignore an error here, as it might start later after setting other stuff up
  189476. logError ("ASIO start", err);
  189477. }
  189478. Thread::sleep (100);
  189479. asioObject->stop();
  189480. }
  189481. else
  189482. {
  189483. error = "Can't detect buffer sizes";
  189484. }
  189485. }
  189486. else
  189487. {
  189488. error = "Can't detect asio channels";
  189489. }
  189490. }
  189491. }
  189492. else
  189493. {
  189494. error = "No such device";
  189495. }
  189496. if (error.isNotEmpty())
  189497. {
  189498. logError (error, err);
  189499. if (asioObject != 0)
  189500. asioObject->disposeBuffers();
  189501. removeCurrentDriver();
  189502. isASIOOpen = false;
  189503. }
  189504. else
  189505. {
  189506. isASIOOpen = true;
  189507. log ("ASIO device open");
  189508. }
  189509. isOpen_ = false;
  189510. needToReset = false;
  189511. isReSync = false;
  189512. return error;
  189513. }
  189514. void callback (const long index) throw()
  189515. {
  189516. if (isStarted)
  189517. {
  189518. bufferIndex = index;
  189519. processBuffer();
  189520. }
  189521. else
  189522. {
  189523. if (postOutput && (asioObject != 0))
  189524. asioObject->outputReady();
  189525. }
  189526. calledback = true;
  189527. }
  189528. void processBuffer() throw()
  189529. {
  189530. const ASIOBufferInfo* const infos = bufferInfos;
  189531. const int bi = bufferIndex;
  189532. const ScopedLock sl (callbackLock);
  189533. if (needToReset)
  189534. {
  189535. needToReset = false;
  189536. if (isReSync)
  189537. {
  189538. log ("! ASIO resync");
  189539. isReSync = false;
  189540. }
  189541. else
  189542. {
  189543. startTimer (20);
  189544. }
  189545. }
  189546. if (bi >= 0)
  189547. {
  189548. const int samps = currentBlockSizeSamples;
  189549. if (currentCallback != 0)
  189550. {
  189551. int i;
  189552. for (i = 0; i < numActiveInputChans; ++i)
  189553. {
  189554. float* const dst = inBuffers[i];
  189555. jassert (dst != 0);
  189556. const char* const src = (const char*) (infos[i].buffers[bi]);
  189557. if (inputChannelIsFloat[i])
  189558. {
  189559. memcpy (dst, src, samps * sizeof (float));
  189560. }
  189561. else
  189562. {
  189563. jassert (dst == tempBuffer + (samps * i));
  189564. switch (inputChannelBitDepths[i])
  189565. {
  189566. case 16:
  189567. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189568. samps, inputChannelLittleEndian[i]);
  189569. break;
  189570. case 24:
  189571. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189572. samps, inputChannelLittleEndian[i]);
  189573. break;
  189574. case 32:
  189575. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189576. samps, inputChannelLittleEndian[i]);
  189577. break;
  189578. case 64:
  189579. jassertfalse
  189580. break;
  189581. }
  189582. }
  189583. }
  189584. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189585. numActiveInputChans,
  189586. outBuffers,
  189587. numActiveOutputChans,
  189588. samps);
  189589. for (i = 0; i < numActiveOutputChans; ++i)
  189590. {
  189591. float* const src = outBuffers[i];
  189592. jassert (src != 0);
  189593. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189594. if (outputChannelIsFloat[i])
  189595. {
  189596. memcpy (dst, src, samps * sizeof (float));
  189597. }
  189598. else
  189599. {
  189600. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189601. switch (outputChannelBitDepths[i])
  189602. {
  189603. case 16:
  189604. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189605. samps, outputChannelLittleEndian[i]);
  189606. break;
  189607. case 24:
  189608. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189609. samps, outputChannelLittleEndian[i]);
  189610. break;
  189611. case 32:
  189612. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189613. samps, outputChannelLittleEndian[i]);
  189614. break;
  189615. case 64:
  189616. jassertfalse
  189617. break;
  189618. }
  189619. }
  189620. }
  189621. }
  189622. else
  189623. {
  189624. for (int i = 0; i < numActiveOutputChans; ++i)
  189625. {
  189626. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189627. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189628. }
  189629. }
  189630. }
  189631. if (postOutput)
  189632. asioObject->outputReady();
  189633. }
  189634. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189635. {
  189636. if (currentASIODev[0] != 0)
  189637. currentASIODev[0]->callback (index);
  189638. return 0;
  189639. }
  189640. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189641. {
  189642. if (currentASIODev[1] != 0)
  189643. currentASIODev[1]->callback (index);
  189644. return 0;
  189645. }
  189646. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189647. {
  189648. if (currentASIODev[2] != 0)
  189649. currentASIODev[2]->callback (index);
  189650. return 0;
  189651. }
  189652. static void bufferSwitchCallback0 (long index, long) throw()
  189653. {
  189654. if (currentASIODev[0] != 0)
  189655. currentASIODev[0]->callback (index);
  189656. }
  189657. static void bufferSwitchCallback1 (long index, long) throw()
  189658. {
  189659. if (currentASIODev[1] != 0)
  189660. currentASIODev[1]->callback (index);
  189661. }
  189662. static void bufferSwitchCallback2 (long index, long) throw()
  189663. {
  189664. if (currentASIODev[2] != 0)
  189665. currentASIODev[2]->callback (index);
  189666. }
  189667. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189668. {
  189669. return asioMessagesCallback (selector, value, 0);
  189670. }
  189671. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189672. {
  189673. return asioMessagesCallback (selector, value, 1);
  189674. }
  189675. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189676. {
  189677. return asioMessagesCallback (selector, value, 2);
  189678. }
  189679. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189680. {
  189681. switch (selector)
  189682. {
  189683. case kAsioSelectorSupported:
  189684. if (value == kAsioResetRequest
  189685. || value == kAsioEngineVersion
  189686. || value == kAsioResyncRequest
  189687. || value == kAsioLatenciesChanged
  189688. || value == kAsioSupportsInputMonitor)
  189689. return 1;
  189690. break;
  189691. case kAsioBufferSizeChange:
  189692. break;
  189693. case kAsioResetRequest:
  189694. if (currentASIODev[deviceIndex] != 0)
  189695. currentASIODev[deviceIndex]->resetRequest();
  189696. return 1;
  189697. case kAsioResyncRequest:
  189698. if (currentASIODev[deviceIndex] != 0)
  189699. currentASIODev[deviceIndex]->resyncRequest();
  189700. return 1;
  189701. case kAsioLatenciesChanged:
  189702. return 1;
  189703. case kAsioEngineVersion:
  189704. return 2;
  189705. case kAsioSupportsTimeInfo:
  189706. case kAsioSupportsTimeCode:
  189707. return 0;
  189708. }
  189709. return 0;
  189710. }
  189711. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189712. {
  189713. }
  189714. static void convertInt16ToFloat (const char* src,
  189715. float* dest,
  189716. const int srcStrideBytes,
  189717. int numSamples,
  189718. const bool littleEndian) throw()
  189719. {
  189720. const double g = 1.0 / 32768.0;
  189721. if (littleEndian)
  189722. {
  189723. while (--numSamples >= 0)
  189724. {
  189725. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189726. src += srcStrideBytes;
  189727. }
  189728. }
  189729. else
  189730. {
  189731. while (--numSamples >= 0)
  189732. {
  189733. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189734. src += srcStrideBytes;
  189735. }
  189736. }
  189737. }
  189738. static void convertFloatToInt16 (const float* src,
  189739. char* dest,
  189740. const int dstStrideBytes,
  189741. int numSamples,
  189742. const bool littleEndian) throw()
  189743. {
  189744. const double maxVal = (double) 0x7fff;
  189745. if (littleEndian)
  189746. {
  189747. while (--numSamples >= 0)
  189748. {
  189749. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189750. dest += dstStrideBytes;
  189751. }
  189752. }
  189753. else
  189754. {
  189755. while (--numSamples >= 0)
  189756. {
  189757. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189758. dest += dstStrideBytes;
  189759. }
  189760. }
  189761. }
  189762. static void convertInt24ToFloat (const char* src,
  189763. float* dest,
  189764. const int srcStrideBytes,
  189765. int numSamples,
  189766. const bool littleEndian) throw()
  189767. {
  189768. const double g = 1.0 / 0x7fffff;
  189769. if (littleEndian)
  189770. {
  189771. while (--numSamples >= 0)
  189772. {
  189773. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189774. src += srcStrideBytes;
  189775. }
  189776. }
  189777. else
  189778. {
  189779. while (--numSamples >= 0)
  189780. {
  189781. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189782. src += srcStrideBytes;
  189783. }
  189784. }
  189785. }
  189786. static void convertFloatToInt24 (const float* src,
  189787. char* dest,
  189788. const int dstStrideBytes,
  189789. int numSamples,
  189790. const bool littleEndian) throw()
  189791. {
  189792. const double maxVal = (double) 0x7fffff;
  189793. if (littleEndian)
  189794. {
  189795. while (--numSamples >= 0)
  189796. {
  189797. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189798. dest += dstStrideBytes;
  189799. }
  189800. }
  189801. else
  189802. {
  189803. while (--numSamples >= 0)
  189804. {
  189805. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189806. dest += dstStrideBytes;
  189807. }
  189808. }
  189809. }
  189810. static void convertInt32ToFloat (const char* src,
  189811. float* dest,
  189812. const int srcStrideBytes,
  189813. int numSamples,
  189814. const bool littleEndian) throw()
  189815. {
  189816. const double g = 1.0 / 0x7fffffff;
  189817. if (littleEndian)
  189818. {
  189819. while (--numSamples >= 0)
  189820. {
  189821. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189822. src += srcStrideBytes;
  189823. }
  189824. }
  189825. else
  189826. {
  189827. while (--numSamples >= 0)
  189828. {
  189829. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189830. src += srcStrideBytes;
  189831. }
  189832. }
  189833. }
  189834. static void convertFloatToInt32 (const float* src,
  189835. char* dest,
  189836. const int dstStrideBytes,
  189837. int numSamples,
  189838. const bool littleEndian) throw()
  189839. {
  189840. const double maxVal = (double) 0x7fffffff;
  189841. if (littleEndian)
  189842. {
  189843. while (--numSamples >= 0)
  189844. {
  189845. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189846. dest += dstStrideBytes;
  189847. }
  189848. }
  189849. else
  189850. {
  189851. while (--numSamples >= 0)
  189852. {
  189853. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189854. dest += dstStrideBytes;
  189855. }
  189856. }
  189857. }
  189858. static void typeToFormatParameters (const long type,
  189859. int& bitDepth,
  189860. int& byteStride,
  189861. bool& formatIsFloat,
  189862. bool& littleEndian) throw()
  189863. {
  189864. bitDepth = 0;
  189865. littleEndian = false;
  189866. formatIsFloat = false;
  189867. switch (type)
  189868. {
  189869. case ASIOSTInt16MSB:
  189870. case ASIOSTInt16LSB:
  189871. case ASIOSTInt32MSB16:
  189872. case ASIOSTInt32LSB16:
  189873. bitDepth = 16; break;
  189874. case ASIOSTFloat32MSB:
  189875. case ASIOSTFloat32LSB:
  189876. formatIsFloat = true;
  189877. bitDepth = 32; break;
  189878. case ASIOSTInt32MSB:
  189879. case ASIOSTInt32LSB:
  189880. bitDepth = 32; break;
  189881. case ASIOSTInt24MSB:
  189882. case ASIOSTInt24LSB:
  189883. case ASIOSTInt32MSB24:
  189884. case ASIOSTInt32LSB24:
  189885. case ASIOSTInt32MSB18:
  189886. case ASIOSTInt32MSB20:
  189887. case ASIOSTInt32LSB18:
  189888. case ASIOSTInt32LSB20:
  189889. bitDepth = 24; break;
  189890. case ASIOSTFloat64MSB:
  189891. case ASIOSTFloat64LSB:
  189892. default:
  189893. bitDepth = 64;
  189894. break;
  189895. }
  189896. switch (type)
  189897. {
  189898. case ASIOSTInt16MSB:
  189899. case ASIOSTInt32MSB16:
  189900. case ASIOSTFloat32MSB:
  189901. case ASIOSTFloat64MSB:
  189902. case ASIOSTInt32MSB:
  189903. case ASIOSTInt32MSB18:
  189904. case ASIOSTInt32MSB20:
  189905. case ASIOSTInt32MSB24:
  189906. case ASIOSTInt24MSB:
  189907. littleEndian = false; break;
  189908. case ASIOSTInt16LSB:
  189909. case ASIOSTInt32LSB16:
  189910. case ASIOSTFloat32LSB:
  189911. case ASIOSTFloat64LSB:
  189912. case ASIOSTInt32LSB:
  189913. case ASIOSTInt32LSB18:
  189914. case ASIOSTInt32LSB20:
  189915. case ASIOSTInt32LSB24:
  189916. case ASIOSTInt24LSB:
  189917. littleEndian = true; break;
  189918. default:
  189919. break;
  189920. }
  189921. switch (type)
  189922. {
  189923. case ASIOSTInt16LSB:
  189924. case ASIOSTInt16MSB:
  189925. byteStride = 2; break;
  189926. case ASIOSTInt24LSB:
  189927. case ASIOSTInt24MSB:
  189928. byteStride = 3; break;
  189929. case ASIOSTInt32MSB16:
  189930. case ASIOSTInt32LSB16:
  189931. case ASIOSTInt32MSB:
  189932. case ASIOSTInt32MSB18:
  189933. case ASIOSTInt32MSB20:
  189934. case ASIOSTInt32MSB24:
  189935. case ASIOSTInt32LSB:
  189936. case ASIOSTInt32LSB18:
  189937. case ASIOSTInt32LSB20:
  189938. case ASIOSTInt32LSB24:
  189939. case ASIOSTFloat32LSB:
  189940. case ASIOSTFloat32MSB:
  189941. byteStride = 4; break;
  189942. case ASIOSTFloat64MSB:
  189943. case ASIOSTFloat64LSB:
  189944. byteStride = 8; break;
  189945. default:
  189946. break;
  189947. }
  189948. }
  189949. };
  189950. class ASIOAudioIODeviceType : public AudioIODeviceType
  189951. {
  189952. public:
  189953. ASIOAudioIODeviceType()
  189954. : AudioIODeviceType (T("ASIO")),
  189955. hasScanned (false)
  189956. {
  189957. CoInitialize (0);
  189958. }
  189959. ~ASIOAudioIODeviceType()
  189960. {
  189961. }
  189962. void scanForDevices()
  189963. {
  189964. hasScanned = true;
  189965. deviceNames.clear();
  189966. classIds.clear();
  189967. HKEY hk = 0;
  189968. int index = 0;
  189969. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189970. {
  189971. for (;;)
  189972. {
  189973. char name [256];
  189974. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189975. {
  189976. addDriverInfo (name, hk);
  189977. }
  189978. else
  189979. {
  189980. break;
  189981. }
  189982. }
  189983. RegCloseKey (hk);
  189984. }
  189985. }
  189986. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189987. {
  189988. jassert (hasScanned); // need to call scanForDevices() before doing this
  189989. return deviceNames;
  189990. }
  189991. int getDefaultDeviceIndex (const bool) const
  189992. {
  189993. jassert (hasScanned); // need to call scanForDevices() before doing this
  189994. for (int i = deviceNames.size(); --i >= 0;)
  189995. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189996. return i; // asio4all is a safe choice for a default..
  189997. #if JUCE_DEBUG
  189998. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189999. return 1; // (the digi m-box driver crashes the app when you run
  190000. // it in the debugger, which can be a bit annoying)
  190001. #endif
  190002. return 0;
  190003. }
  190004. static int findFreeSlot()
  190005. {
  190006. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  190007. if (currentASIODev[i] == 0)
  190008. return i;
  190009. jassertfalse; // unfortunately you can only have a finite number
  190010. // of ASIO devices open at the same time..
  190011. return -1;
  190012. }
  190013. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  190014. {
  190015. jassert (hasScanned); // need to call scanForDevices() before doing this
  190016. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  190017. }
  190018. bool hasSeparateInputsAndOutputs() const { return false; }
  190019. AudioIODevice* createDevice (const String& outputDeviceName,
  190020. const String& inputDeviceName)
  190021. {
  190022. // ASIO can't open two different devices for input and output - they must be the same one.
  190023. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  190024. jassert (hasScanned); // need to call scanForDevices() before doing this
  190025. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  190026. : inputDeviceName);
  190027. if (index >= 0)
  190028. {
  190029. const int freeSlot = findFreeSlot();
  190030. if (freeSlot >= 0)
  190031. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  190032. }
  190033. return 0;
  190034. }
  190035. juce_UseDebuggingNewOperator
  190036. private:
  190037. StringArray deviceNames;
  190038. OwnedArray <CLSID> classIds;
  190039. bool hasScanned;
  190040. static bool checkClassIsOk (const String& classId)
  190041. {
  190042. HKEY hk = 0;
  190043. bool ok = false;
  190044. if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS)
  190045. {
  190046. int index = 0;
  190047. for (;;)
  190048. {
  190049. char buf [512];
  190050. if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS)
  190051. {
  190052. if (classId.equalsIgnoreCase (buf))
  190053. {
  190054. HKEY subKey, pathKey;
  190055. if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190056. {
  190057. if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  190058. {
  190059. char pathName [600];
  190060. DWORD dtype = REG_SZ;
  190061. DWORD dsize = sizeof (pathName);
  190062. if (RegQueryValueExA (pathKey, 0, 0, &dtype,
  190063. (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  190064. {
  190065. OFSTRUCT of;
  190066. zerostruct (of);
  190067. of.cBytes = sizeof (of);
  190068. ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0);
  190069. }
  190070. RegCloseKey (pathKey);
  190071. }
  190072. RegCloseKey (subKey);
  190073. }
  190074. break;
  190075. }
  190076. }
  190077. else
  190078. {
  190079. break;
  190080. }
  190081. }
  190082. RegCloseKey (hk);
  190083. }
  190084. return ok;
  190085. }
  190086. void addDriverInfo (const String& keyName, HKEY hk)
  190087. {
  190088. HKEY subKey;
  190089. if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190090. {
  190091. char buf [256];
  190092. DWORD dtype = REG_SZ;
  190093. DWORD dsize = sizeof (buf);
  190094. zeromem (buf, dsize);
  190095. if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190096. {
  190097. if (dsize > 0 && checkClassIsOk (buf))
  190098. {
  190099. wchar_t classIdStr [130];
  190100. MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128);
  190101. String deviceName;
  190102. CLSID classId;
  190103. if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK)
  190104. {
  190105. dtype = REG_SZ;
  190106. dsize = sizeof (buf);
  190107. if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190108. deviceName = buf;
  190109. else
  190110. deviceName = keyName;
  190111. log (T("found ") + deviceName);
  190112. deviceNames.add (deviceName);
  190113. classIds.add (new CLSID (classId));
  190114. }
  190115. }
  190116. RegCloseKey (subKey);
  190117. }
  190118. }
  190119. }
  190120. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190121. const ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190122. };
  190123. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190124. {
  190125. return new ASIOAudioIODeviceType();
  190126. }
  190127. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190128. void* guid,
  190129. const String& optionalDllForDirectLoading)
  190130. {
  190131. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190132. if (freeSlot < 0)
  190133. return 0;
  190134. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190135. }
  190136. #undef log
  190137. #endif
  190138. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  190139. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  190140. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190141. // compiled on its own).
  190142. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190143. END_JUCE_NAMESPACE
  190144. extern "C"
  190145. {
  190146. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190147. typedef struct typeDSBUFFERDESC
  190148. {
  190149. DWORD dwSize;
  190150. DWORD dwFlags;
  190151. DWORD dwBufferBytes;
  190152. DWORD dwReserved;
  190153. LPWAVEFORMATEX lpwfxFormat;
  190154. GUID guid3DAlgorithm;
  190155. } DSBUFFERDESC;
  190156. struct IDirectSoundBuffer;
  190157. #undef INTERFACE
  190158. #define INTERFACE IDirectSound
  190159. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190160. {
  190161. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190162. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190163. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190164. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190165. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190166. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190167. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190168. STDMETHOD(Compact) (THIS) PURE;
  190169. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190170. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190171. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190172. };
  190173. #undef INTERFACE
  190174. #define INTERFACE IDirectSoundBuffer
  190175. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190176. {
  190177. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190178. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190179. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190180. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190181. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190182. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190183. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190184. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190185. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190186. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190187. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190188. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190189. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190190. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190191. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190192. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190193. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190194. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190195. STDMETHOD(Stop) (THIS) PURE;
  190196. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190197. STDMETHOD(Restore) (THIS) PURE;
  190198. };
  190199. typedef struct typeDSCBUFFERDESC
  190200. {
  190201. DWORD dwSize;
  190202. DWORD dwFlags;
  190203. DWORD dwBufferBytes;
  190204. DWORD dwReserved;
  190205. LPWAVEFORMATEX lpwfxFormat;
  190206. } DSCBUFFERDESC;
  190207. struct IDirectSoundCaptureBuffer;
  190208. #undef INTERFACE
  190209. #define INTERFACE IDirectSoundCapture
  190210. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190211. {
  190212. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190213. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190214. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190215. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190216. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190217. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190218. };
  190219. #undef INTERFACE
  190220. #define INTERFACE IDirectSoundCaptureBuffer
  190221. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190222. {
  190223. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190224. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190225. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190226. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190227. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190228. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190229. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190230. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190231. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190232. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190233. STDMETHOD(Stop) (THIS) PURE;
  190234. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190235. };
  190236. };
  190237. BEGIN_JUCE_NAMESPACE
  190238. static const String getDSErrorMessage (HRESULT hr)
  190239. {
  190240. const char* result = 0;
  190241. switch (hr)
  190242. {
  190243. case MAKE_HRESULT(1, 0x878, 10):
  190244. result = "Device already allocated";
  190245. break;
  190246. case MAKE_HRESULT(1, 0x878, 30):
  190247. result = "Control unavailable";
  190248. break;
  190249. case E_INVALIDARG:
  190250. result = "Invalid parameter";
  190251. break;
  190252. case MAKE_HRESULT(1, 0x878, 50):
  190253. result = "Invalid call";
  190254. break;
  190255. case E_FAIL:
  190256. result = "Generic error";
  190257. break;
  190258. case MAKE_HRESULT(1, 0x878, 70):
  190259. result = "Priority level error";
  190260. break;
  190261. case E_OUTOFMEMORY:
  190262. result = "Out of memory";
  190263. break;
  190264. case MAKE_HRESULT(1, 0x878, 100):
  190265. result = "Bad format";
  190266. break;
  190267. case E_NOTIMPL:
  190268. result = "Unsupported function";
  190269. break;
  190270. case MAKE_HRESULT(1, 0x878, 120):
  190271. result = "No driver";
  190272. break;
  190273. case MAKE_HRESULT(1, 0x878, 130):
  190274. result = "Already initialised";
  190275. break;
  190276. case CLASS_E_NOAGGREGATION:
  190277. result = "No aggregation";
  190278. break;
  190279. case MAKE_HRESULT(1, 0x878, 150):
  190280. result = "Buffer lost";
  190281. break;
  190282. case MAKE_HRESULT(1, 0x878, 160):
  190283. result = "Another app has priority";
  190284. break;
  190285. case MAKE_HRESULT(1, 0x878, 170):
  190286. result = "Uninitialised";
  190287. break;
  190288. case E_NOINTERFACE:
  190289. result = "No interface";
  190290. break;
  190291. case S_OK:
  190292. result = "No error";
  190293. break;
  190294. default:
  190295. return "Unknown error: " + String ((int) hr);
  190296. }
  190297. return result;
  190298. }
  190299. #define DS_DEBUGGING 1
  190300. #ifdef DS_DEBUGGING
  190301. #define CATCH JUCE_CATCH_EXCEPTION
  190302. #undef log
  190303. #define log(a) Logger::writeToLog(a);
  190304. #undef logError
  190305. #define logError(a) logDSError(a, __LINE__);
  190306. static void logDSError (HRESULT hr, int lineNum)
  190307. {
  190308. if (hr != S_OK)
  190309. {
  190310. String error ("DS error at line ");
  190311. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190312. log (error);
  190313. }
  190314. }
  190315. #else
  190316. #define CATCH JUCE_CATCH_ALL
  190317. #define log(a)
  190318. #define logError(a)
  190319. #endif
  190320. #define DSOUND_FUNCTION(functionName, params) \
  190321. typedef HRESULT (WINAPI *type##functionName) params; \
  190322. static type##functionName ds##functionName = 0;
  190323. #define DSOUND_FUNCTION_LOAD(functionName) \
  190324. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190325. jassert (ds##functionName != 0);
  190326. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190327. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190328. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190329. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190330. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190331. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190332. static void initialiseDSoundFunctions()
  190333. {
  190334. if (dsDirectSoundCreate == 0)
  190335. {
  190336. HMODULE h = LoadLibraryA ("dsound.dll");
  190337. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190338. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190339. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190340. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190341. }
  190342. }
  190343. class DSoundInternalOutChannel
  190344. {
  190345. String name;
  190346. LPGUID guid;
  190347. int sampleRate, bufferSizeSamples;
  190348. float* leftBuffer;
  190349. float* rightBuffer;
  190350. IDirectSound* pDirectSound;
  190351. IDirectSoundBuffer* pOutputBuffer;
  190352. DWORD writeOffset;
  190353. int totalBytesPerBuffer;
  190354. int bytesPerBuffer;
  190355. unsigned int lastPlayCursor;
  190356. public:
  190357. int bitDepth;
  190358. bool doneFlag;
  190359. DSoundInternalOutChannel (const String& name_,
  190360. LPGUID guid_,
  190361. int rate,
  190362. int bufferSize,
  190363. float* left,
  190364. float* right)
  190365. : name (name_),
  190366. guid (guid_),
  190367. sampleRate (rate),
  190368. bufferSizeSamples (bufferSize),
  190369. leftBuffer (left),
  190370. rightBuffer (right),
  190371. pDirectSound (0),
  190372. pOutputBuffer (0),
  190373. bitDepth (16)
  190374. {
  190375. }
  190376. ~DSoundInternalOutChannel()
  190377. {
  190378. close();
  190379. }
  190380. void close()
  190381. {
  190382. HRESULT hr;
  190383. if (pOutputBuffer != 0)
  190384. {
  190385. JUCE_TRY
  190386. {
  190387. log (T("closing dsound out: ") + name);
  190388. hr = pOutputBuffer->Stop();
  190389. logError (hr);
  190390. }
  190391. CATCH
  190392. JUCE_TRY
  190393. {
  190394. hr = pOutputBuffer->Release();
  190395. logError (hr);
  190396. }
  190397. CATCH
  190398. pOutputBuffer = 0;
  190399. }
  190400. if (pDirectSound != 0)
  190401. {
  190402. JUCE_TRY
  190403. {
  190404. hr = pDirectSound->Release();
  190405. logError (hr);
  190406. }
  190407. CATCH
  190408. pDirectSound = 0;
  190409. }
  190410. }
  190411. const String open()
  190412. {
  190413. log (T("opening dsound out device: ") + name
  190414. + T(" rate=") + String (sampleRate)
  190415. + T(" bits=") + String (bitDepth)
  190416. + T(" buf=") + String (bufferSizeSamples));
  190417. pDirectSound = 0;
  190418. pOutputBuffer = 0;
  190419. writeOffset = 0;
  190420. String error;
  190421. HRESULT hr = E_NOINTERFACE;
  190422. if (dsDirectSoundCreate != 0)
  190423. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190424. if (hr == S_OK)
  190425. {
  190426. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190427. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190428. const int numChannels = 2;
  190429. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190430. logError (hr);
  190431. if (hr == S_OK)
  190432. {
  190433. IDirectSoundBuffer* pPrimaryBuffer;
  190434. DSBUFFERDESC primaryDesc;
  190435. zerostruct (primaryDesc);
  190436. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190437. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190438. primaryDesc.dwBufferBytes = 0;
  190439. primaryDesc.lpwfxFormat = 0;
  190440. log ("opening dsound out step 2");
  190441. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190442. logError (hr);
  190443. if (hr == S_OK)
  190444. {
  190445. WAVEFORMATEX wfFormat;
  190446. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190447. wfFormat.nChannels = (unsigned short) numChannels;
  190448. wfFormat.nSamplesPerSec = sampleRate;
  190449. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190450. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190451. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190452. wfFormat.cbSize = 0;
  190453. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190454. logError (hr);
  190455. if (hr == S_OK)
  190456. {
  190457. DSBUFFERDESC secondaryDesc;
  190458. zerostruct (secondaryDesc);
  190459. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190460. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190461. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190462. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190463. secondaryDesc.lpwfxFormat = &wfFormat;
  190464. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190465. logError (hr);
  190466. if (hr == S_OK)
  190467. {
  190468. log ("opening dsound out step 3");
  190469. DWORD dwDataLen;
  190470. unsigned char* pDSBuffData;
  190471. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190472. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190473. logError (hr);
  190474. if (hr == S_OK)
  190475. {
  190476. zeromem (pDSBuffData, dwDataLen);
  190477. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190478. if (hr == S_OK)
  190479. {
  190480. hr = pOutputBuffer->SetCurrentPosition (0);
  190481. if (hr == S_OK)
  190482. {
  190483. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190484. if (hr == S_OK)
  190485. return String::empty;
  190486. }
  190487. }
  190488. }
  190489. }
  190490. }
  190491. }
  190492. }
  190493. }
  190494. error = getDSErrorMessage (hr);
  190495. close();
  190496. return error;
  190497. }
  190498. void synchronisePosition()
  190499. {
  190500. if (pOutputBuffer != 0)
  190501. {
  190502. DWORD playCursor;
  190503. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190504. }
  190505. }
  190506. bool service()
  190507. {
  190508. if (pOutputBuffer == 0)
  190509. return true;
  190510. DWORD playCursor, writeCursor;
  190511. for (;;)
  190512. {
  190513. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190514. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190515. {
  190516. pOutputBuffer->Restore();
  190517. continue;
  190518. }
  190519. if (hr == S_OK)
  190520. break;
  190521. logError (hr);
  190522. jassertfalse
  190523. return true;
  190524. }
  190525. int playWriteGap = writeCursor - playCursor;
  190526. if (playWriteGap < 0)
  190527. playWriteGap += totalBytesPerBuffer;
  190528. int bytesEmpty = playCursor - writeOffset;
  190529. if (bytesEmpty < 0)
  190530. bytesEmpty += totalBytesPerBuffer;
  190531. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190532. {
  190533. writeOffset = writeCursor;
  190534. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190535. }
  190536. if (bytesEmpty >= bytesPerBuffer)
  190537. {
  190538. LPBYTE lpbuf1 = 0;
  190539. LPBYTE lpbuf2 = 0;
  190540. DWORD dwSize1 = 0;
  190541. DWORD dwSize2 = 0;
  190542. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190543. bytesPerBuffer,
  190544. (void**) &lpbuf1, &dwSize1,
  190545. (void**) &lpbuf2, &dwSize2, 0);
  190546. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190547. {
  190548. pOutputBuffer->Restore();
  190549. hr = pOutputBuffer->Lock (writeOffset,
  190550. bytesPerBuffer,
  190551. (void**) &lpbuf1, &dwSize1,
  190552. (void**) &lpbuf2, &dwSize2, 0);
  190553. }
  190554. if (hr == S_OK)
  190555. {
  190556. if (bitDepth == 16)
  190557. {
  190558. const float gainL = 32767.0f;
  190559. const float gainR = 32767.0f;
  190560. int* dest = (int*)lpbuf1;
  190561. const float* left = leftBuffer;
  190562. const float* right = rightBuffer;
  190563. int samples1 = dwSize1 >> 2;
  190564. int samples2 = dwSize2 >> 2;
  190565. if (left == 0)
  190566. {
  190567. while (--samples1 >= 0)
  190568. {
  190569. int r = roundToInt (gainR * *right++);
  190570. if (r < -32768)
  190571. r = -32768;
  190572. else if (r > 32767)
  190573. r = 32767;
  190574. *dest++ = (r << 16);
  190575. }
  190576. dest = (int*)lpbuf2;
  190577. while (--samples2 >= 0)
  190578. {
  190579. int r = roundToInt (gainR * *right++);
  190580. if (r < -32768)
  190581. r = -32768;
  190582. else if (r > 32767)
  190583. r = 32767;
  190584. *dest++ = (r << 16);
  190585. }
  190586. }
  190587. else if (right == 0)
  190588. {
  190589. while (--samples1 >= 0)
  190590. {
  190591. int l = roundToInt (gainL * *left++);
  190592. if (l < -32768)
  190593. l = -32768;
  190594. else if (l > 32767)
  190595. l = 32767;
  190596. l &= 0xffff;
  190597. *dest++ = l;
  190598. }
  190599. dest = (int*)lpbuf2;
  190600. while (--samples2 >= 0)
  190601. {
  190602. int l = roundToInt (gainL * *left++);
  190603. if (l < -32768)
  190604. l = -32768;
  190605. else if (l > 32767)
  190606. l = 32767;
  190607. l &= 0xffff;
  190608. *dest++ = l;
  190609. }
  190610. }
  190611. else
  190612. {
  190613. while (--samples1 >= 0)
  190614. {
  190615. int l = roundToInt (gainL * *left++);
  190616. if (l < -32768)
  190617. l = -32768;
  190618. else if (l > 32767)
  190619. l = 32767;
  190620. l &= 0xffff;
  190621. int r = roundToInt (gainR * *right++);
  190622. if (r < -32768)
  190623. r = -32768;
  190624. else if (r > 32767)
  190625. r = 32767;
  190626. *dest++ = (r << 16) | l;
  190627. }
  190628. dest = (int*)lpbuf2;
  190629. while (--samples2 >= 0)
  190630. {
  190631. int l = roundToInt (gainL * *left++);
  190632. if (l < -32768)
  190633. l = -32768;
  190634. else if (l > 32767)
  190635. l = 32767;
  190636. l &= 0xffff;
  190637. int r = roundToInt (gainR * *right++);
  190638. if (r < -32768)
  190639. r = -32768;
  190640. else if (r > 32767)
  190641. r = 32767;
  190642. *dest++ = (r << 16) | l;
  190643. }
  190644. }
  190645. }
  190646. else
  190647. {
  190648. jassertfalse
  190649. }
  190650. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190651. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190652. }
  190653. else
  190654. {
  190655. jassertfalse
  190656. logError (hr);
  190657. }
  190658. bytesEmpty -= bytesPerBuffer;
  190659. return true;
  190660. }
  190661. else
  190662. {
  190663. return false;
  190664. }
  190665. }
  190666. };
  190667. struct DSoundInternalInChannel
  190668. {
  190669. String name;
  190670. LPGUID guid;
  190671. int sampleRate, bufferSizeSamples;
  190672. float* leftBuffer;
  190673. float* rightBuffer;
  190674. IDirectSound* pDirectSound;
  190675. IDirectSoundCapture* pDirectSoundCapture;
  190676. IDirectSoundCaptureBuffer* pInputBuffer;
  190677. public:
  190678. unsigned int readOffset;
  190679. int bytesPerBuffer, totalBytesPerBuffer;
  190680. int bitDepth;
  190681. bool doneFlag;
  190682. DSoundInternalInChannel (const String& name_,
  190683. LPGUID guid_,
  190684. int rate,
  190685. int bufferSize,
  190686. float* left,
  190687. float* right)
  190688. : name (name_),
  190689. guid (guid_),
  190690. sampleRate (rate),
  190691. bufferSizeSamples (bufferSize),
  190692. leftBuffer (left),
  190693. rightBuffer (right),
  190694. pDirectSound (0),
  190695. pDirectSoundCapture (0),
  190696. pInputBuffer (0),
  190697. bitDepth (16)
  190698. {
  190699. }
  190700. ~DSoundInternalInChannel()
  190701. {
  190702. close();
  190703. }
  190704. void close()
  190705. {
  190706. HRESULT hr;
  190707. if (pInputBuffer != 0)
  190708. {
  190709. JUCE_TRY
  190710. {
  190711. log (T("closing dsound in: ") + name);
  190712. hr = pInputBuffer->Stop();
  190713. logError (hr);
  190714. }
  190715. CATCH
  190716. JUCE_TRY
  190717. {
  190718. hr = pInputBuffer->Release();
  190719. logError (hr);
  190720. }
  190721. CATCH
  190722. pInputBuffer = 0;
  190723. }
  190724. if (pDirectSoundCapture != 0)
  190725. {
  190726. JUCE_TRY
  190727. {
  190728. hr = pDirectSoundCapture->Release();
  190729. logError (hr);
  190730. }
  190731. CATCH
  190732. pDirectSoundCapture = 0;
  190733. }
  190734. if (pDirectSound != 0)
  190735. {
  190736. JUCE_TRY
  190737. {
  190738. hr = pDirectSound->Release();
  190739. logError (hr);
  190740. }
  190741. CATCH
  190742. pDirectSound = 0;
  190743. }
  190744. }
  190745. const String open()
  190746. {
  190747. log (T("opening dsound in device: ") + name
  190748. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190749. pDirectSound = 0;
  190750. pDirectSoundCapture = 0;
  190751. pInputBuffer = 0;
  190752. readOffset = 0;
  190753. totalBytesPerBuffer = 0;
  190754. String error;
  190755. HRESULT hr = E_NOINTERFACE;
  190756. if (dsDirectSoundCaptureCreate != 0)
  190757. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190758. logError (hr);
  190759. if (hr == S_OK)
  190760. {
  190761. const int numChannels = 2;
  190762. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190763. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190764. WAVEFORMATEX wfFormat;
  190765. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190766. wfFormat.nChannels = (unsigned short)numChannels;
  190767. wfFormat.nSamplesPerSec = sampleRate;
  190768. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190769. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190770. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190771. wfFormat.cbSize = 0;
  190772. DSCBUFFERDESC captureDesc;
  190773. zerostruct (captureDesc);
  190774. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190775. captureDesc.dwFlags = 0;
  190776. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190777. captureDesc.lpwfxFormat = &wfFormat;
  190778. log (T("opening dsound in step 2"));
  190779. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190780. logError (hr);
  190781. if (hr == S_OK)
  190782. {
  190783. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190784. logError (hr);
  190785. if (hr == S_OK)
  190786. return String::empty;
  190787. }
  190788. }
  190789. error = getDSErrorMessage (hr);
  190790. close();
  190791. return error;
  190792. }
  190793. void synchronisePosition()
  190794. {
  190795. if (pInputBuffer != 0)
  190796. {
  190797. DWORD capturePos;
  190798. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190799. }
  190800. }
  190801. bool service()
  190802. {
  190803. if (pInputBuffer == 0)
  190804. return true;
  190805. DWORD capturePos, readPos;
  190806. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190807. logError (hr);
  190808. if (hr != S_OK)
  190809. return true;
  190810. int bytesFilled = readPos - readOffset;
  190811. if (bytesFilled < 0)
  190812. bytesFilled += totalBytesPerBuffer;
  190813. if (bytesFilled >= bytesPerBuffer)
  190814. {
  190815. LPBYTE lpbuf1 = 0;
  190816. LPBYTE lpbuf2 = 0;
  190817. DWORD dwsize1 = 0;
  190818. DWORD dwsize2 = 0;
  190819. HRESULT hr = pInputBuffer->Lock (readOffset,
  190820. bytesPerBuffer,
  190821. (void**) &lpbuf1, &dwsize1,
  190822. (void**) &lpbuf2, &dwsize2, 0);
  190823. if (hr == S_OK)
  190824. {
  190825. if (bitDepth == 16)
  190826. {
  190827. const float g = 1.0f / 32768.0f;
  190828. float* destL = leftBuffer;
  190829. float* destR = rightBuffer;
  190830. int samples1 = dwsize1 >> 2;
  190831. int samples2 = dwsize2 >> 2;
  190832. const short* src = (const short*)lpbuf1;
  190833. if (destL == 0)
  190834. {
  190835. while (--samples1 >= 0)
  190836. {
  190837. ++src;
  190838. *destR++ = *src++ * g;
  190839. }
  190840. src = (const short*)lpbuf2;
  190841. while (--samples2 >= 0)
  190842. {
  190843. ++src;
  190844. *destR++ = *src++ * g;
  190845. }
  190846. }
  190847. else if (destR == 0)
  190848. {
  190849. while (--samples1 >= 0)
  190850. {
  190851. *destL++ = *src++ * g;
  190852. ++src;
  190853. }
  190854. src = (const short*)lpbuf2;
  190855. while (--samples2 >= 0)
  190856. {
  190857. *destL++ = *src++ * g;
  190858. ++src;
  190859. }
  190860. }
  190861. else
  190862. {
  190863. while (--samples1 >= 0)
  190864. {
  190865. *destL++ = *src++ * g;
  190866. *destR++ = *src++ * g;
  190867. }
  190868. src = (const short*)lpbuf2;
  190869. while (--samples2 >= 0)
  190870. {
  190871. *destL++ = *src++ * g;
  190872. *destR++ = *src++ * g;
  190873. }
  190874. }
  190875. }
  190876. else
  190877. {
  190878. jassertfalse
  190879. }
  190880. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190881. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190882. }
  190883. else
  190884. {
  190885. logError (hr);
  190886. jassertfalse
  190887. }
  190888. bytesFilled -= bytesPerBuffer;
  190889. return true;
  190890. }
  190891. else
  190892. {
  190893. return false;
  190894. }
  190895. }
  190896. };
  190897. class DSoundAudioIODevice : public AudioIODevice,
  190898. public Thread
  190899. {
  190900. public:
  190901. DSoundAudioIODevice (const String& deviceName,
  190902. const int outputDeviceIndex_,
  190903. const int inputDeviceIndex_)
  190904. : AudioIODevice (deviceName, "DirectSound"),
  190905. Thread ("Juce DSound"),
  190906. isOpen_ (false),
  190907. isStarted (false),
  190908. outputDeviceIndex (outputDeviceIndex_),
  190909. inputDeviceIndex (inputDeviceIndex_),
  190910. numInputBuffers (0),
  190911. numOutputBuffers (0),
  190912. totalSamplesOut (0),
  190913. sampleRate (0.0),
  190914. inputBuffers (0),
  190915. outputBuffers (0),
  190916. callback (0),
  190917. bufferSizeSamples (0)
  190918. {
  190919. if (outputDeviceIndex_ >= 0)
  190920. {
  190921. outChannels.add (TRANS("Left"));
  190922. outChannels.add (TRANS("Right"));
  190923. }
  190924. if (inputDeviceIndex_ >= 0)
  190925. {
  190926. inChannels.add (TRANS("Left"));
  190927. inChannels.add (TRANS("Right"));
  190928. }
  190929. }
  190930. ~DSoundAudioIODevice()
  190931. {
  190932. close();
  190933. }
  190934. const StringArray getOutputChannelNames()
  190935. {
  190936. return outChannels;
  190937. }
  190938. const StringArray getInputChannelNames()
  190939. {
  190940. return inChannels;
  190941. }
  190942. int getNumSampleRates()
  190943. {
  190944. return 4;
  190945. }
  190946. double getSampleRate (int index)
  190947. {
  190948. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190949. return samps [jlimit (0, 3, index)];
  190950. }
  190951. int getNumBufferSizesAvailable()
  190952. {
  190953. return 50;
  190954. }
  190955. int getBufferSizeSamples (int index)
  190956. {
  190957. int n = 64;
  190958. for (int i = 0; i < index; ++i)
  190959. n += (n < 512) ? 32
  190960. : ((n < 1024) ? 64
  190961. : ((n < 2048) ? 128 : 256));
  190962. return n;
  190963. }
  190964. int getDefaultBufferSize()
  190965. {
  190966. return 2560;
  190967. }
  190968. const String open (const BitArray& inputChannels,
  190969. const BitArray& outputChannels,
  190970. double sampleRate,
  190971. int bufferSizeSamples)
  190972. {
  190973. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190974. isOpen_ = lastError.isEmpty();
  190975. return lastError;
  190976. }
  190977. void close()
  190978. {
  190979. stop();
  190980. if (isOpen_)
  190981. {
  190982. closeDevice();
  190983. isOpen_ = false;
  190984. }
  190985. }
  190986. bool isOpen()
  190987. {
  190988. return isOpen_ && isThreadRunning();
  190989. }
  190990. int getCurrentBufferSizeSamples()
  190991. {
  190992. return bufferSizeSamples;
  190993. }
  190994. double getCurrentSampleRate()
  190995. {
  190996. return sampleRate;
  190997. }
  190998. int getCurrentBitDepth()
  190999. {
  191000. int i, bits = 256;
  191001. for (i = inChans.size(); --i >= 0;)
  191002. bits = jmin (bits, inChans[i]->bitDepth);
  191003. for (i = outChans.size(); --i >= 0;)
  191004. bits = jmin (bits, outChans[i]->bitDepth);
  191005. if (bits > 32)
  191006. bits = 16;
  191007. return bits;
  191008. }
  191009. const BitArray getActiveOutputChannels() const
  191010. {
  191011. return enabledOutputs;
  191012. }
  191013. const BitArray getActiveInputChannels() const
  191014. {
  191015. return enabledInputs;
  191016. }
  191017. int getOutputLatencyInSamples()
  191018. {
  191019. return (int) (getCurrentBufferSizeSamples() * 1.5);
  191020. }
  191021. int getInputLatencyInSamples()
  191022. {
  191023. return getOutputLatencyInSamples();
  191024. }
  191025. void start (AudioIODeviceCallback* call)
  191026. {
  191027. if (isOpen_ && call != 0 && ! isStarted)
  191028. {
  191029. if (! isThreadRunning())
  191030. {
  191031. // something gone wrong and the thread's stopped..
  191032. isOpen_ = false;
  191033. return;
  191034. }
  191035. call->audioDeviceAboutToStart (this);
  191036. const ScopedLock sl (startStopLock);
  191037. callback = call;
  191038. isStarted = true;
  191039. }
  191040. }
  191041. void stop()
  191042. {
  191043. if (isStarted)
  191044. {
  191045. AudioIODeviceCallback* const callbackLocal = callback;
  191046. {
  191047. const ScopedLock sl (startStopLock);
  191048. isStarted = false;
  191049. }
  191050. if (callbackLocal != 0)
  191051. callbackLocal->audioDeviceStopped();
  191052. }
  191053. }
  191054. bool isPlaying()
  191055. {
  191056. return isStarted && isOpen_ && isThreadRunning();
  191057. }
  191058. const String getLastError()
  191059. {
  191060. return lastError;
  191061. }
  191062. juce_UseDebuggingNewOperator
  191063. StringArray inChannels, outChannels;
  191064. int outputDeviceIndex, inputDeviceIndex;
  191065. private:
  191066. bool isOpen_;
  191067. bool isStarted;
  191068. String lastError;
  191069. OwnedArray <DSoundInternalInChannel> inChans;
  191070. OwnedArray <DSoundInternalOutChannel> outChans;
  191071. WaitableEvent startEvent;
  191072. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  191073. int volatile totalSamplesOut;
  191074. int64 volatile lastBlockTime;
  191075. double sampleRate;
  191076. BitArray enabledInputs, enabledOutputs;
  191077. HeapBlock <float*> inputBuffers, outputBuffers;
  191078. AudioIODeviceCallback* callback;
  191079. CriticalSection startStopLock;
  191080. DSoundAudioIODevice (const DSoundAudioIODevice&);
  191081. const DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  191082. const String openDevice (const BitArray& inputChannels,
  191083. const BitArray& outputChannels,
  191084. double sampleRate_,
  191085. int bufferSizeSamples_);
  191086. void closeDevice()
  191087. {
  191088. isStarted = false;
  191089. stopThread (5000);
  191090. inChans.clear();
  191091. outChans.clear();
  191092. int i;
  191093. for (i = 0; i < numInputBuffers; ++i)
  191094. juce_free (inputBuffers[i]);
  191095. inputBuffers.free();
  191096. numInputBuffers = 0;
  191097. for (i = 0; i < numOutputBuffers; ++i)
  191098. juce_free (outputBuffers[i]);
  191099. outputBuffers.free();
  191100. numOutputBuffers = 0;
  191101. }
  191102. void resync()
  191103. {
  191104. if (! threadShouldExit())
  191105. {
  191106. sleep (5);
  191107. int i;
  191108. for (i = 0; i < outChans.size(); ++i)
  191109. outChans.getUnchecked(i)->synchronisePosition();
  191110. for (i = 0; i < inChans.size(); ++i)
  191111. inChans.getUnchecked(i)->synchronisePosition();
  191112. }
  191113. }
  191114. public:
  191115. void run()
  191116. {
  191117. while (! threadShouldExit())
  191118. {
  191119. if (wait (100))
  191120. break;
  191121. }
  191122. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191123. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191124. while (! threadShouldExit())
  191125. {
  191126. int numToDo = 0;
  191127. uint32 startTime = Time::getMillisecondCounter();
  191128. int i;
  191129. for (i = inChans.size(); --i >= 0;)
  191130. {
  191131. inChans.getUnchecked(i)->doneFlag = false;
  191132. ++numToDo;
  191133. }
  191134. for (i = outChans.size(); --i >= 0;)
  191135. {
  191136. outChans.getUnchecked(i)->doneFlag = false;
  191137. ++numToDo;
  191138. }
  191139. if (numToDo > 0)
  191140. {
  191141. const int maxCount = 3;
  191142. int count = maxCount;
  191143. for (;;)
  191144. {
  191145. for (i = inChans.size(); --i >= 0;)
  191146. {
  191147. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191148. if ((! in->doneFlag) && in->service())
  191149. {
  191150. in->doneFlag = true;
  191151. --numToDo;
  191152. }
  191153. }
  191154. for (i = outChans.size(); --i >= 0;)
  191155. {
  191156. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191157. if ((! out->doneFlag) && out->service())
  191158. {
  191159. out->doneFlag = true;
  191160. --numToDo;
  191161. }
  191162. }
  191163. if (numToDo <= 0)
  191164. break;
  191165. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191166. {
  191167. resync();
  191168. break;
  191169. }
  191170. if (--count <= 0)
  191171. {
  191172. Sleep (1);
  191173. count = maxCount;
  191174. }
  191175. if (threadShouldExit())
  191176. return;
  191177. }
  191178. }
  191179. else
  191180. {
  191181. sleep (1);
  191182. }
  191183. const ScopedLock sl (startStopLock);
  191184. if (isStarted)
  191185. {
  191186. JUCE_TRY
  191187. {
  191188. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191189. numInputBuffers,
  191190. outputBuffers,
  191191. numOutputBuffers,
  191192. bufferSizeSamples);
  191193. }
  191194. JUCE_CATCH_EXCEPTION
  191195. totalSamplesOut += bufferSizeSamples;
  191196. }
  191197. else
  191198. {
  191199. for (i = 0; i < numOutputBuffers; ++i)
  191200. if (outputBuffers[i] != 0)
  191201. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191202. totalSamplesOut = 0;
  191203. sleep (1);
  191204. }
  191205. }
  191206. }
  191207. };
  191208. class DSoundAudioIODeviceType : public AudioIODeviceType
  191209. {
  191210. public:
  191211. DSoundAudioIODeviceType()
  191212. : AudioIODeviceType (T("DirectSound")),
  191213. hasScanned (false)
  191214. {
  191215. initialiseDSoundFunctions();
  191216. }
  191217. ~DSoundAudioIODeviceType()
  191218. {
  191219. }
  191220. void scanForDevices()
  191221. {
  191222. hasScanned = true;
  191223. outputDeviceNames.clear();
  191224. outputGuids.clear();
  191225. inputDeviceNames.clear();
  191226. inputGuids.clear();
  191227. if (dsDirectSoundEnumerateW != 0)
  191228. {
  191229. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191230. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191231. }
  191232. }
  191233. const StringArray getDeviceNames (const bool wantInputNames) const
  191234. {
  191235. jassert (hasScanned); // need to call scanForDevices() before doing this
  191236. return wantInputNames ? inputDeviceNames
  191237. : outputDeviceNames;
  191238. }
  191239. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191240. {
  191241. jassert (hasScanned); // need to call scanForDevices() before doing this
  191242. return 0;
  191243. }
  191244. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191245. {
  191246. jassert (hasScanned); // need to call scanForDevices() before doing this
  191247. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191248. if (d == 0)
  191249. return -1;
  191250. return asInput ? d->inputDeviceIndex
  191251. : d->outputDeviceIndex;
  191252. }
  191253. bool hasSeparateInputsAndOutputs() const { return true; }
  191254. AudioIODevice* createDevice (const String& outputDeviceName,
  191255. const String& inputDeviceName)
  191256. {
  191257. jassert (hasScanned); // need to call scanForDevices() before doing this
  191258. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191259. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191260. if (outputIndex >= 0 || inputIndex >= 0)
  191261. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191262. : inputDeviceName,
  191263. outputIndex, inputIndex);
  191264. return 0;
  191265. }
  191266. juce_UseDebuggingNewOperator
  191267. StringArray outputDeviceNames;
  191268. OwnedArray <GUID> outputGuids;
  191269. StringArray inputDeviceNames;
  191270. OwnedArray <GUID> inputGuids;
  191271. private:
  191272. bool hasScanned;
  191273. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191274. {
  191275. desc = desc.trim();
  191276. if (desc.isNotEmpty())
  191277. {
  191278. const String origDesc (desc);
  191279. int n = 2;
  191280. while (outputDeviceNames.contains (desc))
  191281. desc = origDesc + T(" (") + String (n++) + T(")");
  191282. outputDeviceNames.add (desc);
  191283. if (lpGUID != 0)
  191284. outputGuids.add (new GUID (*lpGUID));
  191285. else
  191286. outputGuids.add (0);
  191287. }
  191288. return TRUE;
  191289. }
  191290. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191291. {
  191292. return ((DSoundAudioIODeviceType*) object)
  191293. ->outputEnumProc (lpGUID, String (description));
  191294. }
  191295. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191296. {
  191297. return ((DSoundAudioIODeviceType*) object)
  191298. ->outputEnumProc (lpGUID, String (description));
  191299. }
  191300. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191301. {
  191302. desc = desc.trim();
  191303. if (desc.isNotEmpty())
  191304. {
  191305. const String origDesc (desc);
  191306. int n = 2;
  191307. while (inputDeviceNames.contains (desc))
  191308. desc = origDesc + T(" (") + String (n++) + T(")");
  191309. inputDeviceNames.add (desc);
  191310. if (lpGUID != 0)
  191311. inputGuids.add (new GUID (*lpGUID));
  191312. else
  191313. inputGuids.add (0);
  191314. }
  191315. return TRUE;
  191316. }
  191317. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191318. {
  191319. return ((DSoundAudioIODeviceType*) object)
  191320. ->inputEnumProc (lpGUID, String (description));
  191321. }
  191322. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191323. {
  191324. return ((DSoundAudioIODeviceType*) object)
  191325. ->inputEnumProc (lpGUID, String (description));
  191326. }
  191327. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191328. const DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191329. };
  191330. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191331. const BitArray& outputChannels,
  191332. double sampleRate_,
  191333. int bufferSizeSamples_)
  191334. {
  191335. closeDevice();
  191336. totalSamplesOut = 0;
  191337. sampleRate = sampleRate_;
  191338. if (bufferSizeSamples_ <= 0)
  191339. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191340. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191341. DSoundAudioIODeviceType dlh;
  191342. dlh.scanForDevices();
  191343. enabledInputs = inputChannels;
  191344. enabledInputs.setRange (inChannels.size(),
  191345. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191346. false);
  191347. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191348. inputBuffers.calloc (numInputBuffers + 2);
  191349. int i, numIns = 0;
  191350. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191351. {
  191352. float* left = 0;
  191353. float* right = 0;
  191354. if (enabledInputs[i])
  191355. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191356. if (enabledInputs[i + 1])
  191357. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191358. if (left != 0 || right != 0)
  191359. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191360. dlh.inputGuids [inputDeviceIndex],
  191361. (int) sampleRate, bufferSizeSamples,
  191362. left, right));
  191363. }
  191364. enabledOutputs = outputChannels;
  191365. enabledOutputs.setRange (outChannels.size(),
  191366. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191367. false);
  191368. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191369. outputBuffers.calloc (numOutputBuffers + 2);
  191370. int numOuts = 0;
  191371. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191372. {
  191373. float* left = 0;
  191374. float* right = 0;
  191375. if (enabledOutputs[i])
  191376. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191377. if (enabledOutputs[i + 1])
  191378. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191379. if (left != 0 || right != 0)
  191380. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191381. dlh.outputGuids [outputDeviceIndex],
  191382. (int) sampleRate, bufferSizeSamples,
  191383. left, right));
  191384. }
  191385. String error;
  191386. // boost our priority while opening the devices to try to get better sync between them
  191387. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191388. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191389. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191390. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191391. for (i = 0; i < outChans.size(); ++i)
  191392. {
  191393. error = outChans[i]->open();
  191394. if (error.isNotEmpty())
  191395. {
  191396. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191397. + T(": \"") + error + T("\"");
  191398. break;
  191399. }
  191400. }
  191401. if (error.isEmpty())
  191402. {
  191403. for (i = 0; i < inChans.size(); ++i)
  191404. {
  191405. error = inChans[i]->open();
  191406. if (error.isNotEmpty())
  191407. {
  191408. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191409. + T(": \"") + error + T("\"");
  191410. break;
  191411. }
  191412. }
  191413. }
  191414. if (error.isEmpty())
  191415. {
  191416. totalSamplesOut = 0;
  191417. for (i = 0; i < outChans.size(); ++i)
  191418. outChans.getUnchecked(i)->synchronisePosition();
  191419. for (i = 0; i < inChans.size(); ++i)
  191420. inChans.getUnchecked(i)->synchronisePosition();
  191421. startThread (9);
  191422. sleep (10);
  191423. notify();
  191424. }
  191425. else
  191426. {
  191427. log (error);
  191428. }
  191429. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191430. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191431. return error;
  191432. }
  191433. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191434. {
  191435. return new DSoundAudioIODeviceType();
  191436. }
  191437. #undef log
  191438. #endif
  191439. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191440. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191441. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191442. // compiled on its own).
  191443. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191444. #if 1
  191445. const String getAudioErrorDesc (HRESULT hr)
  191446. {
  191447. const char* e = 0;
  191448. switch (hr)
  191449. {
  191450. case E_POINTER: e = "E_POINTER"; break;
  191451. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191452. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191453. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191454. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191455. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191456. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191457. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191458. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191459. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191460. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191461. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191462. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191463. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191464. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191465. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191466. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191467. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191468. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191469. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191470. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191471. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191472. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191473. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191474. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191475. default: return String::toHexString ((int) hr);
  191476. }
  191477. return e;
  191478. }
  191479. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191480. #define OK(a) wasapi_checkResult(a)
  191481. static bool wasapi_checkResult (HRESULT hr)
  191482. {
  191483. logFailure (hr);
  191484. return SUCCEEDED (hr);
  191485. }
  191486. #else
  191487. #define logFailure(hr) {}
  191488. #define OK(a) SUCCEEDED(a)
  191489. #endif
  191490. static const String wasapi_getDeviceID (IMMDevice* const device)
  191491. {
  191492. String s;
  191493. WCHAR* deviceId = 0;
  191494. if (OK (device->GetId (&deviceId)))
  191495. {
  191496. s = String (deviceId);
  191497. CoTaskMemFree (deviceId);
  191498. }
  191499. return s;
  191500. }
  191501. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191502. {
  191503. EDataFlow flow = eRender;
  191504. ComSmartPtr <IMMEndpoint> endPoint;
  191505. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191506. (void) OK (endPoint->GetDataFlow (&flow));
  191507. return flow;
  191508. }
  191509. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191510. {
  191511. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191512. }
  191513. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191514. {
  191515. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191516. : sizeof (WAVEFORMATEX));
  191517. }
  191518. class WASAPIDeviceBase
  191519. {
  191520. public:
  191521. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191522. : device (device_),
  191523. sampleRate (0),
  191524. numChannels (0),
  191525. actualNumChannels (0),
  191526. defaultSampleRate (0),
  191527. minBufferSize (0),
  191528. defaultBufferSize (0),
  191529. latencySamples (0),
  191530. useExclusiveMode (useExclusiveMode_)
  191531. {
  191532. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191533. ComSmartPtr <IAudioClient> tempClient (createClient());
  191534. if (tempClient == 0)
  191535. return;
  191536. REFERENCE_TIME defaultPeriod, minPeriod;
  191537. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191538. return;
  191539. WAVEFORMATEX* mixFormat = 0;
  191540. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191541. return;
  191542. WAVEFORMATEXTENSIBLE format;
  191543. wasapi_copyWavFormat (format, mixFormat);
  191544. CoTaskMemFree (mixFormat);
  191545. actualNumChannels = numChannels = format.Format.nChannels;
  191546. defaultSampleRate = format.Format.nSamplesPerSec;
  191547. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191548. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191549. FloatElementComparator<double> comparator;
  191550. rates.addSorted (comparator, defaultSampleRate);
  191551. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191552. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191553. {
  191554. if (ratesToTest[i] == defaultSampleRate)
  191555. continue;
  191556. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191557. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191558. (WAVEFORMATEX*) &format, 0)))
  191559. if (! rates.contains (ratesToTest[i]))
  191560. rates.addSorted (comparator, ratesToTest[i]);
  191561. }
  191562. }
  191563. ~WASAPIDeviceBase()
  191564. {
  191565. device = 0;
  191566. CloseHandle (clientEvent);
  191567. }
  191568. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191569. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191570. {
  191571. sampleRate = newSampleRate;
  191572. channels = newChannels;
  191573. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191574. numChannels = channels.getHighestBit() + 1;
  191575. if (numChannels == 0)
  191576. return true;
  191577. client = createClient();
  191578. if (client != 0
  191579. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191580. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191581. {
  191582. channelMaps.clear();
  191583. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191584. if (channels[i])
  191585. channelMaps.add (i);
  191586. REFERENCE_TIME latency;
  191587. if (OK (client->GetStreamLatency (&latency)))
  191588. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191589. (void) OK (client->GetBufferSize (&actualBufferSize));
  191590. return OK (client->SetEventHandle (clientEvent));
  191591. }
  191592. return false;
  191593. }
  191594. void closeClient()
  191595. {
  191596. if (client != 0)
  191597. client->Stop();
  191598. client = 0;
  191599. ResetEvent (clientEvent);
  191600. }
  191601. ComSmartPtr <IMMDevice> device;
  191602. ComSmartPtr <IAudioClient> client;
  191603. double sampleRate, defaultSampleRate;
  191604. int numChannels, actualNumChannels;
  191605. int minBufferSize, defaultBufferSize, latencySamples;
  191606. const bool useExclusiveMode;
  191607. Array <double> rates;
  191608. HANDLE clientEvent;
  191609. BitArray channels;
  191610. AudioDataConverters::DataFormat dataFormat;
  191611. Array <int> channelMaps;
  191612. UINT32 actualBufferSize;
  191613. int bytesPerSample;
  191614. private:
  191615. const ComSmartPtr <IAudioClient> createClient()
  191616. {
  191617. ComSmartPtr <IAudioClient> client;
  191618. if (device != 0)
  191619. {
  191620. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191621. logFailure (hr);
  191622. }
  191623. return client;
  191624. }
  191625. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191626. {
  191627. WAVEFORMATEXTENSIBLE format;
  191628. zerostruct (format);
  191629. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191630. {
  191631. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191632. }
  191633. else
  191634. {
  191635. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191636. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191637. }
  191638. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191639. format.Format.nChannels = (WORD) numChannels;
  191640. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191641. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191642. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191643. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191644. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191645. switch (numChannels)
  191646. {
  191647. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191648. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191649. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191650. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191651. 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;
  191652. default: break;
  191653. }
  191654. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191655. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191656. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191657. logFailure (hr);
  191658. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191659. {
  191660. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191661. hr = S_OK;
  191662. }
  191663. CoTaskMemFree (nearestFormat);
  191664. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191665. if (useExclusiveMode)
  191666. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191667. GUID session;
  191668. if (hr == S_OK
  191669. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191670. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191671. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191672. {
  191673. actualNumChannels = format.Format.nChannels;
  191674. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191675. bytesPerSample = format.Format.wBitsPerSample / 8;
  191676. dataFormat = isFloat ? AudioDataConverters::float32LE
  191677. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191678. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191679. : AudioDataConverters::int16LE)));
  191680. return true;
  191681. }
  191682. return false;
  191683. }
  191684. };
  191685. class WASAPIInputDevice : public WASAPIDeviceBase
  191686. {
  191687. public:
  191688. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191689. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191690. reservoir (1, 1)
  191691. {
  191692. }
  191693. ~WASAPIInputDevice()
  191694. {
  191695. close();
  191696. }
  191697. bool open (const double newSampleRate, const BitArray& newChannels)
  191698. {
  191699. reservoirSize = 0;
  191700. reservoirCapacity = 16384;
  191701. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191702. return openClient (newSampleRate, newChannels)
  191703. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191704. }
  191705. void close()
  191706. {
  191707. closeClient();
  191708. captureClient = 0;
  191709. reservoir.setSize (0);
  191710. }
  191711. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191712. {
  191713. if (numChannels <= 0)
  191714. return;
  191715. int offset = 0;
  191716. while (bufferSize > 0)
  191717. {
  191718. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191719. {
  191720. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191721. for (int i = 0; i < numDestBuffers; ++i)
  191722. {
  191723. float* const dest = destBuffers[i] + offset;
  191724. const int srcChan = channelMaps.getUnchecked(i);
  191725. switch (dataFormat)
  191726. {
  191727. case AudioDataConverters::float32LE:
  191728. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191729. break;
  191730. case AudioDataConverters::int32LE:
  191731. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191732. break;
  191733. case AudioDataConverters::int24LE:
  191734. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191735. break;
  191736. case AudioDataConverters::int16LE:
  191737. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191738. break;
  191739. default: jassertfalse; break;
  191740. }
  191741. }
  191742. bufferSize -= samplesToDo;
  191743. offset += samplesToDo;
  191744. reservoirSize -= samplesToDo;
  191745. }
  191746. else
  191747. {
  191748. UINT32 packetLength = 0;
  191749. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191750. break;
  191751. if (packetLength == 0)
  191752. {
  191753. if (thread.threadShouldExit())
  191754. break;
  191755. Thread::sleep (1);
  191756. continue;
  191757. }
  191758. uint8* inputData = 0;
  191759. UINT32 numSamplesAvailable;
  191760. DWORD flags;
  191761. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191762. {
  191763. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191764. for (int i = 0; i < numDestBuffers; ++i)
  191765. {
  191766. float* const dest = destBuffers[i] + offset;
  191767. const int srcChan = channelMaps.getUnchecked(i);
  191768. switch (dataFormat)
  191769. {
  191770. case AudioDataConverters::float32LE:
  191771. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191772. break;
  191773. case AudioDataConverters::int32LE:
  191774. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191775. break;
  191776. case AudioDataConverters::int24LE:
  191777. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191778. break;
  191779. case AudioDataConverters::int16LE:
  191780. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191781. break;
  191782. default: jassertfalse; break;
  191783. }
  191784. }
  191785. bufferSize -= samplesToDo;
  191786. offset += samplesToDo;
  191787. if (samplesToDo < numSamplesAvailable)
  191788. {
  191789. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191790. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191791. bytesPerSample * actualNumChannels * reservoirSize);
  191792. }
  191793. captureClient->ReleaseBuffer (numSamplesAvailable);
  191794. }
  191795. }
  191796. }
  191797. }
  191798. ComSmartPtr <IAudioCaptureClient> captureClient;
  191799. MemoryBlock reservoir;
  191800. int reservoirSize, reservoirCapacity;
  191801. };
  191802. class WASAPIOutputDevice : public WASAPIDeviceBase
  191803. {
  191804. public:
  191805. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191806. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191807. {
  191808. }
  191809. ~WASAPIOutputDevice()
  191810. {
  191811. close();
  191812. }
  191813. bool open (const double newSampleRate, const BitArray& newChannels)
  191814. {
  191815. return openClient (newSampleRate, newChannels)
  191816. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191817. }
  191818. void close()
  191819. {
  191820. closeClient();
  191821. renderClient = 0;
  191822. }
  191823. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191824. {
  191825. if (numChannels <= 0)
  191826. return;
  191827. int offset = 0;
  191828. while (bufferSize > 0)
  191829. {
  191830. UINT32 padding = 0;
  191831. if (! OK (client->GetCurrentPadding (&padding)))
  191832. return;
  191833. int samplesToDo = useExclusiveMode ? bufferSize
  191834. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191835. if (samplesToDo <= 0)
  191836. {
  191837. if (thread.threadShouldExit())
  191838. break;
  191839. Thread::sleep (0);
  191840. continue;
  191841. }
  191842. uint8* outputData = 0;
  191843. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191844. {
  191845. for (int i = 0; i < numSrcBuffers; ++i)
  191846. {
  191847. const float* const source = srcBuffers[i] + offset;
  191848. const int destChan = channelMaps.getUnchecked(i);
  191849. switch (dataFormat)
  191850. {
  191851. case AudioDataConverters::float32LE:
  191852. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191853. break;
  191854. case AudioDataConverters::int32LE:
  191855. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191856. break;
  191857. case AudioDataConverters::int24LE:
  191858. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191859. break;
  191860. case AudioDataConverters::int16LE:
  191861. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191862. break;
  191863. default: jassertfalse; break;
  191864. }
  191865. }
  191866. renderClient->ReleaseBuffer (samplesToDo, 0);
  191867. offset += samplesToDo;
  191868. bufferSize -= samplesToDo;
  191869. }
  191870. }
  191871. }
  191872. ComSmartPtr <IAudioRenderClient> renderClient;
  191873. };
  191874. class WASAPIAudioIODevice : public AudioIODevice,
  191875. public Thread
  191876. {
  191877. public:
  191878. WASAPIAudioIODevice (const String& deviceName,
  191879. const String& outputDeviceId_,
  191880. const String& inputDeviceId_,
  191881. const bool useExclusiveMode_)
  191882. : AudioIODevice (deviceName, "Windows Audio"),
  191883. Thread ("Juce WASAPI"),
  191884. isOpen_ (false),
  191885. isStarted (false),
  191886. outputDevice (0),
  191887. outputDeviceId (outputDeviceId_),
  191888. inputDevice (0),
  191889. inputDeviceId (inputDeviceId_),
  191890. useExclusiveMode (useExclusiveMode_),
  191891. currentBufferSizeSamples (0),
  191892. currentSampleRate (0),
  191893. callback (0)
  191894. {
  191895. }
  191896. ~WASAPIAudioIODevice()
  191897. {
  191898. close();
  191899. deleteAndZero (inputDevice);
  191900. deleteAndZero (outputDevice);
  191901. }
  191902. bool initialise()
  191903. {
  191904. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191905. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191906. latencyIn = latencyOut = 0;
  191907. Array <double> ratesIn, ratesOut;
  191908. if (createDevices())
  191909. {
  191910. jassert (inputDevice != 0 || outputDevice != 0);
  191911. if (inputDevice != 0 && outputDevice != 0)
  191912. {
  191913. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191914. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191915. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191916. sampleRates = inputDevice->rates;
  191917. sampleRates.removeValuesNotIn (outputDevice->rates);
  191918. }
  191919. else
  191920. {
  191921. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191922. defaultSampleRate = d->defaultSampleRate;
  191923. minBufferSize = d->minBufferSize;
  191924. defaultBufferSize = d->defaultBufferSize;
  191925. sampleRates = d->rates;
  191926. }
  191927. IntegerElementComparator<int> comparator;
  191928. bufferSizes.addSorted (comparator, defaultBufferSize);
  191929. if (minBufferSize != defaultBufferSize)
  191930. bufferSizes.addSorted (comparator, minBufferSize);
  191931. int n = 64;
  191932. for (int i = 0; i < 40; ++i)
  191933. {
  191934. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191935. bufferSizes.addSorted (comparator, n);
  191936. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191937. }
  191938. return true;
  191939. }
  191940. return false;
  191941. }
  191942. const StringArray getOutputChannelNames()
  191943. {
  191944. StringArray outChannels;
  191945. if (outputDevice != 0)
  191946. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191947. outChannels.add ("Output channel " + String (i));
  191948. return outChannels;
  191949. }
  191950. const StringArray getInputChannelNames()
  191951. {
  191952. StringArray inChannels;
  191953. if (inputDevice != 0)
  191954. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191955. inChannels.add ("Input channel " + String (i));
  191956. return inChannels;
  191957. }
  191958. int getNumSampleRates() { return sampleRates.size(); }
  191959. double getSampleRate (int index) { return sampleRates [index]; }
  191960. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191961. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191962. int getDefaultBufferSize() { return defaultBufferSize; }
  191963. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191964. double getCurrentSampleRate() { return currentSampleRate; }
  191965. int getCurrentBitDepth() { return 32; }
  191966. int getOutputLatencyInSamples() { return latencyOut; }
  191967. int getInputLatencyInSamples() { return latencyIn; }
  191968. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  191969. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  191970. const String getLastError() { return lastError; }
  191971. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  191972. double sampleRate, int bufferSizeSamples)
  191973. {
  191974. close();
  191975. lastError = String::empty;
  191976. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191977. {
  191978. lastError = "The input and output devices don't share a common sample rate!";
  191979. return lastError;
  191980. }
  191981. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191982. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191983. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191984. {
  191985. lastError = "Couldn't open the input device!";
  191986. return lastError;
  191987. }
  191988. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191989. {
  191990. close();
  191991. lastError = "Couldn't open the output device!";
  191992. return lastError;
  191993. }
  191994. if (inputDevice != 0)
  191995. ResetEvent (inputDevice->clientEvent);
  191996. if (outputDevice != 0)
  191997. ResetEvent (outputDevice->clientEvent);
  191998. startThread (8);
  191999. Thread::sleep (5);
  192000. if (inputDevice != 0 && inputDevice->client != 0)
  192001. {
  192002. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  192003. HRESULT hr = inputDevice->client->Start();
  192004. logFailure (hr); //xxx handle this
  192005. }
  192006. if (outputDevice != 0 && outputDevice->client != 0)
  192007. {
  192008. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  192009. HRESULT hr = outputDevice->client->Start();
  192010. logFailure (hr); //xxx handle this
  192011. }
  192012. isOpen_ = true;
  192013. return lastError;
  192014. }
  192015. void close()
  192016. {
  192017. stop();
  192018. if (inputDevice != 0)
  192019. SetEvent (inputDevice->clientEvent);
  192020. if (outputDevice != 0)
  192021. SetEvent (outputDevice->clientEvent);
  192022. stopThread (5000);
  192023. if (inputDevice != 0)
  192024. inputDevice->close();
  192025. if (outputDevice != 0)
  192026. outputDevice->close();
  192027. isOpen_ = false;
  192028. }
  192029. bool isOpen() { return isOpen_ && isThreadRunning(); }
  192030. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  192031. void start (AudioIODeviceCallback* call)
  192032. {
  192033. if (isOpen_ && call != 0 && ! isStarted)
  192034. {
  192035. if (! isThreadRunning())
  192036. {
  192037. // something's gone wrong and the thread's stopped..
  192038. isOpen_ = false;
  192039. return;
  192040. }
  192041. call->audioDeviceAboutToStart (this);
  192042. const ScopedLock sl (startStopLock);
  192043. callback = call;
  192044. isStarted = true;
  192045. }
  192046. }
  192047. void stop()
  192048. {
  192049. if (isStarted)
  192050. {
  192051. AudioIODeviceCallback* const callbackLocal = callback;
  192052. {
  192053. const ScopedLock sl (startStopLock);
  192054. isStarted = false;
  192055. }
  192056. if (callbackLocal != 0)
  192057. callbackLocal->audioDeviceStopped();
  192058. }
  192059. }
  192060. void setMMThreadPriority()
  192061. {
  192062. DynamicLibraryLoader dll ("avrt.dll");
  192063. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  192064. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  192065. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  192066. {
  192067. DWORD dummy = 0;
  192068. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  192069. if (h != 0)
  192070. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  192071. }
  192072. }
  192073. void run()
  192074. {
  192075. setMMThreadPriority();
  192076. const int bufferSize = currentBufferSizeSamples;
  192077. HANDLE events[2];
  192078. int numEvents = 0;
  192079. if (inputDevice != 0)
  192080. events [numEvents++] = inputDevice->clientEvent;
  192081. if (outputDevice != 0)
  192082. events [numEvents++] = outputDevice->clientEvent;
  192083. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  192084. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  192085. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  192086. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  192087. float** const inputBuffers = ins.getArrayOfChannels();
  192088. float** const outputBuffers = outs.getArrayOfChannels();
  192089. ins.clear();
  192090. while (! threadShouldExit())
  192091. {
  192092. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  192093. : WaitForMultipleObjects (numEvents, events, true, 1000);
  192094. if (result == WAIT_TIMEOUT)
  192095. continue;
  192096. if (threadShouldExit())
  192097. break;
  192098. if (inputDevice != 0)
  192099. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  192100. // Make the callback..
  192101. {
  192102. const ScopedLock sl (startStopLock);
  192103. if (isStarted)
  192104. {
  192105. JUCE_TRY
  192106. {
  192107. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  192108. numInputBuffers,
  192109. outputBuffers,
  192110. numOutputBuffers,
  192111. bufferSize);
  192112. }
  192113. JUCE_CATCH_EXCEPTION
  192114. }
  192115. else
  192116. {
  192117. outs.clear();
  192118. }
  192119. }
  192120. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  192121. continue;
  192122. if (outputDevice != 0)
  192123. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192124. }
  192125. }
  192126. juce_UseDebuggingNewOperator
  192127. String outputDeviceId, inputDeviceId;
  192128. String lastError;
  192129. private:
  192130. // Device stats...
  192131. WASAPIInputDevice* inputDevice;
  192132. WASAPIOutputDevice* outputDevice;
  192133. const bool useExclusiveMode;
  192134. double defaultSampleRate;
  192135. int minBufferSize, defaultBufferSize;
  192136. int latencyIn, latencyOut;
  192137. Array <double> sampleRates;
  192138. Array <int> bufferSizes;
  192139. // Active state...
  192140. bool isOpen_, isStarted;
  192141. int currentBufferSizeSamples;
  192142. double currentSampleRate;
  192143. AudioIODeviceCallback* callback;
  192144. CriticalSection startStopLock;
  192145. bool createDevices()
  192146. {
  192147. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192148. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192149. return false;
  192150. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192151. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192152. return false;
  192153. UINT32 numDevices = 0;
  192154. if (! OK (deviceCollection->GetCount (&numDevices)))
  192155. return false;
  192156. for (UINT32 i = 0; i < numDevices; ++i)
  192157. {
  192158. ComSmartPtr <IMMDevice> device;
  192159. if (! OK (deviceCollection->Item (i, &device)))
  192160. continue;
  192161. const String deviceId (wasapi_getDeviceID (device));
  192162. if (deviceId.isEmpty())
  192163. continue;
  192164. const EDataFlow flow = wasapi_getDataFlow (device);
  192165. if (deviceId == inputDeviceId && flow == eCapture)
  192166. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  192167. else if (deviceId == outputDeviceId && flow == eRender)
  192168. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  192169. }
  192170. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192171. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192172. }
  192173. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192174. const WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192175. };
  192176. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192177. {
  192178. public:
  192179. WASAPIAudioIODeviceType()
  192180. : AudioIODeviceType (T("Windows Audio")),
  192181. hasScanned (false)
  192182. {
  192183. }
  192184. ~WASAPIAudioIODeviceType()
  192185. {
  192186. }
  192187. void scanForDevices()
  192188. {
  192189. hasScanned = true;
  192190. outputDeviceNames.clear();
  192191. inputDeviceNames.clear();
  192192. outputDeviceIds.clear();
  192193. inputDeviceIds.clear();
  192194. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192195. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192196. return;
  192197. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192198. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192199. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192200. UINT32 numDevices = 0;
  192201. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192202. && OK (deviceCollection->GetCount (&numDevices))))
  192203. return;
  192204. for (UINT32 i = 0; i < numDevices; ++i)
  192205. {
  192206. ComSmartPtr <IMMDevice> device;
  192207. if (! OK (deviceCollection->Item (i, &device)))
  192208. continue;
  192209. const String deviceId (wasapi_getDeviceID (device));
  192210. DWORD state = 0;
  192211. if (! OK (device->GetState (&state)))
  192212. continue;
  192213. if (state != DEVICE_STATE_ACTIVE)
  192214. continue;
  192215. String name;
  192216. {
  192217. ComSmartPtr <IPropertyStore> properties;
  192218. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192219. continue;
  192220. PROPVARIANT value;
  192221. PropVariantInit (&value);
  192222. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192223. name = value.pwszVal;
  192224. PropVariantClear (&value);
  192225. }
  192226. const EDataFlow flow = wasapi_getDataFlow (device);
  192227. if (flow == eRender)
  192228. {
  192229. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192230. outputDeviceIds.insert (index, deviceId);
  192231. outputDeviceNames.insert (index, name);
  192232. }
  192233. else if (flow == eCapture)
  192234. {
  192235. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192236. inputDeviceIds.insert (index, deviceId);
  192237. inputDeviceNames.insert (index, name);
  192238. }
  192239. }
  192240. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192241. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192242. }
  192243. const StringArray getDeviceNames (const bool wantInputNames) const
  192244. {
  192245. jassert (hasScanned); // need to call scanForDevices() before doing this
  192246. return wantInputNames ? inputDeviceNames
  192247. : outputDeviceNames;
  192248. }
  192249. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192250. {
  192251. jassert (hasScanned); // need to call scanForDevices() before doing this
  192252. return 0;
  192253. }
  192254. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192255. {
  192256. jassert (hasScanned); // need to call scanForDevices() before doing this
  192257. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192258. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192259. : outputDeviceIds.indexOf (d->outputDeviceId));
  192260. }
  192261. bool hasSeparateInputsAndOutputs() const { return true; }
  192262. AudioIODevice* createDevice (const String& outputDeviceName,
  192263. const String& inputDeviceName)
  192264. {
  192265. jassert (hasScanned); // need to call scanForDevices() before doing this
  192266. const bool useExclusiveMode = false;
  192267. WASAPIAudioIODevice* d = 0;
  192268. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192269. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192270. if (outputIndex >= 0 || inputIndex >= 0)
  192271. {
  192272. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192273. : inputDeviceName,
  192274. outputDeviceIds [outputIndex],
  192275. inputDeviceIds [inputIndex],
  192276. useExclusiveMode);
  192277. if (! d->initialise())
  192278. deleteAndZero (d);
  192279. }
  192280. return d;
  192281. }
  192282. juce_UseDebuggingNewOperator
  192283. StringArray outputDeviceNames, outputDeviceIds;
  192284. StringArray inputDeviceNames, inputDeviceIds;
  192285. private:
  192286. bool hasScanned;
  192287. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192288. {
  192289. String s;
  192290. IMMDevice* dev = 0;
  192291. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192292. eMultimedia, &dev)))
  192293. {
  192294. WCHAR* deviceId = 0;
  192295. if (OK (dev->GetId (&deviceId)))
  192296. {
  192297. s = String (deviceId);
  192298. CoTaskMemFree (deviceId);
  192299. }
  192300. dev->Release();
  192301. }
  192302. return s;
  192303. }
  192304. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192305. const WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192306. };
  192307. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192308. {
  192309. return new WASAPIAudioIODeviceType();
  192310. }
  192311. #undef logFailure
  192312. #undef OK
  192313. #endif
  192314. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  192315. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  192316. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192317. // compiled on its own).
  192318. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192319. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192320. {
  192321. public:
  192322. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192323. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192324. const ComSmartPtr <IBaseFilter>& filter_,
  192325. int minWidth, int minHeight,
  192326. int maxWidth, int maxHeight)
  192327. : owner (owner_),
  192328. captureGraphBuilder (captureGraphBuilder_),
  192329. filter (filter_),
  192330. ok (false),
  192331. imageNeedsFlipping (false),
  192332. width (0),
  192333. height (0),
  192334. activeUsers (0),
  192335. recordNextFrameTime (false),
  192336. activeImage (0),
  192337. loadingImage (0)
  192338. {
  192339. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192340. if (FAILED (hr))
  192341. return;
  192342. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192343. if (FAILED (hr))
  192344. return;
  192345. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192346. if (FAILED (hr))
  192347. return;
  192348. {
  192349. ComSmartPtr <IAMStreamConfig> streamConfig;
  192350. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE,
  192351. 0,
  192352. filter,
  192353. IID_IAMStreamConfig,
  192354. (void**) &streamConfig);
  192355. if (streamConfig != 0)
  192356. {
  192357. getVideoSizes (streamConfig);
  192358. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192359. return;
  192360. }
  192361. }
  192362. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192363. if (FAILED (hr))
  192364. return;
  192365. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192366. if (FAILED (hr))
  192367. return;
  192368. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192369. if (FAILED (hr))
  192370. return;
  192371. if (! connectFilters (filter, smartTee))
  192372. return;
  192373. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192374. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192375. if (FAILED (hr))
  192376. return;
  192377. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192378. if (FAILED (hr))
  192379. return;
  192380. AM_MEDIA_TYPE mt;
  192381. zerostruct (mt);
  192382. mt.majortype = MEDIATYPE_Video;
  192383. mt.subtype = MEDIASUBTYPE_RGB24;
  192384. mt.formattype = FORMAT_VideoInfo;
  192385. sampleGrabber->SetMediaType (&mt);
  192386. callback = new GrabberCallback (*this);
  192387. sampleGrabber->SetCallback (callback, 1);
  192388. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192389. if (FAILED (hr))
  192390. return;
  192391. ComSmartPtr <IPin> grabberInputPin;
  192392. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192393. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192394. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192395. return;
  192396. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192397. if (FAILED (hr))
  192398. return;
  192399. zerostruct (mt);
  192400. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192401. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192402. width = pVih->bmiHeader.biWidth;
  192403. height = pVih->bmiHeader.biHeight;
  192404. ComSmartPtr <IBaseFilter> nullFilter;
  192405. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192406. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192407. if (connectFilters (sampleGrabberBase, nullFilter)
  192408. && addGraphToRot())
  192409. {
  192410. activeImage = new Image (Image::RGB, width, height, true);
  192411. loadingImage = new Image (Image::RGB, width, height, true);
  192412. ok = true;
  192413. }
  192414. }
  192415. ~DShowCameraDeviceInteral()
  192416. {
  192417. if (mediaControl != 0)
  192418. mediaControl->Stop();
  192419. removeGraphFromRot();
  192420. for (int i = viewerComps.size(); --i >= 0;)
  192421. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192422. callback = 0;
  192423. graphBuilder = 0;
  192424. sampleGrabber = 0;
  192425. mediaControl = 0;
  192426. filter = 0;
  192427. captureGraphBuilder = 0;
  192428. smartTee = 0;
  192429. smartTeePreviewOutputPin = 0;
  192430. smartTeeCaptureOutputPin = 0;
  192431. mux = 0;
  192432. fileWriter = 0;
  192433. delete activeImage;
  192434. delete loadingImage;
  192435. }
  192436. void addUser()
  192437. {
  192438. if (ok && activeUsers++ == 0)
  192439. mediaControl->Run();
  192440. }
  192441. void removeUser()
  192442. {
  192443. if (ok && --activeUsers == 0)
  192444. mediaControl->Stop();
  192445. }
  192446. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192447. {
  192448. if (recordNextFrameTime)
  192449. {
  192450. const double defaultCameraLatency = 0.1;
  192451. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192452. recordNextFrameTime = false;
  192453. ComSmartPtr <IPin> pin;
  192454. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192455. {
  192456. ComSmartPtr <IAMPushSource> pushSource;
  192457. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192458. if (pushSource != 0)
  192459. {
  192460. REFERENCE_TIME latency = 0;
  192461. hr = pushSource->GetLatency (&latency);
  192462. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192463. }
  192464. }
  192465. }
  192466. imageSwapLock.enter();
  192467. const int lineStride = width * 3;
  192468. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192469. for (int i = 0; i < height; ++i)
  192470. memcpy (destData.getLinePointer ((height - 1) - i),
  192471. buffer + lineStride * i,
  192472. lineStride);
  192473. imageNeedsFlipping = true;
  192474. imageSwapLock.exit();
  192475. callListeners (*loadingImage);
  192476. sendChangeMessage (this);
  192477. }
  192478. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192479. {
  192480. if (imageNeedsFlipping)
  192481. {
  192482. imageSwapLock.enter();
  192483. swapVariables (loadingImage, activeImage);
  192484. imageNeedsFlipping = false;
  192485. imageSwapLock.exit();
  192486. }
  192487. RectanglePlacement rp (RectanglePlacement::centred);
  192488. double dx = 0, dy = 0, dw = width, dh = height;
  192489. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192490. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192491. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192492. g.saveState();
  192493. g.excludeClipRegion (rx, ry, rw, rh);
  192494. g.fillAll (Colours::black);
  192495. g.restoreState();
  192496. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192497. }
  192498. bool createFileCaptureFilter (const File& file)
  192499. {
  192500. removeFileCaptureFilter();
  192501. file.deleteFile();
  192502. mediaControl->Stop();
  192503. firstRecordedTime = Time();
  192504. recordNextFrameTime = true;
  192505. HRESULT hr = mux.CoCreateInstance (CLSID_AviDest, CLSCTX_INPROC_SERVER);
  192506. if (SUCCEEDED (hr))
  192507. {
  192508. hr = graphBuilder->AddFilter (mux, _T("AVI Mux"));
  192509. if (SUCCEEDED (hr))
  192510. {
  192511. fileWriter.CoCreateInstance (CLSID_FileWriter, CLSCTX_INPROC_SERVER);
  192512. if (SUCCEEDED (hr))
  192513. {
  192514. ComSmartPtr <IFileSinkFilter> fileSink;
  192515. hr = fileWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192516. if (SUCCEEDED (hr))
  192517. {
  192518. AM_MEDIA_TYPE mt;
  192519. zerostruct (mt);
  192520. mt.majortype = MEDIATYPE_Stream;
  192521. mt.subtype = MEDIASUBTYPE_Avi;
  192522. mt.formattype = FORMAT_VideoInfo;
  192523. hr = fileSink->SetFileName (file.getFullPathName(), &mt);
  192524. if (SUCCEEDED (hr))
  192525. {
  192526. hr = graphBuilder->AddFilter (fileWriter, _T("File Writer"));
  192527. if (SUCCEEDED (hr))
  192528. {
  192529. ComSmartPtr <IPin> muxInputPin, muxOutputPin, writerInput;
  192530. if (getPin (mux, PINDIR_INPUT, &muxInputPin)
  192531. && getPin (mux, PINDIR_OUTPUT, &muxOutputPin)
  192532. && getPin (fileWriter, PINDIR_INPUT, &writerInput))
  192533. {
  192534. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, muxInputPin);
  192535. if (SUCCEEDED (hr))
  192536. {
  192537. hr = graphBuilder->Connect (muxOutputPin, writerInput);
  192538. if (SUCCEEDED (hr))
  192539. {
  192540. if (ok && activeUsers > 0)
  192541. mediaControl->Run();
  192542. return true;
  192543. }
  192544. }
  192545. }
  192546. }
  192547. }
  192548. }
  192549. }
  192550. }
  192551. }
  192552. removeFileCaptureFilter();
  192553. if (ok && activeUsers > 0)
  192554. mediaControl->Run();
  192555. return false;
  192556. }
  192557. void removeFileCaptureFilter()
  192558. {
  192559. mediaControl->Stop();
  192560. if (mux != 0)
  192561. {
  192562. graphBuilder->RemoveFilter (mux);
  192563. mux = 0;
  192564. }
  192565. if (fileWriter != 0)
  192566. {
  192567. graphBuilder->RemoveFilter (fileWriter);
  192568. fileWriter = 0;
  192569. }
  192570. if (ok && activeUsers > 0)
  192571. mediaControl->Run();
  192572. }
  192573. void addListener (CameraImageListener* listenerToAdd)
  192574. {
  192575. const ScopedLock sl (listenerLock);
  192576. if (listeners.size() == 0)
  192577. addUser();
  192578. listeners.addIfNotAlreadyThere (listenerToAdd);
  192579. }
  192580. void removeListener (CameraImageListener* listenerToRemove)
  192581. {
  192582. const ScopedLock sl (listenerLock);
  192583. listeners.removeValue (listenerToRemove);
  192584. if (listeners.size() == 0)
  192585. removeUser();
  192586. }
  192587. void callListeners (Image& image)
  192588. {
  192589. const ScopedLock sl (listenerLock);
  192590. for (int i = listeners.size(); --i >= 0;)
  192591. {
  192592. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192593. if (l != 0)
  192594. l->imageReceived (image);
  192595. }
  192596. }
  192597. class DShowCaptureViewerComp : public Component,
  192598. public ChangeListener
  192599. {
  192600. public:
  192601. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192602. : owner (owner_)
  192603. {
  192604. setOpaque (true);
  192605. owner->addChangeListener (this);
  192606. owner->addUser();
  192607. owner->viewerComps.add (this);
  192608. setSize (owner_->width, owner_->height);
  192609. }
  192610. ~DShowCaptureViewerComp()
  192611. {
  192612. if (owner != 0)
  192613. {
  192614. owner->viewerComps.removeValue (this);
  192615. owner->removeUser();
  192616. owner->removeChangeListener (this);
  192617. }
  192618. }
  192619. void ownerDeleted()
  192620. {
  192621. owner = 0;
  192622. }
  192623. void paint (Graphics& g)
  192624. {
  192625. g.setColour (Colours::black);
  192626. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192627. if (owner != 0)
  192628. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192629. else
  192630. g.fillAll (Colours::black);
  192631. }
  192632. void changeListenerCallback (void*)
  192633. {
  192634. repaint();
  192635. }
  192636. private:
  192637. DShowCameraDeviceInteral* owner;
  192638. };
  192639. bool ok;
  192640. int width, height;
  192641. Time firstRecordedTime;
  192642. VoidArray viewerComps;
  192643. private:
  192644. CameraDevice* const owner;
  192645. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192646. ComSmartPtr <IBaseFilter> filter;
  192647. ComSmartPtr <IBaseFilter> smartTee;
  192648. ComSmartPtr <IGraphBuilder> graphBuilder;
  192649. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192650. ComSmartPtr <IMediaControl> mediaControl;
  192651. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192652. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192653. ComSmartPtr <IBaseFilter> mux, fileWriter;
  192654. int activeUsers;
  192655. Array <int> widths, heights;
  192656. DWORD graphRegistrationID;
  192657. CriticalSection imageSwapLock;
  192658. bool imageNeedsFlipping;
  192659. Image* loadingImage;
  192660. Image* activeImage;
  192661. bool recordNextFrameTime;
  192662. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192663. {
  192664. widths.clear();
  192665. heights.clear();
  192666. int count = 0, size = 0;
  192667. streamConfig->GetNumberOfCapabilities (&count, &size);
  192668. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192669. {
  192670. for (int i = 0; i < count; ++i)
  192671. {
  192672. VIDEO_STREAM_CONFIG_CAPS scc;
  192673. AM_MEDIA_TYPE* config;
  192674. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192675. if (SUCCEEDED (hr))
  192676. {
  192677. const int w = scc.InputSize.cx;
  192678. const int h = scc.InputSize.cy;
  192679. bool duplicate = false;
  192680. for (int j = widths.size(); --j >= 0;)
  192681. {
  192682. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192683. {
  192684. duplicate = true;
  192685. break;
  192686. }
  192687. }
  192688. if (! duplicate)
  192689. {
  192690. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192691. widths.add (w);
  192692. heights.add (h);
  192693. }
  192694. deleteMediaType (config);
  192695. }
  192696. }
  192697. }
  192698. }
  192699. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192700. const int minWidth, const int minHeight,
  192701. const int maxWidth, const int maxHeight)
  192702. {
  192703. int count = 0, size = 0;
  192704. streamConfig->GetNumberOfCapabilities (&count, &size);
  192705. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192706. {
  192707. for (int i = 0; i < count; ++i)
  192708. {
  192709. VIDEO_STREAM_CONFIG_CAPS scc;
  192710. AM_MEDIA_TYPE* config;
  192711. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192712. if (SUCCEEDED (hr))
  192713. {
  192714. if (scc.InputSize.cx >= minWidth
  192715. && scc.InputSize.cy >= minHeight
  192716. && scc.InputSize.cx <= maxWidth
  192717. && scc.InputSize.cy <= maxHeight)
  192718. {
  192719. hr = streamConfig->SetFormat (config);
  192720. deleteMediaType (config);
  192721. return SUCCEEDED (hr);
  192722. }
  192723. deleteMediaType (config);
  192724. }
  192725. }
  192726. }
  192727. return false;
  192728. }
  192729. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192730. {
  192731. ComSmartPtr <IEnumPins> enumerator;
  192732. ComSmartPtr <IPin> pin;
  192733. filter->EnumPins (&enumerator);
  192734. while (enumerator->Next (1, &pin, 0) == S_OK)
  192735. {
  192736. PIN_DIRECTION dir;
  192737. pin->QueryDirection (&dir);
  192738. if (wantedDirection == dir)
  192739. {
  192740. PIN_INFO info;
  192741. zerostruct (info);
  192742. pin->QueryPinInfo (&info);
  192743. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192744. {
  192745. pin.p->AddRef();
  192746. *result = pin;
  192747. return true;
  192748. }
  192749. }
  192750. }
  192751. return false;
  192752. }
  192753. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192754. {
  192755. ComSmartPtr <IPin> in, out;
  192756. return getPin (first, PINDIR_OUTPUT, &out)
  192757. && getPin (second, PINDIR_INPUT, &in)
  192758. && SUCCEEDED (graphBuilder->Connect (out, in));
  192759. }
  192760. bool addGraphToRot()
  192761. {
  192762. ComSmartPtr <IRunningObjectTable> rot;
  192763. if (FAILED (GetRunningObjectTable (0, &rot)))
  192764. return false;
  192765. ComSmartPtr <IMoniker> moniker;
  192766. WCHAR buffer[128];
  192767. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192768. if (FAILED (hr))
  192769. return false;
  192770. graphRegistrationID = 0;
  192771. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192772. }
  192773. void removeGraphFromRot()
  192774. {
  192775. ComSmartPtr <IRunningObjectTable> rot;
  192776. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192777. rot->Revoke (graphRegistrationID);
  192778. }
  192779. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192780. {
  192781. if (pmt->cbFormat != 0)
  192782. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192783. if (pmt->pUnk != 0)
  192784. pmt->pUnk->Release();
  192785. CoTaskMemFree (pmt);
  192786. }
  192787. class GrabberCallback : public ISampleGrabberCB
  192788. {
  192789. public:
  192790. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192791. : owner (owner_)
  192792. {
  192793. }
  192794. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192795. {
  192796. if (id == IID_IUnknown)
  192797. *result = dynamic_cast <IUnknown*> (this);
  192798. else if (id == IID_ISampleGrabberCB)
  192799. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192800. else
  192801. {
  192802. *result = 0;
  192803. return E_NOINTERFACE;
  192804. }
  192805. AddRef();
  192806. return S_OK;
  192807. }
  192808. ULONG __stdcall AddRef() { return ++refCount; }
  192809. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192810. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192811. {
  192812. return E_FAIL;
  192813. }
  192814. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192815. {
  192816. owner.handleFrame (time, buffer, bufferSize);
  192817. return S_OK;
  192818. }
  192819. private:
  192820. int refCount;
  192821. DShowCameraDeviceInteral& owner;
  192822. GrabberCallback (const GrabberCallback&);
  192823. const GrabberCallback& operator= (const GrabberCallback&);
  192824. };
  192825. ComSmartPtr <GrabberCallback> callback;
  192826. VoidArray listeners;
  192827. CriticalSection listenerLock;
  192828. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192829. const DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192830. };
  192831. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192832. : name (name_)
  192833. {
  192834. isRecording = false;
  192835. }
  192836. CameraDevice::~CameraDevice()
  192837. {
  192838. stopRecording();
  192839. delete (DShowCameraDeviceInteral*) internal;
  192840. internal = 0;
  192841. }
  192842. Component* CameraDevice::createViewerComponent()
  192843. {
  192844. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192845. }
  192846. const String CameraDevice::getFileExtension()
  192847. {
  192848. return ".avi";
  192849. }
  192850. void CameraDevice::startRecordingToFile (const File& file)
  192851. {
  192852. stopRecording();
  192853. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192854. d->addUser();
  192855. isRecording = d->createFileCaptureFilter (file);
  192856. }
  192857. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192858. {
  192859. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192860. return d->firstRecordedTime;
  192861. }
  192862. void CameraDevice::stopRecording()
  192863. {
  192864. if (isRecording)
  192865. {
  192866. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192867. d->removeFileCaptureFilter();
  192868. d->removeUser();
  192869. isRecording = false;
  192870. }
  192871. }
  192872. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192873. {
  192874. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192875. if (listenerToAdd != 0)
  192876. d->addListener (listenerToAdd);
  192877. }
  192878. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192879. {
  192880. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192881. if (listenerToRemove != 0)
  192882. d->removeListener (listenerToRemove);
  192883. }
  192884. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192885. const int deviceIndexToOpen,
  192886. String& name)
  192887. {
  192888. int index = 0;
  192889. ComSmartPtr <IBaseFilter> result;
  192890. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192891. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192892. if (SUCCEEDED (hr))
  192893. {
  192894. ComSmartPtr <IEnumMoniker> enumerator;
  192895. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192896. if (SUCCEEDED (hr) && enumerator != 0)
  192897. {
  192898. ComSmartPtr <IBaseFilter> captureFilter;
  192899. ComSmartPtr <IMoniker> moniker;
  192900. ULONG fetched;
  192901. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192902. {
  192903. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192904. if (SUCCEEDED (hr))
  192905. {
  192906. ComSmartPtr <IPropertyBag> propertyBag;
  192907. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192908. if (SUCCEEDED (hr))
  192909. {
  192910. VARIANT var;
  192911. var.vt = VT_BSTR;
  192912. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192913. propertyBag = 0;
  192914. if (SUCCEEDED (hr))
  192915. {
  192916. if (names != 0)
  192917. names->add (var.bstrVal);
  192918. if (index == deviceIndexToOpen)
  192919. {
  192920. name = var.bstrVal;
  192921. result = captureFilter;
  192922. captureFilter = 0;
  192923. break;
  192924. }
  192925. ++index;
  192926. }
  192927. moniker = 0;
  192928. }
  192929. captureFilter = 0;
  192930. }
  192931. }
  192932. }
  192933. }
  192934. return result;
  192935. }
  192936. const StringArray CameraDevice::getAvailableDevices()
  192937. {
  192938. StringArray devs;
  192939. String dummy;
  192940. enumerateCameras (&devs, -1, dummy);
  192941. return devs;
  192942. }
  192943. CameraDevice* CameraDevice::openDevice (int index,
  192944. int minWidth, int minHeight,
  192945. int maxWidth, int maxHeight)
  192946. {
  192947. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192948. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192949. if (SUCCEEDED (hr))
  192950. {
  192951. String name;
  192952. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192953. if (filter != 0)
  192954. {
  192955. CameraDevice* const cam = new CameraDevice (name, index);
  192956. DShowCameraDeviceInteral* const intern
  192957. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192958. minWidth, minHeight, maxWidth, maxHeight);
  192959. cam->internal = intern;
  192960. if (intern->ok)
  192961. return cam;
  192962. else
  192963. delete cam;
  192964. }
  192965. }
  192966. return 0;
  192967. }
  192968. #endif
  192969. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192970. #endif
  192971. // Auto-link the other win32 libs that are needed by library calls..
  192972. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192973. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192974. // Auto-links to various win32 libs that are needed by library calls..
  192975. #pragma comment(lib, "kernel32.lib")
  192976. #pragma comment(lib, "user32.lib")
  192977. #pragma comment(lib, "shell32.lib")
  192978. #pragma comment(lib, "gdi32.lib")
  192979. #pragma comment(lib, "vfw32.lib")
  192980. #pragma comment(lib, "comdlg32.lib")
  192981. #pragma comment(lib, "winmm.lib")
  192982. #pragma comment(lib, "wininet.lib")
  192983. #pragma comment(lib, "ole32.lib")
  192984. #pragma comment(lib, "oleaut32.lib")
  192985. #pragma comment(lib, "advapi32.lib")
  192986. #pragma comment(lib, "ws2_32.lib")
  192987. #pragma comment(lib, "comsupp.lib")
  192988. #pragma comment(lib, "version.lib")
  192989. #if JUCE_OPENGL
  192990. #pragma comment(lib, "OpenGL32.Lib")
  192991. #pragma comment(lib, "GlU32.Lib")
  192992. #endif
  192993. #if JUCE_QUICKTIME
  192994. #pragma comment (lib, "QTMLClient.lib")
  192995. #endif
  192996. #if JUCE_USE_CAMERA
  192997. #pragma comment (lib, "Strmiids.lib")
  192998. #endif
  192999. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  193000. #endif
  193001. END_JUCE_NAMESPACE
  193002. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  193003. #endif
  193004. #if JUCE_LINUX
  193005. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  193006. BEGIN_JUCE_NAMESPACE
  193007. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  193008. #define SUPPORT_AFFINITIES 1
  193009. #endif
  193010. #define JUCE_INCLUDED_FILE 1
  193011. // Now include the actual code files..
  193012. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  193013. CriticalSection::CriticalSection() throw()
  193014. {
  193015. pthread_mutexattr_t atts;
  193016. pthread_mutexattr_init (&atts);
  193017. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  193018. pthread_mutex_init (&internal, &atts);
  193019. }
  193020. CriticalSection::~CriticalSection() throw()
  193021. {
  193022. pthread_mutex_destroy (&internal);
  193023. }
  193024. void CriticalSection::enter() const throw()
  193025. {
  193026. pthread_mutex_lock (&internal);
  193027. }
  193028. bool CriticalSection::tryEnter() const throw()
  193029. {
  193030. return pthread_mutex_trylock (&internal) == 0;
  193031. }
  193032. void CriticalSection::exit() const throw()
  193033. {
  193034. pthread_mutex_unlock (&internal);
  193035. }
  193036. struct EventStruct
  193037. {
  193038. pthread_cond_t condition;
  193039. pthread_mutex_t mutex;
  193040. bool triggered;
  193041. };
  193042. WaitableEvent::WaitableEvent() throw()
  193043. {
  193044. EventStruct* const es = new EventStruct();
  193045. es->triggered = false;
  193046. pthread_cond_init (&es->condition, 0);
  193047. pthread_mutex_init (&es->mutex, 0);
  193048. internal = es;
  193049. }
  193050. WaitableEvent::~WaitableEvent() throw()
  193051. {
  193052. EventStruct* const es = (EventStruct*) internal;
  193053. pthread_cond_destroy (&es->condition);
  193054. pthread_mutex_destroy (&es->mutex);
  193055. delete es;
  193056. }
  193057. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  193058. {
  193059. EventStruct* const es = (EventStruct*) internal;
  193060. pthread_mutex_lock (&es->mutex);
  193061. if (timeOutMillisecs < 0)
  193062. {
  193063. while (! es->triggered)
  193064. pthread_cond_wait (&es->condition, &es->mutex);
  193065. }
  193066. else
  193067. {
  193068. while (! es->triggered)
  193069. {
  193070. struct timeval t;
  193071. gettimeofday (&t, 0);
  193072. struct timespec time;
  193073. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  193074. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  193075. if (time.tv_nsec >= 1000000000)
  193076. {
  193077. time.tv_nsec -= 1000000000;
  193078. time.tv_sec++;
  193079. }
  193080. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  193081. {
  193082. pthread_mutex_unlock (&es->mutex);
  193083. return false;
  193084. }
  193085. }
  193086. }
  193087. es->triggered = false;
  193088. pthread_mutex_unlock (&es->mutex);
  193089. return true;
  193090. }
  193091. void WaitableEvent::signal() const throw()
  193092. {
  193093. EventStruct* const es = (EventStruct*) internal;
  193094. pthread_mutex_lock (&es->mutex);
  193095. es->triggered = true;
  193096. pthread_cond_broadcast (&es->condition);
  193097. pthread_mutex_unlock (&es->mutex);
  193098. }
  193099. void WaitableEvent::reset() const throw()
  193100. {
  193101. EventStruct* const es = (EventStruct*) internal;
  193102. pthread_mutex_lock (&es->mutex);
  193103. es->triggered = false;
  193104. pthread_mutex_unlock (&es->mutex);
  193105. }
  193106. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  193107. {
  193108. struct timespec time;
  193109. time.tv_sec = millisecs / 1000;
  193110. time.tv_nsec = (millisecs % 1000) * 1000000;
  193111. nanosleep (&time, 0);
  193112. }
  193113. const tchar File::separator = T('/');
  193114. const tchar* File::separatorString = T("/");
  193115. bool juce_copyFile (const String& s, const String& d);
  193116. static bool juce_stat (const String& fileName, struct stat& info)
  193117. {
  193118. return fileName.isNotEmpty()
  193119. && (stat (fileName.toUTF8(), &info) == 0);
  193120. }
  193121. bool juce_isDirectory (const String& fileName)
  193122. {
  193123. struct stat info;
  193124. return fileName.isEmpty()
  193125. || (juce_stat (fileName, info)
  193126. && ((info.st_mode & S_IFDIR) != 0));
  193127. }
  193128. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193129. {
  193130. if (fileName.isEmpty())
  193131. return false;
  193132. const char* const fileNameUTF8 = fileName.toUTF8();
  193133. bool exists = access (fileNameUTF8, F_OK) == 0;
  193134. if (exists && dontCountDirectories)
  193135. {
  193136. struct stat info;
  193137. const int res = stat (fileNameUTF8, &info);
  193138. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193139. exists = false;
  193140. }
  193141. return exists;
  193142. }
  193143. int64 juce_getFileSize (const String& fileName)
  193144. {
  193145. struct stat info;
  193146. return juce_stat (fileName, info) ? info.st_size : 0;
  193147. }
  193148. bool juce_canWriteToFile (const String& fileName)
  193149. {
  193150. return access (fileName.toUTF8(), W_OK) == 0;
  193151. }
  193152. bool juce_deleteFile (const String& fileName)
  193153. {
  193154. if (juce_isDirectory (fileName))
  193155. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193156. else
  193157. return remove ((const char*) fileName.toUTF8()) == 0;
  193158. }
  193159. bool juce_moveFile (const String& source, const String& dest)
  193160. {
  193161. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193162. return true;
  193163. if (juce_canWriteToFile (source)
  193164. && juce_copyFile (source, dest))
  193165. {
  193166. if (juce_deleteFile (source))
  193167. return true;
  193168. juce_deleteFile (dest);
  193169. }
  193170. return false;
  193171. }
  193172. void juce_createDirectory (const String& fileName)
  193173. {
  193174. mkdir (fileName.toUTF8(), 0777);
  193175. }
  193176. void* juce_fileOpen (const String& fileName, bool forWriting)
  193177. {
  193178. int flags = O_RDONLY;
  193179. if (forWriting)
  193180. {
  193181. if (juce_fileExists (fileName, false))
  193182. {
  193183. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193184. if (f != -1)
  193185. lseek (f, 0, SEEK_END);
  193186. return (void*) f;
  193187. }
  193188. else
  193189. {
  193190. flags = O_RDWR + O_CREAT;
  193191. }
  193192. }
  193193. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193194. }
  193195. void juce_fileClose (void* handle)
  193196. {
  193197. if (handle != 0)
  193198. close ((int) (pointer_sized_int) handle);
  193199. }
  193200. int juce_fileRead (void* handle, void* buffer, int size)
  193201. {
  193202. if (handle != 0)
  193203. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193204. return 0;
  193205. }
  193206. int juce_fileWrite (void* handle, const void* buffer, int size)
  193207. {
  193208. if (handle != 0)
  193209. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193210. return 0;
  193211. }
  193212. int64 juce_fileSetPosition (void* handle, int64 pos)
  193213. {
  193214. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193215. return pos;
  193216. return -1;
  193217. }
  193218. int64 juce_fileGetPosition (void* handle)
  193219. {
  193220. if (handle != 0)
  193221. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193222. else
  193223. return -1;
  193224. }
  193225. void juce_fileFlush (void* handle)
  193226. {
  193227. if (handle != 0)
  193228. fsync ((int) (pointer_sized_int) handle);
  193229. }
  193230. const File juce_getExecutableFile()
  193231. {
  193232. Dl_info exeInfo;
  193233. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193234. return File (exeInfo.dli_fname);
  193235. }
  193236. // if this file doesn't exist, find a parent of it that does..
  193237. static bool doStatFS (const File* file, struct statfs& result)
  193238. {
  193239. File f (*file);
  193240. for (int i = 5; --i >= 0;)
  193241. {
  193242. if (f.exists())
  193243. break;
  193244. f = f.getParentDirectory();
  193245. }
  193246. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193247. }
  193248. int64 File::getBytesFreeOnVolume() const
  193249. {
  193250. struct statfs buf;
  193251. if (doStatFS (this, buf))
  193252. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193253. return 0;
  193254. }
  193255. int64 File::getVolumeTotalSize() const
  193256. {
  193257. struct statfs buf;
  193258. if (doStatFS (this, buf))
  193259. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193260. return 0;
  193261. }
  193262. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193263. int& volumeSerialNumber)
  193264. {
  193265. volumeSerialNumber = 0;
  193266. #if JUCE_MAC
  193267. struct VolAttrBuf
  193268. {
  193269. u_int32_t length;
  193270. attrreference_t mountPointRef;
  193271. char mountPointSpace [MAXPATHLEN];
  193272. } attrBuf;
  193273. struct attrlist attrList;
  193274. zerostruct (attrList);
  193275. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193276. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193277. File f (filenameOnVolume);
  193278. for (;;)
  193279. {
  193280. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193281. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193282. {
  193283. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193284. (int) attrBuf.mountPointRef.attr_length);
  193285. }
  193286. const File parent (f.getParentDirectory());
  193287. if (f == parent)
  193288. break;
  193289. f = parent;
  193290. }
  193291. #endif
  193292. return String::empty;
  193293. }
  193294. void juce_runSystemCommand (const String& command)
  193295. {
  193296. int result = system ((const char*) command.toUTF8());
  193297. (void) result;
  193298. }
  193299. const String juce_getOutputFromCommand (const String& command)
  193300. {
  193301. // slight bodge here, as we just pipe the output into a temp file and read it...
  193302. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193303. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193304. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193305. String result (tempFile.loadFileAsString());
  193306. tempFile.deleteFile();
  193307. return result;
  193308. }
  193309. InterProcessLock::InterProcessLock (const String& name_)
  193310. : internal (0),
  193311. name (name_),
  193312. reentrancyLevel (0)
  193313. {
  193314. #if JUCE_MAC
  193315. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193316. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193317. #else
  193318. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193319. #endif
  193320. temp.create();
  193321. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193322. }
  193323. InterProcessLock::~InterProcessLock()
  193324. {
  193325. while (reentrancyLevel > 0)
  193326. this->exit();
  193327. close (internal);
  193328. }
  193329. bool InterProcessLock::enter (const int timeOutMillisecs)
  193330. {
  193331. if (internal == 0)
  193332. return false;
  193333. if (reentrancyLevel != 0)
  193334. return true;
  193335. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193336. struct flock fl;
  193337. zerostruct (fl);
  193338. fl.l_whence = SEEK_SET;
  193339. fl.l_type = F_WRLCK;
  193340. for (;;)
  193341. {
  193342. const int result = fcntl (internal, F_SETLK, &fl);
  193343. if (result >= 0)
  193344. {
  193345. ++reentrancyLevel;
  193346. return true;
  193347. }
  193348. if (errno != EINTR)
  193349. {
  193350. if (timeOutMillisecs == 0
  193351. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193352. break;
  193353. Thread::sleep (10);
  193354. }
  193355. }
  193356. return false;
  193357. }
  193358. void InterProcessLock::exit()
  193359. {
  193360. if (reentrancyLevel > 0 && internal != 0)
  193361. {
  193362. --reentrancyLevel;
  193363. struct flock fl;
  193364. zerostruct (fl);
  193365. fl.l_whence = SEEK_SET;
  193366. fl.l_type = F_UNLCK;
  193367. for (;;)
  193368. {
  193369. const int result = fcntl (internal, F_SETLKW, &fl);
  193370. if (result >= 0 || errno != EINTR)
  193371. break;
  193372. }
  193373. }
  193374. }
  193375. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193376. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193377. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193378. // compiled on its own).
  193379. #if JUCE_INCLUDED_FILE
  193380. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193381. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193382. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193383. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193384. void juce_getFileTimes (const String& fileName,
  193385. int64& modificationTime,
  193386. int64& accessTime,
  193387. int64& creationTime)
  193388. {
  193389. modificationTime = 0;
  193390. accessTime = 0;
  193391. creationTime = 0;
  193392. struct stat info;
  193393. const int res = stat (fileName.toUTF8(), &info);
  193394. if (res == 0)
  193395. {
  193396. modificationTime = (int64) info.st_mtime * 1000;
  193397. accessTime = (int64) info.st_atime * 1000;
  193398. creationTime = (int64) info.st_ctime * 1000;
  193399. }
  193400. }
  193401. bool juce_setFileTimes (const String& fileName,
  193402. int64 modificationTime,
  193403. int64 accessTime,
  193404. int64 creationTime)
  193405. {
  193406. struct utimbuf times;
  193407. times.actime = (time_t) (accessTime / 1000);
  193408. times.modtime = (time_t) (modificationTime / 1000);
  193409. return utime (fileName.toUTF8(), &times) == 0;
  193410. }
  193411. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193412. {
  193413. struct stat info;
  193414. const int res = stat (fileName.toUTF8(), &info);
  193415. if (res != 0)
  193416. return false;
  193417. info.st_mode &= 0777; // Just permissions
  193418. if( isReadOnly )
  193419. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193420. else
  193421. // Give everybody write permission?
  193422. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193423. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193424. }
  193425. bool juce_copyFile (const String& s, const String& d)
  193426. {
  193427. const File source (s), dest (d);
  193428. FileInputStream* in = source.createInputStream();
  193429. bool ok = false;
  193430. if (in != 0)
  193431. {
  193432. if (dest.deleteFile())
  193433. {
  193434. FileOutputStream* const out = dest.createOutputStream();
  193435. if (out != 0)
  193436. {
  193437. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193438. delete out;
  193439. ok = (bytesCopied == source.getSize());
  193440. if (! ok)
  193441. dest.deleteFile();
  193442. }
  193443. }
  193444. delete in;
  193445. }
  193446. return ok;
  193447. }
  193448. const StringArray juce_getFileSystemRoots()
  193449. {
  193450. StringArray s;
  193451. s.add (T("/"));
  193452. return s;
  193453. }
  193454. bool File::isOnCDRomDrive() const
  193455. {
  193456. struct statfs buf;
  193457. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193458. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193459. // Assume not if this fails for some reason
  193460. return false;
  193461. }
  193462. bool File::isOnHardDisk() const
  193463. {
  193464. struct statfs buf;
  193465. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193466. {
  193467. switch (buf.f_type)
  193468. {
  193469. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193470. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193471. case U_NFS_SUPER_MAGIC: // Network NFS
  193472. case U_SMB_SUPER_MAGIC: // Network Samba
  193473. return false;
  193474. default:
  193475. // Assume anything else is a hard-disk (but note it could
  193476. // be a RAM disk. There isn't a good way of determining
  193477. // this for sure)
  193478. return true;
  193479. }
  193480. }
  193481. // Assume so if this fails for some reason
  193482. return true;
  193483. }
  193484. bool File::isOnRemovableDrive() const
  193485. {
  193486. jassertfalse // xxx not implemented for linux!
  193487. return false;
  193488. }
  193489. bool File::isHidden() const
  193490. {
  193491. return getFileName().startsWithChar (T('.'));
  193492. }
  193493. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193494. const File File::getSpecialLocation (const SpecialLocationType type)
  193495. {
  193496. switch (type)
  193497. {
  193498. case userHomeDirectory:
  193499. {
  193500. const char* homeDir = getenv ("HOME");
  193501. if (homeDir == 0)
  193502. {
  193503. struct passwd* const pw = getpwuid (getuid());
  193504. if (pw != 0)
  193505. homeDir = pw->pw_dir;
  193506. }
  193507. return File (String::fromUTF8 ((const uint8*) homeDir));
  193508. }
  193509. case userDocumentsDirectory:
  193510. case userMusicDirectory:
  193511. case userMoviesDirectory:
  193512. case userApplicationDataDirectory:
  193513. return File ("~");
  193514. case userDesktopDirectory:
  193515. return File ("~/Desktop");
  193516. case commonApplicationDataDirectory:
  193517. return File ("/var");
  193518. case globalApplicationsDirectory:
  193519. return File ("/usr");
  193520. case tempDirectory:
  193521. {
  193522. File tmp ("/var/tmp");
  193523. if (! tmp.isDirectory())
  193524. {
  193525. tmp = T("/tmp");
  193526. if (! tmp.isDirectory())
  193527. tmp = File::getCurrentWorkingDirectory();
  193528. }
  193529. return tmp;
  193530. }
  193531. case invokedExecutableFile:
  193532. if (juce_Argv0 != 0)
  193533. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  193534. // deliberate fall-through...
  193535. case currentExecutableFile:
  193536. case currentApplicationFile:
  193537. return juce_getExecutableFile();
  193538. default:
  193539. jassertfalse // unknown type?
  193540. break;
  193541. }
  193542. return File::nonexistent;
  193543. }
  193544. const File File::getCurrentWorkingDirectory()
  193545. {
  193546. char buf [2048];
  193547. return File (String::fromUTF8 ((const uint8*) getcwd (buf, sizeof (buf))));
  193548. }
  193549. bool File::setAsCurrentWorkingDirectory() const
  193550. {
  193551. return chdir (getFullPathName().toUTF8()) == 0;
  193552. }
  193553. const String File::getVersion() const
  193554. {
  193555. return String::empty; // xxx not yet implemented
  193556. }
  193557. const File File::getLinkedTarget() const
  193558. {
  193559. char buffer [4096];
  193560. size_t numChars = readlink ((const char*) getFullPathName().toUTF8(),
  193561. buffer, sizeof (buffer));
  193562. if (numChars > 0 && numChars <= sizeof (buffer))
  193563. return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars));
  193564. return *this;
  193565. }
  193566. bool File::moveToTrash() const
  193567. {
  193568. if (! exists())
  193569. return true;
  193570. File trashCan (T("~/.Trash"));
  193571. if (! trashCan.isDirectory())
  193572. trashCan = T("~/.local/share/Trash/files");
  193573. if (! trashCan.isDirectory())
  193574. return false;
  193575. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193576. getFileExtension()));
  193577. }
  193578. struct FindFileStruct
  193579. {
  193580. String parentDir, wildCard;
  193581. DIR* dir;
  193582. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193583. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193584. {
  193585. const char* const wildcardUTF8 = wildCard.toUTF8();
  193586. for (;;)
  193587. {
  193588. struct dirent* const de = readdir (dir);
  193589. if (de == 0)
  193590. break;
  193591. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193592. {
  193593. result = String::fromUTF8 ((const uint8*) de->d_name);
  193594. const String path (parentDir + result);
  193595. if (isDir != 0 || fileSize != 0)
  193596. {
  193597. struct stat info;
  193598. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193599. if (isDir != 0)
  193600. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193601. if (isHidden != 0)
  193602. *isHidden = (de->d_name[0] == '.');
  193603. if (fileSize != 0)
  193604. *fileSize = statOk ? info.st_size : 0;
  193605. }
  193606. if (modTime != 0 || creationTime != 0)
  193607. {
  193608. int64 m, a, c;
  193609. juce_getFileTimes (path, m, a, c);
  193610. if (modTime != 0)
  193611. *modTime = m;
  193612. if (creationTime != 0)
  193613. *creationTime = c;
  193614. }
  193615. if (isReadOnly != 0)
  193616. *isReadOnly = ! juce_canWriteToFile (path);
  193617. return true;
  193618. }
  193619. }
  193620. return false;
  193621. }
  193622. };
  193623. // returns 0 on failure
  193624. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193625. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193626. Time* creationTime, bool* isReadOnly)
  193627. {
  193628. DIR* d = opendir (directory.toUTF8());
  193629. if (d != 0)
  193630. {
  193631. FindFileStruct* ff = new FindFileStruct();
  193632. ff->parentDir = directory;
  193633. if (!ff->parentDir.endsWithChar (File::separator))
  193634. ff->parentDir += File::separator;
  193635. ff->wildCard = wildCard;
  193636. if (wildCard == T("*.*"))
  193637. ff->wildCard = T("*");
  193638. ff->dir = d;
  193639. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193640. {
  193641. return ff;
  193642. }
  193643. else
  193644. {
  193645. firstResultFile = String::empty;
  193646. isDir = false;
  193647. isHidden = false;
  193648. closedir (d);
  193649. delete ff;
  193650. }
  193651. }
  193652. return 0;
  193653. }
  193654. bool juce_findFileNext (void* handle, String& resultFile,
  193655. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193656. {
  193657. FindFileStruct* const ff = (FindFileStruct*) handle;
  193658. if (ff != 0)
  193659. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193660. return false;
  193661. }
  193662. void juce_findFileClose (void* handle)
  193663. {
  193664. FindFileStruct* const ff = (FindFileStruct*) handle;
  193665. if (ff != 0)
  193666. {
  193667. closedir (ff->dir);
  193668. delete ff;
  193669. }
  193670. }
  193671. bool juce_launchFile (const String& fileName,
  193672. const String& parameters)
  193673. {
  193674. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193675. cmdString << " " << parameters;
  193676. if (URL::isProbablyAWebsiteURL (fileName)
  193677. || cmdString.startsWithIgnoreCase (T("file:"))
  193678. || URL::isProbablyAnEmailAddress (fileName))
  193679. {
  193680. // create a command that tries to launch a bunch of likely browsers
  193681. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193682. StringArray cmdLines;
  193683. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193684. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193685. cmdString = cmdLines.joinIntoString (T(" || "));
  193686. }
  193687. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193688. const int cpid = fork();
  193689. if (cpid == 0)
  193690. {
  193691. setsid();
  193692. // Child process
  193693. execve (argv[0], (char**) argv, environ);
  193694. exit (0);
  193695. }
  193696. return cpid >= 0;
  193697. }
  193698. void File::revealToUser() const
  193699. {
  193700. if (isDirectory())
  193701. startAsProcess();
  193702. else if (getParentDirectory().exists())
  193703. getParentDirectory().startAsProcess();
  193704. }
  193705. #endif
  193706. /*** End of inlined file: juce_linux_Files.cpp ***/
  193707. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193708. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193709. // compiled on its own).
  193710. #if JUCE_INCLUDED_FILE
  193711. struct NamedPipeInternal
  193712. {
  193713. String pipeInName, pipeOutName;
  193714. int pipeIn, pipeOut;
  193715. bool volatile createdPipe, blocked, stopReadOperation;
  193716. static void signalHandler (int) {}
  193717. };
  193718. void NamedPipe::cancelPendingReads()
  193719. {
  193720. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193721. {
  193722. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193723. intern->stopReadOperation = true;
  193724. char buffer [1] = { 0 };
  193725. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193726. (void) bytesWritten;
  193727. int timeout = 2000;
  193728. while (intern->blocked && --timeout >= 0)
  193729. Thread::sleep (2);
  193730. intern->stopReadOperation = false;
  193731. }
  193732. }
  193733. void NamedPipe::close()
  193734. {
  193735. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193736. if (intern != 0)
  193737. {
  193738. internal = 0;
  193739. if (intern->pipeIn != -1)
  193740. ::close (intern->pipeIn);
  193741. if (intern->pipeOut != -1)
  193742. ::close (intern->pipeOut);
  193743. if (intern->createdPipe)
  193744. {
  193745. unlink (intern->pipeInName);
  193746. unlink (intern->pipeOutName);
  193747. }
  193748. delete intern;
  193749. }
  193750. }
  193751. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193752. {
  193753. close();
  193754. NamedPipeInternal* const intern = new NamedPipeInternal();
  193755. internal = intern;
  193756. intern->createdPipe = createPipe;
  193757. intern->blocked = false;
  193758. intern->stopReadOperation = false;
  193759. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193760. siginterrupt (SIGPIPE, 1);
  193761. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193762. intern->pipeInName = pipePath + T("_in");
  193763. intern->pipeOutName = pipePath + T("_out");
  193764. intern->pipeIn = -1;
  193765. intern->pipeOut = -1;
  193766. if (createPipe)
  193767. {
  193768. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  193769. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  193770. {
  193771. delete intern;
  193772. internal = 0;
  193773. return false;
  193774. }
  193775. }
  193776. return true;
  193777. }
  193778. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193779. {
  193780. int bytesRead = -1;
  193781. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193782. if (intern != 0)
  193783. {
  193784. intern->blocked = true;
  193785. if (intern->pipeIn == -1)
  193786. {
  193787. if (intern->createdPipe)
  193788. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  193789. else
  193790. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  193791. if (intern->pipeIn == -1)
  193792. {
  193793. intern->blocked = false;
  193794. return -1;
  193795. }
  193796. }
  193797. bytesRead = 0;
  193798. char* p = (char*) destBuffer;
  193799. while (bytesRead < maxBytesToRead)
  193800. {
  193801. const int bytesThisTime = maxBytesToRead - bytesRead;
  193802. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193803. if (numRead <= 0 || intern->stopReadOperation)
  193804. {
  193805. bytesRead = -1;
  193806. break;
  193807. }
  193808. bytesRead += numRead;
  193809. p += bytesRead;
  193810. }
  193811. intern->blocked = false;
  193812. }
  193813. return bytesRead;
  193814. }
  193815. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193816. {
  193817. int bytesWritten = -1;
  193818. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193819. if (intern != 0)
  193820. {
  193821. if (intern->pipeOut == -1)
  193822. {
  193823. if (intern->createdPipe)
  193824. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  193825. else
  193826. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  193827. if (intern->pipeOut == -1)
  193828. {
  193829. return -1;
  193830. }
  193831. }
  193832. const char* p = (const char*) sourceBuffer;
  193833. bytesWritten = 0;
  193834. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193835. while (bytesWritten < numBytesToWrite
  193836. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193837. {
  193838. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193839. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193840. if (numWritten <= 0)
  193841. {
  193842. bytesWritten = -1;
  193843. break;
  193844. }
  193845. bytesWritten += numWritten;
  193846. p += bytesWritten;
  193847. }
  193848. }
  193849. return bytesWritten;
  193850. }
  193851. #endif
  193852. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193853. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193854. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193855. // compiled on its own).
  193856. #if JUCE_INCLUDED_FILE
  193857. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  193858. {
  193859. int numResults = 0;
  193860. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193861. if (s != -1)
  193862. {
  193863. char buf [1024];
  193864. struct ifconf ifc;
  193865. ifc.ifc_len = sizeof (buf);
  193866. ifc.ifc_buf = buf;
  193867. ioctl (s, SIOCGIFCONF, &ifc);
  193868. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193869. {
  193870. struct ifreq ifr;
  193871. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193872. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193873. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193874. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193875. && numResults < maxNum)
  193876. {
  193877. int64 a = 0;
  193878. for (int j = 6; --j >= 0;)
  193879. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193880. *addresses++ = a;
  193881. ++numResults;
  193882. }
  193883. }
  193884. close (s);
  193885. }
  193886. return numResults;
  193887. }
  193888. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193889. const String& emailSubject,
  193890. const String& bodyText,
  193891. const StringArray& filesToAttach)
  193892. {
  193893. jassertfalse // xxx todo
  193894. return false;
  193895. }
  193896. class JUCE_HTTPSocketStream
  193897. {
  193898. public:
  193899. JUCE_HTTPSocketStream()
  193900. : readPosition (0),
  193901. socketHandle (-1),
  193902. levelsOfRedirection (0),
  193903. timeoutSeconds (15)
  193904. {
  193905. }
  193906. ~JUCE_HTTPSocketStream()
  193907. {
  193908. closeSocket();
  193909. }
  193910. bool open (const String& url,
  193911. const String& headers,
  193912. const MemoryBlock& postData,
  193913. const bool isPost,
  193914. URL::OpenStreamProgressCallback* callback,
  193915. void* callbackContext,
  193916. int timeOutMs)
  193917. {
  193918. closeSocket();
  193919. uint32 timeOutTime = Time::getMillisecondCounter();
  193920. if (timeOutMs == 0)
  193921. timeOutTime += 60000;
  193922. else if (timeOutMs < 0)
  193923. timeOutTime = 0xffffffff;
  193924. else
  193925. timeOutTime += timeOutMs;
  193926. String hostName, hostPath;
  193927. int hostPort;
  193928. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193929. return false;
  193930. const struct hostent* host = 0;
  193931. int port = 0;
  193932. String proxyName, proxyPath;
  193933. int proxyPort = 0;
  193934. String proxyURL (getenv ("http_proxy"));
  193935. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193936. {
  193937. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193938. return false;
  193939. host = gethostbyname ((const char*) proxyName.toUTF8());
  193940. port = proxyPort;
  193941. }
  193942. else
  193943. {
  193944. host = gethostbyname ((const char*) hostName.toUTF8());
  193945. port = hostPort;
  193946. }
  193947. if (host == 0)
  193948. return false;
  193949. struct sockaddr_in address;
  193950. zerostruct (address);
  193951. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193952. address.sin_family = host->h_addrtype;
  193953. address.sin_port = htons (port);
  193954. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193955. if (socketHandle == -1)
  193956. return false;
  193957. int receiveBufferSize = 16384;
  193958. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193959. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193960. #if JUCE_MAC
  193961. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193962. #endif
  193963. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193964. {
  193965. closeSocket();
  193966. return false;
  193967. }
  193968. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193969. proxyName, proxyPort,
  193970. hostPath, url,
  193971. headers, postData,
  193972. isPost));
  193973. size_t totalHeaderSent = 0;
  193974. while (totalHeaderSent < requestHeader.getSize())
  193975. {
  193976. if (Time::getMillisecondCounter() > timeOutTime)
  193977. {
  193978. closeSocket();
  193979. return false;
  193980. }
  193981. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193982. if (send (socketHandle,
  193983. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193984. numToSend, 0)
  193985. != numToSend)
  193986. {
  193987. closeSocket();
  193988. return false;
  193989. }
  193990. totalHeaderSent += numToSend;
  193991. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193992. {
  193993. closeSocket();
  193994. return false;
  193995. }
  193996. }
  193997. const String responseHeader (readResponse (timeOutTime));
  193998. if (responseHeader.isNotEmpty())
  193999. {
  194000. //DBG (responseHeader);
  194001. StringArray lines;
  194002. lines.addLines (responseHeader);
  194003. // NB - using charToString() here instead of just T(" "), because that was
  194004. // causing a mysterious gcc internal compiler error...
  194005. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  194006. .substring (0, 3).getIntValue();
  194007. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  194008. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  194009. String location (findHeaderItem (lines, T("Location:")));
  194010. if (statusCode >= 300 && statusCode < 400
  194011. && location.isNotEmpty())
  194012. {
  194013. if (! location.startsWithIgnoreCase (T("http://")))
  194014. location = T("http://") + location;
  194015. if (levelsOfRedirection++ < 3)
  194016. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  194017. }
  194018. else
  194019. {
  194020. levelsOfRedirection = 0;
  194021. return true;
  194022. }
  194023. }
  194024. closeSocket();
  194025. return false;
  194026. }
  194027. int read (void* buffer, int bytesToRead)
  194028. {
  194029. fd_set readbits;
  194030. FD_ZERO (&readbits);
  194031. FD_SET (socketHandle, &readbits);
  194032. struct timeval tv;
  194033. tv.tv_sec = timeoutSeconds;
  194034. tv.tv_usec = 0;
  194035. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194036. return 0; // (timeout)
  194037. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  194038. readPosition += bytesRead;
  194039. return bytesRead;
  194040. }
  194041. int readPosition;
  194042. juce_UseDebuggingNewOperator
  194043. private:
  194044. int socketHandle, levelsOfRedirection;
  194045. const int timeoutSeconds;
  194046. void closeSocket()
  194047. {
  194048. if (socketHandle >= 0)
  194049. close (socketHandle);
  194050. socketHandle = -1;
  194051. }
  194052. const MemoryBlock createRequestHeader (const String& hostName,
  194053. const int hostPort,
  194054. const String& proxyName,
  194055. const int proxyPort,
  194056. const String& hostPath,
  194057. const String& originalURL,
  194058. const String& headers,
  194059. const MemoryBlock& postData,
  194060. const bool isPost)
  194061. {
  194062. String header (isPost ? "POST " : "GET ");
  194063. if (proxyName.isEmpty())
  194064. {
  194065. header << hostPath << " HTTP/1.0\r\nHost: "
  194066. << hostName << ':' << hostPort;
  194067. }
  194068. else
  194069. {
  194070. header << originalURL << " HTTP/1.0\r\nHost: "
  194071. << proxyName << ':' << proxyPort;
  194072. }
  194073. header << "\r\nUser-Agent: JUCE/"
  194074. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  194075. << "\r\nConnection: Close\r\nContent-Length: "
  194076. << postData.getSize() << "\r\n"
  194077. << headers << "\r\n";
  194078. MemoryBlock mb;
  194079. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  194080. mb.append (postData.getData(), postData.getSize());
  194081. return mb;
  194082. }
  194083. const String readResponse (const uint32 timeOutTime)
  194084. {
  194085. int bytesRead = 0, numConsecutiveLFs = 0;
  194086. MemoryBlock buffer (1024, true);
  194087. while (numConsecutiveLFs < 2 && bytesRead < 32768
  194088. && Time::getMillisecondCounter() <= timeOutTime)
  194089. {
  194090. fd_set readbits;
  194091. FD_ZERO (&readbits);
  194092. FD_SET (socketHandle, &readbits);
  194093. struct timeval tv;
  194094. tv.tv_sec = timeoutSeconds;
  194095. tv.tv_usec = 0;
  194096. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194097. return String::empty; // (timeout)
  194098. buffer.ensureSize (bytesRead + 8, true);
  194099. char* const dest = (char*) buffer.getData() + bytesRead;
  194100. if (recv (socketHandle, dest, 1, 0) == -1)
  194101. return String::empty;
  194102. const char lastByte = *dest;
  194103. ++bytesRead;
  194104. if (lastByte == '\n')
  194105. ++numConsecutiveLFs;
  194106. else if (lastByte != '\r')
  194107. numConsecutiveLFs = 0;
  194108. }
  194109. const String header (String::fromUTF8 ((const uint8*) buffer.getData()));
  194110. if (header.startsWithIgnoreCase (T("HTTP/")))
  194111. return header.trimEnd();
  194112. return String::empty;
  194113. }
  194114. static bool decomposeURL (const String& url,
  194115. String& host, String& path, int& port)
  194116. {
  194117. if (! url.startsWithIgnoreCase (T("http://")))
  194118. return false;
  194119. const int nextSlash = url.indexOfChar (7, '/');
  194120. int nextColon = url.indexOfChar (7, ':');
  194121. if (nextColon > nextSlash && nextSlash > 0)
  194122. nextColon = -1;
  194123. if (nextColon >= 0)
  194124. {
  194125. host = url.substring (7, nextColon);
  194126. if (nextSlash >= 0)
  194127. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194128. else
  194129. port = url.substring (nextColon + 1).getIntValue();
  194130. }
  194131. else
  194132. {
  194133. port = 80;
  194134. if (nextSlash >= 0)
  194135. host = url.substring (7, nextSlash);
  194136. else
  194137. host = url.substring (7);
  194138. }
  194139. if (nextSlash >= 0)
  194140. path = url.substring (nextSlash);
  194141. else
  194142. path = T("/");
  194143. return true;
  194144. }
  194145. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194146. {
  194147. for (int i = 0; i < lines.size(); ++i)
  194148. if (lines[i].startsWithIgnoreCase (itemName))
  194149. return lines[i].substring (itemName.length()).trim();
  194150. return String::empty;
  194151. }
  194152. };
  194153. bool juce_isOnLine()
  194154. {
  194155. return true;
  194156. }
  194157. void* juce_openInternetFile (const String& url,
  194158. const String& headers,
  194159. const MemoryBlock& postData,
  194160. const bool isPost,
  194161. URL::OpenStreamProgressCallback* callback,
  194162. void* callbackContext,
  194163. int timeOutMs)
  194164. {
  194165. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194166. if (s->open (url, headers, postData, isPost,
  194167. callback, callbackContext, timeOutMs))
  194168. return s;
  194169. delete s;
  194170. return 0;
  194171. }
  194172. void juce_closeInternetFile (void* handle)
  194173. {
  194174. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194175. if (s != 0)
  194176. delete s;
  194177. }
  194178. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194179. {
  194180. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194181. if (s != 0)
  194182. return s->read (buffer, bytesToRead);
  194183. return 0;
  194184. }
  194185. int64 juce_getInternetFileContentLength (void* handle)
  194186. {
  194187. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194188. if (s != 0)
  194189. {
  194190. //xxx todo
  194191. jassertfalse
  194192. }
  194193. return -1;
  194194. }
  194195. int juce_seekInInternetFile (void* handle, int newPosition)
  194196. {
  194197. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194198. if (s != 0)
  194199. return s->readPosition;
  194200. return 0;
  194201. }
  194202. #endif
  194203. /*** End of inlined file: juce_linux_Network.cpp ***/
  194204. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  194205. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194206. // compiled on its own).
  194207. #if JUCE_INCLUDED_FILE
  194208. void Logger::outputDebugString (const String& text) throw()
  194209. {
  194210. fputs (text.toUTF8(), stdout);
  194211. fputs ("\n", stdout);
  194212. }
  194213. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194214. {
  194215. String text;
  194216. va_list args;
  194217. va_start (args, format);
  194218. text.vprintf(format, args);
  194219. outputDebugString(text);
  194220. }
  194221. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194222. {
  194223. return Linux;
  194224. }
  194225. const String SystemStats::getOperatingSystemName() throw()
  194226. {
  194227. return T("Linux");
  194228. }
  194229. bool SystemStats::isOperatingSystem64Bit() throw()
  194230. {
  194231. #if JUCE_64BIT
  194232. return true;
  194233. #else
  194234. //xxx not sure how to find this out?..
  194235. return false;
  194236. #endif
  194237. }
  194238. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194239. {
  194240. String info;
  194241. char buf [256];
  194242. FILE* f = fopen ("/proc/cpuinfo", "r");
  194243. while (f != 0 && fgets (buf, sizeof(buf), f))
  194244. {
  194245. if (strncmp (buf, key, strlen (key)) == 0)
  194246. {
  194247. char* p = buf;
  194248. while (*p && *p != '\n')
  194249. ++p;
  194250. if (*p != 0)
  194251. *p = 0;
  194252. p = buf;
  194253. while (*p != 0 && *p != ':')
  194254. ++p;
  194255. if (*p != 0 && *(p + 1) != 0)
  194256. info = p + 2;
  194257. if (! lastOne)
  194258. break;
  194259. }
  194260. }
  194261. fclose (f);
  194262. return info;
  194263. }
  194264. bool SystemStats::hasMMX() throw()
  194265. {
  194266. return getCpuInfo ("flags").contains (T("mmx"));
  194267. }
  194268. bool SystemStats::hasSSE() throw()
  194269. {
  194270. return getCpuInfo ("flags").contains (T("sse"));
  194271. }
  194272. bool SystemStats::hasSSE2() throw()
  194273. {
  194274. return getCpuInfo ("flags").contains (T("sse2"));
  194275. }
  194276. bool SystemStats::has3DNow() throw()
  194277. {
  194278. return getCpuInfo ("flags").contains (T("3dnow"));
  194279. }
  194280. const String SystemStats::getCpuVendor() throw()
  194281. {
  194282. return getCpuInfo ("vendor_id");
  194283. }
  194284. int SystemStats::getCpuSpeedInMegaherz() throw()
  194285. {
  194286. const String speed (getCpuInfo ("cpu MHz"));
  194287. return (int) (speed.getFloatValue() + 0.5f);
  194288. }
  194289. int SystemStats::getMemorySizeInMegabytes() throw()
  194290. {
  194291. struct sysinfo sysi;
  194292. if (sysinfo (&sysi) == 0)
  194293. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194294. return 0;
  194295. }
  194296. uint32 juce_millisecondsSinceStartup() throw()
  194297. {
  194298. static unsigned int calibrate = 0;
  194299. static bool calibrated = false;
  194300. timeval t;
  194301. unsigned int ret = 0;
  194302. if (! gettimeofday (&t, 0))
  194303. {
  194304. if (! calibrated)
  194305. {
  194306. struct sysinfo sysi;
  194307. if (sysinfo (&sysi) == 0)
  194308. // Safe to assume system was not brought up earlier than 1970!
  194309. calibrate = t.tv_sec - sysi.uptime;
  194310. calibrated = true;
  194311. }
  194312. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194313. }
  194314. return ret;
  194315. }
  194316. double Time::getMillisecondCounterHiRes() throw()
  194317. {
  194318. return getHighResolutionTicks() * 0.001;
  194319. }
  194320. int64 Time::getHighResolutionTicks() throw()
  194321. {
  194322. timeval t;
  194323. if (gettimeofday (&t, 0))
  194324. return 0;
  194325. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194326. }
  194327. int64 Time::getHighResolutionTicksPerSecond() throw()
  194328. {
  194329. // Microseconds
  194330. return 1000000;
  194331. }
  194332. bool Time::setSystemTimeToThisTime() const throw()
  194333. {
  194334. timeval t;
  194335. t.tv_sec = millisSinceEpoch % 1000000;
  194336. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194337. return settimeofday (&t, NULL) ? false : true;
  194338. }
  194339. int SystemStats::getPageSize() throw()
  194340. {
  194341. static int systemPageSize = 0;
  194342. if (systemPageSize == 0)
  194343. systemPageSize = sysconf (_SC_PAGESIZE);
  194344. return systemPageSize;
  194345. }
  194346. int SystemStats::getNumCpus() throw()
  194347. {
  194348. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194349. return lastCpu + 1;
  194350. }
  194351. const String SystemStats::getLogonName()
  194352. {
  194353. const char* user = getenv ("USER");
  194354. if (user == 0)
  194355. {
  194356. struct passwd* const pw = getpwuid (getuid());
  194357. if (pw != 0)
  194358. user = pw->pw_name;
  194359. }
  194360. return String::fromUTF8 ((const uint8*) user);
  194361. }
  194362. const String SystemStats::getFullUserName()
  194363. {
  194364. return getLogonName();
  194365. }
  194366. void SystemStats::initialiseStats() throw()
  194367. {
  194368. // Process starts off as root when running suid
  194369. Process::lowerPrivilege();
  194370. String s (SystemStats::getJUCEVersion());
  194371. }
  194372. void PlatformUtilities::fpuReset()
  194373. {
  194374. }
  194375. #endif
  194376. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194377. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194378. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194379. // compiled on its own).
  194380. #if JUCE_INCLUDED_FILE
  194381. void JUCE_API juce_threadEntryPoint (void*);
  194382. void* threadEntryProc (void* value)
  194383. {
  194384. // New threads start off as root when running suid
  194385. Process::lowerPrivilege();
  194386. juce_threadEntryPoint (value);
  194387. return 0;
  194388. }
  194389. void* juce_createThread (void* userData)
  194390. {
  194391. pthread_t handle = 0;
  194392. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194393. {
  194394. pthread_detach (handle);
  194395. return (void*)handle;
  194396. }
  194397. return 0;
  194398. }
  194399. void juce_killThread (void* handle)
  194400. {
  194401. if (handle != 0)
  194402. pthread_cancel ((pthread_t)handle);
  194403. }
  194404. void juce_setCurrentThreadName (const String& /*name*/)
  194405. {
  194406. }
  194407. Thread::ThreadID Thread::getCurrentThreadId()
  194408. {
  194409. return (ThreadID) pthread_self();
  194410. }
  194411. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194412. // priority of the current thread
  194413. bool juce_setThreadPriority (void* handle, int priority)
  194414. {
  194415. struct sched_param param;
  194416. int policy, maxp, minp, pri;
  194417. if (handle == 0)
  194418. handle = (void*) pthread_self();
  194419. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194420. && policy != SCHED_OTHER)
  194421. {
  194422. minp = sched_get_priority_min(policy);
  194423. maxp = sched_get_priority_max(policy);
  194424. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194425. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194426. // Realtime process priority
  194427. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194428. else
  194429. // High process priority
  194430. param.__sched_priority = minp + pri;
  194431. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194432. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194433. }
  194434. return false;
  194435. }
  194436. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194437. {
  194438. #if SUPPORT_AFFINITIES
  194439. cpu_set_t affinity;
  194440. CPU_ZERO (&affinity);
  194441. for (int i = 0; i < 32; ++i)
  194442. if ((affinityMask & (1 << i)) != 0)
  194443. CPU_SET (i, &affinity);
  194444. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194445. sched_yield();
  194446. #else
  194447. /* affinities aren't supported because either the appropriate header files weren't found,
  194448. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194449. */
  194450. jassertfalse
  194451. #endif
  194452. }
  194453. void Thread::yield()
  194454. {
  194455. sched_yield();
  194456. }
  194457. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194458. void Process::setPriority (ProcessPriority prior)
  194459. {
  194460. struct sched_param param;
  194461. int policy, maxp, minp;
  194462. const int p = (int) prior;
  194463. if (p <= 1)
  194464. policy = SCHED_OTHER;
  194465. else
  194466. policy = SCHED_RR;
  194467. minp = sched_get_priority_min (policy);
  194468. maxp = sched_get_priority_max (policy);
  194469. if (p < 2)
  194470. param.__sched_priority = 0;
  194471. else if (p == 2 )
  194472. // Set to middle of lower realtime priority range
  194473. param.__sched_priority = minp + (maxp - minp) / 4;
  194474. else
  194475. // Set to middle of higher realtime priority range
  194476. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194477. pthread_setschedparam (pthread_self(), policy, &param);
  194478. }
  194479. void Process::terminate()
  194480. {
  194481. exit (0);
  194482. }
  194483. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194484. {
  194485. static char testResult = 0;
  194486. if (testResult == 0)
  194487. {
  194488. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194489. if (testResult >= 0)
  194490. {
  194491. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194492. testResult = 1;
  194493. }
  194494. }
  194495. return testResult < 0;
  194496. }
  194497. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194498. {
  194499. return juce_isRunningUnderDebugger();
  194500. }
  194501. void Process::raisePrivilege()
  194502. {
  194503. // If running suid root, change effective user
  194504. // to root
  194505. if (geteuid() != 0 && getuid() == 0)
  194506. {
  194507. setreuid (geteuid(), getuid());
  194508. setregid (getegid(), getgid());
  194509. }
  194510. }
  194511. void Process::lowerPrivilege()
  194512. {
  194513. // If runing suid root, change effective user
  194514. // back to real user
  194515. if (geteuid() == 0 && getuid() != 0)
  194516. {
  194517. setreuid (geteuid(), getuid());
  194518. setregid (getegid(), getgid());
  194519. }
  194520. }
  194521. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194522. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194523. {
  194524. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194525. }
  194526. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194527. {
  194528. dlclose(handle);
  194529. }
  194530. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194531. {
  194532. return dlsym (libraryHandle, (const char*) procedureName);
  194533. }
  194534. #endif
  194535. #endif
  194536. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194537. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194538. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194539. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194540. // compiled on its own).
  194541. #if JUCE_INCLUDED_FILE
  194542. #ifdef JUCE_DEBUG
  194543. #define JUCE_DEBUG_XERRORS 1
  194544. #endif
  194545. extern Display* display;
  194546. extern Window juce_messageWindowHandle;
  194547. static String localClipboardContent;
  194548. static Atom atom_UTF8_STRING;
  194549. static Atom atom_CLIPBOARD;
  194550. static Atom atom_TARGETS;
  194551. static void initSelectionAtoms()
  194552. {
  194553. static bool isInitialised = false;
  194554. if (! isInitialised)
  194555. {
  194556. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194557. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194558. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194559. }
  194560. }
  194561. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194562. // works only for strings shorter than 1000000 bytes
  194563. static String juce_readWindowProperty (Window window, Atom prop,
  194564. Atom fmt, // XA_STRING or UTF8_STRING
  194565. bool deleteAfterReading)
  194566. {
  194567. String returnData;
  194568. uint8 *clipData;
  194569. Atom actualType;
  194570. int actualFormat;
  194571. unsigned long numItems, bytesLeft;
  194572. if (XGetWindowProperty (display, window, prop,
  194573. 0L /* offset */, 1000000 /* length (max) */, False,
  194574. AnyPropertyType /* format */,
  194575. &actualType, &actualFormat, &numItems, &bytesLeft,
  194576. &clipData) == Success)
  194577. {
  194578. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194579. {
  194580. returnData = String::fromUTF8 (clipData, numItems);
  194581. }
  194582. else if (actualType == XA_STRING && actualFormat == 8)
  194583. {
  194584. returnData = String ((const char*) clipData, numItems);
  194585. }
  194586. if (clipData != 0)
  194587. XFree (clipData);
  194588. jassert (bytesLeft == 0 || numItems == 1000000);
  194589. }
  194590. if (deleteAfterReading)
  194591. XDeleteProperty (display, window, prop);
  194592. return returnData;
  194593. }
  194594. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194595. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194596. {
  194597. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194598. // The selection owner will be asked to set the JUCE_SEL property on the
  194599. // juce_messageWindowHandle with the selection content
  194600. XConvertSelection (display, selection, requested_format, property_name,
  194601. juce_messageWindowHandle, CurrentTime);
  194602. int timeoutMs = 200; // will wait at most for 200 ms
  194603. do
  194604. {
  194605. XEvent event;
  194606. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194607. {
  194608. if (event.xselection.property == property_name)
  194609. {
  194610. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194611. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194612. event.xselection.property,
  194613. requested_format, true);
  194614. return true;
  194615. }
  194616. else
  194617. {
  194618. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194619. }
  194620. }
  194621. // not very elegant.. we could do a select() or something like that...
  194622. // however clipboard content requesting is inherently slow on x11, it
  194623. // often takes 50ms or more so...
  194624. Thread::sleep (4);
  194625. timeoutMs -= 4;
  194626. }
  194627. while (timeoutMs > 0);
  194628. DBG("timeout for juce_requestSelectionContent");
  194629. return false;
  194630. }
  194631. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194632. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194633. {
  194634. initSelectionAtoms();
  194635. // the selection content is sent to the target window as a window property
  194636. XSelectionEvent reply;
  194637. reply.type = SelectionNotify;
  194638. reply.display = evt.display;
  194639. reply.requestor = evt.requestor;
  194640. reply.selection = evt.selection;
  194641. reply.target = evt.target;
  194642. reply.property = None; // == "fail"
  194643. reply.time = evt.time;
  194644. HeapBlock <char> data;
  194645. int propertyFormat = 0, numDataItems = 0;
  194646. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194647. {
  194648. if (evt.target == XA_STRING)
  194649. {
  194650. // format data according to system locale
  194651. numDataItems = localClipboardContent.length();
  194652. data.calloc (numDataItems + 2);
  194653. localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1);
  194654. propertyFormat = 8; // bits/item
  194655. }
  194656. else if (evt.target == atom_UTF8_STRING)
  194657. {
  194658. // translate to utf8
  194659. numDataItems = localClipboardContent.copyToUTF8 (0);
  194660. data.calloc (numDataItems + 2);
  194661. localClipboardContent.copyToUTF8 (data, numDataItems + 1);
  194662. propertyFormat = 8; // bits/item
  194663. }
  194664. else if (evt.target == atom_TARGETS)
  194665. {
  194666. // another application wants to know what we are able to send
  194667. numDataItems = 2;
  194668. propertyFormat = 32; // atoms are 32-bit
  194669. data.calloc (numDataItems * 4);
  194670. ((Atom*) data)[0] = atom_UTF8_STRING;
  194671. ((Atom*) data)[1] = XA_STRING;
  194672. }
  194673. }
  194674. else
  194675. {
  194676. DBG ("requested unsupported clipboard");
  194677. }
  194678. if (data != 0)
  194679. {
  194680. const int maxReasonableSelectionSize = 1000000;
  194681. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194682. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194683. {
  194684. XChangeProperty (evt.display, evt.requestor,
  194685. evt.property, evt.target,
  194686. propertyFormat /* 8 or 32 */, PropModeReplace,
  194687. (const unsigned char*) data, numDataItems);
  194688. reply.property = evt.property; // " == success"
  194689. }
  194690. }
  194691. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194692. }
  194693. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194694. {
  194695. initSelectionAtoms();
  194696. localClipboardContent = clipText;
  194697. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194698. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194699. }
  194700. const String SystemClipboard::getTextFromClipboard() throw()
  194701. {
  194702. initSelectionAtoms();
  194703. String content;
  194704. Atom selection = XA_PRIMARY;
  194705. Window selectionOwner = None;
  194706. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194707. {
  194708. selection = atom_CLIPBOARD;
  194709. selectionOwner = XGetSelectionOwner (display, selection);
  194710. }
  194711. if (selectionOwner != None)
  194712. {
  194713. if (selectionOwner == juce_messageWindowHandle)
  194714. {
  194715. content = localClipboardContent;
  194716. }
  194717. else
  194718. {
  194719. // first try: we want an utf8 string
  194720. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194721. if (! ok)
  194722. {
  194723. // second chance, ask for a good old locale-dependent string ..
  194724. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194725. }
  194726. }
  194727. }
  194728. return content;
  194729. }
  194730. #endif
  194731. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194732. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194733. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194734. // compiled on its own).
  194735. #if JUCE_INCLUDED_FILE
  194736. #ifdef JUCE_DEBUG
  194737. #define JUCE_DEBUG_XERRORS 1
  194738. #endif
  194739. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194740. Window juce_messageWindowHandle = None;
  194741. #define SpecialAtom "JUCESpecialAtom"
  194742. #define BroadcastAtom "JUCEBroadcastAtom"
  194743. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194744. static Atom specialId;
  194745. static Atom broadcastId;
  194746. static Atom specialCallbackId;
  194747. // This is referenced from Windowing.cpp
  194748. XContext improbableNumber;
  194749. // Defined in Windowing.cpp
  194750. extern void juce_windowMessageReceive (XEvent* event);
  194751. // Defined in Clipboard.cpp
  194752. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194753. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194754. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194755. class InternalMessageQueue
  194756. {
  194757. public:
  194758. InternalMessageQueue()
  194759. : bytesInSocket (0)
  194760. {
  194761. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194762. (void) ret; jassert (ret == 0);
  194763. setNonBlocking (fd[0]);
  194764. setNonBlocking (fd[1]);
  194765. }
  194766. ~InternalMessageQueue()
  194767. {
  194768. close (fd[0]);
  194769. close (fd[1]);
  194770. }
  194771. void postMessage (Message* msg)
  194772. {
  194773. const int maxBytesInSocketQueue = 128;
  194774. ScopedLock sl (lock);
  194775. queue.add (msg);
  194776. if (bytesInSocket < maxBytesInSocketQueue)
  194777. {
  194778. ++bytesInSocket;
  194779. ScopedUnlock ul (lock);
  194780. const unsigned char x = 0xff;
  194781. size_t bytesWritten = write (fd[0], &x, 1);
  194782. (void) bytesWritten;
  194783. }
  194784. }
  194785. bool isEmpty() const
  194786. {
  194787. ScopedLock sl (lock);
  194788. return queue.size() == 0;
  194789. }
  194790. Message* popNextMessage()
  194791. {
  194792. ScopedLock sl (lock);
  194793. if (bytesInSocket > 0)
  194794. {
  194795. --bytesInSocket;
  194796. ScopedUnlock ul (lock);
  194797. unsigned char x;
  194798. size_t numBytes = read (fd[1], &x, 1);
  194799. (void) numBytes;
  194800. }
  194801. Message* m = queue[0];
  194802. queue.remove (0, false /* deleteObject */);
  194803. return m;
  194804. }
  194805. int getWaitHandle() const { return fd[1]; }
  194806. private:
  194807. CriticalSection lock;
  194808. OwnedArray <Message> queue;
  194809. int fd[2];
  194810. int bytesInSocket;
  194811. static bool setNonBlocking (int handle)
  194812. {
  194813. int socketFlags = fcntl (handle, F_GETFL, 0);
  194814. if (socketFlags == -1)
  194815. return false;
  194816. socketFlags |= O_NONBLOCK;
  194817. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194818. }
  194819. };
  194820. struct MessageThreadFuncCall
  194821. {
  194822. enum { uniqueID = 0x73774623 };
  194823. MessageCallbackFunction* func;
  194824. void* parameter;
  194825. void* result;
  194826. CriticalSection lock;
  194827. WaitableEvent event;
  194828. };
  194829. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194830. // error handling in X11
  194831. static bool errorOccurred = false;
  194832. static bool keyboardBreakOccurred = false;
  194833. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194834. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194835. // Usually happens when client-server connection is broken
  194836. static int ioErrorHandler (Display* display)
  194837. {
  194838. DBG (T("ERROR: connection to X server broken.. terminating."));
  194839. errorOccurred = true;
  194840. if (JUCEApplication::getInstance() != 0)
  194841. Process::terminate();
  194842. return 0;
  194843. }
  194844. // A protocol error has occurred
  194845. static int errorHandler (Display* display, XErrorEvent* event)
  194846. {
  194847. #ifdef JUCE_DEBUG_XERRORS
  194848. char errorStr[64] = { 0 };
  194849. char requestStr[64] = { 0 };
  194850. XGetErrorText (display, event->error_code, errorStr, 64);
  194851. XGetErrorDatabaseText (display,
  194852. "XRequest",
  194853. (const char*) String (event->request_code),
  194854. "Unknown",
  194855. requestStr,
  194856. 64);
  194857. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194858. #endif
  194859. return 0;
  194860. }
  194861. // Breakin from keyboard
  194862. static void signalHandler (int sig)
  194863. {
  194864. if (sig == SIGINT)
  194865. {
  194866. keyboardBreakOccurred = true;
  194867. return;
  194868. }
  194869. static bool reentrant = false;
  194870. if (! reentrant)
  194871. {
  194872. reentrant = true;
  194873. // Illegal instruction
  194874. fflush (stdout);
  194875. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194876. errorOccurred = true;
  194877. if (JUCEApplication::getInstance() != 0)
  194878. Process::terminate();
  194879. }
  194880. else
  194881. {
  194882. if (JUCEApplication::getInstance() != 0)
  194883. exit(0);
  194884. }
  194885. }
  194886. void MessageManager::doPlatformSpecificInitialisation()
  194887. {
  194888. // Initialise xlib for multiple thread support
  194889. static bool initThreadCalled = false;
  194890. if (! initThreadCalled)
  194891. {
  194892. if (! XInitThreads())
  194893. {
  194894. // This is fatal! Print error and closedown
  194895. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194896. if (JUCEApplication::getInstance() != 0)
  194897. Process::terminate();
  194898. return;
  194899. }
  194900. initThreadCalled = true;
  194901. }
  194902. // This is called if the client/server connection is broken
  194903. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194904. // This is called if a protocol error occurs
  194905. oldErrorHandler = XSetErrorHandler (errorHandler);
  194906. // Install signal handler for break-in
  194907. struct sigaction saction;
  194908. sigset_t maskSet;
  194909. sigemptyset (&maskSet);
  194910. saction.sa_handler = signalHandler;
  194911. saction.sa_mask = maskSet;
  194912. saction.sa_flags = 0;
  194913. sigaction (SIGINT, &saction, NULL);
  194914. #ifndef _DEBUG
  194915. // Setup signal handlers for various fatal errors
  194916. sigaction (SIGILL, &saction, NULL);
  194917. sigaction (SIGBUS, &saction, NULL);
  194918. sigaction (SIGFPE, &saction, NULL);
  194919. sigaction (SIGSEGV, &saction, NULL);
  194920. sigaction (SIGSYS, &saction, NULL);
  194921. #endif
  194922. // Create the internal message queue
  194923. juce_internalMessageQueue = new InternalMessageQueue();
  194924. // Try to connect to a display
  194925. String displayName (getenv ("DISPLAY"));
  194926. if (displayName.isEmpty())
  194927. displayName = T(":0.0");
  194928. display = XOpenDisplay (displayName);
  194929. if (display == 0)
  194930. {
  194931. // This is not fatal! we can run headless.
  194932. return;
  194933. }
  194934. // Get defaults for various properties
  194935. int screen = DefaultScreen (display);
  194936. Window root = RootWindow (display, screen);
  194937. Visual* visual = DefaultVisual (display, screen);
  194938. // Create atoms for our ClientMessages (these cannot be deleted)
  194939. specialId = XInternAtom (display, SpecialAtom, false);
  194940. broadcastId = XInternAtom (display, BroadcastAtom, false);
  194941. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  194942. // Create a context to store user data associated with Windows we
  194943. // create in WindowDriver
  194944. improbableNumber = XUniqueContext();
  194945. // We're only interested in client messages for this window
  194946. // which are always sent
  194947. XSetWindowAttributes swa;
  194948. swa.event_mask = NoEventMask;
  194949. // Create our message window (this will never be mapped)
  194950. juce_messageWindowHandle = XCreateWindow (display, root,
  194951. 0, 0, 1, 1, 0, 0, InputOnly,
  194952. visual, CWEventMask, &swa);
  194953. }
  194954. void MessageManager::doPlatformSpecificShutdown()
  194955. {
  194956. deleteAndZero (juce_internalMessageQueue);
  194957. if (display != 0 && ! errorOccurred)
  194958. {
  194959. XDestroyWindow (display, juce_messageWindowHandle);
  194960. XCloseDisplay (display);
  194961. // reset pointers
  194962. juce_messageWindowHandle = 0;
  194963. display = 0;
  194964. // Restore original error handlers
  194965. XSetIOErrorHandler (oldIOErrorHandler);
  194966. oldIOErrorHandler = 0;
  194967. XSetErrorHandler (oldErrorHandler);
  194968. oldErrorHandler = 0;
  194969. }
  194970. }
  194971. bool juce_postMessageToSystemQueue (void* message)
  194972. {
  194973. if (errorOccurred)
  194974. return false;
  194975. juce_internalMessageQueue->postMessage ((Message*) message);
  194976. return true;
  194977. }
  194978. void MessageManager::broadcastMessage (const String& value) throw()
  194979. {
  194980. }
  194981. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194982. void* parameter)
  194983. {
  194984. if (errorOccurred)
  194985. return 0;
  194986. if (! isThisTheMessageThread())
  194987. {
  194988. MessageThreadFuncCall messageCallContext;
  194989. messageCallContext.func = func;
  194990. messageCallContext.parameter = parameter;
  194991. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194992. 0, 0, &messageCallContext));
  194993. // Wait for it to complete before continuing
  194994. messageCallContext.event.wait();
  194995. return messageCallContext.result;
  194996. }
  194997. else
  194998. {
  194999. // Just call the function directly
  195000. return func (parameter);
  195001. }
  195002. }
  195003. // Wait for an event (either XEvent, or an internal Message)
  195004. static bool juce_sleepUntilEvent (const int timeoutMs)
  195005. {
  195006. if (! juce_internalMessageQueue->isEmpty())
  195007. return true;
  195008. if (display != 0)
  195009. {
  195010. ScopedXLock xlock;
  195011. if (XPending (display))
  195012. return true;
  195013. }
  195014. struct timeval tv;
  195015. tv.tv_sec = 0;
  195016. tv.tv_usec = timeoutMs * 1000;
  195017. int fd0 = juce_internalMessageQueue->getWaitHandle();
  195018. int fdmax = fd0;
  195019. fd_set readset;
  195020. FD_ZERO (&readset);
  195021. FD_SET (fd0, &readset);
  195022. if (display != 0)
  195023. {
  195024. ScopedXLock xlock;
  195025. int fd1 = XConnectionNumber (display);
  195026. FD_SET (fd1, &readset);
  195027. fdmax = jmax (fd0, fd1);
  195028. }
  195029. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  195030. return (ret > 0); // ret <= 0 if error or timeout
  195031. }
  195032. // Handle next XEvent (if any)
  195033. static bool juce_dispatchNextXEvent()
  195034. {
  195035. if (display == 0)
  195036. return false;
  195037. XEvent evt;
  195038. {
  195039. ScopedXLock xlock;
  195040. if (! XPending (display))
  195041. return false;
  195042. XNextEvent (display, &evt);
  195043. }
  195044. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  195045. {
  195046. juce_handleSelectionRequest (evt.xselectionrequest);
  195047. }
  195048. else if (evt.xany.window != juce_messageWindowHandle)
  195049. {
  195050. juce_windowMessageReceive (&evt);
  195051. }
  195052. return true;
  195053. }
  195054. // Handle next internal Message (if any)
  195055. static bool juce_dispatchNextInternalMessage()
  195056. {
  195057. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  195058. if (msg == 0)
  195059. return false;
  195060. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  195061. {
  195062. // Handle callback message
  195063. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  195064. call->result = (*(call->func)) (call->parameter);
  195065. call->event.signal();
  195066. }
  195067. else
  195068. {
  195069. // Handle "normal" messages
  195070. MessageManager::getInstance()->deliverMessage (msg.release());
  195071. }
  195072. return true;
  195073. }
  195074. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  195075. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  195076. {
  195077. for (;;)
  195078. {
  195079. if (errorOccurred)
  195080. break;
  195081. if (keyboardBreakOccurred)
  195082. {
  195083. errorOccurred = true;
  195084. if (JUCEApplication::getInstance() != 0)
  195085. Process::terminate();
  195086. break;
  195087. }
  195088. static int totalEventCount = 0;
  195089. ++totalEventCount;
  195090. // The purpose here is to give either priority to XEvents or
  195091. // to internal messages This is necessary to keep a "good"
  195092. // behaviour when the cpu is overloaded
  195093. if (totalEventCount & 1)
  195094. {
  195095. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  195096. return true;
  195097. }
  195098. else
  195099. {
  195100. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  195101. return true;
  195102. }
  195103. if (returnIfNoPendingMessages) // early exit
  195104. break;
  195105. // the timeout is to be on the safe side, but it does not seem to be useful
  195106. juce_sleepUntilEvent (2000);
  195107. }
  195108. return false;
  195109. }
  195110. #endif
  195111. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  195112. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  195113. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195114. // compiled on its own).
  195115. #if JUCE_INCLUDED_FILE
  195116. class FreeTypeFontFace
  195117. {
  195118. public:
  195119. enum FontStyle
  195120. {
  195121. Plain = 0,
  195122. Bold = 1,
  195123. Italic = 2
  195124. };
  195125. struct FontNameIndex
  195126. {
  195127. String fileName;
  195128. int faceIndex;
  195129. };
  195130. FreeTypeFontFace (const String& familyName) throw()
  195131. : hasSerif (false),
  195132. monospaced (false)
  195133. {
  195134. family = familyName;
  195135. }
  195136. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195137. {
  195138. if (names [(int) style].fileName.isEmpty())
  195139. {
  195140. names [(int) style].fileName = name;
  195141. names [(int) style].faceIndex = faceIndex;
  195142. }
  195143. }
  195144. const String& getFamilyName() const throw() { return family; }
  195145. const String& getFileName (const int style, int& faceIndex) const throw()
  195146. {
  195147. faceIndex = names[style].faceIndex;
  195148. return names[style].fileName;
  195149. }
  195150. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195151. bool getMonospaced() const throw() { return monospaced; }
  195152. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195153. bool getSerif() const throw() { return hasSerif; }
  195154. private:
  195155. String family;
  195156. FontNameIndex names[4];
  195157. bool hasSerif, monospaced;
  195158. };
  195159. class FreeTypeInterface : public DeletedAtShutdown
  195160. {
  195161. public:
  195162. FreeTypeInterface() throw()
  195163. : lastFace (0),
  195164. lastBold (false),
  195165. lastItalic (false)
  195166. {
  195167. if (FT_Init_FreeType (&ftLib) != 0)
  195168. {
  195169. ftLib = 0;
  195170. DBG (T("Failed to initialize FreeType"));
  195171. }
  195172. StringArray fontDirs;
  195173. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195174. fontDirs.removeEmptyStrings (true);
  195175. if (fontDirs.size() == 0)
  195176. {
  195177. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195178. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195179. if (fontsInfo != 0)
  195180. {
  195181. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195182. {
  195183. fontDirs.add (e->getAllSubText().trim());
  195184. }
  195185. delete fontsInfo;
  195186. }
  195187. }
  195188. if (fontDirs.size() == 0)
  195189. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195190. for (int i = 0; i < fontDirs.size(); ++i)
  195191. enumerateFaces (fontDirs[i]);
  195192. }
  195193. ~FreeTypeInterface() throw()
  195194. {
  195195. if (lastFace != 0)
  195196. FT_Done_Face (lastFace);
  195197. if (ftLib != 0)
  195198. FT_Done_FreeType (ftLib);
  195199. clearSingletonInstance();
  195200. }
  195201. FreeTypeFontFace* findOrCreate (const String& familyName,
  195202. const bool create = false) throw()
  195203. {
  195204. for (int i = 0; i < faces.size(); i++)
  195205. if (faces[i]->getFamilyName() == familyName)
  195206. return faces[i];
  195207. if (! create)
  195208. return NULL;
  195209. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195210. faces.add (newFace);
  195211. return newFace;
  195212. }
  195213. // Enumerate all font faces available in a given directory
  195214. void enumerateFaces (const String& path) throw()
  195215. {
  195216. File dirPath (path);
  195217. if (path.isEmpty() || ! dirPath.isDirectory())
  195218. return;
  195219. DirectoryIterator di (dirPath, true);
  195220. while (di.next())
  195221. {
  195222. File possible (di.getFile());
  195223. if (possible.hasFileExtension (T("ttf"))
  195224. || possible.hasFileExtension (T("pfb"))
  195225. || possible.hasFileExtension (T("pcf")))
  195226. {
  195227. FT_Face face;
  195228. int faceIndex = 0;
  195229. int numFaces = 0;
  195230. do
  195231. {
  195232. if (FT_New_Face (ftLib,
  195233. possible.getFullPathName(),
  195234. faceIndex,
  195235. &face) == 0)
  195236. {
  195237. if (faceIndex == 0)
  195238. numFaces = face->num_faces;
  195239. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195240. {
  195241. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195242. int style = (int) FreeTypeFontFace::Plain;
  195243. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195244. style |= (int) FreeTypeFontFace::Bold;
  195245. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195246. style |= (int) FreeTypeFontFace::Italic;
  195247. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195248. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195249. // Surely there must be a better way to do this?
  195250. const String name (face->family_name);
  195251. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195252. || name.containsIgnoreCase (T("Verdana"))
  195253. || name.containsIgnoreCase (T("Arial"))));
  195254. }
  195255. FT_Done_Face (face);
  195256. }
  195257. ++faceIndex;
  195258. }
  195259. while (faceIndex < numFaces);
  195260. }
  195261. }
  195262. }
  195263. // Create a FreeType face object for a given font
  195264. FT_Face createFT_Face (const String& fontName,
  195265. const bool bold,
  195266. const bool italic) throw()
  195267. {
  195268. FT_Face face = 0;
  195269. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195270. {
  195271. face = lastFace;
  195272. }
  195273. else
  195274. {
  195275. if (lastFace != 0)
  195276. {
  195277. FT_Done_Face (lastFace);
  195278. lastFace = 0;
  195279. }
  195280. lastFontName = fontName;
  195281. lastBold = bold;
  195282. lastItalic = italic;
  195283. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195284. if (ftFace != 0)
  195285. {
  195286. int style = (int) FreeTypeFontFace::Plain;
  195287. if (bold)
  195288. style |= (int) FreeTypeFontFace::Bold;
  195289. if (italic)
  195290. style |= (int) FreeTypeFontFace::Italic;
  195291. int faceIndex;
  195292. String fileName (ftFace->getFileName (style, faceIndex));
  195293. if (fileName.isEmpty())
  195294. {
  195295. style ^= (int) FreeTypeFontFace::Bold;
  195296. fileName = ftFace->getFileName (style, faceIndex);
  195297. if (fileName.isEmpty())
  195298. {
  195299. style ^= (int) FreeTypeFontFace::Bold;
  195300. style ^= (int) FreeTypeFontFace::Italic;
  195301. fileName = ftFace->getFileName (style, faceIndex);
  195302. if (! fileName.length())
  195303. {
  195304. style ^= (int) FreeTypeFontFace::Bold;
  195305. fileName = ftFace->getFileName (style, faceIndex);
  195306. }
  195307. }
  195308. }
  195309. if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace))
  195310. {
  195311. face = lastFace;
  195312. // If there isn't a unicode charmap then select the first one.
  195313. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195314. FT_Set_Charmap (face, face->charmaps[0]);
  195315. }
  195316. }
  195317. }
  195318. return face;
  195319. }
  195320. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195321. {
  195322. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195323. const float height = (float) (face->ascender - face->descender);
  195324. const float scaleX = 1.0f / height;
  195325. const float scaleY = -1.0f / height;
  195326. Path destShape;
  195327. #define CONVERTX(val) (scaleX * (val).x)
  195328. #define CONVERTY(val) (scaleY * (val).y)
  195329. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195330. || face->glyph->format != ft_glyph_format_outline)
  195331. {
  195332. return false;
  195333. }
  195334. const FT_Outline* const outline = &face->glyph->outline;
  195335. const short* const contours = outline->contours;
  195336. const char* const tags = outline->tags;
  195337. FT_Vector* const points = outline->points;
  195338. for (int c = 0; c < outline->n_contours; c++)
  195339. {
  195340. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195341. const int endPoint = contours[c];
  195342. for (int p = startPoint; p <= endPoint; p++)
  195343. {
  195344. const float x = CONVERTX (points[p]);
  195345. const float y = CONVERTY (points[p]);
  195346. if (p == startPoint)
  195347. {
  195348. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195349. {
  195350. float x2 = CONVERTX (points [endPoint]);
  195351. float y2 = CONVERTY (points [endPoint]);
  195352. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195353. {
  195354. x2 = (x + x2) * 0.5f;
  195355. y2 = (y + y2) * 0.5f;
  195356. }
  195357. destShape.startNewSubPath (x2, y2);
  195358. }
  195359. else
  195360. {
  195361. destShape.startNewSubPath (x, y);
  195362. }
  195363. }
  195364. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195365. {
  195366. if (p != startPoint)
  195367. destShape.lineTo (x, y);
  195368. }
  195369. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195370. {
  195371. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195372. float x2 = CONVERTX (points [nextIndex]);
  195373. float y2 = CONVERTY (points [nextIndex]);
  195374. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195375. {
  195376. x2 = (x + x2) * 0.5f;
  195377. y2 = (y + y2) * 0.5f;
  195378. }
  195379. else
  195380. {
  195381. ++p;
  195382. }
  195383. destShape.quadraticTo (x, y, x2, y2);
  195384. }
  195385. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195386. {
  195387. if (p >= endPoint)
  195388. return false;
  195389. const int next1 = p + 1;
  195390. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195391. const float x2 = CONVERTX (points [next1]);
  195392. const float y2 = CONVERTY (points [next1]);
  195393. const float x3 = CONVERTX (points [next2]);
  195394. const float y3 = CONVERTY (points [next2]);
  195395. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195396. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195397. return false;
  195398. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195399. p += 2;
  195400. }
  195401. }
  195402. destShape.closeSubPath();
  195403. }
  195404. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195405. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195406. addKerning (face, dest, character, glyphIndex);
  195407. return true;
  195408. }
  195409. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195410. {
  195411. const float height = (float) (face->ascender - face->descender);
  195412. uint32 rightGlyphIndex;
  195413. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195414. while (rightGlyphIndex != 0)
  195415. {
  195416. FT_Vector kerning;
  195417. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195418. {
  195419. if (kerning.x != 0)
  195420. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195421. }
  195422. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195423. }
  195424. }
  195425. // Add a glyph to a font
  195426. bool addGlyphToFont (const uint32 character,
  195427. const tchar* fontName, bool bold, bool italic,
  195428. CustomTypeface& dest) throw()
  195429. {
  195430. FT_Face face = createFT_Face (fontName, bold, italic);
  195431. if (face != 0)
  195432. return addGlyph (face, dest, character);
  195433. return false;
  195434. }
  195435. void getFamilyNames (StringArray& familyNames) const throw()
  195436. {
  195437. for (int i = 0; i < faces.size(); i++)
  195438. familyNames.add (faces[i]->getFamilyName());
  195439. }
  195440. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195441. {
  195442. for (int i = 0; i < faces.size(); i++)
  195443. if (faces[i]->getMonospaced())
  195444. monoSpaced.add (faces[i]->getFamilyName());
  195445. }
  195446. void getSerifNames (StringArray& serif) const throw()
  195447. {
  195448. for (int i = 0; i < faces.size(); i++)
  195449. if (faces[i]->getSerif())
  195450. serif.add (faces[i]->getFamilyName());
  195451. }
  195452. void getSansSerifNames (StringArray& sansSerif) const throw()
  195453. {
  195454. for (int i = 0; i < faces.size(); i++)
  195455. if (! faces[i]->getSerif())
  195456. sansSerif.add (faces[i]->getFamilyName());
  195457. }
  195458. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195459. private:
  195460. FT_Library ftLib;
  195461. FT_Face lastFace;
  195462. String lastFontName;
  195463. bool lastBold, lastItalic;
  195464. OwnedArray<FreeTypeFontFace> faces;
  195465. };
  195466. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195467. class FreetypeTypeface : public CustomTypeface
  195468. {
  195469. public:
  195470. FreetypeTypeface (const Font& font)
  195471. {
  195472. FT_Face face = FreeTypeInterface::getInstance()
  195473. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195474. if (face == 0)
  195475. {
  195476. #ifdef JUCE_DEBUG
  195477. String msg (T("Failed to create typeface: "));
  195478. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195479. DBG (msg);
  195480. #endif
  195481. }
  195482. else
  195483. {
  195484. setCharacteristics (font.getTypefaceName(),
  195485. face->ascender / (float) (face->ascender - face->descender),
  195486. font.isBold(), font.isItalic(),
  195487. L' ');
  195488. }
  195489. }
  195490. bool loadGlyphIfPossible (const juce_wchar character)
  195491. {
  195492. return FreeTypeInterface::getInstance()
  195493. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195494. }
  195495. };
  195496. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195497. {
  195498. return new FreetypeTypeface (font);
  195499. }
  195500. const StringArray Font::findAllTypefaceNames() throw()
  195501. {
  195502. StringArray s;
  195503. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195504. s.sort (true);
  195505. return s;
  195506. }
  195507. static const String pickBestFont (const StringArray& names,
  195508. const char* const choicesString)
  195509. {
  195510. StringArray choices;
  195511. choices.addTokens (String (choicesString), T(","), 0);
  195512. choices.trim();
  195513. choices.removeEmptyStrings();
  195514. int i, j;
  195515. for (j = 0; j < choices.size(); ++j)
  195516. if (names.contains (choices[j], true))
  195517. return choices[j];
  195518. for (j = 0; j < choices.size(); ++j)
  195519. for (i = 0; i < names.size(); i++)
  195520. if (names[i].startsWithIgnoreCase (choices[j]))
  195521. return names[i];
  195522. for (j = 0; j < choices.size(); ++j)
  195523. for (i = 0; i < names.size(); i++)
  195524. if (names[i].containsIgnoreCase (choices[j]))
  195525. return names[i];
  195526. return names[0];
  195527. }
  195528. static const String linux_getDefaultSansSerifFontName()
  195529. {
  195530. StringArray allFonts;
  195531. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195532. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195533. }
  195534. static const String linux_getDefaultSerifFontName()
  195535. {
  195536. StringArray allFonts;
  195537. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195538. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195539. }
  195540. static const String linux_getDefaultMonospacedFontName()
  195541. {
  195542. StringArray allFonts;
  195543. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195544. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195545. }
  195546. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195547. {
  195548. defaultSans = linux_getDefaultSansSerifFontName();
  195549. defaultSerif = linux_getDefaultSerifFontName();
  195550. defaultFixed = linux_getDefaultMonospacedFontName();
  195551. }
  195552. #endif
  195553. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195554. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195555. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195556. // compiled on its own).
  195557. #if JUCE_INCLUDED_FILE
  195558. #define TAKE_FOCUS 0
  195559. #define DELETE_WINDOW 1
  195560. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195561. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195562. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195563. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195564. static Atom wm_ChangeState = None;
  195565. static Atom wm_State = None;
  195566. static Atom wm_Protocols = None;
  195567. static Atom wm_ProtocolList [2] = { None, None };
  195568. static Atom wm_ActiveWin = None;
  195569. #define ourDndVersion 3
  195570. static Atom XA_XdndAware = None;
  195571. static Atom XA_XdndEnter = None;
  195572. static Atom XA_XdndLeave = None;
  195573. static Atom XA_XdndPosition = None;
  195574. static Atom XA_XdndStatus = None;
  195575. static Atom XA_XdndDrop = None;
  195576. static Atom XA_XdndFinished = None;
  195577. static Atom XA_XdndSelection = None;
  195578. static Atom XA_XdndProxy = None;
  195579. static Atom XA_XdndTypeList = None;
  195580. static Atom XA_XdndActionList = None;
  195581. static Atom XA_XdndActionDescription = None;
  195582. static Atom XA_XdndActionCopy = None;
  195583. static Atom XA_XdndActionMove = None;
  195584. static Atom XA_XdndActionLink = None;
  195585. static Atom XA_XdndActionAsk = None;
  195586. static Atom XA_XdndActionPrivate = None;
  195587. static Atom XA_JXSelectionWindowProperty = None;
  195588. static Atom XA_MimeTextPlain = None;
  195589. static Atom XA_MimeTextUriList = None;
  195590. static Atom XA_MimeRootDrop = None;
  195591. static XErrorHandler oldHandler = 0;
  195592. static int trappedErrorCode = 0;
  195593. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195594. {
  195595. trappedErrorCode = err->error_code;
  195596. return 0;
  195597. }
  195598. static void trapErrors()
  195599. {
  195600. trappedErrorCode = 0;
  195601. oldHandler = XSetErrorHandler (errorTrapHandler);
  195602. }
  195603. static bool untrapErrors()
  195604. {
  195605. XSetErrorHandler (oldHandler);
  195606. return (trappedErrorCode == 0);
  195607. }
  195608. static bool isActiveApplication = false;
  195609. bool Process::isForegroundProcess()
  195610. {
  195611. return isActiveApplication;
  195612. }
  195613. // These are defined in juce_linux_Messaging.cpp
  195614. extern Display* display;
  195615. extern XContext improbableNumber;
  195616. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195617. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195618. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195619. static int pointerMap[5];
  195620. static int lastMousePosX = 0, lastMousePosY = 0;
  195621. enum MouseButtons
  195622. {
  195623. NoButton = 0,
  195624. LeftButton = 1,
  195625. MiddleButton = 2,
  195626. RightButton = 3,
  195627. WheelUp = 4,
  195628. WheelDown = 5
  195629. };
  195630. static void getMousePos (int& x, int& y, int& mouseMods) throw()
  195631. {
  195632. Window root, child;
  195633. int winx, winy;
  195634. unsigned int mask;
  195635. mouseMods = 0;
  195636. ScopedXLock xlock;
  195637. if (XQueryPointer (display,
  195638. RootWindow (display, DefaultScreen (display)),
  195639. &root, &child,
  195640. &x, &y, &winx, &winy, &mask) == False)
  195641. {
  195642. // Pointer not on the default screen
  195643. x = y = -1;
  195644. }
  195645. else
  195646. {
  195647. if ((mask & Button1Mask) != 0)
  195648. mouseMods |= ModifierKeys::leftButtonModifier;
  195649. if ((mask & Button2Mask) != 0)
  195650. mouseMods |= ModifierKeys::middleButtonModifier;
  195651. if ((mask & Button3Mask) != 0)
  195652. mouseMods |= ModifierKeys::rightButtonModifier;
  195653. }
  195654. }
  195655. static int AltMask = 0;
  195656. static int NumLockMask = 0;
  195657. static bool numLock = 0;
  195658. static bool capsLock = 0;
  195659. static char keyStates [32];
  195660. static void updateKeyStates (const int keycode, const bool press) throw()
  195661. {
  195662. const int keybyte = keycode >> 3;
  195663. const int keybit = (1 << (keycode & 7));
  195664. if (press)
  195665. keyStates [keybyte] |= keybit;
  195666. else
  195667. keyStates [keybyte] &= ~keybit;
  195668. }
  195669. static bool keyDown (const int keycode) throw()
  195670. {
  195671. const int keybyte = keycode >> 3;
  195672. const int keybit = (1 << (keycode & 7));
  195673. return (keyStates [keybyte] & keybit) != 0;
  195674. }
  195675. static const int extendedKeyModifier = 0x10000000;
  195676. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195677. {
  195678. int keysym;
  195679. if (keyCode & extendedKeyModifier)
  195680. {
  195681. keysym = 0xff00 | (keyCode & 0xff);
  195682. }
  195683. else
  195684. {
  195685. keysym = keyCode;
  195686. if (keysym == (XK_Tab & 0xff)
  195687. || keysym == (XK_Return & 0xff)
  195688. || keysym == (XK_Escape & 0xff)
  195689. || keysym == (XK_BackSpace & 0xff))
  195690. {
  195691. keysym |= 0xff00;
  195692. }
  195693. }
  195694. ScopedXLock xlock;
  195695. return keyDown (XKeysymToKeycode (display, keysym));
  195696. }
  195697. // Alt and Num lock are not defined by standard X
  195698. // modifier constants: check what they're mapped to
  195699. static void getModifierMapping() throw()
  195700. {
  195701. ScopedXLock xlock;
  195702. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  195703. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  195704. AltMask = 0;
  195705. NumLockMask = 0;
  195706. XModifierKeymap* mapping = XGetModifierMapping (display);
  195707. if (mapping)
  195708. {
  195709. for (int i = 0; i < 8; i++)
  195710. {
  195711. if (mapping->modifiermap [i << 1] == altLeftCode)
  195712. AltMask = 1 << i;
  195713. else if (mapping->modifiermap [i << 1] == numLockCode)
  195714. NumLockMask = 1 << i;
  195715. }
  195716. XFreeModifiermap (mapping);
  195717. }
  195718. }
  195719. static int currentModifiers = 0;
  195720. void ModifierKeys::updateCurrentModifiers() throw()
  195721. {
  195722. currentModifierFlags = currentModifiers;
  195723. }
  195724. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  195725. {
  195726. int x, y, mouseMods;
  195727. getMousePos (x, y, mouseMods);
  195728. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  195729. currentModifiers |= mouseMods;
  195730. return ModifierKeys (currentModifiers);
  195731. }
  195732. static void updateKeyModifiers (const int status) throw()
  195733. {
  195734. currentModifiers &= ~(ModifierKeys::shiftModifier
  195735. | ModifierKeys::ctrlModifier
  195736. | ModifierKeys::altModifier);
  195737. if (status & ShiftMask)
  195738. currentModifiers |= ModifierKeys::shiftModifier;
  195739. if (status & ControlMask)
  195740. currentModifiers |= ModifierKeys::ctrlModifier;
  195741. if (status & AltMask)
  195742. currentModifiers |= ModifierKeys::altModifier;
  195743. numLock = ((status & NumLockMask) != 0);
  195744. capsLock = ((status & LockMask) != 0);
  195745. }
  195746. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  195747. {
  195748. int modifier = 0;
  195749. bool isModifier = true;
  195750. switch (sym)
  195751. {
  195752. case XK_Shift_L:
  195753. case XK_Shift_R:
  195754. modifier = ModifierKeys::shiftModifier;
  195755. break;
  195756. case XK_Control_L:
  195757. case XK_Control_R:
  195758. modifier = ModifierKeys::ctrlModifier;
  195759. break;
  195760. case XK_Alt_L:
  195761. case XK_Alt_R:
  195762. modifier = ModifierKeys::altModifier;
  195763. break;
  195764. case XK_Num_Lock:
  195765. if (press)
  195766. numLock = ! numLock;
  195767. break;
  195768. case XK_Caps_Lock:
  195769. if (press)
  195770. capsLock = ! capsLock;
  195771. break;
  195772. case XK_Scroll_Lock:
  195773. break;
  195774. default:
  195775. isModifier = false;
  195776. break;
  195777. }
  195778. if (modifier != 0)
  195779. {
  195780. if (press)
  195781. currentModifiers |= modifier;
  195782. else
  195783. currentModifiers &= ~modifier;
  195784. }
  195785. return isModifier;
  195786. }
  195787. #if JUCE_USE_XSHM
  195788. static bool isShmAvailable() throw()
  195789. {
  195790. ScopedXLock xlock;
  195791. static bool isChecked = false;
  195792. static bool isAvailable = false;
  195793. if (! isChecked)
  195794. {
  195795. isChecked = true;
  195796. int major, minor;
  195797. Bool pixmaps;
  195798. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195799. {
  195800. trapErrors();
  195801. XShmSegmentInfo segmentInfo;
  195802. zerostruct (segmentInfo);
  195803. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195804. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195805. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195806. xImage->bytes_per_line * xImage->height,
  195807. IPC_CREAT | 0777)) >= 0)
  195808. {
  195809. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195810. if (segmentInfo.shmaddr != (void*) -1)
  195811. {
  195812. segmentInfo.readOnly = False;
  195813. xImage->data = segmentInfo.shmaddr;
  195814. XSync (display, False);
  195815. if (XShmAttach (display, &segmentInfo) != 0)
  195816. {
  195817. XSync (display, False);
  195818. XShmDetach (display, &segmentInfo);
  195819. isAvailable = true;
  195820. }
  195821. }
  195822. XFlush (display);
  195823. XDestroyImage (xImage);
  195824. shmdt (segmentInfo.shmaddr);
  195825. }
  195826. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195827. isAvailable &= untrapErrors();
  195828. }
  195829. }
  195830. return isAvailable;
  195831. }
  195832. #endif
  195833. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195834. {
  195835. ScopedXLock xlock;
  195836. const int width = image.getWidth();
  195837. const int height = image.getHeight();
  195838. HeapBlock <uint32> colour (width * height);
  195839. int index = 0;
  195840. for (int y = 0; y < height; ++y)
  195841. for (int x = 0; x < width; ++x)
  195842. colour[index++] = image.getPixelAt (x, y).getARGB();
  195843. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195844. 0, (char*) colour, width, height, 32, 0);
  195845. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195846. width, height, 24);
  195847. GC gc = XCreateGC (display, pixmap, 0, 0);
  195848. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195849. XFreeGC (display, gc);
  195850. return pixmap;
  195851. }
  195852. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195853. {
  195854. ScopedXLock xlock;
  195855. const int width = image.getWidth();
  195856. const int height = image.getHeight();
  195857. const int stride = (width + 7) >> 3;
  195858. HeapBlock <uint8> mask;
  195859. mask.calloc (stride * height);
  195860. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195861. for (int y = 0; y < height; ++y)
  195862. {
  195863. for (int x = 0; x < width; ++x)
  195864. {
  195865. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195866. const int offset = y * stride + (x >> 3);
  195867. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195868. mask[offset] |= bit;
  195869. }
  195870. }
  195871. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195872. (char*) mask, width, height, 1, 0, 1);
  195873. }
  195874. class XBitmapImage : public Image
  195875. {
  195876. public:
  195877. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195878. const bool clearImage, const bool is16Bit_)
  195879. : Image (format_, w, h),
  195880. is16Bit (is16Bit_)
  195881. {
  195882. jassert (format_ == RGB || format_ == ARGB);
  195883. pixelStride = (format_ == RGB) ? 3 : 4;
  195884. lineStride = ((w * pixelStride + 3) & ~3);
  195885. ScopedXLock xlock;
  195886. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  195887. #if JUCE_USE_XSHM
  195888. usingXShm = false;
  195889. if ((! is16Bit) && isShmAvailable())
  195890. {
  195891. zerostruct (segmentInfo);
  195892. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  195893. if (xImage != 0)
  195894. {
  195895. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195896. xImage->bytes_per_line * xImage->height,
  195897. IPC_CREAT | 0777)) >= 0)
  195898. {
  195899. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195900. if (segmentInfo.shmaddr != (void*) -1)
  195901. {
  195902. segmentInfo.readOnly = False;
  195903. xImage->data = segmentInfo.shmaddr;
  195904. imageData = (uint8*) segmentInfo.shmaddr;
  195905. XSync (display, False);
  195906. if (XShmAttach (display, &segmentInfo) != 0)
  195907. {
  195908. XSync (display, False);
  195909. usingXShm = true;
  195910. }
  195911. else
  195912. {
  195913. jassertfalse
  195914. }
  195915. }
  195916. else
  195917. {
  195918. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195919. }
  195920. }
  195921. }
  195922. }
  195923. if (! usingXShm)
  195924. #endif
  195925. {
  195926. imageDataAllocated.malloc (lineStride * h);
  195927. imageData = imageDataAllocated;
  195928. if (format_ == ARGB && clearImage)
  195929. zeromem (imageData, h * lineStride);
  195930. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195931. xImage->width = w;
  195932. xImage->height = h;
  195933. xImage->xoffset = 0;
  195934. xImage->format = ZPixmap;
  195935. xImage->data = (char*) imageData;
  195936. xImage->byte_order = ImageByteOrder (display);
  195937. xImage->bitmap_unit = BitmapUnit (display);
  195938. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195939. xImage->bitmap_pad = 32;
  195940. xImage->depth = pixelStride * 8;
  195941. xImage->bytes_per_line = lineStride;
  195942. xImage->bits_per_pixel = pixelStride * 8;
  195943. xImage->red_mask = 0x00FF0000;
  195944. xImage->green_mask = 0x0000FF00;
  195945. xImage->blue_mask = 0x000000FF;
  195946. if (is16Bit)
  195947. {
  195948. const int pixelStride = 2;
  195949. const int lineStride = ((w * pixelStride + 3) & ~3);
  195950. imageData16Bit.malloc (lineStride * h);
  195951. xImage->data = imageData16Bit;
  195952. xImage->bitmap_pad = 16;
  195953. xImage->depth = pixelStride * 8;
  195954. xImage->bytes_per_line = lineStride;
  195955. xImage->bits_per_pixel = pixelStride * 8;
  195956. xImage->red_mask = visual->red_mask;
  195957. xImage->green_mask = visual->green_mask;
  195958. xImage->blue_mask = visual->blue_mask;
  195959. }
  195960. if (! XInitImage (xImage))
  195961. {
  195962. jassertfalse
  195963. }
  195964. }
  195965. }
  195966. ~XBitmapImage()
  195967. {
  195968. ScopedXLock xlock;
  195969. #if JUCE_USE_XSHM
  195970. if (usingXShm)
  195971. {
  195972. XShmDetach (display, &segmentInfo);
  195973. XFlush (display);
  195974. XDestroyImage (xImage);
  195975. shmdt (segmentInfo.shmaddr);
  195976. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195977. }
  195978. else
  195979. #endif
  195980. {
  195981. xImage->data = 0;
  195982. XDestroyImage (xImage);
  195983. }
  195984. }
  195985. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195986. {
  195987. ScopedXLock xlock;
  195988. static GC gc = 0;
  195989. if (gc == 0)
  195990. gc = DefaultGC (display, DefaultScreen (display));
  195991. if (is16Bit)
  195992. {
  195993. const uint32 rMask = xImage->red_mask;
  195994. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195995. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195996. const uint32 gMask = xImage->green_mask;
  195997. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195998. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195999. const uint32 bMask = xImage->blue_mask;
  196000. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  196001. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  196002. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  196003. for (int y = sy; y < sy + dh; ++y)
  196004. {
  196005. const uint8* p = srcData.getPixelPointer (sx, y);
  196006. for (int x = sx; x < sx + dw; ++x)
  196007. {
  196008. const PixelRGB* const pixel = (const PixelRGB*) p;
  196009. p += srcData.pixelStride;
  196010. XPutPixel (xImage, x, y,
  196011. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  196012. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  196013. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  196014. }
  196015. }
  196016. }
  196017. // blit results to screen.
  196018. #if JUCE_USE_XSHM
  196019. if (usingXShm)
  196020. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  196021. else
  196022. #endif
  196023. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  196024. }
  196025. juce_UseDebuggingNewOperator
  196026. private:
  196027. XImage* xImage;
  196028. const bool is16Bit;
  196029. HeapBlock <char> imageData16Bit;
  196030. #if JUCE_USE_XSHM
  196031. XShmSegmentInfo segmentInfo;
  196032. bool usingXShm;
  196033. #endif
  196034. static int getShiftNeeded (const uint32 mask) throw()
  196035. {
  196036. for (int i = 32; --i >= 0;)
  196037. if (((mask >> i) & 1) != 0)
  196038. return i - 7;
  196039. jassertfalse
  196040. return 0;
  196041. }
  196042. };
  196043. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  196044. class LinuxComponentPeer : public ComponentPeer
  196045. {
  196046. public:
  196047. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  196048. : ComponentPeer (component, windowStyleFlags),
  196049. windowH (0),
  196050. parentWindow (0),
  196051. wx (0),
  196052. wy (0),
  196053. ww (0),
  196054. wh (0),
  196055. taskbarImage (0),
  196056. fullScreen (false),
  196057. entered (false),
  196058. mapped (false)
  196059. {
  196060. // it's dangerous to create a window on a thread other than the message thread..
  196061. checkMessageManagerIsLocked
  196062. repainter = new LinuxRepaintManager (this);
  196063. createWindow();
  196064. setTitle (component->getName());
  196065. }
  196066. ~LinuxComponentPeer()
  196067. {
  196068. // it's dangerous to delete a window on a thread other than the message thread..
  196069. checkMessageManagerIsLocked
  196070. deleteTaskBarIcon();
  196071. deleteIconPixmaps();
  196072. destroyWindow();
  196073. windowH = 0;
  196074. }
  196075. void* getNativeHandle() const
  196076. {
  196077. return (void*) windowH;
  196078. }
  196079. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  196080. {
  196081. XPointer peer = 0;
  196082. ScopedXLock xlock;
  196083. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  196084. {
  196085. if (peer != 0 && ! ((LinuxComponentPeer*) peer)->isValidMessageListener())
  196086. peer = 0;
  196087. }
  196088. return (LinuxComponentPeer*) peer;
  196089. }
  196090. void setVisible (bool shouldBeVisible)
  196091. {
  196092. ScopedXLock xlock;
  196093. if (shouldBeVisible)
  196094. XMapWindow (display, windowH);
  196095. else
  196096. XUnmapWindow (display, windowH);
  196097. }
  196098. void setTitle (const String& title)
  196099. {
  196100. setWindowTitle (windowH, title);
  196101. }
  196102. void setPosition (int x, int y)
  196103. {
  196104. setBounds (x, y, ww, wh, false);
  196105. }
  196106. void setSize (int w, int h)
  196107. {
  196108. setBounds (wx, wy, w, h, false);
  196109. }
  196110. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  196111. {
  196112. fullScreen = isNowFullScreen;
  196113. if (windowH != 0)
  196114. {
  196115. const ComponentDeletionWatcher deletionChecker (component);
  196116. wx = x;
  196117. wy = y;
  196118. ww = jmax (1, w);
  196119. wh = jmax (1, h);
  196120. ScopedXLock xlock;
  196121. // Make sure the Window manager does what we want
  196122. XSizeHints* hints = XAllocSizeHints();
  196123. hints->flags = USSize | USPosition;
  196124. hints->width = ww;
  196125. hints->height = wh;
  196126. hints->x = wx;
  196127. hints->y = wy;
  196128. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  196129. {
  196130. hints->min_width = hints->max_width = hints->width;
  196131. hints->min_height = hints->max_height = hints->height;
  196132. hints->flags |= PMinSize | PMaxSize;
  196133. }
  196134. XSetWMNormalHints (display, windowH, hints);
  196135. XFree (hints);
  196136. XMoveResizeWindow (display, windowH,
  196137. wx - windowBorder.getLeft(),
  196138. wy - windowBorder.getTop(), ww, wh);
  196139. if (! deletionChecker.hasBeenDeleted())
  196140. {
  196141. updateBorderSize();
  196142. handleMovedOrResized();
  196143. }
  196144. }
  196145. }
  196146. void getBounds (int& x, int& y, int& w, int& h) const
  196147. {
  196148. x = wx;
  196149. y = wy;
  196150. w = ww;
  196151. h = wh;
  196152. }
  196153. int getScreenX() const
  196154. {
  196155. return wx;
  196156. }
  196157. int getScreenY() const
  196158. {
  196159. return wy;
  196160. }
  196161. void relativePositionToGlobal (int& x, int& y)
  196162. {
  196163. x += wx;
  196164. y += wy;
  196165. }
  196166. void globalPositionToRelative (int& x, int& y)
  196167. {
  196168. x -= wx;
  196169. y -= wy;
  196170. }
  196171. void setMinimised (bool shouldBeMinimised)
  196172. {
  196173. if (shouldBeMinimised)
  196174. {
  196175. Window root = RootWindow (display, DefaultScreen (display));
  196176. XClientMessageEvent clientMsg;
  196177. clientMsg.display = display;
  196178. clientMsg.window = windowH;
  196179. clientMsg.type = ClientMessage;
  196180. clientMsg.format = 32;
  196181. clientMsg.message_type = wm_ChangeState;
  196182. clientMsg.data.l[0] = IconicState;
  196183. ScopedXLock xlock;
  196184. XSendEvent (display, root, false,
  196185. SubstructureRedirectMask | SubstructureNotifyMask,
  196186. (XEvent*) &clientMsg);
  196187. }
  196188. else
  196189. {
  196190. setVisible (true);
  196191. }
  196192. }
  196193. bool isMinimised() const
  196194. {
  196195. bool minimised = false;
  196196. unsigned char* stateProp;
  196197. unsigned long nitems, bytesLeft;
  196198. Atom actualType;
  196199. int actualFormat;
  196200. ScopedXLock xlock;
  196201. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  196202. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  196203. &stateProp) == Success
  196204. && actualType == wm_State
  196205. && actualFormat == 32
  196206. && nitems > 0)
  196207. {
  196208. if (((unsigned long*) stateProp)[0] == IconicState)
  196209. minimised = true;
  196210. XFree (stateProp);
  196211. }
  196212. return minimised;
  196213. }
  196214. void setFullScreen (const bool shouldBeFullScreen)
  196215. {
  196216. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196217. setMinimised (false);
  196218. if (fullScreen != shouldBeFullScreen)
  196219. {
  196220. if (shouldBeFullScreen)
  196221. r = Desktop::getInstance().getMainMonitorArea();
  196222. if (! r.isEmpty())
  196223. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196224. getComponent()->repaint();
  196225. }
  196226. }
  196227. bool isFullScreen() const
  196228. {
  196229. return fullScreen;
  196230. }
  196231. bool isChildWindowOf (Window possibleParent) const
  196232. {
  196233. Window* windowList = 0;
  196234. uint32 windowListSize = 0;
  196235. Window parent, root;
  196236. ScopedXLock xlock;
  196237. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196238. {
  196239. if (windowList != 0)
  196240. XFree (windowList);
  196241. return parent == possibleParent;
  196242. }
  196243. return false;
  196244. }
  196245. bool isFrontWindow() const
  196246. {
  196247. Window* windowList = 0;
  196248. uint32 windowListSize = 0;
  196249. bool result = false;
  196250. ScopedXLock xlock;
  196251. Window parent, root = RootWindow (display, DefaultScreen (display));
  196252. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196253. {
  196254. for (int i = windowListSize; --i >= 0;)
  196255. {
  196256. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196257. if (peer != 0)
  196258. {
  196259. result = (peer == this);
  196260. break;
  196261. }
  196262. }
  196263. }
  196264. if (windowList != 0)
  196265. XFree (windowList);
  196266. return result;
  196267. }
  196268. bool contains (int x, int y, bool trueIfInAChildWindow) const
  196269. {
  196270. jassert (x >= 0 && y >= 0 && x < ww && y < wh); // should only be called for points that are actually inside the bounds
  196271. if (((unsigned int) x) >= (unsigned int) ww
  196272. || ((unsigned int) y) >= (unsigned int) wh)
  196273. return false;
  196274. bool inFront = false;
  196275. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196276. {
  196277. Component* const c = Desktop::getInstance().getComponent (i);
  196278. if (inFront)
  196279. {
  196280. if (c->contains (x + wx - c->getScreenX(),
  196281. y + wy - c->getScreenY()))
  196282. {
  196283. return false;
  196284. }
  196285. }
  196286. else if (c == getComponent())
  196287. {
  196288. inFront = true;
  196289. }
  196290. }
  196291. if (trueIfInAChildWindow)
  196292. return true;
  196293. ::Window root, child;
  196294. unsigned int bw, depth;
  196295. int wx, wy, w, h;
  196296. ScopedXLock xlock;
  196297. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196298. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196299. &bw, &depth))
  196300. {
  196301. return false;
  196302. }
  196303. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196304. return false;
  196305. return child == None;
  196306. }
  196307. const BorderSize getFrameSize() const
  196308. {
  196309. return BorderSize();
  196310. }
  196311. bool setAlwaysOnTop (bool alwaysOnTop)
  196312. {
  196313. if (windowH != 0)
  196314. {
  196315. const bool wasVisible = component->isVisible();
  196316. if (wasVisible)
  196317. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196318. {
  196319. ScopedXLock xlock;
  196320. XSetWindowAttributes swa;
  196321. swa.override_redirect = alwaysOnTop ? True : False;
  196322. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196323. }
  196324. if (wasVisible)
  196325. setVisible (true);
  196326. }
  196327. return true;
  196328. }
  196329. void toFront (bool makeActive)
  196330. {
  196331. if (makeActive)
  196332. {
  196333. setVisible (true);
  196334. grabFocus();
  196335. }
  196336. XEvent ev;
  196337. ev.xclient.type = ClientMessage;
  196338. ev.xclient.serial = 0;
  196339. ev.xclient.send_event = True;
  196340. ev.xclient.message_type = wm_ActiveWin;
  196341. ev.xclient.window = windowH;
  196342. ev.xclient.format = 32;
  196343. ev.xclient.data.l[0] = 2;
  196344. ev.xclient.data.l[1] = CurrentTime;
  196345. ev.xclient.data.l[2] = 0;
  196346. ev.xclient.data.l[3] = 0;
  196347. ev.xclient.data.l[4] = 0;
  196348. {
  196349. ScopedXLock xlock;
  196350. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196351. False,
  196352. SubstructureRedirectMask | SubstructureNotifyMask,
  196353. &ev);
  196354. XWindowAttributes attr;
  196355. XGetWindowAttributes (display, windowH, &attr);
  196356. if (attr.override_redirect)
  196357. XRaiseWindow (display, windowH);
  196358. XSync (display, False);
  196359. }
  196360. handleBroughtToFront();
  196361. }
  196362. void toBehind (ComponentPeer* other)
  196363. {
  196364. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196365. jassert (otherPeer != 0); // wrong type of window?
  196366. if (otherPeer != 0)
  196367. {
  196368. setMinimised (false);
  196369. Window newStack[] = { otherPeer->windowH, windowH };
  196370. ScopedXLock xlock;
  196371. XRestackWindows (display, newStack, 2);
  196372. }
  196373. }
  196374. bool isFocused() const
  196375. {
  196376. int revert;
  196377. Window focusedWindow = 0;
  196378. ScopedXLock xlock;
  196379. XGetInputFocus (display, &focusedWindow, &revert);
  196380. return focusedWindow == windowH;
  196381. }
  196382. void grabFocus()
  196383. {
  196384. XWindowAttributes atts;
  196385. ScopedXLock xlock;
  196386. if (windowH != 0
  196387. && XGetWindowAttributes (display, windowH, &atts)
  196388. && atts.map_state == IsViewable
  196389. && ! isFocused())
  196390. {
  196391. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196392. isActiveApplication = true;
  196393. }
  196394. }
  196395. void textInputRequired (int /*x*/, int /*y*/)
  196396. {
  196397. }
  196398. void repaint (int x, int y, int w, int h)
  196399. {
  196400. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196401. 0, 0,
  196402. getComponent()->getWidth(),
  196403. getComponent()->getHeight()))
  196404. {
  196405. repainter->repaint (x, y, w, h);
  196406. }
  196407. }
  196408. void performAnyPendingRepaintsNow()
  196409. {
  196410. repainter->performAnyPendingRepaintsNow();
  196411. }
  196412. void setIcon (const Image& newIcon)
  196413. {
  196414. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196415. HeapBlock <unsigned long> data (dataSize);
  196416. int index = 0;
  196417. data[index++] = newIcon.getWidth();
  196418. data[index++] = newIcon.getHeight();
  196419. for (int y = 0; y < newIcon.getHeight(); ++y)
  196420. for (int x = 0; x < newIcon.getWidth(); ++x)
  196421. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196422. ScopedXLock xlock;
  196423. XChangeProperty (display, windowH,
  196424. XInternAtom (display, "_NET_WM_ICON", False),
  196425. XA_CARDINAL, 32, PropModeReplace,
  196426. (unsigned char*) data, dataSize);
  196427. deleteIconPixmaps();
  196428. XWMHints* wmHints = XGetWMHints (display, windowH);
  196429. if (wmHints == 0)
  196430. wmHints = XAllocWMHints();
  196431. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196432. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196433. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196434. XSetWMHints (display, windowH, wmHints);
  196435. XFree (wmHints);
  196436. XSync (display, False);
  196437. }
  196438. void deleteIconPixmaps()
  196439. {
  196440. ScopedXLock xlock;
  196441. XWMHints* wmHints = XGetWMHints (display, windowH);
  196442. if (wmHints != 0)
  196443. {
  196444. if ((wmHints->flags & IconPixmapHint) != 0)
  196445. {
  196446. wmHints->flags &= ~IconPixmapHint;
  196447. XFreePixmap (display, wmHints->icon_pixmap);
  196448. }
  196449. if ((wmHints->flags & IconMaskHint) != 0)
  196450. {
  196451. wmHints->flags &= ~IconMaskHint;
  196452. XFreePixmap (display, wmHints->icon_mask);
  196453. }
  196454. XSetWMHints (display, windowH, wmHints);
  196455. XFree (wmHints);
  196456. }
  196457. }
  196458. void handleWindowMessage (XEvent* event)
  196459. {
  196460. switch (event->xany.type)
  196461. {
  196462. case 2: // 'KeyPress'
  196463. {
  196464. ScopedXLock xlock;
  196465. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196466. updateKeyStates (keyEvent->keycode, true);
  196467. char utf8 [64];
  196468. zeromem (utf8, sizeof (utf8));
  196469. KeySym sym;
  196470. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196471. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1);
  196472. int keyCode = (int) unicodeChar;
  196473. if (keyCode < 0x20)
  196474. keyCode = XKeycodeToKeysym (display, keyEvent->keycode,
  196475. (currentModifiers & ModifierKeys::shiftModifier) != 0 ? 1 : 0);
  196476. const int oldMods = currentModifiers;
  196477. bool keyPressed = false;
  196478. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196479. if ((sym & 0xff00) == 0xff00)
  196480. {
  196481. // Translate keypad
  196482. if (sym == XK_KP_Divide)
  196483. keyCode = XK_slash;
  196484. else if (sym == XK_KP_Multiply)
  196485. keyCode = XK_asterisk;
  196486. else if (sym == XK_KP_Subtract)
  196487. keyCode = XK_hyphen;
  196488. else if (sym == XK_KP_Add)
  196489. keyCode = XK_plus;
  196490. else if (sym == XK_KP_Enter)
  196491. keyCode = XK_Return;
  196492. else if (sym == XK_KP_Decimal)
  196493. keyCode = numLock ? XK_period : XK_Delete;
  196494. else if (sym == XK_KP_0)
  196495. keyCode = numLock ? XK_0 : XK_Insert;
  196496. else if (sym == XK_KP_1)
  196497. keyCode = numLock ? XK_1 : XK_End;
  196498. else if (sym == XK_KP_2)
  196499. keyCode = numLock ? XK_2 : XK_Down;
  196500. else if (sym == XK_KP_3)
  196501. keyCode = numLock ? XK_3 : XK_Page_Down;
  196502. else if (sym == XK_KP_4)
  196503. keyCode = numLock ? XK_4 : XK_Left;
  196504. else if (sym == XK_KP_5)
  196505. keyCode = XK_5;
  196506. else if (sym == XK_KP_6)
  196507. keyCode = numLock ? XK_6 : XK_Right;
  196508. else if (sym == XK_KP_7)
  196509. keyCode = numLock ? XK_7 : XK_Home;
  196510. else if (sym == XK_KP_8)
  196511. keyCode = numLock ? XK_8 : XK_Up;
  196512. else if (sym == XK_KP_9)
  196513. keyCode = numLock ? XK_9 : XK_Page_Up;
  196514. switch (sym)
  196515. {
  196516. case XK_Left:
  196517. case XK_Right:
  196518. case XK_Up:
  196519. case XK_Down:
  196520. case XK_Page_Up:
  196521. case XK_Page_Down:
  196522. case XK_End:
  196523. case XK_Home:
  196524. case XK_Delete:
  196525. case XK_Insert:
  196526. keyPressed = true;
  196527. keyCode = (sym & 0xff) | extendedKeyModifier;
  196528. break;
  196529. case XK_Tab:
  196530. case XK_Return:
  196531. case XK_Escape:
  196532. case XK_BackSpace:
  196533. keyPressed = true;
  196534. keyCode &= 0xff;
  196535. break;
  196536. default:
  196537. {
  196538. if (sym >= XK_F1 && sym <= XK_F16)
  196539. {
  196540. keyPressed = true;
  196541. keyCode = (sym & 0xff) | extendedKeyModifier;
  196542. }
  196543. break;
  196544. }
  196545. }
  196546. }
  196547. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196548. keyPressed = true;
  196549. if (oldMods != currentModifiers)
  196550. handleModifierKeysChange();
  196551. if (keyDownChange)
  196552. handleKeyUpOrDown (true);
  196553. if (keyPressed)
  196554. handleKeyPress (keyCode, unicodeChar);
  196555. break;
  196556. }
  196557. case KeyRelease:
  196558. {
  196559. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196560. updateKeyStates (keyEvent->keycode, false);
  196561. ScopedXLock xlock;
  196562. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196563. const int oldMods = currentModifiers;
  196564. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196565. if (oldMods != currentModifiers)
  196566. handleModifierKeysChange();
  196567. if (keyDownChange)
  196568. handleKeyUpOrDown (false);
  196569. break;
  196570. }
  196571. case ButtonPress:
  196572. {
  196573. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196574. bool buttonMsg = false;
  196575. bool wheelUpMsg = false;
  196576. bool wheelDownMsg = false;
  196577. const int map = pointerMap [buttonPressEvent->button - Button1];
  196578. if (map == LeftButton)
  196579. {
  196580. currentModifiers |= ModifierKeys::leftButtonModifier;
  196581. buttonMsg = true;
  196582. }
  196583. else if (map == RightButton)
  196584. {
  196585. currentModifiers |= ModifierKeys::rightButtonModifier;
  196586. buttonMsg = true;
  196587. }
  196588. else if (map == MiddleButton)
  196589. {
  196590. currentModifiers |= ModifierKeys::middleButtonModifier;
  196591. buttonMsg = true;
  196592. }
  196593. else if (map == WheelUp)
  196594. {
  196595. wheelUpMsg = true;
  196596. }
  196597. else if (map == WheelDown)
  196598. {
  196599. wheelDownMsg = true;
  196600. }
  196601. updateKeyModifiers (buttonPressEvent->state);
  196602. if (buttonMsg)
  196603. {
  196604. toFront (true);
  196605. handleMouseDown (buttonPressEvent->x, buttonPressEvent->y,
  196606. getEventTime (buttonPressEvent->time));
  196607. }
  196608. else if (wheelUpMsg || wheelDownMsg)
  196609. {
  196610. handleMouseWheel (0, wheelDownMsg ? -84 : 84,
  196611. getEventTime (buttonPressEvent->time));
  196612. }
  196613. lastMousePosX = lastMousePosY = 0x100000;
  196614. break;
  196615. }
  196616. case ButtonRelease:
  196617. {
  196618. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196619. const int oldModifiers = currentModifiers;
  196620. const int map = pointerMap [buttonRelEvent->button - Button1];
  196621. if (map == LeftButton)
  196622. currentModifiers &= ~ModifierKeys::leftButtonModifier;
  196623. else if (map == RightButton)
  196624. currentModifiers &= ~ModifierKeys::rightButtonModifier;
  196625. else if (map == MiddleButton)
  196626. currentModifiers &= ~ModifierKeys::middleButtonModifier;
  196627. updateKeyModifiers (buttonRelEvent->state);
  196628. handleMouseUp (oldModifiers,
  196629. buttonRelEvent->x, buttonRelEvent->y,
  196630. getEventTime (buttonRelEvent->time));
  196631. lastMousePosX = lastMousePosY = 0x100000;
  196632. break;
  196633. }
  196634. case MotionNotify:
  196635. {
  196636. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196637. updateKeyModifiers (movedEvent->state);
  196638. int x, y, mouseMods;
  196639. getMousePos (x, y, mouseMods);
  196640. if (lastMousePosX != x || lastMousePosY != y)
  196641. {
  196642. lastMousePosX = x;
  196643. lastMousePosY = y;
  196644. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196645. {
  196646. Window wRoot = 0, wParent = 0;
  196647. Window* wChild = 0;
  196648. unsigned int numChildren;
  196649. {
  196650. ScopedXLock xlock;
  196651. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196652. }
  196653. if (wParent != 0
  196654. && wParent != windowH
  196655. && wParent != wRoot)
  196656. {
  196657. parentWindow = wParent;
  196658. updateBounds();
  196659. x -= getScreenX();
  196660. y -= getScreenY();
  196661. }
  196662. else
  196663. {
  196664. parentWindow = 0;
  196665. x -= getScreenX();
  196666. y -= getScreenY();
  196667. }
  196668. }
  196669. else
  196670. {
  196671. x -= getScreenX();
  196672. y -= getScreenY();
  196673. }
  196674. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0)
  196675. handleMouseMove (x, y, getEventTime (movedEvent->time));
  196676. else
  196677. handleMouseDrag (x, y, getEventTime (movedEvent->time));
  196678. }
  196679. break;
  196680. }
  196681. case EnterNotify:
  196682. {
  196683. lastMousePosX = lastMousePosY = 0x100000;
  196684. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196685. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196686. && ! entered)
  196687. {
  196688. updateKeyModifiers (enterEvent->state);
  196689. handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time));
  196690. entered = true;
  196691. }
  196692. break;
  196693. }
  196694. case LeaveNotify:
  196695. {
  196696. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196697. // Suppress the normal leave if we've got a pointer grab, or if
  196698. // it's a bogus one caused by clicking a mouse button when running
  196699. // in a Window manager
  196700. if (((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196701. && leaveEvent->mode == NotifyNormal)
  196702. || leaveEvent->mode == NotifyUngrab)
  196703. {
  196704. updateKeyModifiers (leaveEvent->state);
  196705. handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time));
  196706. entered = false;
  196707. }
  196708. break;
  196709. }
  196710. case FocusIn:
  196711. {
  196712. isActiveApplication = true;
  196713. if (isFocused())
  196714. handleFocusGain();
  196715. break;
  196716. }
  196717. case FocusOut:
  196718. {
  196719. isActiveApplication = false;
  196720. if (! isFocused())
  196721. handleFocusLoss();
  196722. break;
  196723. }
  196724. case Expose:
  196725. {
  196726. // Batch together all pending expose events
  196727. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196728. XEvent nextEvent;
  196729. ScopedXLock xlock;
  196730. if (exposeEvent->window != windowH)
  196731. {
  196732. Window child;
  196733. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196734. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196735. &child);
  196736. }
  196737. repaint (exposeEvent->x, exposeEvent->y,
  196738. exposeEvent->width, exposeEvent->height);
  196739. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196740. {
  196741. XPeekEvent (display, (XEvent*) &nextEvent);
  196742. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196743. break;
  196744. XNextEvent (display, (XEvent*) &nextEvent);
  196745. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196746. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196747. nextExposeEvent->width, nextExposeEvent->height);
  196748. }
  196749. break;
  196750. }
  196751. case CirculateNotify:
  196752. case CreateNotify:
  196753. case DestroyNotify:
  196754. // Think we can ignore these
  196755. break;
  196756. case ConfigureNotify:
  196757. {
  196758. updateBounds();
  196759. updateBorderSize();
  196760. handleMovedOrResized();
  196761. // if the native title bar is dragged, need to tell any active menus, etc.
  196762. if ((styleFlags & windowHasTitleBar) != 0
  196763. && component->isCurrentlyBlockedByAnotherModalComponent())
  196764. {
  196765. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196766. if (currentModalComp != 0)
  196767. currentModalComp->inputAttemptWhenModal();
  196768. }
  196769. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196770. if (confEvent->window == windowH
  196771. && confEvent->above != 0
  196772. && isFrontWindow())
  196773. {
  196774. handleBroughtToFront();
  196775. }
  196776. break;
  196777. }
  196778. case ReparentNotify:
  196779. case GravityNotify:
  196780. {
  196781. parentWindow = 0;
  196782. Window wRoot = 0;
  196783. Window* wChild = 0;
  196784. unsigned int numChildren;
  196785. {
  196786. ScopedXLock xlock;
  196787. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196788. }
  196789. if (parentWindow == windowH || parentWindow == wRoot)
  196790. parentWindow = 0;
  196791. updateBounds();
  196792. updateBorderSize();
  196793. handleMovedOrResized();
  196794. break;
  196795. }
  196796. case MapNotify:
  196797. mapped = true;
  196798. handleBroughtToFront();
  196799. break;
  196800. case UnmapNotify:
  196801. mapped = false;
  196802. break;
  196803. case MappingNotify:
  196804. {
  196805. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196806. if (mappingEvent->request != MappingPointer)
  196807. {
  196808. // Deal with modifier/keyboard mapping
  196809. ScopedXLock xlock;
  196810. XRefreshKeyboardMapping (mappingEvent);
  196811. getModifierMapping();
  196812. }
  196813. break;
  196814. }
  196815. case ClientMessage:
  196816. {
  196817. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196818. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  196819. {
  196820. const Atom atom = (Atom) clientMsg->data.l[0];
  196821. if (atom == wm_ProtocolList [TAKE_FOCUS])
  196822. {
  196823. XWindowAttributes atts;
  196824. ScopedXLock xlock;
  196825. if (clientMsg->window != 0
  196826. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196827. {
  196828. if (atts.map_state == IsViewable)
  196829. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196830. }
  196831. }
  196832. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  196833. {
  196834. handleUserClosingWindow();
  196835. }
  196836. }
  196837. else if (clientMsg->message_type == XA_XdndEnter)
  196838. {
  196839. handleDragAndDropEnter (clientMsg);
  196840. }
  196841. else if (clientMsg->message_type == XA_XdndLeave)
  196842. {
  196843. resetDragAndDrop();
  196844. }
  196845. else if (clientMsg->message_type == XA_XdndPosition)
  196846. {
  196847. handleDragAndDropPosition (clientMsg);
  196848. }
  196849. else if (clientMsg->message_type == XA_XdndDrop)
  196850. {
  196851. handleDragAndDropDrop (clientMsg);
  196852. }
  196853. else if (clientMsg->message_type == XA_XdndStatus)
  196854. {
  196855. handleDragAndDropStatus (clientMsg);
  196856. }
  196857. else if (clientMsg->message_type == XA_XdndFinished)
  196858. {
  196859. resetDragAndDrop();
  196860. }
  196861. break;
  196862. }
  196863. case SelectionNotify:
  196864. handleDragAndDropSelection (event);
  196865. break;
  196866. case SelectionClear:
  196867. case SelectionRequest:
  196868. break;
  196869. default:
  196870. #if JUCE_USE_XSHM
  196871. {
  196872. ScopedXLock xlock;
  196873. if (event->xany.type == XShmGetEventBase (display))
  196874. repainter->notifyPaintCompleted();
  196875. }
  196876. #endif
  196877. break;
  196878. }
  196879. }
  196880. void showMouseCursor (Cursor cursor) throw()
  196881. {
  196882. ScopedXLock xlock;
  196883. XDefineCursor (display, windowH, cursor);
  196884. }
  196885. void setTaskBarIcon (const Image& image)
  196886. {
  196887. ScopedXLock xlock;
  196888. deleteTaskBarIcon();
  196889. taskbarImage = image.createCopy();
  196890. Screen* const screen = XDefaultScreenOfDisplay (display);
  196891. const int screenNumber = XScreenNumberOfScreen (screen);
  196892. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196893. screenAtom << screenNumber;
  196894. Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false);
  196895. XGrabServer (display);
  196896. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196897. if (managerWin != None)
  196898. XSelectInput (display, managerWin, StructureNotifyMask);
  196899. XUngrabServer (display);
  196900. XFlush (display);
  196901. if (managerWin != None)
  196902. {
  196903. XEvent ev;
  196904. zerostruct (ev);
  196905. ev.xclient.type = ClientMessage;
  196906. ev.xclient.window = managerWin;
  196907. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196908. ev.xclient.format = 32;
  196909. ev.xclient.data.l[0] = CurrentTime;
  196910. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196911. ev.xclient.data.l[2] = windowH;
  196912. ev.xclient.data.l[3] = 0;
  196913. ev.xclient.data.l[4] = 0;
  196914. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196915. XSync (display, False);
  196916. }
  196917. // For older KDE's ...
  196918. long atomData = 1;
  196919. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196920. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196921. // For more recent KDE's...
  196922. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196923. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196924. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196925. XSizeHints* hints = XAllocSizeHints();
  196926. hints->flags = PMinSize;
  196927. hints->min_width = 22;
  196928. hints->min_height = 22;
  196929. XSetWMNormalHints (display, windowH, hints);
  196930. XFree (hints);
  196931. }
  196932. void deleteTaskBarIcon()
  196933. {
  196934. deleteAndZero (taskbarImage);
  196935. }
  196936. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196937. juce_UseDebuggingNewOperator
  196938. bool dontRepaint;
  196939. private:
  196940. class LinuxRepaintManager : public Timer
  196941. {
  196942. public:
  196943. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196944. : peer (peer_),
  196945. lastTimeImageUsed (0)
  196946. {
  196947. #if JUCE_USE_XSHM
  196948. shmCompletedDrawing = true;
  196949. useARGBImagesForRendering = isShmAvailable();
  196950. if (useARGBImagesForRendering)
  196951. {
  196952. ScopedXLock xlock;
  196953. XShmSegmentInfo segmentinfo;
  196954. XImage* const testImage
  196955. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196956. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196957. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196958. XDestroyImage (testImage);
  196959. }
  196960. #endif
  196961. }
  196962. ~LinuxRepaintManager()
  196963. {
  196964. }
  196965. void timerCallback()
  196966. {
  196967. #if JUCE_USE_XSHM
  196968. if (! shmCompletedDrawing)
  196969. return;
  196970. #endif
  196971. if (! regionsNeedingRepaint.isEmpty())
  196972. {
  196973. stopTimer();
  196974. performAnyPendingRepaintsNow();
  196975. }
  196976. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196977. {
  196978. stopTimer();
  196979. image = 0;
  196980. }
  196981. }
  196982. void repaint (int x, int y, int w, int h)
  196983. {
  196984. if (! isTimerRunning())
  196985. startTimer (repaintTimerPeriod);
  196986. regionsNeedingRepaint.add (x, y, w, h);
  196987. }
  196988. void performAnyPendingRepaintsNow()
  196989. {
  196990. #if JUCE_USE_XSHM
  196991. if (! shmCompletedDrawing)
  196992. {
  196993. startTimer (repaintTimerPeriod);
  196994. return;
  196995. }
  196996. #endif
  196997. peer->clearMaskedRegion();
  196998. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196999. regionsNeedingRepaint.clear();
  197000. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  197001. if (! totalArea.isEmpty())
  197002. {
  197003. #if JUCE_USE_XSHM
  197004. shmCompletedDrawing = false;
  197005. #endif
  197006. if (image == 0 || image->getWidth() < totalArea.getWidth()
  197007. || image->getHeight() < totalArea.getHeight())
  197008. {
  197009. #if JUCE_USE_XSHM
  197010. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  197011. : Image::RGB,
  197012. #else
  197013. image = new XBitmapImage (Image::RGB,
  197014. #endif
  197015. (totalArea.getWidth() + 31) & ~31,
  197016. (totalArea.getHeight() + 31) & ~31,
  197017. false,
  197018. peer->depthIs16Bit);
  197019. }
  197020. startTimer (repaintTimerPeriod);
  197021. LowLevelGraphicsSoftwareRenderer context (*image);
  197022. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  197023. if (context.clipToRectangleList (originalRepaintRegion))
  197024. peer->handlePaint (context);
  197025. if (! peer->maskedRegion.isEmpty())
  197026. originalRepaintRegion.subtract (peer->maskedRegion);
  197027. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  197028. {
  197029. const Rectangle<int>& r = *i.getRectangle();
  197030. image->blitToWindow (peer->windowH,
  197031. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  197032. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  197033. }
  197034. }
  197035. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  197036. startTimer (repaintTimerPeriod);
  197037. }
  197038. #if JUCE_USE_XSHM
  197039. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  197040. #endif
  197041. private:
  197042. LinuxComponentPeer* const peer;
  197043. ScopedPointer <XBitmapImage> image;
  197044. uint32 lastTimeImageUsed;
  197045. RectangleList regionsNeedingRepaint;
  197046. #if JUCE_USE_XSHM
  197047. bool useARGBImagesForRendering, shmCompletedDrawing;
  197048. #endif
  197049. LinuxRepaintManager (const LinuxRepaintManager&);
  197050. const LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  197051. };
  197052. ScopedPointer <LinuxRepaintManager> repainter;
  197053. friend class LinuxRepaintManager;
  197054. Window windowH, parentWindow;
  197055. int wx, wy, ww, wh;
  197056. Image* taskbarImage;
  197057. bool fullScreen, entered, mapped, depthIs16Bit;
  197058. BorderSize windowBorder;
  197059. struct MotifWmHints
  197060. {
  197061. unsigned long flags;
  197062. unsigned long functions;
  197063. unsigned long decorations;
  197064. long input_mode;
  197065. unsigned long status;
  197066. };
  197067. void removeWindowDecorations (Window wndH)
  197068. {
  197069. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197070. if (hints != None)
  197071. {
  197072. MotifWmHints motifHints;
  197073. zerostruct (motifHints);
  197074. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  197075. motifHints.decorations = 0;
  197076. ScopedXLock xlock;
  197077. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197078. (unsigned char*) &motifHints, 4);
  197079. }
  197080. hints = XInternAtom (display, "_WIN_HINTS", True);
  197081. if (hints != None)
  197082. {
  197083. long gnomeHints = 0;
  197084. ScopedXLock xlock;
  197085. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197086. (unsigned char*) &gnomeHints, 1);
  197087. }
  197088. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  197089. if (hints != None)
  197090. {
  197091. long kwmHints = 2; /*KDE_tinyDecoration*/
  197092. ScopedXLock xlock;
  197093. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197094. (unsigned char*) &kwmHints, 1);
  197095. }
  197096. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  197097. if (hints != None)
  197098. {
  197099. ScopedXLock xlock;
  197100. int netHints [2];
  197101. int numHints = 0;
  197102. if ((styleFlags & windowIsTemporary) != 0)
  197103. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  197104. else
  197105. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  197106. if (netHints [numHints] != 0)
  197107. ++numHints;
  197108. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  197109. if (netHints [numHints] != 0)
  197110. ++numHints;
  197111. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197112. (unsigned char*) &netHints, numHints);
  197113. }
  197114. }
  197115. void addWindowButtons (Window wndH)
  197116. {
  197117. ScopedXLock xlock;
  197118. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197119. if (hints != None)
  197120. {
  197121. MotifWmHints motifHints;
  197122. zerostruct (motifHints);
  197123. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  197124. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197125. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197126. if ((styleFlags & windowHasCloseButton) != 0)
  197127. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197128. if ((styleFlags & windowHasMinimiseButton) != 0)
  197129. {
  197130. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197131. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197132. }
  197133. if ((styleFlags & windowHasMaximiseButton) != 0)
  197134. {
  197135. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197136. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197137. }
  197138. if ((styleFlags & windowIsResizable) != 0)
  197139. {
  197140. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197141. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197142. }
  197143. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197144. }
  197145. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197146. if (hints != None)
  197147. {
  197148. int netHints [6];
  197149. int num = 0;
  197150. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197151. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197152. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197153. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197154. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197155. (unsigned char*) &netHints, num);
  197156. }
  197157. }
  197158. void createWindow()
  197159. {
  197160. ScopedXLock xlock;
  197161. static bool atomsInitialised = false;
  197162. if (! atomsInitialised)
  197163. {
  197164. atomsInitialised = true;
  197165. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197166. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197167. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197168. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197169. wm_State = XInternAtom (display, "WM_STATE", 1);
  197170. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197171. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197172. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197173. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197174. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197175. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197176. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197177. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197178. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197179. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197180. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197181. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197182. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197183. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197184. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197185. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197186. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197187. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197188. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197189. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197190. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197191. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197192. }
  197193. resetDragAndDrop();
  197194. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197195. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197196. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197197. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197198. allowedActions [0] = XA_XdndActionMove;
  197199. allowedActions [1] = XA_XdndActionCopy;
  197200. allowedActions [2] = XA_XdndActionLink;
  197201. allowedActions [3] = XA_XdndActionAsk;
  197202. allowedActions [4] = XA_XdndActionPrivate;
  197203. // Get defaults for various properties
  197204. const int screen = DefaultScreen (display);
  197205. Window root = RootWindow (display, screen);
  197206. // Attempt to create a 24-bit window on the default screen. If this is not
  197207. // possible then exit
  197208. XVisualInfo desiredVisual;
  197209. desiredVisual.screen = screen;
  197210. desiredVisual.depth = 24;
  197211. depthIs16Bit = false;
  197212. int numVisuals;
  197213. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197214. &desiredVisual, &numVisuals);
  197215. if (numVisuals < 1 || visuals == 0)
  197216. {
  197217. XFree (visuals);
  197218. desiredVisual.depth = 16;
  197219. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197220. &desiredVisual, &numVisuals);
  197221. if (numVisuals < 1 || visuals == 0)
  197222. {
  197223. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197224. Process::terminate();
  197225. }
  197226. depthIs16Bit = true;
  197227. }
  197228. XFree (visuals);
  197229. // Set up the window attributes
  197230. XSetWindowAttributes swa;
  197231. swa.border_pixel = 0;
  197232. swa.background_pixmap = None;
  197233. swa.colormap = DefaultColormap (display, screen);
  197234. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197235. swa.event_mask = eventMask;
  197236. Window wndH = XCreateWindow (display, root,
  197237. 0, 0, 1, 1,
  197238. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197239. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197240. &swa);
  197241. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197242. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197243. GrabModeAsync, GrabModeAsync, None, None);
  197244. // Set the window context to identify the window handle object
  197245. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197246. {
  197247. // Failed
  197248. jassertfalse
  197249. Logger::outputDebugString ("Failed to create context information for window.\n");
  197250. XDestroyWindow (display, wndH);
  197251. wndH = 0;
  197252. }
  197253. // Set window manager hints
  197254. XWMHints* wmHints = XAllocWMHints();
  197255. wmHints->flags = InputHint | StateHint;
  197256. wmHints->input = True; // Locally active input model
  197257. wmHints->initial_state = NormalState;
  197258. XSetWMHints (display, wndH, wmHints);
  197259. XFree (wmHints);
  197260. if ((styleFlags & windowIsSemiTransparent) != 0)
  197261. {
  197262. //xxx
  197263. }
  197264. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197265. {
  197266. //xxx
  197267. }
  197268. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197269. if ((styleFlags & windowHasTitleBar) == 0)
  197270. removeWindowDecorations (wndH);
  197271. else
  197272. addWindowButtons (wndH);
  197273. // Set window manager protocols
  197274. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197275. (unsigned char*) wm_ProtocolList, 2);
  197276. // Set drag and drop flags
  197277. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197278. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197279. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197280. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197281. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197282. (const unsigned char*) "", 0);
  197283. unsigned long dndVersion = ourDndVersion;
  197284. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197285. (const unsigned char*) &dndVersion, 1);
  197286. // Set window name
  197287. setWindowTitle (wndH, getComponent()->getName());
  197288. // Initialise the pointer and keyboard mapping
  197289. // This is not the same as the logical pointer mapping the X server uses:
  197290. // we don't mess with this.
  197291. static bool mappingInitialised = false;
  197292. if (! mappingInitialised)
  197293. {
  197294. mappingInitialised = true;
  197295. const int numButtons = XGetPointerMapping (display, 0, 0);
  197296. if (numButtons == 2)
  197297. {
  197298. pointerMap[0] = LeftButton;
  197299. pointerMap[1] = RightButton;
  197300. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197301. }
  197302. else if (numButtons >= 3)
  197303. {
  197304. pointerMap[0] = LeftButton;
  197305. pointerMap[1] = MiddleButton;
  197306. pointerMap[2] = RightButton;
  197307. if (numButtons >= 5)
  197308. {
  197309. pointerMap[3] = WheelUp;
  197310. pointerMap[4] = WheelDown;
  197311. }
  197312. }
  197313. getModifierMapping();
  197314. }
  197315. windowH = wndH;
  197316. }
  197317. void destroyWindow()
  197318. {
  197319. ScopedXLock xlock;
  197320. XPointer handlePointer;
  197321. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197322. XDeleteContext (display, (XID) windowH, improbableNumber);
  197323. XDestroyWindow (display, windowH);
  197324. // Wait for it to complete and then remove any events for this
  197325. // window from the event queue.
  197326. XSync (display, false);
  197327. XEvent event;
  197328. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197329. {}
  197330. }
  197331. static int64 getEventTime (::Time t) throw()
  197332. {
  197333. static int64 eventTimeOffset = 0x12345678;
  197334. const int64 thisMessageTime = t;
  197335. if (eventTimeOffset == 0x12345678)
  197336. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197337. return eventTimeOffset + thisMessageTime;
  197338. }
  197339. static void setWindowTitle (Window xwin, const char* const title) throw()
  197340. {
  197341. XTextProperty nameProperty;
  197342. char* strings[] = { (char*) title };
  197343. ScopedXLock xlock;
  197344. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197345. {
  197346. XSetWMName (display, xwin, &nameProperty);
  197347. XSetWMIconName (display, xwin, &nameProperty);
  197348. XFree (nameProperty.value);
  197349. }
  197350. }
  197351. void updateBorderSize()
  197352. {
  197353. if ((styleFlags & windowHasTitleBar) == 0)
  197354. {
  197355. windowBorder = BorderSize (0);
  197356. }
  197357. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197358. {
  197359. ScopedXLock xlock;
  197360. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197361. if (hints != None)
  197362. {
  197363. unsigned char* data = 0;
  197364. unsigned long nitems, bytesLeft;
  197365. Atom actualType;
  197366. int actualFormat;
  197367. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197368. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197369. &data) == Success)
  197370. {
  197371. const unsigned long* const sizes = (const unsigned long*) data;
  197372. if (actualFormat == 32)
  197373. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197374. (int) sizes[3], (int) sizes[1]);
  197375. XFree (data);
  197376. }
  197377. }
  197378. }
  197379. }
  197380. void updateBounds()
  197381. {
  197382. jassert (windowH != 0);
  197383. if (windowH != 0)
  197384. {
  197385. Window root, child;
  197386. unsigned int bw, depth;
  197387. ScopedXLock xlock;
  197388. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197389. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197390. &bw, &depth))
  197391. {
  197392. wx = wy = ww = wh = 0;
  197393. }
  197394. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197395. {
  197396. wx = wy = 0;
  197397. }
  197398. }
  197399. }
  197400. void resetDragAndDrop()
  197401. {
  197402. dragAndDropFiles.clear();
  197403. lastDropX = lastDropY = -1;
  197404. dragAndDropCurrentMimeType = 0;
  197405. dragAndDropSourceWindow = 0;
  197406. srcMimeTypeAtomList.clear();
  197407. }
  197408. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197409. {
  197410. msg.type = ClientMessage;
  197411. msg.display = display;
  197412. msg.window = dragAndDropSourceWindow;
  197413. msg.format = 32;
  197414. msg.data.l[0] = windowH;
  197415. ScopedXLock xlock;
  197416. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197417. }
  197418. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197419. {
  197420. XClientMessageEvent msg;
  197421. zerostruct (msg);
  197422. msg.message_type = XA_XdndStatus;
  197423. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197424. msg.data.l[4] = dropAction;
  197425. sendDragAndDropMessage (msg);
  197426. }
  197427. void sendDragAndDropLeave()
  197428. {
  197429. XClientMessageEvent msg;
  197430. zerostruct (msg);
  197431. msg.message_type = XA_XdndLeave;
  197432. sendDragAndDropMessage (msg);
  197433. }
  197434. void sendDragAndDropFinish()
  197435. {
  197436. XClientMessageEvent msg;
  197437. zerostruct (msg);
  197438. msg.message_type = XA_XdndFinished;
  197439. sendDragAndDropMessage (msg);
  197440. }
  197441. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197442. {
  197443. if ((clientMsg->data.l[1] & 1) == 0)
  197444. {
  197445. sendDragAndDropLeave();
  197446. if (dragAndDropFiles.size() > 0)
  197447. handleFileDragExit (dragAndDropFiles);
  197448. dragAndDropFiles.clear();
  197449. }
  197450. }
  197451. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197452. {
  197453. if (dragAndDropSourceWindow == 0)
  197454. return;
  197455. dragAndDropSourceWindow = clientMsg->data.l[0];
  197456. const int dropX = ((int) clientMsg->data.l[2] >> 16) - getScreenX();
  197457. const int dropY = ((int) clientMsg->data.l[2] & 0xffff) - getScreenY();
  197458. if (lastDropX != dropX || lastDropY != dropY)
  197459. {
  197460. lastDropX = dropX;
  197461. lastDropY = dropY;
  197462. dragAndDropTimestamp = clientMsg->data.l[3];
  197463. Atom targetAction = XA_XdndActionCopy;
  197464. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197465. {
  197466. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197467. {
  197468. targetAction = allowedActions[i];
  197469. break;
  197470. }
  197471. }
  197472. sendDragAndDropStatus (true, targetAction);
  197473. if (dragAndDropFiles.size() == 0)
  197474. updateDraggedFileList (clientMsg);
  197475. if (dragAndDropFiles.size() > 0)
  197476. handleFileDragMove (dragAndDropFiles, dropX, dropY);
  197477. }
  197478. }
  197479. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197480. {
  197481. if (dragAndDropFiles.size() == 0)
  197482. updateDraggedFileList (clientMsg);
  197483. const StringArray files (dragAndDropFiles);
  197484. const int lastX = lastDropX, lastY = lastDropY;
  197485. sendDragAndDropFinish();
  197486. resetDragAndDrop();
  197487. if (files.size() > 0)
  197488. handleFileDragDrop (files, lastX, lastY);
  197489. }
  197490. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197491. {
  197492. dragAndDropFiles.clear();
  197493. srcMimeTypeAtomList.clear();
  197494. dragAndDropCurrentMimeType = 0;
  197495. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197496. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197497. {
  197498. dragAndDropSourceWindow = 0;
  197499. return;
  197500. }
  197501. dragAndDropSourceWindow = clientMsg->data.l[0];
  197502. if ((clientMsg->data.l[1] & 1) != 0)
  197503. {
  197504. Atom actual;
  197505. int format;
  197506. unsigned long count = 0, remaining = 0;
  197507. unsigned char* data = 0;
  197508. ScopedXLock xlock;
  197509. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197510. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197511. &count, &remaining, &data);
  197512. if (data != 0)
  197513. {
  197514. if (actual == XA_ATOM && format == 32 && count != 0)
  197515. {
  197516. const unsigned long* const types = (const unsigned long*) data;
  197517. for (unsigned int i = 0; i < count; ++i)
  197518. if (types[i] != None)
  197519. srcMimeTypeAtomList.add (types[i]);
  197520. }
  197521. XFree (data);
  197522. }
  197523. }
  197524. if (srcMimeTypeAtomList.size() == 0)
  197525. {
  197526. for (int i = 2; i < 5; ++i)
  197527. if (clientMsg->data.l[i] != None)
  197528. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197529. if (srcMimeTypeAtomList.size() == 0)
  197530. {
  197531. dragAndDropSourceWindow = 0;
  197532. return;
  197533. }
  197534. }
  197535. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197536. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197537. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197538. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197539. handleDragAndDropPosition (clientMsg);
  197540. }
  197541. void handleDragAndDropSelection (const XEvent* const evt)
  197542. {
  197543. dragAndDropFiles.clear();
  197544. if (evt->xselection.property != 0)
  197545. {
  197546. StringArray lines;
  197547. {
  197548. MemoryBlock dropData;
  197549. for (;;)
  197550. {
  197551. Atom actual;
  197552. uint8* data = 0;
  197553. unsigned long count = 0, remaining = 0;
  197554. int format = 0;
  197555. ScopedXLock xlock;
  197556. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197557. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197558. &format, &count, &remaining, &data) == Success)
  197559. {
  197560. dropData.append (data, count * format / 8);
  197561. XFree (data);
  197562. if (remaining == 0)
  197563. break;
  197564. }
  197565. else
  197566. {
  197567. XFree (data);
  197568. break;
  197569. }
  197570. }
  197571. lines.addLines (dropData.toString());
  197572. }
  197573. for (int i = 0; i < lines.size(); ++i)
  197574. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197575. dragAndDropFiles.trim();
  197576. dragAndDropFiles.removeEmptyStrings();
  197577. }
  197578. }
  197579. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197580. {
  197581. dragAndDropFiles.clear();
  197582. if (dragAndDropSourceWindow != None
  197583. && dragAndDropCurrentMimeType != 0)
  197584. {
  197585. dragAndDropTimestamp = clientMsg->data.l[2];
  197586. ScopedXLock xlock;
  197587. XConvertSelection (display,
  197588. XA_XdndSelection,
  197589. dragAndDropCurrentMimeType,
  197590. XA_JXSelectionWindowProperty,
  197591. windowH,
  197592. dragAndDropTimestamp);
  197593. }
  197594. }
  197595. StringArray dragAndDropFiles;
  197596. int dragAndDropTimestamp, lastDropX, lastDropY;
  197597. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197598. Window dragAndDropSourceWindow;
  197599. unsigned int allowedActions [5];
  197600. unsigned int allowedMimeTypeAtoms [3];
  197601. Array <Atom> srcMimeTypeAtomList;
  197602. };
  197603. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197604. {
  197605. if (enableOrDisable)
  197606. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197607. }
  197608. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197609. {
  197610. return new LinuxComponentPeer (this, styleFlags);
  197611. }
  197612. // (this callback is hooked up in the messaging code)
  197613. void juce_windowMessageReceive (XEvent* event)
  197614. {
  197615. if (event->xany.window != None)
  197616. {
  197617. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197618. if (ComponentPeer::isValidPeer (peer))
  197619. peer->handleWindowMessage (event);
  197620. }
  197621. else
  197622. {
  197623. switch (event->xany.type)
  197624. {
  197625. case KeymapNotify:
  197626. {
  197627. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197628. memcpy (keyStates, keymapEvent->key_vector, 32);
  197629. break;
  197630. }
  197631. default:
  197632. break;
  197633. }
  197634. }
  197635. }
  197636. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197637. {
  197638. if (display == 0)
  197639. return;
  197640. #if JUCE_USE_XINERAMA
  197641. int major_opcode, first_event, first_error;
  197642. ScopedXLock xlock;
  197643. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197644. {
  197645. typedef Bool (*tXineramaIsActive) (Display*);
  197646. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197647. static tXineramaIsActive xXineramaIsActive = 0;
  197648. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197649. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197650. {
  197651. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197652. if (h != 0)
  197653. {
  197654. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197655. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197656. }
  197657. }
  197658. if (xXineramaIsActive != 0
  197659. && xXineramaQueryScreens != 0
  197660. && xXineramaIsActive (display))
  197661. {
  197662. int numMonitors = 0;
  197663. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197664. if (screens != 0)
  197665. {
  197666. for (int i = numMonitors; --i >= 0;)
  197667. {
  197668. int index = screens[i].screen_number;
  197669. if (index >= 0)
  197670. {
  197671. while (monitorCoords.size() < index)
  197672. monitorCoords.add (Rectangle<int>());
  197673. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197674. screens[i].y_org,
  197675. screens[i].width,
  197676. screens[i].height));
  197677. }
  197678. }
  197679. XFree (screens);
  197680. }
  197681. }
  197682. }
  197683. if (monitorCoords.size() == 0)
  197684. #endif
  197685. {
  197686. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197687. if (hints != None)
  197688. {
  197689. const int numMonitors = ScreenCount (display);
  197690. for (int i = 0; i < numMonitors; ++i)
  197691. {
  197692. Window root = RootWindow (display, i);
  197693. unsigned long nitems, bytesLeft;
  197694. Atom actualType;
  197695. int actualFormat;
  197696. unsigned char* data = 0;
  197697. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197698. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197699. &data) == Success)
  197700. {
  197701. const long* const position = (const long*) data;
  197702. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197703. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197704. position[2], position[3]));
  197705. XFree (data);
  197706. }
  197707. }
  197708. }
  197709. if (monitorCoords.size() == 0)
  197710. {
  197711. monitorCoords.add (Rectangle<int> (0, 0,
  197712. DisplayWidth (display, DefaultScreen (display)),
  197713. DisplayHeight (display, DefaultScreen (display))));
  197714. }
  197715. }
  197716. }
  197717. bool Desktop::canUseSemiTransparentWindows() throw()
  197718. {
  197719. return false;
  197720. }
  197721. void Desktop::getMousePosition (int& x, int& y) throw()
  197722. {
  197723. int mouseMods;
  197724. getMousePos (x, y, mouseMods);
  197725. }
  197726. void Desktop::setMousePosition (int x, int y) throw()
  197727. {
  197728. ScopedXLock xlock;
  197729. Window root = RootWindow (display, DefaultScreen (display));
  197730. XWarpPointer (display, None, root, 0, 0, 0, 0, x, y);
  197731. }
  197732. static bool screenSaverAllowed = true;
  197733. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197734. {
  197735. if (screenSaverAllowed != isEnabled)
  197736. {
  197737. screenSaverAllowed = isEnabled;
  197738. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197739. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197740. if (xScreenSaverSuspend == 0)
  197741. {
  197742. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197743. if (h != 0)
  197744. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197745. }
  197746. ScopedXLock xlock;
  197747. if (xScreenSaverSuspend != 0)
  197748. xScreenSaverSuspend (display, ! isEnabled);
  197749. }
  197750. }
  197751. bool Desktop::isScreenSaverEnabled() throw()
  197752. {
  197753. return screenSaverAllowed;
  197754. }
  197755. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197756. {
  197757. ScopedXLock xlock;
  197758. Window root = RootWindow (display, DefaultScreen (display));
  197759. const unsigned int imageW = image.getWidth();
  197760. const unsigned int imageH = image.getHeight();
  197761. unsigned int cursorW, cursorH;
  197762. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197763. return 0;
  197764. Image im (Image::ARGB, cursorW, cursorH, true);
  197765. Graphics g (im);
  197766. if (imageW > cursorW || imageH > cursorH)
  197767. {
  197768. hotspotX = (hotspotX * cursorW) / imageW;
  197769. hotspotY = (hotspotY * cursorH) / imageH;
  197770. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197771. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197772. false);
  197773. }
  197774. else
  197775. {
  197776. g.drawImageAt (&image, 0, 0);
  197777. }
  197778. const int stride = (cursorW + 7) >> 3;
  197779. HeapBlock <uint8> maskPlane, sourcePlane;
  197780. maskPlane.calloc (stride * cursorH);
  197781. sourcePlane.calloc (stride * cursorH);
  197782. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197783. for (int y = cursorH; --y >= 0;)
  197784. {
  197785. for (int x = cursorW; --x >= 0;)
  197786. {
  197787. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197788. const int offset = y * stride + (x >> 3);
  197789. const Colour c (im.getPixelAt (x, y));
  197790. if (c.getAlpha() >= 128)
  197791. maskPlane[offset] |= mask;
  197792. if (c.getBrightness() >= 0.5f)
  197793. sourcePlane[offset] |= mask;
  197794. }
  197795. }
  197796. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  197797. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  197798. XColor white, black;
  197799. black.red = black.green = black.blue = 0;
  197800. white.red = white.green = white.blue = 0xffff;
  197801. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197802. XFreePixmap (display, sourcePixmap);
  197803. XFreePixmap (display, maskPixmap);
  197804. return result;
  197805. }
  197806. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197807. {
  197808. ScopedXLock xlock;
  197809. if (cursorHandle != None)
  197810. XFreeCursor (display, (Cursor) cursorHandle);
  197811. }
  197812. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197813. {
  197814. unsigned int shape;
  197815. switch (type)
  197816. {
  197817. case MouseCursor::NoCursor:
  197818. {
  197819. const Image im (Image::ARGB, 16, 16, true);
  197820. return juce_createMouseCursorFromImage (im, 0, 0);
  197821. }
  197822. case MouseCursor::NormalCursor:
  197823. return (void*) None; // Use parent cursor
  197824. case MouseCursor::DraggingHandCursor:
  197825. {
  197826. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197827. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197828. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197829. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197830. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197831. const int dragHandDataSize = 99;
  197832. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197833. return juce_createMouseCursorFromImage (*im, 8, 7);
  197834. }
  197835. case MouseCursor::CopyingCursor:
  197836. {
  197837. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197838. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197839. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197840. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197841. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197842. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197843. const int copyCursorSize = 119;
  197844. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197845. return juce_createMouseCursorFromImage (*im, 1, 3);
  197846. }
  197847. case MouseCursor::WaitCursor:
  197848. shape = XC_watch;
  197849. break;
  197850. case MouseCursor::IBeamCursor:
  197851. shape = XC_xterm;
  197852. break;
  197853. case MouseCursor::PointingHandCursor:
  197854. shape = XC_hand2;
  197855. break;
  197856. case MouseCursor::LeftRightResizeCursor:
  197857. shape = XC_sb_h_double_arrow;
  197858. break;
  197859. case MouseCursor::UpDownResizeCursor:
  197860. shape = XC_sb_v_double_arrow;
  197861. break;
  197862. case MouseCursor::UpDownLeftRightResizeCursor:
  197863. shape = XC_fleur;
  197864. break;
  197865. case MouseCursor::TopEdgeResizeCursor:
  197866. shape = XC_top_side;
  197867. break;
  197868. case MouseCursor::BottomEdgeResizeCursor:
  197869. shape = XC_bottom_side;
  197870. break;
  197871. case MouseCursor::LeftEdgeResizeCursor:
  197872. shape = XC_left_side;
  197873. break;
  197874. case MouseCursor::RightEdgeResizeCursor:
  197875. shape = XC_right_side;
  197876. break;
  197877. case MouseCursor::TopLeftCornerResizeCursor:
  197878. shape = XC_top_left_corner;
  197879. break;
  197880. case MouseCursor::TopRightCornerResizeCursor:
  197881. shape = XC_top_right_corner;
  197882. break;
  197883. case MouseCursor::BottomLeftCornerResizeCursor:
  197884. shape = XC_bottom_left_corner;
  197885. break;
  197886. case MouseCursor::BottomRightCornerResizeCursor:
  197887. shape = XC_bottom_right_corner;
  197888. break;
  197889. case MouseCursor::CrosshairCursor:
  197890. shape = XC_crosshair;
  197891. break;
  197892. default:
  197893. return (void*) None; // Use parent cursor
  197894. }
  197895. ScopedXLock xlock;
  197896. return (void*) XCreateFontCursor (display, shape);
  197897. }
  197898. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197899. {
  197900. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197901. if (lp != 0)
  197902. lp->showMouseCursor ((Cursor) getHandle());
  197903. }
  197904. void MouseCursor::showInAllWindows() const throw()
  197905. {
  197906. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197907. showInWindow (ComponentPeer::getPeer (i));
  197908. }
  197909. Image* juce_createIconForFile (const File& file)
  197910. {
  197911. return 0;
  197912. }
  197913. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197914. {
  197915. return new Image (format, imageWidth, imageHeight, clearImage);
  197916. }
  197917. #if JUCE_OPENGL
  197918. class WindowedGLContext : public OpenGLContext
  197919. {
  197920. public:
  197921. WindowedGLContext (Component* const component,
  197922. const OpenGLPixelFormat& pixelFormat_,
  197923. GLXContext sharedContext)
  197924. : renderContext (0),
  197925. embeddedWindow (0),
  197926. pixelFormat (pixelFormat_)
  197927. {
  197928. jassert (component != 0);
  197929. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197930. if (peer == 0)
  197931. return;
  197932. ScopedXLock xlock;
  197933. XSync (display, False);
  197934. GLint attribs [64];
  197935. int n = 0;
  197936. attribs[n++] = GLX_RGBA;
  197937. attribs[n++] = GLX_DOUBLEBUFFER;
  197938. attribs[n++] = GLX_RED_SIZE;
  197939. attribs[n++] = pixelFormat.redBits;
  197940. attribs[n++] = GLX_GREEN_SIZE;
  197941. attribs[n++] = pixelFormat.greenBits;
  197942. attribs[n++] = GLX_BLUE_SIZE;
  197943. attribs[n++] = pixelFormat.blueBits;
  197944. attribs[n++] = GLX_ALPHA_SIZE;
  197945. attribs[n++] = pixelFormat.alphaBits;
  197946. attribs[n++] = GLX_DEPTH_SIZE;
  197947. attribs[n++] = pixelFormat.depthBufferBits;
  197948. attribs[n++] = GLX_STENCIL_SIZE;
  197949. attribs[n++] = pixelFormat.stencilBufferBits;
  197950. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197951. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197952. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197953. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197954. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197955. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197956. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197957. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197958. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197959. attribs[n++] = None;
  197960. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197961. if (bestVisual == 0)
  197962. return;
  197963. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197964. Window windowH = (Window) peer->getNativeHandle();
  197965. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197966. XSetWindowAttributes swa;
  197967. swa.colormap = colourMap;
  197968. swa.border_pixel = 0;
  197969. swa.event_mask = ExposureMask | StructureNotifyMask;
  197970. embeddedWindow = XCreateWindow (display, windowH,
  197971. 0, 0, 1, 1, 0,
  197972. bestVisual->depth,
  197973. InputOutput,
  197974. bestVisual->visual,
  197975. CWBorderPixel | CWColormap | CWEventMask,
  197976. &swa);
  197977. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197978. XMapWindow (display, embeddedWindow);
  197979. XFreeColormap (display, colourMap);
  197980. XFree (bestVisual);
  197981. XSync (display, False);
  197982. }
  197983. ~WindowedGLContext()
  197984. {
  197985. makeInactive();
  197986. ScopedXLock xlock;
  197987. glXDestroyContext (display, renderContext);
  197988. XUnmapWindow (display, embeddedWindow);
  197989. XDestroyWindow (display, embeddedWindow);
  197990. }
  197991. bool makeActive() const throw()
  197992. {
  197993. jassert (renderContext != 0);
  197994. ScopedXLock xlock;
  197995. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197996. && XSync (display, False);
  197997. }
  197998. bool makeInactive() const throw()
  197999. {
  198000. ScopedXLock xlock;
  198001. return (! isActive()) || glXMakeCurrent (display, None, 0);
  198002. }
  198003. bool isActive() const throw()
  198004. {
  198005. ScopedXLock xlock;
  198006. return glXGetCurrentContext() == renderContext;
  198007. }
  198008. const OpenGLPixelFormat getPixelFormat() const
  198009. {
  198010. return pixelFormat;
  198011. }
  198012. void* getRawContext() const throw()
  198013. {
  198014. return renderContext;
  198015. }
  198016. void updateWindowPosition (int x, int y, int w, int h, int)
  198017. {
  198018. ScopedXLock xlock;
  198019. XMoveResizeWindow (display, embeddedWindow,
  198020. x, y, jmax (1, w), jmax (1, h));
  198021. }
  198022. void swapBuffers()
  198023. {
  198024. ScopedXLock xlock;
  198025. glXSwapBuffers (display, embeddedWindow);
  198026. }
  198027. bool setSwapInterval (const int numFramesPerSwap)
  198028. {
  198029. // xxx needs doing..
  198030. return false;
  198031. }
  198032. int getSwapInterval() const
  198033. {
  198034. // xxx needs doing..
  198035. return 0;
  198036. }
  198037. void repaint()
  198038. {
  198039. }
  198040. juce_UseDebuggingNewOperator
  198041. GLXContext renderContext;
  198042. private:
  198043. Window embeddedWindow;
  198044. OpenGLPixelFormat pixelFormat;
  198045. WindowedGLContext (const WindowedGLContext&);
  198046. const WindowedGLContext& operator= (const WindowedGLContext&);
  198047. };
  198048. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  198049. const OpenGLPixelFormat& pixelFormat,
  198050. const OpenGLContext* const contextToShareWith)
  198051. {
  198052. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  198053. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  198054. if (c->renderContext == 0)
  198055. deleteAndZero (c);
  198056. return c;
  198057. }
  198058. void juce_glViewport (const int w, const int h)
  198059. {
  198060. glViewport (0, 0, w, h);
  198061. }
  198062. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  198063. OwnedArray <OpenGLPixelFormat>& results)
  198064. {
  198065. results.add (new OpenGLPixelFormat()); // xxx
  198066. }
  198067. #endif
  198068. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  198069. {
  198070. jassertfalse // not implemented!
  198071. return false;
  198072. }
  198073. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  198074. {
  198075. jassertfalse // not implemented!
  198076. return false;
  198077. }
  198078. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  198079. {
  198080. if (! isOnDesktop ())
  198081. addToDesktop (0);
  198082. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198083. if (wp != 0)
  198084. {
  198085. wp->setTaskBarIcon (newImage);
  198086. setVisible (true);
  198087. toFront (false);
  198088. repaint();
  198089. }
  198090. }
  198091. void SystemTrayIconComponent::paint (Graphics& g)
  198092. {
  198093. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198094. if (wp != 0)
  198095. {
  198096. const Image* const image = wp->getTaskbarIcon();
  198097. if (image != 0)
  198098. {
  198099. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  198100. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198101. false);
  198102. }
  198103. }
  198104. }
  198105. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198106. {
  198107. // xxx not yet implemented!
  198108. }
  198109. void PlatformUtilities::beep()
  198110. {
  198111. std::cout << "\a" << std::flush;
  198112. }
  198113. bool AlertWindow::showNativeDialogBox (const String& title,
  198114. const String& bodyText,
  198115. bool isOkCancel)
  198116. {
  198117. // xxx this is supposed to pop up an alert!
  198118. Logger::outputDebugString (title + ": " + bodyText);
  198119. // use a non-native one for the time being..
  198120. if (isOkCancel)
  198121. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198122. else
  198123. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198124. return true;
  198125. }
  198126. const int KeyPress::spaceKey = XK_space & 0xff;
  198127. const int KeyPress::returnKey = XK_Return & 0xff;
  198128. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198129. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198130. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198131. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198132. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198133. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198134. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198135. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198136. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198137. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198138. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198139. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198140. const int KeyPress::tabKey = XK_Tab & 0xff;
  198141. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198142. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198143. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198144. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198145. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198146. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198147. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198148. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198149. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198150. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198151. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198152. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198153. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198154. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198155. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198156. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198157. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198158. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198159. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198160. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198161. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198162. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198163. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198164. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198165. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198166. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198167. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198168. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198169. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198170. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198171. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198172. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198173. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198174. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198175. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198176. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198177. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198178. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198179. #endif
  198180. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  198181. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  198182. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198183. // compiled on its own).
  198184. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198185. static const int maxNumChans = 64;
  198186. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198187. {
  198188. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198189. snd_pcm_hw_params_t* hwParams;
  198190. snd_pcm_hw_params_alloca (&hwParams);
  198191. for (int i = 0; ratesToTry[i] != 0; ++i)
  198192. {
  198193. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198194. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198195. {
  198196. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198197. }
  198198. }
  198199. }
  198200. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198201. {
  198202. snd_pcm_hw_params_t *params;
  198203. snd_pcm_hw_params_alloca (&params);
  198204. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198205. {
  198206. snd_pcm_hw_params_get_channels_min (params, minChans);
  198207. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198208. }
  198209. }
  198210. static void getDeviceProperties (const String& id,
  198211. unsigned int& minChansOut,
  198212. unsigned int& maxChansOut,
  198213. unsigned int& minChansIn,
  198214. unsigned int& maxChansIn,
  198215. Array <int>& rates)
  198216. {
  198217. if (id.isEmpty())
  198218. return;
  198219. snd_ctl_t* handle;
  198220. if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0)
  198221. {
  198222. snd_pcm_info_t* info;
  198223. snd_pcm_info_alloca (&info);
  198224. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198225. snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198226. snd_pcm_info_set_subdevice (info, 0);
  198227. if (snd_ctl_pcm_info (handle, info) >= 0)
  198228. {
  198229. snd_pcm_t* pcmHandle;
  198230. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198231. {
  198232. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198233. getDeviceSampleRates (pcmHandle, rates);
  198234. snd_pcm_close (pcmHandle);
  198235. }
  198236. }
  198237. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198238. if (snd_ctl_pcm_info (handle, info) >= 0)
  198239. {
  198240. snd_pcm_t* pcmHandle;
  198241. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198242. {
  198243. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198244. if (rates.size() == 0)
  198245. getDeviceSampleRates (pcmHandle, rates);
  198246. snd_pcm_close (pcmHandle);
  198247. }
  198248. }
  198249. snd_ctl_close (handle);
  198250. }
  198251. }
  198252. class ALSADevice
  198253. {
  198254. public:
  198255. ALSADevice (const String& id,
  198256. const bool forInput)
  198257. : handle (0),
  198258. bitDepth (16),
  198259. numChannelsRunning (0),
  198260. isInput (forInput),
  198261. sampleFormat (AudioDataConverters::int16LE)
  198262. {
  198263. failed (snd_pcm_open (&handle, id,
  198264. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198265. SND_PCM_ASYNC));
  198266. }
  198267. ~ALSADevice()
  198268. {
  198269. if (handle != 0)
  198270. snd_pcm_close (handle);
  198271. }
  198272. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198273. {
  198274. if (handle == 0)
  198275. return false;
  198276. snd_pcm_hw_params_t* hwParams;
  198277. snd_pcm_hw_params_alloca (&hwParams);
  198278. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198279. return false;
  198280. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198281. isInterleaved = false;
  198282. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198283. isInterleaved = true;
  198284. else
  198285. {
  198286. jassertfalse
  198287. return false;
  198288. }
  198289. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198290. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198291. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198292. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198293. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198294. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198295. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198296. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198297. bitDepth = 0;
  198298. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198299. {
  198300. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198301. {
  198302. bitDepth = formatsToTry [i + 1];
  198303. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198304. break;
  198305. }
  198306. }
  198307. if (bitDepth == 0)
  198308. {
  198309. error = "device doesn't support a compatible PCM format";
  198310. DBG (T("ALSA error: ") + error + T("\n"));
  198311. return false;
  198312. }
  198313. int dir = 0;
  198314. unsigned int periods = 4;
  198315. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198316. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198317. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198318. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198319. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198320. || failed (snd_pcm_hw_params (handle, hwParams)))
  198321. {
  198322. return false;
  198323. }
  198324. snd_pcm_sw_params_t* swParams;
  198325. snd_pcm_sw_params_alloca (&swParams);
  198326. snd_pcm_uframes_t boundary;
  198327. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198328. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198329. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198330. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198331. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198332. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198333. || failed (snd_pcm_sw_params (handle, swParams)))
  198334. {
  198335. return false;
  198336. }
  198337. numChannelsRunning = numChannels;
  198338. return true;
  198339. }
  198340. bool write (float** const data, const int numSamples)
  198341. {
  198342. if (isInterleaved)
  198343. {
  198344. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198345. float* interleaved = (float*) scratch;
  198346. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198347. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198348. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198349. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198350. return false;
  198351. }
  198352. else
  198353. {
  198354. for (int i = 0; i < numChannelsRunning; ++i)
  198355. if (data[i] != 0)
  198356. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198357. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198358. if (failed (num))
  198359. {
  198360. if (num == -EPIPE)
  198361. {
  198362. if (failed (snd_pcm_prepare (handle)))
  198363. return false;
  198364. }
  198365. else if (num != -ESTRPIPE)
  198366. return false;
  198367. }
  198368. }
  198369. return true;
  198370. }
  198371. bool read (float** const data, const int numSamples)
  198372. {
  198373. if (isInterleaved)
  198374. {
  198375. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198376. float* interleaved = (float*) scratch;
  198377. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198378. if (failed (num))
  198379. {
  198380. if (num == -EPIPE)
  198381. {
  198382. if (failed (snd_pcm_prepare (handle)))
  198383. return false;
  198384. }
  198385. else if (num != -ESTRPIPE)
  198386. return false;
  198387. }
  198388. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198389. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198390. }
  198391. else
  198392. {
  198393. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198394. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198395. return false;
  198396. for (int i = 0; i < numChannelsRunning; ++i)
  198397. if (data[i] != 0)
  198398. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198399. }
  198400. return true;
  198401. }
  198402. juce_UseDebuggingNewOperator
  198403. snd_pcm_t* handle;
  198404. String error;
  198405. int bitDepth, numChannelsRunning;
  198406. private:
  198407. const bool isInput;
  198408. bool isInterleaved;
  198409. MemoryBlock scratch;
  198410. AudioDataConverters::DataFormat sampleFormat;
  198411. bool failed (const int errorNum)
  198412. {
  198413. if (errorNum >= 0)
  198414. return false;
  198415. error = snd_strerror (errorNum);
  198416. DBG (T("ALSA error: ") + error + T("\n"));
  198417. return true;
  198418. }
  198419. };
  198420. class ALSAThread : public Thread
  198421. {
  198422. public:
  198423. ALSAThread (const String& inputId_,
  198424. const String& outputId_)
  198425. : Thread ("Juce ALSA"),
  198426. sampleRate (0),
  198427. bufferSize (0),
  198428. callback (0),
  198429. inputId (inputId_),
  198430. outputId (outputId_),
  198431. outputDevice (0),
  198432. inputDevice (0),
  198433. numCallbacks (0),
  198434. totalNumInputChannels (0),
  198435. totalNumOutputChannels (0)
  198436. {
  198437. zeromem (outputChannelData, sizeof (outputChannelData));
  198438. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198439. zeromem (inputChannelData, sizeof (inputChannelData));
  198440. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198441. initialiseRatesAndChannels();
  198442. }
  198443. ~ALSAThread()
  198444. {
  198445. close();
  198446. }
  198447. void open (BitArray inputChannels,
  198448. BitArray outputChannels,
  198449. const double sampleRate_,
  198450. const int bufferSize_)
  198451. {
  198452. close();
  198453. error = String::empty;
  198454. sampleRate = sampleRate_;
  198455. bufferSize = bufferSize_;
  198456. currentInputChans.clear();
  198457. currentOutputChans.clear();
  198458. if (inputChannels.getHighestBit() >= 0)
  198459. {
  198460. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198461. {
  198462. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198463. if (inputChannels[i])
  198464. {
  198465. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198466. currentInputChans.setBit (i);
  198467. }
  198468. }
  198469. }
  198470. if (outputChannels.getHighestBit() >= 0)
  198471. {
  198472. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198473. {
  198474. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198475. if (outputChannels[i])
  198476. {
  198477. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198478. currentOutputChans.setBit (i);
  198479. }
  198480. }
  198481. }
  198482. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198483. {
  198484. outputDevice = new ALSADevice (outputId, false);
  198485. if (outputDevice->error.isNotEmpty())
  198486. {
  198487. error = outputDevice->error;
  198488. deleteAndZero (outputDevice);
  198489. return;
  198490. }
  198491. currentOutputChans.setRange (0, minChansOut, true);
  198492. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198493. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198494. bufferSize))
  198495. {
  198496. error = outputDevice->error;
  198497. deleteAndZero (outputDevice);
  198498. return;
  198499. }
  198500. }
  198501. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198502. {
  198503. inputDevice = new ALSADevice (inputId, true);
  198504. if (inputDevice->error.isNotEmpty())
  198505. {
  198506. error = inputDevice->error;
  198507. deleteAndZero (inputDevice);
  198508. return;
  198509. }
  198510. currentInputChans.setRange (0, minChansIn, true);
  198511. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198512. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198513. bufferSize))
  198514. {
  198515. error = inputDevice->error;
  198516. deleteAndZero (inputDevice);
  198517. return;
  198518. }
  198519. }
  198520. if (outputDevice == 0 && inputDevice == 0)
  198521. {
  198522. error = "no channels";
  198523. return;
  198524. }
  198525. if (outputDevice != 0 && inputDevice != 0)
  198526. {
  198527. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198528. }
  198529. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198530. return;
  198531. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198532. return;
  198533. startThread (9);
  198534. int count = 1000;
  198535. while (numCallbacks == 0)
  198536. {
  198537. sleep (5);
  198538. if (--count < 0 || ! isThreadRunning())
  198539. {
  198540. error = "device didn't start";
  198541. break;
  198542. }
  198543. }
  198544. }
  198545. void close()
  198546. {
  198547. stopThread (6000);
  198548. deleteAndZero (inputDevice);
  198549. deleteAndZero (outputDevice);
  198550. for (int i = 0; i < maxNumChans; ++i)
  198551. {
  198552. juce_free (inputChannelData [i]);
  198553. juce_free (outputChannelData [i]);
  198554. }
  198555. zeromem (outputChannelData, sizeof (outputChannelData));
  198556. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198557. zeromem (inputChannelData, sizeof (inputChannelData));
  198558. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198559. totalNumOutputChannels = 0;
  198560. totalNumInputChannels = 0;
  198561. numCallbacks = 0;
  198562. }
  198563. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198564. {
  198565. const ScopedLock sl (callbackLock);
  198566. callback = newCallback;
  198567. }
  198568. void run()
  198569. {
  198570. while (! threadShouldExit())
  198571. {
  198572. if (inputDevice != 0)
  198573. {
  198574. if (! inputDevice->read (inputChannelData, bufferSize))
  198575. {
  198576. DBG ("ALSA: read failure");
  198577. break;
  198578. }
  198579. }
  198580. if (threadShouldExit())
  198581. break;
  198582. {
  198583. const ScopedLock sl (callbackLock);
  198584. ++numCallbacks;
  198585. if (callback != 0)
  198586. {
  198587. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198588. totalNumInputChannels,
  198589. outputChannelDataForCallback,
  198590. totalNumOutputChannels,
  198591. bufferSize);
  198592. }
  198593. else
  198594. {
  198595. for (int i = 0; i < totalNumOutputChannels; ++i)
  198596. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198597. }
  198598. }
  198599. if (outputDevice != 0)
  198600. {
  198601. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198602. if (threadShouldExit())
  198603. break;
  198604. failed (snd_pcm_avail_update (outputDevice->handle));
  198605. if (! outputDevice->write (outputChannelData, bufferSize))
  198606. {
  198607. DBG ("ALSA: write failure");
  198608. break;
  198609. }
  198610. }
  198611. }
  198612. }
  198613. int getBitDepth() const throw()
  198614. {
  198615. if (outputDevice != 0)
  198616. return outputDevice->bitDepth;
  198617. if (inputDevice != 0)
  198618. return inputDevice->bitDepth;
  198619. return 16;
  198620. }
  198621. juce_UseDebuggingNewOperator
  198622. String error;
  198623. double sampleRate;
  198624. int bufferSize;
  198625. BitArray currentInputChans, currentOutputChans;
  198626. Array <int> sampleRates;
  198627. StringArray channelNamesOut, channelNamesIn;
  198628. AudioIODeviceCallback* callback;
  198629. private:
  198630. const String inputId, outputId;
  198631. ALSADevice* outputDevice;
  198632. ALSADevice* inputDevice;
  198633. int numCallbacks;
  198634. CriticalSection callbackLock;
  198635. float* outputChannelData [maxNumChans];
  198636. float* outputChannelDataForCallback [maxNumChans];
  198637. int totalNumInputChannels;
  198638. float* inputChannelData [maxNumChans];
  198639. float* inputChannelDataForCallback [maxNumChans];
  198640. int totalNumOutputChannels;
  198641. unsigned int minChansOut, maxChansOut;
  198642. unsigned int minChansIn, maxChansIn;
  198643. bool failed (const int errorNum) throw()
  198644. {
  198645. if (errorNum >= 0)
  198646. return false;
  198647. error = snd_strerror (errorNum);
  198648. DBG (T("ALSA error: ") + error + T("\n"));
  198649. return true;
  198650. }
  198651. void initialiseRatesAndChannels() throw()
  198652. {
  198653. sampleRates.clear();
  198654. channelNamesOut.clear();
  198655. channelNamesIn.clear();
  198656. minChansOut = 0;
  198657. maxChansOut = 0;
  198658. minChansIn = 0;
  198659. maxChansIn = 0;
  198660. unsigned int dummy = 0;
  198661. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198662. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198663. unsigned int i;
  198664. for (i = 0; i < maxChansOut; ++i)
  198665. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198666. for (i = 0; i < maxChansIn; ++i)
  198667. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198668. }
  198669. };
  198670. class ALSAAudioIODevice : public AudioIODevice
  198671. {
  198672. public:
  198673. ALSAAudioIODevice (const String& deviceName,
  198674. const String& inputId_,
  198675. const String& outputId_)
  198676. : AudioIODevice (deviceName, T("ALSA")),
  198677. inputId (inputId_),
  198678. outputId (outputId_),
  198679. isOpen_ (false),
  198680. isStarted (false),
  198681. internal (0)
  198682. {
  198683. internal = new ALSAThread (inputId, outputId);
  198684. }
  198685. ~ALSAAudioIODevice()
  198686. {
  198687. delete internal;
  198688. }
  198689. const StringArray getOutputChannelNames()
  198690. {
  198691. return internal->channelNamesOut;
  198692. }
  198693. const StringArray getInputChannelNames()
  198694. {
  198695. return internal->channelNamesIn;
  198696. }
  198697. int getNumSampleRates()
  198698. {
  198699. return internal->sampleRates.size();
  198700. }
  198701. double getSampleRate (int index)
  198702. {
  198703. return internal->sampleRates [index];
  198704. }
  198705. int getNumBufferSizesAvailable()
  198706. {
  198707. return 50;
  198708. }
  198709. int getBufferSizeSamples (int index)
  198710. {
  198711. int n = 16;
  198712. for (int i = 0; i < index; ++i)
  198713. n += n < 64 ? 16
  198714. : (n < 512 ? 32
  198715. : (n < 1024 ? 64
  198716. : (n < 2048 ? 128 : 256)));
  198717. return n;
  198718. }
  198719. int getDefaultBufferSize()
  198720. {
  198721. return 512;
  198722. }
  198723. const String open (const BitArray& inputChannels,
  198724. const BitArray& outputChannels,
  198725. double sampleRate,
  198726. int bufferSizeSamples)
  198727. {
  198728. close();
  198729. if (bufferSizeSamples <= 0)
  198730. bufferSizeSamples = getDefaultBufferSize();
  198731. if (sampleRate <= 0)
  198732. {
  198733. for (int i = 0; i < getNumSampleRates(); ++i)
  198734. {
  198735. if (getSampleRate (i) >= 44100)
  198736. {
  198737. sampleRate = getSampleRate (i);
  198738. break;
  198739. }
  198740. }
  198741. }
  198742. internal->open (inputChannels, outputChannels,
  198743. sampleRate, bufferSizeSamples);
  198744. isOpen_ = internal->error.isEmpty();
  198745. return internal->error;
  198746. }
  198747. void close()
  198748. {
  198749. stop();
  198750. internal->close();
  198751. isOpen_ = false;
  198752. }
  198753. bool isOpen()
  198754. {
  198755. return isOpen_;
  198756. }
  198757. int getCurrentBufferSizeSamples()
  198758. {
  198759. return internal->bufferSize;
  198760. }
  198761. double getCurrentSampleRate()
  198762. {
  198763. return internal->sampleRate;
  198764. }
  198765. int getCurrentBitDepth()
  198766. {
  198767. return internal->getBitDepth();
  198768. }
  198769. const BitArray getActiveOutputChannels() const
  198770. {
  198771. return internal->currentOutputChans;
  198772. }
  198773. const BitArray getActiveInputChannels() const
  198774. {
  198775. return internal->currentInputChans;
  198776. }
  198777. int getOutputLatencyInSamples()
  198778. {
  198779. return 0;
  198780. }
  198781. int getInputLatencyInSamples()
  198782. {
  198783. return 0;
  198784. }
  198785. void start (AudioIODeviceCallback* callback)
  198786. {
  198787. if (! isOpen_)
  198788. callback = 0;
  198789. internal->setCallback (callback);
  198790. if (callback != 0)
  198791. callback->audioDeviceAboutToStart (this);
  198792. isStarted = (callback != 0);
  198793. }
  198794. void stop()
  198795. {
  198796. AudioIODeviceCallback* const oldCallback = internal->callback;
  198797. start (0);
  198798. if (oldCallback != 0)
  198799. oldCallback->audioDeviceStopped();
  198800. }
  198801. bool isPlaying()
  198802. {
  198803. return isStarted && internal->error.isEmpty();
  198804. }
  198805. const String getLastError()
  198806. {
  198807. return internal->error;
  198808. }
  198809. String inputId, outputId;
  198810. private:
  198811. bool isOpen_, isStarted;
  198812. ALSAThread* internal;
  198813. };
  198814. class ALSAAudioIODeviceType : public AudioIODeviceType
  198815. {
  198816. public:
  198817. ALSAAudioIODeviceType()
  198818. : AudioIODeviceType (T("ALSA")),
  198819. hasScanned (false)
  198820. {
  198821. }
  198822. ~ALSAAudioIODeviceType()
  198823. {
  198824. }
  198825. void scanForDevices()
  198826. {
  198827. if (hasScanned)
  198828. return;
  198829. hasScanned = true;
  198830. inputNames.clear();
  198831. inputIds.clear();
  198832. outputNames.clear();
  198833. outputIds.clear();
  198834. snd_ctl_t* handle;
  198835. snd_ctl_card_info_t* info;
  198836. snd_ctl_card_info_alloca (&info);
  198837. int cardNum = -1;
  198838. while (outputIds.size() + inputIds.size() <= 32)
  198839. {
  198840. snd_card_next (&cardNum);
  198841. if (cardNum < 0)
  198842. break;
  198843. if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0)
  198844. {
  198845. if (snd_ctl_card_info (handle, info) >= 0)
  198846. {
  198847. String cardId (snd_ctl_card_info_get_id (info));
  198848. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198849. cardId = String (cardNum);
  198850. int device = -1;
  198851. for (;;)
  198852. {
  198853. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198854. break;
  198855. String id, name;
  198856. id << "hw:" << cardId << ',' << device;
  198857. bool isInput, isOutput;
  198858. if (testDevice (id, isInput, isOutput))
  198859. {
  198860. name << snd_ctl_card_info_get_name (info);
  198861. if (name.isEmpty())
  198862. name = id;
  198863. if (isInput)
  198864. {
  198865. inputNames.add (name);
  198866. inputIds.add (id);
  198867. }
  198868. if (isOutput)
  198869. {
  198870. outputNames.add (name);
  198871. outputIds.add (id);
  198872. }
  198873. }
  198874. }
  198875. }
  198876. snd_ctl_close (handle);
  198877. }
  198878. }
  198879. inputNames.appendNumbersToDuplicates (false, true);
  198880. outputNames.appendNumbersToDuplicates (false, true);
  198881. }
  198882. const StringArray getDeviceNames (const bool wantInputNames) const
  198883. {
  198884. jassert (hasScanned); // need to call scanForDevices() before doing this
  198885. return wantInputNames ? inputNames : outputNames;
  198886. }
  198887. int getDefaultDeviceIndex (const bool forInput) const
  198888. {
  198889. jassert (hasScanned); // need to call scanForDevices() before doing this
  198890. return 0;
  198891. }
  198892. bool hasSeparateInputsAndOutputs() const { return true; }
  198893. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198894. {
  198895. jassert (hasScanned); // need to call scanForDevices() before doing this
  198896. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198897. if (d == 0)
  198898. return -1;
  198899. return asInput ? inputIds.indexOf (d->inputId)
  198900. : outputIds.indexOf (d->outputId);
  198901. }
  198902. AudioIODevice* createDevice (const String& outputDeviceName,
  198903. const String& inputDeviceName)
  198904. {
  198905. jassert (hasScanned); // need to call scanForDevices() before doing this
  198906. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198907. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198908. String deviceName (outputIndex >= 0 ? outputDeviceName
  198909. : inputDeviceName);
  198910. if (inputIndex >= 0 || outputIndex >= 0)
  198911. return new ALSAAudioIODevice (deviceName,
  198912. inputIds [inputIndex],
  198913. outputIds [outputIndex]);
  198914. return 0;
  198915. }
  198916. juce_UseDebuggingNewOperator
  198917. private:
  198918. StringArray inputNames, outputNames, inputIds, outputIds;
  198919. bool hasScanned;
  198920. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198921. {
  198922. unsigned int minChansOut = 0, maxChansOut = 0;
  198923. unsigned int minChansIn = 0, maxChansIn = 0;
  198924. Array <int> rates;
  198925. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198926. DBG (T("ALSA device: ") + id
  198927. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198928. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198929. + T(" rates=") + String (rates.size()));
  198930. isInput = maxChansIn > 0;
  198931. isOutput = maxChansOut > 0;
  198932. return (isInput || isOutput) && rates.size() > 0;
  198933. }
  198934. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198935. const ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198936. };
  198937. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198938. {
  198939. return new ALSAAudioIODeviceType();
  198940. }
  198941. #endif
  198942. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198943. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198944. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198945. // compiled on its own).
  198946. #ifdef JUCE_INCLUDED_FILE
  198947. #if JUCE_JACK
  198948. static void* juce_libjack_handle = 0;
  198949. void* juce_load_jack_function (const char* const name)
  198950. {
  198951. if (juce_libjack_handle == 0)
  198952. return 0;
  198953. return dlsym (juce_libjack_handle, name);
  198954. }
  198955. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198956. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198957. return_type fn_name argument_types { \
  198958. static fn_name##_ptr_t fn = 0; \
  198959. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198960. if (fn) return (*fn)arguments; \
  198961. else return 0; \
  198962. }
  198963. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198964. typedef void (*fn_name##_ptr_t)argument_types; \
  198965. void fn_name argument_types { \
  198966. static fn_name##_ptr_t fn = 0; \
  198967. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198968. if (fn) (*fn)arguments; \
  198969. }
  198970. 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));
  198971. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198972. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198973. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198974. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198975. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198976. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198977. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198978. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198979. 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));
  198980. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198981. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198982. 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));
  198983. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198984. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198985. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198986. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198987. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198988. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198989. #if JUCE_DEBUG
  198990. #define JACK_LOGGING_ENABLED 1
  198991. #endif
  198992. #if JACK_LOGGING_ENABLED
  198993. static void jack_Log (const String& s)
  198994. {
  198995. puts (s);
  198996. }
  198997. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198998. {
  198999. if (status & JackServerFailed || status & JackServerError)
  199000. jack_Log ("Unable to connect to JACK server");
  199001. if (status & JackVersionError)
  199002. jack_Log ("Client's protocol version does not match");
  199003. if (status & JackInvalidOption)
  199004. jack_Log ("The operation contained an invalid or unsupported option");
  199005. if (status & JackNameNotUnique)
  199006. jack_Log ("The desired client name was not unique");
  199007. if (status & JackNoSuchClient)
  199008. jack_Log ("Requested client does not exist");
  199009. if (status & JackInitFailure)
  199010. jack_Log ("Unable to initialize client");
  199011. }
  199012. #else
  199013. #define dumpJackErrorMessage(a) {}
  199014. #define jack_Log(...) {}
  199015. #endif
  199016. #ifndef JUCE_JACK_CLIENT_NAME
  199017. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  199018. #endif
  199019. class JackAudioIODevice : public AudioIODevice
  199020. {
  199021. public:
  199022. JackAudioIODevice (const String& deviceName,
  199023. const String& inputId_,
  199024. const String& outputId_)
  199025. : AudioIODevice (deviceName, T("JACK")),
  199026. inputId (inputId_),
  199027. outputId (outputId_),
  199028. isOpen_ (false),
  199029. callback (0),
  199030. totalNumberOfInputChannels (0),
  199031. totalNumberOfOutputChannels (0)
  199032. {
  199033. jassert (deviceName.isNotEmpty());
  199034. jack_status_t status;
  199035. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  199036. if (client == 0)
  199037. {
  199038. dumpJackErrorMessage (status);
  199039. }
  199040. else
  199041. {
  199042. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  199043. // open input ports
  199044. const StringArray inputChannels (getInputChannelNames());
  199045. for (int i = 0; i < inputChannels.size(); i++)
  199046. {
  199047. String inputName;
  199048. inputName << "in_" << (++totalNumberOfInputChannels);
  199049. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName,
  199050. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  199051. }
  199052. // open output ports
  199053. const StringArray outputChannels (getOutputChannelNames());
  199054. for (int i = 0; i < outputChannels.size (); i++)
  199055. {
  199056. String outputName;
  199057. outputName << "out_" << (++totalNumberOfOutputChannels);
  199058. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName,
  199059. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  199060. }
  199061. inChans.calloc (totalNumberOfInputChannels + 2);
  199062. outChans.calloc (totalNumberOfOutputChannels + 2);
  199063. }
  199064. }
  199065. ~JackAudioIODevice()
  199066. {
  199067. close();
  199068. if (client != 0)
  199069. {
  199070. JUCE_NAMESPACE::jack_client_close (client);
  199071. client = 0;
  199072. }
  199073. }
  199074. const StringArray getChannelNames (bool forInput) const
  199075. {
  199076. StringArray names;
  199077. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  199078. forInput ? JackPortIsInput : JackPortIsOutput);
  199079. if (ports != 0)
  199080. {
  199081. int j = 0;
  199082. while (ports[j] != 0)
  199083. {
  199084. const String portName (ports [j++]);
  199085. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199086. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  199087. }
  199088. free (ports);
  199089. }
  199090. return names;
  199091. }
  199092. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  199093. const StringArray getInputChannelNames() { return getChannelNames (true); }
  199094. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  199095. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  199096. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  199097. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  199098. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  199099. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  199100. double sampleRate, int bufferSizeSamples)
  199101. {
  199102. if (client == 0)
  199103. {
  199104. lastError = T("No JACK client running");
  199105. return lastError;
  199106. }
  199107. lastError = String::empty;
  199108. close();
  199109. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199110. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199111. JUCE_NAMESPACE::jack_activate (client);
  199112. isOpen_ = true;
  199113. if (! inputChannels.isEmpty())
  199114. {
  199115. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199116. if (ports != 0)
  199117. {
  199118. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199119. for (int i = 0; i < numInputChannels; ++i)
  199120. {
  199121. const String portName (ports[i]);
  199122. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199123. {
  199124. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199125. if (error != 0)
  199126. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199127. }
  199128. }
  199129. free (ports);
  199130. }
  199131. }
  199132. if (! outputChannels.isEmpty())
  199133. {
  199134. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199135. if (ports != 0)
  199136. {
  199137. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199138. for (int i = 0; i < numOutputChannels; ++i)
  199139. {
  199140. const String portName (ports[i]);
  199141. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199142. {
  199143. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199144. if (error != 0)
  199145. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199146. }
  199147. }
  199148. free (ports);
  199149. }
  199150. }
  199151. return lastError;
  199152. }
  199153. void close()
  199154. {
  199155. stop();
  199156. if (client != 0)
  199157. {
  199158. JUCE_NAMESPACE::jack_deactivate (client);
  199159. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199160. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199161. }
  199162. isOpen_ = false;
  199163. }
  199164. void start (AudioIODeviceCallback* newCallback)
  199165. {
  199166. if (isOpen_ && newCallback != callback)
  199167. {
  199168. if (newCallback != 0)
  199169. newCallback->audioDeviceAboutToStart (this);
  199170. AudioIODeviceCallback* const oldCallback = callback;
  199171. {
  199172. const ScopedLock sl (callbackLock);
  199173. callback = newCallback;
  199174. }
  199175. if (oldCallback != 0)
  199176. oldCallback->audioDeviceStopped();
  199177. }
  199178. }
  199179. void stop()
  199180. {
  199181. start (0);
  199182. }
  199183. bool isOpen() { return isOpen_; }
  199184. bool isPlaying() { return callback != 0; }
  199185. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199186. double getCurrentSampleRate() { return getSampleRate (0); }
  199187. int getCurrentBitDepth() { return 32; }
  199188. const String getLastError() { return lastError; }
  199189. const BitArray getActiveOutputChannels() const
  199190. {
  199191. BitArray outputBits;
  199192. for (int i = 0; i < outputPorts.size(); i++)
  199193. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199194. outputBits.setBit (i);
  199195. return outputBits;
  199196. }
  199197. const BitArray getActiveInputChannels() const
  199198. {
  199199. BitArray inputBits;
  199200. for (int i = 0; i < inputPorts.size(); i++)
  199201. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199202. inputBits.setBit (i);
  199203. return inputBits;
  199204. }
  199205. int getOutputLatencyInSamples()
  199206. {
  199207. int latency = 0;
  199208. for (int i = 0; i < outputPorts.size(); i++)
  199209. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199210. return latency;
  199211. }
  199212. int getInputLatencyInSamples()
  199213. {
  199214. int latency = 0;
  199215. for (int i = 0; i < inputPorts.size(); i++)
  199216. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199217. return latency;
  199218. }
  199219. String inputId, outputId;
  199220. private:
  199221. void process (const int numSamples)
  199222. {
  199223. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199224. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199225. {
  199226. jack_default_audio_sample_t* in
  199227. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199228. if (in != 0)
  199229. inChans [numActiveInChans++] = (float*) in;
  199230. }
  199231. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199232. {
  199233. jack_default_audio_sample_t* out
  199234. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199235. if (out != 0)
  199236. outChans [numActiveOutChans++] = (float*) out;
  199237. }
  199238. const ScopedLock sl (callbackLock);
  199239. if (callback != 0)
  199240. {
  199241. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199242. outChans, numActiveOutChans, numSamples);
  199243. }
  199244. else
  199245. {
  199246. for (i = 0; i < numActiveOutChans; ++i)
  199247. zeromem (outChans[i], sizeof (float) * numSamples);
  199248. }
  199249. }
  199250. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199251. {
  199252. if (callbackArgument != 0)
  199253. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199254. return 0;
  199255. }
  199256. static void threadInitCallback (void* callbackArgument)
  199257. {
  199258. jack_Log ("JackAudioIODevice::initialise");
  199259. }
  199260. static void shutdownCallback (void* callbackArgument)
  199261. {
  199262. jack_Log ("JackAudioIODevice::shutdown");
  199263. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199264. if (device != 0)
  199265. {
  199266. device->client = 0;
  199267. device->close();
  199268. }
  199269. }
  199270. static void errorCallback (const char* msg)
  199271. {
  199272. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199273. }
  199274. bool isOpen_;
  199275. jack_client_t* client;
  199276. String lastError;
  199277. AudioIODeviceCallback* callback;
  199278. CriticalSection callbackLock;
  199279. HeapBlock <float*> inChans, outChans;
  199280. int totalNumberOfInputChannels;
  199281. int totalNumberOfOutputChannels;
  199282. VoidArray inputPorts, outputPorts;
  199283. };
  199284. class JackAudioIODeviceType : public AudioIODeviceType
  199285. {
  199286. public:
  199287. JackAudioIODeviceType()
  199288. : AudioIODeviceType (T("JACK")),
  199289. hasScanned (false)
  199290. {
  199291. }
  199292. ~JackAudioIODeviceType()
  199293. {
  199294. }
  199295. void scanForDevices()
  199296. {
  199297. hasScanned = true;
  199298. inputNames.clear();
  199299. inputIds.clear();
  199300. outputNames.clear();
  199301. outputIds.clear();
  199302. if (juce_libjack_handle == 0)
  199303. {
  199304. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199305. if (juce_libjack_handle == 0)
  199306. return;
  199307. }
  199308. // open a dummy client
  199309. jack_status_t status;
  199310. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199311. if (client == 0)
  199312. {
  199313. dumpJackErrorMessage (status);
  199314. }
  199315. else
  199316. {
  199317. // scan for output devices
  199318. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199319. if (ports != 0)
  199320. {
  199321. int j = 0;
  199322. while (ports[j] != 0)
  199323. {
  199324. String clientName (ports[j]);
  199325. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199326. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199327. && ! inputNames.contains (clientName))
  199328. {
  199329. inputNames.add (clientName);
  199330. inputIds.add (ports [j]);
  199331. }
  199332. ++j;
  199333. }
  199334. free (ports);
  199335. }
  199336. // scan for input devices
  199337. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199338. if (ports != 0)
  199339. {
  199340. int j = 0;
  199341. while (ports[j] != 0)
  199342. {
  199343. String clientName (ports[j]);
  199344. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199345. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199346. && ! outputNames.contains (clientName))
  199347. {
  199348. outputNames.add (clientName);
  199349. outputIds.add (ports [j]);
  199350. }
  199351. ++j;
  199352. }
  199353. free (ports);
  199354. }
  199355. JUCE_NAMESPACE::jack_client_close (client);
  199356. }
  199357. }
  199358. const StringArray getDeviceNames (const bool wantInputNames) const
  199359. {
  199360. jassert (hasScanned); // need to call scanForDevices() before doing this
  199361. return wantInputNames ? inputNames : outputNames;
  199362. }
  199363. int getDefaultDeviceIndex (const bool forInput) const
  199364. {
  199365. jassert (hasScanned); // need to call scanForDevices() before doing this
  199366. return 0;
  199367. }
  199368. bool hasSeparateInputsAndOutputs() const { return true; }
  199369. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199370. {
  199371. jassert (hasScanned); // need to call scanForDevices() before doing this
  199372. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199373. if (d == 0)
  199374. return -1;
  199375. return asInput ? inputIds.indexOf (d->inputId)
  199376. : outputIds.indexOf (d->outputId);
  199377. }
  199378. AudioIODevice* createDevice (const String& outputDeviceName,
  199379. const String& inputDeviceName)
  199380. {
  199381. jassert (hasScanned); // need to call scanForDevices() before doing this
  199382. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199383. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199384. if (inputIndex >= 0 || outputIndex >= 0)
  199385. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199386. : inputDeviceName,
  199387. inputIds [inputIndex],
  199388. outputIds [outputIndex]);
  199389. return 0;
  199390. }
  199391. juce_UseDebuggingNewOperator
  199392. private:
  199393. StringArray inputNames, outputNames, inputIds, outputIds;
  199394. bool hasScanned;
  199395. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199396. const JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199397. };
  199398. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199399. {
  199400. return new JackAudioIODeviceType();
  199401. }
  199402. #else // if JACK is turned off..
  199403. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199404. #endif
  199405. #endif
  199406. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199407. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199408. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199409. // compiled on its own).
  199410. #if JUCE_INCLUDED_FILE
  199411. #if JUCE_ALSA
  199412. static snd_seq_t* iterateDevices (const bool forInput,
  199413. StringArray& deviceNamesFound,
  199414. const int deviceIndexToOpen)
  199415. {
  199416. snd_seq_t* returnedHandle = 0;
  199417. snd_seq_t* seqHandle;
  199418. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199419. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199420. {
  199421. snd_seq_system_info_t* systemInfo;
  199422. snd_seq_client_info_t* clientInfo;
  199423. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199424. {
  199425. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199426. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199427. {
  199428. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199429. while (--numClients >= 0 && returnedHandle == 0)
  199430. {
  199431. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199432. {
  199433. snd_seq_port_info_t* portInfo;
  199434. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199435. {
  199436. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199437. const int client = snd_seq_client_info_get_client (clientInfo);
  199438. snd_seq_port_info_set_client (portInfo, client);
  199439. snd_seq_port_info_set_port (portInfo, -1);
  199440. while (--numPorts >= 0)
  199441. {
  199442. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199443. && (snd_seq_port_info_get_capability (portInfo)
  199444. & (forInput ? SND_SEQ_PORT_CAP_READ
  199445. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199446. {
  199447. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199448. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199449. {
  199450. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199451. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199452. if (sourcePort != -1)
  199453. {
  199454. snd_seq_set_client_name (seqHandle,
  199455. forInput ? "Juce Midi Input"
  199456. : "Juce Midi Output");
  199457. const int portId
  199458. = snd_seq_create_simple_port (seqHandle,
  199459. forInput ? "Juce Midi In Port"
  199460. : "Juce Midi Out Port",
  199461. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199462. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199463. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199464. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199465. returnedHandle = seqHandle;
  199466. }
  199467. }
  199468. }
  199469. }
  199470. snd_seq_port_info_free (portInfo);
  199471. }
  199472. }
  199473. }
  199474. snd_seq_client_info_free (clientInfo);
  199475. }
  199476. snd_seq_system_info_free (systemInfo);
  199477. }
  199478. if (returnedHandle == 0)
  199479. snd_seq_close (seqHandle);
  199480. }
  199481. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199482. return returnedHandle;
  199483. }
  199484. static snd_seq_t* createDevice (const bool forInput,
  199485. const String& deviceNameToOpen)
  199486. {
  199487. snd_seq_t* seqHandle = 0;
  199488. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199489. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199490. {
  199491. snd_seq_set_client_name (seqHandle,
  199492. (const char*) (forInput ? (deviceNameToOpen + T(" Input"))
  199493. : (deviceNameToOpen + T(" Output"))));
  199494. const int portId
  199495. = snd_seq_create_simple_port (seqHandle,
  199496. forInput ? "in"
  199497. : "out",
  199498. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199499. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199500. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199501. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199502. if (portId < 0)
  199503. {
  199504. snd_seq_close (seqHandle);
  199505. seqHandle = 0;
  199506. }
  199507. }
  199508. return seqHandle;
  199509. }
  199510. class MidiOutputDevice
  199511. {
  199512. public:
  199513. MidiOutputDevice (MidiOutput* const midiOutput_,
  199514. snd_seq_t* const seqHandle_)
  199515. :
  199516. midiOutput (midiOutput_),
  199517. seqHandle (seqHandle_),
  199518. maxEventSize (16 * 1024)
  199519. {
  199520. jassert (seqHandle != 0 && midiOutput != 0);
  199521. snd_midi_event_new (maxEventSize, &midiParser);
  199522. }
  199523. ~MidiOutputDevice()
  199524. {
  199525. snd_midi_event_free (midiParser);
  199526. snd_seq_close (seqHandle);
  199527. }
  199528. void sendMessageNow (const MidiMessage& message)
  199529. {
  199530. if (message.getRawDataSize() > maxEventSize)
  199531. {
  199532. maxEventSize = message.getRawDataSize();
  199533. snd_midi_event_free (midiParser);
  199534. snd_midi_event_new (maxEventSize, &midiParser);
  199535. }
  199536. snd_seq_event_t event;
  199537. snd_seq_ev_clear (&event);
  199538. snd_midi_event_encode (midiParser,
  199539. message.getRawData(),
  199540. message.getRawDataSize(),
  199541. &event);
  199542. snd_midi_event_reset_encode (midiParser);
  199543. snd_seq_ev_set_source (&event, 0);
  199544. snd_seq_ev_set_subs (&event);
  199545. snd_seq_ev_set_direct (&event);
  199546. snd_seq_event_output (seqHandle, &event);
  199547. snd_seq_drain_output (seqHandle);
  199548. }
  199549. juce_UseDebuggingNewOperator
  199550. private:
  199551. MidiOutput* const midiOutput;
  199552. snd_seq_t* const seqHandle;
  199553. snd_midi_event_t* midiParser;
  199554. int maxEventSize;
  199555. };
  199556. const StringArray MidiOutput::getDevices()
  199557. {
  199558. StringArray devices;
  199559. iterateDevices (false, devices, -1);
  199560. return devices;
  199561. }
  199562. int MidiOutput::getDefaultDeviceIndex()
  199563. {
  199564. return 0;
  199565. }
  199566. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199567. {
  199568. MidiOutput* newDevice = 0;
  199569. StringArray devices;
  199570. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199571. if (handle != 0)
  199572. {
  199573. newDevice = new MidiOutput();
  199574. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199575. }
  199576. return newDevice;
  199577. }
  199578. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199579. {
  199580. MidiOutput* newDevice = 0;
  199581. snd_seq_t* const handle = createDevice (false, deviceName);
  199582. if (handle != 0)
  199583. {
  199584. newDevice = new MidiOutput();
  199585. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199586. }
  199587. return newDevice;
  199588. }
  199589. MidiOutput::~MidiOutput()
  199590. {
  199591. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199592. delete device;
  199593. }
  199594. void MidiOutput::reset()
  199595. {
  199596. }
  199597. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199598. {
  199599. return false;
  199600. }
  199601. void MidiOutput::setVolume (float leftVol, float rightVol)
  199602. {
  199603. }
  199604. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199605. {
  199606. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199607. }
  199608. class MidiInputThread : public Thread
  199609. {
  199610. public:
  199611. MidiInputThread (MidiInput* const midiInput_,
  199612. snd_seq_t* const seqHandle_,
  199613. MidiInputCallback* const callback_)
  199614. : Thread (T("Juce MIDI Input")),
  199615. midiInput (midiInput_),
  199616. seqHandle (seqHandle_),
  199617. callback (callback_)
  199618. {
  199619. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199620. }
  199621. ~MidiInputThread()
  199622. {
  199623. snd_seq_close (seqHandle);
  199624. }
  199625. void run()
  199626. {
  199627. const int maxEventSize = 16 * 1024;
  199628. snd_midi_event_t* midiParser;
  199629. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199630. {
  199631. HeapBlock <uint8> buffer (maxEventSize);
  199632. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199633. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199634. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199635. while (! threadShouldExit())
  199636. {
  199637. if (poll (pfd, numPfds, 500) > 0)
  199638. {
  199639. snd_seq_event_t* inputEvent = 0;
  199640. snd_seq_nonblock (seqHandle, 1);
  199641. do
  199642. {
  199643. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199644. {
  199645. // xxx what about SYSEXes that are too big for the buffer?
  199646. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199647. snd_midi_event_reset_decode (midiParser);
  199648. if (numBytes > 0)
  199649. {
  199650. const MidiMessage message ((const uint8*) buffer,
  199651. numBytes,
  199652. Time::getMillisecondCounter() * 0.001);
  199653. callback->handleIncomingMidiMessage (midiInput, message);
  199654. }
  199655. snd_seq_free_event (inputEvent);
  199656. }
  199657. }
  199658. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199659. snd_seq_free_event (inputEvent);
  199660. }
  199661. }
  199662. snd_midi_event_free (midiParser);
  199663. }
  199664. };
  199665. juce_UseDebuggingNewOperator
  199666. private:
  199667. MidiInput* const midiInput;
  199668. snd_seq_t* const seqHandle;
  199669. MidiInputCallback* const callback;
  199670. };
  199671. MidiInput::MidiInput (const String& name_)
  199672. : name (name_),
  199673. internal (0)
  199674. {
  199675. }
  199676. MidiInput::~MidiInput()
  199677. {
  199678. stop();
  199679. MidiInputThread* const thread = (MidiInputThread*) internal;
  199680. delete thread;
  199681. }
  199682. void MidiInput::start()
  199683. {
  199684. ((MidiInputThread*) internal)->startThread();
  199685. }
  199686. void MidiInput::stop()
  199687. {
  199688. ((MidiInputThread*) internal)->stopThread (3000);
  199689. }
  199690. int MidiInput::getDefaultDeviceIndex()
  199691. {
  199692. return 0;
  199693. }
  199694. const StringArray MidiInput::getDevices()
  199695. {
  199696. StringArray devices;
  199697. iterateDevices (true, devices, -1);
  199698. return devices;
  199699. }
  199700. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199701. {
  199702. MidiInput* newDevice = 0;
  199703. StringArray devices;
  199704. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199705. if (handle != 0)
  199706. {
  199707. newDevice = new MidiInput (devices [deviceIndex]);
  199708. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199709. }
  199710. return newDevice;
  199711. }
  199712. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199713. {
  199714. MidiInput* newDevice = 0;
  199715. snd_seq_t* const handle = createDevice (true, deviceName);
  199716. if (handle != 0)
  199717. {
  199718. newDevice = new MidiInput (deviceName);
  199719. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199720. }
  199721. return newDevice;
  199722. }
  199723. #else
  199724. // (These are just stub functions if ALSA is unavailable...)
  199725. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199726. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199727. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199728. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199729. MidiOutput::~MidiOutput() {}
  199730. void MidiOutput::reset() {}
  199731. bool MidiOutput::getVolume (float&, float&) { return false; }
  199732. void MidiOutput::setVolume (float, float) {}
  199733. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199734. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199735. MidiInput::~MidiInput() {}
  199736. void MidiInput::start() {}
  199737. void MidiInput::stop() {}
  199738. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199739. const StringArray MidiInput::getDevices() { return StringArray(); }
  199740. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199741. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199742. #endif
  199743. #endif
  199744. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199745. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199746. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199747. // compiled on its own).
  199748. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199749. AudioCDReader::AudioCDReader()
  199750. : AudioFormatReader (0, T("CD Audio"))
  199751. {
  199752. }
  199753. const StringArray AudioCDReader::getAvailableCDNames()
  199754. {
  199755. StringArray names;
  199756. return names;
  199757. }
  199758. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199759. {
  199760. return 0;
  199761. }
  199762. AudioCDReader::~AudioCDReader()
  199763. {
  199764. }
  199765. void AudioCDReader::refreshTrackLengths()
  199766. {
  199767. }
  199768. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199769. int64 startSampleInFile, int numSamples)
  199770. {
  199771. return false;
  199772. }
  199773. bool AudioCDReader::isCDStillPresent() const
  199774. {
  199775. return false;
  199776. }
  199777. int AudioCDReader::getNumTracks() const
  199778. {
  199779. return 0;
  199780. }
  199781. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199782. {
  199783. return 0;
  199784. }
  199785. bool AudioCDReader::isTrackAudio (int trackNum) const
  199786. {
  199787. return false;
  199788. }
  199789. void AudioCDReader::enableIndexScanning (bool b)
  199790. {
  199791. }
  199792. int AudioCDReader::getLastIndex() const
  199793. {
  199794. return 0;
  199795. }
  199796. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199797. {
  199798. return Array<int>();
  199799. }
  199800. int AudioCDReader::getCDDBId()
  199801. {
  199802. return 0;
  199803. }
  199804. #endif
  199805. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199806. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199807. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199808. // compiled on its own).
  199809. #if JUCE_INCLUDED_FILE
  199810. void FileChooser::showPlatformDialog (Array<File>& results,
  199811. const String& title,
  199812. const File& file,
  199813. const String& filters,
  199814. bool isDirectory,
  199815. bool selectsFiles,
  199816. bool isSave,
  199817. bool warnAboutOverwritingExistingFiles,
  199818. bool selectMultipleFiles,
  199819. FilePreviewComponent* previewComponent)
  199820. {
  199821. const tchar* const separator = T(":");
  199822. String command ("zenity --file-selection");
  199823. if (title.isNotEmpty())
  199824. command << " --title=\"" << title << "\"";
  199825. if (file != File::nonexistent)
  199826. command << " --filename=\"" << file.getFullPathName () << "\"";
  199827. if (isDirectory)
  199828. command << " --directory";
  199829. if (isSave)
  199830. command << " --save";
  199831. if (selectMultipleFiles)
  199832. command << " --multiple --separator=\"" << separator << "\"";
  199833. command << " 2>&1";
  199834. MemoryOutputStream result;
  199835. int status = -1;
  199836. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199837. if (stream != 0)
  199838. {
  199839. for (;;)
  199840. {
  199841. char buffer [1024];
  199842. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199843. if (bytesRead <= 0)
  199844. break;
  199845. result.write (buffer, bytesRead);
  199846. }
  199847. status = pclose (stream);
  199848. }
  199849. if (status == 0)
  199850. {
  199851. String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize()));
  199852. StringArray tokens;
  199853. if (selectMultipleFiles)
  199854. tokens.addTokens (resultString, separator, 0);
  199855. else
  199856. tokens.add (resultString);
  199857. for (int i = 0; i < tokens.size(); i++)
  199858. results.add (File (tokens[i]));
  199859. return;
  199860. }
  199861. //xxx ain't got one!
  199862. jassertfalse
  199863. }
  199864. #endif
  199865. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199866. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199867. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199868. // compiled on its own).
  199869. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199870. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199871. : browser (0),
  199872. blankPageShown (false),
  199873. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199874. {
  199875. setOpaque (true);
  199876. }
  199877. WebBrowserComponent::~WebBrowserComponent()
  199878. {
  199879. }
  199880. void WebBrowserComponent::goToURL (const String& url,
  199881. const StringArray* headers,
  199882. const MemoryBlock* postData)
  199883. {
  199884. lastURL = url;
  199885. lastHeaders.clear();
  199886. if (headers != 0)
  199887. lastHeaders = *headers;
  199888. lastPostData.setSize (0);
  199889. if (postData != 0)
  199890. lastPostData = *postData;
  199891. blankPageShown = false;
  199892. }
  199893. void WebBrowserComponent::stop()
  199894. {
  199895. }
  199896. void WebBrowserComponent::goBack()
  199897. {
  199898. lastURL = String::empty;
  199899. blankPageShown = false;
  199900. }
  199901. void WebBrowserComponent::goForward()
  199902. {
  199903. lastURL = String::empty;
  199904. }
  199905. void WebBrowserComponent::refresh()
  199906. {
  199907. }
  199908. void WebBrowserComponent::paint (Graphics& g)
  199909. {
  199910. g.fillAll (Colours::white);
  199911. }
  199912. void WebBrowserComponent::checkWindowAssociation()
  199913. {
  199914. }
  199915. void WebBrowserComponent::reloadLastURL()
  199916. {
  199917. if (lastURL.isNotEmpty())
  199918. {
  199919. goToURL (lastURL, &lastHeaders, &lastPostData);
  199920. lastURL = String::empty;
  199921. }
  199922. }
  199923. void WebBrowserComponent::parentHierarchyChanged()
  199924. {
  199925. checkWindowAssociation();
  199926. }
  199927. void WebBrowserComponent::resized()
  199928. {
  199929. }
  199930. void WebBrowserComponent::visibilityChanged()
  199931. {
  199932. checkWindowAssociation();
  199933. }
  199934. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199935. {
  199936. return true;
  199937. }
  199938. #endif
  199939. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199940. #endif
  199941. END_JUCE_NAMESPACE
  199942. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199943. #endif
  199944. #if JUCE_MAC || JUCE_IPHONE
  199945. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199946. BEGIN_JUCE_NAMESPACE
  199947. #undef Point
  199948. #define JUCE_INCLUDED_FILE 1
  199949. // Now include the actual code files..
  199950. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199951. #ifndef JUCE_ObjCExtraSuffix
  199952. #define JUCE_ObjCExtraSuffix 3
  199953. #endif
  199954. #define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d
  199955. #define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d)
  199956. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix)
  199957. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199958. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199959. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199960. // compiled on its own).
  199961. #if JUCE_INCLUDED_FILE
  199962. static const String nsStringToJuce (NSString* s)
  199963. {
  199964. return String::fromUTF8 ((uint8*) [s UTF8String]);
  199965. }
  199966. static NSString* juceStringToNS (const String& s)
  199967. {
  199968. return [NSString stringWithUTF8String: (const char*) s.toUTF8()];
  199969. }
  199970. static const String convertUTF16ToString (const UniChar* utf16)
  199971. {
  199972. String s;
  199973. while (*utf16 != 0)
  199974. s += (juce_wchar) *utf16++;
  199975. return s;
  199976. }
  199977. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199978. {
  199979. String result;
  199980. if (cfString != 0)
  199981. {
  199982. #if JUCE_STRINGS_ARE_UNICODE
  199983. CFRange range = { 0, CFStringGetLength (cfString) };
  199984. HeapBlock <UniChar> u (range.length + 1);
  199985. CFStringGetCharacters (cfString, range, u);
  199986. u[range.length] = 0;
  199987. result = convertUTF16ToString (u);
  199988. #else
  199989. const int len = CFStringGetLength (cfString);
  199990. HeapBlock <char> buffer (len + 1);
  199991. CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding());
  199992. result = buffer;
  199993. #endif
  199994. }
  199995. return result;
  199996. }
  199997. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199998. {
  199999. #if JUCE_STRINGS_ARE_UNICODE
  200000. const int len = s.length();
  200001. const juce_wchar* t = (const juce_wchar*) s;
  200002. HeapBlock <UniChar> temp (len + 2);
  200003. for (int i = 0; i <= len; ++i)
  200004. temp[i] = t[i];
  200005. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  200006. #else
  200007. return CFStringCreateWithCString (kCFAllocatorDefault,
  200008. (const char*) s,
  200009. CFStringGetSystemEncoding());
  200010. #endif
  200011. }
  200012. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  200013. {
  200014. #if JUCE_IPHONE
  200015. const ScopedAutoReleasePool pool;
  200016. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  200017. #else
  200018. UnicodeMapping map;
  200019. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200020. kUnicodeNoSubset,
  200021. kTextEncodingDefaultFormat);
  200022. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200023. kUnicodeCanonicalCompVariant,
  200024. kTextEncodingDefaultFormat);
  200025. map.mappingVersion = kUnicodeUseLatestMapping;
  200026. UnicodeToTextInfo conversionInfo = 0;
  200027. String result;
  200028. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  200029. {
  200030. const int len = s.length();
  200031. HeapBlock <UniChar> tempIn, tempOut;
  200032. tempIn.calloc (len + 2);
  200033. tempOut.calloc (len + 2);
  200034. for (int i = 0; i <= len; ++i)
  200035. tempIn[i] = s[i];
  200036. ByteCount bytesRead = 0;
  200037. ByteCount outputBufferSize = 0;
  200038. if (ConvertFromUnicodeToText (conversionInfo,
  200039. len * sizeof (UniChar), tempIn,
  200040. kUnicodeDefaultDirectionMask,
  200041. 0, 0, 0, 0,
  200042. len * sizeof (UniChar), &bytesRead,
  200043. &outputBufferSize, tempOut) == noErr)
  200044. {
  200045. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  200046. tchar* t = const_cast <tchar*> ((const tchar*) result);
  200047. unsigned int i;
  200048. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  200049. t[i] = (tchar) tempOut[i];
  200050. t[i] = 0;
  200051. }
  200052. DisposeUnicodeToTextInfo (&conversionInfo);
  200053. }
  200054. return result;
  200055. #endif
  200056. }
  200057. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  200058. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  200059. {
  200060. #if JUCE_IPHONE
  200061. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  200062. forPasteboardType: @"public.text"];
  200063. #else
  200064. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  200065. owner: nil];
  200066. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  200067. forType: NSStringPboardType];
  200068. #endif
  200069. }
  200070. const String SystemClipboard::getTextFromClipboard() throw()
  200071. {
  200072. #if JUCE_IPHONE
  200073. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  200074. #else
  200075. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  200076. #endif
  200077. return text == 0 ? String::empty
  200078. : nsStringToJuce (text);
  200079. }
  200080. #endif
  200081. #endif
  200082. /*** End of inlined file: juce_mac_Strings.mm ***/
  200083. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  200084. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200085. // compiled on its own).
  200086. #if JUCE_INCLUDED_FILE
  200087. static int64 highResTimerFrequency = 0;
  200088. static double highResTimerToMillisecRatio = 0;
  200089. #if JUCE_INTEL
  200090. static void juce_getCpuVendor (char* const v) throw()
  200091. {
  200092. int vendor[4];
  200093. zerostruct (vendor);
  200094. int dummy = 0;
  200095. asm ("mov %%ebx, %%esi \n\t"
  200096. "cpuid \n\t"
  200097. "xchg %%esi, %%ebx"
  200098. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  200099. memcpy (v, vendor, 16);
  200100. }
  200101. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  200102. {
  200103. unsigned int cpu = 0;
  200104. unsigned int ext = 0;
  200105. unsigned int family = 0;
  200106. unsigned int dummy = 0;
  200107. asm ("mov %%ebx, %%esi \n\t"
  200108. "cpuid \n\t"
  200109. "xchg %%esi, %%ebx"
  200110. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  200111. familyModel = family;
  200112. extFeatures = ext;
  200113. return cpu;
  200114. }
  200115. struct CPUFlags
  200116. {
  200117. bool hasMMX : 1;
  200118. bool hasSSE : 1;
  200119. bool hasSSE2 : 1;
  200120. bool has3DNow : 1;
  200121. };
  200122. static CPUFlags cpuFlags;
  200123. #endif
  200124. void SystemStats::initialiseStats() throw()
  200125. {
  200126. static bool initialised = false;
  200127. if (! initialised)
  200128. {
  200129. initialised = true;
  200130. #if JUCE_MAC
  200131. // extremely annoying: adding this line stops the apple menu items from working. Of
  200132. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200133. // any events.
  200134. //NSApplicationLoad();
  200135. [NSApplication sharedApplication];
  200136. #endif
  200137. #if JUCE_INTEL
  200138. {
  200139. unsigned int familyModel, extFeatures;
  200140. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200141. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200142. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200143. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200144. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200145. }
  200146. #endif
  200147. mach_timebase_info_data_t timebase;
  200148. (void) mach_timebase_info (&timebase);
  200149. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200150. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200151. String s (SystemStats::getJUCEVersion());
  200152. rlimit lim;
  200153. getrlimit (RLIMIT_NOFILE, &lim);
  200154. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200155. setrlimit (RLIMIT_NOFILE, &lim);
  200156. }
  200157. }
  200158. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200159. {
  200160. return MacOSX;
  200161. }
  200162. const String SystemStats::getOperatingSystemName() throw()
  200163. {
  200164. return T("Mac OS X");
  200165. }
  200166. bool SystemStats::isOperatingSystem64Bit() throw()
  200167. {
  200168. #if JUCE_64BIT
  200169. return true;
  200170. #else
  200171. //xxx not sure how to find this out?..
  200172. return false;
  200173. #endif
  200174. }
  200175. int SystemStats::getMemorySizeInMegabytes() throw()
  200176. {
  200177. uint64 mem = 0;
  200178. size_t memSize = sizeof (mem);
  200179. int mib[] = { CTL_HW, HW_MEMSIZE };
  200180. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200181. return (int) (mem / (1024 * 1024));
  200182. }
  200183. bool SystemStats::hasMMX() throw()
  200184. {
  200185. #if JUCE_INTEL
  200186. return cpuFlags.hasMMX;
  200187. #else
  200188. return false;
  200189. #endif
  200190. }
  200191. bool SystemStats::hasSSE() throw()
  200192. {
  200193. #if JUCE_INTEL
  200194. return cpuFlags.hasSSE;
  200195. #else
  200196. return false;
  200197. #endif
  200198. }
  200199. bool SystemStats::hasSSE2() throw()
  200200. {
  200201. #if JUCE_INTEL
  200202. return cpuFlags.hasSSE2;
  200203. #else
  200204. return false;
  200205. #endif
  200206. }
  200207. bool SystemStats::has3DNow() throw()
  200208. {
  200209. #if JUCE_INTEL
  200210. return cpuFlags.has3DNow;
  200211. #else
  200212. return false;
  200213. #endif
  200214. }
  200215. const String SystemStats::getCpuVendor() throw()
  200216. {
  200217. #if JUCE_INTEL
  200218. char v [16];
  200219. juce_getCpuVendor (v);
  200220. return String (v, 16);
  200221. #else
  200222. return String::empty;
  200223. #endif
  200224. }
  200225. int SystemStats::getCpuSpeedInMegaherz() throw()
  200226. {
  200227. uint64 speedHz = 0;
  200228. size_t speedSize = sizeof (speedHz);
  200229. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200230. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200231. #if JUCE_BIG_ENDIAN
  200232. if (speedSize == 4)
  200233. speedHz >>= 32;
  200234. #endif
  200235. return (int) (speedHz / 1000000);
  200236. }
  200237. int SystemStats::getNumCpus() throw()
  200238. {
  200239. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200240. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200241. #else
  200242. return MPProcessors();
  200243. #endif
  200244. }
  200245. const String SystemStats::getLogonName()
  200246. {
  200247. return nsStringToJuce (NSUserName());
  200248. }
  200249. const String SystemStats::getFullUserName()
  200250. {
  200251. return nsStringToJuce (NSFullUserName());
  200252. }
  200253. uint32 juce_millisecondsSinceStartup() throw()
  200254. {
  200255. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200256. }
  200257. double Time::getMillisecondCounterHiRes() throw()
  200258. {
  200259. return mach_absolute_time() * highResTimerToMillisecRatio;
  200260. }
  200261. int64 Time::getHighResolutionTicks() throw()
  200262. {
  200263. return (int64) mach_absolute_time();
  200264. }
  200265. int64 Time::getHighResolutionTicksPerSecond() throw()
  200266. {
  200267. return highResTimerFrequency;
  200268. }
  200269. int64 SystemStats::getClockCycleCounter() throw()
  200270. {
  200271. return (int64) mach_absolute_time();
  200272. }
  200273. bool Time::setSystemTimeToThisTime() const throw()
  200274. {
  200275. jassertfalse
  200276. return false;
  200277. }
  200278. int SystemStats::getPageSize() throw()
  200279. {
  200280. return (int) NSPageSize();
  200281. }
  200282. void PlatformUtilities::fpuReset()
  200283. {
  200284. }
  200285. #endif
  200286. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200287. /*** Start of inlined file: juce_mac_Network.mm ***/
  200288. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200289. // compiled on its own).
  200290. #if JUCE_INCLUDED_FILE
  200291. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200292. {
  200293. #ifndef IFT_ETHER
  200294. #define IFT_ETHER 6
  200295. #endif
  200296. ifaddrs* addrs = 0;
  200297. int numResults = 0;
  200298. if (getifaddrs (&addrs) == 0)
  200299. {
  200300. const ifaddrs* cursor = addrs;
  200301. while (cursor != 0 && numResults < maxNum)
  200302. {
  200303. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200304. if (sto->ss_family == AF_LINK)
  200305. {
  200306. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200307. if (sadd->sdl_type == IFT_ETHER)
  200308. {
  200309. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200310. uint64 a = 0;
  200311. for (int i = 6; --i >= 0;)
  200312. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200313. *addresses++ = (int64) a;
  200314. ++numResults;
  200315. }
  200316. }
  200317. cursor = cursor->ifa_next;
  200318. }
  200319. freeifaddrs (addrs);
  200320. }
  200321. return numResults;
  200322. }
  200323. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200324. const String& emailSubject,
  200325. const String& bodyText,
  200326. const StringArray& filesToAttach)
  200327. {
  200328. #if JUCE_IPHONE
  200329. //xxx probably need to use MFMailComposeViewController
  200330. jassertfalse
  200331. return false;
  200332. #else
  200333. const ScopedAutoReleasePool pool;
  200334. String script;
  200335. script << "tell application \"Mail\"\r\n"
  200336. "set newMessage to make new outgoing message with properties {subject:\""
  200337. << emailSubject.replace (T("\""), T("\\\""))
  200338. << "\", content:\""
  200339. << bodyText.replace (T("\""), T("\\\""))
  200340. << "\" & return & return}\r\n"
  200341. "tell newMessage\r\n"
  200342. "set visible to true\r\n"
  200343. "set sender to \"sdfsdfsdfewf\"\r\n"
  200344. "make new to recipient at end of to recipients with properties {address:\""
  200345. << targetEmailAddress
  200346. << "\"}\r\n";
  200347. for (int i = 0; i < filesToAttach.size(); ++i)
  200348. {
  200349. script << "tell content\r\n"
  200350. "make new attachment with properties {file name:\""
  200351. << filesToAttach[i].replace (T("\""), T("\\\""))
  200352. << "\"} at after the last paragraph\r\n"
  200353. "end tell\r\n";
  200354. }
  200355. script << "end tell\r\n"
  200356. "end tell\r\n";
  200357. NSAppleScript* s = [[NSAppleScript alloc]
  200358. initWithSource: juceStringToNS (script)];
  200359. NSDictionary* error = 0;
  200360. const bool ok = [s executeAndReturnError: &error] != nil;
  200361. [s release];
  200362. return ok;
  200363. #endif
  200364. }
  200365. END_JUCE_NAMESPACE
  200366. using namespace JUCE_NAMESPACE;
  200367. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200368. @interface JuceURLConnection : NSObject
  200369. {
  200370. @public
  200371. NSURLRequest* request;
  200372. NSURLConnection* connection;
  200373. NSMutableData* data;
  200374. Thread* runLoopThread;
  200375. bool initialised, hasFailed, hasFinished;
  200376. int position;
  200377. int64 contentLength;
  200378. NSLock* dataLock;
  200379. }
  200380. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200381. - (void) dealloc;
  200382. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200383. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200384. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200385. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200386. - (BOOL) isOpen;
  200387. - (int) read: (char*) dest numBytes: (int) num;
  200388. - (int) readPosition;
  200389. - (void) stop;
  200390. - (void) createConnection;
  200391. @end
  200392. class JuceURLConnectionMessageThread : public Thread
  200393. {
  200394. JuceURLConnection* owner;
  200395. public:
  200396. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200397. : Thread (T("http connection")),
  200398. owner (owner_)
  200399. {
  200400. }
  200401. ~JuceURLConnectionMessageThread()
  200402. {
  200403. stopThread (10000);
  200404. }
  200405. void run()
  200406. {
  200407. [owner createConnection];
  200408. while (! threadShouldExit())
  200409. {
  200410. const ScopedAutoReleasePool pool;
  200411. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200412. }
  200413. }
  200414. };
  200415. @implementation JuceURLConnection
  200416. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200417. withCallback: (URL::OpenStreamProgressCallback*) callback
  200418. withContext: (void*) context;
  200419. {
  200420. [super init];
  200421. request = req;
  200422. [request retain];
  200423. data = [[NSMutableData data] retain];
  200424. dataLock = [[NSLock alloc] init];
  200425. connection = 0;
  200426. initialised = false;
  200427. hasFailed = false;
  200428. hasFinished = false;
  200429. contentLength = -1;
  200430. runLoopThread = new JuceURLConnectionMessageThread (self);
  200431. runLoopThread->startThread();
  200432. while (runLoopThread->isThreadRunning() && ! initialised)
  200433. {
  200434. if (callback != 0)
  200435. callback (context, -1, (int) [[request HTTPBody] length]);
  200436. Thread::sleep (1);
  200437. }
  200438. return self;
  200439. }
  200440. - (void) dealloc
  200441. {
  200442. [self stop];
  200443. delete runLoopThread;
  200444. [connection release];
  200445. [data release];
  200446. [dataLock release];
  200447. [request release];
  200448. [super dealloc];
  200449. }
  200450. - (void) createConnection
  200451. {
  200452. connection = [[NSURLConnection alloc] initWithRequest: request
  200453. delegate: [self retain]];
  200454. if (connection == nil)
  200455. runLoopThread->signalThreadShouldExit();
  200456. }
  200457. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200458. {
  200459. [dataLock lock];
  200460. [data setLength: 0];
  200461. [dataLock unlock];
  200462. initialised = true;
  200463. contentLength = [response expectedContentLength];
  200464. }
  200465. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200466. {
  200467. DBG (nsStringToJuce ([error description]));
  200468. hasFailed = true;
  200469. initialised = true;
  200470. runLoopThread->signalThreadShouldExit();
  200471. }
  200472. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200473. {
  200474. [dataLock lock];
  200475. [data appendData: newData];
  200476. [dataLock unlock];
  200477. initialised = true;
  200478. }
  200479. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200480. {
  200481. hasFinished = true;
  200482. initialised = true;
  200483. runLoopThread->signalThreadShouldExit();
  200484. }
  200485. - (BOOL) isOpen
  200486. {
  200487. return connection != 0 && ! hasFailed;
  200488. }
  200489. - (int) readPosition
  200490. {
  200491. return position;
  200492. }
  200493. - (int) read: (char*) dest numBytes: (int) numNeeded
  200494. {
  200495. int numDone = 0;
  200496. while (numNeeded > 0)
  200497. {
  200498. int available = jmin (numNeeded, (int) [data length]);
  200499. if (available > 0)
  200500. {
  200501. [dataLock lock];
  200502. [data getBytes: dest length: available];
  200503. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200504. [dataLock unlock];
  200505. numDone += available;
  200506. numNeeded -= available;
  200507. dest += available;
  200508. }
  200509. else
  200510. {
  200511. if (hasFailed || hasFinished)
  200512. break;
  200513. Thread::sleep (1);
  200514. }
  200515. }
  200516. position += numDone;
  200517. return numDone;
  200518. }
  200519. - (void) stop
  200520. {
  200521. [connection cancel];
  200522. runLoopThread->stopThread (10000);
  200523. }
  200524. @end
  200525. BEGIN_JUCE_NAMESPACE
  200526. bool juce_isOnLine()
  200527. {
  200528. return true;
  200529. }
  200530. void* juce_openInternetFile (const String& url,
  200531. const String& headers,
  200532. const MemoryBlock& postData,
  200533. const bool isPost,
  200534. URL::OpenStreamProgressCallback* callback,
  200535. void* callbackContext,
  200536. int timeOutMs)
  200537. {
  200538. const ScopedAutoReleasePool pool;
  200539. NSMutableURLRequest* req = [NSMutableURLRequest
  200540. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200541. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200542. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200543. if (req == nil)
  200544. return 0;
  200545. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200546. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200547. StringArray headerLines;
  200548. headerLines.addLines (headers);
  200549. headerLines.removeEmptyStrings (true);
  200550. for (int i = 0; i < headerLines.size(); ++i)
  200551. {
  200552. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200553. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200554. if (key.isNotEmpty() && value.isNotEmpty())
  200555. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200556. }
  200557. if (isPost && postData.getSize() > 0)
  200558. {
  200559. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200560. length: postData.getSize()]];
  200561. }
  200562. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200563. withCallback: callback
  200564. withContext: callbackContext];
  200565. if ([s isOpen])
  200566. return s;
  200567. [s release];
  200568. return 0;
  200569. }
  200570. void juce_closeInternetFile (void* handle)
  200571. {
  200572. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200573. if (s != 0)
  200574. {
  200575. const ScopedAutoReleasePool pool;
  200576. [s stop];
  200577. [s release];
  200578. }
  200579. }
  200580. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200581. {
  200582. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200583. if (s != 0)
  200584. {
  200585. const ScopedAutoReleasePool pool;
  200586. return [s read: (char*) buffer numBytes: bytesToRead];
  200587. }
  200588. return 0;
  200589. }
  200590. int64 juce_getInternetFileContentLength (void* handle)
  200591. {
  200592. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200593. if (s != 0)
  200594. return s->contentLength;
  200595. return -1;
  200596. }
  200597. int juce_seekInInternetFile (void* handle, int newPosition)
  200598. {
  200599. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200600. if (s != 0)
  200601. return [s readPosition];
  200602. return 0;
  200603. }
  200604. #endif
  200605. /*** End of inlined file: juce_mac_Network.mm ***/
  200606. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200607. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200608. // compiled on its own).
  200609. #if JUCE_INCLUDED_FILE
  200610. struct NamedPipeInternal
  200611. {
  200612. String pipeInName, pipeOutName;
  200613. int pipeIn, pipeOut;
  200614. bool volatile createdPipe, blocked, stopReadOperation;
  200615. static void signalHandler (int) {}
  200616. };
  200617. void NamedPipe::cancelPendingReads()
  200618. {
  200619. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200620. {
  200621. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200622. intern->stopReadOperation = true;
  200623. char buffer [1] = { 0 };
  200624. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200625. (void) bytesWritten;
  200626. int timeout = 2000;
  200627. while (intern->blocked && --timeout >= 0)
  200628. Thread::sleep (2);
  200629. intern->stopReadOperation = false;
  200630. }
  200631. }
  200632. void NamedPipe::close()
  200633. {
  200634. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200635. if (intern != 0)
  200636. {
  200637. internal = 0;
  200638. if (intern->pipeIn != -1)
  200639. ::close (intern->pipeIn);
  200640. if (intern->pipeOut != -1)
  200641. ::close (intern->pipeOut);
  200642. if (intern->createdPipe)
  200643. {
  200644. unlink (intern->pipeInName);
  200645. unlink (intern->pipeOutName);
  200646. }
  200647. delete intern;
  200648. }
  200649. }
  200650. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200651. {
  200652. close();
  200653. NamedPipeInternal* const intern = new NamedPipeInternal();
  200654. internal = intern;
  200655. intern->createdPipe = createPipe;
  200656. intern->blocked = false;
  200657. intern->stopReadOperation = false;
  200658. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200659. siginterrupt (SIGPIPE, 1);
  200660. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200661. intern->pipeInName = pipePath + T("_in");
  200662. intern->pipeOutName = pipePath + T("_out");
  200663. intern->pipeIn = -1;
  200664. intern->pipeOut = -1;
  200665. if (createPipe)
  200666. {
  200667. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  200668. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  200669. {
  200670. delete intern;
  200671. internal = 0;
  200672. return false;
  200673. }
  200674. }
  200675. return true;
  200676. }
  200677. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200678. {
  200679. int bytesRead = -1;
  200680. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200681. if (intern != 0)
  200682. {
  200683. intern->blocked = true;
  200684. if (intern->pipeIn == -1)
  200685. {
  200686. if (intern->createdPipe)
  200687. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  200688. else
  200689. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  200690. if (intern->pipeIn == -1)
  200691. {
  200692. intern->blocked = false;
  200693. return -1;
  200694. }
  200695. }
  200696. bytesRead = 0;
  200697. char* p = (char*) destBuffer;
  200698. while (bytesRead < maxBytesToRead)
  200699. {
  200700. const int bytesThisTime = maxBytesToRead - bytesRead;
  200701. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200702. if (numRead <= 0 || intern->stopReadOperation)
  200703. {
  200704. bytesRead = -1;
  200705. break;
  200706. }
  200707. bytesRead += numRead;
  200708. p += bytesRead;
  200709. }
  200710. intern->blocked = false;
  200711. }
  200712. return bytesRead;
  200713. }
  200714. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200715. {
  200716. int bytesWritten = -1;
  200717. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200718. if (intern != 0)
  200719. {
  200720. if (intern->pipeOut == -1)
  200721. {
  200722. if (intern->createdPipe)
  200723. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  200724. else
  200725. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  200726. if (intern->pipeOut == -1)
  200727. {
  200728. return -1;
  200729. }
  200730. }
  200731. const char* p = (const char*) sourceBuffer;
  200732. bytesWritten = 0;
  200733. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200734. while (bytesWritten < numBytesToWrite
  200735. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200736. {
  200737. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200738. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200739. if (numWritten <= 0)
  200740. {
  200741. bytesWritten = -1;
  200742. break;
  200743. }
  200744. bytesWritten += numWritten;
  200745. p += bytesWritten;
  200746. }
  200747. }
  200748. return bytesWritten;
  200749. }
  200750. #endif
  200751. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200752. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200753. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200754. // compiled on its own).
  200755. #if JUCE_INCLUDED_FILE
  200756. void JUCE_API juce_threadEntryPoint (void*);
  200757. void* threadEntryProc (void* userData)
  200758. {
  200759. const ScopedAutoReleasePool pool;
  200760. juce_threadEntryPoint (userData);
  200761. return 0;
  200762. }
  200763. void* juce_createThread (void* userData)
  200764. {
  200765. pthread_t handle = 0;
  200766. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200767. {
  200768. pthread_detach (handle);
  200769. return (void*) handle;
  200770. }
  200771. return 0;
  200772. }
  200773. void juce_killThread (void* handle)
  200774. {
  200775. if (handle != 0)
  200776. pthread_cancel ((pthread_t) handle);
  200777. }
  200778. void juce_setCurrentThreadName (const String& /*name*/)
  200779. {
  200780. }
  200781. Thread::ThreadID Thread::getCurrentThreadId()
  200782. {
  200783. return (ThreadID) pthread_self();
  200784. }
  200785. bool juce_setThreadPriority (void* handle, int priority)
  200786. {
  200787. if (handle == 0)
  200788. handle = (void*) pthread_self();
  200789. struct sched_param param;
  200790. int policy;
  200791. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200792. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200793. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200794. }
  200795. void Thread::yield()
  200796. {
  200797. sched_yield();
  200798. }
  200799. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200800. {
  200801. // xxx
  200802. jassertfalse
  200803. }
  200804. bool Process::isForegroundProcess()
  200805. {
  200806. #if JUCE_MAC
  200807. return [NSApp isActive];
  200808. #else
  200809. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200810. #endif
  200811. }
  200812. void Process::raisePrivilege()
  200813. {
  200814. jassertfalse
  200815. }
  200816. void Process::lowerPrivilege()
  200817. {
  200818. jassertfalse
  200819. }
  200820. void Process::terminate()
  200821. {
  200822. exit (0);
  200823. }
  200824. void Process::setPriority (ProcessPriority p)
  200825. {
  200826. // xxx
  200827. }
  200828. #endif
  200829. /*** End of inlined file: juce_mac_Threads.mm ***/
  200830. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200831. CriticalSection::CriticalSection() throw()
  200832. {
  200833. pthread_mutexattr_t atts;
  200834. pthread_mutexattr_init (&atts);
  200835. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200836. pthread_mutex_init (&internal, &atts);
  200837. }
  200838. CriticalSection::~CriticalSection() throw()
  200839. {
  200840. pthread_mutex_destroy (&internal);
  200841. }
  200842. void CriticalSection::enter() const throw()
  200843. {
  200844. pthread_mutex_lock (&internal);
  200845. }
  200846. bool CriticalSection::tryEnter() const throw()
  200847. {
  200848. return pthread_mutex_trylock (&internal) == 0;
  200849. }
  200850. void CriticalSection::exit() const throw()
  200851. {
  200852. pthread_mutex_unlock (&internal);
  200853. }
  200854. struct EventStruct
  200855. {
  200856. pthread_cond_t condition;
  200857. pthread_mutex_t mutex;
  200858. bool triggered;
  200859. };
  200860. WaitableEvent::WaitableEvent() throw()
  200861. {
  200862. EventStruct* const es = new EventStruct();
  200863. es->triggered = false;
  200864. pthread_cond_init (&es->condition, 0);
  200865. pthread_mutex_init (&es->mutex, 0);
  200866. internal = es;
  200867. }
  200868. WaitableEvent::~WaitableEvent() throw()
  200869. {
  200870. EventStruct* const es = (EventStruct*) internal;
  200871. pthread_cond_destroy (&es->condition);
  200872. pthread_mutex_destroy (&es->mutex);
  200873. delete es;
  200874. }
  200875. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200876. {
  200877. EventStruct* const es = (EventStruct*) internal;
  200878. pthread_mutex_lock (&es->mutex);
  200879. if (timeOutMillisecs < 0)
  200880. {
  200881. while (! es->triggered)
  200882. pthread_cond_wait (&es->condition, &es->mutex);
  200883. }
  200884. else
  200885. {
  200886. while (! es->triggered)
  200887. {
  200888. struct timeval t;
  200889. gettimeofday (&t, 0);
  200890. struct timespec time;
  200891. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200892. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200893. if (time.tv_nsec >= 1000000000)
  200894. {
  200895. time.tv_nsec -= 1000000000;
  200896. time.tv_sec++;
  200897. }
  200898. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200899. {
  200900. pthread_mutex_unlock (&es->mutex);
  200901. return false;
  200902. }
  200903. }
  200904. }
  200905. es->triggered = false;
  200906. pthread_mutex_unlock (&es->mutex);
  200907. return true;
  200908. }
  200909. void WaitableEvent::signal() const throw()
  200910. {
  200911. EventStruct* const es = (EventStruct*) internal;
  200912. pthread_mutex_lock (&es->mutex);
  200913. es->triggered = true;
  200914. pthread_cond_broadcast (&es->condition);
  200915. pthread_mutex_unlock (&es->mutex);
  200916. }
  200917. void WaitableEvent::reset() const throw()
  200918. {
  200919. EventStruct* const es = (EventStruct*) internal;
  200920. pthread_mutex_lock (&es->mutex);
  200921. es->triggered = false;
  200922. pthread_mutex_unlock (&es->mutex);
  200923. }
  200924. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200925. {
  200926. struct timespec time;
  200927. time.tv_sec = millisecs / 1000;
  200928. time.tv_nsec = (millisecs % 1000) * 1000000;
  200929. nanosleep (&time, 0);
  200930. }
  200931. const tchar File::separator = T('/');
  200932. const tchar* File::separatorString = T("/");
  200933. bool juce_copyFile (const String& s, const String& d);
  200934. static bool juce_stat (const String& fileName, struct stat& info)
  200935. {
  200936. return fileName.isNotEmpty()
  200937. && (stat (fileName.toUTF8(), &info) == 0);
  200938. }
  200939. bool juce_isDirectory (const String& fileName)
  200940. {
  200941. struct stat info;
  200942. return fileName.isEmpty()
  200943. || (juce_stat (fileName, info)
  200944. && ((info.st_mode & S_IFDIR) != 0));
  200945. }
  200946. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200947. {
  200948. if (fileName.isEmpty())
  200949. return false;
  200950. const char* const fileNameUTF8 = fileName.toUTF8();
  200951. bool exists = access (fileNameUTF8, F_OK) == 0;
  200952. if (exists && dontCountDirectories)
  200953. {
  200954. struct stat info;
  200955. const int res = stat (fileNameUTF8, &info);
  200956. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200957. exists = false;
  200958. }
  200959. return exists;
  200960. }
  200961. int64 juce_getFileSize (const String& fileName)
  200962. {
  200963. struct stat info;
  200964. return juce_stat (fileName, info) ? info.st_size : 0;
  200965. }
  200966. bool juce_canWriteToFile (const String& fileName)
  200967. {
  200968. return access (fileName.toUTF8(), W_OK) == 0;
  200969. }
  200970. bool juce_deleteFile (const String& fileName)
  200971. {
  200972. if (juce_isDirectory (fileName))
  200973. return rmdir ((const char*) fileName.toUTF8()) == 0;
  200974. else
  200975. return remove ((const char*) fileName.toUTF8()) == 0;
  200976. }
  200977. bool juce_moveFile (const String& source, const String& dest)
  200978. {
  200979. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200980. return true;
  200981. if (juce_canWriteToFile (source)
  200982. && juce_copyFile (source, dest))
  200983. {
  200984. if (juce_deleteFile (source))
  200985. return true;
  200986. juce_deleteFile (dest);
  200987. }
  200988. return false;
  200989. }
  200990. void juce_createDirectory (const String& fileName)
  200991. {
  200992. mkdir (fileName.toUTF8(), 0777);
  200993. }
  200994. void* juce_fileOpen (const String& fileName, bool forWriting)
  200995. {
  200996. int flags = O_RDONLY;
  200997. if (forWriting)
  200998. {
  200999. if (juce_fileExists (fileName, false))
  201000. {
  201001. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  201002. if (f != -1)
  201003. lseek (f, 0, SEEK_END);
  201004. return (void*) f;
  201005. }
  201006. else
  201007. {
  201008. flags = O_RDWR + O_CREAT;
  201009. }
  201010. }
  201011. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  201012. }
  201013. void juce_fileClose (void* handle)
  201014. {
  201015. if (handle != 0)
  201016. close ((int) (pointer_sized_int) handle);
  201017. }
  201018. int juce_fileRead (void* handle, void* buffer, int size)
  201019. {
  201020. if (handle != 0)
  201021. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  201022. return 0;
  201023. }
  201024. int juce_fileWrite (void* handle, const void* buffer, int size)
  201025. {
  201026. if (handle != 0)
  201027. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  201028. return 0;
  201029. }
  201030. int64 juce_fileSetPosition (void* handle, int64 pos)
  201031. {
  201032. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  201033. return pos;
  201034. return -1;
  201035. }
  201036. int64 juce_fileGetPosition (void* handle)
  201037. {
  201038. if (handle != 0)
  201039. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  201040. else
  201041. return -1;
  201042. }
  201043. void juce_fileFlush (void* handle)
  201044. {
  201045. if (handle != 0)
  201046. fsync ((int) (pointer_sized_int) handle);
  201047. }
  201048. const File juce_getExecutableFile()
  201049. {
  201050. Dl_info exeInfo;
  201051. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  201052. return File (exeInfo.dli_fname);
  201053. }
  201054. // if this file doesn't exist, find a parent of it that does..
  201055. static bool doStatFS (const File* file, struct statfs& result)
  201056. {
  201057. File f (*file);
  201058. for (int i = 5; --i >= 0;)
  201059. {
  201060. if (f.exists())
  201061. break;
  201062. f = f.getParentDirectory();
  201063. }
  201064. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  201065. }
  201066. int64 File::getBytesFreeOnVolume() const
  201067. {
  201068. struct statfs buf;
  201069. if (doStatFS (this, buf))
  201070. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  201071. return 0;
  201072. }
  201073. int64 File::getVolumeTotalSize() const
  201074. {
  201075. struct statfs buf;
  201076. if (doStatFS (this, buf))
  201077. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  201078. return 0;
  201079. }
  201080. const String juce_getVolumeLabel (const String& filenameOnVolume,
  201081. int& volumeSerialNumber)
  201082. {
  201083. volumeSerialNumber = 0;
  201084. #if JUCE_MAC
  201085. struct VolAttrBuf
  201086. {
  201087. u_int32_t length;
  201088. attrreference_t mountPointRef;
  201089. char mountPointSpace [MAXPATHLEN];
  201090. } attrBuf;
  201091. struct attrlist attrList;
  201092. zerostruct (attrList);
  201093. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  201094. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  201095. File f (filenameOnVolume);
  201096. for (;;)
  201097. {
  201098. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  201099. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  201100. {
  201101. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  201102. (int) attrBuf.mountPointRef.attr_length);
  201103. }
  201104. const File parent (f.getParentDirectory());
  201105. if (f == parent)
  201106. break;
  201107. f = parent;
  201108. }
  201109. #endif
  201110. return String::empty;
  201111. }
  201112. void juce_runSystemCommand (const String& command)
  201113. {
  201114. int result = system ((const char*) command.toUTF8());
  201115. (void) result;
  201116. }
  201117. const String juce_getOutputFromCommand (const String& command)
  201118. {
  201119. // slight bodge here, as we just pipe the output into a temp file and read it...
  201120. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201121. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201122. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201123. String result (tempFile.loadFileAsString());
  201124. tempFile.deleteFile();
  201125. return result;
  201126. }
  201127. InterProcessLock::InterProcessLock (const String& name_)
  201128. : internal (0),
  201129. name (name_),
  201130. reentrancyLevel (0)
  201131. {
  201132. #if JUCE_MAC
  201133. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201134. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201135. #else
  201136. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201137. #endif
  201138. temp.create();
  201139. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201140. }
  201141. InterProcessLock::~InterProcessLock()
  201142. {
  201143. while (reentrancyLevel > 0)
  201144. this->exit();
  201145. close (internal);
  201146. }
  201147. bool InterProcessLock::enter (const int timeOutMillisecs)
  201148. {
  201149. if (internal == 0)
  201150. return false;
  201151. if (reentrancyLevel != 0)
  201152. return true;
  201153. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201154. struct flock fl;
  201155. zerostruct (fl);
  201156. fl.l_whence = SEEK_SET;
  201157. fl.l_type = F_WRLCK;
  201158. for (;;)
  201159. {
  201160. const int result = fcntl (internal, F_SETLK, &fl);
  201161. if (result >= 0)
  201162. {
  201163. ++reentrancyLevel;
  201164. return true;
  201165. }
  201166. if (errno != EINTR)
  201167. {
  201168. if (timeOutMillisecs == 0
  201169. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201170. break;
  201171. Thread::sleep (10);
  201172. }
  201173. }
  201174. return false;
  201175. }
  201176. void InterProcessLock::exit()
  201177. {
  201178. if (reentrancyLevel > 0 && internal != 0)
  201179. {
  201180. --reentrancyLevel;
  201181. struct flock fl;
  201182. zerostruct (fl);
  201183. fl.l_whence = SEEK_SET;
  201184. fl.l_type = F_UNLCK;
  201185. for (;;)
  201186. {
  201187. const int result = fcntl (internal, F_SETLKW, &fl);
  201188. if (result >= 0 || errno != EINTR)
  201189. break;
  201190. }
  201191. }
  201192. }
  201193. /*** End of inlined file: juce_posix_SharedCode.h ***/
  201194. /*** Start of inlined file: juce_mac_Files.mm ***/
  201195. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201196. // compiled on its own).
  201197. #if JUCE_INCLUDED_FILE
  201198. void juce_getFileTimes (const String& fileName,
  201199. int64& modificationTime,
  201200. int64& accessTime,
  201201. int64& creationTime)
  201202. {
  201203. modificationTime = 0;
  201204. accessTime = 0;
  201205. creationTime = 0;
  201206. struct stat info;
  201207. const int res = stat (fileName.toUTF8(), &info);
  201208. if (res == 0)
  201209. {
  201210. modificationTime = (int64) info.st_mtime * 1000;
  201211. accessTime = (int64) info.st_atime * 1000;
  201212. creationTime = (int64) info.st_ctime * 1000;
  201213. }
  201214. }
  201215. bool juce_setFileTimes (const String& fileName,
  201216. int64 modificationTime,
  201217. int64 accessTime,
  201218. int64 creationTime)
  201219. {
  201220. struct utimbuf times;
  201221. times.actime = (time_t) (accessTime / 1000);
  201222. times.modtime = (time_t) (modificationTime / 1000);
  201223. return utime (fileName.toUTF8(), &times) == 0;
  201224. }
  201225. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201226. {
  201227. struct stat info;
  201228. const int res = stat (fileName.toUTF8(), &info);
  201229. if (res != 0)
  201230. return false;
  201231. info.st_mode &= 0777; // Just permissions
  201232. if (isReadOnly)
  201233. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201234. else
  201235. // Give everybody write permission?
  201236. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201237. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201238. }
  201239. bool juce_copyFile (const String& src, const String& dst)
  201240. {
  201241. const ScopedAutoReleasePool pool;
  201242. NSFileManager* fm = [NSFileManager defaultManager];
  201243. return [fm fileExistsAtPath: juceStringToNS (src)]
  201244. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201245. && [fm copyItemAtPath: juceStringToNS (src)
  201246. toPath: juceStringToNS (dst)
  201247. error: nil];
  201248. #else
  201249. && [fm copyPath: juceStringToNS (src)
  201250. toPath: juceStringToNS (dst)
  201251. handler: nil];
  201252. #endif
  201253. }
  201254. const StringArray juce_getFileSystemRoots()
  201255. {
  201256. StringArray s;
  201257. s.add (T("/"));
  201258. return s;
  201259. }
  201260. static bool isFileOnDriveType (const File* const f, const char** types)
  201261. {
  201262. struct statfs buf;
  201263. if (doStatFS (f, buf))
  201264. {
  201265. const String type (buf.f_fstypename);
  201266. while (*types != 0)
  201267. if (type.equalsIgnoreCase (*types++))
  201268. return true;
  201269. }
  201270. return false;
  201271. }
  201272. bool File::isOnCDRomDrive() const
  201273. {
  201274. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201275. return isFileOnDriveType (this, (const char**) cdTypes);
  201276. }
  201277. bool File::isOnHardDisk() const
  201278. {
  201279. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201280. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201281. }
  201282. bool File::isOnRemovableDrive() const
  201283. {
  201284. #if JUCE_IPHONE
  201285. return false; // xxx is this possible?
  201286. #else
  201287. const ScopedAutoReleasePool pool;
  201288. BOOL removable = false;
  201289. [[NSWorkspace sharedWorkspace]
  201290. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201291. isRemovable: &removable
  201292. isWritable: nil
  201293. isUnmountable: nil
  201294. description: nil
  201295. type: nil];
  201296. return removable;
  201297. #endif
  201298. }
  201299. static bool juce_isHiddenFile (const String& path)
  201300. {
  201301. #if JUCE_IPHONE
  201302. return File (path).getFileName().startsWithChar (T('.'));
  201303. #else
  201304. FSRef ref;
  201305. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201306. return false;
  201307. FSCatalogInfo info;
  201308. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201309. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201310. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201311. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201312. #endif
  201313. }
  201314. bool File::isHidden() const
  201315. {
  201316. return juce_isHiddenFile (getFullPathName());
  201317. }
  201318. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201319. const File File::getSpecialLocation (const SpecialLocationType type)
  201320. {
  201321. const ScopedAutoReleasePool pool;
  201322. String resultPath;
  201323. switch (type)
  201324. {
  201325. case userHomeDirectory:
  201326. resultPath = nsStringToJuce (NSHomeDirectory());
  201327. break;
  201328. case userDocumentsDirectory:
  201329. resultPath = "~/Documents";
  201330. break;
  201331. case userDesktopDirectory:
  201332. resultPath = "~/Desktop";
  201333. break;
  201334. case userApplicationDataDirectory:
  201335. resultPath = "~/Library";
  201336. break;
  201337. case commonApplicationDataDirectory:
  201338. resultPath = "/Library";
  201339. break;
  201340. case globalApplicationsDirectory:
  201341. resultPath = "/Applications";
  201342. break;
  201343. case userMusicDirectory:
  201344. resultPath = "~/Music";
  201345. break;
  201346. case userMoviesDirectory:
  201347. resultPath = "~/Movies";
  201348. break;
  201349. case tempDirectory:
  201350. {
  201351. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201352. tmp.createDirectory();
  201353. return tmp.getFullPathName();
  201354. }
  201355. case invokedExecutableFile:
  201356. if (juce_Argv0 != 0)
  201357. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  201358. // deliberate fall-through...
  201359. case currentExecutableFile:
  201360. return juce_getExecutableFile();
  201361. case currentApplicationFile:
  201362. {
  201363. const File exe (juce_getExecutableFile());
  201364. const File parent (exe.getParentDirectory());
  201365. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201366. ? parent.getParentDirectory().getParentDirectory()
  201367. : exe;
  201368. }
  201369. default:
  201370. jassertfalse // unknown type?
  201371. break;
  201372. }
  201373. if (resultPath != 0)
  201374. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201375. return File::nonexistent;
  201376. }
  201377. const File File::getCurrentWorkingDirectory()
  201378. {
  201379. char buf [2048];
  201380. getcwd (buf, sizeof(buf));
  201381. return File (PlatformUtilities::convertToPrecomposedUnicode (buf));
  201382. }
  201383. bool File::setAsCurrentWorkingDirectory() const
  201384. {
  201385. return chdir (getFullPathName().toUTF8()) == 0;
  201386. }
  201387. const String File::getVersion() const
  201388. {
  201389. const ScopedAutoReleasePool pool;
  201390. String result;
  201391. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201392. if (bundle != 0)
  201393. {
  201394. NSDictionary* info = [bundle infoDictionary];
  201395. if (info != 0)
  201396. {
  201397. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201398. if (name != nil)
  201399. result = nsStringToJuce (name);
  201400. }
  201401. }
  201402. return result;
  201403. }
  201404. const File File::getLinkedTarget() const
  201405. {
  201406. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201407. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201408. #else
  201409. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201410. #endif
  201411. if (dest != nil)
  201412. return File (nsStringToJuce (dest));
  201413. return *this;
  201414. }
  201415. bool File::moveToTrash() const
  201416. {
  201417. if (! exists())
  201418. return true;
  201419. #if JUCE_IPHONE
  201420. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201421. #else
  201422. const ScopedAutoReleasePool pool;
  201423. NSString* p = juceStringToNS (getFullPathName());
  201424. return [[NSWorkspace sharedWorkspace]
  201425. performFileOperation: NSWorkspaceRecycleOperation
  201426. source: [p stringByDeletingLastPathComponent]
  201427. destination: @""
  201428. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201429. tag: nil ];
  201430. #endif
  201431. }
  201432. struct FindFileStruct
  201433. {
  201434. NSDirectoryEnumerator* enumerator;
  201435. String parentDir, wildCard;
  201436. };
  201437. bool juce_findFileNext (void* handle, String& resultFile,
  201438. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201439. {
  201440. ScopedAutoReleasePool pool;
  201441. FindFileStruct* ff = (FindFileStruct*) handle;
  201442. NSString* file;
  201443. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201444. for (;;)
  201445. {
  201446. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201447. return false;
  201448. [ff->enumerator skipDescendents];
  201449. resultFile = nsStringToJuce (file);
  201450. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201451. continue;
  201452. const String path (ff->parentDir + resultFile);
  201453. if (isDir != 0 || fileSize != 0)
  201454. {
  201455. struct stat info;
  201456. const bool statOk = juce_stat (path, info);
  201457. if (isDir != 0)
  201458. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201459. if (isHidden != 0)
  201460. *isHidden = juce_isHiddenFile (path);
  201461. if (fileSize != 0)
  201462. *fileSize = statOk ? info.st_size : 0;
  201463. }
  201464. if (modTime != 0 || creationTime != 0)
  201465. {
  201466. int64 m, a, c;
  201467. juce_getFileTimes (path, m, a, c);
  201468. if (modTime != 0)
  201469. *modTime = m;
  201470. if (creationTime != 0)
  201471. *creationTime = c;
  201472. }
  201473. if (isReadOnly != 0)
  201474. *isReadOnly = ! juce_canWriteToFile (path);
  201475. return true;
  201476. }
  201477. }
  201478. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201479. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201480. Time* creationTime, bool* isReadOnly)
  201481. {
  201482. ScopedAutoReleasePool pool;
  201483. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201484. if (e != 0)
  201485. {
  201486. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201487. ff->enumerator = [e retain];
  201488. ff->parentDir = directory;
  201489. ff->wildCard = wildCard;
  201490. if (! ff->parentDir.endsWithChar (File::separator))
  201491. ff->parentDir += File::separator;
  201492. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201493. return ff.release();
  201494. [e release];
  201495. }
  201496. return 0;
  201497. }
  201498. void juce_findFileClose (void* handle)
  201499. {
  201500. ScopedAutoReleasePool pool;
  201501. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201502. [ff->enumerator release];
  201503. }
  201504. bool juce_launchExecutable (const String& pathAndArguments)
  201505. {
  201506. const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 };
  201507. const int cpid = fork();
  201508. if (cpid == 0)
  201509. {
  201510. // Child process
  201511. if (execve (argv[0], (char**) argv, 0) < 0)
  201512. exit (0);
  201513. }
  201514. else
  201515. {
  201516. if (cpid < 0)
  201517. return false;
  201518. }
  201519. return true;
  201520. }
  201521. bool juce_launchFile (const String& fileName, const String& parameters)
  201522. {
  201523. #if JUCE_IPHONE
  201524. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201525. #else
  201526. const ScopedAutoReleasePool pool;
  201527. if (parameters.isEmpty())
  201528. {
  201529. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201530. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201531. }
  201532. bool ok = false;
  201533. FSRef ref;
  201534. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201535. {
  201536. if (PlatformUtilities::isBundle (fileName))
  201537. {
  201538. NSMutableArray* urls = [NSMutableArray array];
  201539. StringArray docs;
  201540. docs.addTokens (parameters, true);
  201541. for (int i = 0; i < docs.size(); ++i)
  201542. [urls addObject: juceStringToNS (docs[i])];
  201543. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201544. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201545. options: 0
  201546. additionalEventParamDescriptor: nil
  201547. launchIdentifiers: nil];
  201548. }
  201549. else
  201550. {
  201551. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201552. }
  201553. }
  201554. return ok;
  201555. #endif
  201556. }
  201557. void File::revealToUser() const
  201558. {
  201559. #if ! JUCE_IPHONE
  201560. if (exists())
  201561. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201562. else if (getParentDirectory().exists())
  201563. getParentDirectory().revealToUser();
  201564. #endif
  201565. }
  201566. #if ! JUCE_IPHONE
  201567. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201568. {
  201569. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201570. }
  201571. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201572. {
  201573. uint8 path [2048];
  201574. zeromem (path, sizeof (path));
  201575. String result;
  201576. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201577. result = String::fromUTF8 (path);
  201578. return PlatformUtilities::convertToPrecomposedUnicode (result);
  201579. }
  201580. #endif
  201581. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201582. {
  201583. const ScopedAutoReleasePool pool;
  201584. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201585. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201586. #else
  201587. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201588. #endif
  201589. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201590. return [fileDict fileHFSTypeCode];
  201591. }
  201592. bool PlatformUtilities::isBundle (const String& filename)
  201593. {
  201594. #if JUCE_IPHONE
  201595. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201596. #else
  201597. const ScopedAutoReleasePool pool;
  201598. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201599. #endif
  201600. }
  201601. #endif
  201602. /*** End of inlined file: juce_mac_Files.mm ***/
  201603. #if JUCE_IPHONE
  201604. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201605. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201606. // compiled on its own).
  201607. #if JUCE_INCLUDED_FILE
  201608. static JUCEApplication* juce_intialisingApp;
  201609. END_JUCE_NAMESPACE
  201610. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201611. {
  201612. }
  201613. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201614. - (void) applicationWillResignActive: (UIApplication*) application;
  201615. @end
  201616. @implementation JuceAppStartupDelegate
  201617. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201618. {
  201619. String dummy;
  201620. if (! juce_intialisingApp->initialiseApp (dummy))
  201621. exit (0);
  201622. }
  201623. - (void) applicationWillResignActive: (UIApplication*) application
  201624. {
  201625. JUCEApplication::shutdownAppAndClearUp();
  201626. }
  201627. @end
  201628. BEGIN_JUCE_NAMESPACE
  201629. int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app)
  201630. {
  201631. juce_intialisingApp = app;
  201632. return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate");
  201633. }
  201634. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201635. {
  201636. pool = [[NSAutoreleasePool alloc] init];
  201637. }
  201638. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201639. {
  201640. [((NSAutoreleasePool*) pool) release];
  201641. }
  201642. void PlatformUtilities::beep()
  201643. {
  201644. //xxx
  201645. //AudioServicesPlaySystemSound ();
  201646. }
  201647. void PlatformUtilities::addItemToDock (const File& file)
  201648. {
  201649. }
  201650. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201651. END_JUCE_NAMESPACE
  201652. @interface JuceAlertBoxDelegate : NSObject
  201653. {
  201654. @public
  201655. bool clickedOk;
  201656. }
  201657. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201658. @end
  201659. @implementation JuceAlertBoxDelegate
  201660. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201661. {
  201662. clickedOk = (buttonIndex == 0);
  201663. alertView.hidden = true;
  201664. }
  201665. @end
  201666. BEGIN_JUCE_NAMESPACE
  201667. // (This function is used directly by other bits of code)
  201668. bool juce_iPhoneShowModalAlert (const String& title,
  201669. const String& bodyText,
  201670. NSString* okButtonText,
  201671. NSString* cancelButtonText)
  201672. {
  201673. const ScopedAutoReleasePool pool;
  201674. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201675. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201676. message: juceStringToNS (bodyText)
  201677. delegate: callback
  201678. cancelButtonTitle: okButtonText
  201679. otherButtonTitles: cancelButtonText, nil];
  201680. [alert retain];
  201681. [alert show];
  201682. while (! alert.hidden && alert.superview != nil)
  201683. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201684. const bool result = callback->clickedOk;
  201685. [alert release];
  201686. [callback release];
  201687. return result;
  201688. }
  201689. bool AlertWindow::showNativeDialogBox (const String& title,
  201690. const String& bodyText,
  201691. bool isOkCancel)
  201692. {
  201693. return juce_iPhoneShowModalAlert (title, bodyText,
  201694. @"OK",
  201695. isOkCancel ? @"Cancel" : nil);
  201696. }
  201697. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201698. {
  201699. jassertfalse // no such thing on the iphone!
  201700. return false;
  201701. }
  201702. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201703. {
  201704. jassertfalse // no such thing on the iphone!
  201705. return false;
  201706. }
  201707. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201708. {
  201709. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201710. }
  201711. bool Desktop::isScreenSaverEnabled() throw()
  201712. {
  201713. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201714. }
  201715. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201716. {
  201717. const ScopedAutoReleasePool pool;
  201718. monitorCoords.clear();
  201719. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201720. : [[UIScreen mainScreen] bounds];
  201721. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201722. (int) r.origin.y,
  201723. (int) r.size.width,
  201724. (int) r.size.height));
  201725. }
  201726. #endif
  201727. #endif
  201728. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201729. #else
  201730. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201731. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201732. // compiled on its own).
  201733. #if JUCE_INCLUDED_FILE
  201734. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201735. {
  201736. pool = [[NSAutoreleasePool alloc] init];
  201737. }
  201738. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201739. {
  201740. [((NSAutoreleasePool*) pool) release];
  201741. }
  201742. void PlatformUtilities::beep()
  201743. {
  201744. NSBeep();
  201745. }
  201746. void PlatformUtilities::addItemToDock (const File& file)
  201747. {
  201748. // check that it's not already there...
  201749. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201750. .containsIgnoreCase (file.getFullPathName()))
  201751. {
  201752. 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>"
  201753. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201754. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201755. }
  201756. }
  201757. int PlatformUtilities::getOSXMinorVersionNumber()
  201758. {
  201759. SInt32 versionMinor = 0;
  201760. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201761. (void) err;
  201762. jassert (err == noErr);
  201763. return (int) versionMinor;
  201764. }
  201765. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201766. bool AlertWindow::showNativeDialogBox (const String& title,
  201767. const String& bodyText,
  201768. bool isOkCancel)
  201769. {
  201770. const ScopedAutoReleasePool pool;
  201771. return NSRunAlertPanel (juceStringToNS (title),
  201772. juceStringToNS (bodyText),
  201773. @"Ok",
  201774. isOkCancel ? @"Cancel" : nil,
  201775. nil) == NSAlertDefaultReturn;
  201776. }
  201777. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201778. {
  201779. if (files.size() == 0)
  201780. return false;
  201781. Component* sourceComp = Component::getComponentUnderMouse();
  201782. if (sourceComp == 0)
  201783. {
  201784. jassertfalse // this method must be called in response to a
  201785. // component's mouseDrag event!
  201786. return false;
  201787. }
  201788. const ScopedAutoReleasePool pool;
  201789. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201790. if (view == 0)
  201791. return false;
  201792. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201793. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201794. owner: nil];
  201795. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201796. for (int i = 0; i < files.size(); ++i)
  201797. [filesArray addObject: juceStringToNS (files[i])];
  201798. [pboard setPropertyList: filesArray
  201799. forType: NSFilenamesPboardType];
  201800. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201801. fromView: nil];
  201802. dragPosition.x -= 16;
  201803. dragPosition.y -= 16;
  201804. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201805. at: dragPosition
  201806. offset: NSMakeSize (0, 0)
  201807. event: [[view window] currentEvent]
  201808. pasteboard: pboard
  201809. source: view
  201810. slideBack: YES];
  201811. return true;
  201812. }
  201813. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201814. {
  201815. jassertfalse // not implemented!
  201816. return false;
  201817. }
  201818. bool Desktop::canUseSemiTransparentWindows() throw()
  201819. {
  201820. return true;
  201821. }
  201822. void Desktop::getMousePosition (int& x, int& y) throw()
  201823. {
  201824. const ScopedAutoReleasePool pool;
  201825. const NSPoint p ([NSEvent mouseLocation]);
  201826. x = roundToInt (p.x);
  201827. y = roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y);
  201828. }
  201829. void Desktop::setMousePosition (int x, int y) throw()
  201830. {
  201831. // this rubbish needs to be done around the warp call, to avoid causing a
  201832. // bizarre glitch..
  201833. CGAssociateMouseAndMouseCursorPosition (false);
  201834. CGWarpMouseCursorPosition (CGPointMake (x, y));
  201835. CGAssociateMouseAndMouseCursorPosition (true);
  201836. }
  201837. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201838. class ScreenSaverDefeater : public Timer,
  201839. public DeletedAtShutdown
  201840. {
  201841. public:
  201842. ScreenSaverDefeater() throw()
  201843. {
  201844. startTimer (10000);
  201845. timerCallback();
  201846. }
  201847. ~ScreenSaverDefeater() {}
  201848. void timerCallback()
  201849. {
  201850. if (Process::isForegroundProcess())
  201851. UpdateSystemActivity (UsrActivity);
  201852. }
  201853. };
  201854. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201855. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201856. {
  201857. if (isEnabled)
  201858. {
  201859. deleteAndZero (screenSaverDefeater);
  201860. }
  201861. else if (screenSaverDefeater == 0)
  201862. {
  201863. screenSaverDefeater = new ScreenSaverDefeater();
  201864. }
  201865. }
  201866. bool Desktop::isScreenSaverEnabled() throw()
  201867. {
  201868. return screenSaverDefeater == 0;
  201869. }
  201870. #else
  201871. static IOPMAssertionID screenSaverDisablerID = 0;
  201872. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201873. {
  201874. if (isEnabled)
  201875. {
  201876. if (screenSaverDisablerID != 0)
  201877. {
  201878. IOPMAssertionRelease (screenSaverDisablerID);
  201879. screenSaverDisablerID = 0;
  201880. }
  201881. }
  201882. else
  201883. {
  201884. if (screenSaverDisablerID == 0)
  201885. {
  201886. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201887. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201888. CFSTR ("Juce"), &screenSaverDisablerID);
  201889. #else
  201890. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201891. &screenSaverDisablerID);
  201892. #endif
  201893. }
  201894. }
  201895. }
  201896. bool Desktop::isScreenSaverEnabled() throw()
  201897. {
  201898. return screenSaverDisablerID == 0;
  201899. }
  201900. #endif
  201901. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201902. {
  201903. const ScopedAutoReleasePool pool;
  201904. monitorCoords.clear();
  201905. NSArray* screens = [NSScreen screens];
  201906. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201907. for (unsigned int i = 0; i < [screens count]; ++i)
  201908. {
  201909. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201910. NSRect r = clipToWorkArea ? [s visibleFrame]
  201911. : [s frame];
  201912. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201913. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201914. (int) r.size.width,
  201915. (int) r.size.height));
  201916. }
  201917. jassert (monitorCoords.size() > 0);
  201918. }
  201919. #endif
  201920. #endif
  201921. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201922. #endif
  201923. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201924. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201925. // compiled on its own).
  201926. #if JUCE_INCLUDED_FILE
  201927. void Logger::outputDebugString (const String& text) throw()
  201928. {
  201929. std::cerr << (const char*) text.toUTF8() << std::endl;
  201930. }
  201931. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  201932. {
  201933. String text;
  201934. va_list args;
  201935. va_start (args, format);
  201936. text.vprintf (format, args);
  201937. outputDebugString (text);
  201938. }
  201939. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201940. {
  201941. static char testResult = 0;
  201942. if (testResult == 0)
  201943. {
  201944. struct kinfo_proc info;
  201945. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201946. size_t sz = sizeof (info);
  201947. sysctl (m, 4, &info, &sz, 0, 0);
  201948. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201949. }
  201950. return testResult > 0;
  201951. }
  201952. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201953. {
  201954. return juce_isRunningUnderDebugger();
  201955. }
  201956. #endif
  201957. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201958. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201959. #if JUCE_IPHONE
  201960. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201961. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201962. // compiled on its own).
  201963. #if JUCE_INCLUDED_FILE
  201964. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201965. #define SUPPORT_10_4_FONTS 1
  201966. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201967. #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5) || JUCE_PPC
  201968. #define SUPPORT_ONLY_10_4_FONTS 1
  201969. #endif
  201970. END_JUCE_NAMESPACE
  201971. @interface NSFont (PrivateHack)
  201972. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201973. @end
  201974. BEGIN_JUCE_NAMESPACE
  201975. #endif
  201976. class MacTypeface : public Typeface
  201977. {
  201978. public:
  201979. MacTypeface (const Font& font)
  201980. : Typeface (font.getTypefaceName())
  201981. {
  201982. const ScopedAutoReleasePool pool;
  201983. renderingTransform = CGAffineTransformIdentity;
  201984. bool needsItalicTransform = false;
  201985. #if JUCE_IPHONE
  201986. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201987. if (font.isItalic() || font.isBold())
  201988. {
  201989. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201990. for (NSString* i in familyFonts)
  201991. {
  201992. const String fn (nsStringToJuce (i));
  201993. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201994. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201995. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201996. || afterDash.containsIgnoreCase (T("italic"))
  201997. || fn.endsWithIgnoreCase (T("oblique"))
  201998. || fn.endsWithIgnoreCase (T("italic"));
  201999. if (probablyBold == font.isBold()
  202000. && probablyItalic == font.isItalic())
  202001. {
  202002. fontName = i;
  202003. needsItalicTransform = false;
  202004. break;
  202005. }
  202006. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  202007. {
  202008. fontName = i;
  202009. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  202010. }
  202011. }
  202012. if (needsItalicTransform)
  202013. renderingTransform.c = 0.15f;
  202014. }
  202015. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  202016. const int ascender = abs (CGFontGetAscent (fontRef));
  202017. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  202018. ascent = ascender / totalHeight;
  202019. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202020. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  202021. #else
  202022. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  202023. if (font.isItalic())
  202024. {
  202025. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  202026. toHaveTrait: NSItalicFontMask];
  202027. if (newFont == nsFont)
  202028. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  202029. nsFont = newFont;
  202030. }
  202031. if (font.isBold())
  202032. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  202033. [nsFont retain];
  202034. ascent = fabsf ((float) [nsFont ascender]);
  202035. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  202036. ascent /= totalSize;
  202037. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  202038. if (needsItalicTransform)
  202039. {
  202040. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  202041. renderingTransform.c = 0.15f;
  202042. }
  202043. #if SUPPORT_ONLY_10_4_FONTS
  202044. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202045. if (atsFont == 0)
  202046. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202047. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202048. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202049. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202050. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202051. #else
  202052. #if SUPPORT_10_4_FONTS
  202053. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202054. {
  202055. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202056. if (atsFont == 0)
  202057. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202058. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202059. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202060. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202061. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202062. }
  202063. else
  202064. #endif
  202065. {
  202066. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  202067. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  202068. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202069. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  202070. }
  202071. #endif
  202072. #endif
  202073. }
  202074. ~MacTypeface()
  202075. {
  202076. #if ! JUCE_IPHONE
  202077. [nsFont release];
  202078. #endif
  202079. if (fontRef != 0)
  202080. CGFontRelease (fontRef);
  202081. }
  202082. float getAscent() const
  202083. {
  202084. return ascent;
  202085. }
  202086. float getDescent() const
  202087. {
  202088. return 1.0f - ascent;
  202089. }
  202090. float getStringWidth (const String& text)
  202091. {
  202092. if (fontRef == 0 || text.isEmpty())
  202093. return 0;
  202094. const int length = text.length();
  202095. HeapBlock <CGGlyph> glyphs;
  202096. createGlyphsForString (text, length, glyphs);
  202097. float x = 0;
  202098. #if SUPPORT_ONLY_10_4_FONTS
  202099. HeapBlock <NSSize> advances (length);
  202100. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202101. for (int i = 0; i < length; ++i)
  202102. x += advances[i].width;
  202103. #else
  202104. #if SUPPORT_10_4_FONTS
  202105. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202106. {
  202107. HeapBlock <NSSize> advances (length);
  202108. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202109. for (int i = 0; i < length; ++i)
  202110. x += advances[i].width;
  202111. }
  202112. else
  202113. #endif
  202114. {
  202115. HeapBlock <int> advances (length);
  202116. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202117. for (int i = 0; i < length; ++i)
  202118. x += advances[i];
  202119. }
  202120. #endif
  202121. return x * unitsToHeightScaleFactor;
  202122. }
  202123. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202124. {
  202125. xOffsets.add (0);
  202126. if (fontRef == 0 || text.isEmpty())
  202127. return;
  202128. const int length = text.length();
  202129. HeapBlock <CGGlyph> glyphs;
  202130. createGlyphsForString (text, length, glyphs);
  202131. #if SUPPORT_ONLY_10_4_FONTS
  202132. HeapBlock <NSSize> advances (length);
  202133. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202134. int x = 0;
  202135. for (int i = 0; i < length; ++i)
  202136. {
  202137. x += advances[i].width;
  202138. xOffsets.add (x * unitsToHeightScaleFactor);
  202139. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202140. }
  202141. #else
  202142. #if SUPPORT_10_4_FONTS
  202143. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202144. {
  202145. HeapBlock <NSSize> advances (length);
  202146. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202147. float x = 0;
  202148. for (int i = 0; i < length; ++i)
  202149. {
  202150. x += advances[i].width;
  202151. xOffsets.add (x * unitsToHeightScaleFactor);
  202152. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202153. }
  202154. }
  202155. else
  202156. #endif
  202157. {
  202158. HeapBlock <int> advances (length);
  202159. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202160. {
  202161. int x = 0;
  202162. for (int i = 0; i < length; ++i)
  202163. {
  202164. x += advances [i];
  202165. xOffsets.add (x * unitsToHeightScaleFactor);
  202166. resultGlyphs.add (glyphs[i]);
  202167. }
  202168. }
  202169. }
  202170. #endif
  202171. }
  202172. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202173. {
  202174. #if JUCE_IPHONE
  202175. return false;
  202176. #else
  202177. if (nsFont == 0)
  202178. return false;
  202179. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202180. jassert (path.isEmpty());
  202181. const ScopedAutoReleasePool pool;
  202182. NSBezierPath* bez = [NSBezierPath bezierPath];
  202183. [bez moveToPoint: NSMakePoint (0, 0)];
  202184. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202185. inFont: nsFont];
  202186. for (int i = 0; i < [bez elementCount]; ++i)
  202187. {
  202188. NSPoint p[3];
  202189. switch ([bez elementAtIndex: i associatedPoints: p])
  202190. {
  202191. case NSMoveToBezierPathElement:
  202192. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202193. break;
  202194. case NSLineToBezierPathElement:
  202195. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202196. break;
  202197. case NSCurveToBezierPathElement:
  202198. 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);
  202199. break;
  202200. case NSClosePathBezierPathElement:
  202201. path.closeSubPath();
  202202. break;
  202203. default:
  202204. jassertfalse
  202205. break;
  202206. }
  202207. }
  202208. path.applyTransform (pathTransform);
  202209. return true;
  202210. #endif
  202211. }
  202212. juce_UseDebuggingNewOperator
  202213. CGFontRef fontRef;
  202214. float fontHeightToCGSizeFactor;
  202215. CGAffineTransform renderingTransform;
  202216. private:
  202217. float ascent, unitsToHeightScaleFactor;
  202218. #if JUCE_IPHONE
  202219. #else
  202220. NSFont* nsFont;
  202221. AffineTransform pathTransform;
  202222. #endif
  202223. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202224. {
  202225. #if SUPPORT_10_4_FONTS
  202226. #if ! SUPPORT_ONLY_10_4_FONTS
  202227. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202228. #endif
  202229. {
  202230. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202231. NSGlyph* const g = (NSGlyph*) glyphs;
  202232. for (int i = 0; i < length; ++i)
  202233. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202234. return;
  202235. }
  202236. #endif
  202237. #if ! SUPPORT_ONLY_10_4_FONTS
  202238. if (charToGlyphMapper == 0)
  202239. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202240. glyphs.malloc (length);
  202241. for (int i = 0; i < length; ++i)
  202242. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202243. #endif
  202244. }
  202245. #if ! SUPPORT_ONLY_10_4_FONTS
  202246. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202247. class CharToGlyphMapper
  202248. {
  202249. public:
  202250. CharToGlyphMapper (CGFontRef fontRef)
  202251. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202252. idRangeOffset (0), glyphIndexes (0)
  202253. {
  202254. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202255. if (cmapTable != 0)
  202256. {
  202257. const int numSubtables = getValue16 (cmapTable, 2);
  202258. for (int i = 0; i < numSubtables; ++i)
  202259. {
  202260. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202261. {
  202262. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202263. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202264. {
  202265. const int length = getValue16 (cmapTable, offset + 2);
  202266. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202267. segCount = segCountX2 / 2;
  202268. const int endCodeOffset = offset + 14;
  202269. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202270. const int idDeltaOffset = startCodeOffset + segCountX2;
  202271. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202272. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202273. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202274. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202275. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202276. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202277. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202278. }
  202279. break;
  202280. }
  202281. }
  202282. CFRelease (cmapTable);
  202283. }
  202284. }
  202285. ~CharToGlyphMapper()
  202286. {
  202287. if (endCode != 0)
  202288. {
  202289. CFRelease (endCode);
  202290. CFRelease (startCode);
  202291. CFRelease (idDelta);
  202292. CFRelease (idRangeOffset);
  202293. CFRelease (glyphIndexes);
  202294. }
  202295. }
  202296. int getGlyphForCharacter (const juce_wchar c) const
  202297. {
  202298. for (int i = 0; i < segCount; ++i)
  202299. {
  202300. if (getValue16 (endCode, i * 2) >= c)
  202301. {
  202302. const int start = getValue16 (startCode, i * 2);
  202303. if (start > c)
  202304. break;
  202305. const int delta = getValue16 (idDelta, i * 2);
  202306. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202307. if (rangeOffset == 0)
  202308. return delta + c;
  202309. else
  202310. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202311. }
  202312. }
  202313. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202314. return jmax (-1, c - 29);
  202315. }
  202316. private:
  202317. int segCount;
  202318. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202319. static uint16 getValue16 (CFDataRef data, const int index)
  202320. {
  202321. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202322. }
  202323. static uint32 getValue32 (CFDataRef data, const int index)
  202324. {
  202325. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202326. }
  202327. };
  202328. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202329. #endif
  202330. };
  202331. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202332. {
  202333. return new MacTypeface (font);
  202334. }
  202335. const StringArray Font::findAllTypefaceNames() throw()
  202336. {
  202337. StringArray names;
  202338. const ScopedAutoReleasePool pool;
  202339. #if JUCE_IPHONE
  202340. NSArray* fonts = [UIFont familyNames];
  202341. #else
  202342. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202343. #endif
  202344. for (unsigned int i = 0; i < [fonts count]; ++i)
  202345. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202346. names.sort (true);
  202347. return names;
  202348. }
  202349. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202350. {
  202351. #if JUCE_IPHONE
  202352. defaultSans = "Helvetica";
  202353. defaultSerif = "Times New Roman";
  202354. defaultFixed = "Courier New";
  202355. #else
  202356. defaultSans = "Lucida Grande";
  202357. defaultSerif = "Times New Roman";
  202358. defaultFixed = "Monaco";
  202359. #endif
  202360. }
  202361. #endif
  202362. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202363. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202364. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202365. // compiled on its own).
  202366. #if JUCE_INCLUDED_FILE
  202367. class CoreGraphicsImage : public Image
  202368. {
  202369. public:
  202370. CoreGraphicsImage (const PixelFormat format_,
  202371. const int imageWidth_,
  202372. const int imageHeight_,
  202373. const bool clearImage)
  202374. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202375. {
  202376. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202377. : CGColorSpaceCreateDeviceRGB();
  202378. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202379. colourSpace, getCGImageFlags (*this));
  202380. CGColorSpaceRelease (colourSpace);
  202381. }
  202382. ~CoreGraphicsImage()
  202383. {
  202384. CGContextRelease (context);
  202385. }
  202386. LowLevelGraphicsContext* createLowLevelContext();
  202387. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202388. {
  202389. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202390. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202391. {
  202392. return CGBitmapContextCreateImage (nativeImage->context);
  202393. }
  202394. else
  202395. {
  202396. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202397. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202398. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202399. 8, srcData.pixelStride * 8, srcData.lineStride,
  202400. colourSpace, getCGImageFlags (juceImage), provider,
  202401. 0, true, kCGRenderingIntentDefault);
  202402. CGDataProviderRelease (provider);
  202403. return imageRef;
  202404. }
  202405. }
  202406. #if JUCE_MAC
  202407. static NSImage* createNSImage (const Image& image)
  202408. {
  202409. const ScopedAutoReleasePool pool;
  202410. NSImage* im = [[NSImage alloc] init];
  202411. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202412. [im lockFocus];
  202413. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202414. CGImageRef imageRef = createImage (image, false, colourSpace);
  202415. CGColorSpaceRelease (colourSpace);
  202416. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202417. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202418. CGImageRelease (imageRef);
  202419. [im unlockFocus];
  202420. return im;
  202421. }
  202422. #endif
  202423. CGContextRef context;
  202424. private:
  202425. static CGBitmapInfo getCGImageFlags (const Image& image)
  202426. {
  202427. #if JUCE_BIG_ENDIAN
  202428. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202429. #else
  202430. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202431. #endif
  202432. }
  202433. };
  202434. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202435. {
  202436. #if USE_COREGRAPHICS_RENDERING
  202437. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202438. #else
  202439. return new Image (format, imageWidth, imageHeight, clearImage);
  202440. #endif
  202441. }
  202442. class CoreGraphicsContext : public LowLevelGraphicsContext
  202443. {
  202444. public:
  202445. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202446. : context (context_),
  202447. flipHeight (flipHeight_),
  202448. numGradientLookupEntries (0)
  202449. {
  202450. CGContextRetain (context);
  202451. CGContextSaveGState(context);
  202452. CGContextSetShouldSmoothFonts (context, true);
  202453. CGContextSetShouldAntialias (context, true);
  202454. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202455. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202456. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202457. gradientCallbacks.version = 0;
  202458. gradientCallbacks.evaluate = gradientCallback;
  202459. gradientCallbacks.releaseInfo = 0;
  202460. state = new SavedState();
  202461. }
  202462. ~CoreGraphicsContext()
  202463. {
  202464. CGContextRestoreGState (context);
  202465. CGContextRelease (context);
  202466. CGColorSpaceRelease (rgbColourSpace);
  202467. CGColorSpaceRelease (greyColourSpace);
  202468. }
  202469. bool isVectorDevice() const { return false; }
  202470. void setOrigin (int x, int y)
  202471. {
  202472. CGContextTranslateCTM (context, x, -y);
  202473. }
  202474. bool clipToRectangle (const Rectangle<int>& r)
  202475. {
  202476. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202477. return ! isClipEmpty();
  202478. }
  202479. bool clipToRectangleList (const RectangleList& clipRegion)
  202480. {
  202481. if (clipRegion.isEmpty())
  202482. {
  202483. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202484. return false;
  202485. }
  202486. else
  202487. {
  202488. const int numRects = clipRegion.getNumRectangles();
  202489. HeapBlock <CGRect> rects (numRects);
  202490. for (int i = 0; i < numRects; ++i)
  202491. {
  202492. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202493. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202494. }
  202495. CGContextClipToRects (context, rects, numRects);
  202496. return ! isClipEmpty();
  202497. }
  202498. }
  202499. void excludeClipRectangle (const Rectangle<int>& r)
  202500. {
  202501. RectangleList remaining (getClipBounds());
  202502. remaining.subtract (r);
  202503. clipToRectangleList (remaining);
  202504. }
  202505. void clipToPath (const Path& path, const AffineTransform& transform)
  202506. {
  202507. createPath (path, transform);
  202508. CGContextClip (context);
  202509. }
  202510. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202511. {
  202512. if (! transform.isSingularity())
  202513. {
  202514. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202515. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202516. flip();
  202517. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202518. applyTransform (t);
  202519. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202520. CGContextClipToMask (context, r, image);
  202521. applyTransform (t.inverted());
  202522. flip();
  202523. CGImageRelease (image);
  202524. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202525. }
  202526. }
  202527. bool clipRegionIntersects (const Rectangle<int>& r)
  202528. {
  202529. return getClipBounds().intersects (r);
  202530. }
  202531. const Rectangle<int> getClipBounds() const
  202532. {
  202533. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202534. return Rectangle<int> (roundToInt (bounds.origin.x),
  202535. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202536. roundToInt (bounds.size.width),
  202537. roundToInt (bounds.size.height));
  202538. }
  202539. bool isClipEmpty() const
  202540. {
  202541. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202542. }
  202543. void saveState()
  202544. {
  202545. CGContextSaveGState (context);
  202546. stateStack.add (new SavedState (*state));
  202547. }
  202548. void restoreState()
  202549. {
  202550. CGContextRestoreGState (context);
  202551. SavedState* const top = stateStack.getLast();
  202552. if (top != 0)
  202553. {
  202554. state = top;
  202555. stateStack.removeLast (1, false);
  202556. }
  202557. else
  202558. {
  202559. jassertfalse // trying to pop with an empty stack!
  202560. }
  202561. }
  202562. void setFill (const FillType& fillType)
  202563. {
  202564. state->fillType = fillType;
  202565. if (fillType.isColour())
  202566. {
  202567. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202568. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202569. CGContextSetAlpha (context, 1.0f);
  202570. }
  202571. }
  202572. void setOpacity (float newOpacity)
  202573. {
  202574. state->fillType.setOpacity (newOpacity);
  202575. setFill (state->fillType);
  202576. }
  202577. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202578. {
  202579. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202580. ? kCGInterpolationLow
  202581. : kCGInterpolationHigh);
  202582. }
  202583. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202584. {
  202585. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202586. if (replaceExistingContents)
  202587. {
  202588. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202589. CGContextClearRect (context, cgRect);
  202590. #else
  202591. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202592. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202593. CGContextClearRect (context, cgRect);
  202594. else
  202595. #endif
  202596. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202597. #endif
  202598. fillRect (r, false);
  202599. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202600. }
  202601. else
  202602. {
  202603. if (state->fillType.isColour())
  202604. {
  202605. CGContextFillRect (context, cgRect);
  202606. }
  202607. else if (state->fillType.isGradient())
  202608. {
  202609. CGContextSaveGState (context);
  202610. CGContextClipToRect (context, cgRect);
  202611. drawGradient();
  202612. CGContextRestoreGState (context);
  202613. }
  202614. else
  202615. {
  202616. CGContextSaveGState (context);
  202617. CGContextClipToRect (context, cgRect);
  202618. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202619. CGContextRestoreGState (context);
  202620. }
  202621. }
  202622. }
  202623. void fillPath (const Path& path, const AffineTransform& transform)
  202624. {
  202625. CGContextSaveGState (context);
  202626. if (state->fillType.isColour())
  202627. {
  202628. flip();
  202629. applyTransform (transform);
  202630. createPath (path);
  202631. if (path.isUsingNonZeroWinding())
  202632. CGContextFillPath (context);
  202633. else
  202634. CGContextEOFillPath (context);
  202635. }
  202636. else
  202637. {
  202638. createPath (path, transform);
  202639. if (path.isUsingNonZeroWinding())
  202640. CGContextClip (context);
  202641. else
  202642. CGContextEOClip (context);
  202643. if (state->fillType.isGradient())
  202644. drawGradient();
  202645. else
  202646. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202647. }
  202648. CGContextRestoreGState (context);
  202649. }
  202650. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202651. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202652. {
  202653. jassert (sourceImage.getBounds().contains (srcClip));
  202654. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202655. CGImageRef image = fullImage;
  202656. if (srcClip != sourceImage.getBounds())
  202657. {
  202658. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202659. srcClip.getWidth(), srcClip.getHeight()));
  202660. CGImageRelease (fullImage);
  202661. }
  202662. CGContextSaveGState (context);
  202663. CGContextSetAlpha (context, state->fillType.getOpacity());
  202664. flip();
  202665. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202666. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202667. if (fillEntireClipAsTiles)
  202668. {
  202669. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202670. CGContextDrawTiledImage (context, imageRect, image);
  202671. #else
  202672. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202673. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202674. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202675. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202676. CGContextDrawTiledImage (context, imageRect, image);
  202677. else
  202678. #endif
  202679. {
  202680. // Fallback to manually doing a tiled fill on 10.4
  202681. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202682. const int iw = srcClip.getWidth();
  202683. const int ih = srcClip.getHeight();
  202684. int x = 0, y = 0;
  202685. while (x > clip.origin.x) x -= iw;
  202686. while (y > clip.origin.y) y -= ih;
  202687. const int right = (int) (clip.origin.x + clip.size.width);
  202688. const int bottom = (int) (clip.origin.y + clip.size.height);
  202689. while (y < bottom)
  202690. {
  202691. for (int x2 = x; x2 < right; x2 += iw)
  202692. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202693. y += ih;
  202694. }
  202695. }
  202696. #endif
  202697. }
  202698. else
  202699. {
  202700. CGContextDrawImage (context, imageRect, image);
  202701. }
  202702. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202703. CGContextRestoreGState (context);
  202704. }
  202705. void drawLine (double x1, double y1, double x2, double y2)
  202706. {
  202707. CGContextSetLineCap (context, kCGLineCapSquare);
  202708. CGContextSetLineWidth (context, 1.0f);
  202709. CGContextSetRGBStrokeColor (context,
  202710. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202711. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202712. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202713. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202714. CGContextStrokeLineSegments (context, line, 1);
  202715. }
  202716. void drawVerticalLine (const int x, double top, double bottom)
  202717. {
  202718. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202719. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202720. #else
  202721. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202722. // the x co-ord slightly to trick it..
  202723. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202724. #endif
  202725. }
  202726. void drawHorizontalLine (const int y, double left, double right)
  202727. {
  202728. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202729. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202730. #else
  202731. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202732. // the x co-ord slightly to trick it..
  202733. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202734. #endif
  202735. }
  202736. void setFont (const Font& newFont)
  202737. {
  202738. if (state->font != newFont)
  202739. {
  202740. state->fontRef = 0;
  202741. state->font = newFont;
  202742. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202743. if (mf != 0)
  202744. {
  202745. state->fontRef = mf->fontRef;
  202746. CGContextSetFont (context, state->fontRef);
  202747. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202748. state->fontTransform = mf->renderingTransform;
  202749. state->fontTransform.a *= state->font.getHorizontalScale();
  202750. CGContextSetTextMatrix (context, state->fontTransform);
  202751. }
  202752. }
  202753. }
  202754. const Font getFont()
  202755. {
  202756. return state->font;
  202757. }
  202758. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202759. {
  202760. if (state->fontRef != 0 && state->fillType.isColour())
  202761. {
  202762. if (transform.isOnlyTranslation())
  202763. {
  202764. CGGlyph g = glyphNumber;
  202765. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202766. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202767. }
  202768. else
  202769. {
  202770. CGContextSaveGState (context);
  202771. flip();
  202772. applyTransform (transform);
  202773. CGAffineTransform t = state->fontTransform;
  202774. t.d = -t.d;
  202775. CGContextSetTextMatrix (context, t);
  202776. CGGlyph g = glyphNumber;
  202777. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202778. CGContextSetTextMatrix (context, state->fontTransform);
  202779. CGContextRestoreGState (context);
  202780. }
  202781. }
  202782. else
  202783. {
  202784. Path p;
  202785. Font& f = state->font;
  202786. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202787. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202788. .followedBy (transform));
  202789. }
  202790. }
  202791. private:
  202792. CGContextRef context;
  202793. const float flipHeight;
  202794. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202795. CGFunctionCallbacks gradientCallbacks;
  202796. struct SavedState
  202797. {
  202798. SavedState()
  202799. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202800. {
  202801. }
  202802. SavedState (const SavedState& other)
  202803. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202804. fontTransform (other.fontTransform)
  202805. {
  202806. }
  202807. ~SavedState()
  202808. {
  202809. }
  202810. FillType fillType;
  202811. Font font;
  202812. CGFontRef fontRef;
  202813. CGAffineTransform fontTransform;
  202814. };
  202815. ScopedPointer <SavedState> state;
  202816. OwnedArray <SavedState> stateStack;
  202817. HeapBlock <PixelARGB> gradientLookupTable;
  202818. int numGradientLookupEntries;
  202819. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202820. {
  202821. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202822. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202823. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202824. colour.unpremultiply();
  202825. outData[0] = colour.getRed() / 255.0f;
  202826. outData[1] = colour.getGreen() / 255.0f;
  202827. outData[2] = colour.getBlue() / 255.0f;
  202828. outData[3] = colour.getAlpha() / 255.0f;
  202829. }
  202830. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202831. {
  202832. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202833. --numGradientLookupEntries;
  202834. CGShadingRef result = 0;
  202835. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202836. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202837. if (gradient.isRadial)
  202838. {
  202839. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202840. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202841. function, true, true);
  202842. }
  202843. else
  202844. {
  202845. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202846. CGPointMake (gradient.x2, gradient.y2),
  202847. function, true, true);
  202848. }
  202849. CGFunctionRelease (function);
  202850. return result;
  202851. }
  202852. void drawGradient()
  202853. {
  202854. flip();
  202855. applyTransform (state->fillType.transform);
  202856. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202857. // you draw a gradient with high quality interp enabled).
  202858. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202859. CGContextSetAlpha (context, state->fillType.getOpacity());
  202860. CGContextDrawShading (context, shading);
  202861. CGShadingRelease (shading);
  202862. }
  202863. void createPath (const Path& path) const
  202864. {
  202865. CGContextBeginPath (context);
  202866. Path::Iterator i (path);
  202867. while (i.next())
  202868. {
  202869. switch (i.elementType)
  202870. {
  202871. case Path::Iterator::startNewSubPath:
  202872. CGContextMoveToPoint (context, i.x1, i.y1);
  202873. break;
  202874. case Path::Iterator::lineTo:
  202875. CGContextAddLineToPoint (context, i.x1, i.y1);
  202876. break;
  202877. case Path::Iterator::quadraticTo:
  202878. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202879. break;
  202880. case Path::Iterator::cubicTo:
  202881. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202882. break;
  202883. case Path::Iterator::closePath:
  202884. CGContextClosePath (context); break;
  202885. default:
  202886. jassertfalse
  202887. break;
  202888. }
  202889. }
  202890. }
  202891. void createPath (const Path& path, const AffineTransform& transform) const
  202892. {
  202893. CGContextBeginPath (context);
  202894. Path::Iterator i (path);
  202895. while (i.next())
  202896. {
  202897. switch (i.elementType)
  202898. {
  202899. case Path::Iterator::startNewSubPath:
  202900. transform.transformPoint (i.x1, i.y1);
  202901. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202902. break;
  202903. case Path::Iterator::lineTo:
  202904. transform.transformPoint (i.x1, i.y1);
  202905. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202906. break;
  202907. case Path::Iterator::quadraticTo:
  202908. transform.transformPoint (i.x1, i.y1);
  202909. transform.transformPoint (i.x2, i.y2);
  202910. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202911. break;
  202912. case Path::Iterator::cubicTo:
  202913. transform.transformPoint (i.x1, i.y1);
  202914. transform.transformPoint (i.x2, i.y2);
  202915. transform.transformPoint (i.x3, i.y3);
  202916. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202917. break;
  202918. case Path::Iterator::closePath:
  202919. CGContextClosePath (context); break;
  202920. default:
  202921. jassertfalse
  202922. break;
  202923. }
  202924. }
  202925. }
  202926. static Image* createAlphaChannelImage (const Image& im)
  202927. {
  202928. if (im.getFormat() == Image::SingleChannel)
  202929. return const_cast <Image*> (&im);
  202930. return im.createCopyOfAlphaChannel();
  202931. }
  202932. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202933. {
  202934. if (im.getFormat() != Image::SingleChannel)
  202935. delete alphaIm;
  202936. }
  202937. void flip() const
  202938. {
  202939. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202940. }
  202941. void applyTransform (const AffineTransform& transform) const
  202942. {
  202943. CGAffineTransform t;
  202944. t.a = transform.mat00;
  202945. t.b = transform.mat10;
  202946. t.c = transform.mat01;
  202947. t.d = transform.mat11;
  202948. t.tx = transform.mat02;
  202949. t.ty = transform.mat12;
  202950. CGContextConcatCTM (context, t);
  202951. }
  202952. float flipY (float y) const
  202953. {
  202954. return flipHeight - y;
  202955. }
  202956. };
  202957. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202958. {
  202959. return new CoreGraphicsContext (context, imageHeight);
  202960. }
  202961. #endif
  202962. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202963. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202964. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202965. // compiled on its own).
  202966. #if JUCE_INCLUDED_FILE
  202967. class UIViewComponentPeer;
  202968. END_JUCE_NAMESPACE
  202969. #define JuceUIView MakeObjCClassName(JuceUIView)
  202970. @interface JuceUIView : UIView
  202971. {
  202972. @public
  202973. UIViewComponentPeer* owner;
  202974. }
  202975. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202976. - (void) dealloc;
  202977. - (void) drawRect: (CGRect) r;
  202978. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202979. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202980. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202981. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202982. - (BOOL) becomeFirstResponder;
  202983. - (BOOL) resignFirstResponder;
  202984. - (BOOL) canBecomeFirstResponder;
  202985. - (void) asyncRepaint: (id) rect;
  202986. @end
  202987. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202988. @interface JuceUIWindow : UIWindow
  202989. {
  202990. @private
  202991. UIViewComponentPeer* owner;
  202992. bool isZooming;
  202993. }
  202994. - (void) setOwner: (UIViewComponentPeer*) owner;
  202995. - (void) becomeKeyWindow;
  202996. @end
  202997. BEGIN_JUCE_NAMESPACE
  202998. class UIViewComponentPeer : public ComponentPeer
  202999. {
  203000. public:
  203001. UIViewComponentPeer (Component* const component,
  203002. const int windowStyleFlags,
  203003. UIView* viewToAttachTo);
  203004. ~UIViewComponentPeer();
  203005. void* getNativeHandle() const;
  203006. void setVisible (bool shouldBeVisible);
  203007. void setTitle (const String& title);
  203008. void setPosition (int x, int y);
  203009. void setSize (int w, int h);
  203010. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  203011. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  203012. void getBounds (int& x, int& y, int& w, int& h) const;
  203013. int getScreenX() const;
  203014. int getScreenY() const;
  203015. void relativePositionToGlobal (int& x, int& y);
  203016. void globalPositionToRelative (int& x, int& y);
  203017. void setMinimised (bool shouldBeMinimised);
  203018. bool isMinimised() const;
  203019. void setFullScreen (bool shouldBeFullScreen);
  203020. bool isFullScreen() const;
  203021. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  203022. const BorderSize getFrameSize() const;
  203023. bool setAlwaysOnTop (bool alwaysOnTop);
  203024. void toFront (bool makeActiveWindow);
  203025. void toBehind (ComponentPeer* other);
  203026. void setIcon (const Image& newIcon);
  203027. virtual void drawRect (CGRect r);
  203028. virtual bool canBecomeKeyWindow();
  203029. virtual bool windowShouldClose();
  203030. virtual void redirectMovedOrResized();
  203031. virtual CGRect constrainRect (CGRect r);
  203032. virtual void viewFocusGain();
  203033. virtual void viewFocusLoss();
  203034. bool isFocused() const;
  203035. void grabFocus();
  203036. void textInputRequired (int x, int y);
  203037. void repaint (int x, int y, int w, int h);
  203038. void performAnyPendingRepaintsNow();
  203039. juce_UseDebuggingNewOperator
  203040. UIWindow* window;
  203041. JuceUIView* view;
  203042. bool isSharedWindow, fullScreen, insideDrawRect;
  203043. };
  203044. END_JUCE_NAMESPACE
  203045. @implementation JuceUIView
  203046. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  203047. withFrame: (CGRect) frame
  203048. {
  203049. [super initWithFrame: frame];
  203050. owner = owner_;
  203051. return self;
  203052. }
  203053. - (void) dealloc
  203054. {
  203055. [super dealloc];
  203056. }
  203057. - (void) drawRect: (CGRect) r
  203058. {
  203059. if (owner != 0)
  203060. owner->drawRect (r);
  203061. }
  203062. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  203063. {
  203064. return false;
  203065. }
  203066. static int currentModifiers = 0;
  203067. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  203068. {
  203069. return ModifierKeys (currentModifiers);
  203070. }
  203071. void ModifierKeys::updateCurrentModifiers() throw()
  203072. {
  203073. currentModifierFlags = currentModifiers;
  203074. }
  203075. static int getModifierForButtonNumber (const int num)
  203076. {
  203077. return num == 0 ? ModifierKeys::leftButtonModifier
  203078. : (num == 1 ? ModifierKeys::rightButtonModifier
  203079. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  203080. }
  203081. static int64 getMouseTime (UIEvent* e)
  203082. {
  203083. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  203084. + (int64) ([e timestamp] * 1000.0);
  203085. }
  203086. int juce_lastMouseX = 0, juce_lastMouseY = 0;
  203087. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  203088. {
  203089. if (owner == 0)
  203090. return;
  203091. NSArray* const t = [[event touchesForView: self] allObjects];
  203092. switch ([t count])
  203093. {
  203094. case 1: // One finger..
  203095. {
  203096. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203097. currentModifiers |= getModifierForButtonNumber (0);
  203098. int x, y, w, h;
  203099. owner->getBounds (x, y, w, h, true);
  203100. juce_lastMouseX = x + (int) p.x;
  203101. juce_lastMouseY = y + (int) p.y;
  203102. owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event));
  203103. if (owner != 0)
  203104. owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event));
  203105. }
  203106. default:
  203107. //xxx multi-touch..
  203108. break;
  203109. }
  203110. }
  203111. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  203112. {
  203113. if (owner == 0)
  203114. return;
  203115. NSArray* const t = [[event touchesForView: self] allObjects];
  203116. switch ([t count])
  203117. {
  203118. case 1: // One finger..
  203119. {
  203120. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203121. int x, y, w, h;
  203122. owner->getBounds (x, y, w, h, true);
  203123. juce_lastMouseX = x + (int) p.x;
  203124. juce_lastMouseY = y + (int) p.y;
  203125. owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event));
  203126. }
  203127. default:
  203128. //xxx multi-touch..
  203129. break;
  203130. }
  203131. }
  203132. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203133. {
  203134. if (owner == 0)
  203135. return;
  203136. NSArray* const t = [[event touchesForView: self] allObjects];
  203137. switch ([t count])
  203138. {
  203139. case 1: // One finger..
  203140. {
  203141. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203142. int x, y, w, h;
  203143. owner->getBounds (x, y, w, h, true);
  203144. juce_lastMouseX = x + (int) p.x;
  203145. juce_lastMouseY = y + (int) p.y;
  203146. const int oldMods = currentModifiers;
  203147. currentModifiers &= ~getModifierForButtonNumber (0);
  203148. owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event));
  203149. }
  203150. default:
  203151. //xxx multi-touch..
  203152. break;
  203153. }
  203154. }
  203155. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203156. {
  203157. [self touchesEnded: touches withEvent: event];
  203158. }
  203159. - (BOOL) becomeFirstResponder
  203160. {
  203161. if (owner != 0)
  203162. owner->viewFocusGain();
  203163. return true;
  203164. }
  203165. - (BOOL) resignFirstResponder
  203166. {
  203167. if (owner != 0)
  203168. owner->viewFocusLoss();
  203169. return true;
  203170. }
  203171. - (BOOL) canBecomeFirstResponder
  203172. {
  203173. return owner != 0 && owner->canBecomeKeyWindow();
  203174. }
  203175. - (void) asyncRepaint: (id) rect
  203176. {
  203177. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203178. [self setNeedsDisplayInRect: *r];
  203179. }
  203180. @end
  203181. @implementation JuceUIWindow
  203182. - (void) setOwner: (UIViewComponentPeer*) owner_
  203183. {
  203184. owner = owner_;
  203185. isZooming = false;
  203186. }
  203187. - (void) becomeKeyWindow
  203188. {
  203189. [super becomeKeyWindow];
  203190. if (owner != 0)
  203191. owner->grabFocus();
  203192. }
  203193. @end
  203194. BEGIN_JUCE_NAMESPACE
  203195. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203196. const int windowStyleFlags,
  203197. UIView* viewToAttachTo)
  203198. : ComponentPeer (component, windowStyleFlags),
  203199. window (0),
  203200. view (0),
  203201. isSharedWindow (viewToAttachTo != 0),
  203202. fullScreen (false),
  203203. insideDrawRect (false)
  203204. {
  203205. CGRect r;
  203206. r.origin.x = 0;
  203207. r.origin.y = 0;
  203208. r.size.width = (float) component->getWidth();
  203209. r.size.height = (float) component->getHeight();
  203210. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203211. if (isSharedWindow)
  203212. {
  203213. window = [viewToAttachTo window];
  203214. [viewToAttachTo addSubview: view];
  203215. setVisible (component->isVisible());
  203216. }
  203217. else
  203218. {
  203219. r.origin.x = (float) component->getX();
  203220. r.origin.y = (float) component->getY();
  203221. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203222. window = [[JuceUIWindow alloc] init];
  203223. window.frame = r;
  203224. window.opaque = component->isOpaque();
  203225. view.opaque = component->isOpaque();
  203226. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203227. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203228. [((JuceUIWindow*) window) setOwner: this];
  203229. if (component->isAlwaysOnTop())
  203230. window.windowLevel = UIWindowLevelAlert;
  203231. [window addSubview: view];
  203232. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203233. view.hidden = ! component->isVisible();
  203234. window.hidden = ! component->isVisible();
  203235. }
  203236. setTitle (component->getName());
  203237. }
  203238. UIViewComponentPeer::~UIViewComponentPeer()
  203239. {
  203240. view->owner = 0;
  203241. [view removeFromSuperview];
  203242. [view release];
  203243. if (! isSharedWindow)
  203244. {
  203245. [((JuceUIWindow*) window) setOwner: 0];
  203246. [window release];
  203247. }
  203248. }
  203249. void* UIViewComponentPeer::getNativeHandle() const
  203250. {
  203251. return view;
  203252. }
  203253. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203254. {
  203255. view.hidden = ! shouldBeVisible;
  203256. if (! isSharedWindow)
  203257. window.hidden = ! shouldBeVisible;
  203258. }
  203259. void UIViewComponentPeer::setTitle (const String& title)
  203260. {
  203261. // xxx is this possible?
  203262. }
  203263. void UIViewComponentPeer::setPosition (int x, int y)
  203264. {
  203265. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203266. }
  203267. void UIViewComponentPeer::setSize (int w, int h)
  203268. {
  203269. setBounds (component->getX(), component->getY(), w, h, false);
  203270. }
  203271. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203272. {
  203273. fullScreen = isNowFullScreen;
  203274. w = jmax (0, w);
  203275. h = jmax (0, h);
  203276. CGRect r;
  203277. r.origin.x = (float) x;
  203278. r.origin.y = (float) y;
  203279. r.size.width = (float) w;
  203280. r.size.height = (float) h;
  203281. if (isSharedWindow)
  203282. {
  203283. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203284. if ([view frame].size.width != r.size.width
  203285. || [view frame].size.height != r.size.height)
  203286. [view setNeedsDisplay];
  203287. view.frame = r;
  203288. }
  203289. else
  203290. {
  203291. window.frame = r;
  203292. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203293. }
  203294. }
  203295. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  203296. {
  203297. CGRect r = [view frame];
  203298. if (global && [view window] != 0)
  203299. {
  203300. r = [view convertRect: r toView: nil];
  203301. CGRect wr = [[view window] frame];
  203302. r.origin.x += wr.origin.x;
  203303. r.origin.y += wr.origin.y;
  203304. }
  203305. x = (int) r.origin.x;
  203306. y = (int) r.origin.y;
  203307. w = (int) r.size.width;
  203308. h = (int) r.size.height;
  203309. }
  203310. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  203311. {
  203312. getBounds (x, y, w, h, ! isSharedWindow);
  203313. }
  203314. int UIViewComponentPeer::getScreenX() const
  203315. {
  203316. int x, y, w, h;
  203317. getBounds (x, y, w, h, true);
  203318. return x;
  203319. }
  203320. int UIViewComponentPeer::getScreenY() const
  203321. {
  203322. int x, y, w, h;
  203323. getBounds (x, y, w, h, true);
  203324. return y;
  203325. }
  203326. void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  203327. {
  203328. int wx, wy, ww, wh;
  203329. getBounds (wx, wy, ww, wh, true);
  203330. x += wx;
  203331. y += wy;
  203332. }
  203333. void UIViewComponentPeer::globalPositionToRelative (int& x, int& y)
  203334. {
  203335. int wx, wy, ww, wh;
  203336. getBounds (wx, wy, ww, wh, true);
  203337. x -= wx;
  203338. y -= wy;
  203339. }
  203340. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203341. {
  203342. if (constrainer != 0)
  203343. {
  203344. CGRect current = [window frame];
  203345. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203346. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203347. int x = (int) r.origin.x;
  203348. int y = (int) r.origin.y;
  203349. int w = (int) r.size.width;
  203350. int h = (int) r.size.height;
  203351. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203352. (int) current.size.width, (int) current.size.height);
  203353. constrainer->checkBounds (x, y, w, h,
  203354. original,
  203355. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203356. y != original.getY() && y + h == original.getBottom(),
  203357. x != original.getX() && x + w == original.getRight(),
  203358. y == original.getY() && y + h != original.getBottom(),
  203359. x == original.getX() && x + w != original.getRight());
  203360. r.origin.x = x;
  203361. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - y;
  203362. r.size.width = w;
  203363. r.size.height = h;
  203364. }
  203365. return r;
  203366. }
  203367. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203368. {
  203369. // xxx
  203370. }
  203371. bool UIViewComponentPeer::isMinimised() const
  203372. {
  203373. return false;
  203374. }
  203375. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203376. {
  203377. if (! isSharedWindow)
  203378. {
  203379. Rectangle<int> r (lastNonFullscreenBounds);
  203380. setMinimised (false);
  203381. if (fullScreen != shouldBeFullScreen)
  203382. {
  203383. if (shouldBeFullScreen)
  203384. r = Desktop::getInstance().getMainMonitorArea();
  203385. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203386. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203387. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203388. }
  203389. }
  203390. }
  203391. bool UIViewComponentPeer::isFullScreen() const
  203392. {
  203393. return fullScreen;
  203394. }
  203395. bool UIViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  203396. {
  203397. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  203398. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  203399. return false;
  203400. CGPoint p;
  203401. p.x = (float) x;
  203402. p.y = (float) y;
  203403. UIView* v = [view hitTest: p withEvent: nil];
  203404. if (trueIfInAChildWindow)
  203405. return v != nil;
  203406. return v == view;
  203407. }
  203408. const BorderSize UIViewComponentPeer::getFrameSize() const
  203409. {
  203410. BorderSize b;
  203411. if (! isSharedWindow)
  203412. {
  203413. CGRect v = [view convertRect: [view frame] toView: nil];
  203414. CGRect w = [window frame];
  203415. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203416. b.setBottom ((int) v.origin.y);
  203417. b.setLeft ((int) v.origin.x);
  203418. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203419. }
  203420. return b;
  203421. }
  203422. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203423. {
  203424. if (! isSharedWindow)
  203425. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203426. return true;
  203427. }
  203428. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203429. {
  203430. if (isSharedWindow)
  203431. [[view superview] bringSubviewToFront: view];
  203432. if (window != 0 && component->isVisible())
  203433. [window makeKeyAndVisible];
  203434. }
  203435. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203436. {
  203437. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203438. if (isSharedWindow)
  203439. {
  203440. [[view superview] insertSubview: view belowSubview: o->view];
  203441. }
  203442. else
  203443. {
  203444. jassertfalse // don't know how to do this
  203445. }
  203446. }
  203447. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203448. {
  203449. // to do..
  203450. }
  203451. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203452. void UIViewComponentPeer::viewFocusGain()
  203453. {
  203454. if (currentlyFocusedPeer != this)
  203455. {
  203456. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203457. currentlyFocusedPeer->handleFocusLoss();
  203458. currentlyFocusedPeer = this;
  203459. handleFocusGain();
  203460. }
  203461. }
  203462. void UIViewComponentPeer::viewFocusLoss()
  203463. {
  203464. if (currentlyFocusedPeer == this)
  203465. {
  203466. currentlyFocusedPeer = 0;
  203467. handleFocusLoss();
  203468. }
  203469. }
  203470. void juce_HandleProcessFocusChange()
  203471. {
  203472. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203473. {
  203474. if (Process::isForegroundProcess())
  203475. {
  203476. currentlyFocusedPeer->handleFocusGain();
  203477. ComponentPeer::bringModalComponentToFront();
  203478. }
  203479. else
  203480. {
  203481. currentlyFocusedPeer->handleFocusLoss();
  203482. // turn kiosk mode off if we lose focus..
  203483. Desktop::getInstance().setKioskModeComponent (0);
  203484. }
  203485. }
  203486. }
  203487. bool UIViewComponentPeer::isFocused() const
  203488. {
  203489. return isSharedWindow ? this == currentlyFocusedPeer
  203490. : (window != 0 && [window isKeyWindow]);
  203491. }
  203492. void UIViewComponentPeer::grabFocus()
  203493. {
  203494. if (window != 0)
  203495. {
  203496. [window makeKeyWindow];
  203497. viewFocusGain();
  203498. }
  203499. }
  203500. void UIViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  203501. {
  203502. }
  203503. void UIViewComponentPeer::drawRect (CGRect r)
  203504. {
  203505. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203506. return;
  203507. CGContextRef cg = UIGraphicsGetCurrentContext();
  203508. if (! component->isOpaque())
  203509. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203510. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203511. CoreGraphicsContext g (cg, view.bounds.size.height);
  203512. insideDrawRect = true;
  203513. handlePaint (g);
  203514. insideDrawRect = false;
  203515. }
  203516. bool UIViewComponentPeer::canBecomeKeyWindow()
  203517. {
  203518. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203519. }
  203520. bool UIViewComponentPeer::windowShouldClose()
  203521. {
  203522. if (! isValidPeer (this))
  203523. return YES;
  203524. handleUserClosingWindow();
  203525. return NO;
  203526. }
  203527. void UIViewComponentPeer::redirectMovedOrResized()
  203528. {
  203529. handleMovedOrResized();
  203530. }
  203531. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203532. {
  203533. }
  203534. class AsyncRepaintMessage : public CallbackMessage
  203535. {
  203536. public:
  203537. UIViewComponentPeer* const peer;
  203538. const Rectangle<int> rect;
  203539. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203540. : peer (peer_), rect (rect_)
  203541. {
  203542. }
  203543. void messageCallback()
  203544. {
  203545. if (ComponentPeer::isValidPeer (peer))
  203546. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203547. }
  203548. };
  203549. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203550. {
  203551. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203552. {
  203553. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203554. }
  203555. else
  203556. {
  203557. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203558. }
  203559. }
  203560. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203561. {
  203562. }
  203563. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203564. {
  203565. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203566. }
  203567. Image* juce_createIconForFile (const File& file)
  203568. {
  203569. return 0;
  203570. }
  203571. bool Desktop::canUseSemiTransparentWindows() throw()
  203572. {
  203573. return true;
  203574. }
  203575. void Desktop::getMousePosition (int& x, int& y) throw()
  203576. {
  203577. x = juce_lastMouseX;
  203578. y = juce_lastMouseY;
  203579. }
  203580. void Desktop::setMousePosition (int x, int y) throw()
  203581. {
  203582. }
  203583. const int KeyPress::spaceKey = ' ';
  203584. const int KeyPress::returnKey = 0x0d;
  203585. const int KeyPress::escapeKey = 0x1b;
  203586. const int KeyPress::backspaceKey = 0x7f;
  203587. const int KeyPress::leftKey = 0x1000;
  203588. const int KeyPress::rightKey = 0x1001;
  203589. const int KeyPress::upKey = 0x1002;
  203590. const int KeyPress::downKey = 0x1003;
  203591. const int KeyPress::pageUpKey = 0x1004;
  203592. const int KeyPress::pageDownKey = 0x1005;
  203593. const int KeyPress::endKey = 0x1006;
  203594. const int KeyPress::homeKey = 0x1007;
  203595. const int KeyPress::deleteKey = 0x1008;
  203596. const int KeyPress::insertKey = -1;
  203597. const int KeyPress::tabKey = 9;
  203598. const int KeyPress::F1Key = 0x2001;
  203599. const int KeyPress::F2Key = 0x2002;
  203600. const int KeyPress::F3Key = 0x2003;
  203601. const int KeyPress::F4Key = 0x2004;
  203602. const int KeyPress::F5Key = 0x2005;
  203603. const int KeyPress::F6Key = 0x2006;
  203604. const int KeyPress::F7Key = 0x2007;
  203605. const int KeyPress::F8Key = 0x2008;
  203606. const int KeyPress::F9Key = 0x2009;
  203607. const int KeyPress::F10Key = 0x200a;
  203608. const int KeyPress::F11Key = 0x200b;
  203609. const int KeyPress::F12Key = 0x200c;
  203610. const int KeyPress::F13Key = 0x200d;
  203611. const int KeyPress::F14Key = 0x200e;
  203612. const int KeyPress::F15Key = 0x200f;
  203613. const int KeyPress::F16Key = 0x2010;
  203614. const int KeyPress::numberPad0 = 0x30020;
  203615. const int KeyPress::numberPad1 = 0x30021;
  203616. const int KeyPress::numberPad2 = 0x30022;
  203617. const int KeyPress::numberPad3 = 0x30023;
  203618. const int KeyPress::numberPad4 = 0x30024;
  203619. const int KeyPress::numberPad5 = 0x30025;
  203620. const int KeyPress::numberPad6 = 0x30026;
  203621. const int KeyPress::numberPad7 = 0x30027;
  203622. const int KeyPress::numberPad8 = 0x30028;
  203623. const int KeyPress::numberPad9 = 0x30029;
  203624. const int KeyPress::numberPadAdd = 0x3002a;
  203625. const int KeyPress::numberPadSubtract = 0x3002b;
  203626. const int KeyPress::numberPadMultiply = 0x3002c;
  203627. const int KeyPress::numberPadDivide = 0x3002d;
  203628. const int KeyPress::numberPadSeparator = 0x3002e;
  203629. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203630. const int KeyPress::numberPadEquals = 0x30030;
  203631. const int KeyPress::numberPadDelete = 0x30031;
  203632. const int KeyPress::playKey = 0x30000;
  203633. const int KeyPress::stopKey = 0x30001;
  203634. const int KeyPress::fastForwardKey = 0x30002;
  203635. const int KeyPress::rewindKey = 0x30003;
  203636. #endif
  203637. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203638. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203639. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203640. // compiled on its own).
  203641. #if JUCE_INCLUDED_FILE
  203642. struct CallbackMessagePayload
  203643. {
  203644. MessageCallbackFunction* function;
  203645. void* parameter;
  203646. void* volatile result;
  203647. bool volatile hasBeenExecuted;
  203648. };
  203649. END_JUCE_NAMESPACE
  203650. using namespace JUCE_NAMESPACE;
  203651. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203652. {
  203653. }
  203654. - (JuceAppDelegate*) init;
  203655. - (void) dealloc;
  203656. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203657. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203658. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203659. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203660. - (void) customEvent: (id) data;
  203661. - (void) performCallback: (id) info;
  203662. @end
  203663. @implementation JuceAppDelegate
  203664. - (JuceAppDelegate*) init
  203665. {
  203666. [super init];
  203667. [[UIApplication sharedApplication] setDelegate: self];
  203668. return self;
  203669. }
  203670. - (void) dealloc
  203671. {
  203672. [[UIApplication sharedApplication] setDelegate: nil];
  203673. [super dealloc];
  203674. }
  203675. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203676. {
  203677. if (JUCEApplication::getInstance() != 0)
  203678. {
  203679. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203680. return YES;
  203681. }
  203682. return NO;
  203683. }
  203684. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203685. {
  203686. juce_HandleProcessFocusChange();
  203687. }
  203688. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203689. {
  203690. juce_HandleProcessFocusChange();
  203691. }
  203692. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203693. {
  203694. juce_HandleProcessFocusChange();
  203695. }
  203696. - (void) customEvent: (id) n
  203697. {
  203698. NSData* data = (NSData*) n;
  203699. void* message = 0;
  203700. [data getBytes: &message length: sizeof (message)];
  203701. [data release];
  203702. if (message != 0)
  203703. MessageManager::getInstance()->deliverMessage (message);
  203704. }
  203705. - (void) performCallback: (id) info
  203706. {
  203707. if ([info isKindOfClass: [NSData class]])
  203708. {
  203709. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203710. if (pl != 0)
  203711. {
  203712. pl->result = (*pl->function) (pl->parameter);
  203713. pl->hasBeenExecuted = true;
  203714. }
  203715. }
  203716. else
  203717. {
  203718. jassertfalse // should never get here!
  203719. }
  203720. }
  203721. @end
  203722. BEGIN_JUCE_NAMESPACE
  203723. static JuceAppDelegate* juceAppDelegate = 0;
  203724. void MessageManager::runDispatchLoop()
  203725. {
  203726. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203727. runDispatchLoopUntil (-1);
  203728. }
  203729. void MessageManager::stopDispatchLoop()
  203730. {
  203731. exit (0); // iPhone apps get no mercy..
  203732. }
  203733. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203734. {
  203735. const ScopedAutoReleasePool pool;
  203736. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203737. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203738. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203739. while (! quitMessagePosted)
  203740. {
  203741. const ScopedAutoReleasePool pool;
  203742. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203743. beforeDate: endDate];
  203744. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203745. break;
  203746. }
  203747. return ! quitMessagePosted;
  203748. }
  203749. static CFRunLoopRef runLoop = 0;
  203750. static CFRunLoopSourceRef runLoopSource = 0;
  203751. static Array <void*, CriticalSection>* pendingMessages = 0;
  203752. static void runLoopSourceCallback (void*)
  203753. {
  203754. if (pendingMessages != 0)
  203755. {
  203756. int numDispatched = 0;
  203757. do
  203758. {
  203759. void* const nextMessage = pendingMessages->remove (0);
  203760. if (nextMessage == 0)
  203761. return;
  203762. const ScopedAutoReleasePool pool;
  203763. MessageManager::getInstance()->deliverMessage (nextMessage);
  203764. } while (++numDispatched <= 4);
  203765. CFRunLoopSourceSignal (runLoopSource);
  203766. CFRunLoopWakeUp (runLoop);
  203767. }
  203768. }
  203769. void MessageManager::doPlatformSpecificInitialisation()
  203770. {
  203771. pendingMessages = new Array <void*, CriticalSection>();
  203772. runLoop = CFRunLoopGetCurrent();
  203773. CFRunLoopSourceContext sourceContext;
  203774. zerostruct (sourceContext);
  203775. sourceContext.perform = runLoopSourceCallback;
  203776. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203777. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203778. if (juceAppDelegate == 0)
  203779. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203780. }
  203781. void MessageManager::doPlatformSpecificShutdown()
  203782. {
  203783. CFRunLoopSourceInvalidate (runLoopSource);
  203784. CFRelease (runLoopSource);
  203785. runLoopSource = 0;
  203786. if (pendingMessages != 0)
  203787. {
  203788. while (pendingMessages->size() > 0)
  203789. delete ((Message*) pendingMessages->remove(0));
  203790. deleteAndZero (pendingMessages);
  203791. }
  203792. if (juceAppDelegate != 0)
  203793. {
  203794. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203795. [juceAppDelegate release];
  203796. juceAppDelegate = 0;
  203797. }
  203798. }
  203799. bool juce_postMessageToSystemQueue (void* message)
  203800. {
  203801. if (pendingMessages != 0)
  203802. {
  203803. pendingMessages->add (message);
  203804. CFRunLoopSourceSignal (runLoopSource);
  203805. CFRunLoopWakeUp (runLoop);
  203806. }
  203807. return true;
  203808. }
  203809. void MessageManager::broadcastMessage (const String& value) throw()
  203810. {
  203811. }
  203812. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203813. void* data)
  203814. {
  203815. if (isThisTheMessageThread())
  203816. {
  203817. return (*callback) (data);
  203818. }
  203819. else
  203820. {
  203821. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203822. // deadlock because the message manager is blocked from running, so can never
  203823. // call your function..
  203824. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203825. const ScopedAutoReleasePool pool;
  203826. CallbackMessagePayload cmp;
  203827. cmp.function = callback;
  203828. cmp.parameter = data;
  203829. cmp.result = 0;
  203830. cmp.hasBeenExecuted = false;
  203831. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203832. withObject: [NSData dataWithBytesNoCopy: &cmp
  203833. length: sizeof (cmp)
  203834. freeWhenDone: NO]
  203835. waitUntilDone: YES];
  203836. return cmp.result;
  203837. }
  203838. }
  203839. #endif
  203840. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203841. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203842. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203843. // compiled on its own).
  203844. #if JUCE_INCLUDED_FILE
  203845. #if JUCE_MAC
  203846. END_JUCE_NAMESPACE
  203847. using namespace JUCE_NAMESPACE;
  203848. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203849. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203850. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203851. #else
  203852. @interface JuceFileChooserDelegate : NSObject
  203853. #endif
  203854. {
  203855. StringArray* filters;
  203856. }
  203857. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203858. - (void) dealloc;
  203859. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203860. @end
  203861. @implementation JuceFileChooserDelegate
  203862. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203863. {
  203864. [super init];
  203865. filters = filters_;
  203866. return self;
  203867. }
  203868. - (void) dealloc
  203869. {
  203870. delete filters;
  203871. [super dealloc];
  203872. }
  203873. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203874. {
  203875. const File f (nsStringToJuce (filename));
  203876. for (int i = filters->size(); --i >= 0;)
  203877. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203878. return true;
  203879. return f.isDirectory();
  203880. }
  203881. @end
  203882. BEGIN_JUCE_NAMESPACE
  203883. void FileChooser::showPlatformDialog (Array<File>& results,
  203884. const String& title,
  203885. const File& currentFileOrDirectory,
  203886. const String& filter,
  203887. bool selectsDirectory,
  203888. bool selectsFiles,
  203889. bool isSaveDialogue,
  203890. bool warnAboutOverwritingExistingFiles,
  203891. bool selectMultipleFiles,
  203892. FilePreviewComponent* extraInfoComponent)
  203893. {
  203894. const ScopedAutoReleasePool pool;
  203895. StringArray* filters = new StringArray();
  203896. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  203897. filters->trim();
  203898. filters->removeEmptyStrings();
  203899. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203900. [delegate autorelease];
  203901. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203902. : [NSOpenPanel openPanel];
  203903. [panel setTitle: juceStringToNS (title)];
  203904. if (! isSaveDialogue)
  203905. {
  203906. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203907. [openPanel setCanChooseDirectories: selectsDirectory];
  203908. [openPanel setCanChooseFiles: selectsFiles];
  203909. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203910. }
  203911. [panel setDelegate: delegate];
  203912. if (isSaveDialogue || selectsDirectory)
  203913. [panel setCanCreateDirectories: YES];
  203914. String directory, filename;
  203915. if (currentFileOrDirectory.isDirectory())
  203916. {
  203917. directory = currentFileOrDirectory.getFullPathName();
  203918. }
  203919. else
  203920. {
  203921. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203922. filename = currentFileOrDirectory.getFileName();
  203923. }
  203924. if ([panel runModalForDirectory: juceStringToNS (directory)
  203925. file: juceStringToNS (filename)]
  203926. == NSOKButton)
  203927. {
  203928. if (isSaveDialogue)
  203929. {
  203930. results.add (File (nsStringToJuce ([panel filename])));
  203931. }
  203932. else
  203933. {
  203934. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203935. NSArray* urls = [openPanel filenames];
  203936. for (unsigned int i = 0; i < [urls count]; ++i)
  203937. {
  203938. NSString* f = [urls objectAtIndex: i];
  203939. results.add (File (nsStringToJuce (f)));
  203940. }
  203941. }
  203942. }
  203943. [panel setDelegate: nil];
  203944. }
  203945. #else
  203946. void FileChooser::showPlatformDialog (Array<File>& results,
  203947. const String& title,
  203948. const File& currentFileOrDirectory,
  203949. const String& filter,
  203950. bool selectsDirectory,
  203951. bool selectsFiles,
  203952. bool isSaveDialogue,
  203953. bool warnAboutOverwritingExistingFiles,
  203954. bool selectMultipleFiles,
  203955. FilePreviewComponent* extraInfoComponent)
  203956. {
  203957. const ScopedAutoReleasePool pool;
  203958. jassertfalse //xxx to do
  203959. }
  203960. #endif
  203961. #endif
  203962. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203963. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203964. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203965. // compiled on its own).
  203966. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203967. #if JUCE_MAC
  203968. END_JUCE_NAMESPACE
  203969. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203970. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203971. {
  203972. CriticalSection* contextLock;
  203973. bool needsUpdate;
  203974. }
  203975. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203976. - (bool) makeActive;
  203977. - (void) makeInactive;
  203978. - (void) reshape;
  203979. @end
  203980. @implementation ThreadSafeNSOpenGLView
  203981. - (id) initWithFrame: (NSRect) frameRect
  203982. pixelFormat: (NSOpenGLPixelFormat*) format
  203983. {
  203984. contextLock = new CriticalSection();
  203985. self = [super initWithFrame: frameRect pixelFormat: format];
  203986. if (self != nil)
  203987. [[NSNotificationCenter defaultCenter] addObserver: self
  203988. selector: @selector (_surfaceNeedsUpdate:)
  203989. name: NSViewGlobalFrameDidChangeNotification
  203990. object: self];
  203991. return self;
  203992. }
  203993. - (void) dealloc
  203994. {
  203995. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203996. delete contextLock;
  203997. [super dealloc];
  203998. }
  203999. - (bool) makeActive
  204000. {
  204001. const ScopedLock sl (*contextLock);
  204002. if ([self openGLContext] == 0)
  204003. return false;
  204004. [[self openGLContext] makeCurrentContext];
  204005. if (needsUpdate)
  204006. {
  204007. [super update];
  204008. needsUpdate = false;
  204009. }
  204010. return true;
  204011. }
  204012. - (void) makeInactive
  204013. {
  204014. const ScopedLock sl (*contextLock);
  204015. [NSOpenGLContext clearCurrentContext];
  204016. }
  204017. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  204018. {
  204019. const ScopedLock sl (*contextLock);
  204020. needsUpdate = true;
  204021. }
  204022. - (void) update
  204023. {
  204024. const ScopedLock sl (*contextLock);
  204025. needsUpdate = true;
  204026. }
  204027. - (void) reshape
  204028. {
  204029. const ScopedLock sl (*contextLock);
  204030. needsUpdate = true;
  204031. }
  204032. @end
  204033. BEGIN_JUCE_NAMESPACE
  204034. class WindowedGLContext : public OpenGLContext
  204035. {
  204036. public:
  204037. WindowedGLContext (Component* const component,
  204038. const OpenGLPixelFormat& pixelFormat_,
  204039. NSOpenGLContext* sharedContext)
  204040. : renderContext (0),
  204041. pixelFormat (pixelFormat_)
  204042. {
  204043. jassert (component != 0);
  204044. NSOpenGLPixelFormatAttribute attribs [64];
  204045. int n = 0;
  204046. attribs[n++] = NSOpenGLPFADoubleBuffer;
  204047. attribs[n++] = NSOpenGLPFAAccelerated;
  204048. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  204049. attribs[n++] = NSOpenGLPFAColorSize;
  204050. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  204051. pixelFormat.greenBits,
  204052. pixelFormat.blueBits);
  204053. attribs[n++] = NSOpenGLPFAAlphaSize;
  204054. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  204055. attribs[n++] = NSOpenGLPFADepthSize;
  204056. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  204057. attribs[n++] = NSOpenGLPFAStencilSize;
  204058. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  204059. attribs[n++] = NSOpenGLPFAAccumSize;
  204060. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  204061. pixelFormat.accumulationBufferGreenBits,
  204062. pixelFormat.accumulationBufferBlueBits,
  204063. pixelFormat.accumulationBufferAlphaBits);
  204064. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  204065. attribs[n++] = NSOpenGLPFASampleBuffers;
  204066. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  204067. attribs[n++] = NSOpenGLPFAClosestPolicy;
  204068. attribs[n++] = NSOpenGLPFANoRecovery;
  204069. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  204070. NSOpenGLPixelFormat* format
  204071. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  204072. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204073. pixelFormat: format];
  204074. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  204075. shareContext: sharedContext] autorelease];
  204076. const GLint swapInterval = 1;
  204077. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  204078. [view setOpenGLContext: renderContext];
  204079. [renderContext setView: view];
  204080. [format release];
  204081. viewHolder = new NSViewComponentInternal (view, component);
  204082. }
  204083. ~WindowedGLContext()
  204084. {
  204085. makeInactive();
  204086. [renderContext clearDrawable];
  204087. viewHolder = 0;
  204088. }
  204089. bool makeActive() const throw()
  204090. {
  204091. jassert (renderContext != 0);
  204092. [view makeActive];
  204093. return isActive();
  204094. }
  204095. bool makeInactive() const throw()
  204096. {
  204097. [view makeInactive];
  204098. return true;
  204099. }
  204100. bool isActive() const throw()
  204101. {
  204102. return [NSOpenGLContext currentContext] == renderContext;
  204103. }
  204104. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204105. void* getRawContext() const throw() { return renderContext; }
  204106. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204107. {
  204108. }
  204109. void swapBuffers()
  204110. {
  204111. [renderContext flushBuffer];
  204112. }
  204113. bool setSwapInterval (const int numFramesPerSwap)
  204114. {
  204115. [renderContext setValues: (const GLint*) &numFramesPerSwap
  204116. forParameter: NSOpenGLCPSwapInterval];
  204117. return true;
  204118. }
  204119. int getSwapInterval() const
  204120. {
  204121. GLint numFrames = 0;
  204122. [renderContext getValues: &numFrames
  204123. forParameter: NSOpenGLCPSwapInterval];
  204124. return numFrames;
  204125. }
  204126. void repaint()
  204127. {
  204128. // we need to invalidate the juce view that holds this gl view, to make it
  204129. // cause a repaint callback
  204130. NSView* v = (NSView*) viewHolder->view;
  204131. NSRect r = [v frame];
  204132. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204133. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204134. // repaint message, thus never causing our paint() callback, and never repainting
  204135. // the comp. So invalidating just a little bit around the edge helps..
  204136. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204137. }
  204138. void* getNativeWindowHandle() const { return viewHolder->view; }
  204139. juce_UseDebuggingNewOperator
  204140. NSOpenGLContext* renderContext;
  204141. ThreadSafeNSOpenGLView* view;
  204142. private:
  204143. OpenGLPixelFormat pixelFormat;
  204144. ScopedPointer <NSViewComponentInternal> viewHolder;
  204145. WindowedGLContext (const WindowedGLContext&);
  204146. const WindowedGLContext& operator= (const WindowedGLContext&);
  204147. };
  204148. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204149. const OpenGLPixelFormat& pixelFormat,
  204150. const OpenGLContext* const contextToShareWith)
  204151. {
  204152. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204153. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204154. return (c->renderContext != 0) ? c.release() : 0;
  204155. }
  204156. void* OpenGLComponent::getNativeWindowHandle() const
  204157. {
  204158. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204159. : 0;
  204160. }
  204161. void juce_glViewport (const int w, const int h)
  204162. {
  204163. glViewport (0, 0, w, h);
  204164. }
  204165. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204166. OwnedArray <OpenGLPixelFormat>& results)
  204167. {
  204168. /* GLint attribs [64];
  204169. int n = 0;
  204170. attribs[n++] = AGL_RGBA;
  204171. attribs[n++] = AGL_DOUBLEBUFFER;
  204172. attribs[n++] = AGL_ACCELERATED;
  204173. attribs[n++] = AGL_NO_RECOVERY;
  204174. attribs[n++] = AGL_NONE;
  204175. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204176. while (p != 0)
  204177. {
  204178. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204179. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204180. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204181. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204182. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204183. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204184. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204185. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204186. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204187. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204188. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204189. results.add (pf);
  204190. p = aglNextPixelFormat (p);
  204191. }*/
  204192. //jassertfalse //xxx can't see how you do this in cocoa!
  204193. }
  204194. #else
  204195. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204196. const OpenGLPixelFormat& pixelFormat,
  204197. const OpenGLContext* const contextToShareWith)
  204198. {
  204199. return 0;
  204200. }
  204201. void juce_glViewport (const int w, const int h)
  204202. {
  204203. //glViewport (0, 0, w, h);
  204204. }
  204205. #endif
  204206. #endif
  204207. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204208. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204209. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204210. // compiled on its own).
  204211. #if JUCE_INCLUDED_FILE
  204212. #if JUCE_MAC
  204213. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204214. {
  204215. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204216. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204217. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204218. [im release];
  204219. return (void*) c;
  204220. }
  204221. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204222. {
  204223. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204224. jassert (im != 0);
  204225. if (im == 0)
  204226. return 0;
  204227. return juce_createMouseCursorFromImage (*im,
  204228. (int) (hx * im->getWidth()),
  204229. (int) (hy * im->getHeight()));
  204230. }
  204231. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204232. {
  204233. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204234. MemoryBlock mb;
  204235. if (f.getChildFile (filename).loadFileAsData (mb))
  204236. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204237. return 0;
  204238. }
  204239. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204240. {
  204241. const ScopedAutoReleasePool pool;
  204242. NSCursor* c = 0;
  204243. switch (type)
  204244. {
  204245. case MouseCursor::NormalCursor:
  204246. c = [NSCursor arrowCursor];
  204247. break;
  204248. case MouseCursor::NoCursor:
  204249. {
  204250. Image blank (Image::ARGB, 8, 8, true);
  204251. return juce_createMouseCursorFromImage (blank, 0, 0);
  204252. }
  204253. case MouseCursor::DraggingHandCursor:
  204254. c = [NSCursor openHandCursor];
  204255. break;
  204256. case MouseCursor::CopyingCursor:
  204257. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204258. case MouseCursor::WaitCursor:
  204259. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204260. break;
  204261. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204262. case MouseCursor::IBeamCursor:
  204263. c = [NSCursor IBeamCursor];
  204264. break;
  204265. case MouseCursor::PointingHandCursor:
  204266. c = [NSCursor pointingHandCursor];
  204267. break;
  204268. case MouseCursor::LeftRightResizeCursor:
  204269. c = [NSCursor resizeLeftRightCursor];
  204270. break;
  204271. case MouseCursor::LeftEdgeResizeCursor:
  204272. c = [NSCursor resizeLeftCursor];
  204273. break;
  204274. case MouseCursor::RightEdgeResizeCursor:
  204275. c = [NSCursor resizeRightCursor];
  204276. break;
  204277. case MouseCursor::UpDownResizeCursor:
  204278. case MouseCursor::TopEdgeResizeCursor:
  204279. case MouseCursor::BottomEdgeResizeCursor:
  204280. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204281. case MouseCursor::TopLeftCornerResizeCursor:
  204282. case MouseCursor::BottomRightCornerResizeCursor:
  204283. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204284. case MouseCursor::TopRightCornerResizeCursor:
  204285. case MouseCursor::BottomLeftCornerResizeCursor:
  204286. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204287. case MouseCursor::UpDownLeftRightResizeCursor:
  204288. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204289. case MouseCursor::CrosshairCursor:
  204290. c = [NSCursor crosshairCursor];
  204291. break;
  204292. }
  204293. [c retain];
  204294. return (void*) c;
  204295. }
  204296. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204297. {
  204298. NSCursor* c = (NSCursor*) cursorHandle;
  204299. [c release];
  204300. }
  204301. void MouseCursor::showInAllWindows() const throw()
  204302. {
  204303. showInWindow (0);
  204304. }
  204305. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204306. {
  204307. NSCursor* const c = (NSCursor*) getHandle();
  204308. [c set];
  204309. }
  204310. #else
  204311. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204312. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204313. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204314. void MouseCursor::showInAllWindows() const throw() {}
  204315. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204316. #endif
  204317. #endif
  204318. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204319. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204320. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204321. // compiled on its own).
  204322. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204323. #if JUCE_MAC
  204324. END_JUCE_NAMESPACE
  204325. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204326. @interface DownloadClickDetector : NSObject
  204327. {
  204328. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204329. }
  204330. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204331. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204332. request: (NSURLRequest*) request
  204333. frame: (WebFrame*) frame
  204334. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204335. @end
  204336. @implementation DownloadClickDetector
  204337. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204338. {
  204339. [super init];
  204340. ownerComponent = ownerComponent_;
  204341. return self;
  204342. }
  204343. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204344. request: (NSURLRequest*) request
  204345. frame: (WebFrame*) frame
  204346. decisionListener: (id <WebPolicyDecisionListener>) listener
  204347. {
  204348. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204349. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204350. [listener use];
  204351. else
  204352. [listener ignore];
  204353. }
  204354. @end
  204355. BEGIN_JUCE_NAMESPACE
  204356. class WebBrowserComponentInternal : public NSViewComponent
  204357. {
  204358. public:
  204359. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204360. {
  204361. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204362. frameName: @""
  204363. groupName: @""];
  204364. setView (webView);
  204365. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204366. [webView setPolicyDelegate: clickListener];
  204367. }
  204368. ~WebBrowserComponentInternal()
  204369. {
  204370. [webView setPolicyDelegate: nil];
  204371. [clickListener release];
  204372. setView (0);
  204373. }
  204374. void goToURL (const String& url,
  204375. const StringArray* headers,
  204376. const MemoryBlock* postData)
  204377. {
  204378. NSMutableURLRequest* r
  204379. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204380. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204381. timeoutInterval: 30.0];
  204382. if (postData != 0 && postData->getSize() > 0)
  204383. {
  204384. [r setHTTPMethod: @"POST"];
  204385. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204386. length: postData->getSize()]];
  204387. }
  204388. if (headers != 0)
  204389. {
  204390. for (int i = 0; i < headers->size(); ++i)
  204391. {
  204392. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204393. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204394. [r setValue: juceStringToNS (headerValue)
  204395. forHTTPHeaderField: juceStringToNS (headerName)];
  204396. }
  204397. }
  204398. stop();
  204399. [[webView mainFrame] loadRequest: r];
  204400. }
  204401. void goBack()
  204402. {
  204403. [webView goBack];
  204404. }
  204405. void goForward()
  204406. {
  204407. [webView goForward];
  204408. }
  204409. void stop()
  204410. {
  204411. [webView stopLoading: nil];
  204412. }
  204413. void refresh()
  204414. {
  204415. [webView reload: nil];
  204416. }
  204417. private:
  204418. WebView* webView;
  204419. DownloadClickDetector* clickListener;
  204420. };
  204421. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204422. : browser (0),
  204423. blankPageShown (false),
  204424. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204425. {
  204426. setOpaque (true);
  204427. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204428. }
  204429. WebBrowserComponent::~WebBrowserComponent()
  204430. {
  204431. deleteAndZero (browser);
  204432. }
  204433. void WebBrowserComponent::goToURL (const String& url,
  204434. const StringArray* headers,
  204435. const MemoryBlock* postData)
  204436. {
  204437. lastURL = url;
  204438. lastHeaders.clear();
  204439. if (headers != 0)
  204440. lastHeaders = *headers;
  204441. lastPostData.setSize (0);
  204442. if (postData != 0)
  204443. lastPostData = *postData;
  204444. blankPageShown = false;
  204445. browser->goToURL (url, headers, postData);
  204446. }
  204447. void WebBrowserComponent::stop()
  204448. {
  204449. browser->stop();
  204450. }
  204451. void WebBrowserComponent::goBack()
  204452. {
  204453. lastURL = String::empty;
  204454. blankPageShown = false;
  204455. browser->goBack();
  204456. }
  204457. void WebBrowserComponent::goForward()
  204458. {
  204459. lastURL = String::empty;
  204460. browser->goForward();
  204461. }
  204462. void WebBrowserComponent::refresh()
  204463. {
  204464. browser->refresh();
  204465. }
  204466. void WebBrowserComponent::paint (Graphics& g)
  204467. {
  204468. }
  204469. void WebBrowserComponent::checkWindowAssociation()
  204470. {
  204471. if (isShowing())
  204472. {
  204473. if (blankPageShown)
  204474. goBack();
  204475. }
  204476. else
  204477. {
  204478. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204479. {
  204480. // when the component becomes invisible, some stuff like flash
  204481. // carries on playing audio, so we need to force it onto a blank
  204482. // page to avoid this, (and send it back when it's made visible again).
  204483. blankPageShown = true;
  204484. browser->goToURL ("about:blank", 0, 0);
  204485. }
  204486. }
  204487. }
  204488. void WebBrowserComponent::reloadLastURL()
  204489. {
  204490. if (lastURL.isNotEmpty())
  204491. {
  204492. goToURL (lastURL, &lastHeaders, &lastPostData);
  204493. lastURL = String::empty;
  204494. }
  204495. }
  204496. void WebBrowserComponent::parentHierarchyChanged()
  204497. {
  204498. checkWindowAssociation();
  204499. }
  204500. void WebBrowserComponent::resized()
  204501. {
  204502. browser->setSize (getWidth(), getHeight());
  204503. }
  204504. void WebBrowserComponent::visibilityChanged()
  204505. {
  204506. checkWindowAssociation();
  204507. }
  204508. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204509. {
  204510. return true;
  204511. }
  204512. #else
  204513. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204514. {
  204515. }
  204516. WebBrowserComponent::~WebBrowserComponent()
  204517. {
  204518. }
  204519. void WebBrowserComponent::goToURL (const String& url,
  204520. const StringArray* headers,
  204521. const MemoryBlock* postData)
  204522. {
  204523. }
  204524. void WebBrowserComponent::stop()
  204525. {
  204526. }
  204527. void WebBrowserComponent::goBack()
  204528. {
  204529. }
  204530. void WebBrowserComponent::goForward()
  204531. {
  204532. }
  204533. void WebBrowserComponent::refresh()
  204534. {
  204535. }
  204536. void WebBrowserComponent::paint (Graphics& g)
  204537. {
  204538. }
  204539. void WebBrowserComponent::checkWindowAssociation()
  204540. {
  204541. }
  204542. void WebBrowserComponent::reloadLastURL()
  204543. {
  204544. }
  204545. void WebBrowserComponent::parentHierarchyChanged()
  204546. {
  204547. }
  204548. void WebBrowserComponent::resized()
  204549. {
  204550. }
  204551. void WebBrowserComponent::visibilityChanged()
  204552. {
  204553. }
  204554. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204555. {
  204556. return true;
  204557. }
  204558. #endif
  204559. #endif
  204560. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204561. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204562. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204563. // compiled on its own).
  204564. #if JUCE_INCLUDED_FILE
  204565. class IPhoneAudioIODevice : public AudioIODevice
  204566. {
  204567. public:
  204568. IPhoneAudioIODevice (const String& deviceName)
  204569. : AudioIODevice (deviceName, T("Audio")),
  204570. audioUnit (0),
  204571. isRunning (false),
  204572. callback (0),
  204573. actualBufferSize (0),
  204574. floatData (1, 2)
  204575. {
  204576. numInputChannels = 2;
  204577. numOutputChannels = 2;
  204578. preferredBufferSize = 0;
  204579. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204580. updateDeviceInfo();
  204581. }
  204582. ~IPhoneAudioIODevice()
  204583. {
  204584. close();
  204585. }
  204586. const StringArray getOutputChannelNames()
  204587. {
  204588. StringArray s;
  204589. s.add ("Left");
  204590. s.add ("Right");
  204591. return s;
  204592. }
  204593. const StringArray getInputChannelNames()
  204594. {
  204595. StringArray s;
  204596. if (audioInputIsAvailable)
  204597. {
  204598. s.add ("Left");
  204599. s.add ("Right");
  204600. }
  204601. return s;
  204602. }
  204603. int getNumSampleRates()
  204604. {
  204605. return 1;
  204606. }
  204607. double getSampleRate (int index)
  204608. {
  204609. return sampleRate;
  204610. }
  204611. int getNumBufferSizesAvailable()
  204612. {
  204613. return 1;
  204614. }
  204615. int getBufferSizeSamples (int index)
  204616. {
  204617. return getDefaultBufferSize();
  204618. }
  204619. int getDefaultBufferSize()
  204620. {
  204621. return 1024;
  204622. }
  204623. const String open (const BitArray& inputChannels,
  204624. const BitArray& outputChannels,
  204625. double sampleRate,
  204626. int bufferSize)
  204627. {
  204628. close();
  204629. lastError = String::empty;
  204630. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204631. // xxx set up channel mapping
  204632. activeOutputChans = outputChannels;
  204633. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204634. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204635. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204636. activeInputChans = inputChannels;
  204637. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204638. numInputChannels = activeInputChans.countNumberOfSetBits();
  204639. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204640. AudioSessionSetActive (true);
  204641. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204642. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204643. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204644. fixAudioRouteIfSetToReceiver();
  204645. updateDeviceInfo();
  204646. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204647. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204648. actualBufferSize = preferredBufferSize;
  204649. prepareFloatBuffers();
  204650. isRunning = true;
  204651. propertyChanged (0, 0, 0); // creates and starts the AU
  204652. lastError = audioUnit != 0 ? String::empty
  204653. : T("Couldn't open the device");
  204654. return lastError;
  204655. }
  204656. void close()
  204657. {
  204658. if (isRunning)
  204659. {
  204660. isRunning = false;
  204661. AudioSessionSetActive (false);
  204662. if (audioUnit != 0)
  204663. {
  204664. AudioComponentInstanceDispose (audioUnit);
  204665. audioUnit = 0;
  204666. }
  204667. }
  204668. }
  204669. bool isOpen()
  204670. {
  204671. return isRunning;
  204672. }
  204673. int getCurrentBufferSizeSamples()
  204674. {
  204675. return actualBufferSize;
  204676. }
  204677. double getCurrentSampleRate()
  204678. {
  204679. return sampleRate;
  204680. }
  204681. int getCurrentBitDepth()
  204682. {
  204683. return 16;
  204684. }
  204685. const BitArray getActiveOutputChannels() const
  204686. {
  204687. return activeOutputChans;
  204688. }
  204689. const BitArray getActiveInputChannels() const
  204690. {
  204691. return activeInputChans;
  204692. }
  204693. int getOutputLatencyInSamples()
  204694. {
  204695. return 0; //xxx
  204696. }
  204697. int getInputLatencyInSamples()
  204698. {
  204699. return 0; //xxx
  204700. }
  204701. void start (AudioIODeviceCallback* callback_)
  204702. {
  204703. if (isRunning && callback != callback_)
  204704. {
  204705. if (callback_ != 0)
  204706. callback_->audioDeviceAboutToStart (this);
  204707. callbackLock.enter();
  204708. callback = callback_;
  204709. callbackLock.exit();
  204710. }
  204711. }
  204712. void stop()
  204713. {
  204714. if (isRunning)
  204715. {
  204716. callbackLock.enter();
  204717. AudioIODeviceCallback* const lastCallback = callback;
  204718. callback = 0;
  204719. callbackLock.exit();
  204720. if (lastCallback != 0)
  204721. lastCallback->audioDeviceStopped();
  204722. }
  204723. }
  204724. bool isPlaying()
  204725. {
  204726. return isRunning && callback != 0;
  204727. }
  204728. const String getLastError()
  204729. {
  204730. return lastError;
  204731. }
  204732. private:
  204733. CriticalSection callbackLock;
  204734. Float64 sampleRate;
  204735. int numInputChannels, numOutputChannels;
  204736. int preferredBufferSize;
  204737. int actualBufferSize;
  204738. bool isRunning;
  204739. String lastError;
  204740. AudioStreamBasicDescription format;
  204741. AudioUnit audioUnit;
  204742. UInt32 audioInputIsAvailable;
  204743. AudioIODeviceCallback* callback;
  204744. BitArray activeOutputChans, activeInputChans;
  204745. AudioSampleBuffer floatData;
  204746. float* inputChannels[3];
  204747. float* outputChannels[3];
  204748. bool monoInputChannelNumber, monoOutputChannelNumber;
  204749. void prepareFloatBuffers()
  204750. {
  204751. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204752. zerostruct (inputChannels);
  204753. zerostruct (outputChannels);
  204754. for (int i = 0; i < numInputChannels; ++i)
  204755. inputChannels[i] = floatData.getSampleData (i);
  204756. for (int i = 0; i < numOutputChannels; ++i)
  204757. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204758. }
  204759. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204760. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204761. {
  204762. OSStatus err = noErr;
  204763. if (audioInputIsAvailable)
  204764. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204765. const ScopedLock sl (callbackLock);
  204766. if (callback != 0)
  204767. {
  204768. if (audioInputIsAvailable && numInputChannels > 0)
  204769. {
  204770. short* shortData = (short*) ioData->mBuffers[0].mData;
  204771. if (numInputChannels >= 2)
  204772. {
  204773. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204774. {
  204775. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204776. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204777. }
  204778. }
  204779. else
  204780. {
  204781. if (monoInputChannelNumber > 0)
  204782. ++shortData;
  204783. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204784. {
  204785. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204786. ++shortData;
  204787. }
  204788. }
  204789. }
  204790. else
  204791. {
  204792. for (int i = numInputChannels; --i >= 0;)
  204793. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204794. }
  204795. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204796. outputChannels, numOutputChannels,
  204797. (int) inNumberFrames);
  204798. short* shortData = (short*) ioData->mBuffers[0].mData;
  204799. int n = 0;
  204800. if (numOutputChannels >= 2)
  204801. {
  204802. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204803. {
  204804. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204805. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204806. }
  204807. }
  204808. else if (numOutputChannels == 1)
  204809. {
  204810. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204811. {
  204812. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204813. shortData [n++] = s;
  204814. shortData [n++] = s;
  204815. }
  204816. }
  204817. else
  204818. {
  204819. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204820. }
  204821. }
  204822. else
  204823. {
  204824. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204825. }
  204826. return err;
  204827. }
  204828. void updateDeviceInfo()
  204829. {
  204830. UInt32 size = sizeof (sampleRate);
  204831. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204832. size = sizeof (audioInputIsAvailable);
  204833. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204834. }
  204835. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204836. {
  204837. if (! isRunning)
  204838. return;
  204839. if (inPropertyValue != 0)
  204840. {
  204841. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204842. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204843. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204844. SInt32 routeChangeReason;
  204845. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204846. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204847. fixAudioRouteIfSetToReceiver();
  204848. }
  204849. updateDeviceInfo();
  204850. createAudioUnit();
  204851. AudioSessionSetActive (true);
  204852. if (audioUnit != 0)
  204853. {
  204854. UInt32 formatSize = sizeof (format);
  204855. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204856. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204857. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204858. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204859. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204860. AudioOutputUnitStart (audioUnit);
  204861. }
  204862. }
  204863. void interruptionListener (UInt32 inInterruption)
  204864. {
  204865. if (inInterruption == kAudioSessionEndInterruption)
  204866. {
  204867. isRunning = true;
  204868. AudioSessionSetActive (true);
  204869. AudioOutputUnitStart (audioUnit);
  204870. }
  204871. }
  204872. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204873. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204874. {
  204875. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204876. }
  204877. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204878. {
  204879. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204880. }
  204881. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204882. {
  204883. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204884. }
  204885. void resetFormat (const int numChannels)
  204886. {
  204887. memset (&format, 0, sizeof (format));
  204888. format.mFormatID = kAudioFormatLinearPCM;
  204889. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204890. format.mBitsPerChannel = 8 * sizeof (short);
  204891. format.mChannelsPerFrame = 2;
  204892. format.mFramesPerPacket = 1;
  204893. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204894. }
  204895. bool createAudioUnit()
  204896. {
  204897. if (audioUnit != 0)
  204898. {
  204899. AudioComponentInstanceDispose (audioUnit);
  204900. audioUnit = 0;
  204901. }
  204902. resetFormat (2);
  204903. AudioComponentDescription desc;
  204904. desc.componentType = kAudioUnitType_Output;
  204905. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204906. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204907. desc.componentFlags = 0;
  204908. desc.componentFlagsMask = 0;
  204909. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204910. AudioComponentInstanceNew (comp, &audioUnit);
  204911. if (audioUnit == 0)
  204912. return false;
  204913. const UInt32 one = 1;
  204914. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204915. AudioChannelLayout layout;
  204916. layout.mChannelBitmap = 0;
  204917. layout.mNumberChannelDescriptions = 0;
  204918. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204919. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204920. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204921. AURenderCallbackStruct inputProc;
  204922. inputProc.inputProc = processStatic;
  204923. inputProc.inputProcRefCon = this;
  204924. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204925. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204926. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204927. AudioUnitInitialize (audioUnit);
  204928. return true;
  204929. }
  204930. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204931. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204932. static void fixAudioRouteIfSetToReceiver()
  204933. {
  204934. CFStringRef audioRoute = 0;
  204935. UInt32 propertySize = sizeof (audioRoute);
  204936. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204937. {
  204938. NSString* route = (NSString*) audioRoute;
  204939. //DBG ("audio route: " + nsStringToJuce (route));
  204940. if ([route hasPrefix: @"Receiver"])
  204941. {
  204942. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204943. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204944. }
  204945. CFRelease (audioRoute);
  204946. }
  204947. }
  204948. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204949. const IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204950. };
  204951. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204952. {
  204953. public:
  204954. IPhoneAudioIODeviceType()
  204955. : AudioIODeviceType (T("iPhone Audio"))
  204956. {
  204957. }
  204958. ~IPhoneAudioIODeviceType()
  204959. {
  204960. }
  204961. void scanForDevices()
  204962. {
  204963. }
  204964. const StringArray getDeviceNames (const bool wantInputNames) const
  204965. {
  204966. StringArray s;
  204967. s.add ("iPhone Audio");
  204968. return s;
  204969. }
  204970. int getDefaultDeviceIndex (const bool forInput) const
  204971. {
  204972. return 0;
  204973. }
  204974. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204975. {
  204976. return device != 0 ? 0 : -1;
  204977. }
  204978. bool hasSeparateInputsAndOutputs() const { return false; }
  204979. AudioIODevice* createDevice (const String& outputDeviceName,
  204980. const String& inputDeviceName)
  204981. {
  204982. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204983. {
  204984. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204985. : inputDeviceName);
  204986. }
  204987. return 0;
  204988. }
  204989. juce_UseDebuggingNewOperator
  204990. private:
  204991. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204992. const IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204993. };
  204994. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204995. {
  204996. return new IPhoneAudioIODeviceType();
  204997. }
  204998. #endif
  204999. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  205000. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  205001. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205002. // compiled on its own).
  205003. #if JUCE_INCLUDED_FILE
  205004. #if JUCE_MAC
  205005. #undef log
  205006. #define log(a) Logger::writeToLog(a)
  205007. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  205008. {
  205009. if (err == noErr)
  205010. return true;
  205011. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  205012. jassertfalse
  205013. return false;
  205014. }
  205015. #undef OK
  205016. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  205017. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  205018. {
  205019. String result;
  205020. CFStringRef str = 0;
  205021. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  205022. if (str != 0)
  205023. {
  205024. result = PlatformUtilities::cfStringToJuceString (str);
  205025. CFRelease (str);
  205026. str = 0;
  205027. }
  205028. MIDIEntityRef entity = 0;
  205029. MIDIEndpointGetEntity (endpoint, &entity);
  205030. if (entity == 0)
  205031. return result; // probably virtual
  205032. if (result.isEmpty())
  205033. {
  205034. // endpoint name has zero length - try the entity
  205035. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  205036. if (str != 0)
  205037. {
  205038. result += PlatformUtilities::cfStringToJuceString (str);
  205039. CFRelease (str);
  205040. str = 0;
  205041. }
  205042. }
  205043. // now consider the device's name
  205044. MIDIDeviceRef device = 0;
  205045. MIDIEntityGetDevice (entity, &device);
  205046. if (device == 0)
  205047. return result;
  205048. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  205049. if (str != 0)
  205050. {
  205051. const String s (PlatformUtilities::cfStringToJuceString (str));
  205052. CFRelease (str);
  205053. // if an external device has only one entity, throw away
  205054. // the endpoint name and just use the device name
  205055. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  205056. {
  205057. result = s;
  205058. }
  205059. else if (! result.startsWithIgnoreCase (s))
  205060. {
  205061. // prepend the device name to the entity name
  205062. result = (s + T(" ") + result).trimEnd();
  205063. }
  205064. }
  205065. return result;
  205066. }
  205067. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  205068. {
  205069. String result;
  205070. // Does the endpoint have connections?
  205071. CFDataRef connections = 0;
  205072. int numConnections = 0;
  205073. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  205074. if (connections != 0)
  205075. {
  205076. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  205077. if (numConnections > 0)
  205078. {
  205079. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  205080. for (int i = 0; i < numConnections; ++i, ++pid)
  205081. {
  205082. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  205083. MIDIObjectRef connObject;
  205084. MIDIObjectType connObjectType;
  205085. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  205086. if (err == noErr)
  205087. {
  205088. String s;
  205089. if (connObjectType == kMIDIObjectType_ExternalSource
  205090. || connObjectType == kMIDIObjectType_ExternalDestination)
  205091. {
  205092. // Connected to an external device's endpoint (10.3 and later).
  205093. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  205094. }
  205095. else
  205096. {
  205097. // Connected to an external device (10.2) (or something else, catch-all)
  205098. CFStringRef str = 0;
  205099. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205100. if (str != 0)
  205101. {
  205102. s = PlatformUtilities::cfStringToJuceString (str);
  205103. CFRelease (str);
  205104. }
  205105. }
  205106. if (s.isNotEmpty())
  205107. {
  205108. if (result.isNotEmpty())
  205109. result += (", ");
  205110. result += s;
  205111. }
  205112. }
  205113. }
  205114. }
  205115. CFRelease (connections);
  205116. }
  205117. if (result.isNotEmpty())
  205118. return result;
  205119. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205120. return getEndpointName (endpoint, false);
  205121. }
  205122. const StringArray MidiOutput::getDevices()
  205123. {
  205124. StringArray s;
  205125. const ItemCount num = MIDIGetNumberOfDestinations();
  205126. for (ItemCount i = 0; i < num; ++i)
  205127. {
  205128. MIDIEndpointRef dest = MIDIGetDestination (i);
  205129. if (dest != 0)
  205130. {
  205131. String name (getConnectedEndpointName (dest));
  205132. if (name.isEmpty())
  205133. name = "<error>";
  205134. s.add (name);
  205135. }
  205136. else
  205137. {
  205138. s.add ("<error>");
  205139. }
  205140. }
  205141. return s;
  205142. }
  205143. int MidiOutput::getDefaultDeviceIndex()
  205144. {
  205145. return 0;
  205146. }
  205147. static MIDIClientRef globalMidiClient;
  205148. static bool hasGlobalClientBeenCreated = false;
  205149. static bool makeSureClientExists()
  205150. {
  205151. if (! hasGlobalClientBeenCreated)
  205152. {
  205153. String name (T("JUCE"));
  205154. if (JUCEApplication::getInstance() != 0)
  205155. name = JUCEApplication::getInstance()->getApplicationName();
  205156. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205157. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205158. CFRelease (appName);
  205159. }
  205160. return hasGlobalClientBeenCreated;
  205161. }
  205162. class MidiPortAndEndpoint
  205163. {
  205164. public:
  205165. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205166. : port (port_), endPoint (endPoint_)
  205167. {
  205168. }
  205169. ~MidiPortAndEndpoint()
  205170. {
  205171. if (port != 0)
  205172. MIDIPortDispose (port);
  205173. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205174. MIDIEndpointDispose (endPoint);
  205175. }
  205176. MIDIPortRef port;
  205177. MIDIEndpointRef endPoint;
  205178. };
  205179. MidiOutput* MidiOutput::openDevice (int index)
  205180. {
  205181. MidiOutput* mo = 0;
  205182. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205183. {
  205184. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205185. CFStringRef pname;
  205186. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205187. {
  205188. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205189. if (makeSureClientExists())
  205190. {
  205191. MIDIPortRef port;
  205192. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205193. {
  205194. mo = new MidiOutput();
  205195. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205196. }
  205197. }
  205198. CFRelease (pname);
  205199. }
  205200. }
  205201. return mo;
  205202. }
  205203. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205204. {
  205205. MidiOutput* mo = 0;
  205206. if (makeSureClientExists())
  205207. {
  205208. MIDIEndpointRef endPoint;
  205209. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205210. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205211. {
  205212. mo = new MidiOutput();
  205213. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205214. }
  205215. CFRelease (name);
  205216. }
  205217. return mo;
  205218. }
  205219. MidiOutput::~MidiOutput()
  205220. {
  205221. delete (MidiPortAndEndpoint*) internal;
  205222. }
  205223. void MidiOutput::reset()
  205224. {
  205225. }
  205226. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205227. {
  205228. return false;
  205229. }
  205230. void MidiOutput::setVolume (float leftVol, float rightVol)
  205231. {
  205232. }
  205233. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205234. {
  205235. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205236. if (message.isSysEx())
  205237. {
  205238. const int maxPacketSize = 256;
  205239. int pos = 0, bytesLeft = message.getRawDataSize();
  205240. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205241. HeapBlock <MIDIPacketList> packets;
  205242. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205243. packets->numPackets = numPackets;
  205244. MIDIPacket* p = packets->packet;
  205245. for (int i = 0; i < numPackets; ++i)
  205246. {
  205247. p->timeStamp = 0;
  205248. p->length = jmin (maxPacketSize, bytesLeft);
  205249. memcpy (p->data, message.getRawData() + pos, p->length);
  205250. pos += p->length;
  205251. bytesLeft -= p->length;
  205252. p = MIDIPacketNext (p);
  205253. }
  205254. if (mpe->port != 0)
  205255. MIDISend (mpe->port, mpe->endPoint, packets);
  205256. else
  205257. MIDIReceived (mpe->endPoint, packets);
  205258. }
  205259. else
  205260. {
  205261. MIDIPacketList packets;
  205262. packets.numPackets = 1;
  205263. packets.packet[0].timeStamp = 0;
  205264. packets.packet[0].length = message.getRawDataSize();
  205265. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205266. if (mpe->port != 0)
  205267. MIDISend (mpe->port, mpe->endPoint, &packets);
  205268. else
  205269. MIDIReceived (mpe->endPoint, &packets);
  205270. }
  205271. }
  205272. const StringArray MidiInput::getDevices()
  205273. {
  205274. StringArray s;
  205275. const ItemCount num = MIDIGetNumberOfSources();
  205276. for (ItemCount i = 0; i < num; ++i)
  205277. {
  205278. MIDIEndpointRef source = MIDIGetSource (i);
  205279. if (source != 0)
  205280. {
  205281. String name (getConnectedEndpointName (source));
  205282. if (name.isEmpty())
  205283. name = "<error>";
  205284. s.add (name);
  205285. }
  205286. else
  205287. {
  205288. s.add ("<error>");
  205289. }
  205290. }
  205291. return s;
  205292. }
  205293. int MidiInput::getDefaultDeviceIndex()
  205294. {
  205295. return 0;
  205296. }
  205297. struct MidiPortAndCallback
  205298. {
  205299. MidiInput* input;
  205300. MidiPortAndEndpoint* portAndEndpoint;
  205301. MidiInputCallback* callback;
  205302. MemoryBlock pendingData;
  205303. int pendingBytes;
  205304. double pendingDataTime;
  205305. bool active;
  205306. };
  205307. static CriticalSection callbackLock;
  205308. static VoidArray activeCallbacks;
  205309. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  205310. {
  205311. if (*d == 0xf0)
  205312. {
  205313. mpc->pendingBytes = 0;
  205314. mpc->pendingDataTime = time;
  205315. }
  205316. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  205317. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  205318. uint8* dest = totalMessage + mpc->pendingBytes;
  205319. while (size > 0)
  205320. {
  205321. if (mpc->pendingBytes > 0 && *d >= 0x80)
  205322. {
  205323. if (*d >= 0xfa || *d == 0xf8)
  205324. {
  205325. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  205326. ++d;
  205327. --size;
  205328. }
  205329. else
  205330. {
  205331. if (*d == 0xf7)
  205332. {
  205333. *dest++ = *d++;
  205334. mpc->pendingBytes++;
  205335. --size;
  205336. }
  205337. break;
  205338. }
  205339. }
  205340. else
  205341. {
  205342. *dest++ = *d++;
  205343. mpc->pendingBytes++;
  205344. --size;
  205345. }
  205346. }
  205347. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  205348. {
  205349. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  205350. mpc->pendingBytes,
  205351. mpc->pendingDataTime));
  205352. mpc->pendingBytes = 0;
  205353. }
  205354. else
  205355. {
  205356. mpc->callback->handlePartialSysexMessage (mpc->input,
  205357. totalMessage,
  205358. mpc->pendingBytes,
  205359. mpc->pendingDataTime);
  205360. }
  205361. }
  205362. static void midiInputProc (const MIDIPacketList* pktlist,
  205363. void* readProcRefCon,
  205364. void* srcConnRefCon)
  205365. {
  205366. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205367. const double originalTime = time;
  205368. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205369. const ScopedLock sl (callbackLock);
  205370. if (activeCallbacks.contains (mpc) && mpc->active)
  205371. {
  205372. const MIDIPacket* packet = &pktlist->packet[0];
  205373. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205374. {
  205375. const uint8* d = (const uint8*) (packet->data);
  205376. int size = packet->length;
  205377. while (size > 0)
  205378. {
  205379. time = originalTime;
  205380. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205381. {
  205382. processSysex (mpc, d, size, time);
  205383. }
  205384. else
  205385. {
  205386. int used = 0;
  205387. const MidiMessage m (d, size, used, 0, time);
  205388. if (used <= 0)
  205389. {
  205390. jassertfalse // malformed midi message
  205391. break;
  205392. }
  205393. else
  205394. {
  205395. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205396. }
  205397. size -= used;
  205398. d += used;
  205399. }
  205400. }
  205401. packet = MIDIPacketNext (packet);
  205402. }
  205403. }
  205404. }
  205405. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205406. {
  205407. MidiInput* mi = 0;
  205408. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205409. {
  205410. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205411. if (endPoint != 0)
  205412. {
  205413. CFStringRef pname;
  205414. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205415. {
  205416. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205417. if (makeSureClientExists())
  205418. {
  205419. MIDIPortRef port;
  205420. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205421. mpc->active = false;
  205422. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205423. {
  205424. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205425. {
  205426. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205427. mpc->callback = callback;
  205428. mpc->pendingBytes = 0;
  205429. mpc->pendingData.ensureSize (128);
  205430. mi = new MidiInput (getDevices() [index]);
  205431. mpc->input = mi;
  205432. mi->internal = (void*) mpc;
  205433. const ScopedLock sl (callbackLock);
  205434. activeCallbacks.add (mpc.release());
  205435. }
  205436. else
  205437. {
  205438. OK (MIDIPortDispose (port));
  205439. }
  205440. }
  205441. }
  205442. }
  205443. CFRelease (pname);
  205444. }
  205445. }
  205446. return mi;
  205447. }
  205448. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205449. {
  205450. MidiInput* mi = 0;
  205451. if (makeSureClientExists())
  205452. {
  205453. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205454. mpc->active = false;
  205455. MIDIEndpointRef endPoint;
  205456. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205457. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205458. {
  205459. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205460. mpc->callback = callback;
  205461. mpc->pendingBytes = 0;
  205462. mpc->pendingData.ensureSize (128);
  205463. mi = new MidiInput (deviceName);
  205464. mpc->input = mi;
  205465. mi->internal = (void*) mpc;
  205466. const ScopedLock sl (callbackLock);
  205467. activeCallbacks.add (mpc.release());
  205468. }
  205469. CFRelease (name);
  205470. }
  205471. return mi;
  205472. }
  205473. MidiInput::MidiInput (const String& name_)
  205474. : name (name_)
  205475. {
  205476. }
  205477. MidiInput::~MidiInput()
  205478. {
  205479. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205480. mpc->active = false;
  205481. callbackLock.enter();
  205482. activeCallbacks.removeValue (mpc);
  205483. callbackLock.exit();
  205484. if (mpc->portAndEndpoint->port != 0)
  205485. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205486. delete mpc->portAndEndpoint;
  205487. delete mpc;
  205488. }
  205489. void MidiInput::start()
  205490. {
  205491. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205492. const ScopedLock sl (callbackLock);
  205493. mpc->active = true;
  205494. }
  205495. void MidiInput::stop()
  205496. {
  205497. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205498. const ScopedLock sl (callbackLock);
  205499. mpc->active = false;
  205500. }
  205501. #undef log
  205502. #else
  205503. MidiOutput::~MidiOutput()
  205504. {
  205505. }
  205506. void MidiOutput::reset()
  205507. {
  205508. }
  205509. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205510. {
  205511. return false;
  205512. }
  205513. void MidiOutput::setVolume (float leftVol, float rightVol)
  205514. {
  205515. }
  205516. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205517. {
  205518. }
  205519. const StringArray MidiOutput::getDevices()
  205520. {
  205521. return StringArray();
  205522. }
  205523. MidiOutput* MidiOutput::openDevice (int index)
  205524. {
  205525. return 0;
  205526. }
  205527. const StringArray MidiInput::getDevices()
  205528. {
  205529. return StringArray();
  205530. }
  205531. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205532. {
  205533. return 0;
  205534. }
  205535. #endif
  205536. #endif
  205537. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205538. #else
  205539. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205540. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205541. // compiled on its own).
  205542. #if JUCE_INCLUDED_FILE
  205543. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205544. #define SUPPORT_10_4_FONTS 1
  205545. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205546. #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5) || JUCE_PPC
  205547. #define SUPPORT_ONLY_10_4_FONTS 1
  205548. #endif
  205549. END_JUCE_NAMESPACE
  205550. @interface NSFont (PrivateHack)
  205551. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205552. @end
  205553. BEGIN_JUCE_NAMESPACE
  205554. #endif
  205555. class MacTypeface : public Typeface
  205556. {
  205557. public:
  205558. MacTypeface (const Font& font)
  205559. : Typeface (font.getTypefaceName())
  205560. {
  205561. const ScopedAutoReleasePool pool;
  205562. renderingTransform = CGAffineTransformIdentity;
  205563. bool needsItalicTransform = false;
  205564. #if JUCE_IPHONE
  205565. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205566. if (font.isItalic() || font.isBold())
  205567. {
  205568. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205569. for (NSString* i in familyFonts)
  205570. {
  205571. const String fn (nsStringToJuce (i));
  205572. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205573. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205574. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205575. || afterDash.containsIgnoreCase (T("italic"))
  205576. || fn.endsWithIgnoreCase (T("oblique"))
  205577. || fn.endsWithIgnoreCase (T("italic"));
  205578. if (probablyBold == font.isBold()
  205579. && probablyItalic == font.isItalic())
  205580. {
  205581. fontName = i;
  205582. needsItalicTransform = false;
  205583. break;
  205584. }
  205585. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205586. {
  205587. fontName = i;
  205588. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205589. }
  205590. }
  205591. if (needsItalicTransform)
  205592. renderingTransform.c = 0.15f;
  205593. }
  205594. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205595. const int ascender = abs (CGFontGetAscent (fontRef));
  205596. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205597. ascent = ascender / totalHeight;
  205598. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205599. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205600. #else
  205601. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205602. if (font.isItalic())
  205603. {
  205604. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205605. toHaveTrait: NSItalicFontMask];
  205606. if (newFont == nsFont)
  205607. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205608. nsFont = newFont;
  205609. }
  205610. if (font.isBold())
  205611. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205612. [nsFont retain];
  205613. ascent = fabsf ((float) [nsFont ascender]);
  205614. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205615. ascent /= totalSize;
  205616. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205617. if (needsItalicTransform)
  205618. {
  205619. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205620. renderingTransform.c = 0.15f;
  205621. }
  205622. #if SUPPORT_ONLY_10_4_FONTS
  205623. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205624. if (atsFont == 0)
  205625. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205626. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205627. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205628. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205629. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205630. #else
  205631. #if SUPPORT_10_4_FONTS
  205632. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205633. {
  205634. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205635. if (atsFont == 0)
  205636. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205637. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205638. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205639. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205640. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205641. }
  205642. else
  205643. #endif
  205644. {
  205645. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205646. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205647. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205648. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205649. }
  205650. #endif
  205651. #endif
  205652. }
  205653. ~MacTypeface()
  205654. {
  205655. #if ! JUCE_IPHONE
  205656. [nsFont release];
  205657. #endif
  205658. if (fontRef != 0)
  205659. CGFontRelease (fontRef);
  205660. }
  205661. float getAscent() const
  205662. {
  205663. return ascent;
  205664. }
  205665. float getDescent() const
  205666. {
  205667. return 1.0f - ascent;
  205668. }
  205669. float getStringWidth (const String& text)
  205670. {
  205671. if (fontRef == 0 || text.isEmpty())
  205672. return 0;
  205673. const int length = text.length();
  205674. HeapBlock <CGGlyph> glyphs;
  205675. createGlyphsForString (text, length, glyphs);
  205676. float x = 0;
  205677. #if SUPPORT_ONLY_10_4_FONTS
  205678. HeapBlock <NSSize> advances (length);
  205679. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205680. for (int i = 0; i < length; ++i)
  205681. x += advances[i].width;
  205682. #else
  205683. #if SUPPORT_10_4_FONTS
  205684. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205685. {
  205686. HeapBlock <NSSize> advances (length);
  205687. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205688. for (int i = 0; i < length; ++i)
  205689. x += advances[i].width;
  205690. }
  205691. else
  205692. #endif
  205693. {
  205694. HeapBlock <int> advances (length);
  205695. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205696. for (int i = 0; i < length; ++i)
  205697. x += advances[i];
  205698. }
  205699. #endif
  205700. return x * unitsToHeightScaleFactor;
  205701. }
  205702. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205703. {
  205704. xOffsets.add (0);
  205705. if (fontRef == 0 || text.isEmpty())
  205706. return;
  205707. const int length = text.length();
  205708. HeapBlock <CGGlyph> glyphs;
  205709. createGlyphsForString (text, length, glyphs);
  205710. #if SUPPORT_ONLY_10_4_FONTS
  205711. HeapBlock <NSSize> advances (length);
  205712. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205713. int x = 0;
  205714. for (int i = 0; i < length; ++i)
  205715. {
  205716. x += advances[i].width;
  205717. xOffsets.add (x * unitsToHeightScaleFactor);
  205718. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205719. }
  205720. #else
  205721. #if SUPPORT_10_4_FONTS
  205722. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205723. {
  205724. HeapBlock <NSSize> advances (length);
  205725. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205726. float x = 0;
  205727. for (int i = 0; i < length; ++i)
  205728. {
  205729. x += advances[i].width;
  205730. xOffsets.add (x * unitsToHeightScaleFactor);
  205731. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205732. }
  205733. }
  205734. else
  205735. #endif
  205736. {
  205737. HeapBlock <int> advances (length);
  205738. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205739. {
  205740. int x = 0;
  205741. for (int i = 0; i < length; ++i)
  205742. {
  205743. x += advances [i];
  205744. xOffsets.add (x * unitsToHeightScaleFactor);
  205745. resultGlyphs.add (glyphs[i]);
  205746. }
  205747. }
  205748. }
  205749. #endif
  205750. }
  205751. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205752. {
  205753. #if JUCE_IPHONE
  205754. return false;
  205755. #else
  205756. if (nsFont == 0)
  205757. return false;
  205758. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205759. jassert (path.isEmpty());
  205760. const ScopedAutoReleasePool pool;
  205761. NSBezierPath* bez = [NSBezierPath bezierPath];
  205762. [bez moveToPoint: NSMakePoint (0, 0)];
  205763. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205764. inFont: nsFont];
  205765. for (int i = 0; i < [bez elementCount]; ++i)
  205766. {
  205767. NSPoint p[3];
  205768. switch ([bez elementAtIndex: i associatedPoints: p])
  205769. {
  205770. case NSMoveToBezierPathElement:
  205771. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205772. break;
  205773. case NSLineToBezierPathElement:
  205774. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205775. break;
  205776. case NSCurveToBezierPathElement:
  205777. 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);
  205778. break;
  205779. case NSClosePathBezierPathElement:
  205780. path.closeSubPath();
  205781. break;
  205782. default:
  205783. jassertfalse
  205784. break;
  205785. }
  205786. }
  205787. path.applyTransform (pathTransform);
  205788. return true;
  205789. #endif
  205790. }
  205791. juce_UseDebuggingNewOperator
  205792. CGFontRef fontRef;
  205793. float fontHeightToCGSizeFactor;
  205794. CGAffineTransform renderingTransform;
  205795. private:
  205796. float ascent, unitsToHeightScaleFactor;
  205797. #if JUCE_IPHONE
  205798. #else
  205799. NSFont* nsFont;
  205800. AffineTransform pathTransform;
  205801. #endif
  205802. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205803. {
  205804. #if SUPPORT_10_4_FONTS
  205805. #if ! SUPPORT_ONLY_10_4_FONTS
  205806. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205807. #endif
  205808. {
  205809. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205810. NSGlyph* const g = (NSGlyph*) glyphs;
  205811. for (int i = 0; i < length; ++i)
  205812. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205813. return;
  205814. }
  205815. #endif
  205816. #if ! SUPPORT_ONLY_10_4_FONTS
  205817. if (charToGlyphMapper == 0)
  205818. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205819. glyphs.malloc (length);
  205820. for (int i = 0; i < length; ++i)
  205821. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205822. #endif
  205823. }
  205824. #if ! SUPPORT_ONLY_10_4_FONTS
  205825. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205826. class CharToGlyphMapper
  205827. {
  205828. public:
  205829. CharToGlyphMapper (CGFontRef fontRef)
  205830. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205831. idRangeOffset (0), glyphIndexes (0)
  205832. {
  205833. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205834. if (cmapTable != 0)
  205835. {
  205836. const int numSubtables = getValue16 (cmapTable, 2);
  205837. for (int i = 0; i < numSubtables; ++i)
  205838. {
  205839. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205840. {
  205841. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205842. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205843. {
  205844. const int length = getValue16 (cmapTable, offset + 2);
  205845. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205846. segCount = segCountX2 / 2;
  205847. const int endCodeOffset = offset + 14;
  205848. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205849. const int idDeltaOffset = startCodeOffset + segCountX2;
  205850. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205851. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205852. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205853. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205854. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205855. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205856. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205857. }
  205858. break;
  205859. }
  205860. }
  205861. CFRelease (cmapTable);
  205862. }
  205863. }
  205864. ~CharToGlyphMapper()
  205865. {
  205866. if (endCode != 0)
  205867. {
  205868. CFRelease (endCode);
  205869. CFRelease (startCode);
  205870. CFRelease (idDelta);
  205871. CFRelease (idRangeOffset);
  205872. CFRelease (glyphIndexes);
  205873. }
  205874. }
  205875. int getGlyphForCharacter (const juce_wchar c) const
  205876. {
  205877. for (int i = 0; i < segCount; ++i)
  205878. {
  205879. if (getValue16 (endCode, i * 2) >= c)
  205880. {
  205881. const int start = getValue16 (startCode, i * 2);
  205882. if (start > c)
  205883. break;
  205884. const int delta = getValue16 (idDelta, i * 2);
  205885. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205886. if (rangeOffset == 0)
  205887. return delta + c;
  205888. else
  205889. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205890. }
  205891. }
  205892. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205893. return jmax (-1, c - 29);
  205894. }
  205895. private:
  205896. int segCount;
  205897. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205898. static uint16 getValue16 (CFDataRef data, const int index)
  205899. {
  205900. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205901. }
  205902. static uint32 getValue32 (CFDataRef data, const int index)
  205903. {
  205904. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205905. }
  205906. };
  205907. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205908. #endif
  205909. };
  205910. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205911. {
  205912. return new MacTypeface (font);
  205913. }
  205914. const StringArray Font::findAllTypefaceNames() throw()
  205915. {
  205916. StringArray names;
  205917. const ScopedAutoReleasePool pool;
  205918. #if JUCE_IPHONE
  205919. NSArray* fonts = [UIFont familyNames];
  205920. #else
  205921. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205922. #endif
  205923. for (unsigned int i = 0; i < [fonts count]; ++i)
  205924. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205925. names.sort (true);
  205926. return names;
  205927. }
  205928. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205929. {
  205930. #if JUCE_IPHONE
  205931. defaultSans = "Helvetica";
  205932. defaultSerif = "Times New Roman";
  205933. defaultFixed = "Courier New";
  205934. #else
  205935. defaultSans = "Lucida Grande";
  205936. defaultSerif = "Times New Roman";
  205937. defaultFixed = "Monaco";
  205938. #endif
  205939. }
  205940. #endif
  205941. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205942. // (must go before juce_mac_CoreGraphicsContext.mm)
  205943. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205944. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205945. // compiled on its own).
  205946. #if JUCE_INCLUDED_FILE
  205947. class CoreGraphicsImage : public Image
  205948. {
  205949. public:
  205950. CoreGraphicsImage (const PixelFormat format_,
  205951. const int imageWidth_,
  205952. const int imageHeight_,
  205953. const bool clearImage)
  205954. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205955. {
  205956. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205957. : CGColorSpaceCreateDeviceRGB();
  205958. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205959. colourSpace, getCGImageFlags (*this));
  205960. CGColorSpaceRelease (colourSpace);
  205961. }
  205962. ~CoreGraphicsImage()
  205963. {
  205964. CGContextRelease (context);
  205965. }
  205966. LowLevelGraphicsContext* createLowLevelContext();
  205967. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205968. {
  205969. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205970. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205971. {
  205972. return CGBitmapContextCreateImage (nativeImage->context);
  205973. }
  205974. else
  205975. {
  205976. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205977. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205978. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205979. 8, srcData.pixelStride * 8, srcData.lineStride,
  205980. colourSpace, getCGImageFlags (juceImage), provider,
  205981. 0, true, kCGRenderingIntentDefault);
  205982. CGDataProviderRelease (provider);
  205983. return imageRef;
  205984. }
  205985. }
  205986. #if JUCE_MAC
  205987. static NSImage* createNSImage (const Image& image)
  205988. {
  205989. const ScopedAutoReleasePool pool;
  205990. NSImage* im = [[NSImage alloc] init];
  205991. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205992. [im lockFocus];
  205993. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205994. CGImageRef imageRef = createImage (image, false, colourSpace);
  205995. CGColorSpaceRelease (colourSpace);
  205996. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205997. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205998. CGImageRelease (imageRef);
  205999. [im unlockFocus];
  206000. return im;
  206001. }
  206002. #endif
  206003. CGContextRef context;
  206004. private:
  206005. static CGBitmapInfo getCGImageFlags (const Image& image)
  206006. {
  206007. #if JUCE_BIG_ENDIAN
  206008. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  206009. #else
  206010. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  206011. #endif
  206012. }
  206013. };
  206014. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  206015. {
  206016. #if USE_COREGRAPHICS_RENDERING
  206017. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  206018. #else
  206019. return new Image (format, imageWidth, imageHeight, clearImage);
  206020. #endif
  206021. }
  206022. class CoreGraphicsContext : public LowLevelGraphicsContext
  206023. {
  206024. public:
  206025. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  206026. : context (context_),
  206027. flipHeight (flipHeight_),
  206028. numGradientLookupEntries (0)
  206029. {
  206030. CGContextRetain (context);
  206031. CGContextSaveGState(context);
  206032. CGContextSetShouldSmoothFonts (context, true);
  206033. CGContextSetShouldAntialias (context, true);
  206034. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206035. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  206036. greyColourSpace = CGColorSpaceCreateDeviceGray();
  206037. gradientCallbacks.version = 0;
  206038. gradientCallbacks.evaluate = gradientCallback;
  206039. gradientCallbacks.releaseInfo = 0;
  206040. state = new SavedState();
  206041. }
  206042. ~CoreGraphicsContext()
  206043. {
  206044. CGContextRestoreGState (context);
  206045. CGContextRelease (context);
  206046. CGColorSpaceRelease (rgbColourSpace);
  206047. CGColorSpaceRelease (greyColourSpace);
  206048. }
  206049. bool isVectorDevice() const { return false; }
  206050. void setOrigin (int x, int y)
  206051. {
  206052. CGContextTranslateCTM (context, x, -y);
  206053. }
  206054. bool clipToRectangle (const Rectangle<int>& r)
  206055. {
  206056. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  206057. return ! isClipEmpty();
  206058. }
  206059. bool clipToRectangleList (const RectangleList& clipRegion)
  206060. {
  206061. if (clipRegion.isEmpty())
  206062. {
  206063. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  206064. return false;
  206065. }
  206066. else
  206067. {
  206068. const int numRects = clipRegion.getNumRectangles();
  206069. HeapBlock <CGRect> rects (numRects);
  206070. for (int i = 0; i < numRects; ++i)
  206071. {
  206072. const Rectangle<int>& r = clipRegion.getRectangle(i);
  206073. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206074. }
  206075. CGContextClipToRects (context, rects, numRects);
  206076. return ! isClipEmpty();
  206077. }
  206078. }
  206079. void excludeClipRectangle (const Rectangle<int>& r)
  206080. {
  206081. RectangleList remaining (getClipBounds());
  206082. remaining.subtract (r);
  206083. clipToRectangleList (remaining);
  206084. }
  206085. void clipToPath (const Path& path, const AffineTransform& transform)
  206086. {
  206087. createPath (path, transform);
  206088. CGContextClip (context);
  206089. }
  206090. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  206091. {
  206092. if (! transform.isSingularity())
  206093. {
  206094. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206095. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206096. flip();
  206097. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206098. applyTransform (t);
  206099. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206100. CGContextClipToMask (context, r, image);
  206101. applyTransform (t.inverted());
  206102. flip();
  206103. CGImageRelease (image);
  206104. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206105. }
  206106. }
  206107. bool clipRegionIntersects (const Rectangle<int>& r)
  206108. {
  206109. return getClipBounds().intersects (r);
  206110. }
  206111. const Rectangle<int> getClipBounds() const
  206112. {
  206113. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206114. return Rectangle<int> (roundToInt (bounds.origin.x),
  206115. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206116. roundToInt (bounds.size.width),
  206117. roundToInt (bounds.size.height));
  206118. }
  206119. bool isClipEmpty() const
  206120. {
  206121. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206122. }
  206123. void saveState()
  206124. {
  206125. CGContextSaveGState (context);
  206126. stateStack.add (new SavedState (*state));
  206127. }
  206128. void restoreState()
  206129. {
  206130. CGContextRestoreGState (context);
  206131. SavedState* const top = stateStack.getLast();
  206132. if (top != 0)
  206133. {
  206134. state = top;
  206135. stateStack.removeLast (1, false);
  206136. }
  206137. else
  206138. {
  206139. jassertfalse // trying to pop with an empty stack!
  206140. }
  206141. }
  206142. void setFill (const FillType& fillType)
  206143. {
  206144. state->fillType = fillType;
  206145. if (fillType.isColour())
  206146. {
  206147. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206148. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206149. CGContextSetAlpha (context, 1.0f);
  206150. }
  206151. }
  206152. void setOpacity (float newOpacity)
  206153. {
  206154. state->fillType.setOpacity (newOpacity);
  206155. setFill (state->fillType);
  206156. }
  206157. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206158. {
  206159. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206160. ? kCGInterpolationLow
  206161. : kCGInterpolationHigh);
  206162. }
  206163. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206164. {
  206165. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206166. if (replaceExistingContents)
  206167. {
  206168. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206169. CGContextClearRect (context, cgRect);
  206170. #else
  206171. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206172. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206173. CGContextClearRect (context, cgRect);
  206174. else
  206175. #endif
  206176. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206177. #endif
  206178. fillRect (r, false);
  206179. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206180. }
  206181. else
  206182. {
  206183. if (state->fillType.isColour())
  206184. {
  206185. CGContextFillRect (context, cgRect);
  206186. }
  206187. else if (state->fillType.isGradient())
  206188. {
  206189. CGContextSaveGState (context);
  206190. CGContextClipToRect (context, cgRect);
  206191. drawGradient();
  206192. CGContextRestoreGState (context);
  206193. }
  206194. else
  206195. {
  206196. CGContextSaveGState (context);
  206197. CGContextClipToRect (context, cgRect);
  206198. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206199. CGContextRestoreGState (context);
  206200. }
  206201. }
  206202. }
  206203. void fillPath (const Path& path, const AffineTransform& transform)
  206204. {
  206205. CGContextSaveGState (context);
  206206. if (state->fillType.isColour())
  206207. {
  206208. flip();
  206209. applyTransform (transform);
  206210. createPath (path);
  206211. if (path.isUsingNonZeroWinding())
  206212. CGContextFillPath (context);
  206213. else
  206214. CGContextEOFillPath (context);
  206215. }
  206216. else
  206217. {
  206218. createPath (path, transform);
  206219. if (path.isUsingNonZeroWinding())
  206220. CGContextClip (context);
  206221. else
  206222. CGContextEOClip (context);
  206223. if (state->fillType.isGradient())
  206224. drawGradient();
  206225. else
  206226. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206227. }
  206228. CGContextRestoreGState (context);
  206229. }
  206230. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206231. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206232. {
  206233. jassert (sourceImage.getBounds().contains (srcClip));
  206234. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206235. CGImageRef image = fullImage;
  206236. if (srcClip != sourceImage.getBounds())
  206237. {
  206238. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206239. srcClip.getWidth(), srcClip.getHeight()));
  206240. CGImageRelease (fullImage);
  206241. }
  206242. CGContextSaveGState (context);
  206243. CGContextSetAlpha (context, state->fillType.getOpacity());
  206244. flip();
  206245. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206246. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206247. if (fillEntireClipAsTiles)
  206248. {
  206249. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206250. CGContextDrawTiledImage (context, imageRect, image);
  206251. #else
  206252. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206253. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206254. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206255. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206256. CGContextDrawTiledImage (context, imageRect, image);
  206257. else
  206258. #endif
  206259. {
  206260. // Fallback to manually doing a tiled fill on 10.4
  206261. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206262. const int iw = srcClip.getWidth();
  206263. const int ih = srcClip.getHeight();
  206264. int x = 0, y = 0;
  206265. while (x > clip.origin.x) x -= iw;
  206266. while (y > clip.origin.y) y -= ih;
  206267. const int right = (int) (clip.origin.x + clip.size.width);
  206268. const int bottom = (int) (clip.origin.y + clip.size.height);
  206269. while (y < bottom)
  206270. {
  206271. for (int x2 = x; x2 < right; x2 += iw)
  206272. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206273. y += ih;
  206274. }
  206275. }
  206276. #endif
  206277. }
  206278. else
  206279. {
  206280. CGContextDrawImage (context, imageRect, image);
  206281. }
  206282. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206283. CGContextRestoreGState (context);
  206284. }
  206285. void drawLine (double x1, double y1, double x2, double y2)
  206286. {
  206287. CGContextSetLineCap (context, kCGLineCapSquare);
  206288. CGContextSetLineWidth (context, 1.0f);
  206289. CGContextSetRGBStrokeColor (context,
  206290. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206291. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206292. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206293. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206294. CGContextStrokeLineSegments (context, line, 1);
  206295. }
  206296. void drawVerticalLine (const int x, double top, double bottom)
  206297. {
  206298. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206299. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206300. #else
  206301. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206302. // the x co-ord slightly to trick it..
  206303. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206304. #endif
  206305. }
  206306. void drawHorizontalLine (const int y, double left, double right)
  206307. {
  206308. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206309. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206310. #else
  206311. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206312. // the x co-ord slightly to trick it..
  206313. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206314. #endif
  206315. }
  206316. void setFont (const Font& newFont)
  206317. {
  206318. if (state->font != newFont)
  206319. {
  206320. state->fontRef = 0;
  206321. state->font = newFont;
  206322. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206323. if (mf != 0)
  206324. {
  206325. state->fontRef = mf->fontRef;
  206326. CGContextSetFont (context, state->fontRef);
  206327. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206328. state->fontTransform = mf->renderingTransform;
  206329. state->fontTransform.a *= state->font.getHorizontalScale();
  206330. CGContextSetTextMatrix (context, state->fontTransform);
  206331. }
  206332. }
  206333. }
  206334. const Font getFont()
  206335. {
  206336. return state->font;
  206337. }
  206338. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206339. {
  206340. if (state->fontRef != 0 && state->fillType.isColour())
  206341. {
  206342. if (transform.isOnlyTranslation())
  206343. {
  206344. CGGlyph g = glyphNumber;
  206345. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206346. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206347. }
  206348. else
  206349. {
  206350. CGContextSaveGState (context);
  206351. flip();
  206352. applyTransform (transform);
  206353. CGAffineTransform t = state->fontTransform;
  206354. t.d = -t.d;
  206355. CGContextSetTextMatrix (context, t);
  206356. CGGlyph g = glyphNumber;
  206357. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206358. CGContextSetTextMatrix (context, state->fontTransform);
  206359. CGContextRestoreGState (context);
  206360. }
  206361. }
  206362. else
  206363. {
  206364. Path p;
  206365. Font& f = state->font;
  206366. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206367. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206368. .followedBy (transform));
  206369. }
  206370. }
  206371. private:
  206372. CGContextRef context;
  206373. const float flipHeight;
  206374. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206375. CGFunctionCallbacks gradientCallbacks;
  206376. struct SavedState
  206377. {
  206378. SavedState()
  206379. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206380. {
  206381. }
  206382. SavedState (const SavedState& other)
  206383. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206384. fontTransform (other.fontTransform)
  206385. {
  206386. }
  206387. ~SavedState()
  206388. {
  206389. }
  206390. FillType fillType;
  206391. Font font;
  206392. CGFontRef fontRef;
  206393. CGAffineTransform fontTransform;
  206394. };
  206395. ScopedPointer <SavedState> state;
  206396. OwnedArray <SavedState> stateStack;
  206397. HeapBlock <PixelARGB> gradientLookupTable;
  206398. int numGradientLookupEntries;
  206399. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206400. {
  206401. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206402. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206403. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206404. colour.unpremultiply();
  206405. outData[0] = colour.getRed() / 255.0f;
  206406. outData[1] = colour.getGreen() / 255.0f;
  206407. outData[2] = colour.getBlue() / 255.0f;
  206408. outData[3] = colour.getAlpha() / 255.0f;
  206409. }
  206410. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206411. {
  206412. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206413. --numGradientLookupEntries;
  206414. CGShadingRef result = 0;
  206415. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206416. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206417. if (gradient.isRadial)
  206418. {
  206419. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206420. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206421. function, true, true);
  206422. }
  206423. else
  206424. {
  206425. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206426. CGPointMake (gradient.x2, gradient.y2),
  206427. function, true, true);
  206428. }
  206429. CGFunctionRelease (function);
  206430. return result;
  206431. }
  206432. void drawGradient()
  206433. {
  206434. flip();
  206435. applyTransform (state->fillType.transform);
  206436. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206437. // you draw a gradient with high quality interp enabled).
  206438. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206439. CGContextSetAlpha (context, state->fillType.getOpacity());
  206440. CGContextDrawShading (context, shading);
  206441. CGShadingRelease (shading);
  206442. }
  206443. void createPath (const Path& path) const
  206444. {
  206445. CGContextBeginPath (context);
  206446. Path::Iterator i (path);
  206447. while (i.next())
  206448. {
  206449. switch (i.elementType)
  206450. {
  206451. case Path::Iterator::startNewSubPath:
  206452. CGContextMoveToPoint (context, i.x1, i.y1);
  206453. break;
  206454. case Path::Iterator::lineTo:
  206455. CGContextAddLineToPoint (context, i.x1, i.y1);
  206456. break;
  206457. case Path::Iterator::quadraticTo:
  206458. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206459. break;
  206460. case Path::Iterator::cubicTo:
  206461. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206462. break;
  206463. case Path::Iterator::closePath:
  206464. CGContextClosePath (context); break;
  206465. default:
  206466. jassertfalse
  206467. break;
  206468. }
  206469. }
  206470. }
  206471. void createPath (const Path& path, const AffineTransform& transform) const
  206472. {
  206473. CGContextBeginPath (context);
  206474. Path::Iterator i (path);
  206475. while (i.next())
  206476. {
  206477. switch (i.elementType)
  206478. {
  206479. case Path::Iterator::startNewSubPath:
  206480. transform.transformPoint (i.x1, i.y1);
  206481. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206482. break;
  206483. case Path::Iterator::lineTo:
  206484. transform.transformPoint (i.x1, i.y1);
  206485. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206486. break;
  206487. case Path::Iterator::quadraticTo:
  206488. transform.transformPoint (i.x1, i.y1);
  206489. transform.transformPoint (i.x2, i.y2);
  206490. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206491. break;
  206492. case Path::Iterator::cubicTo:
  206493. transform.transformPoint (i.x1, i.y1);
  206494. transform.transformPoint (i.x2, i.y2);
  206495. transform.transformPoint (i.x3, i.y3);
  206496. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206497. break;
  206498. case Path::Iterator::closePath:
  206499. CGContextClosePath (context); break;
  206500. default:
  206501. jassertfalse
  206502. break;
  206503. }
  206504. }
  206505. }
  206506. static Image* createAlphaChannelImage (const Image& im)
  206507. {
  206508. if (im.getFormat() == Image::SingleChannel)
  206509. return const_cast <Image*> (&im);
  206510. return im.createCopyOfAlphaChannel();
  206511. }
  206512. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206513. {
  206514. if (im.getFormat() != Image::SingleChannel)
  206515. delete alphaIm;
  206516. }
  206517. void flip() const
  206518. {
  206519. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206520. }
  206521. void applyTransform (const AffineTransform& transform) const
  206522. {
  206523. CGAffineTransform t;
  206524. t.a = transform.mat00;
  206525. t.b = transform.mat10;
  206526. t.c = transform.mat01;
  206527. t.d = transform.mat11;
  206528. t.tx = transform.mat02;
  206529. t.ty = transform.mat12;
  206530. CGContextConcatCTM (context, t);
  206531. }
  206532. float flipY (float y) const
  206533. {
  206534. return flipHeight - y;
  206535. }
  206536. };
  206537. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206538. {
  206539. return new CoreGraphicsContext (context, imageHeight);
  206540. }
  206541. #endif
  206542. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206543. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206544. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206545. // compiled on its own).
  206546. #if JUCE_INCLUDED_FILE
  206547. class NSViewComponentPeer;
  206548. END_JUCE_NAMESPACE
  206549. #define JuceNSView MakeObjCClassName(JuceNSView)
  206550. @interface JuceNSView : NSView
  206551. {
  206552. @public
  206553. NSViewComponentPeer* owner;
  206554. NSNotificationCenter* notificationCenter;
  206555. }
  206556. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206557. - (void) dealloc;
  206558. - (BOOL) isOpaque;
  206559. - (void) drawRect: (NSRect) r;
  206560. - (void) mouseDown: (NSEvent*) ev;
  206561. - (void) asyncMouseDown: (NSEvent*) ev;
  206562. - (void) mouseUp: (NSEvent*) ev;
  206563. - (void) asyncMouseUp: (NSEvent*) ev;
  206564. - (void) mouseDragged: (NSEvent*) ev;
  206565. - (void) mouseMoved: (NSEvent*) ev;
  206566. - (void) mouseEntered: (NSEvent*) ev;
  206567. - (void) mouseExited: (NSEvent*) ev;
  206568. - (void) rightMouseDown: (NSEvent*) ev;
  206569. - (void) rightMouseDragged: (NSEvent*) ev;
  206570. - (void) rightMouseUp: (NSEvent*) ev;
  206571. - (void) otherMouseDown: (NSEvent*) ev;
  206572. - (void) otherMouseDragged: (NSEvent*) ev;
  206573. - (void) otherMouseUp: (NSEvent*) ev;
  206574. - (void) scrollWheel: (NSEvent*) ev;
  206575. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206576. - (void) frameChanged: (NSNotification*) n;
  206577. - (void) viewDidMoveToWindow;
  206578. - (void) keyDown: (NSEvent*) ev;
  206579. - (void) keyUp: (NSEvent*) ev;
  206580. - (void) flagsChanged: (NSEvent*) ev;
  206581. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206582. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206583. #endif
  206584. - (BOOL) becomeFirstResponder;
  206585. - (BOOL) resignFirstResponder;
  206586. - (BOOL) acceptsFirstResponder;
  206587. - (void) asyncRepaint: (id) rect;
  206588. - (NSArray*) getSupportedDragTypes;
  206589. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206590. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206591. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206592. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206593. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206594. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206595. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206596. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206597. @end
  206598. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206599. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206600. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206601. #else
  206602. @interface JuceNSWindow : NSWindow
  206603. #endif
  206604. {
  206605. @private
  206606. NSViewComponentPeer* owner;
  206607. bool isZooming;
  206608. }
  206609. - (void) setOwner: (NSViewComponentPeer*) owner;
  206610. - (BOOL) canBecomeKeyWindow;
  206611. - (void) becomeKeyWindow;
  206612. - (BOOL) windowShouldClose: (id) window;
  206613. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206614. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206615. - (void) zoom: (id) sender;
  206616. @end
  206617. BEGIN_JUCE_NAMESPACE
  206618. class NSViewComponentPeer : public ComponentPeer
  206619. {
  206620. public:
  206621. NSViewComponentPeer (Component* const component,
  206622. const int windowStyleFlags,
  206623. NSView* viewToAttachTo);
  206624. ~NSViewComponentPeer();
  206625. void* getNativeHandle() const;
  206626. void setVisible (bool shouldBeVisible);
  206627. void setTitle (const String& title);
  206628. void setPosition (int x, int y);
  206629. void setSize (int w, int h);
  206630. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206631. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  206632. void getBounds (int& x, int& y, int& w, int& h) const;
  206633. int getScreenX() const;
  206634. int getScreenY() const;
  206635. void relativePositionToGlobal (int& x, int& y);
  206636. void globalPositionToRelative (int& x, int& y);
  206637. void setMinimised (bool shouldBeMinimised);
  206638. bool isMinimised() const;
  206639. void setFullScreen (bool shouldBeFullScreen);
  206640. bool isFullScreen() const;
  206641. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  206642. const BorderSize getFrameSize() const;
  206643. bool setAlwaysOnTop (bool alwaysOnTop);
  206644. void toFront (bool makeActiveWindow);
  206645. void toBehind (ComponentPeer* other);
  206646. void setIcon (const Image& newIcon);
  206647. const StringArray getAvailableRenderingEngines() throw();
  206648. int getCurrentRenderingEngine() throw();
  206649. void setCurrentRenderingEngine (int index) throw();
  206650. virtual void redirectMouseDown (NSEvent* ev);
  206651. virtual void redirectMouseUp (NSEvent* ev);
  206652. virtual void redirectMouseDrag (NSEvent* ev);
  206653. virtual void redirectMouseMove (NSEvent* ev);
  206654. virtual void redirectMouseEnter (NSEvent* ev);
  206655. virtual void redirectMouseExit (NSEvent* ev);
  206656. virtual void redirectMouseWheel (NSEvent* ev);
  206657. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206658. virtual bool redirectKeyDown (NSEvent* ev);
  206659. virtual bool redirectKeyUp (NSEvent* ev);
  206660. virtual void redirectModKeyChange (NSEvent* ev);
  206661. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206662. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206663. #endif
  206664. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206665. virtual bool isOpaque();
  206666. virtual void drawRect (NSRect r);
  206667. virtual bool canBecomeKeyWindow();
  206668. virtual bool windowShouldClose();
  206669. virtual void redirectMovedOrResized();
  206670. virtual void viewMovedToWindow();
  206671. virtual NSRect constrainRect (NSRect r);
  206672. static void showArrowCursorIfNeeded();
  206673. virtual void viewFocusGain();
  206674. virtual void viewFocusLoss();
  206675. bool isFocused() const;
  206676. void grabFocus();
  206677. void textInputRequired (int x, int y);
  206678. void repaint (int x, int y, int w, int h);
  206679. void performAnyPendingRepaintsNow();
  206680. juce_UseDebuggingNewOperator
  206681. NSWindow* window;
  206682. JuceNSView* view;
  206683. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206684. };
  206685. END_JUCE_NAMESPACE
  206686. @implementation JuceNSView
  206687. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206688. withFrame: (NSRect) frame
  206689. {
  206690. [super initWithFrame: frame];
  206691. owner = owner_;
  206692. notificationCenter = [NSNotificationCenter defaultCenter];
  206693. [notificationCenter addObserver: self
  206694. selector: @selector (frameChanged:)
  206695. name: NSViewFrameDidChangeNotification
  206696. object: self];
  206697. if (! owner_->isSharedWindow)
  206698. {
  206699. [notificationCenter addObserver: self
  206700. selector: @selector (frameChanged:)
  206701. name: NSWindowDidMoveNotification
  206702. object: owner_->window];
  206703. }
  206704. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206705. return self;
  206706. }
  206707. - (void) dealloc
  206708. {
  206709. [notificationCenter removeObserver: self];
  206710. [super dealloc];
  206711. }
  206712. - (void) drawRect: (NSRect) r
  206713. {
  206714. if (owner != 0)
  206715. owner->drawRect (r);
  206716. }
  206717. - (BOOL) isOpaque
  206718. {
  206719. return owner == 0 || owner->isOpaque();
  206720. }
  206721. - (void) mouseDown: (NSEvent*) ev
  206722. {
  206723. // In some host situations, the host will stop modal loops from working
  206724. // correctly if they're called from a mouse event, so we'll trigger
  206725. // the event asynchronously..
  206726. if (JUCEApplication::getInstance() == 0)
  206727. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206728. withObject: ev
  206729. waitUntilDone: NO];
  206730. else
  206731. [self asyncMouseDown: ev];
  206732. }
  206733. - (void) asyncMouseDown: (NSEvent*) ev
  206734. {
  206735. if (owner != 0)
  206736. owner->redirectMouseDown (ev);
  206737. }
  206738. - (void) mouseUp: (NSEvent*) ev
  206739. {
  206740. // In some host situations, the host will stop modal loops from working
  206741. // correctly if they're called from a mouse event, so we'll trigger
  206742. // the event asynchronously..
  206743. if (JUCEApplication::getInstance() == 0)
  206744. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206745. withObject: ev
  206746. waitUntilDone: NO];
  206747. else
  206748. [self asyncMouseUp: ev];
  206749. }
  206750. - (void) asyncMouseUp: (NSEvent*) ev
  206751. {
  206752. if (owner != 0)
  206753. owner->redirectMouseUp (ev);
  206754. }
  206755. - (void) mouseDragged: (NSEvent*) ev
  206756. {
  206757. if (owner != 0)
  206758. owner->redirectMouseDrag (ev);
  206759. }
  206760. - (void) mouseMoved: (NSEvent*) ev
  206761. {
  206762. if (owner != 0)
  206763. owner->redirectMouseMove (ev);
  206764. }
  206765. - (void) mouseEntered: (NSEvent*) ev
  206766. {
  206767. if (owner != 0)
  206768. owner->redirectMouseEnter (ev);
  206769. }
  206770. - (void) mouseExited: (NSEvent*) ev
  206771. {
  206772. if (owner != 0)
  206773. owner->redirectMouseExit (ev);
  206774. }
  206775. - (void) rightMouseDown: (NSEvent*) ev
  206776. {
  206777. [self mouseDown: ev];
  206778. }
  206779. - (void) rightMouseDragged: (NSEvent*) ev
  206780. {
  206781. [self mouseDragged: ev];
  206782. }
  206783. - (void) rightMouseUp: (NSEvent*) ev
  206784. {
  206785. [self mouseUp: ev];
  206786. }
  206787. - (void) otherMouseDown: (NSEvent*) ev
  206788. {
  206789. [self mouseDown: ev];
  206790. }
  206791. - (void) otherMouseDragged: (NSEvent*) ev
  206792. {
  206793. [self mouseDragged: ev];
  206794. }
  206795. - (void) otherMouseUp: (NSEvent*) ev
  206796. {
  206797. [self mouseUp: ev];
  206798. }
  206799. - (void) scrollWheel: (NSEvent*) ev
  206800. {
  206801. if (owner != 0)
  206802. owner->redirectMouseWheel (ev);
  206803. }
  206804. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206805. {
  206806. return YES;
  206807. }
  206808. - (void) frameChanged: (NSNotification*) n
  206809. {
  206810. if (owner != 0)
  206811. owner->redirectMovedOrResized();
  206812. }
  206813. - (void) viewDidMoveToWindow
  206814. {
  206815. if (owner != 0)
  206816. owner->viewMovedToWindow();
  206817. }
  206818. - (void) asyncRepaint: (id) rect
  206819. {
  206820. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206821. [self setNeedsDisplayInRect: *r];
  206822. }
  206823. - (void) keyDown: (NSEvent*) ev
  206824. {
  206825. if (owner == 0 || ! owner->redirectKeyDown (ev))
  206826. [super keyDown: ev];
  206827. }
  206828. - (void) keyUp: (NSEvent*) ev
  206829. {
  206830. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206831. [super keyUp: ev];
  206832. }
  206833. - (void) flagsChanged: (NSEvent*) ev
  206834. {
  206835. if (owner != 0)
  206836. owner->redirectModKeyChange (ev);
  206837. }
  206838. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206839. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206840. {
  206841. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206842. return true;
  206843. return [super performKeyEquivalent: ev];
  206844. }
  206845. #endif
  206846. - (BOOL) becomeFirstResponder
  206847. {
  206848. if (owner != 0)
  206849. owner->viewFocusGain();
  206850. return true;
  206851. }
  206852. - (BOOL) resignFirstResponder
  206853. {
  206854. if (owner != 0)
  206855. owner->viewFocusLoss();
  206856. return true;
  206857. }
  206858. - (BOOL) acceptsFirstResponder
  206859. {
  206860. return owner != 0 && owner->canBecomeKeyWindow();
  206861. }
  206862. - (NSArray*) getSupportedDragTypes
  206863. {
  206864. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206865. }
  206866. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206867. {
  206868. return owner != 0 && owner->sendDragCallback (type, sender);
  206869. }
  206870. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206871. {
  206872. if ([self sendDragCallback: 0 sender: sender])
  206873. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206874. else
  206875. return NSDragOperationNone;
  206876. }
  206877. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206878. {
  206879. if ([self sendDragCallback: 0 sender: sender])
  206880. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206881. else
  206882. return NSDragOperationNone;
  206883. }
  206884. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206885. {
  206886. [self sendDragCallback: 1 sender: sender];
  206887. }
  206888. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206889. {
  206890. [self sendDragCallback: 1 sender: sender];
  206891. }
  206892. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206893. {
  206894. return YES;
  206895. }
  206896. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206897. {
  206898. return [self sendDragCallback: 2 sender: sender];
  206899. }
  206900. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206901. {
  206902. }
  206903. @end
  206904. @implementation JuceNSWindow
  206905. - (void) setOwner: (NSViewComponentPeer*) owner_
  206906. {
  206907. owner = owner_;
  206908. isZooming = false;
  206909. }
  206910. - (BOOL) canBecomeKeyWindow
  206911. {
  206912. return owner != 0 && owner->canBecomeKeyWindow();
  206913. }
  206914. - (void) becomeKeyWindow
  206915. {
  206916. [super becomeKeyWindow];
  206917. if (owner != 0)
  206918. owner->grabFocus();
  206919. }
  206920. - (BOOL) windowShouldClose: (id) window
  206921. {
  206922. return owner == 0 || owner->windowShouldClose();
  206923. }
  206924. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206925. {
  206926. if (owner != 0)
  206927. frameRect = owner->constrainRect (frameRect);
  206928. return frameRect;
  206929. }
  206930. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206931. {
  206932. if (isZooming)
  206933. return proposedFrameSize;
  206934. NSRect frameRect = [self frame];
  206935. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206936. frameRect.size = proposedFrameSize;
  206937. if (owner != 0)
  206938. frameRect = owner->constrainRect (frameRect);
  206939. return frameRect.size;
  206940. }
  206941. - (void) zoom: (id) sender
  206942. {
  206943. isZooming = true;
  206944. [super zoom: sender];
  206945. isZooming = false;
  206946. }
  206947. - (void) windowWillMove: (NSNotification*) notification
  206948. {
  206949. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206950. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206951. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206952. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206953. }
  206954. @end
  206955. BEGIN_JUCE_NAMESPACE
  206956. static ComponentPeer* currentlyFocusedPeer = 0;
  206957. static VoidArray keysCurrentlyDown;
  206958. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206959. {
  206960. if (keysCurrentlyDown.contains ((void*) keyCode))
  206961. return true;
  206962. if (keyCode >= 'A' && keyCode <= 'Z'
  206963. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206964. return true;
  206965. if (keyCode >= 'a' && keyCode <= 'z'
  206966. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206967. return true;
  206968. return false;
  206969. }
  206970. static int getKeyCodeFromEvent (NSEvent* ev)
  206971. {
  206972. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206973. int keyCode = unmodified[0];
  206974. if (keyCode == 0x19) // (backwards-tab)
  206975. keyCode = '\t';
  206976. else if (keyCode == 0x03) // (enter)
  206977. keyCode = '\r';
  206978. return keyCode;
  206979. }
  206980. static int currentModifiers = 0;
  206981. static void updateModifiers (NSEvent* e)
  206982. {
  206983. int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
  206984. | ModifierKeys::altModifier | ModifierKeys::commandModifier);
  206985. if (([e modifierFlags] & NSShiftKeyMask) != 0)
  206986. m |= ModifierKeys::shiftModifier;
  206987. if (([e modifierFlags] & NSControlKeyMask) != 0)
  206988. m |= ModifierKeys::ctrlModifier;
  206989. if (([e modifierFlags] & NSAlternateKeyMask) != 0)
  206990. m |= ModifierKeys::altModifier;
  206991. if (([e modifierFlags] & NSCommandKeyMask) != 0)
  206992. m |= ModifierKeys::commandModifier;
  206993. currentModifiers = m;
  206994. }
  206995. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  206996. {
  206997. updateModifiers (ev);
  206998. int keyCode = getKeyCodeFromEvent (ev);
  206999. if (keyCode != 0)
  207000. {
  207001. if (isKeyDown)
  207002. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207003. else
  207004. keysCurrentlyDown.removeValue ((void*) keyCode);
  207005. }
  207006. }
  207007. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207008. {
  207009. return ModifierKeys (currentModifiers);
  207010. }
  207011. void ModifierKeys::updateCurrentModifiers() throw()
  207012. {
  207013. currentModifierFlags = currentModifiers;
  207014. }
  207015. static int64 getMouseTime (NSEvent* e)
  207016. {
  207017. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  207018. + (int64) ([e timestamp] * 1000.0);
  207019. }
  207020. static void getMousePos (NSEvent* e, NSView* view, int& x, int& y)
  207021. {
  207022. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  207023. x = roundToInt (p.x);
  207024. y = roundToInt ([view frame].size.height - p.y);
  207025. }
  207026. static int getModifierForButtonNumber (const NSInteger num)
  207027. {
  207028. return num == 0 ? ModifierKeys::leftButtonModifier
  207029. : (num == 1 ? ModifierKeys::rightButtonModifier
  207030. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  207031. }
  207032. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207033. const int windowStyleFlags,
  207034. NSView* viewToAttachTo)
  207035. : ComponentPeer (component_, windowStyleFlags),
  207036. window (0),
  207037. view (0),
  207038. isSharedWindow (viewToAttachTo != 0),
  207039. fullScreen (false),
  207040. insideDrawRect (false),
  207041. #if USE_COREGRAPHICS_RENDERING
  207042. usingCoreGraphics (true),
  207043. #else
  207044. usingCoreGraphics (false),
  207045. #endif
  207046. recursiveToFrontCall (false)
  207047. {
  207048. NSRect r;
  207049. r.origin.x = 0;
  207050. r.origin.y = 0;
  207051. r.size.width = (float) component->getWidth();
  207052. r.size.height = (float) component->getHeight();
  207053. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207054. [view setPostsFrameChangedNotifications: YES];
  207055. if (isSharedWindow)
  207056. {
  207057. window = [viewToAttachTo window];
  207058. [viewToAttachTo addSubview: view];
  207059. setVisible (component->isVisible());
  207060. }
  207061. else
  207062. {
  207063. r.origin.x = (float) component->getX();
  207064. r.origin.y = (float) component->getY();
  207065. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207066. unsigned int style = 0;
  207067. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207068. style = NSBorderlessWindowMask;
  207069. else
  207070. style = NSTitledWindowMask;
  207071. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207072. style |= NSMiniaturizableWindowMask;
  207073. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207074. style |= NSClosableWindowMask;
  207075. if ((windowStyleFlags & windowIsResizable) != 0)
  207076. style |= NSResizableWindowMask;
  207077. window = [[JuceNSWindow alloc] initWithContentRect: r
  207078. styleMask: style
  207079. backing: NSBackingStoreBuffered
  207080. defer: YES];
  207081. [((JuceNSWindow*) window) setOwner: this];
  207082. [window orderOut: nil];
  207083. [window setDelegate: (JuceNSWindow*) window];
  207084. [window setOpaque: component->isOpaque()];
  207085. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207086. if (component->isAlwaysOnTop())
  207087. [window setLevel: NSFloatingWindowLevel];
  207088. [window setContentView: view];
  207089. [window setAutodisplay: YES];
  207090. [window setAcceptsMouseMovedEvents: YES];
  207091. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207092. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207093. [window setReleasedWhenClosed: YES];
  207094. [window retain];
  207095. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207096. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207097. }
  207098. setTitle (component->getName());
  207099. }
  207100. NSViewComponentPeer::~NSViewComponentPeer()
  207101. {
  207102. view->owner = 0;
  207103. [view removeFromSuperview];
  207104. [view release];
  207105. if (! isSharedWindow)
  207106. {
  207107. [((JuceNSWindow*) window) setOwner: 0];
  207108. [window close];
  207109. [window release];
  207110. }
  207111. }
  207112. void* NSViewComponentPeer::getNativeHandle() const
  207113. {
  207114. return view;
  207115. }
  207116. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207117. {
  207118. if (isSharedWindow)
  207119. {
  207120. [view setHidden: ! shouldBeVisible];
  207121. }
  207122. else
  207123. {
  207124. if (shouldBeVisible)
  207125. {
  207126. [window orderFront: nil];
  207127. handleBroughtToFront();
  207128. }
  207129. else
  207130. {
  207131. [window orderOut: nil];
  207132. }
  207133. }
  207134. }
  207135. void NSViewComponentPeer::setTitle (const String& title)
  207136. {
  207137. const ScopedAutoReleasePool pool;
  207138. if (! isSharedWindow)
  207139. [window setTitle: juceStringToNS (title)];
  207140. }
  207141. void NSViewComponentPeer::setPosition (int x, int y)
  207142. {
  207143. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207144. }
  207145. void NSViewComponentPeer::setSize (int w, int h)
  207146. {
  207147. setBounds (component->getX(), component->getY(), w, h, false);
  207148. }
  207149. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207150. {
  207151. fullScreen = isNowFullScreen;
  207152. w = jmax (0, w);
  207153. h = jmax (0, h);
  207154. NSRect r;
  207155. r.origin.x = (float) x;
  207156. r.origin.y = (float) y;
  207157. r.size.width = (float) w;
  207158. r.size.height = (float) h;
  207159. if (isSharedWindow)
  207160. {
  207161. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207162. if ([view frame].size.width != r.size.width
  207163. || [view frame].size.height != r.size.height)
  207164. [view setNeedsDisplay: true];
  207165. [view setFrame: r];
  207166. }
  207167. else
  207168. {
  207169. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207170. [window setFrame: [window frameRectForContentRect: r]
  207171. display: true];
  207172. }
  207173. }
  207174. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  207175. {
  207176. NSRect r = [view frame];
  207177. if (global && [view window] != 0)
  207178. {
  207179. r = [view convertRect: r toView: nil];
  207180. NSRect wr = [[view window] frame];
  207181. r.origin.x += wr.origin.x;
  207182. r.origin.y += wr.origin.y;
  207183. y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height);
  207184. }
  207185. else
  207186. {
  207187. y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height);
  207188. }
  207189. x = (int) r.origin.x;
  207190. w = (int) r.size.width;
  207191. h = (int) r.size.height;
  207192. }
  207193. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  207194. {
  207195. getBounds (x, y, w, h, ! isSharedWindow);
  207196. }
  207197. int NSViewComponentPeer::getScreenX() const
  207198. {
  207199. int x, y, w, h;
  207200. getBounds (x, y, w, h, true);
  207201. return x;
  207202. }
  207203. int NSViewComponentPeer::getScreenY() const
  207204. {
  207205. int x, y, w, h;
  207206. getBounds (x, y, w, h, true);
  207207. return y;
  207208. }
  207209. void NSViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  207210. {
  207211. int wx, wy, ww, wh;
  207212. getBounds (wx, wy, ww, wh, true);
  207213. x += wx;
  207214. y += wy;
  207215. }
  207216. void NSViewComponentPeer::globalPositionToRelative (int& x, int& y)
  207217. {
  207218. int wx, wy, ww, wh;
  207219. getBounds (wx, wy, ww, wh, true);
  207220. x -= wx;
  207221. y -= wy;
  207222. }
  207223. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207224. {
  207225. if (constrainer != 0)
  207226. {
  207227. NSRect current = [window frame];
  207228. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207229. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207230. int x = (int) r.origin.x;
  207231. int y = (int) r.origin.y;
  207232. int w = (int) r.size.width;
  207233. int h = (int) r.size.height;
  207234. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207235. (int) current.size.width, (int) current.size.height);
  207236. constrainer->checkBounds (x, y, w, h,
  207237. original,
  207238. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207239. y != original.getY() && y + h == original.getBottom(),
  207240. x != original.getX() && x + w == original.getRight(),
  207241. y == original.getY() && y + h != original.getBottom(),
  207242. x == original.getX() && x + w != original.getRight());
  207243. r.origin.x = x;
  207244. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - y;
  207245. r.size.width = w;
  207246. r.size.height = h;
  207247. }
  207248. return r;
  207249. }
  207250. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207251. {
  207252. if (! isSharedWindow)
  207253. {
  207254. if (shouldBeMinimised)
  207255. [window miniaturize: nil];
  207256. else
  207257. [window deminiaturize: nil];
  207258. }
  207259. }
  207260. bool NSViewComponentPeer::isMinimised() const
  207261. {
  207262. return window != 0 && [window isMiniaturized];
  207263. }
  207264. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207265. {
  207266. if (! isSharedWindow)
  207267. {
  207268. Rectangle<int> r (lastNonFullscreenBounds);
  207269. setMinimised (false);
  207270. if (fullScreen != shouldBeFullScreen)
  207271. {
  207272. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207273. {
  207274. fullScreen = true;
  207275. [window performZoom: nil];
  207276. }
  207277. else
  207278. {
  207279. if (shouldBeFullScreen)
  207280. r = Desktop::getInstance().getMainMonitorArea();
  207281. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207282. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207283. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207284. }
  207285. }
  207286. }
  207287. }
  207288. bool NSViewComponentPeer::isFullScreen() const
  207289. {
  207290. return fullScreen;
  207291. }
  207292. bool NSViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  207293. {
  207294. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  207295. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  207296. return false;
  207297. NSPoint p;
  207298. p.x = (float) x;
  207299. p.y = (float) y;
  207300. NSView* v = [view hitTest: p];
  207301. if (trueIfInAChildWindow)
  207302. return v != nil;
  207303. return v == view;
  207304. }
  207305. const BorderSize NSViewComponentPeer::getFrameSize() const
  207306. {
  207307. BorderSize b;
  207308. if (! isSharedWindow)
  207309. {
  207310. NSRect v = [view convertRect: [view frame] toView: nil];
  207311. NSRect w = [window frame];
  207312. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207313. b.setBottom ((int) v.origin.y);
  207314. b.setLeft ((int) v.origin.x);
  207315. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207316. }
  207317. return b;
  207318. }
  207319. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207320. {
  207321. if (! isSharedWindow)
  207322. {
  207323. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207324. : NSNormalWindowLevel];
  207325. }
  207326. return true;
  207327. }
  207328. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207329. {
  207330. if (isSharedWindow)
  207331. {
  207332. [[view superview] addSubview: view
  207333. positioned: NSWindowAbove
  207334. relativeTo: nil];
  207335. }
  207336. if (window != 0 && component->isVisible())
  207337. {
  207338. if (makeActiveWindow)
  207339. [window makeKeyAndOrderFront: nil];
  207340. else
  207341. [window orderFront: nil];
  207342. if (! recursiveToFrontCall)
  207343. {
  207344. recursiveToFrontCall = true;
  207345. handleBroughtToFront();
  207346. recursiveToFrontCall = false;
  207347. }
  207348. }
  207349. }
  207350. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207351. {
  207352. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207353. if (isSharedWindow)
  207354. {
  207355. [[view superview] addSubview: view
  207356. positioned: NSWindowBelow
  207357. relativeTo: o->view];
  207358. }
  207359. else
  207360. {
  207361. [window orderWindow: NSWindowBelow
  207362. relativeTo: o->window != 0 ? [o->window windowNumber]
  207363. : nil ];
  207364. }
  207365. }
  207366. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207367. {
  207368. // to do..
  207369. }
  207370. void NSViewComponentPeer::viewFocusGain()
  207371. {
  207372. if (currentlyFocusedPeer != this)
  207373. {
  207374. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207375. currentlyFocusedPeer->handleFocusLoss();
  207376. currentlyFocusedPeer = this;
  207377. handleFocusGain();
  207378. }
  207379. }
  207380. void NSViewComponentPeer::viewFocusLoss()
  207381. {
  207382. if (currentlyFocusedPeer == this)
  207383. {
  207384. currentlyFocusedPeer = 0;
  207385. handleFocusLoss();
  207386. }
  207387. }
  207388. void juce_HandleProcessFocusChange()
  207389. {
  207390. keysCurrentlyDown.clear();
  207391. if (NSViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  207392. {
  207393. if (Process::isForegroundProcess())
  207394. {
  207395. currentlyFocusedPeer->handleFocusGain();
  207396. ComponentPeer::bringModalComponentToFront();
  207397. }
  207398. else
  207399. {
  207400. currentlyFocusedPeer->handleFocusLoss();
  207401. // turn kiosk mode off if we lose focus..
  207402. Desktop::getInstance().setKioskModeComponent (0);
  207403. }
  207404. }
  207405. }
  207406. bool NSViewComponentPeer::isFocused() const
  207407. {
  207408. return isSharedWindow ? this == currentlyFocusedPeer
  207409. : (window != 0 && [window isKeyWindow]);
  207410. }
  207411. void NSViewComponentPeer::grabFocus()
  207412. {
  207413. if (window != 0)
  207414. {
  207415. [window makeKeyWindow];
  207416. [window makeFirstResponder: view];
  207417. viewFocusGain();
  207418. }
  207419. }
  207420. void NSViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  207421. {
  207422. }
  207423. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207424. {
  207425. String unicode (nsStringToJuce ([ev characters]));
  207426. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207427. int keyCode = getKeyCodeFromEvent (ev);
  207428. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207429. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207430. if (unicode.isNotEmpty() || keyCode != 0)
  207431. {
  207432. if (isKeyDown)
  207433. {
  207434. bool used = false;
  207435. while (unicode.length() > 0)
  207436. {
  207437. juce_wchar textCharacter = unicode[0];
  207438. unicode = unicode.substring (1);
  207439. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207440. textCharacter = 0;
  207441. used = handleKeyUpOrDown (true) || used;
  207442. used = handleKeyPress (keyCode, textCharacter) || used;
  207443. }
  207444. return used;
  207445. }
  207446. else
  207447. {
  207448. if (handleKeyUpOrDown (false))
  207449. return true;
  207450. }
  207451. }
  207452. return false;
  207453. }
  207454. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207455. {
  207456. updateKeysDown (ev, true);
  207457. bool used = handleKeyEvent (ev, true);
  207458. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207459. {
  207460. // for command keys, the key-up event is thrown away, so simulate one..
  207461. updateKeysDown (ev, false);
  207462. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207463. }
  207464. // (If we're running modally, don't allow unused keystrokes to be passed
  207465. // along to other blocked views..)
  207466. if (Component::getCurrentlyModalComponent() != 0)
  207467. used = true;
  207468. return used;
  207469. }
  207470. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207471. {
  207472. updateKeysDown (ev, false);
  207473. return handleKeyEvent (ev, false)
  207474. || Component::getCurrentlyModalComponent() != 0;
  207475. }
  207476. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207477. {
  207478. keysCurrentlyDown.clear();
  207479. handleKeyUpOrDown (true);
  207480. updateModifiers (ev);
  207481. handleModifierKeysChange();
  207482. }
  207483. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207484. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207485. {
  207486. if ([ev type] == NSKeyDown)
  207487. return redirectKeyDown (ev);
  207488. else if ([ev type] == NSKeyUp)
  207489. return redirectKeyUp (ev);
  207490. return false;
  207491. }
  207492. #endif
  207493. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207494. {
  207495. updateModifiers (ev);
  207496. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207497. int x, y;
  207498. getMousePos (ev, view, x, y);
  207499. handleMouseDown (x, y, getMouseTime (ev));
  207500. }
  207501. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207502. {
  207503. const int oldMods = currentModifiers;
  207504. updateModifiers (ev);
  207505. currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]);
  207506. int x, y;
  207507. getMousePos (ev, view, x, y);
  207508. handleMouseUp (oldMods, x, y, getMouseTime (ev));
  207509. showArrowCursorIfNeeded();
  207510. }
  207511. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207512. {
  207513. updateModifiers (ev);
  207514. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207515. int x, y;
  207516. getMousePos (ev, view, x, y);
  207517. handleMouseDrag (x, y, getMouseTime (ev));
  207518. }
  207519. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207520. {
  207521. updateModifiers (ev);
  207522. int x, y;
  207523. getMousePos (ev, view, x, y);
  207524. handleMouseMove (x, y, getMouseTime (ev));
  207525. showArrowCursorIfNeeded();
  207526. }
  207527. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207528. {
  207529. updateModifiers (ev);
  207530. int x, y;
  207531. getMousePos (ev, view, x, y);
  207532. handleMouseEnter (x, y, getMouseTime (ev));
  207533. }
  207534. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207535. {
  207536. updateModifiers (ev);
  207537. int x, y;
  207538. getMousePos (ev, view, x, y);
  207539. handleMouseExit (x, y, getMouseTime (ev));
  207540. }
  207541. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207542. {
  207543. updateModifiers (ev);
  207544. handleMouseWheel (roundToInt ([ev deltaX] * 10.0f),
  207545. roundToInt ([ev deltaY] * 10.0f),
  207546. getMouseTime (ev));
  207547. }
  207548. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207549. {
  207550. if (Component::getComponentUnderMouse() == 0)
  207551. {
  207552. int mx, my;
  207553. Desktop::getInstance().getMousePosition (mx, my);
  207554. if (Desktop::getInstance().findComponentAt (mx, my) == 0)
  207555. [[NSCursor arrowCursor] set];
  207556. }
  207557. }
  207558. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207559. {
  207560. NSString* bestType
  207561. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207562. if (bestType == nil)
  207563. return false;
  207564. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207565. int x = (int) p.x;
  207566. int y = (int) ([view frame].size.height - p.y);
  207567. StringArray files;
  207568. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207569. if (list == nil)
  207570. return false;
  207571. if ([list isKindOfClass: [NSArray class]])
  207572. {
  207573. NSArray* items = (NSArray*) list;
  207574. for (unsigned int i = 0; i < [items count]; ++i)
  207575. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207576. }
  207577. if (files.size() == 0)
  207578. return false;
  207579. if (type == 0)
  207580. handleFileDragMove (files, x, y);
  207581. else if (type == 1)
  207582. handleFileDragExit (files);
  207583. else if (type == 2)
  207584. handleFileDragDrop (files, x, y);
  207585. return true;
  207586. }
  207587. bool NSViewComponentPeer::isOpaque()
  207588. {
  207589. if (! getComponent()->isValidComponent())
  207590. return true;
  207591. return getComponent()->isOpaque();
  207592. }
  207593. void NSViewComponentPeer::drawRect (NSRect r)
  207594. {
  207595. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207596. return;
  207597. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207598. if (! component->isOpaque())
  207599. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207600. #if USE_COREGRAPHICS_RENDERING
  207601. if (usingCoreGraphics)
  207602. {
  207603. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207604. insideDrawRect = true;
  207605. handlePaint (context);
  207606. insideDrawRect = false;
  207607. }
  207608. else
  207609. #endif
  207610. {
  207611. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207612. (int) (r.size.width + 0.5f),
  207613. (int) (r.size.height + 0.5f),
  207614. ! getComponent()->isOpaque());
  207615. LowLevelGraphicsSoftwareRenderer context (temp);
  207616. context.setOrigin (-roundToInt (r.origin.x),
  207617. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207618. const NSRect* rects = 0;
  207619. NSInteger numRects = 0;
  207620. [view getRectsBeingDrawn: &rects count: &numRects];
  207621. RectangleList clip;
  207622. for (int i = 0; i < numRects; ++i)
  207623. {
  207624. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207625. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207626. roundToInt (rects[i].size.width),
  207627. roundToInt (rects[i].size.height)));
  207628. }
  207629. if (context.clipToRectangleList (clip))
  207630. {
  207631. insideDrawRect = true;
  207632. handlePaint (context);
  207633. insideDrawRect = false;
  207634. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207635. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207636. CGColorSpaceRelease (colourSpace);
  207637. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207638. CGImageRelease (image);
  207639. }
  207640. }
  207641. }
  207642. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207643. {
  207644. StringArray s;
  207645. s.add ("Software Renderer");
  207646. #if USE_COREGRAPHICS_RENDERING
  207647. s.add ("CoreGraphics Renderer");
  207648. #endif
  207649. return s;
  207650. }
  207651. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207652. {
  207653. return usingCoreGraphics ? 1 : 0;
  207654. }
  207655. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207656. {
  207657. #if USE_COREGRAPHICS_RENDERING
  207658. if (usingCoreGraphics != (index > 0))
  207659. {
  207660. usingCoreGraphics = index > 0;
  207661. [view setNeedsDisplay: true];
  207662. }
  207663. #endif
  207664. }
  207665. bool NSViewComponentPeer::canBecomeKeyWindow()
  207666. {
  207667. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207668. }
  207669. bool NSViewComponentPeer::windowShouldClose()
  207670. {
  207671. if (! isValidPeer (this))
  207672. return YES;
  207673. handleUserClosingWindow();
  207674. return NO;
  207675. }
  207676. void NSViewComponentPeer::redirectMovedOrResized()
  207677. {
  207678. handleMovedOrResized();
  207679. }
  207680. void NSViewComponentPeer::viewMovedToWindow()
  207681. {
  207682. if (isSharedWindow)
  207683. window = [view window];
  207684. }
  207685. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207686. {
  207687. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207688. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207689. // is apparently still available in 64-bit apps..
  207690. if (enableOrDisable)
  207691. {
  207692. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207693. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207694. }
  207695. else
  207696. {
  207697. SetSystemUIMode (kUIModeNormal, 0);
  207698. }
  207699. }
  207700. class AsyncRepaintMessage : public CallbackMessage
  207701. {
  207702. public:
  207703. NSViewComponentPeer* const peer;
  207704. const Rectangle<int> rect;
  207705. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207706. : peer (peer_), rect (rect_)
  207707. {
  207708. }
  207709. void messageCallback()
  207710. {
  207711. if (ComponentPeer::isValidPeer (peer))
  207712. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207713. }
  207714. };
  207715. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207716. {
  207717. if (insideDrawRect)
  207718. {
  207719. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207720. }
  207721. else
  207722. {
  207723. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207724. (float) w, (float) h)];
  207725. }
  207726. }
  207727. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207728. {
  207729. [view displayIfNeeded];
  207730. }
  207731. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207732. {
  207733. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207734. }
  207735. Image* juce_createIconForFile (const File& file)
  207736. {
  207737. const ScopedAutoReleasePool pool;
  207738. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207739. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207740. [NSGraphicsContext saveGraphicsState];
  207741. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207742. [image drawAtPoint: NSMakePoint (0, 0)
  207743. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207744. operation: NSCompositeSourceOver fraction: 1.0f];
  207745. [[NSGraphicsContext currentContext] flushGraphics];
  207746. [NSGraphicsContext restoreGraphicsState];
  207747. return result;
  207748. }
  207749. const int KeyPress::spaceKey = ' ';
  207750. const int KeyPress::returnKey = 0x0d;
  207751. const int KeyPress::escapeKey = 0x1b;
  207752. const int KeyPress::backspaceKey = 0x7f;
  207753. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207754. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207755. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207756. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207757. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207758. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207759. const int KeyPress::endKey = NSEndFunctionKey;
  207760. const int KeyPress::homeKey = NSHomeFunctionKey;
  207761. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207762. const int KeyPress::insertKey = -1;
  207763. const int KeyPress::tabKey = 9;
  207764. const int KeyPress::F1Key = NSF1FunctionKey;
  207765. const int KeyPress::F2Key = NSF2FunctionKey;
  207766. const int KeyPress::F3Key = NSF3FunctionKey;
  207767. const int KeyPress::F4Key = NSF4FunctionKey;
  207768. const int KeyPress::F5Key = NSF5FunctionKey;
  207769. const int KeyPress::F6Key = NSF6FunctionKey;
  207770. const int KeyPress::F7Key = NSF7FunctionKey;
  207771. const int KeyPress::F8Key = NSF8FunctionKey;
  207772. const int KeyPress::F9Key = NSF9FunctionKey;
  207773. const int KeyPress::F10Key = NSF10FunctionKey;
  207774. const int KeyPress::F11Key = NSF1FunctionKey;
  207775. const int KeyPress::F12Key = NSF12FunctionKey;
  207776. const int KeyPress::F13Key = NSF13FunctionKey;
  207777. const int KeyPress::F14Key = NSF14FunctionKey;
  207778. const int KeyPress::F15Key = NSF15FunctionKey;
  207779. const int KeyPress::F16Key = NSF16FunctionKey;
  207780. const int KeyPress::numberPad0 = 0x30020;
  207781. const int KeyPress::numberPad1 = 0x30021;
  207782. const int KeyPress::numberPad2 = 0x30022;
  207783. const int KeyPress::numberPad3 = 0x30023;
  207784. const int KeyPress::numberPad4 = 0x30024;
  207785. const int KeyPress::numberPad5 = 0x30025;
  207786. const int KeyPress::numberPad6 = 0x30026;
  207787. const int KeyPress::numberPad7 = 0x30027;
  207788. const int KeyPress::numberPad8 = 0x30028;
  207789. const int KeyPress::numberPad9 = 0x30029;
  207790. const int KeyPress::numberPadAdd = 0x3002a;
  207791. const int KeyPress::numberPadSubtract = 0x3002b;
  207792. const int KeyPress::numberPadMultiply = 0x3002c;
  207793. const int KeyPress::numberPadDivide = 0x3002d;
  207794. const int KeyPress::numberPadSeparator = 0x3002e;
  207795. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207796. const int KeyPress::numberPadEquals = 0x30030;
  207797. const int KeyPress::numberPadDelete = 0x30031;
  207798. const int KeyPress::playKey = 0x30000;
  207799. const int KeyPress::stopKey = 0x30001;
  207800. const int KeyPress::fastForwardKey = 0x30002;
  207801. const int KeyPress::rewindKey = 0x30003;
  207802. #endif
  207803. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207804. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207805. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207806. // compiled on its own).
  207807. #if JUCE_INCLUDED_FILE
  207808. #if JUCE_MAC
  207809. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207810. {
  207811. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207812. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207813. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207814. [im release];
  207815. return (void*) c;
  207816. }
  207817. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207818. {
  207819. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207820. jassert (im != 0);
  207821. if (im == 0)
  207822. return 0;
  207823. return juce_createMouseCursorFromImage (*im,
  207824. (int) (hx * im->getWidth()),
  207825. (int) (hy * im->getHeight()));
  207826. }
  207827. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207828. {
  207829. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207830. MemoryBlock mb;
  207831. if (f.getChildFile (filename).loadFileAsData (mb))
  207832. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207833. return 0;
  207834. }
  207835. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207836. {
  207837. const ScopedAutoReleasePool pool;
  207838. NSCursor* c = 0;
  207839. switch (type)
  207840. {
  207841. case MouseCursor::NormalCursor:
  207842. c = [NSCursor arrowCursor];
  207843. break;
  207844. case MouseCursor::NoCursor:
  207845. {
  207846. Image blank (Image::ARGB, 8, 8, true);
  207847. return juce_createMouseCursorFromImage (blank, 0, 0);
  207848. }
  207849. case MouseCursor::DraggingHandCursor:
  207850. c = [NSCursor openHandCursor];
  207851. break;
  207852. case MouseCursor::CopyingCursor:
  207853. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207854. case MouseCursor::WaitCursor:
  207855. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207856. break;
  207857. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207858. case MouseCursor::IBeamCursor:
  207859. c = [NSCursor IBeamCursor];
  207860. break;
  207861. case MouseCursor::PointingHandCursor:
  207862. c = [NSCursor pointingHandCursor];
  207863. break;
  207864. case MouseCursor::LeftRightResizeCursor:
  207865. c = [NSCursor resizeLeftRightCursor];
  207866. break;
  207867. case MouseCursor::LeftEdgeResizeCursor:
  207868. c = [NSCursor resizeLeftCursor];
  207869. break;
  207870. case MouseCursor::RightEdgeResizeCursor:
  207871. c = [NSCursor resizeRightCursor];
  207872. break;
  207873. case MouseCursor::UpDownResizeCursor:
  207874. case MouseCursor::TopEdgeResizeCursor:
  207875. case MouseCursor::BottomEdgeResizeCursor:
  207876. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207877. case MouseCursor::TopLeftCornerResizeCursor:
  207878. case MouseCursor::BottomRightCornerResizeCursor:
  207879. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207880. case MouseCursor::TopRightCornerResizeCursor:
  207881. case MouseCursor::BottomLeftCornerResizeCursor:
  207882. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207883. case MouseCursor::UpDownLeftRightResizeCursor:
  207884. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207885. case MouseCursor::CrosshairCursor:
  207886. c = [NSCursor crosshairCursor];
  207887. break;
  207888. }
  207889. [c retain];
  207890. return (void*) c;
  207891. }
  207892. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207893. {
  207894. NSCursor* c = (NSCursor*) cursorHandle;
  207895. [c release];
  207896. }
  207897. void MouseCursor::showInAllWindows() const throw()
  207898. {
  207899. showInWindow (0);
  207900. }
  207901. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207902. {
  207903. NSCursor* const c = (NSCursor*) getHandle();
  207904. [c set];
  207905. }
  207906. #else
  207907. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207908. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207909. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207910. void MouseCursor::showInAllWindows() const throw() {}
  207911. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207912. #endif
  207913. #endif
  207914. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207915. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207916. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207917. // compiled on its own).
  207918. #if JUCE_INCLUDED_FILE
  207919. class NSViewComponentInternal : public ComponentMovementWatcher
  207920. {
  207921. Component* const owner;
  207922. NSViewComponentPeer* currentPeer;
  207923. bool wasShowing;
  207924. public:
  207925. NSView* const view;
  207926. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207927. : ComponentMovementWatcher (owner_),
  207928. owner (owner_),
  207929. currentPeer (0),
  207930. wasShowing (false),
  207931. view (view_)
  207932. {
  207933. [view_ retain];
  207934. if (owner_->isShowing())
  207935. componentPeerChanged();
  207936. }
  207937. ~NSViewComponentInternal()
  207938. {
  207939. [view removeFromSuperview];
  207940. [view release];
  207941. }
  207942. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207943. {
  207944. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207945. // The ComponentMovementWatcher version of this method avoids calling
  207946. // us when the top-level comp is resized, but for an NSView we need to know this
  207947. // because with inverted co-ords, we need to update the position even if the
  207948. // top-left pos hasn't changed
  207949. if (comp.isOnDesktop() && wasResized)
  207950. componentMovedOrResized (wasMoved, wasResized);
  207951. }
  207952. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207953. {
  207954. Component* const topComp = owner->getTopLevelComponent();
  207955. if (topComp->getPeer() != 0)
  207956. {
  207957. int x = 0, y = 0;
  207958. owner->relativePositionToOtherComponent (topComp, x, y);
  207959. NSRect r;
  207960. r.origin.x = (float) x;
  207961. r.origin.y = (float) y;
  207962. r.size.width = (float) owner->getWidth();
  207963. r.size.height = (float) owner->getHeight();
  207964. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207965. [view setFrame: r];
  207966. }
  207967. }
  207968. void componentPeerChanged()
  207969. {
  207970. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207971. if (currentPeer != peer)
  207972. {
  207973. [view removeFromSuperview];
  207974. currentPeer = peer;
  207975. if (peer != 0)
  207976. {
  207977. [peer->view addSubview: view];
  207978. componentMovedOrResized (false, false);
  207979. }
  207980. }
  207981. [view setHidden: ! owner->isShowing()];
  207982. }
  207983. void componentVisibilityChanged (Component&)
  207984. {
  207985. componentPeerChanged();
  207986. }
  207987. juce_UseDebuggingNewOperator
  207988. private:
  207989. NSViewComponentInternal (const NSViewComponentInternal&);
  207990. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207991. };
  207992. NSViewComponent::NSViewComponent()
  207993. {
  207994. }
  207995. NSViewComponent::~NSViewComponent()
  207996. {
  207997. }
  207998. void NSViewComponent::setView (void* view)
  207999. {
  208000. if (view != getView())
  208001. {
  208002. if (view != 0)
  208003. info = new NSViewComponentInternal ((NSView*) view, this);
  208004. else
  208005. info = 0;
  208006. }
  208007. }
  208008. void* NSViewComponent::getView() const
  208009. {
  208010. return info == 0 ? 0 : info->view;
  208011. }
  208012. void NSViewComponent::paint (Graphics& g)
  208013. {
  208014. }
  208015. #endif
  208016. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  208017. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  208018. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208019. // compiled on its own).
  208020. #if JUCE_INCLUDED_FILE
  208021. AppleRemoteDevice::AppleRemoteDevice()
  208022. : device (0),
  208023. queue (0),
  208024. remoteId (0)
  208025. {
  208026. }
  208027. AppleRemoteDevice::~AppleRemoteDevice()
  208028. {
  208029. stop();
  208030. }
  208031. static io_object_t getAppleRemoteDevice()
  208032. {
  208033. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208034. io_iterator_t iter = 0;
  208035. io_object_t iod = 0;
  208036. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208037. && iter != 0)
  208038. {
  208039. iod = IOIteratorNext (iter);
  208040. }
  208041. IOObjectRelease (iter);
  208042. return iod;
  208043. }
  208044. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208045. {
  208046. jassert (*device == 0);
  208047. io_name_t classname;
  208048. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208049. {
  208050. IOCFPlugInInterface** cfPlugInInterface = 0;
  208051. SInt32 score = 0;
  208052. if (IOCreatePlugInInterfaceForService (iod,
  208053. kIOHIDDeviceUserClientTypeID,
  208054. kIOCFPlugInInterfaceID,
  208055. &cfPlugInInterface,
  208056. &score) == kIOReturnSuccess)
  208057. {
  208058. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208059. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208060. device);
  208061. (void) hr;
  208062. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208063. }
  208064. }
  208065. return *device != 0;
  208066. }
  208067. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208068. {
  208069. if (queue != 0)
  208070. return true;
  208071. stop();
  208072. bool result = false;
  208073. io_object_t iod = getAppleRemoteDevice();
  208074. if (iod != 0)
  208075. {
  208076. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208077. result = true;
  208078. else
  208079. stop();
  208080. IOObjectRelease (iod);
  208081. }
  208082. return result;
  208083. }
  208084. void AppleRemoteDevice::stop()
  208085. {
  208086. if (queue != 0)
  208087. {
  208088. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208089. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208090. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208091. queue = 0;
  208092. }
  208093. if (device != 0)
  208094. {
  208095. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208096. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208097. device = 0;
  208098. }
  208099. }
  208100. bool AppleRemoteDevice::isActive() const
  208101. {
  208102. return queue != 0;
  208103. }
  208104. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208105. {
  208106. if (result == kIOReturnSuccess)
  208107. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208108. }
  208109. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208110. {
  208111. Array <int> cookies;
  208112. CFArrayRef elements;
  208113. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208114. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208115. return false;
  208116. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208117. {
  208118. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208119. // get the cookie
  208120. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208121. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208122. continue;
  208123. long number;
  208124. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208125. continue;
  208126. cookies.add ((int) number);
  208127. }
  208128. CFRelease (elements);
  208129. if ((*(IOHIDDeviceInterface**) device)
  208130. ->open ((IOHIDDeviceInterface**) device,
  208131. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208132. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208133. {
  208134. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208135. if (queue != 0)
  208136. {
  208137. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208138. for (int i = 0; i < cookies.size(); ++i)
  208139. {
  208140. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208141. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208142. }
  208143. CFRunLoopSourceRef eventSource;
  208144. if ((*(IOHIDQueueInterface**) queue)
  208145. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208146. {
  208147. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208148. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208149. {
  208150. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208151. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208152. return true;
  208153. }
  208154. }
  208155. }
  208156. }
  208157. return false;
  208158. }
  208159. void AppleRemoteDevice::handleCallbackInternal()
  208160. {
  208161. int totalValues = 0;
  208162. AbsoluteTime nullTime = { 0, 0 };
  208163. char cookies [12];
  208164. int numCookies = 0;
  208165. while (numCookies < numElementsInArray (cookies))
  208166. {
  208167. IOHIDEventStruct e;
  208168. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208169. break;
  208170. if ((int) e.elementCookie == 19)
  208171. {
  208172. remoteId = e.value;
  208173. buttonPressed (switched, false);
  208174. }
  208175. else
  208176. {
  208177. totalValues += e.value;
  208178. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208179. }
  208180. }
  208181. cookies [numCookies++] = 0;
  208182. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208183. static const char buttonPatterns[] =
  208184. {
  208185. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208186. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208187. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208188. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208189. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208190. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208191. 0x1f, 0x12, 0x04, 0x02, 0,
  208192. 0x1f, 0x12, 0x03, 0x02, 0,
  208193. 0x1f, 0x12, 0x1f, 0x12, 0,
  208194. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208195. 19, 0
  208196. };
  208197. int buttonNum = (int) menuButton;
  208198. int i = 0;
  208199. while (i < numElementsInArray (buttonPatterns))
  208200. {
  208201. if (strcmp (cookies, buttonPatterns + i) == 0)
  208202. {
  208203. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208204. break;
  208205. }
  208206. i += (int) strlen (buttonPatterns + i) + 1;
  208207. ++buttonNum;
  208208. }
  208209. }
  208210. #endif
  208211. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208212. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208213. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208214. // compiled on its own).
  208215. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208216. #if JUCE_MAC
  208217. END_JUCE_NAMESPACE
  208218. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208219. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208220. {
  208221. CriticalSection* contextLock;
  208222. bool needsUpdate;
  208223. }
  208224. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208225. - (bool) makeActive;
  208226. - (void) makeInactive;
  208227. - (void) reshape;
  208228. @end
  208229. @implementation ThreadSafeNSOpenGLView
  208230. - (id) initWithFrame: (NSRect) frameRect
  208231. pixelFormat: (NSOpenGLPixelFormat*) format
  208232. {
  208233. contextLock = new CriticalSection();
  208234. self = [super initWithFrame: frameRect pixelFormat: format];
  208235. if (self != nil)
  208236. [[NSNotificationCenter defaultCenter] addObserver: self
  208237. selector: @selector (_surfaceNeedsUpdate:)
  208238. name: NSViewGlobalFrameDidChangeNotification
  208239. object: self];
  208240. return self;
  208241. }
  208242. - (void) dealloc
  208243. {
  208244. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208245. delete contextLock;
  208246. [super dealloc];
  208247. }
  208248. - (bool) makeActive
  208249. {
  208250. const ScopedLock sl (*contextLock);
  208251. if ([self openGLContext] == 0)
  208252. return false;
  208253. [[self openGLContext] makeCurrentContext];
  208254. if (needsUpdate)
  208255. {
  208256. [super update];
  208257. needsUpdate = false;
  208258. }
  208259. return true;
  208260. }
  208261. - (void) makeInactive
  208262. {
  208263. const ScopedLock sl (*contextLock);
  208264. [NSOpenGLContext clearCurrentContext];
  208265. }
  208266. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208267. {
  208268. const ScopedLock sl (*contextLock);
  208269. needsUpdate = true;
  208270. }
  208271. - (void) update
  208272. {
  208273. const ScopedLock sl (*contextLock);
  208274. needsUpdate = true;
  208275. }
  208276. - (void) reshape
  208277. {
  208278. const ScopedLock sl (*contextLock);
  208279. needsUpdate = true;
  208280. }
  208281. @end
  208282. BEGIN_JUCE_NAMESPACE
  208283. class WindowedGLContext : public OpenGLContext
  208284. {
  208285. public:
  208286. WindowedGLContext (Component* const component,
  208287. const OpenGLPixelFormat& pixelFormat_,
  208288. NSOpenGLContext* sharedContext)
  208289. : renderContext (0),
  208290. pixelFormat (pixelFormat_)
  208291. {
  208292. jassert (component != 0);
  208293. NSOpenGLPixelFormatAttribute attribs [64];
  208294. int n = 0;
  208295. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208296. attribs[n++] = NSOpenGLPFAAccelerated;
  208297. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208298. attribs[n++] = NSOpenGLPFAColorSize;
  208299. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208300. pixelFormat.greenBits,
  208301. pixelFormat.blueBits);
  208302. attribs[n++] = NSOpenGLPFAAlphaSize;
  208303. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208304. attribs[n++] = NSOpenGLPFADepthSize;
  208305. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208306. attribs[n++] = NSOpenGLPFAStencilSize;
  208307. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208308. attribs[n++] = NSOpenGLPFAAccumSize;
  208309. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208310. pixelFormat.accumulationBufferGreenBits,
  208311. pixelFormat.accumulationBufferBlueBits,
  208312. pixelFormat.accumulationBufferAlphaBits);
  208313. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208314. attribs[n++] = NSOpenGLPFASampleBuffers;
  208315. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208316. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208317. attribs[n++] = NSOpenGLPFANoRecovery;
  208318. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208319. NSOpenGLPixelFormat* format
  208320. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208321. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208322. pixelFormat: format];
  208323. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208324. shareContext: sharedContext] autorelease];
  208325. const GLint swapInterval = 1;
  208326. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208327. [view setOpenGLContext: renderContext];
  208328. [renderContext setView: view];
  208329. [format release];
  208330. viewHolder = new NSViewComponentInternal (view, component);
  208331. }
  208332. ~WindowedGLContext()
  208333. {
  208334. makeInactive();
  208335. [renderContext clearDrawable];
  208336. viewHolder = 0;
  208337. }
  208338. bool makeActive() const throw()
  208339. {
  208340. jassert (renderContext != 0);
  208341. [view makeActive];
  208342. return isActive();
  208343. }
  208344. bool makeInactive() const throw()
  208345. {
  208346. [view makeInactive];
  208347. return true;
  208348. }
  208349. bool isActive() const throw()
  208350. {
  208351. return [NSOpenGLContext currentContext] == renderContext;
  208352. }
  208353. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208354. void* getRawContext() const throw() { return renderContext; }
  208355. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208356. {
  208357. }
  208358. void swapBuffers()
  208359. {
  208360. [renderContext flushBuffer];
  208361. }
  208362. bool setSwapInterval (const int numFramesPerSwap)
  208363. {
  208364. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208365. forParameter: NSOpenGLCPSwapInterval];
  208366. return true;
  208367. }
  208368. int getSwapInterval() const
  208369. {
  208370. GLint numFrames = 0;
  208371. [renderContext getValues: &numFrames
  208372. forParameter: NSOpenGLCPSwapInterval];
  208373. return numFrames;
  208374. }
  208375. void repaint()
  208376. {
  208377. // we need to invalidate the juce view that holds this gl view, to make it
  208378. // cause a repaint callback
  208379. NSView* v = (NSView*) viewHolder->view;
  208380. NSRect r = [v frame];
  208381. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208382. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208383. // repaint message, thus never causing our paint() callback, and never repainting
  208384. // the comp. So invalidating just a little bit around the edge helps..
  208385. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208386. }
  208387. void* getNativeWindowHandle() const { return viewHolder->view; }
  208388. juce_UseDebuggingNewOperator
  208389. NSOpenGLContext* renderContext;
  208390. ThreadSafeNSOpenGLView* view;
  208391. private:
  208392. OpenGLPixelFormat pixelFormat;
  208393. ScopedPointer <NSViewComponentInternal> viewHolder;
  208394. WindowedGLContext (const WindowedGLContext&);
  208395. const WindowedGLContext& operator= (const WindowedGLContext&);
  208396. };
  208397. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208398. const OpenGLPixelFormat& pixelFormat,
  208399. const OpenGLContext* const contextToShareWith)
  208400. {
  208401. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208402. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208403. return (c->renderContext != 0) ? c.release() : 0;
  208404. }
  208405. void* OpenGLComponent::getNativeWindowHandle() const
  208406. {
  208407. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208408. : 0;
  208409. }
  208410. void juce_glViewport (const int w, const int h)
  208411. {
  208412. glViewport (0, 0, w, h);
  208413. }
  208414. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208415. OwnedArray <OpenGLPixelFormat>& results)
  208416. {
  208417. /* GLint attribs [64];
  208418. int n = 0;
  208419. attribs[n++] = AGL_RGBA;
  208420. attribs[n++] = AGL_DOUBLEBUFFER;
  208421. attribs[n++] = AGL_ACCELERATED;
  208422. attribs[n++] = AGL_NO_RECOVERY;
  208423. attribs[n++] = AGL_NONE;
  208424. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208425. while (p != 0)
  208426. {
  208427. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208428. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208429. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208430. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208431. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208432. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208433. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208434. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208435. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208436. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208437. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208438. results.add (pf);
  208439. p = aglNextPixelFormat (p);
  208440. }*/
  208441. //jassertfalse //xxx can't see how you do this in cocoa!
  208442. }
  208443. #else
  208444. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208445. const OpenGLPixelFormat& pixelFormat,
  208446. const OpenGLContext* const contextToShareWith)
  208447. {
  208448. return 0;
  208449. }
  208450. void juce_glViewport (const int w, const int h)
  208451. {
  208452. //glViewport (0, 0, w, h);
  208453. }
  208454. #endif
  208455. #endif
  208456. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208457. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208458. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208459. // compiled on its own).
  208460. #if JUCE_INCLUDED_FILE
  208461. class JuceMainMenuHandler;
  208462. END_JUCE_NAMESPACE
  208463. using namespace JUCE_NAMESPACE;
  208464. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208465. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208466. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208467. #else
  208468. @interface JuceMenuCallback : NSObject
  208469. #endif
  208470. {
  208471. JuceMainMenuHandler* owner;
  208472. }
  208473. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208474. - (void) dealloc;
  208475. - (void) menuItemInvoked: (id) menu;
  208476. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208477. @end
  208478. BEGIN_JUCE_NAMESPACE
  208479. class JuceMainMenuHandler : private MenuBarModelListener,
  208480. private DeletedAtShutdown
  208481. {
  208482. public:
  208483. static JuceMainMenuHandler* instance;
  208484. JuceMainMenuHandler()
  208485. : currentModel (0),
  208486. lastUpdateTime (0)
  208487. {
  208488. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208489. }
  208490. ~JuceMainMenuHandler()
  208491. {
  208492. setMenu (0);
  208493. jassert (instance == this);
  208494. instance = 0;
  208495. [callback release];
  208496. }
  208497. void setMenu (MenuBarModel* const newMenuBarModel)
  208498. {
  208499. if (currentModel != newMenuBarModel)
  208500. {
  208501. if (currentModel != 0)
  208502. currentModel->removeListener (this);
  208503. currentModel = newMenuBarModel;
  208504. if (currentModel != 0)
  208505. currentModel->addListener (this);
  208506. menuBarItemsChanged (0);
  208507. }
  208508. }
  208509. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208510. const String& name, const int menuId, const int tag)
  208511. {
  208512. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208513. action: nil
  208514. keyEquivalent: @""];
  208515. [item setTag: tag];
  208516. NSMenu* sub = createMenu (child, name, menuId, tag);
  208517. [parent setSubmenu: sub forItem: item];
  208518. [sub setAutoenablesItems: false];
  208519. [sub release];
  208520. }
  208521. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208522. const String& name, const int menuId, const int tag)
  208523. {
  208524. [parentItem setTag: tag];
  208525. NSMenu* menu = [parentItem submenu];
  208526. [menu setTitle: juceStringToNS (name)];
  208527. while ([menu numberOfItems] > 0)
  208528. [menu removeItemAtIndex: 0];
  208529. PopupMenu::MenuItemIterator iter (menuToCopy);
  208530. while (iter.next())
  208531. addMenuItem (iter, menu, menuId, tag);
  208532. [menu setAutoenablesItems: false];
  208533. [menu update];
  208534. }
  208535. void menuBarItemsChanged (MenuBarModel*)
  208536. {
  208537. lastUpdateTime = Time::getMillisecondCounter();
  208538. StringArray menuNames;
  208539. if (currentModel != 0)
  208540. menuNames = currentModel->getMenuBarNames();
  208541. NSMenu* menuBar = [NSApp mainMenu];
  208542. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208543. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208544. int menuId = 1;
  208545. for (int i = 0; i < menuNames.size(); ++i)
  208546. {
  208547. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208548. if (i >= [menuBar numberOfItems] - 1)
  208549. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208550. else
  208551. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208552. }
  208553. }
  208554. static void flashMenuBar (NSMenu* menu)
  208555. {
  208556. [menu retain];
  208557. const unichar f35Key = NSF35FunctionKey;
  208558. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208559. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208560. action: nil
  208561. keyEquivalent: f35String];
  208562. [item setTarget: nil];
  208563. [menu insertItem: item atIndex: [menu numberOfItems]];
  208564. [item release];
  208565. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208566. location: NSZeroPoint
  208567. modifierFlags: NSCommandKeyMask
  208568. timestamp: 0
  208569. windowNumber: 0
  208570. context: [NSGraphicsContext currentContext]
  208571. characters: f35String
  208572. charactersIgnoringModifiers: f35String
  208573. isARepeat: NO
  208574. keyCode: 0];
  208575. [menu performKeyEquivalent: f35Event];
  208576. if ([menu indexOfItem: item] >= 0)
  208577. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208578. [menu release];
  208579. }
  208580. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208581. {
  208582. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208583. {
  208584. NSMenuItem* m = [menu itemAtIndex: i];
  208585. if ([m tag] == info.commandID)
  208586. return m;
  208587. if ([m submenu] != 0)
  208588. {
  208589. NSMenuItem* found = findMenuItem ([m submenu], info);
  208590. if (found != 0)
  208591. return found;
  208592. }
  208593. }
  208594. return 0;
  208595. }
  208596. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208597. {
  208598. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208599. if (item != 0)
  208600. flashMenuBar ([item menu]);
  208601. }
  208602. void updateMenus()
  208603. {
  208604. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208605. menuBarItemsChanged (0);
  208606. }
  208607. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208608. {
  208609. if (currentModel != 0)
  208610. {
  208611. if (commandManager != 0)
  208612. {
  208613. ApplicationCommandTarget::InvocationInfo info (commandId);
  208614. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208615. commandManager->invoke (info, true);
  208616. }
  208617. currentModel->menuItemSelected (commandId, topLevelIndex);
  208618. }
  208619. }
  208620. MenuBarModel* currentModel;
  208621. uint32 lastUpdateTime;
  208622. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208623. const int topLevelMenuId, const int topLevelIndex)
  208624. {
  208625. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208626. if (text == 0)
  208627. text = @"";
  208628. if (iter.isSeparator)
  208629. {
  208630. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208631. }
  208632. else if (iter.isSectionHeader)
  208633. {
  208634. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208635. action: nil
  208636. keyEquivalent: @""];
  208637. [item setEnabled: false];
  208638. }
  208639. else if (iter.subMenu != 0)
  208640. {
  208641. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208642. action: nil
  208643. keyEquivalent: @""];
  208644. [item setTag: iter.itemId];
  208645. [item setEnabled: iter.isEnabled];
  208646. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208647. [sub setDelegate: nil];
  208648. [menuToAddTo setSubmenu: sub forItem: item];
  208649. [sub release];
  208650. }
  208651. else
  208652. {
  208653. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208654. action: @selector (menuItemInvoked:)
  208655. keyEquivalent: @""];
  208656. [item setTag: iter.itemId];
  208657. [item setEnabled: iter.isEnabled];
  208658. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208659. [item setTarget: (id) callback];
  208660. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208661. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208662. [item setRepresentedObject: info];
  208663. if (iter.commandManager != 0)
  208664. {
  208665. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208666. ->getKeyPressesAssignedToCommand (iter.itemId));
  208667. if (keyPresses.size() > 0)
  208668. {
  208669. const KeyPress& kp = keyPresses.getReference(0);
  208670. juce_wchar key = kp.getTextCharacter();
  208671. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208672. key = NSBackspaceCharacter;
  208673. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208674. key = NSDeleteCharacter;
  208675. else if (key == 0)
  208676. key = (juce_wchar) kp.getKeyCode();
  208677. unsigned int mods = 0;
  208678. if (kp.getModifiers().isShiftDown())
  208679. mods |= NSShiftKeyMask;
  208680. if (kp.getModifiers().isCtrlDown())
  208681. mods |= NSControlKeyMask;
  208682. if (kp.getModifiers().isAltDown())
  208683. mods |= NSAlternateKeyMask;
  208684. if (kp.getModifiers().isCommandDown())
  208685. mods |= NSCommandKeyMask;
  208686. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208687. [item setKeyEquivalentModifierMask: mods];
  208688. }
  208689. }
  208690. }
  208691. }
  208692. JuceMenuCallback* callback;
  208693. private:
  208694. NSMenu* createMenu (const PopupMenu menu,
  208695. const String& menuName,
  208696. const int topLevelMenuId,
  208697. const int topLevelIndex)
  208698. {
  208699. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208700. [m setAutoenablesItems: false];
  208701. [m setDelegate: callback];
  208702. PopupMenu::MenuItemIterator iter (menu);
  208703. while (iter.next())
  208704. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208705. [m update];
  208706. return m;
  208707. }
  208708. };
  208709. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208710. END_JUCE_NAMESPACE
  208711. @implementation JuceMenuCallback
  208712. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208713. {
  208714. [super init];
  208715. owner = owner_;
  208716. return self;
  208717. }
  208718. - (void) dealloc
  208719. {
  208720. [super dealloc];
  208721. }
  208722. - (void) menuItemInvoked: (id) menu
  208723. {
  208724. NSMenuItem* item = (NSMenuItem*) menu;
  208725. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208726. {
  208727. // 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
  208728. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208729. // into the focused component and let it trigger the menu item indirectly.
  208730. NSEvent* e = [NSApp currentEvent];
  208731. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208732. {
  208733. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208734. {
  208735. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208736. if (peer != 0)
  208737. {
  208738. if ([e type] == NSKeyDown)
  208739. peer->redirectKeyDown (e);
  208740. else
  208741. peer->redirectKeyUp (e);
  208742. return;
  208743. }
  208744. }
  208745. }
  208746. NSArray* info = (NSArray*) [item representedObject];
  208747. owner->invoke ((int) [item tag],
  208748. (ApplicationCommandManager*) (pointer_sized_int)
  208749. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208750. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208751. }
  208752. }
  208753. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208754. {
  208755. if (JuceMainMenuHandler::instance != 0)
  208756. JuceMainMenuHandler::instance->updateMenus();
  208757. }
  208758. @end
  208759. BEGIN_JUCE_NAMESPACE
  208760. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208761. const PopupMenu* extraItems)
  208762. {
  208763. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208764. {
  208765. PopupMenu::MenuItemIterator iter (*extraItems);
  208766. while (iter.next())
  208767. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208768. [menu addItem: [NSMenuItem separatorItem]];
  208769. }
  208770. NSMenuItem* item;
  208771. // Services...
  208772. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208773. action: nil keyEquivalent: @""];
  208774. [menu addItem: item];
  208775. [item release];
  208776. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208777. [menu setSubmenu: servicesMenu forItem: item];
  208778. [NSApp setServicesMenu: servicesMenu];
  208779. [servicesMenu release];
  208780. [menu addItem: [NSMenuItem separatorItem]];
  208781. // Hide + Show stuff...
  208782. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208783. action: @selector (hide:) keyEquivalent: @"h"];
  208784. [item setTarget: NSApp];
  208785. [menu addItem: item];
  208786. [item release];
  208787. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208788. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208789. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208790. [item setTarget: NSApp];
  208791. [menu addItem: item];
  208792. [item release];
  208793. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208794. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208795. [item setTarget: NSApp];
  208796. [menu addItem: item];
  208797. [item release];
  208798. [menu addItem: [NSMenuItem separatorItem]];
  208799. // Quit item....
  208800. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208801. action: @selector (terminate:) keyEquivalent: @"q"];
  208802. [item setTarget: NSApp];
  208803. [menu addItem: item];
  208804. [item release];
  208805. return menu;
  208806. }
  208807. // Since our app has no NIB, this initialises a standard app menu...
  208808. static void rebuildMainMenu (const PopupMenu* extraItems)
  208809. {
  208810. // this can't be used in a plugin!
  208811. jassert (JUCEApplication::getInstance() != 0);
  208812. if (JUCEApplication::getInstance() != 0)
  208813. {
  208814. const ScopedAutoReleasePool pool;
  208815. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208816. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208817. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208818. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208819. [mainMenu setSubmenu: appMenu forItem: item];
  208820. [NSApp setMainMenu: mainMenu];
  208821. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208822. [appMenu release];
  208823. [mainMenu release];
  208824. }
  208825. }
  208826. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208827. const PopupMenu* extraAppleMenuItems)
  208828. {
  208829. if (getMacMainMenu() != newMenuBarModel)
  208830. {
  208831. const ScopedAutoReleasePool pool;
  208832. if (newMenuBarModel == 0)
  208833. {
  208834. delete JuceMainMenuHandler::instance;
  208835. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208836. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208837. extraAppleMenuItems = 0;
  208838. }
  208839. else
  208840. {
  208841. if (JuceMainMenuHandler::instance == 0)
  208842. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208843. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208844. }
  208845. }
  208846. rebuildMainMenu (extraAppleMenuItems);
  208847. if (newMenuBarModel != 0)
  208848. newMenuBarModel->menuItemsChanged();
  208849. }
  208850. MenuBarModel* MenuBarModel::getMacMainMenu()
  208851. {
  208852. return JuceMainMenuHandler::instance != 0
  208853. ? JuceMainMenuHandler::instance->currentModel : 0;
  208854. }
  208855. void initialiseMainMenu()
  208856. {
  208857. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208858. rebuildMainMenu (0);
  208859. }
  208860. #endif
  208861. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208862. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208863. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208864. // compiled on its own).
  208865. #if JUCE_INCLUDED_FILE
  208866. #if JUCE_MAC
  208867. END_JUCE_NAMESPACE
  208868. using namespace JUCE_NAMESPACE;
  208869. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208870. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208871. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208872. #else
  208873. @interface JuceFileChooserDelegate : NSObject
  208874. #endif
  208875. {
  208876. StringArray* filters;
  208877. }
  208878. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208879. - (void) dealloc;
  208880. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208881. @end
  208882. @implementation JuceFileChooserDelegate
  208883. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208884. {
  208885. [super init];
  208886. filters = filters_;
  208887. return self;
  208888. }
  208889. - (void) dealloc
  208890. {
  208891. delete filters;
  208892. [super dealloc];
  208893. }
  208894. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208895. {
  208896. const File f (nsStringToJuce (filename));
  208897. for (int i = filters->size(); --i >= 0;)
  208898. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208899. return true;
  208900. return f.isDirectory();
  208901. }
  208902. @end
  208903. BEGIN_JUCE_NAMESPACE
  208904. void FileChooser::showPlatformDialog (Array<File>& results,
  208905. const String& title,
  208906. const File& currentFileOrDirectory,
  208907. const String& filter,
  208908. bool selectsDirectory,
  208909. bool selectsFiles,
  208910. bool isSaveDialogue,
  208911. bool warnAboutOverwritingExistingFiles,
  208912. bool selectMultipleFiles,
  208913. FilePreviewComponent* extraInfoComponent)
  208914. {
  208915. const ScopedAutoReleasePool pool;
  208916. StringArray* filters = new StringArray();
  208917. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  208918. filters->trim();
  208919. filters->removeEmptyStrings();
  208920. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208921. [delegate autorelease];
  208922. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208923. : [NSOpenPanel openPanel];
  208924. [panel setTitle: juceStringToNS (title)];
  208925. if (! isSaveDialogue)
  208926. {
  208927. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208928. [openPanel setCanChooseDirectories: selectsDirectory];
  208929. [openPanel setCanChooseFiles: selectsFiles];
  208930. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208931. }
  208932. [panel setDelegate: delegate];
  208933. if (isSaveDialogue || selectsDirectory)
  208934. [panel setCanCreateDirectories: YES];
  208935. String directory, filename;
  208936. if (currentFileOrDirectory.isDirectory())
  208937. {
  208938. directory = currentFileOrDirectory.getFullPathName();
  208939. }
  208940. else
  208941. {
  208942. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208943. filename = currentFileOrDirectory.getFileName();
  208944. }
  208945. if ([panel runModalForDirectory: juceStringToNS (directory)
  208946. file: juceStringToNS (filename)]
  208947. == NSOKButton)
  208948. {
  208949. if (isSaveDialogue)
  208950. {
  208951. results.add (File (nsStringToJuce ([panel filename])));
  208952. }
  208953. else
  208954. {
  208955. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208956. NSArray* urls = [openPanel filenames];
  208957. for (unsigned int i = 0; i < [urls count]; ++i)
  208958. {
  208959. NSString* f = [urls objectAtIndex: i];
  208960. results.add (File (nsStringToJuce (f)));
  208961. }
  208962. }
  208963. }
  208964. [panel setDelegate: nil];
  208965. }
  208966. #else
  208967. void FileChooser::showPlatformDialog (Array<File>& results,
  208968. const String& title,
  208969. const File& currentFileOrDirectory,
  208970. const String& filter,
  208971. bool selectsDirectory,
  208972. bool selectsFiles,
  208973. bool isSaveDialogue,
  208974. bool warnAboutOverwritingExistingFiles,
  208975. bool selectMultipleFiles,
  208976. FilePreviewComponent* extraInfoComponent)
  208977. {
  208978. const ScopedAutoReleasePool pool;
  208979. jassertfalse //xxx to do
  208980. }
  208981. #endif
  208982. #endif
  208983. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  208984. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  208985. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208986. // compiled on its own).
  208987. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  208988. #define theMovie ((QTMovie*) movie)
  208989. QuickTimeMovieComponent::QuickTimeMovieComponent()
  208990. : movie (0)
  208991. {
  208992. setOpaque (true);
  208993. setVisible (true);
  208994. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  208995. setView (view);
  208996. }
  208997. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  208998. {
  208999. closeMovie();
  209000. setView (0);
  209001. }
  209002. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209003. {
  209004. return true;
  209005. }
  209006. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209007. {
  209008. // unfortunately, QTMovie objects can only be created on the main thread..
  209009. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209010. QTMovie* movie = 0;
  209011. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209012. if (fin != 0)
  209013. {
  209014. movieFile = fin->getFile();
  209015. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209016. error: nil];
  209017. }
  209018. else
  209019. {
  209020. MemoryBlock temp;
  209021. movieStream->readIntoMemoryBlock (temp);
  209022. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209023. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209024. {
  209025. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209026. length: temp.getSize()]
  209027. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209028. MIMEType: @""]
  209029. error: nil];
  209030. if (movie != 0)
  209031. break;
  209032. }
  209033. }
  209034. return movie;
  209035. }
  209036. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209037. const bool isControllerVisible_)
  209038. {
  209039. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209040. }
  209041. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209042. const bool controllerVisible_)
  209043. {
  209044. closeMovie();
  209045. if (getPeer() == 0)
  209046. {
  209047. // To open a movie, this component must be visible inside a functioning window, so that
  209048. // the QT control can be assigned to the window.
  209049. jassertfalse
  209050. return false;
  209051. }
  209052. movie = openMovieFromStream (movieStream, movieFile);
  209053. [theMovie retain];
  209054. QTMovieView* view = (QTMovieView*) getView();
  209055. [view setMovie: theMovie];
  209056. [view setControllerVisible: controllerVisible_];
  209057. setLooping (looping);
  209058. return movie != nil;
  209059. }
  209060. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209061. const bool isControllerVisible_)
  209062. {
  209063. // unfortunately, QTMovie objects can only be created on the main thread..
  209064. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209065. closeMovie();
  209066. if (getPeer() == 0)
  209067. {
  209068. // To open a movie, this component must be visible inside a functioning window, so that
  209069. // the QT control can be assigned to the window.
  209070. jassertfalse
  209071. return false;
  209072. }
  209073. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209074. NSError* err;
  209075. if ([QTMovie canInitWithURL: url])
  209076. movie = [QTMovie movieWithURL: url error: &err];
  209077. [theMovie retain];
  209078. QTMovieView* view = (QTMovieView*) getView();
  209079. [view setMovie: theMovie];
  209080. [view setControllerVisible: controllerVisible];
  209081. setLooping (looping);
  209082. return movie != nil;
  209083. }
  209084. void QuickTimeMovieComponent::closeMovie()
  209085. {
  209086. stop();
  209087. QTMovieView* view = (QTMovieView*) getView();
  209088. [view setMovie: nil];
  209089. [theMovie release];
  209090. movie = 0;
  209091. movieFile = File::nonexistent;
  209092. }
  209093. bool QuickTimeMovieComponent::isMovieOpen() const
  209094. {
  209095. return movie != nil;
  209096. }
  209097. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209098. {
  209099. return movieFile;
  209100. }
  209101. void QuickTimeMovieComponent::play()
  209102. {
  209103. [theMovie play];
  209104. }
  209105. void QuickTimeMovieComponent::stop()
  209106. {
  209107. [theMovie stop];
  209108. }
  209109. bool QuickTimeMovieComponent::isPlaying() const
  209110. {
  209111. return movie != 0 && [theMovie rate] != 0;
  209112. }
  209113. void QuickTimeMovieComponent::setPosition (const double seconds)
  209114. {
  209115. if (movie != 0)
  209116. {
  209117. QTTime t;
  209118. t.timeValue = (uint64) (100000.0 * seconds);
  209119. t.timeScale = 100000;
  209120. t.flags = 0;
  209121. [theMovie setCurrentTime: t];
  209122. }
  209123. }
  209124. double QuickTimeMovieComponent::getPosition() const
  209125. {
  209126. if (movie == 0)
  209127. return 0.0;
  209128. QTTime t = [theMovie currentTime];
  209129. return t.timeValue / (double) t.timeScale;
  209130. }
  209131. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209132. {
  209133. [theMovie setRate: newSpeed];
  209134. }
  209135. double QuickTimeMovieComponent::getMovieDuration() const
  209136. {
  209137. if (movie == 0)
  209138. return 0.0;
  209139. QTTime t = [theMovie duration];
  209140. return t.timeValue / (double) t.timeScale;
  209141. }
  209142. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209143. {
  209144. looping = shouldLoop;
  209145. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209146. forKey: QTMovieLoopsAttribute];
  209147. }
  209148. bool QuickTimeMovieComponent::isLooping() const
  209149. {
  209150. return looping;
  209151. }
  209152. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209153. {
  209154. [theMovie setVolume: newVolume];
  209155. }
  209156. float QuickTimeMovieComponent::getMovieVolume() const
  209157. {
  209158. return movie != 0 ? [theMovie volume] : 0.0f;
  209159. }
  209160. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209161. {
  209162. width = 0;
  209163. height = 0;
  209164. if (movie != 0)
  209165. {
  209166. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209167. width = (int) s.width;
  209168. height = (int) s.height;
  209169. }
  209170. }
  209171. void QuickTimeMovieComponent::paint (Graphics& g)
  209172. {
  209173. if (movie == 0)
  209174. g.fillAll (Colours::black);
  209175. }
  209176. bool QuickTimeMovieComponent::isControllerVisible() const
  209177. {
  209178. return controllerVisible;
  209179. }
  209180. void QuickTimeMovieComponent::goToStart()
  209181. {
  209182. setPosition (0.0);
  209183. }
  209184. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209185. const RectanglePlacement& placement)
  209186. {
  209187. int normalWidth, normalHeight;
  209188. getMovieNormalSize (normalWidth, normalHeight);
  209189. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209190. {
  209191. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209192. placement.applyTo (x, y, w, h,
  209193. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209194. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209195. if (w > 0 && h > 0)
  209196. {
  209197. setBounds (roundToInt (x), roundToInt (y),
  209198. roundToInt (w), roundToInt (h));
  209199. }
  209200. }
  209201. else
  209202. {
  209203. setBounds (spaceToFitWithin);
  209204. }
  209205. }
  209206. #if ! (JUCE_MAC && JUCE_64BIT)
  209207. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209208. {
  209209. if (movieStream == 0)
  209210. return false;
  209211. File file;
  209212. QTMovie* movie = openMovieFromStream (movieStream, file);
  209213. if (movie != nil)
  209214. result = [movie quickTimeMovie];
  209215. return movie != nil;
  209216. }
  209217. #endif
  209218. #endif
  209219. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209220. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209221. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209222. // compiled on its own).
  209223. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209224. END_JUCE_NAMESPACE
  209225. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209226. @interface OpenDiskDevice : NSObject
  209227. {
  209228. DRDevice* device;
  209229. NSMutableArray* tracks;
  209230. }
  209231. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device;
  209232. - (void) dealloc;
  209233. - (bool) isDiskPresent;
  209234. - (int) getNumAvailableAudioBlocks;
  209235. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209236. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209237. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting;
  209238. @end
  209239. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209240. @interface AudioTrackProducer : NSObject
  209241. {
  209242. JUCE_NAMESPACE::AudioSource* source;
  209243. int readPosition, lengthInFrames;
  209244. }
  209245. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209246. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209247. - (void) dealloc;
  209248. - (void) setupTrackProperties: (DRTrack*) track;
  209249. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209250. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209251. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209252. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209253. toMedia:(NSDictionary*)mediaInfo;
  209254. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209255. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209256. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209257. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209258. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209259. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209260. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209261. ioFlags:(uint32_t*)flags;
  209262. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209263. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209264. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209265. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209266. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209267. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209268. ioFlags:(uint32_t*)flags;
  209269. @end
  209270. @implementation OpenDiskDevice
  209271. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device_
  209272. {
  209273. [super init];
  209274. device = device_;
  209275. tracks = [[NSMutableArray alloc] init];
  209276. return self;
  209277. }
  209278. - (void) dealloc
  209279. {
  209280. [tracks release];
  209281. [super dealloc];
  209282. }
  209283. - (bool) isDiskPresent
  209284. {
  209285. return [device isValid]
  209286. && [[[device status] objectForKey: DRDeviceMediaStateKey]
  209287. isEqualTo: DRDeviceMediaStateMediaPresent];
  209288. }
  209289. - (int) getNumAvailableAudioBlocks
  209290. {
  209291. return [[[[device status] objectForKey: DRDeviceMediaInfoKey]
  209292. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209293. }
  209294. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209295. {
  209296. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209297. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209298. [p setupTrackProperties: t];
  209299. [tracks addObject: t];
  209300. [t release];
  209301. [p release];
  209302. }
  209303. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209304. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting
  209305. {
  209306. DRBurn* burn = [DRBurn burnForDevice: device];
  209307. if (! [device acquireExclusiveAccess])
  209308. {
  209309. *error = "Couldn't open or write to the CD device";
  209310. return;
  209311. }
  209312. [device acquireMediaReservation];
  209313. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209314. [d autorelease];
  209315. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209316. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209317. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount)
  209318. forKey: DRBurnCompletionActionKey];
  209319. [burn setProperties: d];
  209320. [burn writeLayout: tracks];
  209321. for (;;)
  209322. {
  209323. JUCE_NAMESPACE::Thread::sleep (300);
  209324. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209325. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209326. {
  209327. [burn abort];
  209328. *error = "User cancelled the write operation";
  209329. break;
  209330. }
  209331. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209332. {
  209333. *error = "Write operation failed";
  209334. break;
  209335. }
  209336. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209337. {
  209338. break;
  209339. }
  209340. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209341. objectForKey: DRErrorStatusErrorStringKey];
  209342. if ([err length] > 0)
  209343. {
  209344. *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]);
  209345. break;
  209346. }
  209347. }
  209348. [device releaseMediaReservation];
  209349. [device releaseExclusiveAccess];
  209350. }
  209351. @end
  209352. @implementation AudioTrackProducer
  209353. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209354. {
  209355. lengthInFrames = lengthInFrames_;
  209356. readPosition = 0;
  209357. return self;
  209358. }
  209359. - (void) setupTrackProperties: (DRTrack*) track
  209360. {
  209361. NSMutableDictionary* p = [[track properties] mutableCopy];
  209362. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209363. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209364. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209365. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209366. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209367. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209368. [track setProperties: p];
  209369. [p release];
  209370. }
  209371. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209372. {
  209373. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209374. if (s != nil)
  209375. s->source = source_;
  209376. return s;
  209377. }
  209378. - (void) dealloc
  209379. {
  209380. if (source != 0)
  209381. {
  209382. source->releaseResources();
  209383. delete source;
  209384. }
  209385. [super dealloc];
  209386. }
  209387. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209388. {
  209389. }
  209390. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209391. {
  209392. return true;
  209393. }
  209394. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209395. {
  209396. return lengthInFrames;
  209397. }
  209398. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209399. toMedia: (NSDictionary*) mediaInfo
  209400. {
  209401. if (source != 0)
  209402. source->prepareToPlay (44100 / 75, 44100);
  209403. readPosition = 0;
  209404. return true;
  209405. }
  209406. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209407. {
  209408. if (source != 0)
  209409. source->prepareToPlay (44100 / 75, 44100);
  209410. return true;
  209411. }
  209412. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209413. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209414. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209415. {
  209416. if (source != 0)
  209417. {
  209418. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209419. if (numSamples > 0)
  209420. {
  209421. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209422. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209423. info.buffer = &tempBuffer;
  209424. info.startSample = 0;
  209425. info.numSamples = numSamples;
  209426. source->getNextAudioBlock (info);
  209427. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209428. buffer, numSamples, 4);
  209429. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209430. buffer + 2, numSamples, 4);
  209431. readPosition += numSamples;
  209432. }
  209433. return numSamples * 4;
  209434. }
  209435. return 0;
  209436. }
  209437. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209438. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209439. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209440. ioFlags: (uint32_t*) flags
  209441. {
  209442. zeromem (buffer, bufferLength);
  209443. return bufferLength;
  209444. }
  209445. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209446. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209447. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209448. {
  209449. return true;
  209450. }
  209451. @end
  209452. BEGIN_JUCE_NAMESPACE
  209453. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209454. : internal (0)
  209455. {
  209456. OpenDiskDevice* dev = [[OpenDiskDevice alloc] initWithDevice: [[DRDevice devices] objectAtIndex: deviceIndex]];
  209457. internal = (void*) dev;
  209458. }
  209459. AudioCDBurner::~AudioCDBurner()
  209460. {
  209461. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209462. if (dev != 0)
  209463. [dev release];
  209464. }
  209465. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209466. {
  209467. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209468. if (b->internal == 0)
  209469. b = 0;
  209470. return b.release();
  209471. }
  209472. static NSArray* findDiskBurnerDevices()
  209473. {
  209474. NSMutableArray* results = [NSMutableArray array];
  209475. NSArray* devs = [DRDevice devices];
  209476. if (devs != 0)
  209477. {
  209478. int num = [devs count];
  209479. int i;
  209480. for (i = 0; i < num; ++i)
  209481. {
  209482. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209483. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209484. if (name != nil)
  209485. [results addObject: name];
  209486. }
  209487. }
  209488. return results;
  209489. }
  209490. const StringArray AudioCDBurner::findAvailableDevices()
  209491. {
  209492. NSArray* names = findDiskBurnerDevices();
  209493. StringArray s;
  209494. for (unsigned int i = 0; i < [names count]; ++i)
  209495. s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String]));
  209496. return s;
  209497. }
  209498. bool AudioCDBurner::isDiskPresent() const
  209499. {
  209500. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209501. return dev != 0 && [dev isDiskPresent];
  209502. }
  209503. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209504. {
  209505. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209506. return [dev getNumAvailableAudioBlocks];
  209507. }
  209508. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209509. {
  209510. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209511. if (dev != 0)
  209512. {
  209513. [dev addSourceTrack: source numSamples: numSamps];
  209514. return true;
  209515. }
  209516. return false;
  209517. }
  209518. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209519. const bool ejectDiscAfterwards,
  209520. const bool peformFakeBurnForTesting)
  209521. {
  209522. String error ("Couldn't open or write to the CD device");
  209523. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209524. if (dev != 0)
  209525. {
  209526. error = String::empty;
  209527. [dev burn: listener
  209528. errorString: &error
  209529. ejectAfterwards: ejectDiscAfterwards
  209530. isFake: peformFakeBurnForTesting];
  209531. }
  209532. return error;
  209533. }
  209534. void AudioCDReader::ejectDisk()
  209535. {
  209536. const ScopedAutoReleasePool p;
  209537. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209538. }
  209539. #endif
  209540. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209541. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209542. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209543. // compiled on its own).
  209544. #if JUCE_INCLUDED_FILE
  209545. struct CallbackMessagePayload
  209546. {
  209547. MessageCallbackFunction* function;
  209548. void* parameter;
  209549. void* volatile result;
  209550. bool volatile hasBeenExecuted;
  209551. };
  209552. class AppDelegateRedirector
  209553. {
  209554. public:
  209555. AppDelegateRedirector()
  209556. {
  209557. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209558. runLoop = CFRunLoopGetMain();
  209559. #else
  209560. runLoop = CFRunLoopGetCurrent();
  209561. #endif
  209562. CFRunLoopSourceContext sourceContext;
  209563. zerostruct (sourceContext);
  209564. sourceContext.info = this;
  209565. sourceContext.perform = runLoopSourceCallback;
  209566. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209567. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209568. }
  209569. virtual ~AppDelegateRedirector()
  209570. {
  209571. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209572. CFRunLoopSourceInvalidate (runLoopSource);
  209573. CFRelease (runLoopSource);
  209574. while (messages.size() > 0)
  209575. delete ((Message*) messages.remove(0));
  209576. }
  209577. virtual NSApplicationTerminateReply shouldTerminate()
  209578. {
  209579. if (JUCEApplication::getInstance() != 0)
  209580. {
  209581. JUCEApplication::getInstance()->systemRequestedQuit();
  209582. return NSTerminateCancel;
  209583. }
  209584. return NSTerminateNow;
  209585. }
  209586. virtual BOOL openFile (const NSString* filename)
  209587. {
  209588. if (JUCEApplication::getInstance() != 0)
  209589. {
  209590. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209591. return YES;
  209592. }
  209593. return NO;
  209594. }
  209595. virtual void openFiles (NSArray* filenames)
  209596. {
  209597. StringArray files;
  209598. for (unsigned int i = 0; i < [filenames count]; ++i)
  209599. {
  209600. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209601. if (filename.containsChar (T(' ')))
  209602. filename = filename.quoted('"');
  209603. files.add (filename);
  209604. }
  209605. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209606. {
  209607. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209608. }
  209609. }
  209610. virtual void focusChanged()
  209611. {
  209612. juce_HandleProcessFocusChange();
  209613. }
  209614. virtual void performCallback (CallbackMessagePayload* pl)
  209615. {
  209616. pl->result = (*pl->function) (pl->parameter);
  209617. pl->hasBeenExecuted = true;
  209618. }
  209619. virtual void deleteSelf()
  209620. {
  209621. delete this;
  209622. }
  209623. void postMessage (void* m)
  209624. {
  209625. messages.add (m);
  209626. CFRunLoopSourceSignal (runLoopSource);
  209627. CFRunLoopWakeUp (runLoop);
  209628. }
  209629. private:
  209630. CFRunLoopRef runLoop;
  209631. CFRunLoopSourceRef runLoopSource;
  209632. Array <void*, CriticalSection> messages;
  209633. void runLoopCallback()
  209634. {
  209635. int numDispatched = 0;
  209636. do
  209637. {
  209638. void* const nextMessage = messages.remove (0);
  209639. if (nextMessage == 0)
  209640. return;
  209641. const ScopedAutoReleasePool pool;
  209642. MessageManager::getInstance()->deliverMessage (nextMessage);
  209643. } while (++numDispatched <= 4);
  209644. CFRunLoopSourceSignal (runLoopSource);
  209645. CFRunLoopWakeUp (runLoop);
  209646. }
  209647. static void runLoopSourceCallback (void* info)
  209648. {
  209649. ((AppDelegateRedirector*) info)->runLoopCallback();
  209650. }
  209651. };
  209652. END_JUCE_NAMESPACE
  209653. using namespace JUCE_NAMESPACE;
  209654. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209655. @interface JuceAppDelegate : NSObject
  209656. {
  209657. @private
  209658. id oldDelegate;
  209659. @public
  209660. AppDelegateRedirector* redirector;
  209661. }
  209662. - (JuceAppDelegate*) init;
  209663. - (void) dealloc;
  209664. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209665. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209666. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209667. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209668. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209669. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209670. - (void) performCallback: (id) info;
  209671. - (void) dummyMethod;
  209672. @end
  209673. @implementation JuceAppDelegate
  209674. - (JuceAppDelegate*) init
  209675. {
  209676. [super init];
  209677. redirector = new AppDelegateRedirector();
  209678. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209679. if (JUCEApplication::getInstance() != 0)
  209680. {
  209681. oldDelegate = [NSApp delegate];
  209682. [NSApp setDelegate: self];
  209683. }
  209684. else
  209685. {
  209686. oldDelegate = 0;
  209687. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209688. name: NSApplicationDidResignActiveNotification object: NSApp];
  209689. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209690. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209691. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209692. name: NSApplicationWillUnhideNotification object: NSApp];
  209693. }
  209694. return self;
  209695. }
  209696. - (void) dealloc
  209697. {
  209698. if (oldDelegate != 0)
  209699. [NSApp setDelegate: oldDelegate];
  209700. redirector->deleteSelf();
  209701. [super dealloc];
  209702. }
  209703. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209704. {
  209705. return redirector->shouldTerminate();
  209706. }
  209707. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209708. {
  209709. return redirector->openFile (filename);
  209710. }
  209711. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209712. {
  209713. return redirector->openFiles (filenames);
  209714. }
  209715. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209716. {
  209717. redirector->focusChanged();
  209718. }
  209719. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209720. {
  209721. redirector->focusChanged();
  209722. }
  209723. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209724. {
  209725. redirector->focusChanged();
  209726. }
  209727. - (void) performCallback: (id) info
  209728. {
  209729. if ([info isKindOfClass: [NSData class]])
  209730. {
  209731. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209732. if (pl != 0)
  209733. redirector->performCallback (pl);
  209734. }
  209735. else
  209736. {
  209737. jassertfalse // should never get here!
  209738. }
  209739. }
  209740. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209741. @end
  209742. BEGIN_JUCE_NAMESPACE
  209743. static JuceAppDelegate* juceAppDelegate = 0;
  209744. void MessageManager::runDispatchLoop()
  209745. {
  209746. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209747. {
  209748. const ScopedAutoReleasePool pool;
  209749. // must only be called by the message thread!
  209750. jassert (isThisTheMessageThread());
  209751. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209752. @try
  209753. {
  209754. [NSApp run];
  209755. }
  209756. @catch (NSException* e)
  209757. {
  209758. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209759. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209760. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209761. }
  209762. @finally
  209763. {
  209764. }
  209765. #else
  209766. [NSApp run];
  209767. #endif
  209768. }
  209769. }
  209770. void MessageManager::stopDispatchLoop()
  209771. {
  209772. quitMessagePosted = true;
  209773. [NSApp stop: nil];
  209774. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209775. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209776. }
  209777. static bool isEventBlockedByModalComps (NSEvent* e)
  209778. {
  209779. if (Component::getNumCurrentlyModalComponents() == 0)
  209780. return false;
  209781. NSWindow* const w = [e window];
  209782. if (w == 0 || [w worksWhenModal])
  209783. return false;
  209784. bool isKey = false, isInputAttempt = false;
  209785. switch ([e type])
  209786. {
  209787. case NSKeyDown:
  209788. case NSKeyUp:
  209789. isKey = isInputAttempt = true;
  209790. break;
  209791. case NSLeftMouseDown:
  209792. case NSRightMouseDown:
  209793. case NSOtherMouseDown:
  209794. isInputAttempt = true;
  209795. break;
  209796. case NSLeftMouseDragged:
  209797. case NSRightMouseDragged:
  209798. case NSLeftMouseUp:
  209799. case NSRightMouseUp:
  209800. case NSOtherMouseUp:
  209801. case NSOtherMouseDragged:
  209802. if (Component::getComponentUnderMouse() != 0)
  209803. return false;
  209804. break;
  209805. case NSMouseMoved:
  209806. case NSMouseEntered:
  209807. case NSMouseExited:
  209808. case NSCursorUpdate:
  209809. case NSScrollWheel:
  209810. case NSTabletPoint:
  209811. case NSTabletProximity:
  209812. break;
  209813. default:
  209814. return false;
  209815. }
  209816. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209817. {
  209818. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209819. NSView* const compView = (NSView*) peer->getNativeHandle();
  209820. if ([compView window] == w)
  209821. {
  209822. if (isKey)
  209823. {
  209824. if (compView == [w firstResponder])
  209825. return false;
  209826. }
  209827. else
  209828. {
  209829. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209830. [compView bounds]))
  209831. return false;
  209832. }
  209833. }
  209834. }
  209835. if (isInputAttempt)
  209836. {
  209837. if (! [NSApp isActive])
  209838. [NSApp activateIgnoringOtherApps: YES];
  209839. Component* const modal = Component::getCurrentlyModalComponent (0);
  209840. if (modal != 0)
  209841. modal->inputAttemptWhenModal();
  209842. }
  209843. return true;
  209844. }
  209845. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209846. {
  209847. const ScopedAutoReleasePool pool;
  209848. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209849. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209850. while (! quitMessagePosted)
  209851. {
  209852. const ScopedAutoReleasePool pool2;
  209853. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209854. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209855. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209856. inMode: NSDefaultRunLoopMode
  209857. dequeue: YES];
  209858. if (e != 0 && ! isEventBlockedByModalComps (e))
  209859. [NSApp sendEvent: e];
  209860. if (Time::getMillisecondCounter() >= endTime)
  209861. break;
  209862. }
  209863. return ! quitMessagePosted;
  209864. }
  209865. void MessageManager::doPlatformSpecificInitialisation()
  209866. {
  209867. if (juceAppDelegate == 0)
  209868. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209869. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209870. // correctly (needed prior to 10.5)
  209871. if (! [NSThread isMultiThreaded])
  209872. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209873. toTarget: juceAppDelegate
  209874. withObject: nil];
  209875. initialiseMainMenu();
  209876. }
  209877. void MessageManager::doPlatformSpecificShutdown()
  209878. {
  209879. if (juceAppDelegate != 0)
  209880. {
  209881. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209882. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209883. [juceAppDelegate release];
  209884. juceAppDelegate = 0;
  209885. }
  209886. }
  209887. bool juce_postMessageToSystemQueue (void* message)
  209888. {
  209889. juceAppDelegate->redirector->postMessage (message);
  209890. return true;
  209891. }
  209892. void MessageManager::broadcastMessage (const String& value) throw()
  209893. {
  209894. }
  209895. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209896. void* data)
  209897. {
  209898. if (isThisTheMessageThread())
  209899. {
  209900. return (*callback) (data);
  209901. }
  209902. else
  209903. {
  209904. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209905. // deadlock because the message manager is blocked from running, so can never
  209906. // call your function..
  209907. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209908. const ScopedAutoReleasePool pool;
  209909. CallbackMessagePayload cmp;
  209910. cmp.function = callback;
  209911. cmp.parameter = data;
  209912. cmp.result = 0;
  209913. cmp.hasBeenExecuted = false;
  209914. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209915. withObject: [NSData dataWithBytesNoCopy: &cmp
  209916. length: sizeof (cmp)
  209917. freeWhenDone: NO]
  209918. waitUntilDone: YES];
  209919. return cmp.result;
  209920. }
  209921. }
  209922. #endif
  209923. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209924. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209925. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209926. // compiled on its own).
  209927. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209928. #if JUCE_MAC
  209929. END_JUCE_NAMESPACE
  209930. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209931. @interface DownloadClickDetector : NSObject
  209932. {
  209933. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  209934. }
  209935. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  209936. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209937. request: (NSURLRequest*) request
  209938. frame: (WebFrame*) frame
  209939. decisionListener: (id<WebPolicyDecisionListener>) listener;
  209940. @end
  209941. @implementation DownloadClickDetector
  209942. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  209943. {
  209944. [super init];
  209945. ownerComponent = ownerComponent_;
  209946. return self;
  209947. }
  209948. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209949. request: (NSURLRequest*) request
  209950. frame: (WebFrame*) frame
  209951. decisionListener: (id <WebPolicyDecisionListener>) listener
  209952. {
  209953. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  209954. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  209955. [listener use];
  209956. else
  209957. [listener ignore];
  209958. }
  209959. @end
  209960. BEGIN_JUCE_NAMESPACE
  209961. class WebBrowserComponentInternal : public NSViewComponent
  209962. {
  209963. public:
  209964. WebBrowserComponentInternal (WebBrowserComponent* owner)
  209965. {
  209966. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  209967. frameName: @""
  209968. groupName: @""];
  209969. setView (webView);
  209970. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  209971. [webView setPolicyDelegate: clickListener];
  209972. }
  209973. ~WebBrowserComponentInternal()
  209974. {
  209975. [webView setPolicyDelegate: nil];
  209976. [clickListener release];
  209977. setView (0);
  209978. }
  209979. void goToURL (const String& url,
  209980. const StringArray* headers,
  209981. const MemoryBlock* postData)
  209982. {
  209983. NSMutableURLRequest* r
  209984. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  209985. cachePolicy: NSURLRequestUseProtocolCachePolicy
  209986. timeoutInterval: 30.0];
  209987. if (postData != 0 && postData->getSize() > 0)
  209988. {
  209989. [r setHTTPMethod: @"POST"];
  209990. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  209991. length: postData->getSize()]];
  209992. }
  209993. if (headers != 0)
  209994. {
  209995. for (int i = 0; i < headers->size(); ++i)
  209996. {
  209997. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  209998. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  209999. [r setValue: juceStringToNS (headerValue)
  210000. forHTTPHeaderField: juceStringToNS (headerName)];
  210001. }
  210002. }
  210003. stop();
  210004. [[webView mainFrame] loadRequest: r];
  210005. }
  210006. void goBack()
  210007. {
  210008. [webView goBack];
  210009. }
  210010. void goForward()
  210011. {
  210012. [webView goForward];
  210013. }
  210014. void stop()
  210015. {
  210016. [webView stopLoading: nil];
  210017. }
  210018. void refresh()
  210019. {
  210020. [webView reload: nil];
  210021. }
  210022. private:
  210023. WebView* webView;
  210024. DownloadClickDetector* clickListener;
  210025. };
  210026. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210027. : browser (0),
  210028. blankPageShown (false),
  210029. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210030. {
  210031. setOpaque (true);
  210032. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210033. }
  210034. WebBrowserComponent::~WebBrowserComponent()
  210035. {
  210036. deleteAndZero (browser);
  210037. }
  210038. void WebBrowserComponent::goToURL (const String& url,
  210039. const StringArray* headers,
  210040. const MemoryBlock* postData)
  210041. {
  210042. lastURL = url;
  210043. lastHeaders.clear();
  210044. if (headers != 0)
  210045. lastHeaders = *headers;
  210046. lastPostData.setSize (0);
  210047. if (postData != 0)
  210048. lastPostData = *postData;
  210049. blankPageShown = false;
  210050. browser->goToURL (url, headers, postData);
  210051. }
  210052. void WebBrowserComponent::stop()
  210053. {
  210054. browser->stop();
  210055. }
  210056. void WebBrowserComponent::goBack()
  210057. {
  210058. lastURL = String::empty;
  210059. blankPageShown = false;
  210060. browser->goBack();
  210061. }
  210062. void WebBrowserComponent::goForward()
  210063. {
  210064. lastURL = String::empty;
  210065. browser->goForward();
  210066. }
  210067. void WebBrowserComponent::refresh()
  210068. {
  210069. browser->refresh();
  210070. }
  210071. void WebBrowserComponent::paint (Graphics& g)
  210072. {
  210073. }
  210074. void WebBrowserComponent::checkWindowAssociation()
  210075. {
  210076. if (isShowing())
  210077. {
  210078. if (blankPageShown)
  210079. goBack();
  210080. }
  210081. else
  210082. {
  210083. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210084. {
  210085. // when the component becomes invisible, some stuff like flash
  210086. // carries on playing audio, so we need to force it onto a blank
  210087. // page to avoid this, (and send it back when it's made visible again).
  210088. blankPageShown = true;
  210089. browser->goToURL ("about:blank", 0, 0);
  210090. }
  210091. }
  210092. }
  210093. void WebBrowserComponent::reloadLastURL()
  210094. {
  210095. if (lastURL.isNotEmpty())
  210096. {
  210097. goToURL (lastURL, &lastHeaders, &lastPostData);
  210098. lastURL = String::empty;
  210099. }
  210100. }
  210101. void WebBrowserComponent::parentHierarchyChanged()
  210102. {
  210103. checkWindowAssociation();
  210104. }
  210105. void WebBrowserComponent::resized()
  210106. {
  210107. browser->setSize (getWidth(), getHeight());
  210108. }
  210109. void WebBrowserComponent::visibilityChanged()
  210110. {
  210111. checkWindowAssociation();
  210112. }
  210113. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210114. {
  210115. return true;
  210116. }
  210117. #else
  210118. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210119. {
  210120. }
  210121. WebBrowserComponent::~WebBrowserComponent()
  210122. {
  210123. }
  210124. void WebBrowserComponent::goToURL (const String& url,
  210125. const StringArray* headers,
  210126. const MemoryBlock* postData)
  210127. {
  210128. }
  210129. void WebBrowserComponent::stop()
  210130. {
  210131. }
  210132. void WebBrowserComponent::goBack()
  210133. {
  210134. }
  210135. void WebBrowserComponent::goForward()
  210136. {
  210137. }
  210138. void WebBrowserComponent::refresh()
  210139. {
  210140. }
  210141. void WebBrowserComponent::paint (Graphics& g)
  210142. {
  210143. }
  210144. void WebBrowserComponent::checkWindowAssociation()
  210145. {
  210146. }
  210147. void WebBrowserComponent::reloadLastURL()
  210148. {
  210149. }
  210150. void WebBrowserComponent::parentHierarchyChanged()
  210151. {
  210152. }
  210153. void WebBrowserComponent::resized()
  210154. {
  210155. }
  210156. void WebBrowserComponent::visibilityChanged()
  210157. {
  210158. }
  210159. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210160. {
  210161. return true;
  210162. }
  210163. #endif
  210164. #endif
  210165. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210166. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210167. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210168. // compiled on its own).
  210169. #if JUCE_INCLUDED_FILE
  210170. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210171. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210172. #endif
  210173. #undef log
  210174. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210175. #define log(a) Logger::writeToLog (a)
  210176. #else
  210177. #define log(a)
  210178. #endif
  210179. #undef OK
  210180. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210181. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210182. {
  210183. if (err == noErr)
  210184. return true;
  210185. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210186. jassertfalse
  210187. return false;
  210188. }
  210189. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210190. #else
  210191. #define OK(a) (a == noErr)
  210192. #endif
  210193. class CoreAudioInternal : public Timer
  210194. {
  210195. public:
  210196. CoreAudioInternal (AudioDeviceID id)
  210197. : inputLatency (0),
  210198. outputLatency (0),
  210199. callback (0),
  210200. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210201. audioProcID (0),
  210202. #endif
  210203. inputDevice (0),
  210204. isSlaveDevice (false),
  210205. deviceID (id),
  210206. started (false),
  210207. sampleRate (0),
  210208. bufferSize (512),
  210209. numInputChans (0),
  210210. numOutputChans (0),
  210211. callbacksAllowed (true),
  210212. numInputChannelInfos (0),
  210213. numOutputChannelInfos (0)
  210214. {
  210215. jassert (deviceID != 0);
  210216. updateDetailsFromDevice();
  210217. AudioObjectPropertyAddress pa;
  210218. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210219. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210220. pa.mElement = kAudioObjectPropertyElementWildcard;
  210221. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210222. }
  210223. ~CoreAudioInternal()
  210224. {
  210225. AudioObjectPropertyAddress pa;
  210226. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210227. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210228. pa.mElement = kAudioObjectPropertyElementWildcard;
  210229. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210230. stop (false);
  210231. delete inputDevice;
  210232. }
  210233. void allocateTempBuffers()
  210234. {
  210235. const int tempBufSize = bufferSize + 4;
  210236. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210237. tempInputBuffers.calloc (numInputChans + 2);
  210238. tempOutputBuffers.calloc (numOutputChans + 2);
  210239. int i, count = 0;
  210240. for (i = 0; i < numInputChans; ++i)
  210241. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210242. for (i = 0; i < numOutputChans; ++i)
  210243. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210244. }
  210245. // returns the number of actual available channels
  210246. void fillInChannelInfo (const bool input)
  210247. {
  210248. int chanNum = 0;
  210249. UInt32 size;
  210250. AudioObjectPropertyAddress pa;
  210251. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210252. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210253. pa.mElement = kAudioObjectPropertyElementMaster;
  210254. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210255. {
  210256. HeapBlock <AudioBufferList> bufList;
  210257. bufList.calloc (size, 1);
  210258. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210259. {
  210260. const int numStreams = bufList->mNumberBuffers;
  210261. for (int i = 0; i < numStreams; ++i)
  210262. {
  210263. const AudioBuffer& b = bufList->mBuffers[i];
  210264. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210265. {
  210266. String name;
  210267. {
  210268. uint8 channelName [256];
  210269. zerostruct (channelName);
  210270. UInt32 nameSize = sizeof (channelName);
  210271. UInt32 channelNum = chanNum + 1;
  210272. pa.mSelector = kAudioDevicePropertyChannelName;
  210273. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210274. name = String::fromUTF8 (channelName, nameSize);
  210275. }
  210276. if (input)
  210277. {
  210278. if (activeInputChans[chanNum])
  210279. {
  210280. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210281. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210282. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210283. ++numInputChannelInfos;
  210284. }
  210285. if (name.isEmpty())
  210286. name << "Input " << (chanNum + 1);
  210287. inChanNames.add (name);
  210288. }
  210289. else
  210290. {
  210291. if (activeOutputChans[chanNum])
  210292. {
  210293. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210294. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210295. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210296. ++numOutputChannelInfos;
  210297. }
  210298. if (name.isEmpty())
  210299. name << "Output " << (chanNum + 1);
  210300. outChanNames.add (name);
  210301. }
  210302. ++chanNum;
  210303. }
  210304. }
  210305. }
  210306. }
  210307. }
  210308. void updateDetailsFromDevice()
  210309. {
  210310. stopTimer();
  210311. if (deviceID == 0)
  210312. return;
  210313. const ScopedLock sl (callbackLock);
  210314. Float64 sr;
  210315. UInt32 size = sizeof (Float64);
  210316. AudioObjectPropertyAddress pa;
  210317. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210318. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210319. pa.mElement = kAudioObjectPropertyElementMaster;
  210320. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210321. sampleRate = sr;
  210322. UInt32 framesPerBuf;
  210323. size = sizeof (framesPerBuf);
  210324. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210325. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210326. {
  210327. bufferSize = framesPerBuf;
  210328. allocateTempBuffers();
  210329. }
  210330. bufferSizes.clear();
  210331. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210332. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210333. {
  210334. HeapBlock <AudioValueRange> ranges;
  210335. ranges.calloc (size, 1);
  210336. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210337. {
  210338. bufferSizes.add ((int) ranges[0].mMinimum);
  210339. for (int i = 32; i < 8192; i += 32)
  210340. {
  210341. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210342. {
  210343. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210344. {
  210345. bufferSizes.addIfNotAlreadyThere (i);
  210346. break;
  210347. }
  210348. }
  210349. }
  210350. if (bufferSize > 0)
  210351. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210352. }
  210353. }
  210354. if (bufferSizes.size() == 0 && bufferSize > 0)
  210355. bufferSizes.add (bufferSize);
  210356. sampleRates.clear();
  210357. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210358. String rates;
  210359. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210360. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210361. {
  210362. HeapBlock <AudioValueRange> ranges;
  210363. ranges.calloc (size, 1);
  210364. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210365. {
  210366. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210367. {
  210368. bool ok = false;
  210369. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210370. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210371. ok = true;
  210372. if (ok)
  210373. {
  210374. sampleRates.add (possibleRates[i]);
  210375. rates << possibleRates[i] << T(" ");
  210376. }
  210377. }
  210378. }
  210379. }
  210380. if (sampleRates.size() == 0 && sampleRate > 0)
  210381. {
  210382. sampleRates.add (sampleRate);
  210383. rates << sampleRate;
  210384. }
  210385. log (T("sr: ") + rates);
  210386. inputLatency = 0;
  210387. outputLatency = 0;
  210388. UInt32 lat;
  210389. size = sizeof (lat);
  210390. pa.mSelector = kAudioDevicePropertyLatency;
  210391. pa.mScope = kAudioDevicePropertyScopeInput;
  210392. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210393. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210394. inputLatency = (int) lat;
  210395. pa.mScope = kAudioDevicePropertyScopeOutput;
  210396. size = sizeof (lat);
  210397. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210398. outputLatency = (int) lat;
  210399. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210400. inChanNames.clear();
  210401. outChanNames.clear();
  210402. inputChannelInfo.calloc (numInputChans + 2);
  210403. numInputChannelInfos = 0;
  210404. outputChannelInfo.calloc (numOutputChans + 2);
  210405. numOutputChannelInfos = 0;
  210406. fillInChannelInfo (true);
  210407. fillInChannelInfo (false);
  210408. }
  210409. const StringArray getSources (bool input)
  210410. {
  210411. StringArray s;
  210412. HeapBlock <OSType> types;
  210413. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210414. for (int i = 0; i < num; ++i)
  210415. {
  210416. AudioValueTranslation avt;
  210417. char buffer[256];
  210418. avt.mInputData = (void*) &(types[i]);
  210419. avt.mInputDataSize = sizeof (UInt32);
  210420. avt.mOutputData = buffer;
  210421. avt.mOutputDataSize = 256;
  210422. UInt32 transSize = sizeof (avt);
  210423. AudioObjectPropertyAddress pa;
  210424. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210425. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210426. pa.mElement = kAudioObjectPropertyElementMaster;
  210427. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210428. {
  210429. DBG (buffer);
  210430. s.add (buffer);
  210431. }
  210432. }
  210433. return s;
  210434. }
  210435. int getCurrentSourceIndex (bool input) const
  210436. {
  210437. OSType currentSourceID = 0;
  210438. UInt32 size = sizeof (currentSourceID);
  210439. int result = -1;
  210440. AudioObjectPropertyAddress pa;
  210441. pa.mSelector = kAudioDevicePropertyDataSource;
  210442. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210443. pa.mElement = kAudioObjectPropertyElementMaster;
  210444. if (deviceID != 0)
  210445. {
  210446. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210447. {
  210448. HeapBlock <OSType> types;
  210449. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210450. for (int i = 0; i < num; ++i)
  210451. {
  210452. if (types[num] == currentSourceID)
  210453. {
  210454. result = i;
  210455. break;
  210456. }
  210457. }
  210458. }
  210459. }
  210460. return result;
  210461. }
  210462. void setCurrentSourceIndex (int index, bool input)
  210463. {
  210464. if (deviceID != 0)
  210465. {
  210466. HeapBlock <OSType> types;
  210467. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210468. if (((unsigned int) index) < (unsigned int) num)
  210469. {
  210470. AudioObjectPropertyAddress pa;
  210471. pa.mSelector = kAudioDevicePropertyDataSource;
  210472. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210473. pa.mElement = kAudioObjectPropertyElementMaster;
  210474. OSType typeId = types[index];
  210475. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210476. }
  210477. }
  210478. }
  210479. const String reopen (const BitArray& inputChannels,
  210480. const BitArray& outputChannels,
  210481. double newSampleRate,
  210482. int bufferSizeSamples)
  210483. {
  210484. String error;
  210485. log ("CoreAudio reopen");
  210486. callbacksAllowed = false;
  210487. stopTimer();
  210488. stop (false);
  210489. activeInputChans = inputChannels;
  210490. activeInputChans.setRange (inChanNames.size(),
  210491. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210492. false);
  210493. activeOutputChans = outputChannels;
  210494. activeOutputChans.setRange (outChanNames.size(),
  210495. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210496. false);
  210497. numInputChans = activeInputChans.countNumberOfSetBits();
  210498. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210499. // set sample rate
  210500. AudioObjectPropertyAddress pa;
  210501. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210502. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210503. pa.mElement = kAudioObjectPropertyElementMaster;
  210504. Float64 sr = newSampleRate;
  210505. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210506. {
  210507. error = "Couldn't change sample rate";
  210508. }
  210509. else
  210510. {
  210511. // change buffer size
  210512. UInt32 framesPerBuf = bufferSizeSamples;
  210513. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210514. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210515. {
  210516. error = "Couldn't change buffer size";
  210517. }
  210518. else
  210519. {
  210520. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210521. // correctly report their new settings until some random time in the future, so
  210522. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210523. // to make sure we're using the correct numbers..
  210524. updateDetailsFromDevice();
  210525. sampleRate = newSampleRate;
  210526. bufferSize = bufferSizeSamples;
  210527. if (sampleRates.size() == 0)
  210528. error = "Device has no available sample-rates";
  210529. else if (bufferSizes.size() == 0)
  210530. error = "Device has no available buffer-sizes";
  210531. else if (inputDevice != 0)
  210532. error = inputDevice->reopen (inputChannels,
  210533. outputChannels,
  210534. newSampleRate,
  210535. bufferSizeSamples);
  210536. }
  210537. }
  210538. callbacksAllowed = true;
  210539. return error;
  210540. }
  210541. bool start (AudioIODeviceCallback* cb)
  210542. {
  210543. if (! started)
  210544. {
  210545. callback = 0;
  210546. if (deviceID != 0)
  210547. {
  210548. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210549. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210550. #else
  210551. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210552. #endif
  210553. {
  210554. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210555. {
  210556. started = true;
  210557. }
  210558. else
  210559. {
  210560. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210561. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210562. #else
  210563. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210564. audioProcID = 0;
  210565. #endif
  210566. }
  210567. }
  210568. }
  210569. }
  210570. if (started)
  210571. {
  210572. const ScopedLock sl (callbackLock);
  210573. callback = cb;
  210574. }
  210575. if (inputDevice != 0)
  210576. return started && inputDevice->start (cb);
  210577. else
  210578. return started;
  210579. }
  210580. void stop (bool leaveInterruptRunning)
  210581. {
  210582. callbackLock.enter();
  210583. callback = 0;
  210584. callbackLock.exit();
  210585. if (started
  210586. && (deviceID != 0)
  210587. && ! leaveInterruptRunning)
  210588. {
  210589. OK (AudioDeviceStop (deviceID, audioIOProc));
  210590. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210591. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210592. #else
  210593. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210594. audioProcID = 0;
  210595. #endif
  210596. started = false;
  210597. callbackLock.enter();
  210598. callbackLock.exit();
  210599. // wait until it's definately stopped calling back..
  210600. for (int i = 40; --i >= 0;)
  210601. {
  210602. Thread::sleep (50);
  210603. UInt32 running = 0;
  210604. UInt32 size = sizeof (running);
  210605. AudioObjectPropertyAddress pa;
  210606. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210607. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210608. pa.mElement = kAudioObjectPropertyElementMaster;
  210609. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210610. if (running == 0)
  210611. break;
  210612. }
  210613. callbackLock.enter();
  210614. callbackLock.exit();
  210615. }
  210616. if (inputDevice != 0)
  210617. inputDevice->stop (leaveInterruptRunning);
  210618. }
  210619. double getSampleRate() const
  210620. {
  210621. return sampleRate;
  210622. }
  210623. int getBufferSize() const
  210624. {
  210625. return bufferSize;
  210626. }
  210627. void audioCallback (const AudioBufferList* inInputData,
  210628. AudioBufferList* outOutputData)
  210629. {
  210630. int i;
  210631. const ScopedLock sl (callbackLock);
  210632. if (callback != 0)
  210633. {
  210634. if (inputDevice == 0)
  210635. {
  210636. for (i = numInputChans; --i >= 0;)
  210637. {
  210638. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210639. float* dest = tempInputBuffers [i];
  210640. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210641. + info.dataOffsetSamples;
  210642. const int stride = info.dataStrideSamples;
  210643. if (stride != 0) // if this is zero, info is invalid
  210644. {
  210645. for (int j = bufferSize; --j >= 0;)
  210646. {
  210647. *dest++ = *src;
  210648. src += stride;
  210649. }
  210650. }
  210651. }
  210652. }
  210653. if (! isSlaveDevice)
  210654. {
  210655. if (inputDevice == 0)
  210656. {
  210657. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210658. numInputChans,
  210659. tempOutputBuffers,
  210660. numOutputChans,
  210661. bufferSize);
  210662. }
  210663. else
  210664. {
  210665. jassert (inputDevice->bufferSize == bufferSize);
  210666. // Sometimes the two linked devices seem to get their callbacks in
  210667. // parallel, so we need to lock both devices to stop the input data being
  210668. // changed while inside our callback..
  210669. const ScopedLock sl2 (inputDevice->callbackLock);
  210670. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210671. inputDevice->numInputChans,
  210672. tempOutputBuffers,
  210673. numOutputChans,
  210674. bufferSize);
  210675. }
  210676. for (i = numOutputChans; --i >= 0;)
  210677. {
  210678. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210679. const float* src = tempOutputBuffers [i];
  210680. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210681. + info.dataOffsetSamples;
  210682. const int stride = info.dataStrideSamples;
  210683. if (stride != 0) // if this is zero, info is invalid
  210684. {
  210685. for (int j = bufferSize; --j >= 0;)
  210686. {
  210687. *dest = *src++;
  210688. dest += stride;
  210689. }
  210690. }
  210691. }
  210692. }
  210693. }
  210694. else
  210695. {
  210696. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210697. {
  210698. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210699. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210700. + info.dataOffsetSamples;
  210701. const int stride = info.dataStrideSamples;
  210702. if (stride != 0) // if this is zero, info is invalid
  210703. {
  210704. for (int j = bufferSize; --j >= 0;)
  210705. {
  210706. *dest = 0.0f;
  210707. dest += stride;
  210708. }
  210709. }
  210710. }
  210711. }
  210712. }
  210713. // called by callbacks
  210714. void deviceDetailsChanged()
  210715. {
  210716. if (callbacksAllowed)
  210717. startTimer (100);
  210718. }
  210719. void timerCallback()
  210720. {
  210721. stopTimer();
  210722. log ("CoreAudio device changed callback");
  210723. const double oldSampleRate = sampleRate;
  210724. const int oldBufferSize = bufferSize;
  210725. updateDetailsFromDevice();
  210726. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210727. {
  210728. callbacksAllowed = false;
  210729. stop (false);
  210730. updateDetailsFromDevice();
  210731. callbacksAllowed = true;
  210732. }
  210733. }
  210734. CoreAudioInternal* getRelatedDevice() const
  210735. {
  210736. UInt32 size = 0;
  210737. ScopedPointer <CoreAudioInternal> result;
  210738. AudioObjectPropertyAddress pa;
  210739. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210740. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210741. pa.mElement = kAudioObjectPropertyElementMaster;
  210742. if (deviceID != 0
  210743. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210744. && size > 0)
  210745. {
  210746. HeapBlock <AudioDeviceID> devs;
  210747. devs.calloc (size, 1);
  210748. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210749. {
  210750. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210751. {
  210752. if (devs[i] != deviceID && devs[i] != 0)
  210753. {
  210754. result = new CoreAudioInternal (devs[i]);
  210755. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210756. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210757. if (thisIsInput != otherIsInput
  210758. || (inChanNames.size() + outChanNames.size() == 0)
  210759. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210760. break;
  210761. result = 0;
  210762. }
  210763. }
  210764. }
  210765. }
  210766. return result.release();
  210767. }
  210768. juce_UseDebuggingNewOperator
  210769. int inputLatency, outputLatency;
  210770. BitArray activeInputChans, activeOutputChans;
  210771. StringArray inChanNames, outChanNames;
  210772. Array <double> sampleRates;
  210773. Array <int> bufferSizes;
  210774. AudioIODeviceCallback* callback;
  210775. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210776. AudioDeviceIOProcID audioProcID;
  210777. #endif
  210778. CoreAudioInternal* inputDevice;
  210779. bool isSlaveDevice;
  210780. private:
  210781. CriticalSection callbackLock;
  210782. AudioDeviceID deviceID;
  210783. bool started;
  210784. double sampleRate;
  210785. int bufferSize;
  210786. HeapBlock <float> audioBuffer;
  210787. int numInputChans, numOutputChans;
  210788. bool callbacksAllowed;
  210789. struct CallbackDetailsForChannel
  210790. {
  210791. int streamNum;
  210792. int dataOffsetSamples;
  210793. int dataStrideSamples;
  210794. };
  210795. int numInputChannelInfos, numOutputChannelInfos;
  210796. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210797. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210798. CoreAudioInternal (const CoreAudioInternal&);
  210799. const CoreAudioInternal& operator= (const CoreAudioInternal&);
  210800. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210801. const AudioTimeStamp* inNow,
  210802. const AudioBufferList* inInputData,
  210803. const AudioTimeStamp* inInputTime,
  210804. AudioBufferList* outOutputData,
  210805. const AudioTimeStamp* inOutputTime,
  210806. void* device)
  210807. {
  210808. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210809. return noErr;
  210810. }
  210811. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210812. {
  210813. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210814. switch (pa->mSelector)
  210815. {
  210816. case kAudioDevicePropertyBufferSize:
  210817. case kAudioDevicePropertyBufferFrameSize:
  210818. case kAudioDevicePropertyNominalSampleRate:
  210819. case kAudioDevicePropertyStreamFormat:
  210820. case kAudioDevicePropertyDeviceIsAlive:
  210821. intern->deviceDetailsChanged();
  210822. break;
  210823. case kAudioDevicePropertyBufferSizeRange:
  210824. case kAudioDevicePropertyVolumeScalar:
  210825. case kAudioDevicePropertyMute:
  210826. case kAudioDevicePropertyPlayThru:
  210827. case kAudioDevicePropertyDataSource:
  210828. case kAudioDevicePropertyDeviceIsRunning:
  210829. break;
  210830. }
  210831. return noErr;
  210832. }
  210833. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210834. {
  210835. AudioObjectPropertyAddress pa;
  210836. pa.mSelector = kAudioDevicePropertyDataSources;
  210837. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210838. pa.mElement = kAudioObjectPropertyElementMaster;
  210839. UInt32 size = 0;
  210840. if (deviceID != 0
  210841. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210842. {
  210843. types.calloc (size, 1);
  210844. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210845. return size / (int) sizeof (OSType);
  210846. }
  210847. return 0;
  210848. }
  210849. };
  210850. class CoreAudioIODevice : public AudioIODevice
  210851. {
  210852. public:
  210853. CoreAudioIODevice (const String& deviceName,
  210854. AudioDeviceID inputDeviceId,
  210855. const int inputIndex_,
  210856. AudioDeviceID outputDeviceId,
  210857. const int outputIndex_)
  210858. : AudioIODevice (deviceName, "CoreAudio"),
  210859. inputIndex (inputIndex_),
  210860. outputIndex (outputIndex_),
  210861. isOpen_ (false),
  210862. isStarted (false)
  210863. {
  210864. internal = 0;
  210865. CoreAudioInternal* device = 0;
  210866. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210867. {
  210868. jassert (inputDeviceId != 0);
  210869. device = new CoreAudioInternal (inputDeviceId);
  210870. }
  210871. else
  210872. {
  210873. device = new CoreAudioInternal (outputDeviceId);
  210874. if (inputDeviceId != 0)
  210875. {
  210876. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210877. device->inputDevice = secondDevice;
  210878. secondDevice->isSlaveDevice = true;
  210879. }
  210880. }
  210881. internal = device;
  210882. AudioObjectPropertyAddress pa;
  210883. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210884. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210885. pa.mElement = kAudioObjectPropertyElementWildcard;
  210886. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210887. }
  210888. ~CoreAudioIODevice()
  210889. {
  210890. AudioObjectPropertyAddress pa;
  210891. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210892. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210893. pa.mElement = kAudioObjectPropertyElementWildcard;
  210894. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210895. delete internal;
  210896. }
  210897. const StringArray getOutputChannelNames()
  210898. {
  210899. return internal->outChanNames;
  210900. }
  210901. const StringArray getInputChannelNames()
  210902. {
  210903. if (internal->inputDevice != 0)
  210904. return internal->inputDevice->inChanNames;
  210905. else
  210906. return internal->inChanNames;
  210907. }
  210908. int getNumSampleRates()
  210909. {
  210910. return internal->sampleRates.size();
  210911. }
  210912. double getSampleRate (int index)
  210913. {
  210914. return internal->sampleRates [index];
  210915. }
  210916. int getNumBufferSizesAvailable()
  210917. {
  210918. return internal->bufferSizes.size();
  210919. }
  210920. int getBufferSizeSamples (int index)
  210921. {
  210922. return internal->bufferSizes [index];
  210923. }
  210924. int getDefaultBufferSize()
  210925. {
  210926. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210927. if (getBufferSizeSamples(i) >= 512)
  210928. return getBufferSizeSamples(i);
  210929. return 512;
  210930. }
  210931. const String open (const BitArray& inputChannels,
  210932. const BitArray& outputChannels,
  210933. double sampleRate,
  210934. int bufferSizeSamples)
  210935. {
  210936. isOpen_ = true;
  210937. if (bufferSizeSamples <= 0)
  210938. bufferSizeSamples = getDefaultBufferSize();
  210939. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  210940. isOpen_ = lastError.isEmpty();
  210941. return lastError;
  210942. }
  210943. void close()
  210944. {
  210945. isOpen_ = false;
  210946. internal->stop (false);
  210947. }
  210948. bool isOpen()
  210949. {
  210950. return isOpen_;
  210951. }
  210952. int getCurrentBufferSizeSamples()
  210953. {
  210954. return internal != 0 ? internal->getBufferSize() : 512;
  210955. }
  210956. double getCurrentSampleRate()
  210957. {
  210958. return internal != 0 ? internal->getSampleRate() : 0;
  210959. }
  210960. int getCurrentBitDepth()
  210961. {
  210962. return 32; // no way to find out, so just assume it's high..
  210963. }
  210964. const BitArray getActiveOutputChannels() const
  210965. {
  210966. return internal != 0 ? internal->activeOutputChans : BitArray();
  210967. }
  210968. const BitArray getActiveInputChannels() const
  210969. {
  210970. BitArray chans;
  210971. if (internal != 0)
  210972. {
  210973. chans = internal->activeInputChans;
  210974. if (internal->inputDevice != 0)
  210975. chans.orWith (internal->inputDevice->activeInputChans);
  210976. }
  210977. return chans;
  210978. }
  210979. int getOutputLatencyInSamples()
  210980. {
  210981. if (internal == 0)
  210982. return 0;
  210983. // this seems like a good guess at getting the latency right - comparing
  210984. // this with a round-trip measurement, it gets it to within a few millisecs
  210985. // for the built-in mac soundcard
  210986. return internal->outputLatency + internal->getBufferSize() * 2;
  210987. }
  210988. int getInputLatencyInSamples()
  210989. {
  210990. if (internal == 0)
  210991. return 0;
  210992. return internal->inputLatency + internal->getBufferSize() * 2;
  210993. }
  210994. void start (AudioIODeviceCallback* callback)
  210995. {
  210996. if (internal != 0 && ! isStarted)
  210997. {
  210998. if (callback != 0)
  210999. callback->audioDeviceAboutToStart (this);
  211000. isStarted = true;
  211001. internal->start (callback);
  211002. }
  211003. }
  211004. void stop()
  211005. {
  211006. if (isStarted && internal != 0)
  211007. {
  211008. AudioIODeviceCallback* const lastCallback = internal->callback;
  211009. isStarted = false;
  211010. internal->stop (true);
  211011. if (lastCallback != 0)
  211012. lastCallback->audioDeviceStopped();
  211013. }
  211014. }
  211015. bool isPlaying()
  211016. {
  211017. if (internal->callback == 0)
  211018. isStarted = false;
  211019. return isStarted;
  211020. }
  211021. const String getLastError()
  211022. {
  211023. return lastError;
  211024. }
  211025. int inputIndex, outputIndex;
  211026. juce_UseDebuggingNewOperator
  211027. private:
  211028. CoreAudioInternal* internal;
  211029. bool isOpen_, isStarted;
  211030. String lastError;
  211031. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211032. {
  211033. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211034. switch (pa->mSelector)
  211035. {
  211036. case kAudioHardwarePropertyDevices:
  211037. intern->deviceDetailsChanged();
  211038. break;
  211039. case kAudioHardwarePropertyDefaultOutputDevice:
  211040. case kAudioHardwarePropertyDefaultInputDevice:
  211041. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211042. break;
  211043. }
  211044. return noErr;
  211045. }
  211046. CoreAudioIODevice (const CoreAudioIODevice&);
  211047. const CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211048. };
  211049. class CoreAudioIODeviceType : public AudioIODeviceType
  211050. {
  211051. public:
  211052. CoreAudioIODeviceType()
  211053. : AudioIODeviceType (T("CoreAudio")),
  211054. hasScanned (false)
  211055. {
  211056. }
  211057. ~CoreAudioIODeviceType()
  211058. {
  211059. }
  211060. void scanForDevices()
  211061. {
  211062. hasScanned = true;
  211063. inputDeviceNames.clear();
  211064. outputDeviceNames.clear();
  211065. inputIds.clear();
  211066. outputIds.clear();
  211067. UInt32 size;
  211068. AudioObjectPropertyAddress pa;
  211069. pa.mSelector = kAudioHardwarePropertyDevices;
  211070. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211071. pa.mElement = kAudioObjectPropertyElementMaster;
  211072. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211073. {
  211074. HeapBlock <AudioDeviceID> devs;
  211075. devs.calloc (size, 1);
  211076. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211077. {
  211078. static bool alreadyLogged = false;
  211079. const int num = size / (int) sizeof (AudioDeviceID);
  211080. for (int i = 0; i < num; ++i)
  211081. {
  211082. char name [1024];
  211083. size = sizeof (name);
  211084. pa.mSelector = kAudioDevicePropertyDeviceName;
  211085. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211086. {
  211087. const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name)));
  211088. if (! alreadyLogged)
  211089. log (T("CoreAudio device: ") + nameString);
  211090. const int numIns = getNumChannels (devs[i], true);
  211091. const int numOuts = getNumChannels (devs[i], false);
  211092. if (numIns > 0)
  211093. {
  211094. inputDeviceNames.add (nameString);
  211095. inputIds.add (devs[i]);
  211096. }
  211097. if (numOuts > 0)
  211098. {
  211099. outputDeviceNames.add (nameString);
  211100. outputIds.add (devs[i]);
  211101. }
  211102. }
  211103. }
  211104. alreadyLogged = true;
  211105. }
  211106. }
  211107. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211108. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211109. }
  211110. const StringArray getDeviceNames (const bool wantInputNames) const
  211111. {
  211112. jassert (hasScanned); // need to call scanForDevices() before doing this
  211113. if (wantInputNames)
  211114. return inputDeviceNames;
  211115. else
  211116. return outputDeviceNames;
  211117. }
  211118. int getDefaultDeviceIndex (const bool forInput) const
  211119. {
  211120. jassert (hasScanned); // need to call scanForDevices() before doing this
  211121. AudioDeviceID deviceID;
  211122. UInt32 size = sizeof (deviceID);
  211123. // if they're asking for any input channels at all, use the default input, so we
  211124. // get the built-in mic rather than the built-in output with no inputs..
  211125. AudioObjectPropertyAddress pa;
  211126. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211127. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211128. pa.mElement = kAudioObjectPropertyElementMaster;
  211129. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211130. {
  211131. if (forInput)
  211132. {
  211133. for (int i = inputIds.size(); --i >= 0;)
  211134. if (inputIds[i] == deviceID)
  211135. return i;
  211136. }
  211137. else
  211138. {
  211139. for (int i = outputIds.size(); --i >= 0;)
  211140. if (outputIds[i] == deviceID)
  211141. return i;
  211142. }
  211143. }
  211144. return 0;
  211145. }
  211146. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211147. {
  211148. jassert (hasScanned); // need to call scanForDevices() before doing this
  211149. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211150. if (d == 0)
  211151. return -1;
  211152. return asInput ? d->inputIndex
  211153. : d->outputIndex;
  211154. }
  211155. bool hasSeparateInputsAndOutputs() const { return true; }
  211156. AudioIODevice* createDevice (const String& outputDeviceName,
  211157. const String& inputDeviceName)
  211158. {
  211159. jassert (hasScanned); // need to call scanForDevices() before doing this
  211160. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211161. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211162. String deviceName (outputDeviceName);
  211163. if (deviceName.isEmpty())
  211164. deviceName = inputDeviceName;
  211165. if (index >= 0)
  211166. return new CoreAudioIODevice (deviceName,
  211167. inputIds [inputIndex],
  211168. inputIndex,
  211169. outputIds [outputIndex],
  211170. outputIndex);
  211171. return 0;
  211172. }
  211173. juce_UseDebuggingNewOperator
  211174. private:
  211175. StringArray inputDeviceNames, outputDeviceNames;
  211176. Array <AudioDeviceID> inputIds, outputIds;
  211177. bool hasScanned;
  211178. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211179. {
  211180. int total = 0;
  211181. UInt32 size;
  211182. AudioObjectPropertyAddress pa;
  211183. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211184. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211185. pa.mElement = kAudioObjectPropertyElementMaster;
  211186. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211187. {
  211188. HeapBlock <AudioBufferList> bufList;
  211189. bufList.calloc (size, 1);
  211190. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211191. {
  211192. const int numStreams = bufList->mNumberBuffers;
  211193. for (int i = 0; i < numStreams; ++i)
  211194. {
  211195. const AudioBuffer& b = bufList->mBuffers[i];
  211196. total += b.mNumberChannels;
  211197. }
  211198. }
  211199. }
  211200. return total;
  211201. }
  211202. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211203. const CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211204. };
  211205. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211206. {
  211207. return new CoreAudioIODeviceType();
  211208. }
  211209. #undef log
  211210. #endif
  211211. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211212. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211213. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211214. // compiled on its own).
  211215. #if JUCE_INCLUDED_FILE
  211216. #if JUCE_MAC
  211217. #undef log
  211218. #define log(a) Logger::writeToLog(a)
  211219. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211220. {
  211221. if (err == noErr)
  211222. return true;
  211223. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211224. jassertfalse
  211225. return false;
  211226. }
  211227. #undef OK
  211228. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211229. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211230. {
  211231. String result;
  211232. CFStringRef str = 0;
  211233. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211234. if (str != 0)
  211235. {
  211236. result = PlatformUtilities::cfStringToJuceString (str);
  211237. CFRelease (str);
  211238. str = 0;
  211239. }
  211240. MIDIEntityRef entity = 0;
  211241. MIDIEndpointGetEntity (endpoint, &entity);
  211242. if (entity == 0)
  211243. return result; // probably virtual
  211244. if (result.isEmpty())
  211245. {
  211246. // endpoint name has zero length - try the entity
  211247. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211248. if (str != 0)
  211249. {
  211250. result += PlatformUtilities::cfStringToJuceString (str);
  211251. CFRelease (str);
  211252. str = 0;
  211253. }
  211254. }
  211255. // now consider the device's name
  211256. MIDIDeviceRef device = 0;
  211257. MIDIEntityGetDevice (entity, &device);
  211258. if (device == 0)
  211259. return result;
  211260. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211261. if (str != 0)
  211262. {
  211263. const String s (PlatformUtilities::cfStringToJuceString (str));
  211264. CFRelease (str);
  211265. // if an external device has only one entity, throw away
  211266. // the endpoint name and just use the device name
  211267. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211268. {
  211269. result = s;
  211270. }
  211271. else if (! result.startsWithIgnoreCase (s))
  211272. {
  211273. // prepend the device name to the entity name
  211274. result = (s + T(" ") + result).trimEnd();
  211275. }
  211276. }
  211277. return result;
  211278. }
  211279. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211280. {
  211281. String result;
  211282. // Does the endpoint have connections?
  211283. CFDataRef connections = 0;
  211284. int numConnections = 0;
  211285. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211286. if (connections != 0)
  211287. {
  211288. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211289. if (numConnections > 0)
  211290. {
  211291. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211292. for (int i = 0; i < numConnections; ++i, ++pid)
  211293. {
  211294. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211295. MIDIObjectRef connObject;
  211296. MIDIObjectType connObjectType;
  211297. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211298. if (err == noErr)
  211299. {
  211300. String s;
  211301. if (connObjectType == kMIDIObjectType_ExternalSource
  211302. || connObjectType == kMIDIObjectType_ExternalDestination)
  211303. {
  211304. // Connected to an external device's endpoint (10.3 and later).
  211305. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211306. }
  211307. else
  211308. {
  211309. // Connected to an external device (10.2) (or something else, catch-all)
  211310. CFStringRef str = 0;
  211311. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211312. if (str != 0)
  211313. {
  211314. s = PlatformUtilities::cfStringToJuceString (str);
  211315. CFRelease (str);
  211316. }
  211317. }
  211318. if (s.isNotEmpty())
  211319. {
  211320. if (result.isNotEmpty())
  211321. result += (", ");
  211322. result += s;
  211323. }
  211324. }
  211325. }
  211326. }
  211327. CFRelease (connections);
  211328. }
  211329. if (result.isNotEmpty())
  211330. return result;
  211331. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211332. return getEndpointName (endpoint, false);
  211333. }
  211334. const StringArray MidiOutput::getDevices()
  211335. {
  211336. StringArray s;
  211337. const ItemCount num = MIDIGetNumberOfDestinations();
  211338. for (ItemCount i = 0; i < num; ++i)
  211339. {
  211340. MIDIEndpointRef dest = MIDIGetDestination (i);
  211341. if (dest != 0)
  211342. {
  211343. String name (getConnectedEndpointName (dest));
  211344. if (name.isEmpty())
  211345. name = "<error>";
  211346. s.add (name);
  211347. }
  211348. else
  211349. {
  211350. s.add ("<error>");
  211351. }
  211352. }
  211353. return s;
  211354. }
  211355. int MidiOutput::getDefaultDeviceIndex()
  211356. {
  211357. return 0;
  211358. }
  211359. static MIDIClientRef globalMidiClient;
  211360. static bool hasGlobalClientBeenCreated = false;
  211361. static bool makeSureClientExists()
  211362. {
  211363. if (! hasGlobalClientBeenCreated)
  211364. {
  211365. String name (T("JUCE"));
  211366. if (JUCEApplication::getInstance() != 0)
  211367. name = JUCEApplication::getInstance()->getApplicationName();
  211368. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211369. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211370. CFRelease (appName);
  211371. }
  211372. return hasGlobalClientBeenCreated;
  211373. }
  211374. class MidiPortAndEndpoint
  211375. {
  211376. public:
  211377. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211378. : port (port_), endPoint (endPoint_)
  211379. {
  211380. }
  211381. ~MidiPortAndEndpoint()
  211382. {
  211383. if (port != 0)
  211384. MIDIPortDispose (port);
  211385. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211386. MIDIEndpointDispose (endPoint);
  211387. }
  211388. MIDIPortRef port;
  211389. MIDIEndpointRef endPoint;
  211390. };
  211391. MidiOutput* MidiOutput::openDevice (int index)
  211392. {
  211393. MidiOutput* mo = 0;
  211394. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211395. {
  211396. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211397. CFStringRef pname;
  211398. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211399. {
  211400. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211401. if (makeSureClientExists())
  211402. {
  211403. MIDIPortRef port;
  211404. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211405. {
  211406. mo = new MidiOutput();
  211407. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211408. }
  211409. }
  211410. CFRelease (pname);
  211411. }
  211412. }
  211413. return mo;
  211414. }
  211415. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211416. {
  211417. MidiOutput* mo = 0;
  211418. if (makeSureClientExists())
  211419. {
  211420. MIDIEndpointRef endPoint;
  211421. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211422. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211423. {
  211424. mo = new MidiOutput();
  211425. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211426. }
  211427. CFRelease (name);
  211428. }
  211429. return mo;
  211430. }
  211431. MidiOutput::~MidiOutput()
  211432. {
  211433. delete (MidiPortAndEndpoint*) internal;
  211434. }
  211435. void MidiOutput::reset()
  211436. {
  211437. }
  211438. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211439. {
  211440. return false;
  211441. }
  211442. void MidiOutput::setVolume (float leftVol, float rightVol)
  211443. {
  211444. }
  211445. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211446. {
  211447. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211448. if (message.isSysEx())
  211449. {
  211450. const int maxPacketSize = 256;
  211451. int pos = 0, bytesLeft = message.getRawDataSize();
  211452. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211453. HeapBlock <MIDIPacketList> packets;
  211454. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211455. packets->numPackets = numPackets;
  211456. MIDIPacket* p = packets->packet;
  211457. for (int i = 0; i < numPackets; ++i)
  211458. {
  211459. p->timeStamp = 0;
  211460. p->length = jmin (maxPacketSize, bytesLeft);
  211461. memcpy (p->data, message.getRawData() + pos, p->length);
  211462. pos += p->length;
  211463. bytesLeft -= p->length;
  211464. p = MIDIPacketNext (p);
  211465. }
  211466. if (mpe->port != 0)
  211467. MIDISend (mpe->port, mpe->endPoint, packets);
  211468. else
  211469. MIDIReceived (mpe->endPoint, packets);
  211470. }
  211471. else
  211472. {
  211473. MIDIPacketList packets;
  211474. packets.numPackets = 1;
  211475. packets.packet[0].timeStamp = 0;
  211476. packets.packet[0].length = message.getRawDataSize();
  211477. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211478. if (mpe->port != 0)
  211479. MIDISend (mpe->port, mpe->endPoint, &packets);
  211480. else
  211481. MIDIReceived (mpe->endPoint, &packets);
  211482. }
  211483. }
  211484. const StringArray MidiInput::getDevices()
  211485. {
  211486. StringArray s;
  211487. const ItemCount num = MIDIGetNumberOfSources();
  211488. for (ItemCount i = 0; i < num; ++i)
  211489. {
  211490. MIDIEndpointRef source = MIDIGetSource (i);
  211491. if (source != 0)
  211492. {
  211493. String name (getConnectedEndpointName (source));
  211494. if (name.isEmpty())
  211495. name = "<error>";
  211496. s.add (name);
  211497. }
  211498. else
  211499. {
  211500. s.add ("<error>");
  211501. }
  211502. }
  211503. return s;
  211504. }
  211505. int MidiInput::getDefaultDeviceIndex()
  211506. {
  211507. return 0;
  211508. }
  211509. struct MidiPortAndCallback
  211510. {
  211511. MidiInput* input;
  211512. MidiPortAndEndpoint* portAndEndpoint;
  211513. MidiInputCallback* callback;
  211514. MemoryBlock pendingData;
  211515. int pendingBytes;
  211516. double pendingDataTime;
  211517. bool active;
  211518. };
  211519. static CriticalSection callbackLock;
  211520. static VoidArray activeCallbacks;
  211521. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  211522. {
  211523. if (*d == 0xf0)
  211524. {
  211525. mpc->pendingBytes = 0;
  211526. mpc->pendingDataTime = time;
  211527. }
  211528. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  211529. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  211530. uint8* dest = totalMessage + mpc->pendingBytes;
  211531. while (size > 0)
  211532. {
  211533. if (mpc->pendingBytes > 0 && *d >= 0x80)
  211534. {
  211535. if (*d >= 0xfa || *d == 0xf8)
  211536. {
  211537. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  211538. ++d;
  211539. --size;
  211540. }
  211541. else
  211542. {
  211543. if (*d == 0xf7)
  211544. {
  211545. *dest++ = *d++;
  211546. mpc->pendingBytes++;
  211547. --size;
  211548. }
  211549. break;
  211550. }
  211551. }
  211552. else
  211553. {
  211554. *dest++ = *d++;
  211555. mpc->pendingBytes++;
  211556. --size;
  211557. }
  211558. }
  211559. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  211560. {
  211561. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  211562. mpc->pendingBytes,
  211563. mpc->pendingDataTime));
  211564. mpc->pendingBytes = 0;
  211565. }
  211566. else
  211567. {
  211568. mpc->callback->handlePartialSysexMessage (mpc->input,
  211569. totalMessage,
  211570. mpc->pendingBytes,
  211571. mpc->pendingDataTime);
  211572. }
  211573. }
  211574. static void midiInputProc (const MIDIPacketList* pktlist,
  211575. void* readProcRefCon,
  211576. void* srcConnRefCon)
  211577. {
  211578. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211579. const double originalTime = time;
  211580. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211581. const ScopedLock sl (callbackLock);
  211582. if (activeCallbacks.contains (mpc) && mpc->active)
  211583. {
  211584. const MIDIPacket* packet = &pktlist->packet[0];
  211585. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211586. {
  211587. const uint8* d = (const uint8*) (packet->data);
  211588. int size = packet->length;
  211589. while (size > 0)
  211590. {
  211591. time = originalTime;
  211592. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211593. {
  211594. processSysex (mpc, d, size, time);
  211595. }
  211596. else
  211597. {
  211598. int used = 0;
  211599. const MidiMessage m (d, size, used, 0, time);
  211600. if (used <= 0)
  211601. {
  211602. jassertfalse // malformed midi message
  211603. break;
  211604. }
  211605. else
  211606. {
  211607. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211608. }
  211609. size -= used;
  211610. d += used;
  211611. }
  211612. }
  211613. packet = MIDIPacketNext (packet);
  211614. }
  211615. }
  211616. }
  211617. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211618. {
  211619. MidiInput* mi = 0;
  211620. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211621. {
  211622. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211623. if (endPoint != 0)
  211624. {
  211625. CFStringRef pname;
  211626. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211627. {
  211628. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211629. if (makeSureClientExists())
  211630. {
  211631. MIDIPortRef port;
  211632. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211633. mpc->active = false;
  211634. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211635. {
  211636. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211637. {
  211638. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211639. mpc->callback = callback;
  211640. mpc->pendingBytes = 0;
  211641. mpc->pendingData.ensureSize (128);
  211642. mi = new MidiInput (getDevices() [index]);
  211643. mpc->input = mi;
  211644. mi->internal = (void*) mpc;
  211645. const ScopedLock sl (callbackLock);
  211646. activeCallbacks.add (mpc.release());
  211647. }
  211648. else
  211649. {
  211650. OK (MIDIPortDispose (port));
  211651. }
  211652. }
  211653. }
  211654. }
  211655. CFRelease (pname);
  211656. }
  211657. }
  211658. return mi;
  211659. }
  211660. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211661. {
  211662. MidiInput* mi = 0;
  211663. if (makeSureClientExists())
  211664. {
  211665. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211666. mpc->active = false;
  211667. MIDIEndpointRef endPoint;
  211668. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211669. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211670. {
  211671. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211672. mpc->callback = callback;
  211673. mpc->pendingBytes = 0;
  211674. mpc->pendingData.ensureSize (128);
  211675. mi = new MidiInput (deviceName);
  211676. mpc->input = mi;
  211677. mi->internal = (void*) mpc;
  211678. const ScopedLock sl (callbackLock);
  211679. activeCallbacks.add (mpc.release());
  211680. }
  211681. CFRelease (name);
  211682. }
  211683. return mi;
  211684. }
  211685. MidiInput::MidiInput (const String& name_)
  211686. : name (name_)
  211687. {
  211688. }
  211689. MidiInput::~MidiInput()
  211690. {
  211691. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211692. mpc->active = false;
  211693. callbackLock.enter();
  211694. activeCallbacks.removeValue (mpc);
  211695. callbackLock.exit();
  211696. if (mpc->portAndEndpoint->port != 0)
  211697. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211698. delete mpc->portAndEndpoint;
  211699. delete mpc;
  211700. }
  211701. void MidiInput::start()
  211702. {
  211703. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211704. const ScopedLock sl (callbackLock);
  211705. mpc->active = true;
  211706. }
  211707. void MidiInput::stop()
  211708. {
  211709. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211710. const ScopedLock sl (callbackLock);
  211711. mpc->active = false;
  211712. }
  211713. #undef log
  211714. #else
  211715. MidiOutput::~MidiOutput()
  211716. {
  211717. }
  211718. void MidiOutput::reset()
  211719. {
  211720. }
  211721. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211722. {
  211723. return false;
  211724. }
  211725. void MidiOutput::setVolume (float leftVol, float rightVol)
  211726. {
  211727. }
  211728. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211729. {
  211730. }
  211731. const StringArray MidiOutput::getDevices()
  211732. {
  211733. return StringArray();
  211734. }
  211735. MidiOutput* MidiOutput::openDevice (int index)
  211736. {
  211737. return 0;
  211738. }
  211739. const StringArray MidiInput::getDevices()
  211740. {
  211741. return StringArray();
  211742. }
  211743. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211744. {
  211745. return 0;
  211746. }
  211747. #endif
  211748. #endif
  211749. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211750. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211751. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211752. // compiled on its own).
  211753. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211754. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211755. class QTCameraDeviceInteral;
  211756. END_JUCE_NAMESPACE
  211757. @interface QTCaptureCallbackDelegate : NSObject
  211758. {
  211759. @public
  211760. CameraDevice* owner;
  211761. QTCameraDeviceInteral* internal;
  211762. Time* firstRecordedTime;
  211763. }
  211764. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211765. - (void) dealloc;
  211766. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211767. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211768. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211769. fromConnection: (QTCaptureConnection*) connection;
  211770. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211771. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211772. fromConnection: (QTCaptureConnection*) connection;
  211773. @end
  211774. BEGIN_JUCE_NAMESPACE
  211775. class QTCameraDeviceInteral
  211776. {
  211777. public:
  211778. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211779. {
  211780. const ScopedAutoReleasePool pool;
  211781. session = [[QTCaptureSession alloc] init];
  211782. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211783. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211784. input = 0;
  211785. audioInput = 0;
  211786. audioDevice = 0;
  211787. fileOutput = 0;
  211788. imageOutput = 0;
  211789. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211790. internalDev: this];
  211791. NSError* err = 0;
  211792. [device retain];
  211793. [device open: &err];
  211794. if (err == 0)
  211795. {
  211796. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211797. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211798. [session addInput: input error: &err];
  211799. if (err == 0)
  211800. {
  211801. resetFile();
  211802. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211803. [imageOutput setDelegate: callbackDelegate];
  211804. if (err == 0)
  211805. {
  211806. [session startRunning];
  211807. return;
  211808. }
  211809. }
  211810. }
  211811. openingError = nsStringToJuce ([err description]);
  211812. DBG (openingError);
  211813. }
  211814. ~QTCameraDeviceInteral()
  211815. {
  211816. [session stopRunning];
  211817. [session removeOutput: imageOutput];
  211818. [session release];
  211819. [input release];
  211820. [device release];
  211821. [audioDevice release];
  211822. [audioInput release];
  211823. [fileOutput release];
  211824. [imageOutput release];
  211825. [callbackDelegate release];
  211826. }
  211827. void resetFile()
  211828. {
  211829. [fileOutput recordToOutputFileURL: nil];
  211830. [session removeOutput: fileOutput];
  211831. [fileOutput release];
  211832. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211833. [session removeInput: audioInput];
  211834. [audioInput release];
  211835. audioInput = 0;
  211836. [audioDevice release];
  211837. audioDevice = 0;
  211838. [fileOutput setDelegate: callbackDelegate];
  211839. }
  211840. void addDefaultAudioInput()
  211841. {
  211842. NSError* err = nil;
  211843. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211844. if ([audioDevice open: &err])
  211845. [audioDevice retain];
  211846. else
  211847. audioDevice = nil;
  211848. if (audioDevice != 0)
  211849. {
  211850. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211851. [session addInput: audioInput error: &err];
  211852. }
  211853. }
  211854. void addListener (CameraImageListener* listenerToAdd)
  211855. {
  211856. const ScopedLock sl (listenerLock);
  211857. if (listeners.size() == 0)
  211858. [session addOutput: imageOutput error: nil];
  211859. listeners.addIfNotAlreadyThere (listenerToAdd);
  211860. }
  211861. void removeListener (CameraImageListener* listenerToRemove)
  211862. {
  211863. const ScopedLock sl (listenerLock);
  211864. listeners.removeValue (listenerToRemove);
  211865. if (listeners.size() == 0)
  211866. [session removeOutput: imageOutput];
  211867. }
  211868. void callListeners (CIImage* frame, int w, int h)
  211869. {
  211870. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211871. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211872. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211873. CGContextFlush (image.context);
  211874. const ScopedLock sl (listenerLock);
  211875. for (int i = listeners.size(); --i >= 0;)
  211876. {
  211877. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211878. if (l != 0)
  211879. l->imageReceived (image);
  211880. }
  211881. }
  211882. QTCaptureDevice* device;
  211883. QTCaptureDeviceInput* input;
  211884. QTCaptureDevice* audioDevice;
  211885. QTCaptureDeviceInput* audioInput;
  211886. QTCaptureSession* session;
  211887. QTCaptureMovieFileOutput* fileOutput;
  211888. QTCaptureDecompressedVideoOutput* imageOutput;
  211889. QTCaptureCallbackDelegate* callbackDelegate;
  211890. String openingError;
  211891. VoidArray listeners;
  211892. CriticalSection listenerLock;
  211893. };
  211894. END_JUCE_NAMESPACE
  211895. @implementation QTCaptureCallbackDelegate
  211896. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211897. internalDev: (QTCameraDeviceInteral*) d
  211898. {
  211899. [super init];
  211900. owner = owner_;
  211901. internal = d;
  211902. firstRecordedTime = 0;
  211903. return self;
  211904. }
  211905. - (void) dealloc
  211906. {
  211907. delete firstRecordedTime;
  211908. [super dealloc];
  211909. }
  211910. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211911. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211912. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211913. fromConnection: (QTCaptureConnection*) connection
  211914. {
  211915. if (internal->listeners.size() > 0)
  211916. {
  211917. const ScopedAutoReleasePool pool;
  211918. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211919. CVPixelBufferGetWidth (videoFrame),
  211920. CVPixelBufferGetHeight (videoFrame));
  211921. }
  211922. }
  211923. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211924. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211925. fromConnection: (QTCaptureConnection*) connection
  211926. {
  211927. if (firstRecordedTime == 0)
  211928. {
  211929. const Time now (Time::getCurrentTime());
  211930. firstRecordedTime = new Time (now - RelativeTime (0.1));
  211931. }
  211932. }
  211933. @end
  211934. BEGIN_JUCE_NAMESPACE
  211935. class QTCaptureViewerComp : public NSViewComponent
  211936. {
  211937. public:
  211938. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  211939. {
  211940. const ScopedAutoReleasePool pool;
  211941. captureView = [[QTCaptureView alloc] init];
  211942. [captureView setCaptureSession: internal->session];
  211943. setSize (640, 480); // xxx need to somehow get the movie size - how?
  211944. setView (captureView);
  211945. }
  211946. ~QTCaptureViewerComp()
  211947. {
  211948. setView (0);
  211949. [captureView setCaptureSession: nil];
  211950. [captureView release];
  211951. }
  211952. QTCaptureView* captureView;
  211953. };
  211954. CameraDevice::CameraDevice (const String& name_, int index)
  211955. : name (name_)
  211956. {
  211957. isRecording = false;
  211958. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  211959. internal = d;
  211960. }
  211961. CameraDevice::~CameraDevice()
  211962. {
  211963. stopRecording();
  211964. delete (QTCameraDeviceInteral*) internal;
  211965. internal = 0;
  211966. }
  211967. Component* CameraDevice::createViewerComponent()
  211968. {
  211969. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  211970. }
  211971. const String CameraDevice::getFileExtension()
  211972. {
  211973. return ".mov";
  211974. }
  211975. void CameraDevice::startRecordingToFile (const File& file)
  211976. {
  211977. stopRecording();
  211978. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211979. deleteAndZero (d->callbackDelegate->firstRecordedTime);
  211980. file.deleteFile();
  211981. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  211982. // out wrong, so we'll put some audio in there too..,
  211983. d->addDefaultAudioInput();
  211984. [d->session addOutput: d->fileOutput error: nil];
  211985. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  211986. for (;;)
  211987. {
  211988. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  211989. if (connection == 0)
  211990. break;
  211991. QTCompressionOptions* options = 0;
  211992. NSString* mediaType = [connection mediaType];
  211993. if ([mediaType isEqualToString: QTMediaTypeVideo])
  211994. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsSD480SizeH264Video"];
  211995. else if ([mediaType isEqualToString: QTMediaTypeSound])
  211996. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  211997. [d->fileOutput setCompressionOptions: options forConnection: connection];
  211998. }
  211999. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212000. isRecording = true;
  212001. }
  212002. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212003. {
  212004. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212005. if (d->callbackDelegate->firstRecordedTime != 0)
  212006. return *d->callbackDelegate->firstRecordedTime;
  212007. return Time();
  212008. }
  212009. void CameraDevice::stopRecording()
  212010. {
  212011. if (isRecording)
  212012. {
  212013. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212014. d->resetFile();
  212015. isRecording = false;
  212016. }
  212017. }
  212018. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212019. {
  212020. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212021. if (listenerToAdd != 0)
  212022. d->addListener (listenerToAdd);
  212023. }
  212024. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212025. {
  212026. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212027. if (listenerToRemove != 0)
  212028. d->removeListener (listenerToRemove);
  212029. }
  212030. const StringArray CameraDevice::getAvailableDevices()
  212031. {
  212032. const ScopedAutoReleasePool pool;
  212033. StringArray results;
  212034. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212035. for (int i = 0; i < (int) [devs count]; ++i)
  212036. {
  212037. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212038. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212039. }
  212040. return results;
  212041. }
  212042. CameraDevice* CameraDevice::openDevice (int index,
  212043. int minWidth, int minHeight,
  212044. int maxWidth, int maxHeight)
  212045. {
  212046. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212047. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212048. return d.release();
  212049. return 0;
  212050. }
  212051. #endif
  212052. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212053. #endif
  212054. #endif
  212055. END_JUCE_NAMESPACE
  212056. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212057. #endif
  212058. #endif